Jan 31, 2011, 11:17:18 PM (9 years ago)

Merge shrink-tcr branch. This enables the 32-bit Windows lisp to run
on 64-bit Windows.

On 32-bit x86 ports, we expect to use a segment register to point to a
block of thread-local data called the TCR (thread context record).
This has always been kind of a bother on 32-bit Windows: we have been
using a kludge that allows us to use the %es segment register
(conditionalized on WIN32_ES_HACK).

Unfortunately, 64-bit Windows doesn't support using an LDT. This is
why the 32-bit lisp wouldn't run on 64-bit Windows.

The new scheme is to use some of the TlsSlots? (part of the Windows
TEB) for the most important parts of the TCR, and to introduce an "aux
vector" for the remaining TCR slots. Since %fs points to the TEB, we
can make this work. We reserve the last 34 (of 64) slots for our use,
and will die if we don't get them.

Microsoft's documentation says not to access the TlsSlots? directly
(you're supposed to use TlsGetValue/TlsSetValue?), so we're treading on
undocumented ground. Frankly, we've done worse.

This change introduces some ugliness. In lisp kernel C files, there's
a TCR_AUX(tcr) macro that expands to "tcr->aux" on win32, and to "tcr"

If lisp or lap code has a pointer to a TCR, it's necessary to subtract
off target::tcr-bias (which on Windows/x86 is #xe10, the offset from
%fs to the TlsSlots? in the Windows TEB). We also sometimes have to load
target::tcr.aux to get at data which has been moved there.

These changes should only affect Windows/x86. The story on the other
platforms is just the same as before.

1 edited


  • trunk/source/level-0/X86/X8632/x8632-misc.lisp

    r13365 r14619  
    208208  (movl (@ (% :rcontext) x8632::tcr.last-allocptr) (% temp0))
    209209  (cmpl ($ -8) (% temp1))               ;void_allocptr
     210  (jz @go)
     211  #+windows-target
     212  (progn
     213    (movl (:rcontext x8632::tcr.aux) (% imm0))
     214    (movq (@ x8632::tcr-aux.total-bytes-allocated-low (% imm0)) (% mm0)))
     215  #-windows-target
    210216  (movq (@ (% :rcontext) x8632::tcr.total-bytes-allocated-low) (% mm0))
    211   (jz @go)
    212217  (movl (% temp0) (% arg_y))
    213218  (subl (% temp1) (% temp0))
    340345(defx8632lapfunction %tcr-toplevel-function ((tcr arg_z))
    341346  (check-nargs 1)
    342   (movl (@ x8632::tcr.vs-area (% tcr)) (% temp0))
     347  (movl (@ (- x8632::tcr.vs-area x8632::tcr-bias) (% tcr)) (% temp0))
    343348  (movl (@ x8632::area.high (% temp0)) (% imm0)) ;bottom of vstack
    344349  (cmpl (% tcr) (@ (% :rcontext) x8632::tcr.linear))
    355360(defx8632lapfunction %set-tcr-toplevel-function ((tcr arg_y) (fun arg_z))
    356361  (check-nargs 2)
    357   (movl (@ x8632::tcr.vs-area (% tcr)) (% temp0))
     362  (movl (@ (- x8632::tcr.vs-area x8632::tcr-bias) (% tcr)) (% temp0))
    358363  (movl (@ x8632::area.high (% temp0)) (% imm0))
    359364  (cmpl (% tcr) (@ (% :rcontext) x8632::tcr.linear))
    368373  (jne @have-room)
    369374  (movl (% imm0) (@ x8632::area.active (% temp0)))
    370   (movl (% imm0) (@ x8632::tcr.save-vsp (% tcr)))
     375  (movl (% imm0) (@ (- x8632::tcr.save-vsp x8632::tcr-bias) (% tcr)))
    371376  (jmp @have-room)
    372377  @have-room
Note: See TracChangeset for help on using the changeset viewer.