October 21, 2024
Chicago 12, Melborne City, USA
C++

How to determine available physical RAM in a RISC-V OS?


I was recently going through the source code for xv6 (https://github.com/mit-pdos/xv6-riscv), when I recently came across this line:
(https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/memlayout.h)

#define PHYSTOP (KERNBASE + 128*1024*1024)

combine this with the Makefile of the project (https://github.com/mit-pdos/xv6-riscv/blob/riscv/Makefile):

QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m 128M -smp $(CPUS) -nographic

This made me realise that they are just hard coding the OS to assume 128MB of RAM and then specifying the same size to QEMU. However, this is obviously not the case is real operating systems. So, I would like to know how an actual operating system would determine available physical memory?

Upon doing some research, I found online that this information is provided by BIOS of the device. For x86 systems, GNU multiboot.h can provide a lot of this information. In fact this page talks in detail about how this can be achieved. However, this link talks exclusively about the x86 architecture. How can this be achieved in the RISC-V architecture? And how can one test that inside QEMU?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video