Tampilkan postingan dengan label computer. Tampilkan semua postingan
Tampilkan postingan dengan label computer. Tampilkan semua postingan

Jumat, 21 Februari 2014

NASM bootstraps tutorial

The basics
----------
These are the rules that you must follow:
  - The BIOS will load your bootstrap to address 07C00h. Sadly, the segment and     offset varies.
  - Bootstraps must be compiled as plain binary files.
  - The filesize for the plain binary file must be 512 bytes.
  - The file must end with AA55h.

A minimal bootstrap
-------------------
This bootstrap just hangs:

    ; HANG.ASM
    ; A minimal bootstrap
    hang:                   ; Hang!
            jmp hang

    times 510-($-$$) db 0   ; Fill the file with 0's
    dw 0AA55h               ; End the file with AA55

The line starting with "times" is a command that only NASM understands. The line will insert 0's until the filesize is 510 bytes. The whole file will therefore be 512 bytes. The last instruction puts AA55 at the end of the file.

Bootsector

Requirements
============
During this article I assume that you have good knowledge of the assembly language and intel architecture. If not, read an assembly tutorial, they aren't hard to find...

Start
=====

Creating your own bootsector is simpler than you may think, the only requirement is that the bootsector is 512 bytes long, and at offset 0x1FE (decimal=510), the word 0xAA55 is placed. This is the first thing the BIOS does when the PC boots up, it first looks on the first floppy drive at the first sector for 0xAA55 at the end, and if it finds it then it loads it into memory, and starts executing it, otherwise it trys the primary harddisk, and if that isn't found it just bombs out with an error.

Kamis, 20 Februari 2014

How It Works -- Master Boot Record

   This article is a disassembly of a Master Boot Record (MBR).  The MBR is the sector at cylinder 0, head 0, sector 1 of a hard disk. An MBR is created by the FDISK program.  The FDISK program of all operating systems must create a functionally similar MBR. The MBR is first of what could be many partition sectors, each one containing a four entry partition table.

   At the completion of your system's Power On Self Test (POST), INT 19 is called.  Usually INT 19 tries to read a boot sector from the first floppy drive.  If a boot sector is found on the floppy disk, the that boot sector is read into memory at location 0000:7C00 and INT 19 jumps to memory location 0000:7C00. However, if no boot sector is found on the first floppy drive, INT 19 tries to read the MBR from the first hard drive.  If an MBR is found it is read into memory at location 0000:7c00 and INT 19 jumps to memory location 0000:7c00.  The small program in the MBR will attempt to locate an active (bootable) partition in its
partition table.  If such a partition is found, the boot sector of that partition is read into memory at location 0000:7C00 and the MBR program jumps to memory location 0000:7C00.  Each operating system has its own boot sector format.  The small program in the boot sector must locate the first part of the operating system's kernel loader program (or perhaps the kernel itself or perhaps a "boot manager program") and read that into memory.

INT 19 is also called when the CTRL-ALT-DEL keys are used.  On most systems, CTRL-ALT-DEL causes an short version of the POST to be executed before INT 19 is called.