Wed Oct 8 22:57:28 2008 UTC ()
Move functionality for preparing the kernel (including XMS support) into
a new function common_load_kernel.


(joerg)
diff -r1.31 -r1.32 src/sys/arch/i386/stand/lib/exec.c

cvs diff -r1.31 -r1.32 src/sys/arch/i386/stand/lib/exec.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/lib/exec.c 2008/10/08 22:46:19 1.31
+++ src/sys/arch/i386/stand/lib/exec.c 2008/10/08 22:57:28 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: exec.c,v 1.31 2008/10/08 22:46:19 joerg Exp $ */ 1/* $NetBSD: exec.c,v 1.32 2008/10/08 22:57:28 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -123,85 +123,72 @@ @@ -123,85 +123,72 @@
123extern struct btinfo_console btinfo_console; 123extern struct btinfo_console btinfo_console;
124 124
125boot_module_t *boot_modules; 125boot_module_t *boot_modules;
126bool boot_modules_enabled = true; 126bool boot_modules_enabled = true;
127bool kernel_loaded; 127bool kernel_loaded;
128 128
129static struct btinfo_modulelist *btinfo_modulelist; 129static struct btinfo_modulelist *btinfo_modulelist;
130static size_t btinfo_modulelist_size; 130static size_t btinfo_modulelist_size;
131static uint32_t image_end; 131static uint32_t image_end;
132static char module_base[64] = "/"; 132static char module_base[64] = "/";
133 133
134static void module_init(void); 134static void module_init(void);
135 135
136int 136static int
137exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy) 137common_load_kernel(const char *file, u_long *basemem, u_long *extmem,
 138 physaddr_t loadaddr, int floppy, u_long marks[MARK_MAX])
138{ 139{
139 u_long boot_argv[BOOT_NARGS]; 140 int fd;
140 int fd; 
141 u_long marks[MARK_MAX]; 
142 struct btinfo_symtab btinfo_symtab; 
143 u_long extmem; 
144 u_long basemem; 
145#ifdef XMS 141#ifdef XMS
146 u_long xmsmem; 142 u_long xmsmem;
147 physaddr_t origaddr = loadaddr; 143 physaddr_t origaddr = loadaddr;
148#endif 144#endif
149 145
150#ifdef DEBUG 146 *extmem = getextmem();
151 printf("exec: file=%s loadaddr=0x%lx\n", 147 *basemem = getbasemem();
152 file ? file : "NULL", loadaddr); 
153#endif 
154 
155 BI_ALLOC(32); /* ??? */ 
156 
157 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console)); 
158 
159 extmem = getextmem(); 
160 basemem = getbasemem(); 
161 148
162#ifdef XMS 149#ifdef XMS
163 if ((getextmem1() == 0) && (xmsmem = checkxms())) { 150 if ((getextmem1() == 0) && (xmsmem = checkxms())) {
164 u_long kernsize; 151 u_long kernsize;
165 152
166 /* 153 /*
167 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because 154 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
168 * getextmem() is getextmem1(). Without, the "smart" 155 * getextmem() is getextmem1(). Without, the "smart"
169 * methods could fail to report all memory as well. 156 * methods could fail to report all memory as well.
170 * xmsmem is a few kB less than the actual size, but 157 * xmsmem is a few kB less than the actual size, but
171 * better than nothing. 158 * better than nothing.
172 */ 159 */
173 if (xmsmem > extmem) 160 if (xmsmem > *extmem)
174 extmem = xmsmem; 161 *extmem = xmsmem;
175 /* 162 /*
176 * Get the size of the kernel 163 * Get the size of the kernel
177 */ 164 */
178 marks[MARK_START] = loadaddr; 165 marks[MARK_START] = loadaddr;
179 if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1) 166 if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
180 goto out; 167 return EIO;
181 close(fd); 168 close(fd);
182 169
183 kernsize = marks[MARK_END]; 170 kernsize = marks[MARK_END];
184 kernsize = (kernsize + 1023) / 1024; 171 kernsize = (kernsize + 1023) / 1024;
185 172
186 loadaddr = xmsalloc(kernsize); 173 loadaddr = xmsalloc(kernsize);
187 if (!loadaddr) 174 if (!loadaddr)
188 return ENOMEM; 175 return ENOMEM;
189 } 176 }
190#endif 177#endif
191 marks[MARK_START] = loadaddr; 178 marks[MARK_START] = loadaddr;
192 if ((fd = loadfile(file, marks, 179 if ((fd = loadfile(file, marks,
193 LOAD_KERNEL & ~(floppy ? LOAD_NOTE : 0))) == -1) 180 LOAD_KERNEL & ~(floppy ? LOAD_NOTE : 0))) == -1)
194 goto out; 181 return EIO;
195 182
196 close(fd); 183 close(fd);
197 184
198 /* 185 /*
199 * Gather some information for the kernel. Do this after the 186 * Gather some information for the kernel. Do this after the
200 * "point of no return" to avoid memory leaks. 187 * "point of no return" to avoid memory leaks.
201 * (but before DOS might be trashed in the XMS case) 188 * (but before DOS might be trashed in the XMS case)
202 */ 189 */
203#ifdef PASS_BIOSGEOM 190#ifdef PASS_BIOSGEOM
204 bi_getbiosgeom(); 191 bi_getbiosgeom();
205#endif 192#endif
206#ifdef PASS_MEMMAP 193#ifdef PASS_MEMMAP
207 bi_getmemmap(); 194 bi_getmemmap();
@@ -216,26 +203,50 @@ exec_netbsd(const char *file, physaddr_t @@ -216,26 +203,50 @@ exec_netbsd(const char *file, physaddr_t
216 */ 203 */
217 marks[MARK_START] -= loadaddr; 204 marks[MARK_START] -= loadaddr;
218 marks[MARK_END] -= loadaddr; 205 marks[MARK_END] -= loadaddr;
219 marks[MARK_SYM] -= loadaddr; 206 marks[MARK_SYM] -= loadaddr;
220 marks[MARK_END] -= loadaddr; 207 marks[MARK_END] -= loadaddr;
221 ppbcopy(loadaddr, origaddr, marks[MARK_END]); 208 ppbcopy(loadaddr, origaddr, marks[MARK_END]);
222 } 209 }
223#endif 210#endif
224 marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) & 211 marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
225 (-sizeof(int)); 212 (-sizeof(int));
226 image_end = marks[MARK_END]; 213 image_end = marks[MARK_END];
227 kernel_loaded = true; 214 kernel_loaded = true;
228 215
 216 return 0;
 217}
 218
 219int
 220exec_netbsd(const char *file, physaddr_t loadaddr, int boothowto, int floppy)
 221{
 222 u_long boot_argv[BOOT_NARGS];
 223 u_long marks[MARK_MAX];
 224 struct btinfo_symtab btinfo_symtab;
 225 u_long extmem;
 226 u_long basemem;
 227
 228#ifdef DEBUG
 229 printf("exec: file=%s loadaddr=0x%lx\n",
 230 file ? file : "NULL", loadaddr);
 231#endif
 232
 233 BI_ALLOC(32); /* ??? */
 234
 235 BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
 236
 237 if (common_load_kernel(file, &basemem, &extmem, loadaddr, floppy, marks))
 238 goto out;
 239
229 boot_argv[0] = boothowto; 240 boot_argv[0] = boothowto;
230 boot_argv[1] = 0; 241 boot_argv[1] = 0;
231 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */ 242 boot_argv[2] = vtophys(bootinfo); /* old cyl offset */
232 boot_argv[3] = marks[MARK_END]; 243 boot_argv[3] = marks[MARK_END];
233 boot_argv[4] = extmem; 244 boot_argv[4] = extmem;
234 boot_argv[5] = basemem; 245 boot_argv[5] = basemem;
235 246
236 /* pull in any modules if necessary */ 247 /* pull in any modules if necessary */
237 if (boot_modules_enabled) { 248 if (boot_modules_enabled) {
238 module_init(); 249 module_init();
239 if (btinfo_modulelist) { 250 if (btinfo_modulelist) {
240 BI_ADD(btinfo_modulelist, BTINFO_MODULELIST, 251 BI_ADD(btinfo_modulelist, BTINFO_MODULELIST,
241 btinfo_modulelist_size); 252 btinfo_modulelist_size);