Merge branch 'master' of ssh://git.dehosting.club:3022/quintenk/kornos

This commit is contained in:
Quinten Kock 2020-12-07 21:31:08 +01:00
commit 2a0b5ed86e
11 changed files with 53 additions and 8 deletions

2
.gdbinit Normal file
View File

@ -0,0 +1,2 @@
file kernel/bin/kernel-x86_64
target remote :1234

View File

@ -17,7 +17,6 @@ run: $(KERNEL_HDD)
-drive file=$(KERNEL_HDD),format=raw \
-smp 2 \
-enable-kvm \
-debugcon stdio \
$(QEMUFLAGS)
bochs: $(KERNEL_HDD) ext/bochsrc

View File

@ -8,7 +8,7 @@ LDSCRIPT = make/$(ARCH)/linker.ld
-include make/$(ARCH)/make.config
CFLAGS ?= -O2
CFLAGS ?= -Og -g
CFLAGS := $(CFLAGS) $(ARCH_CFLAGS) \
-Wall -Wextra -pedantic -Wno-language-extension-token -std=gnu11 -I../ext -Isrc -fPIE
LDFLAGS := $(LDFLAGS) -T $(LDSCRIPT)

View File

@ -14,4 +14,4 @@ void* arena_alloc(struct arena_allocator* alloc, size_t len, size_t align) {
alloc->begin += len;
alloc->length -= len;
return retval;
}
}

View File

@ -5,4 +5,4 @@ struct arena_allocator {
size_t length;
};
void *arena_alloc(struct arena_allocator* alloc, size_t length, size_t align);
void *arena_alloc(struct arena_allocator* alloc, size_t length, size_t align);

View File

@ -1,4 +1,9 @@
#include <print/print.h>
void halt_catch_fire() {
asm volatile ("cli");
while(1) asm volatile ("hlt");
while(1) {
asm volatile ("hlt");
puts("INTERRUPTED!");
};
}

View File

@ -7,6 +7,8 @@
#include <main.h>
#include "gdt.h"
static uint8_t stack[4096] = {0};
void stivale2_main(struct stivale2_struct *info);
@ -28,7 +30,7 @@ struct stivale2_header header2 = {
void stivale2_main(struct stivale2_struct *info) {
parse_stivale2(info);
print_stivale2_memmap(info);
// print_stivale2_memmap(info);
uint64_t* cr3;
__asm__ __volatile__ (
@ -39,6 +41,14 @@ void stivale2_main(struct stivale2_struct *info) {
);
printf("PAGE TABLE AT: %x\n", cr3);
struct gdt_ptr pGDT;
__asm__ __volatile__("sgdt %0" : : "m"(pGDT) : "memory");
printf("GDT: %x (%d)\n", pGDT.base, pGDT.limit);
for(int i = 0; i < (pGDT.limit+1)/8; i++) {
uint64_t *gdt_ent = pGDT.base + 8*i;
printf("GDTent(%d at %x): %x\n", i, gdt_ent, *gdt_ent);
}
char *argv[3] = {"stivale2", info->bootloader_brand, info->bootloader_version};
kmain(3, argv);
}

View File

@ -0,0 +1,9 @@
#include <stdint.h>
struct gdt_ptr
{
uint16_t limit;
uint64_t base;
} __attribute__((packed));
void loadgdt();

View File

@ -0,0 +1,16 @@
section .rodata
gdt64:
dq 0
.code: equ $-gdt64
dq (1<<44) | (1<<47) | (1<<41) | (1<<43) | (1<<53)
.data: equ $ - gdt64
dq (1<<44) | (1<<47) | (1<<41)
.pointer:
dw .pointer - gdt64 - 1
dq gdt64
section .text
global loadgdt
loadgdt:
lgdt [gdt64.pointer]

View File

@ -11,7 +11,7 @@ void kmain() {
printf("Bootloader type: %s (%s %s)\n", boot_info.boot_protocol, boot_info.bootloader_name, boot_info.bootloader_ver);
printf("System time: %d\n", boot_info.epoch);
printf("Usable memory: %h (at %x)\n", boot_info.usable.len, boot_info.usable.start);
printf("Cmdline: %s", boot_info.cmdline);
printf("Cmdline: %s\n", boot_info.cmdline);
vga_setcolor(VGA_DARK_GRAY);
vga_write_elsewhere("(c) Quinten Kock 2020 (MIT License)", 24, 0);

View File

@ -32,8 +32,12 @@ static void printhex(size_t num) {
num /= 16;
}
i++;
puts("0x");
for(int j = i; j >= 0; j--) {
putchar('0');
}
i++;
puts(&buf[i]);
}