Fri, 15 Dec 2017 23:48:31 +0100
3 files changed,
80 insertions(+),
29 deletions(-)
M
boot/boot.s
→
boot/boot.s
@@ -1,4 +1,5 @@
.section .text +.code16 # disable interrupts cli@@ -8,52 +9,95 @@ ljmp $0, $start
start: # setup segments - mov $0x0000, %ax - mov %ax, %ss - mov %ax, %ds - mov %ax, %es - mov %ax, %fs + movw $0x0000, %ax + movw %ax, %ss + movw %ax, %ds + movw %ax, %es + movw %ax, %fs # setup stack - mov $0x9000, %ax - mov %ax, %bp - mov %ax, %sp + movw $0x9000, %sp + movw %sp, %bp # select display page 0 - mov $0, %al - mov $0x05, %ah + movb $0, %al + movb $0x05, %ah int $0x10 # print hello world - mov $message, %si - mov $0x0000, %bx - mov $0x0E, %ah + movw $message, %si + call print -print_loop: - lodsb - or %al, %al - jz print_end - int $0x10 - jmp print_loop -print_end: + # reset bootdrive +reset: + movb $0x00, %ah + int $0x13 + jc reset - # TODO: - # - load kernel into memory starting at adress 0x10000 + # load second stage into memory starting at adress 0x10000 # (NOTE: this code can only be jumped to after loading the global descriptor table # because it uses absolute adresses larger than 16 bit) + # (NOTE2: this routine only loads 0x48 sectors of the second stage into memory + # and is in general pretty whacky. should be replaced with sth more serious) +load: + movw $0x0000, %bx # buffer address + movw $0x1000, %ax + movw %ax, %es # buffer address (segment) + movb $0x02, %ah # function 0x02: read a sector + movb $0x48, %al # sectors to read count + movb $0x00, %ch # cylinder + movb $0x02, %cl # sector + movb $0x00, %dh # head + # dl (drive) keep as is + int $0x13 + jnc load + + # prints out string thats loaded into memory at 0x00010000 + # remove this test later + mov $0x1000, %ax + mov %ax, %ds + mov $0, %si + call print + xor %ax, %ax + mov %ax, %ds + mov %ax, %es + + # TODO: # - load global descriptor table and far jump into protected mode # - activate A20 gate - # - jump to low kernel code + # - jump to second stage code - # loop forever + # loop forever loop: jmp loop + + # ############################################ + # print + # prints out a string on the screen + # %si: points to the message to be printed + # ############################################ +print: + movw $0x0000, %bx + movb $0x0E, %ah + +print_loop: + lodsb + or %al, %al + jz print_end + int $0x10 + jmp print_loop +print_end: + ret + + # some data message: - .ascii " Hello World!" - .byte 0x00 + .ascii "Hello World!" + .byte 13 + .byte 10 + .byte 0 end: .=510
M
second_stage/entry.s
→
second_stage/entry.s
@@ -1,3 +1,10 @@
+.section .text start: -loop: - ljmp $0,$loop +# loop: +# jmp loop + +low_kernel_welcome: + .ascii "Welcome to the low kernel!" + .byte 13 + .byte 10 + .byte 0