Annotation of lucent/sys/src/boot/pc/f002811, revision 1.1.1.1

1.1       root        1: #include       "u.h"
                      2: #include       "lib.h"
                      3: #include       "mem.h"
                      4: #include       "dat.h"
                      5: #include       "fns.h"
                      6: 
                      7: /*
                      8:  *  read in a segment
                      9:  */
                     10: static long
                     11: readseg(int dev, long (*read)(int, void*, int), long len, long addr)
                     12: {
                     13:        char *a;
                     14:        long n, sofar;
                     15: 
                     16:        a = (char *)addr;
                     17:        for(sofar = 0; sofar < len; sofar += n){
                     18:                n = 8*1024;
                     19:                if(len - sofar < n)
                     20:                        n = len - sofar;
                     21:                n = (*read)(dev, a + sofar, n);
                     22:                if(n <= 0)
                     23:                        break;
                     24:                print(".");
                     25:        }
                     26:        return sofar;
                     27: }
                     28: 
                     29: /*
                     30:  *  boot
                     31:  */
                     32: int
                     33: plan9boot(int dev, long (*seek)(int, long), long (*read)(int, void*, int))
                     34: {
                     35:        long n;
                     36:        long addr;
                     37:        void (*b)(void);
                     38:        Exec *ep;
                     39: 
                     40:        if((*seek)(dev, 0) < 0)
                     41:                return -1;
                     42: 
                     43:        /*
                     44:         *  read header
                     45:         */
                     46:        ep = (Exec *) ialloc(sizeof(Exec), 0);
                     47:        n = sizeof(Exec);
                     48:        if(readseg(dev, read, n, (ulong) ep) != n){
                     49:                print("premature EOF\n");
                     50:                return -1;
                     51:        }
                     52:        if(GLLONG(ep->magic) != I_MAGIC){
                     53:                print("bad magic 0x%lux not a plan 9 executable!\n", GLLONG(ep->magic));
                     54:                return -1;
                     55:        }
                     56: 
                     57:        /*
                     58:         *  read text
                     59:         */
                     60:        addr = PADDR(GLLONG(ep->entry));
                     61:        n = GLLONG(ep->text);
                     62:        print("%d", n);
                     63:        if(readseg(dev, read, n, addr) != n){
                     64:                print("premature EOF\n");
                     65:                return -1;
                     66:        }
                     67: 
                     68:        /*
                     69:         *  read data (starts at first page after kernel)
                     70:         */
                     71:        addr = PGROUND(addr+n);
                     72:        n = GLLONG(ep->data);
                     73:        print("+%d", n);
                     74:        if(readseg(dev, read, n, addr) != n){
                     75:                print("premature EOF\n");
                     76:                return -1;
                     77:        }
                     78: 
                     79:        /*
                     80:         *  bss and entry point
                     81:         */
                     82:        print("+%d\nstart at 0x%lux\n", GLLONG(ep->bss), GLLONG(ep->entry));
                     83: 
                     84:        /*
                     85:         *  Go to new code. It's up to the program to get its PC relocated to
                     86:         *  the right place.
                     87:         */
                     88:        b = (void (*)(void))(PADDR(GLLONG(ep->entry)));
                     89:        (*b)();
                     90:        return 0;
                     91: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.