Adding Vm8086 to a flat memory model kernel
Posted: Wed Apr 23, 2014 3:48 am
Hey guys
I've decided to implement Vm8086 tasks for my kernel, basically only to switch to a decent graphics mode ^^'
It would be nice if one of you could review my implementation plan before I start, so I don't mess it up totally
First some information, my kernel is set up like this:
- the linker script links the kernel so that the binary is loaded to 0x100000 (first entry of my SECTIONS is ". = 0x100000;")
- i let GRUB load the kernel and the ramdisk modules. the kernel and the modules are then at addresses above 1MiB
- in my kernel, there is only one page directory, identity-mapping the lower memory + the space used by the kernel (for example up to 0x105000), and making a contiguous area above that using all remaining free memory
- all the processes are running in kernel mode
- i have a flat GDT set up, with to entries for code and data covering the entire memory
- i use preemptive multitasking to switch tasks on timer interrupts, storing the registers on the processes stack
Now my plan to integrate a vm8086 task to my system would be to simply do the following:
- creating a "lower memory allocator" that uses the area from 0x00007E00 to 0x0007FFFF (by now I assume that this exists, later I'll check it from the memory map), this allocator serves for all vm8086 tasks (i'll use system calls to keep it reentrant-safe) - and I doubt that I will have so many tasks that I'll need more memory than there is available down there
- when setting up a task, ill set the VM-Bit in the flags register of the CPU
- compile a 16 bit object and load it as a GRUB module, than allocate a chunk of that size with my lower memory allocator, copy the object there and set the IP of my vm task to the start address
- allocate a stack with my lower memory allocator and set it as the stack for my task
Then, once the task has it's turn, the IRET should jump into that task and automatically switch to v86 mode. The only thing I'll have to do then, is add a routine to my GPF handler that treats GPFs from a vm86 task by handling them somehow.
Will it work this way? Or is there anything else I have to consider when switching to the v86 mode?
Thank you
I've decided to implement Vm8086 tasks for my kernel, basically only to switch to a decent graphics mode ^^'
It would be nice if one of you could review my implementation plan before I start, so I don't mess it up totally
First some information, my kernel is set up like this:
- the linker script links the kernel so that the binary is loaded to 0x100000 (first entry of my SECTIONS is ". = 0x100000;")
- i let GRUB load the kernel and the ramdisk modules. the kernel and the modules are then at addresses above 1MiB
- in my kernel, there is only one page directory, identity-mapping the lower memory + the space used by the kernel (for example up to 0x105000), and making a contiguous area above that using all remaining free memory
- all the processes are running in kernel mode
- i have a flat GDT set up, with to entries for code and data covering the entire memory
- i use preemptive multitasking to switch tasks on timer interrupts, storing the registers on the processes stack
Now my plan to integrate a vm8086 task to my system would be to simply do the following:
- creating a "lower memory allocator" that uses the area from 0x00007E00 to 0x0007FFFF (by now I assume that this exists, later I'll check it from the memory map), this allocator serves for all vm8086 tasks (i'll use system calls to keep it reentrant-safe) - and I doubt that I will have so many tasks that I'll need more memory than there is available down there
- when setting up a task, ill set the VM-Bit in the flags register of the CPU
- compile a 16 bit object and load it as a GRUB module, than allocate a chunk of that size with my lower memory allocator, copy the object there and set the IP of my vm task to the start address
- allocate a stack with my lower memory allocator and set it as the stack for my task
Then, once the task has it's turn, the IRET should jump into that task and automatically switch to v86 mode. The only thing I'll have to do then, is add a routine to my GPF handler that treats GPFs from a vm86 task by handling them somehow.
Will it work this way? Or is there anything else I have to consider when switching to the v86 mode?
Thank you