3 ms·
I don't know anything about OS development, but how do you implement an OS in a language whose runtime depends on an OS?
by weberc2 9y ago
I don't know anything about OS development, but how do you implement an OS in a language whose runtime depends on an OS?
- bpicolo 9y agoLooks like it's a matter of not importing almost any libraries other than "unsafe".
- weberc2 9y agoNot only that, but you'd have to take care not to do anything that would trigger an allocation, since you don't have memory management.
- pjmlp 9y agoJust on the very lowest layer, then GC is just yet another kernel service. There are lots of GC enabled OSes and research papers to learn from.
- nickpsecurity 9y agoOn the lowest levels only. The rest of the OS can be GC'd. See Oberon, JX OS, and House in Haskell for instance. That Go has a low-latency GC makes it even better for that usage. http://programatica.cs.pdx.edu/House/ http://programatica.cs.pdx.edu/House/
- dullgiulio 9y agoWell, the Go runtime is written in Go itself. And you can write Go without the runtime, the same way the compiler is. The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself. You have to forgo all the niceties of having a runtime but you can do it. Definitely not the most productive use of Go, but it's fun and you learn a lot.
- weberc2 9y ago> And you can write Go without the runtime, the same way the compiler is. The compiler does depend on the runtime AFAIK > The hard part is that the runtime is indeed build on OS primitives (syscall mostly), that you have to implement yourself. This is what I was referring to. I don't know how you would do this without patching the language.
- pjmlp 9y agoBy using a mix of cross-compiling and some Assembly help, just like C needs some help beyond what ANSI C specifies.
- haberman 9y ago> Well, the Go runtime is written in Go itself. That's a bit of a stretch. The runtime uses special pragmas that are not available to normal programs. I don't think it would be possible to write Go's GC in Go unless these special pragmas existed: https://github.com/golang/go/blob/57df2f802f0417f08100ff8002f3b062e695e148/src/runtime/HACKING.md https://github.com/golang/go/blob/57df2f802f0417f08100ff8002... Also, there are magical variables in the runtime that the compiler knows about and special-cases: https://github.com/golang/go/blob/57df2f802f0417f08100ff8002f3b062e695e148/src/runtime/mgc.go#L241 https://github.com/golang/go/blob/57df2f802f0417f08100ff8002... > And you can write Go without the runtime, the same way the compiler is. How would you write Go without using the GC?
- pjmlp 9y agoThat is the magic of cross compilation. There is already a compiler that knows those special pragmas, one just needs to add a new bare-metal backed to it. As for writing Go without a GC, just like in any other GC enabled systems programming language, by not using language features that require GC in the lowest layer, which the other packages then depend on. Example in Oberon, https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kernel.Mod.txt https://people.inf.ethz.ch/wirth/ProjectOberon/Sources/Kerne... Also even ANSI C requires some Assembly or compiler extensions to fully implement libc.
- dbancajas 9y agoThe entire runtime does not depend on the OS. C's run-time is very minimal for exaple. You have a stack memory, heap etc that you setup in protected mode. Your OS will manage the page-tables, process creation etc. "Go" binary will basically compile into machine code which can be run on bare-metal. I am doing this currently: https://pdos.csail.mit.edu/6.828/2012/schedule.html https://pdos.csail.mit.edu/6.828/2012/schedule.html And it's been eye opening to how everything works under the hood!
- pjmlp 9y agoType safety. I advise you to read Project Oberon from Niklaus Wirth, originally published in 1992, revised in 2013 for targeting a FPGA instead of the Ceres workstation that was used at Zurich Institute of Technology (ETHZ) during the 90's. https://people.inf.ethz.ch/wirth/ProjectOberon/index.html https://people.inf.ethz.ch/wirth/ProjectOberon/index.html http://www.ocp.inf.ethz.ch/wiki/Documentation/Front http://www.ocp.inf.ethz.ch/wiki/Documentation/Front A complete graphical workstation OS used by the IT department for their OS programming classes, language design and even by the non technical personal at the department.
- vonmoltke 9y agoWhat does this have to do with the runtime of a specific language depending on an OS?
- pjmlp 9y agoAll runtimes can run bare metal, it is just a matter how much Assembly they might require for the HAL. Runtimes are a portable OS, that just by convince and practicability reasons happen to run on top of an existing OS. That is the whole premise of Unikernels, to go back to the days when the language runtime was the OS, like on the Xerox environments.
- acomjean 9y agoYou generally don't. Thus the "proof of concept". Though to be fair a lot of the standard C libraries have there own "Linux" version in the Kernel so the OS can do things without using the OS... http://lxr.linux.no/linux+v4.10.1/include/linux/ http://lxr.linux.no/linux+v4.10.1/include/linux/