Xyris  0.5
stivale2.c File Reference
#include <Arch/i686/Bootloader/EarlyPanic.hpp>
#include <Arch/i686/Bootloader/Loader.hpp>
#include <Arch/i686/Memory.i686.hpp>
#include <Arch/i686/regs.hpp>
#include <Support/sections.hpp>
#include <stdint.h>
#include <stivale/stivale2.h>
+ Include dependency graph for stivale2.c:

Go to the source code of this file.

Macros

#define _STIVALE2_SPLIT_64
 
#define KERNEL_STACK_SZ   4 * ARCH_PAGE_SIZE
 
#define STIVALE2_MAGIC   0x73747632
 

Functions

 __attribute__ ((section(".early_bss"), aligned(4096)))
 
 __attribute__ ((section(".early_text")))
 
 __attribute__ ((section(".early_text"), noreturn))
 
 __attribute__ ((section(".early_data"), used)) const
 
 __attribute__ ((section(".stivale2hdr"), used)) const
 

Macro Definition Documentation

◆ _STIVALE2_SPLIT_64

#define _STIVALE2_SPLIT_64

Definition at line 19 of file stivale2.c.

◆ KERNEL_STACK_SZ

#define KERNEL_STACK_SZ   4 * ARCH_PAGE_SIZE

Definition at line 22 of file stivale2.c.

◆ STIVALE2_MAGIC

#define STIVALE2_MAGIC   0x73747632

Definition at line 23 of file stivale2.c.

Function Documentation

◆ __attribute__() [1/5]

__attribute__ ( (section(".early_bss"), aligned(4096))  )

Scan the stivale2 tags to find the reclaimable bootloader memory map tag that starts at the stivale2 tag base address. Return the length found. We'll memory map the entire area.

Definition at line 30 of file stivale2.c.

79 {
80  while (tag) {
81  switch (tag->identifier) {
82  case STIVALE2_STRUCT_TAG_MEMMAP_ID:
83  {
84  struct stivale2_struct_tag_memmap* memmap = (struct stivale2_struct_tag_memmap*)tag;
85  for (size_t i = 0; i < memmap->entries; i++) {
86  switch (memmap->memmap[i].type)
87  {
88  case STIVALE2_MMAP_BOOTLOADER_RECLAIMABLE:
89  if (((uint32_t)memmap->memmap[i].base) == (uint32_t)tag) {
90  return (uint32_t)memmap->memmap[i].length;
91  }
92  break;
93 
94  default:
95  break;
96  }
97  }
98  }
99  default:
100  break;
101  }
102  tag = (struct stivale2_tag*)(uint32_t)tag->next;
103  }
104  // If we get here, there's a problem so we will panic and never return
105  EarlyPanic("Error: Cannot detect bootloader info length!");
106 }

◆ __attribute__() [2/5]

__attribute__ ( (section(".early_data"), used)  ) const

Definition at line 293 of file stivale2.c.

294  {
295  .tag = {
296  .identifier = STIVALE2_HEADER_TAG_FRAMEBUFFER_ID,
297  .next = 0,
298  },
299  .framebuffer_width = 0,
300  .framebuffer_height = 0,
301  .framebuffer_bpp = 0,
302 };

◆ __attribute__() [3/5]

__attribute__ ( (section(".early_text"))  )

Finalize stage1 by loading the finalized page directory and enabling paging.

Stivale2 protocol kernel stage 1 entry. Stage 1 is responsible for providing an entry point for the bootloader in C, performing any necessary bootstrappign and then calling into the C++ stage 2.

identity map from 0x00000000 -> LOWMEM_END

Map kernel memory into the higher half of memory See linker.ld for details on where the kernel should be mapped.

Map bootloader information into the higher half of memory so that the kernel can access it and parse it.

Definition at line 113 of file stivale2.c.

115 {
116  setPageDirectory((uintptr_t)&pageDirectory);
117 
118  struct CR0 cr0 = readCR0();
119  cr0.pagingEnable = 1;
120  writeCR0(cr0);
121 }

◆ __attribute__() [4/5]

__attribute__ ( (section(".early_text"), noreturn)  )

Prepare a higher-half stack for kernel usage.

Definition at line 127 of file stivale2.c.

129 {
130  // zero the kernel BSS (higher half stack)
131  for (size_t i = 0; i < (size_t)&_BSS_SIZE; i++) {
132  ((uint8_t*)&_BSS_START)[i] = 0;
133  }
134 
135  // adjust the stack pointer to use the higher half, kernel stack
136  asm volatile (
137  "movl %0, %%esp\n" // set the stack pointer
138  "xor %%ebp, %%ebp\n" // clear the base pointer
139  "pushl %1\n" // push argument 2 (magic)
140  "pushl %2\n" // push argument 1 (info ptr)
141  "pushl $0\n" // push a null return address
142  "jmp stage2Entry\n" // jump to stage 2
143  : // no output
144  : "i" ((stage2Stack + sizeof(stage2Stack)))
145  , "i" (STIVALE2_MAGIC)
146  , "rm" (stivale2Info)
147  );
148 
149  // it's impossible to return back to this function
150  __builtin_unreachable();
151 }

◆ __attribute__() [5/5]

__attribute__ ( (section(".stivale2hdr"), used)  ) const

Definition at line 304 of file stivale2.c.

305  {
306  .entry_point = (uint32_t)stage1Entry,
307  .stack = (uint32_t)stage1Stack + sizeof(stage1Stack),
308  .flags = 0,
309  .tags = (uint32_t)&framebuffer_hdr_tag,
310 };
STIVALE2_MAGIC
#define STIVALE2_MAGIC
Definition: stivale2.c:23
CR0::pagingEnable
uint32_t pagingEnable
Definition: regs.hpp:45
_BSS_START
size_t _BSS_START
_BSS_SIZE
size_t _BSS_SIZE
CR0
Definition: regs.hpp:30