Page 1 of 1
Int 0x80 from user mode code
Posted: Mon Jan 29, 2007 5:43 am
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
Posted: Mon Jan 29, 2007 6:06 am
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
Posted: Mon Jan 29, 2007 11:26 pm
by sampath
Hi,
I have given DPL of 3 in the interrupt gate.Its not giving any GPF ..its simply rebooting.!!
Sampath S
Posted: Tue Jan 30, 2007 4:03 am
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:
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
Posted: Tue Jan 30, 2007 6:41 am
by sampath
Hi,
My GDT,IDT,TSS all are in less then 1MB memory address will it be a problem ??
Rgds,
sampath S
Posted: Tue Jan 30, 2007 8:54 am
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 ?
Posted: Tue Jan 30, 2007 10:08 pm
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
Posted: Wed Jan 31, 2007 2:42 am
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.
Posted: Wed Jan 31, 2007 7:10 am
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....
Posted: Wed Jan 31, 2007 7:43 am
by AJ
Any chance of some code
Adam
Posted: Wed Jan 31, 2007 8:37 am
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 )