I know that a kernel is platform dependent, but I was wondering about the basic idea of how it worked. For example, how would the kernel allocate memory for the applications to use. Things like that.

Basically, I created this topic, because I asked Kerm, and he asked me to create this topic, so here it is. If you know anything about kernels, please feel free to respond.
I know a lot about kernels (probably the most of anyone here, as I've written one - a really crappy one, but still). If you have a specific question, I'll answer that, but "how a kernel works" is a *very* broad question. Wiki will get you started: http://en.wikipedia.org/wiki/Kernel_%28computing%29
Kllrnohj wrote:
I know a lot about kernels (probably the most of anyone here, as I've written one - a really crappy one, but still).
Hey, I wrote a real kernel for computers in C as well (as opposed to calculators and z80), so I think I'm at least as knowledgeable. I know that I've done some research into the Linux kernel internals, but then again, I think you have too.
Kllrnohj wrote:
If you have a specific question, I'll answer that, but "how a kernel works" is a *very* broad question. Wiki will get you started: http://en.wikipedia.org/wiki/Kernel_%28computing%29
Well, I think he probably wants to know what a kernel is, what it does, what it doesn't do and instead is done by other portions of the operating system, and where one would start to write a kernel.
That is correct. For example, if you were to write a kernel, where would you start? How do you allow applications to use the cpu and memory. (eg, who gets what memory/cpu). How do you allow your applications and OS to be written in C, while your kernel is written in some assembly language like z80 or arm.

Any info would help. btw, I've already read the wiki page for the most part.
graphmastur wrote:
That is correct. For example, if you were to write a kernel, where would you start? How do you allow applications to use the cpu and memory. (eg, who gets what memory/cpu). How do you allow your applications and OS to be written in C, while your kernel is written in some assembly language like z80 or arm.

Any info would help. btw, I've already read the wiki page for the most part.
I think this paragraph is where you need to start thinking:

Wikipedia:Kernel (computing) wrote:
A kernel will usually provide features for low-level scheduling of processes (dispatching), inter-process communication, process synchronization, context switching, manipulation of process control blocks, interrupt handling, process creation and destruction, and process suspension and resumption (see process states).
So the kernel needs to keep track of all your memory and provide the equivalent of malloc() and free(), manage all the processes running on the system, switch which one has control of the CPU, give everyone a fair share, and in some cases connect hardware to drivers.
graphmastur wrote:
That is correct. For example, if you were to write a kernel, where would you start? How do you allow applications to use the cpu and memory. (eg, who gets what memory/cpu). How do you allow your applications and OS to be written in C, while your kernel is written in some assembly language like z80 or arm.

Any info would help. btw, I've already read the wiki page for the most part.


To learn to write your own kernel: http://wiki.osdev.org/Main_Page

Step 1: Install Linux and become familiar with GCC. Make sure you are very familiar with C and things like pointers. Then start here: http://wiki.osdev.org/Getting_Started

KermMartian wrote:
Hey, I wrote a real kernel for computers in C as well (as opposed to calculators and z80), so I think I'm at least as knowledgeable. I know that I've done some research into the Linux kernel internals, but then again, I think you have too.


I didn't know you'd written an x86 kernel as well Smile
Kllrnohj, good call on OSDev, that should be a good place for him to start. Yup, I've written an x86 kernel in my day. I was chatting with Merth on IRC earlier, and he said that he did as well for his OS class.
Okay, so say I wanted to allow an os and application framework. I have the c header libraries. If I'm using arm, do I have it assemble to arm, or what?

Also, since the memory will be fragmented, how do I handle if my app requests 32 bytes or something. I thought about having it set up so that 0 is the first byte. There would be a header that lists the size of the section, and the next section. Would that work?
graphmastur wrote:
Okay, so say I wanted to allow an os and application framework. I have the c header libraries. If I'm using arm, do I have it assemble to arm, or what?

Also, since the memory will be fragmented, how do I handle if my app requests 32 bytes or something. I thought about having it set up so that 0 is the first byte. There would be a header that lists the size of the section, and the next section. Would that work?


When you are developing a kernel there are no C libraries. There is nothing. Not a single function call exists. You must write *everything*. I don't know what is available in arm, but for x86 a memory page is 4kb. You allocate pages of 4kb, and then allocate pieces of that 4kb page as necessary.

If you have any notion of having something usable in a week or two, forget about it. Since you are starting from scratch, you might have an x86 kernel that can print to the screen before halting in a week, memory allocating will probably take you several weeks in and of itself, it's fairly complicated. And forget about an application framework, that requires a cross-compile environment.

Now, go read the wikipedia page on kernels, and then read the OSDev getting started page. This will take a *LOT* of reading and research. I'm not going to answer any more of these basic questions when I've already given you the resources to learn. This will take a lot of *WORK* on your part just to understand wtf is going on.
Yeah, i got ninja'd twice on that last post. I know it takes time. I am not underestimating the difficulty of it. I know it's complicated.

I have been reading osdev, though. ;-)
graphmastur wrote:
Yeah, i got ninja'd twice on that last post. I know it takes time. I am not underestimating the difficulty of it. I know it's complicated.

I have been reading osdev, though. Wink
Excellent, let us know how your're doing with reading OSDev, and if you have any specific questions based on what you've been reading. Smile
KermMartian wrote:
graphmastur wrote:
Yeah, i got ninja'd twice on that last post. I know it takes time. I am not underestimating the difficulty of it. I know it's complicated.

I have been reading osdev, though. ;-)
Excellent, let us know how your're doing with reading OSDev, and if you have any specific questions based on what you've been reading. :)


