Bootloader code using at & t assembly syntax
Posted: Mon Apr 12, 2010 3:25 am
Hello,
I am using the following code for reading the kernel of 128 sectors.
when i allocate stack to the kernel and pass control to it,its code is not executed.Could you plz help me what is wrong in the following code??
Thanks,
########################################################
.equ BOOT_SEGMENT,0x07c0
.equ DISPLAY_SEGMENT,0xb800
equ SECTOR_SIZE, 0x0200
.text # Code segment
.globl _start # The entry point must be global
.code16 # Real mode
_start:
jmp over
os_size:
.long 0x00000000
drive_number:
.byte 0x00
max_sector:
.byte 0x00
max_head:
.byte 0x00
over:
movw $NEW_BOOT_SEGMENT, %ax #The address where the bios loaded the bootloader
movw %ax, %ds
movb %dl, drive_number #Address of the boot device
movb $0x08, %ah #getting parameters of boot device
int $0x13
andb $0x3f, %cl
movb %cl, max_sector
movb %dh, max_head
movw os_size, %bp #loop counter
movw $0x0002, %cx
movb $0x00, %dh
movw $0x0000, %ax
movw %ax, %es
movw $0x0100, %bx
read_sectors:
cmpw $0x0000, %bp #termination check
jng after_load
decw %bp
movw $0x0201, %ax #reading 1 sector at a time
int $0x13
jc error #if cf=1
cmpb max_sector, %cl
jnl next_head
incb %cl
jmp after_next
next_head:
movb $0x01, %cl
cmpb max_head, %dh
jnl next_cylinder
incb %dh
jmp after_next
next_cylinder:
movb $0x00, %dh
incb %ch
after_next:
addw $SECTOR_SIZE, %bx
jnc read_sectors
after_load:
movw $0x0003, %ax
int $0x10
mov $0x0e.%ah #after loading kernel at es:bx display a flag character
mov $'O',%al
int $0x10
mov $0x9000,%bx #allocate stack to the kernel
mov %bx,%ss
mov $0xfffe,%sp
ljmp 0x01000 #long jump to the kernel location
error:
mov $0x0e.%ah
mov $'E',%al
int $0x10
forever:
# Loop forever
hlt
jmp forever
I am using the following code for reading the kernel of 128 sectors.
when i allocate stack to the kernel and pass control to it,its code is not executed.Could you plz help me what is wrong in the following code??
Thanks,
########################################################
.equ BOOT_SEGMENT,0x07c0
.equ DISPLAY_SEGMENT,0xb800
equ SECTOR_SIZE, 0x0200
.text # Code segment
.globl _start # The entry point must be global
.code16 # Real mode
_start:
jmp over
os_size:
.long 0x00000000
drive_number:
.byte 0x00
max_sector:
.byte 0x00
max_head:
.byte 0x00
over:
movw $NEW_BOOT_SEGMENT, %ax #The address where the bios loaded the bootloader
movw %ax, %ds
movb %dl, drive_number #Address of the boot device
movb $0x08, %ah #getting parameters of boot device
int $0x13
andb $0x3f, %cl
movb %cl, max_sector
movb %dh, max_head
movw os_size, %bp #loop counter
movw $0x0002, %cx
movb $0x00, %dh
movw $0x0000, %ax
movw %ax, %es
movw $0x0100, %bx
read_sectors:
cmpw $0x0000, %bp #termination check
jng after_load
decw %bp
movw $0x0201, %ax #reading 1 sector at a time
int $0x13
jc error #if cf=1
cmpb max_sector, %cl
jnl next_head
incb %cl
jmp after_next
next_head:
movb $0x01, %cl
cmpb max_head, %dh
jnl next_cylinder
incb %dh
jmp after_next
next_cylinder:
movb $0x00, %dh
incb %ch
after_next:
addw $SECTOR_SIZE, %bx
jnc read_sectors
after_load:
movw $0x0003, %ax
int $0x10
mov $0x0e.%ah #after loading kernel at es:bx display a flag character
mov $'O',%al
int $0x10
mov $0x9000,%bx #allocate stack to the kernel
mov %bx,%ss
mov $0xfffe,%sp
ljmp 0x01000 #long jump to the kernel location
error:
mov $0x0e.%ah
mov $'E',%al
int $0x10
forever:
# Loop forever
hlt
jmp forever