source: trunk/source/lisp-kernel/x86-subprims64.s @ 8602

Last change on this file since 8602 was 8602, checked in by andreas, 12 years ago

Convert start_lisp to platform-independent registers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/*   Copyright (C) 2005 Clozure Associates*/
2/*   This file is part of OpenMCL.  */
3
4/*   OpenMCL is licensed under the terms of the Lisp Lesser GNU Public*/
5/*   License , known as the LLGPL and distributed with OpenMCL as the*/
6/*   file "LICENSE".  The LLGPL consists of a preamble and the LGPL,*/
7/*   which is distributed with OpenMCL as the file "LGPL".  Where these*/
8/*   conflict, the preamble takes precedence.  */
9
10/*   OpenMCL is referenced in the preamble as the "LIBRARY."*/
11
12/*   The LLGPL is also available online at*/
13/*   http://opensource.franz.com/preamble.html*/
14
15
16        include(lisp.s)
17        _beginfile
18
19        .globl _SPmkcatch1v
20        .globl _SPnthrow1value
21
22
23/* This is called from a c-style context and calls a lisp function.*/
24/* This does the moral equivalent of*/
25/*   (loop */
26/*      (let* ((fn (%function_on_top_of_lisp_stack)))*/
27/*        (if fn*/
28/*            (catch %toplevel-catch%*/
29/*             (funcall fn))*/
30/*            (return nil))))*/
31
32
33_exportfn(toplevel_loop)
34        __(push %rbp)
35        __(movq %rsp,%rbp)
36        /* Switch to the lisp stack */
37        __(push $0)
38        __(push $0)
39        __(movq %rsp,rcontext(tcr.foreign_sp))
40        __(movq rcontext(tcr.save_vsp),%rsp)
41        __(push $0)
42        __(movq %rsp,%rbp)
43       
44        __(TSP_Alloc_Fixed(0,%temp0))
45        __(movsd %fpzero,tsp_frame.save_rbp(%temp0)) /* sentinel */
46        __(jmp local_label(test))
47local_label(loop):
48        __(ref_nrs_value(toplcatch,%arg_z))
49        __(leaq local_label(back_from_catch)(%rip),%ra0)
50        __(leaq local_label(test)(%rip),%xfn)
51        __(push %ra0)
52        __(jmp _SPmkcatch1v)
53__(tra(local_label(back_from_catch)))
54        __(movq %arg_x,%temp0)
55        __(leaq local_label(back_from_funcall)(%rip),%ra0)
56        __(push %ra0)
57        __(set_nargs(0))
58        __(jmp _SPfuncall)
59__(tra(local_label(back_from_funcall)))
60        __(movl $fixnumone,%imm0_l)
61        __(leaq local_label(test)(%rip),%ra0)
62        __(jmp _SPnthrow1value)
63__(tra(local_label(test)))
64        __(movq 8(%rbp),%arg_x)
65        __(cmpq $nil_value,%arg_x)
66        __(jnz local_label(loop))
67local_label(back_to_c):
68        __(discard_temp_frame(%imm0))
69        __(movq rcontext(tcr.foreign_sp),%rsp)
70        __(addq $dnode_size,%rsp)
71        __(movq %rsp,%rbp)
72        __(leave)
73        __(ret)
74
75/* This is called from C code when a thread (including the initial thread) */
76/* starts execution.  (Historically, it also provided a primitive way of */
77/* "resettting" a thread in the event of catastrophic failure, but this */
78/* hasn't worked in a long time.) */
79/* For compatibility with PPC code, this is called with the first foreign */
80/* argument pointing to the thread's TCR and the second foreign argument */
81/*  being a Boolean which indicates whether the thread should try to */
82/* "reset" itself or start running lisp code.  Both of these arguments */
83/* are currently ignored (the TCR is maintained in a segment register and */
84/*  the reset/panic code doesn't work ...) */
85   
86_exportfn(C(start_lisp))
87        __(push %rbp)
88        __(movq %rsp,%rbp)
89        __(push %csave0)
90        __(push %csave1)
91        __(push %csave2)
92        __(push %csave3)
93        __(push %csave4)
94        __ifdef([WINDOWS])
95        __(push %csave5)
96        __(push %csave6)
97        /* FIXME: set up %rcontext_reg a.k.a. r11 */
98        __endif
99        __ifdef([DARWIN_GS_HACK])
100         __(set_gs_base())
101        __endif
102        __(sub $8,%rsp) /* %rsp is now 16-byte aligned  */
103        /* Put harmless values in lisp node registers  */
104        __(clr %arg_z)
105        __(clr %arg_y)
106        __(clr %arg_x)
107        __(clr %temp0)
108        __(clr %temp1)
109        __(clr %temp2)
110        __(clr %fn)
111        /*      __(clr %ra0) */ /* %ra0 == %temp2, now zeroed above */
112        __(clr %save0)
113        __(clr %save1)
114        __(clr %save2)
115        __ifndef([WINDOWS]) /* no %save3, r11 is %rcontext_reg */
116        __(clr %save3)
117        __endif
118        __(pxor %fpzero,%fpzero)        /* fpzero = 0.0[d0] */
119        __(stmxcsr rcontext(tcr.foreign_mxcsr))
120        __(andb $~mxcsr_all_exceptions,rcontext(tcr.foreign_mxcsr))
121        __(ldmxcsr rcontext(tcr.lisp_mxcsr))
122        __(movq $TCR_STATE_LISP,rcontext(tcr.valence))
123        __(call toplevel_loop)
124        __(movq $TCR_STATE_FOREIGN,rcontext(tcr.valence))
125        __(emms)
126        __(addq $8,%rsp)        /* discard alignment word */
127        __ifdef([WINDOWS])
128        __(pop %csave6)
129        __(pop %csave5)
130        __endif
131        __(pop %csave4)
132        __(pop %csave3)
133        __(pop %csave2)
134        __(pop %csave1)
135        __(pop %csave0)
136        __(ldmxcsr rcontext(tcr.foreign_mxcsr))
137        __ifdef([DARWIN_GS_HACK])
138         __(set_foreign_gs_base)
139        __endif
140        __(movl $nil_value,%eax)
141        __(leave)
142        __(ret)
143_endfn
144               
Note: See TracBrowser for help on using the repository browser.