blob: aca439cb1bf9ab4152e62c5d7a5e97c55494bbf6 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <stddef.h>
#include <stdint.h>
#include <global.h>
#define STAGE2_ADDR ((volatile char*) 0x4000)
// 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
__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 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) &__stage2_size; i++)
STAGE2_ADDR[i] = (&__stage2_start)[i];
// jump to stage2
((void(*)(uint32_t, uint32_t, uint32_t))STAGE2_ADDR)(r0, r1, atags);
}
|