void noted(Ureg*, ulong);
+static void debugexc(Ureg*, void*);
static void debugbpt(Ureg*, void*);
static void fault386(Ureg*, void*);
static void doublefault(Ureg*, void*);
irq, tbdf, name);
return;
}
-
- if(tbdf != BUSUNKNOWN && (irq == 0xff || irq == 0)){
- print("intrenable: got unassigned irq %d, tbdf 0x%uX for %s\n",
- irq, tbdf, name);
+ if(tbdf != BUSUNKNOWN && (irq == 0xff || irq == 0))
irq = -1;
- }
+
+ /*
+ * IRQ2 doesn't really exist, it's used to gang the interrupt
+ * controllers together. A device set to IRQ2 will appear on
+ * the second interrupt controller as IRQ9.
+ */
+ if(irq == 2)
+ irq = 9;
if((v = xalloc(sizeof(Vctl))) == nil)
panic("intrenable: out of memory");
iunlock(&vctllock);
}
-int
+void
intrdisable(int irq, void (*f)(Ureg *, void *), void *a, int tbdf, char *name)
{
Vctl **pv, *v;
int vno;
- /*
- * For now, none of this will work with the APIC code,
- * there is no mapping between irq and vector as the IRQ
- * is pretty meaningless.
- */
- if(arch->intrvecno == nil)
- return -1;
- vno = arch->intrvecno(irq);
+ if(irq == 2)
+ irq = 9;
+ if(arch->intrvecno == nil || (tbdf != BUSUNKNOWN && (irq == 0xff || irq == 0))){
+ /*
+ * on APIC machine, irq is pretty meaningless
+ * and disabling a the vector is not implemented.
+ * however, we still want to remove the matching
+ * Vctl entry to prevent calling Vctl.f() with a
+ * stale Vctl.a pointer.
+ */
+ irq = -1;
+ vno = VectorPIC;
+ } else {
+ vno = arch->intrvecno(irq);
+ }
ilock(&vctllock);
- pv = &vctl[vno];
- while (*pv &&
- ((*pv)->irq != irq || (*pv)->tbdf != tbdf || (*pv)->f != f || (*pv)->a != a ||
- strcmp((*pv)->name, name)))
- pv = &((*pv)->next);
- assert(*pv);
-
- v = *pv;
- *pv = (*pv)->next; /* Link out the entry */
-
- if(vctl[vno] == nil && arch->intrdisable != nil)
- arch->intrdisable(irq);
+ do {
+ for(pv = &vctl[vno]; (v = *pv) != nil; pv = &v->next){
+ if(v->isintr && (v->irq == irq || irq == -1)
+ && v->tbdf == tbdf && v->f == f && v->a == a
+ && strcmp(v->name, name) == 0)
+ break;
+ }
+ if(v != nil){
+ *pv = v->next;
+ xfree(v);
+
+ if(irq != -1 && vctl[vno] == nil && arch->intrdisable != nil)
+ arch->intrdisable(irq);
+ break;
+ }
+ } while(irq == -1 && ++vno <= MaxVectorAPIC);
iunlock(&vctllock);
- xfree(v);
- return 0;
}
static long
-irqallocread(Chan*, void *vbuf, long n, vlong offset)
+irqallocread(Chan*, void *a, long n, vlong offset)
{
- char *buf, *p, str[2*(11+1)+KNAMELEN+1+1];
- int m, vno;
- long oldn;
+ char buf[2*(11+1)+KNAMELEN+1+1];
+ int vno, m;
Vctl *v;
if(n < 0 || offset < 0)
error(Ebadarg);
- oldn = n;
- buf = vbuf;
for(vno=0; vno<nelem(vctl); vno++){
for(v=vctl[vno]; v; v=v->next){
- m = snprint(str, sizeof str, "%11d %11d %.*s\n", vno, v->irq, KNAMELEN, v->name);
- if(m <= offset) /* if do not want this, skip entry */
- offset -= m;
- else{
- /* skip offset bytes */
- m -= offset;
- p = str+offset;
- offset = 0;
-
- /* write at most max(n,m) bytes */
- if(m > n)
- m = n;
- memmove(buf, p, m);
- n -= m;
- buf += m;
-
- if(n == 0)
- return oldn;
- }
+ m = snprint(buf, sizeof(buf), "%11d %11d %.*s\n", vno, v->irq, KNAMELEN, v->name);
+ offset -= m;
+ if(offset >= 0)
+ continue;
+ if(n > -offset)
+ n = -offset;
+ offset += m;
+ memmove(a, buf+offset, n);
+ return n;
}
}
- return oldn - n;
+ return 0;
}
void
outb(0x70, 0);
x = inb(0x61) & 0x07; /* Enable NMI */
- outb(0x61, 0x08|x);
+ outb(0x61, 0x0C|x);
outb(0x61, x);
}
* Special traps.
* Syscall() is called directly without going through trap().
*/
+ trapenable(VectorDE, debugexc, 0, "debugexc");
trapenable(VectorBPT, debugbpt, 0, "debugpt");
trapenable(VectorPF, fault386, 0, "fault386");
trapenable(Vector2F, doublefault, 0, "doublefault");
if(0)print("cpu%d: spurious interrupt %d, last %d\n",
m->machno, vno, m->lastintr);
if(0)if(conf.nmach > 1){
- for(i = 0; i < 32; i++){
- if(!(active.machs & (1<<i)))
+ for(i = 0; i < MAXMACH; i++){
+ if(active.machs[i] == 0)
continue;
mach = MACHP(i);
if(m->machno == mach->machno)
* Don't re-enable, it confuses the crash dumps.
nmienable();
*/
- iprint("cpu%d: PC %#8.8lux\n", m->machno, ureg->pc);
+ iprint("cpu%d: nmi PC %#8.8lux, status %ux\n",
+ m->machno, ureg->pc, inb(0x61));
while(m->machno != 0)
;
}
extern void _forkretiret(void);
extern void _rdmsrinst(void);
extern void _wrmsrinst(void);
+ extern void _peekinst(void);
extern void load_fs(ulong);
extern void load_gs(ulong);
ureg->pc += 2;
return;
}
+ } else if(pc == _peekinst){
+ if(vno == VectorGPF){
+ ureg->pc += 2;
+ return;
+ }
}
}
callwithureg(_dumpstack);
}
+static void
+debugexc(Ureg *ureg, void *)
+{
+ u32int dr6, m;
+ char buf[ERRMAX];
+ char *p, *e;
+ int i;
+
+ dr6 = getdr6();
+ if(up == nil)
+ panic("kernel debug exception dr6=%#.8ux", dr6);
+ putdr6(up->dr[6]);
+ if(userureg(ureg))
+ qlock(&up->debug);
+ else if(!canqlock(&up->debug))
+ return;
+ m = up->dr[7];
+ m = (m >> 4 | m >> 3) & 8 | (m >> 3 | m >> 2) & 4 | (m >> 2 | m >> 1) & 2 | (m >> 1 | m) & 1;
+ m &= dr6;
+ if(m == 0){
+ sprint(buf, "sys: debug exception dr6=%#.8ux", dr6);
+ postnote(up, 0, buf, NDebug);
+ }else{
+ p = buf;
+ e = buf + sizeof(buf);
+ p = seprint(p, e, "sys: watchpoint ");
+ for(i = 0; i < 4; i++)
+ if((m & 1<<i) != 0)
+ p = seprint(p, e, "%d%s", i, (m >> i + 1 != 0) ? "," : "");
+ postnote(up, 0, buf, NDebug);
+ }
+ qunlock(&up->debug);
+}
+
static void
debugbpt(Ureg* ureg, void*)
{
if(!user){
if(vmapsync(addr))
return;
+ {
+ extern void _peekinst(void);
+ if((void(*)(void))ureg->pc == _peekinst){
+ ureg->pc += 2;
+ return;
+ }
+ }
if(addr >= USTKTOP)
panic("kernel fault: bad address pc=0x%.8lux addr=0x%.8lux", ureg->pc, addr);
if(up == nil)
insyscall = up->insyscall;
up->insyscall = 1;
- n = fault(addr, read);
+ n = fault(addr, ureg->pc, read);
if(n < 0){
if(!user){
dumpregs(ureg);
return 0;
if(up->fpstate == FPactive){
- fpsave(&up->fpsave);
+ fpsave(up->fpsave);
up->fpstate = FPinactive;
}
up->fpstate |= FPillegal;
memmove(cureg, ureg, sizeof(Ureg));
/* return value of syscall in child */
cureg->ax = 0;
-
- /* Things from bottom of syscall which were never executed */
- p->psstate = 0;
- p->insyscall = 0;
}
/* Give enough context in the ureg to produce a kernel stack for