Index: trunk/src/kernel32/iccio.asm
===================================================================
--- trunk/src/kernel32/iccio.asm	(revision 4296)
+++ trunk/src/kernel32/iccio.asm	(revision 4298)
@@ -1,3 +1,3 @@
-; $Id: iccio.asm,v 1.6 2000-09-21 18:24:32 hugh Exp $
+; $Id: iccio.asm,v 1.7 2000-09-21 19:44:32 sandervl Exp $
 
 ; **********************************************************************
@@ -10,78 +10,79 @@
 ; compile with ALP
 ;
-  TITLE  ICCIO.ASM
-  .386
-  .387
-CODE32  SEGMENT DWORD USE32 PUBLIC 'CODE'
-CODE32  ENDS
-DATA32  SEGMENT DWORD USE32 PUBLIC 'DATA'
+    TITLE   ICCIO.ASM
+    .386
+    .387
+
+DATA32  SEGMENT DWORD PUBLIC USE32 'DATA'
+;        ASSUME  CS:FLAT ,DS:FLAT,SS:FLAT
+        ASSUME  DS:FLAT,SS:FLAT
+    EXTRN   ioentry:DWORD
+    EXTRN   gdt:WORD
+    EXTRN   devname:BYTE
 DATA32  ENDS
-CONST32  SEGMENT DWORD USE32 PUBLIC 'CONST'
-CONST32  ENDS
-BSS32  SEGMENT DWORD USE32 PUBLIC 'BSS'
-BSS32  ENDS
-DGROUP  GROUP CONST32, BSS32, DATA32
-  ASSUME  CS:FLAT, DS:FLAT, SS:FLAT, ES:FLAT
-DATA32  SEGMENT
-DATA32  ENDS
-BSS32  SEGMENT
-BSS32  ENDS
-CONST32  SEGMENT
-CONST32  ENDS
-
-DATA32  SEGMENT
-ioentry   DWORD  0
-gdt    WORD  0
-DATA32  ENDS
-
-CODE32  SEGMENT
+
+CODE32  SEGMENT DWORD PUBLIC USE32 'CODE'
+;        ASSUME  CS:FLAT ,DS:FLAT,SS:FLAT
+        ASSUME DS:FLAT,SS:FLAT
+
+    ALIGN 04H
 
 ; performs fast output of a byte to an I/O port
-; this routine is intended to be called from gcc C code
-;
-; Calling convention:
-;  void c_outb1(short port,char data)
-;
-;
-  PUBLIC  c_outb
-  ALIGN  04H
-c_outb  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  MOV  AL, [ESP+8]    ; get data
-  OUT  DX,AL
-  RET
-c_outb  ENDP
+; this routine is intended to be called from icc C code
+;
+; Calling convention:
+;   void _c_outb(short port,char data)
+;
+;
+    PUBLIC  _c_outb
+_c_outb PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port
+    MOV AL, BYTE PTR [ESP+8]    ; get data
+    PUSH    EBX         ; save register
+    MOV EBX, 4          ; function code 4 = write byte
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX
+    RET
+_c_outb ENDP
 
 ; performs fast output of a word to an I/O port
