⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hardware.c

📁 Linux下的类似softice的调试工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/hardware.c,v $ * $Revision: 1.6 $ * $Date: 2004/02/17 23:07:36 $ * $Author: lightweave $ * $Name:  $ * * $Log: hardware.c,v $ * Revision 1.6  2004/02/17 23:07:36  lightweave * * Improved the DEBUG facillity and replaced the configuration handler with a * new code which now can read MS Windows INI style files. See CHANGES.txt for * more details. * Also added a macro which prevents compiling for kernels before 2.4.19. * * Revision 1.4  2003/06/18 22:00:22  lightweave * DEBUG and DEBUG_SERIAL added * * *****************************************************************************/static char *ident = "$Header: /cvsroot/pice/pice/module/hardware.c,v 1.6 2004/02/17 23:07:36 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. GerlicherModule Name:    hardware.cAbstract:	    output to consoleEnvironment:    Kernel mode onlyAuthor:    Klaus P. GerlicherRevision History:    04-Aug-1998:	created    15-Nov-2000:    general cleanup of source files    Copyright notice:  This file may be distributed under the terms of the GNU Public License.--*/////////////////////////////////////////////////////// INCLUDES////#include "remods.h"#include <asm/io.h>#include <linux/ctype.h>#include <asm/delay.h>#include "precomp.h"////////////////////////////////////////////////////// PROTOTYPES////////////////////////////////////////////////////////// DEFINES////////////////////////////////////////////////////////// GLOBALS////// flagging stuffBOOLEAN bCursorEnabled = FALSE;BOOLEAN bConsoleIsInitialized = FALSE;// terminal emulationETERMINALMODE eTerminalMode = TERMINAL_MODE_NONE;// window stuffWINDOW wWindow[4];// screen parameterULONG GLOBAL_SCREEN_WIDTH,GLOBAL_SCREEN_HEIGHT;// jump table to real output functionsOUTPUT_HANDLERS ohandlers;INPUT_HANDLERS ihandlers;// ring buffer stuffULONG ulInPos = 0,ulLastPos = 0;ULONG ulOldInPos = 0,ulOldDelta = 0;BOOLEAN bSuspendPrintRingBuffer = FALSE;struct _RING_BUFFER{	USHORT usForegroundColor;	USHORT usBackgroundColor;	char buffer[1024];} aBuffers[LINES_IN_BUFFER];char OneTempBuffer[sizeof(aBuffers[0].buffer)];// color of windows pane separation barsUSHORT usCaptionColor       = BLUE;USHORT usCaptionText        = WHITE;USHORT usForegroundColor    = LTGRAY;USHORT usBackgroundColor    = BLACK;USHORT usHiLiteColor        = WHITE;////////////////////////////////////////////////////// FUNCTIONS//////*************************************************************************// SuspendPrintRingBuffer()////*************************************************************************void SuspendPrintRingBuffer(BOOLEAN bSuspend){    //ENTER_FUNC();    bSuspendPrintRingBuffer = bSuspend;    //LEAVE_FUNC();}//*************************************************************************// EmptyRingBuffer()////*************************************************************************void EmptyRingBuffer(void){    //ENTER_FUNC();    ulLastPos = ulInPos = ulOldInPos = ulOldDelta = 0;	PICE_memset(aBuffers,0,sizeof(aBuffers));    //LEAVE_FUNC();}//*************************************************************************// LinesInRingBuffer()////*************************************************************************ULONG LinesInRingBuffer(void){    ULONG ulResult;    //ENTER_FUNC();    ulResult = (ulInPos-ulLastPos)%LINES_IN_BUFFER;    //LEAVE_FUNC();	return ulResult;}//*************************************************************************// CheckRingBuffer()////*************************************************************************void CheckRingBuffer(void){    //ENTER_FUNC();	PrintRingBuffer(wWindow[OUTPUT_WINDOW].cy-1);    //LEAVE_FUNC();}//*************************************************************************// AddToRingBuffer()////*************************************************************************BOOLEAN AddToRingBuffer(LPSTR p){   ULONG i,j,len;   BOOLEAN bHadReturn = FALSE;   //ENTER_FUNC();    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "checking if inside buffers (ulInpos = %u)\n", ulInPos);    if(ulInPos >= LINES_IN_BUFFER)    {		 DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "attempt to leave ring buffer\n");		 //LEAVE_FUNC();		 return FALSE;    }    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "checking input string\n");    j = PICE_strlen(p);    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "input string has %u chars\n",j);    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "getting length of string\n");    // size of current string    j = PICE_strlen(aBuffers[ulInPos].buffer);    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "length of current string = %u\n",j);    // start with ':' and current has ':' in front    if(aBuffers[ulInPos].buffer[0]==':' && *p==':')    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "colon case\n");        if(j==1)        {            //LEAVE_FUNC();            return FALSE;        }		aBuffers[ulInPos].buffer[j++]='\n';		aBuffers[ulInPos].buffer[j]=0;		ulInPos = (ulInPos+1)%LINES_IN_BUFFER;		// wrap around		if(ulInPos == ulLastPos)		{			ulLastPos = (ulLastPos+1)%LINES_IN_BUFFER;			PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));		}        // reset to start of buffer		j = 0;        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "leaving colon case\n");    }    // it's an internal print ("pICE: ...")    else    if(aBuffers[ulInPos].buffer[0]==':' && PICE_strncmpi(p,"pICE:",5)==0)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "internal case\n");	if(j==1)	{	   PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));	}	else	{	   aBuffers[ulInPos].buffer[j++]='\n';	   aBuffers[ulInPos].buffer[j]=0;	   ulInPos = (ulInPos+1)%LINES_IN_BUFFER;	   // wrap around	   if(ulInPos == ulLastPos)	   {	      ulLastPos = (ulLastPos+1)%LINES_IN_BUFFER;	      PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));	   }	}        // reset to start of buffer	j = 0;        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "leaving internal case\n");    }    // it's a debug print and the current line is starting with ':'    else    if(aBuffers[ulInPos].buffer[0]==':' &&       ( (*p=='<' && isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) )    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "kernel debug print\n");	if(j==1)	{	   PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));	}	else	{	   aBuffers[ulInPos].buffer[j++]='\n';	   aBuffers[ulInPos].buffer[j]=0;	   ulInPos = (ulInPos+1)%LINES_IN_BUFFER;	   // wrap around	   if(ulInPos == ulLastPos)	   {	      ulLastPos = (ulLastPos+1)%LINES_IN_BUFFER;	      PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));	   }	}        // reset to start of buffer	j = 0;        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "leaving kernel debug print\n");    }    // it's a debug print    else if(( (*p=='<' && isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) )    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "debug print\n");        p += 3;        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "leaving debug print\n");    }    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "getting size of new string\n");    // size of new string    len = PICE_strlen(p);    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "size of new string = %u\n",len);    // if combined string length too big    // reduce to maximum    if( (len+j) > sizeof(aBuffers[0].buffer)-2 )    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "combine strings\n");        PICE_memcpy(OneTempBuffer,p,sizeof(aBuffers[0].buffer)-2);        p = OneTempBuffer;        // assume we end in NEWLINE        p[sizeof(aBuffers[0].buffer)-2]='\n';        p[sizeof(aBuffers[0].buffer)-1]=0;        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "leaving combine strings\n");    }    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "formatting string\n");	for(i=0;p[i]!=0;i++)	{		// newline		if(p[i]=='\n')		{			aBuffers[ulInPos].buffer[j++]='\n';			aBuffers[ulInPos].buffer[j]=0;			ulInPos = (ulInPos+1)%LINES_IN_BUFFER;			// wrap around			if(ulInPos == ulLastPos)			{				ulLastPos = (ulLastPos+1)%LINES_IN_BUFFER;				PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));			}            // reset to start of buffer			j = 0;            // notify that we had a NEWLINE            bHadReturn = TRUE;		}		// backspace		else if(p[i]=='\b')		{			if(j!=0)			{				j--;				aBuffers[ulInPos].buffer[j] = 0;			}		}		// TAB		else if(p[i]=='\t')		{            // copy TAB			aBuffers[ulInPos].buffer[j++] = p[i];		}		else		{			if((UCHAR)p[i]<0x20 || (UCHAR)p[i]>0x7f)				p[i]=0x20;						aBuffers[ulInPos].buffer[j++] = p[i];		}	}    	// set colors on buffer line	aBuffers[ulInPos].usForegroundColor = usForegroundColor;	aBuffers[ulInPos].usBackgroundColor = usBackgroundColor;    //LEAVE_FUNC();    return bHadReturn;}//*************************************************************************// ReplaceRingBufferCurrent()////*************************************************************************void ReplaceRingBufferCurrent(LPSTR s){    //ENTER_FUNC();    if(ulInPos >= LINES_IN_BUFFER)    {       DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "attempt to leave ring buffer\n");       //LEAVE_FUNC();       return;    }    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "checking input string\n");    if(!PICE_strlen(s))    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "string is empty!\n");        //LEAVE_FUNC();        return;    }    PICE_memset(aBuffers[ulInPos].buffer,0,sizeof(aBuffers[0].buffer));    PICE_strcpy(aBuffers[ulInPos].buffer,s);    //LEAVE_FUNC();}//*************************************************************************// PrintRingBuffer()////*************************************************************************void PrintRingBuffer(ULONG ulLines){   ULONG ulDelta;   ULONG ulOutPos,i;    //ENTER_FUNC();   if(bSuspendPrintRingBuffer)   {      DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "suspended\n");      //LEAVE_FUNC();      return;   }   if(ulInPos == ulOldInPos )   {      DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "didn't move forward\n");      //LEAVE_FUNC();      return;   }	    ulOldInPos = ulInPos;    ulDelta = LinesInRingBuffer();        if(!ulDelta)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "no lines in ring buffer\n");        //LEAVE_FUNC();		return;    }    if(ulDelta<ulOldDelta)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "lines already output\n");        //LEAVE_FUNC();        return;    }    ulOldDelta = ulDelta;    if(ulDelta < ulLines)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "less lines than requested\n");	ulLines = ulDelta;    }	ulOutPos = (ulInPos-ulLines)%LINES_IN_BUFFER;    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulOutPos = %u\n",ulOutPos);    Home(OUTPUT_WINDOW);    ClrLines(wWindow[OUTPUT_WINDOW].y,ulLines);    i = ulLines;	while(ulLines--)	{		SetForegroundColor(aBuffers[ulOutPos].usForegroundColor);		SetBackgroundColor(aBuffers[ulOutPos].usBackgroundColor);		Print(OUTPUT_WINDOW_UNBUFFERED,aBuffers[ulOutPos].buffer);		ResetColor();		ulOutPos = (ulOutPos+1)%LINES_IN_BUFFER;	}    if(aBuffers[ulOutPos].buffer[0]==':')    {        ClrLines(wWindow[OUTPUT_WINDOW].y+i,1);		SetForegroundColor(aBuffers[ulOutPos].usForegroundColor);		SetBackgroundColor(aBuffers[ulOutPos].usBackgroundColor);		Print(OUTPUT_WINDOW_UNBUFFERED,aBuffers[ulOutPos].buffer);		ResetColor();    	wWindow[OUTPUT_WINDOW].usCurX = 1;    }    //LEAVE_FUNC();}//*************************************************************************// PrintRingBufferOffset()////*************************************************************************BOOLEAN PrintRingBufferOffset(ULONG ulLines,ULONG ulOffset){	ULONG ulLinesInRingBuffer;	ULONG ulOutPos;    //ENTER_FUNC();    ulLinesInRingBuffer = LinesInRingBuffer();    // no lines in ring buffer	if(!ulLinesInRingBuffer)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulLinesInRingBuffer is 0\n");        //LEAVE_FUNC();		return FALSE;    }    // more lines inc. offset to display than in ring buffer	if(ulLinesInRingBuffer < ulLines)    {        ulLines = ulLinesInRingBuffer;    }	if(ulLinesInRingBuffer < ulOffset+ulLines)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulLinesInRingBuffer < ulOffset+ulLines\n");        //LEAVE_FUNC();        return FALSE;    }    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulLinesInRingBuffer %u ulLines %u ulOffset %u\n",ulLinesInRingBuffer,ulLines,ulOffset);    ulOutPos = (ulInPos-ulOffset-ulLines)%LINES_IN_BUFFER;    DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulOutPos = %u\n",ulOutPos);    if(ulOutPos == ulInPos)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "ulOutPos == ulInPos\n");        //LEAVE_FUNC();        return FALSE;    }    // start to output upper left corner of window	Home(OUTPUT_WINDOW);    // while not end reached...    ClrLines(wWindow[OUTPUT_WINDOW].y,ulLines);	while(ulLines--)	{		SetForegroundColor(aBuffers[ulOutPos].usForegroundColor);		SetBackgroundColor(aBuffers[ulOutPos].usBackgroundColor);		Print(OUTPUT_WINDOW_UNBUFFERED,aBuffers[ulOutPos].buffer);		ResetColor();		ulOutPos = (ulOutPos+1)%LINES_IN_BUFFER;	}    if(aBuffers[ulInPos].buffer[0]==':')    {        ClrLines(wWindow[OUTPUT_WINDOW].y+wWindow[OUTPUT_WINDOW].cy-1,1);        wWindow[OUTPUT_WINDOW].usCurY = wWindow[OUTPUT_WINDOW].cy-1;		SetForegroundColor(aBuffers[ulInPos].usForegroundColor);		SetBackgroundColor(aBuffers[ulInPos].usBackgroundColor);		Print(OUTPUT_WINDOW_UNBUFFERED,aBuffers[ulInPos].buffer);		ResetColor();    	wWindow[OUTPUT_WINDOW].usCurX = strlen(aBuffers[ulInPos].buffer)+1;    }    //LEAVE_FUNC();    return TRUE;}//*************************************************************************// PrintRingBufferHome()////*************************************************************************BOOLEAN PrintRingBufferHome(ULONG ulLines){   ULONG ulDelta;   ULONG ulOutPos;    //ENTER_FUNC();    ulDelta = LinesInRingBuffer();    // no lines in ring buffer    if(!ulDelta)    {        DPRINT(PICE_DEBUG, DBT_HARDWARE, DBL_INFO, "no lines in ring buffer\n");        //LEAVE_FUNC();	return FALSE;    }    // more lines inc. offset to display than in ring buffer	if(ulDelta < ulLines)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -