Page 1 of 1

Will this code works ?

Posted: Mon Oct 17, 2005 4:34 pm
by HardEnough

Code: Select all

gdt:
   null_desc   dd   0h
         dd   0h
   flat_code   dw   0ffffh
         dw   0h
         db   0h
         db   10011110b ; 9eh
         db   11001111b ; cfh
         db   0h
   flat_data   dw   0ffffh
         dw   0h
         db   0h
         db   10010010b ; 92h
         db   11001111b ; cfh
         db   0h
   kernel_code   dw   2ffh
         dw   0h
         db   0h
         db   10011110b ; 9eh
         db   11000000b ; c0h
         db   0h
   kernel_data   dw   2ffh
         dw   0h
         db   0h
         db   10010010b ; 92h
         db   11000000b ; c0h
         db   0h
   kernel_stack   dw   0ffh
         dw   0h
         db   30h
         db   10010110b ; 96h
         db   11000000b ; c0h
         db   0h
   user_code   dw   0h
         dw   0h
         db   0h
         db   00000000b
         db   00000000b
         db   0h
   user_data   dw   0h
         dw   0h
         db   0h
         db   00000000b
         db   00000000b
         db   0h
   user_stack   dw   0h
         dw   0h
         db   0h
         db   00000000b
         db   00000000b
         db   0h
   task_state   dd   0h
         dd   0h

tss:
   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
   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

set_tr:
   push   eax
   push   ebx
   push   esi
   mov   esi, task_state
   mov   ebx, tss
   and   ebx, 0ffffh
   mov   ebx, tss
   shr   ebx, 10h
   mov   [esi], word 1101000b
   mov   [esi+2], word bx
   mov   [esi+4], byte bl 
   mov   [esi+5], byte 10001001b
   mov   [esi+6], byte 11000000b
   mov   [esi+7], byte bh
   mov   ax, 48h
   ltr   ax
   pop   esi
   pop   ebx
   pop   eax
   ret
will this code works and the tss is set correctly ?

Re:Will this code works ?

Posted: Mon Oct 17, 2005 6:48 pm
by Brendan
Hi,
HardEnough wrote:will this code works and the tss is set correctly ?
No...

For a start, you can't store 2 different values in EBX at the same time:

Code: Select all

   mov   ebx, tss
   and   ebx, 0ffffh
   mov   ebx, tss
   shr   ebx, 10h
   mov   [esi], word 1101000b
   mov   [esi+2], word bx
   mov   [esi+4], byte bl 
   mov   [esi+5], byte 10001001b
   mov   [esi+6], byte 11000000b
   mov   [esi+7], byte bh
I'd suggest something like:

Code: Select all

   mov   ebx, tss
   mov   [esi+2], word bx
   shr   ebx, 10h
   mov   [esi], word 1101000b
   mov   [esi+4], byte bl 
   mov   [esi+5], byte 10001001b
   mov   [esi+6], byte 11000000b
   mov   [esi+7], byte bh

Cheers,

Brendan

Re:Will this code works ?

Posted: Tue Oct 18, 2005 12:26 am
by HardEnough
Thanks alot Brendan.
i know i've made a silly mistake , but that what i really meant

Code: Select all

set_tr:
  mov  ebx, tss
  and  ebx, 0ffffh
  mov  [esi], word 1101000b
  mov  [esi+2], word bx
  mov  ebx, tss
  shr  ebx, 10h
  mov  [esi+4], byte bl
  mov  [esi+5], byte 10001001b
  mov  [esi+6], byte 11000000b
  mov  [esi+7], byte bh
and here is the last one

Code: Select all

set_tr:
   push   eax
   push   ebx
   push   esi
   mov   esi, task_state
   mov   ebx, tss
   mov   [esi], word 1101000b
   mov   [esi+2], word bx
   shr   ebx, 10h
   mov   [esi+4], byte bl 
   mov   [esi+5], byte 10001001b
   mov   [esi+6], byte 11000000b
   mov   [esi+7], byte bh
   mov   ax, 48h
   ltr   ax
   pop   esi
   pop   ebx
   pop   eax
   ret