Live data from Hacker News

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

jvns.ca

51–60 of 90 posts

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

#51

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 (%esp)` requires SIB byte whereas it's not true for all other registers) and so on.

From OS perspective, it's also overcomplicated: switching from real to protected mode is an exercise in doing every action in a long chain properly and in the right order or the whole undertaking fails. Remapping IRQs into interrupts that do not mess with the CPU internal exceptions, weird legacy memory layout with BIOS, a slew of CPU modes (real/protected/PAE/long/etc), crazy format of entries in Interrupt Descriptor Table (where four bits of a pointer may be stored separately from the main part), where bits are often used differently for different contexts; redundant built-in features like poor multitasking support (Linux and other sane kernels try to avoid it as much as possible, but it's still is not possible to go into kernel mode from userspace without filling kernel stack pointer into a TSS entry), memory segments (in protected mode, where a pointer can address the whole virtual memory unlike real mode), four privilege rings (whereas all modern OSes use two: 0 for kernel space and 3 for userspace).

All that does not feel like it should be and often it only gets worse.

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

#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 any kind.

3) As far as I can see, this is not an OS but a ring-0 application that reads the keyboard using IRQs. IMHO an Operative System should at least supply filesystem/memory manager or process-manager services.

Hacker school alumni, those articles are awesome but please get your concepts right and at least learn the correct terminology or you will only confuse people. But I suspect those articles are vague on purpose to incite controversy.

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

#54
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…

It's not a process manager because there are no processes. And how do you get keypresses to come up on the screen with no OS?

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

#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 are primarily intended as educational tools for the author and nothing else.

If you had a point, you could have made it in a way that makes you seem like a decent person, not an angry antisocial geek.

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

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

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

#57
I think, after I clear out my current project log, OS hacking is the next thing on my plate. I'll probably start with drivers, but I eventually want to get into learning the core concepts. OS kernels and compiler design are kind of the last "things" that I've not yet done with programming, and probably couldn't just jump into it feet first and be productive. I've done AI, graphics, real-time embedded programming, high-performance algorithm stuffs, large scale data crunching, etc. etc., and they all pretty much come down to the same stuff: know your math and don't waste cycles. 'Spose that's kernels and compilers, too.

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

#58

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)

Yeah, I'll think pack on this article whenever my PIC32 fails to do what I tell it and think "It could be much worse."

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

#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 Intel's x86 documentation from start to finish. It took me a solid 3 weeks just to figure out how to start talking to the ethernet card. I spent days reading the same few pages in the manual over and over trying to understand how to get everything to fit together in assembly & C.

After 9 weeks I was able to address & initialize the ethernet card after the OS booted. I never was able to send or receive any data after a solid 50 hours of work.

Oh yeah, and I got a solid A for my work.

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

#60

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

[deleted]
Post reply on HN