summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/amd64/boot.S72
-rw-r--r--src/arch/amd64/linker.ld25
2 files changed, 97 insertions, 0 deletions
diff --git a/src/arch/amd64/boot.S b/src/arch/amd64/boot.S
index e69de29..f7c24c4 100644
--- a/src/arch/amd64/boot.S
+++ b/src/arch/amd64/boot.S
@@ -0,0 +1,72 @@
+global start
+extern kmain
+bits 32
+
+; base, limit, access, flags
+%macro gdt_entry 4
+ db %2 & 0xff
+ db (%2 >> 8) & 0xff
+ db %1 & 0xff
+ db (%1 >> 8) & 0xff
+ db (%1 >> 16) & 0xff
+ db %3
+ db ((%2 >> 16) & 0x0f) | (%4 << 4)
+ db (%1 >> 24) & 0xff
+%endmacro
+
+section .multiboot
+align 8
+mb_start:
+; header
+dd 0xe85250d6
+dd 0
+dd mb_end - mb_start
+dd 0x100000000 - (0xe85250d6 + (mb_end - mb_start))
+; null tag
+dw 0
+dw 0
+dd 8
+;
+mb_end:
+
+section .bss
+align 16
+stack_start:
+ resb 16384
+stack_end:
+
+section .rodata
+align 16
+gdt_start:
+gdt_entry 0, 0, 0, 0
+gdt_entry 0, 0xFFFFF, 0x9A, 0xC
+gdt_entry 0, 0xFFFFF, 0x92, 0xC
+gdt_end:
+gdt_descriptor:
+ dw gdt_end - gdt_start - 1
+ dd gdt_start
+
+
+section .text
+align 8
+start:
+ cli
+ lgdt [gdt_descriptor]
+ jmp 0x08:after_lgdt
+after_lgdt:
+ mov ax, 0x10
+ mov ds, ax
+ mov ss, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov esp, stack_end
+ mov ebp, stack_end
+ sti
+ push ebx
+ call kmain
+ cli
+halt:
+ hlt
+ jmp halt
+
diff --git a/src/arch/amd64/linker.ld b/src/arch/amd64/linker.ld
new file mode 100644
index 0000000..4e796e2
--- /dev/null
+++ b/src/arch/amd64/linker.ld
@@ -0,0 +1,25 @@
+ENTRY(start)
+
+SECTIONS {
+ . = 1M;
+
+ .boot BLOCK(4K) : ALIGN(4K)
+ {
+ *(.multiboot)
+ }
+
+ .rodata BLOCK(4K) : ALIGN(4K)
+ {
+ *(.rodata)
+ }
+
+ .text BLOCK(4K) : ALIGN(4K)
+ {
+ *(.text)
+ }
+
+ .bss BLOCK(4K) : ALIGN(4K)
+ {
+ *(.bss)
+ }
+}