diff --git a/.boot.asm.swp b/.boot.asm.swp deleted file mode 100644 index 415ec97..0000000 Binary files a/.boot.asm.swp and /dev/null differ diff --git a/Makefile b/Makefile index 267777a..47a1203 100755 --- a/Makefile +++ b/Makefile @@ -3,18 +3,21 @@ all : image compile : nasm -f bin -o boot.bin boot.asm nasm -f bin -o program.bin program.asm + nasm -f bin -o program2.bin program2.asm image : compile sudo dd if=/dev/zero of=disk.img bs=1024 count=720 sudo dd if=boot.bin of=disk.img bs=512 count=1 conv=notrunc sudo dd if=program.bin of=disk.img bs=512 seek=1 count=1 conv=notrunc + sudo dd if=program2.bin of=disk.img bs=512 seek=2 count=1 conv=notrunc + flashusb : image - #sudo umount /dev/sdb sudo dd if=boot.bin of=/dev/sdb bs=512 count=1 sudo dd if=program.bin of=/dev/sdb bs=512 seek=1 count=1 + sudo dd if=program2.bin of=/dev/sdb bs=512 seek=2 count=1 run : image qemu-system-x86_64 disk.img @@ -23,5 +26,3 @@ clean : rm *.img rm *.bin - - diff --git a/README.md b/README.md index e4ed292..090075f 100755 --- a/README.md +++ b/README.md @@ -24,3 +24,6 @@ https://stackoverflow.com/questions/36044706/enable-the-boot-loader-to-load-the- ###Tutorial on second stage / read interrupt BUT only for floppy :( For disk see above https://blog.ghaiklor.com/how-to-implement-a-second-stage-boot-loader-80e75ae4270c + +###Boc drawing characters +https://en.wikipedia.org/wiki/Box-drawing_character diff --git a/boot.asm b/boot.asm index 6cbde22..f140a73 100755 --- a/boot.asm +++ b/boot.asm @@ -2,6 +2,11 @@ [bits 16] +;cmp dl, 0x05 +;je welcome + +;mov [bootdev], dl ; Save boot device number + ; Use the boot drive number passed to us by BIOS in register DL welcome: xor ax,ax ; We want a segment of 0 for DS for this question @@ -14,7 +19,6 @@ welcome: cld ; Set the direction flag to be positive direction - mov si, wolf_wel_msg call wolf_print @@ -22,10 +26,12 @@ start: mov ah, 0x00 int 0x16 cmp al, "0" - je load_it_all - jmp over + je load_it_all_0 + cmp al, "1" + je load_it_all_1 + jmp over -load_it_all: +load_it_all_0: mov si, wolf_kernel_load call wolf_print @@ -36,28 +42,62 @@ load_it_all: mov ah,00 int 13h - read_sector: +.read_sector: mov ax, 0x0 mov es, ax ; ES = 0 - mov bx, 0x1000 ; BX = 0x1000. ES:BX=0x0:0x1000 + mov bx, 0x2000 ; BX = 0x1000. ES:BX=0x0:0x1000 ; ES:BX = starting address to read sector(s) into mov ah, 02 ; Int 13h/AH=2 = Read Sectors From Drive mov al, 01 ; Sectors to read = 1 mov ch, 00 ; CH=Cylinder. Second sector of disk ; is at Cylinder 0 not 1 - mov cl, 02 ; Sector to read = 2 + mov cl, 03 ; Sector to read = 2 mov dh, 00 ; Head to read = 0 ; DL hasn't been destroyed by our bootloader code and still ; contains boot drive # passed to our bootloader by the BIOS int 13h + jc wolf_error + popf + jmp 0x0:0x2000 + cli + hlt + + +load_it_all_1: + + mov si, wolf_kernel_load + call wolf_print + + pushf + stc + + mov ah,00 + int 13h + +.read_sector: + mov ax, 0x0 + mov es, ax ; ES = 0 + mov bx, 0x1000 ; BX = 0x1000. ES:BX=0x0:0x1000 + ; ES:BX = starting address to read sector(s) into + mov ah, 02 ; Int 13h/AH=2 = Read Sectors From Drive + mov al, 01 ; Sectors to read = 1 + mov ch, 00 ; CH=Cylinder. Second sector of disk + ; is at Cylinder 0 not 1 + mov cl, 02 ; Sector to read = 2 + mov dh, 00 ; Head to read = 0 + ; DL hasn't been destroyed by our bootloader code and still + ; contains boot drive # passed to our bootloader by the BIOS + int 13h + jc wolf_error popf jmp 0x0:0x1000 cli hlt - wolf_error: + +wolf_error: mov si, wolf_error_msg call wolf_print mov si, wolf_error_msg1 @@ -67,8 +107,7 @@ load_it_all: xor ax,ax int 19h - wolf_print: - +wolf_print: lodsb or al,al jz exit @@ -89,5 +128,7 @@ wolf_kernel_load db 'Loading program',0x0D,0x0A,0 wolf_error_msg db 'Program not found!',0x0D,0x0A,0 wolf_error_msg1 db 'Press any key to restart..',0 +;bootdev db 0 ; Boot device number + times 510-($-$$) db 0 dw 0xAA55 diff --git a/boot.bin b/boot.bin index 4e054cd..c7b6db4 100755 Binary files a/boot.bin and b/boot.bin differ diff --git a/disk.img b/disk.img index 4be6a53..3f14e73 100755 Binary files a/disk.img and b/disk.img differ diff --git a/program2.asm b/program2.asm new file mode 100755 index 0000000..27cb254 --- /dev/null +++ b/program2.asm @@ -0,0 +1,90 @@ +[org 0x2000] + + +start: + mov ah, 01h ;make cursor invisible + mov cx, 2607h + int 10h + + mov ah, 06h ; Scroll up function + xor al, al ; Clear entire screen + xor cx, cx ; Upper left corner CH=row, CL=column + mov dx, 184FH ; lower right corner DH=row, DL=column + mov bh, 1Eh ; YellowOnBlue + int 10H ; execute interrupt + + mov ah, 06h ;draw rect on background + mov cx, 0101h + mov dx, 164Dh + mov bh, 4Fh + int 10h + + mov ah, 06h ;draw shadow + mov cx, 1702h + mov dx, 174Eh + mov bh, 0Eh + int 10h + mov ah, 06h ;draw shadow + mov cx, 024Eh + mov dx, 174Eh + mov bh, 0Eh + int 10h + + + mov ah, 02h ;sets cursor to top to write + mov bh, 0h + mov dh, 1h + mov dl, 1h + int 10h + + mov al, 0xC9 ;draw border + mov bl, 0x03 + mov ah,0x0e + int 10h + mov al, 0xCD + mov bl, 0x03 + mov ah,0x0e + int 10h + + mov ah, 02h ;sets cursor to top to write + mov bh, 0h + mov dh, 4h + mov dl, 4h + int 10h + + mov si, msg1 + call print + mov si, msg2 + + call wait_for_key + +wait_for_key: + mov ah, 0x00 + int 0x16 + cmp al, "0" + je exit_bootloader + jmp over + + +print: + lodsb + or al,al + jz .exit + mov bl, 0x03 + mov ah,0x0e + int 10h + jmp print + .exit: + ret + +exit_bootloader: +mov dl, 0x05 +jmp 0x0:0x7c00 ;jump back to bootloader init +hlt + +over: + jmp wait_for_key + + +msg1 db "TEST",0x0A,0 +msg2 db "TEST",0x0D,0x0A,0 diff --git a/program2.bin b/program2.bin new file mode 100644 index 0000000..bb93191 Binary files /dev/null and b/program2.bin differ