read-image.scm 2.1 KB

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