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

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