Why the memory cannot be written?

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
bayesian
Posts: 3
Joined: Mon Jun 22, 2020 6:04 pm

Why the memory cannot be written?

Post by bayesian »

I have already implemented physic allocation and paging. But I found otherwise I got the right virtual address of the memory, I cannot write the memory.
It's my testing code, physic_alloc will return physic address of page(s) witch can fit request size.
And interrupt is active, paging fault handler also is setted.

Code: Select all

	int* arr = (int*) ((uint32_t)physic_alloc(45*sizeof(int)) + PAGE_OFFSET);
	for(int i = 0; i<12; ++i) {
		arr[i] = i;
	}

	for(int i = 0; i<12; ++i) {
		printf("%d\n", arr[i]);
	}
	arr[2] = 4;
The testing outputs no error or exception, but

Code: Select all

0
0
0
... ('0' * 12)
In another test, I try to set value of members of a struct, but there is no effect.
The target address, 0xe00d9000, its page directory entry is

Code: Select all

pdg_k[0x380] = 0x18e003
page entry is

Code: Select all

tables[0x80][0xd9] = 0x200d9003
So the paging target is right, and RW bit is true, why the page cannot be wrote?

It's my code to enable paging. 0x00000000 -> 0xC0000000

Code: Select all

uint32_t cr0;
asm volatile ("mov %%cr0, %0" : "=r" (cr0));
cr0 |= 0x80000000;
asm volatile ("mov %0, %%cr0" : : "r" (cr0));
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why the memory cannot be written?

Post by Octocontrabass »

What does the firmware memory map say?
Post Reply