but it is not work on my vmware
when i set cr0 (PE) bit, it is crash
i was try to figure out it myself, but i can't.
Please help me, What i missed...
This code makes me crazy..... oh god...
Code: Select all
; Bootsector
%define BOOTSEG 0x07c0 ; 0x07c0:offset => 0x7c00 + offset
%define INITSS 0x1000
%define INITSP 0xffff
%define INITSEG 0x2000
[ORG 0]
[BITS 16]
; Our size of boot code is 512 bytes (0x0200)
; We will load second code to 0x09c0(0x07c0 + 0x0200)
; After this code we will load second code for testing protected mode
jmp entry ; jump to our private boot code!!
nop ; someone use this for compatiblity of assembler
; Starting point
; ===============================================
entry:
cli ; disable interrupts
mov ax, INITSS
mov ss, ax
mov sp, INITSP
cld ; clear direction
mov ax, INITSEG
mov es, ax ; ES == 0x2000
xor di, di
mov ax, BOOTSEG
mov ds, ax ; DS == 0x07c0
xor si, si
mov cx, 0x0100 ; 256
; DS:SI => ES:DI
; BOOTSEG => INITSEG
; movsb == 1
; movsw == 2
; movsd == 4
repz movsw ; repz : do 'movsw' 256 times => 256 * 2 = 512
jmp INITSEG:main
main:
; ok, we jumped from BOOT Segment
; so we have to set our ds to here
mov ax, INITSEG
mov ds, ax
; Tell me something :)
mov si, bootmsg
call print
; I will load second sector to 0x2000:0x0000
; mov ax, 0x2000 ; will be the base address of codesel
; mov es, ax ;
; mov bx, 0x0 ;
; mov al, 1 ;
; mov cl, 2 ;
; call read_sector
; load Global Descriptor Table
lgdt [gdt_ptr]
; enter the protected mode
mov eax, cr0
or al, 1 ; toggle PE bit
mov cr0, eax
bits 32
jmp codesel:pmode ; now we have code descriptor and selector, so we will use it for far jump
pmode:
jmp pmode
bits 16
; ----------------------------------------------------------
; Functions
; ==========================================================
print:
cld ; direction forward
lodsb ; next character ; ds:si
cmp al, 0
jz p_done;
mov ah, 0x0E
mov bx, 0x0007
int 0x10
jmp print
p_done:
ret
waitkey:
mov ah,0
int 0x16
ret
read_sector:
; es:bx = address of destination (memory)
; al = sector count
; cl = sector start number
mov ah, 0x02
mov ch, 0
mov dl, [bootdrive]
mov dh, 0
int 0x13
jc read_sector
ret
; End of code section, I don't want to execute below data
; =====================
; Data section
; =====================
bootdrive db 0
bootmsg db 'SJOS v0.1', 13, 10, 0
pressmsg db 'Press any key', 13, 10, 0
gdt_ptr
dw end_gdt - begin_gdt - 1 ; limit
dd begin_gdt ; base address
begin_gdt
dd 0x00000000 ; null descriptor
dd 0x00000000
; these two descriptors are indicate same data, becuase we will implement the flat model
codesel equ $-begin_gdt ; start address of code descriptor(index), we will use this for selector(cs)
code0
dw 0xffff ; segment limit
dw 0x0000 ; base address
db 0x00
db 0x9a ; 10011010 - priv level 0, code
db 0xcf ; 11001111 - granurlarity
db 0x00 ; 00000000 - base address
datasel equ $-begin_gdt ; start address of data descriptor(index), we will use this for selector(ds)
data0
dw 0xffff
dw 0x0000
db 0x00
db 0x92
db 0xcf
db 0x00; Bootsector