3 This code was written as part of the CMU Common Lisp project at
4 Carnegie Mellon University, and has been placed in the public domain.
20 #include "internals.h"
25 process_directory(int fd, long *ptr, int count)
28 lispobj *free_pointer;
30 struct ndir_entry *entry;
32 entry = (struct ndir_entry *) ptr;
35 id = entry->identifier;
36 offset = CORE_PAGESIZE * (1 + entry->data_page);
37 addr = (os_vm_address_t) (CORE_PAGESIZE * entry->address);
38 free_pointer = (lispobj *) addr + entry->nwords;
39 len = CORE_PAGESIZE * entry->page_count;
42 os_vm_address_t real_addr;
45 printf("Mapping %ld bytes at 0x%lx.\n", len, addr);
47 real_addr = os_map(fd, offset, addr, len);
48 if (real_addr != addr)
50 "process_directory: file mapped in wrong place! (0x%p != 0x%p)\n",
51 (void *) real_addr, (void *) addr);
54 printf("Space ID = %d, free pointer = 0x%08x.\n", id, free_pointer);
58 case DYNAMIC_SPACE_ID:
59 if (addr != (os_vm_address_t) dynamic_0_space
60 && addr != (os_vm_address_t) dynamic_1_space)
61 printf("Strange ... dynamic space lossage.\n");
62 current_dynamic_space = (lispobj *) addr;
63 #if defined(ibmrt) || defined(i386) || defined(__x86_64)
64 SetSymbolValue(ALLOCATION_POINTER, (lispobj) free_pointer);
66 current_dynamic_space_free_pointer = free_pointer;
70 static_space = (lispobj *) addr;
71 if (len >= static_space_size) {
72 fprintf(stderr, "Error: Static space size (%ld) exceeds allocated space (%ld)!\n",
73 len, static_space_size);
77 case READ_ONLY_SPACE_ID:
78 /* Don't care about read only space */
79 if (len >= read_only_space_size) {
80 fprintf(stderr, "Error: Read only space size (%ld) exceeds allocated space (%lu)!\n",
81 len, read_only_space_size);
86 printf("Strange space ID: %ld; ignored.\n", id);
94 load_core_file(const char *file, fpu_mode_t* fpu_type)
96 int fd = open(file, O_RDONLY), count;
98 #if !(defined(alpha) || defined(__x86_64))
99 long header[CORE_PAGESIZE / sizeof(long)], val, len, *ptr;
101 u32 header[CORE_PAGESIZE / sizeof(u32)], val, len, *ptr;
103 lispobj initial_function = NIL;
106 fprintf(stderr, "Could not open file \"%s\".\n", file);
111 count = read(fd, header, CORE_PAGESIZE);
116 if (count < CORE_PAGESIZE) {
117 fprintf(stderr, "Premature EOF.\n");
124 if (val != CORE_MAGIC) {
125 fprintf(stderr, "Invalid magic number: 0x%lx should have been 0x%x.\n",
130 while (val != CORE_END) {
139 if (*ptr != version) {
141 "WARNING: startup-code version (%d) different from core version (%ld).\nYou may lose big.\n",
145 *fpu_type = (fpu_mode_t) ptr[1];
152 fprintf(stderr, "Validation no longer supported; ignored.\n");
155 case CORE_NDIRECTORY:
156 process_directory(fd, ptr,
157 #if !(defined(alpha) || defined(__x86_64))
158 (len - 2) / (sizeof(struct ndir_entry) / sizeof(long)));
160 (len - 2) / (sizeof(struct ndir_entry) / sizeof(u32)));
164 case CORE_INITIAL_FUNCTION:
165 initial_function = (lispobj) * ptr;
168 case CORE_MACHINE_STATE:
169 fprintf(stderr, "Obsolete core file.\n");
174 printf("Unknown core file entry: %ld; skipping.\n", val);
181 return initial_function;