Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[189dd8]: src / compiler / generic / target-core.lisp Maximize Restore History

Download this file

target-core.lisp    119 lines (105 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;;;; target-only code that knows how to load compiled code directly
;;;; into core
;;;;
;;;; FIXME: The filename here is confusing because "core" here means
;;;; "main memory", while elsewhere in the system it connotes a
;;;; ".core" file dumping the contents of main memory.
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; This software is derived from the CMU CL system, which was
;;;; written at Carnegie Mellon University and released into the
;;;; public domain. The software is in the public domain and is
;;;; provided with absolutely no warranty. See the COPYING and CREDITS
;;;; files for more information.
(in-package "SB!C")
(declaim (ftype (function (fixnum fixnum) (values code-component &optional))
allocate-code-object))
(defun allocate-code-object (boxed unboxed)
#!+gencgc
(without-gcing
(%make-lisp-obj
(alien-funcall (extern-alien "alloc_code_object" (function unsigned unsigned unsigned))
boxed unboxed)))
#!-gencgc
(%primitive allocate-code-object boxed unboxed))
;;; Make a function entry, filling in slots from the ENTRY-INFO.
(defun make-fun-entry (entry-info code-obj object)
(declare (type entry-info entry-info) (type core-object object))
(let ((offset (label-position (entry-info-offset entry-info))))
(declare (type index offset))
(unless (zerop (logand offset sb!vm:lowtag-mask))
(error "Unaligned function object, offset = #X~X." offset))
(let ((res (%primitive compute-fun code-obj offset)))
(setf (%simple-fun-self res) res)
(setf (%simple-fun-next res) (%code-entry-points code-obj))
(setf (%code-entry-points code-obj) res)
(setf (%simple-fun-name res) (entry-info-name entry-info))
(setf (%simple-fun-arglist res) (entry-info-arguments entry-info))
(setf (%simple-fun-type res) (entry-info-type entry-info))
(setf (%simple-fun-info res) (entry-info-info entry-info))
(note-fun entry-info res object))))
;;; Dump a component to core. We pass in the assembler fixups, code
;;; vector and node info.
(defun make-core-component (component segment length trace-table fixup-notes object)
(declare (type component component)
(type sb!assem:segment segment)
(type index length)
(list trace-table fixup-notes)
(type core-object object))
(without-gcing
(let* ((2comp (component-info component))
(constants (ir2-component-constants 2comp))
(trace-table (pack-trace-table trace-table))
(trace-table-len (length trace-table))
(trace-table-bits (* trace-table-len tt-bits-per-entry))
(total-length (+ length
(ceiling trace-table-bits sb!vm:n-byte-bits)))
(box-num (- (length constants) sb!vm:code-trace-table-offset-slot))
(code-obj (allocate-code-object box-num total-length))
(fill-ptr (code-instructions code-obj)))
(declare (type index box-num total-length))
(let ((v (sb!assem:segment-contents-as-vector segment)))
(declare (type (simple-array sb!assem:assembly-unit 1) v))
(copy-byte-vector-to-system-area v fill-ptr)
(setf fill-ptr (sap+ fill-ptr (length v))))
(do-core-fixups code-obj fixup-notes)
(dolist (entry (ir2-component-entries 2comp))
(make-fun-entry entry code-obj object))
#!-(or x86 x86-64)
(sb!vm:sanctify-for-execution code-obj)
(let ((info (debug-info-for-component component)))
(push info (core-object-debug-info object))
(setf (%code-debug-info code-obj) info))
(setf (code-header-ref code-obj sb!vm:code-trace-table-offset-slot)
length)
;; KLUDGE: the "old" COPY-TO-SYSTEM-AREA automagically worked if
;; somebody changed the number of bytes in a trace table entry.
;; This version is a bit more fragile; if only there were some way
;; to insulate ourselves against changes like that...
;;
;; Then again, PACK-TRACE-TABLE in src/compiler/trace-table.lisp
;; doesn't appear to do anything interesting, returning a 0-length
;; array. So it seemingly doesn't matter what we do here. Is this
;; stale code?
;; --njf, 2005-03-23
(copy-ub16-to-system-area trace-table 0 fill-ptr 0 trace-table-len)
(do ((index sb!vm:code-constants-offset (1+ index)))
((>= index (length constants)))
(let ((const (aref constants index)))
(etypecase const
(null)
(constant
(setf (code-header-ref code-obj index)
(constant-value const)))
(list
(ecase (car const)
(:entry
(reference-core-fun code-obj index (cdr const) object))
(:fdefinition
(setf (code-header-ref code-obj index)
(find-or-create-fdefn (cdr const))))
(:known-fun
(setf (code-header-ref code-obj index)
(%coerce-name-to-fun (cdr const)))))))))))
(values))