Code: Select all
;; Nextep loader stage 1
;; This file must be put in the boot sector of your boot disk
;; it will load the stage2.bin file, located at the first few
;; sectors of the boot disk.
org 0x7C00
bits 16
ATTR_GREEN equ 0x02
ATTR_RED equ 0x04
ATTR_WHITE equ 0x07
;; make sure the header is not executed
;; (jump over it)
db 0xEB
db ConfigHeader.end-ConfigHeader
ConfigHeader:
.bootdisk db 0x00 ;; 00h=fd0, 01h=fd1, 80h=hd0, 81h=hd1 [offset 2]
.stage2size dw 3 ;; size of the stage2.bin file (in sectors) [offset 3]
.width dw 720 ;; preferred screen width [offset 5]
.height dw 480 ;; preferred screen height [offset 7]
.end:
;; set up the registers correctly
mov ax, 0
mov ds, ax
mov ss, ax
jmp 0:_start
_start:
;; reset the correct video mode (some BIOSes set up a graphics mode to start with)
mov ax, 2
int 10h
;; set up a stack
mov sp, 0x7CFF
;; Make sure everything is OK
mov ax, [ConfigHeader.stage2size]
test ax, ax
jnz ok0
;; if not OK, print an error message
mov si, str_config_fail
mov dl, ATTR_RED
call putmsg
cli
hlt
;; Main loading routine
ok0:
mov si, str_loading
mov dl, ATTR_WHITE
call putmsg
loadloop:
mov ax, 0x7E0
mov es, ax
mov ah, 0x02
mov al, [ConfigHeader.stage2size]
mov cx, 2
mov dh, 0
mov dl, [ConfigHeader.bootdisk]
mov bx, 0
int 13h
jc loadloop ; if failed, retry
;; tell the user we are about to pass control to stage2.bin
mov si, str_passing
mov dl, ATTR_GREEN
call putmsg
;; finally, run stage2.bin!
jmp 0x7E0:0
;; print a message to the screen
;; in SI = string to print (NUL-terminated)
;; in DL = color attribute to be used
;; DI, ES = destroyed
putmsg:
mov ax, 0xb800
mov es, ax
xor di, di
mov cx, 80*25*2
mov al, 0
rep stosb ; clear the screen
xor di, di
.loop:
lodsb
test al, al
jz .ret
mov ah, dl
stosw
jmp .loop
.ret:
ret
;; STRINGS
str_loading db 'Loading stage2.bin', 0
str_config_fail db 'Nextep loader stage1.bin configuration invalid', 0
str_passing db 'Passing control to stage2.bin', 0
times 510 - ($ - $$) db 0
db 0x55, 0xAA
That's the whole code. I think it could actually be a QEMU bug - in my stage 2 loader, which prints without clearing the screen, messages only come up after a
next message is printed. In VirtualBox there is no problem with that stage 2 loader, but there is the same problem with this one, however.