paging
This commit is contained in:
parent
513b9b3199
commit
e6bec1afcd
11 changed files with 134 additions and 76 deletions
|
@ -1,29 +1,38 @@
|
||||||
ENTRY(start)
|
ENTRY(start)
|
||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 1M;
|
|
||||||
|
. = 0x00100000;
|
||||||
|
|
||||||
kernel_start = .;
|
kernel_start = .;
|
||||||
|
|
||||||
.boot BLOCK(4K) : ALIGN(4K)
|
.multiboot.data : {
|
||||||
{
|
*(.multiboot.data)
|
||||||
*(.multiboot)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.text BLOCK(4K) : ALIGN(4K)
|
.multiboot.text : {
|
||||||
|
*(.multiboot.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
. += 0xC0000000;
|
||||||
|
|
||||||
|
.text ALIGN (4K) : AT (ADDR (.text) - 0xC0000000)
|
||||||
{
|
{
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
|
.rodata ALIGN (4K) : AT (ADDR (.rodata) - 0xC0000000)
|
||||||
.rodata BLOCK(4K) : ALIGN(4K)
|
|
||||||
{
|
{
|
||||||
*(.rodata)
|
*(.rodata)
|
||||||
}
|
}
|
||||||
|
.data ALIGN (4K) : AT (ADDR (.data) - 0xC0000000)
|
||||||
|
|
||||||
.bss BLOCK(4K) : ALIGN(4K)
|
|
||||||
{
|
{
|
||||||
|
*(.data)
|
||||||
|
}
|
||||||
|
.bss ALIGN (4K) : AT (ADDR (.bss) - 0xC0000000)
|
||||||
|
{
|
||||||
|
*(COMMON)
|
||||||
*(.bss)
|
*(.bss)
|
||||||
|
*(.bootstrap_stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel_end = .;
|
kernel_end = .;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
static struct BootInfo info;
|
static struct BootInfo info;
|
||||||
|
|
||||||
static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) {
|
static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) {
|
||||||
debugk("Found cmdline");
|
|
||||||
if (len >= CMDLINE_MAX)
|
if (len >= CMDLINE_MAX)
|
||||||
panic("multiboot2 cmd line to long\nmax is %d but was provided %d\n",
|
panic("multiboot2 cmd line to long\nmax is %d but was provided %d\n",
|
||||||
CMDLINE_MAX, len);
|
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) {
|
static void read_memorymap(struct BootTag *tag, uint32_t *data) {
|
||||||
debugk("Found memorymap");
|
|
||||||
tag->data.memory_map = (struct MemoryMap *) data;
|
tag->data.memory_map = (struct MemoryMap *) data;
|
||||||
info.tags[iD_MEMORYMAP] = *tag;
|
info.tags[iD_MEMORYMAP] = *tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_rsdp(struct BootTag *tag, char *data) {
|
static void read_rsdp(struct BootTag *tag, char *data) {
|
||||||
debugk("Found RSDP");
|
|
||||||
tag->data.rsdp = (struct RootSystemDescriptionPointer *) data;
|
tag->data.rsdp = (struct RootSystemDescriptionPointer *) data;
|
||||||
info.tags[ID_RSDP] = *tag;
|
info.tags[ID_RSDP] = *tag;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +57,6 @@ static uint32_t *read_tag(uint32_t *data) {
|
||||||
|
|
||||||
void load_boot_info(void* boot_info) {
|
void load_boot_info(void* boot_info) {
|
||||||
|
|
||||||
debugk("Reading multiboot info");
|
|
||||||
|
|
||||||
memset(&info, 0, sizeof(boot_info));
|
memset(&info, 0, sizeof(boot_info));
|
||||||
|
|
||||||
uint32_t* data = (uint32_t*) boot_info;
|
uint32_t* data = (uint32_t*) boot_info;
|
||||||
|
@ -72,7 +67,6 @@ void load_boot_info(void* boot_info) {
|
||||||
data = read_tag(data);
|
data = read_tag(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
succek("Loaded multiboot info");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_boot_tag(enum BootTagID id, struct BootTag **tag) {
|
bool get_boot_tag(enum BootTagID id, struct BootTag **tag) {
|
||||||
|
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
|
||||||
extern int sse_init (void);
|
extern uint8_t sse_init (void);
|
||||||
extern int fpu_init (void);
|
extern uint8_t fpu_init (void);
|
||||||
|
|
||||||
void init_registers (void) {
|
uint8_t init_registers (uint8_t reg) {
|
||||||
if (!sse_init()) {
|
uint8_t res = 0;
|
||||||
debugk("Loaded SIMD");
|
|
||||||
} else {
|
|
||||||
errork("SIMD not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fpu_init()) {
|
if (reg & SSE_REG)
|
||||||
debugk("Loaded FPU");
|
res |= ~sse_init() & SSE_REG;
|
||||||
} else {
|
|
||||||
errork("FPU not supported");
|
if (reg & FPU_REG)
|
||||||
}
|
res |= ~fpu_init() & FPU_REG;
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void init_registers (void);
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define SSE_REG 0x01
|
||||||
|
#define FPU_REG 0x02
|
||||||
|
|
||||||
|
uint8_t init_registers (uint8_t reg);
|
||||||
|
|
|
@ -48,8 +48,6 @@ void ps2ctrl_set_port2(void) {
|
||||||
|
|
||||||
void ps2ctrl_init(void) {
|
void ps2ctrl_init(void) {
|
||||||
|
|
||||||
debugk("Loading PS/2 Controller");
|
|
||||||
|
|
||||||
is_init = false;
|
is_init = false;
|
||||||
|
|
||||||
pic_mask(1); // keyboard
|
pic_mask(1); // keyboard
|
||||||
|
@ -61,8 +59,7 @@ void ps2ctrl_init(void) {
|
||||||
ps2ctrl_out_cmd(0xAA);
|
ps2ctrl_out_cmd(0xAA);
|
||||||
uint8_t response = ps2ctrl_in();
|
uint8_t response = ps2ctrl_in();
|
||||||
if(response != 0x55) {
|
if(response != 0x55) {
|
||||||
errork("PS/2 controller failed to initialize");
|
panic("PS/2 controller failed to initialize");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set config
|
// set config
|
||||||
|
@ -80,8 +77,7 @@ void ps2ctrl_init(void) {
|
||||||
ps2ctrl_out_cmd(0xA9);
|
ps2ctrl_out_cmd(0xA9);
|
||||||
response = ps2ctrl_in();
|
response = ps2ctrl_in();
|
||||||
if (response == 0x01) {
|
if (response == 0x01) {
|
||||||
errork("PS/2 port 2 not supported");
|
panic("PS/2 port 2 not supported");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ps2ctrl_out_cmd(0xA8);
|
ps2ctrl_out_cmd(0xA8);
|
||||||
|
@ -90,8 +86,6 @@ void ps2ctrl_init(void) {
|
||||||
|
|
||||||
pic_unmask(1);
|
pic_unmask(1);
|
||||||
pic_unmask(12);
|
pic_unmask(12);
|
||||||
|
|
||||||
succek("Loaded PS/2 Controller");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ps2ctrl_is_init(void) {
|
bool ps2ctrl_is_init(void) {
|
||||||
|
|
|
@ -59,8 +59,6 @@ static bool state_ext = false;
|
||||||
|
|
||||||
void ps2kb_init(void) {
|
void ps2kb_init(void) {
|
||||||
|
|
||||||
debugk("Loading PS/2 Keyboard");
|
|
||||||
|
|
||||||
is_init = false;
|
is_init = false;
|
||||||
pic_mask(1);
|
pic_mask(1);
|
||||||
|
|
||||||
|
@ -69,24 +67,22 @@ void ps2kb_init(void) {
|
||||||
ps2ctrl_out_data(0xFF);
|
ps2ctrl_out_data(0xFF);
|
||||||
result = ps2ctrl_in();
|
result = ps2ctrl_in();
|
||||||
if(result != 0xFA) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
result = ps2ctrl_in();
|
result = ps2ctrl_in();
|
||||||
if(result != 0xAA) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ps2ctrl_out_data(0xF4);
|
ps2ctrl_out_data(0xF4);
|
||||||
result = ps2ctrl_in();
|
result = ps2ctrl_in();
|
||||||
if(result != 0xFA) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
succek("PS/2 Keyboard has has been loaded");
|
|
||||||
|
|
||||||
pic_unmask(1);
|
pic_unmask(1);
|
||||||
is_init = true;
|
is_init = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ static uint8_t first_b, second_b, third_b;
|
||||||
|
|
||||||
void ps2mouse_init(void) {
|
void ps2mouse_init(void) {
|
||||||
|
|
||||||
debugk("Loading PS/2 Mouse");
|
|
||||||
|
|
||||||
is_init = false;
|
is_init = false;
|
||||||
pic_mask(12);
|
pic_mask(12);
|
||||||
|
|
||||||
|
@ -26,12 +24,12 @@ void ps2mouse_init(void) {
|
||||||
ps2ctrl_out_data(0xFF);
|
ps2ctrl_out_data(0xFF);
|
||||||
result = ps2ctrl_in();
|
result = ps2ctrl_in();
|
||||||
if (result != 0xFA) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
result = ps2ctrl_in();
|
result = ps2ctrl_in();
|
||||||
if (result != 0xAA) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +38,6 @@ void ps2mouse_init(void) {
|
||||||
|
|
||||||
pic_unmask(12);
|
pic_unmask(12);
|
||||||
is_init = true;
|
is_init = true;
|
||||||
|
|
||||||
succek("PS/2 Mouse has has been loaded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t packet_num = 0;
|
static uint8_t packet_num = 0;
|
||||||
|
|
|
@ -12,12 +12,18 @@
|
||||||
|
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys.h>
|
#include <sys.h>
|
||||||
|
|
||||||
static double x = 0, y = 0;
|
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();
|
term_init();
|
||||||
cursor_enable();
|
cursor_enable();
|
||||||
|
@ -28,16 +34,16 @@ void kernel_main(void* boot_info) {
|
||||||
idt_init();
|
idt_init();
|
||||||
pic_remap(PIC_REMAP_OFFSET);
|
pic_remap(PIC_REMAP_OFFSET);
|
||||||
|
|
||||||
load_boot_info(boot_info);
|
// load_boot_info(boot_info);
|
||||||
acpi_init();
|
// acpi_init();
|
||||||
|
|
||||||
memory_init();
|
// memory_init();
|
||||||
|
|
||||||
ps2ctrl_init();
|
ps2ctrl_init();
|
||||||
ps2kb_init();
|
ps2kb_init();
|
||||||
ps2mouse_init();
|
ps2mouse_init();
|
||||||
|
|
||||||
init_registers();
|
init_registers(FPU_REG | SSE_REG);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int_wait();
|
int_wait();
|
||||||
|
|
|
@ -20,7 +20,7 @@ void _panic_impl(char* msg, int line, char* file, ...) {
|
||||||
vprintk(msg, args);
|
vprintk(msg, args);
|
||||||
if (!term_newline()) putchar('\n');
|
if (!term_newline()) putchar('\n');
|
||||||
printk("\nin %s at line %d\n", file, line);
|
printk("\nin %s at line %d\n", file, line);
|
||||||
|
term_flush();
|
||||||
while(1) {
|
while(1) {
|
||||||
halt();
|
halt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
global start
|
global start
|
||||||
global heap_start
|
extern kernel_boot
|
||||||
extern kernel_main
|
extern kernel_main
|
||||||
|
extern kernel_start
|
||||||
|
extern kernel_end
|
||||||
bits 32
|
bits 32
|
||||||
|
|
||||||
; base, limit, access, flags
|
; base, limit, access, flags
|
||||||
|
@ -16,14 +18,18 @@ bits 32
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
MAGIC equ 0xe85250d6
|
MAGIC equ 0xe85250d6
|
||||||
|
FLAGS equ 0
|
||||||
LENGTH equ mb_end - mb_start
|
LENGTH equ mb_end - mb_start
|
||||||
CHECKSUM equ -(MAGIC + LENGTH)
|
CHECKSUM equ -(MAGIC + LENGTH)
|
||||||
|
|
||||||
section .multiboot
|
VGABUF equ 0x000B8000
|
||||||
|
KRNMAP equ 0xC0000000
|
||||||
|
|
||||||
|
section .multiboot.data
|
||||||
align 8
|
align 8
|
||||||
mb_start:
|
mb_start:
|
||||||
dd MAGIC
|
dd MAGIC
|
||||||
dd 0
|
dd FLAGS
|
||||||
dd LENGTH
|
dd LENGTH
|
||||||
dd CHECKSUM
|
dd CHECKSUM
|
||||||
dw 0
|
dw 0
|
||||||
|
@ -31,12 +37,6 @@ dw 0
|
||||||
dd 8
|
dd 8
|
||||||
mb_end:
|
mb_end:
|
||||||
|
|
||||||
section .bss
|
|
||||||
align 16
|
|
||||||
stack_end:
|
|
||||||
resb 16384
|
|
||||||
stack_top:
|
|
||||||
|
|
||||||
section .rodata
|
section .rodata
|
||||||
align 16
|
align 16
|
||||||
gdt_start:
|
gdt_start:
|
||||||
|
@ -48,16 +48,77 @@ gdt_descriptor:
|
||||||
dw gdt_end - gdt_start - 1
|
dw gdt_end - gdt_start - 1
|
||||||
dd gdt_start
|
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
|
align 8
|
||||||
start:
|
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
|
cli
|
||||||
lgdt [gdt_descriptor]
|
lgdt [gdt_descriptor]
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
or al, 1
|
or al, 1
|
||||||
mov cr0, eax
|
mov cr0, eax
|
||||||
jmp 0x08:after_lgdt
|
jmp 0x08:load_kernel
|
||||||
after_lgdt:
|
|
||||||
|
load_kernel:
|
||||||
|
|
||||||
|
mov dword [page_directory], 0
|
||||||
|
mov ecx, cr3
|
||||||
|
mov cr3, ecx
|
||||||
|
|
||||||
mov ax, 0x10
|
mov ax, 0x10
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
|
@ -67,7 +128,6 @@ after_lgdt:
|
||||||
mov esp, stack_end
|
mov esp, stack_end
|
||||||
mov ebp, stack_end
|
mov ebp, stack_end
|
||||||
sti
|
sti
|
||||||
push ebx
|
|
||||||
call kernel_main
|
call kernel_main
|
||||||
cli
|
cli
|
||||||
halt:
|
halt:
|
||||||
|
|
|
@ -28,7 +28,7 @@ static void term_clear_line(int y) {
|
||||||
void term_init (void) {
|
void term_init (void) {
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
front = (uint16_t*) 0xb8000;
|
front = (uint16_t*) 0xC03FF000;
|
||||||
term_setfg(VGA_WHITE);
|
term_setfg(VGA_WHITE);
|
||||||
term_setbg(VGA_BLACK);
|
term_setbg(VGA_BLACK);
|
||||||
term_clear();
|
term_clear();
|
||||||
|
|
Loading…
Reference in a new issue