I have been programming for 16-bit for a while, but was not able to transfer to protected mode with everything I needed answered... Can anybody help me?
1. Once transfered completely into protected mode, how can you change the memory? For example, if I am trying open a file, to run, I normally would find some free space, and put the code there, then just jump to the segment. In protected mode, I seem to have to change the memory in some way to have a free level 3 ring memory segment that I first write to, and then can only execute from after. How can I do this? (especially if multi-tasking).
2. Is there some tutorial that looks at mostly the interrupts and multi-tasking part? Most tutorials skip that saying something like 'we will stick to the basics'...
3. In multi-tasking, how can you detect which program is taking up more CPU (by precentage), and be able to set the priority of different programs, as done in windows?
4. If a bad command is sent by a 3 ring program, for example:
again: cli
hlt
jmp again
how can the OS detect this and stop it?
5. I have been able to set 4 GB of memory for my OS, but I don't understand how the computer knows what memory I want to allocate. In a tutorial, each memory segment seemed to be very similar to 16-bit.. bios sector, video sector, etc. ..but all on the same assigned 4 GB memory space that is for my OS. Can anybody explain how to remove this? ..and maybe change it so that there was also some memory assigned only for the video memory?
Sorry if I'm asking too much.. It's just that the tutorials usually hardly explain any of this...
Protected Mode
Re: Protected Mode
Ehm, well, quickly I got at least three answers.
2.http://www.distantvoices.org/html/multitasking.html
http://legendos.codingworld.net/tutoria ... ching.html
3. That is exactly your task to provide this functionality when you'll write your scheduler.
4. That would raise an exception already at the cli instruction. Then your kernel should kill this program.
2.http://www.distantvoices.org/html/multitasking.html
http://legendos.codingworld.net/tutoria ... ching.html
3. That is exactly your task to provide this functionality when you'll write your scheduler.
4. That would raise an exception already at the cli instruction. Then your kernel should kill this program.
*post*
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: Protected Mode
So I'll tackle the remaining two:
1. The same technique used in real mode can be used in protected mode. Load executable code into memory and jump to it. This implies that your code would be executed in ring 0. This is how I implemented my rZero (ie, ring zero) modules in my kernel.
More typically, however, you'll want applications to run in ring 2 or 3, which means you're going to need to switch privilege levels. You can do this through task gates, tss segments, etc. There are several different ways to go about this (I suggest a good protected mode book... I'll try and remember to post my favorite book on this topic. If i forget, remind me!).
My suggestion would be start executing code at ring 0 (because it's easy) and then, when you've decided how you want your multitasking code to work, *then* revisit this. Ideally you have several applications in memory, as well as the kernel, and drivers. It's entirely possible for you to switch back and forth between each of the above tasks, and (at the same time) switch to ring 0 for the kernel, ring 2 for drivers, and ring 3 for applications (or however you decide to divide these up). This is probably the approach you'll eventually want to use.
5. Memory is layed out exactly the same as rmode, technically... it's just accessed linearly, rather then through segments.
pmode_physical_address == rmode_segment * 16 + rmode_segment_offset
This is how you can access the entire memory space in one linear segment (you should already know that each segment is only 16 bytes long, so this shouldn't be new...).
In order to map certain portions of memory to other linear locations, you'll need to utilize the pager. This is another area where a pmode book is handy (and my pmode book describes this quite well, but I'm not at my place to write down the name and isbn, unfortunately). Essentially the pager allows you to create directories and tables which redefine where every page (aka 4096 bytes, or 4MB, with extensions) is located in physical memory and allows you to do what you want.
--Jeff
1. The same technique used in real mode can be used in protected mode. Load executable code into memory and jump to it. This implies that your code would be executed in ring 0. This is how I implemented my rZero (ie, ring zero) modules in my kernel.
More typically, however, you'll want applications to run in ring 2 or 3, which means you're going to need to switch privilege levels. You can do this through task gates, tss segments, etc. There are several different ways to go about this (I suggest a good protected mode book... I'll try and remember to post my favorite book on this topic. If i forget, remind me!).
My suggestion would be start executing code at ring 0 (because it's easy) and then, when you've decided how you want your multitasking code to work, *then* revisit this. Ideally you have several applications in memory, as well as the kernel, and drivers. It's entirely possible for you to switch back and forth between each of the above tasks, and (at the same time) switch to ring 0 for the kernel, ring 2 for drivers, and ring 3 for applications (or however you decide to divide these up). This is probably the approach you'll eventually want to use.
5. Memory is layed out exactly the same as rmode, technically... it's just accessed linearly, rather then through segments.
pmode_physical_address == rmode_segment * 16 + rmode_segment_offset
This is how you can access the entire memory space in one linear segment (you should already know that each segment is only 16 bytes long, so this shouldn't be new...).
In order to map certain portions of memory to other linear locations, you'll need to utilize the pager. This is another area where a pmode book is handy (and my pmode book describes this quite well, but I'm not at my place to write down the name and isbn, unfortunately). Essentially the pager allows you to create directories and tables which redefine where every page (aka 4096 bytes, or 4MB, with extensions) is located in physical memory and allows you to do what you want.
--Jeff