FreeCalypso > hg > fc-selenite
annotate src/cs/system/main/gcc/irqfiq.S @ 174:097e25b925a2
doc/Compiling: gtm900 target added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 19 Jun 2019 06:15:56 +0000 |
parents | 95ef11e76c5b |
children |
rev | line source |
---|---|
78
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the assembly shells for IRQ and FIQ, separated |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * from the architectured vectors only by some simple unconditional |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * branch instructions. |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * Note that TI's way of handling interrupts sacrifices Nucleus' ability |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * to nest interrupts and minimize the IRQ-disabled window: if my (Falcon's) |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * understanding is correct, TI's code leaves all further IRQs disabled |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * for the full execution duration of an IRQ handler. (IRQ handlers are |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * really LISRs, but TI's GSM fw does not use Nucleus' LISR framework.) |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 .text |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 .code 32 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 .globl _INT_IRQ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 _INT_IRQ: |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 STMDB sp!,{r0-r4} @ used to be a1-a4 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 /* |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 * Thanks to TI for discovering and documenting this apparent ARM7TDMI bug: |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 BUG correction 1st part ------------------- |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 It looks like there is an issue with ARM7 IRQ masking in the CPSR register |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 which leads to crashes in Nucleus+ scheduler. |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 Basically the code below (correct as LOCKOUT = 0xC0) is used in many places by N+ but do not |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 prevent from having an interrupt after the execution of the third line (I mean execution, not |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fetch). |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 MRS a1,CPSR ; Pickup current CPSR |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 ORR a1,a1,#LOCKOUT ; Build interrupt lockout value |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 MSR CPSR,a1 ; Lockout interrupts |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 * IRQ INTERRUPT ! * |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 Next instructions... |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 SW workaround: |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 When a task is interrupted at this point an interrupted context is stored on its task and will |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 be resumed later on at the next instruction but to make a long story short it leads to some |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 problem as the OS does not expect to be interrupted there. |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 Further testing tends to show that the CPSR *seems* to be loaded with the proper masking value |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 but that the IRQ is still triggered (has been hardwarewise requested during the instruction |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exectution by the ARM7 core?) |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 MRS a1,spsr @ check for the IRQ bug: |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 TST a1,#0x80 @ if the I - flag is set, |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 BNE IRQBUG @ then postpone execution of this IRQ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* Bug correction 1st part end --------------- */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 SUB r4,lr,#4 @ Save IRQ's lr (return address) |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 BL TCT_Interrupt_Context_Save @ Call context save routine |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 BL IQ_IRQ_isr @ Call int. service routine |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* IRQ interrupt processing is complete. Restore context- Never |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 returns! */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 B TCT_Interrupt_Context_Restore |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* BUG correction 2nd part ------------------ */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 IRQBUG: LDMFD sp!,{r0-r4} @ return from interrupt |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 SUBS pc,r14,#4 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 /* BUG correction 2nd part end -------------- */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 .globl _INT_FIQ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 _INT_FIQ: |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 STMDB sp!,{r0-r4} @ used to be a1-a4 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 SUB r4,lr,#4 @ Save FIQ's lr (return address) |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 BL TCT_Interrupt_Context_Save @ Call context save routine |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 BL IQ_FIQ_isr @ Call the FIQ ISR |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /* FIQ interrupt processing is complete. Restore context- Never |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 returns! */ |
95ef11e76c5b
src/cs/system/main/gcc: asm code pieced from Citrine
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 B TCT_Interrupt_Context_Restore |