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 (declaim (ftype (sfunction (#!+immobile-code boolean fixnum fixnum
)
20 code-component
) allocate-code-object
))
21 (defun allocate-code-object (#!+immobile-code immobile-p boxed unboxed
)
24 (if (or #!+immobile-code immobile-p
)
25 #!+immobile-code
(sb!vm
::allocate-immobile-code boxed unboxed
)
28 (alien-funcall (extern-alien "alloc_code_object" (function unsigned unsigned unsigned
))
31 (%primitive allocate-code-object boxed unboxed
))
33 ;;; Make a function entry, filling in slots from the ENTRY-INFO.
34 (defun make-fun-entry (entry-info code-obj object
)
35 (declare (type entry-info entry-info
) (type core-object object
))
36 (let ((offset (label-position (entry-info-offset entry-info
))))
37 (declare (type index offset
))
38 (unless (zerop (logand offset sb
!vm
:lowtag-mask
))
39 (error "Unaligned function object, offset = #X~X." offset
))
40 (let ((res (%primitive compute-fun code-obj offset
)))
41 (setf (%simple-fun-self res
) res
)
42 (setf (%simple-fun-next res
) (%code-entry-points code-obj
))
43 (setf (%code-entry-points code-obj
) res
)
44 (setf (%simple-fun-name res
) (entry-info-name entry-info
))
45 (setf (%simple-fun-arglist res
) (entry-info-arguments entry-info
))
46 (setf (%simple-fun-type res
) (entry-info-type entry-info
))
47 (setf (%simple-fun-info res
) (entry-info-info entry-info
))
49 (note-fun entry-info res object
))))
51 ;;; Dump a component to core. We pass in the assembler fixups, code
52 ;;; vector and node info.
53 (defun make-core-component (component segment length fixup-notes object
)
54 (declare (type component component
)
55 (type sb
!assem
:segment segment
)
58 (type core-object object
))
59 (let ((debug-info (debug-info-for-component component
)))
60 ;; FIXME: use WITHOUT-GCING only for stuff that needs it.
62 (let* ((2comp (component-info component
))
63 (constants (ir2-component-constants 2comp
))
64 (box-num (- (length constants
) sb
!vm
:code-constants-offset
))
65 ;; All compilation into memory favors the immobile space.
66 (code-obj (allocate-code-object #!+immobile-code t box-num length
))
67 (fill-ptr (code-instructions code-obj
)))
68 (declare (type index box-num length
))
70 (let ((v (sb!assem
:segment-contents-as-vector segment
)))
71 (declare (type (simple-array sb
!assem
:assembly-unit
1) v
))
72 (copy-byte-vector-to-system-area v fill-ptr
)
73 (setf fill-ptr
(sap+ fill-ptr
(length v
))))
75 (do-core-fixups code-obj fixup-notes
)
77 (dolist (entry (ir2-component-entries 2comp
))
78 (make-fun-entry entry code-obj object
))
81 (sb!vm
:sanctify-for-execution code-obj
)
83 (push debug-info
(core-object-debug-info object
))
84 (setf (%code-debug-info code-obj
) debug-info
)
86 (do ((index sb
!vm
:code-constants-offset
(1+ index
)))
87 ((>= index
(length constants
)))
88 (let ((const (aref constants index
)))
92 (setf (code-header-ref code-obj index
)
93 (constant-value const
)))
97 (reference-core-fun code-obj index
(cdr const
) object
))
99 (setf (code-header-ref code-obj index
)
100 (find-or-create-fdefn (cdr const
))))
102 (setf (code-header-ref code-obj index
)
103 (%coerce-name-to-fun
(cdr const
))))))))))))