1 ;;;; target-only code that knows how to load compiled code directly
4 ;;;; FIXME: The filename here is confusing because "core" here means
5 ;;;; "main memory", while elsewhere in the system it connotes a
6 ;;;; ".core" file dumping the contents of main memory.
8 ;;;; This software is part of the SBCL system. See the README file for
11 ;;;; This software is derived from the CMU CL system, which was
12 ;;;; written at Carnegie Mellon University and released into the
13 ;;;; public domain. The software is in the public domain and is
14 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
15 ;;;; files for more information.
19 ;;; Make a function entry, filling in slots from the ENTRY-INFO.
20 (defun make-function-entry (entry code-obj object)
21 (declare (type entry-info entry) (type core-object object))
22 (let ((offset (label-position (entry-info-offset entry))))
23 (declare (type index offset))
24 (unless (zerop (logand offset sb!vm:lowtag-mask))
25 (error "Unaligned function object, offset = #X~X." offset))
26 (let ((res (%primitive compute-function code-obj offset)))
27 (setf (%function-self res) res)
28 (setf (%function-next res) (%code-entry-points code-obj))
29 (setf (%code-entry-points code-obj) res)
30 (setf (%function-name res) (entry-info-name entry))
31 (setf (%function-arglist res) (entry-info-arguments entry))
32 (setf (%function-type res) (entry-info-type entry))
34 (note-function entry res object))))
36 ;;; Dump a component to core. We pass in the assembler fixups, code vector
38 (defun make-core-component (component segment length trace-table fixups object)
39 (declare (type component component)
40 (type sb!assem:segment segment)
42 (list trace-table fixups)
43 (type core-object object))
45 (let* ((2comp (component-info component))
46 (constants (ir2-component-constants 2comp))
47 (trace-table (pack-trace-table trace-table))
48 (trace-table-len (length trace-table))
49 (trace-table-bits (* trace-table-len tt-bits-per-entry))
50 (total-length (+ length (ceiling trace-table-bits sb!vm:byte-bits)))
51 (box-num (- (length constants) sb!vm:code-trace-table-offset-slot))
53 ;; FIXME: In CMU CL the X86 behavior here depended on
54 ;; *ENABLE-DYNAMIC-SPACE-CODE*, but in SBCL we always use
55 ;; dynamic space code, so we could make
56 ;; ALLOCATE-DYNAMIC-CODE-OBJECT more parallel with
57 ;; ALLOCATE-CODE-OBJECT and remove this confusing
58 ;; read-macro conditionalization.
60 (%primitive allocate-dynamic-code-object box-num total-length)
62 (%primitive allocate-code-object box-num total-length))
63 (fill-ptr (code-instructions code-obj)))
64 (declare (type index box-num total-length))
66 (sb!assem:on-segment-contents-vectorly
69 (declare (type (simple-array sb!assem:assembly-unit 1) v))
70 (copy-byte-vector-to-system-area v fill-ptr)
71 (setf fill-ptr (sap+ fill-ptr (length v)))))
73 (do-core-fixups code-obj fixups)
75 (dolist (entry (ir2-component-entries 2comp))
76 (make-function-entry entry code-obj object))
78 (sb!vm:sanctify-for-execution code-obj)
80 (let ((info (debug-info-for-component component)))
81 (push info (core-object-debug-info object))
82 (setf (%code-debug-info code-obj) info))
84 (setf (code-header-ref code-obj sb!vm:code-trace-table-offset-slot) length)
85 (copy-to-system-area trace-table
86 (* sb!vm:vector-data-offset sb!vm:word-bits)
91 (do ((index sb!vm:code-constants-offset (1+ index)))
92 ((>= index (length constants)))
93 (let ((const (aref constants index)))
97 (setf (code-header-ref code-obj index)
98 (constant-value const)))
102 (reference-core-function code-obj index
105 (setf (code-header-ref code-obj index)
106 (fdefinition-object (cdr const) t))))))))))
109 (defun make-core-byte-component (segment length constants xeps object)
110 (declare (type sb!assem:segment segment)
112 (type vector constants)
114 (type core-object object))
116 (let* ((num-constants (length constants))
117 ;; KLUDGE: On the X86, using ALLOCATE-CODE-OBJECT is
118 ;; supposed to make the result non-relocatable, which is
119 ;; probably not what we want. Could this be made into
120 ;; ALLOCATE-DYNAMIC-CODE-OBJECT? Is there some other fix?
121 ;; Am I just confused? -- WHN 19990916
122 (code-obj (%primitive allocate-code-object
123 (the index (1+ num-constants))
125 (fill-ptr (code-instructions code-obj)))
126 (declare (type index length)
127 (type system-area-pointer fill-ptr))
128 (sb!assem:on-segment-contents-vectorly
131 (declare (type (simple-array sb!assem:assembly-unit 1) v))
132 (copy-byte-vector-to-system-area v fill-ptr)
133 (setf fill-ptr (sap+ fill-ptr (length v)))))
135 (setf (code-header-ref code-obj sb!vm:code-trace-table-offset-slot)
138 (let ((xep (cdr noise)))
139 (setf (byte-function-component xep) code-obj)
140 (initialize-byte-compiled-function xep)
141 (note-function (lambda-info (car noise)) xep object)))
143 (dotimes (index num-constants)
144 (let ((const (aref constants index))
145 (code-obj-index (+ index sb!vm:code-constants-offset)))
149 (setf (code-header-ref code-obj code-obj-index)
150 (constant-value const)))
154 (reference-core-function code-obj code-obj-index (cdr const)
157 (setf (code-header-ref code-obj code-obj-index)
158 (sb!impl::fdefinition-object (cdr const) t)))
160 (let ((*unparse-function-type-simplify* t))
161 (setf (code-header-ref code-obj code-obj-index)
162 (load-type-predicate (type-specifier (cdr const))))))
164 (let ((xep (cdr (assoc (cdr const) xeps :test #'eq))))
166 (setf (code-header-ref code-obj code-obj-index) xep))))))))))