Task Switch: JMP DWORD AX:0x12345678 doesn't work

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
sevobal
Member
Member
Posts: 63
Joined: Sun Oct 22, 2006 7:11 am

Task Switch: JMP DWORD AX:0x12345678 doesn't work

Post by sevobal »

Hey everyone!
I've tried to make a hardware based task switch. First of all, I load a selector into ax:

Code: Select all

mov esi,[tasking_current] ;base of a task table entry
add esi, 0x00000002        ; TSS selector for a task
mov word ax, [es:esi]      ; Now the selector is in ax
Now ax holds a selector of a gdt entry which points to a tss of a task. Now, all I have to do is making a far jmp using this selector as segment. Offset can be a random value, because it will be ignored. So I tried this:

Code: Select all

jmp dword ax:0x12345678
But the assembler (nasm) doesn't like it. So how can I handle it? I need ax (or it's value) to do a correct jump.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: Task Switch: JMP DWORD AX:0x12345678 doesn't work

Post by ru2aqare »

Try this:

Code: Select all

    push    eax       ; ax contains your TSS selector
    push    0         ; offset is ignored
    jmp     far ptr [esp+0]
    add     esp, 8    ; if you switch back to this task, remove the dwords pushed onto the stack
Or you can use self-modifying code, like this:

Code: Select all

    mov     [offset dummy_label + 1], ax
dummy_label:
    db      0EAh      ; opcode for far jump
    dw      0         ; selector will be plugged in here
    dd      12345678h ; offset
Last edited by ru2aqare on Tue Aug 19, 2008 1:31 am, edited 1 time in total.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Task Switch: JMP DWORD AX:0x12345678 doesn't work

Post by Brendan »

Hi,
sevobal wrote:But the assembler (nasm) doesn't like it. So how can I handle it? I need ax (or it's value) to do a correct jump.
It's the CPU that wouldn't like it... ;)

You could try something like this:

Code: Select all

    mov esi,[tasking_current] ;base of a task table entry
    add esi, 0x00000002        ; TSS selector for a task
    jmp far dword [es:esi - 4]
This works because the offset is ignored, so we can pretend that "[es:esi-4]" contains a 4 byte offset (that's ignored) followed by the 2 byte selector.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply