Live data from Hacker News

After 5 days, my OS doesn't crash when I press a key

jvns.ca

61–70 of 90 posts

Re: After 5 days, my OS doesn't crash when I press a key

#61
post #59

When I was in undergrad I wanted to take Operating Systems 2 but it was only offered once/year and didn't match up with my free time. So I did an independent study where my plan was to write a basic ethernet driver for Linux. I have never been as humbled by any sort of programming in my life. This was back in 2004 so the resources available online weren't nearly as good. I basically figured everything out by reading…

With regards to kernel programming, I'm reminded of the old quote from Star Trek, "It's life, Jim, but not as we know it."

Re: After 5 days, my OS doesn't crash when I press a key

#63
post #35

Working at the layer below is a very useful exercise. As part of my undergrad course in EE in the late 1980's we had to design and simulate a 4 bit micro-processor using logic components (essentially NAND gates). I got completely immersed in that project. Not only did it force me to understand a complete, albeit simple processor but actually building it gave me a lot more confidence in writing code. Things have moved…

Was it a full microprocessor or just an ALU? In my Digital Design class we created a 4-bit ALU with about 8-9 opcodes and one register.

Re: After 5 days, my OS doesn't crash when I press a key

#64
post #56

> This continues for 2 days This thing made me scoff at the article the most. I've written a unix-like OS for ARM 2 years ago as a final project for an OS class I took on campus. There were 20 other people in the class, and all of us forgot to update the IDT at some point. It was a common mistake, so for this article to emphasize it like it's some bug that takes 2 days is just lame. Imagine if my blog post would talk…

> like it's some bug that takes 2 days is just lame. Unless she was spending full time on it, it was not some bug that takes 2 days. At the same time: If you've never come across some trivial, stupid little bug that has left you stumped for far longer than it should have, you're either superhuman (or have selective memory), or you're a total beginner. Your dismissive tone is really offputting.

When I did Operating Systems in University (in a group), I remember distinctly only 3 bugs that we had difficulty debugging:

* re-using a loop variable from the outer loop in an inner loop (damn you `int i`!)

* putting a char[256] on the stack when the stack size was only 256 bytes and getting stack corruption (this one wasn't me, thankfully)

* signed vs unsigned code being passed between user mode and kernel mode causing problems (no idea why it was causing issues; i just made it all unsigned and the issue went away)

In hindsight, -Wall would have probably caught everything and saved a couple hours of "wtf" at 2-3 in the morning.

Often the simplest things are the hardest to discover.

Re: After 5 days, my OS doesn't crash when I press a key

#65
post #40
post #10

Earlier quoted context omitted.

I'm not sure how it is implemented at the graphics card level, but the Linux kernel virtual console can be high-resolution. The "correct" thing to do here is set the console font to a larger one. If you are on a systemd-using distribution, see vconsole.conf(8). Now, you could force a lower resolution, but that causes jaggy text, as pixels will be stretched unevenly by the graphics card. This can be done with KMS, or…

Does that work (changing the font) even when you swap to TTY2 for example? If so, you're a lifesaver!

Yes.

Re: After 5 days, my OS doesn't crash when I press a key

#66

Back in the day when I was playing around with osdev, I ran my code in the Bochs emulator. WAY easier than running on actual hardware, especially starting the emulator was 10x faster then booting on an actual PC. I do remember the excitement of getting interrupts to work - good times. Getting task switching to work was magic.

She mentions in the article that she's using Qemu.

Re: After 5 days, my OS doesn't crash when I press a key

#67
post #26

Another good read and really gives the insight on how much time and effort it takes to make anything happen on bare metal. @jvns: SPOILERS AHEAD, DO NOT READ FURTHER IF YOU WANT TO GET TO THE HEART OF THIS PROBLEM YOURSELF As for your problem with the keyboard interrupt firing only once, I think (after a quick glance over the code) that you do not signal "end of interrupt" (EOI) message to the 8259 PIC chip after you…

Spoilers for a bug report... that's a new one! Very thoughtful. :)

Re: After 5 days, my OS doesn't crash when I press a key

#68

I enjoyed this. It brought back memories of bringing up BSD2.9 on the PDP 11/55t we had in the lab. That particular PDP 11 was pretty rare (it had some memory split features to improve performance for computational tasks) and poking around in the kernel to get to the point where init was started. Nothing quite like that thrill, a mixture of power, and 'oh crap this is going to be a lot of work'.

What she's doing is surprisingly a lot harder. Getting a modern IA-32(e) architecture into the 64 bit mode we all know and love is INSANE.

Re: After 5 days, my OS doesn't crash when I press a key

#69
post #55
post #53

I really wanted to not sound like an asshole and start critizicing this because I like low-level programming articles but this article is confunsing: 1) You don't need an OS to press keys and make them come out in the screen. An OS is kind of a library that an application uses to do things. 2) I believe what the article refers as "OS" is a small process manager. I don't know if it's preemptive, no mention of timer of…

You can call it a ring-0 application if wish to argue about semantics or the definition of an OS but you really do end up sounding like an asshole. Every OS projects starts out as a "ring 0 application" running on bare metal. An application which does nothing except handle interrupts and spew out numbers on the screen to tell that it is working. And most OS projects never really evolve a lot past that, because they a…

Also, aortega wrote "Operative System" instead of "operating system", so because of that incorrect terminology, we can ignore everything in the post. That's how this works, right?

Re: After 5 days, my OS doesn't crash when I press a key

#70

For some reason HN ate my previous comment Doing OS things is hard. In x86 it's extra hard x86 is one kludge on top of another. Like interrupt chaining These issues remind me of making a Sound Blaster card work on DOS (I was making a program to play a simple file in Pascal/C) It's very complicated, and several trials to make it work (and no Stackoverflow, Wikis, etc)

That's very true from both compiler and OS point of view. Intel machine code is so kludgy: variable-length codes, subtle differences in prefixes in different modes, exceptions in register handling all over the place, plenty of addressing modes for memory access, special machine codes for a qualified register (`mov %ax` code differs from `mov %cx/%dx/%bx/...`), more lengthy encoding for more often uses (like `mov (%es…

Going from Motorola 68k to x86 with few preconceptions in the nineties was quite a shock after slowly having been convinced that the grass actually was greener.

On the x86 side I was surprised to find an unnecessarily cryptic assembly language, little-endian words and a byzantine memory model for starters.

Hacks upon layers of hacks and not the intuitive and aesthetically pleasing solutions seems to win out in most cases.

Post reply on HN