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

📄 main.c

📁 PXA270的EBOOT源代码!可以启动wince内核
💻 C
📖 第 1 页 / 共 5 页
字号:
	u8Digit += '0';
	OEMWriteDebugByte(u8Digit);
}

static void PrintHexPair(UINT8 u8Hex)
{
	PrintHexDigit(u8Hex >> 4);
	PrintHexDigit(u8Hex & 0xf);
}

static void PrintHexValue(UINT32 u32Value,
						  UINT8 u8Value)
{
	if (8 == u8Value)
	{
		PrintHexPair(u32Value);
	}

	if (16 == u8Value)
	{
		PrintHexPair(u32Value >> 8);
		PrintHexPair(u32Value & 0xff);
	}

	if (32 == u8Value)
	{
		PrintHexPair(u32Value >> 24);
		PrintHexPair(u32Value >> 16);
		PrintHexPair(u32Value >> 8);
		PrintHexPair(u32Value & 0xff);
	}
}

static ELex LexGetNextToken(void)
{
	ELex eToken = LEX_EOF;
	UINT32 u32TokenLength = 0;

	// Eat any leading spaces

	sg_pu8LexPos = EatWhitespace(sg_pu8LexPos);

	// If this is the end of the string, let everyone know

	if ('\0' == *sg_pu8LexPos)
	{
		return(LEX_EOF);
	}

	sg_u8YYLEX[u32TokenLength++] = *sg_pu8LexPos;

	// Time to parse!

	if (*sg_pu8LexPos >= '0' && *sg_pu8LexPos <= '9')
	{
		BOOL bHexNotation = FALSE;

		// It's a number! Let's see if it's hex notation

		if ('0' == *sg_pu8LexPos)
		{
			++sg_pu8LexPos;
			sg_u8YYLEX[u32TokenLength++] = *sg_pu8LexPos;

			if ('X' == ToUpper(*sg_pu8LexPos))
			{
				// Yup! It's 0x something. Just ignore the 0x and eat everything else

				bHexNotation = TRUE;

				// Back up over the 0x

				u32TokenLength -= 2;
				sg_pu8LexPos++;
			}
			else
			{
				sg_pu8LexPos++;
			}

		}
		else
		{
			--u32TokenLength;
		}

		while (1)
		{
			if ((IsDigit(*sg_pu8LexPos) ||
				(bHexNotation && (ToUpper(*sg_pu8LexPos) >= 'A' && ToUpper(*sg_pu8LexPos) <= 'F') ) ) )
			{
				sg_u8YYLEX[u32TokenLength++] = *sg_pu8LexPos;
				++sg_pu8LexPos;
			}
			else
			{
				break;
			}
		}

		sg_u8YYLEX[u32TokenLength] = '\0';

		if (bHexNotation)
		{
			UINT8 *pu8Ptr;

			pu8Ptr = sg_u8YYLEX;
			sg_u32Constant = 0;

			while (*pu8Ptr != '\0')
			{
				sg_u32Constant <<= 4;

				if (IsDigit(*pu8Ptr))
				{
					sg_u32Constant |= (*pu8Ptr - '0');
				}
				else
				{
					sg_u32Constant |= ((ToUpper(*pu8Ptr) - 'A') + 10);
				}
				++pu8Ptr;
			}
		}
		else
		{
			sg_u32Constant = atol(sg_u8YYLEX);
		}

		eToken = LEX_CONSTANT;
	}
	else
	if (ToUpper(*sg_pu8LexPos) >= 'A' && ToUpper(*sg_pu8LexPos) <= 'Z')
	{
		struct SIdentifierEntry *psIdent;

		eToken = LEX_IDENTIFIER;

		++sg_pu8LexPos;

		while ( (IsAlpha(*sg_pu8LexPos)) ||	('_' == *sg_pu8LexPos) )
		{
			sg_u8YYLEX[u32TokenLength++] = *sg_pu8LexPos++;
		}

		psIdent = sg_sIdentifiers;
		sg_u8YYLEX[u32TokenLength] = '\0';

		while (psIdent->pu8TextToMatch)
		{
			if (stricmp(psIdent->pu8TextToMatch, sg_u8YYLEX) == 0)
			{
				eToken = psIdent->eToken;
				break;
			}
			psIdent++;
		}
	}
	else
	{
		eToken = sg_u8YYLEX[u32TokenLength - 1];
	}

	sg_u8YYLEX[u32TokenLength] = '\0';

	return(eToken);
}

