...
This commit is contained in:
14
makefile
14
makefile
@@ -1,16 +1,16 @@
|
|||||||
CC = i686-elf-gcc
|
CC = x86_64-elf-gcc
|
||||||
LD = i686-elf-ld
|
LD = x86_64-elf-ld
|
||||||
AS = nasm
|
AS = nasm
|
||||||
|
|
||||||
# Modify these settings here for defines and debug info
|
# Modify these settings here for defines and debug info
|
||||||
CFLAGS = -g -D DEBUG
|
CFLAGS =
|
||||||
LDFLAGS = -g
|
LDFLAGS =
|
||||||
ASFLAGS = -g -F dwarf
|
ASFLAGS =
|
||||||
|
|
||||||
# Do not modify
|
# Do not modify
|
||||||
CFLAGS += -m32 -ffreestanding -fno-stack-protector -nostdlib -nostdinc -Wall -Wextra -std=c23 -Isrc/shared
|
CFLAGS += -m64 -ffreestanding -fno-stack-protector -nostdlib -nostdinc -Wall -Wextra -std=c23 -Isrc/shared
|
||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
ASFLAGS += -f elf32
|
ASFLAGS += -f elf64
|
||||||
|
|
||||||
SRC_C := $(shell find src -name '*.c')
|
SRC_C := $(shell find src -name '*.c')
|
||||||
SRC_ASM := $(shell find src -name '*.asm')
|
SRC_ASM := $(shell find src -name '*.asm')
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#include "console.h"
|
||||||
|
#include "multiboot2.h"
|
||||||
|
|
||||||
#include <def.h>
|
#include <def.h>
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "multiboot2.h"
|
#include "multiboot2.h"
|
||||||
@@ -58,3 +61,7 @@ static void find_memory_regions(uptr multiboot_info) {
|
|||||||
entry_ptr += tag->entry_size;
|
entry_ptr += tag->entry_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kmain(uptr multiboot_info) {
|
||||||
|
find_memory_regions(multiboot_info);
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
global _start
|
global _start
|
||||||
|
extern kernel_start
|
||||||
|
extern kernel_end
|
||||||
|
extern kmain
|
||||||
|
|
||||||
%define MAGIC 0xe85250d6
|
%define MAGIC 0xe85250d6
|
||||||
%define ARCH 0x0
|
%define ARCH 0x0
|
||||||
@@ -20,10 +23,42 @@ header:
|
|||||||
|
|
||||||
section .data
|
section .data
|
||||||
align 8
|
align 8
|
||||||
multiboot_info: dd 0
|
multiboot_info: dq 0
|
||||||
|
|
||||||
|
%define PRESENT 1 << 7
|
||||||
|
%define NOT_SYS 1 << 4
|
||||||
|
%define EXEC 1 << 3
|
||||||
|
%define DC 1 << 2
|
||||||
|
%define RW 1 << 1
|
||||||
|
%define ACCESSED 1 << 0
|
||||||
|
|
||||||
|
%define GRAN_4K 1 << 7
|
||||||
|
%define SZ_32 1 << 6
|
||||||
|
%define LONG_MODE 1 << 5
|
||||||
|
|
||||||
|
gdt:
|
||||||
|
.null: equ $ - gdt
|
||||||
|
dq 0
|
||||||
|
.code: equ $ - gdt
|
||||||
|
.code.limit_lo: dw 0xffff
|
||||||
|
.code.base_lo: dw 0
|
||||||
|
.code.base_mid: db 0
|
||||||
|
.code.access: db PRESENT | NOT_SYS | EXEC | RW
|
||||||
|
.code.flags: db GRAN_4K | LONG_MODE | 0xF
|
||||||
|
.code.base_hi: db 0
|
||||||
|
.data: equ $ - gdt
|
||||||
|
.data.limit_lo: dw 0xffff
|
||||||
|
.data.base_lo: dw 0
|
||||||
|
.data.base_mid: db 0
|
||||||
|
.data.access: db PRESENT | NOT_SYS | RW
|
||||||
|
.data.Flags: db GRAN_4K | SZ_32 | 0xF
|
||||||
|
.data.base_hi: db 0
|
||||||
|
.pointer:
|
||||||
|
dw $ - gdt - 1
|
||||||
|
dq gdt
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
align 4096
|
align 16
|
||||||
stack:
|
stack:
|
||||||
.bottom:
|
.bottom:
|
||||||
resb 1024 * 16
|
resb 1024 * 16
|
||||||
@@ -36,9 +71,8 @@ pdt: resb 4096
|
|||||||
pt: resb 4096
|
pt: resb 4096
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
|
bits 32
|
||||||
_start:
|
_start:
|
||||||
mov esp, stack.top
|
|
||||||
|
|
||||||
%define BOOTLOADER_MAGIC 0x36d76289
|
%define BOOTLOADER_MAGIC 0x36d76289
|
||||||
|
|
||||||
; Make sure we booted with multiboot 2
|
; Make sure we booted with multiboot 2
|
||||||
@@ -75,10 +109,17 @@ _start:
|
|||||||
%define PAGE_SIZE 0x1000
|
%define PAGE_SIZE 0x1000
|
||||||
%define START_ADDRESS 0x0
|
%define START_ADDRESS 0x0
|
||||||
|
|
||||||
; Identity map first 2mb of memory
|
; Identity map kernel pages
|
||||||
mov edi, pt
|
mov edi, pt
|
||||||
mov ebx, START_ADDRESS | PT_PRESENT | PT_READABLE
|
mov ebx, kernel_start
|
||||||
mov ecx, ENTRIES_PER_PT
|
and ebx, 0xfffff000
|
||||||
|
or ebx, PT_PRESENT | PT_READABLE
|
||||||
|
|
||||||
|
mov eax, kernel_end
|
||||||
|
sub eax, kernel_start
|
||||||
|
add eax, PAGE_SIZE-1
|
||||||
|
shr eax, 12
|
||||||
|
mov ecx, eax
|
||||||
|
|
||||||
.set_pt_entry:
|
.set_pt_entry:
|
||||||
mov [edi], ebx
|
mov [edi], ebx
|
||||||
@@ -108,6 +149,28 @@ _start:
|
|||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
or eax, CR0_PG_ENABLE
|
or eax, CR0_PG_ENABLE
|
||||||
mov cr0, eax
|
mov cr0, eax
|
||||||
|
|
||||||
|
; Load gdt
|
||||||
|
lgdt [gdt.pointer]
|
||||||
|
jmp gdt.code:start64
|
||||||
|
.halt:
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
jmp .halt
|
||||||
|
|
||||||
|
section .text
|
||||||
|
bits 64
|
||||||
|
start64:
|
||||||
|
mov ax, gdt.data
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax
|
||||||
|
mov ss, ax
|
||||||
|
|
||||||
|
mov rsp, stack.top
|
||||||
|
mov rdi, [multiboot_info]
|
||||||
|
call kmain
|
||||||
.halt:
|
.halt:
|
||||||
cli
|
cli
|
||||||
hlt
|
hlt
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include <def.h>
|
|
||||||
#include "console.h"
|
|
||||||
#include "multiboot2.h"
|
|
||||||
#include "panic.h"
|
|
||||||
|
|
||||||
void c_start() {
|
|
||||||
console_clear();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user