rswier / swieros Goto Github PK
View Code? Open in Web Editor NEWA tiny hand crafted CPU emulator, C compiler, and Operating System
License: GNU General Public License v2.0
A tiny hand crafted CPU emulator, C compiler, and Operating System
License: GNU General Public License v2.0
hi, rswier,
Great project!
Any idear about adding debugger in em simulator for OS debug?
Thank you!
Rob,
I forked swieros and ported eu.c (user mode emulator) to 64-bit over the weekend. It works well, and built an alternative boot that uses the 64-bit user-mode emulator to run a 32-bit previously-compiled bin/c (c compiler) to compile bin/c.c, then have the new bin/c compile etc/os.c, etc/mkfs.c and then run the emulator to run etc/mkfs to build the file system. It all works great. The next step is to port the protected mode emulator em.c to 64-bit and then everything should be working.
After taking a hard look at the C compiler, I think it is far easier to leave it as 32-bit, as well as of course the v6 OS, since they seem pretty dependent on sizeof int == sizeof int *.
The mechanism I used to port eu.c is very basic: none of the "pointers" or 32-bit pointer code were changed. Instead, all pointers are treated as 32-bit offsets to memory returned by a rewritten sbrk() in linux/libc.h, which initially allocates 64MB once using malloc and now supports break shrinkage as required by the C compiler. A single real pointer to the base of this memory is stored in a "unsigned char *mem" global and then added to any 32-bit "pointer/offset" to be used as a real pointer for each emulation instruction. Thus the execution cost is only a single 64-bit pointer add for each instruction executed. This would also be the case for 32-bit, where previously the sbrk() allocation was added once before start, now its added each instruction execution. So it is slower in 32-bit mode. But it has the advantage of very little changing, which promotes reliability.
The same mechanism can be used for the protected mode emulator, which I plan to port shortly. This approach allowed the C compiler to remain entirely unchanged, and the sbrk() improvement only affects host-compiled programs, since lib/libc.h was not changed either.
I have tested the c compiler recursively compiling the c compiler compiling a program, as well as recursively running the user mode emulator running the user mode emulator running a program :)
I didn't create a pull request since I'm not finished, and wanted your input as to what you think of this approach.
Hello, rswier.
I'm interested in your project and now looking into it.
It seems that the virtual CPU is based on neither x86 nor arm instruction set. Is it an instruction set that defined by yourself? Is there any documentation about the hardware/software interface?
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.