Annotation of xinu/sys/shell/x_snap.c, revision 1.1

1.1     ! root        1: /* x_snap.c - x_snap */
        !             2: 
        !             3: #include <conf.h>
        !             4: #include <kernel.h>
        !             5: #include <shell.h>
        !             6: #include <coreX.h>
        !             7: 
        !             8: extern int     maxaddr;
        !             9: LOCAL  int     snapreg;
        !            10: #define        SNAPSIZ 512
        !            11: 
        !            12: /*------------------------------------------------------------------------
        !            13:  *  x_snap  -  (command snap) write snapshot of memory to a core file
        !            14:  *------------------------------------------------------------------------
        !            15:  */
        !            16: COMMAND        x_snap(stdin, stdout, stderr, nargs, args)
        !            17: int    stdin, stdout, stderr, nargs;
        !            18: char   *args[];
        !            19: {
        !            20:        int     dev, iPkt, len;
        !            21:        struct  coreX   hdr;
        !            22:        char    *p;
        !            23: 
        !            24:        if (nargs > 2) {
        !            25:                fprintf(stderr,"usage: snap [core-file]\n");
        !            26:                return(SYSERR);
        !            27:        }
        !            28:        p = nargs==1 ? "coreX" : args[1];
        !            29:        if ((dev=open(NAMESPACE, p, "w")) == SYSERR) {
        !            30:                fprintf(stderr,"snap: cannot open %s for writing\n", p);
        !            31:                return(SYSERR);
        !            32:        }
        !            33: 
        !            34:        /* make up a core image using coreX structure heading format */
        !            35: 
        !            36:        hdr.c_magic = COREMAGIC;
        !            37:        hdr.c_size = hdr.c_zero1 = hdr.c_zero2 = hdr.c_zero3 =
        !            38:                hdr.c_zero4 = hdr.c_zero5 = 0;
        !            39:        /* Capture machine registers */
        !            40: 
        !            41:        asm("mfpr $0x0, _snapreg"); hdr.c_regs[KSP] = snapreg;
        !            42:        asm("mfpr $0x1, _snapreg"); hdr.c_regs[ESP] = snapreg;
        !            43:        asm("mfpr $0x2, _snapreg"); hdr.c_regs[SSP] = snapreg;
        !            44:        asm("mfpr $0x3, _snapreg"); hdr.c_regs[SSP] = snapreg;
        !            45:        asm("movl r0,_snapreg");  hdr.c_regs[R0]  = snapreg;
        !            46:        asm("movl r1,_snapreg");  hdr.c_regs[R1]  = snapreg;
        !            47:        asm("movl r2,_snapreg");  hdr.c_regs[R2]  = snapreg;
        !            48:        asm("movl r3,_snapreg");  hdr.c_regs[R3]  = snapreg;
        !            49:        asm("movl r4,_snapreg");  hdr.c_regs[R4]  = snapreg;
        !            50:        asm("movl r5,_snapreg");  hdr.c_regs[R5]  = snapreg;
        !            51:        asm("movl r6,_snapreg");  hdr.c_regs[R6]  = snapreg;
        !            52:        asm("movl r7,_snapreg");  hdr.c_regs[R7]  = snapreg;
        !            53:        asm("movl r8,_snapreg");  hdr.c_regs[R8]  = snapreg;
        !            54:        asm("movl r9,_snapreg");  hdr.c_regs[R9]  = snapreg;
        !            55:        asm("movl r10,_snapreg"); hdr.c_regs[R10] = snapreg;
        !            56:        asm("movl r11,_snapreg"); hdr.c_regs[R11] = snapreg;
        !            57:        asm("movl ap,_snapreg");  hdr.c_regs[AP] = snapreg;
        !            58:        asm("movl fp,_snapreg");  hdr.c_regs[FP] = snapreg;
        !            59:        asm("sneakpc: moval sneakpc, _snapreg");  hdr.c_regs[PC] = snapreg;
        !            60:        asm("movpsl _snapreg");   hdr.c_psw = hdr.c_regs[PSL] = snapreg;
        !            61:        asm("mfpr $0x8, _snapreg"); hdr.c_regs[P0BR] = snapreg;
        !            62:        asm("mfpr $0x9, _snapreg"); hdr.c_regs[P0LR] = snapreg;
        !            63:        asm("mfpr $0xa, _snapreg"); hdr.c_regs[P1BR] = snapreg;
        !            64:        asm("mfpr $0xb, _snapreg"); hdr.c_regs[P1LR] = snapreg;
        !            65:        fprintf(stderr, "Writing core image");
        !            66:        if ( write(dev, &hdr, sizeof(struct coreX)) == SYSERR ) {
        !            67:                fprintf(stderr,"snap: can't write core header, quitting\n");
        !            68:                close(dev);
        !            69:                return(SYSERR);
        !            70:        }
        !            71: 
        !            72:        /* Add contents of real memory to core image */
        !            73: 
        !            74:        iPkt = 0;
        !            75:        for (p= (char *)0 ; p < (char *)(maxaddr+sizeof(int)) ; p += len) {
        !            76:                if (++iPkt == 25) {
        !            77:                        iPkt = 0;
        !            78:                        putc(stderr, '.');
        !            79:                }
        !            80:                len = (int) maxaddr - (int) p + sizeof(int);
        !            81:                if (len > (unsigned) SNAPSIZ)
        !            82:                        len = SNAPSIZ;
        !            83:                if (write(dev, p, SNAPSIZ) == SYSERR) {
        !            84:                        fprintf(stderr,
        !            85:                                "\nsnap: write error, quitting\n");
        !            86:                        close(dev);
        !            87:                        return(SYSERR);
        !            88:                }
        !            89:        }
        !            90:        putc(stderr, '\n');
        !            91:        close(dev);
        !            92:        return(OK);
        !            93: }

unix.superglobalmegacorp.com

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