;@GOTO TRANSLATE

.586P

.MODEL            FLAT, STDCALL


   OPTION         CASEMAP: NONE
   INCLUDE        WINDOWS.inc
   UNICODE        = FALSE
   INCLUDE        APIMACRO.mac

   INCLUDELIB     iKERNEL32
   INCLUDELIB     iUSER32

;------------------------------------------------------------------

PUBLIC _tls_used

.CONST
_tls_array EQU   2CH  ;  FS:2CH

.DATA?
_tls_index DWORD ?

   OPTION         DOTNAME
.tls   SEGMENT
_tls_start LABEL  DWORD
 DWORD     80H    DUP ("slt.") 
_tls_end   LABEL  DWORD
.tls   ENDS
   OPTION         NODOTNAME

.DATA
__xl_a DWORD TlsCallBack0, TlsCallBack1, TlsCallBack2, TlsCallBack3
__xl_z DWORD 0


TLS_DIRECTORY    STRUCT
 lpTlsDataStart LPDWORD ?
 lpTlsDataEnd   LPDWORD ?
 lpTlsIndex     LPDWORD ?
 lpTlsCallbacks LPDWORD ?
 ZeroFillSize     DWORD ?
 Characteristic   DWORD ?
TLS_DIRECTORY      ENDS

_tls_used TLS_DIRECTORY <_tls_start, _tls_end, _tls_index, __xl_a, 0, ?>


;------------------------------------------------------------------
;Load Config table is ignored (on x86 only?),
;but Load Config directory can be created
;Size is set to 40H
PUBLIC _load_config_used
_load_config_used DWORD 0,0,0,0, 0,0,0,0, NOPptr,0,0,0, 0,0,0,0 
NOPptr DWORD Nop0, Nop1, Nop2, 0
Nothing DWORD ?

;Bound Import can created by BIND.exe or by LINK -EDIT /BIND
;Delay Import descriptor can created by /DELAY and /DELAYLOAD LINK switches

.CODE

 Nop0:
   LOCK    INC  Nothing
 Nop1:
   LOCK    INC  Nothing
 Nop2:
   LOCK    INC  Nothing
;------------------------------------------------------------------
 TlsCallBack0   PROC    hinstImg, fdwReason, lpvReserved
   sWin32  GiveRegards, sCB0, hinstImg, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 TlsCallBack0   ENDP

 TlsCallBack1   PROC    hinstImg, fdwReason, lpvReserved
   sWin32  GiveRegards, sCB1, hinstImg, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 TlsCallBack1   ENDP

 TlsCallBack2   PROC    hinstImg, fdwReason, lpvReserved
   sWin32  GiveRegards, sCB2, hinstImg, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 TlsCallBack2   ENDP

 TlsCallBack3   PROC    hinstImg, fdwReason, lpvReserved
   sWin32  GiveRegards, sCB3, hinstImg, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 TlsCallBack3   ENDP

 TlsCallBack4   PROC    hinstImg, fdwReason, lpvReserved
   sWin32  GiveRegards, sCB3, hinstImg, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 TlsCallBack4   ENDP

 DllMain        PROC    hinstDLL, fdwReason, lpvReserved
   sWin32  GiveRegards, sDLL, hinstDLL, fdwReason, lpvReserved
   MOV     EAX, TRUE
   RET
 DllMain  ENDP


  ALIGN   4
  Reasons DWORD PDT, PAT, TAT, TDT
  
  TEXTA   Unk,  <UNKNOWN/0> 
  TEXTA   PDT,  <PROCESS_DETACH/0> 
  TEXTA   PAT,  <PROCESS_ATTACH/0> 
  TEXTA   TAT,  <THREAD_ATTACH/0> 
  TEXTA   TDT,  <THREAD_DETACH/0> 
  
  TEXTA   CB0,  <DLL Tls Callback #0/0> 
  TEXTA   CB1,  <DLL Tls Callback #1/0> 
  TEXTA   CB2,  <DLL Tls Callback #2/0> 
  TEXTA   CB3,  <DLL Tls Callback #3/0> 
  TEXTA   DLL,  <DLL ---------- Main/0> 

  TEXTA   ParmTempl, < Image:/#08X  Reason:/#14s  Reserved:/#08X/n/0> 

 GiveRegards PROC    WriteMsg, hinstDLL, fdwReason, lpvReserved
  LOCAL   Place[80] :CHAR 
  iWin32  lstrlenA,  WriteMsg
  iWin32  WriteFile, STD_OUTPUT_HANDLE, WriteMsg, EAX, ESP, NULL
  MOV     EAX,       fdwReason
  CMP     EAX,       DLL_THREAD_DETACH
  MOV     EDX,       sUnk 
  JA      @F
  MOV     EDX,       Reasons[EAX*4]
 @@:
  LEA     EAX,       Place
  PUSH    EAX 
  icWin32 wsprintfA, EAX, sParmTempl, hinstDLL, EDX, lpvReserved
  POP     ECX
  iWin32  WriteFile, STD_OUTPUT_HANDLE, ECX, EAX, ESP, NULL
  RET 
 GiveRegards ENDP

 PUBLIC   GiveRegards

END DllMain

:TRANSLATE
@ECHO OFF
ML   /c /coff  /nologo TlsDll.bat
LINK TlsDll /nologo /optidata /IGNORE:4078,4086,4060 /DLL /EXPORT:GiveRegards /SUBSYSTEM:CONSOLE /MERGE:.rdata=.text /STUB:PESTUB.EXE
DEL  TlsDll.obj
DEL  TlsDll.exp
REM DEL   TlsDll.lib
PAUSE
CLS