Live data from Hacker News

Kernel 101 – Let’s write a Kernel

arjunsreedharan.org

51–60 of 104 posts

Re: Kernel 101 – Let’s write a Kernel

#51

Earlier quoted context omitted.

http://en.wikipedia.org/wiki/Exokernel <- if you're playing the 'how big is a kernel' game.

Awesome link, thanks! The key part of any kernel can be expressed from this Exokernel definition: Exokernels are tiny, since functionality is limited to ensuring protection and multiplexing of resources, which are vastly simpler than conventional microkernels' implementation of message passing and monolithic kernels' implementation of abstractions. They have to, in some way shape or form, deal with conflicting reques…

The generic answer to any question about exokernels is "In userspace."

It also applies here: There's generally a userspace scheduler which programs can register themselves with. Or they can implement their own.

Re: Kernel 101 – Let’s write a Kernel

#52
post #14

Great! except that to be called a kernel it's missing just a process manager, memory manager, filesystem, process separation and hardware abstraction. Yeah I'm that guy, down vote me as you wish, the article is still wrong. It's a way to load a ring-0 application into grub. Pretty cool, but not a kernel.

The start of an extreme microkernel. Just add messaging, a little memory work, processes and the rest can be possibly done in user mode!

Re: Kernel 101 – Let’s write a Kernel

#53
post #31

Earlier quoted context omitted.

I've found myself spending a lot more time here as well. Was there any code/policy change with the HN site? Or is this new moderators jumping in and helping out a lot? Either way, I agree that it is excellent.

About a week or two ago pg added moderation. I cannot find the thread right now, but basically comments are not published until someone with high enough karma (I think 1000 points) approves the comment.

That's for comments, but the quality improvement is largely in link submissions

Re: Kernel 101 – Let’s write a Kernel

#54
post #5

I'm not exactly Linus Torvalds but I'm pretty sure a program that prints one line of text is not "a kernel". :)

It may or may not be "a kernel", but personally, I learned a lot from this one simple tutorial. As someone who normally plays with website code, even something this simple can be very helpful in understanding other areas of programming and how computers work.

Re: Kernel 101 – Let’s write a Kernel

#55
post #38

If anybody is doing this, let me share some words of advice based on experience. Please use a virtual machine instead of doing this on your primary machine. You eliminate the risk of messing up your machine. Also, if you setup the VM properly, you get a debugger.

Could you point to how to go about setting a suitable VM up on Debian? I could do with not bricking my machine :)

Use QEMU.

http://qemu.weilnetz.de/qemu-doc.html

Re: Kernel 101 – Let’s write a Kernel

#56
post #31

Earlier quoted context omitted.

About a week or two ago pg added moderation. I cannot find the thread right now, but basically comments are not published until someone with high enough karma (I think 1000 points) approves the comment.

Oh, I thought that was only for selected threads.

It is, bebop was mistaken. (Unless my comment does not show up, in which case he is correct.)

Re: Kernel 101 – Let’s write a Kernel

#57
post #52
post #14

Great! except that to be called a kernel it's missing just a process manager, memory manager, filesystem, process separation and hardware abstraction. Yeah I'm that guy, down vote me as you wish, the article is still wrong. It's a way to load a ring-0 application into grub. Pretty cool, but not a kernel.

The start of an extreme microkernel. Just add messaging, a little memory work, processes and the rest can be possibly done in user mode!

I agree, it's like a microkernel, you only have to add a microkernel.

Re: Kernel 101 – Let’s write a Kernel

#58
I got this running on qemu by cannibalizing a tiny bit of code from xv6 (http://pdos.csail.mit.edu/6.828/2012/xv6.html) to replace the GRUB dependency. After cloning and building mkernel according to its instructions:

  $ git clone git://pdos.csail.mit.edu/xv6/xv6.git
  $ cd xv6
  $ make
Now you should be able to run xv6 by itself:

  $ path-to-qemu/x86_64-softmmu/qemu-system-x86_64 -serial mon:stdio -hdb fs.img xv6.img -m 512
To run mkernel on qemu, we'll replace xv6's kernel with mkernel's:

  $ dd if=/dev/zero of=mkernel.img count=10000
  $ dd if=bootblock of=mkernel.img conv=notrunc
  $ dd if=../mkernel/kernel of=mkernel.img seek=1 conv=notrunc
Now you can boot up the mkernel.img rather than xv6.img:

  $ path-to-qemu/x86_64-softmmu/qemu-system-x86_64 -serial mon:stdio -hdb fs.img mkernel.img -m 512
(Based on xv6 at hash ff2783442ea2801a4bf6c76f198f36a6e985e7dd and mkernel at hash 42fd4c83fe47933b3e0d1b54f761a323f8350904. Ping me if you have questions; email in profile.)

Re: Kernel 101 – Let’s write a Kernel

#59
post #5

I'm not exactly Linus Torvalds but I'm pretty sure a program that prints one line of text is not "a kernel". :)

And if you look at the comments on the post itself, you will see this "Hey, i am actually planning to write another post with addition of a keyboard driver among others. :)"

This post is just a small steping stone on the way to a kernel (assuming the poster continues)

Re: Kernel 101 – Let’s write a Kernel

#60

Very cool. I personally (as a developer without a CS background) find these sorts of posts wonderfully interesting, even if this kernel, as pointed out in this thread, lacks a lot of what a normal kernel does. I'd love to see one of these for a compiler!

Writing an expression parser is probably the compiler "equivalent": http://www.strchr.com/expression_evaluator

More like an expression parser that doesn't handle precedence or unary operators

FYI, I recommend using the precedence climbing algorithm if you do need to do expression parsing: http://eli.thegreenplace.net/2012/08/02/parsing-expressions-...

It fits very well into a full recursive descent parser and is much more efficient and flexible than hardcoding in productions for handling the operators (and you can dynamically add new ones easily).

Post reply on HN