ReactOS  r76032
shell.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define REASON_INT3   (0)
 
#define REASON_SINGLESTEP   (1)
 
#define REASON_CTRLF   (2)
 
#define REASON_PAGEFAULT   (3)
 
#define REASON_GP_FAULT   (4)
 
#define REASON_HARDWARE_BP   (5)
 
#define REASON_DOUBLE_FAULT   (6)
 
#define REASON_MODULE_LOAD   (7)
 
#define REASON_INTERNAL_ERROR   (8)
 
#define I8042_PHYSICAL_BASE   0x60
 
#define I8042_DATA_REGISTER_OFFSET   0
 
#define I8042_COMMAND_REGISTER_OFFSET   4
 
#define I8042_STATUS_REGISTER_OFFSET   4
 
#define KEYBOARD_IRQ   1
 

Functions

void InstallGlobalKeyboardHook (void)
 
void DeInstallGlobalKeyboardHook (void)
 
void RealIsr (ULONG dwReasonForBreak)
 
void NewInt31Handler (void)
 
void ShowStatusLine (void)
 

Variables

volatile BOOLEAN bNotifyToExit
 
volatile BOOLEAN bSingleStep
 
volatile UCHAR ucKeyPressedWhileIdle
 
volatile BOOLEAN bInDebuggerShell
 
ULONG CurrentEIP
 
ULONG CurrentEFL
 
ULONG CurrentEAX
 
ULONG CurrentEBX
 
ULONG CurrentECX
 
ULONG CurrentEDX
 
ULONG CurrentESP
 
ULONG CurrentEBP
 
ULONG CurrentESI
 
ULONG CurrentEDI
 
ULONG CurrentDR0
 
ULONG CurrentDR1
 
ULONG CurrentDR2
 
ULONG CurrentDR3
 
ULONG CurrentDR6
 
ULONG CurrentDR7
 
ULONG CurrentCR0
 
ULONG CurrentCR2
 
ULONG CurrentCR3
 
USHORT CurrentCS
 
USHORT CurrentDS
 
USHORT CurrentES
 
USHORT CurrentFS
 
USHORT CurrentGS
 
USHORT CurrentSS
 
volatile BOOLEAN bControl
 
volatile BOOLEAN bShift
 
volatile BOOLEAN bAlt
 
ULONG OldEIP
 
ULONG OldEFL
 
ULONG OldEAX
 
ULONG OldEBX
 
ULONG OldECX
 
ULONG OldEDX
 
ULONG OldESP
 
ULONG OldEBP
 
ULONG OldESI
 
ULONG OldEDI
 
USHORT OldCS
 
USHORT OldDS
 
USHORT OldES
 
USHORT OldFS
 
USHORT OldGS
 
USHORT OldSS
 
ULONG CurrentProcess
 
USHORT OldSelector
 
ULONG OldOffset
 
ULONG ulRealStackPtr
 
ULONG g_ulLineNumberStart
 
BOOLEAN bStepThroughSource
 
BOOLEAN bStepInto
 
volatile BOOLEAN bEnterNow
 

Macro Definition Documentation

#define I8042_COMMAND_REGISTER_OFFSET   4

Definition at line 86 of file shell.h.

#define I8042_DATA_REGISTER_OFFSET   0

Definition at line 85 of file shell.h.

Referenced by GetKeyData().

#define I8042_PHYSICAL_BASE   0x60

Definition at line 84 of file shell.h.

Referenced by GetKeyData(), and GetKeyStatus().

#define I8042_STATUS_REGISTER_OFFSET   4

Definition at line 87 of file shell.h.

Referenced by GetKeyStatus().

#define KEYBOARD_IRQ   1

Definition at line 91 of file shell.h.

Referenced by InitPICE().

#define REASON_CTRLF   (2)

Definition at line 73 of file shell.h.

Referenced by InitPICE(), PiceKbdIsr(), and RealIsr().

#define REASON_DOUBLE_FAULT   (6)

Definition at line 77 of file shell.h.

Referenced by RealIsr().

#define REASON_GP_FAULT   (4)

Definition at line 75 of file shell.h.

Referenced by RealIsr().

#define REASON_HARDWARE_BP   (5)

Definition at line 76 of file shell.h.

Referenced by RealIsr().

#define REASON_INT3   (0)

Definition at line 71 of file shell.h.

Referenced by RealIsr().

#define REASON_INTERNAL_ERROR   (8)

Definition at line 79 of file shell.h.

Referenced by RealIsr().

#define REASON_MODULE_LOAD   (7)

Definition at line 78 of file shell.h.

#define REASON_PAGEFAULT   (3)

Definition at line 74 of file shell.h.

Referenced by RealIsr().

#define REASON_SINGLESTEP   (1)

Definition at line 72 of file shell.h.

Referenced by RealIsr().

Function Documentation

void DeInstallGlobalKeyboardHook ( void  )

Definition at line 1677 of file shell.c.

Referenced by CleanUpPICE().

1678 {
1679  ENTER_FUNC();
1680 
1681  MaskIrqs();
1683  {
1686  }
1687  UnmaskIrqs();
1688 
1689  LEAVE_FUNC();
1690 }
ULONG SetGlobalInt(ULONG dwInt, ULONG NewIntHandler)
Definition: hooks.c:95
#define LEAVE_FUNC()
Definition: debug.h:43
void MaskIrqs(void)
Definition: hooks.c:68
volatile ULONG OldGlobalInt31Handler
Definition: shell.c:74
ULONG KeyboardIRQL
Definition: init.c:50
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
void UnmaskIrqs(void)
Definition: hooks.c:82
void InstallGlobalKeyboardHook ( void  )

