2  * Main post-paging 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>
 
  19 #include "../net/net.h"
 
  20 #include "vga-overlay.h"
 
  24 unsigned int lastctr = 0;
 
  25 extern unsigned int counter;
 
  27 static int _ibf_ready = 0;
 
  28 static int _waiting_for_data = 0;
 
  29 static int curdev = 0;
 
  30 static int adding_locks_from_time_to_time = 0;
 
  32 static int _inject_ready()
 
  34         return _ibf_ready && !_waiting_for_data && !adding_locks_from_time_to_time;
 
  39         if (kbd_has_injected_scancode() && _inject_ready())
 
  41                 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
 
  43                 while (inb(0x64) & 0x02)        /* Busy? */
 
  45                 outb(0x64, 0xD2);       /* "Inject, please!" */
 
  46                 while (inb(0x64) & 0x02)        /* Busy? */
 
  48                 outb(0x60, kbd_get_injected_scancode());        /* data */
 
  49                 while ((inb(0x64) & 0x02) && i--)       /* wait for completion */
 
  52                 adding_locks_from_time_to_time++;
 
  53                 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
 
  54         } else if (kbd_has_injected_scancode())
 
  55                 outputf("Would like to inject, but %d %d", _ibf_ready, _waiting_for_data);
 
  74                         /* Read the real hardware and mask in our OBF if need be. */
 
  77                         curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0;
 
  79                         if ((curdev == 0) && kbd_has_injected_scancode())
 
  82                         _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1;
 
  86                         if ((curdev == 0) && kbd_has_injected_scancode() && !adding_locks_from_time_to_time)
 
  87                                 b = kbd_get_injected_scancode();
 
  90                         if (adding_locks_from_time_to_time)
 
  91                                 adding_locks_from_time_to_time--;
 
  92                         if ((curdev == 0) && (b == 0x01)) {     /* Escape */
 
  93                                 outb(0xCF9, 0x4);       /* Reboot */
 
  99                         b = inb(cts & 0xFFFF);
 
 102                 dologf("READ : %08x (%02x)", cts, b);
 
 103                 *(unsigned char*)0xAFFD0 /* EAX */ = b;
 
 110                 b = *(unsigned char*)0xAFFD0 /* EAX */;
 
 111                 dologf("WRITE: %08x (%02x)", cts, b);
 
 112                 if ((cts & 0xFFFF) == 0x64)
 
 115                         case 0x60 /*KBD_CCMD_WRITE_MODE*/:
 
 116                         case 0xD2 /*KBD_CCMD_WRITE_OBUF*/:
 
 117                         case 0xD3 /*KBD_CCMD_WRITE_AUX_OBUF*/:
 
 118                         case 0xD4 /*KBD_CCMD_WRITE_MOUSE*/:
 
 119                         case 0xD1 /*KBD_CCMD_WRITE_OUTPORT*/:
 
 120                                 _waiting_for_data = 1;  /* These all should not be interrupted. */
 
 122                 else if ((cts & 0xFFFF) == 0x60)
 
 123                         _waiting_for_data = 0;
 
 124                 outb(cts & 0xFFFF, b);
 
 128                 dolog("Unhandled PCI cycle");
 
 136 void timer_handler(smi_event_t ev)
 
 138         static unsigned int ticks = 0;
 
 140         smi_disable_event(SMI_EVENT_FAST_TIMER);
 
 141         smi_enable_event(SMI_EVENT_FAST_TIMER);
 
 145         outb(0x80, (ticks++) & 0xFF);
 
 147         if (!fb || fb->curmode.text)
 
 151 void kbc_handler(smi_event_t ev)
 
 156 void gbl_rls_handler(smi_event_t ev)
 
 160         ecx = *(unsigned long*)0xAFFD4;
 
 162         packet_t * packet = check_packet(ecx);
 
 165                 dologf("WARN: bad packet at %08x", ecx);
 
 169         outputf("Got packet: type %08x", packet->type);
 
 171         if (packet->type == 42) {
 
 172                 dump_log((char *)packet->data);
 
 173                 *(unsigned long*)0xAFFD4 = 42;
 
 174         } else if (packet->type == 0xAA) {
 
 175                 kbd_inject_keysym('A', 1);
 
 176                 kbd_inject_keysym('A', 0);
 
 178                 *(unsigned long*)0xAFFD4 = 0x2BADD00D;