1 | /** |
---|
2 | * @file cpu.c |
---|
3 | * |
---|
4 | * ARM CPU Dependent Source. |
---|
5 | */ |
---|
6 | /* |
---|
7 | * RTEMS GBA BSP |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 2000 Canon Research Centre France SA. |
---|
10 | * Emmanuel Raguet, mailto:raguet@crf.canon.fr |
---|
11 | * |
---|
12 | * Copyright (c) 2002 Advent Networks, Inc |
---|
13 | * Jay Monkman <jmonkman@adventnetworks.com> |
---|
14 | * |
---|
15 | * Copyright (c) 2004 |
---|
16 | * Markku Puro <markku.puro@kopteri.net> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | * |
---|
22 | * $Id$ |
---|
23 | */ |
---|
24 | #include <stdint.h> |
---|
25 | #include <rtems/system.h> |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/bspIo.h> |
---|
28 | #include <rtems/score/isr.h> |
---|
29 | #include <rtems/score/wkspace.h> |
---|
30 | #include <rtems/score/thread.h> |
---|
31 | #include <rtems/score/cpu.h> |
---|
32 | #include <arm_mode_bits.h> |
---|
33 | |
---|
34 | /** |
---|
35 | * @brief _CPU_Initialize routine performs processor dependent initialization |
---|
36 | * |
---|
37 | * @param cpu_table CPU table to initialize |
---|
38 | * @param thread_dispatch address of ISR disptaching routine (unused) |
---|
39 | * @return None |
---|
40 | */ |
---|
41 | void _CPU_Initialize( |
---|
42 | rtems_cpu_table *cpu_table, |
---|
43 | void (*thread_dispatch) /* ignored on this CPU */ |
---|
44 | ) |
---|
45 | { |
---|
46 | _CPU_Table = *cpu_table; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * @brief _CPU_ISR_Get_level returns the current interrupt level |
---|
51 | * |
---|
52 | * @param None |
---|
53 | * @return int level |
---|
54 | */ |
---|
55 | uint32_t _CPU_ISR_Get_level( void ) |
---|
56 | { |
---|
57 | uint32_t reg = 0; /* to avoid warning */ |
---|
58 | |
---|
59 | asm volatile ("mrs %0, cpsr \n" \ |
---|
60 | "and %0, %0, #0xc0 \n" \ |
---|
61 | : "=r" (reg) \ |
---|
62 | : "0" (reg) ); |
---|
63 | return reg; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief _CPU_ISR_install_vector kernel routine installs the RTEMS handler for the |
---|
69 | * specified vector |
---|
70 | * |
---|
71 | * @param vector interrupt vector number |
---|
72 | * @param new_handler replacement ISR for this vector number |
---|
73 | * @param old_handler pointer to store former ISR for this vector number |
---|
74 | * @return None |
---|
75 | * |
---|
76 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
77 | */ |
---|
78 | extern __inline__ void _CPU_ISR_install_vector(uint32_t vector, proc_ptr new_handler, proc_ptr *old_handler); |
---|
79 | |
---|
80 | /** |
---|
81 | * @brief _CPU_Context_Initialize kernel routine initialize the specified context |
---|
82 | * |
---|
83 | * @param the_context |
---|
84 | * @param stack_base |
---|
85 | * @param size |
---|
86 | * @param new_level |
---|
87 | * @param entry_point |
---|
88 | * @param is_fp |
---|
89 | * @return None |
---|
90 | */ |
---|
91 | void _CPU_Context_Initialize( |
---|
92 | Context_Control *the_context, |
---|
93 | uint32_t *stack_base, |
---|
94 | uint32_t size, |
---|
95 | uint32_t new_level, |
---|
96 | void *entry_point, |
---|
97 | boolean is_fp |
---|
98 | ) |
---|
99 | { |
---|
100 | the_context->register_sp = (uint32_t)stack_base + size ; |
---|
101 | the_context->register_lr = (uint32_t)entry_point; |
---|
102 | the_context->register_cpsr = new_level | ModePriv; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief _CPU_Install_interrupt_stack function is empty since the BSP must set up the interrupt stacks. |
---|
108 | * |
---|
109 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
110 | */ |
---|
111 | extern __inline__ void _CPU_Install_interrupt_stack( void ); |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief _defaultExcHandler function is empty |
---|
115 | * |
---|
116 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
117 | */ |
---|
118 | extern void _defaultExcHandler (CPU_Exception_frame *ctx); |
---|
119 | |
---|
120 | /** |
---|
121 | * @brief _currentExcHandler function is empty (_defaultExcHandler) |
---|
122 | * |
---|
123 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
124 | */ |
---|
125 | cpuExcHandlerType _currentExcHandler = _defaultExcHandler; |
---|
126 | /* |
---|
127 | extern void _Exception_Handler_Undef_Swi(); |
---|
128 | extern void _Exception_Handler_Abort(); |
---|
129 | extern void _exc_data_abort(); |
---|
130 | */ |
---|
131 | |
---|
132 | /** |
---|
133 | * @brief rtems_exception_init_mngt function is empty since the BSP must set up the interrupt stacks. |
---|
134 | * |
---|
135 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
136 | */ |
---|
137 | extern __inline__ void rtems_exception_init_mngt(); |
---|
138 | |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief do_data_abort function is empty |
---|
142 | * |
---|
143 | * This function figure out what caused the data abort |
---|
144 | * |
---|
145 | * @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! |
---|
146 | * This function is supposed to figure out what caused the data abort, do that, then return. |
---|
147 | * All unhandled instructions cause the system to hang. |
---|
148 | */ |
---|
149 | extern __inline__ void do_data_abort(uint32_t insn, uint32_t spsr, CPU_Exception_frame *ctx); |
---|
150 | |
---|
151 | |
---|
152 | /* @todo Can't use exception vectors in GBA because they are already in GBA ROM BIOS!! */ |
---|
153 | /* @todo Remove dummy functions needed by linker |
---|
154 | ****************************************************************************************/ |
---|
155 | /* @cond INCLUDE_ASM */ |
---|
156 | asm (" .text"); |
---|
157 | asm (" .arm"); |
---|
158 | asm (" .global _CPU_ISR_install_vector"); |
---|
159 | asm ("_CPU_ISR_install_vector:"); |
---|
160 | asm (" .global _CPU_Install_interrupt_stack"); |
---|
161 | asm ("_CPU_Install_interrupt_stack:"); |
---|
162 | asm (" .global _defaultExcHandler"); |
---|
163 | asm ("_defaultExcHandler:"); |
---|
164 | asm (" .global rtems_exception_init_mngt"); |
---|
165 | asm ("rtems_exception_init_mngt:"); |
---|
166 | asm (" .global do_data_abort"); |
---|
167 | asm ("do_data_abort:"); |
---|
168 | asm (" mov pc, lr"); |
---|
169 | /* @endcond */ |
---|
170 | |
---|