1. I am using vmware as virtual machine , using floppy image to load my bootsector.
2. boot1.asm (file is also attached)
nasm boot1.asm -o boot
3. main.c as my c file (file attached)
gcc -o main main.c
4. I created an image file kernel.img by loading 'boot' at 1st sector
and 'main' is loaded at following sectors
PROBLEM
I am getting this output:
welcome to boot sector
downloaded sector 2,3 at 1000h
after this my it gets automatically reset and then same output and again reset and ...
..............................................................................................................................................
"boot1.asm"
Code: Select all
[BITS 16]
[ORG 0]
jmp start
driveno db 0
a db 'welcome to boot sector', 13,10,0
b db 'downloaded sector 2,3 at 1000h', 13,10,0
c db 'helloo',13,10,0
start:
mov [driveno],dl
mov ax,0x7c0
mov ds ,ax
mov gs, ax
mov ss,ax
mov sp,0x1000
mov si,a
call message
mov ax ,0
mov es,ax
mov bx,0x1000
;mov cx,2 ; no of sectors to read
;mov ax,1
;mov si,ax
read_kn:
call read_sector
mov si ,b
call message
enable_A20:
; mov dx,0x70
; in al,dx
; or al,0x80
; out dx,al
cli
;;enable a20 line
mov al,0xd1
out 0x64,al
mov al,0x03
out 0x60,al
xor ax,ax
mov ds , ax
lgdt [GDT]
;;turn on protected mode
mov eax,cr0
or al,1
mov cr0,eax
jmp 0x08: code.11
[BITS 32]
code:
.11: mov ax,0x10
mov ds,ax
mov ss,ax
mov esp,9000h
jmp 0x08:0x1000
stop : jmp stop
[BITS 16]
read_sector:
push ax
push cx
push dx
push bx
; mov ax,si
; xor dx,dx
;inc ax
mov cx,2 ; ch= cylinder cl= sector
xor dx,dx ; dh= head= 0
; mov bx,2
;mov dh,dl
;xor dl,dl
mov dl,[driveno] ; dl = drive no
pop bx
mov al,2
mov ah,2
int 0x13
pop dx
pop cx
pop ax
ret
message: ; Dump ds:si to screen.
lodsb ; load byte at ds:si into al
or al,al ; test if character is 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call BIOS
jmp message
done:
ret
GDT: dw gdt_limit ; null segment, used to store GDT metadata
dd GDT
dw 0
.cseg: dd 0x0000FFFF, 0x00CF9a00 ; code segment, 32-bit, 0 ;4GB
.dseg: dd 0x0000FFFF, 0x00CF9200 ; data segment, 32-bit, 0 ;to 4GB
gdt_limit equ $-GDT-1
; --------------------------
; boot seal
; --------------------------
[bits 16]
times 512-($-$$)-2 db 0x00
dw 0xaa55