2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
31 write_bytes(FILE *file, char *addr, long bytes)
33 long count, here, data;
35 bytes = (bytes+os_vm_page_size-1)&~(os_vm_page_size-1);
40 data = (ftell(file)+os_vm_page_size-1)&~(os_vm_page_size-1);
44 count = fwrite(addr, 1, bytes, file);
50 perror("error writing to save file");
56 return data/os_vm_page_size - 1;
60 output_space(FILE *file, int id, lispobj *addr, lispobj *end)
62 int words, bytes, data;
63 static char *names[] = {NULL, "dynamic", "static", "read-only"};
69 bytes = words * sizeof(lispobj);
71 printf("writing %d bytes from the %s space at 0x%08lx\n",
72 bytes, names[id], (unsigned long)addr);
74 data = write_bytes(file, (char *)addr, bytes);
77 putw((long)addr / os_vm_page_size, file);
78 putw((bytes + os_vm_page_size - 1) / os_vm_page_size, file);
82 save(char *filename, lispobj init_function)
87 file = fopen(filename, "w");
92 printf("[undoing binding stack... ");
94 unbind_to_here((lispobj *)BINDING_STACK_START);
95 SetSymbolValue(CURRENT_CATCH_BLOCK, 0);
96 SetSymbolValue(CURRENT_UNWIND_PROTECT_BLOCK, 0);
97 SetSymbolValue(EVAL_STACK_TOP, 0);
99 printf("[saving current Lisp image into %s:\n", filename);
101 putw(CORE_MAGIC, file);
103 putw(CORE_VERSION, file);
105 putw(SBCL_CORE_VERSION_INTEGER, file);
107 putw(CORE_NDIRECTORY, file);
110 output_space(file, READ_ONLY_SPACE_ID, (lispobj *)READ_ONLY_SPACE_START,
111 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER));
112 output_space(file, STATIC_SPACE_ID, (lispobj *)STATIC_SPACE_START,
113 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER));
115 output_space(file, DYNAMIC_SPACE_ID, (lispobj *)current_dynamic_space,
116 dynamic_space_free_pointer);
119 /* Flush the current_region updating the tables. */
120 gc_alloc_update_page_tables(0,&boxed_region);
121 gc_alloc_update_page_tables(1,&unboxed_region);
122 update_x86_dynamic_space_free_pointer();
124 output_space(file, DYNAMIC_SPACE_ID, (lispobj *)DYNAMIC_SPACE_START,
125 (lispobj *)SymbolValue(ALLOCATION_POINTER));
128 putw(CORE_INITIAL_FUNCTION, file);
130 putw(init_function, file);
132 putw(CORE_END, file);