diff options
Diffstat (limited to 'prog/src')
-rw-r--r-- | prog/src/main.c | 11 | ||||
-rw-r--r-- | prog/src/prog.s.tst (renamed from prog/src/prog.s) | 0 | ||||
-rw-r--r-- | prog/src/startup.c | 39 | ||||
-rw-r--r-- | prog/src/startup.s | 59 |
4 files changed, 44 insertions, 65 deletions
diff --git a/prog/src/main.c b/prog/src/main.c index 082172d..a31196f 100644 --- a/prog/src/main.c +++ b/prog/src/main.c @@ -1,13 +1,12 @@ #include <stdint.h> -//volatile uint32_t *io_in = (volatile uint32_t *)0x00000000; -//volatile uint32_t *io_out = (volatile uint32_t *)0x00000004; +volatile uint32_t *io_in = (volatile uint32_t *)0x00000000; +volatile uint32_t *io_out = (volatile uint32_t *)0x00000004; + int main(void) { while (1) { - for (int i = 0; i < 32; ++i) { - *((volatile uint32_t *)0x00000004) = i; - for (int j = 0; j < 1024 * 128; ++j); - } + if (*io_in) *io_out = 0b00000; + else *io_out = 0b11111; } } diff --git a/prog/src/prog.s b/prog/src/prog.s.tst index ec227a9..ec227a9 100644 --- a/prog/src/prog.s +++ b/prog/src/prog.s.tst diff --git a/prog/src/startup.c b/prog/src/startup.c new file mode 100644 index 0000000..32aa131 --- /dev/null +++ b/prog/src/startup.c @@ -0,0 +1,39 @@ +extern unsigned int _sidata; /* Start address for the .data section in ROM */ +extern unsigned int _sdata; /* Start address for the .data section in RAM */ +extern unsigned int _edata; /* End address for the .data section in RAM */ +extern unsigned int _sbss; /* Start address for the .bss section */ +extern unsigned int _ebss; /* End address for the .bss section */ +extern unsigned int _estack; /* End address for the stack section */ + +void main(void); /* The main function declaration */ +void _start(void) __attribute__((section(".text.startup"), naked)); /* The entry point */ + +void _start(void) +{ + unsigned int *src, *dest; + + /* Copy .data section from ROM to RAM */ + src = &_sidata; /* ROM address of the .data section */ + for (dest = &_sdata; dest < &_edata;) + { + *dest++ = *src++; + } + + //while(1); + + /* Zero initialize .bss section */ + for (dest = &_sbss; dest < &_ebss;) + { + *dest++ = 0; + } + + + /* Initialize stack pointer */ + asm volatile ("la sp, _estack"); + + /* Call the main function */ + main(); + + /* If main returns, loop forever */ + while (1); +} diff --git a/prog/src/startup.s b/prog/src/startup.s deleted file mode 100644 index 963c288..0000000 --- a/prog/src/startup.s +++ /dev/null @@ -1,59 +0,0 @@ -.section .init -.globl _start -_start: - -prog: -/* - la t0, 4 - la t1, 1 - - sw t1, 0(t0) - - la t0, 0x00100000 - li t1, 1 - sw t1, 0(t0) - lw t2, 0(t0) - - - j halt - -*/ - /* 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 |