virtual memory problem

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
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

virtual memory problem

Post by stdcall »

I have a very strange behavior that doesn't make sense to me.
I'm writing a value to a virtual memory location I just mapped, and the value doesn't stick.
when I read back I get 0.

I assume that there's no issues with the paging setup, as I would expect a page fault to occur, I just can find a reason why this could happen.

Can you think of a possible bug/issue I have that can cause this ?

Configuration: x86 32 bit kernel running on qemu. paging enabled, without PAE.

The code for reference:

Code: Select all

printk("value before: %x\r\n", physmem.bitmap[0]);
physmem.bitmap[0] = 0xFF;
printk("value after: %x\r\n", physmem.bitmap[0]);
What I already tested:
* printk is ok, GDB also shows 0 in the memory.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: virtual memory problem

Post by Ch4ozz »

You should declare your map as volatile and turn off optimizations to make sure its executed in the right order and compiler doesnt store the value in a register.
Does it work without paging?
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: virtual memory problem

Post by stdcall »

Ch4ozz wrote:You should declare your map as volatile and turn off optimizations to make sure its executed in the right order and compiler doesnt store the value in a register.
Does it work without paging?
I'm building without optimization.
The assembly code looks good. I singled stepped it. It writes to memory.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: virtual memory problem

Post by jnc100 »

What is the physical address of the page you have mapped and are trying to write to? Are you trying to write to non-existant memory or a device rather than RAM?

Regards,
John.
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: virtual memory problem

Post by Velko »

Check the address of physical page virtual location is mapped to. AFAIK MMU does not check if physical memory at mapped location exists, so there will be no page fault.
If something looks overcomplicated, most likely it is.
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: virtual memory problem

Post by stdcall »

Velko wrote:Check the address of physical page virtual location is mapped to. AFAIK MMU does not check if physical memory at mapped location exists, so there will be no page fault.
Yep. that was the problem.... damn.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Post Reply