git: 9front

Download patch

ref: 6c62c97db25ca86f1e313b75894ff028804d0f4f
parent: c9f5a30d9d4510a2284303c6dfbc0f0dbe3444c5
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Fri Jun 21 20:47:24 EDT 2013

apic: fix lapic timer divider (fixes wrong lapic frequency on boot)

loading the divider before programming one shot mode *sometimes*
gives the wrong frequency. (X200s got 192Mhz vs. 266Mhz, after
5 boot attempts)

also reload the divider after programming periodic mode. (from
http://wiki.osdev.org/APIC_timer)

--- a/sys/src/9/pc/apic.c
+++ b/sys/src/9/pc/apic.c
@@ -124,6 +124,12 @@
 	lapicw(LapicTICR, lapictimer.max);
 	lapicw(LapicTIMER, LapicCLKIN|LapicPERIODIC|(VectorPIC+IrqTIMER));
 
+	/*
+	 * not strickly neccesary, but reported (osdev.org) to be
+	 * required for some machines.
+	 */
+	lapicw(LapicTDCR, lapictdxtab[lapictimer.tdx]);
+
 	lapicw(LapicTPR, 0);
 }
 
@@ -134,8 +140,8 @@
 lapictimerinit(void)
 {
 Retry:
-	lapicw(LapicTDCR, lapictdxtab[lapictimer.tdx]);
 	lapicw(LapicTIMER, ApicIMASK|LapicCLKIN|LapicONESHOT|(VectorPIC+IrqTIMER));
+	lapicw(LapicTDCR, lapictdxtab[lapictimer.tdx]);
 
 	if(lapictimer.hz == 0ULL){
 		uvlong x, v, hz;
--