source: branches/working-0711/ccl/lisp-kernel/x86-asmutils64.s @ 9984

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

Use symbolic names for C arg registers, since Windows uses a
(very) different C ABI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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       
17
18        include(lisp.s)
19
20        _beginfile
21
22/* Flush %carg1 cache lines, starting at address in %carg0.  Each line is */
23/*   assumed to be %carg2 bytes wide. */
24_exportfn(C(flush_cache_lines))
25        __(cmpq $0,%carg1)
26        __(jmp 2f)
271:      __(clflush (%carg0))
28        __(addq %carg2,%carg0)
29        __(subq $1,%carg1)
302:      __(jg 1b)       
31        __(repret)
32_endfn
33
34_exportfn(C(current_stack_pointer))
35        __(movq %rsp,%cret)
36        __(ret)
37_endfn
38
39_exportfn(C(touch_page))
40        __(movq %carg0,(%carg0))
41        __(movq $0,(%carg0))
42        __(movl $1,%cret_l)
43        .globl C(touch_page_end)
44C(touch_page_end):     
45        __(ret)
46                       
47_exportfn(C(count_leading_zeros))
48        __(bsrq %carg0,%cret)
49        __(xorq $63,%cret)
50        __(ret)
51_endfn
52
53_exportfn(C(noop))
54        __(retq)
55_endfn
56
57_exportfn(C(set_mxcsr))
58        __(pushq %carg0)
59        __(ldmxcsr (%rsp))
60        __(addq $8,%rsp)
61        __(ret)
62_endfn
63       
64_exportfn(C(get_mxcsr))
65        __(pushq $0)
66        __(stmxcsr (%rsp))
67        __(popq %cret)
68        __(ret)
69_endfn
70
71_exportfn(C(save_fp_context))
72_endfn
73       
74_exportfn(C(restore_fp_context))
75_endfn                       
76
77/*  Atomically store new value (%carg2) in *%carg0, if old value == %carg1. */
78/*  Return actual old value. */
79_exportfn(C(store_conditional))
80        __(mov %carg1,%cret)
81        __(lock)
82        __(cmpxchgq %carg2,(%carg0))
83        __(cmovne %carg2,%cret)
84        __(ret)
85_endfn
86
87/*      Atomically store new_value(%carg1) in *%carg0 ;  return previous contents */
88/*      of *%carg0. */
89
90_exportfn(C(atomic_swap))
91        __(lock) 
92        __(xchg %carg1,(%carg0))
93        __(mov %carg1,%cret)
94        __(ret)
95_endfn
96
97/*        Logior the value in *%carg0 with the value in %carg1 (presumably a */
98/*      bitmask with exactly 1 bit set.)  Return non-zero if any of */
99/*      the bits in that bitmask were already set. */
100_exportfn(C(atomic_ior))
1010:      __(movq (%carg0),%cret)
102        __(movq %cret,%carg2)
103        __(orq %carg1,%carg2)
104        __(lock)
105        __(cmpxchg %carg2,(%carg0))
106        __(jnz 0b)
107        __(andq %carg1,%cret)
108        __(ret)
109_endfn
110       
111       
112/* Logand the value in *carg0 with the value in carg1 (presumably a bitmask with exactly 1 */
113/* bit set.)  Return the value now in *carg0 (for some value of "now" */
114
115_exportfn(C(atomic_and))
1160:      __(movq (%carg0),%cret)
117        __(movq %cret,%carg2)
118        __(and %carg1,%carg2)
119        __(lock)
120        __(cmpxchg %carg2,(%carg0))
121        __(jnz 0b)
122        __(movq %carg2,%cret)
123        __(ret)
124_endfn
125
126
127        __ifdef([DARWIN])
128_exportfn(C(pseudo_sigreturn))
129        __(hlt)
130        __(jmp C(pseudo_sigreturn))
131_endfn
132        __endif                       
133
134/* int cpuid (natural code, natural *pebx, natural *pecx, natural *pedx)  */
135_exportfn(C(cpuid))
136        __(pushq %carg2)
137        __(pushq %carg3)
138        __(movq %carg1, %ctemp0)
139        __(pushq %rbx)          /* non-volatile reg, clobbered by CPUID */
140        __(movq %carg0, %rax)
141        __(xorq %rcx,%rcx)
142        __(cpuid)
143        __(movq %rbx,(%ctemp0))
144        __(popq %rbx)
145        __(popq %ctemp0)           /* recover pedx */
146        __(movq %rdx,(%ctemp0))
147        __(popq %ctemp0)                /* recover pecx */
148        __(movq %rcx,(%ctemp0))
149        __(ret)
150_endfn
151
152/* switch_to_foreign_stack(new_sp, func, arg_0, arg_1, arg_2, arg_3)  */
153/*   Not fully general, but should get us off of the signal stack */
154_exportfn(C(switch_to_foreign_stack))
155        __ifdef([WINDOWS])
156        __(movq 8(%rsp), %ctemp0)
157        __(movq 16(%rsp), %ctemp1)
158        __endif
159        __(movq %carg0,%rsp)
160        __(movq %carg1,%rax)
161        __(movq %carg2,%carg0)
162        __(movq %carg3,%carg1)
163        __ifdef([WINDOWS])
164        __(movq %ctemp0, %carg2)
165        __(movq %ctemp1, %carg3)
166        __else
167        __(movq %carg4,%carg2)
168        __(movq %carg5,%carg3)
169        __endif
170        __(jmp *%rax)
171_endfn
172
173_exportfn(C(freebsd_sigreturn))
174        __(movl $417,%eax)      /* SYS_sigreturn */
175        __(syscall)                             
176_exportfn(C(get_vector_registers))
177_endfn
178
179_exportfn(C(put_vector_registers))
180_endfn                         
181       
182       
183        __ifdef([DARWIN_GS_HACK])
184/* Check (in an ugly, non-portable way) to see if %gs is addressing
185   pthreads data.  If it was, return 0; otherwise, assume that it's
186   addressing a lisp tcr and set %gs to point to the tcr's tcr.osid,
187   then return 1. */
188       
189thread_signature = 0x54485244 /* 'THRD' */
190       
191_exportfn(C(ensure_gs_pthread))
192        __(cmpl $thread_signature,%gs:0)
193        __(movl $0,%eax)
194        __(je 9f)
195        __(movq %gs:tcr.osid,%rdi)
196        __(movl $0x3000003,%eax)
197        __(syscall)
198        __(movl $1,%eax)
1999:      __(repret)
200_endfn
201
202        /* Ensure that %gs addresses the linear address in %rdi */
203        /* This incidentally returns the segment selector .*/
204_exportfn(C(set_gs_address))
205        __(movl $0x3000003,%eax)
206        __(syscall)
207        __(ret)
208_endfn
209        __endif         
210        _endfile
Note: See TracBrowser for help on using the repository browser.