Annotation of researchv9/jtools/src/pi/kerncore.c, revision 1.1

1.1     ! root        1: #include "process.pri"
        !             2: #include "frame.pri"
        !             3: #include "symtab.pri"
        !             4: #include "symbol.h"
        !             5: #include "hostcore.h"
        !             6: /*#include <sys/reg.h>*/
        !             7: #include "master.pri"
        !             8: SRCFILE("kerncore.c")
        !             9: 
        !            10: #define P0P1_PROG      0x00000000
        !            11: #define P0P1_STCK      0x08000000
        !            12: #define P0P1_SYST      0x0F000000
        !            13: #define P0P1_MASK      0x0F000000
        !            14: #define VPN_MASK       0x00FFE000
        !            15: #define PAGE_MASK      0x00001FFF
        !            16: #define PAGE_SHIFT     13
        !            17: #define PFN_MASK       0x0007FFFF
        !            18: #define FOD_MASK       0x00100000
        !            19: 
        !            20: class Pte {
        !            21: public:
        !            22:        long    e;
        !            23:        long    pfn()           { return e&PFN_MASK;                    }
        !            24:        int     fod()           { return e&FOD_MASK;                    }
        !            25:        int     valid()         { return e<0 || (!fod() && pfn());      }
        !            26:        long    pfntob()        { return pfn()<<PAGE_SHIFT;             }
        !            27: };
        !            28: 
        !            29: char *KernCore::specialop(char *s)
        !            30: {
        !            31:        trace( "%d.specialop(%s)", this, s?s:"0" ); OK(0);
        !            32:        if( !strcmp(s, "pte") )
        !            33:                return "pcb = $";
        !            34:        return 0;
        !            35: }
        !            36: 
        !            37: char *KernCore::special(char *s, long addr)
        !            38: {
        !            39:        trace("%d.special(%s,0x%X)", this, s?s:"0", loc); OK(0);
        !            40:        IF_LIVE(strcmp(s, "pte")) return 0;
        !            41:        char *error = getpcb(peek(addr)->lng);
        !            42:        if( !error )
        !            43:                _process->habeascorpus(PENDING, 0);
        !            44:        return error;
        !            45: }
        !            46: 
        !            47: char *KernCore::getpcb(long addr)
        !            48: {
        !            49:        trace("%d.getpcb(0x%X)", this, addr);   OK("KernCore::getpcb");
        !            50:        lseek(corefd, pcb_loc = (addr&PFN_MASK)<<PAGE_SHIFT, 0);
        !            51:        if( !ReadOK(corefd, (char*)&pcb_copy, sizeof pcb_copy) )
        !            52:                return "can't read pcb";
        !            53:        pcb_copy.pcb_p0lr &= ~AST_CLR;
        !            54:        return 0;
        !            55: }
        !            56: 
        !            57: char *KernCore::open()
        !            58: {
        !            59:        trace("%d.open() %d", this, _process); OK("KernCore::open");
        !            60:        int mode = 2;
        !            61:        while( corefd<0 && mode>=0 )
        !            62:                corefd = ::open(procpath(), mode--);
        !            63:        if( corefstat() )
        !            64:                return SysErr("core image: " );
        !            65:        if( stabpath() ){
        !            66:                stabfd = ::open(stabpath(),0);
        !            67:                if( stabfd<0 ) return SysErr( "symbol tables: " );
        !            68:        }
        !            69:        _online = 0;
        !            70:        stabfstat();
        !            71:        if( stabfd >= 0 ) _symtab = 0;          /* don't inherit /unix */
        !            72: #ifdef V9
        !            73:        _symtab = new Ed8SymTab(this, stabfd, _symtab);
        !            74: #else
        !            75:        _symtab = new BsdSymTab(this, stabfd, _symtab);
        !            76: #endif
        !            77:        _symtab->read();
        !            78:        static char *id[3] = { "Sysmap",  "Syssize",  "intstack" };
        !            79:        static char *_id[3]= { "_Sysmap", "_Syssize", "_intstack" };
        !            80:        Symbol *glb[4];
        !            81:        SSet glbfun(U_GLB,  U_FUNC);
        !            82:        for( int i = 0; i <= 2; ++i )
        !            83:                if( !(glb[i] = _symtab->idtosym(glbfun,  id[i]))
        !            84:                 && !(glb[i] = _symtab->idtosym(glbfun, _id[i])) )
        !            85:                        return sf("not found: %s", id[i]);
        !            86:        sbr = glb[0]->range.lo;
        !            87:        slr = glb[1]->range.lo;
        !            88:        intstack = glb[2]->range.lo;
        !            89: //     char *error = getpcb(peek(glb[2]->range.lo&~P0P1_SYST)->lng);
        !            90: //     if( error ) return error;
        !            91:        return readcontrol();
        !            92: }
        !            93: 
        !            94: char *KernCore::readcontrol()
        !            95: {
        !            96:        trace( "%d.readcontrol()", this ); OK("KernCore::readcontrol()");
        !            97:        if( corefstat() )
        !            98:                return "cannot fstat core image";
        !            99:        return 0;
        !           100: }
        !           101: 
        !           102: Behavs KernCore::behavs()
        !           103: {
        !           104:        trace( "%d.behavs()", this );   OK(ERRORED);
        !           105:        char *error = readcontrol();
        !           106:        if( error ){
        !           107:                behavs_problem = sf( "readcontrol(): %s", error );
        !           108:                return ERRORED;
        !           109:        }
        !           110:        return PENDING;
        !           111: }
        !           112: 
        !           113: char *KernCore::eventname()
        !           114: {
        !           115:        OK("eventname");
        !           116:        return
        !           117:        sf("sbr=0x%X slr=0x%X p0br=0x%X p0lr=0x%X p1br=0x%X p1lr=0x%X",
        !           118:        sbr, slr,
        !           119:        pcb_copy.pcb_p0br, pcb_copy.pcb_p0lr, pcb_copy.pcb_p1br, pcb_copy.pcb_p1lr
        !           120:        );
        !           121: }
        !           122: 
        !           123: int KernCore::event()          { return 0; }           /* ever called? */
        !           124: 
        !           125: char *KernCore::seekto(int&, long &addr, int&)
        !           126: {
        !           127:        trace("%d.seekto(%d,0x%X,%d)", this, addr); OK("seekto");
        !           128:        Pte p;
        !           129:        long page = (addr&VPN_MASK)>>PAGE_SHIFT, po = addr&PAGE_MASK;
        !           130:        switch( addr & P0P1_MASK ){
        !           131: //     case P0P1_STCK:
        !           132: //             if( page < pcb_copy.pcb_p1lr )
        !           133: //                     return "page < p1lr";
        !           134: //             addr = (long)(pcb_copy.pcb_p1br+page);
        !           135: //             if( !(addr&P0P1_SYST) )
        !           136: //                     return "user stack page table error";
        !           137: //             seekto(0, addr, 0);
        !           138: //             p.e = peek(addr)->lng;
        !           139: //             if( !p.valid() )
        !           140: //                     return "invalid page table entry";
        !           141: //             addr = p.pfntob() + po;
        !           142: //             break;
        !           143:        case P0P1_SYST:
        !           144:                if( page > slr )
        !           145:                        return "page > slr";
        !           146:                p.e = peek((sbr+page*4)&~P0P1_SYST)->lng;
        !           147:                if( !p.valid() )
        !           148:                        return "invalid page table entry";
        !           149:                addr = p.pfntob() + po;
        !           150:                break;
        !           151:        }
        !           152:        return 0;
        !           153: }
        !           154: 
        !           155: long KernCore::regloc(int ,int)
        !           156: {
        !           157: //     return pcb_loc + ((long)(&pcb_copy.pcb_r0) - (long)&pcb_copy) + 4*r;
        !           158:        return 0;
        !           159: }
        !           160: 
        !           161: long KernCore::pc()
        !           162: {
        !           163: //     return pcb_copy.pcb_pc;
        !           164:        return 0;
        !           165: }
        !           166: 
        !           167: long KernCore::fp()
        !           168: {
        !           169:        if (cs_fp)
        !           170:                return cs_fp;
        !           171:        return 0;
        !           172: //     Cslfd *cp = peek(intstack-4);
        !           173: //     return cp ? cp->lng : 0;
        !           174: }
        !           175: 
        !           176: int KernCore::instack(long curfp, long prevfp )
        !           177: {
        !           178:        return curfp && (curfp>prevfp);
        !           179: }

unix.superglobalmegacorp.com

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