]>
Commit | Line | Data |
---|---|---|
1 | /* smi.c | |
2 | * First-run SMI C entry point | |
3 | * NetWatch system management mode administration console | |
4 | * | |
5 | * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved. | |
6 | * This program is free software; you can redistribute and/or modify it under | |
7 | * the terms found in the file LICENSE in the root of this source tree. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <io.h> | |
12 | #include <smram.h> | |
13 | #include <video_defines.h> | |
14 | #include <minilib.h> | |
15 | #include <smi.h> | |
16 | #include <pci-bother.h> | |
17 | #include <serial.h> | |
18 | #include <fb.h> | |
19 | #include <output.h> | |
20 | #include <msr.h> | |
21 | #include "../net/net.h" | |
22 | #include "vga-overlay.h" | |
23 | ||
24 | unsigned int counter = 0; | |
25 | unsigned long pcisave = 0; | |
26 | unsigned char vgasave = 0; | |
27 | ||
28 | void smi_entry(void) | |
29 | { | |
30 | char statstr[512]; | |
31 | ||
32 | /* Reenable caching on SMRAM. */ | |
33 | WRMSR(0x202, (RDMSR(0x202) & ~(0xFFULL)) | 0x06ULL); | |
34 | ||
35 | pcisave = inl(0xCF8); | |
36 | vgasave = inb(0x3D4); | |
37 | pci_unbother_all(); | |
38 | ||
39 | serial_init(); | |
40 | ||
41 | if (fb) | |
42 | fb->getvmode(fb->priv); | |
43 | ||
44 | counter++; | |
45 | if (!fb || fb->curmode.text) | |
46 | { | |
47 | sprintf(statstr, "NetWatch! %08x %08x", smi_status(), counter); | |
48 | strblit(statstr, 0, 0, 0); | |
49 | } | |
50 | ||
51 | eth_poll(); | |
52 | ||
53 | if (inl(0x840) & 0x1000) | |
54 | { | |
55 | /* | |
56 | pci_dump(); | |
57 | */ | |
58 | outl(0x840, 0x1100); | |
59 | outl(0x840, 0x0100); | |
60 | } | |
61 | ||
62 | ||
63 | smi_poll(); | |
64 | ||
65 | pci_bother_all(); | |
66 | outl(0xCF8, pcisave); | |
67 | outb(0x3D4, vgasave); | |
68 | ||
69 | /* Disable caching on SMRAM again, to prevent the user from whacking us. */ | |
70 | WRMSR(0x202, RDMSR(0x202) & ~(0xFFULL)); | |
71 | } | |
72 | ||
73 | extern void timer_handler(smi_event_t ev); | |
74 | extern void kbc_handler(smi_event_t ev); | |
75 | extern void gbl_rls_handler(smi_event_t ev); | |
76 | extern void cs410_pwrbtn_handler(smi_event_t ev); | |
77 | ||
78 | void __firstrun_stub() { | |
79 | ||
80 | /* Try really hard to shut up USB_LEGKEY. */ | |
81 | pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); | |
82 | pci_write16(0, 31, 2, 0xC0, 0); | |
83 | pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); | |
84 | pci_write16(0, 31, 4, 0xC0, 0); | |
85 | ||
86 | /* Turn on the SMIs we want */ | |
87 | smi_disable(); | |
88 | ||
89 | smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler); | |
90 | smi_enable_event(SMI_EVENT_FAST_TIMER); | |
91 | ||
92 | smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler); | |
93 | smi_enable_event(SMI_EVENT_DEVTRAP_KBC); | |
94 | ||
95 | smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler); | |
96 | smi_enable_event(SMI_EVENT_GBL_RLS); | |
97 | ||
98 | smi_register_handler(SMI_EVENT_PWRBTN, cs410_pwrbtn_handler); | |
99 | smi_enable_event(SMI_EVENT_PWRBTN); | |
100 | ||
101 | smi_enable(); | |
102 | } |