diff options
author | Wojtek Kosior <kwojtus@protonmail.com> | 2019-10-11 11:59:59 +0200 |
---|---|---|
committer | Wojtek Kosior <kwojtus@protonmail.com> | 2019-10-11 11:59:59 +0200 |
commit | 23e6ba8ef9f9967e0c15c6245fd92cdd5f60fc55 (patch) | |
tree | e7c51792a025b1d9a71eba5aa0a85128515b43d4 /loader_stage1.c | |
parent | 50814e0cbd58590a7e367b604afa8c06271a273a (diff) | |
download | rpi-MMU-example-23e6ba8ef9f9967e0c15c6245fd92cdd5f60fc55.tar.gz rpi-MMU-example-23e6ba8ef9f9967e0c15c6245fd92cdd5f60fc55.zip |
add initial bootloader work
Diffstat (limited to 'loader_stage1.c')
-rw-r--r-- | loader_stage1.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/loader_stage1.c b/loader_stage1.c new file mode 100644 index 0000000..9492747 --- /dev/null +++ b/loader_stage1.c @@ -0,0 +1,30 @@ +#include <stddef.h> +#include <stdint.h> +#include <uart.h> +#include <global.h> + +char *const stage2_addr = ((void*) 0x4000); + +// there's one tricky thing about embedding file in executable; +// mainly, symbols are visible to c code as extern chars, but the actual +// values are their adresses... see the code below +extern char + _binary_loader_stage2_img_start, + _binary_loader_stage2_img_end, + _binary_loader_stage2_img_size; + +void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) +{ + // uart_init() call to be moved to stage2... + uart_init(); + uart_puts("Hello, bootloader World!\r\n"); + + // stage2 of the bootloader is a blob embedded in executable; + // copy it over to it's destination place + // TODO implement a memcpy() somewhere and use it instead of loops + for (size_t i = 0; i < (size_t) &_binary_loader_stage2_img_size; i++) + stage2_addr[i] = (&_binary_loader_stage2_img_start)[i]; + + // jump to stage2 + ((void(*)(uint32_t, uint32_t, uint32_t))stage2_addr)(r0, r1, atags); +} |