In the previous post we had seen how to create a simple boot sector or boot block. Boot sector or Boot loader is essential for any operating system to load. It is the boot loader or boot sector which loads the operating system kernel and operating system essentials before giving control to the operating system.
It is the BIOS which will look for boot sector or boot loader of length 512 bytes in floppy disc or hard drive or CD/DVD or pen drive. From the previous post we know that, BIOS will identify the boot block of boot sector with the key word 0xaa55 as the end of 512 bytes. Now let us understand BIOS and just use the BIOS to play around by displaying some information on the screen.
BIOS (basic input/output system) is the is a piece of software which is implemented by the motherboard manufacturer to detect hardware connected to the motherboard and do some basic tests to check if the hardware connected is working as intended. When the simple tests for hardware failed or hardware not detected, BIOS will print the ERROR or WARNING information before proceeding with booting operating system. Error like "KEYBOARD NOT DETECTED" etc. Which means, BIOS has already detected hardware, after this BIOS will look for the boot loader or boot sector to load the operating system. Before writing actual boot loader to load operating system kernel etc, to understand the BIOS in depth, we can make use of some of the BIOS functionality. Displaying something on the screen is easiest thing to recognise that our code written in boot loader is working.
So, here I am planning to write word "HELLO" on screen using boot loader and BIOS. To do that we need to know how BIOS can help us to display word "HELLO" on the screen. As we are sure that BIOS has already detected display driver (as it displayed some information on the screen), BIOS can help us in displaying the word "HELLO" on screen.
BIOS uses the interrupt calls to do certain things. These interrupts can also be used by operating system for certain things using kernel. The BIOS interrupt calls details can be found in the link: https://en.wikipedia.org/wiki/BIOS_interrupt_call. As we are trying to print word "HELLO" on the screen, our interest is in "Video Service" related interrupt call (0x10), and we want use the Display driver in TTY/TeleType mode (print a character on screen and move the cursor to the next position). Interrupt can be triggered using assembly instruction INT. For Video service, we have to use INT 0x10. To use the INT 0x10 in TTY mode, the ah register should be assigned with value "0x0e". Now we need to know how to print each letter from word "HELLO" on the screen.
In x86 family there are CPU registers which will be used for many purposes. Some of the General purpose registers are AX, BX, CX and DX. Each of these are 16 bit registers. These 16 bit registers can be accessed in byte format like for ex: ah - higher byte of AX register and al - lower byte of AX register. These registers can be used in Real Mode which can be used by BIOS (Note: Before loading the Kernel BIOS will switch to Protected Mode. Click here to know the details or Real Mode and Protected Mode). There are 32 bit and 64 bit registers as well. For more details on x86 CPU registers follow this link: https://en.wikibooks.org/wiki/X86_Assembly/16_32_and_64_Bits.
We have seen above that, to use display in TTY mode using interrupt call, we have to assign "0x0e" in ah register (Higher byte of AX register). The video service interrupt (INT 0x10) works is, it will look for the mode in ah register, if it is a TTY mode (0x0e) it will print the value in al register when interrupt has be called. So to print the word "HELLO", we have to load ah register with value 0x0e, and we have load letter by letter to al register and call interrupt using assembly instruction INT 0x10h.
So, assembly code to print word "HELLO" is (actual assembly file can be found here):
mov ah, 0x0e ; Teletype (TTY) mode.
mov al, 'H' ; letter 'H'
int 0x10 ; Raise the interrupt
mov al, 'E'
int 0x10
mov al, 'L'
int 0x10
int 0x10 ; here the register 'al' already has the value 'L'
mov al, 'O'
int 0x10
loop:
jmp loop
times 510-($-$$) db 0
dw 0xaa55
The hex dump of the above assembly code is:
00000000 b4 0e b0 48 cd 10 b0 45 cd 10 b0 4c cd 10 cd 10 |...H...E...L....|
00000010 b0 4f cd 10 eb fe 00 00 00 00 00 00 00 00 00 00 |.O..............|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
* (appended with 0's)
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
Screen shot of HELLO message on screen is:
It is the BIOS which will look for boot sector or boot loader of length 512 bytes in floppy disc or hard drive or CD/DVD or pen drive. From the previous post we know that, BIOS will identify the boot block of boot sector with the key word 0xaa55 as the end of 512 bytes. Now let us understand BIOS and just use the BIOS to play around by displaying some information on the screen.
BIOS (basic input/output system) is the is a piece of software which is implemented by the motherboard manufacturer to detect hardware connected to the motherboard and do some basic tests to check if the hardware connected is working as intended. When the simple tests for hardware failed or hardware not detected, BIOS will print the ERROR or WARNING information before proceeding with booting operating system. Error like "KEYBOARD NOT DETECTED" etc. Which means, BIOS has already detected hardware, after this BIOS will look for the boot loader or boot sector to load the operating system. Before writing actual boot loader to load operating system kernel etc, to understand the BIOS in depth, we can make use of some of the BIOS functionality. Displaying something on the screen is easiest thing to recognise that our code written in boot loader is working.
So, here I am planning to write word "HELLO" on screen using boot loader and BIOS. To do that we need to know how BIOS can help us to display word "HELLO" on the screen. As we are sure that BIOS has already detected display driver (as it displayed some information on the screen), BIOS can help us in displaying the word "HELLO" on screen.
BIOS uses the interrupt calls to do certain things. These interrupts can also be used by operating system for certain things using kernel. The BIOS interrupt calls details can be found in the link: https://en.wikipedia.org/wiki/BIOS_interrupt_call. As we are trying to print word "HELLO" on the screen, our interest is in "Video Service" related interrupt call (0x10), and we want use the Display driver in TTY/TeleType mode (print a character on screen and move the cursor to the next position). Interrupt can be triggered using assembly instruction INT. For Video service, we have to use INT 0x10. To use the INT 0x10 in TTY mode, the ah register should be assigned with value "0x0e". Now we need to know how to print each letter from word "HELLO" on the screen.
In x86 family there are CPU registers which will be used for many purposes. Some of the General purpose registers are AX, BX, CX and DX. Each of these are 16 bit registers. These 16 bit registers can be accessed in byte format like for ex: ah - higher byte of AX register and al - lower byte of AX register. These registers can be used in Real Mode which can be used by BIOS (Note: Before loading the Kernel BIOS will switch to Protected Mode. Click here to know the details or Real Mode and Protected Mode). There are 32 bit and 64 bit registers as well. For more details on x86 CPU registers follow this link: https://en.wikibooks.org/wiki/X86_Assembly/16_32_and_64_Bits.
We have seen above that, to use display in TTY mode using interrupt call, we have to assign "0x0e" in ah register (Higher byte of AX register). The video service interrupt (INT 0x10) works is, it will look for the mode in ah register, if it is a TTY mode (0x0e) it will print the value in al register when interrupt has be called. So to print the word "HELLO", we have to load ah register with value 0x0e, and we have load letter by letter to al register and call interrupt using assembly instruction INT 0x10h.
So, assembly code to print word "HELLO" is (actual assembly file can be found here):
mov ah, 0x0e ; Teletype (TTY) mode.
mov al, 'H' ; letter 'H'
int 0x10 ; Raise the interrupt
mov al, 'E'
int 0x10
mov al, 'L'
int 0x10
int 0x10 ; here the register 'al' already has the value 'L'
mov al, 'O'
int 0x10
loop:
jmp loop
times 510-($-$$) db 0
dw 0xaa55
The hex dump of the above assembly code is:
00000000 b4 0e b0 48 cd 10 b0 45 cd 10 b0 4c cd 10 cd 10 |...H...E...L....|
00000010 b0 4f cd 10 eb fe 00 00 00 00 00 00 00 00 00 00 |.O..............|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
* (appended with 0's)
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
Screen shot of HELLO message on screen is:
No comments:
Post a Comment