From 9e76b9001c37ab2da2e99c922406b991bd0e53af Mon Sep 17 00:00:00 2001 From: Flavian Kaufmann Date: Wed, 15 May 2024 08:27:12 +0200 Subject: running c program --- prog/src/startup.s | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 prog/src/startup.s (limited to 'prog/src/startup.s') 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 -- cgit v1.2.3