From 0d537e16046b8a4c899c6ccf21626b5dda5d3b34 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Mon, 29 Sep 2014 11:14:34 +0200 Subject: [PATCH] simple boot sector --- 00-environment/README.md | 5 ++++- 01-boot-sector/.README.md.swp | Bin 12288 -> 0 bytes 01-boot-sector/README.md | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) delete mode 100644 01-boot-sector/.README.md.swp diff --git a/00-environment/README.md b/00-environment/README.md index 08cf531..fd85aaa 100644 --- a/00-environment/README.md +++ b/00-environment/README.md @@ -3,4 +3,7 @@ available for you. On a mac, [install Homebrew](http://brew.sh) and then `brew install qemu nasm` -Don't use the Xcode developer tools `nasm` if you have them installed, they won't work for the most cases. +Don't use the Xcode developer tools `nasm` if you have them installed, they won't work for the most cases. Always use `/usr/local/bin/nasm` + +Furthermore, on a mac, qemu is split into multiple binaries. You will want +to call `qemu-system-x86_84 *binfile*` diff --git a/01-boot-sector/.README.md.swp b/01-boot-sector/.README.md.swp deleted file mode 100644 index dc243f91b5be1830b469d863de1a5fdc17cd4358..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zi-n(6vtn>xBQxzcnw3TlsHbS2;sdRg?BJiN^Wn7{^s%Eav_yKsEe_3h5X=04uL`(ne0mrQ^O zFaajO1egF5U;<2l3H;9l%%lPDsKK4O$vgGj*qG}jPfUObFaajO1egF5U;<2l2`~XB zzyz4U4J07wXL@57K#=VJ|K<1p*INKzNQUH*zV88iB7G#iCN)X>q+jIslk|i1jr4&e zNiN3hOM5cw^-zd^uy>I`KE*h~ zINq`_psE0di7JsElSnL8Hc4e^&|bI3#dT|xZ)9--(Cc2cM;<88qk)+0jZF13#phk>#)vuAWk*adh)Y@yzDoa?xt3>9` zC)C-bGSrN*A8C*Qm_u4C$oiC}*KEDj&6QDh~+w WNYlc4hJ~b>QC9_0>+7es55EB)!wo|K diff --git a/01-boot-sector/README.md b/01-boot-sector/README.md index 8b75e10..f641e35 100644 --- a/01-boot-sector/README.md +++ b/01-boot-sector/README.md @@ -1,5 +1,8 @@ This is very exciting, we're going to create our own boot sector! +Theory +------ + When the computer boots, the BIOS doesn't know how to load the OS, so it delegates that task to the boot sector. Thus, the boot sector must be placed in a known, standard location. That location is the first sector @@ -15,3 +18,37 @@ e9 fd ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa ``` + +It is basically all zeros, ending with the 16-bit value +`0xAA55` (beware of indianness, x86 is little-endian). +The first three bytes perform an infinite jump + +Simplest boot sector ever +------------------------- + +You can either write this with a binary editor, or just write a very +simple assembler code: + +``` +; Infinite loop (e9 fd ff) +loop: + jmp loop + +; Fill with 510 zeros minus the size of the previous code +times 510-($-$$) db 0 +; Magic number +dw 0xaa55 +``` + +To compile: +`nasm -f bin boot_sect_simple.asm -o boot_sect_simple.bin` + +> OSX warning: if this drops an error, read chapter 00 again + +I know you're anxious to try it out (I am!), so let's do it: + +`qemu boot_sect_simple.bin` + +You will see a window open which says "Booting from Hard Disk..." and +nothing else. When was the last time you were so excited to see an infinite +loop? ;-)