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-fun-entry (entry-info code-obj object)
21 (declare (type entry-info entry-info) (type core-object object))
22 (let ((offset (label-position (entry-info-offset entry-info))))
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-fun code-obj offset)))
27 (setf (%simple-fun-self res) res)
28 (setf (%simple-fun-next res) (%code-entry-points code-obj))
29 (setf (%code-entry-points code-obj) res)
30 (setf (%simple-fun-name res) (entry-info-name entry-info))
31 (setf (%simple-fun-arglist res) (entry-info-arguments entry-info))
32 (setf (%simple-fun-type res) (entry-info-type entry-info))
33 (setf (%simple-fun-xrefs res) (entry-info-xref entry-info))
35 (note-fun entry-info res object))))
37 ;;; Dump a component to core. We pass in the assembler fixups, code
38 ;;; vector and node info.
39 (defun make-core-component (component segment length trace-table fixup-notes object)
40 (declare (type component component)
41 (type sb!assem:segment segment)
43 (list trace-table fixup-notes)
44 (type core-object object))
46 (let* ((2comp (component-info component))
47 (constants (ir2-component-constants 2comp))
48 (trace-table (pack-trace-table trace-table))
49 (trace-table-len (length trace-table))
50 (trace-table-bits (* trace-table-len tt-bits-per-entry))
51 (total-length (+ length
52 (ceiling trace-table-bits sb!vm:n-byte-bits)))
53 (box-num (- (length constants) sb!vm:code-trace-table-offset-slot))
55 (%primitive allocate-code-object box-num total-length))
56 (fill-ptr (code-instructions code-obj)))
57 (declare (type index box-num total-length))
59 (sb!assem:on-segment-contents-vectorly
62 (declare (type (simple-array sb!assem:assembly-unit 1) v))
63 (copy-byte-vector-to-system-area v fill-ptr)
64 (setf fill-ptr (sap+ fill-ptr (length v)))))
66 (do-core-fixups code-obj fixup-notes)
68 (dolist (entry (ir2-component-entries 2comp))
69 (make-fun-entry entry code-obj object))
71 (sb!vm:sanctify-for-execution code-obj)
73 (let ((info (debug-info-for-component component)))
74 (push info (core-object-debug-info object))
75 (setf (%code-debug-info code-obj) info))
77 (setf (code-header-ref code-obj sb!vm:code-trace-table-offset-slot)
79 ;; KLUDGE: the "old" COPY-TO-SYSTEM-AREA automagically worked if
80 ;; somebody changed the number of bytes in a trace table entry.
81 ;; This version is a bit more fragile; if only there were some way
82 ;; to insulate ourselves against changes like that...
84 ;; Then again, PACK-TRACE-TABLE in src/compiler/trace-table.lisp
85 ;; doesn't appear to do anything interesting, returning a 0-length
86 ;; array. So it seemingly doesn't matter what we do here. Is this
89 (copy-ub16-to-system-area trace-table 0 fill-ptr 0 trace-table-len)
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-fun code-obj index (cdr const) object))
104 (setf (code-header-ref code-obj index)
105 (fdefinition-object (cdr const) t))))))))))