972
edits
[unchecked revision] | [unchecked revision] |
No edit summary |
mNo edit summary |
||
(23 intermediate revisions by 16 users not shown) | |||
Line 1:
__NOTOC__
=== Your first boot sector ===▼
The following code is the smallest possible example of booting code from a floppy. It is assembled in [[NASM]] and copied to floppy using either partcopy or dd. Then you simply boot from the floppy.▼
{{Tone}}
{{Rating|1}}
! Windows/DOS▼
{{Infobox Tutorial
| name=Babystep1: Your first boot sector
| next=[[Babystep2]]
> nasmw boot.asm -f bin -o boot.bin▼
> partcopy boot.bin 0 200 -f0▼
▲=== Your first boot sector. ===
$ nasm boot.asm -f bin -o boot.bin▼
==Code==
$ dd if=boot.bin of=/dev/fd0▼
The following code is the smallest possible example of booting code from a disk.
▲|}
<syntaxhighlight lang="asm">
; boot.asm
hang:
Line 20:
times 512-($-$$) db 0
</syntaxhighlight>
The CPU starts in real mode and the [[BIOS]] loads this code at address 0000:7c00.
<syntaxhighlight lang="asm">
; boot.asm
hang:
Line 32:
db 0x55
db 0xAA
</syntaxhighlight>
<syntaxhighlight lang="asm">
;boot.asm
cli
Line 46:
db 0x55
db 0xAA
</syntaxhighlight>
You may notice that the
Removing the loop and merely padding out the sector with zeroes will usually cause the BIOS to throw an error on boot. On most machines, it will say "Operating System Not Found".
==Creating disk image==
▲The
For a more detailed description, see the [[Bootable Disk]] page.
<syntaxhighlight lang="bash">
OR
debug boot.bin
-W 100 0 0 1
-Q</syntaxhighlight>
===Unix===
<syntaxhighlight lang="bash">
</syntaxhighlight>
To write to a hard drive or USB-stick, use
<syntaxhighlight lang="bash">
nasm boot.asm -f bin -o boot.bin
dd if=boot.bin of=/dev/sda
</syntaxhighlight>
where replace "sda" with sdb, sdc etc. according to your configuration.
==Running the binary in QEMU==
If you don't have an old machine with floppy drive you can emulate one using QEMU (note "'''f'''da").
<syntaxhighlight lang="bash">
qemu-system-i386 -fda boot.bin
</syntaxhighlight>
But it is advisable to forget about floppies altogether, and focus on USB-sticks instead. Also if you're afraid to test your code on your development machine (that would be wise), you can use QEMU (note "'''h'''da").
<syntaxhighlight lang="bash">
qemu-system-i386 -hda boot.bin
</syntaxhighlight>
Use the QEMU monitor command to send Ctrl-Alt-Del to the VM:
<syntaxhighlight lang="bash">
sendkey ctrl-alt-delete
</syntaxhighlight>
Because of how fast emulation has become, you might need to slow down emulation speed to 1% to notice the reboots.
* Instruction Set from the horse's mouth: [http://www.intel.com/design/pentiumII/documentation.htm]
* Easier to read: [http://www.baldwin.cx/386htm/toc.htm]
Line 60 ⟶ 103:
* Interrupts by number: [http://www.osdever.net/downloads.php]
* Randall Hyde's look into the bowels of the PC: [http://webster.cs.ucr.edu/]
* QEMU [https://www.qemu.org]
[[Category:Babystep]]
[[Category:Bootloaders]]
|