Browse Source

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.
pull/1223/merge
Ayke van Laethem 4 years ago
committed by Ron Evans
parent
commit
bfa29f17da
  1. 14
      src/runtime/gc_arm.S
  2. 52
      src/runtime/gc_avr.S
  3. 0
      src/runtime/gc_riscv.S
  4. 53
      src/runtime/scheduler_avr.S
  5. 31
      src/runtime/scheduler_cortexm.S
  6. 1
      targets/avr.json
  7. 1
      targets/cortex-m.json
  8. 2
      targets/gameboy-advance.json
  9. 2
      targets/riscv.json

14
src/runtime/scheduler_gba.S → src/runtime/gc_arm.S

@ -1,14 +1,25 @@
// Only generate .debug_frame, don't generate .eh_frame.
.cfi_sections .debug_frame
.section .text.tinygo_scanCurrentStack
.global tinygo_scanCurrentStack
.type tinygo_scanCurrentStack, %function
tinygo_scanCurrentStack:
.cfi_startproc
// Save callee-saved registers onto the stack.
#if defined(__thumb2__)
push {r4-r11, lr}
.cfi_def_cfa_offset 9*4
#else
mov r0, r8
mov r1, r9
mov r2, r10
mov r3, r11
push {r0-r3, lr}
.cfi_def_cfa_offset 5*4
push {r4-r7}
.cfi_def_cfa_offset 4*4
#endif
// Scan the stack.
mov r0, sp
@ -16,4 +27,7 @@ tinygo_scanCurrentStack:
// Restore stack state and return.
add sp, #32
.cfi_def_cfa_offset 1*4
pop {pc}
.cfi_endproc
.size tinygo_scanCurrentStack, .-tinygo_scanCurrentStack

52
src/runtime/gc_avr.S

@ -0,0 +1,52 @@
.section .text.tinygo_scanCurrentStack
.global tinygo_scanCurrentStack
.type tinygo_scanCurrentStack, %function
tinygo_scanCurrentStack:
// Save callee-saved registers.
push r29 // Y
push r28 // Y
push r17
push r16
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push r7
push r6
push r5
push r4
push r3
push r2
// Scan the stack.
in r24, 0x3d; SPL
in r25, 0x3e; SPH
#if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25
rcall tinygo_scanstack
#else
call tinygo_scanstack
#endif
// Restore callee-saved registers.
pop r2
pop r3
pop r4
pop r5
pop r6
pop r7
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15
pop r16
pop r17
pop r28 // Y
pop r29 // Y

0
src/runtime/scheduler_tinygoriscv.S → src/runtime/gc_riscv.S

53
src/runtime/scheduler_avr.S

@ -187,56 +187,3 @@ tinygo_switchToScheduler:
// Return into the scheduler, as if tinygo_switchToTask was a regular call.
ret
.section .text.tinygo_scanCurrentStack
.global tinygo_scanCurrentStack
.type tinygo_scanCurrentStack, %function
tinygo_scanCurrentStack:
// Save callee-saved registers.
push r29 // Y
push r28 // Y
push r17
push r16
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push r7
push r6
push r5
push r4
push r3
push r2
// Scan the stack.
in r24, 0x3d; SPL
in r25, 0x3e; SPH
#if __AVR_ARCH__ == 2 || __AVR_ARCH__ == 25
rcall tinygo_scanstack
#else
call tinygo_scanstack
#endif
// Restore callee-saved registers.
pop r2
pop r3
pop r4
pop r5
pop r6
pop r7
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15
pop r16
pop r17
pop r28 // Y
pop r29 // Y

31
src/runtime/scheduler_cortexm.S

@ -136,34 +136,3 @@ tinygo_swapTask:
#endif
.cfi_endproc
.size tinygo_swapTask, .-tinygo_swapTask
.section .text.tinygo_scanCurrentStack
.global tinygo_scanCurrentStack
.type tinygo_scanCurrentStack, %function
tinygo_scanCurrentStack:
.cfi_startproc
// Save callee-saved registers onto the stack.
#if defined(__thumb2__)
push {r4-r11, lr}
.cfi_def_cfa_offset 9*4
#else
mov r0, r8
mov r1, r9
mov r2, r10
mov r3, r11
push {r0-r3, lr}
.cfi_def_cfa_offset 5*4
push {r4-r7}
.cfi_def_cfa_offset 4*4
#endif
// Scan the stack.
mov r0, sp
bl tinygo_scanstack
// Restore stack state and return.
add sp, #32
.cfi_def_cfa_offset 1*4
pop {pc}
.cfi_endproc
.size tinygo_scanCurrentStack, .-tinygo_scanCurrentStack

1
targets/avr.json

@ -13,6 +13,7 @@
"-Wl,--gc-sections"
],
"extra-files": [
"src/runtime/gc_avr.S",
"src/runtime/scheduler_avr.S"
]
}

1
targets/cortex-m.json

@ -25,6 +25,7 @@
],
"extra-files": [
"src/device/arm/cortexm.s",
"src/runtime/gc_arm.S",
"src/runtime/scheduler_cortexm.S"
],
"gdb": "gdb-multiarch"

2
targets/gameboy-advance.json

@ -25,7 +25,7 @@
"linkerscript": "targets/gameboy-advance.ld",
"extra-files": [
"targets/gameboy-advance.s",
"src/runtime/scheduler_gba.S"
"src/runtime/gc_arm.S"
],
"gdb": "gdb-multiarch",
"emulator": ["mgba", "-3"]

2
targets/riscv.json

@ -18,7 +18,7 @@
],
"extra-files": [
"src/device/riscv/start.S",
"src/runtime/scheduler_tinygoriscv.S",
"src/runtime/gc_riscv.S",
"src/device/riscv/handleinterrupt.S"
],
"gdb": "riscv64-unknown-elf-gdb"

Loading…
Cancel
Save