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 (%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))
31 (setf (%simple-fun-arglist res) (entry-info-arguments entry))
32 (setf (%simple-fun-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
51 (ceiling trace-table-bits sb!vm:n-byte-bits)))
52 (box-num (- (length constants) sb!vm:code-trace-table-offset-slot))
54 ;; FIXME: In CMU CL the X86 behavior here depended on
55 ;; *ENABLE-DYNAMIC-SPACE-CODE*, but in SBCL we always use
56 ;; dynamic space code, so we could make
57 ;; ALLOCATE-DYNAMIC-CODE-OBJECT more parallel with
58 ;; ALLOCATE-CODE-OBJECT and remove this confusing
59 ;; read-macro conditionalization.
61 (%primitive allocate-dynamic-code-object box-num total-length)
63 (%primitive allocate-code-object box-num total-length))
64 (fill-ptr (code-instructions code-obj)))
65 (declare (type index box-num total-length))
67 (sb!assem:on-segment-contents-vectorly
70 (declare (type (simple-array sb!assem:assembly-unit 1) v))
71 (copy-byte-vector-to-system-area v fill-ptr)
72 (setf fill-ptr (sap+ fill-ptr (length v)))))
74 (do-core-fixups code-obj fixups)
76 (dolist (entry (ir2-component-entries 2comp))
77 (make-function-entry entry code-obj object))
79 (sb!vm:sanctify-for-execution code-obj)
81 (let ((info (debug-info-for-component component)))
82 (push info (core-object-debug-info object))
83 (setf (%code-debug-info code-obj) info))
85 (setf (code-header-ref code-obj sb!vm:code-trace-table-offset-slot)
87 (copy-to-system-area trace-table
88 (* sb!vm:vector-data-offset sb!vm:n-word-bits)
93 (do ((index sb!vm:code-constants-offset (1+ index)))
94 ((>= index (length constants)))
95 (let ((const (aref constants index)))
99 (setf (code-header-ref code-obj index)
100 (constant-value const)))
104 (reference-core-function code-obj index
107 (setf (code-header-ref code-obj index)
108 (fdefinition-object (cdr const) t))))))))))