Start migrating from floppy to hard disk

Move stage1 into the MBR boot code
Move stage2 into the second sector of the hard disk
This commit is contained in:
Baptiste Wicht 2013-12-31 15:16:04 +01:00
parent 3f6bc4270a
commit 35ba77cb0f
6 changed files with 79 additions and 34 deletions

View File

@ -15,6 +15,8 @@ bootloader/bootloader.bin: force_look sectors
cd bootloader; $(MAKE) cd bootloader; $(MAKE)
thor.flp: bootloader/bootloader.bin thor.flp: bootloader/bootloader.bin
dd if=bootloader/stage1.bin of=hdd.img bs=446 count=1 conv=notrunc
dd if=bootloader/stage2.bin of=hdd.img bs=512 count=1 seek=1 conv=notrunc
cat bootloader/bootloader.bin > thor.bin cat bootloader/bootloader.bin > thor.bin
cat kernel/kernel.bin >> thor.bin cat kernel/kernel.bin >> thor.bin
cat filler.bin >> thor.bin cat filler.bin >> thor.bin

View File

@ -1,5 +1,4 @@
display_library: sdl display_library: sdl
magic_break: enabled=1 magic_break: enabled=1
floppya: 1_44=thor.flp, status=inserted
ata0-master: type=disk, path="hdd.img", mode=flat, cylinders=1000, heads=16, spt=63 ata0-master: type=disk, path="hdd.img", mode=flat, cylinders=1000, heads=16, spt=63
boot:floppy boot: disk

View File

@ -11,13 +11,13 @@ stage1.bin: stage1.asm
stage2.bin: stage2.asm sectors.asm stage2.bin: stage2.asm sectors.asm
nasm -w+all -f bin -o stage2.bin stage2.asm nasm -w+all -f bin -o stage2.bin stage2.asm
padding.bin: #padding.bin:
dd if=/dev/zero of=padding.bin bs=512 count=34 # dd if=/dev/zero of=padding.bin bs=512 count=34
bootloader.bin: stage1.bin stage2.bin padding.bin bootloader.bin: stage1.bin stage2.bin
cat stage1.bin > bootloader.bin cat stage1.bin > bootloader.bin
cat stage2.bin >> bootloader.bin cat stage2.bin >> bootloader.bin
cat padding.bin >> bootloader.bin # cat padding.bin >> bootloader.bin
clean: clean:
rm -f stage1.bin rm -f stage1.bin

View File

@ -48,6 +48,49 @@ print_16:
.done: .done:
ret ret
print_int_16:
push ax
push bx
push dx
push si
mov ax, di
xor si, si
.loop:
xor dx, dx
mov bx, 10
div bx
add dx, 48
push dx
inc si
test ax, ax
jne .loop
.next:
test si, si
je .exit
dec si
; write the char
pop ax
mov ah, 0Eh
int 10h
jmp .next
.exit:
pop si
pop dx
pop bx
pop ax
ret
key_wait: key_wait:
mov al, 0xD2 mov al, 0xD2
out 64h, al out 64h, al

View File

@ -19,6 +19,10 @@ rm_start:
mov ss, ax mov ss, ax
mov sp, 4096 mov sp, 4096
; Used for disk access
xor ax, ax
mov gs, ax
; Set data segment ; Set data segment
mov ax, 0x7C0 mov ax, 0x7C0
mov ds, ax mov ds, ax
@ -62,6 +66,12 @@ rm_start:
jc extensions_not_supported jc extensions_not_supported
; Tests
; This is the partition start
; mov di, [gs:(0x1000 + 446 + 8)]
; call print_int_16
; 3. Wait for a key press ; 3. Wait for a key press
call new_line_16 call new_line_16
@ -78,36 +88,15 @@ rm_start:
mov si, load_msg mov si, load_msg
call print_line_16 call print_line_16
; Reset disk drive ; Loading the stage 2 from disk
xor ax, ax
xor ah, ah
mov dl, 0
int 0x13
jc reset_failed mov ah, 0x42
mov si, DAP
; Loading the stage 2 from floppy mov dl, 0x80
bootdev equ 0x0
sectors equ 1
mov ax, 0x90
mov es, ax
xor bx, bx
mov ah, 0x2 ; Read sectors from memory
mov al, sectors ; Number of sectors to read
xor ch, ch ; Cylinder 0
mov cl, 2 ; Sector 2
xor dh, dh ; Head 0
mov dl, bootdev ; Drive
int 0x13 int 0x13
jc read_failed jc read_failed
cmp al, sectors
jne read_failed
; Run the stage 2 ; Run the stage 2
jmp dword 0x90:0x0 jmp dword 0x90:0x0
@ -134,7 +123,18 @@ error_end:
jmp $ jmp $
; Datas ; Variable Datas
DAP:
.size db 0x10
.null db 0x0
.count dw 1
.offset dw 0
.segment dw 0x90
.lba dd 1
.lba48 dd 0
; Constants Datas
header_1 db 'Welcome to Thor OS Bootloader!', 0 header_1 db 'Welcome to Thor OS Bootloader!', 0
@ -148,5 +148,4 @@ error_end:
; Make a real bootsector ; Make a real bootsector
times 510-($-$$) db 0 times 446-($-$$) db 0
dw 0xAA55

View File

@ -24,6 +24,8 @@ second_step:
mov si, load_kernel mov si, load_kernel
call print_line_16 call print_line_16
jmp $
; Reset disk drive ; Reset disk drive
xor ax, ax xor ax, ax
mov dl, bootdev mov dl, bootdev