5f720fed4464dca0ae01a07d4a7ae2a93801389e
[sbcl.git] / src / compiler / x86-64 / debug.lisp
1 ;;;; x86 support for the debugger
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!VM")
13
14 (define-vop (debug-cur-sp)
15   (:translate current-sp)
16   (:policy :fast-safe)
17   (:results (res :scs (sap-reg sap-stack)))
18   (:result-types system-area-pointer)
19   (:generator 1
20     (move res rsp-tn)))
21
22 (define-vop (debug-cur-fp)
23   (:translate current-fp)
24   (:policy :fast-safe)
25   (:results (res :scs (sap-reg sap-stack)))
26   (:result-types system-area-pointer)
27   (:generator 1
28     (move res rbp-tn)))
29
30 ;;; Stack-ref and %set-stack-ref can be used to read and store
31 ;;; descriptor objects on the control stack. Use the sap-ref
32 ;;; functions to access other data types.
33 (define-vop (read-control-stack)
34   (:translate stack-ref)
35   (:policy :fast-safe)
36   (:args (sap :scs (sap-reg) :to :eval)
37          (offset :scs (any-reg) :target temp))
38   (:arg-types system-area-pointer positive-fixnum)
39   (:temporary (:sc unsigned-reg :from (:argument 1)) temp)
40   (:results (result :scs (descriptor-reg)))
41   (:result-types *)
42   (:generator 9
43     (move temp offset)
44     (inst neg temp)
45     (inst mov result
46           (make-ea :qword :base sap :disp (frame-byte-offset 0) :index temp))))
47
48 (define-vop (read-control-stack-c)
49   (:translate stack-ref)
50   (:policy :fast-safe)
51   (:args (sap :scs (sap-reg)))
52   (:info index)
53   (:arg-types system-area-pointer (:constant (signed-byte 29)))
54   (:results (result :scs (descriptor-reg)))
55   (:result-types *)
56   (:generator 5
57     (inst mov result (make-ea :qword :base sap
58                               :disp (frame-byte-offset index)))))
59
60 (define-vop (write-control-stack)
61   (:translate %set-stack-ref)
62   (:policy :fast-safe)
63   (:args (sap :scs (sap-reg) :to :eval)
64          (offset :scs (any-reg) :target temp)
65          (value :scs (descriptor-reg) :to :result :target result))
66   (:arg-types system-area-pointer positive-fixnum *)
67   (:temporary (:sc unsigned-reg :from (:argument 1) :to :result) temp)
68   (:results (result :scs (descriptor-reg)))
69   (:result-types *)
70   (:generator 9
71     (move temp offset)
72     (inst neg temp)
73     (inst mov
74           (make-ea :qword :base sap :disp (frame-byte-offset 0) :index temp)
75           value)
76     (move result value)))
77
78 (define-vop (write-control-stack-c)
79   (:translate %set-stack-ref)
80   (:policy :fast-safe)
81   (:args (sap :scs (sap-reg))
82          (value :scs (descriptor-reg) :target result))
83   (:info index)
84   (:arg-types system-area-pointer (:constant (signed-byte 29)) *)
85   (:results (result :scs (descriptor-reg)))
86   (:result-types *)
87   (:generator 5
88     (inst mov (make-ea :qword :base sap :disp (frame-byte-offset index))
89           value)
90     (move result value)))
91
92 (define-vop (code-from-mumble)
93   (:policy :fast-safe)
94   (:args (thing :scs (descriptor-reg)))
95   (:results (code :scs (descriptor-reg)))
96   (:temporary (:sc unsigned-reg) temp)
97   (:variant-vars lowtag)
98   (:generator 5
99     (let ((bogus (gen-label))
100           (done (gen-label)))
101       (loadw temp thing 0 lowtag)
102       (inst shr temp n-widetag-bits)
103       (inst jmp :z bogus)
104       (inst shl temp (1- (integer-length n-word-bytes)))
105       (unless (= lowtag other-pointer-lowtag)
106         (inst add temp (- lowtag other-pointer-lowtag)))
107       (move code thing)
108       (inst sub code temp)
109       (emit-label done)
110       (assemble (*elsewhere*)
111         (emit-label bogus)
112         (inst mov code nil-value)
113         (inst jmp done)))))
114
115 (define-vop (code-from-lra code-from-mumble)
116   (:translate sb!di::lra-code-header)
117   (:variant other-pointer-lowtag))
118
119 (define-vop (code-from-function code-from-mumble)
120   (:translate sb!di::fun-code-header)
121   (:variant fun-pointer-lowtag))
122
123 (define-vop (%make-lisp-obj)
124   (:policy :fast-safe)
125   (:translate %make-lisp-obj)
126   (:args (value :scs (unsigned-reg unsigned-stack) :target result))
127   (:arg-types unsigned-num)
128   (:results (result :scs (descriptor-reg)
129                     :load-if (not (sc-is value unsigned-reg))
130                     ))
131   (:generator 1
132     (move result value)))
133
134 (define-vop (get-lisp-obj-address)
135   (:policy :fast-safe)
136   (:translate sb!di::get-lisp-obj-address)
137   (:args (thing :scs (descriptor-reg control-stack) :target result))
138   (:results (result :scs (unsigned-reg)
139                     :load-if (not (and (sc-is thing descriptor-reg)
140                                        (sc-is result unsigned-stack)))))
141   (:result-types unsigned-num)
142   (:generator 1
143     (move result thing)))
144
145
146 (define-vop (fun-word-offset)
147   (:policy :fast-safe)
148   (:translate sb!di::fun-word-offset)
149   (:args (fun :scs (descriptor-reg)))
150   (:results (res :scs (unsigned-reg)))
151   (:result-types positive-fixnum)
152   (:generator 5
153     (loadw res fun 0 fun-pointer-lowtag)
154     (inst shr res n-widetag-bits)))