Reset code and vector handling from Linux

上级 7a34e712
...@@ -43,6 +43,8 @@ void initfutex(void); ...@@ -43,6 +43,8 @@ void initfutex(void);
void initcmdline(void); void initcmdline(void);
void idleloop(void); void idleloop(void);
#define IO_RTC 0x70
static volatile int bstate; static volatile int bstate;
void void
...@@ -59,6 +61,34 @@ mpboot(void) ...@@ -59,6 +61,34 @@ mpboot(void)
} }
static void static void
warmreset(u32 addr)
{
volatile u16 *wrv;
// "The BSP must initialize CMOS shutdown code to 0AH
// and the warm reset vector (DWORD based at 40:67) to point at
// the AP startup code prior to the [universal startup algorithm]."
outb(IO_RTC, 0xF); // offset 0xF is shutdown code
outb(IO_RTC+1, 0x0A);
wrv = (u16*)(0x40<<4 | 0x67); // Warm reset vector
wrv[0] = 0;
wrv[1] = addr >> 4;
}
static void
rstrreset(void)
{
volatile u16 *wrv;
// Paranoid: set warm reset code and vector back to defaults
outb(IO_RTC, 0xF);
outb(IO_RTC+1, 0);
wrv = (u16*)(0x40<<4 | 0x67);
wrv[0] = 0;
wrv[1] = 0;
}
static void
bootothers(void) bootothers(void)
{ {
extern u8 _bootother_start[]; extern u8 _bootother_start[];
...@@ -78,6 +108,8 @@ bootothers(void) ...@@ -78,6 +108,8 @@ bootothers(void)
if(c == cpus+myid()) // We've started already. if(c == cpus+myid()) // We've started already.
continue; continue;
warmreset(v2p(code));
// Tell bootother.S what stack to use and the address of apstart; // Tell bootother.S what stack to use and the address of apstart;
// it expects to find these two addresses stored just before // it expects to find these two addresses stored just before
// its first instruction. // its first instruction.
...@@ -92,6 +124,7 @@ bootothers(void) ...@@ -92,6 +124,7 @@ bootothers(void)
// Wait for cpu to finish mpmain() // Wait for cpu to finish mpmain()
while(bstate == 0) while(bstate == 0)
; ;
rstrreset();
} }
} }
......
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#define TCCR 0x839 // Timer Current Count #define TCCR 0x839 // Timer Current Count
#define TDCR 0x83e // Timer Divide Configuration #define TDCR 0x83e // Timer Divide Configuration
#define IO_RTC 0x70
static u64 x2apichz; static u64 x2apichz;
static int static int
...@@ -65,16 +63,6 @@ void ...@@ -65,16 +63,6 @@ void
x2apicstartap(hwid_t id, u32 addr) x2apicstartap(hwid_t id, u32 addr)
{ {
int i; int i;
volatile u16 *wrv;
// "The BSP must initialize CMOS shutdown code to 0AH
// and the warm reset vector (DWORD based at 40:67) to point at
// the AP startup code prior to the [universal startup algorithm]."
outb(IO_RTC, 0xF); // offset 0xF is shutdown code
outb(IO_RTC+1, 0x0A);
wrv = (u16*)(0x40<<4 | 0x67); // Warm reset vector
wrv[0] = 0;
wrv[1] = addr >> 4;
// Be paranoid about clearing APIC errors // Be paranoid about clearing APIC errors
writemsr(ESR, 0); writemsr(ESR, 0);
......
...@@ -187,16 +187,6 @@ void ...@@ -187,16 +187,6 @@ void
xapicstartap(hwid hwid, u32 addr) xapicstartap(hwid hwid, u32 addr)
{ {
int i; int i;
volatile u16 *wrv;
// "The BSP must initialize CMOS shutdown code to 0AH
// and the warm reset vector (DWORD based at 40:67) to point at
// the AP startup code prior to the [universal startup algorithm]."
outb(IO_RTC, 0xF); // offset 0xF is shutdown code
outb(IO_RTC+1, 0x0A);
wrv = (u16*)(0x40<<4 | 0x67); // Warm reset vector
wrv[0] = 0;
wrv[1] = addr >> 4;
// "Universal startup algorithm." // "Universal startup algorithm."
// Send INIT (level-triggered) interrupt to reset other CPU. // Send INIT (level-triggered) interrupt to reset other CPU.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论