Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc - When starting the boot program, cache a bu...



details:   https://anonhg.NetBSD.org/src/rev/59721178b9f4
branches:  trunk
changeset: 953195:59721178b9f4
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Feb 28 20:27:40 2021 +0000

description:
- When starting the boot program, cache a bunch of OFW frequently used
  ihandles / phandles, rather than fetching them all the time.
- Change the signature of OF_call_method() to take an array of cells for
  the inputs and outputs, rather than using variadic arguments.  This
  makes it much easier to use OF_call_method() when the format of the
  arguments passed to a given method are determined at run-time
  (due to e.g. #address-cells).
- Properly inform OpenFirmware where the kernel is loaded by using
  "claim" on /chosen/memory and, if running in virtual-mode, using
  "claim" on /chosen/mmu to reserve the VA, and "map" on /chosen/mmu
  to enter the translation.  (The kernel is still always mapped VA==PA.)

diffstat:

 sys/arch/macppc/include/loadfile_machdep.h       |   14 +-
 sys/arch/macppc/stand/ofwboot/Locore.c           |  138 +++++-
 sys/arch/macppc/stand/ofwboot/Makefile           |    5 +-
 sys/arch/macppc/stand/ofwboot/boot.c             |   38 +-
 sys/arch/macppc/stand/ofwboot/loadfile_machdep.c |  452 +++++++++++++++++++++++
 sys/arch/macppc/stand/ofwboot/ofdev.c            |   13 +-
 sys/arch/macppc/stand/ofwboot/openfirm.h         |   18 +-
 sys/arch/macppc/stand/ofwboot/version            |    3 +-
 8 files changed, 631 insertions(+), 50 deletions(-)

diffs (truncated from 914 to 300 lines):

diff -r 7d0fd6b239a5 -r 59721178b9f4 sys/arch/macppc/include/loadfile_machdep.h
--- a/sys/arch/macppc/include/loadfile_machdep.h        Sun Feb 28 20:17:13 2021 +0000
+++ b/sys/arch/macppc/include/loadfile_machdep.h        Sun Feb 28 20:27:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: loadfile_machdep.h,v 1.6 2014/08/06 21:57:50 joerg Exp $       */
+/*     $NetBSD: loadfile_machdep.h,v 1.7 2021/02/28 20:27:40 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -36,9 +36,21 @@
 
 #define LOADADDR(a)            (((u_long)(a)) + offset)
 #define ALIGNENTRY(a)          ((u_long)(a))
+
+#ifdef _STANDALONE
+ssize_t        macppc_read(int, void *, size_t);
+void * macppc_memcpy(void *, const void *, size_t);
+void * macppc_memset(void *, int, size_t);
+
+#define READ(f, b, c)          macppc_read((f), (void *)LOADADDR(b), (c))
+#define BCOPY(s, d, c)         macppc_memcpy((void *)LOADADDR(d), (void *)(s), (c))
+#define BZERO(d, c)            macppc_memset((void *)LOADADDR(d), 0, (c))
+#else
 #define READ(f, b, c)          read((f), (void *)LOADADDR(b), (c))
 #define BCOPY(s, d, c)         memcpy((void *)LOADADDR(d), (void *)(s), (c))
 #define BZERO(d, c)            memset((void *)LOADADDR(d), 0, (c))
+#endif /* _STANDALONE */
+
 #define        WARN(a)                 do { \
                                        (void)printf a; \
                                        if (errno) \
diff -r 7d0fd6b239a5 -r 59721178b9f4 sys/arch/macppc/stand/ofwboot/Locore.c
--- a/sys/arch/macppc/stand/ofwboot/Locore.c    Sun Feb 28 20:17:13 2021 +0000
+++ b/sys/arch/macppc/stand/ofwboot/Locore.c    Sun Feb 28 20:27:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: Locore.c,v 1.34 2020/04/15 13:33:13 rin Exp $  */
+/*     $NetBSD: Locore.c,v 1.35 2021/02/28 20:27:40 thorpej Exp $      */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -201,6 +201,34 @@
 }
 #endif
 
