Page 4 of 5

Re: Multitasking in real mode?

Posted: Fri Mar 29, 2013 10:55 pm
by Prochamber
m12 wrote:I never said it was a good idea - i said it was possible, and that if somebody finds a way to do it better than they can in pmode, then it is a good idea then.
You were actually right though. Although protected mode frees us from addressing limitation, the whole point of protected mode is to impose limitations on what programs can do not to take them away. I'm not saying this is bad, most of the best features of protected mode like memory protection and instruction permissions come imposing limitations on programs.
Brendan wrote:
Prochamber wrote:
Brendan wrote:A "write-through" disk cache isn't very much work at all.
It's not as simple as it seems.
Currently the kernel has no way to know the actual address in which task memory is located, it just know which memory handle that the task uses.
The kernel doesn't need to know the actual address in which task memory is located - it only needs to know which address the task is reading the data to (or writing the data from), and the kernel can get this information from ES:BX when the task uses "int 0x13".
Yes this is true, but the task will be at a different location when it is inactive to when it is active and made the request. This location which will not be known. Therefore data will have to be stored in a buffer until the task becomes active again. What if the task is paused or killed before the request is complete? The data might never be collected. The only solution I can see is to give each task it's own 64k buffer. Wouldn't this require the writing of complex disk drivers?
Brendan wrote:I've got some experimental crud I wrote a few weeks ago. It's a wrapper around the BIOS that lets protected mode software use BIOS services directly
It's some very nice code you've got but I'm not sure if I want the future of my operating system to rely on a little experimental code or use protected mode. It would be a good way to get into protected mode if I ever want to.
Brendan wrote:It would allow you to fill the first 3 GiB of RAM with about 40000 of your little 64 KiB applications and run them where they are
Actually including buffers, kernel space, stack spaces, etc that would be more like ten thousand. With 16 tasks the most I would need is four megabytes of memory, though I probably want a bit extra just in case programs allocate more.
My memory allocation system allows up to eight megabytes of memory in sizes of 512 bytes.

I plan to save:
  • All registers and segment registers include the instruction pointer.
  • The BIOS Data Area - 256b
  • Stack Space - 4k
  • Kernel Space - 64k
  • Program Space - 64k
  • Individual Video Buffers - 64k
Is there anything I missed?

PS It's a bit off topic but I have nice mouse driver in NASM that I recently made and I want to help others make theirs, should I upload code for it on a new post?

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 1:32 am
by iansjack
Although protected mode frees us from addressing limitation, the whole point of protected mode is to impose limitations on what programs can do not to take them away.
Not quite true. One of the features of protected mode is to allow the operating system to impose limitations on what userland programs can do. (But you don't have to choose to do that if - for some inexplicable, crazy reason - you don't want to.) This is a significant increase in the capabilities of the OS. Very few people start off their OS design by saying "I want userland programs to have the ability to trash each others memory and (important in view of your previous remarks) overwrite the IDT so even the timer interrupt doesn't work".

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 1:49 am
by bluemoon
Prochamber wrote:the task will be at a different location when it is inactive to when it is active and made the request. This location which will not be known.
I don't quite get you here.It's your kernel that swap the process out, why don't you know the location? Just think a way to pass this information out, like storing on process's information node.
Prochamber wrote:What if the task is paused or killed before the request is complete? The data might never be collected
The kernel need to handle resource cleanup upon task end, including process's memory, buffers, locks and perhaps device's handle.

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 1:59 am
by bluemoon
Prochamber wrote: I plan to save:
  • All registers and segment registers include the instruction pointer.
  • The BIOS Data Area - 256b
  • Stack Space - 4k
  • Kernel Space - 64k
  • Program Space - 64k
  • Individual Video Buffers - 64k
Is there anything I missed?
How about:
- process specific information (aka program segment prefix in DOS term)
- process's resource mapping (device handle, file control block, etc)

