Solved PAE paging problems

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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Solved PAE paging problems

Post by Octacone »

I am currently trying to implement PAE paging but something is wrong.
My kernel triple faults because everything is mapped 0x10E000 bytes too high, for e.g instead of 0x1000->0x1000 I see 0x1000->0x10E000.
After 3 days of bug hunting I can't find anything obvious left to fix.
Can you please take a look at my PAE data structures and tell me if there is something that doesn't look good: https://pastebin.com/E6DzWc3s?
Last edited by Octacone on Mon Jul 02, 2018 11:55 am, edited 3 times in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: PAE questions

Post by iansjack »

I can see a couple of potential problems with your use of bitfields (apart from the obvious one that you have allocated 65 bits in page_t).

1. Possible packing problems. As your structs are not packed it's possible that each bitfield is occupying 64 bits.

2. The order in which the compiler allocates bits for bitfields is not specified in the C standard. It varies between processor and compiler.

Either of these may not matter in your case, or one or both may apply - I don't know which compiler you are using. The easiest way to check is to look at the tables actually produced by your code. It should be fairly obvious if there is a problem. As for bitfields, I'd avoid them and use masks instead.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: PAE questions

Post by Octacone »

iansjack wrote:I can see a couple of potential problems with your use of bitfields (apart from the obvious one that you have allocated 65 bits in page_t).

1. Possible packing problems. As your structs are not packed it's possible that each bitfield is occupying 64 bits.

2. The order in which the compiler allocates bits for bitfields is not specified in the C standard. It varies between processor and compiler.

Either of these may not matter in your case, or one or both may apply - I don't know which compiler you are using. The easiest way to check is to look at the tables actually produced by your code. It should be fairly obvious if there is a problem. As for bitfields, I'd avoid them and use masks instead.
65? I went over that thing like 50 times and didn't notice it...
All of the issues are now fixed but nothing has changed.
I am actually writing this in C++ not C, don't know about the way C++ orders bitfields, but they worked for me in the past as far as paging goes.
I use GCC cross-compiler to compile my code.
I am looking at the tables and I don't see anything interesting.


Anyways, here is the rest of my code: https://pastebin.com/BRX2va4E
I hope somebody can notice something awfully wrong.
Edit: ignore line 47
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: PAE paging problems

Post by eryjus »

Did you find your 64-/65-bit problem? It's pretty evident based on the original pastebin. If you did, can you update your code so we are looking at the latest and greatest?

Also, you might want to add a static_assert since you are using C++. Something like the following would be a good addition in my opinion:

Code: Select all

static_assert(sizeof(page_t) == 8, "Something went wrong with the sizing of the page_t structure and needs to be corrected.");
This way, the compiler can help you by double checking the structure sizes for you.
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: PAE paging problems

Post by Octacone »

eryjus wrote:Did you find your 64-/65-bit problem? It's pretty evident based on the original pastebin. If you did, can you update your code so we are looking at the latest and greatest?

Also, you might want to add a static_assert since you are using C++. Something like the following would be a good addition in my opinion:

Code: Select all

static_assert(sizeof(page_t) == 8, "Something went wrong with the sizing of the page_t structure and needs to be corrected.");
This way, the compiler can help you by double checking the structure sizes for you.
Yeah I fixed the problem as soon as it was pointed out to me.
I didn't know that static_assert worked in a standalone environment, that is really handy.

Anyways here is that latest code: I know it's a lot of code but this way people will see it. Looks like people are very lazy when it comes to clicking.
Last edited by Octacone on Mon Jul 02, 2018 11:49 am, edited 1 time in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: PAE paging problems

Post by iansjack »

Looks like people are very lazy when it comes to clicking.
Being rude to other posters is not the best policy when asking for help.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: PAE paging problems

Post by alexfru »

iansjack wrote:
Looks like people are very lazy when it comes to clicking.
Being rude to other posters is not the best policy when asking for help.
Or you could turn it around by replacing clicking with debugging. :)
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: PAE paging problems

Post by Octacone »

iansjack wrote:
Looks like people are very lazy when it comes to clicking.
Being rude to other posters is not the best policy when asking for help.
That was not supposed to be rude. It is generally true, unrelated to this forum.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: PAE paging problems

Post by Octacone »

alexfru wrote:
iansjack wrote:
Looks like people are very lazy when it comes to clicking.
Being rude to other posters is not the best policy when asking for help.
Or you could turn it around by replacing clicking with debugging. :)
Well I don't think there are things left to debug. I checked if all the addresses are matching, if the tables look okay in memory, went over my code a lot of times, nothing.
Just impossible to figure out.
There are just no other implementations I could cross reference, only legacy paging, no PAE.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Solved PAE paging problems

Post by Octacone »

Solved!
Another stupid mistake, PAE wasn't enabled at all...
Oh boy my number had a ->bit<- extra, 33 instead of 32.
I was using 000000...b NASM notation.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: Solved PAE paging problems

Post by nullplan »

And that is why I despise binary notation, especially for large numbers. Telling the difference between 8 and 9 is way easier than telling the difference between 32 and 33. Hexadecimal for LIVE!
Carpe diem!
Post Reply