-; this routine is intended to be called from gcc C code
-;
-; Calling convention:
-;  void c_outw1(short port,short data)
-;
-;
-  PUBLIC  c_outw
-  ALIGN  04H
-c_outw  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  MOV  AX, [ESP+8]    ; get data
-  OUT  DX,AX
-  RET
-c_outw  ENDP
-
-; performs fast output of a longword to an I/O port
-; this routine is intended to be called from gcc C code
-;
-; Calling convention:
-;  void c_outl1(short port,long data)
-;
-;
-  PUBLIC  c_outl
-  ALIGN  04H
-c_outl  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  MOV  EAX, [ESP+8]    ; get data
-  OUT  DX, EAX
-  RET
-c_outl  ENDP
+; this routine is intended to be called from icc C code
+;
+; Calling convention:
+;   void _c_outw(short port,short data)
+;
+;
+    ALIGN   04H
+
+    PUBLIC  _c_outw
+_c_outw PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port
+    MOV AX, WORD PTR [ESP+8]    ; get data
+    PUSH    EBX         ; save register
+    MOV EBX, 5          ; function code 5 = write word
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX
+    RET
+_c_outw ENDP
+
+; performs fast output of a dword to an I/O port
+; this routine is intended to be called from icc C code
+;
+; Calling convention:
+;   void _c_outl(short port,long data)
+;
+;
+    ALIGN   04H
+
+    PUBLIC  _c_outl
+_c_outl PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port
+    MOV EAX, DWORD PTR [ESP+8]  ; get data
+    PUSH    EBX         ; save register
+    MOV EBX, 6          ; function code 6 = write dword
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX
+    RET
+_c_outl ENDP
 
 ; performs fast input of a byte from an I/O port
@@ -89,15 +90,18 @@
 ;
 ; Calling convention:
-;  char c_inb1(short port)
-;
-;
-  PUBLIC c_inb
-  ALIGN  04H
-c_inb  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  IN  AL,DX
-  AND  EAX, 000000FFh
-  RET
-c_inb  ENDP
+;   char _c_inb(short port)
+;
+;
+    ALIGN   04H
+    PUBLIC  _c_inb
+_c_inb  PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port number
+    PUSH    EBX         ; save register
+    MOV EBX, 1          ; function code 1 = read byte
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    AND EAX, 000000ffH      ; mask out required byte
+    POP EBX         ; restore register
+    RET
+_c_inb  ENDP
 
 ; performs fast input of a word from an I/O port
@@ -105,30 +109,182 @@
 ;
 ; Calling convention:
-;  short c_inw1(short port)
-;
-;
-  PUBLIC c_inw
-  ALIGN  04H
-c_inw  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  IN  AX, DX
-  AND  EAX, 0000FFFFh    ; mask out word
-  RET
-c_inw  ENDP
-
-; performs fast input of a longword from an I/O port
+;   short _c_inw(short port)
+;
+;
+    ALIGN   04H
+    PUBLIC  _c_inw
+_c_inw  PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port number
+    PUSH    EBX         ; save register
+    MOV EBX, 2          ; function code 2 = read short
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    AND EAX, 0000ffffH      ; mask out required byte
+    POP EBX         ; restore register
+    RET
+_c_inw  ENDP
+
+; performs fast input of a dword from an I/O port
 ; this routine is intended to be called from gcc C code
 ;
 ; Calling convention:
