diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-15 08:27:12 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-15 08:27:12 +0200 |
commit | 9e76b9001c37ab2da2e99c922406b991bd0e53af (patch) | |
tree | 686aa90639b28c92013e6158e01d5010973b0f03 /prog/src/startup.s | |
parent | d107f7e40f02a7374b8685ba310500a6c38d43b1 (diff) | |
download | riscv_cpu-9e76b9001c37ab2da2e99c922406b991bd0e53af.tar.gz riscv_cpu-9e76b9001c37ab2da2e99c922406b991bd0e53af.zip |
running c program
Diffstat (limited to 'prog/src/startup.s')
-rw-r--r-- | prog/src/startup.s | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/prog/src/startup.s b/prog/src/startup.s new file mode 100644 index 0000000..7adfb5e --- /dev/null +++ b/prog/src/startup.s @@ -0,0 +1,42 @@ +.section .init +.globl _start +_start: + /* Set up stack pointer */ + la sp, _stack_end + + /* Initialize .data section (copy from LMA to VMA) */ + la t0, _sdata /* VMA start of .data */ + la t1, _edata /* VMA end of .data */ + la t2, _etext /* LMA start of .data in flash */ +copy_data: + beq t0, t1, clear_bss + lw t3, 0(t2) + sw t3, 0(t0) + addi t0, t0, 4 + addi t2, t2, 4 + j copy_data + +clear_bss: + /* Clear .bss section */ + la t0, _sbss /* VMA start of .bss */ + la t1, _ebss /* VMA end of .bss */ +clear_loop: + beq t0, t1, init_libc + sw x0, 0(t0) + addi t0, t0, 4 + j clear_loop + +init_libc: + /* Call libc initialization functions */ + /* call _init */ + + /* Call main function */ + call main + +finalize_libc: + /* Call libc finalization functions */ + /* call _fini */ + +halt: + /* Infinite loop after main returns */ + j halt |