diff --git a/Makefile b/Makefile index 7cd0a9d5..2dca12bf 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ bootloader/bootloader.bin: force_look sectors cd bootloader; $(MAKE) 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 kernel/kernel.bin >> thor.bin cat filler.bin >> thor.bin diff --git a/bochsrc.txt b/bochsrc.txt index 7a67fcf1..9296f346 100644 --- a/bochsrc.txt +++ b/bochsrc.txt @@ -1,5 +1,4 @@ display_library: sdl 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 -boot:floppy \ No newline at end of file +boot: disk \ No newline at end of file diff --git a/bootloader/Makefile b/bootloader/Makefile index 344e1765..01152819 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -11,13 +11,13 @@ stage1.bin: stage1.asm stage2.bin: stage2.asm sectors.asm nasm -w+all -f bin -o stage2.bin stage2.asm -padding.bin: - dd if=/dev/zero of=padding.bin bs=512 count=34 +#padding.bin: +# 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 stage2.bin >> bootloader.bin - cat padding.bin >> bootloader.bin +# cat padding.bin >> bootloader.bin clean: rm -f stage1.bin diff --git a/bootloader/intel_16.asm b/bootloader/intel_16.asm index dfafec1a..e91ae526 100644 --- a/bootloader/intel_16.asm +++ b/bootloader/intel_16.asm @@ -48,6 +48,49 @@ print_16: .done: 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: mov al, 0xD2 out 64h, al diff --git a/bootloader/stage1.asm b/bootloader/stage1.asm index 185bbe99..1fe6943e 100644 --- a/bootloader/stage1.asm +++ b/bootloader/stage1.asm @@ -19,6 +19,10 @@ rm_start: mov ss, ax mov sp, 4096 + ; Used for disk access + xor ax, ax + mov gs, ax + ; Set data segment mov ax, 0x7C0 mov ds, ax @@ -62,6 +66,12 @@ rm_start: 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 call new_line_16 @@ -78,36 +88,15 @@ rm_start: mov si, load_msg call print_line_16 - ; Reset disk drive - xor ax, ax - xor ah, ah - mov dl, 0 - int 0x13 + ; Loading the stage 2 from disk - jc reset_failed - - ; Loading the stage 2 from floppy - - 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 + mov ah, 0x42 + mov si, DAP + mov dl, 0x80 int 0x13 jc read_failed - cmp al, sectors - jne read_failed - ; Run the stage 2 jmp dword 0x90:0x0 @@ -134,7 +123,18 @@ error_end: 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 @@ -148,5 +148,4 @@ error_end: ; Make a real bootsector - times 510-($-$$) db 0 - dw 0xAA55 \ No newline at end of file + times 446-($-$$) db 0 \ No newline at end of file diff --git a/bootloader/stage2.asm b/bootloader/stage2.asm index 26890941..5a71a7e6 100644 --- a/bootloader/stage2.asm +++ b/bootloader/stage2.asm @@ -24,6 +24,8 @@ second_step: mov si, load_kernel call print_line_16 + jmp $ + ; Reset disk drive xor ax, ax mov dl, bootdev