Accessing the physical memory and bypassing virtual memory
Posted: Thu Aug 08, 2019 8:37 am
Let me start with quick background;
I was always interested in in writing some C code to pint to a memory location like "0x0" and loop to infinity and set every byte of memory to 0, and hence crash the OS while it's running, just for fun. This is of course not possible due to virtual memory and user address space and so on.
Fast forwarding until now, I have played around with written my own "hello world" kernel as well as linux kernel modules just so I can touch the physical memory but i'm still not sure if I have succeeded.
Now here are my questions:
1- Going through this beginner tutorial https://wiki.osdev.org/Bare_Bones, it says that "The bootloader has loaded us into 32-bit protected mode on a x86 machine. Interrupts are disabled. Paging is disabled." Does the "Paging is disabled" part mean i'm using physical memory at this point? I have followed everything int he above page and managed to see "Hello world" on my screen, but I'm not sure if i'm using virtual memory at that point or physical memory.
If GRUB loads me into protected mode how can virtual memory be turned off? I thought thats the whole point of having a protected mode in x86.
2- Is it possible to touch physical memory when writing Kernel Modules?
3- I have also read that "The Kernel Virtual Address Space (KVA) is the virtual memory area in which all Linux kernel threads reside", why does an OS need to use virtual addressing for itself? Why doesn't it use the physical memory directly?
Sorry if questions seem to be all over the place, they are all sort of related to memory management.
I was always interested in in writing some C code to pint to a memory location like "0x0" and loop to infinity and set every byte of memory to 0, and hence crash the OS while it's running, just for fun. This is of course not possible due to virtual memory and user address space and so on.
Fast forwarding until now, I have played around with written my own "hello world" kernel as well as linux kernel modules just so I can touch the physical memory but i'm still not sure if I have succeeded.
Now here are my questions:
1- Going through this beginner tutorial https://wiki.osdev.org/Bare_Bones, it says that "The bootloader has loaded us into 32-bit protected mode on a x86 machine. Interrupts are disabled. Paging is disabled." Does the "Paging is disabled" part mean i'm using physical memory at this point? I have followed everything int he above page and managed to see "Hello world" on my screen, but I'm not sure if i'm using virtual memory at that point or physical memory.
If GRUB loads me into protected mode how can virtual memory be turned off? I thought thats the whole point of having a protected mode in x86.
2- Is it possible to touch physical memory when writing Kernel Modules?
3- I have also read that "The Kernel Virtual Address Space (KVA) is the virtual memory area in which all Linux kernel threads reside", why does an OS need to use virtual addressing for itself? Why doesn't it use the physical memory directly?
Sorry if questions seem to be all over the place, they are all sort of related to memory management.