]> Joshua Wise's Git repositories - netwatch.git/blame - netwatch/smi.c
Merge branch 'master' of git@github.com:jwise/netwatch
[netwatch.git] / netwatch / smi.c
CommitLineData
3c4e084d
JP
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
9e2a82e4
JP
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>
113df320 17#include <serial.h>
c77a83d6
JW
18#include <fb.h>
19#include <output.h>
eda689ee 20#include <msr.h>
9e2a82e4
JP
21#include "../net/net.h"
22#include "vga-overlay.h"
23
9e2a82e4 24unsigned int counter = 0;
9e2a82e4
JP
25unsigned long pcisave = 0;
26unsigned char vgasave = 0;
27
9e2a82e4
JP
28void smi_entry(void)
29{
30 char statstr[512];
68beefa8 31
eda689ee
JW
32 /* Reenable caching on SMRAM. */
33 WRMSR(0x202, (RDMSR(0x202) & ~(0xFFULL)) | 0x06ULL);
34
9e2a82e4
JP
35 pcisave = inl(0xCF8);
36 vgasave = inb(0x3D4);
9e2a82e4 37 pci_unbother_all();
c77a83d6
JW
38
39 serial_init();
40
41 if (fb)
42 fb->getvmode(fb->priv);
68beefa8 43
9e2a82e4 44 counter++;
5cb80fe1
JW
45 if (!fb || fb->curmode.text)
46 {
47 sprintf(statstr, "NetWatch! %08x %08x", smi_status(), counter);
48 strblit(statstr, 0, 0, 0);
49 }
9e2a82e4 50
9e2a82e4 51 eth_poll();
9e2a82e4
JP
52
53 if (inl(0x840) & 0x1000)
54 {
55 /*
56 pci_dump();
57 */
58 outl(0x840, 0x1100);
59 outl(0x840, 0x0100);
60 }
61
113df320 62
9e2a82e4 63 smi_poll();
68beefa8 64
9e2a82e4 65 pci_bother_all();
9e2a82e4
JP
66 outl(0xCF8, pcisave);
67 outb(0x3D4, vgasave);
eda689ee
JW
68
69 /* Disable caching on SMRAM again, to prevent the user from whacking us. */
70 WRMSR(0x202, RDMSR(0x202) & ~(0xFFULL));
9e2a82e4
JP
71}
72
722e5aea
JP
73extern void timer_handler(smi_event_t ev);
74extern void kbc_handler(smi_event_t ev);
75extern void gbl_rls_handler(smi_event_t ev);
9e2a82e4 76
722e5aea 77void __firstrun_stub() {
9e2a82e4 78
722e5aea
JP
79 /* Try really hard to shut up USB_LEGKEY. */
80 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
81 pci_write16(0, 31, 2, 0xC0, 0);
82 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
83 pci_write16(0, 31, 4, 0xC0, 0);
9e2a82e4 84
722e5aea
JP
85 /* Turn on the SMIs we want */
86 smi_disable();
9e2a82e4
JP
87
88 smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
89 smi_enable_event(SMI_EVENT_FAST_TIMER);
90
722e5aea
JP
91 smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
92 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
93
94 smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
95 smi_enable_event(SMI_EVENT_GBL_RLS);
96
9e2a82e4
JP
97 smi_enable();
98}
This page took 0.036733 seconds and 4 git commands to generate.