added a second program to load from 0x2000 on keypress 0 or 1

master
Your Name 6 years ago
parent 20e2e1a88c
commit b33cc00d31

Binary file not shown.

@ -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

@ -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

@ -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

Binary file not shown.

Binary file not shown.

@ -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

Binary file not shown.
Loading…
Cancel
Save