Page 1 of 1
task switch using gcc inline assembler
Posted: Sat Apr 08, 2006 8:38 am
by crackers
I've created TSS segment and using
where 0x80 is proper selector to TSS segment I can switch task. I want to have it parametrised, but i don't know how do this using gcc in;line assembler.
I've found something like this
Code: Select all
__asm__ __volatile__ ( "ljmp *(%0)": :"g" ((DWORD *)&selector) );
Unfortunately it's not working.
Re:task switch using gcc inline assembler
Posted: Sat Apr 08, 2006 9:32 am
by YeXo
crackers wrote:
Code: Select all
__asm__ __volatile__ ( "ljmp *(%0)": :"g" ((DWORD *)&selector) );
This is another line of asm than your first (I mean they do different things). If you want a call segment,0 your inline assembly should be something like this (I don't whether this will work or needs some tweaking):
Code: Select all
__asm__ __volatile__ ( "call (%0),0": :"g" (selector) );
where selector contains 0x80 in your example
Re:task switch using gcc inline assembler
Posted: Sun Apr 09, 2006 3:41 am
by crackers
I'm getting "Error : '(%ax)' is not a valid base/index expression" so I've tried to change constraints to
Code: Select all
__asm__ __volatile__ ( "call (%0),0": :"b" (selector) );
__asm__ __volatile__ ( "call (%0),0": :"S" (selector) );
__asm__ __volatile__ ( "call (%0),0": :"D" (selector) );
b - bx, S - si, D - di, but then I'm getting "Too many memory references for 'call' "
If nobody knows how to do this in inline assembler than maybe someone could tell me how to do it in NASM ?
Re:task switch using gcc inline assembler
Posted: Sun Apr 09, 2006 11:01 am
by JoeKayzA
Does it make a difference when you try to remove the brackets around '%0' (and using "g")? 'Selector' is an integer variable, not a pointer (I assume, at least), so you should reference it without the brackets.
cheers Joe
Re:task switch using gcc inline assembler
Posted: Mon Apr 10, 2006 6:00 am
by crackers
JoeKayzA wrote:
Does it make a difference when you try to remove the brackets around '%0' (and using "g")? 'Selector' is an integer variable, not a pointer (I assume, at least), so you should reference it without the brackets.
Yes, 'selector' is unsigned short
Code: Select all
__asm__ __volatile__ ( "call %0,0": :"g" (selector) );
Upon this code I'm getting "Error: sufix or operands invalid for 'call' "
Re:task switch using gcc inline assembler
Posted: Mon Apr 10, 2006 6:15 am
by paulbarker
lcall? I know you use ljmp rather than jmp for a far jump, so I assume you use lcall for a far call.
The 'l' is an L. Confusing fonts.
Re:task switch using gcc inline assembler
Posted: Wed Apr 12, 2006 1:43 am
by crackers
I'm still getting the same error :-\
Re:task switch using gcc inline assembler
Posted: Fri Apr 14, 2006 11:40 am
by crackers
I did it in NASM
Code: Select all
mov ebx, task_address
call word far [ebx]
....
task_address:
.offset: dw 0
.segment: dw 0
Re:task switch using gcc inline assembler
Posted: Fri May 05, 2006 3:45 am
by nicesj
hello
I wrote a code for task-switching.
#define switch_task(a) __asm__ volatile("jmp %0,$0"::"i"(a))
good luck with you.
http://nicesj.com (euc-kr)
Re:task switch using gcc inline assembler
Posted: Fri May 05, 2006 5:26 am
by Pype.Clicker
use of "call xxx" is strongly discouradged in the case of multitasking. Outgoing TSS will be marked as busy, meaning that you can't "call" it again.
Re:task switch using gcc inline assembler
Posted: Mon May 08, 2006 7:17 am
by crackers
Well I'm using two versions jmp and call - depend on situation.