read-image.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, David Frese, Mike Sperber
  3. ;; Image reader that reads images into the two-space GC
  4. (define (really-read-image format reverse-byte-order? port)
  5. (enum-case image-format format
  6. ((two-space)
  7. (really-read-image-two-space-native reverse-byte-order? port))
  8. ((bibop)
  9. (really-read-image-portable format reverse-byte-order? port))
  10. (else
  11. (read-lost "unknown image format" port)
  12. -1)))
  13. (define (really-read-image-two-space-native reverse-byte-order? port)
  14. (let* ((delta (address-difference (get-new-heap-start-addr)
  15. (get-img-start-addr)))
  16. (new-hp (address+ (get-img-end-addr) delta)))
  17. ;; Allocate the needed whole space at once
  18. (alloc-space (cells->a-units (get-img-heap-size)))
  19. ;; Copy the objects in the allocated space
  20. (receive (okay? string)
  21. (image-read-block port (get-new-heap-start-addr)
  22. (cells->a-units (get-img-heap-size)))
  23. (receive (ch eof? status)
  24. (read-char port)
  25. (cond ((not okay?)
  26. (read-lost string port))
  27. ((error? status)
  28. (read-lost "Error reading from image file" port))
  29. ((not eof?)
  30. (read-lost "Image file has extraneous data after image" port))
  31. ((error? (close-input-port port))
  32. (read-lost "Error closing image file" port))
  33. (else
  34. (if reverse-byte-order?
  35. (reverse-byte-order! (get-new-heap-start-addr) new-hp))
  36. (if (not (= delta 0))
  37. (begin
  38. (set-startup-procedure! (adjust (get-startup-procedure) delta))
  39. (set-symbols! (adjust (get-symbols) delta))
  40. (set-imported-bindings! (adjust (get-imported-bindings) delta))
  41. (set-exported-bindings! (adjust (get-exported-bindings) delta))
  42. (set-resumer-records! (adjust (get-resumer-records) delta))
  43. (relocate-symbol-table-two-space! (get-symbols) delta)
  44. (relocate-binding-table-two-space! (get-imported-bindings) delta)
  45. (relocate-binding-table-two-space! (get-exported-bindings) delta)
  46. (relocate-image delta (get-new-heap-start-addr) new-hp)))
  47. 0))))))
  48. (define (initialize-image-areas!)
  49. (unspecific))