From 2d91eebbf1fc9335269207602b360ec485aaf7bb Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 17 Dec 2019 17:39:03 +0100 Subject: don't embed stage2 of bootloader as binary blob - use smart section naming --- loader_stage1.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'loader_stage1.c') diff --git a/loader_stage1.c b/loader_stage1.c index d209c15..aca439c 100644 --- a/loader_stage1.c +++ b/loader_stage1.c @@ -2,24 +2,25 @@ #include #include -char *const stage2_addr = ((void*) 0x4000); +#define STAGE2_ADDR ((volatile char*) 0x4000) -// there's one tricky thing about embedding file in executable; -// mainly, symbols are visible to c code as extern chars, but the actual +// There's one tricky thing about managing executable's own code. +// 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; + __stage2_start, + __stage2_end, + __stage2_size; +__attribute__((section(".text.stage1main"))) void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags) { - // stage2 of the bootloader is a blob embedded in executable; + // stage2 of the bootloader is part of 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]; + for (size_t i = 0; i < (size_t) &__stage2_size; i++) + STAGE2_ADDR[i] = (&__stage2_start)[i]; // jump to stage2 - ((void(*)(uint32_t, uint32_t, uint32_t))stage2_addr)(r0, r1, atags); + ((void(*)(uint32_t, uint32_t, uint32_t))STAGE2_ADDR)(r0, r1, atags); } -- cgit v1.2.3