-;  lomg c_inl1(short port)
-;
-;
-  PUBLIC c_inl
-  ALIGN  04H
-c_inl  PROC
-  MOV  EDX, [ESP+4]    ; get port
-  IN  EAX, DX
-  RET
-c_inl  ENDP
+;   long _c_inl(short port)
+;
+;
+    ALIGN   04H
+    PUBLIC  _c_inl
+_c_inl  PROC
+    MOV EDX, DWORD PTR [ESP+4]  ; get port number
+    PUSH    EBX         ; save register
+    MOV EBX, 3          ; function code 3 = read long
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+;   AND EAX, 000000ffH      ; mask out required byte
+    POP EBX         ; restore register
+    RET
+_c_inl  ENDP
+
+    ALIGN   4
+    PUBLIC  _c_readmsr
+_c_readmsr PROC NEAR
+    PUSH    EBP
+    MOV EBP, ESP
+    PUSH    EAX
+    PUSH    EBX
+    PUSH    ECX
+    PUSH    EDX         ; save register
+    MOV ECX, DWORD PTR [EBP+8]  ; get msr reg
+    MOV EBX, 7          ; function code 7 = read msr
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    MOV EBX, DWORD PTR [EBP+12] ; LONGLONG ptr
+    MOV DWORD PTR [EBX+4], EDX
+    MOV DWORD PTR [EBX], EAX
+    POP EDX
+    POP ECX
+    POP EBX         ; restore register
+    POP EAX
+    POP EBP
+    RET
+_c_readmsr ENDP
+
+;------------------------------------------------------------------------------
+
+; performs fast output of a byte to an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   MOV AL, data
+;   CALL    a_outb
+;
+;
+    ALIGN   04H
+    PUBLIC  a_outb
+a_outb  PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 4          ; function code 4 = write byte
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX         ; restore bx
+    RET
+a_outb  ENDP
+
+; performs fast output of a word to an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   MOV AX, data
+;   CALL    a_outw
+;
+;
+    ALIGN   04H
+    PUBLIC  a_outw
+a_outw  PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 5          ; function code 5 = write word
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX         ; restore bx
+    RET
+a_outw  ENDP
+
+; performs fast output of a long to an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   MOV EAX, data
+;   CALL    a_outl
+;
+;
+    ALIGN   04H
+    PUBLIC  a_outl
+a_outl  PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 6          ; function code 6 = write long
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX         ; restore bx
+    RET
+a_outl  ENDP
+
+; performs fast input of a byte from an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   CALL    a_inb
+;   ;data in AL
+;
+    ALIGN   04H
+    PUBLIC  a_inb
+a_inb   PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 1          ; function code 1 = read byte
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    AND EAX, 000000FFh      ; mask byte
+    POP EBX         ; restore register
+    RET
+a_inb   ENDP
+
+
+; performs fast input of a word from an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   CALL    a_inb
+;   ;data in AX
+;
+    ALIGN   04H
+    PUBLIC  a_inw
+a_inw   PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 2          ; function code 2 = read word
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    AND EAX, 0000FFFFh      ; mask byte
+    POP EBX         ; restore register
+    RET
+a_inw   ENDP
+
+; performs fast input of a dword from an I/O port
+; this routine is intended to be called from assembler code
+; note there is no stack frame, however 8 byte stack space is required
+;
+; calling convention:
+;   MOV EDX, portnr
+;   CALL    a_inl
+;   ;data in EAX
+;
+    ALIGN   04H
+    PUBLIC  a_inl
+a_inl   PROC
+    PUSH    EBX         ; save register
+    MOV EBX, 3          ; function code 3 = read dword
+    CALL    FWORD PTR [ioentry] ; call intersegment indirect 16:32
+    POP EBX         ; restore register
+    RET
+a_inl   ENDP
 
 CODE32  ENDS
@@ -137,34 +293,27 @@
 
 ; Initialize I/O access via the driver.
-; You *must* call this routine once for each *thread* that wants to do
+; You *must* call this routine once for each executable that wants to do
 ; I/O.
 ;
 ; The routine is mainly equivalent to a C routine performing the
 ; following (but no need to add another file):
-;  DosOpen("/dev/fastio$", read, nonexclusive)
-;  DosDevIOCtl(device, XFREE86IO, IOGETSEL32)
-;  selector -> ioentry+4
-;  DosClose(device)
-;
-; Calling convention:
-;  int io_init1(void)
+;   DosOpen("/dev/fastio$", read, nonexclusive)
+;   DosDevIOCtl(device, XFREE86_IO, IO_GETSEL32)
+;   selector -> ioentry+4
+;   DosClose(device)
+;
+; Calling convention:
+;   int io_init(void)
 ; Return:
-;  0 if successful
-;  standard APIRET RETurn code if error
-;
-
-CONST32  SEGMENT
-  ALIGN  04H
-devname:
-  DB  "/dev/fastio$",0
-CONST32  ENDS
-
+;   0 if successful
+;   standard APIRET return code if error
+;
 
 CODE32  SEGMENT
-    PUBLIC  io_init1
+    PUBLIC  _io_init
     EXTRN   DosOpen:PROC
     EXTRN   DosClose:PROC
     EXTRN   DosDevIOCtl:PROC
