Skip to main content

Posts

Showing posts from 2012

Launch Boot loader from MBR

In previous posts I went into the process of building a Boot loader in assembler on the MBR (Master Boot Record). If you open a binary editor to inspect the contents of the Boot loader created in the previous post you will realize that the assembled code occupies around 203 bytes. Due to the distribution of the MBR , there are around 440 bytes available for the code. So this simple code used to print basic drive information takes around 50% of the total available. In modern OS (ie Linux) the MBR is used to launch the Boot loader (Linux) from a specific location in the Disk (where there should be more than enough space). Linux, in particular, uses the MBR to launch it's Boot loader (GRUB) The following code will launch our boot loader from the MBR. First, our launcher must load the Bootloader from the media (aka Disk Drive) to a specific location in memory. Then we call a "jmp" to transfer the flow of execution to the loaded application. BITS  16      ...

Reading Disk Properties in Assembler - INT 13H

This post is a continuation from the previous post [ Writting a Bootloader ] which was an attempt to build a Bootloader for the x86 architecture. Although the executable size is limited to 512 Bytes, there are several important tasks that can be accomplished during booting process. One of them is to read the Geometry from several storage devices. Interrupt 13h [ INT 13h ] provides sector-based disk access services using the CHS addressing  method (Cylinder/Head/Sectors). This values provide the physical location of the data (although this is not completely true nowadays). The code below is an example of this interrupt. It reads the CHS from the first Hard Disk using Interrupt 13h. Briefly, interrupt parameters are set in AX and DX registers. After interrupt is completed, its values can be read from the appropriate registers (CX, DX). The rest of the code includes helper functions to print numbers and strings to present results properly. After booting our virtu...

Writing a Bootloader

I am starting to think of any reason to Write a Bootloader ... I've been always interested not only how to write applications but understanding how the whole system works, from the moment the machine boots. The first steps in computer booting can be described in general as follows: Power Up Start Processing ROM BIOS Execute POS (Power-on self Test) Check hardware devices Look for OS to load During the last step, BIOS will search for Storage Devices (described in the device Boot Order). These are usually CD-Rom, Hard Drives,  USB Drives,  Disk Drives, etc. For each Device (In order), BIOS will look for MBR (Master Boot Record) which corresponds to the first 512 bytes of the Device Image.  These 512 Bytes are loaded then into the memory and executed. It's a very small space in memory to be able to achieve many tasks.  Bootloaders are commonly used to access the kernel loader located in the boot sector of the drive. Other tasks includes initi...