/[cmucl]/src/lisp/coreparse.c
ViewVC logotype

Contents of /src/lisp/coreparse.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations)
Tue Jan 20 03:58:11 2009 UTC (5 years, 3 months ago) by agoncharov
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, post-merge-intl-branch, merged-unicode-utf16-extfmt-2009-06-11, intl-branch-working-2010-02-19-1000, unicode-string-buffer-impl-base, release-20b-pre1, release-20b-pre2, unicode-string-buffer-base, sparc-tramp-assem-2010-07-19, amd64-dd-start, release-19f-pre1, intl-2-branch-base, GIT-CONVERSION, cross-sol-x86-merged, label-2009-03-16, release-19f-base, merge-with-19f, intl-branch-working-2010-02-11-1000, RELEASE_20b, RELEASE_19f, release-20a-base, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, pre-merge-intl-branch, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-01, snapshot-2010-03, snapshot-2010-02, snapshot-2010-08, label-2009-03-25, cross-sol-x86-2010-12-20, intl-branch-2010-03-18-1300, RELEASE_20a, release-20a-pre1, snapshot-2009-11, snapshot-2009-12, portable-clx-import-2009-06-16, cross-sparc-branch-base, intl-branch-base, portable-clx-base, snapshot-2009-08, snapshot-2009-02, snapshot-2009-07, snapshot-2009-05, snapshot-2009-04, HEAD
Branch point for: RELEASE-19F-BRANCH, portable-clx-branch, cross-sparc-branch, RELEASE-20B-BRANCH, unicode-string-buffer-branch, sparc-tramp-assem-branch, RELEASE-20A-BRANCH, amd64-dd-branch, unicode-string-buffer-impl-branch, intl-branch, cross-sol-x86-branch, intl-2-branch
Changes since 1.13: +2 -2 lines
File MIME type: text/plain
Use 'const char *' instead of 'char *' where appropriate
1 /* $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/coreparse.c,v 1.14 2009/01/20 03:58:11 agoncharov Rel $ */
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/file.h>
5
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9
10 #include "os.h"
11 #include "lisp.h"
12 #include "globals.h"
13 #include "core.h"
14 #include "internals.h"
15
16 extern int version;
17
18 static void
19 process_directory(int fd, long *ptr, int count)
20 {
21 long id, offset, len;
22 lispobj *free_pointer;
23 os_vm_address_t addr;
24 struct ndir_entry *entry;
25
26 entry = (struct ndir_entry *) ptr;
27
28 while (count-- > 0) {
29 id = entry->identifier;
30 offset = CORE_PAGESIZE * (1 + entry->data_page);
31 addr = (os_vm_address_t) (CORE_PAGESIZE * entry->address);
32 free_pointer = (lispobj *) addr + entry->nwords;
33 len = CORE_PAGESIZE * entry->page_count;
34
35 if (len != 0) {
36 os_vm_address_t real_addr;
37
38 #ifdef PRINTNOISE
39 printf("Mapping %ld bytes at 0x%lx.\n", len, addr);
40 #endif
41 real_addr = os_map(fd, offset, addr, len);
42 if (real_addr != addr)
43 fprintf(stderr,
44 "process_directory: file mapped in wrong place! (0x%p != 0x%p)\n",
45 (void *) real_addr, (void *) addr);
46 }
47 #if 0
48 printf("Space ID = %d, free pointer = 0x%08x.\n", id, free_pointer);
49 #endif
50
51 switch (id) {
52 case DYNAMIC_SPACE_ID:
53 if (addr != (os_vm_address_t) dynamic_0_space
54 && addr != (os_vm_address_t) dynamic_1_space)
55 printf("Strange ... dynamic space lossage.\n");
56 current_dynamic_space = (lispobj *) addr;
57 #if defined(ibmrt) || defined(i386) || defined(__x86_64)
58 SetSymbolValue(ALLOCATION_POINTER, (lispobj) free_pointer);
59 #else
60 current_dynamic_space_free_pointer = free_pointer;
61 #endif
62 break;
63 case STATIC_SPACE_ID:
64 static_space = (lispobj *) addr;
65 break;
66 case READ_ONLY_SPACE_ID:
67 /* Don't care about read only space */
68 break;
69 default:
70 printf("Strange space ID: %ld; ignored.\n", id);
71 break;
72 }
73 entry++;
74 }
75 }
76
77 lispobj
78 load_core_file(const char *file, fpu_mode_t* fpu_type)
79 {
80 int fd = open(file, O_RDONLY), count;
81
82 #if !(defined(alpha) || defined(__x86_64))
83 long header[CORE_PAGESIZE / sizeof(long)], val, len, *ptr;
84 #else
85 u32 header[CORE_PAGESIZE / sizeof(u32)], val, len, *ptr;
86 #endif
87 lispobj initial_function = NIL;
88
89 if (fd < 0) {
90 fprintf(stderr, "Could not open file \"%s\".\n", file);
91 perror("open");
92 exit(1);
93 }
94
95 count = read(fd, header, CORE_PAGESIZE);
96 if (count < 0) {
97 perror("read");
98 exit(1);
99 }
100 if (count < CORE_PAGESIZE) {
101 fprintf(stderr, "Premature EOF.\n");
102 exit(1);
103 }
104
105 ptr = header;
106 val = *ptr++;
107
108 if (val != CORE_MAGIC) {
109 fprintf(stderr, "Invalid magic number: 0x%lx should have been 0x%x.\n",
110 val, CORE_MAGIC);
111 exit(1);
112 }
113
114 while (val != CORE_END) {
115 val = *ptr++;
116 len = *ptr++;
117
118 switch (val) {
119 case CORE_END:
120 break;
121
122 case CORE_VERSION:
123 if (*ptr != version) {
124 fprintf(stderr,
125 "WARNING: startup-code version (%d) different from core version (%ld).\nYou may lose big.\n",
126 version, *ptr);
127 }
128 if (len == 4) {
129 *fpu_type = (fpu_mode_t) ptr[1];
130 } else {
131 *fpu_type = AUTO;
132 }
133 break;
134
135 case CORE_VALIDATE:
136 fprintf(stderr, "Validation no longer supported; ignored.\n");
137 break;
138
139 case CORE_NDIRECTORY:
140 process_directory(fd, ptr,
141 #if !(defined(alpha) || defined(__x86_64))
142 (len - 2) / (sizeof(struct ndir_entry) / sizeof(long)));
143 #else
144 (len - 2) / (sizeof(struct ndir_entry) / sizeof(u32)));
145 #endif
146 break;
147
148 case CORE_INITIAL_FUNCTION:
149 initial_function = (lispobj) * ptr;
150 break;
151
152 case CORE_MACHINE_STATE:
153 fprintf(stderr, "Obsolete core file.\n");
154 exit(1);
155 break;
156
157 default:
158 printf("Unknown core file entry: %ld; skipping.\n", val);
159 break;
160 }
161
162 ptr += len - 2;
163 }
164
165 return initial_function;
166 }

  ViewVC Help
Powered by ViewVC 1.1.5