Paging not detecting non-present directories

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
Primis
Member
Member
Posts: 62
Joined: Fri May 14, 2010 3:46 pm
Libera.chat IRC: Primis
Location: New York, NY
Contact:

Paging not detecting non-present directories

Post by Primis »

So I was rewriting a new kernel from scratch, when it came time to write the paging code, so I write a basic set for the first 4MB identity map, then I was going to expand from there. However, when I went to test my code in rebochs, the page table shows that the pages that should be marked as invalid are showing up as present, and are mapped to 0, I've tried this in bochs, and in virtual box to no avail. Is it my code or is it my compiler? (relevant code in paste)
http://pastebin.com/EA6gG2YS
"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
Image
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Paging not detecting non-present directories

Post by jnc100 »

Your code looks reasonable for 32 bit paging assuming you're already in protected mode when it runs. Out of interest, what type does unsigned represent in your compiler? And what exactly does bochs suggest is wrong? Is it the output from 'info tab'?

Regards,
John.
User avatar
Primis
Member
Member
Posts: 62
Joined: Fri May 14, 2010 3:46 pm
Libera.chat IRC: Primis
Location: New York, NY
Contact:

Re: Paging not detecting non-present directories

Post by Primis »

In my test code, I have it try and access a non-present address (specifically 0xA0000000) which should result in a page fault, however the code keeps executing without an issue, so I tested it in reBochs (great simulator with a built in debugger) and when I checked my page tables, all the pages in the directory above the mapped area were still showing as "present" but the pages were all redirecting to 0x00, it makes no sense. The table set up properly, just not the invalid pages...
"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
Image
User avatar
Primis
Member
Member
Posts: 62
Joined: Fri May 14, 2010 3:46 pm
Libera.chat IRC: Primis
Location: New York, NY
Contact:

Re: Paging not detecting non-present directories

Post by Primis »

And uh, 'unsigned' is shorthand for 'unsigned int' which defaults to 32 bits
"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
Image
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Paging not detecting non-present directories

Post by jnc100 »

Primis wrote:And uh, 'unsigned' is shorthand for 'unsigned int' which defaults to 32 bits
Not necessarily - C99 only defines unsigned int to be at least 2 bytes, ILP64 compilers have it as 8 bytes. If using a gcc cross compiler for x86 this is unlikely to be your problem (however this wasn't explicitly stated in your post), but for portability you can use the types in stdint.h.

The only other possible issue I can see is that gcc is optimising your memory accesses away. Are you able to inspect the raw bytes at 0x9c004, 0x9c008 etc to see that they contain what you think they contain?

Regards,
John.
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:

Re: Paging not detecting non-present directories

Post by Combuster »

jnc100 wrote:(...) the raw bytes at 0x9c004, 0x9c008 etc to see that they contain (...)
Without looking, the EBDA?

(And no, I really haven't bothered to look at the code yet. It just sounds like a really bad plan)
"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 ]
User avatar
SparrowOS
Member
Member
Posts: 72
Joined: Wed Nov 14, 2012 5:22 pm
Location: Vegas
Contact:

Re: Paging not detecting non-present directories

Post by SparrowOS »

I upgraded computers one time about 5 years ago. When booted to CD-ROM my PS/2 emulated keyboard and mouse worked but when booted to hard drive, my mouse didn't work. My boot-loaders were different for CD-ROM and mouse. Both boot-loaders copied themselves up to under 0xA0000 and loaded my 2nd stage at 0x10000. I was unaware there was such a thing as an EBDA.

It turns-out I got lucky because I learned my particular BIOS has a byte in EBDA 0x9FC30 which must be set to 0x01 or the mouse doesn't work.

Today, I load to under 0x90000 and I just shove a 0x01 into 0x9FC30 and pray.

I just upgraded this week and my new computer doesn't appear to support ATA/ATAPI port I/O.

I have been working for 9 years full-time and I have upgraded about 4 times, each time it failed to work. This time I can't fix it. I guess I'll be in VMWare from now on, which makes it pointless.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Paging not detecting non-present directories

Post by jnc100 »

Combuster wrote:
jnc100 wrote:(...) the raw bytes at 0x9c004, 0x9c008 etc to see that they contain (...)
Without looking, the EBDA?

(And no, I really haven't bothered to look at the code yet. It just sounds like a really bad plan)
I thought this at first when I saw his code, but checking both my virtualbox memory map and even with our wiki the EBDA tends to start at 0x9fc00 and the pages at 0x9c000 (where he puts the page directory) and 0x9d000 (first page table) should be okay. Obviously this is no substitute for actually checking the memory map on his own particular machine.

Regards,
John.
User avatar
Primis
Member
Member
Posts: 62
Joined: Fri May 14, 2010 3:46 pm
Libera.chat IRC: Primis
Location: New York, NY
Contact:

Re: Paging not detecting non-present directories

Post by Primis »

Turns out gcc optimizations were the blame, a quick -O0 on the compilation list worked wonders.
"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
Image
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Paging not detecting non-present directories

Post by bluemoon »

Primis wrote:Turns out gcc optimizations were the blame, a quick -O0 on the compilation list worked wonders.
If I were you I would not blame the optimization, but the misbehave code that messed it up.
Have you provide enough hints for gcc (eg. clobber list in sensitive instructions)?
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Paging not detecting non-present directories

Post by Jezze »

Unless you are doing something really freaky you most probably have a bug.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
Post Reply