Skip to content

Commit 4f14d8d

Browse files
committed
Commit to running on an SMP (perhaps with only 1 core). Remove most code
from picirq.c and remove timer.c completely. Update runoff.list.
1 parent 7070596 commit 4f14d8d

10 files changed

+6
-125
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ OBJS = \
2222
syscall.o\
2323
sysfile.o\
2424
sysproc.o\
25-
timer.o\
2625
trapasm.o\
2726
trap.o\
2827
uart.o\

console.c

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ consoleinit(void)
294294
devsw[CONSOLE].read = consoleread;
295295
cons.locking = 1;
296296

297-
picenable(IRQ_KBD);
298297
ioapicenable(IRQ_KBD, 0);
299298
}
300299

ide.c

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ ideinit(void)
5353
int i;
5454

5555
initlock(&idelock, "ide");
56-
picenable(IRQ_IDE);
5756
ioapicenable(IRQ_IDE, ncpu - 1);
5857
idewait(0);
5958

ioapic.c

-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ ioapicinit(void)
5050
{
5151
int i, id, maxintr;
5252

53-
if(!ismp)
54-
return;
55-
5653
ioapic = (volatile struct ioapic*)IOAPIC;
5754
maxintr = (ioapicread(REG_VER) >> 16) & 0xFF;
5855
id = ioapicread(REG_ID) >> 24;
@@ -70,9 +67,6 @@ ioapicinit(void)
7067
void
7168
ioapicenable(int irq, int cpunum)
7269
{
73-
if(!ismp)
74-
return;
75-
7670
// Mark interrupt edge-triggered, active high,
7771
// enabled, and routed to the given cpunum,
7872
// which happens to be that cpu's APIC ID.

main.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main(void)
2222
mpinit(); // detect other processors
2323
lapicinit(); // interrupt controller
2424
seginit(); // segment descriptors
25-
picinit(); // another interrupt controller
25+
picinit(); // disable pic
2626
ioapicinit(); // another interrupt controller
2727
consoleinit(); // console hardware
2828
uartinit(); // serial port
@@ -31,8 +31,6 @@ main(void)
3131
binit(); // buffer cache
3232
fileinit(); // file table
3333
ideinit(); // disk
34-
if(!ismp)
35-
timerinit(); // uniprocessor timer
3634
startothers(); // start other processors
3735
kinit2(P2V(4*1024*1024), P2V(PHYSTOP)); // must come after startothers()
3836
userinit(); // first user process

mp.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "proc.h"
1313

1414
struct cpu cpus[NCPU];
15-
int ismp;
1615
int ncpu;
1716
uchar ioapicid;
1817

@@ -93,13 +92,14 @@ void
9392
mpinit(void)
9493
{
9594
uchar *p, *e;
95+
int ismp;
9696
struct mp *mp;
9797
struct mpconf *conf;
9898
struct mpproc *proc;
9999
struct mpioapic *ioapic;
100100

101101
if((conf = mpconfig(&mp)) == 0)
102-
return;
102+
panic("Expect to run on an SMP");
103103
ismp = 1;
104104
lapic = (uint*)conf->lapicaddr;
105105
for(p=(uchar*)(conf+1), e=(uchar*)conf+conf->length; p<e; ){
@@ -127,13 +127,8 @@ mpinit(void)
127127
break;
128128
}
129129
}
130-
if(!ismp){
131-
// Didn't like what we found; fall back to no MP.
132-
ncpu = 1;
133-
lapic = 0;
134-
ioapicid = 0;
135-
return;
136-
}
130+
if(!ismp)
131+
panic("Didn't find a suitable machine");
137132

138133
if(mp->imcrp){
139134
// Bochs doesn't support IMCR, so this doesn't run on Bochs.

picirq.c

+1-69
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Intel 8259A programmable interrupt controllers.
2-
31
#include "types.h"
42
#include "x86.h"
53
#include "traps.h"
@@ -8,79 +6,13 @@
86
#define IO_PIC1 0x20 // Master (IRQs 0-7)
97
#define IO_PIC2 0xA0 // Slave (IRQs 8-15)
108

11-
#define IRQ_SLAVE 2 // IRQ at which slave connects to master
12-
13-
// Current IRQ mask.
14-
// Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
15-
static ushort irqmask = 0xFFFF & ~(1<<IRQ_SLAVE);
16-
17-
static void
18-
picsetmask(ushort mask)
19-
{
20-
irqmask = mask;
21-
outb(IO_PIC1+1, mask);
22-
outb(IO_PIC2+1, mask >> 8);
23-
}
24-
25-
void
26-
picenable(int irq)
27-
{
28-
picsetmask(irqmask & ~(1<<irq));
29-
}
30-
31-
// Initialize the 8259A interrupt controllers.
9+
// Don't use the 8259A interrupt controllers. Xv6 assumes SMP hardware.
3210
void
3311
picinit(void)
3412
{
3513
// mask all interrupts
3614
outb(IO_PIC1+1, 0xFF);
3715
outb(IO_PIC2+1, 0xFF);
38-
39-
// Set up master (8259A-1)
40-
41-
// ICW1: 0001g0hi
42-
// g: 0 = edge triggering, 1 = level triggering
43-
// h: 0 = cascaded PICs, 1 = master only
44-
// i: 0 = no ICW4, 1 = ICW4 required
45-
outb(IO_PIC1, 0x11);
46-
47-
// ICW2: Vector offset
48-
outb(IO_PIC1+1, T_IRQ0);
49-
50-
// ICW3: (master PIC) bit mask of IR lines connected to slaves
51-
// (slave PIC) 3-bit # of slave's connection to master
52-
outb(IO_PIC1+1, 1<<IRQ_SLAVE);
53-
54-
// ICW4: 000nbmap
55-
// n: 1 = special fully nested mode
56-
// b: 1 = buffered mode
57-
// m: 0 = slave PIC, 1 = master PIC
58-
// (ignored when b is 0, as the master/slave role
59-
// can be hardwired).
60-
// a: 1 = Automatic EOI mode
61-
// p: 0 = MCS-80/85 mode, 1 = intel x86 mode
62-
outb(IO_PIC1+1, 0x3);
63-
64-
// Set up slave (8259A-2)
65-
outb(IO_PIC2, 0x11); // ICW1
66-
outb(IO_PIC2+1, T_IRQ0 + 8); // ICW2
67-
outb(IO_PIC2+1, IRQ_SLAVE); // ICW3
68-
// NB Automatic EOI mode doesn't tend to work on the slave.
69-
// Linux source code says it's "to be investigated".
70-
outb(IO_PIC2+1, 0x3); // ICW4
71-
72-
// OCW3: 0ef01prs
73-
// ef: 0x = NOP, 10 = clear specific mask, 11 = set specific mask
74-
// p: 0 = no polling, 1 = polling mode
75-
// rs: 0x = NOP, 10 = read IRR, 11 = read ISR
76-
outb(IO_PIC1, 0x68); // clear specific mask
77-
outb(IO_PIC1, 0x0a); // read IRR by default
78-
79-
outb(IO_PIC2, 0x68); // OCW3
80-
outb(IO_PIC2, 0x0a); // OCW3
81-
82-
if(irqmask != 0xFFFF)
83-
picsetmask(irqmask);
8416
}
8517

8618
//PAGEBREAK!

runoff.list

-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ mp.h
6060
mp.c
6161
lapic.c
6262
ioapic.c
63-
picirq.c
6463
kbd.h
6564
kbd.c
6665
console.c
67-
timer.c
6866
uart.c
6967

7068
# user-level

timer.c

-32
This file was deleted.

uart.c

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ uartinit(void)
4141
// enable interrupts.
4242
inb(COM1+2);
4343
inb(COM1+0);
44-
picenable(IRQ_COM1);
4544
ioapicenable(IRQ_COM1, 0);
4645

4746
// Announce that we're here.

0 commit comments

Comments
 (0)