I'm developing a minimal x86-64 OS from scratch and I am attempting to detect memory to be able to map the higher half of the virtual address space to all physical memory available.
From this link: https://www.kernel.org/doc/html/latest/x86/x86_64/mm.html, I think this is what the Linux kernel does also. Probably to be able to reach all physical addresses if the need arises at some point.
ffff888000000000 | -119.5 TB | ffffc87fffffffff | 64 TB | direct mapping of all physical memory (page_offset_base)
I want to do the same in my kernel but I need to detect the amount of physical memory installed currently on my system. I can always use the Memory Map returned by UEFI but this doesn't necessarily tell me how much memory is actually installed.
I'm emulating on QEMU and I thought of locating the SMBIOS table to do that. If I print memory from 0xf0000 to 0xfffff, I don't find the signature of the SMBIOS table:
(gdb) dump memory result.bin 0xf0000 0xfffff
user@user-System-Product-Name:~$ hexdump -C result.bin
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
0000fd00 ff ff ff ff ff ff ff ff 2e 06 a0 1b 79 c7 82 45 |............y..E|
0000fd10 85 66 33 6a e8 f7 8f 09 08 aa 01 08 f8 02 00 f8 |.f3j............|
0000fd20 0c 00 00 19 00 00 00 00 00 00 00 00 d4 02 00 19 |................|
0000fd30 31 c0 2d 00 10 00 00 3d 00 00 00 ff 72 33 81 78 |1.-....=....r3.x|
0000fd40 10 78 e5 8c 8c 75 eb 81 78 14 3d 8a 1c 4f 75 e2 |.x...u..x.=..Ou.|
0000fd50 81 78 18 99 35 89 61 75 d9 81 78 1c 85 c3 2d d3 |.x..5.au..x...-.|
0000fd60 75 d0 83 78 24 00 75 ca 89 c3 03 58 20 75 c3 eb |u..x$.u....X u..|
0000fd70 09 b8 bf bf bf bf 89 c5 eb fe 89 c5 e9 37 02 00 |.............7..|
0000fd80 00 31 db 89 de 89 e8 66 8b 5d 30 01 d8 72 3b eb |.1.....f.]0..r;.|
0000fd90 03 40 72 36 85 c0 74 32 83 c0 07 72 2d 24 f8 8a |.@r6..t2...r-$..|
0000fda0 58 17 f6 c3 20 74 ea 8b 48 14 81 e1 ff ff ff 00 |X... t..H.......|
0000fdb0 09 c9 74 dd 01 c1 74 02 72 d7 80 78 12 03 75 06 |..t...t.r..x..u.|
0000fdc0 eb 17 85 c0 75 06 89 c8 eb ca 31 c0 89 c6 85 f6 |....u.....1.....|
0000fdd0 75 02 74 fe e9 e4 01 00 00 85 c0 74 5f 83 c0 18 |u.t........t_...|
0000fde0 39 c8 73 58 80 78 03 10 74 1b 80 78 03 12 74 32 |9.sX.x..t..x..t2|
0000fdf0 8b 18 81 e3 ff ff ff 00 01 d8 72 40 83 c0 03 72 |..........r@...r|
0000fe00 3b 24 fc eb db 83 c0 04 66 81 38 4d 5a 75 2d 0f |;$......f.8MZu-.|
0000fe10 b7 58 3c 01 c3 81 3b 50 45 00 00 75 1f 03 43 28 |.X<...;PE..u..C(|
0000fe20 eb 1f 83 c0 04 89 c3 66 81 3b 56 5a 75 0e 03 43 |.......f.;VZu..C|
0000fe30 08 83 c0 28 0f b7 5b 06 29 d8 eb 05 b8 00 00 00 |...(..[.).......|
0000fe40 00 e9 7c ff ff ff eb 60 0f 20 e0 0f ba e8 05 0f |..|....`. ......|
0000fe50 22 e0 b9 80 00 00 c0 0f 32 0f ba e8 08 0f 30 0f |".......2.....0.|
0000fe60 20 c0 0f ba e8 1f 0f 22 c0 ea 70 fe ff ff 18 00 | ......"..p.....|
0000fe70 e9 4d 01 00 00 b8 00 00 00 80 0f a2 3d 1f 00 00 |.M..........=...|
0000fe80 80 7c 21 b8 1f 00 00 80 0f a2 0f ba e0 01 73 14 |.|!...........s.|
0000fe90 b9 31 01 01 c0 0f 32 0f ba e0 00 73 07 89 d8 83 |.1....2....s....|
0000fea0 e0 3f eb 02 31 c0 eb 02 eb cb 31 d2 85 c0 74 06 |.?..1.....1...t.|
0000feb0 83 e8 20 0f ab c2 b9 00 18 00 00 31 c0 89 04 8d |.. ........1....|
0000fec0 fc ff 7f 00 e2 f7 c7 05 00 00 80 00 23 10 80 00 |............#...|
0000fed0 89 15 04 00 80 00 c7 05 00 10 80 00 23 20 80 00 |............# ..|
0000fee0 89 15 04 10 80 00 c7 05 08 10 80 00 23 30 80 00 |............#0..|
0000fef0 89 15 0c 10 80 00 c7 05 10 10 80 00 23 40 80 00 |............#@..|
0000ff00 89 15 14 10 80 00 c7 05 18 10 80 00 23 50 80 00 |............#P..|
0000ff10 89 15 1c 10 80 00 b9 00 08 00 00 89 c8 48 c1 e0 |.............H..|
0000ff20 15 05 e3 00 00 00 89 04 cd f8 1f 80 00 89 14 cd |................|
0000ff30 fc 1f 80 00 e2 e5 b8 00 00 80 00 0f 22 d8 e9 05 |............"...|
0000ff40 ff ff ff fa bb 00 f0 8e db bb 7a ff 2e 66 0f 01 |..........z..f..|
0000ff50 17 66 b8 23 00 00 40 0f 22 c0 66 ea 62 ff ff ff |.f.#..@.".f.b...|
0000ff60 10 00 b8 40 06 00 00 0f 22 e0 66 b8 08 00 8e d8 |...@....".f.....|
0000ff70 8e c0 8e e0 8e e8 8e d0 eb 39 1f 00 80 ff ff ff |.........9......|
0000ff80 00 00 00 00 00 00 00 00 ff ff 00 00 00 93 cf 00 |................|
0000ff90 ff ff 00 00 00 9b cf 00 ff ff 00 00 00 9b af 00 |................|
0000ffa0 bf 42 50 eb 0a bf 41 50 eb 05 66 89 c4 eb 02 eb |.BP...AP..f.....|
0000ffb0 f9 eb 90 e9 78 fd ff ff e9 c4 fd ff ff e9 84 fe |....x...........|
0000ffc0 ff ff b8 ff ff ff ff 48 21 c6 48 21 c5 48 21 c4 |.......H!.H!.H!.|
0000ffd0 48 89 e0 ff e6 90 90 90 90 90 90 90 90 90 90 90 |H...............|
0000ffe0 eb c3 90 90 90 90 90 90 00 00 00 00 56 54 46 00 |............VTF.|
0000fff0 90 90 eb ac 90 90 90 90 90 90 90 90 90 90 90 |...............|
0000ffff
I did try to add the -smbios type=0 flag when I launch QEMU from the command line.
I was wondering how the Linux kernel, when it runs within QEMU, does to detect memory and hardware. Does it use ACPI tables instead? I think SMBIOS is much more easy to use.
Is SMBIOS reliable enough so that operating-systems that run on newer hardware can assume its presence?