Thanks! Why isn't the quote working?

Actually, I already have a question. If I'm writing this, so for the ti calcs, how would the bootloader work? There is only flash and ram, so would the kernel just be the first thing at $0000 or what?

Also, for memory, I still don't understand the mmu and paging. I understand dividing the memory in pages, because you can only read so much at a time, but i don't understand it in regards to paging for apps. Also, how do I make the app run anywhere? I thought about having it start at $0000 and have all the calls and jumps be virtual addresses. Would that work?
graphmastur wrote:
I understand dividing the memory in pages, because you can only read so much at a time


That isn't why you use pages at all. Think about it like this, if you allocated on a per-byte basis for the MMU, you would essentially end up with half the amount of RAM since half of it will go to managing the other half. Instead we use pages, because then you just track chunks of memory, which results in much, much less overhead. You can also do things with pages like limit access (so page 1 can be read/write, but page 2 is read only, etc...)

Quote:
but i don't understand it in regards to paging for apps.


That is because you are probably getting confused between page allocation of physical RAM, and paging memory to disk (swapfile). Two completely different things Smile

Quote:
Also, how do I make the app run anywhere? I thought about having it start at $0000 and have all the calls and jumps be virtual addresses. Would that work?


There are several ways you can tackle this, but that doesn't matter because you are a *looooong* way away from running other applications.
Kllrnohj wrote:
graphmastur wrote:
I understand dividing the memory in pages, because you can only read so much at a time


That isn't why you use pages at all. Think about it like this, if you allocated on a per-byte basis for the MMU, you would essentially end up with half the amount of RAM since half of it will go to managing the other half. Instead we use pages, because then you just track chunks of memory, which results in much, much less overhead. You can also do things with pages like limit access (so page 1 can be read/write, but page 2 is read only, etc...)

Quote:
but i don't understand it in regards to paging for apps.


That is because you are probably getting confused between page allocation of physical RAM, and paging memory to disk (swapfile). Two completely different things Smile

Quote:
Also, how do I make the app run anywhere? I thought about having it start at $0000 and have all the calls and jumps be virtual addresses. Would that work?


There are several ways you can tackle this, but that doesn't matter because you are a *looooong* way away from running other applications.

Okay. I'll re-read the paging section.
*necrobump*

For Fishbot/Qwerty, a nifty map of the Linux kernel:

http://www.makelinux.net/kernel_map
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement