| plan 9 kernel history: overview | file list | diff list |
1991/0720/pc/trap.c (diff list | history)
| 1991/0613/sys/src/9/pc/trap.c:43,49 – 1991/0614/sys/src/9/pc/trap.c:43,49 (short | long) | ||
| 1991/0613 | }; /* | |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0613 | */ Segdesc ilt[256] = { | |
| 1991/0613/sys/src/9/pc/trap.c:63,65 – 1991/0614/sys/src/9/pc/trap.c:63,84 | ||
| 1991/0613 | [Efault] TRAPGATE(KESEL, efault, 3), [Eco] TRAPGATE(KESEL, eco, 3), }; | |
| 1991/0614 | /* * trap table */ uchar traptab[4096]; /* * set up some basic vectored interrupts */ trapinit( /* * j-random uncaught trap or interrupt */ void trap(void) { panic("unknown trap"); } | |
| 1991/0614/sys/src/9/pc/trap.c:70,80 – 1991/0625/sys/src/9/pc/trap.c:70,75 (short | long) | ||
| 1991/0614 | uchar traptab[4096]; /* | |
| 1991/0625/sys/src/9/pc/trap.c:4,79 – 1991/0703/sys/src/9/pc/trap.c:4,99 (short | long) | ||
| 1991/0613 | #include "dat.h" #include "fns.h" #include "io.h" | |
| 1991/0703 | #include "ureg.h" | |
| 1991/0613 |
| |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0613 | */ | |
| 1991/0703 | Segdesc ilt[256]; void (*ivec[256])(void*); void sethvec(int v, void (*r)(void), int type) | |
| 1991/0613 | { | |
| 1991/0703 | ilt[v].d0 = ((ulong)r)&0xFFFF|(KESEL<<16); ilt[v].d1 = ((ulong)r)&0xFFFF0000|SEGP|SEGPL(3)|type; } | |
| 1991/0614 | ||
| 1991/0703 | void setvec(int v, void (*r)(void*), int type) { ilt[v].d1 &= ~SEGTYPE; ilt[v].d1 |= type; ivec[v] = r; } | |
| 1991/0614 | /* | |
| 1991/0703 | * set up the interrupt/trap gates | |
| 1991/0614 | */ | |
| 1991/0703 | void trapinit(void) { int i; | |
| 1991/0614 | ||
| 1991/0703 | /* * set the standard traps */ sethvec(0, intr0, SEGTG); sethvec(1, intr1, SEGTG); sethvec(2, intr2, SEGTG); sethvec(3, intr3, SEGTG); sethvec(4, intr4, SEGTG); sethvec(5, intr5, SEGTG); sethvec(6, intr6, SEGTG); sethvec(7, intr7, SEGTG); sethvec(8, intr8, SEGTG); sethvec(9, intr9, SEGTG); sethvec(10, intr10, SEGTG); sethvec(11, intr11, SEGTG); sethvec(12, intr12, SEGTG); sethvec(13, intr13, SEGTG); sethvec(14, intr14, SEGTG); sethvec(15, intr15, SEGTG); sethvec(16, intr16, SEGTG); /* * set all others to unknown */ for(i = 17; i < 256; i++) sethvec(i, intrbad, SEGIG); /* * tell the hardware where the table is (and how long) */ lidt(ilt, sizeof(ilt)); } | |
| 1991/0614 | /* | |
| 1991/0703 | * All traps | |
| 1991/0614 | */ | |
| 1991/0703 | trap(Ureg *ur) | |
| 1991/0614 | { | |
| 1991/0703 | print("trap %lux\n", ur->trap); print(" edi %lux\n", ur->edi); print(" esi %lux\n", ur->esi); print(" ebp %lux\n", ur->ebp); print(" esp %lux\n", ur->esp); print(" ebx %lux\n", ur->ebx); print(" edx %lux\n", ur->edx); print(" ecx %lux\n", ur->ecx); print(" eax %lux\n", ur->eax); print(" ds %lux\n", ur->ds); print(" trap %lux\n", ur->trap); print(" ecode %lux\n", ur->ecode); print(" eip %lux\n", ur->eip); print(" cs %lux\n", ur->cs); print(" eflags %lux\n", ur->eflags); print(" oesp %lux\n", ur->oesp); print(" ss %lux\n", ur->ss); delay(500); if(ur->trap>=256 || ivec[ur->trap] == 0) panic("bad trap type %d\n", ur->trap); (*ivec[ur->trap])(ur); | |
| 1991/0614 | } | |
| 1991/0703/sys/src/9/pc/trap.c:66,71 – 1991/0704/sys/src/9/pc/trap.c:66,85 (short | long) | ||
| 1991/0703 | * tell the hardware where the table is (and how long) */ lidt(ilt, sizeof(ilt)); | |
| 1991/0704 | /* * Set up the 8259 interrupt processor #1. * Make 8259 interrupts starting at vector I8259vec. * * N.B. This is all magic to me. It comes from the * IBM technical reference manual. I just * changed the vector. */ outb(I8259ctl, 0x11); /* ICW1 - edge, master, ICW4 */ outb(I8259aux, I8259vec); /* ICW2 - interrupt vector */ outb(I8259aux, 0x04); /* ICW3 - master level 2 */ outb(I8259aux, 0x01); /* ICW4 - master, 8086 mode */ outb(I8259aux, 0x00); /* mask - all enabled */ | |
| 1991/0703 | } | |
| 1991/0704/sys/src/9/pc/trap.c:75,85 – 1991/0705/sys/src/9/pc/trap.c:75,85 (short | long) | ||
| 1991/0704 | * IBM technical reference manual. I just * changed the vector. */ | |
| 1991/0705 | outb(Int0ctl, 0x11); /* ICW1 - edge, master, ICW4 */ outb(Int0aux, Int0vec); /* ICW2 - interrupt vector */ outb(Int0aux, 0x04); /* ICW3 - master level 2 */ outb(Int0aux, 0x01); /* ICW4 - master, 8086 mode */ outb(Int0aux, 0x00); /* mask - all enabled */ | |
| 1991/0703 | } | |
| 1991/0705/sys/src/9/pc/trap.c:20,26 – 1991/0706/sys/src/9/pc/trap.c:20,26 (short | long) | ||
| 1991/0703 | } | |
| 1991/0614 | ||
| 1991/0703 | void | |
| 1991/0706 | setvec(int v, void (*r)(Ureg*), int type) | |
| 1991/0703 | { ilt[v].d1 &= ~SEGTYPE; ilt[v].d1 |= type; | |
| 1991/0705/sys/src/9/pc/trap.c:55,65 – 1991/0706/sys/src/9/pc/trap.c:55,72 | ||
| 1991/0703 | sethvec(14, intr14, SEGTG); sethvec(15, intr15, SEGTG); sethvec(16, intr16, SEGTG); | |
| 1991/0706 | sethvec(17, intr17, SEGTG); sethvec(18, intr18, SEGTG); sethvec(19, intr19, SEGTG); sethvec(20, intr20, SEGTG); sethvec(21, intr21, SEGTG); sethvec(22, intr22, SEGTG); sethvec(23, intr23, SEGTG); | |
| 1991/0703 | /* * set all others to unknown */ | |
| 1991/0706 | for(i = 24; i < 256; i++) | |
| 1991/0703 | sethvec(i, intrbad, SEGIG); /* | |
| 1991/0705/sys/src/9/pc/trap.c:88,113 – 1991/0706/sys/src/9/pc/trap.c:95,103 | ||
| 1991/0614 | */ | |
| 1991/0703 | trap(Ureg *ur) | |
| 1991/0614 | { | |
| 1991/0703 |
| |
| 1991/0706 | INT0ENABLE; | |
| 1991/0614 | } | |
| 1991/0706/sys/src/9/pc/trap.c:7,12 – 1991/0709/sys/src/9/pc/trap.c:7,28 (short | long) | ||
| 1991/0703 | #include "ureg.h" | |
| 1991/0613 | /* | |
| 1991/0709 | * 8259 interrupt controllers */ enum { Int0ctl= 0x20, /* control port (ICW1, OCW2, OCW3) */ Int0aux= 0x21, /* everything else (ICW2, ICW3, ICW4, OCW1) */ Int1ctl= 0xA0, /* control port */ Int1aux= 0xA1, /* everything else (ICW2, ICW3, ICW4, OCW1) */ EOI= 0x20, /* non-specific end of interrupt */ }; int int0mask = 7; /* interrupts enabled for first 8259 */ int int1mask = 7; /* interrupts enabled for second 8259 */ /* | |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0613 | */ | |
| 1991/0703 | Segdesc ilt[256]; | |
| 1991/0706/sys/src/9/pc/trap.c:25,30 – 1991/0709/sys/src/9/pc/trap.c:41,54 | ||
| 1991/0703 | ilt[v].d1 &= ~SEGTYPE; ilt[v].d1 |= type; ivec[v] = r; | |
| 1991/0709 | /* * enable corresponding interrupt in 8259 */ if((v&~0x7) == Int0vec){ int0mask &= ~(1<<(v&7)); outb(Int0aux, int0mask); } | |
| 1991/0703 | } | |
| 1991/0614 | /* | |
| 1991/0706/sys/src/9/pc/trap.c:75,95 – 1991/0709/sys/src/9/pc/trap.c:99,116 | ||
| 1991/0703 | lidt(ilt, sizeof(ilt)); | |
| 1991/0704 | /* | |
| 1991/0709 | * Set up the first 8259 interrupt processor. * Make 8259 interrupts start at CPU vector Int0vec. * Set the 8259 as master with edge triggered * input with fully nested interrupts. | |
| 1991/0704 | */ | |
| 1991/0705 |
| |
| 1991/0709 | outb(Int0ctl, 0x11); /* ICW1 - edge triggered, master, ICW4 will be sent */ outb(Int0aux, Int0vec); /* ICW2 - interrupt vector offset */ | |
| 1991/0705 | outb(Int0aux, 0x04); /* ICW3 - master level 2 */ | |
| 1991/0709 | outb(Int0aux, 0x01); /* ICW4 - 8086 mode, not buffered */ | |
| 1991/0703 | } | |
| 1991/0614 | /* | |
| 1991/0703 | * All traps | |
| 1991/0614 | */ | |
| 1991/0706/sys/src/9/pc/trap.c:98,103 – 1991/0709/sys/src/9/pc/trap.c:119,132 | ||
| 1991/0703 | if(ur->trap>=256 || ivec[ur->trap] == 0) panic("bad trap type %d\n", ur->trap); | |
| 1991/0709 | /* * call the trap routine */ | |
| 1991/0703 | (*ivec[ur->trap])(ur); | |
| 1991/0706 |
| |
| 1991/0709 | /* * tell the 8259 that we're done with the * highest level interrupt */ outb(Int0ctl, EOI); | |
| 1991/0614 | } | |
| 1991/0709/sys/src/9/pc/trap.c:29,38 – 1991/0710/sys/src/9/pc/trap.c:29,38 (short | long) | ||
| 1991/0703 | void (*ivec[256])(void*); void | |
| 1991/0710 | sethvec(int v, void (*r)(void), int type, int pri) | |
| 1991/0613 | { | |
| 1991/0703 | ilt[v].d0 = ((ulong)r)&0xFFFF|(KESEL<<16); | |
| 1991/0710 | ilt[v].d1 = ((ulong)r)&0xFFFF0000|SEGP|SEGPL(pri)|type; | |
| 1991/0703 | } | |
| 1991/0614 | ||
| 1991/0703 | void | |
| 1991/0709/sys/src/9/pc/trap.c:62,99 – 1991/0710/sys/src/9/pc/trap.c:62,105 | ||
| 1991/0703 | /* * set the standard traps */ | |
| 1991/0706 |
| |
| 1991/0710 | sethvec(0, intr0, SEGTG, 0); sethvec(1, intr1, SEGTG, 0); sethvec(2, intr2, SEGTG, 0); sethvec(3, intr3, SEGTG, 0); sethvec(4, intr4, SEGTG, 0); sethvec(5, intr5, SEGTG, 0); sethvec(6, intr6, SEGTG, 0); sethvec(7, intr7, SEGTG, 0); sethvec(8, intr8, SEGTG, 0); sethvec(9, intr9, SEGTG, 0); sethvec(10, intr10, SEGTG, 0); sethvec(11, intr11, SEGTG, 0); sethvec(12, intr12, SEGTG, 0); sethvec(13, intr13, SEGTG, 0); sethvec(14, intr14, SEGTG, 0); sethvec(15, intr15, SEGTG, 0); sethvec(16, intr16, SEGTG, 0); sethvec(17, intr17, SEGTG, 0); sethvec(18, intr18, SEGTG, 0); sethvec(19, intr19, SEGTG, 0); sethvec(20, intr20, SEGTG, 0); sethvec(21, intr21, SEGTG, 0); sethvec(22, intr22, SEGTG, 0); sethvec(23, intr23, SEGTG, 0); | |
| 1991/0703 | /* * set all others to unknown */ | |
| 1991/0706 | for(i = 24; i < 256; i++) | |
| 1991/0703 |
| |
| 1991/0710 | sethvec(i, intrbad, SEGIG, 0); | |
| 1991/0703 | /* | |
| 1991/0710 | * system calls */ sethvec(64, intr64, SEGTG, 3); /* setvec(64, syscall, SEGTG); /**/ /* | |
| 1991/0703 | * tell the hardware where the table is (and how long) */ lidt(ilt, sizeof(ilt)); | |
| 1991/0709/sys/src/9/pc/trap.c:114,119 – 1991/0710/sys/src/9/pc/trap.c:120,126 | ||
| 1991/0614 | /* | |
| 1991/0703 | * All traps | |
| 1991/0614 | */ | |
| 1991/0710 | void | |
| 1991/0703 | trap(Ureg *ur) | |
| 1991/0614 | { | |
| 1991/0703 | if(ur->trap>=256 || ivec[ur->trap] == 0) | |
| 1991/0709/sys/src/9/pc/trap.c:129,132 – 1991/0710/sys/src/9/pc/trap.c:136,171 | ||
| 1991/0709 | * highest level interrupt */ outb(Int0ctl, EOI); | |
| 1991/0710 | } /* * system calls */ long syscall(Ureg *ur) { panic("syscall"); } #include "errstr.h" void error(int code) { strncpy(u->error, errstrtab[code], ERRLEN); nexterror(); } void errors(char *err) { strncpy(u->error, err, ERRLEN); nexterror(); } void nexterror(void) { gotolabel(&u->errlab[--u->nerrlab]); | |
| 1991/0614 | } | |
| 1991/0710/sys/src/9/pc/trap.c:124,130 – 1991/0711/sys/src/9/pc/trap.c:124,130 (short | long) | ||
| 1991/0703 | trap(Ureg *ur) | |
| 1991/0614 | { | |
| 1991/0703 | if(ur->trap>=256 || ivec[ur->trap] == 0) | |
| 1991/0711 | panic("bad trap type %d %lux\n", ur->trap, ur->pc); | |
| 1991/0703 | ||
| 1991/0709 | /* * call the trap routine | |
| 1991/0710/sys/src/9/pc/trap.c:147,171 – 1991/0711/sys/src/9/pc/trap.c:147,159 | ||
| 1991/0710 | panic("syscall"); } | |
| 1991/0711 | dumpstack(void) | |
| 1991/0710 | { | |
| 1991/0711 | execpc(ulong entry) | |
| 1991/0710 | { | |
| 1991/0711 | ((Ureg*)UREGADDR)->pc = entry; | |
| 1991/0614 | } | |
| 1991/0711/sys/src/9/pc/trap.c:36,45 – 1991/0716/sys/src/9/pc/trap.c:36,43 (short | long) | ||
| 1991/0703 | } | |
| 1991/0614 | ||
| 1991/0703 | void | |
| 1991/0706 |
| |
| 1991/0716 | setvec(int v, void (*r)(Ureg*)) | |
| 1991/0703 | { | |
| 1991/0709 | /* | |
| 1991/0711/sys/src/9/pc/trap.c:97,103 – 1991/0716/sys/src/9/pc/trap.c:95,101 | ||
| 1991/0710 | * system calls */ sethvec(64, intr64, SEGTG, 3); | |
| 1991/0716 | setvec(64, (void (*)(Ureg*))syscall); | |
| 1991/0710 | /* | |
| 1991/0703 | * tell the hardware where the table is (and how long) | |
| 1991/0716/sys/src/9/pc/trap.c:86,92 – 1991/0718/sys/src/9/pc/trap.c:86,92 (short | long) | ||
| 1991/0710 | sethvec(23, intr23, SEGTG, 0); | |
| 1991/0703 | /* | |
| 1991/0718 | * set all others to unknown interrupts | |
| 1991/0703 | */ | |
| 1991/0706 | for(i = 24; i < 256; i++) | |
| 1991/0710 | sethvec(i, intrbad, SEGIG, 0); | |
| 1991/0716/sys/src/9/pc/trap.c:100,106 – 1991/0718/sys/src/9/pc/trap.c:100,106 | ||
| 1991/0710 | /* | |
| 1991/0703 | * tell the hardware where the table is (and how long) */ | |
| 1991/0718 | putidt(ilt, sizeof(ilt)); | |
| 1991/0704 | /* | |
| 1991/0709 | * Set up the first 8259 interrupt processor. | |
| 1991/0716/sys/src/9/pc/trap.c:137,147 – 1991/0718/sys/src/9/pc/trap.c:137,169 | ||
| 1991/0710 | } /* | |
| 1991/0718 | * dump registers */ void dumpregs(Ureg *ur) { if(u) print("registers for %s %d\n", u->p->text, u->p->pid); else print("registers for kernel\n"); print("FLAGS=%lux ECODE=%lux CS=%lux PC=%lux SS=%lux USP=%lux\n", ur->flags, ur->ecode, ur->cs, ur->pc, ur->ss, ur->usp); print(" AX %8.8lux BX %8.8lux CX %8.8lux DX %8.8lux\n", ur->ax, ur->bx, ur->cx, ur->dx); print(" SI %8.8lux DI %8.8lux BP %8.8lux DS %8.8lux\n", ur->si, ur->di, ur->bp, ur->ds); } /* | |
| 1991/0710 | * system calls */ long syscall(Ureg *ur) { | |
| 1991/0718 | u->p->insyscall = 1; u->p->pc = ur->pc; | |
| 1991/0710 | panic("syscall"); } | |
| 1991/0718/sys/src/9/pc/trap.c:60,89 – 1991/0719/sys/src/9/pc/trap.c:60,89 (short | long) | ||
| 1991/0703 | /* * set the standard traps */ | |
| 1991/0710 |
| |
| 1991/0719 | sethvec(0, intr0, SEGIG, 0); sethvec(1, intr1, SEGIG, 0); sethvec(2, intr2, SEGIG, 0); sethvec(3, intr3, SEGIG, 0); sethvec(4, intr4, SEGIG, 0); sethvec(5, intr5, SEGIG, 0); sethvec(6, intr6, SEGIG, 0); sethvec(7, intr7, SEGIG, 0); sethvec(8, intr8, SEGIG, 0); sethvec(9, intr9, SEGIG, 0); sethvec(10, intr10, SEGIG, 0); sethvec(11, intr11, SEGIG, 0); sethvec(12, intr12, SEGIG, 0); sethvec(13, intr13, SEGIG, 0); sethvec(14, intr14, SEGIG, 0); sethvec(15, intr15, SEGIG, 0); sethvec(16, intr16, SEGIG, 0); sethvec(17, intr17, SEGIG, 0); sethvec(18, intr18, SEGIG, 0); sethvec(19, intr19, SEGIG, 0); sethvec(20, intr20, SEGIG, 0); sethvec(21, intr21, SEGIG, 0); sethvec(22, intr22, SEGIG, 0); sethvec(23, intr23, SEGIG, 0); | |
| 1991/0703 | /* | |
| 1991/0718 | * set all others to unknown interrupts | |
| 1991/0719/sys/src/9/pc/trap.c:5,11 – 1991/0720/sys/src/9/pc/trap.c:5,15 (short | long) | ||
| 1991/0613 | #include "fns.h" #include "io.h" | |
| 1991/0703 | #include "ureg.h" | |
| 1991/0720 | #include "errno.h" | |
| 1991/0613 | ||
| 1991/0720 | void noted(Ureg*, ulong); void notify(Ureg*); | |
| 1991/0613 | /* | |
| 1991/0709 | * 8259 interrupt controllers */ | |
| 1991/0719/sys/src/9/pc/trap.c:155,179 – 1991/0720/sys/src/9/pc/trap.c:159,369 | ||
| 1991/0718 | ur->si, ur->di, ur->bp, ur->ds); } | |
| 1991/0720 | void dumpstack(void) { } void execpc(ulong entry) { ((Ureg*)UREGADDR)->pc = entry; } | |
| 1991/0718 | /* | |
| 1991/0710 | * system calls */ | |
| 1991/0720 | #undef CHDIR /* BUG */ #include "/sys/src/libc/9syscall/sys.h" typedef long Syscall(ulong*); Syscall sysr1, sysfork, sysexec, sysgetpid, syssleep, sysexits, sysdeath, syswait; Syscall sysopen, sysclose, sysread, syswrite, sysseek, syserrstr, sysaccess, sysstat, sysfstat; Syscall sysdup, syschdir, sysforkpgrp, sysbind, sysmount, syspipe, syscreate; Syscall sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted, sysalarm; Syscall *systab[]={ sysr1, syserrstr, sysbind, syschdir, sysclose, sysdup, sysalarm, sysexec, sysexits, sysfork, sysforkpgrp, sysfstat, sysdeath, sysmount, sysopen, sysread, sysseek, syssleep, sysstat, syswait, syswrite, syspipe, syscreate, sysdeath, sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted, sysdeath, /* sysfilsys */ }; | |
| 1991/0710 | long syscall(Ureg *ur) { | |
| 1991/0720 | ulong ax; ulong sp; long ret; int i; static int times; ulong *z; | |
| 1991/0718 | u->p->insyscall = 1; u->p->pc = ur->pc; | |
| 1991/0720 | if((ur->cs)&0xffff == KESEL) panic("recursive system call"); u->p->insyscall = 0; | |
| 1991/0718 | ||
| 1991/0710 |
| |
| 1991/0720 | /* * do something about floating point!!! */ ax = ur->ax; sp = ur->usp; u->nerrlab = 0; ret = -1; z = (ulong *)sp; print("syscall %lux %lux %lux %lux\n", *z, *(z+1), *(z+2), *(z+3)); dumpregs(ur); if(++times==3) panic("3rd time in syscall"); if(!waserror()){ if(ax >= sizeof systab/BY2WD){ pprint("bad sys call number %d pc %lux\n", ax, ur->pc); postnote(u->p, 1, "sys: bad sys call", NDebug); error(Ebadarg); } if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-(1+MAXSYSARG)*BY2WD)) validaddr(sp, (1+MAXSYSARG)*BY2WD, 0); ret = (*systab[ax])((ulong*)(sp+BY2WD)); poperror(); } print("return from syscall\n"); if(u->nerrlab){ print("bad errstack [%d]: %d extra\n", ax, u->nerrlab); for(i = 0; i < NERR; i++) print("sp=%lux pc=%lux\n", u->errlab[i].sp, u->errlab[i].pc); panic("error stack"); } u->p->insyscall = 0; if(ax == NOTED){ noted(ur, *(ulong*)(sp+BY2WD)); ret = -1; } else if(u->nnote){ ur->ax = ret; notify(ur); } return ret; | |
| 1991/0710 | } | |
| 1991/0720 | /* * Call user, if necessary, with note. * Pass user the Ureg struct and the note on his stack. */ | |
| 1991/0710 | void | |
| 1991/0711 |
| |
| 1991/0720 | notify(Ureg *ur) | |
| 1991/0710 | { | |
| 1991/0720 | ulong sp; lock(&u->p->debug); if(u->nnote==0){ unlock(&u->p->debug); return; } if(u->note[0].flag!=NUser && (u->notified || u->notify==0)){ if(u->note[0].flag == NDebug) pprint("suicide: %s\n", u->note[0].msg); Die: unlock(&u->p->debug); pexit(u->note[0].msg, u->note[0].flag!=NDebug); } if(!u->notified){ if(!u->notify) goto Die; u->svcs = ur->cs; u->svss = ur->ss; u->svflags = ur->flags; sp = ur->usp; sp -= sizeof(Ureg); u->ureg = (void*)sp; memmove((Ureg*)sp, ur, sizeof(Ureg)); sp -= ERRLEN; memmove((char*)sp, u->note[0].msg, ERRLEN); sp -= 3*BY2WD; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ *(ulong*)(sp+1*BY2WD) = (ulong)u->ureg; /* arg 1 is ureg* */ *(ulong*)(sp+0*BY2WD) = 0; /* arg 0 is pc */ ur->usp = sp; ur->pc = (ulong)u->notify; u->notified = 1; u->nnote--; memmove(&u->lastnote, &u->note[0], sizeof(Note)); memmove(&u->note[0], &u->note[1], u->nnote*sizeof(Note)); } unlock(&u->p->debug); | |
| 1991/0710 | } | |
| 1991/0720 | /* * Return user to state before notify() */ | |
| 1991/0710 | void | |
| 1991/0711 |
| |
| 1991/0720 | noted(Ureg *ur, ulong arg0) | |
| 1991/0710 | { | |
| 1991/0711 |
| |
| 1991/0720 | Ureg *nur; nur = u->ureg; validaddr(nur->pc, 1, 0); validaddr(nur->usp, BY2WD, 0); if(nur->cs!=u->svcs || nur->ss!=u->svss || (nur->flags&0xff)!=(u->svflags&0xff)){ pprint("bad noted ureg cs %ux ss %ux flags %ux\n", nur->cs, nur->ss, nur->flags); pexit("Suicide", 0); } lock(&u->p->debug); if(!u->notified){ unlock(&u->p->debug); return; } u->notified = 0; nur->flags = (u->svflags&0xffffff00) | (ur->flags&0xff); memmove(ur, u->ureg, sizeof(Ureg)); ur->ax = -1; /* return error from the interrupted call */ switch(arg0){ case NCONT: splhi(); unlock(&u->p->debug); rfnote(ur); break; /* never returns */ default: pprint("unknown noted arg 0x%lux\n", arg0); u->lastnote.flag = NDebug; /* fall through */ case NDFLT: if(u->lastnote.flag == NDebug) pprint("suicide: %s\n", u->lastnote.msg); unlock(&u->p->debug); pexit(u->lastnote.msg, u->lastnote.flag!=NDebug); } | |
| 1991/0614 | } | |
| 1991/0720/sys/src/9/pc/trap.c:303,308 – 1991/0722/sys/src/9/pc/trap.c:303,316 (short | long) | ||
| 1991/0720 | u->svflags = ur->flags; sp = ur->usp; sp -= sizeof(Ureg); | |
| 1991/0722 | if(waserror()){ pprint("suicide: trap in notify\n"); unlock(&u->p->debug); pexit("Suicide", 0); } validaddr((ulong)u->notify, 1, 0); validaddr(sp-ERRLEN-3*BY2WD, sizeof(Ureg)+ERRLEN-3*BY2WD, 0); poperror(); | |
| 1991/0720 | u->ureg = (void*)sp; memmove((Ureg*)sp, ur, sizeof(Ureg)); sp -= ERRLEN; | |
| 1991/0720/sys/src/9/pc/trap.c:351,359 – 1991/0722/sys/src/9/pc/trap.c:359,365 | ||
| 1991/0720 | case NCONT: splhi(); unlock(&u->p->debug); | |
| 1991/0722 | return; | |
| 1991/0720 | default: pprint("unknown noted arg 0x%lux\n", arg0); | |
| 1991/0722/sys/src/9/pc/trap.c:223,230 – 1991/0723/sys/src/9/pc/trap.c:223,228 (short | long) | ||
| 1991/0720 | ulong sp; long ret; int i; | |
| 1991/0718 | u->p->insyscall = 1; u->p->pc = ur->pc; | |
| 1991/0722/sys/src/9/pc/trap.c:240,250 – 1991/0723/sys/src/9/pc/trap.c:238,243 | ||
| 1991/0720 | sp = ur->usp; u->nerrlab = 0; ret = -1; | |
| 1991/0722/sys/src/9/pc/trap.c:256,262 – 1991/0723/sys/src/9/pc/trap.c:249,254 | ||
| 1991/0720 | ret = (*systab[ax])((ulong*)(sp+BY2WD)); poperror(); } | |
| 1991/0723/sys/src/9/pc/trap.c:259,265 – 1991/0724/sys/src/9/pc/trap.c:259,265 (short | long) | ||
| 1991/0720 | if(ax == NOTED){ noted(ur, *(ulong*)(sp+BY2WD)); ret = -1; | |
| 1991/0724 | } else if(u->nnote && ax!=FORK){ | |
| 1991/0720 | ur->ax = ret; notify(ur); } | |
| 1991/0723/sys/src/9/pc/trap.c:346,352 – 1991/0724/sys/src/9/pc/trap.c:346,352 | ||
| 1991/0720 | u->notified = 0; nur->flags = (u->svflags&0xffffff00) | (ur->flags&0xff); memmove(ur, u->ureg, sizeof(Ureg)); | |
| 1991/0724 | ur->ax = -1; /* return error from the interrupted syscall */ | |
| 1991/0720 | switch(arg0){ case NCONT: splhi(); | |
| 1991/0724/sys/src/9/pc/trap.c:256,265 – 1991/0725/sys/src/9/pc/trap.c:256,264 (short | long) | ||
| 1991/0720 | panic("error stack"); } u->p->insyscall = 0; | |
| 1991/0725 | if(ax == NOTED) | |
| 1991/0720 | noted(ur, *(ulong*)(sp+BY2WD)); | |
| 1991/0724 |
| |
| 1991/0725 | else if(u->nnote && ax!=FORK){ | |
| 1991/0720 | ur->ax = ret; notify(ur); } | |
| 1991/0724/sys/src/9/pc/trap.c:346,352 – 1991/0725/sys/src/9/pc/trap.c:345,351 | ||
| 1991/0720 | u->notified = 0; nur->flags = (u->svflags&0xffffff00) | (ur->flags&0xff); memmove(ur, u->ureg, sizeof(Ureg)); | |
| 1991/0724 |
| |
| 1991/0725 | /* ur->ax = -1; /* return error from the interrupted syscall */ | |
| 1991/0720 | switch(arg0){ case NCONT: splhi(); | |
| 1991/0725/sys/src/9/pc/trap.c:279,284 – 1991/0727/sys/src/9/pc/trap.c:279,285 (short | long) | ||
| 1991/0720 | unlock(&u->p->debug); return; } | |
| 1991/0727 | u->p->notepending = 0; | |
| 1991/0720 | if(u->note[0].flag!=NUser && (u->notified || u->notify==0)){ if(u->note[0].flag == NDebug) pprint("suicide: %s\n", u->note[0].msg); | |
| 1991/0727/sys/src/9/pc/trap.c:10,15 – 1991/0731/sys/src/9/pc/trap.c:10,26 (short | long) | ||
| 1991/0720 | void noted(Ureg*, ulong); void notify(Ureg*); | |
| 1991/0731 | void intr0(void), intr1(void), intr2(void), intr3(void); void intr4(void), intr5(void), intr6(void), intr7(void); void intr8(void), intr9(void), intr10(void), intr11(void); void intr12(void), intr13(void), intr14(void), intr15(void); void intr16(void), intr17(void), intr18(void), intr19(void); void intr20(void), intr21(void), intr22(void), intr23(void); void intr24(void), intr25(void), intr26(void), intr27(void); void intr28(void), intr29(void), intr30(void), intr31(void); void intr64(void); void intrbad(void); | |
| 1991/0613 | /* | |
| 1991/0709 | * 8259 interrupt controllers */ | |
| 1991/0727/sys/src/9/pc/trap.c:23,30 – 1991/0731/sys/src/9/pc/trap.c:34,41 | ||
| 1991/0709 | EOI= 0x20, /* non-specific end of interrupt */ }; | |
| 1991/0731 | int int0mask = 0xff; /* interrupts enabled for first 8259 */ int int1mask = 0xff; /* interrupts enabled for second 8259 */ | |
| 1991/0709 | /* | |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0727/sys/src/9/pc/trap.c:50,55 – 1991/0731/sys/src/9/pc/trap.c:61,69 | ||
| 1991/0709 | if((v&~0x7) == Int0vec){ int0mask &= ~(1<<(v&7)); outb(Int0aux, int0mask); | |
| 1991/0731 | } else if((v&~0x7) == Int1vec){ int1mask &= ~(1<<(v&7)); outb(Int1aux, int1mask); | |
| 1991/0709 | } | |
| 1991/0703 | } | |
| 1991/0727/sys/src/9/pc/trap.c:62,67 – 1991/0731/sys/src/9/pc/trap.c:76,87 | ||
| 1991/0703 | int i; | |
| 1991/0614 | ||
| 1991/0703 | /* | |
| 1991/0731 | * set all interrupts to panics */ for(i = 32; i < 256; i++) sethvec(i, intrbad, SEGIG, 0); /* | |
| 1991/0703 | * set the standard traps */ | |
| 1991/0719 | sethvec(0, intr0, SEGIG, 0); | |
| 1991/0727/sys/src/9/pc/trap.c:80,85 – 1991/0731/sys/src/9/pc/trap.c:100,109 | ||
| 1991/0719 | sethvec(13, intr13, SEGIG, 0); sethvec(14, intr14, SEGIG, 0); sethvec(15, intr15, SEGIG, 0); | |
| 1991/0731 | /* * set the standard devices */ | |
| 1991/0719 | sethvec(16, intr16, SEGIG, 0); sethvec(17, intr17, SEGIG, 0); sethvec(18, intr18, SEGIG, 0); | |
| 1991/0727/sys/src/9/pc/trap.c:88,101 – 1991/0731/sys/src/9/pc/trap.c:112,127 | ||
| 1991/0719 | sethvec(21, intr21, SEGIG, 0); sethvec(22, intr22, SEGIG, 0); sethvec(23, intr23, SEGIG, 0); | |
| 1991/0731 | sethvec(24, intr24, SEGIG, 0); sethvec(25, intr25, SEGIG, 0); sethvec(26, intr26, SEGIG, 0); sethvec(27, intr27, SEGIG, 0); sethvec(28, intr28, SEGIG, 0); sethvec(29, intr29, SEGIG, 0); sethvec(30, intr30, SEGIG, 0); sethvec(31, intr31, SEGIG, 0); | |
| 1991/0703 | /* | |
| 1991/0718 |
| |
| 1991/0703 |
| |
| 1991/0706 |
| |
| 1991/0710 |
| |
| 1991/0703 |
| |
| 1991/0710 | * system calls */ sethvec(64, intr64, SEGTG, 3); | |
| 1991/0727/sys/src/9/pc/trap.c:115,122 – 1991/0731/sys/src/9/pc/trap.c:141,166 | ||
| 1991/0709 | outb(Int0ctl, 0x11); /* ICW1 - edge triggered, master, ICW4 will be sent */ outb(Int0aux, Int0vec); /* ICW2 - interrupt vector offset */ | |
| 1991/0705 |
| |
| 1991/0731 | outb(Int0aux, 0x04); /* ICW3 - have slave on level 2 */ | |
| 1991/0709 | outb(Int0aux, 0x01); /* ICW4 - 8086 mode, not buffered */ | |
| 1991/0731 | /* * Set up the second 8259 interrupt processor. * Make 8259 interrupts start at CPU vector Int0vec. * Set the 8259 as master with edge triggered * input with fully nested interrupts. */ outb(Int1ctl, 0x11); /* ICW1 - edge triggered, master, ICW4 will be sent */ outb(Int1aux, Int1vec); /* ICW2 - interrupt vector offset */ outb(Int1aux, 0x02); /* ICW3 - I am a slave on level 2 */ outb(Int1aux, 0x01); /* ICW4 - 8086 mode, not buffered */ /* * pass #2 8259 interrupts to #1 */ int0mask &= ~0x04; outb(Int0aux, int0mask); | |
| 1991/0703 | } | |
| 1991/0614 | /* | |
| 1991/0727/sys/src/9/pc/trap.c:125,143 – 1991/0731/sys/src/9/pc/trap.c:169,196 | ||
| 1991/0710 | void | |
| 1991/0703 | trap(Ureg *ur) | |
| 1991/0614 | { | |
| 1991/0703 |
| |
| 1991/0711 |
| |
| 1991/0731 | int v; int c; | |
| 1991/0703 | ||
| 1991/0731 | v = ur->trap; if(v>=256 || ivec[v] == 0) panic("bad trap type %d %lux\n", v, ur->pc); | |
| 1991/0709 | /* * call the trap routine */ | |
| 1991/0703 |
| |
| 1991/0731 | (*ivec[v])(ur); | |
| 1991/0709 | /* * tell the 8259 that we're done with the * highest level interrupt */ | |
| 1991/0731 | c = v&~0x7; if(c==Int0vec || c==Int1vec){ outb(Int0ctl, EOI); if(c == Int1vec) outb(Int1ctl, EOI); } | |
| 1991/0710 | } /* | |
| 1991/0727/sys/src/9/pc/trap.c:173,220 – 1991/0731/sys/src/9/pc/trap.c:226,232 | ||
| 1991/0718 | /* | |
| 1991/0710 | * system calls */ | |
| 1991/0720 |
| |
| 1991/0731 | #include "../port/systab.h" | |
| 1991/0720 | ||
| 1991/0710 | long syscall(Ureg *ur) | |
| 1991/0731/sys/src/9/pc/trap.c:177,189 – 1991/0801/sys/src/9/pc/trap.c:177,185 (short | long) | ||
| 1991/0731 | panic("bad trap type %d %lux\n", v, ur->pc); | |
| 1991/0709 | /* | |
| 1991/0731 |
| |
| 1991/0709 |
| |
| 1991/0801 | * highest level interrupt (interrupts are still * off at this point) | |
| 1991/0709 | */ | |
| 1991/0731 | c = v&~0x7; if(c==Int0vec || c==Int1vec){ | |
| 1991/0731/sys/src/9/pc/trap.c:191,196 – 1991/0801/sys/src/9/pc/trap.c:187,197 | ||
| 1991/0731 | if(c == Int1vec) outb(Int1ctl, EOI); } | |
| 1991/0801 | /* * call the trap routine */ (*ivec[v])(ur); | |
| 1991/0710 | } /* | |
| 1991/0731/sys/src/9/pc/trap.c:268,277 – 1991/0801/sys/src/9/pc/trap.c:269,278 | ||
| 1991/0720 | panic("error stack"); } u->p->insyscall = 0; | |
| 1991/0801 | ur->ax = ret; | |
| 1991/0725 | if(ax == NOTED) | |
| 1991/0720 | noted(ur, *(ulong*)(sp+BY2WD)); | |
| 1991/0725 | else if(u->nnote && ax!=FORK){ | |
| 1991/0720 |
| |
| 1991/0801/sys/src/9/pc/trap.c:251,256 – 1991/0802/sys/src/9/pc/trap.c:251,257 (short | long) | ||
| 1991/0720 | sp = ur->usp; u->nerrlab = 0; ret = -1; | |
| 1991/0802 | spllo(); | |
| 1991/0720 | if(!waserror()){ if(ax >= sizeof systab/BY2WD){ pprint("bad sys call number %d pc %lux\n", ax, ur->pc); | |
| 1991/0801/sys/src/9/pc/trap.c:270,278 – 1991/0802/sys/src/9/pc/trap.c:271,279 | ||
| 1991/0720 | } u->p->insyscall = 0; | |
| 1991/0801 | ur->ax = ret; | |
| 1991/0725 |
| |
| 1991/0802 | if(ax == NOTED){ | |
| 1991/0720 | noted(ur, *(ulong*)(sp+BY2WD)); | |
| 1991/0725 |
| |
| 1991/0802 | } else if(u->nnote && ax!=FORK){ | |
| 1991/0720 | notify(ur); } return ret; | |
| 1991/0801/sys/src/9/pc/trap.c:346,352 – 1991/0802/sys/src/9/pc/trap.c:347,353 | ||
| 1991/0720 | validaddr(nur->pc, 1, 0); validaddr(nur->usp, BY2WD, 0); if(nur->cs!=u->svcs || nur->ss!=u->svss | |
| 1991/0802 | || (nur->flags&0xff00)!=(u->svflags&0xff00)){ | |
| 1991/0720 | pprint("bad noted ureg cs %ux ss %ux flags %ux\n", nur->cs, nur->ss, nur->flags); pexit("Suicide", 0); | |
| 1991/0801/sys/src/9/pc/trap.c:359,368 – 1991/0802/sys/src/9/pc/trap.c:360,367 | ||
| 1991/0720 | u->notified = 0; nur->flags = (u->svflags&0xffffff00) | (ur->flags&0xff); memmove(ur, u->ureg, sizeof(Ureg)); | |
| 1991/0725 |
| |
| 1991/0720 | switch(arg0){ case NCONT: | |
| 1991/0722 | return; | |
| 1991/0720 | ||
| 1991/0802/sys/src/9/pc/trap.c:35,41 – 1991/0803/sys/src/9/pc/trap.c:35,41 (short | long) | ||
|
Whitespace edit.
rsc Mon Mar 7 11:06:58 2005 | ||
| 1991/0709 | }; | |
| 1991/0731 | int int0mask = 0xff; /* interrupts enabled for first 8259 */ | |
| 1991/0803 | int int1mask = 0xff; /* interrupts enabled for second 8259 */ | |
| 1991/0709 | /* | |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0803/sys/src/9/pc/trap.c:176,181 – 1991/0806/sys/src/9/pc/trap.c:176,184 (short | long) | ||
| 1991/0731 | if(v>=256 || ivec[v] == 0) panic("bad trap type %d %lux\n", v, ur->pc); | |
| 1991/0806 | if(v==19 || v==20) print("trap = %d\n", v); | |
| 1991/0709 | /* * tell the 8259 that we're done with the | |
| 1991/0801 | * highest level interrupt (interrupts are still | |
| 1991/0803/sys/src/9/pc/trap.c:183,191 – 1991/0806/sys/src/9/pc/trap.c:186,194 | ||
| 1991/0709 | */ | |
| 1991/0731 | c = v&~0x7; if(c==Int0vec || c==Int1vec){ | |
| 1991/0806 | outb(Int0ctl, EOI); | |
| 1991/0731 | } | |
| 1991/0801 | /* | |
| 1991/0803/sys/src/9/pc/trap.c:192,197 – 1991/0806/sys/src/9/pc/trap.c:195,221 | ||
| 1991/0801 | * call the trap routine */ (*ivec[v])(ur); | |
| 1991/0806 | } /* * print 8259 status */ void dump8259(void) { int c; outb(Int0ctl, 0x0a); /* read ir */ print("ir0 %lux\n", inb(Int0ctl)); outb(Int0ctl, 0x0b); /* read is */ print("is0 %lux\n", inb(Int0ctl)); print("im0 %lux\n", inb(Int0aux)); outb(Int1ctl, 0x0a); /* read ir */ print("ir1 %lux\n", inb(Int1ctl)); outb(Int1ctl, 0x0b); /* read is */ print("is1 %lux\n", inb(Int1ctl)); print("im1 %lux\n", inb(Int1aux)); | |
| 1991/0710 | } /* | |
| 1991/0806/sys/src/9/pc/trap.c:173,180 – 1991/0807/sys/src/9/pc/trap.c:173,182 (short | long) | ||
| 1991/0731 | int c; | |
| 1991/0703 | ||
| 1991/0731 | v = ur->trap; | |
| 1991/0807 | if(v>=256 || ivec[v] == 0){ print("bad trap type %d %lux %lux %lux\n", v, ur->pc, int0mask, int1mask); return; } | |
| 1991/0731 | ||
| 1991/0806 | if(v==19 || v==20) print("trap = %d\n", v); | |
| 1991/0807/sys/src/9/pc/trap.c:34,41 – 1991/0808/sys/src/9/pc/trap.c:34,41 (short | long) | ||
| 1991/0709 | EOI= 0x20, /* non-specific end of interrupt */ }; | |
| 1991/0731 |
| |
| 1991/0803 |
| |
| 1991/0808 | int int0mask = 0x00; /* interrupts enabled for first 8259 */ int int1mask = 0x00; /* interrupts enabled for second 8259 */ | |
| 1991/0709 | /* | |
| 1991/0614 | * trap/interrupt gates | |
| 1991/0807/sys/src/9/pc/trap.c:231,237 – 1991/0808/sys/src/9/pc/trap.c:231,237 | ||
| 1991/0718 | else print("registers for kernel\n"); print("FLAGS=%lux ECODE=%lux CS=%lux PC=%lux SS=%lux USP=%lux\n", ur->flags, | |
| 1991/0808 | ur->ecode, ur->cs&0xff, ur->pc, ur->ss&0xff, ur->usp); | |
| 1991/0718 | print(" AX %8.8lux BX %8.8lux CX %8.8lux DX %8.8lux\n", ur->ax, ur->bx, ur->cx, ur->dx); | |
| 1991/0807/sys/src/9/pc/trap.c:286,292 – 1991/0808/sys/src/9/pc/trap.c:286,296 | ||
| 1991/0720 | } if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-(1+MAXSYSARG)*BY2WD)) validaddr(sp, (1+MAXSYSARG)*BY2WD, 0); | |
| 1991/0808 | if(ax == EXITS) print("%d exiting\n", u->p->pid); | |
| 1991/0720 | ret = (*systab[ax])((ulong*)(sp+BY2WD)); | |
| 1991/0808 | if(ax == EXITS) print("%d returned from sysexits!\n", u->p->pid); | |
| 1991/0720 | poperror(); } if(u->nerrlab){ | |
| Too many diffs (26 > 25). Stopping. | ||