1 //==========================================================================
5 // HAL platform miscellaneous functions
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
43 // Author(s): dmoseley (based on the original by nickg)
44 // Contributors: nickg, jlarmour, dmoseley
46 // Purpose: HAL miscellaneous functions
47 // Description: This file contains miscellaneous functions provided by the
50 //####DESCRIPTIONEND####
52 //========================================================================*/
54 #include <pkgconf/hal.h>
56 #include <cyg/infra/cyg_type.h> // Base types
57 #include <cyg/infra/cyg_trac.h> // tracing macros
58 #include <cyg/infra/cyg_ass.h> // assertion macros
60 #include <cyg/hal/hal_arch.h> // architectural definitions
62 #include <cyg/hal/hal_intr.h> // Interrupt handling
64 #include <cyg/hal/hal_cache.h> // Cache handling
66 #include <cyg/hal/hal_if.h>
68 #include <cyg/hal/plf_io.h>
70 /*------------------------------------------------------------------------*/
72 cyg_uint8 led_val(CYG_WORD hexdig)
74 static cyg_uint8 map[] = {
92 return map[(hexdig & 0xF)];
95 /*------------------------------------------------------------------------*/
97 #include CYGHWR_MEMORY_LAYOUT_H
98 #if defined(CYGPKG_CYGMON)
99 extern unsigned long cygmon_memsize;
102 void hal_platform_init(void)
104 HAL_WRITE_UINT8(HAL_LED_ADDRESS, led_val(8));
106 #if defined(CYG_HAL_STARTUP_ROM)
107 // Note that the hardware seems to come up with the
108 // caches containing random data. Hence they must be
109 // invalidated before being enabled.
110 // However, we only do this if we are in ROM. If we are
111 // in RAM, then we leave the caches in the state chosen
112 // by the ROM monitor. If we enable them when the monitor
113 // is not expecting it, we can end up breaking things if the
114 // monitor is not doing cache flushes.
116 HAL_ICACHE_INVALIDATE_ALL();
118 HAL_DCACHE_INVALIDATE_ALL();
122 #if defined(CYGPKG_CYGMON)
123 cygmon_memsize = 16 * 1024 * 1024 - 0x200; // 16 MB - 0x200 (for _hal_vsr_table and _hal_virtual_vector_table)
126 // Set up eCos/ROM interfaces
129 #if defined(CYGPKG_KERNEL) && \
130 defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
131 defined(CYGSEM_HAL_USE_ROM_MONITOR_GDB_stubs)
133 extern CYG_ADDRESS hal_virtual_vector_table[32];
134 extern void patch_dbg_syscalls(void * vector);
135 patch_dbg_syscalls( (void *)(&hal_virtual_vector_table[0]) );
138 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
140 static void hal_ctrlc_isr_init(void);
141 hal_ctrlc_isr_init();
146 // Make sure the TBR points at the base of ROM
148 #define TBR 0xC0000024
150 HAL_READ_UINT32(TBR, TBR_val);
151 TBR_val = (TBR_val & 0x00FFFFFF) | (CYGMEM_REGION_rom & 0xFF000000);
152 HAL_WRITE_UINT32(TBR, TBR_val);
155 // Make sure the MTBR points at the base of ROM
157 #define mTBR 0xC0000028
159 HAL_READ_UINT32(mTBR, mTBR_val);
160 mTBR_val = (mTBR_val & 0x00FFFFFF) | (CYGMEM_REGION_rom & 0xFF000000);
161 HAL_WRITE_UINT32(mTBR, mTBR_val);
166 /*------------------------------------------------------------------------*/
167 /* Functions to support the detection and execution of a user provoked */
168 /* program break. These are usually called from interrupt routines. */
170 /*------------------------------------------------------------------------*/
171 /* Control C ISR support */
172 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
174 #if CYGHWR_HAL_MN10300_AM33_STB_GDB_PORT == 0
176 // We use serial0 on AM33
177 #define SERIAL_CR ((volatile cyg_uint16 *)0xd4002000)
178 #define SERIAL_ICR ((volatile cyg_uint8 *) 0xd4002004)
179 #define SERIAL_TXR ((volatile cyg_uint8 *) 0xd4002008)
180 #define SERIAL_RXR ((volatile cyg_uint8 *) 0xd4002009)
181 #define SERIAL_SR ((volatile cyg_uint16 *)0xd400200c)
183 // Timer 1 provided baud rate divisor
184 #define TIMER_MD ((volatile cyg_uint8 *)0xd4003000)
185 #define TIMER_BR ((volatile cyg_uint8 *)0xd4003010)
186 #define TIMER_CR ((volatile cyg_uint8 *)0xd4003020)
188 #define SIO_LSTAT_TRDY 0x20
189 #define SIO_LSTAT_RRDY 0x10
193 #error Unsupported GDB port
197 struct Hal_SavedRegisters *hal_saved_interrupt_state;
199 static void hal_ctrlc_isr_init(void)
203 // HAL_READ_UINT16( SERIAL_CR, cr );
205 // HAL_WRITE_UINT16( SERIAL_CR, cr );
206 HAL_INTERRUPT_SET_LEVEL( CYGHWR_HAL_GDB_PORT_VECTOR, 4 );
207 HAL_INTERRUPT_UNMASK( CYGHWR_HAL_GDB_PORT_VECTOR );
210 cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
215 HAL_INTERRUPT_ACKNOWLEDGE( CYGHWR_HAL_GDB_PORT_VECTOR );
217 HAL_READ_UINT16( SERIAL_SR, sr );
219 if( sr & SIO_LSTAT_RRDY )
221 HAL_READ_UINT8( SERIAL_RXR, c);
223 if( cyg_hal_is_break( &c , 1 ) )
224 cyg_hal_user_break( (CYG_ADDRWORD *)hal_saved_interrupt_state );
233 void hal_arch_funcall_new_stack(void (*func)(void), void* stack_base, cyg_uint32 stack_size)
235 register cyg_uint32 stack_top = (cyg_uint32)stack_base + stack_size;
236 register cyg_uint32 old_stack;
237 asm volatile (" mov sp, %0" : "=r" (old_stack) : );
238 asm volatile (" mov %0, sp" : : "r" (stack_top) );
240 asm volatile (" mov %0, sp" : : "r" (old_stack) );
243 /*------------------------------------------------------------------------*/
244 /* Syscall support */
246 // Cygmon provides syscall handling for this board
247 #include <cyg/hal/hal_stub.h>
248 int __get_syscall_num (void)
254 /*------------------------------------------------------------------------*/
255 /* End of plf_misc.c */