Int 0x80 from user mode code

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
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Int 0x80 from user mode code

Post by sampath »

Hi all,
I wrote my ISR for int 0x80 in KERNEL and hooked the ISR into the IDT using the interrupt gate desc.I also have one TSS and its descriptor just to hold SS0 & ESP0 info.After all these when I use 'int 0x80' from user mode code my ISR is not getting invoked :-)

Am i missing anything here ???


Thanks in advance,
sampath S
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

When you set up the entry in your IDT, have you set its DPL3? If you are running user code in ring 3 you will need to do this to allow your user code to call the interrupt.

Do you get any kind of processor fault when this happens? If the above is correct, you should get a GPF.

Cheers,
Adam
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Post by sampath »

Hi,
I have given DPL of 3 in the interrupt gate.Its not giving any GPF ..its simply rebooting.!!
Sampath S
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

If your GPF handler is not being invoked, it seems to me that you have either a bad kernel-mode stack, bad paging, or incorrectly loaded segment registers.

One thing I have found useful in this situation is Bochs. In the Bochs source file, try setting the line which is similar to:

Code: Select all

cpu: count=1, ips=2000000
and extend this line so it reads:

Code: Select all

cpu: count=1, ips=2000000, reset_on_triple_fault=0
When you get the triple fault and the CPU resets, Bochs will halt, displaying current register information. Often, it also displays a helpful comment above this, such as 'SS RPL != DPL', or something similar.

HTH,
Adam
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Post by sampath »

Hi,
My GDT,IDT,TSS all are in less then 1MB memory address will it be a problem ??

Rgds,
sampath S
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

No, that should be no problem, but your user mode code needs access to them.

Maybe you should tell us what works in user mode and what not. What happens if you do a simple loop ( eb fe ) in user mode or if you produce a division by zero ?
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Post by sampath »

Inside the USER MODE code loops and other normal functions works.Exceptions generated by div by zero,INT instructions are not passing the control to ISRs.When ever these things happens it simply reboots.

I have filled TSS with esp0,ss0 and did ltr during init itself.

Cheers!!!
Sampath S
Jules
Member
Member
Posts: 30
Joined: Mon Jan 08, 2007 3:19 am
Location: UK

Post by Jules »

The problem is almost certainly that either:

1. Your IDT isn't available for some reason. If you have paging enabled, have you used a physical or virtual address in your LIDT instruction? Do you get the same behaviour when you enable interrupts?

2. Your IDT is incorrectly formatted. Check the structure you're using is correct. Is the present bit set?

3. The address of your ISR in the IDT is wrong. Have you used physical addresses rather than virtual? Is CS wrong?

4. Your ISR is unavailable. Is it inside the limits of your code segment? Are its pages available and marked as present? If it's in a different code segment, is its descriptor marked as present?

5. Your ISR does something that immediately causes an unhandled exception.
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Post by sampath »

*My IDT & ISRs are working fine when I am in KERNEL MODE.I use physical address in LIDT.
Yes! when I enable interrupts in user mode I get same behaviour.

*All the present bits are set to one.

*My ISR does nothing except SAVE_ALL & RESTORE_ALL register functions.

*My CallGate from user mode to kernel mode is working fine.

But still by int 0x80 is not working....
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Any chance of some code :?:
Adam
Otter
Member
Member
Posts: 75
Joined: Sun Dec 31, 2006 11:56 am
Location: Germany

Post by Otter »

I use physical address in LIDT
You should use virtual address ...

Well, you say that lot's of your user space code works, even call gates to kernel mode. So I guess you're able to print something to the screen from usermode ? You could print the values of your idt entry and check whether they are correct ( even if you need to adjust the flags of that page you should do that )
Post Reply