- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libsys.h"
|
||||
|
||||
UINT8 g_pattern8[] = {0x01, 0x02, 0x03, 0x4, 0x05, 0x06, 0x07, 0x08};
|
||||
UINT16 g_pattern16[sizeof(g_pattern8)/2] = {0};
|
||||
UINT32 g_pattern32[sizeof(g_pattern8)/4] = {0};
|
||||
UINT8 _g_bytes[4] = {0x12, 0x34, 0x56, 0x78};
|
||||
UINT8 _g_bytes2[4] = {0};
|
||||
|
||||
void MakePattern(void)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
UINT16 *pPat16 = (UINT16*)g_pattern8;
|
||||
UINT32 *pPat32 = (UINT32*)g_pattern8;
|
||||
|
||||
|
||||
for (i=0; i < sizeof(g_pattern16)/2; i++)
|
||||
{
|
||||
g_pattern16[i] = pPat16[i];
|
||||
}
|
||||
|
||||
for (i=0; i < sizeof(g_pattern32)/4; i++)
|
||||
{
|
||||
g_pattern32[i] = pPat32[i];
|
||||
}
|
||||
}
|
||||
|
||||
void PrintPattern(void)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
printf("Pattern 8bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern8); i++)
|
||||
{
|
||||
printf("%02X ", g_pattern8[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Pattern 16bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern16)/2; i++)
|
||||
{
|
||||
printf("%04X ", g_pattern16[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Pattern 32bit:\n");
|
||||
for (i=0; i < sizeof(g_pattern32)/4; i++)
|
||||
{
|
||||
printf("%08X ", g_pattern32[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int IsEndianBig(void)
|
||||
{
|
||||
int i, result;
|
||||
|
||||
UINT8 *pBuf8;
|
||||
UINT16 *pBuf16;
|
||||
UINT32 *pBuf32;
|
||||
UINT16 halve;
|
||||
UINT32 word;
|
||||
|
||||
|
||||
halve = 0x1234;
|
||||
word = 0x12345678;
|
||||
|
||||
result = -1;
|
||||
|
||||
for (i=0; i < 4; i++)
|
||||
_g_bytes2[i] = _g_bytes[i];
|
||||
|
||||
pBuf8 = (UINT8*)&word;
|
||||
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34) && (*(pBuf8+2) == 0x56) && (*(pBuf8+3) == 0x78))
|
||||
{
|
||||
pBuf8 = (UINT8*)&halve;
|
||||
if (((*pBuf8+0) == 0x12) && (*(pBuf8+1) == 0x34))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
pBuf8 = (UINT8*)&word;
|
||||
if (((*pBuf8+0) == 0x78) && (*(pBuf8+1) == 0x56) && (*(pBuf8+2) == 0x34) && (*(pBuf8+3) == 0x12))
|
||||
{
|
||||
pBuf8 = (UINT8*)&halve;
|
||||
if (((*pBuf8+0) == 0x34) && (*(pBuf8+1) == 0x12))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PrintCPUinfo(void)
|
||||
{
|
||||
int result, rev_id;
|
||||
int cache_size, cache_line;
|
||||
int eb;
|
||||
|
||||
char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"};
|
||||
|
||||
// Print Status register
|
||||
result = CP0_SR_read();
|
||||
|
||||
printf("--------------------------------------------------\n");
|
||||
printf("Status : %8.8X\n", result);
|
||||
|
||||
// Print Revision
|
||||
result = CP0_PRID_read();
|
||||
rev_id = (result >> 8) & 0xFF;
|
||||
printf("CPU type : MIPS ");
|
||||
if ((rev_id > 0) && (rev_id < 0x07))
|
||||
{
|
||||
printf(cpu_type_str[rev_id]);
|
||||
printf(" Rev. ");
|
||||
rev_id = result & 0xFF;
|
||||
printf("%d", rev_id);
|
||||
}
|
||||
else
|
||||
printf("Unknown");
|
||||
|
||||
eb = IsEndianBig();
|
||||
if (eb > 0)
|
||||
printf(" [Big-endian]\n");
|
||||
if (eb == 0)
|
||||
printf(" [Little-endian]\n");
|
||||
if (eb < 0)
|
||||
printf(" [Unknown endian]\n");
|
||||
|
||||
printf("--------------------------------------------------\n");
|
||||
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int eb;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
CP0_SR_write(CP0_SR_read() & ~(1 << 25));
|
||||
|
||||
PrintCPUinfo();
|
||||
|
||||
if (IsEndianBig() == 1)
|
||||
printf("Endian is big\n");
|
||||
if (IsEndianBig() == 0)
|
||||
printf("Endian is little\n");
|
||||
|
||||
PrintBuffer8(_g_bytes2, 8, 4);
|
||||
MakePattern();
|
||||
PrintPattern();
|
||||
|
||||
memset(g_pattern16, 0, sizeof(g_pattern16));
|
||||
memset(g_pattern32, 0, sizeof(g_pattern32));
|
||||
|
||||
CP0_SR_write(CP0_SR_read() | (1 << 25));
|
||||
eb = IsEndianBig();
|
||||
|
||||
MakePattern();
|
||||
|
||||
CP0_SR_write(CP0_SR_read() & ~(1 << 25));
|
||||
if (eb == 1)
|
||||
printf("Endian is big\n");
|
||||
if (eb == 0)
|
||||
printf("Endian is little\n");
|
||||
PrintBuffer8(_g_bytes2, 8, 4);
|
||||
|
||||
PrintPattern();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user