Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't know anything about OS development, but how do you implement an OS in a language whose runtime depends on an OS?


The 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

And it's been eye opening to how everything works under the hood!


Type 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

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.


What does this have to do with the runtime of a specific language depending on an OS?


All 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.


Well, 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.


> 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/57df2f802f0417f08100ff8002...

Also, there are magical variables in the runtime that the compiler knows about and special-cases: 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?


That 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/Kerne...

Also even ANSI C requires some Assembly or compiler extensions to fully implement libc.


> 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.


By using a mix of cross-compiling and some Assembly help, just like C needs some help beyond what ANSI C specifies.


You 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/


Looks like it's a matter of not importing almost any libraries other than "unsafe".


Not 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.


Just 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.


On 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/




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: