Page 1 of 1
iret to pl3
Posted: Wed Feb 11, 2004 8:45 am
by Adek336
hi guys... I've been trying to add support for PL#3 code. In the end I have this code
Code: Select all
int system_main()
{
(..)
asm volatile ("cli\n");
asm volatile ("push $0x23\n"
"push $0xc0008800\n"
"push $0x200\n"
"push $0x1b\n"
"push $DIE\n"
"iret");
(...)}
void DIE() asm ("DIE");
.globl DIE
DIE:
nop
nop
nop
mov $0xa1b2c3d4, %edi
jmp DIE
It fails so badly even my interrupt handlers do not catch the problem. As I checked it, (uint32) &DIE == 0xc0008000, 0x1b is for PL#3 code, 0x23 is PL#3 data. The data pushed on stack seem in compliance with the iret specs.
user code: limit 0xfffff, base 0, attr 0xfa, flags 0xc0
used data: limit 0xfffff, base 0, attr 0xf2, flags 0xc0
If I change the code to
asm volatile ("pushf 0x8"
"pushf &DIE"
"iret");
it seems to work.
Hm, as I write this I begin to think it's the rtc timer interrupt which fails, perhaps because the kernel tss isn't yet loaded at that moment.. to be investigated.
Cheers,
Adrian.
Re:iret to pl3
Posted: Thu Feb 12, 2004 4:22 am
by Pype.Clicker
do you have a TSS and a SS0 /ESP0 for that task ? if not, the CPU will not be able to switch back to ring 0 to report exceptions ...
Re:iret to pl3
Posted: Thu Feb 12, 2004 4:11 pm
by Adek336
I did map the appropriate pte entries with PTE_USER set, but forgot to do so with the whole page table. Now I am able to iret to a piece of code running in PL3. It actually spins a character in the topmost left of the screen
But, bloody intel, I can't get it to call an exception properly :/
Code: Select all
func_user:
pushl $0x23
popl %ds ;setup user data segment
spin:
incl (0x80001000) ;access video memory, mapped to 0xb8000
int $0xb
jmp spin
intr0xb:
hlt
That piece of code reboots. Hm, I once had some scheduling code which would switch between many PL3 threads :/ That's weird, I'll try to get at it.
(offtopic) So then the french did lost Paris within one month yes? Perhaps the war would end earlier if France did not fail so quickly.
Cheers
[shadow=red,left,300]Adrian, who has 3 stars ;D [/shadow]
Re:iret to pl3
Posted: Fri Feb 13, 2004 1:04 am
by BI lazy
oooch come on, what's that bragging about 3 stars good for? *rofl*
are you talking 'bout WWII?
Then, listen: If someone comes and holds a gun under your nose and tells you what to do, you are under normal circumstances quick at satisfying the request for the sake of your own beloved life. This has nothing to do with failing or so... it's just wanting to be alive and not wanting to experience harm. People like their skin intact, know ya?
That's what might have happened in France, hm, and in Austria tooo, when at 12.3.1938(not sure about this one) Hitler marched in and annexed Austria. Folks just wanted to live - and so they cooperated.
Re:iret to pl3
Posted: Fri Feb 13, 2004 3:55 am
by Adek336
Yea, possible.. didn't think about it that way.
Cheers,
Adrian.
Re:iret to pl3
Posted: Fri Feb 13, 2004 4:04 am
by Pype.Clicker
trying to *call* an exception, huh ? and you really though the CPU designer would let you fool them that way ?? Remember the 'PL' field in the IDT that you left to 0 "as said in the tutorials" ? well that was precisely what it was meant to do: prevent your user program to issue fake exceptions and other fake hardware interrupts ...
If you want to call the OS, you should provide a new interrupt with DPL=3 and call it.
If you just want to get out of your user mode program, you can either call the former interrupt with a code saying "i'm done" or just issue a HLT, which will raise a GPF and have something in your handler that knows HLT == end-of-process, or jump at a conventionnal 0xcafebabe address or something ... i'd personnally recommend the syscall approach for it is cleaner...
If you want to check how exceptions are processed, just do something illegal
ps: don't take offense if you feel like i'm teasing you... i found myself so stupid when i made the same mistake that i can't prevent myself to find it funny, still now ...
Re:iret to pl3
Posted: Fri Feb 13, 2004 8:07 am
by Adek336
Hm, so that's why I got the text "EXCEPTION 0x0d" each time I
I'll try to use the DIV instruction to get int 0 running.. cheers,
Adrian
Re:iret to pl3
Posted: Fri Feb 13, 2004 8:15 am
by Pype.Clicker
Yup. If you want to see 'division by zero" message, just do
oh, btw, when i say
Pype.Clicker wrote:
If you want to check how exceptions are processed, just do something illegal
i don't mean "download Kylie's last album using KaZaa" ... of course, this would only raise the MyDoomException ;D