Re: 32bit protected mode init problem
Posted: Thu Jul 11, 2013 2:40 am
You mean I should do pmode enabling in kernel ??
The Place to Start for Operating System Developers
http://f.osdev.org/
Yes, in kernel or in stage 2 boot loader, not in stage 1.czlowieczek wrote:You mean I should do pmode enabling in kernel ??
It means that you should switch into protected mode whilst you are still in the first megabyte of memory, because that is all a sixteen bit instruction pointer can manage, and being in "flat" real mode doesn't change that - it only allows data accesses above 1mb.czlowieczek wrote:You mean I should do pmode enabling in kernel ??
Code: Select all
[bits 16]
[org 500h]
jmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt:
dd 0
dd 0
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end:
; naglowek
gdt_descr:
dw gdt_end - gdt - 1
dd gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
cli
lgdt [gdt_descr]
mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32]
xor eax, eax
mov esp, 0x8000
jmp 08h:start32
start32:
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov gs, ax
mov fs, ax
petla:
jmp petla
Code: Select all
mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32]
xor eax, eax ; really it's "xor ax,ax"
mov esp, 0x8000 ; "mov sp,8000h" and "dw 0"!!!
jmp 08h:start32 ; "jmp 0:start32" and "dw 8"!!!
Because, I want xor EAX not AX, and I want to move 8000h to ESP not to SP !!xor eax, eax ; really it's "xor ax,ax"
mov esp, 0x8000 ; "mov sp,8000h" and "dw 0"!!!
Code: Select all
[bits 16]
[org 500h]
jmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt:
dd 0
dd 0
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end:
; naglowek
gdt_descr:
dw gdt_end - gdt - 1
dd gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
cli
lgdt [gdt_descr]
mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32]
jmp 0x08:start32
start32:
xor eax, eax
mov esp, 0x8000
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov gs, ax
mov fs, ax
petla:
jmp petla
This results in:czlowieczek wrote:Ok, I moved it after start32 section, but jump to that code (jmp 0x08:start32) generates an error too.
My code:Code: Select all
dw 0xFFFF dw 0 db 0 db 10011010b db 11001111b db 0
Code: Select all
dq 0
dq 0xCF9A000000FFFF
dq 0xCF92000000FFFF
The [bits 32] is still in front of the jmp instruction.mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32]
jmp 0x08:start32
start32:
It seems to me that should be: dw gdt_end - gdt + 1.dw gdt_end - gdt - 1
Code: Select all
[bits 16]
[org 500h]
jmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gdt:
dq 0
dq 0xCF9A000000FFFF ;m12 descriptors
dq 0xCF92000000FFFF
gdt_end:
gdt_descr:
dw gdt_end - gdt + 1 ; +1
dd gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
cli
lgdt [gdt_descr]
mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32] ;before jump
jmp 0x08:start32
start32:
xor eax, eax
mov esp, 0x8000
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov gs, ax
mov fs, ax
petla:
jmp petla