> Then, you also need to load the code segment register with 0. I think
> the only way to do that is to load the stack with 0:0x7c00, then do a
> far return. I'm not sure of the byte order, though, so you may have
I've found FREEBIOS, and looked at their source code. They had a very
interesting way of doing it:
db 0xea
dw 0x7c00,0x0000
:-)
After "porting" their TurboAssembler(?)-source to NASM I *almost* got it
working: Loading for example a Solaris7 install-floppy works, but it
crashes a few seconds later(!). Loading DOS or GRUB seems to fail. This is
clearly strange. Maybe DOS itself modifies the interrupt table? I'm
currently running from Windows95-DOS, maybe I should try a older version.
I've attached the FREEBIOS-code, with my modifications. Also, here is the
small quick-and-dirty code I wrote (which behavies quite the same):
ORG 0x100
SECTION .text
;; ES = 0
mov ax, 0
mov es, ax
mov ds, ax
mov ss, cx
mov sp, 0x7a00
mov di, sp
mov si, 0x7c00
cld
;; Print A
mov ah, 0x2
mov dl, 0x41
int 0x21
;; Load bootsector
mov ah, 2 ; Function 2 = read
mov al, 1 ; One sector
mov bx, 0x7c00 ; Buffer
mov cl, 1 ; Sectornumber
mov ch, 0 ; Cylinder 0
mov dl, 0x0 ; HD
mov dh, 0 ; Head 0
int 0x13
;; Check for error value
cmp ah, 0
jz noerror
;; Print B
mov ah, 0x2
mov dl, 0x42
int 0x21
noerror:
;; Print C
mov ah, 0x2
mov dl, 0x43
int 0x21
;; Wait for key
mov ah, 0x1
int 0x21
;; Print D
mov ah, 0x2
mov dl, 0x44
int 0x21
mov dl, 0x0 ; HD
db 0xea
dw 0x7c00,0x0000
Thanks for all help.
/Peter Astrand <[EMAIL PROTECTED]>
ORG 0x100
SECTION .text
sti
pop es
mov di,013h
cld
xor ax,ax
stosw ; destroy vdisk signature
TryBoot:
mov bx,MSG_Try
call WriteAsciiz
mov cx,3 ; try 3 times
Retry:
push cx
xor ah,ah
xor dx, dx
int 013h
xor ax,ax
mov es,ax
mov ax,00201h
mov bx,07c00h
mov cx,00001h
xor dx, dx
int 013h
pop cx
jnc ReadOK
dec cx
jnz Retry
cmp ah,080h
mov bx, ERR_NoDisk
jz NoDisk
mov bx, ERR_ReadError
NoDisk:
call WriteAsciiz
jmp WaitKey
ReadOK:
; cmp word [07dfeh],0aa55h
; jnz Invalid
db 0eah
dw 07c00h,00000h
Invalid:
mov bx, ERR_BootSectorInvalid
call WriteAsciiz
WaitKey:
mov bx, MSG_WaitKey
call WriteAsciiz
mov ah,010h
int 016h
jmp TryBoot
WriteAsciiz:
push ax
push bx
writenextchar:
mov al,[bx]
or al,al
jz exit
inc bx
push bx
mov ah,00eh ; video bios teletype output
xor bx,bx ; page 0 (bh)
int 010h
pop bx
jmp writenextchar
exit:
pop bx
pop ax
ret
MSG_Try db 'attempting to boot from drive a:...',13,10,0
ERR_BootSectorInvalid db 'boot sector invalid',13,10,0
ERR_NoDisk db 'no disk in drive',13,10,0
ERR_ReadError db 'read error',13,10,0
MSG_WaitKey db 'press a key to retry',13,10,0