Page 1 of 1

Design of memory setup

Posted: Sat Feb 28, 2004 4:13 pm
by beyondsociety
I am going to support VM86, so I need to keep the 1MB of address space free for it. I also would eventually want to support ISA cards, DMA for floppy, so I need to keep from 2MB - 16MB free for that. Given that in mind, I would like to load the kernel from 16MB - 1GB and place the user on top of that from 1GB and on.

Now in order to run VM86, I need a way to access user mode ring 3.
Suffice to say that if you've chosen to put your kernel in the bottom half and your applications in the top half, you're stuck (unless you re-map the first megabyte so that it's accessible to ring 3 and make sure there's nothing important there
So this solves my problem. Theres only one catch.

Where do I run my vm86 code from? I suppose its in the kernel space, but if this is so; will I be able to access the vm86 code from the memory space outside of the kernel?

Second point: Can I have a kernel space from 1MB - 1GB and have the Vm86, ISA/DMA code inside of it?

Third point: If the vm86 code is in the kernel, is there a way to prevent the code from enterfering with other drivers and stuff found in the kernel?

Re:Design of memory setup

Posted: Sat Feb 28, 2004 5:37 pm
by Tim
beyondsociety wrote:I also would eventually want to support ISA cards, DMA for floppy, so I need to keep from 2MB - 16MB free for that.
DMA doesn't know about virtual memory, only physical. You can put DMA buffers anywhere within the processor's virtual address space, as long as their physical addresses are compatible with DMA.
Where do I run my vm86 code from? I suppose its in the kernel space, but if this is so; will I be able to access the vm86 code from the memory space outside of the kernel?
No, V86 is hard-wired to ring 3. You will get an exception if you try to use supervisor pages in V86 mode. But there's nothing stopping kernel code from accessing user pages.
Second point: Can I have a kernel space from 1MB - 1GB and have the Vm86, ISA/DMA code inside of it?
DMA: See above.

V86: Yes, but you'd have an 'island' of user-accessible memory in the middle of kernel memory. Mobius deals with this by having V86-mode code run in a separate kernel process, to which no application has access.
Third point: If the vm86 code is in the kernel, is there a way to prevent the code from enterfering with other drivers and stuff found in the kernel?
It's not actually in the kernel -- V86 code has the same privileges as any other ring 3 code. If you want it to access hardware etc. you have to allow it explicitly.

Did you see my V86 tutorial? If not, it would be a good idea to read it. It should explain as much there as I can here.

Re:Design of memory setup

Posted: Sun Feb 29, 2004 1:19 pm
by beyondsociety
Did you see my V86 tutorial? If not, it would be a good idea to read it. It should explain as much there as I can here.
Yes I did, but I guess I'll have to read it again. Im also at the moment re-looking over your memory management tuorials.

Re:Design of memory setup

Posted: Sun Feb 29, 2004 6:09 pm
by beyondsociety
After reading up on what the intel manuals say, I have a few questions and a design idea.
An 8086 program may generate linear addresses anywhere in the range "0 - 10FFEFh(1MB + 64 KB's)" of the tasks linear address space.

Vm86 tasks generate 32-bit linear addresses. While an 8086 program can only utilize the low-order 20 bits of a linear address, the linear address can be mapped via page tables to any 32-bit physical address.
So does this mean that I can put my vm86 tasks anywhere in virtual memory?

This is comming from here
No, and the reason is V86. It's not Dangerous to run it in kernel space, it's Impossible. V86 mode is hard-coded to ring 3 and to the bottom 1MB of address space. If you put the kernel at the bottom, then it means that the bottom 1MB of any process which runs V86 must be accessible to user mode, so the kernel will really be at 0010_0000 to 0040_0000.
In the intel manauls, it says that the vm86 monitor runs in CPL 0 mode. So that makes the kernel able to run vm86 tasks. So I realize that the kernel wouldnt actually run it but actually switch tasks to CPL 3 and then execute the vm86 tasks.
When you use both paging and V86 mode (not very uncommon), you have to map the page tables to 0x0 - 0x003FFFFF or 0xFFC00000 - 0xFFFFFFFF to make use of page directories that are also page tables, in other words, to save memory.
Is this true or can I map it anywhere? Also coming from above link.