selfmade-os

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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sun Nov 01 23:50:00 2009 +0100
     1.3 @@ -0,0 +1,5 @@
     1.4 +syntax: glob
     1.5 +*.o
     1.6 +kernel
     1.7 +os-isofiles
     1.8 +*.iso
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/linker.ld	Sun Nov 01 23:50:00 2009 +0100
     2.3 @@ -0,0 +1,28 @@
     2.4 +ENTRY (loader)
     2.5 +
     2.6 +SECTIONS{
     2.7 +    . = 0x00200000;
     2.8 +
     2.9 +    .multiboot :{
    2.10 +        *(.multiboot)
    2.11 +    }
    2.12 +
    2.13 +    .text :{
    2.14 +        *(.text)
    2.15 +    }
    2.16 +
    2.17 +    .rodata  : {
    2.18 +        *(.rodata)
    2.19 +    }
    2.20 +
    2.21 +    .data  : {
    2.22 +        *(.data)
    2.23 +    }
    2.24 +
    2.25 +    .bss : {
    2.26 +        sbss = .;
    2.27 +        *(COMMON)
    2.28 +        *(.bss)
    2.29 +        ebss = .;
    2.30 +    }
    2.31 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/loader.s	Sun Nov 01 23:50:00 2009 +0100
     3.3 @@ -0,0 +1,35 @@
     3.4 +global loader           ; making entry point visible to linker
     3.5 +extern kmain             ; main is defined elsewhere
     3.6 +
     3.7 +; setting up the Multiboot header - see GRUB docs for details
     3.8 +MODULEALIGN equ  1<<0                   ; align loaded modules on page
     3.9 +; boundaries
    3.10 +MEMINFO     equ  1<<1                   ; provide memory map
    3.11 +FLAGS       equ  MODULEALIGN | MEMINFO  ; this is the Multiboot 'flag' field
    3.12 +MAGIC       equ    0x1BADB002           ; 'magic number' lets bootloader find the header
    3.13 +CHECKSUM    equ  -(MAGIC + FLAGS)       ; checksum required
    3.14 +
    3.15 +section .multiboot
    3.16 +align 4
    3.17 +MultiBootHeader:
    3.18 +   dd MAGIC
    3.19 +   dd FLAGS
    3.20 +   dd CHECKSUM
    3.21 +
    3.22 +; reserve initial kernel stack space
    3.23 +STACKSIZE equ 0x4000                  ; that's 16k.
    3.24 +
    3.25 +loader:
    3.26 +   mov esp, stack+STACKSIZE           ; set up the stack
    3.27 +   push eax                           ; pass Multiboot magic number
    3.28 +   push ebx                           ; pass Multiboot info structure
    3.29 +   call kmain                          ; call kernel proper
    3.30 +   cli
    3.31 +hang:
    3.32 +   hlt                                ; halt machine should kernel return
    3.33 +   jmp   hang
    3.34 +
    3.35 +section .bss
    3.36 +align 32
    3.37 +stack:
    3.38 +   resb STACKSIZE                     ; reserve stack on a quadword boundary