Babystep1: Difference between revisions

105 bytes added ,  15 years ago
m
no edit summary
[unchecked revision][unchecked revision]
(Added rating.)
mNo edit summary
Line 10:
The following code is the smallest possible example of booting code from a floppy.
 
<source lang="asm">
<pre>
; boot.asm
hang:
Line 16:
 
times 512-($-$$) db 0
</presource>
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 expect 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 [[BIOS|BIOSes]] looked for this in order to identify a boot sector on a disk. It is evidentially unnecessary nowadays. If it's needed, the last line would be replaced with (or some version of it)
<source lang="asm">
<pre>
; boot.asm
hang:
Line 28:
db 0x55
db 0xAA
</presource>
 
But the thing I'd really like to point out is how once you'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:
<source lang="asm">
<pre>
;boot.asm
cli
Line 42:
db 0x55
db 0xAA
</presource>
You may notice that the floppy motor doesn't turn off and you can't reboot with Ctrl-Alt-Del.
 
Line 53:
 
===Windows===
<source lang="bash">
nasmw boot.asm -f bin -o boot.bin
partcopynasmw boot.binasm 0-f 200bin -f0o boot.bin
partcopy boot.bin 0 200 -f0
</source>
===Unix===
<source lang="bash">
$ nasm boot.asm -f bin -o boot.bin
$nasm dd if=boot.asm -f bin of=/dev/fd0-o boot.bin
dd if=boot.bin of=/dev/fd0
</source>
 
== References ==
Anonymous user