rochus-keller / OberonSystem3

A cross-platform version of the ETH Oberon System 3 compatible with the Oberon+ compiler and IDE
86 stars 5 forks source link

Native x86 version possible? #3

Closed mateodif closed 4 months ago

mateodif commented 4 months ago

Would it be possible to compile a Native Oberon system using the Oberon+ compiler? I've been digging into the source but I'm not sure how the actual native compilation/booting works.

rochus-keller commented 4 months ago

Yes. The Oberon+ compiler can generate C99 alternatively to CIL. This allows some kind of native/AOT, re-using the excellent optimization features of current C compilers. Actually the x86 version of the OberonSystem3 (see http://software.rochus-keller.ch/OberonSystem3_win32.zip) was compiled this way; if you're interested in the generated C99 source code, here it is: http://software.rochus-keller.ch/OberonSystem_generated_C_source.zip.

I hope this answers your question.

mateodif commented 4 months ago

I'm interested in booting a version of Oberon on bare-metal x86, just like the Native Oberon version that can be found here. I believe the C source can be useful for this so I'll definetely check it out. If you have any suggestions on achieving this, they would be very appreciated :)

Thanks for the quick answer!

mateodif commented 4 months ago

After looking at Changes.txt, I'm realizing that it won't be easily achieved. I should've started by looking there.

Thanks anyways!

rochus-keller commented 4 months ago

Ok, got it. The original Native Oberon System source code is full of non-portable assembler code. I pretty much refactored the system so that most of it runs just depending on the PAL API. Actually I implement a new low-level Oberon version called Micron (Micro Oberon) at the moment which can be used to implement a core presenting the PAL API on any bare-metal hardware. Personally I don't think that Oberon as a language is suited for this. Wirth indirectly confermed this in that the low-level stuff uses a lot of assembler and the back-doors in the SYSTEM module (and a couple of other tricks working around the type checker and garbage collector). Micron supports different levels, the lowest working even without a stack.

mateodif commented 4 months ago

Actually I implement a new low-level Oberon version called Micron (Micro Oberon) at the moment which can be used to implement a core presenting the PAL API on any bare-metal hardware.

That sounds very interesting, I would love to take a look at the project once you decide to publish it.

Personally I don't think that Oberon as a language is suited for this.

That's probably true. The main reason I'm researching the Oberon System is because I'm fascinated by the design decisions it took. Things like a system-wide garbage collector and a system-wide REPL that can dynamically load modules with a simple yet great UI. It's also pretty well documented. The only issue I have is that I don't quite understand how it actually boots. Oberon0.dsk can be used to boot into the system but I can't find documentation that explains how it's actually compiled.

mateodif commented 4 months ago

The idea of building an abstraction layer between hardware and a top level system reminds me a bit of Nopsys. It was used to host a VM that can run Smalltalk, effectively running Squeak on QEMU as its own OS called CogNOS. I'll look into the PAL API and see if I can make any experiments with it.

rochus-keller commented 4 months ago

I would love to take a look at the project once you decide to publish it.

The specification for the language and IR is already published, but still work in progress (just updated it today). See https://github.com/micron-language/specification/. The parser and code generator are not yet complete and mature enough to be published; it will take a few more weeks to have a decently working version.

Actually, in case you are interested, I recently found an exceptional compiler kit written in C++ which can generate code for about 16 architectures from a common intermediate language. See https://github.com/EigenCompilerSuite/. I managed to migrate the code so it compiles on old GCC and MSVC versions: https://github.com/rochus-keller/EiGen.

I can't find documentation that explains how it's actually compiled.

I never compiled the whole system with the original Oberon tools, but only my migrated version. There is a mailing list where you might try to ask: https://lists.inf.ethz.ch/pipermail/oberon/2024/date.html

abstraction layer between hardware and a top level, Nopsys , CogNOS.

Thanks for the links; I will take a look. The PAL API is not actually a layer, but the minimal function set to run the Oberon System 3 on any operating system; with Micron I will try to directly run on the hardware or on a MINIX instance (the microkernel architecture looks like a great fit for Oberon).