Friday, June 5, 2015

Write your own Boot loader in NASM

By: sachin On: 4:23 AM
  • Share The Gag
  • What is a boot Loader

    Before we start writing a boot loader, let us know what exactly a boot loader is, A boot loader is a small program (sequence of instructions ) that gets executed when the system boots. This instructions is responsible to boot the rest of the operating system.


    A boot loader must be written in the first 512 bytes of any storage device. On the POST process the BIOS check the first 512 bytes of each sector in order to check weather the device is bootable or not.Thus there should be some delimiter which indicates that the current disk is bootable. This is achieved by a signature in 511 and 512 th bytes of the first sector of the device, They should be respectively aa55 ( which makes 2 byte ).This signature makes BIOS treat that the device is bootable and it starts executing the instructions from the 0 th byte in the disk.

    NASM code to write a very basic boot loader


    loop:    jmp $ ;  Waits for infinite time ( a infinite loop )
    times 510 - ($ - $$ ) db 0  ; fill all the 510 bytes with 0's ( except the jmp instruction )
    dw  0xAA55  ; signature of boot loader

    The above code will make a empty boot loader , It does nothing but halts on boot up.

    NASM code to print hello in boot loader

    mov ah,0x0e    ; to print a character 0 x 0 e
    mov al,'h'           ; Print ' hello'
    int 0x10
    mov al,'e'
    int 0x10
    mov al,'l'
    int 0x10
    mov al,'l'
    int 0x10
    mov al,''
    int 0x10

    loop:    jmp $ ;  Waits for infinite time ( a infinite loop )
    times 510 - ($ - $$ ) db 0  ; fill all the 510 bytes with 0's ( except the jmp instruction )
    dw  0xAA55  ; signature of boot loader

    Compile your bootloader into a binary file

    In Linux Systems :  nasm  ./bootloader.asm -f bin  -o ./bootloader
    The above command will create a .bin ( binary image ) of your boot loader, you can explore the binary file with GHEX tool for verification.

    Burn the Boot loader into a USB device

    To burn the boot loader into your USB device use the DD command in Linux systems
    dd if="./bootloader.bin" od="/dev/sdb" bs=512
    The above command will burn the boot loader into first 512 Byte of the pen drive making it bootable.
    Now finally restart the computer and enjoy the boot loader, Also you can extend the boot loader with other BIOS interrupts .

    Setting Up OpenGL andCodeBlocks in Ubuntu 14.04

    By: sachin On: 3:59 AM
  • Share The Gag
  • What is OpenGL

    OpenGL is an free graphics library written in c. This is available for various platforms including C, C++,Java,Android etc. In this article we explain in detail how to install and set up OpenGL library in your Ubuntu 14.04  environment.


     Before we start setting up the software, We must try to download the required Packages which are explained in the steps bellow.

    Setup OpenGL with Ubuntu

    Install the mesa-common-dev and freeglut3-dev libraries in your Ubuntu systems. By using the Commands bellow. $ sudo apt-get install mesa-common-dev $ sudo apt-get install  freeglut3-dev Once you set up these libraries successfully, You need to just cobfigure your CodeBlocks IDE to start developping the OpenGL project. Before you start developping , first download the codebolocks IDE using the following commands. $ sudo apt-get install codeblocks

    Configure Your CodeBlocks IDE for OpenGL

    Open the CodeBlocks IDE  


    Once you are done opening the CodeBlocks, Open the new project, fill the details of the application you are going to create.



    NewProject -> OpenGL project-> Fill Project Details ->Select the Compiler (eg : GCC ) -> Finish the setup    

    Configure your Code Blocks To link all the required Libraries

    Perform the Following tasks as shown in bellow images to configure and to add the required flags inorder to make your linker add the required object libraries during linking.



    Project Properties -> Build Settings -> Build Options -> Linker Setting -> Other Linker Options Add the following flags as specified bellow along with ' - ' sign -lGL -lGLU -lglut