git: 9front

Download patch

ref: f6bc8b62dc1c1bb4f7d8cec2627a516148049d1b
parent: 5f667d26529c7405842b6cdb7b00985dd72a662b
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sat Aug 25 10:06:42 EDT 2012

archmp: checksum _MP_ structure before use, coherence() and comments (import from sources)

we used to only test the checksum of the PCMP structure referenced by
the _MP_ without checking _MP_ itself. now fixed.

geoff added some coherence() calls and comments in the mpstartup and
apic code which seems to be a good idea.

--- a/sys/src/9/pc/apic.c
+++ b/sys/src/9/pc/apic.c
@@ -242,6 +242,7 @@
 	int i;
 	ulong crhi;
 
+	/* make apic's processor do a warm reset */
 	crhi = apic->apicno<<24;
 	lapicw(LapicICRHI, crhi);
 	lapicw(LapicICRLO, LapicFIELD|ApicLEVEL|LapicASSERT|ApicINIT);
@@ -249,8 +250,10 @@
 	lapicw(LapicICRLO, LapicFIELD|ApicLEVEL|LapicDEASSERT|ApicINIT);
 	delay(10);
 
+	/* assumes apic is not an 82489dx */
 	for(i = 0; i < 2; i++){
 		lapicw(LapicICRHI, crhi);
+		/* make apic's processor start at v in real mode */
 		lapicw(LapicICRLO, LapicFIELD|ApicEDGE|ApicSTARTUP|(v/BY2PG));
 		microdelay(200);
 	}
--- a/sys/src/9/pc/archmp.c
+++ b/sys/src/9/pc/archmp.c
@@ -384,11 +384,12 @@
 	 * if correct, check the version.
 	 * To do: check extended table checksum.
 	 */
-	if((_mp_ = sigsearch("_MP_")) == 0 || _mp_->physaddr == 0)
+	if((_mp_ = sigsearch("_MP_")) == 0 || checksum(_mp_, sizeof(_MP_)) || 
+	   (_mp_->physaddr == 0))
 		return 1;
 
 	pcmp = KADDR(_mp_->physaddr);
-	if(memcmp(pcmp, "PCMP", 4) || checksum(pcmp, pcmp->length) || 
+	if(memcmp(pcmp, "PCMP", 4) || checksum(pcmp, pcmp->length) ||
 	   (pcmp->version != 1 && pcmp->version != 4)) {
 		pcmp = nil;
 		return 1;
--- a/sys/src/9/pc/mp.c
+++ b/sys/src/9/pc/mp.c
@@ -185,6 +185,7 @@
 	checkmtrr();
 
 	apic->online = 1;
+	coherence();
 
 	lapicinit(apic);
 	lapiconline();
@@ -251,7 +252,7 @@
 	 * The offsets are known in the AP bootstrap code.
 	 */
 	apbootp = (ulong*)(APBOOTSTRAP+0x08);
-	*apbootp++ = (ulong)squidboy;
+	*apbootp++ = (ulong)squidboy;	/* assembler jumps here eventually */
 	*apbootp++ = PADDR(pdb);
 	*apbootp = (ulong)apic;
 
@@ -258,7 +259,7 @@
 	/*
 	 * Universal Startup Algorithm.
 	 */
-	p = KADDR(0x467);
+	p = KADDR(0x467);		/* warm-reset vector */
 	*p++ = PADDR(APBOOTSTRAP);
 	*p++ = PADDR(APBOOTSTRAP)>>8;
 	i = (PADDR(APBOOTSTRAP) & ~0xFFFF)/16;
@@ -267,8 +268,9 @@
 		print("mp: bad APBOOTSTRAP\n");
 	*p++ = i;
 	*p = i>>8;
+	coherence();
 
-	nvramwrite(0x0F, 0x0A);
+	nvramwrite(0x0F, 0x0A);		/* shutdown code: warm reset upon init ipi */
 	lapicstartap(apic, PADDR(APBOOTSTRAP));
 	for(i = 0; i < 1000; i++){
 		if(apic->online)
@@ -327,6 +329,7 @@
 		return;
 	}
 	apic->online = 1;
+
 	lapicinit(apic);
 
 	/*
--