Here's my setup:
Windows 10 Pro 64-bit (Version 1511 OS Build 10586.545)
Cygwin (uname -a -> CYGWIN_NT-10.0 DESKTOP-T7AC450 2.5.2(0.297/5/3) 2016-06-23 14:29 x86_64 Cygwin)
NASM version 2.10.07
dd (coreutils) 8.25
I've tried both VirtualBox (Version 5.1.2 r108956) and bochs (2.6. and both yield the same result. The code is pretty small so I'll post it here.
bootloader.asm
Code: Select all
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
reset: ; Reset the floppy drive
mov ax, 0
mov dl, 0 ; Drive=0 (=A)
int 13h
jc reset ; ERROR => reset again
mov si,status_string
call print_string
push ax
mov al,ah
call print_hex_byte
pop ax
read:
mov ax, 0900h ;
mov es, ax
mov bx, 0
mov ah, 2 ; Load disk data to ES:BX
mov al, 1 ; Load 5 sectors
mov ch, 0 ; Cylinder=0
mov cl, 2 ; Sector=2
mov dh, 0 ; Head=0
mov dl, 0 ; Drive=0
int 13h ; Read!
Jc read ; ERROR => Try again
mov si,status_string
call print_string
push ax
mov al,ah
call print_hex_byte
pop ax
mov si,read_string
call print_string
call print_hex_byte
mov si,sectors_string
call print_string
jmp 0900h ; Jump to the program
fail_string db 13,10,'Fail',0
read_string db 13,10,"Read ",0
sectors_string db " sectors",0
status_string db 13,10,"Status ",0
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
print_hex_byte: ; Routine : output the value of AL on the screen in hex
pusha
mov bl, 11110000b ; MSB mask
and bl, al
shr bl, 4 ; Shift right 4 bits
push ax
mov al,bl
call fourbit_to_ascii
mov al,bl
mov ah, 0Eh
int 10h
pop ax
mov bl, 00001111b
and al,bl
call fourbit_to_ascii
mov al,bl
int 10h
mov al,104
int 10h
popa
ret
fourbit_to_ascii: ; Routine : Puts the ASCII representation of the 4 LSB of AL into BL
cmp al, 9
jle .number
add al,55
mov bl,al
ret
.number:
add al,48
mov bl,al
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
helloworld.asm
Code: Select all
BITS 16
hello_world_start:
mov si, secondstage_string ; Put string position into SI
call pprint_string ; Call our string-printing routine
hang:
jmp hang ; Jump here - infinite loop!
secondstage_string db 13,10,'Hello World!', 0
pprint_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0x0000 ; The standard PC boot signature
build.sh
Code: Select all
#!/bin/bash
/usr/bin/nasm -f bin -l bootloader.lst bootloader_s.asm -o bootloader.bin
/usr/bin/nasm -f bin -l helloworld.lst helloworld.asm -o helloworld.bin
echo "Compilation complete"
dd bs=512 count=2880 if=/dev/zero of=disk.img
dd if=bootloader.bin of=disk.img conv=notrunc
dd if=helloworld.bin of=disk.img seek=512 conv=notrunc
echo "Disk image complete"
Code: Select all
Status 0Eh
Status 0Eh
Read 00h sectors
Cheers,
L