From 4a5964137923b992577df3db42cde800e5eaf461 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Mon, 29 Sep 2014 11:22:00 +0200 Subject: [PATCH] boot sector with interrupts --- 01-simple-boot-sector/.README.md.swp | Bin 0 -> 12288 bytes 01-simple-boot-sector/README.md | 56 +++++++++++++++++++++ 01-simple-boot-sector/boot_sect_simple.asm | 6 +++ 3 files changed, 62 insertions(+) create mode 100644 01-simple-boot-sector/.README.md.swp create mode 100644 01-simple-boot-sector/README.md create mode 100644 01-simple-boot-sector/boot_sect_simple.asm diff --git a/01-simple-boot-sector/.README.md.swp b/01-simple-boot-sector/.README.md.swp new file mode 100644 index 0000000000000000000000000000000000000000..5821b1e7fab166f2740b104549e42e7bfe2c986e GIT binary patch literal 12288 zcmeI2&u<$=6vwBP_)S~X{sDbSBPEvXwVf)ZO(ddLDI!Q|BoZj4Lh&O$fURhnEXM>Xh$1_4~&D1t8Uq5{C{k9NMS7jzijFsHE|B;3=NK7P?{fCr2Z~ir5 zb0s(Z&l@Y5k7?tmY`P4G6j2xh?v zFb(cJEyO3_I(Q58zy+`dX25Sx3GoB?9()IGfzQE5;6q@*CGa9x21{TO1mM>vh4=-0 z20jG?unS%Tm%uUbHT+~>4Oj+8z-{<{16%{^;5hjCF(JML?|?1P1iwEj#5dprV8Ajs z0&YKo>%ld!4vqtVcm=!y54{43G5uv)YSct#Tu*1)q!OzFy4X`04WuR4Q_;~R7@*nHNqj<$*I~gV&nPL|9$ZV)hfnsXN@_ZR*U4e)ENxRq)n;O zC75!rePy4yx4pD`(@Pg4#@4Z)LR7kwv{t2I0ws95MNyg{Spx~lRjjeYwoWFeD+Qir zgB+1Sl6F--Dgz>7Sz$GD`eD)6%}^w1#KTE-Z9tE>sACQZ9t3mRY8(t<&)IDMBzL z+POqERM}GtNUS<;4yD!Dsho@mZ62zO;tKzLqfM9%}h5DHR? z%QSz6QUmJ}4YR7LtsXjsEaF9PR9-5He0u#~OkY|dCd>SQMwKo=XZVj7dsqd3g%?Ziqs+?11T9EgGFCo+P) zNN`zJnhX~?IK^d(x2ijBvVb=Erjw5oX{u1HZXsd?$0cHW?2UvYT&3XEU0U!=1wwC6 zGo_qLp%UfOfIGQ(6kLt?;_(Hg3b9c(n{`!H?4dH^CW(Q!eAW6!Sp&73Bp9cRL1O;7 lq@1QzNk<&lQRKO*ZW|72OcbFIBAZQ-lNnScZ!F=I_ycQd?SB9O literal 0 HcmV?d00001 diff --git a/01-simple-boot-sector/README.md b/01-simple-boot-sector/README.md new file mode 100644 index 0000000..7c68686 --- /dev/null +++ b/01-simple-boot-sector/README.md @@ -0,0 +1,56 @@ +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 +of the disk (cylinder 0, head 0, sector 0) and it takes 512 bytes. + +To make sure that the "disk is bootable", the BIOS checks that bytes +511 and 512 of the alleged boot sector are bytes `0xAA55`. + +This is the simplest boot sector ever: + +``` +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 +[ 29 more lines with sixteen zero-bytes each ] +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 the above 512 bytes +with a binary editor, or just write a very +simple assembler code: + +```nasm +; 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? ;-) diff --git a/01-simple-boot-sector/boot_sect_simple.asm b/01-simple-boot-sector/boot_sect_simple.asm new file mode 100644 index 0000000..ce78003 --- /dev/null +++ b/01-simple-boot-sector/boot_sect_simple.asm @@ -0,0 +1,6 @@ +; A simple boot sector program that loops forever +loop: + jmp loop + +times 510-($-$$) db 0 +dw 0xaa55