static UINT32 GetLine(UINT8 *pu8InputBuffer,
				  	  UINT32 u32MaxLength)
{
	UINT32 u32Position = 0;
	UINT32 u32Length = 0;
	INT16 s16IncomingByte = 0;
	UINT8 u8EscapeState = 0;

	// If there are any characters in the buffer already, print them out so we can start
	// on a non-clear edited line

	EdbgOutputDebugString(pu8InputBuffer);
	u32Length = strlen(pu8InputBuffer);

	while (1)
	{
		// Wait for a data byte to come in

		do
		{
			s16IncomingByte = OEMReadDebugByte();
		} while (OEM_DEBUG_READ_NODATA == s16IncomingByte);

		if (('\b' == s16IncomingByte) && (u32Length))
		{
			EdbgOutputDebugString("\b \b");
			u32Length--;
			pu8InputBuffer[u32Length] = '\0';
		}
		else
		if ('\r' == s16IncomingByte)
		{
			EdbgOutputDebugString("\r\n");
			pu8InputBuffer[u32Length] = '\0';
			return(LINE_OK);
		}
		else
		if (0x03 == s16IncomingByte)
		{
			EdbgOutputDebugString("^C\r\n");
			pu8InputBuffer[u32Length] = '\0';
			return(LINE_EXIT);
		}
		else
		if ((0x1b == s16IncomingByte) && (0 == u8EscapeState))
		{
			u8EscapeState = 1;
		}
		else
		if (('[' == s16IncomingByte) && (1 == u8EscapeState))
		{
			u8EscapeState = 2;
		}
		else
		if (('A' == s16IncomingByte || 'B' == s16IncomingByte) && (2 == u8EscapeState))
		{
			// It's an UP or DOWN!

			u8EscapeState = 0;

			while (u32Length--)
			{
				EdbgOutputDebugString("\b \b");
			}

			if ('A' == s16IncomingByte)
			{
				pu8InputBuffer[u32Length] = '\0';
				return(LINE_UP);
			}
			if ('B' == s16IncomingByte)
			{
				pu8InputBuffer[u32Length] = '\0';
				return(LINE_DOWN);
			}
		}
		else
		if ((s16IncomingByte >= ' ') && (u32Length < u32MaxLength) && (0 == u8EscapeState))
		{
			pu8InputBuffer[u32Length] = (UINT8) s16IncomingByte;
			OEMWriteDebugByte(pu8InputBuffer[u32Length]);
			u32Length++;
		}
		else
		{
			u8EscapeState = 0;
		}

	}
}

static BOOL ParseForAddressAndData(ELex *peDataSize,
								   UINT32 *pu32Address,
								   UINT32 *pu32Data,
								   BOOL bRequireData)
{
	ELex eToken;
	
	*pu32Address = 0;

	if (pu32Data)
	{
		*pu32Data = 0;
	}

	*peDataSize = sg_eDatasize;

	eToken = LexGetNextToken();

	// Look for optional data size

	if (LEX_BYTE == eToken || LEX_WORD == eToken || LEX_DWORD == eToken)
	{
		*peDataSize = eToken;
		eToken = LexGetNextToken();
	}

	if (LEX_EOF == eToken)
	{
		EdbgOutputDebugString("Missing address\r\n");
		return(FALSE);
	}

	if (eToken != LEX_CONSTANT)
	{
		EdbgOutputDebugString("Expected constant or optional 'byte', 'word', or 'dword' after command\r\n");
		return(FALSE);
	}

	*pu32Address = sg_u32Constant;

	// We have our address. Let's see if we require a data byte

	if (bRequireData)
	{
		eToken = LexGetNextToken();

		if (eToken != LEX_CONSTANT)
		{
			EdbgOutputDebugString("Expected data byte/word/dword after address\r\n");
			return(FALSE);
		}

		*pu32Data = sg_u32Constant;
	}

	return(TRUE);
}

