ReactOS  0.4.14-dev-614-gbfd8a84
shell.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  shell.c
8 
9 Abstract:
10 
11  user interface for debugger
12 
13 Environment:
14 
15  Kernel mode only
16 
17 Author:
18 
19  Klaus P. Gerlicher
20 
21 Revision History:
22 
23  16-Jul-1998: created
24  22-Sep-1998: rewrite of keyboard hooking through patching the original keyboard driver
25  29-Sep-1998: started documentation on project
26  15-Nov-2000: general cleanup of source files
27 
28 Copyright notice:
29 
30  This file may be distributed under the terms of the GNU Public License.
31 
32 --*/
33 
35 // INCLUDES
37 #include "remods.h"
38 #include "precomp.h"
39 
40 
42 // DEFINES
44 #define LINES_IN_COMMAND_BUFFER (64)
45 
47 // PROTOTYPES
49 
51 // GLOBALS
53 
55 
56 // flags to set when we need to pass things to the old INT handlers
61 
66 
67 // key handling
68 UCHAR ucConverted; // key converted from scancode to ANSI
69 
70 volatile BOOLEAN bControl=FALSE; // TRUE when CTRL key was pressed
71 volatile BOOLEAN bShift=FALSE; // TRUE when SHIFT key was pressed
72 volatile BOOLEAN bAlt=FALSE; // TRUE when ALT key was pressed
73 volatile ULONG OldInt31Handler; // address of old keyboard ISR
74 volatile ULONG OldGlobalInt31Handler; // address of old global keyboard ISR
75 volatile BOOLEAN bEnterNow=FALSE; // TRUE if already stopped
76 volatile BOOLEAN bNotifyToExit=FALSE; // TRUE when debugger should leave
77 volatile BOOLEAN bSkipMainLoop=FALSE; // TRUE when debugger should skip main loop
78 volatile UCHAR ucKeyPressedWhileIdle=0; // key pressed when system was stopped
79 volatile BOOLEAN bInDebuggerShell=FALSE; // TRUE while in DebuggerShell()
81 
83 static ULONG PCR_SEL = PCR_SELECTOR;
84 static ULONG OLD_PCR;
85 
86 char tempShell[256]; // temporary string container
87 
88 // old address of display memory
91 
93 
94 // functions of function keys
95 char *szFunctionKeys[10]={
96  "mod", // F1
97  "proc", // F2
98  "src", // F3
99  "code", // F4
100  "x", // F5
101  "vma", // F6
102  "", // F7
103  "t", // F8
104  "", // F9
105  "p" // F10
106 };
107 
108 // new stack for "deep parsing"
111 
112 // registers save area (context)
119 // previous context
124 
126 
130 
131 // the last command lines
135 
136 
137 extern ULONG KeyboardIRQL;
138 
139 //*************************************************************************
140 // GetLinesInCommandHistory()
141 //
142 //*************************************************************************
144 {
146 
147  ENTER_FUNC();
148 
149  DPRINT((0,"GetLinesInCommandHistory() returns %u (ulIn %u ulLast %u)\n",ulResult,ulCommandInPos,ulCommandLastPos));
150 
151  LEAVE_FUNC();
152 
153  return ulResult;
154 }
155 
156 //*************************************************************************
157 // AddToCommandLineHistory()
158 //
159 //*************************************************************************
161 {
162  ULONG i;
163 
164  ENTER_FUNC();
165  DPRINT((0,"AddToCommandLineHistory(%s)\n",s));
166 
167  if(PICE_strlen(s))
168  {
169  for(i=0;i<LINES_IN_COMMAND_BUFFER;i++)
170  {
171  if(PICE_strcmpi(&aszCommandLines[i][1],s) == 0)
172  {
173  DPRINT((0,"AddToCommandLineHistory(): command line already exists\n"));
174  LEAVE_FUNC();
175  return;
176  }
177  }
182  {
184  }
185  }
186 
187  LEAVE_FUNC();
188 }
189 
190 //*************************************************************************
191 // GetFromCommandLineHistory()
192 //
193 //*************************************************************************
195 {
196  LPSTR pRet;
197 
198  ENTER_FUNC();
199 
200  DPRINT((0,"GetFromCommandLineHistory(): current = %u\n",ulCurrentCommandPos));
201 
202  // skip leading ':'
203  pRet = aszCommandLines[ulCurrentCommandPos] + 1;
204 
205  DPRINT((0,"GetFromCommandLineHistory(%s)\n",pRet));
206 
207  LEAVE_FUNC();
208 
209  return pRet;
210 }
211 
212 //*************************************************************************
213 // ShowStatusLine()
214 //
215 //*************************************************************************
216 void ShowStatusLine(void)
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 }
250 
251 //*************************************************************************
252 // ProcessBootParams()
253 //
254 //*************************************************************************
256 {
257  LPSTR p1,p2;
258 
259  ENTER_FUNC();
260  if(*szBootParams)
261  {
262  DPRINT((0,"ProcessBootParams()\n"));
263 
264  p1 = szBootParams;
265 
266  while(*p1)
267  {
268  p2 = ucCommandBuffer;
269  DPRINT((0,"ProcessBootParams(): boot params = %s\n",p1));
270  while(*p1 && *p1!=';')
271  {
272  *p2++ = *p1++;
273  }
274  *p2=0;
275  DPRINT((0,"ProcessBootParams(): cmd buf = %s\n",ucCommandBuffer));
276  if(*p1 != ';')
277  {
278  DPRINT((0,"ProcessBootParams(): error in cmd buf\n"));
279  break;
280  }
281  p1++;
282  DPRINT((0,"ProcessBootParams(): next cmd buf = %s\n",p1));
283 
285  }
287  *szBootParams = 0;
288  }
289  LEAVE_FUNC();
290 }
291 
292 //*************************************************************************
293 // bNoCtrlKeys()
294 //
295 //*************************************************************************
296 BOOLEAN __inline bNoCtrlKeys(void)
297 {
298  return (!bControl && !bAlt && !bShift);
299 }
300 
301 
302 //*************************************************************************
303 // DebuggerShell()
304 //
305 // handle user interface when stopped system
306 //*************************************************************************
307 void DebuggerShell(void)
308 {
309  ARGS Args;
310  UCHAR speaker;
311  PEPROCESS pCurrentProcess;
312 
313  ENTER_FUNC();
314 
315  // save the graphics state
317 
318  // tell USER we are stopped
319  ShowStoppedMsg();
320 
322 
323  CheckRingBuffer();
324 
325  // kill the speakers annoying beep
326  speaker = inb_p((PCHAR)0x61);
327  speaker &= 0xFC;
328  outb_p(speaker,(PCHAR)0x61);
329 
331 
332  DPRINT((0,"DebuggerShell(): DisplayRegs()\n"));
333  // display register contents
334  DisplayRegs();
335 
336  DPRINT((0,"DebuggerShell(): DisplayMemory()\n"));
337  // display data window
338  Args.Value[0]=OldSelector;
339  Args.Value[1]=OldOffset;
340  Args.Count=2;
342 
343  DPRINT((0,"DebuggerShell(): Unassemble()\n"));
344 
345  // disassembly from current address
346  PICE_memset(&Args,0,sizeof(ARGS));
347  Args.Value[0]=CurrentCS;
348  Args.Value[1]=CurrentEIP;
349  Args.Count=2;
350  Unassemble(&Args);
351 
352  // try to find current process's name
353  pCurrentProcess = IoGetCurrentProcess();
354  CurrentProcess = (ULONG)pCurrentProcess;
355 
356  // display status line
357  ShowStatusLine();
358 
359  // switch on cursor
360  ShowCursor();
361 
362  // while we are not told to exit
363  while(bNotifyToExit==FALSE)
364  {
365  // emulate graphics cursor
367 
368  // we have a key press
370  {
371  DPRINT((0,"DebuggerShell(): key = %x control = %u shift = %u\n",ucKeyPressedWhileIdle,bControl,bShift));
372 
373  // if cursor reversed, normalize it again (only graphics)
374  if(bRev)
375  {
376  PrintCursor(TRUE);
377  }
378 
379  // convert key to ANSI, if success add to command buffer and try to
380  // find a command that fits the already entered letters
382 
383 #if 0
386 #endif
387 
388  if(!bControl && !bAlt && ucConverted)
389  {
390  DPRINT((0,"DebuggerShell(): normal key\n"));
391  if(!(usCurrentPosInInputBuffer==0 && ucConverted==' '))
392  {
393  // if we have space in the command buffer
394  // put the character there
396  {
398  // output the character
402  }
403  // if we have something in command buffer
404  // try to find command help that fits
406  {
408  }
409  else ShowStoppedMsg();
410  }
411  }
412  // normal key while holding down CONTROL
413  else if(bControl && !bAlt && !bShift && ucConverted)
414  {
415  if(ucConverted == 'f')
417  }
418  // normal key while holding down ALT
419  else if(!bControl && bAlt && !bShift && ucConverted)
420  {
421  }
422  // normal key while holding down ALT & CONTROL
423  else if(bControl && bAlt && !bShift && ucConverted)
424  {
425  }
426  // we didn't get a converted key
427  // so this must be a control key
428  else
429  {
430  // RETURN
432  {
433  DPRINT((0,"DebuggerShell(): RETURN\n"));
435  if(ucCommandBuffer[0])
436  {
441  // setup a safe stack for parsing
442  __asm__ __volatile__("\n\t \
443  movl %2,%%eax\n\t \
444  movl %%esp,%%ebx\n\t \
445  mov %%ebx,%0\n\t \
446  leal _aulNewStack,%%ebx\n\t \
447  addl $0x1FFF0,%%ebx\n\t \
448  movl %%ebx,%%esp\n\t \
449  pushl $0\n\t \
450  pushl %%eax\n\t \
451  call _Parse\n\t \
452  movl %0,%%ebx\n\t \
453  movl %%ebx,%%esp"
454  :"=m" (ulOldStack)
455  :"m" (ulOldStack),"m" (ucCommandBuffer)
456  :"eax","ebx");
457 
458  ShowStoppedMsg();
459  }
460  else
461  {
463  {
466  }
467  }
470  }
471  // backspace
473  {
474  DPRINT((0,"DebuggerShell(): BACKSPACE\n"));
476  {
479  else
480  ShowStoppedMsg();
481 
484  Print(OUTPUT_WINDOW,"\b");
485  }
486  }
487  // Tab
489  {
490  DPRINT((0,"DebuggerShell(): TAB\n"));
492  {
493  LPSTR pCmd;
494 
495  if((pCmd=FindCommand(ucCommandBuffer)) )
496  {
497  ULONG i;
498 
499  // clear the displayed command line
500  for(i=0;i<usCurrentPosInInputBuffer;i++)
501  Print(OUTPUT_WINDOW,"\b");
502  // clear command buffer
504  // copy the found command into command buffer
509  }
510  }
511  }
512  else
513  {
514  // function keys
516  {
517  DPRINT((0,"DebuggerShell(): FUNCTION %u\n",ucKeyPressedWhileIdle-59));
518  PICE_sprintf(tempShell,":");
525  if(ucCommandBuffer[0])
526  {
529 
530  // setup a safe stack for parsing
531  __asm__ __volatile__("\n\t \
532  movl %2,%%eax\n\t \
533  movl %%esp,%%ebx\n\t \
534  mov %%ebx,%0\n\t \
535  leal _aulNewStack,%%ebx\n\t \
536  addl $0x1FFF0,%%ebx\n\t \
537  movl %%ebx,%%esp\n\t \
538  pushl $1\n\t \
539  pushl %%eax\n\t \
540  call _Parse\n\t \
541  movl %0,%%ebx\n\t \
542  movl %%ebx,%%esp"
543  :"=m" (ulOldStack)
544  :"m" (ulOldStack),"m" (ucCommandBuffer)
545  :"eax","ebx");
548  }
549  }
550  else
551  {
552  switch(ucKeyPressedWhileIdle)
553  {
554  case SCANCODE_ESC:
556  {
557  PICE_sprintf(tempShell,":");
561  Print(OUTPUT_WINDOW,"");
562  ShowStoppedMsg();
563  }
564  break;
565  case SCANCODE_HOME: // home
566  DPRINT((0,"DebuggerShell(): HOME\n"));
567  // memory window
568  if(bAlt)
569  {
570  DPRINT((0,"DebuggerShell(): data window home\n"));
571  OldOffset=0x0;
572  // display data window
573  Args.Value[0]=OldSelector;
574  Args.Value[1]=OldOffset;
575  Args.Count=2;
577  }
578  // output window
579  else if(bShift)
580  {
581  DPRINT((0,"DebuggerShell(): output window home\n"));
583  {
586  }
587  }
588  // source window home
589  else if(bControl)
590  {
592  {
594 
596  {
598 
600  (LPSTR)pSrc+pSrc->ulOffsetToNext,
601  1,-1);
602  }
603  }
604  }
605  else if(!bShift && !bControl && !bAlt)
606  {
607  }
608  break;
609  case SCANCODE_END: // end
610  DPRINT((0,"DebuggerShell(): END\n"));
611  // memory window
612  if(bAlt)
613  {
614  DPRINT((0,"DebuggerShell(): data window end\n"));
615  OldOffset=0xFFFFFFFF-0x10*4;
616  // display data window
617  Args.Value[0]=OldSelector;
618  Args.Value[1]=OldOffset;
619  Args.Count=2;
621  }
622  // output window
623  else if(bShift)
624  {
625  DPRINT((0,"DebuggerShell(): output window end\n"));
627  {
629 
631  }
632  }
633  else if(!bShift && !bControl && !bAlt)
634  {
635  }
636  break;
637  case SCANCODE_UP: // up
638  DPRINT((0,"DebuggerShell(): UP\n"));
639  // memory window
640  if(bAlt)
641  {
642  DPRINT((0,"DebuggerShell(): data window up\n"));
643  OldOffset-=0x10;
644  // display data window
645  Args.Value[0]=OldSelector;
646  Args.Value[1]=OldOffset;
647  Args.Count=2;
649  }
650  // output window
651  else if(bShift)
652  {
653  DPRINT((0,"DebuggerShell(): output window up ulLastLineDisplayedOffset = %u\n",ulLastLineDisplayedOffset));
654 
656  {
658 
660  }
661  }
662  // source window up
663  else if(bControl)
664  {
666  {
668 
670  {
673  (LPSTR)pSrc+pSrc->ulOffsetToNext,
675  }
676  }
677  else
678  {
680  }
681  }
682  // command line history
683  else if(!bShift && !bControl && !bAlt)
684  {
685  LPSTR pCurrentCmd;
686  ULONG len;
687 
688  DPRINT((0,"DebuggerShell(): command line up\n"));
689 
690  // only if anything in history
692  {
693  // go to next entry in history
696  else
698  DPRINT((0,"DebuggerShell(): current history pos = %u\n",ulCommandCurrentPos));
699  // get this entry
701  // if it has a string attached
702  if((len = PICE_strlen(pCurrentCmd)))
703  {
704  // replace the current command line
705  PICE_sprintf(tempShell,":");
708  PICE_strcpy(ucCommandBuffer,pCurrentCmd);
710  Print(OUTPUT_WINDOW,pCurrentCmd);
711  }
712  }
713  }
714  break;
715  case SCANCODE_DOWN: // down
716  DPRINT((0,"DebuggerShell(): DOWN\n"));
717  // memory window
718  if(bAlt)
719  {
720  DPRINT((0,"DebuggerShell(): data window down\n"));
721  OldOffset+=0x10;
722  // display data window
723  Args.Value[0]=OldSelector;
724  Args.Value[1]=OldOffset;
725  Args.Count=2;
727  }
728  // output window
729  else if(bShift)
730  {
731  DPRINT((0,"DebuggerShell(): output window down ulLastLineDisplayedOffset = %u\n",ulLastLineDisplayedOffset));
733  {
735 
737  {
740  }
741  }
742  }
743  // source window down
744  else if(bControl)
745  {
747  {
749 
751  {
754  (LPSTR)pSrc+pSrc->ulOffsetToNext,
756  }
757  }
758  else
759  {
761  }
762  }
763  // command line history
764  else if(!bShift && !bControl && !bAlt)
765  {
766  LPSTR pCurrentCmd;
767  ULONG len;
768 
769  DPRINT((0,"DebuggerShell(): command line down\n"));
770 
771  // only if anything in history
773  {
774  // go to next entry in history
776  DPRINT((0,"DebuggerShell(): current history pos = %u\n",ulCommandCurrentPos));
777  // get this entry
779  // if it has a string attached
780  if((len = PICE_strlen(pCurrentCmd)))
781  {
782  // replace the current command line
783  PICE_sprintf(tempShell,":");
786  PICE_strcpy(ucCommandBuffer,pCurrentCmd);
788  Print(OUTPUT_WINDOW,pCurrentCmd);
789  }
790  }
791  }
792  break;
793  case SCANCODE_LEFT: // left
794  DPRINT((0,"DebuggerShell(): LEFT\n"));
795  // memory window
796  if(bAlt)
797  {
798  DPRINT((0,"DebuggerShell(): data window left\n"));
799 
800  OldOffset-=0x1;
801  // display data window
802  Args.Value[0]=OldSelector;
803  Args.Value[1]=OldOffset;
804  Args.Count=2;
806  }
807  else if(!bShift && !bControl && !bAlt)
808  {
809  }
810  else if(bControl)
811  {
812  if(ulWindowOffset > 0)
813  ulWindowOffset--;
814  PICE_memset(&Args,0,sizeof(ARGS));
815  Args.Count=0;
816  Unassemble(&Args);
817  }
818  break;
819  case SCANCODE_RIGHT: // right
820  // memory window
821  if(bAlt)
822  {
823  DPRINT((0,"DebuggerShell(): data window right\n"));
824 
825  OldOffset+=0x1;
826  // display data window
827  Args.Value[0]=OldSelector;
828  Args.Value[1]=OldOffset;
829  Args.Count=2;
831  }
832  else if(!bShift && !bControl && !bAlt)
833  {
834  }
835  else if(bControl)
836  {
837  if(ulWindowOffset < 80)
838  ulWindowOffset++;
839  PICE_memset(&Args,0,sizeof(ARGS));
840  Args.Count=0;
841  Unassemble(&Args);
842  }
843  break;
844  case SCANCODE_PGUP: // page up
845  DPRINT((0,"DebuggerShell(): PAGEUP\n"));
846  // memory window
847  if(bAlt)
848  {
850  // display data window
851  Args.Value[0]=OldSelector;
852  Args.Value[1]=OldOffset;
853  Args.Count=2;
855  }
856  // output window
857  else if(bShift)
858  {
860  {
862 
864  }
865  else
866  {
868  {
871  }
872  }
873  }
874  // source window page up
875  else if(bControl)
876  {
878  {
880  {
882 
884  {
886 
888  (LPSTR)pSrc+pSrc->ulOffsetToNext,
890  }
891  }
892  else
893  {
895 
897  {
899 
901  (LPSTR)pSrc+pSrc->ulOffsetToNext,
903  }
904  }
905  }
906  else
907  {
909  }
910 
911  }
912  else if(!bShift && !bControl && !bAlt)
913  {
914  }
915  break;
916  case SCANCODE_PGDN: // page down
917  DPRINT((0,"DebuggerShell(): PAGEDOWN\n"));
918  // memory window
919  if(bAlt)
920  {
922  // display data window
923  Args.Value[0]=OldSelector;
924  Args.Value[1]=OldOffset;
925  Args.Count=2;
927  }
928  else if(bShift)
929  {
931  {
933 
935  }
936  else
937  {
939  {
942  }
943  }
944  }
945  else if(bControl)
946  {
948  {
950  {
952 
954  {
956 
958  (LPSTR)pSrc+pSrc->ulOffsetToNext,
960  }
961  }
962  else
963  {
965 
967  {
969 
971  (LPSTR)pSrc+pSrc->ulOffsetToNext,
973  }
974  }
975  }
976  else
977  {
979  }
980  }
981  else if(!bShift && !bControl && !bAlt)
982  {
983  }
984  break;
985  }
986  }
987  }
988  }
990  }
991  }
992 
993  SaveOldRegs();
994 
995  PrintLogo(TRUE);
996 
997  ShowRunningMsg();
998 
999  if(bRev)
1000  PrintCursor(TRUE);
1001 
1002  // hide the cursor
1003  HideCursor();
1004 
1006 
1008 
1009  LEAVE_FUNC();
1010 }
1011 
1012 //*************************************************************************
1013 // RealIsr()
1014 //
1015 //*************************************************************************
1016 void RealIsr(ULONG dwReasonForBreak)
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 }
1465 
1466 
1467 __asm__(".global NewInt31Handler\n\t \
1468 NewInt31Handler:\n\t \
1469  cli\n\t \
1470  cld\n\t \
1471 \n\t \
1472  pushl %eax\n\t \
1473  pushl %ds\n\t \
1474 \n\t \
1475  movw %ss,%ax\n\t \
1476  mov %ax,%ds\n\t \
1477 \n\t \
1478  mov 0x4(%esp),%eax\n\t \
1479  movl %eax,_CurrentEAX\n\t \
1480  movl %ebx,_CurrentEBX\n\t \
1481  movl %ecx,_CurrentECX\n\t \
1482  movl %edx,_CurrentEDX\n\t \
1483  movl %esi,_CurrentESI\n\t \
1484  movl %edi,_CurrentEDI\n\t \
1485  movl %ebp,_CurrentEBP\n\t \
1486  movl (%esp),%eax\n\t \
1487  movw %ax,_CurrentDS\n\t \
1488 \n\t \
1489  // test for V86 mode\n\t \
1490  testl $0x20000,5*4(%esp)\n\t \
1491  jz notV86\n\t \
1492 \n\t \
1493  int $0x03\n\t \
1494 \n\t \
1495 notV86:\n\t \
1496  // test if stack switched (ring3->ring0 transition)\n\t \
1497  // stack is switched if orig. SS is not global kernel code segment\n\t \
1498  movl 4*4(%esp),%eax\n\t \
1499  cmpw $" STR(GLOBAL_CODE_SEGMENT) ",%ax\n\t \
1500  je notswitched\n\t \
1501 \n\t \
1502  // switched stack\n\t \
1503  movl 6*4(%esp),%eax\n\t \
1504  mov %eax,_CurrentESP\n\t \
1505  mov 7*4(%esp),%eax\n\t \
1506  movzwl %ax,%eax\n\t \
1507  mov %ax,_CurrentSS\n\t \
1508  jmp afterswitch\n\t \
1509 \n\t \
1510 notswitched:\n\t \
1511  // didn't switch stack\n\t \
1512  movl %esp,_CurrentESP\n\t \
1513  addl $24,_CurrentESP\n\t \
1514  movw %ss,%ax\n\t \
1515  movzwl %ax,%eax\n\t \
1516  mov %ax,_CurrentSS\n\t \
1517 \n\t \
1518 afterswitch:\n\t \
1519  // save EIP\n\t \
1520  mov 3*4(%esp),%eax\n\t \
1521  mov %eax,_CurrentEIP\n\t \
1522  //save CS\n\t \
1523  mov 4*4(%esp),%eax\n\t \
1524  movzwl %ax,%eax\n\t \
1525  movw %ax,_CurrentCS\n\t \
1526  // save flags\n\t \
1527  movl 5*4(%esp),%eax\n\t \
1528  andl $0xFFFFFEFF,%eax\n\t \
1529  movl %eax,_CurrentEFL\n\t \
1530 \n\t \
1531  pushal\n\t \
1532 \n\t \
1533  // get reason code\n\t \
1534  mov 0x28(%esp),%ebx\n\t \
1535 \n\t \
1536  /*\n\t \
1537  * Load the PCR selector.\n\t \
1538  */\n\t \
1539 \n\t \
1540  movl %fs, %eax\n\t \
1541  movl %eax, _OLD_PCR\n\t \
1542  movl _PCR_SEL, %eax\n\t \
1543  movl %eax, %fs\n\t \
1544 \n\t \
1545  // setup a large work stack\n\t \
1546  movl %esp,%eax\n\t \
1547  movl %eax,_ulRealStackPtr\n\t \
1548 \n\t \
1549  pushl %ebx\n\t \
1550  call _RealIsr\n\t \
1551  addl $4,%esp\n\t \
1552 \n\t \
1553  pushl %eax\n\t \
1554  movl _OLD_PCR, %eax\n\t \
1555  movl %eax, %fs\n\t \
1556  popl %eax\n\t \
1557 \n\t \
1558  // restore all regs\n\t \
1559  popal\n\t \
1560 \n\t \
1561  // do an EOI to IRQ controller (because we definitely pressed some key)\n\t \
1562  // TODO: SMP APIC support\n\t \
1563  movb $0x20,%al\n\t \
1564  outb %al,$0x20\n\t \
1565 \n\t \
1566  popl %ds\n\t \
1567  popl %eax\n\t \
1568 \n\t \
1569  // remove reason code\n\t \
1570  addl $4,%esp\n\t \
1571 \n\t \
1572  // make EAX available\n\t \
1573  pushl %eax\n\t \
1574 \n\t \
1575  // modify or restore EFLAGS\n\t \
1576  .byte 0x2e\n\t \
1577  mov _CurrentEFL,%eax\n\t \
1578  mov %eax,3*4(%esp)\n\t \
1579  .byte 0x2e\n\t \
1580  movzwl _CurrentCS,%eax\n\t \
1581  mov %eax,2*4(%esp)\n\t \
1582  .byte 0x2e\n\t \
1583  mov _CurrentEIP,%eax\n\t \
1584  mov %eax,1*4(%esp)\n\t \
1585 \n\t \
1586  // restore EAX\n\t \
1587  popl %eax\n\t \
1588 \n\t \
1589  // do we need to call old INT1 handler\n\t \
1590  .byte 0x2e\n\t \
1591  cmp $0,_dwCallOldInt1Handler\n\t \
1592  je do_iret2\n\t \
1593 \n\t \
1594  // call INT3 handler\n\t \
1595  .byte 0x2e\n\t \
1596  jmp *_OldInt1Handler\n\t \
1597 \n\t \
1598 do_iret2:\n\t \
1599  // do we need to call old INT3 handler\n\t \
1600  .byte 0x2e\n\t \
1601  cmp $0,_dwCallOldInt3Handler\n\t \
1602  je do_iret1\n\t \
1603 \n\t \
1604  // call INT3 handler\n\t \
1605  .byte 0x2e\n\t \
1606  jmp *_OldInt3Handler\n\t \
1607 \n\t \
1608 do_iret1:\n\t \
1609  // do we need to call old pagefault handler\n\t \
1610  .byte 0x2e\n\t \
1611  cmp $0,_dwCallOldIntEHandler\n\t \
1612  je do_iret3\n\t \
1613 \n\t \
1614  // call old pagefault handler\n\t \
1615  .byte 0x2e\n\t \
1616  pushl _error_code\n\t \
1617  .byte 0x2e\n\t \
1618  jmp *_OldIntEHandler\n\t \
1619 \n\t \
1620 do_iret3:\n\t \
1621  // do we need to call old general protection fault handler\n\t \
1622  .byte 0x2e\n\t \
1623  cmp $0,_dwCallOldGPFaultHandler\n\t \
1624  je do_iret\n\t \
1625 \n\t \
1626  // call old pagefault handler\n\t \
1627  .byte 0x2e\n\t \
1628  pushl _error_code\n\t \
1629  .byte 0x2e\n\t \
1630  jmp *_OldGPFaultHandler\n\t \
1631 \n\t \
1632 do_iret:\n\t \
1633  //ei\n\t \
1634  //int3\n\t \
1635  iretl ");
1636 
1637 //
1638 // stub for entering via CTRL-F
1639 //
1640 // IDTs keyboard IRQ points here
1641 //
1642 __asm__ ("\n\t \
1643 NewGlobalInt31Handler:\n\t \
1644  .byte 0x2e\n\t \
1645  cmpb $0,_bEnterNow\n\t \
1646  jne dotheenter\n\t \
1647 \n\t \
1648  // chain to old handler\n\t \
1649  .byte 0x2e\n\t \
1650  jmp *_OldGlobalInt31Handler\n\t \
1651 \n\t \
1652 dotheenter:\n\t \
1653  pushl $" STR(REASON_CTRLF) "\n\t \
1654  jmp NewInt31Handler "
1655 );
1656 
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 }
1676 
1678 {
1679  ENTER_FUNC();
1680 
1681  MaskIrqs();
1683  {
1686  }
1687  UnmaskIrqs();
1688 
1689  LEAVE_FUNC();
1690 }
1691 
1692 
ULONG CurrentDR6
Definition: shell.c:117
USHORT CurrentCS
Definition: shell.c:116
signed char * PCHAR
Definition: retypes.h:7
ULONG OldESP
Definition: shell.c:122
volatile BOOLEAN bEnterNow
Definition: shell.c:75
void AddToCommandLineHistory(LPSTR s)
Definition: shell.c:160
#define SCANCODE_PGDN
Definition: scancodes.h:76
void SetForegroundColor(ECOLORS c)
Definition: hardware.c:576
ULONG LinesInRingBuffer(void)
Definition: hardware.c:116
char * szFunctionKeys[10]
Definition: shell.c:95
volatile ULONG OldInt31Handler
Definition: shell.c:73
volatile BOOLEAN bInDebuggerShell
Definition: shell.c:79
#define TRUE
Definition: types.h:120
#define REASON_DOUBLE_FAULT
Definition: shell.h:77
void HideCursor(void)
Definition: hardware.c:566
void UnassembleOnePageUp(ULONG page)
Definition: parse.c:1513
void UnassembleOneLineDown(void)
Definition: parse.c:1413
volatile UCHAR ucKeyPressedWhileIdle
Definition: shell.c:78
volatile BOOLEAN bSkipMainLoop
Definition: shell.c:77
ULONG OldESI
Definition: shell.c:122
#define SCANCODE_BACKSPACE
Definition: scancodes.h:36
ULONG ulRealStackPtr
Definition: shell.c:82
BOOLEAN bRev
Definition: hercules.c:53
#define SCANCODE_PGUP
Definition: scancodes.h:70
BOOLEAN PrintRingBufferHome(ULONG ulLines)
Definition: hardware.c:447
ULONG ulCommandCurrentPos
Definition: shell.c:134
BOOLEAN bStepInto
Definition: shell.c:65
#define LINES_IN_COMMAND_BUFFER
Definition: shell.c:44
USHORT CurrentSS
Definition: shell.c:116
USHORT OldGS
Definition: shell.c:123
void SaveOldRegs(void)
Definition: utils.c:1324
ULONG GLOBAL_SCREEN_WIDTH
Definition: hardware.c:62
ULONG OldEIP
Definition: shell.c:120
ULONG OldOffset
Definition: shell.c:90
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
LPSTR FindCommand(LPSTR p)
Definition: parse.c:3252
ULONG OldEDX
Definition: shell.c:121
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
void RealIsr(ULONG dwReasonForBreak)
Definition: shell.c:1016
ULONG dwCallOldInt1Handler
Definition: shell.c:57
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
struct Parse Parse
Definition: dwarfinfo.c:330
USHORT cy
Definition: hardware.h:33
ULONG OldEDI
Definition: shell.c:122
volatile BOOLEAN bShift
Definition: shell.c:71
USHORT OldFS
Definition: shell.c:123
#define SCANCODE_ENTER
Definition: scancodes.h:39
ULONG SetGlobalInt(ULONG dwInt, ULONG NewIntHandler)
Definition: hooks.c:95
BOOLEAN PrintRingBufferOffset(ULONG ulLines, ULONG ulOffset)
Definition: hardware.c:378
#define LEAVE_FUNC()
Definition: debug.h:43
void ShowCursor(void)
Definition: hardware.c:556
ULONG CurrentESI
Definition: shell.c:115
char * LPSTR
Definition: xmlstorage.h:182
Definition: bp.h:31
__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 DisplaySourceFile(LPSTR pSrcLine, LPSTR pSrcEnd, ULONG ulLineNumber, ULONG ulLineNumberToInvert)
Definition: parse.c:1313
ULONG CurrentDR3
Definition: shell.c:117
BOOLEAN bStepping
Definition: parse.c:63
ULONG OldEAX
Definition: shell.c:121
#define SCANCODE_ESC
Definition: scancodes.h:35
ULONG GetLinesInCommandHistory(void)
Definition: shell.c:143
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
#define STR(x)
Definition: utils.h:34
#define SCANCODE_LEFT
Definition: scancodes.h:71
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
BOOLEAN bShowSrc
Definition: parse.c:252
void UnassembleOnePageDown(ULONG page)
Definition: parse.c:1436
ULONG CurrentCR3
Definition: shell.c:118
#define REASON_GP_FAULT
Definition: shell.h:75
#define REASON_INTERNAL_ERROR
Definition: shell.h:79
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
USHORT OldCS
Definition: shell.c:123
char aszCommandLines[LINES_IN_COMMAND_BUFFER][sizeof(ucCommandBuffer)+2]
Definition: shell.c:132
USHORT OldSS
Definition: shell.c:123
#define REASON_HARDWARE_BP
Definition: shell.h:76
volatile BOOLEAN bSingleStep
Definition: shell.c:129
void InstallGlobalKeyboardHook(void)
Definition: shell.c:1657
void outb_p(UCHAR data, PUCHAR port)
Definition: utils.c:2159
UCHAR AsciiFromScan(UCHAR s)
Definition: utils.c:2069
#define SCANCODE_HOME
Definition: scancodes.h:68
#define SCANCODE_RIGHT
Definition: scancodes.h:73
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:581
#define SCANCODE_TAB
Definition: scancodes.h:37
ULONG CurrentDR7
Definition: shell.c:117
unsigned char BOOLEAN
#define COLOR_TEXT
Definition: hardware.h:158
smooth NULL
Definition: ftsmooth.c:416
ULONG CurrentEDI
Definition: shell.c:115
LONG ulCurrentlyDisplayedLineNumber
Definition: parse.c:46
ULONG dwCallOldGPFaultHandler
Definition: shell.c:60
void ProcessBootParams(void)
Definition: shell.c:255
void ClrLine(ULONG line)
Definition: hardware.c:662
USHORT CurrentFS
Definition: shell.c:116
void DPRINT(...)
Definition: polytest.cpp:61
char ** Args
Definition: acdebug.h:347
WINDOW wWindow[4]
Definition: hardware.c:59
void DeInstallGlobalKeyboardHook(void)
Definition: shell.c:1677
void MaskIrqs(void)
Definition: hooks.c:68
ULONG dwCallOldInt3Handler
Definition: shell.c:58
void ShowRunningMsg(void)
Definition: utils.c:843
ULONG OldEBP
Definition: shell.c:122
ULONG CurrentCR0
Definition: shell.c:118
USHORT OldDS
Definition: shell.c:123
TCHAR szCurrentFile[MAX_PATH]
Definition: mplay32.c:29
char tempShell[256]
Definition: shell.c:86
volatile BOOLEAN bControl
Definition: shell.c:70
ULONG CurrentProcess
Definition: shell.c:125
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:139
ULONG CurrentDR2
Definition: shell.c:117
#define SCANCODE_UP
Definition: scancodes.h:69
void RestoreGraphicsState(void)
Definition: hardware.c:906
ULONG aulNewStack[0x20000]
Definition: shell.c:109
UCHAR ucConverted
Definition: shell.c:68
USHORT CurrentDS
Definition: shell.c:116
ULONG dwCallOldIntEHandler
Definition: shell.c:59
void ReplaceRingBufferCurrent(LPSTR s)
Definition: hardware.c:301
BOOLEAN __inline bNoCtrlKeys(void)
Definition: shell.c:296
#define SCANCODE_DOWN
Definition: scancodes.h:75
Definition: parse.h:31
volatile BOOLEAN bAlt
Definition: shell.c:72
static ULONG PCR_SEL
Definition: shell.c:83
unsigned char UCHAR
Definition: xmlstorage.h:181
void ShowStatusLine(void)
Definition: shell.c:216
ULONG CurrentEDX
Definition: shell.c:114
void TryToInstallVirtualSWBreakpoints(void)
Definition: bp.c:331
ULONG GetLinearAddress(USHORT Segment, ULONG Offset)
Definition: utils.c:782
ULONG CurrentCR2
Definition: shell.c:118
ULONG CurrentECX
Definition: shell.c:114
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
void FlushKeyboardQueue(void)
Definition: hardware.c:935
void InstallPrintkHook(void)
Definition: output.c:252
void ShowStoppedMsg(void)
Definition: utils.c:861
void PrintRingBuffer(ULONG ulLines)
Definition: hardware.c:315
ULONG ulOldStack
Definition: shell.c:110
void DisplayRegs(void)
Definition: utils.c:1097
ULONG OldEBX
Definition: shell.c:121
#define REASON_SINGLESTEP
Definition: shell.h:72
void SaveGraphicsState(void)
Definition: hardware.c:897
USHORT CurrentGS
Definition: shell.c:116
BOOLEAN ReInstallSWBreakpoint(ULONG ulAddress)
Definition: bp.c:197
PSW_BP IsPermanentSWBreakpoint(ULONG ulAddress)
Definition: bp.c:520
ULONG ulCommandInPos
Definition: shell.c:133
ULONG OldECX
Definition: shell.c:121
ULONG ulCommandLastPos
Definition: shell.c:133
UCHAR GetKeyPolled(void)
Definition: hardware.c:926
LPSTR FindSourceLineForAddress(ULONG addr, PULONG pulLineNumber, LPSTR *ppSrcStart, LPSTR *ppSrcEnd, LPSTR *ppFilename)
Definition: symbols.c:1476
ULONG CurrentDR0
Definition: shell.c:117
BOOLEAN bStepThroughSource
Definition: shell.c:64
void PutChar(LPSTR p, ULONG x, ULONG y)
Definition: hardware.c:604
USHORT usCurrentPosInInputBuffer
Definition: shell.c:128
UCHAR inb_p(PUCHAR port)
Definition: utils.c:2179
USHORT OldES
Definition: shell.c:123
ULONG OldEFL
Definition: shell.c:120
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN bIrqStateAtBreak
Definition: shell.c:80
USHORT usCurX
Definition: hardware.h:34
LPSTR GetFromCommandLineHistory(ULONG ulCurrentCommandPos)
Definition: shell.c:194
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
volatile ULONG OldGlobalInt31Handler
Definition: shell.c:74
ULONG CurrentEBX
Definition: shell.c:114
BOOLEAN NeedToReInstallSWBreakpoints(ULONG ulAddress, BOOLEAN bUseAddress)
Definition: bp.c:150
ULONG CurrentEBP
Definition: shell.c:115
unsigned int * PULONG
Definition: retypes.h:1
ULONG CurrentDR1
Definition: shell.c:117
BOOLEAN DeInstallSWBreakpoint(ULONG ulAddress)
Definition: bp.c:428
void CheckRingBuffer(void)
Definition: hardware.c:133
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
void SetBackgroundColor(ECOLORS c)
Definition: hardware.c:590
ULONG ulWindowOffset
Definition: shell.c:63
void UnassembleOneLineUp(void)
Definition: parse.c:1460
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
BOOLEAN IsSwBpAtAddressInstalled(ULONG ulAddress)
Definition: bp.c:113
ULONG KeyboardIRQL
Definition: init.c:50
BOOLEAN ConvertTokenToSrcFile(LPSTR p, PULONG pValue)
Definition: parse.c:3693
unsigned int ULONG
Definition: retypes.h:1
#define SCANCODE_END
Definition: scancodes.h:74
#define ENTER_FUNC()
Definition: debug.h:42
ULONG CurrentESP
Definition: shell.c:115
BOOLEAN ScanExportsByAddress(LPSTR *pFind, ULONG ulValue)
Definition: symbols.c:599
void ResetColor(void)
Definition: hardware.c:500
ULONG CurrentEFL
Definition: shell.c:113
UCHAR ucCommandBuffer[256]
Definition: shell.c:127
GLfloat GLfloat p
Definition: glext.h:8902
ULONG bPreviousCommandWasGo
Definition: shell.c:54
USHORT OldSelector
Definition: shell.c:89
USHORT CurrentES
Definition: shell.c:116
#define COLOR_CAPTION
Definition: hardware.h:156
volatile BOOLEAN bNotifyToExit
Definition: shell.c:76
void PrintLogo(BOOLEAN bShow)
Definition: hardware.c:778
ULONG ulLastLineDisplayedOffset
Definition: shell.c:92
#define GLOBAL_CODE_SEGMENT
Definition: utils.h:246
void PICE_memset(void *p, unsigned char c, int sz)
Definition: utils.c:228
void PrintCursor(BOOLEAN bForce)
Definition: hardware.c:788
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
BOOLEAN(* DisplayMemory)(PARGS)
Definition: parse.c:56
ULONG CurrentEAX
Definition: shell.c:114
#define REASON_INT3
Definition: shell.h:71
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
void UnmaskIrqs(void)
Definition: hooks.c:82
char szBootParams[1024]
Definition: init.c:41
#define REASON_CTRLF
Definition: shell.h:73
#define REASON_PAGEFAULT
Definition: shell.h:74