Page 1 of 1

physical memory access on addresses larger than 4GB (64bit)

Posted: Mon Jan 15, 2018 2:24 am
by algawi86
Hi,
I''m having some problems with memory access,
my os is setup as follows on VMWare

I've setup the machine to 4GB and i got the following address map from e820
edit:
the same problem exists even when i use 8GB of ram.

the format is base, limit, type

Code: Select all

0000000000009F400 000000000009FFFF 0002
000000000000CE000 00000000000CFFFF 0002
000000000000DC000 00000000000FFFFF 0002
00000000000100000 00000000BFEDFFFF 0001
000000000BFEE0000 00000000BFEFEFFF 0003
000000000BFEFF000 00000000BFEFFFFF 0004
000000000BFF00000 00000000BFFFFFFF 0001
000000000F0000000 00000000F7FFFFFF 0002
000000000FEC00000 00000000FEC0FFFF 0002
000000000FEE00000 00000000FEE00FFF 0002
000000000FFFE0000 00000000FFFFFFFF 0002
00000000100000000 000000013FFFFFFF 0001
as you can see the last region is accessible and i wish to write to that region.
I've setup my machine to long mode with a cr3 which has identity mapping accross 16GB of ram
and still the machine crashes when i try and access that region.

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 2:55 am
by iansjack
If you only have 4GB of RAM and your memory is identity mapped, you obviously can't access RAM above 4GB.

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 2:59 am
by algawi86
the code for building the cr3 does not take into account the actual size of ram, it just maps 16GB of ram to itself.
even when i set the machine to 8GB i get the same results.

So in reality when e820 states i have an address which is accessible i should be able to read and write from it.

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 3:29 am
by iansjack
How do you expect to be able to read/write memory that doesn't exist?

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 3:32 am
by algawi86
if e820 tells me the range 00000000100000000:000000013FFFFFFF is accessible, why can't i use it ?

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 4:35 am
by iansjack
It's always possible that there is an error in your memory-detection routine. It shouldn't tell you that non-present memory is accessible.

It's also possible that there is an error in your page-mapping code.

The simpe fact remains - if memory isn't present then you can't read or write it.

Re: physical memory access on addresses larger than 4GB (64b

Posted: Mon Jan 15, 2018 10:19 am
by xenos
The memory map looks correct to me - I get the same in my 4GB laptop (also under Linux). Obviously RAM is located at physical addresses 0-3GB and 4-5GB, to have a memory hole for other things in the 3-4GB area. The RAM above that hole should be accessible.

Re: physical memory access on addresses larger than 4GB (64b

Posted: Tue Jan 16, 2018 10:59 am
by Octocontrabass
iansjack wrote:The simpe fact remains - if memory isn't present then you can't read or write it.
You can, but it won't do anything useful. There's no "nonexistent hardware" exception in x86.

If your code is crashing due to an exception, then you've most likely configured the page tables wrong.