2 * First-run SMI C entry point
3 * NetWatch system management mode administration console
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.
13 #include <video_defines.h>
16 #include <pci-bother.h>
21 #include "../net/net.h"
22 #include "vga-overlay.h"
24 unsigned int counter = 0;
25 unsigned long pcisave = 0;
26 unsigned char vgasave = 0;
28 unsigned long lastentry = 0;
29 unsigned long lastlength = 0;
34 asm volatile ("mov %%cr4, %%eax;"
37 "rdtsc" : "=a"(tsc) : : "edx");
44 unsigned long entrytime;
46 /* Reenable caching on SMRAM. */
47 WRMSR(0x202, (RDMSR(0x202) & ~(0xFFULL)) | 0x06ULL);
58 fb->getvmode(fb->priv);
61 if (!fb || fb->curmode.text)
65 if (entrytime < lastentry)
66 totcyc = entrytime + (0xFFFFFFFFUL - lastentry) + 1;
68 totcyc = entrytime - lastentry;
70 totcyc = 1; /* argh */
75 pct = lastlength / totcyc;
77 sprintf(statstr, "NetWatch! %08x %08x, %2d.%d%%", smi_status(), counter, pct/10, pct%10);
78 strblit(statstr, 0, 0, 0);
83 if (inl(0x840) & 0x1000)
99 lastentry = entrytime;
101 if (entrytime < lastentry)
102 lastlength = entrytime + (0xFFFFFFFFUL - lastentry) + 1;
104 lastlength = entrytime - lastentry;
106 /* Disable caching on SMRAM again, to prevent the user from whacking us. */
107 WRMSR(0x202, RDMSR(0x202) & ~(0xFFULL));
110 extern void timer_handler(smi_event_t ev);
111 extern void kbc_handler(smi_event_t ev);
112 extern void gbl_rls_handler(smi_event_t ev);
114 void __firstrun_stub()
116 /* Turn on the SMIs we want */
119 smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
120 smi_enable_event(SMI_EVENT_FAST_TIMER);
122 smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
123 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
125 smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
126 smi_enable_event(SMI_EVENT_GBL_RLS);