Show HN: My self-written hobby OS is finally running on my vintage IBM ThinkPad (opens in a new tab)github.com
575 pointsFinally got my hobby OS up and running on real hardware. I love the old IBM thinkpads, so thought it was the perfect machine to get it working on. Been working on it for quite some time now, but this has been a big milestone!
Comments (116) 39 threads
Earlier commentshttps://github.com/joexbayer/RetrOS-32/blob/development/grap...
https://github.com/joexbayer/RetrOS-32/blob/development/grap...
Forget practicality.
Forget "go to market" strategy.
Forget target fit.
Just build and learn.
There are some tutorials out there too, but a lot of them have bugs and you basically recreate their OS.
Regarding studying opcodes, I never went that deep, closest I got was looking them up for my C compiler, so I know the most common basic ones.
https://forum.osdev.org/ https://wiki.osdev.org/Expanded_Main_Page
You have a short loop that scans through the prefixes, checks for a REX prefix (if you handle 64-bit mode), reads the opcode (1-3 bytes), reads the MOD/RM byte if there is one (use a table lookup), reads the SIB byte if there is one (table), reads offset if there is one (table), reads immediate if there is one (table).
It's probably easiest if you use an "expanded/normalized" opcode internally so the 1-3 opcode bytes + the 3 extra bits from some MOD/RM bytes + prefix info (for certain SIMD instructions) map to a single 16-bit opcode (likely around a couple hundred to a thousand opcodes in total).
You have a table that maps those to mnemonics + operand info. You have some tables that map 0-7 (or 0-15) to AL/AH/... and AX/BX/CX/... and CS/DS/ES/... and various system registers.
Not that much code all in all. Several tables. You can squeeze them and bit pack them to your heart's content if you want.
Once you have that, a simple assembler isn't so hard.
I've been thinking about doing a long term hobby project of creating a personal computer - one where I create the entire software stack myself and can know the provenance of every bit that goes into the system (though I can't do the same with the hardware, unless I can get enough performance out of an FPGA to run everything on it).
Until now it seemed unrealistic but you proved it's possible! And looks like you're even implementing a hobby C compiler: https://github.com/joexbayer/C-Compiler
The C compiler is built for the OS, and works inside it. The project became just so big that I wanted to take it out of the OS repo. Especially because it works on Linux too.
All comments shown.
Couldn't load more comments. Check your connection and try again.