Page 1 of 1

Solved PAE paging problems

Posted: Sun Jul 01, 2018 3:36 am
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?

Re: PAE questions

Posted: Sun Jul 01, 2018 4:11 am
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.

Re: PAE questions

Posted: Sun Jul 01, 2018 12:56 pm
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

Re: PAE paging problems

Posted: Sun Jul 01, 2018 4:36 pm
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.

Re: PAE paging problems

Posted: Mon Jul 02, 2018 5:56 am
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.

Re: PAE paging problems

Posted: Mon Jul 02, 2018 8:31 am
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.

Re: PAE paging problems

Posted: Mon Jul 02, 2018 10:13 am
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. :)

Re: PAE paging problems

Posted: Mon Jul 02, 2018 10:15 am
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.

Re: PAE paging problems

Posted: Mon Jul 02, 2018 10:21 am
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.

Solved PAE paging problems

Posted: Mon Jul 02, 2018 11:55 am
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.

Re: Solved PAE paging problems

Posted: Mon Jul 02, 2018 10:06 pm
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!