Definition at line 1657 of file shell.c.

Referenced by InitPICE().

1658 {
1659  ULONG LocalNewGlobalInt31Handler;
1660 
1661  ENTER_FUNC();
1662 
1663  MaskIrqs();
1665  {
1666  __asm__("mov $NewGlobalInt31Handler,%0"
1667  :"=r" (LocalNewGlobalInt31Handler)
1668  :
1669  :"eax");
1670  OldGlobalInt31Handler=SetGlobalInt(KeyboardIRQL,(ULONG)LocalNewGlobalInt31Handler);
1671  }
1672  UnmaskIrqs();
1673 
1674  LEAVE_FUNC();
1675 }
ULONG SetGlobalInt(ULONG dwInt, ULONG NewIntHandler)
Definition: hooks.c:95
#define LEAVE_FUNC()
Definition: debug.h:43
__asm__(".global NewInt31Handler\n\t \ NewInt31Handler:\n\t \ cli\n\t \ cld\n\t \ \n\t \ pushl %eax\n\t \ pushl %ds\n\t \ \n\t \ movw %ss,%ax\n\t \ mov %ax,%ds\n\t \ \n\t \ mov 0x4(%esp),%eax\n\t \ movl %eax,_CurrentEAX\n\t \ movl %ebx,_CurrentEBX\n\t \ movl %ecx,_CurrentECX\n\t \ movl %edx,_CurrentEDX\n\t \ movl %esi,_CurrentESI\n\t \ movl %edi,_CurrentEDI\n\t \ movl %ebp,_CurrentEBP\n\t \ movl (%esp),%eax\n\t \ movw %ax,_CurrentDS\n\t \ \n\t \ // test for V86 mode\n\t \ testl $0x20000,5*4(%esp)\n\t \ jz notV86\n\t \ \n\t \ int $0x03\n\t \ \n\t \ notV86:\n\t \ // test if stack switched (ring3->ring0 transition)\n\t \ // stack is switched if orig. SS is not global kernel code segment\n\t \ movl 4*4(%esp),%eax\n\t \ cmpw $"STR(GLOBAL_CODE_SEGMENT)",%ax\n\t \ je notswitched\n\t \ \n\t \ // switched stack\n\t \ movl 6*4(%esp),%eax\n\t \ mov %eax,_CurrentESP\n\t \ mov 7*4(%esp),%eax\n\t \ movzwl %ax,%eax\n\t \ mov %ax,_CurrentSS\n\t \ jmp afterswitch\n\t \ \n\t \ notswitched:\n\t \ // didn't switch stack\n\t \ movl %esp,_CurrentESP\n\t \ addl $24,_CurrentESP\n\t \ movw %ss,%ax\n\t \ movzwl %ax,%eax\n\t \ mov %ax,_CurrentSS\n\t \ \n\t \ afterswitch:\n\t \ // save EIP\n\t \ mov 3*4(%esp),%eax\n\t \ mov %eax,_CurrentEIP\n\t \ //save CS\n\t \ mov 4*4(%esp),%eax\n\t \ movzwl %ax,%eax\n\t \ movw %ax,_CurrentCS\n\t \ // save flags\n\t \ movl 5*4(%esp),%eax\n\t \ andl $0xFFFFFEFF,%eax\n\t \ movl %eax,_CurrentEFL\n\t \ \n\t \ pushal\n\t \ \n\t \ // get reason code\n\t \ mov 0x28(%esp),%ebx\n\t \ \n\t \ /*\n\t \ * Load the PCR selector.\n\t \ */\n\t \ \n\t \ movl %fs, %eax\n\t \ movl %eax, _OLD_PCR\n\t \ movl _PCR_SEL, %eax\n\t \ movl %eax, %fs\n\t \ \n\t \ // setup a large work stack\n\t \ movl %esp,%eax\n\t \ movl %eax,_ulRealStackPtr\n\t \ \n\t \ pushl %ebx\n\t \ call _RealIsr\n\t \ addl $4,%esp\n\t \ \n\t \ pushl %eax\n\t \ movl _OLD_PCR, %eax\n\t \ movl %eax, %fs\n\t \ popl %eax\n\t \ \n\t \ // restore all regs\n\t \ popal\n\t \ \n\t \ // do an EOI to IRQ controller (because we definitely pressed some key)\n\t \ // TODO: SMP APIC support\n\t \ movb $0x20,%al\n\t \ outb %al,$0x20\n\t \ \n\t \ popl %ds\n\t \ popl %eax\n\t \ \n\t \ // remove reason code\n\t \ addl $4,%esp\n\t \ \n\t \ // make EAX available\n\t \ pushl %eax\n\t \ \n\t \ // modify or restore EFLAGS\n\t \ .byte 0x2e\n\t \ mov _CurrentEFL,%eax\n\t \ mov %eax,3*4(%esp)\n\t \ .byte 0x2e\n\t \ movzwl _CurrentCS,%eax\n\t \ mov %eax,2*4(%esp)\n\t \ .byte 0x2e\n\t \ mov _CurrentEIP,%eax\n\t \ mov %eax,1*4(%esp)\n\t \ \n\t \ // restore EAX\n\t \ popl %eax\n\t \ \n\t \ // do we need to call old INT1 handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldInt1Handler\n\t \ je do_iret2\n\t \ \n\t \ // call INT3 handler\n\t \ .byte 0x2e\n\t \ jmp *_OldInt1Handler\n\t \ \n\t \ do_iret2:\n\t \ // do we need to call old INT3 handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldInt3Handler\n\t \ je do_iret1\n\t \ \n\t \ // call INT3 handler\n\t \ .byte 0x2e\n\t \ jmp *_OldInt3Handler\n\t \ \n\t \ do_iret1:\n\t \ // do we need to call old pagefault handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldIntEHandler\n\t \ je do_iret3\n\t \ \n\t \ // call old pagefault handler\n\t \ .byte 0x2e\n\t \ pushl _error_code\n\t \ .byte 0x2e\n\t \ jmp *_OldIntEHandler\n\t \ \n\t \ do_iret3:\n\t \ // do we need to call old general protection fault handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldGPFaultHandler\n\t \ je do_iret\n\t \ \n\t \ // call old pagefault handler\n\t \ .byte 0x2e\n\t \ pushl _error_code\n\t \ .byte 0x2e\n\t \ jmp *_OldGPFaultHandler\n\t \ \n\t \ do_iret:\n\t \ //ei\n\t \ //int3\n\t \ iretl ")
void MaskIrqs(void)
Definition: hooks.c:68
volatile ULONG OldGlobalInt31Handler
Definition: shell.c:74
ULONG KeyboardIRQL
Definition: init.c:50
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
void UnmaskIrqs(void)
Definition: hooks.c:82
void NewInt31Handler ( void  )
void RealIsr ( ULONG  dwReasonForBreak)

