Operating System Development-baby tutorial 1

Source: Internet
Author: User

The following code is the smallest possible example of booting code from a floppy.

; boot.asmhang:    jmp hang     times 512-($-$$) db 0

The CPU starts in real mode and the BIOS loads this code at address 0000: 7c00. the "Times 512... "stuff is NASM's way of saying fill up 512 bytes with zeros. and partcopy is going to perform CT that (200 in hex = 512 in decimal ). change it and you'll see partcopy
Choke.

Often, you will see a so-called boot signature (0xaa55) at the end. Older versions of BIOSes looked for this in order to identify a boot sector on a disk.
It is evidently unnecessary nowadays. If it's needed, the last line wocould be replaced with (or some version of it)

; boot.asmhang:    jmp hang     times 510-($-$$) db 0 ; 2 bytes less now    db 0x55    db 0xAA

But the thing I 'd really like to point out is how once you 've ve booted, And the cursor is happily blinking on a blank screen, you might notice two things. one is that the floppy motor will turn off and the other is that you can press Ctrl-alt-del to reboot. the
Point is that interrupts (such as int 0x09) as still being generated.

For kicks try clearing the interrupts flag:

;boot.asm     cli hang:     jmp hang      times 510-($-$$) db 0     db 0x55     db 0xAA

You may notice that the floppy motor doesn't turn off and you can't reboot with Ctrl-alt-Del.

If you try to reduce this even more by removing the loop and merely pad out the sector with zeros, the BIOS will have something to say about it. on my machine, it was "operating system not found ". I have yet to try filling the sector with zeros memory T for adding
A boot signature.

Not exactly something you wocould show your girlfriend, but I wanted to show just what the bare minimum is before I elaborate. Unless I'm irritating anyone, in which case I'll desist.

Creating disk image

The code is assembled in NASM and copied to Floppy using partcopy, DD, or debug. Then you simply boot from the floppy.

Windows
nasmw boot.asm -f bin -o boot.binpartcopy boot.bin 0 200 -f0 ORdebug boot.bin-W 100 0 0 1-Q
UNIX
nasm boot.asm -f bin -o boot.bindd if=boot.bin of=/dev/fd0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.