+int    ofw_real_mode;
+int    ofw_address_cells;
+int    ofw_size_cells;
+
+int    ofw_root;               /* / */
+int    ofw_options;            /* /options */
+int    ofw_openprom;           /* /openprom */
+int    ofw_chosen;             /* /chosen (package) */
+int    ofw_stdin;              /* /chosen/stdin */
+int    ofw_stdout;             /* /chosen/stdout */
+int    ofw_memory_ihandle;     /* /chosen/memory */
+int    ofw_mmu_ihandle;        /* /chosen/mmu */
+
+bool
+ofw_option_truefalse(const char *prop, int proplen)
+{
+       /* These are all supposed to be strings. */
+       switch (prop[0]) {  
+       case 'y':
+       case 'Y':
+       case 't':
+       case 'T':
+       case '1':
+               return true; 
+       }
+       return false;
+}
+
 static void
 startup(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl)
 {
@@ -623,9 +651,9 @@
 #endif
 
 int
-OF_call_method(const char *method, int ihandle, int nargs, int nreturns, ...)
+OF_call_method(const char *method, int ihandle, int nargs, int nreturns,
+    int *cells)
 {
-       va_list ap;
        static struct {
                const char *name;
                int nargs;
@@ -642,47 +670,47 @@
 
        if (nargs > 6)
                return -1;
+
        args.nargs = nargs + 2;
        args.nreturns = nreturns + 1;
        args.method = method;
        args.ihandle = ihandle;
-       va_start(ap, nreturns);
+
        for (ip = args.args_n_results + (n = nargs); --n >= 0;)
-               *--ip = va_arg(ap, int);
+               *--ip = *cells++;
 
        if (openfirmware(&args) == -1) {
-               va_end(ap);
                return -1;
        }
+
        if (args.args_n_results[nargs]) {
-               va_end(ap);
                return args.args_n_results[nargs];
        }
+
        for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
-               *va_arg(ap, int *) = *--ip;
-       va_end(ap);
+               *cells++ = *--ip;
+
        return 0;
 }
 
-static int stdin;
-static int stdout;
-
 static void
 setup(void)
 {
-       int chosen;
+       char prop[32];
+       int proplen;
+       const char *reason = NULL;
 
-       if ((chosen = OF_finddevice("/chosen")) == -1)
+       if ((ofw_chosen = OF_finddevice("/chosen")) == -1)
                OF_exit();
-       if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) !=
-           sizeof(stdin) ||
-           OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) !=
-           sizeof(stdout))
+       if (OF_getprop(ofw_chosen, "stdin", &ofw_stdin, sizeof(ofw_stdin)) !=
+           sizeof(ofw_stdin) ||
+           OF_getprop(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) !=
+           sizeof(ofw_stdout))
                OF_exit();
 
-       if (stdout == 0) {
+       if (ofw_stdout == 0) {
                /* screen should be console, but it is not open */
-               stdout = OF_open("screen");
+               ofw_stdout = OF_open("screen");
        }
 
 #ifdef HEAP_VARIABLE
@@ -699,6 +727,72 @@
 
        setheap(heapspace, heapspace + HEAP_SIZE);
 #endif /* HEAP_VARIABLE */
+
+       ofw_root = OF_finddevice("/");
+       ofw_options = OF_finddevice("/options");
+       ofw_openprom = OF_finddevice("/openprom");
+       ofw_chosen = OF_finddevice("/chosen");
+
+       if (ofw_root == -1) {
+               reason = "No root node";
+               goto bad_environment;
+       }
+       if (ofw_chosen == -1) {
+               reason = "No chosen node";
+               goto bad_environment;
+       }
+
+       if (ofw_options != -1) {
+               proplen = OF_getprop(ofw_options, "real-mode?", prop,
+                   sizeof(prop));
+               if (proplen > 0) {
+                       ofw_real_mode = ofw_option_truefalse(prop, proplen);
+               }
+       }
+
+       /*
+        * Get #address-cells and #size-cells.
+        */
+       ofw_address_cells = 1;
+       ofw_size_cells = 1;
+       OF_getprop(ofw_root, "#address-cells", &ofw_address_cells,
+                  sizeof(ofw_address_cells));
+       OF_getprop(ofw_root, "#size-cells", &ofw_size_cells,
+                  sizeof(ofw_size_cells));
+
+       /* See loadfile_machdep.c */
+       if (ofw_size_cells != 1) {
+               printf("#size-cells = %d not yet supported\n", ofw_size_cells);
+               reason = "unsupported #size-cells";
+               goto bad_environment;
+       }
+
+       /*
+        * Get the ihandle on /chosen/memory and /chosen/mmu.
+        */
+       ofw_memory_ihandle = -1;
+       ofw_mmu_ihandle = -1;
+       OF_getprop(ofw_chosen, "memory", &ofw_memory_ihandle,
+                  sizeof(ofw_memory_ihandle));
+       OF_getprop(ofw_chosen, "mmu", &ofw_mmu_ihandle,
+                  sizeof(ofw_mmu_ihandle));
+       if (ofw_memory_ihandle == -1) {
+               reason = "no /chosen/memory";
+               goto bad_environment;
+       }
+       if (ofw_mmu_ihandle == -1) {
+               reason = "no /chosen/mmu";
+               goto bad_environment;
+       }
+
+       return;
+
+ bad_environment:
+       if (reason == NULL) {
+               reason = "unknown reason";
+       }
+       printf("Invalid Openfirmware environment: %s\n", reason);
+       OF_exit();
 }
 
 void