-io_init1   PROC
+_io_init    PROC
     PUSH    EBP
     MOV EBP, ESP    ; standard stack frame
@@ -193,95 +342,81 @@
     ALIGN   04H
 goon:
-  LEA  EAX, [EBP-16]  ; address of 'len' arg of DosDevIOCtl
-  PUSH  EAX
-  PUSH  2    ; sizeof(short)
-  LEA  EAX, [EBP-2]  ; address to return the GDT selector
-  PUSH  EAX
-  PUSH  0    ; no parameter len
-  PUSH  0    ; no parameter size
-  PUSH  0    ; no parameter address
-  PUSH  100    ; function code IOGETSEL32
-  PUSH  118    ; category code XFREE6IO
-  MOV  EAX,[EBP-8]  ; file handle
-  PUSH  EAX
-  CALL  DosDevIOCtl  ; perform ioctl
-  ADD  ESP, 36    ; cleanup stack
-  CMP  EAX, 0    ; is return code = 0?
-  JE  ok    ; yes, proceed
-  PUSH  EAX    ; was error, save error code
-  MOV  EAX, [EBP-8]  ; file handle
-  PUSH  EAX
-  CALL  DosClose  ; close device
-  ADD  ESP,4    ; clean stack
-  POP  EAX    ; get error code
-  LEAVE      ; return error
-  RET
-
-  ALIGN  04H
+    LEA EAX, [EBP-16]   ; address of 'len' arg of DosDevIOCtl
+    PUSH    EAX
+    PUSH    2       ; sizeof(short)
+    LEA EAX, [EBP-2]    ; address to return the GDT selector
+    PUSH    EAX
+    PUSH    0       ; no parameter len
+    PUSH    0       ; no parameter size
+    PUSH    0       ; no parameter address
+    PUSH    100     ; function code IO_GETSEL32
+    PUSH    118     ; category code XFREE6_IO
+    MOV EAX, [EBP-8]    ; file handle
+    PUSH    EAX
+    CALL    DosDevIOCtl ; perform ioctl
+    ADD ESP, 36     ; cleanup stack
+    CMP EAX, 0      ; is return code = 0?
+    JE  ok      ; yes, proceed
+    PUSH    EAX     ; was error, save error code
+    MOV EAX, [EBP-8]    ; file handle
+    PUSH    EAX
+    CALL    DosClose    ; close device
+    ADD ESP, 4      ; clean stack
+    POP EAX     ; get error code
+    LEAVE           ; return error
+    RET
+
+    ALIGN   04H
 ok:
