Live data from Hacker News

Operating System in 1,000 Lines – Intro

operating-system-in-1000-lines.vercel.app

71–80 of 129 posts

Re: Operating System in 1,000 Lines – Intro

#71
post #17

A noble idea, but Github is literally littered with hobbyist home-grown Unix-like kernels in C. As an industry are we not supposed to be trying to move away from hoary old unsafe C? Could we not have a hobbyist educational OSes in more of the C replacements? Drew DeVault wrote Bunnix in Hare, in one month. There's the proof of concept. How about tiny toy Unix-likes in Zig, Nim, Crystal, Odin, D, Rust, Circle, Carbon,…

> Yes I know Ada is not a good fit, but there has already been a Unix-like OS entirely implemented in a derivative of Pascal: TUNIS. Isn't it? There is a very well-developed kernel written in ADA with SPARK and formally verified at that: https://ironclad.nongnu.org And PASCAL-derived languages were very popular for operating systems in the 80s. To name a few: Apple's LISA OS, DEC's VAXELN, and OBERON. There were othe…

Thanks for this!

I did not realise VAXELN was in Pascal. The others I did know of, yes, although Ironclad only from another comment in this thread.

Re: Operating System in 1,000 Lines – Intro

#72
post #34

Very delightful article. Based on my experience in "hobby" OS programming, I would add setting up GDB debugging as early as possible. It was a great help in my projects and an improvement over debugging with the QEMU monitor only. QEMU contains a built-in GDB server, you'll need a GDB client built for the target architecture (riscv in this case) and connecting to the QEMU GDB server over the network. https://qemu-pro…

Agree, and I'll add 3 other really useful QEMU features for osdev: 1) Record & Replay: Record an execution and replay it back. You can even attach GDB while replaying, and go back in time while debugging with "reverse-next" and "reverse-continue": https://qemu-project.gitlab.io/qemu/system/replay.html 2) The QEMU monitor, especially the "gva2gpa" and "xp" commands which are very useful to debug stuff with virtual mem…

thanks for sharing! qemu is very powerful, but it’s hard to discocer a lot of these features

Re: Operating System in 1,000 Lines – Intro

#74
post #36

Author here. I wrote this book so you can spend a boring weekend writing an operating system from scratch. You don’t have to write it in C - you can use your favorite programming language, like Rust or Zig. I intentionally made it not UNIX-like and kept only the essential parts. Thinking about how the OS differs from Linux or Windows can also be fun. Designing an OS is like creating your own world—you can make it how…

Hi OP, this looks super cool. I remember hearing about this ( https://www.linuxfromscratch.org/ ) many years ago but have never done it. Curious, what are the prerequisites for this? Do I have to know about how kernels work? How memory management, protection rings or processes are queued? Some I'd like to definitely learn about.

LFS is about building a Linux distribution from scratch (i.e. using the Linux kernel.)

The book in question is about how to build your own operating system (i.e. a non-Linux) kernel from scratch.

> We'll implement basic context switching, paging, user mode, a command-line shell, a disk device driver, and file read/write operations in C. Sounds like a lot, however, it's only 1,000 lines of code!

Re: Operating System in 1,000 Lines – Intro

#75
post #36

Author here. I wrote this book so you can spend a boring weekend writing an operating system from scratch. You don’t have to write it in C - you can use your favorite programming language, like Rust or Zig. I intentionally made it not UNIX-like and kept only the essential parts. Thinking about how the OS differs from Linux or Windows can also be fun. Designing an OS is like creating your own world—you can make it how…

Hi OP, this looks super cool. I remember hearing about this ( https://www.linuxfromscratch.org/ ) many years ago but have never done it. Curious, what are the prerequisites for this? Do I have to know about how kernels work? How memory management, protection rings or processes are queued? Some I'd like to definitely learn about.

[deleted]

Re: Operating System in 1,000 Lines – Intro

#77
post #69
post #32

Earlier quoted context omitted.

> Yes I know Ada is not a good fit Why? > https://en.wikipedia.org/wiki/TUNIS Interesting; do you know whether the source code is available somewhere?

No, sadly, I don't know of any. You might ask co-developer Prof James Cordy: https://en.wikipedia.org/wiki/James_Cordy Or approach the University of Toronto: https://www.utoronto.ca/

I had a look at the available literature. Many of the ideas are pretty similar to the work of Per Brinch Hansen a decade earlier. Actually the successor of Concurrent Euclid, called Object-Oriented Turing, is pretty interesting, because it is still a Pascal descendant, but supports modules, declarations in the statement flow, OO and concurrent programming. As it seems it's worth a closer look.

Re: Operating System in 1,000 Lines – Intro

#78
post #17

A noble idea, but Github is literally littered with hobbyist home-grown Unix-like kernels in C. As an industry are we not supposed to be trying to move away from hoary old unsafe C? Could we not have a hobbyist educational OSes in more of the C replacements? Drew DeVault wrote Bunnix in Hare, in one month. There's the proof of concept. How about tiny toy Unix-likes in Zig, Nim, Crystal, Odin, D, Rust, Circle, Carbon,…

Dijkstra famously said that programmers who started with BASIC are "mentally mutilated". But I think this applies a lot more to C and UNIX. Most of them don't seem to understand how anything substantially different could exist in the world of computing - every other language and operating system is seen as either an inferior copy, or as another layer of abstraction building on top of C and UNIX.

> Dijkstra famously said that programmers who started with BASIC are "mentally mutilated"

He knew how to make friends.

Re: Operating System in 1,000 Lines – Intro

#79
post #46

Very cool to see someone tackling a small OS for RISC-V. Shameless plug: I've written hobby OS (well, a kernel actually) in Nim for x86-64[0] and it's all documented as well. I put its development on hold until I create a JetBrains plugin for Nim (in heavy development right now). [0] https://0xc0ffee.netlify.app/osdev

And discussed here a few months ago: https://news.ycombinator.com/item?id=40962767 - Fusion – A hobby OS implemented in Nim (110 comments)

Re: Operating System in 1,000 Lines – Intro

#80

I never counted, but my first professional software project was an operating system (firmware) for an RF switching box. It was written in 8085 ASM, and was probably in the neighborhood of 1,000 lines. Apples to oranges, though. It was a specialized firmware system. Probably the biggest part was the IEEE-488 communications handler.

This is it[0].

Looks like more like 2800 lines.

[0] https://littlegreenviper.com/wp-content/uploads/2022/07/TF30...

Post reply on HN