task switch using gcc inline assembler

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
crackers

task switch using gcc inline assembler

Post by crackers »

I've created TSS segment and using

Code: Select all

asm("call $0x80,$0");
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.
YeXo

Re:task switch using gcc inline assembler

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

Re:task switch using gcc inline assembler

Post 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 ?
JoeKayzA

Re:task switch using gcc inline assembler

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

Re:task switch using gcc inline assembler

Post 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' "
paulbarker

Re:task switch using gcc inline assembler

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

Re:task switch using gcc inline assembler

Post by crackers »

I'm still getting the same error :-\
crackers

Re:task switch using gcc inline assembler

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

Re:task switch using gcc inline assembler

Post 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)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:task switch using gcc inline assembler

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

Re:task switch using gcc inline assembler

Post by crackers »

Well I'm using two versions jmp and call - depend on situation.
Post Reply