iret gcc problem

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
guest

iret gcc problem

Post 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.
AR

Re:iret gcc problem

Post 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.
guest

Re:iret gcc problem

Post 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.
guest

Re:iret gcc problem

Post 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
AR

Re:iret gcc problem

Post 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.
Guest

Re:iret gcc problem

Post by Guest »

Yes, i see ;D
Post Reply