long mode pagging tutorials?

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:

long mode pagging tutorials?

Post by HJED »

dose anyone know of any long mode paging tutorials because apparently it is different form normal pagging :D
.................................. um what should i put here .............................?..........................................
..... :D................
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Why do you need a tutorial? Read through the Intel docs. There are a few extra bits you need to set (IIRC when I last read the section on paging) and I think you may be forced to use 4MB pages? But, it all should be explained in detail in the Intel doc and it shouldn't be too different if you understand x86 paging.
My OS is Perception.
Avarok
Member
Member
Posts: 102
Joined: Thu Aug 30, 2007 9:09 pm

Post by Avarok »

Uh... Intel has long mode? I haven't seen a 64-bit intel CPU on the shelf yet.

AMD's been out with them for the last two years at the very least. I'd stick with AMD's instruction set if they differ at all, since anyone with 64-bit is using that.

I too am interested in reading a tutorial. 800 page PDF docs are for people who want to spend 6 months studying to write a 40 instruction sequence. I prefer to just get the layman's version, thanks.

Sincerely,
the Devil :twisted:
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Avarok wrote:Uh... Intel has long mode? I haven't seen a 64-bit intel CPU on the shelf yet.
Intel did try going in a different direction with their 64bit Itanium architecture, but they eventually decided to incorporate AMD's 64bit x86 enhancements.

http://en.wikipedia.org/wiki/X86_64#History_of_Intel_64

Many OS's still call their port "amd64", but they often support Intel processors anyway..
Last edited by Brynet-Inc on Sun Oct 14, 2007 7:26 am, edited 1 time in total.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Avarok wrote:Uh... Intel has long mode? I haven't seen a 64-bit intel CPU on the shelf yet.

AMD's been out with them for the last two years at the very least. I'd stick with AMD's instruction set if they differ at all, since anyone with 64-bit is using that.
Intel have supported 64-bit/long mode for ages (introduced in 2004, but possbly not widely available until 2005). It's almost identical to AMD's long mode (there's always minor differences between CPUs, even CPUs made by the same manufacturer).

For long mode, paging is very similar to a 32-bit CPUs using PAE. Pages are 4 KB (but you can use "large pages" that are 2 MB, and a mixture of 4 KB and 2 MB pages in the same address space).

There's also more levels to the paging structures - the page tables and page directory are identical to 32-bit paging with PAE, the "page directory pointer table" has been enlarged to 4 KB (for 32-bit paging with PAE it's only 4 entries or 32 bytes). On top of this they added a new table (the "Page Map Level 4"). CR3 contains the physical address of the PLM4, which contains physical addresses for page directory pointer tables, which contains addresses for page directories, which contains addresses for page tables (for 4KB pages) and/or addresses for large pages.

Also, AMD added the "NX" (No-eXecute) bit, and back-ported it to 32-bit PAE (e.g. a 32-bit OS that uses PAE can use the no-execute feature if it's running on a 64-bit CPU). This is another page protection flag (like the read/write page protection flags) that allows the OS to make it impossible for page/s (e.g. data, stack) to be executed. Intel have this too, but they call it the "XD" (eXecute Disable) bit.

Mostly, it's the exact same principles that 80x86 CPUs have been using for 20 years, that have been extended (with more paging structures) to make it work for a larger linear address space size. The same flags have the same meanings as they did for 32-bit CPUs (G, PAT, D, A, PCD, PWT, U/S, R/W, P), and things like TLB invalidation are identical.

Lastly, AMD have recently added "1 GB page" support. I'm not sure if this has reached the shelves yet, but from it's name it's easy to guess how it works - entries in the PLM4 may point to a huge page of RAM instead of pointing to a page directory (just like 2 MB pages, where page directory entries may point to a large page of RAM instead of pointing to a page table).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

Not sure about tutorial ..., once you know protected mode - long mode is simple. Paging maybe most puzzling.
Extremely simple and commented sources: http://flatassembler.net/examples.php
related thread http://board.flatassembler.net/topic.php?t=6206
+ intel manuals, once you see something in sources you press 'search' button for this thing in PDF file.
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Avarok wrote:I too am interested in reading a tutorial. 800 page PDF docs are for people who want to spend 6 months studying to write a 40 instruction sequence. I prefer to just get the layman's version, thanks.
They also deliver hard copies for free (as mentioned 100+ times on this forum).

Let's see if I can't figure this out..
- Open Volume 3A - System Programming Guide Part 2
- Scan contents: Protected-mode-memory management>Pae-enabled paging in IA-32e mode
- Turn to page 3-37

Okay, the following few pages (text + diagrams) show the exactly layout of the page directory and page table structures in memory, and step by step instructions. If you need a tutorial to work out that, then I'm afraid you won't get very far when one day you try to implement an ISO 9660 driver, or a network card driver with nothing more than a few tech sheets, and you'll be asking "but... Where's my tutorial? :cry:".
My OS is Perception.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Avarok wrote:Uh... Intel has long mode? I haven't seen a 64-bit intel CPU on the shelf yet.
I took it off the shelf last year June and put it in my computer, hope you don't mind...
HJED
Member
Member
Posts: 61
Joined: Tue Sep 04, 2007 4:18 am
Location: the world wide web
Contact:

Post by HJED »

paging in long mode seems to require about 3 extra tables but isn`t very clear about how to implement this
.................................. 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 »

Actually, only two extra tables. There's no essential difference between 32-bit and 64-bit paging (64-bit entries instead of 32 bit ones, and as said, two extra tables)

The intel manuals will tell you fine how those tables fit together. You must only write the necessary code. If you can do 32-bit paging, you can do 64-bit paging with little extra effort.

I suggest you read the manuals since your reply suggests you didn't even try to comprehend it.
"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 ]
Post Reply