Definition at line 1016 of file shell.c.

Referenced by InitPICE().

1017 {
1018  BOOLEAN ReinstallPermanentBp = FALSE;
1019 
1020  DPRINT((0,"reason: %u#################################################################\n", dwReasonForBreak));
1021  ENTER_FUNC();
1022 
1023  // in handler
1025 
1026  bStepping = FALSE;
1027 
1028  // don't assume we must call original handlers yet
1030  bSkipMainLoop = FALSE;
1031  bEnterNow = FALSE;
1032 
1033  // reset trace flag (TF) on the stack
1034  CurrentEFL&=(~0x100);
1035 
1037 
1038  // control is not depressed
1039  bControl=FALSE;
1040 
1041  bIrqStateAtBreak = ((CurrentEFL&(1<<9))!=0);
1042 
1043  DPRINT((0,"\nbInDebuggerShell %x, dwReasonForBreak: %x, bIrqStateAtBreak: %d\n", bInDebuggerShell, dwReasonForBreak, bIrqStateAtBreak));
1044  DPRINT((0,"CurrentEIP: %x, CurrentESP: %x\n", CurrentEIP, CurrentESP));
1045 
1046  // came in because TF flag was set
1047  if(dwReasonForBreak == REASON_SINGLESTEP)
1048  {
1049  ULONG ulAddress,ulAddressCurrent;
1050 
1051  DPRINT((0,"REASON_SINGLESTEP: bSingleStep: %u\n", bSingleStep));
1052 
1053  if(!bSingleStep)
1054  {
1056  DPRINT((0,"no single step requested: %u!\n", dwCallOldInt1Handler));
1057  goto common_return_point;
1058  }
1059 
1060  ulAddress = GetLinearAddress(OldCS,OldEIP);
1061  ulAddressCurrent = GetLinearAddress(CurrentCS,CurrentEIP);
1062 
1063  // if we came in because we needed to skip past a permanent
1064  // INT3 hook, we need to put the INT3 back in place and
1065  // simply restart the system.
1066  if(NeedToReInstallSWBreakpoints(ulAddress,TRUE) )
1067  {
1068  DPRINT((0,"reinstalling INT3 @ %.4X:%.8X\n",OldCS,OldEIP));
1069 
1070  ReInstallSWBreakpoint(ulAddress);
1071 
1072  // previous command was go i.e. we did not single-step over a location
1073  // where a permanent breakpoint was installed (Printk() etc.) we simply restart
1074  // else we must stop the system.
1076  {
1079 
1080  if(bStepThroughSource)
1081  {
1082  // set TF flag
1083  CurrentEFL |= 0x100;
1084  }
1085 
1086  LEAVE_FUNC();
1087  DPRINT((0,"singlestep-----------------------------------------------------------------\n"));
1088  return;
1089  }
1091  }
1092 
1093  if(IsSwBpAtAddressInstalled(ulAddressCurrent))
1094  DeInstallSWBreakpoint(ulAddressCurrent);
1095 
1096  // we came here while stepping through source code block
1097  if(bStepThroughSource)
1098  {
1099  ULONG ulLineNumber;
1100  LPSTR pSrc,pFileName;
1101 
1102  DPRINT((0,"RealIsr(): stepping through source!\n"));
1103 
1104  // look up the corresponding source line
1105  // if there isn't any or the source line number has changed
1106  // we break back into the debugger
1107  if(bShowSrc)
1108  pSrc = FindSourceLineForAddress(ulAddressCurrent,&ulLineNumber,NULL,NULL,&pFileName);
1109  else pSrc = NULL;
1110 
1111  DPRINT((0,"RealIsr(): line #%u pSrc=%x (old line #%u)\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart));
1112 
1113  // if we have found a source line there
1114  if(pSrc && ulLineNumber==g_ulLineNumberStart)
1115  {
1116  DPRINT((0,"RealIsr(): stepping through line #%u in file = %s!\n",ulLineNumber,pFileName));
1117 
1118  if(bStepInto)
1119  StepInto(NULL);
1120  else
1121  StepOver(NULL);
1122 
1124  LEAVE_FUNC();
1125  DPRINT((0,"singstep-----------------------------------------------------------------\n"));
1126  return;
1127  }
1129  bNotifyToExit = FALSE;
1130  bSkipMainLoop = FALSE;
1131  }
1132  }
1133  // came in because hardware register triggered a breakpoint
1134  else if(dwReasonForBreak == REASON_HARDWARE_BP)
1135  {
1136  ULONG ulReason;
1137 
1138  DPRINT((0,"REASON_HARDWARE_BP\n"));
1139 
1140  // disable HW breakpoints
1141  __asm__("\n\t \
1142  movl %%dr6,%%eax\n\t \
1143  movl %%eax,%0\n\t \
1144  xorl %%eax,%%eax\n\t \
1145  movl %%eax,%%dr6\n\t \
1146  movl %%eax,%%dr7"
1147  :"=m" (ulReason)
1148  :
1149  :"eax"
1150  );
1151 
1152  DPRINT((0,"REASON_HARDWARE_BP: %x\n",(ulReason&0xF)));
1153 
1154  // HW breakpoint DR1 (skip: only used in init_module detection)
1155  if(ulReason&0x2)
1156  {
1157  CurrentEFL |=(1<<16); // set resume flag
1158 
1159  bSkipMainLoop = TRUE;
1160 
1162  }
1163  // HW breakpoint DR0
1164  else if(ulReason&0x1)
1165  {
1166  ULONG ulAddressCurrent;
1167 
1168  ulAddressCurrent = GetLinearAddress(CurrentCS,CurrentEIP);
1169 
1170  // we came here while stepping through source code block
1171  if(bStepThroughSource)
1172  {
1173  ULONG ulLineNumber;
1174  LPSTR pSrc,pFileName;
1175 
1176  DPRINT((0,"RealIsr(): stepping through source! [2]\n"));
1177 
1178  // look up the corresponding source line
1179  // if there isn't any or the source line number has changed
1180  // we break back into the debugger
1181  if(bShowSrc)
1182  pSrc = FindSourceLineForAddress(ulAddressCurrent,&ulLineNumber,NULL,NULL,&pFileName);
1183  else
1184  pSrc = NULL;
1185 
1186  DPRINT((0,"RealIsr(): line #%u pSrc=%x (old line #%u) [2]\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart));
1187 
1188  // if we have found a source line there
1189  if(pSrc && ulLineNumber==g_ulLineNumberStart)
1190  {
1191  DPRINT((0,"RealIsr(): stepping through line #%u in file = %s! [2]\n",ulLineNumber,pFileName));
1192 
1193  if(bStepInto)
1194  StepInto(NULL);
1195  else
1196  StepOver(NULL);
1197 
1199  LEAVE_FUNC();
1200  DPRINT((0,"rrr-----------------------------------------------------------------\n"));
1201  return;
1202  }
1203  bNotifyToExit = FALSE;
1204  bSkipMainLoop = FALSE;
1206  }
1207  }
1208  }
1209  else if(dwReasonForBreak==REASON_INT3)
1210  {
1211  ULONG ulAddress;
1212 
1213  DPRINT((0,"REASON_INT3\n"));
1214 
1215  // must subtract one cause INT3s are generated after instructions execution
1216  CurrentEIP--;
1217 
1218  // make a flat address
1219  ulAddress = GetLinearAddress(CurrentCS,CurrentEIP);
1220 
1221  DPRINT((0,"INT3 @ %.8X\n",ulAddress));
1222 
1223  // if there's a breakpoint installed at current EIP remove it
1224  if(DeInstallSWBreakpoint(ulAddress) )
1225  {
1226  PSW_BP p;
1227 
1228  DPRINT((0,"INT3 @ %.8X removed\n",ulAddress));
1229 
1230  // if it's permanent (must be Printk() ) skip the DebuggerShell() and
1231  // do a callback
1232  if( (p = IsPermanentSWBreakpoint(ulAddress)) )
1233  {
1234  DPRINT((0,"permanent breakpoint\n"));
1235 
1236  ReinstallPermanentBp = TRUE;
1237 
1238  OldCS = CurrentCS;
1239  OldEIP = CurrentEIP;
1240 
1241  bSkipMainLoop = TRUE;
1242  DPRINT((0,"callback at %x\n",p->Callback));
1243  if(p->Callback)
1244  p->Callback();
1245  }
1246  else
1247  {
1248  LPSTR pFind;
1250  {
1251  PICE_sprintf(tempShell,"pICE: SW Breakpoint at %s (%.4X:%.8X)\n",pFind,CurrentCS,CurrentEIP);
1252  }
1253  else
1254  {
1255  PICE_sprintf(tempShell,"pICE: SW Breakpoint at %.4X:%.8X\n",CurrentCS,CurrentEIP);
1256  }
1258  }
1259  CurrentEFL &= ~(1<<16); // clear resume flag
1260  }
1261  else
1262  {
1263  LPSTR pFind;
1264  PEPROCESS my_current = IoGetCurrentProcess();
1265 
1266  DPRINT((0,"can't deinstall, somebody else's breakpoint\n"));
1267 
1268 
1269  // if no other debugger is running on this process and the address is
1270  // above TASK_SIZE we assume this to be a hard embedded INT3
1271 /*
1272 #if REAL_LINUX_VERSION_CODE < 0x020400
1273  if(ulAddress<TASK_SIZE && !(my_current->flags & PF_PTRACED) )
1274 #else
1275  if(ulAddress<TASK_SIZE && !(my_current->ptrace & PT_PTRACED) )
1276 #endif
1277 */
1278  if( ulAddress )
1279  {
1281  {
1282  PICE_sprintf(tempShell,"pICE: break due to embedded INT 3 at %s (%.4X:%.8X)\n",pFind,CurrentCS,CurrentEIP);
1283  }
1284  else
1285  {
1286  PICE_sprintf(tempShell,"pICE: break due to embedded INT 3 at user-mode address %.4X:%.8X\n",CurrentCS,CurrentEIP);
1287  }
1289  CurrentEFL &= ~(1<<16); // clear resume flag
1290  }
1291  // well someone is already debugging this, we must pass the INT3 on to old handler
1292  // but only when it's a user-mode address
1293 /*
1294  else
1295  {
1296  if(ulAddress<TASK_SIZE || !bInt3Here)
1297  {
1298  DPRINT((0,"SW Breakpoint but debugged by other process at %.4X:%.8X\n",CurrentCS,CurrentEIP));
1299  // call the old handler on return from RealIsr()
1300  dwCallOldInt3Handler = 1;
1301  // and skip DebuggerShell()
1302  bSkipMainLoop = TRUE;
1303  }
1304  else
1305  {
1306  if(ScanExportsByAddress(&pFind,GetLinearAddress(CurrentCS,CurrentEIP)))
1307  {
1308  PICE_sprintf(tempShell,"pICE: break due to embedded INT 3 at (%s) %.4X:%.8X\n",
1309  pFind,CurrentCS,CurrentEIP);
1310  }
1311  else
1312  {
1313  PICE_sprintf(tempShell,"pICE: break due to embedded INT 3 at kernel-mode address %.4X:%.8X\n",
1314  CurrentCS,CurrentEIP);
1315  }
1316  Print(OUTPUT_WINDOW,tempShell);
1317  CurrentEFL &= ~(1<<16); // clear resume flag
1318  }
1319  }
1320 */
1321  // skip INT3
1322  CurrentEIP++;
1323  }
1324  }
1325  else if(dwReasonForBreak == REASON_PAGEFAULT)
1326  {
1327  LPSTR pSymbolName;
1328 
1329  DPRINT((0,"REASON_PAGEFAULT\n"));
1330 
1332  {
1333  PICE_sprintf(tempShell,"pICE: Breakpoint due to page fault at %.4X:%.8X (%s)\n",CurrentCS,CurrentEIP,pSymbolName);
1334  }
1335  else
1336  {
1337  PICE_sprintf(tempShell,"pICE: Breakpoint due to page fault at %.4X:%.8X\n",CurrentCS,CurrentEIP);
1338  }
1340  PICE_sprintf(tempShell,"pICE: memory referenced %x\n",CurrentCR2);
1343  }
1344  else if(dwReasonForBreak == REASON_GP_FAULT)
1345  {
1346  LPSTR pSymbolName;
1347 
1348  DPRINT((0,"REASON_GPFAULT\n"));
1349 
1351  {
1352  PICE_sprintf(tempShell,"pICE: Breakpoint due to general protection fault at %.4X:%.8X (%s)\n",CurrentCS,CurrentEIP,pSymbolName);
1353  }
1354  else
1355  {
1356  PICE_sprintf(tempShell,"pICE: Breakpoint due to general protection fault at %.4X:%.8X\n",CurrentCS,CurrentEIP);
1357  }
1360  }
1361  else if(dwReasonForBreak == REASON_CTRLF)
1362  {
1363  DPRINT((0,"REASON_CTRLF\n"));
1364  // nothing to do
1365  }
1366  else if(dwReasonForBreak == REASON_DOUBLE_FAULT)
1367  {
1368  DPRINT((0,"REASON_DOUBLE_FAULT\n"));
1369 
1370  PICE_sprintf(tempShell,"pICE: Breakpoint due to double fault at %.4X:%.8X\n",CurrentCS,CurrentEIP);
1372  }
1373  else if(dwReasonForBreak == REASON_INTERNAL_ERROR)
1374  {
1375  DPRINT((0,"REASON_INTERNAL_ERROR\n"));
1376 
1377  Print(OUTPUT_WINDOW,"pICE: Please report this error to klauspg@diamondmm.com!\n");
1378 // Print(OUTPUT_WINDOW,"pICE: !!! SYSTEM HALTED !!!\n");
1379 // __asm__ __volatile__("hlt");
1380  }
1381  else
1382  {
1383  DPRINT((0,"REASON_UNKNOWN\n"));
1384 
1385  PICE_sprintf(tempShell,"pICE: Breakpoint due to unknown reason at %.4X:%.8X (code %x)\n",CurrentCS,CurrentEIP,dwReasonForBreak);
1387  Print(OUTPUT_WINDOW,"pICE: Please report this error to klauspg@diamondmm.com!\n");
1388  Print(OUTPUT_WINDOW,"pICE: !!! SYSTEM HALTED !!!\n");
1389  __asm__ __volatile__("hlt");
1390  }
1391 
1392  // we don't single-step yet
1393  DPRINT((0,"RealIsr(): not stepping yet\n"));
1395 
1396  // process commands
1397  if(bSkipMainLoop == FALSE)
1398  {
1399  DPRINT((0,"RealIsr(): saving registers\n"));
1400  // save the extended regs
1401  __asm__ __volatile__
1402  ("\n\t \
1403  pushl %eax\n\t \
1404  movw %es,%ax\n\t \
1405  movw %ax,_CurrentES\n\t \
1406  //movw %fs,%ax\n\t \
1407  //movw %ax,_CurrentFS\n\t \
1408  movw %gs,%ax\n\t \
1409  movw %ax,_CurrentGS\n\t \
1410  movl %dr0,%eax\n\t \
1411  movl %eax,_CurrentDR0\n\t \
1412  movl %dr1,%eax\n\t \
1413  movl %eax,_CurrentDR1\n\t \
1414  movl %dr2,%eax\n\t \
1415  movl %eax,_CurrentDR2\n\t \
1416  movl %dr3,%eax\n\t \
1417  movl %eax,_CurrentDR3\n\t \
1418  movl %dr6,%eax\n\t \
1419  movl %eax,_CurrentDR6\n\t \
1420  movl %dr7,%eax\n\t \
1421  movl %eax,_CurrentDR7\n\t \
1422  movl %cr0,%eax\n\t \
1423  movl %eax,_CurrentCR0\n\t \
1424  movl %cr2,%eax\n\t \
1425  movl %eax,_CurrentCR2\n\t \
1426  movl %cr3,%eax\n\t \
1427  movl %eax,_CurrentCR3\n\t \
1428  popl %eax"
1429  );
1430 
1431  CurrentFS = OLD_PCR;
1432  DPRINT((0,"RealIsr(): adding colon to output()\n"));
1433  Print(OUTPUT_WINDOW,":");
1434 
1435  DPRINT((0,"RealIsr(): calling DebuggerShell()\n"));
1436  DebuggerShell();
1437  }
1438 
1439  // if there was a SW breakpoint at CS:EIP
1441  {
1442  DPRINT((0,"need to reinstall INT3\n"));
1443  // remember how we restarted last time
1445  // do a single step to reinstall breakpoint
1446  // modify trace flag
1447  CurrentEFL|=0x100; // set trace flag (TF)
1448 
1449  bSingleStep=TRUE;
1451  }
1452 
1453 common_return_point:
1454 
1455  // reset the global flags
1456  bNotifyToExit = FALSE;
1457  bSkipMainLoop = FALSE;
1458 
1459  // not in handler anymore
1461 
1462  LEAVE_FUNC();
1463  DPRINT((0,"common return-----------------------------------------------------------------\n"));
1464 }
USHORT CurrentCS
Definition: shell.c:116
volatile BOOLEAN bEnterNow
Definition: shell.c:75
volatile BOOLEAN bInDebuggerShell
Definition: shell.c:79
#define TRUE
Definition: types.h:120
#define REASON_DOUBLE_FAULT
Definition: shell.h:77
volatile BOOLEAN bSkipMainLoop
Definition: shell.c:77
BOOLEAN bStepInto
Definition: shell.c:65
ULONG OldEIP
Definition: shell.c:120
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
ULONG dwCallOldInt1Handler
Definition: shell.c:57
#define LEAVE_FUNC()
Definition: debug.h:43
char * LPSTR
Definition: xmlstorage.h:182
Definition: bp.h:31
BOOLEAN bStepping
Definition: parse.c:63
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
BOOLEAN bShowSrc
Definition: parse.c:252
#define REASON_GP_FAULT
Definition: shell.h:75
#define REASON_INTERNAL_ERROR
Definition: shell.h:79
__asm__(".global NewInt31Handler\n\t \ NewInt31Handler:\n\t \ cli\n\t \ cld\n\t \ \n\t \ pushl %eax\n\t \ pushl %ds\n\t \ \n\t \ movw %ss,%ax\n\t \ mov %ax,%ds\n\t \ \n\t \ mov 0x4(%esp),%eax\n\t \ movl %eax,_CurrentEAX\n\t \ movl %ebx,_CurrentEBX\n\t \ movl %ecx,_CurrentECX\n\t \ movl %edx,_CurrentEDX\n\t \ movl %esi,_CurrentESI\n\t \ movl %edi,_CurrentEDI\n\t \ movl %ebp,_CurrentEBP\n\t \ movl (%esp),%eax\n\t \ movw %ax,_CurrentDS\n\t \ \n\t \ // test for V86 mode\n\t \ testl $0x20000,5*4(%esp)\n\t \ jz notV86\n\t \ \n\t \ int $0x03\n\t \ \n\t \ notV86:\n\t \ // test if stack switched (ring3->ring0 transition)\n\t \ // stack is switched if orig. SS is not global kernel code segment\n\t \ movl 4*4(%esp),%eax\n\t \ cmpw $"STR(GLOBAL_CODE_SEGMENT)",%ax\n\t \ je notswitched\n\t \ \n\t \ // switched stack\n\t \ movl 6*4(%esp),%eax\n\t \ mov %eax,_CurrentESP\n\t \ mov 7*4(%esp),%eax\n\t \ movzwl %ax,%eax\n\t \ mov %ax,_CurrentSS\n\t \ jmp afterswitch\n\t \ \n\t \ notswitched:\n\t \ // didn't switch stack\n\t \ movl %esp,_CurrentESP\n\t \ addl $24,_CurrentESP\n\t \ movw %ss,%ax\n\t \ movzwl %ax,%eax\n\t \ mov %ax,_CurrentSS\n\t \ \n\t \ afterswitch:\n\t \ // save EIP\n\t \ mov 3*4(%esp),%eax\n\t \ mov %eax,_CurrentEIP\n\t \ //save CS\n\t \ mov 4*4(%esp),%eax\n\t \ movzwl %ax,%eax\n\t \ movw %ax,_CurrentCS\n\t \ // save flags\n\t \ movl 5*4(%esp),%eax\n\t \ andl $0xFFFFFEFF,%eax\n\t \ movl %eax,_CurrentEFL\n\t \ \n\t \ pushal\n\t \ \n\t \ // get reason code\n\t \ mov 0x28(%esp),%ebx\n\t \ \n\t \ /*\n\t \ * Load the PCR selector.\n\t \ */\n\t \ \n\t \ movl %fs, %eax\n\t \ movl %eax, _OLD_PCR\n\t \ movl _PCR_SEL, %eax\n\t \ movl %eax, %fs\n\t \ \n\t \ // setup a large work stack\n\t \ movl %esp,%eax\n\t \ movl %eax,_ulRealStackPtr\n\t \ \n\t \ pushl %ebx\n\t \ call _RealIsr\n\t \ addl $4,%esp\n\t \ \n\t \ pushl %eax\n\t \ movl _OLD_PCR, %eax\n\t \ movl %eax, %fs\n\t \ popl %eax\n\t \ \n\t \ // restore all regs\n\t \ popal\n\t \ \n\t \ // do an EOI to IRQ controller (because we definitely pressed some key)\n\t \ // TODO: SMP APIC support\n\t \ movb $0x20,%al\n\t \ outb %al,$0x20\n\t \ \n\t \ popl %ds\n\t \ popl %eax\n\t \ \n\t \ // remove reason code\n\t \ addl $4,%esp\n\t \ \n\t \ // make EAX available\n\t \ pushl %eax\n\t \ \n\t \ // modify or restore EFLAGS\n\t \ .byte 0x2e\n\t \ mov _CurrentEFL,%eax\n\t \ mov %eax,3*4(%esp)\n\t \ .byte 0x2e\n\t \ movzwl _CurrentCS,%eax\n\t \ mov %eax,2*4(%esp)\n\t \ .byte 0x2e\n\t \ mov _CurrentEIP,%eax\n\t \ mov %eax,1*4(%esp)\n\t \ \n\t \ // restore EAX\n\t \ popl %eax\n\t \ \n\t \ // do we need to call old INT1 handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldInt1Handler\n\t \ je do_iret2\n\t \ \n\t \ // call INT3 handler\n\t \ .byte 0x2e\n\t \ jmp *_OldInt1Handler\n\t \ \n\t \ do_iret2:\n\t \ // do we need to call old INT3 handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldInt3Handler\n\t \ je do_iret1\n\t \ \n\t \ // call INT3 handler\n\t \ .byte 0x2e\n\t \ jmp *_OldInt3Handler\n\t \ \n\t \ do_iret1:\n\t \ // do we need to call old pagefault handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldIntEHandler\n\t \ je do_iret3\n\t \ \n\t \ // call old pagefault handler\n\t \ .byte 0x2e\n\t \ pushl _error_code\n\t \ .byte 0x2e\n\t \ jmp *_OldIntEHandler\n\t \ \n\t \ do_iret3:\n\t \ // do we need to call old general protection fault handler\n\t \ .byte 0x2e\n\t \ cmp $0,_dwCallOldGPFaultHandler\n\t \ je do_iret\n\t \ \n\t \ // call old pagefault handler\n\t \ .byte 0x2e\n\t \ pushl _error_code\n\t \ .byte 0x2e\n\t \ jmp *_OldGPFaultHandler\n\t \ \n\t \ do_iret:\n\t \ //ei\n\t \ //int3\n\t \ iretl ")
#define FALSE
Definition: types.h:117
USHORT OldCS
Definition: shell.c:123
#define REASON_HARDWARE_BP
Definition: shell.h:76
volatile BOOLEAN bSingleStep
Definition: shell.c:129
smooth NULL
Definition: ftsmooth.c:557
ULONG dwCallOldGPFaultHandler
Definition: shell.c:60
USHORT CurrentFS
Definition: shell.c:116
void DPRINT(...)
Definition: polytest.cpp:61
ULONG dwCallOldInt3Handler
Definition: shell.c:58
char tempShell[256]
Definition: shell.c:86
unsigned char BOOLEAN
volatile BOOLEAN bControl
Definition: shell.c:70
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:112
void(* Callback)(void)
Definition: bp.h:42
ULONG dwCallOldIntEHandler
Definition: shell.c:59
void TryToInstallVirtualSWBreakpoints(void)
Definition: bp.c:331
ULONG GetLinearAddress(USHORT Segment, ULONG Offset)
Definition: utils.c:782
ULONG CurrentCR2
Definition: shell.c:118
void InstallPrintkHook(void)
Definition: output.c:252
#define REASON_SINGLESTEP
Definition: shell.h:72
BOOLEAN ReInstallSWBreakpoint(ULONG ulAddress)
Definition: bp.c:197
PSW_BP IsPermanentSWBreakpoint(ULONG ulAddress)
Definition: bp.c:520
LPSTR FindSourceLineForAddress(ULONG addr, PULONG pulLineNumber, LPSTR *ppSrcStart, LPSTR *ppSrcEnd, LPSTR *ppFilename)
Definition: symbols.c:1476
BOOLEAN bStepThroughSource
Definition: shell.c:64
BOOLEAN bIrqStateAtBreak
Definition: shell.c:80
ULONG g_ulLineNumberStart
Definition: shell.c:62
void DebuggerShell(void)
Definition: shell.c:307
static ULONG OLD_PCR
Definition: shell.c:84
ULONG CurrentEIP
Definition: shell.c:113
BOOLEAN NeedToReInstallSWBreakpoints(ULONG ulAddress, BOOLEAN bUseAddress)
Definition: bp.c:150
BOOLEAN DeInstallSWBreakpoint(ULONG ulAddress)
Definition: bp.c:428
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
BOOLEAN IsSwBpAtAddressInstalled(ULONG ulAddress)
Definition: bp.c:113
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
ULONG CurrentESP
Definition: shell.c:115
BOOLEAN ScanExportsByAddress(LPSTR *pFind, ULONG ulValue)
Definition: symbols.c:599
ULONG CurrentEFL
Definition: shell.c:113
GLfloat GLfloat p
Definition: glext.h:8902
ULONG bPreviousCommandWasGo
Definition: shell.c:54
volatile BOOLEAN bNotifyToExit
Definition: shell.c:76
#define REASON_INT3
Definition: shell.h:71
#define REASON_CTRLF
Definition: shell.h:73
#define REASON_PAGEFAULT
Definition: shell.h:74
void ShowStatusLine ( void  )

Definition at line 216 of file shell.c.

Referenced by DebuggerShell(), Parse(), and RepaintDesktop().

217 {
218  PEPROCESS pCurrentProcess = IoGetCurrentProcess();
219  LPSTR pProcessName;
220 
221  ENTER_FUNC();
222 
223  if(IsAddressValid((ULONG)pCurrentProcess))
224  {
227 
229 
230  pProcessName = pCurrentProcess->ImageFileName;
231  if(IsAddressValid((ULONG)pProcessName) )
232  {
234  " PROCESS(%.8X \"%s\") ",
235  (ULONG)pCurrentProcess,pProcessName);
236  }
237  else
238  {
240  " PROCESS(%.8X) ",
241  (ULONG)pCurrentProcess);
242  }
244 
245  ResetColor();
246  }
247 
248  LEAVE_FUNC();
249 }
void SetForegroundColor(ECOLORS c)
Definition: hardware.c:576
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
#define LEAVE_FUNC()
Definition: debug.h:43
char * LPSTR
Definition: xmlstorage.h:182
#define COLOR_TEXT
Definition: hardware.h:158
void ClrLine(ULONG line)
Definition: hardware.c:662
WINDOW wWindow[4]
Definition: hardware.c:59
char tempShell[256]
Definition: shell.c:86
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:112
void PutChar(LPSTR p, ULONG x, ULONG y)
Definition: hardware.c:604
void SetBackgroundColor(ECOLORS c)
Definition: hardware.c:590
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
void ResetColor(void)
Definition: hardware.c:500
#define COLOR_CAPTION
Definition: hardware.h:156
INT INT y
Definition: msvc.h:62
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611

Variable Documentation

volatile BOOLEAN bControl

Definition at line 70 of file shell.c.

Referenced by bNoCtrlKeys(), DebuggerShell(), KeyboardGetKeyPolled(), PiceKbdIsr(), and RealIsr().

volatile BOOLEAN bEnterNow

Definition at line 75 of file shell.c.

Referenced by PiceKbdIsr(), and RealIsr().

volatile BOOLEAN bInDebuggerShell

Definition at line 79 of file shell.c.

Referenced by HandlePageFault(), and RealIsr().

volatile BOOLEAN bNotifyToExit

Definition at line 76 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), DebuggerShell(), and RealIsr().

volatile BOOLEAN bShift

Definition at line 71 of file shell.c.

Referenced by AsciiFromScan(), AsciiToScan(), bNoCtrlKeys(), DebuggerShell(), and KeyboardGetKeyPolled().

volatile BOOLEAN bSingleStep

Definition at line 129 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), and RealIsr().

