This commit is contained in:
Tyler Murphy 2023-07-17 00:09:26 -04:00
parent 513b9b3199
commit e6bec1afcd
11 changed files with 134 additions and 76 deletions

View file

@ -1,29 +1,38 @@
ENTRY(start)
SECTIONS {
. = 1M;
. = 0x00100000;
kernel_start = .;
.boot BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
.multiboot.data : {
*(.multiboot.data)
}
.text BLOCK(4K) : ALIGN(4K)
.multiboot.text : {
*(.multiboot.text)
}
. += 0xC0000000;
.text ALIGN (4K) : AT (ADDR (.text) - 0xC0000000)
{
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
.rodata ALIGN (4K) : AT (ADDR (.rodata) - 0xC0000000)
{
*(.rodata)
}
.bss BLOCK(4K) : ALIGN(4K)
.data ALIGN (4K) : AT (ADDR (.data) - 0xC0000000)
{
*(.data)
}
.bss ALIGN (4K) : AT (ADDR (.bss) - 0xC0000000)
{
*(COMMON)
*(.bss)
*(.bootstrap_stack)
}
kernel_end = .;

View file

@ -9,7 +9,6 @@
static struct BootInfo info;
static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) {
debugk("Found cmdline");
if (len >= CMDLINE_MAX)
panic("multiboot2 cmd line to long\nmax is %d but was provided %d\n",
CMDLINE_MAX, len);
@ -18,13 +17,11 @@ static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) {
}
static void read_memorymap(struct BootTag *tag, uint32_t *data) {
debugk("Found memorymap");
tag->data.memory_map = (struct MemoryMap *) data;
info.tags[iD_MEMORYMAP] = *tag;
}
static void read_rsdp(struct BootTag *tag, char *data) {
debugk("Found RSDP");
tag->data.rsdp = (struct RootSystemDescriptionPointer *) data;
info.tags[ID_RSDP] = *tag;
}
@ -60,8 +57,6 @@ static uint32_t *read_tag(uint32_t *data) {
void load_boot_info(void* boot_info) {
debugk("Reading multiboot info");
memset(&info, 0, sizeof(boot_info));
uint32_t* data = (uint32_t*) boot_info;
@ -72,7 +67,6 @@ void load_boot_info(void* boot_info) {
data = read_tag(data);
}
succek("Loaded multiboot info");
}
bool get_boot_tag(enum BootTagID id, struct BootTag **tag) {

View file

@ -2,19 +2,17 @@
#include "print.h"
extern int sse_init (void);
extern int fpu_init (void);
extern uint8_t sse_init (void);
extern uint8_t fpu_init (void);
void init_registers (void) {
if (!sse_init()) {
debugk("Loaded SIMD");
} else {
errork("SIMD not supported");
}
uint8_t init_registers (uint8_t reg) {
uint8_t res = 0;
if (!fpu_init()) {
debugk("Loaded FPU");
} else {
errork("FPU not supported");
}
if (reg & SSE_REG)
res |= ~sse_init() & SSE_REG;
if (reg & FPU_REG)
res |= ~fpu_init() & FPU_REG;
return res;
}

View file

@ -1,3 +1,8 @@
#pragma once
void init_registers (void);
#include <stdint.h>
#define SSE_REG 0x01
#define FPU_REG 0x02
uint8_t init_registers (uint8_t reg);

View file

@ -48,8 +48,6 @@ void ps2ctrl_set_port2(void) {
void ps2ctrl_init(void) {
debugk("Loading PS/2 Controller");
is_init = false;
pic_mask(1); // keyboard
@ -61,8 +59,7 @@ void ps2ctrl_init(void) {
ps2ctrl_out_cmd(0xAA);
uint8_t response = ps2ctrl_in();
if(response != 0x55) {
errork("PS/2 controller failed to initialize");
return;
panic("PS/2 controller failed to initialize");
}
// set config
@ -80,8 +77,7 @@ void ps2ctrl_init(void) {
ps2ctrl_out_cmd(0xA9);
response = ps2ctrl_in();
if (response == 0x01) {
errork("PS/2 port 2 not supported");
return;
panic("PS/2 port 2 not supported");
}
ps2ctrl_out_cmd(0xA8);
@ -90,8 +86,6 @@ void ps2ctrl_init(void) {
pic_unmask(1);
pic_unmask(12);
succek("Loaded PS/2 Controller");
}
bool ps2ctrl_is_init(void) {

View file

@ -59,8 +59,6 @@ static bool state_ext = false;
void ps2kb_init(void) {
debugk("Loading PS/2 Keyboard");
is_init = false;
pic_mask(1);
@ -69,24 +67,22 @@ void ps2kb_init(void) {
ps2ctrl_out_data(0xFF);
result = ps2ctrl_in();
if(result != 0xFA) {
errork("Failed to reset PS/2 keyboard: expected 0xFA, got 0x%X\n", result);
panic("Failed to reset PS/2 keyboard: expected 0xFA, got 0x%X\n", result);
return;
}
result = ps2ctrl_in();
if(result != 0xAA) {
errork("Failed to reset PS/2 keyboard: expected 0xAA, got 0x%X\n", result);
panic("Failed to reset PS/2 keyboard: expected 0xAA, got 0x%X\n", result);
return;
}
ps2ctrl_out_data(0xF4);
result = ps2ctrl_in();
if(result != 0xFA) {
errork("Failed to enable PS/2 keyboard: expected 0xFA, got 0x%X\n", result);
panic("Failed to enable PS/2 keyboard: expected 0xFA, got 0x%X\n", result);
return;
}
succek("PS/2 Keyboard has has been loaded");
pic_unmask(1);
is_init = true;
}

View file

@ -15,8 +15,6 @@ static uint8_t first_b, second_b, third_b;
void ps2mouse_init(void) {
debugk("Loading PS/2 Mouse");
is_init = false;
pic_mask(12);
@ -26,12 +24,12 @@ void ps2mouse_init(void) {
ps2ctrl_out_data(0xFF);
result = ps2ctrl_in();
if (result != 0xFA) {
errork("Failed to reset PS/2 mouse: expected 0xFA, got 0x%X", result);
panic("Failed to reset PS/2 mouse: expected 0xFA, got 0x%X", result);
return;
}
result = ps2ctrl_in();
if (result != 0xAA) {
errork("Failed to reset PS/2 mouse: expected 0xAA, got 0x%X", result);
panic("Failed to reset PS/2 mouse: expected 0xAA, got 0x%X", result);
return;
}
@ -40,8 +38,6 @@ void ps2mouse_init(void) {
pic_unmask(12);
is_init = true;
succek("PS/2 Mouse has has been loaded");
}
static uint8_t packet_num = 0;

View file

@ -12,12 +12,18 @@
#include <print.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys.h>
static double x = 0, y = 0;
void kernel_main(void* boot_info) {
void kernel_boot(void *boot_info) {
(void)boot_info;
}
void kernel_main(void) {
term_init();
cursor_enable();
@ -28,16 +34,16 @@ void kernel_main(void* boot_info) {
idt_init();
pic_remap(PIC_REMAP_OFFSET);
load_boot_info(boot_info);
acpi_init();
// load_boot_info(boot_info);
// acpi_init();
memory_init();
// memory_init();
ps2ctrl_init();
ps2kb_init();
ps2mouse_init();
init_registers();
init_registers(FPU_REG | SSE_REG);
while(1) {
int_wait();

View file

@ -20,7 +20,7 @@ void _panic_impl(char* msg, int line, char* file, ...) {
vprintk(msg, args);
if (!term_newline()) putchar('\n');
printk("\nin %s at line %d\n", file, line);
term_flush();
while(1) {
halt();
}

View file

@ -1,6 +1,8 @@
global start
global heap_start
extern kernel_boot
extern kernel_main
extern kernel_start
extern kernel_end
bits 32
; base, limit, access, flags
@ -16,14 +18,18 @@ bits 32
%endmacro
MAGIC equ 0xe85250d6
FLAGS equ 0
LENGTH equ mb_end - mb_start
CHECKSUM equ -(MAGIC + LENGTH)
section .multiboot
VGABUF equ 0x000B8000
KRNMAP equ 0xC0000000
section .multiboot.data
align 8
mb_start:
dd MAGIC
dd 0
dd FLAGS
dd LENGTH
dd CHECKSUM
dw 0
@ -31,12 +37,6 @@ dw 0
dd 8
mb_end:
section .bss
align 16
stack_end:
resb 16384
stack_top:
section .rodata
align 16
gdt_start:
@ -48,16 +48,77 @@ gdt_descriptor:
dw gdt_end - gdt_start - 1
dd gdt_start
section .text
section .bootstrap_stack
align 16
stack_start:
resb 16384 ; 16 KiB
stack_end:
section .bss
align 4096
page_directory:
resb 4096
page_table1:
resb 4096
section .multiboot.text
align 8
start:
; push ebx
; call kernel_boot
; pop eax
mov edi, page_table1 - KRNMAP
mov esi, 0
mov ecx, 1023
paging_cmp:
cmp esi, kernel_start
jl paging_add
cmp esi, kernel_end - KRNMAP
jge paging_map
mov edx, esi
or edx, 0x003
mov [edi], edx
paging_add:
add esi, 4096
add edi, 4
loop paging_cmp
paging_map:
mov dword [page_table1 - KRNMAP + 1023 * 4], VGABUF | 0x003
mov dword [page_directory - KRNMAP + 0], page_table1 - KRNMAP + 0x003
mov dword [page_directory - KRNMAP + 768 * 4], page_table1 - KRNMAP + 0x003
mov ecx, page_directory - KRNMAP
mov cr3, ecx
mov ecx, cr0
or ecx, 0x80010000
mov cr0, ecx
lea ecx, load_gdt
jmp near ecx
section .text
align 8
load_gdt:
cli
lgdt [gdt_descriptor]
mov eax, cr0
or al, 1
mov cr0, eax
jmp 0x08:after_lgdt
after_lgdt:
jmp 0x08:load_kernel
load_kernel:
mov dword [page_directory], 0
mov ecx, cr3
mov cr3, ecx
mov ax, 0x10
mov ds, ax
mov ss, ax
@ -67,7 +128,6 @@ after_lgdt:
mov esp, stack_end
mov ebp, stack_end
sti
push ebx
call kernel_main
cli
halt:

View file

@ -28,7 +28,7 @@ static void term_clear_line(int y) {
void term_init (void) {
x = 0;
y = 0;
front = (uint16_t*) 0xb8000;
front = (uint16_t*) 0xC03FF000;
term_setfg(VGA_WHITE);
term_setbg(VGA_BLACK);
term_clear();