From 88e95ba5cdd3e4873d0fb665f3fcc3bac96f8a26 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 22 Feb 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-02-22 --- gnot/fns.h | 1 + pc/fns.h | 3 ++- pc/kbd.c | 12 ++++++++---- port/portdat.h | 1 + port/stream.c | 7 +++++-- gnot/lock.c => port/taslock.c | 14 ++++++++------ power/fns.h | 2 +- power/l.s | 2 +- power/lock.c | 8 ++++---- ss/fns.h | 3 ++- ss/l.s | 2 +- 11 files changed, 34 insertions(+), 21 deletions(-) rename gnot/lock.c => port/taslock.c (75%) diff --git a/gnot/fns.h b/gnot/fns.h index 8201663f09f661b886b7a1542f73e0a5318f00d5..35b7a4116f8b2df1a30cc2c5efb186ec311318d2 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -61,3 +61,4 @@ int tas(char*); void touser(void); #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) #define kmapperm(x) kmap(x) +#define getcallerpc(x) (*(ulong*)(x)) diff --git a/pc/fns.h b/pc/fns.h index 91f965c32383b8120e9ec02efa0039aee23acdcc..190e708c77394d6777161cfd99803ad32e9628f0 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -57,9 +57,10 @@ void setvec(int, void (*)(Ureg*)); void systrap(void); void touser(void); void trapinit(void); -int tas(Lock*); +int tas(void*); void uartclock(void); void uartintr0(Ureg*); void vgainit(void); #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) #define kmapperm(x) kmap(x) +#define getcallerpc(x) (*(ulong*)(x)) diff --git a/pc/kbd.c b/pc/kbd.c index b33f7dae14121321992b09759df7a54329369d94..3a9e905a1a4cd02a65a68204295001933e56da6b 100644 --- a/pc/kbd.c +++ b/pc/kbd.c @@ -296,8 +296,8 @@ middle(int newval) /* * keyboard interrupt */ -void -kbdintr(Ureg *ur) +int +kbdintr0(void) { int s, c, i, nk, nc; static int esc1, esc2; @@ -309,8 +309,6 @@ kbdintr(Ureg *ur) static uchar kc[5]; int keyup; - USED(ur); - /* * get status */ @@ -450,3 +448,9 @@ dochar: kbdputc(&kbdq, c); return 0; } + +void +kbdintr(Ureg *ur) +{ + kbdintr0(); +} diff --git a/port/portdat.h b/port/portdat.h index 424b88d527d1ffd86c060b680b676e475ee5e46a..0e4d84eff625ee98d066e769985c7279ef1f51cb 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -107,6 +107,7 @@ struct Block uchar *base; /* start of the buffer */ uchar flags; uchar type; + ulong pc; /* pc of caller */ }; struct Blist { diff --git a/port/stream.c b/port/stream.c index b1fc0130e4f535d5ca20846bf96715391bbddcc7..37282a91964d23f23108d544147401928615a0f9 100644 --- a/port/stream.c +++ b/port/stream.c @@ -235,9 +235,12 @@ freeb(Block *bp) Block *nbp; Bclass *bcp; int x; + ulong pc; - if((bp->flags&S_CLASS) >= Nclass) - panic("freeb class"); + pc = getcallerpc(((uchar*)&bp) - sizeof(bp)); + if((bp->flags&S_CLASS) >= Nclass) /* Check for double free */ + panic("freeb class last(%lux) this(%lux)", bp->pc, pc); + bp->pc = pc; for(; bp; bp = nbp){ bcp = &bclass[bp->flags & S_CLASS]; diff --git a/gnot/lock.c b/port/taslock.c similarity index 75% rename from gnot/lock.c rename to port/taslock.c index d4b2281c89dc9c4b3d7eac9570a4998fa9a7c01d..845206bfe99f202df6e3b318ed7fc370dd61e157 100644 --- a/gnot/lock.c +++ b/port/taslock.c @@ -5,18 +5,20 @@ #include "fns.h" #include "../port/error.h" -#define PCOFF -1 - void lock(Lock *l) { + Lock *ll = l; int i; + ulong pc; + + pc = getcallerpc(((uchar*)&l) - sizeof(l)); for(i = 0; i < 1000000; i++){ - if (tas(&l->key) == 0){ + if (tas(&ll->key) == 0){ if(u) u->p->hasspin = 1; - l->pc = ((ulong*)&l)[PCOFF]; + ll->pc = pc; return; } if(u && u->p->state == Running) @@ -26,7 +28,7 @@ lock(Lock *l) l->key = 0; panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n", l, i, - ((ulong*)&l)[PCOFF], l->pc); + pc, l->pc); } int @@ -34,7 +36,7 @@ canlock(Lock *l) { if(tas(&l->key)) return 0; - l->pc = ((ulong*)&l)[PCOFF]; + l->pc = getcallerpc(((uchar*)&l) - sizeof(l)); if(u && u->p) u->p->hasspin = 1; return 1; diff --git a/power/fns.h b/power/fns.h index 94b566da0810a4b37fae001f2da09497d9cab9fa..6f889924fb87ba2348a1b4c5e50c535b15aa25ef 100644 --- a/power/fns.h +++ b/power/fns.h @@ -25,7 +25,7 @@ void flushmmu(void); void gettlb(int, ulong*); ulong gettlbvirt(int); void gotopc(ulong); -ulong getcallerpc(void); +ulong getcallerpc(void*); void icflush(void *, ulong); void ioboardinit(void); void intr(Ureg*); diff --git a/power/l.s b/power/l.s index a2c5c9298d50ae2d41e3b4c6fd163a7a652cd081..5f5bcb95548322c4cd32f37479042511cb3a3862 100644 --- a/power/l.s +++ b/power/l.s @@ -151,7 +151,7 @@ TEXT gotolabel(SB), $-4 TEXT getcallerpc(SB), $0 - MOVW (SP), R1 + MOVW 4(SP), R1 RET TEXT gotopc(SB), $8 diff --git a/power/lock.c b/power/lock.c index 0cec3d0aae4bbe8bb9de09eb0e9e3c51a6c373d7..106245883efe61f9d7e512c9f6b2ae04176c78a4 100644 --- a/power/lock.c +++ b/power/lock.c @@ -132,16 +132,16 @@ lock(Lock *l) * Try the fast grab first */ if((*sbsem&1) == 0){ - l->pc = getcallerpc(); + l->pc = getcallerpc(l); return; } for(i=0; i<10000000; i++) if((*sbsem&1) == 0){ - l->pc = getcallerpc(); + l->pc = getcallerpc(l); return; } *sbsem = 0; - print("lock loop %lux pc %lux held by pc %lux\n", l, getcallerpc(), l->pc); + print("lock loop %lux pc %lux held by pc %lux\n", l, getcallerpc(l), l->pc); dumpstack(); } @@ -168,7 +168,7 @@ canlock(Lock *l) } if(*sbsem & 1) return 0; - l->pc = getcallerpc(); + l->pc = getcallerpc(l); return 1; } diff --git a/ss/fns.h b/ss/fns.h index d22d3b0feb903df2a3ef4d69b6addd704b15c8bd..1e98b5b154c5b9bfaea58d7116778fb074b9f667 100644 --- a/ss/fns.h +++ b/ss/fns.h @@ -61,9 +61,10 @@ void screeninit(void); void screenputc(int); void screenputs(char*, int); void spldone(void); -ulong swap1(ulong*); +ulong tas(ulong*); void touser(ulong); void trap(Ureg*); void trapinit(void); #define wbflush() /* mips compatibility */ #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) +#define getcallerpc(x) (*(ulong*)(x)) diff --git a/ss/l.s b/ss/l.s index 9b5a246808f18b796043b4a0e2636003df9abef4..27065a9b57630e7379f8ae7ef1e4ae3c63a3ed1a 100644 --- a/ss/l.s +++ b/ss/l.s @@ -55,7 +55,7 @@ TEXT startvirt(SB), $-4 MOVW (R0), R0 RETURN -TEXT swap1(SB), $0 +TEXT tas(SB), $0 TAS (R7), R7 /* LDSTUB, thank you ken */ RETURN