IA-32e mode

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.
Post Reply
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

IA-32e mode

Post by HJED »

Hi
I am trying to write an OS that runs in IA-32e mode i have read the intel documantation on this

at curent my code is in protected mode
it has
gdt , idt , irqs, a keboard layout , and i can print mesages to the screan

it then tries to enable pagging and long mode(it makes seans to put them together becouse u change pagging setting to enable long mode)

paging is not enabled
i am using the NASM assembler
could some one pleas tell me how to
2. Enable physical-address extensions (PAE) by setting CR4.PAE = 1.
and
4. Enable IA-32e mode by setting IA32_EFER.LME = 1.
PS i have figured out how to do the other steps :D
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

use this example, you'll save yourself lots of time
http://flatassembler.net/examples/longmode.zip

there was corresponding thread about these examples here http://board.flatassembler.net/forum.php?f=11

fasm is similar to nasm i think.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Re: IA-32e mode

Post by bluecode »

AT&T assembler:
HJED wrote:2. Enable physical-address extensions (PAE) by setting CR4.PAE = 1.

Code: Select all

/* Set cr4.PAE */
mov %cr4, %eax
or $0x20, %eax
mov %eax, %cr4
4. Enable IA-32e mode by setting IA32_EFER.LME = 1.

Code: Select all

/* Set EFER.LME */
mov $0xC0000080, %ecx
rdmsr
or $0x100, %eax
wrmsr
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

Thank you :D
i foud i site that explanes chaging AT&T asm in to intel asm and now it works thanks
for your code it was realy help full :D :D :D
:D :P :)
here is my code for swiching to long mode for others who have a smilar problem
c++

Code: Select all

 
long_mode1(); // start long mode int
    write_cr3((unsigned long *)0x9C000); // put that page directory address into CR3
    long_mode2(); // pagging int 2
    write_cr0( (unsigned long *)((unsigned long) read_cr0() | (unsigned long) 0x80000000)); // set the paging bit in CR0 to 1
NASM

Code: Select all

[global _read_cr0]
_read_cr0:
	mov eax, cr0
	retn

[global _write_cr0]
_write_cr0:
	push ebp
	mov ebp, esp
	mov eax, [ebp+8]
	mov cr0,  eax
	pop ebp
	retn

[global _read_cr3]
_read_cr3:
	mov eax, cr3
	retn

[global _write_cr3]
_write_cr3:
	push ebp
	mov ebp, esp
	mov eax, [ebp+8]
	mov cr3, eax
	pop ebp
	retn
[global _long_mode1]
_long_mode1:
  ; cr0.PG is alread at 0 

  ; Set cr4.PAE 
mov eax , cr4
or eax , 0x2000000
mov cr4 , eax  
  ; L4PT loaded in pagging.cpp
  retn
[global _long_mode2]
_long_mode2:
  
;Set EFER.LME
mov  ecx , 0xC0000080
rdmsr
or  eax , 0x100
wrmsr 
  rent
  ;rest in paging

once again thanks for your help :D
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

HJED wrote:

Code: Select all

  rent
Typo?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

Combuster wrote:
HJED wrote:

Code: Select all

  rent
Typo?
no it was in a pagging tutorial which had lot of erros
.................................. um what should i put here .............................?..........................................
..... :D................
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

HJED wrote:
Combuster wrote:Typo?
no it was in a pagging tutorial which had lot of erros
Well, it makes me wonder why you post code of which you know is incorrect. :roll:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

u assume i already new that orginaly i only found out it had lots of errors after i posted this :x
.................................. um what should i put here .............................?..........................................
..... :D................
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

still you should make an effort to check for errors before posting, both gramma and programing.

I usually write a post and then hit the "submit" button forgetting to read it through first.
and then i use alot of time editing the post. well maybe not alot of time, but anyways.

Code: Select all

10 GOTO 30
20 CORRECT ERROR
30 LOOK FOR ERROR!
40 IF ERROR FOUND GOTO 20
50 HIT SUBMIT
I never did learn basic but you get the message...

THIS POST BEEN EDITED "1" TIME!
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

what you just said dose`nt make sense the paging post wasn`t working i was going thought issue 1 @ a time the paging code dose now work and i din`t know that rent thing was an error until someone in this post told me because asm did`nt complain abut it
.................................. um what should i put here .............................?..........................................
..... :D................
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

Paying rent will keep you from getting booted.
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

whattttttt?
.................................. um what should i put here .............................?..........................................
..... :D................
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

paying rent will keep you from getting booted, but you could allso not pay rent and uffer the consequeses (damn i cant spell)

e.g. paying the rent is a smart thing to do.
Post Reply