aboutsummaryrefslogtreecommitdiff
path: root/loader_stage1.c
blob: d209c159347f46106c5deca7676583fb265c9746 (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
#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);
}