-  MOV  EAX, [EBP-8]  ; file handle
-  PUSH  EAX    ; do normal close
-  CALL  DosClose
-  ADD  ESP,4    ; clean stack
-
-  MOV  AX, [EBP-2]  ; load gdt selector
-  MOV  gdt, AX    ; store in ioentry address selector part
-  XOR  EAX, EAX  ; EAX = 0
-  MOV  DWORD PTR [ioentry], EAX ; clear ioentry offset part
-        ; return code = 0 (in EAX)
-
-        ; now use this function to raise the IOPL
-  MOV  EBX,13    ; special function code
-  CALL  FWORD PTR [ioentry]  ; CALL intersegment indirect 16:32
-
-  ; thread should now be running at IOPL=3
-
-  XOR  EAX, EAX  ; return code = 0
-  LEAVE      ; clean stack frame
-  RET      ; exit
-io_init1 ENDP
-
-; void in_init(short)
-PUBLIC  io_init2
-  ALIGN  04H
-io_init2  PROC
-
-  MOV  gdt, AX    ; store in ioentry address selector part
-  XOR  EAX, EAX  ; EAX = 0
-  MOV  DWORD PTR [ioentry], EAX ; clear ioentry offset part
-        ; return code = 0 (in EAX)
-
-        ; now use this function to raise the IOPL
-  MOV  EBX,13    ; special function code
-  CALL  FWORD PTR [ioentry]  ; CALL intersegment indirect 16:32
-
-  XOR  EAX, EAX  ; return code = 0
-  ret
-io_init2  ENDP
-
-  PUBLIC  io_exit1
-  ALIGN  04H
-io_exit1  PROC
-  push  EBP
-  MOV  EBP, ESP  ; stackframe, I am accustomed to this :-)
-
-  MOV  AX, gdt    ; check if ioinit was called once
-  OR  AX, AX
-  JZ  exerr    ; no gdt entry, so process cannot be at IOPL=3
-        ; through this mechanism
-
-  MOV  EBX, 14    ; function code to disable iopl
-  CALL  FWORD PTR [ioentry]  ; call intersegment indirect 16:32
-
-  ; process should now be at IOPL=3 again
-  XOR  EAX, EAX  ; ok, RETurn code = 0
-  LEAVE
-  RET
-exerr:  XOR  EAX, EAX  ; not ok, RETurn code = ffffffff
-  DEC  EAX
-  LEAVE
-  RET
-io_exit1  ENDP
-
+    MOV EAX,[EBP-8] ; file handle
+    PUSH    EAX     ; do normal close
+    CALL    DosClose
+    ADD ESP, 4      ; clean stack
+
+    MOV AX, WORD PTR [EBP-2]    ; load gdt selector
+    MOV gdt, AX     ; store in ioentry address selector part
+    XOR EAX, EAX    ; eax = 0
+    MOV DWORD PTR [ioentry], EAX ; clear ioentry offset part
+                ; return code = 0 (in %eax)
+    LEAVE           ; clean stack frame
+    RET         ; exit
+_io_init    ENDP
+
+; just for symmetry, does nothing
+
+    ALIGN   04H
+    PUBLIC  _io_exit
+_io_exit    PROC
+    XOR EAX,EAX
+    RET
+_io_exit    ENDP
+
+    ALIGN   04H
+    PUBLIC  int03
+
+int03   PROC
+    INT 3
+    RET
+int03   ENDP
+
+;------------------------------------------------------------------------------
+
+; Initialize I/O access via the driver.
+; You *must* call this routine once for each *thread* that wants to do
+; I/O.
+;
+; The routine is mainly equivalent to a C routine performing the
+; following (but no need to add another file):
+;   DosOpen("/dev/fastio$", read, nonexclusive)
+;   DosDevIOCtl(device, XFREE86IO, IOGETSEL32)
+;   selector -> ioentry+4
+;   DosClose(device)
+;
+; Calling convention:
+;   int io_init1(void)
+; Return:
+;   0 if successful
+;   standard APIRET RETurn code if error
+;
 
     PUBLIC  _io_init1
@@ -388,12 +523,12 @@
 ; for diagnostic only
 
-  PUBLIC  psw
-  ALIGN  04H
-psw  PROC
-  PUSHF      ; get the current PSW
-  POP  EAX    ; into EAX
-  RET
-psw  ENDP
+    PUBLIC  psw
+    ALIGN   04H
+psw PROC
+    PUSHF           ; get the current PSW
+    POP EAX     ; into EAX
+    RET
+psw ENDP
 
 CODE32  ENDS
