|
|||
![]() |
|||
|
|||
|
This Tutorial teaches you how to Make boot floppy and print message on the screen
Let us see the booting sequence of intel PC.
1. When PC is switched on, BIOS starts booting and detects and initialize the hardware.
2. Bios will check the boot signature 0xAA55 at 511th location of the boot sector of first bootable media. If Bios find the signature, it will copy the first sector at location 0x7c00.
3. Then Bios will jump at this location. and the code written at this section starts executing and takes control of PC.
Thus when boot code takes control, CS register contains 0x7C00 and IP contains 0x0. Contents of other segment registers are undefined.
MYOS.S contains the code for booting the system with floppy.
In this code, first contents of CS is copied to DS (0x7c00) and ES is loaded with 0xB800 which is the location of video RAM. Then the msg1 and msg2 are copied at video RAM. At the end, using org 510 statement, boot sector signature 0xAA55 is located.
Makefile compiles the code, locate it using LD linker and build the floppy disk.
Please insert the floppy disk and issue make command. Reboot the system. You can see the MYOS message on the screen.
Code Zip File : tut1.zip
MYOS.S
# My First OS
# Building Boot Floppy
# 1. Compile file
# gcc -c myos.s
# 2. Link and Locate the file
# ld -Ttext 0x0 -s --oformat binary myos.o -o myos
# 3 Copying myos into boot sector of floppy
# dd if=myos of=/dev/fd0
# Size of myos is 512 bytes
.code16
.text
.global _start
_start:
#Initialize ds
movw $0x7c0, %ax
movw %ax, %ds
# %ds = 0x7c0
#Initialize es
movw $0xB800,%ax
movw %ax, %es
# Initilized es to 0xb800 display base address
#displaying msg1
movw $(end_msg1-msg1), %cx # length
of string msg1
movw $msg1, %si
# offset of msg1 from 0x7c0 base
movw $160*11+5*2,%di
# offset of destination from 0xb800
1: movb (%si),%al
# Move the contents pointed by si in al
movb %al,%es:(%di)
# Move the al contents at address referenced by di
incw %si
# increment si
incw %di
# increment di
movb $0x42,%es:(%di)
# set background and forground color
incw %di
# increment di
decw %cx
# loop
jnz 1b
#displaying msg2
movw $(end_msg2-msg2), %cx # length
of string msg1
movw $msg2, %si
# offset of msg1 from 0x7c0 base
movw $160*12+5*2,%di
# offset of destination from 0xb800
1: movb (%si),%al
# Move the contents pointed by si in al
movb %al,%es:(%di)
# Move the al contents at address referenced by di
incw %si
# increment si
incw %di
# increment di
movb $0x42,%es:(%di)
# set background and forground color
incw %di
# increment di
decw %cx
# loop
jnz 1b
#halting the machine
hlt
msg1: .ascii " ************ MYOS by Madhuri ************* "
end_msg1:
msg2: .ascii " ***** Remove floppy and Reboot the machine ********** "
end_msg2:
.org 510
boot_flag: .word 0xAA55
Makefile
install : myos
dd if=myos of=/dev/fd0
myos : myos.o
ld -Ttext 0x0 -s --oformat binary myos.o -o myos
myos.o : myos.s
gcc -c myos.s
clean :
rm -f myos myos.o
Code Zip File : tut1.zip
For any help Contact : ajaylohia_linux@rediffmail.com