Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm writing an open source operating system and I've got the boot sector as follows


ASM
[BITS 16]       ; We need 16-bit instructions for Real mode 
[ORG 0x7C00]    ; The BIOS loads the boot sector into memory location 0x7C00 
        mov ah, 0Eh     ; We want to print a single character
        mov al, 'A'     ; That character is 'A'
        mov bh, 0Eh     ; White text on black background, not blinking
        mov bl, 0       ; Page number 0
        int 10h

hang:
        jmp hang        ; Loop, self-jump

times 510-($-$) db 0    ; Fill the rest of the files with zeros, until we reach 510 bytes

        dw 0AA55h       ; Our boot sector identifier



My first question -
I'm writing the boot sector for 4096 bytes per sector Hard Disks. Shouldn't I change the line "times 510-($-$) db 0" to "times 4094-($-$) db 0". Cos I'm writing for 4096 bytes per sector.

My second question -
Instead of filling the boot sector with 0 and then writing the boot signature at the last 2 bytes, what other information can I put in the boot sector? (that's instead of filling it with 0)

thanks
Posted
Comments
Chuck O'Toole 8-Nov-11 8:34am    
Put in your name and phone number so some future debugger can call you in on a consultation. Don't forget to charge more when they do.
Mohibur Rashid 8-Nov-11 11:00am    
when do you call something an os??

What do you expect to add in it?

Writing an OS is a seriously technical endeavor which requires a lot of low level knowledge.

If you are asking these kinds of questions this early in the process, you had better read more books and learn more before going on.
 
Share this answer
 
You should be storing a BPB[^] at the start. Your code should start with a JMP & NOP to skip over it.

I'm guessing that the 4096B sectors are on a CD. I never made it this far when making my OS, but there was some trick to it.

You can store anything you want in the free space, but typically you would fill it with code or error messages.

This is the basics of my boot sector. It boots off a floppy disk because they are really easy to use.

When you want to halt execution, you should use the hlt instruction. This puts the CPU to sleep. Your current jump loop is thrashing the CPU.

[BITS 16]
[ORG 0x7C00]

JMP main
NOP

bpbOEM               db "MY OS    "
bpbBytesPerSector    dw 512
bpbSectorsPerCluster db 1
bpbReservedSectors   dw 1
bpbNumberOfFATs      db 2
bpbRootEntries       dw 224
bpbTotalSectors      dw 2880
bpbMedia             db 0xF0
bpbSectorsPerFAT     dw 9
bpbSectorsPerTrack   dw 18
bpbHeadsPerCylinder  dw 2
bpbHiddenSectors     dd 0
bpbTotalSectorsBig   dd 0
bsDriveNumber        db 0
bsUnused             db 0
bsExtBootSignature   db 0x29
bsSerialNumber       dd 0xA0A1A2A3
bsVolumeLabel        db "MY OS BOOT "
bsFileSystem         db "FAT12   "

main:
;code removed

;error messages and such
TIMES 510 - ($ - $$) db 0
dw 0xAA55
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900