Hi , I tested your code. There are some things you have overlooked.
For eg: when you have
Code: Select all
[BITS 16]
mov ax , Label1 ; Here Label1 is a 16 bit address
Label1:
.....some-code.....
Code: Select all
[BITS 32]
mov ax , Label1 ; Here Label1 is a 32 bit address
Label1:
.....some-code.....
Code: Select all
[BITS 16]
mov ax , Label1 ; Here Label1 is a 32 bit address. SO THIS WILL RESULT IN THE LOWER 16 BITS OF THE
; ADDESS OF LABEL1 being entered into ax
mov eax, Label1 ; Here you get what is expected
[BITS 32]
Label1:
.....some-code.....
Code: Select all
[BITS 32]
mov ax , Label1 ; Here Label1 is a 16 bit address. SO THIS WILL RESULT IN THE LOWER 16 BITS OF THE
; ADDESS OF LABEL1 being entered into ax. THIS IS AS EXPECTED
mov eax, Label1 ; Here you get what is NOT expected. The higher EAX is now garbage
[BITS 16]
Label1:
.....some-code.....
Jmp dword 8:next ; This is a special opcode that takes 8 as Cs and the 32 bit address of next because next
; next comes under the section [BITS 32]
[BITS 32]
next:
Now What you have done in your code is that you tried filling the values of the gdtptr at wrong addresses like
Code: Select all
mov dword [gdtptr+2], ecx ; which gets the 16 bit address of gdtptr and adds 2 which is not what you want
Also it seems that your gdt table is also wrong ... I didnt check it but when I inserted my GDT it worked.
So a clean version would be i.e only taking into account getting into protected mode would be
Code: Select all
[BITS 16]
[ORG 0x7C00]
jmp 0:start
start:
cli
mov ax , 0
mov ds , ax ;################ SET DS TO 0
lgdt [GDTR] ; charge la gdt
mov eax, cr0
or ax, 1
mov cr0, eax ; PE mis a 1 (CR0)
jmp dword 8:protected
[BITS 32]
protected:
mov ax, 0x10 ; segment de donne
mov ds, ax
mov fs, ax
mov gs, ax
mov es, ax
mov ss, ax
mov esp, 0x9F000
jmp $ ; if I do that I see my boot message
jmp 0x8:0x1000 ; It restart my real computer & works in VMs
GDTR :
dw GDT_End - GDT - 1 ; 16 Bit Size Limit Of GDT
dd GDT ; 32 Bit Linear Address Of GDT
GDT :
dd 0x00000000 , 0x00000000 ; Null
dd 0x0000FFFF , 0x00CF9A00 ; Kernel Code
dd 0x0000FFFF , 0x00CF9200 ; Kernel Data
dd 0x0000FFFF , 0x00CFFA00 ; User Code
dd 0x0000FFFF , 0x00CFF200 ; User Data
GDT_End :
times 510-($-$$) db 144
dw 0xAA55