From 2f31ea1c82614f1fb2eadae2b21a873d9849a859 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 13 Aug 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-08-13 --- pc/dat.h | 1 + pc/main.c | 17 ++++++++--------- pc/mem.h | 4 ++++ pc/trap.c | 32 +++++++++++++++++++++++++++++++- port/chan.c | 2 +- port/devcons.c | 3 +++ 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/pc/dat.h b/pc/dat.h index 0ccf03e826f138c9a438fd3f7165e14386f03ef3..7c18da9cd489f8f750343770fa3c1e57b229bd02 100644 --- a/pc/dat.h +++ b/pc/dat.h @@ -195,3 +195,4 @@ extern int cpuflag; /* true if this is a CPU */ extern Mach *m; extern Proc *up; extern char filaddr[]; +extern ulong crasharea; diff --git a/pc/main.c b/pc/main.c index 711728e7f6576947886c420fce9fd7401b77c8ce..adf43b795de4321f879d011bb605e9e2177c6579 100644 --- a/pc/main.c +++ b/pc/main.c @@ -31,6 +31,7 @@ char filaddr[NAMELEN]; char *confname[MAXCONF]; char *confval[MAXCONF]; int nconf; +ulong crasharea; /* memory map */ #define MAXMEG 64 @@ -63,6 +64,7 @@ main(void) chandevreset(); swapinit(); userinit(); +conf.npage0 += CRASHSIZE; schedinit(); } @@ -353,7 +355,6 @@ confinit(void) /* * zero memory to set ECC but skip over the kernel * do a quick memory test also - */ if(i != 1){ for(j = 0; j < MB/BY2PG; j += BY2PG){ lp = mapaddr(KZERO|(i*MB+j)); @@ -376,6 +377,7 @@ confinit(void) memset(lp, 0, BY2PG); } } + */ } x += 0x3141526; } @@ -387,16 +389,17 @@ confinit(void) conf.base0 = ktop; for(i = 1; mmap[i] == 'x'; i++) ; - conf.npage0 = (i*MB - ktop)/BY2PG; + conf.npage0 = (i*MB - ktop - CRASHSIZE)/BY2PG; + crasharea = KZERO|(conf.base0 + conf.npage0*BY2PG); conf.topofmem = i*MB; /* - * bank1 usually goes from the end of BOOTARGS to 640k + * bank1 usually goes from the end of BOOTARGS to 640k - crash space */ - conf.base1 = (ulong)(BOOTARGS+BOOTARGSLEN); + conf.base1 = (ulong)(BOOTARGS + BOOTARGSLEN); conf.base1 = PGROUND(conf.base1); conf.base1 = PADDR(conf.base1); - conf.npage1 = (640*1024-conf.base1)/BY2PG; + conf.npage1 = (640*1024 - conf.base1)/BY2PG; /* * if there is a hole in memory (due to a shadow BIOS) make the @@ -568,15 +571,11 @@ procrestore(Proc *p) USED(p); } - /* * the following functions all are slightly different from * PC to PC. */ -/* - * reset the i387 chip - */ void exit(int ispanic) { diff --git a/pc/mem.h b/pc/mem.h index bceb1403bf2682f341549907b0fde717d42c44e7..4e9680c2bc343390eb60768641c71c4ab2422ad8 100644 --- a/pc/mem.h +++ b/pc/mem.h @@ -55,6 +55,10 @@ #define MACHSIZE 4096 +/* + * an area for storing crash info to be picked up later + */ +#define CRASHSIZE (KSTACK+BY2PG) /* * known 80386 segments (in GDT) and their selectors diff --git a/pc/trap.c b/pc/trap.c index 7f4e066d463e615aa3753b2f623919d5df448f6e..14bd520c4df44e25d0e28fb6c45350e6df685a95 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -61,6 +61,19 @@ struct int free; } halloc; +/* + * somewhere to drop crash info + */ +typedef struct +{ + ulong magic; + void *kbot; + void *ksp; + char text[NAMELEN]; + Ureg ureg; + uchar kstack[KSTACK]; +} Crashstate; + void sethvec(int v, void (*r)(void), int type, int pri) { @@ -340,12 +353,20 @@ dumpregs2(Ureg *ur) void dumpregs(Ureg *ur) { + Crashstate *cs; + extern ulong etext; ulong *x; + x = (ulong*)(ur+1); dumpregs2(ur); print(" magic %lux %lux %lux\n", x[0], x[1], x[2]); print(" ur %lux up %lux\n", ur, up); + + /* save crash info */ + print("crasharea 0x%lux\n", crasharea); + cs = (Crashstate*)crasharea; + memmove(&cs->ureg, ur, sizeof(Ureg)); } void @@ -354,13 +375,14 @@ dumpstack(void) ulong l, v, i; extern ulong etext; int lim; + Crashstate *cs; if(up == 0) return; i = 0; lim = 6; - for(l=(ulong)&l; l<(ulong)(up->kstack+BY2PG) && lim; l+=4){ + for(l=(ulong)&l; l<(ulong)(up->kstack+KSTACK) && lim; l+=4){ v = *(ulong*)l; if(KTZERO < v && v < (ulong)&etext){ print("%lux ", v); @@ -373,6 +395,14 @@ dumpstack(void) } } + /* save crash info */ + print("crasharea 0x%lux\n", crasharea); + cs = (Crashstate*)crasharea; + memmove(cs->kstack, up->kstack, KSTACK); + cs->kbot = up->kstack; + memmove(cs->text, up->text, NAMELEN); + cs->magic = 0xdeaddead; + cs->ksp = &l; } /* diff --git a/port/chan.c b/port/chan.c index a0eb28c639a143983ea35918785023c0ac5ee473..419047e7813d2943decbafe057960ecad79eba78 100644 --- a/port/chan.c +++ b/port/chan.c @@ -130,7 +130,7 @@ chanfree(Chan *c) void close(Chan *c) { - if(c == 0 || (c->flag&CFREE)) + if(c->flag&CFREE) panic("close"); if(decref(c)) diff --git a/port/devcons.c b/port/devcons.c index 070cdf90ca591ea1fdb4c2d9327f82cc273e40b5..fd01cc28c67eba6691d983766ce3f085f1fdbd9e 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -214,6 +214,9 @@ echo(Rune r, char *buf, int n) switch(r){ case 0x14: break; /* pass it on */ + case 's': + dumpstack(); + break; case 'x': xsummary(); ixsummary();