aboutsummaryrefslogtreecommitdiff
path: root/loader_stage1.c
diff options
context:
space:
mode:
authorvetch <vetch97@gmail.com>2019-10-15 15:44:41 +0200
committervetch <vetch97@gmail.com>2019-10-15 15:44:41 +0200
commite20129720adb334f46e329bfbe7090ee7188caac (patch)
tree4a8fab2da509d5e870ddbf64cf6521c110b7e0cf /loader_stage1.c
parent8de2ff74293a583fbf4cd9a87a8bf29c0c93d5a8 (diff)
parent0921cc609a1b411d2b6769a327fa11a675ac3d3a (diff)
downloadrpi-MMU-example-e20129720adb334f46e329bfbe7090ee7188caac.tar.gz
rpi-MMU-example-e20129720adb334f46e329bfbe7090ee7188caac.zip
Merge branch 'bob' into alice
Diffstat (limited to 'loader_stage1.c')
-rw-r--r--loader_stage1.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/loader_stage1.c b/loader_stage1.c
new file mode 100644
index 0000000..d209c15
--- /dev/null
+++ b/loader_stage1.c
@@ -0,0 +1,25 @@
+#include <stddef.h>
+#include <stdint.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)
+{
+ // 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);
+}