Rev 2235 | Rev 2262 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2235 | Rev 2245 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | #include <arch/exception.h> |
36 | #include <arch/exception.h> |
37 | #include "aux_print/printf.h" |
37 | #include "aux_print/printf.h" |
38 | #include <arch/memstr.h> |
38 | #include <arch/memstr.h> |
39 | #include <arch/regutils.h> |
39 | #include <arch/regutils.h> |
40 | #include <interrupt.h> |
40 | #include <interrupt.h> |
41 | - | ||
- | 41 | #include <arch/drivers/gxemul.h> |
|
42 | 42 | ||
43 | #define PREFETCH_OFFSET 0x8 |
43 | #define PREFETCH_OFFSET 0x8 |
44 | #define BRANCH_OPCODE 0xea000000 |
44 | #define BRANCH_OPCODE 0xea000000 |
45 | #define LDR_OPCODE 0xe59ff000 |
45 | #define LDR_OPCODE 0xe59ff000 |
46 | #define VALID_BRANCH_MASK 0xff000000 |
46 | #define VALID_BRANCH_MASK 0xff000000 |
47 | #define EXC_VECTORS_SIZE 0x20 |
47 | #define EXC_VECTORS_SIZE 0x20 |
48 | #define EXC_VECTORS 0x8 |
48 | #define EXC_VECTORS 0x8 |
49 | 49 | ||
50 | /* GXEmul interrupt controller macros |
- | |
51 | TODO might go to drivers/ together with servicing functions |
- | |
52 | */ |
- | |
53 | /* IRQ Controller device is added in a special premium gxemul |
- | |
54 | * edition at www.ms.mff.cuni.cz/~stepp3am/mygxemul-0.4.4.1.tar.gz |
- | |
55 | * :) |
- | |
56 | */ |
- | |
57 | #define IRQ_CONTROLLER_CAUSE 0x0000000016000000 |
- | |
58 | #define IRQ_CONTROLLER_MAX_IRQ 8 |
- | |
59 | - | ||
60 | /* IRQs */ |
- | |
61 | #define CONSOLE_IRQ 2 |
- | |
62 | #define TIMER_IRQ 4 |
- | |
63 | - | ||
64 | 50 | ||
65 | #define SAVE_REGS_TO_STACK \ |
51 | #define SAVE_REGS_TO_STACK \ |
66 | asm("stmfd sp!, {r0-r12, sp, lr}"); \ |
52 | asm("stmfd sp!, {r0-r12, sp, lr}"); \ |
67 | asm("mrs r14, spsr"); \ |
53 | asm("mrs r14, spsr"); \ |
68 | asm("stmfd sp!, {r14}"); |
54 | asm("stmfd sp!, {r14}"); |
Line 155... | Line 141... | ||
155 | /** Interrupt Exception handler. |
141 | /** Interrupt Exception handler. |
156 | * Determines the sources of interrupt, and calls their handlers. |
142 | * Determines the sources of interrupt, and calls their handlers. |
157 | */ |
143 | */ |
158 | static void irq_exception(int exc_no, istate_t* istate) |
144 | static void irq_exception(int exc_no, istate_t* istate) |
159 | { |
145 | { |
160 | /* TODO this will call interrupt dispatching routine |
- | |
161 | * |
- | |
162 | */ |
- | |
163 | - | ||
164 | uint32_t sources = *(uint32_t*) IRQ_CONTROLLER_CAUSE; |
146 | uint32_t sources = gxemul_irqc_get_sources(); |
165 | int i = 0; |
147 | int i = 0; |
166 | int noirq = 1; |
- | |
167 | for (; i < IRQ_CONTROLLER_MAX_IRQ; i++) { |
148 | for (; i < GXEMUL_IRQC_MAX_IRQ; i++) { |
168 | if (sources & (1 << i)) { |
149 | if (sources & (1 << i)) { |
- | 150 | irq_t *irq = irq_dispatch_and_lock(i); |
|
- | 151 | if (irq) { |
|
- | 152 | /* The IRQ handler was found. */ |
|
- | 153 | irq->handler(irq, irq->arg); |
|
- | 154 | spinlock_unlock(&irq->lock); |
|
- | 155 | } else { |
|
- | 156 | /* Spurious interrupt.*/ |
|
- | 157 | aux_printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, i); |
|
- | 158 | } |
|
- | 159 | } |
|
- | 160 | } |
|
- | 161 | /* TODO remove after testing the above code |
|
169 | noirq = 0; |
162 | noirq = 0; |
170 | if (i == CONSOLE_IRQ) { |
163 | if (i == CONSOLE_IRQ) { |
171 | char readchar = *(char*)0x10000000; |
164 | char readchar = *(char*)0x10000000; |
172 | if (readchar == 0) { |
165 | if (readchar == 0) { |
173 | aux_puts("?"); |
166 | aux_puts("?"); |
Line 177... | Line 170... | ||
177 | } |
170 | } |
178 | 171 | |
|
179 | } |
172 | } |
180 | else if (i == TIMER_IRQ) { |
173 | else if (i == TIMER_IRQ) { |
181 | aux_printf("\n.\n"); |
174 | aux_printf("\n.\n"); |
182 | /* acknowledge */ |
175 | //acknowledge |
183 | *(uint32_t*)0x15000110 = 0; |
176 | *(uint32_t*)0x15000110 = 0; |
184 | } |
177 | } |
185 | } |
178 | } |
186 | } |
179 | } |
187 | 180 | ||
188 | if (noirq) |
181 | if (noirq) |
189 | aux_puts("IRQ exception without source\n"); |
182 | aux_puts("IRQ exception without source\n");*/ |
190 | } |
183 | } |
191 | 184 | ||
192 | /** Fills exception vectors with appropriate exception handlers. |
185 | /** Fills exception vectors with appropriate exception handlers. |
193 | */ |
186 | */ |
194 | void install_exception_handlers(void) |
187 | void install_exception_handlers(void) |
Line 213... | Line 206... | ||
213 | 206 | ||
214 | install_handler((unsigned)fiq_exception_entry, |
207 | install_handler((unsigned)fiq_exception_entry, |
215 | (unsigned*)EXC_FIQ_VEC); |
208 | (unsigned*)EXC_FIQ_VEC); |
216 | } |
209 | } |
217 | 210 | ||
- | 211 | /** Initializes exception handling. |
|
- | 212 | * |
|
- | 213 | * Installs low-level exception handlers and then registers |
|
218 | /** Registers exceptions and their handlers to kernel exception dispatcher. */ |
214 | * exceptions and their handlers to kernel exception dispatcher. |
- | 215 | */ |
|
219 | void exception_init(void) |
216 | void exception_init(void) |
220 | { |
217 | { |
- | 218 | install_exception_handlers(); |
|
- | 219 | ||
221 | exc_register(EXC_IRQ, "interrupt", (iroutine) irq_exception); |
220 | exc_register(EXC_IRQ, "interrupt", (iroutine) irq_exception); |
222 | /* TODO add next */ |
221 | /* TODO add next */ |
223 | } |
222 | } |
224 | 223 | ||
225 | /* TODO change soon, temporary hack. */ |
224 | /* TODO change soon, temporary hack. */ |
Line 230... | Line 229... | ||
230 | current_status_reg_control_write( |
229 | current_status_reg_control_write( |
231 | (cspr & ~STATUS_REG_MODE_MASK) | IRQ_MODE |
230 | (cspr & ~STATUS_REG_MODE_MASK) | IRQ_MODE |
232 | ); |
231 | ); |
233 | asm("ldr sp, =irq_stack"); |
232 | asm("ldr sp, =irq_stack"); |
234 | current_status_reg_control_write( cspr); |
233 | current_status_reg_control_write( cspr); |
- | 234 | ||
- | 235 | /* TODO if you want to test other exceptions than IRQ, |
|
- | 236 | make stack analogous to irq_stack (in start.S), |
|
- | 237 | and then set stack pointer here */ |
|
235 | } |
238 | } |
236 | 239 | ||
237 | /** @} |
240 | /** @} |
238 | */ |
241 | */ |