BASIC compiler/interpreter for PIC32MX/MZ-80K
修订版 | a8f2a2fb367957f62d9732be551206575fe1d26f (tree) |
---|---|
时间 | 2019-04-07 08:07:34 |
作者 | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Avoid exception when interrupt in case using $s5 in function.
@@ -275,18 +275,19 @@ static const void* debugjumptable[]={ | ||
275 | 275 | |
276 | 276 | int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){ |
277 | 277 | asm volatile(".set noreorder"); |
278 | - asm volatile("b label1"); | |
279 | - asm volatile("lui $v1,0x1234"); | |
280 | - asm volatile("ori $v1,$v1,0x5678"); | |
281 | - asm volatile("sw $v0,0($v1)"); | |
282 | - asm volatile("label1:"); | |
283 | - asm volatile("sw $zero,0x1234($v1)"); | |
284 | - asm volatile("sw $zero,0x1234($gp)"); | |
285 | 278 | asm volatile("nop"); |
286 | - int i; | |
287 | - for2(i,1,10){ | |
288 | - asm volatile("nop"); | |
289 | - } | |
279 | + asm volatile("nop"); | |
280 | + asm volatile("nop"); | |
281 | + asm volatile("nop"); | |
282 | + asm volatile("nop"); | |
283 | + asm volatile("nop"); | |
284 | + asm volatile("nop"); | |
285 | + asm volatile("nop"); | |
286 | + asm volatile("nop"); | |
287 | + asm volatile("nop"); | |
288 | + asm volatile("nop"); | |
289 | + asm volatile("nop"); | |
290 | + a2&=0xFFFFFFFC; | |
290 | 291 | return a2+a3; |
291 | 292 | } |
292 | 293 |
@@ -44,7 +44,12 @@ void dumpMemory(){ | ||
44 | 44 | void dumpMemory(){} |
45 | 45 | #endif //ifdef DUMPFILE |
46 | 46 | |
47 | +void _general_exception_handler_main (void); | |
47 | 48 | void _general_exception_handler (void){ |
49 | + asm volatile("la $sp,%0"::"i"(&RAM[RAMSIZE-4])); | |
50 | + asm volatile("j _general_exception_handler_main"); | |
51 | +} | |
52 | +void _general_exception_handler_main (void){ | |
48 | 53 | int i; |
49 | 54 | // $v1 is g_ex_data |
50 | 55 | asm volatile("la $v1,%0"::"i"(&g_ex_data[0])); |
@@ -79,7 +84,9 @@ void _general_exception_handler (void){ | ||
79 | 84 | if((readbuttons()&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE)) |
80 | 85 | !=(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE)) i=0; |
81 | 86 | } |
82 | - asm volatile("j SoftReset"); | |
87 | + RCONbits.POR=0; | |
88 | + RCONbits.EXTR=0; | |
89 | + asm volatile("j 0x9FC00000"); | |
83 | 90 | #endif |
84 | 91 | } |
85 | 92 |
@@ -167,14 +167,30 @@ char* timer_function(){ | ||
167 | 167 | */ |
168 | 168 | |
169 | 169 | void BasicInt(int addr){ |
170 | - // $a0 is the address in BASIC code | |
170 | + // Note that $s0-$s7 values must be set again here. | |
171 | 171 | asm volatile(".set noreorder"); |
172 | + // Set s5 for initial_s5_stack | |
173 | + asm volatile("la $s5,%0"::"i"(&g_initial_s5_stack[2])); | |
174 | + // Set s7 for easy calling call_library() | |
175 | + asm volatile("la $s7,%0"::"i"(&call_library)); | |
176 | + // $a0 is the address in BASIC code | |
172 | 177 | asm volatile("jr $a0"); |
173 | 178 | asm volatile("nop"); |
174 | 179 | } |
175 | 180 | #pragma interrupt CS1Handler IPL1SOFT vector 2 |
176 | 181 | void CS1Handler(void){ |
177 | 182 | int i; |
183 | + // Store s0-s7, fp, and ra in stacks | |
184 | + asm volatile("#":::"s0"); | |
185 | + asm volatile("#":::"s1"); | |
186 | + asm volatile("#":::"s2"); | |
187 | + asm volatile("#":::"s3"); | |
188 | + asm volatile("#":::"s4"); | |
189 | + asm volatile("#":::"s5"); | |
190 | + asm volatile("#":::"s6"); | |
191 | + asm volatile("#":::"s7"); | |
192 | + asm volatile("#":::"fp"); | |
193 | + asm volatile("#":::"ra"); | |
178 | 194 | while(g_interrupt_flags){ |
179 | 195 | for(i=0;i<NUM_INTERRUPT_TYPES;i++){ |
180 | 196 | if (g_interrupt_flags & (1<<i)) { |