Page 1 of 1

iret gcc problem

Posted: Thu Oct 06, 2005 8:08 am
by guest
Hello, i have a problem with GCC inline assembler.

This code does work when i use NASM:

Code: Select all

             pushf
   push 0x08
   push abc
   iret
abc:
   
   jmp $
But when i use this code in gcc inline assembler:

Code: Select all

asm(
   "pushfl;"
   "pushw $0x08;"
   "pushl xxx;"
   "iret;"
   "xxx:"
   );
my kernel hangs.

Please help me.

Re:iret gcc problem

Posted: Thu Oct 06, 2005 8:37 am
by AR
What do you mean by "does not work"?

As for the second one:
"pushw $0x08;"
This is wrong, it should be "pushl", all stack items are 32bit aligned.

Re:iret gcc problem

Posted: Thu Oct 06, 2005 8:48 am
by guest
Hello, i fixed the problem.
I had to change:

pushw $0x08 to pushl $0x08

and

pushl xxx to pushl $xxx

And now i have another problem.
I want to change to ring3 from ring0 without TSS.
I use this code:

Code: Select all


// 0x18 => ring3 code
// 0x20 => ring3 data

   __asm__ __volatile__
   (
   "movl %esp, %eax;"
   "pushl $0x23;"
   "pushl %eax;"
   "pushfl;"
   "pushl $0x1b;"
   "pushl $xxx;"
   "iret;"
   "xxx:"
   "jmp xxx;"   
             );
But QEMU just closes the window when executing this code.

Re:iret gcc problem

Posted: Thu Oct 06, 2005 8:59 am
by guest
ok i fixed ;D

I thought when U/S bit in paging stuff is cleared its for user ;D

I set and works now ;D

Re:iret gcc problem

Posted: Thu Oct 06, 2005 9:06 am
by AR
You can't switch to Ring 3 without a TSS (well you can but it will crash when an interrupt occurs). The TSS is the only way for the CPU to get the kernel stack.

Re:iret gcc problem

Posted: Thu Oct 06, 2005 11:08 am
by Guest
Yes, i see ;D