bootloader works in VirtualBox, but not on real machine
Posted: Sat Oct 22, 2011 3:32 pm
Hi all,
I`ve written some bootloader which should enable a20, set gdt table, enter protected mode, etc. The problem is that it works in VirtualBox, but on real machine in starts, but at the point it should load my kernel, it just breaks...
Here is look of my bootloader:
Uploaded with ImageShack.us
Sorry it`s not on eng, but the red marked string simple wont show up on real machine...
The thing is that I first write string "enabling a20 line" (1st string) and after that i write DONE, now that works, but when I try to write loading kernel... it wont write it, but after trying to load kernel he writes DONE...
heare is code 4 my bootloader
So I guess that the problem is loading kernel... I tried this on 64bit CPU, could that be the reason (I currently doesn`t have 32bit machine to test it). And i`ve been loading from USB, just to let u know...
Thanks
I`ve written some bootloader which should enable a20, set gdt table, enter protected mode, etc. The problem is that it works in VirtualBox, but on real machine in starts, but at the point it should load my kernel, it just breaks...
Here is look of my bootloader:
Uploaded with ImageShack.us
Sorry it`s not on eng, but the red marked string simple wont show up on real machine...
The thing is that I first write string "enabling a20 line" (1st string) and after that i write DONE, now that works, but when I try to write loading kernel... it wont write it, but after trying to load kernel he writes DONE...
heare is code 4 my bootloader
Code: Select all
;defines
%DEFINE kernelAddress 0x1000
%DEFINE kernelSector 3 ;1st is bootloader, 2nd is filetable
%DEFINE drive 0x80 ;HDD
[BITS 16] ;16bit code
[ORG 0x7C00] ;memory adress where the code will be loaded
;copy content of CS to DS and ES
MOV AX, CS
MOV DS, AX
MOV ES, AX
;set video mode to 80 x 25, 16 colors
MOV AL,03h
MOV AH,0
INT 10h
;print welcome message
MOV SI, WelcomeMsg ;string pointer goes to SI
CALL strPrint ;print string procedure
MOV SI, A20 ;string pointer goes to SI
CALL strPrint ;print string procedure
;Let BIOS enable A20
in al, 0x92
or al, 2
out 0x92, al
CALL printDone
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;THIS PART IS NOT PRINTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MOV SI, loadSectorStr ;string pointer goes to SI
CALL strPrint ;print string procedure
;
;main()
;
resetDrive:
MOV AH, 0 ;reset command
INT 13h ;call interrupt 13h
OR AH, AH ;check for error code
JNZ resetDrive ;try again if ah != 0
;;;;;;;;;;;;;;;;;;;
;load to kernel
MOV AX, 0
MOV ES, AX
MOV CL, kernelSector ;sector to be loaded
MOV AL, 30 ;!!!important number of sectors
CALL loadSector
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BUT THIS PART IS PRINTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
CALL printDone
;JMP kernelAddress:0000 ;go to kernel
MOV SI, plzWait ;string pointer goes to SI
CALL strPrint ;print string procedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;read keyboard scancode (blocking)
MOV AH, 0
INT 16h
;start protected mode
CLI ;disable interupts
XOR AX, AX ;AX = 0
MOV DS, AX ;DS = 0 - needed for lgdt
LGDT [gdtDescriptor] ;load the GDT descriptor
;set bit0 into CR0
MOV EAX, CR0
OR EAX, 1
MOV CR0, EAX
JMP 08h:clearPipe ;clear pipe from 16bit instructions by going to code segment by specified offset
loadSector:
;MOV BX,0 ;offset from ES
MOV BX, kernelAddress
MOV DL, drive ;drive
MOV DH, 0 ;head
MOV CH, 0 ;track
;read floppy/hard disk in CHS mode
MOV AH, 2
INT 0x13
JC exception
RET
;write error string if something went wrong, and reset drive
exception:
MOV SI, errStr
CALL strPrint
JMP resetDrive
;
;printing to screen
;
charPrint: ;character print
MOV AH, 0x0E ;inform BIOS that 1 character willbe printed
MOV BH, 0x00 ;page number
MOV BL, 0x0F ;color
INT 0x10 ;video interupt
RET ;go back to calling procedure
strPrint: ;string print
nextChar: ;loop
MOV AL, [SI] ;take byte from SI and store in AL
INC SI ;increment pointer in SI
OR AL, AL ;if(AL == 0)
JZ exit ;go to exit - end of function
CALL charPrint ;print character
JMP nextChar ;do all again
exit:
RET
;
;print DONE in green color
;
printDone:
MOV SI, done
call strPrint
RET
;data - 10=line feed, 13=carriage return - 10,13 = \n
WelcomeMsg db 'CSL@TFC bootloader v0.1', 10, 13, 10, 13, 0
plzWait db 10, 13, 'Pritisnite bilo koji taster za startovanje 32-bitnog moda i jezgra OS-a...', 10, 13, 0
errStr db 'Greska pri ucitavanju sektora.', 10, 13, 0
A20 db 'Omogucavanje maksimalne velicine memorije na 4GB ........................ ', 0
loadSectorStr db 'Ucitavanje jezgra ....................................................... ', 0
done db 'GOTOVO', 0
;GDT - goes between code and AA55 signature
[BITS 32] ;32-bit instructions
clearPipe:
MOV AX, 10h ;Save data segment identifyer
MOV DS, AX ;move a valid data segment into the data segment register
MOV SS, AX ;move a valid data segment into the stack segment register
MOV ESP, 090000h ;move the stack pointer to 090000h
JMP 08h:01000h
;JMP $ ;jump to here - infinite loop
;instead of JMP $(eats cpu time) we use cli(already activated) and hlt
;cli ; stop interrupts
here:
hlt
jmp here
;address of the GDT start
gdtStart:
;null segment reserved by intel, size of Qword
dq 0
;code segment, read/execute, non-conforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
;data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
;address of the GDT end
gdtEnd:
gdtDescriptor: ;GDT descriptor
dw gdtEnd - gdtStart - 1 ;size
dd gdtStart ;address of the GDT
TIMES 510 - ($ - $$) db 0 ;fill rest with 0
DW 0xAA55 ;signature that this is bootloader
Thanks