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);
89 lastentry = entrytime;
91 if (entrytime < lastentry)
92 lastlength = entrytime + (0xFFFFFFFFUL - lastentry) + 1;
94 lastlength = entrytime - lastentry;
96 /* Disable caching on SMRAM again, to prevent the user from whacking us. */
97 WRMSR(0x202, RDMSR(0x202) & ~(0xFFULL));
100 extern void timer_handler(smi_event_t ev);
101 extern void kbc_handler(smi_event_t ev);
102 extern void gbl_rls_handler(smi_event_t ev);
104 void __firstrun_stub()
106 /* Turn on the SMIs we want */
109 smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
110 smi_enable_event(SMI_EVENT_FAST_TIMER);
112 smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
113 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
115 smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
116 smi_enable_event(SMI_EVENT_GBL_RLS);