I am makeing a simple, 1-character commands opperating system to learn how to do it. I have made some code in asm and assembled it. I loaded it into the bootsector of a floppy and it works fine, desplaying the 'Command?' prompt. However, when I try to use BOOT12.BIN as a bootloader, it doesn't even boot up. Here is the code I use when I am doing pure bootsector:
org 0x7c00 ; This is where BIOS loads the bootloader
; Execution begins here
entry:
jmp start ; jump over the DOS boot record data
; ----------------------------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM name & DOS version (8 chars)
brBPS DW 512 ; 000Bh - Bytes/sector
brSPC DB 1 ; 000Dh - Sectors/cluster
brResCount DW 1 ; 000Eh - Reserved (boot) sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSPH DW 18 ; 0018h - Sectors per track
brHPC DW 2 ; 001Ah - Number of Heads
brHidden DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig
brSerialNum DD 404418EAH ; 0027h - Volume serial number (random)
brLabel DB 'OS Disk ' ; 002Bh - Volume label (11 chars)
brFSID DB 'FAT12 ' ; 0036h - File System ID (8 chars)
xor ax, ax ; Zero out ax
mov ds, ax ; Set data segment to base of RAM
hello db 0x0A, 0x0D, 'Hello ', 0
prompt db 0x0A, 0x0D, 'Command? ', 0
bdcmd db ' Bad Command Letter.', 0
loading db ' Loading...', 0
rebooting db ' Rebooting the system...', 0
start:
mov si, prompt
call putstr
xor ah, ah
int 0x16
mov ah, 0x0E
mov bl, 0x07
int 0x10
cmp al, 'h'
jz hellogame
cmp al, 'r'
jz reboot
jnz badcmd
hellogame:
mov si, loading
call putstr
mov si, hello
call putstr
xor ah, ah
int 0x16
mov ah, 0x0E
mov bl, 0x07
int 0x10
cmp al, '`'
jz start
jnz hellogame
reboot:
mov si, rebooting
call putstr
mov ax, 0xFFFF
push ax
mov ax, 0xFFFE
push ax
iret
; Print a null-terminated string on the screen
putstr:
lodsb ; AL = [DS:SI]
or al, al ; Set zero flag if al=0
jz putstrd ; jump to putstrd if zero flag is set
mov ah, 0x0e ; video function 0Eh (print char)
mov bx, 0x0007 ; color
int 0x10
jmp putstr
putstrd:
retn
badcmd:
mov si, bdcmd
call putstr
jmp start
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
times (512 - size - 2) db 0
db 0x55, 0xAA ;2 byte boot signature
--------------------------END CODE---------------------
Here is the code I use with the bootloader:
xor ax, ax ; Zero out ax
mov ds, ax ; Set data segment to base of RAM
hello db 0x0A, 0x0D, 'Hello ', 0
prompt db 0x0A, 0x0D, 'Command? ', 0
bdcmd db ' Bad Command Letter.', 0
loading db ' Loading...', 0
rebooting db ' Rebooting the system...', 0
start:
mov si, prompt
call putstr
xor ah, ah
int 0x16
mov ah, 0x0E
mov bl, 0x07
int 0x10
cmp al, 'h'
jz hellogame
cmp al, 'r'
jz reboot
jnz badcmd
hellogame:
mov si, loading
call putstr
mov si, hello
call putstr
xor ah, ah
int 0x16
mov ah, 0x0E
mov bl, 0x07
int 0x10
cmp al, '`'
jz start
jnz hellogame
reboot:
mov si, rebooting
call putstr
mov ax, 0xFFFF
push ax
mov ax, 0xFFFE
push ax
iret
; Print a null-terminated string on the screen
putstr:
lodsb ; AL = [DS:SI]
or al, al ; Set zero flag if al=0
jz putstrd ; jump to putstrd if zero flag is set
mov ah, 0x0e ; video function 0Eh (print char)
mov bx, 0x0007 ; color
int 0x10
jmp putstr
putstrd:
retn
badcmd:
mov si, bdcmd
call putstr
jmp start
-----------------------END CODE------------------------
Can anyone help me? BOOT12's source can be found at:
http://www.cse.unl.edu/~jgompert/OS/lesson6.htm
THANKS A LOT!
Eric Snabber
Basic Bootsector Problem
RE:Basic Bootsector Problem
hm.. i don't understand you.. is it so that you found a fat12 bootstrap loading your file, and that doesn't work?
if so, i see a biiig mistake at the hand:
you have to add jmp start just before your data, or the cpu will try to run it as code.
Cheers,
Adrian.
if so, i see a biiig mistake at the hand:
you have to add jmp start just before your data, or the cpu will try to run it as code.
Cheers,
Adrian.
RE:Basic Bootsector Problem
Besides the jump, I belive you must set data segment to the linear address where you load the kernel, not to the base of RAM.
pepito
pepito