summaryrefslogtreecommitdiff
path: root/src/boot.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot.s')
-rw-r--r--src/boot.s80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/boot.s b/src/boot.s
new file mode 100644
index 0000000..71017ff
--- /dev/null
+++ b/src/boot.s
@@ -0,0 +1,80 @@
+/* Parameters for the multiboot header */
+.set ALIGN, 1<<0
+.set MEMINFO, 1<<1
+.set FLAGS, ALIGN | MEMINFO
+.set MAGIC, 0x1BADB002
+.set CHECKSUM, -(MAGIC + FLAGS)
+
+.section .multiboot
+.align 4
+.long MAGIC
+.long FLAGS
+.long CHECKSUM
+
+
+/* Allocate room for stack */
+.section bss
+.align 16
+stack_bottom:
+.skip 16384 /* 16 KiB */
+stack_top:
+
+.section .data
+
+.intel_syntax noprefix
+gdt:
+ null_gdt: /* null descriptor */
+ .quad 0x00
+
+ code_gdt:
+ .word 0xFFFF /* limit */
+ .word 0x0000 /* base */
+ .byte 0x00 /* base */
+ .byte 0x9A /* type flag (access) */
+ .byte 0b11001111 /* limit */
+ .byte 0x00 /* base */
+
+ data_gdt:
+ .word 0xFFFF /* limit */
+ .word 0x0000 /* base */
+ .byte 0x00 /* base */
+ .byte 0x92 /* type flag (access) */
+ .byte 0b11001111 /* limit */
+ .byte 0x00 /* base */
+
+ end_gdt:
+
+ gdt_desc:
+ .word end_gdt - gdt - 1
+ .int gdt
+
+.att_syntax
+
+.section .text
+.global _start
+.type _start, @function
+_start:
+ mov $stack_top, %esp
+
+ cli
+
+.intel_syntax noprefix
+ lgdt [gdt_desc] /* load GDT */
+ mov ax, 0x10
+ mov ds, ax
+ mov ss, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ jmp 0x08:continue
+.att_syntax
+
+continue:
+ call kernel_main
+
+ cli
+1: hlt
+ jmp 1b
+
+/* The size of the _start symbol is the current location '.' minus its start. */
+.size _start, . - _start