1: static char sccsid[] = "@(#)access.c 4.2 8/17/82"; 2: # 3: /* 4: * 5: * UNIX debugger 6: * 7: */ 8: 9: #include "head.h" 10: struct user u; 11: 12: 13: MSG BADDAT; 14: MSG BADTXT; 15: MAP txtmap; 16: MAP datmap; 17: STRING errflg; 18: int errno; 19: 20: INT pid; 21: 22: 23: 24: 25: /* file handling and access routines */ 26: 27: int dmask[5] = {0, 0xff, 0xffff, 0xffffff, 0xffffffff}; 28: 29: /* get data at loc using descriptor format d */ 30: long 31: getval(loc, d, space) 32: ADDR loc; 33: char d; { 34: register int val; 35: 36: val = get(loc, space); 37: val &= dmask[dtol(d)]; 38: return(val); 39: } 40: 41: /* put value at loc using descriptor format d */ 42: putval(loc, d, value) 43: ADDR loc; char d; long value; { 44: register long val; 45: 46: val = get(loc, DSP); 47: val = (val & !dmask[dtol(d)]) | (value & dmask[dtol(d)]); 48: put(loc, DSP, val); 49: } 50: 51: /* put value in named register using descriptor format d */ 52: putreg(reg, d, value) 53: ADDR reg; char d; long value; { 54: register long val; 55: 56: val = *(ADDR *)(((ADDR)&u)+R0+WORDSIZE*reg); 57: val = (val & !dmask[dtol(d)]) | (value & dmask[dtol(d)]); 58: *(ADDR *)(((ADDR)&u)+R0+WORDSIZE*reg) = val; 59: } 60: 61: put(adr,space,value) 62: L_INT adr; 63: { 64: access(WT,adr,space,value); 65: } 66: 67: POS get(adr, space) 68: L_INT adr; 69: { 70: return(access(RD,adr,space,0)); 71: } 72: 73: 74: access(mode,adr,space,value) 75: L_INT adr; 76: { 77: INT pmode,rd,file; 78: ADDR w; 79: if (debug) 80: printf("access(mode=%d,adr=%d,space=%d,value=%d) with pid %d\n", 81: mode, adr, space, value, pid); 82: rd = mode==RD; 83: 84: IF space == NSP THEN return(0); FI 85: 86: IF pid /* tracing on? */ 87: THEN 88: #ifndef vax 89: IF adr&01 ANDF !rd THEN error(ODDADR); FI 90: #endif 91: pmode = (space&DSP?(rd?RDUSER:WDUSER):(rd?RIUSER:WIUSER)); 92: w = ptrace(pmode, pid, adr, value); 93: if (debug) 94: printf("ptrace(%d,%d,%d,%d) = %d with error=%d\n", 95: pmode, pid, adr, value, w, errno); 96: #ifndef vax 97: IF adr&01 98: THEN w1 = ptrace(pmode, pid, shorten(adr+1), value); 99: w = (w>>8)&LOBYTE | (w1<<8); 100: FI 101: #endif 102: IF errno 103: THEN errflg = (space&DSP ? BADDAT : BADTXT); 104: FI 105: return(w); 106: FI 107: w = 0; 108: IF !chkmap(&adr,space) 109: THEN return(0); 110: FI 111: file=(space&DSP?datmap.ufd:txtmap.ufd); 112: if (longseek(file,adr)==0 || 113: (rd ? read(file,&w,sizeof(w)) : write(file,&value,sizeof(w))) < 1) 114: errflg=(space&DSP?BADDAT:BADTXT); 115: return(w); 116: 117: } 118: 119: chkmap(adr,space) 120: REG L_INT *adr; 121: REG INT space; 122: { 123: REG MAPPTR amap; 124: amap=((space&DSP?&datmap:&txtmap)); 125: IF space&STAR ORF !within(*adr,amap->b1,amap->e1) 126: THEN if (within(*adr,amap->b2,amap->e2)) 127: *adr += (amap->f2)-(amap->b2); 128: else { 129: errflg=(space&DSP?BADDAT:BADTXT); return(0); 130: } 131: ELSE *adr += (amap->f1)-(amap->b1); 132: FI 133: return(1); 134: } 135: 136: within(adr,lbd,ubd) 137: POS adr, lbd, ubd; 138: { 139: return(adr>=lbd && adr<ubd); 140: } 141: 142: /* ------------ */ 143: POS chkget(n, space) 144: L_INT n; 145: { 146: #ifndef vax 147: REG INT w; 148: #else 149: REG L_INT w; 150: #endif 151: 152: w = get(n, space); 153: chkerr(); 154: return(w); 155: } 156: 157: POS bchkget(n, space) 158: L_INT n; 159: { 160: return(chkget(n, space) & LOBYTE); 161: }