By the why, what is included in the kernel space? Note that some of the kernel memory should be shared across all process (ie. those global variables in your kernel) If you save/restore that region you may mess up the kernel's program flow; on the other hand, static content of the kernel need not to be saved, if they are corrupted by program you're doom anyway.

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 3:09 am
by Brendan
Hi,
Prochamber wrote:
Brendan wrote:
Prochamber wrote:It's not as simple as it seems.
Currently the kernel has no way to know the actual address in which task memory is located, it just know which memory handle that the task uses.
The kernel doesn't need to know the actual address in which task memory is located - it only needs to know which address the task is reading the data to (or writing the data from), and the kernel can get this information from ES:BX when the task uses "int 0x13".
Yes this is true, but the task will be at a different location when it is inactive to when it is active and made the request.
Who cares? You'd only care which address the task wants when you're copying data from the cache to the task (reads) or from the task to the cache (writes). Further, you won't be switching tasks if any actual disk IO is involved because your entire OS will be "locked up" (waiting) while it's using BIOS's "int 0x13" code. Also note that if you had your own drivers for disk IO there still wouldn't be any problem because the driver would be reading/writing data into the cache and not into the task's buffer.
Prochamber wrote:
Brendan wrote:I've got some experimental crud I wrote a few weeks ago. It's a wrapper around the BIOS that lets protected mode software use BIOS services directly
It's some very nice code you've got but I'm not sure if I want the future of my operating system to rely on a little experimental code or use protected mode. It would be a good way to get into protected mode if I ever want to.
I was hoping you'd be smart enough to see how it works and implement your own version (or just make whatever changes) based on the same simple/easy idea. I was also hoping that (after seeing how simple/easy it is) you'd realise that not using protected mode is completely and utterly pointless; and that it doesn't prevent you from using the BIOS and doesn't prevent you from achieving any of your goals (e.g. you'd still be able to make an extremely bad OS despite using protected mode a little).
Prochamber wrote:
Brendan wrote:It would allow you to fill the first 3 GiB of RAM with about 40000 of your little 64 KiB applications and run them where they are
Actually including buffers, kernel space, stack spaces, etc that would be more like ten thousand. With 16 tasks the most I would need is four megabytes of memory, though I probably want a bit extra just in case programs allocate more.
My memory allocation system allows up to eight megabytes of memory in sizes of 512 bytes.
Why would you have a maximum of only 16 tasks and a maximum of only 8 MiB? Are you worried that someone might think you're a competent programmer, or is there some sort of "worst OS possible" contest where you might win a banana?


Cheers,

Brendan

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 7:51 am
by Prochamber
iansjack wrote:Not quite true. One of the features of protected mode is to allow the operating system to impose limitations on what userland programs can do. (But you don't have to choose to do that if - for some inexplicable, crazy reason - you don't want to.) This is a significant increase in the capabilities of the OS. Very few people start off their OS design by saying "I want userland programs to have the ability to trash each others memory and (important in view of your previous remarks) overwrite the IDT so even the timer interrupt doesn't work".
Yea, my point exactly. I never said that the limitations were bad just that the point of protected mode was to add limitations that limit the effect programs can have on the operating system not to remove limitations on programs since in real mode they don't have any.
Also in my previous remarks I just meant the system would keep working if they mess up a single non-essential interrupt handler i.e. a keyboard handler not IRQ 0.
bluemoon wrote:I don't quite get you here.It's your kernel that swap the process out, why don't you know the location? Just think a way to pass this information out, like storing on process's information node.
Ah, but it's not the kernel that swaps processes out. This task is done by an independent multitasking layer. The multitasking layer keeps track of who's who and how they access certain resources plus any global variables. The kernel has many API calls which can be called by programs and contain temporary buffers with their workings that need to be preserved.

Each process has it's own copy of the kernel, which it uses independently as it would in a monotasking environment except it gets interrupted at timer ticks and shifted in and out of memory and the low level BIOS interface that it uses is manipulated by the multitasking layer to change the effect of it's actions depending on the conditions.

Prochamber wrote:What if the task is paused or killed before the request is complete? The data might never be collected
The kernel need to handle resource cleanup upon task end, including process's memory, buffers, locks and perhaps device's handle.[/quote]
Brendan wrote:Who cares? You'd only care which address the task wants when you're copying data from the cache to the task (reads) or from the task to the cache (writes). Further, you won't be switching tasks if any actual disk IO is involved because your entire OS will be "locked up" (waiting) while it's using BIOS's "int 0x13" code. Also note that if you had your own drivers for disk IO there still wouldn't be any problem because the driver would be reading/writing data into the cache and not into the task's buffer.
I meant if I used caching instead of freezing the system. I suppose having a disk cache for each task would be realistic, I can have a 32k memory handle for each task that data gets put if when it arrives. However looking at the disk controller specifications on the OSDev Wiki they are anything but simple. Even a floppy disk controller is very complex. If I do add disk drivers, it might need to be a few more releases down the track.
Brendan wrote:I was hoping you'd be smart enough to see how it works and implement your own version (or just make whatever changes) based on the same simple/easy idea. I was also hoping that (after seeing how simple/easy it is) you'd realise that not using protected mode is completely and utterly pointless; and that it doesn't prevent you from using the BIOS and doesn't prevent you from achieving any of your goals (e.g. you'd still be able to make an extremely bad OS despite using protected mode a little).
Protected mode is certainly an interesting idea but I'm fine with real mode. I really don't see any reason why I should go to the effort of rewriting my operating system for protected mode when real mode works fine for me as it always has. I'm not saying that there is anything wrong with protected mode but it's just not for me.
Brendan wrote:Why would you have a maximum of only 16 tasks and a maximum of only 8 MiB? Are you worried that someone might think you're a competent programmer, or is there some sort of "worst OS possible" contest where you might win a banana?
I learnt from MikeOS, which taught me that making operating systems isn't about jumping right into complex features and implementing
them in the most complex way imaginable. Sixteen tasks is more than enough for what I need.
In a standard system I might be running:
  • A kernel service
  • A graphical interface service
  • A rendering service (maybe even part of the interface service)
  • A text editor
  • Another Desktop Program
I can't really see where all sixteen tasks would go. I only have five windows open on the operating system I am using to write this post and most of the system tasks are complex things I wouldn't need in my operating system anyway. I would have thought that sixteen tasks would be enough for almost all the operating systems on this site.

I am a realist. I do not want to waste years on something that it too complex and difficult for me to ever complete. I know what I can do in a realistic time frame and I know what I can't. If there is some way to make my job easier I will take it because it will allow me to create something better in the same time frame. BIOS happens to do this so I use it. Writing my own disk drivers does not.

If I want to write my own disk drivers, I will do that at a later release. For now I will work on getting the multitasking system working then add features to it. I'd rather do what I do now and have frequent releases, slowly adding features than spend years building up to some almighty release that I may or may not finish. It's worked well for me so far.

On subject of competitions I don't think you're going to win and for politeness. I see that your next post will be your 5000th on this forum, so I recommend you have a good rest and a few extra teaspoons of sugar in your morning coffee before hand.

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 9:18 am
by shikhin
Hi,

I'd not consider myself the best candidate for replying to the posts, but I just read it, and thought I wanted to butt in. If you think I'm just adding to the flame, kindly ignore the post (or go as far as to report it, so some moderator can take it out).
Prochamber wrote:since in real mode they don't have any
Prochamber wrote:when real mode works fine for me as it always has
Which is why you've been busy on this thread for doing task switching properly, while it should be pretty trivial in protected mode? :)
Prochamber wrote:making operating systems isn't about jumping right into complex features and implementing them in the most complex way imaginable
Yep, which is why you go the easy way with protected mode and do protection easily (rather than doing things like copying around the BDA, trying to save yourself from the wrath of privleged user space code, and stuff like that).
Prochamber wrote:I am a realist. I do not want to waste years on something that it too complex and difficult for me to ever complete. I know what I can do in a realistic time frame and I know what I can't. If there is some way to make my job easier I will take it because it will allow me to create something better in the same time frame. BIOS happens to do this so I use it. Writing my own disk drivers does not.

If I want to write my own disk drivers, I will do that at a later release. For now I will work on getting the multitasking system working then add features to it. I'd rather do what I do now and have frequent releases, slowly adding features than spend years building up to some almighty release that I may or may not finish. It's worked well for me so far
MikeOS' earliest reference I can find is from OS news. For comparision sake, let's take up one of my favorite protected mode OS -- Sortix, written by sortiecat. Sortix was started in April 2011; the first version of MikeOS was released in September 2007. MikeOS lists its features as "text-mode dialog and menu-driven interface; boots from a floppy disk, CD-ROM or USB key; over 60 system calls for use by third-party programs; file manager, text editor, image viewer, games; includes a BASIC interpreter with 46 instructions; PC speaker sound and serial terminal connection." Sortix lists its features as keyboard driver, multitasking, multithreaded kernel, reasonable libc and POSIX support, (wip: package management), gcc/binutils/make port, quake, video player, (ports of other stuff), self-compiling, a bad harddisk driver, not-entirely-but-a-bit bad kernel, an ok-but-hacky shell, lots of small utlity programs, user-space filesystem support (wip), various games, graphics, ..."

I'm not here to compare OSes. MikeOS does its job well -- and most probably achieves the goals it wanted to. Neither am I to say sortiecat did a faster job at writing his OS; everyone has limitations on time. What I'm trying to say is, that:
  1. You CAN write a protected mode OS with good enough features in a short period of time (note that Sortix was the author's [sortiecat] first project).
  2. Your goals fit more along Sortix' direction. For example, I doubt Mike had "multitasking" as his goal when he wrote his OS.
Prochamber wrote:On subject of competitions I don't think you're going to win and for politeness. I see that your next post will be your 5000th on this forum, so I recommend you have a good rest and a few extra teaspoons of sugar in your morning coffee before hand.
While Brendan may be an elitist for 100% of the time, it's well worth noting that almost EVERYONE (with goals like multitasking) uses protected mode. Not doing so... isn't doing it the easy way. It's doing it the hard way, and then claiming it's easy.

Just because the processor lands up first in real mode (due to chronological order of features) doesn't make it the easier one.

Regards,
Shikhin

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 11:21 am
by AJ
Hi,

Why is the impression given in this thread that it's PMode (rather than Long Mode) that should be the contemporary target of choice? Surely protected mode is becoming as much of an anachronism as Real Mode.
Brendan wrote:I've got some experimental crud I wrote a few weeks ago. It's a wrapper around the BIOS that lets protected mode software use BIOS services directly
I did the same when I was writing a bootloader. Stage 1 did disk access and provided real mode function calls for this. Stage 2 did relocation and mode changes and then provided PMode wrappers for said real mode function calls in stage 1. Real mode functions exposed were 'seek', 'read' and a generic on for calling any BIOS service. It sounds messy, but worked very well.

Having said that, the aim was never to use these wrappers as a replacement for 'proper' drivers once the kernel had actually booted. It did at least make for a boot-medium agnostic stage 2 and a binary format agnostic stage 1.

Cheers,
Adam

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 11:55 am
by iansjack
I agree about long mode (although 32-bit OSs are still prevalent), but protected mode is far closer to it than real mode is to pm, IMO.

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 4:53 pm
by Brendan
Hi,
Prochamber wrote:
Brendan wrote:Why would you have a maximum of only 16 tasks and a maximum of only 8 MiB? Are you worried that someone might think you're a competent programmer, or is there some sort of "worst OS possible" contest where you might win a banana?
I learnt from MikeOS, which taught me that making operating systems isn't about jumping right into complex features and implementing
them in the most complex way imaginable.
There are 3 issues here: using real mode for things like applications and the kernel, using the BIOS for drivers, and having arbitrary limitations for no reason whatsoever. These are all completely separate things.

Using real mode for things like applications and the kernel is completely pointless. There is no sane reason to do this - it only makes everything harder. It's impossible to justify.

Using BIOS for drivers does make things easier in the beginning; but makes things harder in the long run. It's like building a pretend car out of cardboard - it gives the illusion of progress, but as soon as you attempt to replace the transmission or steering or engine with something that actually works properly the cardboard lacks the strength to support it and the project falls apart.

Arbitrary limitations for no reason whatsoever is just plain incompetence. It doesn't matter if it's a linked list that is only able to store 20 things, or a file system that can only store 4 files, or a scheduler that can only handle 16 tasks, or a memory manager than can only handle 8 MiB. You have to have an actual reason for limitations like this; like "the hardware can't handle more", or "task IDs are 4-bit and can't be increased without breaking backward compatibility", or "there is no RAM so I have to use the CPU's cache instead, and the CPU's cache is only 8 MiB".

The only thing you've learned from MikeOS is to be too afraid to try.


Cheers,

Brendan

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 5:29 pm
by Prochamber
Brendan wrote: Arbitrary limitations for no reason whatsoever is just plain incompetence. It doesn't matter if it's a linked list that is only able to store 20 things, or a file system that can only store 4 files, or a scheduler that can only handle 16 tasks, or a memory manager than can only handle 8 MiB. You have to have an actual reason for limitations like this; like "the hardware can't handle more", or "task IDs are 4-bit and can't be increased without breaking backward compatibility", or "there is no RAM so I have to use the CPU's cache instead, and the CPU's cache is only 8 MiB".
You're right about arbitrary limitations being pointless but having a scheduler that can only handle sixteen tasks is not the same as having a file system that can only handle four files. I would typically use twenty to thirty files in my operating system but I can't what I would use all sixteen task for.

These limitations are not arbitrary. My reasoning for imposing limitations on the number of tasks is memory limitations, I have eight megabytes of memory and each task takes 256 KB of memory at most. My logic is that running tasks should only take up half the memory because they may need memory as well.
So:
(8 * 0.25) / 2 = 16 tasks

Next, memory limitations.
Half the kernel segment is specialized buffer space (32k). A generous half of this buffer space (16k) is allocated to a memory allocation bitmap. I use a bitmap because it is the simplest way to allocate memory. Memory is allocated by the memory manager in blocks of 512 bytes.
So:
Memory Size = Block Size * Number of Block
512 * 16 * 1024 = 8 MB

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 6:06 pm
by Brendan
Hi,
Prochamber wrote:
Brendan wrote: Arbitrary limitations for no reason whatsoever is just plain incompetence. It doesn't matter if it's a linked list that is only able to store 20 things, or a file system that can only store 4 files, or a scheduler that can only handle 16 tasks, or a memory manager than can only handle 8 MiB. You have to have an actual reason for limitations like this; like "the hardware can't handle more", or "task IDs are 4-bit and can't be increased without breaking backward compatibility", or "there is no RAM so I have to use the CPU's cache instead, and the CPU's cache is only 8 MiB".
You're right about arbitrary limitations being pointless but having a scheduler that can only handle sixteen tasks is not the same as having a file system that can only handle four files. I would typically use twenty to thirty files in my operating system but I can't what I would use all sixteen task for.

These limitations are not arbitrary. My reasoning for imposing limitations on the number of tasks is memory limitations, I have eight megabytes of memory and each task takes 256 KB of memory at most. My logic is that running tasks should only take up half the memory because they may need memory as well.
So:
(8 * 0.25) / 2 = 16 tasks
So you're saying that "16 tasks" is an arbitrary limit; and that you should have no limit (or maybe 65536 tasks or something) and return an "out of memory" error if an application tries to start a task but can't because there isn't enough memory?

Prochamber wrote:Next, memory limitations.
Half the kernel segment is specialized buffer space (32k). A generous half of this buffer space (16k) is allocated to a memory allocation bitmap. I use a bitmap because it is the simplest way to allocate memory. Memory is allocated by the memory manager in blocks of 512 bytes.
So:
Memory Size = Block Size * Number of Block
512 * 16 * 1024 = 8 MB
Why 512 byte blocks? Why not 128 byte blocks or 1024 byte blocks (or 4096 byte blocks)?

Why 16 KiB for the bitmap? Why not 15 KiB or 17 KiB?

More importantly; why not "%define MEM_MANAGER_BITMAP_SIZE 512", or have code to determine the bitmap's size during boot?

Think of it like this: my computer has 12 GiB of RAM, and you're going to waste 99.99993642% of that RAM because you're worried that a larger bitmap might use too much memory (!?). If you were only wasting 75% of the RAM then that'd actually make sense to me (as using more than 3 GiB of it would require paging/PAE).


Cheers,

Brendan

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 7:15 pm
by Prochamber
Brendan wrote:
Prochamber wrote:
Brendan wrote: Arbitrary limitations for no reason whatsoever is just plain incompetence. It doesn't matter if it's a linked list that is only able to store 20 things, or a file system that can only store 4 files, or a scheduler that can only handle 16 tasks, or a memory manager than can only handle 8 MiB. You have to have an actual reason for limitations like this; like "the hardware can't handle more", or "task IDs are 4-bit and can't be increased without breaking backward compatibility", or "there is no RAM so I have to use the CPU's cache instead, and the CPU's cache is only 8 MiB".
You're right about arbitrary limitations being pointless but having a scheduler that can only handle sixteen tasks is not the same as having a file system that can only handle four files. I would typically use twenty to thirty files in my operating system but I can't what I would use all sixteen task for.

These limitations are not arbitrary. My reasoning for imposing limitations on the number of tasks is memory limitations, I have eight megabytes of memory and each task takes 256 KB of memory at most. My logic is that running tasks should only take up half the memory because they may need memory as well.
So:
(8 * 0.25) / 2 = 16 tasks
So you're saying that "16 tasks" is an arbitrary limit; and that you should have no limit (or maybe 65536 tasks or something) and return an "out of memory" error if an application tries to start a task but can't because there isn't enough memory?
No, I'm saying that I chose to use sixteen tasks because it uses exactly half the memory if I impose this limit there will always be enough memory to start new tasks. Tasks take memory but I don't want them to use it all up. Remind me again why all these tasks are needed.
Brendan wrote:
Prochamber wrote:Next, memory limitations.
Half the kernel segment is specialized buffer space (32k). A generous half of this buffer space (16k) is allocated to a memory allocation bitmap. I use a bitmap because it is the simplest way to allocate memory. Memory is allocated by the memory manager in blocks of 512 bytes.
So:
Memory Size = Block Size * Number of Block
512 * 16 * 1024 = 8 MB
Why 512 byte blocks? Why not 128 byte blocks or 1024 byte blocks (or 4096 byte blocks)?

Why 16 KiB for the bitmap? Why not 15 KiB or 17 KiB?

More importantly; why not "%define MEM_MANAGER_BITMAP_SIZE 512", or have code to determine the bitmap's size during boot?

Think of it like this: my computer has 12 GiB of RAM, and you're going to waste 99.99993642% of that RAM because you're worried that a larger bitmap might use too much memory (!?). If you were only wasting 75% of the RAM then that'd actually make sense to me (as using more than 3 GiB of it would require paging/PAE).
My current computer has 16 GB of RAM but I don't feel any compulsion to use every last byte.

Don't forget I still need to have the memory allocation bitmap somewhere where it can be read by the memory manager.
Sixteen kilobytes is half of the kernel buffer space. It's a nice round number and all the other buffers fit in nicely. The block size is the size it is because memory handles must of course be swapped in and out of application memory. I don't want blocks too large because that would force applications to allocate huge buffers but I don't want blocks too small because the would limit the amount of memory. What block size are you suggesting?

I could put the memory allocation bitmap in the unused segment 0x5000, giving me 64 KB rather than 16 KB to allocate memory and freeing up buffer space. This would allow up to 32 MB of memory and 64 tasks. This is actually a lot of memory, 33,554,432 bytes, perhaps nothing compared to what a "modern" operating system would use but more than enough for my purposes.

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 8:31 pm
by Brendan
Hi,
Prochamber wrote:
Brendan wrote:
Prochamber wrote:You're right about arbitrary limitations being pointless but having a scheduler that can only handle sixteen tasks is not the same as having a file system that can only handle four files. I would typically use twenty to thirty files in my operating system but I can't what I would use all sixteen task for.

These limitations are not arbitrary. My reasoning for imposing limitations on the number of tasks is memory limitations, I have eight megabytes of memory and each task takes 256 KB of memory at most. My logic is that running tasks should only take up half the memory because they may need memory as well.
So:
(8 * 0.25) / 2 = 16 tasks
So you're saying that "16 tasks" is an arbitrary limit; and that you should have no limit (or maybe 65536 tasks or something) and return an "out of memory" error if an application tries to start a task but can't because there isn't enough memory?
No, I'm saying that I chose to use sixteen tasks because it uses exactly half the memory if I impose this limit there will always be enough memory to start new tasks. Tasks take memory but I don't want them to use it all up.
Why not set a "half the (usable) memory" limit?
Prochamber wrote:Remind me again why all these tasks are needed.
Only a fool would attempt to predict how many tasks any end user might want. The only thing you can predict is "lower limits are less likely to disappoint".

Apparently, I'm currently using 188 processes on Linux; but Linux supports multi-threading - if it didn't support multi-threading some of those processes would "fork()" instead of using threads and there'd be even more processes. Of course your OS is very different to Linux. For your OS something like a "paint.exe " would need to use 500 processes just to get enough RAM to store a picture.
Prochamber wrote:
Brendan wrote:
Prochamber wrote:Next, memory limitations.
Half the kernel segment is specialized buffer space (32k). A generous half of this buffer space (16k) is allocated to a memory allocation bitmap. I use a bitmap because it is the simplest way to allocate memory. Memory is allocated by the memory manager in blocks of 512 bytes.
So:
Memory Size = Block Size * Number of Block
512 * 16 * 1024 = 8 MB
Why 512 byte blocks? Why not 128 byte blocks or 1024 byte blocks (or 4096 byte blocks)?

Why 16 KiB for the bitmap? Why not 15 KiB or 17 KiB?

More importantly; why not "%define MEM_MANAGER_BITMAP_SIZE 512", or have code to determine the bitmap's size during boot?

Think of it like this: my computer has 12 GiB of RAM, and you're going to waste 99.99993642% of that RAM because you're worried that a larger bitmap might use too much memory (!?). If you were only wasting 75% of the RAM then that'd actually make sense to me (as using more than 3 GiB of it would require paging/PAE).
My current computer has 16 GB of RAM but I don't feel any compulsion to use every last byte.
You're supposed to be writing an OS. An OS's job is to provide an environment for applications to use. The OS shouldn't be using all that RAM, it should be allowing "whatever applications the user feels like using" to use that RAM.
Prochamber wrote:Don't forget I still need to have the memory allocation bitmap somewhere where it can be read by the memory manager.
Sixteen kilobytes is half of the kernel buffer space. It's a nice round number and all the other buffers fit in nicely. The block size is the size it is because memory handles must of course be swapped in and out of application memory. I don't want blocks too large because that would force applications to allocate huge buffers but I don't want blocks too small because the would limit the amount of memory. What block size are you suggesting?
Given that you seem to want to do a lot of extra work just to make the OS more retarded; it's a bit hard to make sane suggestions.

However; I'd consider given each task one 512 KiB block. It's a nice round number and leaves about 100 KiB for the kernel to use (without copying) in real mode. You could even pre-allocate these blocks during boot and not bother having any memory manager at all (e.g. "task number 4 uses memory block number 4"). You could also do "max. tasks = RAM between 0x00100000 and 0xFFFFFFFF / 512 KiB" (and end up with a limit of about 6142 tasks on machines with 3 GiB or more RAM).

Basically; it'd be significantly less limited, and it'd also be easier to implement.

Of course it'd still be bad (e.g. lots of RAM wasted by tasks that only use part of the 512 KiB they're given), but it's a few orders of magnitude less bad than wasting 99.99% of RAM.


Cheers,

Brendan

Re: Multitasking in real mode?

Posted: Sat Mar 30, 2013 9:25 pm
by Nessphoro
It seems as though OP has read too much Necronomicon and is now trying to bring something from the dead for no apparent reason other than that he is too lazy to write a x86 emulator if he ever so wishes to have access to bios.

IMO, why plague yourself with real mode et al when there are better alternatives - ex. Identity mapped page table along with relocations so that tasks can be ran from any address.

While you're at it: do the whole thing in PHP.