changeset 0:99db6262c157

initial commit with code from http://wiki.osdev.org/Bare_bones
author meillo@marmaro.de
date Sun, 01 Nov 2009 23:50:00 +0100
parents
children 42ba76f77035
files .hgignore linker.ld loader.s
diffstat 3 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sun Nov 01 23:50:00 2009 +0100
@@ -0,0 +1,5 @@
+syntax: glob
+*.o
+kernel
+os-isofiles
+*.iso
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linker.ld	Sun Nov 01 23:50:00 2009 +0100
@@ -0,0 +1,28 @@
+ENTRY (loader)
+
+SECTIONS{
+    . = 0x00200000;
+
+    .multiboot :{
+        *(.multiboot)
+    }
+
+    .text :{
+        *(.text)
+    }
+
+    .rodata  : {
+        *(.rodata)
+    }
+
+    .data  : {
+        *(.data)
+    }
+
+    .bss : {
+        sbss = .;
+        *(COMMON)
+        *(.bss)
+        ebss = .;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader.s	Sun Nov 01 23:50:00 2009 +0100
@@ -0,0 +1,35 @@
+global loader           ; making entry point visible to linker
+extern kmain             ; main is defined elsewhere
+
+; setting up the Multiboot header - see GRUB docs for details
+MODULEALIGN equ  1<<0                   ; align loaded modules on page
+; boundaries
+MEMINFO     equ  1<<1                   ; provide memory map
+FLAGS       equ  MODULEALIGN | MEMINFO  ; this is the Multiboot 'flag' field
+MAGIC       equ    0x1BADB002           ; 'magic number' lets bootloader find the header
+CHECKSUM    equ  -(MAGIC + FLAGS)       ; checksum required
+
+section .multiboot
+align 4
+MultiBootHeader:
+   dd MAGIC
+   dd FLAGS
+   dd CHECKSUM
+
+; reserve initial kernel stack space
+STACKSIZE equ 0x4000                  ; that's 16k.
+
+loader:
+   mov esp, stack+STACKSIZE           ; set up the stack
+   push eax                           ; pass Multiboot magic number
+   push ebx                           ; pass Multiboot info structure
+   call kmain                          ; call kernel proper
+   cli
+hang:
+   hlt                                ; halt machine should kernel return
+   jmp   hang
+
+section .bss
+align 32
+stack:
+   resb STACKSIZE                     ; reserve stack on a quadword boundary