[idt problem]start a user space process

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.
Post Reply
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

[idt problem]start a user space process

Post by Otter »

Hello,
I want to start a user space process. Actually I have:

Code: Select all

/* 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 ...
senaus
Member
Member
Posts: 66
Joined: Sun Oct 22, 2006 5:31 am
Location: Oxford, UK
Contact:

Post by senaus »

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.

Code: Select all

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M/MU d- s:- a--- C++++ UL P L++ E--- W+++ N+ w++ M- V+ PS+ Y+ PE- PGP t-- 5- X R- tv b DI-- D+ G e h! r++ y+
------END GEEK CODE BLOCK------
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

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.
senaus
Member
Member
Posts: 66
Joined: Sun Oct 22, 2006 5:31 am
Location: Oxford, UK
Contact:

Post by senaus »

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.

Cheers,
Sean

P.S.
You only need one TSS for every interrupt.

Code: Select all

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M/MU d- s:- a--- C++++ UL P L++ E--- W+++ N+ w++ M- V+ PS+ Y+ PE- PGP t-- 5- X R- tv b DI-- D+ G e h! r++ y+
------END GEEK CODE BLOCK------
Post Reply