Page 1 of 1
How to write boot codes using 8088?
Posted: Sun Nov 21, 2010 9:35 pm
by leetow2003
I read boot codes in a book,it is written by nasm,look:
Code: Select all
org 07c00h
mov ax,cs
mov ds,ax
mov es,ax
call DispStr
jmp $
DispStr:
mov ax,BootMessage
mov bp,ax
mov cx,16
mov ax,01301h
mov bx,000ch
mov dl,0
int 10h
ret
BootMessage: db "hello,OS world!"
times 510-($-$$) db 0
dw 0xaa55
I want to rewrite codes using 8088,look:
Code: Select all
code segment
assume cs:code
start:
org 07c00h
mov ax,cs
mov ds,ax
mov es,ax
call DispStr
jmp $
DispStr:
mov ax,offset BootMessage
mov bp,ax
mov cx,16
mov ax,01301h
mov bx,000ch
mov dl,0
int 10h
ret
BootMessage db "hello,OS world!"
db 510-($-$$) dup(0) ;error
dw 0aa55h
code ends
end start
I know that symbol $$ is unknown in 8088,but I don't how to change?
I want to know how to change code:times 510-($-$$) db 0?
Thank you very much.
Re: How to write boot codes using 8088?
Posted: Sun Nov 21, 2010 9:46 pm
by TylerH
There's these really cool things called code tags, look:
[/code]
Re: How to write boot codes using 8088?
Posted: Sun Nov 21, 2010 10:44 pm
by osdevkid
Hi,
Based on my knowledge, '$' & '$$' symbols are specific to NASM compiler, they are not instructions of any specific processor.
I am sorry, if the above information is wrong.
Re: How to write boot codes using 8088?
Posted: Sun Nov 21, 2010 10:51 pm
by Artlav
leetow2003 wrote:I want to rewrite codes using 8088,look:
{code}
I know that symbol $$ is unknown in 8088,but I don't how to change?
I want to know how to change code:times 510-($-$$) db 0?
Confusing terminology.
You rewrote the same code from modern NASM notation into older TASM notation.
8088 is a cpu - both things would work at it, or anything later (x86).
NASM and TASM are assemblers - compilers - that translate this code.
As for the error - it's either db 510-$ dup(0) or org 510, depending on how old a TASM you use.
Re: How to write boot codes using 8088?
Posted: Wed Dec 08, 2010 3:24 am
by miker00lz
hi all. first post. anyway.. maybe this will help you. it's a simple bootloader that i wrote for my real-mode OS kernel that loads my 28 KB kernel into 1000:0000 starting from the second sector of the bootdisk. then it sets up some registers and transfers control to the kernel.
Code: Select all
org 7c00h
jmp entry
spt db 18 ;sectors per track
heads db 2 ;heads
entry:
xor ax, ax
xor bx, bx
xor cx, cx
xor si, si
xor di, di
xor bp, bp
push ax
push ax
push ax
pop es
pop ds
pop ss
mov sp, 0FFFEh
sti
lea si, loadbanner
call printstr
mov cx, 2
mov dx, 0
mov bx, 0
mov ax, 01000h
push ax
pop es
jmp read
readsect:
inc cl
cmp cl, spt
ja nexthead
add bx, 512
read:
push bx
push cx
mov ax, 0201h
int 013h
pop cx
pop bx
jc readerr
inc total
call printdot
push cx
mov cx, total
cmp cx, sectorcount
pop cx
jz success
mov retrycount, 0
jmp readsect
readerr:
push ax
mov ax, retrycount
inc ax
mov retrycount, ax
cmp ax, 7 ;allow up to 6 retries
pop ax
jnz read
lea si, errbanner
call printstr
cli
hlt
nexthead:
mov cl, 0
inc dh
cmp dh, heads
jnz readsect
mov dh, 0
inc ch
jmp readsect
success:
mov ax, 01000h
push ax
push ax
push ax
pop ds
pop ss
pop es
mov ax, 0FFFEh
push ax
pop sp
mov ax, 01000h
push ax
mov ax, 00h
push ax
cli
retf
printstr:
mov ah, 0Eh
mov al, [si]
cmp al, 0
jz goback
mov bx, 0
int 010h
inc si
jmp printstr
goback:
ret
printdot:
push ax
push bx
mov ah, 0Eh
mov al, '.'
int 010h
pop bx
pop ax
ret
total dw 0
retrycount dw 0
sectorcount db 56
loadbanner db 'Loading NamelessOS...', 0
errbanner db 'Error reading data! System halted.', 13, 10, 0
i'm pretty new to x86 assembly still, so i'm sure it could be made better somehow, but it does it's job perfectly and you can change a couple variables if you need to work with different disk geometries. the above code will work unmodified on a 1.44 MB floppy.
Re: How to write boot codes using 8088?
Posted: Wed Dec 08, 2010 8:04 am
by qw
Classic mistake. You can't rely on CS being zero so the origin may be compeletely off. You should explicitly load zero into DS. Also, you did not set up a stack.
Roel