source: trunk/source/lisp-kernel/x86-subprims32.s @ 11370

Last change on this file since 11370 was 11370, checked in by gb, 11 years ago

Using i386_set_ldt() to point %fs at the tcr on 32-bit FreeBSD doesn't work
on a 64-bit kernel. Using i386_set_fsbase does work on both 32-bit and
64-bit kernels, but doesn't allow writing to %fs: at least by the time
we've called i386_set_fsbase() on thread startup, %fs contains an appropriate
selector and it never changes throughout the life of the thread.

File size: 3.4 KB
Line 
1        include(lisp.s)
2        _beginfile
3       
4        .globl _SPmkcatch1v
5        .globl _SPnthrow1value
6       
7/* This is called from a c-style context and calls a lisp function.*/
8/* This does the moral equivalent of*/
9/*   (loop */
10/*      (let* ((fn (%function_on_top_of_lisp_stack)))*/
11/*        (if fn*/
12/*            (catch %toplevel-catch%*/
13/*             (funcall fn))*/
14/*            (return nil))))*/
15
16
17_exportfn(toplevel_loop)
18Xsubprims_start:               
19        __(push %ebp)
20        __(movl %esp,%ebp)
21        /* Switch to the lisp stack */
22        __(movl %esp,rcontext(tcr.foreign_sp))
23        __(movl rcontext(tcr.save_vsp),%esp)
24        __(push $0)
25        __(mov %esp,%ebp)
26        __(cmpl $0,C(GCDebug))
27        __(je 1f)
28        __(ref_global(initial_tcr,%imm0))
29        __(cmpl rcontext(tcr.linear),%imm0)
30        __(jne 1f)
31        __(clr %imm0)
32        __(uuo_error_gc_trap)
331:
34        __(jmp local_label(test))
35local_label(loop):
36        __(ref_nrs_value(toplcatch,%arg_z))
37        __(movl [$]local_label(back_from_catch),%ra0)
38        __(movl [$]local_label(test),%xfn)
39        __(push %ra0)
40        __(jmp _SPmkcatch1v)
41__(tra(local_label(back_from_catch)))
42        __(movl %arg_y,%temp0)
43        __(pushl [$]local_label(back_from_funcall))
44        __(set_nargs(0))
45        __(jmp _SPfuncall)
46__(tra(local_label(back_from_funcall)))
47        __(movl $fixnumone,%imm0)
48        __(movl [$]local_label(test),%ra0)
49        __(jmp _SPnthrow1value)
50__(tra(local_label(test)))
51        __(movl 4(%ebp),%arg_y)
52        __(cmpl $nil_value,%arg_y)
53        __(jnz local_label(loop))
54local_label(back_to_c):
55        __(movl rcontext(tcr.foreign_sp),%esp)
56        __(movl %esp,%ebp)
57        __(leave)
58        __(ret)
59
60/* This is called from C code when a thread (including the initial thread) */
61/* starts execution.  (Historically, it also provided a primitive way of */
62/* "resettting" a thread in the event of catastrophic failure, but this */
63/* hasn't worked in a long time.) */
64/* For compatibility with PPC code, this is called with the first foreign */
65/* argument pointing to the thread's TCR and the second foreign argument */
66/*  being a Boolean which indicates whether the thread should try to */
67/* "reset" itself or start running lisp code. */
68/* The reset/panic code doesn't work. */
69
70_exportfn(C(start_lisp))
71        __(push %ebp)
72        __(movl %esp, %ebp)
73        __(push %edi)
74        __(push %esi)
75        __(push %ebx)
76        __(mov 8(%ebp), %ebx)   /* get tcr */
77        __ifndef([FREEBSD])
78         __(movw tcr.ldt_selector(%ebx), %rcontext_reg)
79        __endif
80        __(movl 8(%ebp),%eax)
81        __(cmpl rcontext(tcr.linear),%eax)
82        __(je 0f)
83        __(hlt)
840:             
85        .if c_stack_16_byte_aligned
86        __(sub $12, %esp)       /* stack now 16-byte aligned */
87        .else
88        __(andl $~15,%esp)
89        .endif
90        __(clr %arg_z)
91        __(clr %arg_y) 
92        __(clr %temp0)
93        __(clr %temp1)
94        __(clr %fn)
95        __(pxor %fpzero, %fpzero)
96        __(stmxcsr rcontext(tcr.foreign_mxcsr))
97        __(andb $~mxcsr_all_exceptions,rcontext(tcr.foreign_mxcsr))
98        __(ldmxcsr rcontext(tcr.lisp_mxcsr))
99        __(movl $TCR_STATE_LISP, rcontext(tcr.valence))
100        __(call toplevel_loop)
101        __(movl $TCR_STATE_FOREIGN, rcontext(tcr.valence))
102        __(emms)
103        __(leal -3*node_size(%ebp),%esp)
104        __(pop %ebx)
105        __(pop %esi)
106        __(pop %edi)
107        __(ldmxcsr rcontext(tcr.foreign_mxcsr))
108        __ifdef([WIN32_ES_HACK])
109         __(push %ds)
110         __(pop %es)
111        __endif
112        __(movl $nil_value, %eax)
113        __(leave)
114        __(ret)
115Xsubprims_end:           
116_endfn
117
118        .data
119        .globl C(subprims_start)
120        .globl C(subprims_end)
121C(subprims_start):      .long Xsubprims_start
122C(subprims_end):        .long Xsubprims_end
123        .text
124
125
Note: See TracBrowser for help on using the repository browser.