What's next for my kernel?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

What's next for my kernel?

Post by osdf_1 »

Hi, what should I try to add to my kernel now? Here's what it does:

- Set up new GDT
- Set up IDT
- Set up ISRs
- Set up IRQs
- Set up video functions (printChar(), print(), etc)
- Handle keyboard

I read somewhere, I believe in Bran's Kernel Development Tutorial (that's the one I read to go this far), that I should go on with memory management. Is this an easy task? What about running applications? Is that something you can do about now?
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

Re: What's next for my kernel?

Post by leledumbo »

... I should go on with memory management. Is this an easy task?
Absolutely NO! I've passed through thousands of triple faults because of it.
What about running applications? Is that something you can do about now?
Try SkelixOS. I don't think it's possible before you have a memory manager, how would you give memory space to your application without it?
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: What's next for my kernel?

Post by Stevo14 »

leledumbo wrote:
... I should go on with memory management. Is this an easy task?
Absolutely NO! I've passed through thousands of triple faults because of it.
I have to respectfully disagree. Memory management is probably the next thing that needs to be done in osdf_1's kernel.

I would recommend starting with a simple "watermark" allocator for physical memory. See the wiki: Memory_Allocation. Especially the first part called "a very simple memory manager".
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: What's next for my kernel?

Post by Brendan »

Hi,
Stevo14 wrote:
leledumbo wrote:
... I should go on with memory management. Is this an easy task?
Absolutely NO! I've passed through thousands of triple faults because of it.
I have to respectfully disagree. Memory management is probably the next thing that needs to be done in osdf_1's kernel.

I agree with Stevo - memory manager should come next.
I also agree with Leledumbo - implementing a memory manager isn't an easy task (or at least, IMHO implementing memory manager/s *shouldn't* be an easy task).

Note 1: If you think memory manager/s are easy, then you're probably not trying hard enough (e.g. not optimizing enough, not supporting enough features, etc).... :D

Note 2: Regardless of how hard or easy it is, postponing it won't make it easier!


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Re: What's next for my kernel?

Post by naiksidd_85 »

True I do think memory manager is most important part that should come up in the line.
Creating an memory manager is not and easy job but, again its your design desicion.
you may want your memory manager to just create pages of specified size and have a link list of it. Or you may want to implement something like variable size pages all linked so that no memory is wasted.

You may even go ahead and try to write drivers like basic devices eg floppy drive or cd rom butyou wont be able to continue far without memory manager
Learning a lot these days THANKS to OSdev users
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: What's next for my kernel?

Post by jal »

Brendan wrote:Note 1: If you think memory manager/s are easy, then you're probably not trying hard enough (e.g. not optimizing enough, not supporting enough features, etc).... :D
Memory managers are not easy, but a basic memory manager is simple enough. Optimizing and the like can wait for later. No need to dive into page-colouring-mixed-bitmap-stack-allocation and the like directly. First keep it simple, improve later.


JAL
User avatar
AndrewAPrice
Member
Member
Posts: 2327
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: What's next for my kernel?

Post by AndrewAPrice »

