
Physical Memory Manager - Amateur OS Dev (C/x86 asm)
Use BIOS int 15h EAX E820h to get a physical memory map, make a physical memory manager & allocator, and use it in the kernel to allocate and free blocks of memory for loaded files. Also some small extras like a print_dec() function to print decimal integers.
OS Dev playlist:
https://www.youtube.com/playlist?list=PLT7NbkyNWaqajsw8Xh7SP9KJwjfpP8TNX
Source code at the end of this video:
https://git.sr.ht/~queso_fuego/amateur_os_video_sources/tree/master/item/35_phys_mem_mgr
Git repos:
https://git.sr.ht/~queso_fuego/quesos
https://github.com/queso-fuego/amateuros
OS Dev wiki detecting memory:
https://wiki.osdev.org/Detecting_Memory_(x86)
Brokenthorn OS tutorial on physical memory manager (My memory manager functions and printed info came from his examples):
http://www.brokenthorn.com/Resources/OSDev17.html
Latest ACPI spec for int 15h eax E820h:
https://uefi.org/specifications
The html version should be similar to this (might be 404 due to newer versions, try replacing the "6.5" with the newest version or getting the pdf):
https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.html#int-15h-e820h-query-system-address-map
ACPI 1.0 spec (1996):
http://uefi.org/sites/default/files/resources/ACPI_1.pdf
Misc thoughts/neuroticism:
- How to handle constants, with const variables or defines? Maybe put defines in header files, and use const mainly for passing "read-only" parameters to functions?
- For stuff only used in one file, is it better to use/include a header, or write the code directly in the file? Separate headers for each thing seems more "modular", but it adds clutter. I don't like projects with a ton of .h & .c files and no way to tell what's going on, or how to navigate the project as an outsider. If everything is a self contained unit (.h & .c implementation, or single .h implementation), is that easier to understand than a monolithic version where all the code is defined and used in one file? I don't know.
I'd like the OS to be simple, in readability and understand-ability, with the least lines of code.
- I'll combine some of the print_* functions into less files, for printing numbers, strings, etc.
- Changed microphone filters again, for less bass, more midrange/compression, and some de-essing, to be clearer and a bit louder, and more understandable. Then I got a new microphone, which has bass roll-off and midrange boosting built-in. Hopefully audio is better after ~1h 32m, with the new mic. I added and removed bass roll-off at various points to hear how it is on video, so the sound keeps changing between parts, sorry about that. I'll probably remove the bass roll-off, but add a high pass filter for low frequencies, around 60hz maybe. It's harder to get decent compression and EQ and all than you'd think, at least if you have a bad voice :^)
I always sound tired, from work or trying to be quiet for others in the house or other things. Sometimes tea or coffee makes my voice worse, but it tastes so good!
How do podcasters or streamers talk for hours a day, voice training?
Next video ideas:
Interrupt descriptor table, software interrupts (int 80h), malloc/free for a called program to allocate/free memory; paging & virtual memory manager; x86 assembler; user changeable graphics modes; or other things
- Let me know if there's anything specific you'd like to see
Outline:
0:00 - Test memory map/manager output
3:13 - Bios int 15h eax E820h from ACPI docs & OS Dev Wiki
12:49 - Add bios interrupt to bootloader, show int 12h
26:16 - Print memory map info
39:01 - Change print_hex for 32bit & variable sizes, print total memory
55:42 - physical_memory_manager.h
1:32:18 - print block info, initialize memory manager
1:53:31 - prtmemmap command
1:57:20 - Allocate & free blocks for loaded files
2:16:53 - Fix 0x20000 and global string issues (use static keyword in called programs)
2:25:32 - Some const string changes
2:28:18 - print_dec(), change some print_hex calls to print decimal numbers
2:42:28 - Closing thoughts, coming up, outro
Software used:
VMware Workstation Player - https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html
openBSD - https://www.openbsd.org/
qemu - https://www.qemu.org/
vim - https://www.vim.org/
clang - https://clang.llvm.org/
davinci resolve - https://www.blackmagicdesign.com/products/davinciresolve/
OBS Studio - https://obsproject.com/
Peripherals:
Camera: Sony ZV-1, Elgato Camlink 4k
Microphone: Shure SM7B, Cloudlifter CL-1, Focusrite Scarlett Solo
Keyboard: HHKB Pro Hybrid Type S, white/blank keycaps
Mouse: Logitech G502
Contact:
https://queso_fuego.srht.site/contact.html
Thoughts/Notes/Suggestions/Other - Drop a message in the video comments, twitter, or email
Credits:
Music from https://incompetech.com:
"Your Call" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/
#osdev #programming #memory