Setting TR

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
Humble

Setting TR

Post by Humble »

Will this function works ?

Code: Select all

set_task_register:
   push   eax
   push   ebx
   push   esi
   mov   esi, task_dec
   mov   ebx, tss_struct
   mov   [esi], word 68h
   mov   [esi+2], word bx
   shr   ebx, 10h
   mov   [esi+4], byte bl
   mov   [esi+5], byte 10001001b      ; 89h
   mov   [esi+6], byte 10000000b      ; c0h
   mov   [esi+7], byte bh
   mov   ax, 18h
   ltr   ax
   pop   esi
   pop   ebx
   pop   eax
   ret

Code: Select all

gdt:
   null_desc    dd    0h
            dd   0h
   flat_code     dw     0ffffh
            dw   0h
            db    0h
            db   10011110b ; feh
            db   11001111b ; cfh
            db   0h
   flat_data      dw      0ffffh
            dw   0h
            db   0h
            db   10010010b ; f2h
            db   11001111b ; cfh
            db   0h
   task_desc       dd   0h
            dd     0h

tss_struct:
   back_link   dw   0h
         dw   0h
   esp0      dd   0h
   ss0      dw   0h
         dw   0h
   esp1      dd   0h
   ss1      dw   0h
         dw   0h
   esp2      dd   0h
   ss2      dw   0h
         dw   0h
   ccr3      dd   0h
   eip      dd   0h
   eflags   dd   0h
   eeax      dd   0h
   eecx      dd   0h
   eedx      dd   0h
   eebx      dd   0h
   eesp      dd   0h
   eebp   dd   0h
   eesi      dd   0h
   eedi      dd   0h
   ees      dw   0h
         dw   0h
   ecs      dw   0h
         dw   0h
   ess      dw   0h
         dw   0h
   eds      dw   0h
         dw   0h
   efs      dw   0h
         dw   0h
   egs      dw   0h
         dw   0h
   eldt      dw   0h
         dw   0h
         dw   0h
   bitmap   dw   0h

User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Setting TR

Post by Brendan »

Hi,

Humble wrote: Will this function works ?
You probably don't want to set the "granularity" flag, and the limit field is "limit - 1" (at the moment your limit would be 420 KB).

Try this:

Code: Select all

set_task_register:
   push   eax
   mov   [task_dec], word 67h
   mov   [task_dec+2], word tss_struct & 0xFFFF
   mov   [task_dec+4], byte (tss_struct >> 16) & 0xFF
   mov   [task_dec+5], byte 10001001b                 ; 89h
   mov   [task_dec+6], byte 00000000b                 ; 00h
   mov   [task_dec+7], byte (tss_struct >> 24) & 0xFF
   mov   ax, 18h
   ltr   ax
   pop   eax 
   ret

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.
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:Setting TR

Post by Pype.Clicker »

you may have hard times trying to link code that does things like "(tss_struct >> 16) & 0xff", especially if tss_struct is in one section (e.g. data) and code in another section (e.g. text).

You're probably better to load tss_struct in one register (e.g. ecx) and then do things like

Code: Select all

  mov  [task_dec+2], cx
  shr ecx,16
  mov  [task_dec+4], cl
  mov  [task_dec+5], byte 10001001b                ; 89h
  mov  [task_dec+6], byte 00000000b                ; 00h
  mov  [task_dec+7], ch
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Setting TR

Post by Brendan »

Hi,
Pype.Clicker wrote: you may have hard times trying to link code that does things like "(tss_struct >> 16) & 0xff", especially if tss_struct is in one section (e.g. data) and code in another section (e.g. text).
If your linker is broken, why use it? ;D


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.
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:Setting TR

Post by Pype.Clicker »

^_^ I wish it was just something wrong with the linker, but actually it's not: it's something wrong with the code that you often encounter when filling descriptors.

The linker has to perform some address adjustments with symbols which are based on relocation lists. Those list can express things like "the address of MyFunction is stored at offset 12345678" or "relative offset to MyFunction stored at offset 12345678", but it certainly have no way to express that "((address of MyFunction)>>16) & 0xFF is stored at offset 12345678".

I'm not even certain that having tss_struct and the code in the same section would actually help.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Setting TR

Post by Brendan »

Hi,
Pype.Clicker wrote: ^_^ I wish it was just something wrong with the linker, but actually it's not: it's something wrong with the code that you often encounter when filling descriptors.
Perhaps I should rephrase - if all linkers are broken, and if the entire concept of linking seperate object files makes them broken, then why use a broken tool chain?

I've never had problems like this, but then I never use linkers for anything important.

BTW - don't overlook the ;D in my previous post - it has significance...


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