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.
/* Creating the executable image */
unsigned int imagePhysPage = __get_phys_block(0); // requesting 1<<0 physical pages
unsigned short* vimage = (unsigned short*)accessPhysBlock(imagePhysPage);
*vimage = 0xfeeb; // eb fe: jmp short -2 ; very simple process
releasePhysBlock(vimage); // no more access needed for executable image
/* Creating user space */
CAddressSpace userspace = new CAddressSpace();
userspace->create(); // setting up a page directory
userspace->makeSystemBlockReadable(); // readonly-access for gdt / idt
userspace->map( 0x00400 , imagePhysPage ); // text section at 0x00400000
/* Start */
CTask* task = new CTask(
0x00400000, // eip
0, // no stack needed
userspace->cr3 // task uses userspace
);
task->go();
This works fine.
My problem is that I'm not sure about how to handle interrupts. If I press any key, the system reboots, because even though the process can read the IDT, it cannot use it.
I think I have to use task gates, but: If I do so, I need a tss for each isr I want to use, right ? Is there a better way ? I don't want as much entries in my gdt ...
Afaik, you have to set the DPL field in the IDT entries to 3 in order for user-mode code to access them, did you do this? I had this problem when I first tried going into user mode.
No, I have not, but that will not work either, because the pages containing the isr code are not mapped into the usermode, and I won't do that because the code should be called in kernel mode.
I want to know if it's really necessary to create one tss for all isrs I want to use ( if this is true, I need a bigger gdt )
I thought about some handlers, which are mapped into user space as well and which call a common isr handler in kernel mode, if possible, givin the isr number as parameter.
You need some ISR code mapped into the address space. This doesn't have to be marked as user code, as the CPU will switch to ring 0 automatically, but it still needs to be mapped! It could be as little as a stub ISR that switches the address space to a kernel address space, but I doubt that would be too efficient.
Every modern OS I know of maps the whole kernel into every address space, I suggest you do this.