-  END
+    END
Index: trunk/src/kernel32/wintls.cpp
===================================================================
--- trunk/src/kernel32/wintls.cpp	(revision 4296)
+++ trunk/src/kernel32/wintls.cpp	(revision 4298)
@@ -1,3 +1,3 @@
-/* $Id: wintls.cpp,v 1.12 2000-09-20 21:32:54 hugh Exp $ */
+/* $Id: wintls.cpp,v 1.13 2000-09-21 19:39:57 sandervl Exp $ */
 /*
  * Win32 TLS API functions
@@ -25,11 +25,11 @@
 {
    if(!tlsAddress)
-  return;
+        return;
 
    tlsIndex = TlsAlloc();
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-  DebugInt3();
-  return;
+        dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+        DebugInt3();
+        return;
    }
    dprintf(("Win32ImageBase::tlsAlloc (%d) for module %x", tlsIndex, hinstance));
@@ -40,10 +40,10 @@
 {
    if(!tlsAddress)
-  return;
+        return;
 
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-  DebugInt3();
-  return;
+        dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+        DebugInt3();
+        return;
    }
    dprintf(("Win32ImageBase::tlsDestroy (%d) for module %x", tlsIndex, hinstance));
@@ -60,10 +60,10 @@
 
    if(!tlsAddress)
-  return;
+        return;
 
    if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
-  dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
-  DebugInt3();
-  return;
+        dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
+        DebugInt3();
+        return;
    }
 
@@ -77,7 +77,7 @@
    tibmem = VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
    if(tibmem == NULL) {
-  dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
-  DebugInt3();
-  return;
+        dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
+        DebugInt3();
+        return;
    }
    memset(tibmem, 0, tlsTotalSize);
@@ -88,13 +88,13 @@
 
    if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
-  pCallback = tlsCallBackAddr;
-  while(*pCallback) {
-    dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
-
-    (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
-
-    dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
-    *pCallback++;
-  }
+        pCallback = tlsCallBackAddr;
+        while(*pCallback) {
+            dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
+
+            (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
+
+            dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
+            *pCallback++;
+        }
    }
    return;
@@ -109,25 +109,25 @@
 
    if(!tlsAddress)
-  return;
+        return;
 
    dprintf(("Win32ImageBase::tlsDetachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
 
    if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
-  pCallback = tlsCallBackAddr;
-  while(*pCallback) {
-    dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
-
-    (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
-
-    dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
-    *pCallback++;
-  }
+        pCallback = tlsCallBackAddr;
+        while(*pCallback) {
+            dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
+
+            (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
+
+            dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
+            *pCallback++;
+        }
    }
    tlsmem = TlsGetValue(tlsIndex);
    if(tlsmem) {
-    VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
+        VirtualFree(tlsmem, tlsTotalSize, MEM_RELEASE);
    }
    else {
-  dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!"));
+        dprintf(("ERROR: tlsDetachThread: tlsmem == NULL!!!"));
    }
    TlsFree(tlsIndex);
@@ -154,18 +154,18 @@
   tibidx = 0;
   if(pdb->tls_bits[0] == 0xFFFFFFFF) {
-    if(pdb->tls_bits[1] == 0xFFFFFFFF) {
-      LeaveCriticalSection(&pdb->crit_section);
-      SetLastError(ERROR_NO_MORE_ITEMS);  //TODO: correct error?
-    return -1;
-  }
-  tibidx = 1;
+        if(pdb->tls_bits[1] == 0xFFFFFFFF) {
+            LeaveCriticalSection(&pdb->crit_section);
+            SetLastError(ERROR_NO_MORE_ITEMS);  //TODO: correct error?
+            return -1;
+        }
+        tibidx = 1;
   }
   for(i=0;i<32;i++) {
-  mask = (1 << i);
-  if((pdb->tls_bits[tibidx] & mask) == 0) {
-    pdb->tls_bits[tibidx] |= mask;
-    index = (tibidx*32) + i;
-    break;
-  }
+        mask = (1 << i);
+        if((pdb->tls_bits[tibidx] & mask) == 0) {
+            pdb->tls_bits[tibidx] |= mask;
+            index = (tibidx*32) + i;
+            break;
+        }
   }
   LeaveCriticalSection(&pdb->crit_section);
@@ -205,8 +205,8 @@
   if(pdb->tls_bits[tlsidx] & mask) {
         LeaveCriticalSection(&pdb->crit_section);
-  pdb->tls_bits[tlsidx] &= ~mask;
+        pdb->tls_bits[tlsidx] &= ~mask;
         thdb->tls_array[index] = 0;
         SetLastError(ERROR_SUCCESS);
-  return TRUE;
+        return TRUE;
   }
   LeaveCriticalSection(&pdb->crit_section);
