BASIC compiler/interpreter for PIC32MX/MZ-80K
Revisión | a1ee537c7d3b88c5d262424a379540a6e961ec82 (tree) |
---|---|
Tiempo | 2019-04-08 10:00:46 |
Autor | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Force TMR1=0 when executing TIMER statement
@@ -24,15 +24,17 @@ | ||
24 | 24 | $s7: address of call_library() |
25 | 25 | $t8-$t9: used as temporary registors |
26 | 26 | $k0-$k1: not used |
27 | - $gp: for accessing global valiables by C | |
27 | + $gp: for accessing global variables by C | |
28 | 28 | $sp: stack pointer |
29 | - $fp($s8) for accessing valiables by BASIC | |
29 | + $fp($s8) for accessing variables by BASIC | |
30 | 30 | $ra: contains return address |
31 | 31 | */ |
32 | 32 | |
33 | 33 | #include "compiler.h" |
34 | 34 | |
35 | 35 | void start_program(void* addr, void* memory){ |
36 | + // Note that if usage of $s0-$s7, and $fp is changed, | |
37 | + // revice BasicInt() in timer.c, too. | |
36 | 38 | static unsigned int stored_sp; |
37 | 39 | // Store s0-s7, fp, and ra in stacks |
38 | 40 | asm volatile("#":::"s0"); |
@@ -139,21 +139,22 @@ char* timer_statement(){ | ||
139 | 139 | char* err; |
140 | 140 | err=get_value(); |
141 | 141 | if (err) return err; |
142 | - i=(int)(&g_timer); | |
143 | - check_obj_space(3); | |
142 | + i=(int)(&g_timer)+0x8000; | |
143 | + check_obj_space(4); | |
144 | 144 | g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,xxxx |
145 | - g_object[g_objpos++]=0x34630000|(i&0x0000FFFF); // ori v1,v1,xxxx | |
146 | - g_object[g_objpos++]=0xAC620000; // sw v0,0(v1) | |
145 | + g_object[g_objpos++]=0xAC620000|((i-0x8000)&0xFFFF); // sw v0,xxxx(v1) | |
146 | + i=(int)(&TMR1)+0x8000;//0xBF800610 | |
147 | + g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,0xbf80 | |
148 | + g_object[g_objpos++]=0xAC600000|((i-0x8000)&0xFFFF); // sw zero,0x0610(v1) | |
147 | 149 | return 0; |
148 | 150 | } |
149 | 151 | |
150 | 152 | char* timer_function(){ |
151 | 153 | int i; |
152 | - i=(int)(&g_timer); | |
153 | - check_obj_space(3); | |
154 | + i=(int)(&g_timer)+0x8000; | |
155 | + check_obj_space(2); | |
154 | 156 | g_object[g_objpos++]=0x3C020000|((i>>16)&0x0000FFFF); // lui v0,xxxx |
155 | - g_object[g_objpos++]=0x34420000|(i&0x0000FFFF); // ori v0,v0,xxxx | |
156 | - g_object[g_objpos++]=0x8C420000; // lw v0,0(v0) | |
157 | + g_object[g_objpos++]=0x8C420000|((i-0x8000)&0xFFFF); // lw v0,xxxx(v0) | |
157 | 158 | return 0; |
158 | 159 | } |
159 | 160 |
@@ -165,16 +166,15 @@ char* timer_function(){ | ||
165 | 166 | |
166 | 167 | */ |
167 | 168 | |
168 | -void BasicInt(int addr){ | |
169 | - // Note that $s0-$s7 values must be set again here. | |
170 | - asm volatile(".set noreorder"); | |
169 | +void BasicInt(int addr,void* memory){ | |
170 | + // Note that $s0-$s7 and $fp values must be set again here. | |
171 | 171 | // Set s5 for initial_s5_stack |
172 | 172 | asm volatile("la $s5,%0"::"i"(&g_initial_s5_stack[2])); |
173 | 173 | // Set s7 for easy calling call_library() |
174 | 174 | asm volatile("la $s7,%0"::"i"(&call_library)); |
175 | - // $a0 is the address in BASIC code | |
175 | + // Set fp and execute BASIC code at $a0 | |
176 | + asm volatile("addu $fp,$zero,$a1"); | |
176 | 177 | asm volatile("jr $a0"); |
177 | - asm volatile("nop"); | |
178 | 178 | } |
179 | 179 | #pragma interrupt CS1Handler IPL1SOFT vector 2 |
180 | 180 | void CS1Handler(void){ |
@@ -193,7 +193,7 @@ void CS1Handler(void){ | ||
193 | 193 | while(g_interrupt_flags){ |
194 | 194 | for(i=0;i<NUM_INTERRUPT_TYPES;i++){ |
195 | 195 | if (g_interrupt_flags & (1<<i)) { |
196 | - if (g_int_vector[i]) BasicInt(g_int_vector[i]); | |
196 | + if (g_int_vector[i]) BasicInt(g_int_vector[i],(void*)(&g_var_mem[0])); | |
197 | 197 | g_interrupt_flags &= (1<<i)^0xffff; |
198 | 198 | } |
199 | 199 | } |
@@ -24,15 +24,17 @@ | ||
24 | 24 | $s7: address of call_library() |
25 | 25 | $t8-$t9: used as temporary registors |
26 | 26 | $k0-$k1: not used |
27 | - $gp: for accessing global valiables by C | |
27 | + $gp: for accessing global variables by C | |
28 | 28 | $sp: stack pointer |
29 | - $fp($s8) for accessing valiables by BASIC | |
29 | + $fp($s8) for accessing variables by BASIC | |
30 | 30 | $ra: contains return address |
31 | 31 | */ |
32 | 32 | |
33 | 33 | #include "compiler.h" |
34 | 34 | |
35 | 35 | void start_program(void* addr, void* memory){ |
36 | + // Note that if usage of $s0-$s7, and $fp is changed, | |
37 | + // revice BasicInt() in timer.c, too. | |
36 | 38 | static unsigned int stored_sp; |
37 | 39 | // Store s0-s7, fp, and ra in stacks |
38 | 40 | asm volatile("#":::"s0"); |
@@ -139,21 +139,22 @@ char* timer_statement(){ | ||
139 | 139 | char* err; |
140 | 140 | err=get_value(); |
141 | 141 | if (err) return err; |
142 | - i=(int)(&g_timer); | |
143 | - check_obj_space(3); | |
142 | + i=(int)(&g_timer)+0x8000; | |
143 | + check_obj_space(4); | |
144 | 144 | g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,xxxx |
145 | - g_object[g_objpos++]=0x34630000|(i&0x0000FFFF); // ori v1,v1,xxxx | |
146 | - g_object[g_objpos++]=0xAC620000; // sw v0,0(v1) | |
145 | + g_object[g_objpos++]=0xAC620000|((i-0x8000)&0xFFFF); // sw v0,xxxx(v1) | |
146 | + i=(int)(&TMR1)+0x8000;//0xBF800610 | |
147 | + g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,0xbf80 | |
148 | + g_object[g_objpos++]=0xAC600000|((i-0x8000)&0xFFFF); // sw zero,0x0610(v1) | |
147 | 149 | return 0; |
148 | 150 | } |
149 | 151 | |
150 | 152 | char* timer_function(){ |
151 | 153 | int i; |
152 | - i=(int)(&g_timer); | |
153 | - check_obj_space(3); | |
154 | + i=(int)(&g_timer)+0x8000; | |
155 | + check_obj_space(2); | |
154 | 156 | g_object[g_objpos++]=0x3C020000|((i>>16)&0x0000FFFF); // lui v0,xxxx |
155 | - g_object[g_objpos++]=0x34420000|(i&0x0000FFFF); // ori v0,v0,xxxx | |
156 | - g_object[g_objpos++]=0x8C420000; // lw v0,0(v0) | |
157 | + g_object[g_objpos++]=0x8C420000|((i-0x8000)&0xFFFF); // lw v0,xxxx(v0) | |
157 | 158 | return 0; |
158 | 159 | } |
159 | 160 |
@@ -165,16 +166,15 @@ char* timer_function(){ | ||
165 | 166 | |
166 | 167 | */ |
167 | 168 | |
168 | -void BasicInt(int addr){ | |
169 | - // Note that $s0-$s7 values must be set again here. | |
170 | - asm volatile(".set noreorder"); | |
169 | +void BasicInt(int addr,void* memory){ | |
170 | + // Note that $s0-$s7 and $fp values must be set again here. | |
171 | 171 | // Set s5 for initial_s5_stack |
172 | 172 | asm volatile("la $s5,%0"::"i"(&g_initial_s5_stack[2])); |
173 | 173 | // Set s7 for easy calling call_library() |
174 | 174 | asm volatile("la $s7,%0"::"i"(&call_library)); |
175 | - // $a0 is the address in BASIC code | |
175 | + // Set fp and execute BASIC code at $a0 | |
176 | + asm volatile("addu $fp,$zero,$a1"); | |
176 | 177 | asm volatile("jr $a0"); |
177 | - asm volatile("nop"); | |
178 | 178 | } |
179 | 179 | #pragma interrupt CS1Handler IPL1SOFT vector 2 |
180 | 180 | void CS1Handler(void){ |
@@ -193,7 +193,7 @@ void CS1Handler(void){ | ||
193 | 193 | while(g_interrupt_flags){ |
194 | 194 | for(i=0;i<NUM_INTERRUPT_TYPES;i++){ |
195 | 195 | if (g_interrupt_flags & (1<<i)) { |
196 | - if (g_int_vector[i]) BasicInt(g_int_vector[i]); | |
196 | + if (g_int_vector[i]) BasicInt(g_int_vector[i],(void*)(&g_var_mem[0])); | |
197 | 197 | g_interrupt_flags &= (1<<i)^0xffff; |
198 | 198 | } |
199 | 199 | } |