Gopher-OS: A Proof of Concept OS Written in Go
github.com
github.com
If you take a look at the Go runtime sources you will notice that all the low-level arch/os-related bits have been split into separate files which usually invoke some syscalls (e.g. the memory allocator eventually calls mmap)
The idea I am currently investigating is to first provide an implementation for things such as physical memory allocation and virtual memory mapping which would ultimately allow me to bootstrap the Go allocator. From that point onwards the plan is to incrementally add more features and gradually initialize the rest of the runtime.
This is much more difficult than it sounds as all code must be written in such a way to prevent the compiler from calling the runtime allocator (no variables allowed to escape to the heap).
The hard part is once you get memory and paging working, you'll need a syscall interface. If you want to be able to run Go userspace programs, that means you need to implement the syscall interfaces for an OS that's already supported, and can't just go out and design your own, and at that part it starts getting a lot less fun.
That's possibly more work but it's the approach I would have taken as it seems more fun than just replicating Linux (or whatever) syscalls.
My point was just the memory allocation and paging isn't significantly different than it would be writing an OS in any other language, it's once you get to the part where you need to implement other people's interfaces/standards to make a viable product that it starts bogging down (if you go that route. If you go your route, then you have two major projects instead of one: writing an OS, and adding a new OS target to an existing toolchain.)
https://anvaka.github.io/common-words/#?lang=go
(the top 4 by far are err, if, return, nil!)
Gopher is already an established name, so the naming seems a bit unfortunate.
Just because something is no longer in common/widespread use, does not mean you can come along and use its meaning or name on your shiny new product.
Gopher the protocol maybe niche these days, but it's not dead. The continued use of the term 'Gopher-XYZ' by the Go language people will only accelerate the death of the Gopher protocol, which although inevitable it does not mean it should be erased from history by something else.
/home/atom/opt/Atom/bin/atom
And to check it's running? NP! Just use `ps -eF|grep -i atom`We need more letters
Why do you think it's inevitable, if not exactly because it is to be erased by something else?
I get that each time a "ML" link is posted here. Sadly it's almost never about the various successors of Miranda.
Yet another instance of the programmer establishment thinking they know what's best for everyone...
println does indeed print if you're using a teletype. The fact that you're probably not using a teletype is simply a matter of preference on your part.
https://en.wikipedia.org/wiki/Digital_current_loop_interface
Teletype current loop ports were common on machines up to the 1970s, but by the 1980s had largely disappeared. The serial port card on the original IBM PC and the XT had 20mA current loop support, but it was very rarely used, so AT machines onward removed it. (MIDI is also a current loop, but MIDI uses 5mA rather than 20mA, plus the protocol is different.)
You should be able to connect a teletype to a modern computer by using two conversion devices, one USB-to-RS232 and the other RS232-to-20mA-current-loop. Then the teletype will appear to the computer as a (very dumb) serial terminal.
There are lots of GC enabled OSes and research papers to learn from.
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.
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.
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?
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.
"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!
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.
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.
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...
I'm guessing a project like this will need to implement the Go runtime given that (I'm assuming) it uses posix (Or windows etc.) system calls.
Go uses the Plan9 assembly syntax but doesn't support GNU asm syntax. gccgo uses GNU asm syntax but doesn't support Plan9 assembly.
The Go linker doesn't allow you to not link in the Go standard library runtime, which means you need to use gccgo to write a kernel.
The end result is that you can't do something that's buildable with the standard Go toolchain, and even if Go were to add a "don't link the runtime" option there'd be no way to incrementally port your ASM over one bit at a time. It's all or nothing.
I will be talking about this approach in more detail in GolangUK '17.
Sounds great. Any chance for you to come to dotgo.eu?
What's all this voodoo inside Makefile, I would love more comments in there. I think that would be the first step for anyone wanting to contribute, to understand the Makefile.
@echo "[go] compiling go sources into a standalone .o file"
@GOARCH=$(GOARCH) GOOS=$(GOOS) go build -n 2>&1 | sed \
-e "1s|^|set -e\n|" \
-e "1s|^|export GOOS=$(GOOS)\n|" \
-e "1s|^|export GOARCH=$(GOARCH)\n|" \
-e "1s|^|WORK='$(BUILD_ABS_DIR)'\n|" \
-e "1s|^|alias pack='go tool pack'\n|" \
-e "/^mv/d" \
-e "s|-extld|-tmpdir='$(BUILD_ABS_DIR)' -linkmode=external -extldflags='-nostartfiles -nodefaultlibs -nostdlib -r' -extld|g" \
| sh 2>&1 | sed -e "s/^/ | /g"
edit I think I understand what's happening here, funny how writing it down helps one understand. It's just building up a build script with sed and executing it. The thing was I didn't know sed could do that. TIL func foo(b []byte) {
for i := range b {
b[i] = 0
}
}
the compiler turns it into a `memclr` call which can be pretty fast: https://github.com/golang/go/commit/f03c9202c43e0abb13066985...Perhaps there could be a performance boost to a simple for-range loop if `value == 0`?
And store data in HTML elements instead of files?
Why care about OS:es when there is no room for anyone on that level of abstraction apart from a handful developers at MS, Apple and Google?
Writing operating systems is also a great way/introduction to work on operating systems, and it's a fairly distinct area of development. It's hard to get day-to-day overlap if you're working on things that don't have the constraints and operating system does.
https://github.com/klange/toaruos << example of a hobby OS taken farther than most I've seen.
That doesn't mean it's useless to develop them. If you set your sights low (playing around, learning, academic) you can still benefit from them without them being a huge success by popularity standards.
"I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu)"
An OS project I suspect will always end when you no longer have time for it or are stuck somewhere. I'd be annoyed by that.
You really don't know, and cannot know, where the next Linux is going to come from. I don't know if this will be it, just by considering probabilities, it probably won't be, but it could.
Even at the worst case, the author of a project like this is going to learn A LOT from it, and the people who read through the source code are also going to learn a lot. Writing an OS in a higher-level language absolutely is beneficial to people who want to learn more about how hardware works and interacts with the OS, without needing to delve into something as complex as the Linux/BSD kernels.
At a minimum, I think projects like this directly create contributions to other "real" kernels by teaching developers how to do kernel/OS programming.
There is as much room as there are people frustrated with the "state of the art."
Edit: Have you seen this apple commercial https://www.youtube.com/watch?v=OYecfV3ubP8. Yes it is from 1984 and you might think it doesn't apply.
1. Even if the project never replaces the other software you use, you gain a better understanding of that other software by solving some of the same problems, making the same mistakes, learning the same lessons.
2. You may have special requirements that don't make sense to add to an existing project aimed at a broader audience. This is where a lot of niche microcontroller OSes come from.
3. You have a crazy idea that would be hard to explore within the architecture of an existing project. If it turns out to be crazy enough to work, then maybe people will do the work to migrate it to the mainstream.
4. Everyone has a little dream that the masses will find great value in their work and flock to it, supplanting the status quo. Like becoming a billionaire, it essentially never happens, but you can't blame people for trying.
A lot of people -myself included- enjoy solving puzzles for fun. So I often set myself weird or obscure challenges to solve with code.