BOOLEAN bStepInto

Definition at line 65 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), and RealIsr().

BOOLEAN bStepThroughSource

Definition at line 64 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), and RealIsr().

ULONG CurrentCR0

Definition at line 118 of file shell.c.

ULONG CurrentCR2

Definition at line 118 of file shell.c.

Referenced by RealIsr().

ULONG CurrentCR3

Definition at line 118 of file shell.c.

ULONG CurrentDR0

Definition at line 117 of file shell.c.

ULONG CurrentDR1

Definition at line 117 of file shell.c.

ULONG CurrentDR2

Definition at line 117 of file shell.c.

ULONG CurrentDR3

Definition at line 117 of file shell.c.

ULONG CurrentDR6

Definition at line 117 of file shell.c.

ULONG CurrentDR7

Definition at line 117 of file shell.c.

USHORT CurrentDS

Definition at line 116 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), DisplayRegs(), InitPICE(), and SaveOldRegs().

ULONG CurrentEAX

Definition at line 114 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentEBX

Definition at line 114 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentECX

Definition at line 114 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentEDI

Definition at line 115 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentEDX

Definition at line 114 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentEFL

Definition at line 113 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), DisplayRegs(), RealIsr(), and SaveOldRegs().

USHORT CurrentES

Definition at line 116 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentESI

