Page 1 of 1

Paging problem (memory is filled after every read)

Posted: Thu Jan 22, 2009 8:49 am
by tarrox
Hello,
I am trying to implement Paging and for so far the paging works. I have paging enabled and there arent any errors so far.
It is also no problem to map a page to the virtual address, but now i get a strange problem. I can give a pointer the address so far, but when i am accessing the content, it is making strange things. I can write to the address, but after i looked what is written in it, the accessed memory is written full with 1. For example:

Code: Select all

//Maps a page
map_page(paging.get_kernel_directory(), (u32int*)0x10000000, (u32int*)memory.get_page(NMEMORY::UPPER_MEM), FPAGING_IS_WRITEABLE);
//a Pointer
u32int* tmp;
//gives the pointer an address of the new mapped virtual space
tmp = (u32int*)0x10000010;
//prints the given address, it is correct
std::cout<<"Addr: "<<std::HEX<<(u32int)tmp<<"\n";
//prints the content of the address space, it should be 0x0, because it is a new page, but it is 0xFFFFFFFF
std::cout<<"inhalt: "<<std::HEX<<*tmp<<"\n";
//Now i am writing into the memory
*tmp = 10;
//It worked he prints 0xA
console.writeint_hex(*tmp);
//It stoped working it prints 0xFFFFFFFF, why the hell?
console.writeint_hex(*tmp);
//Now i could make the thing over and over^^
I though it could be the virtual Machine i am testing on but with bochs and VirtualPC it is the same error. And in VirtualBox it only changes OxFFFFFFFF to 0x0.

I dont know where the problem is and what the problem is. I hope someone of you knows maybe the problem, or has an idea what to do. The code itself ended up being pretty much the same as the new code of JamesM's paging code, but if you want i can post it.

MfG Tarrox.

Re: Paging problem (memory is filled after evry read)

Posted: Thu Jan 22, 2009 9:08 am
by Brendan
Hi,

Try this piece by itself:

Code: Select all

u32int* tmp;
tmp = (u32int*)0x10000010;
std::cout<<"Addr: "<<std::HEX<<(u32int)tmp<<"\n";
I'm guessing that paging has nothing to do with the problem... ;)


Cheers,

Brendan

Re: Paging problem (memory is filled after every read)

Posted: Thu Jan 22, 2009 9:20 am
by thepowersgang
Try running it with the Bochs debugger and place a write watch point on the physical address that tmp points to (use `watch write <physaddr>`)

Re: Paging problem (memory is filled after every read)

Posted: Thu Jan 22, 2009 10:03 am
by Combuster
And in VirtualBox it only changes OxFFFFFFFF to 0x0.
Sounds like accessing unconnected memory...

Re: Paging problem (memory is filled after every read)

Posted: Thu Jan 22, 2009 1:19 pm
by tarrox
I tried the bochs debugger and found out that when i want to access a mapped place, i get an "Write outside the limits of physical memory" Error, which is ignored. I think this is the Problem, but how do i get rid of it, or better question what is my kernel doing to get something like this. Is it an error of the Paging or somewhere else.

Re: Paging problem (memory is filled after every read)

Posted: Thu Jan 22, 2009 4:24 pm
by Firestryke31
It's an error with your paging code, because you're trying to write to RAM you don't have (or isn't really RAM). There are several ways to find how much RAM you really have, as well as where usable RAM is. One common way is to drop to real mode temporarily to use a BIOS function call (can't remember exactly which one, someone else will say) or, more often, to have it passed in by a boot loader (which most likely uses the BIOS function call). Also, remember that in the tables and directories, the value you write are the physical address (where it really is), and where you write it corresponds to the virtual address (where you want it).