Fixes to VM8086 handler to remove operand size errors.
[tpg/acess2.git] / Kernel / arch / x86 / kpanic.c
1 /*
2  * Acess 2 Kernel
3  * By John Hodge (thePowersGang)
4  * - x86 Kernel Panic Handler
5  */
6
7 #include <acess.h>
8
9 #define FB      ((Uint16 *)(KERNEL_BASE|0xB8000))
10 #define BGC     0x4F00  // White on Red
11 //#define BGC   0xC000  // Black on Bright Red
12 //#define BGC   0x1F00  // White on Blue (BSOD!)
13
14  int    giKP_Pos = 0;
15
16 const struct {
17         Uint16  IdxPort;
18         Uint16  DatPort;
19         Uint8   Index;
20         Uint8   Value;
21 }       caRegValues[] = {
22         //{0x3C0, 0x3C0, 0x10, 0x0C},   // Mode Control (Blink Enabled)
23         {0x3C0, 0x3C0, 0x10, 0x04},     // Mode Control (Blink Disabled)
24         {0x3C0, 0x3C0, 0x11, 0x00},     // Overscan Register
25         {0x3C0, 0x3C0, 0x12, 0x0F},     // Color Plane Enable
26         {0x3C0, 0x3C0, 0x13, 0x08},     // Horizontal Panning
27         {0x3C0, 0x3C0, 0x14, 0x00},     // Color Select
28         {0    , 0x3C2, 0   , 0x67},     // Miscellaneous Output Register
29         {0x3C4, 0x3C5, 0x01, 0x00},     // Clock Mode Register
30         {0x3C4, 0x3C5, 0x03, 0x00},     // Character select
31         {0x3C4, 0x3C5, 0x04, 0x07},     // Memory Mode Register
32         {0x3CE, 0x3CF, 0x05, 0x10},     // Mode Register
33         {0x3CE, 0x3CF, 0x06, 0x0E},     // Miscellaneous Register
34         {0x3D4, 0x3D5, 0x00, 0x5F},     // Horizontal Total
35         {0x3D4, 0x3D5, 0x01, 0x4F},     // Horizontal Display Enable End
36         {0x3D4, 0x3D5, 0x02, 0x50},     // Horizontal Blank Start
37         {0x3D4, 0x3D5, 0x03, 0x82},     // Horizontal Blank End
38         {0x3D4, 0x3D5, 0x04, 0x55},     // Horizontal Retrace Start
39         {0x3D4, 0x3D5, 0x05, 0x81},     // Horizontal Retrace End
40         {0x3D4, 0x3D5, 0x06, 0xBF},     // Vertical Total
41         {0x3D4, 0x3D5, 0x07, 0x1F},     // Overflow Register
42         {0x3D4, 0x3D5, 0x08, 0x00},     // Preset row scan
43         {0x3D4, 0x3D5, 0x09, 0x4F},     // Maximum Scan Line
44         {0x3D4, 0x3D5, 0x10, 0x9C},     // Vertical Retrace Start
45         {0x3D4, 0x3D5, 0x11, 0x8E},     // Vertical Retrace End
46         {0x3D4, 0x3D5, 0x12, 0x8F},     // Vertical Display Enable End
47         {0x3D4, 0x3D5, 0x13, 0x28},     // Logical Width
48         {0x3D4, 0x3D5, 0x14, 0x1F},     // Underline Location
49         {0x3D4, 0x3D5, 0x15, 0x96},     // Vertical Blank Start
50         {0x3D4, 0x3D5, 0x16, 0xB9},     // Vertical Blank End
51         {0x3D4, 0x3D5, 0x17, 0xA3}      // CRTC Mode Control
52 };
53 #define NUM_REGVALUES   (sizeof(caRegValues)/sizeof(caRegValues[0]))
54
55 /**
56  * \brief Sets the screen mode for a kernel panic
57  */
58 void KernelPanic_SetMode()
59 {
60          int    i;
61         
62         // This function is called by Panic(), but MM_PageFault and the
63         // CPU exception handers also call it, so let's not clear the screen
64         // twice
65         if( giKP_Pos )  return ;
66         
67         // Restore VGA 0xB8000 text mode
68         #if 1
69         for( i = 0; i < NUM_REGVALUES; i++ )
70         {
71                 // Reset Flip-Flop
72                 if( caRegValues[i].IdxPort == 0x3C0 )   inb(0x3DA);
73                 
74                 if( caRegValues[i].IdxPort )
75                         outb(caRegValues[i].IdxPort, caRegValues[i].Index);
76                 outb(caRegValues[i].DatPort, caRegValues[i].Value);
77         }
78         
79         inb(0x3DA);
80         outb(0x3C0, 0x20);
81         #endif
82         
83         // Clear Screen
84         for( i = 0; i < 80*25; i++ )
85         {
86                 FB[i] = BGC;
87         }
88 }
89
90 void KernelPanic_PutChar(char Ch)
91 {
92         if( giKP_Pos > 80*25 )  return ;
93         switch(Ch)
94         {
95         case '\t':
96                 do {
97                         FB[giKP_Pos] &= 0xFF00;
98                         FB[giKP_Pos++] |= ' ';
99                 } while(giKP_Pos & 7);
100                 break;
101         
102         case '\n':
103                 giKP_Pos += 80;
104         case '\r':
105                 giKP_Pos -= giKP_Pos % 80;
106                 break;
107         
108         default:
109                 if(' ' <= Ch && Ch < 0x7F)
110                 {
111                         FB[giKP_Pos] &= 0xFF00;
112                         FB[giKP_Pos] |= Ch;
113                 }
114                 giKP_Pos ++;
115                 break;
116         }
117 }

UCC git Repository :: git.ucc.asn.au