Skip to content

Commit bfa29f1

Browse files
aykevldeadprogram
authored andcommitted
runtime: move/refactor some GC-related code
Instead of putting tinygo_scanCurrentStack in scheduler_*.S files, put them in dedicated files. The function tinygo_scanCurrentStack has nothing to do with scheduling and so doesn't belong there. Additionally, while scheduling code is made specific for the Cortex-M, the tinygo_scanCurrentStack is generic to all ARM targets so this move removes some duplication there. Specifically: * tinygo_scanCurrentStack is moved out of scheduler_cortexm.S as it isn't really part of the scheduler. It is now gc_arm.S. * Same for the AVR target. * Same for the RISCV target. * scheduler_gba.S is removed, using gc_arm.S instead as it only contains tinygo_scanCurrentStack.
1 parent 7123941 commit bfa29f1

File tree

9 files changed

+70
-86
lines changed

9 files changed

+70
-86
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
// Only generate .debug_frame, don't generate .eh_frame.
2+
.cfi_sections .debug_frame
3+
14
.section .text.tinygo_scanCurrentStack
25
.global tinygo_scanCurrentStack
36
.type tinygo_scanCurrentStack, %function
47
tinygo_scanCurrentStack:
8+
.cfi_startproc
59
// Save callee-saved registers onto the stack.
10+
#if defined(__thumb2__)
11+
push {r4-r11, lr}
12+
.cfi_def_cfa_offset 9*4
13+
#else
614
mov r0, r8
715
mov r1, r9
816
mov r2, r10
917
mov r3, r11
1018
push {r0-r3, lr}
19+
.cfi_def_cfa_offset 5*4
1120
push {r4-r7}
21+
.cfi_def_cfa_offset 4*4
22+
#endif
1223

1324
// Scan the stack.
1425
mov r0, sp
1526
bl tinygo_scanstack
1627

1728
// Restore stack state and return.
1829
add sp, #32
30+
.cfi_def_cfa_offset 1*4
1931
pop {pc}
32+
.cfi_endproc
33+
.size tinygo_scanCurrentStack, .-tinygo_scanCurrentStack

src/runtime/gc_avr.S

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.section .text.tinygo_scanCurrentStack
2+
.global tinygo_scanCurrentStack
3+
.type tinygo_scanCurrentStack, %function
4+
tinygo_scanCurrentStack:
5+
// Save callee-saved registers.
6+
push r29 // Y
7+
push r28 // Y
8+
push r17
9+
push r16
10+
push r15
11+
push r14
12+
push r13
13+
push r12
14+
push r11
15+
push r10
16+
push r9
17+
push r8
18+
push r7
19+
push r6
20+
push r5
21+
push r4
22+
push r3
23+
push r2
24+
25+
// Scan the stack.
26+
in r24, 0x3d; SPL
27+
in r25, 0x3e; SPH
28+
#if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25
29+
rcall tinygo_scanstack
30+
#else
31+
call tinygo_scanstack
32+
#endif
33+
34+
// Restore callee-saved registers.
35+
pop r2
36+
pop r3
37+
pop r4
38+
pop r5
39+
pop r6
40+
pop r7
41+
pop r8
42+
pop r9
43+
pop r10
44+
pop r11
45+
pop r12
46+
pop r13
47+
pop r14
48+
pop r15
49+
pop r16
50+
pop r17
51+
pop r28 // Y
52+
pop r29 // Y
File renamed without changes.

src/runtime/scheduler_avr.S

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -187,56 +187,3 @@ tinygo_switchToScheduler:
187187

188188
// Return into the scheduler, as if tinygo_switchToTask was a regular call.
189189
ret
190-
191-
.section .text.tinygo_scanCurrentStack
192-
.global tinygo_scanCurrentStack
193-
.type tinygo_scanCurrentStack, %function
194-
tinygo_scanCurrentStack:
195-
// Save callee-saved registers.
196-
push r29 // Y
197-
push r28 // Y
198-
push r17
199-
push r16
200-
push r15
201-
push r14
202-
push r13
203-
push r12
204-
push r11
205-
push r10
206-
push r9
207-
push r8
208-
push r7
209-
push r6
210-
push r5
211-
push r4
212-
push r3
213-
push r2
214-
215-
// Scan the stack.
216-
in r24, 0x3d; SPL
217-
in r25, 0x3e; SPH
218-
#if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25
219-
rcall tinygo_scanstack
220-
#else
221-
call tinygo_scanstack
222-
#endif
223-
224-
// Restore callee-saved registers.
225-
pop r2
226-
pop r3
227-
pop r4
228-
pop r5
229-
pop r6
230-
pop r7
231-
pop r8
232-
pop r9
233-
pop r10
234-
pop r11
235-
pop r12
236-
pop r13
237-
pop r14
238-
pop r15
239-
pop r16
240-
pop r17
241-
pop r28 // Y
242-
pop r29 // Y

src/runtime/scheduler_cortexm.S

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,34 +136,3 @@ tinygo_swapTask:
136136
#endif
137137
.cfi_endproc
138138
.size tinygo_swapTask, .-tinygo_swapTask
139-
140-
.section .text.tinygo_scanCurrentStack
141-
.global tinygo_scanCurrentStack
142-
.type tinygo_scanCurrentStack, %function
143-
tinygo_scanCurrentStack:
144-
.cfi_startproc
145-
// Save callee-saved registers onto the stack.
146-
#if defined(__thumb2__)
147-
push {r4-r11, lr}
148-
.cfi_def_cfa_offset 9*4
149-
#else
150-
mov r0, r8
151-
mov r1, r9
152-
mov r2, r10
153-
mov r3, r11
154-
push {r0-r3, lr}
155-
.cfi_def_cfa_offset 5*4
156-
push {r4-r7}
157-
.cfi_def_cfa_offset 4*4
158-
#endif
159-
160-
// Scan the stack.
161-
mov r0, sp
162-
bl tinygo_scanstack
163-
164-
// Restore stack state and return.
165-
add sp, #32
166-
.cfi_def_cfa_offset 1*4
167-
pop {pc}
168-
.cfi_endproc
169-
.size tinygo_scanCurrentStack, .-tinygo_scanCurrentStack

targets/avr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"-Wl,--gc-sections"
1414
],
1515
"extra-files": [
16+
"src/runtime/gc_avr.S",
1617
"src/runtime/scheduler_avr.S"
1718
]
1819
}

targets/cortex-m.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"extra-files": [
2727
"src/device/arm/cortexm.s",
28+
"src/runtime/gc_arm.S",
2829
"src/runtime/scheduler_cortexm.S"
2930
],
3031
"gdb": "gdb-multiarch"

targets/gameboy-advance.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"linkerscript": "targets/gameboy-advance.ld",
2626
"extra-files": [
2727
"targets/gameboy-advance.s",
28-
"src/runtime/scheduler_gba.S"
28+
"src/runtime/gc_arm.S"
2929
],
3030
"gdb": "gdb-multiarch",
3131
"emulator": ["mgba", "-3"]

targets/riscv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"extra-files": [
2020
"src/device/riscv/start.S",
21-
"src/runtime/scheduler_tinygoriscv.S",
21+
"src/runtime/gc_riscv.S",
2222
"src/device/riscv/handleinterrupt.S"
2323
],
2424
"gdb": "riscv64-unknown-elf-gdb"

0 commit comments

Comments
 (0)