Compare commits

...

3 Commits

Author SHA1 Message Date
Quinten Kock e5cf785097 add printing pagetable location 2020-12-05 03:33:49 +01:00
Quinten Kock 95ac2d439a make linker.ld more readable 2020-12-05 03:33:33 +01:00
Quinten Kock 499e25d23d add arena allocator 2020-12-05 03:33:26 +01:00
4 changed files with 39 additions and 3 deletions

View File

@ -3,7 +3,7 @@ ENTRY(stivale2_main)
SECTIONS
{
kernel_phys_offset = 0xffffffff80000000;
. = kernel_phys_offset + 0x100000;
. = kernel_phys_offset + 1M;
.stivale2hdr ALIGN(4K) :
{

View File

@ -0,0 +1,17 @@
/* An Arena allocator is a very basic allocator that simply discards free() calls. */
#include "arena.h"
#include <hal/ops.h>
void* arena_alloc(struct arena_allocator* alloc, size_t len, size_t align) {
if(alloc->begin % align) {
alloc->begin += (align - alloc->begin % align);
}
if(alloc->length < len) {
PANIC("Attempt to allocate more memory than is available");
}
void* retval = (void*)alloc->begin;
alloc->begin += len;
alloc->length -= len;
return retval;
}

View File

@ -0,0 +1,8 @@
#include <stddef.h>
struct arena_allocator {
size_t begin;
size_t length;
};
void *arena_alloc(struct arena_allocator* alloc, size_t length, size_t align);

View File

@ -2,8 +2,10 @@
#include <stdint.h>
#include <stddef.h>
#include "../../main.h"
#include "arch/x86/stivale2-parse.h"
#include <arch/x86/stivale2-parse.h>
#include <print/print.h>
#include <main.h>
static uint8_t stack[4096] = {0};
void stivale2_main(struct stivale2_struct *info);
@ -28,6 +30,15 @@ void stivale2_main(struct stivale2_struct *info) {
parse_stivale2(info);
print_stivale2_memmap(info);
uint64_t* cr3;
__asm__ __volatile__ (
"movq %%cr3, %0\n\t"
: "=r" (cr3)
: /* no input */
: /* no clobbers */
);
printf("PAGE TABLE AT: %x\n", cr3);
char *argv[3] = {"stivale2", info->bootloader_brand, info->bootloader_version};
kmain(3, argv);
}