I think you should decide to go with a memory manager. Memory management isn't a scary field like it's made out to be. Are you going to use paging (must easier than a flat memory model since you don't need to reply on position independent code)? It's not that difficult.. You just need to divide the memory in to pages (usually 4KB but you can do 4MB also), keep a list of free/used pages (a huge bitmap with 1 set if a page is allocated, 0 if it's free), and have a function for finding the next free page. Set up a simple data structure in memory (an array of addresses with a few special bit set), pass the processor the address, and you're all set :)

I recommend porting a stable malloc implementation. liballoc is nice since it only requires a few hook functions (so it can use your code to find the next free page). Then you'll have malloc/free and life will be much simpler for the time being (since you can use dynamically sized strings in paths, allocate objects during runtime, you can use linked lists).

After you have a memory manager I would recommend you get programs loading and executing (Grub modules help a lot since you don't need a file system or disk driver). Each program will require it's own table of pages.

That should keep you occupied for a while. Once that is done get a system working to communicate between os<->program (interrupts are commonly used), then I would focus on what level of abstraction for your drivers (you already have a keyboard and screen driver!) One of the problems I had earlier on was getting ahead of myself here and forgetting what level of abstraction I wanted.

If any of that seems scary, I assure you it's not. We're here to help :)

Just remember, divide your goals (and your code) up in to small easy chunks, and do them one by one. e.g.

Code: Select all

void init_paging()
{
    /* Step 1: construct a list of pages and mark everyone as free (except for the first few MB for the kernel/grub) */
    /* (skip step 2/3 until you want to start loading programs) */
    /* Step 2: make the relevant page tables (huge array of addresses) and page directory (a table of page tables)*/
    /* Step 3: give the processor the location of the page directory */
}

unsigned int allocate_page_for_kernel(unsigned int noPages)
{
    /* Step 1: scan through list and find free pages */
    /* Step 2: mark those pages as being used */
    /* Step 3: return the address of the first page */
}

vod free_page_from_kernel(unsigned int firstpage, unsigned int noPages)
{
    /* Step 1: loop through each page allocated, mark each one as free */
}
My OS is Perception.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Re: What's next for my kernel?

Post by lukem95 »

@ MessiahAndrw

That's some great advice, if there was a rating system on osdev, i'd give you 5 stars :)
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: What's next for my kernel?

Post by inflater »

That's some great advice, if there was a rating system on osdev, i'd give you 5 stars
Oh please. :roll:

Before adding a memory manager, I would create a simple fdd/hdd driver and separate the shell off the kernel file. I think kernel itself needs no memory managment, as the kernel developer should know what parts of RAM are used or not (or to reserve e.g. two megabytes before the shell and applications).

Also I would forget about paging and virtual memory completely, but that's just me :)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: What's next for my kernel?

Post by JamesM »

inflater wrote:
That's some great advice, if there was a rating system on osdev, i'd give you 5 stars
Oh please. :roll:

Before adding a memory manager, I would create a simple fdd/hdd driver and separate the shell off the kernel file. I think kernel itself needs no memory managment, as the kernel developer should know what parts of RAM are used or not (or to reserve e.g. two megabytes before the shell and applications).

Also I would forget about paging and virtual memory completely, but that's just me :)
:| What horrible advice! Loading drivers and user programs before you have memory management? That means you have to retrofit and change all your abstractions once you finally implement one.

IMHO that's just a hack to get yourself to the stage where you can see results quicker. Not the best idea in the slightest.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: What's next for my kernel?

Post by inflater »

JamesM wrote:Loading drivers and user programs before you have memory management?
Nope.
me wrote:I would create a simple fdd/hdd driver and separate the shell off the kernel file.
I do this because my kernel starts from real mode (and kernels not-using GRUB do that too) and plus, separating it will give you a stability increase. :)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: What's next for my kernel?

Post by Korona »

inflater wrote:I think kernel itself needs no memory managment, as the kernel developer should know what parts of RAM are used or not (or to reserve e.g. two megabytes before the shell and applications).
If the kernel has no memory manager it cannot allocate memory for task, thread and ipc structures. I would suggest to implement paging code early. If you wait until your kernel becomes bigger you'll have to modify lots of code fragments that have to use virtual addresses instead of physical ones when paging is enabled.
Implementing memory management is a good idea as it makes other tasks easier/possible. (such as writing drivers for a monolithic kernel).
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: What's next for my kernel?

Post by bewing »

There is a big difference between a physical memory allocator, and a virtual memory allocator.

During the kernel initialization phase, you certainly need to do some simple physical memory allocation. You certainly do not need to use virtual memory at all.

Your next step (to be more detailed about it) is going to be to parse the hardware memory map that you get from GRUB, or the BIOS. Then you probably need to allocate some important buffers and arrays for your kernel. Then you need to set up a physical memory heap. Then you need to write (or find) a nice physical memory malloc/free function.

You may (or may not) find it useful (several steps from now) to create temporary singletasking-mode drivers, that will read disks and things until you have multitasking up and running (several steps after that).
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: What's next for my kernel?

Post by osdf_1 »

Is all this needed if I'm writing a single-task kernel? If not, would my next step be implementing a kind of file system?
Post Reply