32bit protected mode init problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

You mean I should do pmode enabling in kernel ??
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: 32bit protected mode init problem

Post by egos »

czlowieczek wrote:You mean I should do pmode enabling in kernel ??
Yes, in kernel or in stage 2 boot loader, not in stage 1.
If you have seen bad English in my words, tell me what's wrong, please.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: 32bit protected mode init problem

Post by Casm »

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.

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.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

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

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
I think that is the last issue in my code :)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: 32bit protected mode init problem

Post by egos »

What's this epidemic!

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.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

Egos, I don't understand your
xor eax, eax ; really it's "xor ax,ax"
mov esp, 0x8000 ; "mov sp,8000h" and "dw 0"!!!
Because, I want xor EAX not AX, and I want to move 8000h to ESP not to SP !!
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: 32bit protected mode init problem

Post by Gigasoft »

You have an incorrect bits 32 directive, causing the generation of wrong instructions. Move it to the start32 label.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

Ok, I moved it after start32 section, but jump to that code (jmp 0x08:start32) generates an error too.

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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: 32bit protected mode init problem

Post by egos »

It's not summer school here. Learn Intel manuals.

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.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

I am trying but bosch report an error at jumping to code (jmp 0x08:start32)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: 32bit protected mode init problem

Post by egos »

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.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: 32bit protected mode init problem

Post by Mikemk »

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         
This results in:
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
(If you want to modify, most programming calculators let you set or unset individual bits. I suggest you get one.)
mov eax, cr0
or eax, 1
mov cr0, eax
[bits 32]


jmp 0x08:start32

start32:
The [bits 32] is still in front of the jmp instruction.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: 32bit protected mode init problem

Post by egos »

m12, descriptors were correct.
If you have seen bad English in my words, tell me what's wrong, please.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: 32bit protected mode init problem

Post by Casm »

dw gdt_end - gdt - 1
It seems to me that should be: 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.
czlowieczek
Posts: 21
Joined: Wed Jul 10, 2013 3:00 am

Re: 32bit protected mode init problem

Post by czlowieczek »

I used them, but I had the same error
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
Post Reply