static UINT32 WriteData(void)
{
	ELex eDataSize;
	volatile UINT8 *pu8Pointer;
	volatile UINT16 *pu16Pointer;
	volatile UINT32 *pu32Pointer;
	UINT32 u32Address;
	UINT32 u32Data;
	BOOL bResult;

	// Parse to get size (byte, word, dword)

	bResult = ParseForAddressAndData(&eDataSize,
									 &u32Address,
									 &u32Data,
									 TRUE);

	if (FALSE == bResult)
	{
		return(0);
	}

	// We know our size! Let's get our address.

	if (LEX_BYTE == eDataSize)
	{
		pu8Pointer = (UINT8 *) u32Address;
	}

	if (LEX_WORD == eDataSize)
	{
		pu16Pointer = (UINT16 *) u32Address;
	}

	if (LEX_DWORD == eDataSize)
	{
		pu32Pointer = (UINT32 *) u32Address;
	}

	// Check data sizes

	if (LEX_BYTE == eDataSize && u32Data > 0xff)
	{
		EdbgOutputDebugString(">8 Bit value cannot be written in a byte transaction\r\n");
		return(0);
	}

	if (LEX_WORD == eDataSize && u32Data > 0xffff)
	{
		EdbgOutputDebugString(">16 Bit value cannot be written to a word transaction\r\n");
		return(0);
	}

	// Now go write the data!

	if (LEX_BYTE == eDataSize)
	{
		*pu8Pointer = (UINT8) u32Data;
	}

	if (LEX_WORD == eDataSize)
	{
		*pu16Pointer = (UINT16) u32Data;
	}

	if (LEX_DWORD == eDataSize)
	{
		*pu32Pointer = u32Data;
	}

	return(0);
}

static UINT32 ExitDebugger(void)
{
	return(LEX_EXIT);
}

static UINT32 Help(void)
{
	EdbgOutputDebugString("\r\nDebugger help:\r\n\r\n");
	EdbgOutputDebugString("sz - Data size can be 'byte', 'word' (16 bits), or 'dword' (32 bits)\r\n");
	EdbgOutputDebugString("ad - Address - can be decimal (default) or hex (preceeded by 0x)\r\n");
	EdbgOutputDebugString("da - Data - can be decimal (default) or hex (preceeded by 0x)\r\n");
	EdbgOutputDebugString("si - Size of data in bytes\r\n");
	EdbgOutputDebugString("{} - Indicates optional parameter\r\n\r\n");

	EdbgOutputDebugString("d | dump {sz} [ad] {ln}       - Dumps data for {ln} memory locations (default ln=0x100)\r\n");
	EdbgOutputDebugString("datasize {sz}                 - Sets the default data size if none specified\r\n");
	EdbgOutputDebugString("exit                          - Exits the debugger back to eBoot main menu\r\n");
	EdbgOutputDebugString("fill | f {sz} [ad] [da] [si]  - Fills memory starting @ [ad] with [da] for [si] bytes\r\n");
	EdbgOutputDebugString("map                           - Dump system memory map\r\n");
	EdbgOutputDebugString("r | read {sz} [ad]            - Performs a memory read\r\n");
	EdbgOutputDebugString("w | write {sz} [ad] [da]      - Performs a memory write\r\n");
	EdbgOutputDebugString("wr | writeread {sz} [ad] [da] - Performs a write followed by a read from the same address\r\n");
	EdbgOutputDebugString("\r\n");
	return(0);
}

static UINT32 ReadData(void)
{
	ELex eDataSize;
	UINT32 u32Address;
	UINT32 u32Data;
	UINT32 *pu32Pointer;
	UINT8 *pu8Pointer;
	UINT16 *pu16Pointer;
	BOOL bResult;

	// Parse to get size (byte, word, dword)

	bResult = ParseForAddressAndData(&eDataSize,
									 &u32Address,
									 NULL,
									 FALSE);

	if (FALSE == bResult)
	{
		return(0);
	}

	if (LEX_BYTE == eDataSize)
	{
		pu8Pointer = (UINT8 *) u32Address;
		u32Data = (UINT32) *pu8Pointer;
	}

	if (LEX_WORD == eDataSize)
	{
		pu16Pointer = (UINT16 *) u32Address;
		u32Data = (UINT32) *pu16Pointer;
	}

	if (LEX_DWORD == eDataSize)
	{
		pu32Pointer = (UINT32 *) u32Address;
		u32Data = *pu32Pointer;
	}

	EdbgOutputDebugString("Addr 0x%x = 0x", u32Address);

	if (LEX_BYTE == eDataSize)
	{
		PrintHexValue(u32Data, 8);
	}
	if (LEX_WORD == eDataSize)
	{
		PrintHexValue(u32Data, 16);
	}
	if (LEX_DWORD == eDataSize)
	{
		PrintHexValue(u32Data, 32);
	}

	EdbgOutputDebugString("\r\n");

	return(0);
}

static UINT32 Dump(void)
{
	ELex eToken;
	ELex eDataSize;
	UINT8 *pu8Pointer;
	UINT16 *pu16Pointer;
	UINT32 *pu32Pointer;
	UINT32 u32Data;
	UINT32 u32End;
	UINT32 u32Start;
	UINT32 u32Length = 0x100;
	UINT8 u8Loop;

⌨️ 快捷键说明

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