Definition at line 115 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG CurrentESP

Definition at line 115 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), DisplayRegs(), PrintkCallback(), RealIsr(), and SaveOldRegs().

USHORT CurrentFS

Definition at line 116 of file shell.c.

Referenced by DisplayRegs(), RealIsr(), and SaveOldRegs().

USHORT CurrentGS

Definition at line 116 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

USHORT CurrentSS

Definition at line 116 of file shell.c.

Referenced by DisplayRegs(), InitPICE(), PrintkCallback(), and SaveOldRegs().

ULONG g_ulLineNumberStart

Definition at line 62 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), and RealIsr().

USHORT OldCS

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), RealIsr(), and SaveOldRegs().

USHORT OldDS

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEAX

Definition at line 121 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEBP

Definition at line 122 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEBX

Definition at line 121 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldECX

Definition at line 121 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEDI

Definition at line 122 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEDX

Definition at line 121 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEFL

Definition at line 120 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldEIP

Definition at line 120 of file shell.c.

Referenced by DisplayRegs(), RealIsr(), and SaveOldRegs().

USHORT OldES

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldESI

Definition at line 122 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldESP

Definition at line 122 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

USHORT OldFS

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

USHORT OldGS

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

ULONG OldOffset
USHORT OldSelector

Definition at line 89 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), DebuggerShell(), and RepaintDesktop().

USHORT OldSS

Definition at line 123 of file shell.c.

Referenced by DisplayRegs(), and SaveOldRegs().

volatile UCHAR ucKeyPressedWhileIdle

Definition at line 78 of file shell.c.

Referenced by DebuggerShell(), and WaitForKey().

ULONG ulRealStackPtr

Definition at line 82 of file shell.c.

Referenced by COMMAND_PROTOTYPE(), and HandleInDebuggerFault().