@@ -708,7 +802,7 @@
 
        if (c == '\n')
                putchar('\r');
-       OF_write(stdout, &ch, 1);
+       OF_write(ofw_stdout, &ch, 1);
 }
 
 int
@@ -717,7 +811,7 @@
        unsigned char ch = '\0';
        int l;
 
-       while ((l = OF_read(stdin, &ch, 1)) != 1)
+       while ((l = OF_read(ofw_stdin, &ch, 1)) != 1)
                if (l != -2 && l != 0)
                        return -1;
        return ch;
diff -r 7d0fd6b239a5 -r 59721178b9f4 sys/arch/macppc/stand/ofwboot/Makefile
--- a/sys/arch/macppc/stand/ofwboot/Makefile    Sun Feb 28 20:17:13 2021 +0000
+++ b/sys/arch/macppc/stand/ofwboot/Makefile    Sun Feb 28 20:27:40 2021 +0000
@@ -1,10 +1,11 @@
-#      $NetBSD: Makefile,v 1.59 2018/06/06 22:56:25 uwe Exp $
+#      $NetBSD: Makefile,v 1.60 2021/02/28 20:27:40 thorpej Exp $
 
 S=     ${.CURDIR}/../../../..
 
 PROG=          ofwboot
 FILES=         ${PROG}.elf ${PROG}.xcf
-SRCS=          Locore.c boot.c ofdev.c hfs.c net.c netif_of.c
+SRCS=          Locore.c boot.c ofdev.c hfs.c net.c netif_of.c \
+               loadfile_machdep.c
 XCOFFXTRA=     Xcoffxtra.c
 XCOFFXTRAOBJ=  Xcoffxtra.o
 CFLAGS+=       -ffreestanding
diff -r 7d0fd6b239a5 -r 59721178b9f4 sys/arch/macppc/stand/ofwboot/boot.c
--- a/sys/arch/macppc/stand/ofwboot/boot.c      Sun Feb 28 20:17:13 2021 +0000
+++ b/sys/arch/macppc/stand/ofwboot/boot.c      Sun Feb 28 20:27:40 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.30 2020/04/23 00:12:28 joerg Exp $  */
+/*     $NetBSD: boot.c,v 1.31 2021/02/28 20:27:40 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -211,8 +211,8 @@
 main(void)
 {
        extern char bootprog_name[], bootprog_rev[];
-       int chosen, options, openprom;
        char bootline[512];             /* Should check size? */
+       char prop[32];
        char *cp;
        u_long marks[MARK_MAX];
        u_int32_t entry;
@@ -224,25 +224,24 @@
        /*
         * Figure out what version of Open Firmware...
         */
-       if ((openprom = OF_finddevice("/openprom")) != -1) {
-               char model[32];
-
-               memset(model, 0, sizeof model);
-               OF_getprop(openprom, "model", model, sizeof model);
-               for (cp = model; *cp; cp++)
+       if (ofw_openprom != -1) {
+               memset(prop, 0, sizeof prop);
+               OF_getprop(ofw_openprom, "model", prop, sizeof prop);
+               for (cp = prop; *cp; cp++)
                        if (*cp >= '0' && *cp <= '9') {
                                ofw_version = *cp - '0';
                                break;
                        }
-               DPRINTF(">> Open Firmware version %d.x\n", ofw_version);
+               printf(">> Open Firmware version %d.x\n", ofw_version);
        }



Home | Main Index | Thread Index | Old Index