32bit protected mode init problem
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
You mean I should do pmode enabling in kernel ??
Re: 32bit protected mode init problem
Yes, in kernel or in stage 2 boot loader, not in stage 1.czlowieczek wrote:You mean I should do pmode enabling in kernel ??
If you have seen bad English in my words, tell me what's wrong, please.
Re: 32bit protected mode init problem
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 ??
When, in olden days, real mode MS-DOS programs had their code sections restricted to the first 1mb, it wasn't because they had taken a vow of poverty, so far as memory was concerned.
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
Ok, I found better bootloader and my kernel is working...... partly. My kernel turn protected mode on and load gdt but crash after trying to reload any segmen ds,es ... and when i'm trying to reload cs by jumping (jmp 08h:start32) it crashes too. Bootloader load my kernel at adress 0000h:500h
I think that is the last issue in my code
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
Re: 32bit protected mode init problem
What's this epidemic!
The following code is very bad.
The following code is very bad.
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"!!!
If you have seen bad English in my words, tell me what's wrong, please.
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
Egos, I don't understand your
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"!!!
Re: 32bit protected mode init problem
You have an incorrect bits 32 directive, causing the generation of wrong instructions. Move it to the start32 label.
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
Ok, I moved it after start32 section, but jump to that code (jmp 0x08:start32) generates an error too.
My code:
My code:
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
Re: 32bit protected mode init problem
It's not summer school here. Learn Intel manuals.
To run 32-bit code you should jump to 32-bit code.
To run 32-bit code you should jump to 32-bit code.
If you have seen bad English in my words, tell me what's wrong, please.
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
I am trying but bosch report an error at jumping to code (jmp 0x08:start32)
Re: 32bit protected mode init problem
As I said, my code works fine. I tested it in Bochs.
If you have seen bad English in my words, tell me what's wrong, please.
Re: 32bit protected mode init problem
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
0xFFFF0000009ACF00
base: 0xFF00009A
limit: 0xFCF00
flags:
GR=true SZ=true L=true false=true
access:
pr=false privilege=ring0 true=false
code/data=data direction=up read/write=false accessed=false
Try:
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:
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: 32bit protected mode init problem
m12, descriptors were correct.
If you have seen bad English in my words, tell me what's wrong, please.
Re: 32bit protected mode init problem
It seems to me that should be: dw gdt_end - gdt + 1.dw gdt_end - gdt - 1
If your gdt was only 8 bytes long, and it began at (say) 16h the second byte would be, 17h, the third byte 18h, and so on up to 1dh
1dh - 16h = 7, which is one short of what it should be.
Last edited by Casm on Fri Jul 12, 2013 11:28 am, edited 2 times in total.
-
- Posts: 21
- Joined: Wed Jul 10, 2013 3:00 am
Re: 32bit protected mode init problem
I used them, but I had the same error
Code:
Code:
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