Pull up following revision(s) (requested by nonaka in ticket #1309): sys/arch/i386/stand/lib/exec.c: revision 1.73 sys/arch/i386/stand/efiboot/efiboot.c: revision 1.10 sys/arch/i386/stand/lib/libi386.h: revision 1.44 sys/arch/i386/stand/efiboot/efimemory.c: revision 1.6 sys/arch/i386/stand/efiboot/efimemory.c: revision 1.7 sys/arch/i386/stand/efiboot/efimemory.c: revision 1.8 sys/arch/i386/stand/efiboot/efiboot.c: revision 1.9 sys/arch/i386/stand/efiboot/boot.c: revision 1.12 sys/arch/i386/stand/efiboot/boot.c: revision 1.13 sys/arch/i386/stand/efiboot/efiboot.h: revision 1.9 sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.15 sys/arch/i386/stand/efiboot/dev_net.c: revision 1.2 Added tftp support to x86 efiboot. Pre-allocate memory for the kernel space at startup. Added BTINFO_EFIMEMMAP compaction support to x86 efiboot. Sync the output of memmap command to the output of stand/efiboot mem command. Added missing efi_memory_probe() call.diff -r1.9.2.3 -r1.9.2.4 src/sys/arch/i386/stand/efiboot/Makefile.efiboot
(martin)
--- src/sys/arch/i386/stand/efiboot/Makefile.efiboot 2018/04/11 14:51:43 1.9.2.3
+++ src/sys/arch/i386/stand/efiboot/Makefile.efiboot 2019/08/01 13:22:48 1.9.2.4
@@ -1,76 +1,79 @@ | @@ -1,76 +1,79 @@ | |||
1 | # $NetBSD: Makefile.efiboot,v 1.9.2.3 2018/04/11 14:51:43 martin Exp $ | 1 | # $NetBSD: Makefile.efiboot,v 1.9.2.4 2019/08/01 13:22:48 martin Exp $ | |
2 | 2 | |||
3 | S= ${.CURDIR}/../../../../.. | 3 | S= ${.CURDIR}/../../../../.. | |
4 | 4 | |||
5 | NOMAN= # defined | 5 | NOMAN= # defined | |
6 | PROG?= boot.efi | 6 | PROG?= boot.efi | |
7 | NEWVERSWHAT?= "EFI Boot" | 7 | NEWVERSWHAT?= "EFI Boot" | |
8 | 8 | |||
9 | AFLAGS.start.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:} | 9 | AFLAGS.start.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:} | |
10 | 10 | |||
11 | SOURCES= start.S boot.c conf.c devopen.c dev_net.c self_reloc.c panic.c | 11 | SOURCES= start.S boot.c conf.c devopen.c dev_net.c self_reloc.c panic.c | |
12 | SOURCES+= efiboot.c efichar.c eficons.c efidelay.c efidev.c | 12 | SOURCES+= efiboot.c efichar.c eficons.c efidelay.c efidev.c | |
13 | SOURCES+= efidisk.c efidisk_ll.c efigetsecs.c efimemory.c | 13 | SOURCES+= efidisk.c efidisk_ll.c efigetsecs.c efimemory.c | |
14 | SOURCES+= efinet.c efipxe.c | 14 | SOURCES+= efinet.c efipxe.c | |
15 | LIBI386SRCS= biosdisk.c bootinfo.c bootinfo_biosgeom.c bootmenu.c | 15 | LIBI386SRCS= biosdisk.c bootinfo.c bootinfo_biosgeom.c bootmenu.c | |
16 | LIBI386SRCS+= diskbuf.c exec.c menuutils.c parseutils.c pread.c | 16 | LIBI386SRCS+= diskbuf.c exec.c menuutils.c parseutils.c pread.c | |
17 | SRCS= ${SOURCES} ${EXTRA_SOURCES} ${LIBI386SRCS} | 17 | # use our own nfs implementation | |
18 | LIBSASRCS+= nfs.c | |||
19 | SRCS= ${SOURCES} ${EXTRA_SOURCES} ${LIBI386SRCS} ${LIBSASRCS} | |||
18 | 20 | |||
19 | PIE_CFLAGS= | 21 | PIE_CFLAGS= | |
20 | PIE_LDFLAGS= | 22 | PIE_LDFLAGS= | |
21 | PIE_AFLAGS= | 23 | PIE_AFLAGS= | |
22 | 24 | |||
23 | .include <bsd.own.mk> | 25 | .include <bsd.own.mk> | |
24 | 26 | |||
25 | STRIPFLAG= # nothing | 27 | STRIPFLAG= # nothing | |
26 | 28 | |||
27 | LIBCRT0= # nothing | 29 | LIBCRT0= # nothing | |
28 | LIBCRTI= # nothing | 30 | LIBCRTI= # nothing | |
29 | LIBCRTBEGIN= # nothing | 31 | LIBCRTBEGIN= # nothing | |
30 | LIBCRTEND= # nothing | 32 | LIBCRTEND= # nothing | |
31 | LIBC= # nothing | 33 | LIBC= # nothing | |
32 | 34 | |||
33 | BINDIR=/usr/mdec | 35 | BINDIR=/usr/mdec | |
34 | BINMODE=444 | 36 | BINMODE=444 | |
35 | 37 | |||
36 | .PATH: ${.CURDIR} ${.CURDIR}/.. | 38 | .PATH: ${.CURDIR} ${.CURDIR}/.. | |
37 | .PATH: ${.CURDIR}/../../lib | 39 | .PATH: ${.CURDIR}/../../lib | |
40 | .PATH: ${.CURDIR}/../../libsa | |||
38 | 41 | |||
39 | LDSCRIPT?= ${.CURDIR}/ldscript | 42 | LDSCRIPT?= ${.CURDIR}/ldscript | |
40 | LDFLAGS+= -nostdlib -T${LDSCRIPT} -Bsymbolic -shared -nocombreloc | 43 | LDFLAGS+= -nostdlib -T${LDSCRIPT} -Bsymbolic -shared -nocombreloc | |
41 | CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/.. -I$S/lib/libsa | 44 | CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/.. -I$S/lib/libsa | |
42 | CPPFLAGS+= -I${.OBJDIR} | 45 | CPPFLAGS+= -I${.OBJDIR} | |
43 | CPPFLAGS+= -I${.CURDIR}/../../lib | 46 | CPPFLAGS+= -I${.CURDIR}/../../lib | |
44 | 47 | |||
45 | COPTS+= -ffreestanding -fPIC -fshort-wchar -fno-strict-aliasing -fno-builtin | 48 | COPTS+= -ffreestanding -fPIC -fshort-wchar -fno-strict-aliasing -fno-builtin | |
46 | COPTS+= -fno-stack-protector | 49 | COPTS+= -fno-stack-protector | |
47 | COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :} | 50 | COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :} | |
48 | CPPFLAGS+= -nostdinc -D_STANDALONE | 51 | CPPFLAGS+= -nostdinc -D_STANDALONE | |
49 | CPPFLAGS+= -DEFIBOOT | 52 | CPPFLAGS+= -DEFIBOOT | |
50 | 53 | |||
51 | CPPFLAGS+= -Wall -Wmissing-prototypes | 54 | CPPFLAGS+= -Wall -Wmissing-prototypes | |
52 | CPPFLAGS+= -Wno-pointer-sign | 55 | CPPFLAGS+= -Wno-pointer-sign | |
53 | 56 | |||
54 | CPPFLAGS+= -DEFI_ALLOCATE_MAX_ADDRESS=0x100000000ULL | 57 | CPPFLAGS+= -DEFI_ALLOCATE_MAX_ADDRESS=0x100000000ULL | |
55 | CPPFLAGS+= -DHEAP_VARIABLE | 58 | CPPFLAGS+= -DHEAP_VARIABLE | |
56 | CPPFLAGS+= -DSUPPORT_CD9660 | 59 | CPPFLAGS+= -DSUPPORT_CD9660 | |
57 | CPPFLAGS+= -D"devb2cdb(bno)=(bno)" | 60 | CPPFLAGS+= -D"devb2cdb(bno)=(bno)" | |
58 | CPPFLAGS+= -DSUPPORT_DOSFS | 61 | CPPFLAGS+= -DSUPPORT_DOSFS | |
59 | CPPFLAGS+= -DSUPPORT_EXT2FS | 62 | CPPFLAGS+= -DSUPPORT_EXT2FS | |
60 | CPPFLAGS+= -DSUPPORT_BOOTP | 63 | CPPFLAGS+= -DSUPPORT_BOOTP | |
61 | CPPFLAGS+= -DSUPPORT_DHCP | 64 | CPPFLAGS+= -DSUPPORT_DHCP | |
62 | CPPFLAGS+= -DSUPPORT_NFS | 65 | CPPFLAGS+= -DSUPPORT_NFS | |
63 | #CPPFLAGS+= -DSUPPORT_TFTP | 66 | CPPFLAGS+= -DSUPPORT_TFTP | |
64 | CPPFLAGS+= -DPASS_BIOSGEOM | 67 | CPPFLAGS+= -DPASS_BIOSGEOM | |
65 | CPPFLAGS+= -DBIOSDISK_DEFAULT_SECSIZE=2048 # for bootinfo_biosgeom.c | 68 | CPPFLAGS+= -DBIOSDISK_DEFAULT_SECSIZE=2048 # for bootinfo_biosgeom.c | |
66 | CPPFLAGS+= -DLIBSA_ENABLE_LS_OP | 69 | CPPFLAGS+= -DLIBSA_ENABLE_LS_OP | |
67 | 70 | |||
68 | #CPPFLAGS+= -DARP_DEBUG | 71 | #CPPFLAGS+= -DARP_DEBUG | |
69 | #CPPFLAGS+= -DBOOTP_DEBUG | 72 | #CPPFLAGS+= -DBOOTP_DEBUG | |
70 | #CPPFLAGS+= -DNET_DEBUG | 73 | #CPPFLAGS+= -DNET_DEBUG | |
71 | #CPPFLAGS+= -DNETIF_DEBUG | 74 | #CPPFLAGS+= -DNETIF_DEBUG | |
72 | #CPPFLAGS+= -DNFS_DEBUG | 75 | #CPPFLAGS+= -DNFS_DEBUG | |
73 | #CPPFLAGS+= -DRARP_DEBUG | 76 | #CPPFLAGS+= -DRARP_DEBUG | |
74 | #CPPFLAGS+= -DRPC_DEBUG | 77 | #CPPFLAGS+= -DRPC_DEBUG | |
75 | 78 | |||
76 | EFIDIR= ${S}/external/bsd/gnu-efi/dist | 79 | EFIDIR= ${S}/external/bsd/gnu-efi/dist |
--- src/sys/arch/i386/stand/efiboot/boot.c 2018/04/11 14:51:43 1.5.2.5
+++ src/sys/arch/i386/stand/efiboot/boot.c 2019/08/01 13:22:48 1.5.2.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: boot.c,v 1.5.2.5 2018/04/11 14:51:43 martin Exp $ */ | 1 | /* $NetBSD: boot.c,v 1.5.2.6 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | 4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | |
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. | |
@@ -214,60 +214,36 @@ sprint_bootsel(const char *filename) | @@ -214,60 +214,36 @@ sprint_bootsel(const char *filename) | |||
214 | } | 214 | } | |
215 | 215 | |||
216 | void | 216 | void | |
217 | clearit(void) | 217 | clearit(void) | |
218 | { | 218 | { | |
219 | 219 | |||
220 | if (bootcfg_info.clear) | 220 | if (bootcfg_info.clear) | |
221 | clear_pc_screen(); | 221 | clear_pc_screen(); | |
222 | } | 222 | } | |
223 | 223 | |||
224 | static void | 224 | static void | |
225 | bootit(const char *filename, int howto) | 225 | bootit(const char *filename, int howto) | |
226 | { | 226 | { | |
227 | EFI_STATUS status; | |||
228 | EFI_PHYSICAL_ADDRESS bouncebuf; | |||
229 | UINTN npages; | |||
230 | u_long allocsz; | |||
231 | 227 | |||
232 | if (howto & AB_VERBOSE) | 228 | if (howto & AB_VERBOSE) | |
233 | printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename), | 229 | printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename), | |
234 | howto); | 230 | howto); | |
235 | 231 | |||
236 | if (count_netbsd(filename, &allocsz) < 0) { | 232 | if (exec_netbsd(filename, efi_loadaddr, howto, 0, efi_cleanup) < 0) | |
237 | printf("boot: %s: %s\n", sprint_bootsel(filename), | |||
238 | strerror(errno)); | |||
239 | return; | |||
240 | } | |||
241 | ||||
242 | bouncebuf = EFI_ALLOCATE_MAX_ADDRESS; | |||
243 | npages = EFI_SIZE_TO_PAGES(allocsz); | |||
244 | status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, | |||
245 | EfiLoaderData, npages, &bouncebuf); | |||
246 | if (EFI_ERROR(status)) { | |||
247 | printf("boot: %s: %s\n", sprint_bootsel(filename), | |||
248 | strerror(ENOMEM)); | |||
249 | return; | |||
250 | } | |||
251 | ||||
252 | efi_loadaddr = bouncebuf; | |||
253 | if (exec_netbsd(filename, bouncebuf, howto, 0, efi_cleanup) < 0) | |||
254 | printf("boot: %s: %s\n", sprint_bootsel(filename), | 233 | printf("boot: %s: %s\n", sprint_bootsel(filename), | |
255 | strerror(errno)); | 234 | strerror(errno)); | |
256 | else | 235 | else | |
257 | printf("boot returned\n"); | 236 | printf("boot returned\n"); | |
258 | ||||
259 | (void) uefi_call_wrapper(BS->FreePages, 2, bouncebuf, npages); | |||
260 | efi_loadaddr = 0; | |||
261 | } | 237 | } | |
262 | 238 | |||
263 | void | 239 | void | |
264 | print_banner(void) | 240 | print_banner(void) | |
265 | { | 241 | { | |
266 | int n; | 242 | int n; | |
267 | 243 | |||
268 | clearit(); | 244 | clearit(); | |
269 | if (bootcfg_info.banner[0]) { | 245 | if (bootcfg_info.banner[0]) { | |
270 | for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n]; | 246 | for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n]; | |
271 | n++) | 247 | n++) | |
272 | printf("%s\n", bootcfg_info.banner[n]); | 248 | printf("%s\n", bootcfg_info.banner[n]); | |
273 | } else | 249 | } else | |
@@ -362,27 +338,27 @@ command_help(char *arg) | @@ -362,27 +338,27 @@ command_help(char *arg) | |||
362 | 338 | |||
363 | printf("commands are:\n" | 339 | printf("commands are:\n" | |
364 | "boot [xdNx:][filename] [-12acdqsvxz]\n" | 340 | "boot [xdNx:][filename] [-12acdqsvxz]\n" | |
365 | " (ex. \"hd0a:netbsd.old -s\"\n" | 341 | " (ex. \"hd0a:netbsd.old -s\"\n" | |
366 | "dev [xd[N[x]]:]\n" | 342 | "dev [xd[N[x]]:]\n" | |
367 | "consdev {pc|com[0123][,{speed}]|com,{ioport}[,{speed}]}\n" | 343 | "consdev {pc|com[0123][,{speed}]|com,{ioport}[,{speed}]}\n" | |
368 | "devpath\n" | 344 | "devpath\n" | |
369 | "efivar\n" | 345 | "efivar\n" | |
370 | "gop [{modenum|list}]\n" | 346 | "gop [{modenum|list}]\n" | |
371 | "load {path_to_module}\n" | 347 | "load {path_to_module}\n" | |
372 | #if LIBSA_ENABLE_LS_OP | 348 | #if LIBSA_ENABLE_LS_OP | |
373 | "ls [path]\n" | 349 | "ls [path]\n" | |
374 | #endif | 350 | #endif | |
375 | "memmap [{sorted|unsorted}]\n" | 351 | "memmap [{sorted|unsorted|compact}]\n" | |
376 | #ifndef SMALL | 352 | #ifndef SMALL | |
377 | "menu (reenters boot menu, if defined in boot.cfg)\n" | 353 | "menu (reenters boot menu, if defined in boot.cfg)\n" | |
378 | #endif | 354 | #endif | |
379 | "modules {on|off|enabled|disabled}\n" | 355 | "modules {on|off|enabled|disabled}\n" | |
380 | "multiboot [xdNx:][filename] [<args>]\n" | 356 | "multiboot [xdNx:][filename] [<args>]\n" | |
381 | "rndseed {path_to_rndseed_file}\n" | 357 | "rndseed {path_to_rndseed_file}\n" | |
382 | "splash {path_to_image_file}\n" | 358 | "splash {path_to_image_file}\n" | |
383 | "text [{modenum|list}]\n" | 359 | "text [{modenum|list}]\n" | |
384 | "userconf {command}\n" | 360 | "userconf {command}\n" | |
385 | "version\n" | 361 | "version\n" | |
386 | "help|?\n" | 362 | "help|?\n" | |
387 | "quit\n"); | 363 | "quit\n"); | |
388 | } | 364 | } | |
@@ -615,38 +591,41 @@ command_version(char *arg) | @@ -615,38 +591,41 @@ command_version(char *arg) | |||
615 | } | 591 | } | |
616 | 592 | |||
617 | printf("\n" | 593 | printf("\n" | |
618 | ">> %s, Revision %s (from NetBSD %s)\n" | 594 | ">> %s, Revision %s (from NetBSD %s)\n" | |
619 | ">> Memory: %d/%d k\n", | 595 | ">> Memory: %d/%d k\n", | |
620 | bootprog_name, bootprog_rev, bootprog_kernrev, | 596 | bootprog_name, bootprog_rev, bootprog_kernrev, | |
621 | getbasemem(), getextmem()); | 597 | getbasemem(), getextmem()); | |
622 | } | 598 | } | |
623 | 599 | |||
624 | void | 600 | void | |
625 | command_memmap(char *arg) | 601 | command_memmap(char *arg) | |
626 | { | 602 | { | |
627 | bool sorted = true; | 603 | bool sorted = true; | |
604 | bool compact = false; | |||
628 | 605 | |||
629 | if (*arg == '\0' || strcmp(arg, "sorted") == 0) | 606 | if (*arg == '\0' || strcmp(arg, "sorted") == 0) | |
630 | /* Already sorted is true. */; | 607 | /* Already sorted is true. */; | |
631 | else if (strcmp(arg, "unsorted") == 0) | 608 | else if (strcmp(arg, "unsorted") == 0) | |
632 | sorted = false; | 609 | sorted = false; | |
610 | else if (strcmp(arg, "compact") == 0) | |||
611 | compact = true; | |||
633 | else { | 612 | else { | |
634 | printf("invalid flag, " | 613 | printf("invalid flag, " | |
635 | "must be 'sorted' or 'unsorted'.\n"); | 614 | "must be 'sorted', 'unsorted' or 'compact'.\n"); | |
636 | return; | 615 | return; | |
637 | } | 616 | } | |
638 | 617 | |||
639 | efi_memory_show_map(sorted); | 618 | efi_memory_show_map(sorted, compact); | |
640 | } | 619 | } | |
641 | 620 | |||
642 | void | 621 | void | |
643 | command_devpath(char *arg) | 622 | command_devpath(char *arg) | |
644 | { | 623 | { | |
645 | EFI_STATUS status; | 624 | EFI_STATUS status; | |
646 | UINTN i, nhandles; | 625 | UINTN i, nhandles; | |
647 | EFI_HANDLE *handles; | 626 | EFI_HANDLE *handles; | |
648 | EFI_DEVICE_PATH *dp0, *dp; | 627 | EFI_DEVICE_PATH *dp0, *dp; | |
649 | CHAR16 *path; | 628 | CHAR16 *path; | |
650 | char *upath; | 629 | char *upath; | |
651 | UINTN cols, rows, row = 0; | 630 | UINTN cols, rows, row = 0; | |
652 | int rv; | 631 | int rv; |
--- src/sys/arch/i386/stand/efiboot/dev_net.c 2018/04/11 14:51:43 1.1.2.2
+++ src/sys/arch/i386/stand/efiboot/dev_net.c 2019/08/01 13:22:48 1.1.2.3
@@ -1,3 +1,256 @@ | @@ -1,3 +1,256 @@ | |||
1 | /* $NetBSD: dev_net.c,v 1.1.2.2 2018/04/11 14:51:43 martin Exp $ */ | 1 | /* $NetBSD: dev_net.c,v 1.1.2.3 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | #include <lib/libsa/dev_net.c> | 3 | /*- | |
4 | * Copyright (c) 1997 The NetBSD Foundation, Inc. | |||
5 | * All rights reserved. | |||
6 | * | |||
7 | * This code is derived from software contributed to The NetBSD Foundation | |||
8 | * by Gordon W. Ross. | |||
9 | * | |||
10 | * Redistribution and use in source and binary forms, with or without | |||
11 | * modification, are permitted provided that the following conditions | |||
12 | * are met: | |||
13 | * 1. Redistributions of source code must retain the above copyright | |||
14 | * notice, this list of conditions and the following disclaimer. | |||
15 | * 2. Redistributions in binary form must reproduce the above copyright | |||
16 | * notice, this list of conditions and the following disclaimer in the | |||
17 | * documentation and/or other materials provided with the distribution. | |||
18 | * | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |||
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |||
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |||
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |||
29 | * POSSIBILITY OF SUCH DAMAGE. | |||
30 | */ | |||
31 | ||||
32 | /* | |||
33 | * This module implements a "raw device" interface suitable for | |||
34 | * use by the stand-alone I/O library NFS code. This interface | |||
35 | * does not support any "block" access, and exists only for the | |||
36 | * purpose of initializing the network interface, getting boot | |||
37 | * parameters, and performing the NFS mount. | |||
38 | * | |||
39 | * At open time, this does: | |||
40 | * | |||
41 | * find interface - netif_open() | |||
42 | * RARP for IP address - rarp_getipaddress() | |||
43 | * RPC/bootparams - callrpc(d, RPC_BOOTPARAMS, ...) | |||
44 | * RPC/mountd - nfs_mount(sock, ip, path) | |||
45 | */ | |||
46 | ||||
47 | #include <sys/param.h> | |||
48 | #include <sys/socket.h> | |||
49 | #include <net/if.h> | |||
50 | #include <netinet/in.h> | |||
51 | #include <netinet/in_systm.h> | |||
52 | ||||
53 | #include <lib/libkern/libkern.h> | |||
54 | ||||
55 | #include "stand.h" | |||
56 | #include "net.h" | |||
57 | #include "netif.h" | |||
58 | #include "nfs.h" | |||
59 | #include "bootparam.h" | |||
60 | #include "dev_net.h" | |||
61 | #ifdef SUPPORT_BOOTP | |||
62 | #include "bootp.h" | |||
63 | #endif | |||
64 | ||||
65 | static int netdev_sock = -1; | |||
66 | static int netdev_opens; | |||
67 | ||||
68 | static int net_getparams(int); | |||
69 | ||||
70 | /* | |||
71 | * Called by devopen after it sets f->f_dev to our devsw entry. | |||
72 | * This opens the low-level device and sets f->f_devdata. | |||
73 | * This is declared with variable arguments... | |||
74 | */ | |||
75 | int | |||
76 | net_open(struct open_file *f, ...) | |||
77 | { | |||
78 | va_list ap; | |||
79 | char *devname; /* Device part of file name (or NULL). */ | |||
80 | int error = 0; | |||
81 | ||||
82 | va_start(ap, f); | |||
83 | devname = va_arg(ap, char *); | |||
84 | va_end(ap); | |||
85 | ||||
86 | #ifdef NETIF_DEBUG | |||
87 | if (debug) | |||
88 | printf("%s\n", devname); | |||
89 | #endif | |||
90 | ||||
91 | /* On first open, do netif open, mount, etc. */ | |||
92 | if (netdev_opens == 0) { | |||
93 | /* Find network interface. */ | |||
94 | if (netdev_sock < 0) { | |||
95 | netdev_sock = netif_open(devname); | |||
96 | if (netdev_sock < 0) { | |||
97 | printf("netif_open() failed\n"); | |||
98 | return ENXIO; | |||
99 | } | |||
100 | #ifdef NETIF_DEBUG | |||
101 | if (debug) | |||
102 | printf("netif_open() succeeded\n"); | |||
103 | #endif | |||
104 | } | |||
105 | if (rootip.s_addr == 0) { | |||
106 | /* Get root IP address, and path, etc. */ | |||
107 | error = net_getparams(netdev_sock); | |||
108 | if (error) { | |||
109 | /* getparams makes its own noise */ | |||
110 | netif_close(netdev_sock); | |||
111 | netdev_sock = -1; | |||
112 | return error; | |||
113 | } | |||
114 | } | |||
115 | } | |||
116 | netdev_opens++; | |||
117 | f->f_devdata = &netdev_sock; | |||
118 | return error; | |||
119 | } | |||
120 | ||||
121 | int | |||
122 | net_close(struct open_file *f) | |||
123 | { | |||
124 | ||||
125 | #ifdef NETIF_DEBUG | |||
126 | if (debug) | |||
127 | printf("net_close: opens=%d\n", netdev_opens); | |||
128 | #endif | |||
129 | ||||
130 | /* On last close, do netif close, etc. */ | |||
131 | f->f_devdata = NULL; | |||
132 | /* Extra close call? */ | |||
133 | if (netdev_opens <= 0) | |||
134 | return 0; | |||
135 | netdev_opens--; | |||
136 | /* Not last close? */ | |||
137 | if (netdev_opens > 0) | |||
138 | return 0; | |||
139 | rootip.s_addr = 0; | |||
140 | if (netdev_sock >= 0) { | |||
141 | #ifdef NETIF_DEBUG | |||
142 | if (debug) | |||
143 | printf("%s: calling netif_close()\n", __func__); | |||
144 | #endif | |||
145 | netif_close(netdev_sock); | |||
146 | netdev_sock = -1; | |||
147 | } | |||
148 | return 0; | |||
149 | } | |||
150 | ||||
151 | int | |||
152 | net_ioctl(struct open_file *f, u_long cmd, void *data) | |||
153 | { | |||
154 | ||||
155 | return EIO; | |||
156 | } | |||
157 | ||||
158 | int | |||
159 | net_strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf, | |||
160 | size_t *rsize) | |||
161 | { | |||
162 | ||||
163 | return EIO; | |||
164 | } | |||
165 | ||||
166 | ||||
167 | #ifdef SUPPORT_BOOTP | |||
168 | int try_bootp; | |||
169 | #endif | |||
170 | ||||
171 | static int | |||
172 | net_getparams(int sock) | |||
173 | { | |||
174 | char buf[MAXHOSTNAMELEN]; | |||
175 | n_long smask; | |||
176 | ||||
177 | #ifdef SUPPORT_BOOTP | |||
178 | /* | |||
179 | * Try to get boot info using BOOTP. If we succeed, then | |||
180 | * the server IP address, gateway, and root path will all | |||
181 | * be initialized. If any remain uninitialized, we will | |||
182 | * use RARP and RPC/bootparam (the Sun way) to get them. | |||
183 | */ | |||
184 | if (try_bootp) | |||
185 | bootp(sock); | |||
186 | if (myip.s_addr != 0) | |||
187 | return 0; | |||
188 | #ifdef NETIF_DEBUG | |||
189 | if (debug) | |||
190 | printf("BOOTP failed, trying RARP/RPC...\n"); | |||
191 | #endif | |||
192 | #endif | |||
193 | ||||
194 | /* | |||
195 | * Use RARP to get our IP address. This also sets our | |||
196 | * netmask to the "natural" default for our address. | |||
197 | */ | |||
198 | if (rarp_getipaddress(sock)) { | |||
199 | printf("RARP failed\n"); | |||
200 | return EIO; | |||
201 | } | |||
202 | #ifdef NETIF_DEBUG | |||
203 | if (debug) | |||
204 | printf("client addr: %s\n", inet_ntoa(myip)); | |||
205 | #endif | |||
206 | ||||
207 | /* Get our hostname, server IP address, gateway. */ | |||
208 | if (bp_whoami(sock)) { | |||
209 | printf("bootparam/whoami RPC failed\n"); | |||
210 | return EIO; | |||
211 | } | |||
212 | #ifdef NETIF_DEBUG | |||
213 | if (debug) | |||
214 | printf("client name: %s\n", hostname); | |||
215 | #endif | |||
216 | ||||
217 | /* | |||
218 | * Ignore the gateway from whoami (unreliable). | |||
219 | * Use the "gateway" parameter instead. | |||
220 | */ | |||
221 | smask = 0; | |||
222 | gateip.s_addr = 0; | |||
223 | if (bp_getfile(sock, "gateway", &gateip, buf)) { | |||
224 | printf("%s: gateway bootparam missing\n", __func__); | |||
225 | } else { | |||
226 | /* Got it! Parse the netmask. */ | |||
227 | smask = inet_addr(buf); | |||
228 | } | |||
229 | if (smask) { | |||
230 | netmask = smask; | |||
231 | #ifdef NETIF_DEBUG | |||
232 | if (debug) | |||
233 | printf("subnet mask: %s\n", intoa(netmask)); | |||
234 | #endif | |||
235 | } | |||
236 | #ifdef NETIF_DEBUG | |||
237 | if (debug) | |||
238 | if (gateip.s_addr) | |||
239 | printf("net gateway: %s\n", inet_ntoa(gateip)); | |||
240 | #endif | |||
241 | ||||
242 | /* Get the root server and pathname. */ | |||
243 | if (bp_getfile(sock, "root", &rootip, rootpath)) { | |||
244 | printf("bootparam/getfile RPC failed\n"); | |||
245 | return EIO; | |||
246 | } | |||
247 | ||||
248 | #ifdef NETIF_DEBUG | |||
249 | if (debug) { | |||
250 | printf("server addr: %s\n", inet_ntoa(rootip)); | |||
251 | printf("server path: %s\n", rootpath); | |||
252 | } | |||
253 | #endif | |||
254 | ||||
255 | return 0; | |||
256 | } |
--- src/sys/arch/i386/stand/efiboot/efiboot.c 2018/04/11 14:51:43 1.4.10.3
+++ src/sys/arch/i386/stand/efiboot/efiboot.c 2019/08/01 13:22:48 1.4.10.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: efiboot.c,v 1.4.10.3 2018/04/11 14:51:43 martin Exp $ */ | 1 | /* $NetBSD: efiboot.c,v 1.4.10.4 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | 4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | |
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. | |
@@ -79,26 +79,27 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS | @@ -79,26 +79,27 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS | |||
79 | for (dp = dp0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) { | 79 | for (dp = dp0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) { | |
80 | if (DevicePathType(dp) == MEDIA_DEVICE_PATH && | 80 | if (DevicePathType(dp) == MEDIA_DEVICE_PATH && | |
81 | DevicePathSubType(dp) == MEDIA_CDROM_DP) { | 81 | DevicePathSubType(dp) == MEDIA_CDROM_DP) { | |
82 | efi_bootdp_type = BOOT_DEVICE_TYPE_CD; | 82 | efi_bootdp_type = BOOT_DEVICE_TYPE_CD; | |
83 | break; | 83 | break; | |
84 | } | 84 | } | |
85 | if (DevicePathType(dp) == MESSAGING_DEVICE_PATH && | 85 | if (DevicePathType(dp) == MESSAGING_DEVICE_PATH && | |
86 | DevicePathSubType(dp) == MSG_MAC_ADDR_DP) { | 86 | DevicePathSubType(dp) == MSG_MAC_ADDR_DP) { | |
87 | efi_bootdp_type = BOOT_DEVICE_TYPE_NET; | 87 | efi_bootdp_type = BOOT_DEVICE_TYPE_NET; | |
88 | break; | 88 | break; | |
89 | } | 89 | } | |
90 | } | 90 | } | |
91 | 91 | |||
92 | efi_memory_probe(); | |||
92 | efi_disk_probe(); | 93 | efi_disk_probe(); | |
93 | efi_pxe_probe(); | 94 | efi_pxe_probe(); | |
94 | efi_net_probe(); | 95 | efi_net_probe(); | |
95 | 96 | |||
96 | status = uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0, 0, NULL); | 97 | status = uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0, 0, NULL); | |
97 | if (EFI_ERROR(status)) | 98 | if (EFI_ERROR(status)) | |
98 | panic("SetWatchdogTimer: %" PRIxMAX, (uintmax_t)status); | 99 | panic("SetWatchdogTimer: %" PRIxMAX, (uintmax_t)status); | |
99 | 100 | |||
100 | boot(); | 101 | boot(); | |
101 | 102 | |||
102 | return EFI_SUCCESS; | 103 | return EFI_SUCCESS; | |
103 | } | 104 | } | |
104 | 105 | |||
@@ -125,26 +126,27 @@ efi_cleanup(void) | @@ -125,26 +126,27 @@ efi_cleanup(void) | |||
125 | desc = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | 126 | desc = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | |
126 | &DescriptorVersion, true); | 127 | &DescriptorVersion, true); | |
127 | status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, MapKey); | 128 | status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, MapKey); | |
128 | if (EFI_ERROR(status)) { | 129 | if (EFI_ERROR(status)) { | |
129 | FreePool(desc); | 130 | FreePool(desc); | |
130 | desc = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | 131 | desc = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | |
131 | &DescriptorVersion, true); | 132 | &DescriptorVersion, true); | |
132 | status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, MapKey); | 133 | status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, MapKey); | |
133 | if (EFI_ERROR(status)) | 134 | if (EFI_ERROR(status)) | |
134 | panic("ExitBootServices failed"); | 135 | panic("ExitBootServices failed"); | |
135 | } | 136 | } | |
136 | efi_cleanuped = true; | 137 | efi_cleanuped = true; | |
137 | 138 | |||
139 | efi_memory_compact_map(desc, &NoEntries, DescriptorSize); | |||
138 | allocsz = sizeof(struct btinfo_efimemmap) - 1 | 140 | allocsz = sizeof(struct btinfo_efimemmap) - 1 | |
139 | + NoEntries * DescriptorSize; | 141 | + NoEntries * DescriptorSize; | |
140 | bim = alloc(allocsz); | 142 | bim = alloc(allocsz); | |
141 | bim->num = NoEntries; | 143 | bim->num = NoEntries; | |
142 | bim->version = DescriptorVersion; | 144 | bim->version = DescriptorVersion; | |
143 | bim->size = DescriptorSize; | 145 | bim->size = DescriptorSize; | |
144 | memcpy(bim->memmap, desc, NoEntries * DescriptorSize); | 146 | memcpy(bim->memmap, desc, NoEntries * DescriptorSize); | |
145 | BI_ADD(bim, BTINFO_EFIMEMMAP, allocsz); | 147 | BI_ADD(bim, BTINFO_EFIMEMMAP, allocsz); | |
146 | } | 148 | } | |
147 | 149 | |||
148 | static void | 150 | static void | |
149 | efi_heap_init(void) | 151 | efi_heap_init(void) | |
150 | { | 152 | { |
--- src/sys/arch/i386/stand/efiboot/efiboot.h 2018/04/11 14:51:43 1.5.2.3
+++ src/sys/arch/i386/stand/efiboot/efiboot.h 2019/08/01 13:22:48 1.5.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: efiboot.h,v 1.5.2.3 2018/04/11 14:51:43 martin Exp $ */ | 1 | /* $NetBSD: efiboot.h,v 1.5.2.4 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | 4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | |
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. | |
@@ -70,29 +70,31 @@ void efi_cons_show(void); | @@ -70,29 +70,31 @@ void efi_cons_show(void); | |||
70 | void command_text(char *); | 70 | void command_text(char *); | |
71 | void command_gop(char *); | 71 | void command_gop(char *); | |
72 | 72 | |||
73 | /* efidev.c */ | 73 | /* efidev.c */ | |
74 | int efi_device_path_depth(EFI_DEVICE_PATH *dp, int); | 74 | int efi_device_path_depth(EFI_DEVICE_PATH *dp, int); | |
75 | int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int); | 75 | int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int); | |
76 | 76 | |||
77 | /* efidisk.c */ | 77 | /* efidisk.c */ | |
78 | void efi_disk_probe(void); | 78 | void efi_disk_probe(void); | |
79 | void efi_disk_show(void); | 79 | void efi_disk_show(void); | |
80 | 80 | |||
81 | /* efimemory.c */ | 81 | /* efimemory.c */ | |
82 | void efi_memory_probe(void); | 82 | void efi_memory_probe(void); | |
83 | void efi_memory_show_map(bool); | 83 | void efi_memory_show_map(bool, bool); | |
84 | EFI_MEMORY_DESCRIPTOR *efi_memory_get_map(UINTN *, UINTN *, UINTN *, UINT32 *, | 84 | EFI_MEMORY_DESCRIPTOR *efi_memory_get_map(UINTN *, UINTN *, UINTN *, UINT32 *, | |
85 | bool); | 85 | bool); | |
86 | EFI_MEMORY_DESCRIPTOR *efi_memory_compact_map(EFI_MEMORY_DESCRIPTOR *, UINTN *, | |||
87 | UINTN); | |||
86 | 88 | |||
87 | /* efinet.c */ | 89 | /* efinet.c */ | |
88 | void efi_net_probe(void); | 90 | void efi_net_probe(void); | |
89 | void efi_net_show(void); | 91 | void efi_net_show(void); | |
90 | int efi_net_get_booted_interface_unit(void); | 92 | int efi_net_get_booted_interface_unit(void); | |
91 | 93 | |||
92 | /* efipxe.c */ | 94 | /* efipxe.c */ | |
93 | void efi_pxe_probe(void); | 95 | void efi_pxe_probe(void); | |
94 | void efi_pxe_show(void); | 96 | void efi_pxe_show(void); | |
95 | bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32); | 97 | bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32); | |
96 | 98 | |||
97 | /* panic.c */ | 99 | /* panic.c */ | |
98 | __dead VOID Panic(IN CHAR16 *, ...); | 100 | __dead VOID Panic(IN CHAR16 *, ...); |
--- src/sys/arch/i386/stand/efiboot/efimemory.c 2018/04/02 08:50:33 1.4.10.1
+++ src/sys/arch/i386/stand/efiboot/efimemory.c 2019/08/01 13:22:48 1.4.10.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: efimemory.c,v 1.4.10.1 2018/04/02 08:50:33 martin Exp $ */ | 1 | /* $NetBSD: efimemory.c,v 1.4.10.2 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | 4 | * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> | |
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. | |
@@ -20,59 +20,47 @@ | @@ -20,59 +20,47 @@ | |||
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include "efiboot.h" | 29 | #include "efiboot.h" | |
30 | 30 | |||
31 | #include <bootinfo.h> | 31 | #include <bootinfo.h> | |
32 | 32 | |||
33 | static const char *memtypes[] = { | 33 | static const char *efi_memory_type[] = { | |
34 | "unknown", | 34 | [EfiReservedMemoryType] = "Reserved Memory Type", | |
35 | "available", | 35 | [EfiLoaderCode] = "Loader Code", | |
36 | "reserved", | 36 | [EfiLoaderData] = "Loader Data", | |
37 | "ACPI reclaimable", | 37 | [EfiBootServicesCode] = "Boot Services Code", | |
38 | "ACPI NVS", | 38 | [EfiBootServicesData] = "Boot Services Data", | |
39 | "unusable", | 39 | [EfiRuntimeServicesCode] = "Runtime Services Code", | |
40 | "disabled", | 40 | [EfiRuntimeServicesData] = "Runtime Services Data", | |
41 | "Persistent", | 41 | [EfiConventionalMemory] = "Conventional Memory", | |
42 | "undefined (8)", | 42 | [EfiUnusableMemory] = "Unusable Memory", | |
43 | "undefined (9)", | 43 | [EfiACPIReclaimMemory] = "ACPI Reclaim Memory", | |
44 | "undefined (10)", | 44 | [EfiACPIMemoryNVS] = "ACPI Memory NVS", | |
45 | "undefined (11)", | 45 | [EfiMemoryMappedIO] = "MMIO", | |
46 | "Persistent (Legacy)" | 46 | [EfiMemoryMappedIOPortSpace] = "MMIO (Port Space)", | |
47 | [EfiPalCode] = "Pal Code", | |||
48 | [EfiPersistentMemory] = "Persistent Memory", | |||
47 | }; | 49 | }; | |
48 | 50 | |||
49 | static const char *efimemtypes[] = { | 51 | #ifndef KERN_LOADSPACE_SIZE | |
50 | "Reserved", | 52 | #define KERN_LOADSPACE_SIZE (128 * 1024 * 1024) /* 128MiB */ | |
51 | "LoaderCode", | 53 | #endif | |
52 | "LoaderData", | |||
53 | "BootServicesCode", | |||
54 | "BootServicesData", | |||
55 | "RuntimeServicesCode", | |||
56 | "RuntimeServicesData", | |||
57 | "ConventionalMemory", | |||
58 | "UnusableMemory", | |||
59 | "ACPIReclaimMemory", | |||
60 | "ACPIMemoryNVS", | |||
61 | "MemoryMappedIO", | |||
62 | "MemoryMappedIOPortSpace", | |||
63 | "PalCode", | |||
64 | "PersistentMemory", | |||
65 | }; | |||
66 | 54 | |||
67 | static int | 55 | static int | |
68 | getmemtype(EFI_MEMORY_DESCRIPTOR *md) | 56 | getmemtype(EFI_MEMORY_DESCRIPTOR *md) | |
69 | { | 57 | { | |
70 | 58 | |||
71 | switch (md->Type) { | 59 | switch (md->Type) { | |
72 | case EfiLoaderCode: | 60 | case EfiLoaderCode: | |
73 | case EfiLoaderData: | 61 | case EfiLoaderData: | |
74 | case EfiBootServicesCode: | 62 | case EfiBootServicesCode: | |
75 | case EfiBootServicesData: | 63 | case EfiBootServicesData: | |
76 | case EfiConventionalMemory: | 64 | case EfiConventionalMemory: | |
77 | return (md->Attribute & EFI_MEMORY_WB) ? | 65 | return (md->Attribute & EFI_MEMORY_WB) ? | |
78 | BIM_Memory : BIM_Reserved; | 66 | BIM_Memory : BIM_Reserved; | |
@@ -93,49 +81,125 @@ getmemtype(EFI_MEMORY_DESCRIPTOR *md) | @@ -93,49 +81,125 @@ getmemtype(EFI_MEMORY_DESCRIPTOR *md) | |||
93 | case EfiMemoryMappedIO: | 81 | case EfiMemoryMappedIO: | |
94 | case EfiMemoryMappedIOPortSpace: | 82 | case EfiMemoryMappedIOPortSpace: | |
95 | case EfiPalCode: | 83 | case EfiPalCode: | |
96 | case EfiMaxMemoryType: | 84 | case EfiMaxMemoryType: | |
97 | default: | 85 | default: | |
98 | return BIM_Reserved; | 86 | return BIM_Reserved; | |
99 | } | 87 | } | |
100 | } | 88 | } | |
101 | 89 | |||
102 | EFI_MEMORY_DESCRIPTOR * | 90 | EFI_MEMORY_DESCRIPTOR * | |
103 | efi_memory_get_map(UINTN *NoEntries, UINTN *MapKey, UINTN *DescriptorSize, | 91 | efi_memory_get_map(UINTN *NoEntries, UINTN *MapKey, UINTN *DescriptorSize, | |
104 | UINT32 *DescriptorVersion, bool sorted) | 92 | UINT32 *DescriptorVersion, bool sorted) | |
105 | { | 93 | { | |
106 | EFI_MEMORY_DESCRIPTOR *desc, *md, *next, *target, tmp; | 94 | EFI_MEMORY_DESCRIPTOR *desc, *md, *next, *target, *tmp; | |
107 | UINTN i, j; | 95 | UINTN i, j; | |
108 | 96 | |||
109 | *NoEntries = 0; | 97 | *NoEntries = 0; | |
110 | desc = LibMemoryMap(NoEntries, MapKey, DescriptorSize, | 98 | desc = LibMemoryMap(NoEntries, MapKey, DescriptorSize, | |
111 | DescriptorVersion); | 99 | DescriptorVersion); | |
112 | if (desc == NULL) | 100 | if (desc == NULL) | |
113 | panic("efi_memory_get_map failed"); | 101 | panic("efi_memory_get_map failed"); | |
114 | 102 | |||
115 | if (!sorted) | 103 | if (!sorted) | |
116 | return desc; | 104 | return desc; | |
117 | 105 | |||
106 | tmp = alloc(*DescriptorSize); | |||
107 | if (tmp == NULL) | |||
108 | return desc; | |||
109 | ||||
118 | for (i = 0, md = desc; i < *NoEntries - 1; i++, md = next) { | 110 | for (i = 0, md = desc; i < *NoEntries - 1; i++, md = next) { | |
119 | target = next = NextMemoryDescriptor(md, *DescriptorSize); | 111 | target = next = NextMemoryDescriptor(md, *DescriptorSize); | |
120 | for (j = i + 1; j < *NoEntries; j++) { | 112 | for (j = i + 1; j < *NoEntries; j++) { | |
121 | if (md->PhysicalStart > target->PhysicalStart) { | 113 | if (md->PhysicalStart > target->PhysicalStart) { | |
122 | CopyMem(&tmp, md, sizeof(*md)); | 114 | CopyMem(tmp, md, *DescriptorSize); | |
123 | CopyMem(md, target, sizeof(*md)); | 115 | CopyMem(md, target, *DescriptorSize); | |
124 | CopyMem(target, &tmp, sizeof(*md)); | 116 | CopyMem(target, tmp, *DescriptorSize); | |
125 | } | 117 | } | |
126 | target = NextMemoryDescriptor(target, *DescriptorSize); | 118 | target = NextMemoryDescriptor(target, *DescriptorSize); | |
127 | } | 119 | } | |
128 | } | 120 | } | |
121 | dealloc(tmp, *DescriptorSize); | |||
122 | ||||
123 | return desc; | |||
124 | } | |||
125 | ||||
126 | EFI_MEMORY_DESCRIPTOR * | |||
127 | efi_memory_compact_map(EFI_MEMORY_DESCRIPTOR *desc, UINTN *NoEntries, | |||
128 | UINTN DescriptorSize) | |||
129 | { | |||
130 | EFI_MEMORY_DESCRIPTOR *md, *next, *target, *tmp; | |||
131 | UINTN i, j; | |||
132 | UINT32 type; | |||
133 | bool first = true, do_compact; | |||
134 | ||||
135 | for (i = 0, md = target = desc; i < *NoEntries; i++, md = next) { | |||
136 | type = md->Type; | |||
137 | switch (type) { | |||
138 | case EfiLoaderCode: | |||
139 | case EfiLoaderData: | |||
140 | case EfiBootServicesCode: | |||
141 | case EfiBootServicesData: | |||
142 | case EfiConventionalMemory: | |||
143 | if ((md->Attribute & EFI_MEMORY_WB) != 0) | |||
144 | type = EfiConventionalMemory; | |||
145 | if (md->Attribute == target->Attribute) { | |||
146 | do_compact = true; | |||
147 | break; | |||
148 | } | |||
149 | /* FALLTHROUGH */ | |||
150 | case EfiACPIReclaimMemory: | |||
151 | case EfiACPIMemoryNVS: | |||
152 | case EfiPersistentMemory: | |||
153 | case EfiReservedMemoryType: | |||
154 | case EfiRuntimeServicesCode: | |||
155 | case EfiRuntimeServicesData: | |||
156 | case EfiUnusableMemory: | |||
157 | case EfiMemoryMappedIO: | |||
158 | case EfiMemoryMappedIOPortSpace: | |||
159 | case EfiPalCode: | |||
160 | default: | |||
161 | do_compact = false; | |||
162 | break; | |||
163 | } | |||
164 | ||||
165 | if (first) { | |||
166 | first = false; | |||
167 | } else if (do_compact && | |||
168 | type == target->Type && | |||
169 | md->Attribute == target->Attribute && | |||
170 | md->PhysicalStart == target->PhysicalStart + target->NumberOfPages * EFI_PAGE_SIZE) { | |||
171 | /* continuous region */ | |||
172 | target->NumberOfPages += md->NumberOfPages; | |||
173 | ||||
174 | tmp = md; | |||
175 | for (j = i + 1; j < *NoEntries; j++) { | |||
176 | next = NextMemoryDescriptor(md, DescriptorSize); | |||
177 | CopyMem(md, next, DescriptorSize); | |||
178 | md = next; | |||
179 | } | |||
180 | next = tmp; | |||
181 | ||||
182 | i--; | |||
183 | (*NoEntries)--; | |||
184 | continue; | |||
185 | } else { | |||
186 | target = md; | |||
187 | } | |||
188 | ||||
189 | target->Type = type; | |||
190 | next = NextMemoryDescriptor(md, DescriptorSize); | |||
191 | } | |||
192 | ||||
129 | return desc; | 193 | return desc; | |
130 | } | 194 | } | |
131 | 195 | |||
132 | /* | 196 | /* | |
133 | * get memory size below 1MB | 197 | * get memory size below 1MB | |
134 | */ | 198 | */ | |
135 | int | 199 | int | |
136 | getbasemem(void) | 200 | getbasemem(void) | |
137 | { | 201 | { | |
138 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | 202 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | |
139 | UINTN i, NoEntries, MapKey, DescriptorSize, MappingSize; | 203 | UINTN i, NoEntries, MapKey, DescriptorSize, MappingSize; | |
140 | UINT32 DescriptorVersion; | 204 | UINT32 DescriptorVersion; | |
141 | EFI_PHYSICAL_ADDRESS basemem = 0, epa; | 205 | EFI_PHYSICAL_ADDRESS basemem = 0, epa; | |
@@ -221,94 +285,102 @@ getextmemx(void) | @@ -221,94 +285,102 @@ getextmemx(void) | |||
221 | if (extmem16m > 1 * 1024 * 1024) | 285 | if (extmem16m > 1 * 1024 * 1024) | |
222 | extmem16m -= 1 * 1024 * 1024; /* below 1MB */ | 286 | extmem16m -= 1 * 1024 * 1024; /* below 1MB */ | |
223 | 287 | |||
224 | extmem = extmem16m / 1024; | 288 | extmem = extmem16m / 1024; | |
225 | if (extmem == 15 * 1024) | 289 | if (extmem == 15 * 1024) | |
226 | extmem += extmem4g / 1024; | 290 | extmem += extmem4g / 1024; | |
227 | return extmem; | 291 | return extmem; | |
228 | } | 292 | } | |
229 | 293 | |||
230 | void | 294 | void | |
231 | efi_memory_probe(void) | 295 | efi_memory_probe(void) | |
232 | { | 296 | { | |
233 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | 297 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | |
298 | EFI_STATUS status; | |||
299 | EFI_PHYSICAL_ADDRESS bouncebuf; | |||
234 | UINTN i, n, NoEntries, MapKey, DescriptorSize, MappingSize; | 300 | UINTN i, n, NoEntries, MapKey, DescriptorSize, MappingSize; | |
235 | UINT32 DescriptorVersion; | 301 | UINT32 DescriptorVersion; | |
236 | int memtype; | 302 | int memtype; | |
237 | 303 | |||
304 | bouncebuf = EFI_ALLOCATE_MAX_ADDRESS; | |||
305 | status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, | |||
306 | EfiLoaderData, EFI_SIZE_TO_PAGES(KERN_LOADSPACE_SIZE), &bouncebuf); | |||
307 | if (EFI_ERROR(status)) | |||
308 | panic("couldn't allocate kernel space."); | |||
309 | efi_loadaddr = bouncebuf; | |||
310 | ||||
238 | mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | 311 | mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | |
239 | &DescriptorVersion, false); | 312 | &DescriptorVersion, false); | |
240 | ||||
241 | printf(" mem["); | 313 | printf(" mem["); | |
242 | for (i = 0, n = 0, md = mdtop; i < NoEntries; i++, md = next) { | 314 | for (i = 0, n = 0, md = mdtop; i < NoEntries; i++, md = next) { | |
243 | next = NextMemoryDescriptor(md, DescriptorSize); | 315 | next = NextMemoryDescriptor(md, DescriptorSize); | |
244 | 316 | |||
245 | memtype = getmemtype(md); | 317 | memtype = getmemtype(md); | |
246 | if (memtype != BIM_Memory) | 318 | if (memtype != BIM_Memory) | |
247 | continue; | 319 | continue; | |
248 | 320 | |||
249 | MappingSize = md->NumberOfPages * EFI_PAGE_SIZE; | 321 | MappingSize = md->NumberOfPages * EFI_PAGE_SIZE; | |
250 | if (MappingSize < 12 * 1024) /* XXX Why? from OpenBSD */ | 322 | if (MappingSize < 12 * 1024) /* XXX Why? from OpenBSD */ | |
251 | continue; | 323 | continue; | |
252 | 324 | |||
253 | if (n++ > 0) | 325 | if (n++ > 0) | |
254 | printf(" "); | 326 | printf(" "); | |
255 | printf("0x%" PRIxMAX "-0x%" PRIxMAX, (uintmax_t)md->PhysicalStart, | 327 | printf("0x%" PRIxMAX "-0x%" PRIxMAX, (uintmax_t)md->PhysicalStart, | |
256 | (uintmax_t)(md->PhysicalStart + MappingSize - 1)); | 328 | (uintmax_t)(md->PhysicalStart + MappingSize - 1)); | |
257 | } | 329 | } | |
258 | printf("]\n"); | 330 | printf("]\n"); | |
259 | 331 | |||
260 | FreePool(mdtop); | 332 | FreePool(mdtop); | |
261 | } | 333 | } | |
262 | 334 | |||
263 | void | 335 | void | |
264 | efi_memory_show_map(bool sorted) | 336 | efi_memory_show_map(bool sorted, bool compact) | |
265 | { | 337 | { | |
266 | EFI_STATUS status; | 338 | EFI_STATUS status; | |
267 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | 339 | EFI_MEMORY_DESCRIPTOR *mdtop, *md, *next; | |
268 | UINTN i, NoEntries, MapKey, DescriptorSize; | 340 | UINTN i, NoEntries, MapKey, DescriptorSize; | |
269 | UINT32 DescriptorVersion; | 341 | UINT32 DescriptorVersion; | |
270 | char memstr[32], efimemstr[32]; | 342 | char efimemstr[32]; | |
271 | int memtype; | 343 | UINTN cols, rows, row; | |
272 | UINTN cols, rows, row = 0; | |||
273 | 344 | |||
274 | status = uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut, | 345 | status = uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut, | |
275 | ST->ConOut->Mode->Mode, &cols, &rows); | 346 | ST->ConOut->Mode->Mode, &cols, &rows); | |
276 | if (EFI_ERROR(status) || rows <= 2) | 347 | if (EFI_ERROR(status) || rows <= 2) | |
277 | rows = 0; | 348 | rows = 0; | |
278 | else | 349 | else | |
279 | rows -= 2; | 350 | rows -= 2; | |
280 | 351 | |||
281 | mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | 352 | mdtop = efi_memory_get_map(&NoEntries, &MapKey, &DescriptorSize, | |
282 | &DescriptorVersion, sorted); | 353 | &DescriptorVersion, sorted); | |
354 | if (compact) | |||
355 | efi_memory_compact_map(mdtop, &NoEntries, DescriptorSize); | |||
356 | ||||
357 | printf("%-22s %-16s %-16s %-16s\n", "Type", "Start", "End", "Attributes"); | |||
358 | printf("---------------------- ---------------- ---------------- ----------------\n"); | |||
359 | row = 2; | |||
283 | 360 | |||
284 | for (i = 0, md = mdtop; i < NoEntries; i++, md = next) { | 361 | for (i = 0, md = mdtop; i < NoEntries; i++, md = next) { | |
285 | next = NextMemoryDescriptor(md, DescriptorSize); | 362 | next = NextMemoryDescriptor(md, DescriptorSize); | |
286 | 363 | |||
287 | memtype = getmemtype(md); | 364 | if (md->Type >= __arraycount(efi_memory_type)) | |
288 | if (memtype >= __arraycount(memtypes)) | |||
289 | snprintf(memstr, sizeof(memstr), "unknown (%d)", | |||
290 | memtype); | |||
291 | if (md->Type >= __arraycount(efimemtypes)) | |||
292 | snprintf(efimemstr, sizeof(efimemstr), "unknown (%d)", | 365 | snprintf(efimemstr, sizeof(efimemstr), "unknown (%d)", | |
293 | md->Type); | 366 | md->Type); | |
294 | printf("%016" PRIxMAX "/%016" PRIxMAX ": %s [%s]\n", | 367 | printf("%-22s %016" PRIxMAX " %016" PRIxMAX " %016" PRIxMAX "\n", | |
368 | md->Type >= __arraycount(efi_memory_type) ? | |||
369 | efimemstr : efi_memory_type[md->Type], | |||
295 | (uintmax_t)md->PhysicalStart, | 370 | (uintmax_t)md->PhysicalStart, | |
296 | (uintmax_t)md->PhysicalStart + | 371 | (uintmax_t)md->PhysicalStart + | |
297 | md->NumberOfPages * EFI_PAGE_SIZE - 1, | 372 | md->NumberOfPages * EFI_PAGE_SIZE - 1, | |
298 | memtype >= __arraycount(memtypes) ? | 373 | (uintmax_t)md->Attribute); | |
299 | memstr : memtypes[memtype], | |||
300 | md->Type >= __arraycount(efimemtypes) ? | |||
301 | efimemstr : efimemtypes[md->Type]); | |||
302 | 374 | |||
303 | if (++row >= rows) { | 375 | if (++row >= rows) { | |
304 | row = 0; | 376 | row = 0; | |
305 | printf("Press Any Key to continue :"); | 377 | printf("Press Any Key to continue :"); | |
306 | (void) awaitkey(-1, 0); | 378 | (void) awaitkey(-1, 0); | |
307 | printf("\n"); | 379 | printf("\n"); | |
308 | } | 380 | } | |
309 | } | 381 | } | |
310 | 382 | |||
311 | FreePool(mdtop); | 383 | FreePool(mdtop); | |
312 | } | 384 | } | |
313 | 385 | |||
314 | void | 386 | void |
--- src/sys/arch/i386/stand/lib/exec.c 2017/03/24 08:50:17 1.68
+++ src/sys/arch/i386/stand/lib/exec.c 2019/08/01 13:22:48 1.68.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: exec.c,v 1.68 2017/03/24 08:50:17 nonaka Exp $ */ | 1 | /* $NetBSD: exec.c,v 1.68.6.1 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008, 2009 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. | |
@@ -454,75 +454,26 @@ exec_netbsd(const char *file, physaddr_t | @@ -454,75 +454,26 @@ exec_netbsd(const char *file, physaddr_t | |||
454 | efi_kernel_start = marks[MARK_START]; | 454 | efi_kernel_start = marks[MARK_START]; | |
455 | efi_kernel_size = image_end - efi_loadaddr - efi_kernel_start; | 455 | efi_kernel_size = image_end - efi_loadaddr - efi_kernel_start; | |
456 | #endif | 456 | #endif | |
457 | startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv, | 457 | startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv, | |
458 | x86_trunc_page(basemem * 1024)); | 458 | x86_trunc_page(basemem * 1024)); | |
459 | panic("exec returned"); | 459 | panic("exec returned"); | |
460 | 460 | |||
461 | out: | 461 | out: | |
462 | BI_FREE(); | 462 | BI_FREE(); | |
463 | bootinfo = NULL; | 463 | bootinfo = NULL; | |
464 | return -1; | 464 | return -1; | |
465 | } | 465 | } | |
466 | 466 | |||
467 | int | |||
468 | count_netbsd(const char *file, u_long *rsz) | |||
469 | { | |||
470 | u_long marks[MARK_MAX]; | |||
471 | char kdev[64]; | |||
472 | char base_path[64] = "/"; | |||
473 | struct stat st; | |||
474 | boot_module_t *bm; | |||
475 | u_long sz; | |||
476 | int err, fd; | |||
477 | ||||
478 | howto = AB_SILENT; | |||
479 | ||||
480 | memset(marks, 0, sizeof(marks)); | |||
481 | if ((fd = loadfile(file, marks, COUNT_KERNEL | LOAD_NOTE)) == -1) | |||
482 | return -1; | |||
483 | close(fd); | |||
484 | marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) & | |||
485 | (-sizeof(int)); | |||
486 | sz = marks[MARK_END]; | |||
487 | ||||
488 | /* The modules must be allocated after the kernel */ | |||
489 | if (boot_modules_enabled) { | |||
490 | extract_device(file, kdev, sizeof(kdev)); | |||
491 | module_base_path(base_path, sizeof(base_path)); | |||
492 | ||||
493 | /* If the root fs type is unusual, load its module. */ | |||
494 | if (fsmod != NULL) | |||
495 | module_add_common(fsmod, BM_TYPE_KMOD); | |||
496 | ||||
497 | for (bm = boot_modules; bm; bm = bm->bm_next) { | |||
498 | fd = module_open(bm, 0, kdev, base_path, false); | |||
499 | if (fd == -1) | |||
500 | continue; | |||
501 | sz = (sz + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); | |||
502 | err = fstat(fd, &st); | |||
503 | if (err == -1 || st.st_size == -1) { | |||
504 | close(fd); | |||
505 | continue; | |||
506 | } | |||
507 | sz += st.st_size; | |||
508 | close(fd); | |||
509 | } | |||
510 | } | |||
511 | ||||
512 | *rsz = sz; | |||
513 | return 0; | |||
514 | } | |||
515 | ||||
516 | static void | 467 | static void | |
517 | extract_device(const char *path, char *buf, size_t buflen) | 468 | extract_device(const char *path, char *buf, size_t buflen) | |
518 | { | 469 | { | |
519 | size_t i; | 470 | size_t i; | |
520 | 471 | |||
521 | if (strchr(path, ':') != NULL) { | 472 | if (strchr(path, ':') != NULL) { | |
522 | for (i = 0; i < buflen - 2 && path[i] != ':'; i++) | 473 | for (i = 0; i < buflen - 2 && path[i] != ':'; i++) | |
523 | buf[i] = path[i]; | 474 | buf[i] = path[i]; | |
524 | buf[i++] = ':'; | 475 | buf[i++] = ':'; | |
525 | buf[i] = '\0'; | 476 | buf[i] = '\0'; | |
526 | } else | 477 | } else | |
527 | buf[0] = '\0'; | 478 | buf[0] = '\0'; | |
528 | } | 479 | } |
--- src/sys/arch/i386/stand/lib/libi386.h 2017/03/12 05:33:48 1.42
+++ src/sys/arch/i386/stand/lib/libi386.h 2019/08/01 13:22:48 1.42.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: libi386.h,v 1.42 2017/03/12 05:33:48 nonaka Exp $ */ | 1 | /* $NetBSD: libi386.h,v 1.42.6.1 2019/08/01 13:22:48 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1996 | 4 | * Copyright (c) 1996 | |
5 | * Matthias Drochner. All rights reserved. | 5 | * Matthias Drochner. 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. | |
@@ -33,27 +33,26 @@ typedef unsigned long physaddr_t; | @@ -33,27 +33,26 @@ typedef unsigned long physaddr_t; | |||
33 | 33 | |||
34 | /* this is in startup code */ | 34 | /* this is in startup code */ | |
35 | void vpbcopy(const void *, void *, size_t); | 35 | void vpbcopy(const void *, void *, size_t); | |
36 | void pvbcopy(const void *, void *, size_t); | 36 | void pvbcopy(const void *, void *, size_t); | |
37 | void pbzero(void *, size_t); | 37 | void pbzero(void *, size_t); | |
38 | physaddr_t vtophys(void *); | 38 | physaddr_t vtophys(void *); | |
39 | 39 | |||
40 | ssize_t pread(int, void *, size_t); | 40 | ssize_t pread(int, void *, size_t); | |
41 | void startprog(physaddr_t, uint32_t, uint32_t *, physaddr_t); | 41 | void startprog(physaddr_t, uint32_t, uint32_t *, physaddr_t); | |
42 | void multiboot(physaddr_t, physaddr_t, physaddr_t); | 42 | void multiboot(physaddr_t, physaddr_t, physaddr_t); | |
43 | 43 | |||
44 | int exec_netbsd(const char *, physaddr_t, int, int, void (*)(void)); | 44 | int exec_netbsd(const char *, physaddr_t, int, int, void (*)(void)); | |
45 | int exec_multiboot(const char *, char *); | 45 | int exec_multiboot(const char *, char *); | |
46 | int count_netbsd(const char *, u_long *); | |||
47 | 46 | |||
48 | void delay(int); | 47 | void delay(int); | |
49 | int getbasemem(void); | 48 | int getbasemem(void); | |
50 | int getextmemx(void); | 49 | int getextmemx(void); | |
51 | int getextmem1(void); | 50 | int getextmem1(void); | |
52 | int biosvideomode(void); | 51 | int biosvideomode(void); | |
53 | #ifdef CONSERVATIVE_MEMDETECT | 52 | #ifdef CONSERVATIVE_MEMDETECT | |
54 | #define getextmem() getextmem1() | 53 | #define getextmem() getextmem1() | |
55 | #else | 54 | #else | |
56 | #define getextmem() getextmemx() | 55 | #define getextmem() getextmemx() | |
57 | #endif | 56 | #endif | |
58 | void printmemlist(void); | 57 | void printmemlist(void); | |
59 | void reboot(void); | 58 | void reboot(void); |