URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/bootloaders
- from Rev 405 to Rev 406
- ↔ Reverse comparison
Rev 405 → Rev 406
/orpmon/include/int.h
18,3 → 18,6
|
/* Enable interrupt */ |
int int_enable(unsigned long vect); |
|
/* Error vector handler */ |
void int_error(int vect); |
/orpmon/include/build.h
1,3 → 18,6
#define BUILD_VERSION "Tue Nov 2 15:05:20 CET 2010" |
#define BUILD_VERSION "Tue Nov 2 22:26:31 CET 2010" |
/orpmon/reset.S
6,6 → 6,7
.extern _dst_beg |
.extern _dst_end |
.extern int_main |
.extern int_error |
.extern tick_interrupt |
.extern _crc32 |
|
86,10 → 87,13
/* Just trap */ |
l.trap 0 |
.endif |
.if 0 |
l.nop 0x1 |
l.j 0 |
l.nop |
|
.endif |
l.j _int_error |
l.ori r3, r0, 0x2 |
|
.if IN_FLASH |
.section .vectors, "ax" |
127,9 → 131,13
.if 0 |
l.trap 0 |
.endif |
.if 0 |
l.nop 0x1 |
l.j 0 |
l.nop |
.endif |
l.j _int_error |
l.ori r3, r0, 0x6 |
|
.if IN_FLASH |
.org 0x700 |
141,11 → 149,14
/* Just trap */ |
l.trap 0 |
.endif |
.if 0 |
l.nop 0x1 |
l.j 0 |
l.nop |
.endif |
l.j _int_error |
l.ori r3, r0, 0x7 |
|
|
.if IN_FLASH |
.org 0x800 |
.else |
606,3 → 617,11
l.lwz r31,0x7c(r1) |
l.addi r1,r1,128 |
l.rfe |
|
|
/* Jump to error function. Clobber r2 */ |
_int_error: |
l.movhi r2,hi(int_error) |
l.ori r2,r2,lo(int_error) |
l.jr r2 |
l.nop |
/orpmon/services/modem.c
19,26 → 19,23
#define TIMEOUT 3 |
|
/* update CRC */ |
unsigned short |
updcrc(register int c, register unsigned int crc) |
unsigned short updcrc(register int c, register unsigned int crc) |
{ |
register int count; |
|
for (count=8; --count>=0;) { |
if (crc & 0x8000) { |
crc <<= 1; |
crc += (((c<<=1) & 0400) != 0); |
crc ^= 0x1021; |
} |
else { |
crc <<= 1; |
crc += (((c<<=1) & 0400) != 0); |
} |
} |
return crc; |
register int count; |
|
for (count = 8; --count >= 0;) { |
if (crc & 0x8000) { |
crc <<= 1; |
crc += (((c <<= 1) & 0400) != 0); |
crc ^= 0x1021; |
} else { |
crc <<= 1; |
crc += (((c <<= 1) & 0400) != 0); |
} |
} |
return crc; |
} |
|
|
static thand_f *mTimeHandler; |
static unsigned long mTimeValue; |
static int mTimeoutCount; |
52,191 → 49,184
|
static void mStartTimeout(void); |
|
void |
mSetTimeout(int iv, thand_f *f) |
void mSetTimeout(int iv, thand_f * f) |
{ |
if(iv == 0) |
mTimeHandler = (thand_f *)0; |
else { |
mTimeHandler = f; |
mTimeValue = get_timer(0) + iv; |
} |
if (iv == 0) |
mTimeHandler = (thand_f *) 0; |
else { |
mTimeHandler = f; |
mTimeValue = get_timer(0) + iv; |
} |
} |
|
static void |
mStartTimeout(void) |
static void mStartTimeout(void) |
{ |
if(++mTimeoutCount >= RETRY) { |
printf("...retry counter exceeded, quitting...\n"); |
return; |
} else { |
printf("."); |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mStartTimeout); |
uart_putc(C); |
if (++mTimeoutCount >= RETRY) { |
printf("...retry counter exceeded, quitting...\n"); |
return; |
} else { |
printf("."); |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mStartTimeout); |
uart_putc(C); |
|
} |
} |
} |
|
static void |
mReceiveTimeout(void) |
static void mReceiveTimeout(void) |
{ |
if(++mTimeoutCount >= RETRY) { |
uart_putc(NAK); |
printf("..."); |
return; |
} else { |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mReceiveTimeout); |
uart_putc(NAK); |
} |
if (++mTimeoutCount >= RETRY) { |
uart_putc(NAK); |
printf("..."); |
return; |
} else { |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mReceiveTimeout); |
uart_putc(NAK); |
} |
} |
|
int |
getBlock(unsigned char t) |
int getBlock(unsigned char t) |
{ |
unsigned int i = 0, j = 0; |
unsigned char mybuf[133]; |
unsigned char bNo, nBno; |
unsigned long dst_addr; |
unsigned int i = 0, j = 0; |
unsigned char mybuf[133]; |
unsigned char bNo, nBno; |
unsigned long dst_addr; |
|
unsigned char flags; |
flags = UART_LSR_FE | UART_LSR_PE | UART_LSR_OE | UART_LSR_BI; /*frame,parity,overrun errors */ |
unsigned char flags; |
flags = UART_LSR_FE | UART_LSR_PE | UART_LSR_OE | UART_LSR_BI; /*frame,parity,overrun errors */ |
|
mycrc = 0; |
mycrc = 0; |
|
switch(t) { |
case SOH: |
for(i = 0; i < 132; i++) { |
if((REG8(UART_BASE + UART_LSR) & flags) == flags) { |
uart_putc(CAN); |
} |
mybuf[i] = uart_getc(); |
} |
switch (t) { |
case SOH: |
for (i = 0; i < 132; i++) { |
if ((REG8(UART_BASE + UART_LSR) & flags) == flags) { |
uart_putc(CAN); |
} |
mybuf[i] = uart_getc(); |
} |
|
bNo = mybuf[0]; /* packet id */ |
nBno = mybuf[1]; /* neg. packet id */ |
bNo = mybuf[0]; /* packet id */ |
nBno = mybuf[1]; /* neg. packet id */ |
|
if((bNo == 0x00) && (nBno == 0xff) && (bno == 0)) { /* start block */ |
modemMode = 2; /* ymodem */ |
uart_putc(ACK); |
uart_putc(C); |
return 1; |
} |
else if((0xff-bNo) == nBno) { /* data block */ |
for(i = 2, j = 0; i < 130; i++, j++) { |
length++; |
mycrc = updcrc(mybuf[i], mycrc); |
dst_addr = src_addr+(bno*0x8000)+((bNo-1)*0x80)+j; |
REG8(dst_addr) = mybuf[i]; |
} |
if ((bNo == 0x00) && (nBno == 0xff) && (bno == 0)) { /* start block */ |
modemMode = 2; /* ymodem */ |
uart_putc(ACK); |
uart_putc(C); |
return 1; |
} else if ((0xff - bNo) == nBno) { /* data block */ |
for (i = 2, j = 0; i < 130; i++, j++) { |
length++; |
mycrc = updcrc(mybuf[i], mycrc); |
dst_addr = |
src_addr + (bno * 0x8000) + |
((bNo - 1) * 0x80) + j; |
REG8(dst_addr) = mybuf[i]; |
} |
|
mycrc = updcrc(mybuf[130], mycrc); |
mycrc = updcrc(mybuf[131], mycrc); |
mycrc = updcrc(mybuf[130], mycrc); |
mycrc = updcrc(mybuf[131], mycrc); |
|
if(mycrc == 0) /* CRC match! */ { |
uart_putc(ACK); |
for(i=0;i < 128; i+=4) { |
/* for(j=0; j<4; j++) { |
tmp = tmp << 8; |
tmp |= mybuf[i+j+2]; |
if (mycrc == 0) { /* CRC match! */ |
uart_putc(ACK); |
for (i = 0; i < 128; i += 4) { |
/* for(j=0; j<4; j++) { |
tmp = tmp << 8; |
tmp |= mybuf[i+j+2]; |
} |
dst_addr = src_addr+(bno*0x8000)+((bNo-1)*128)+i; |
fl_word_program(dst_addr, tmp); */ |
} |
if (bNo == 0xff) |
bno++; |
return 1; |
} else { |
uart_putc(NAK); |
return -1; |
} |
} else { /* packet id didn't match neg packet id! */ |
uart_putc(NAK); |
return -1; |
} |
return 1; |
break; |
case EOT: |
if (modemMode == 2) { /* ymodem */ |
uart_putc(NAK); |
if (uart_getc() == EOT) { |
uart_putc(ACK); |
uart_putc(C); |
} else |
uart_putc(ACK); |
} else /* zmodem */ |
uart_putc(ACK); |
|
return 0; |
break; |
default: |
/* Unknown header */ |
uart_putc(NAK); |
return -1; |
} |
dst_addr = src_addr+(bno*0x8000)+((bNo-1)*128)+i; |
fl_word_program(dst_addr, tmp);*/ |
} |
if(bNo == 0xff) |
bno++; |
return 1; |
} |
else { |
uart_putc(NAK); |
return -1; |
} |
} |
else { /* packet id didn't match neg packet id! */ |
uart_putc(NAK); |
return -1; |
} |
return 1; |
break; |
case EOT: |
if(modemMode == 2) {/* ymodem */ |
uart_putc(NAK); |
if(uart_getc() == EOT) { |
uart_putc(ACK); |
uart_putc(C); |
} |
else |
uart_putc(ACK); |
} else /* zmodem */ |
uart_putc(ACK); |
|
return 0; |
break; |
default: |
/* Unknown header */ |
uart_putc(NAK); |
return -1; |
} |
} |
|
int |
mGetData(unsigned long saddr) |
int mGetData(unsigned long saddr) |
{ |
int retval = 1; |
unsigned char c; |
int retval = 1; |
unsigned char c; |
|
length = 0; |
src_addr = saddr; |
modemMode = 1; |
bno = 0; |
length = 0; |
src_addr = saddr; |
modemMode = 1; |
bno = 0; |
|
printf("src_addr: 0x%lx\n", src_addr); |
if(fl_init() != 0) { |
printf("Flash init failed!\n"); |
return(-1); |
} |
|
printf("src_addr: 0x%lx\n", src_addr); |
if (fl_init() != 0) { |
printf("Flash init failed!\n"); |
return (-1); |
} |
#if 0 |
printf("Unlocking flash..."); |
for (i = 0, c = FLASH_BASE_ADDR; i < (FLASH_SIZE / FLASH_BLOCK_SIZE); |
i++, c += FLASH_BLOCK_SIZE) |
if (fl_unlock_one_block (c)) return 1; |
printf("done\n"); |
printf("Unlocking flash..."); |
for (i = 0, c = FLASH_BASE_ADDR; i < (FLASH_SIZE / FLASH_BLOCK_SIZE); |
i++, c += FLASH_BLOCK_SIZE) |
if (fl_unlock_one_block(c)) |
return 1; |
printf("done\n"); |
|
printf("Erasing flash..."); |
for (i = 0, c = FLASH_BASE_ADDR; i < (FLASH_SIZE / FLASH_BLOCK_SIZE); |
i++, c += FLASH_BLOCK_SIZE) |
if (fl_block_erase (c)) return 1; |
printf ("done\n"); |
printf("Erasing flash..."); |
for (i = 0, c = FLASH_BASE_ADDR; i < (FLASH_SIZE / FLASH_BLOCK_SIZE); |
i++, c += FLASH_BLOCK_SIZE) |
if (fl_block_erase(c)) |
return 1; |
printf("done\n"); |
#endif |
printf("Waiting..."); |
printf("Waiting..."); |
|
mTimeoutCount = 0; |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mStartTimeout); |
mTimeoutCount = 0; |
mSetTimeout(TIMEOUT * TICKS_PER_SEC, mStartTimeout); |
|
while(1) { |
if(mTimeHandler && (get_timer(0) > mTimeValue)) { |
thand_f *x; |
x = mTimeHandler; |
mTimeHandler = (thand_f *)0; |
(*x)(); |
} |
c = uart_testc(); |
if(c != 0) |
break; |
} |
while (1) { |
if (mTimeHandler && (get_timer(0) > mTimeValue)) { |
thand_f *x; |
x = mTimeHandler; |
mTimeHandler = (thand_f *) 0; |
(*x) (); |
} |
c = uart_testc(); |
if (c != 0) |
break; |
} |
|
while(retval != 0) { |
retval = getBlock(c); |
if(retval != 0) |
c = uart_getc(); |
} |
while (retval != 0) { |
retval = getBlock(c); |
if (retval != 0) |
c = uart_getc(); |
} |
|
if(modemMode == 2) { |
c = uart_getc(); |
retval = getBlock(c); /* last 'dummy' block for YModem */ |
printf("... protocol: YModem, "); |
} |
else |
printf("... protocol: ZModem, "); |
return length; |
if (modemMode == 2) { |
c = uart_getc(); |
retval = getBlock(c); /* last 'dummy' block for YModem */ |
printf("... protocol: YModem, "); |
} else |
printf("... protocol: ZModem, "); |
return length; |
} |
/orpmon/services/arp.c
29,13 → 29,14
#include "arp.h" |
#include "string.h" |
|
#define TIMEOUT 5 /* Seconds before trying ARP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
#define DEBUG // jb |
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len); |
#define TIMEOUT 5 /* Seconds before trying ARP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
#define DEBUG // jb |
static void ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, |
unsigned len); |
static void ArpTimeout(void); |
|
int ArpTry = 0; |
int ArpTry = 0; |
|
/* |
* Handle a ARP received packet. |
44,68 → 45,67
ArpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len) |
{ |
/* Check if the frame is really an ARP reply */ |
if (memcmp (NetServerEther, NetBcastAddr, 6) != 0) { |
if (memcmp(NetServerEther, NetBcastAddr, 6) != 0) { |
#ifdef DEBUG |
printf("Got good ARP - start TFTP\n"); |
#endif |
TftpStart (); |
TftpStart(); |
} |
} |
|
|
/* |
* Timeout on ARP request. |
*/ |
static void |
ArpTimeout(void) |
static void ArpTimeout(void) |
{ |
if (ArpTry >= TIMEOUT_COUNT) { |
printf("\nRetry count exceeded; starting again\n"); |
NetStartAgain (); |
NetStartAgain(); |
} else { |
NetSetTimeout (TIMEOUT * TICKS_PER_SEC, ArpTimeout); |
ArpRequest (); |
NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout); |
ArpRequest(); |
} |
} |
|
|
void |
ArpRequest (void) |
void ArpRequest(void) |
{ |
int i; |
volatile unsigned char *pkt; |
ARP_t * arp; |
ARP_t *arp; |
#ifdef DEBUG |
printf("ARP broadcast %d\n", ++ArpTry); |
#endif |
pkt = NetTxPacket; |
#endif |
// NetTxPacket is a char* to global buffer used for constructing |
// a packet to send. |
pkt = NetTxPacket; |
|
// Setup an ethernet header for ARP protocol in packet |
NetSetEther(pkt, NetBcastAddr, PROT_ARP); |
pkt += ETHER_HDR_SIZE; |
|
arp = (ARP_t *)pkt; |
arp = (ARP_t *) pkt; |
|
arp->ar_hrd = ARP_ETHER; |
arp->ar_pro = PROT_IP; |
arp->ar_hln = 6; |
arp->ar_pln = 4; |
arp->ar_op = ARPOP_REQUEST; |
arp->ar_op = ARPOP_REQUEST; |
NetCopyEther(&arp->ar_data[0], NetOurEther); /* source ET addr */ |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; /* source IP addr */ |
memcpy(&arp->ar_data[6], (unsigned char*) &NetOurIP, 4); |
|
for (i=10; i<16; ++i) { |
arp->ar_data[i] = 0; /* dest ET addr = 0*/ |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; /* source IP addr */ |
memcpy(&arp->ar_data[6], (unsigned char *)&NetOurIP, 4); |
|
for (i = 10; i < 16; ++i) { |
arp->ar_data[i] = 0; /* dest ET addr = 0 */ |
} |
|
if((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) { |
//*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP; |
memcpy(&arp->ar_data[16], (unsigned char*) &NetOurGatewayIP, |
sizeof(IPaddr_t)); |
if ((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) { |
//*(IPaddr_t *)(&arp->ar_data[16]) = NetOurGatewayIP; |
memcpy(&arp->ar_data[16], (unsigned char *)&NetOurGatewayIP, |
sizeof(IPaddr_t)); |
} else { |
//*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP; |
memcpy(&arp->ar_data[16], (unsigned char*) &NetServerIP, |
sizeof(IPaddr_t)); |
//*((IPaddr_t *)(&(arp->ar_data[16]))) = NetServerIP; |
memcpy(&arp->ar_data[16], (unsigned char *)&NetServerIP, |
sizeof(IPaddr_t)); |
} |
|
NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE); |
113,4 → 113,3
NetSetTimeout(TIMEOUT * TICKS_PER_SEC, ArpTimeout); |
NetSetHandler(ArpHandler); |
} |
|
/orpmon/services/tftp.h
14,7 → 14,7
*/ |
|
/* tftp.c */ |
extern void TftpStart (void); /* Begin TFTP get */ |
extern void TftpStart(void); /* Begin TFTP get */ |
|
/**********************************************************************/ |
|
/orpmon/services/bootp.c
9,7 → 9,7
|
#if 1 |
#define DEBUG 1 /* general debug */ |
#define DEBUG_BOOTP_EXT 1 /* Debug received vendor fields */ |
#define DEBUG_BOOTP_EXT 1 /* Debug received vendor fields */ |
#endif |
|
#ifdef DEBUG_BOOTP_EXT |
24,24 → 24,24
#include "tftp.h" |
#include "arp.h" |
|
#define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ |
#define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ |
|
#if (CONFIG_COMMANDS & CFG_CMD_NET) |
|
#define TIMEOUT 5 /* Seconds before trying BOOTP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
#define TIMEOUT 5 /* Seconds before trying BOOTP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
|
#define PORT_BOOTPS 67 /* BOOTP server UDP port */ |
#define PORT_BOOTPC 68 /* BOOTP client UDP port */ |
#define PORT_BOOTPS 67 /* BOOTP server UDP port */ |
#define PORT_BOOTPC 68 /* BOOTP client UDP port */ |
|
#ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */ |
#ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */ |
#define CONFIG_DHCP_MIN_EXT_LEN 64 |
#endif |
|
ulong BootpID; |
int BootpTry; |
ulong BootpID; |
int BootpTry; |
#ifdef CONFIG_BOOTP_RANDOM_DELAY |
ulong seed1, seed2; |
ulong seed1, seed2; |
#endif |
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
53,25 → 53,41
char *dhcpmsg2str(int type) |
{ |
switch (type) { |
case 1: return "DHCPDISCOVER"; break; |
case 2: return "DHCPOFFER"; break; |
case 3: return "DHCPREQUEST"; break; |
case 4: return "DHCPDECLINE"; break; |
case 5: return "DHCPACK"; break; |
case 6: return "DHCPNACK"; break; |
case 7: return "DHCPRELEASE"; break; |
default: return "UNKNOWN/INVALID MSG TYPE"; break; |
case 1: |
return "DHCPDISCOVER"; |
break; |
case 2: |
return "DHCPOFFER"; |
break; |
case 3: |
return "DHCPREQUEST"; |
break; |
case 4: |
return "DHCPDECLINE"; |
break; |
case 5: |
return "DHCPACK"; |
break; |
case 6: |
return "DHCPNACK"; |
break; |
case 7: |
return "DHCPRELEASE"; |
break; |
default: |
return "UNKNOWN/INVALID MSG TYPE"; |
break; |
} |
} |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX) |
extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */ |
extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */ |
extern u8 *dhcp_vendorex_prep(u8 * e); /*rtn new e after add own opts. */ |
extern u8 *dhcp_vendorex_proc(u8 * e); /*rtn next e if mine,else NULL */ |
#endif |
|
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
|
static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len) |
static int BootpCheckPkt(uchar * pkt, unsigned dest, unsigned src, unsigned len) |
{ |
Bootp_t *bp = (Bootp_t *) pkt; |
int retval = 0; |
78,13 → 94,12
|
if (dest != PORT_BOOTPC || src != PORT_BOOTPS) |
retval = -1; |
if (len < sizeof (Bootp_t) - OPT_SIZE) |
if (len < sizeof(Bootp_t) - OPT_SIZE) |
retval = -2; |
if (bp->bp_op != OP_BOOTREQUEST && |
bp->bp_op != OP_BOOTREPLY && |
bp->bp_op != DHCP_OFFER && |
bp->bp_op != DHCP_ACK && |
bp->bp_op != DHCP_NAK ) { |
bp->bp_op != DHCP_ACK && bp->bp_op != DHCP_NAK) { |
retval = -3; |
} |
if (bp->bp_htype != HWT_ETHER) |
94,7 → 109,7
if (bp->bp_id != BootpID) |
retval = -6; |
|
debug ("Filtering pkt = %d\n", retval); |
debug("Filtering pkt = %d\n", retval); |
|
return retval; |
} |
102,29 → 117,30
/* |
* Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet |
*/ |
void BootpCopyNetParams(Bootp_t *bp) |
void BootpCopyNetParams(Bootp_t * bp) |
{ |
NetOurIP = bp->bp_yiaddr; |
NetServerIP = bp->bp_siaddr; |
NetCopyEther(NetServerEther, ((Ethernet_t *)NetRxPkt)->et_src); |
copy_filename (BootFile, bp->bp_file, sizeof(BootFile)); |
NetCopyEther(NetServerEther, ((Ethernet_t *) NetRxPkt)->et_src); |
copy_filename(BootFile, bp->bp_file, sizeof(BootFile)); |
|
debug ("Bootfile: %s\n", BootFile); |
debug("Bootfile: %s\n", BootFile); |
|
/* Propagate to environment: |
* don't delete exising entry when BOOTP / DHCP reply does |
* don't delete exising entry when BOOTP / DHCP reply does |
* not contain a new value |
*/ |
if (*BootFile) { |
setenv ("bootfile", BootFile); |
setenv("bootfile", BootFile); |
} |
} |
|
static int truncate_sz (const char *name, int maxlen, int curlen) |
static int truncate_sz(const char *name, int maxlen, int curlen) |
{ |
if (curlen >= maxlen) { |
printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n", |
name, curlen, maxlen); |
printf |
("*** WARNING: %s is too long (%d - max: %d) - truncated\n", |
name, curlen, maxlen); |
curlen = maxlen - 1; |
} |
return (curlen); |
132,180 → 148,183
|
#if !(CONFIG_COMMANDS & CFG_CMD_DHCP) |
|
static void BootpVendorFieldProcess(u8 *ext) |
static void BootpVendorFieldProcess(u8 * ext) |
{ |
int size = *(ext+1) ; |
int size = *(ext + 1); |
|
debug_ext ("[BOOTP] Processing extension %d... (%d bytes)\n", *ext, *(ext+1)); |
debug_ext("[BOOTP] Processing extension %d... (%d bytes)\n", *ext, |
*(ext + 1)); |
|
NetBootFileSize = 0; |
NetBootFileSize = 0; |
|
switch (*ext) { |
/* Fixed length fields */ |
case 1: /* Subnet mask */ |
switch (*ext) { |
/* Fixed length fields */ |
case 1: /* Subnet mask */ |
if (NetOurSubnetMask == 0) |
memcpy(&NetOurSubnetMask, ext+2, 4); |
memcpy(&NetOurSubnetMask, ext + 2, 4); |
break; |
case 2: /* Time offset - Not yet supported */ |
case 2: /* Time offset - Not yet supported */ |
break; |
/* Variable length fields */ |
case 3: /* Gateways list */ |
/* Variable length fields */ |
case 3: /* Gateways list */ |
if (NetOurGatewayIP == 0) { |
memcpy(&NetOurGatewayIP, ext+2, 4); |
memcpy(&NetOurGatewayIP, ext + 2, 4); |
} |
break; |
case 4: /* Time server - Not yet supported */ |
case 4: /* Time server - Not yet supported */ |
break; |
case 5: /* IEN-116 name server - Not yet supported */ |
case 5: /* IEN-116 name server - Not yet supported */ |
break; |
case 6: |
if (NetOurDNSIP == 0) { |
memcpy(&NetOurDNSIP, ext+2, 4); |
memcpy(&NetOurDNSIP, ext + 2, 4); |
} |
break; |
case 7: /* Log server - Not yet supported */ |
case 7: /* Log server - Not yet supported */ |
break; |
case 8: /* Cookie/Quote server - Not yet supported */ |
case 8: /* Cookie/Quote server - Not yet supported */ |
break; |
case 9: /* LPR server - Not yet supported */ |
case 9: /* LPR server - Not yet supported */ |
break; |
case 10: /* Impress server - Not yet supported */ |
case 10: /* Impress server - Not yet supported */ |
break; |
case 11: /* RPL server - Not yet supported */ |
case 11: /* RPL server - Not yet supported */ |
break; |
case 12: /* Host name */ |
case 12: /* Host name */ |
if (NetOurHostName[0] == 0) { |
size = truncate_sz("Host Name", sizeof(NetOurHostName), size); |
memcpy(&NetOurHostName, ext+2, size); |
NetOurHostName[size] = 0 ; |
size = |
truncate_sz("Host Name", sizeof(NetOurHostName), |
size); |
memcpy(&NetOurHostName, ext + 2, size); |
NetOurHostName[size] = 0; |
} |
break; |
case 13: /* Boot file size */ |
memcpy(&NetBootFileSize, ext+2, size); |
case 13: /* Boot file size */ |
memcpy(&NetBootFileSize, ext + 2, size); |
break; |
case 14: /* Merit dump file - Not yet supported */ |
case 14: /* Merit dump file - Not yet supported */ |
break; |
case 15: /* Domain name - Not yet supported */ |
case 15: /* Domain name - Not yet supported */ |
break; |
case 16: /* Swap server - Not yet supported */ |
case 16: /* Swap server - Not yet supported */ |
break; |
case 17: /* Root path */ |
case 17: /* Root path */ |
if (NetOurRootPath[0] == 0) { |
size = truncate_sz("Root Path", sizeof(NetOurRootPath), size); |
memcpy(&NetOurRootPath, ext+2, size); |
NetOurRootPath[size] = 0 ; |
size = |
truncate_sz("Root Path", sizeof(NetOurRootPath), |
size); |
memcpy(&NetOurRootPath, ext + 2, size); |
NetOurRootPath[size] = 0; |
} |
break; |
case 18: /* Extension path - Not yet supported */ |
case 18: /* Extension path - Not yet supported */ |
/* |
* This can be used to send the informations of the |
* vendor area in another file that the client can |
* access via TFTP. |
* This can be used to send the informations of the |
* vendor area in another file that the client can |
* access via TFTP. |
*/ |
break; |
/* IP host layer fields */ |
case 40: /* NIS Domain name */ |
/* IP host layer fields */ |
case 40: /* NIS Domain name */ |
if (NetOurNISDomain[0] == 0) { |
size = truncate_sz ("NIS Domain Name", |
sizeof(NetOurNISDomain), |
size); |
memcpy(&NetOurNISDomain, ext+2, size); |
NetOurNISDomain[size] = 0 ; |
size = truncate_sz("NIS Domain Name", |
sizeof(NetOurNISDomain), size); |
memcpy(&NetOurNISDomain, ext + 2, size); |
NetOurNISDomain[size] = 0; |
} |
break; |
/* Application layer fields */ |
case 43: /* Vendor specific info - Not yet supported */ |
/* Application layer fields */ |
case 43: /* Vendor specific info - Not yet supported */ |
/* |
* Binary informations to exchange specific |
* product information. |
* Binary informations to exchange specific |
* product information. |
*/ |
break; |
/* Reserved (custom) fields (128..254) */ |
} |
/* Reserved (custom) fields (128..254) */ |
} |
} |
|
static void BootpVendorProcess(u8 *ext, int size) |
static void BootpVendorProcess(u8 * ext, int size) |
{ |
u8 *end = ext + size ; |
u8 *end = ext + size; |
|
debug_ext ("[BOOTP] Checking extension (%d bytes)...\n", size); |
debug_ext("[BOOTP] Checking extension (%d bytes)...\n", size); |
|
while ((ext < end) && (*ext != 0xff)) { |
if (*ext == 0) { |
ext ++ ; |
} else { |
u8 *opt = ext ; |
ext += ext[1] + 2 ; |
if (ext <= end) |
BootpVendorFieldProcess (opt) ; |
while ((ext < end) && (*ext != 0xff)) { |
if (*ext == 0) { |
ext++; |
} else { |
u8 *opt = ext; |
ext += ext[1] + 2; |
if (ext <= end) |
BootpVendorFieldProcess(opt); |
} |
} |
} |
|
#ifdef DEBUG_BOOTP_EXT |
printf("[BOOTP] Received fields: \n"); |
if (NetOurSubnetMask) { |
puts ("NetOurSubnetMask : "); |
print_IPaddr (NetOurSubnetMask); |
putc('\n'); |
} |
printf("[BOOTP] Received fields: \n"); |
if (NetOurSubnetMask) { |
puts("NetOurSubnetMask : "); |
print_IPaddr(NetOurSubnetMask); |
putc('\n'); |
} |
|
if (NetOurGatewayIP) { |
puts ("NetOurGatewayIP : "); |
print_IPaddr (NetOurGatewayIP); |
putc('\n'); |
} |
if (NetOurGatewayIP) { |
puts("NetOurGatewayIP : "); |
print_IPaddr(NetOurGatewayIP); |
putc('\n'); |
} |
|
if (NetBootFileSize) { |
printf("NetBootFileSize : %d\n", NetBootFileSize); |
} |
if (NetBootFileSize) { |
printf("NetBootFileSize : %d\n", NetBootFileSize); |
} |
|
if (NetOurHostName[0]) { |
printf("NetOurHostName : %s\n", NetOurHostName); |
} |
if (NetOurHostName[0]) { |
printf("NetOurHostName : %s\n", NetOurHostName); |
} |
|
if (NetOurRootPath[0]) { |
printf("NetOurRootPath : %s\n", NetOurRootPath); |
} |
if (NetOurRootPath[0]) { |
printf("NetOurRootPath : %s\n", NetOurRootPath); |
} |
|
if (NetOurNISDomain[0]) { |
printf("NetOurNISDomain : %s\n", NetOurNISDomain); |
} |
#endif /* DEBUG_BOOTP_EXT */ |
if (NetOurNISDomain[0]) { |
printf("NetOurNISDomain : %s\n", NetOurNISDomain); |
} |
#endif /* DEBUG_BOOTP_EXT */ |
} |
|
/* |
* Handle a BOOTP received packet. |
*/ |
static void |
BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) |
static void BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) |
{ |
Bootp_t *bp; |
char *s; |
char *s; |
|
debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n", |
src, dest, len, sizeof (Bootp_t)); |
debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n", |
src, dest, len, sizeof(Bootp_t)); |
|
bp = (Bootp_t *)pkt; |
bp = (Bootp_t *) pkt; |
|
if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */ |
return; |
|
/* |
* Got a good BOOTP reply. Copy the data into our variables. |
* Got a good BOOTP reply. Copy the data into our variables. |
*/ |
#ifdef CONFIG_STATUS_LED |
status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF); |
status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
#endif |
|
BootpCopyNetParams(bp); /* Store net parameters from reply */ |
BootpCopyNetParams(bp); /* Store net parameters from reply */ |
|
/* Retrieve extended informations (we must parse the vendor area) */ |
if ((*(uint *)bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
BootpVendorProcess(&bp->bp_vend[4], len); |
if ((*(uint *) bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
BootpVendorProcess(&bp->bp_vend[4], len); |
|
NetSetTimeout(0, (thand_f *)0); |
NetSetTimeout(0, (thand_f *) 0); |
|
debug ("Got good BOOTP\n"); |
debug("Got good BOOTP\n"); |
|
if (((s = getenv("autoload")) != NULL) && (*s == 'n')) { |
/* |
321,20 → 340,19
*/ |
ArpRequest(); |
} |
#endif /* !CFG_CMD_DHCP */ |
#endif /* !CFG_CMD_DHCP */ |
|
/* |
* Timeout on BOOTP/DHCP request. |
*/ |
static void |
BootpTimeout(void) |
static void BootpTimeout(void) |
{ |
if (BootpTry >= TIMEOUT_COUNT) { |
puts ("\nRetry count exceeded; starting again\n"); |
NetStartAgain (); |
puts("\nRetry count exceeded; starting again\n"); |
NetStartAgain(); |
} else { |
NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout); |
BootpRequest (); |
NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout); |
BootpRequest(); |
} |
} |
|
342,167 → 360,166
* Initialize BOOTP extension fields in the request. |
*/ |
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP) |
static int DhcpExtended(u8 * e, int message_type, IPaddr_t ServerID, |
IPaddr_t RequestedIP) |
{ |
u8 *start = e ; |
u8 *cnt; |
u8 *start = e; |
u8 *cnt; |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX) |
u8 *x; |
u8 *x; |
#endif |
|
*e++ = 99; /* RFC1048 Magic Cookie */ |
*e++ = 130; |
*e++ = 83; |
*e++ = 99; |
*e++ = 99; /* RFC1048 Magic Cookie */ |
*e++ = 130; |
*e++ = 83; |
*e++ = 99; |
|
*e++ = 53; /* DHCP Message Type */ |
*e++ = 1; |
*e++ = message_type; |
*e++ = 53; /* DHCP Message Type */ |
*e++ = 1; |
*e++ = message_type; |
|
*e++ = 57; /* Maximum DHCP Message Size */ |
*e++ = 2; |
*e++ = (576-312+OPT_SIZE) >> 8; |
*e++ = (576-312+OPT_SIZE) & 0xff; |
*e++ = 57; /* Maximum DHCP Message Size */ |
*e++ = 2; |
*e++ = (576 - 312 + OPT_SIZE) >> 8; |
*e++ = (576 - 312 + OPT_SIZE) & 0xff; |
|
if ( ServerID ) { |
*e++ = 54; /* ServerID */ |
*e++ = 4; |
*e++ = ServerID >> 24; |
*e++ = ServerID >> 16; |
*e++ = ServerID >> 8; |
*e++ = ServerID & 0xff; |
} |
if (ServerID) { |
*e++ = 54; /* ServerID */ |
*e++ = 4; |
*e++ = ServerID >> 24; |
*e++ = ServerID >> 16; |
*e++ = ServerID >> 8; |
*e++ = ServerID & 0xff; |
} |
|
if ( RequestedIP ) { |
*e++ = 50; /* Requested IP */ |
*e++ = 4; |
*e++ = RequestedIP >> 24; |
*e++ = RequestedIP >> 16; |
*e++ = RequestedIP >> 8; |
*e++ = RequestedIP & 0xff; |
} |
|
if (RequestedIP) { |
*e++ = 50; /* Requested IP */ |
*e++ = 4; |
*e++ = RequestedIP >> 24; |
*e++ = RequestedIP >> 16; |
*e++ = RequestedIP >> 8; |
*e++ = RequestedIP & 0xff; |
} |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX) |
if ((x = dhcp_vendorex_prep (e))) |
return x - start ; |
if ((x = dhcp_vendorex_prep(e))) |
return x - start; |
#endif |
|
*e++ = 55; /* Parameter Request List */ |
cnt = e++; /* Pointer to count of requested items */ |
*cnt = 0; |
*e++ = 55; /* Parameter Request List */ |
cnt = e++; /* Pointer to count of requested items */ |
*cnt = 0; |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK) |
*e++ = 1; /* Subnet Mask */ |
*cnt += 1; |
*e++ = 1; /* Subnet Mask */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY) |
*e++ = 3; /* Router Option */ |
*cnt += 1; |
*e++ = 3; /* Router Option */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS) |
*e++ = 6; /* DNS Server(s) */ |
*cnt += 1; |
*e++ = 6; /* DNS Server(s) */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME) |
*e++ = 12; /* Hostname */ |
*cnt += 1; |
*e++ = 12; /* Hostname */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE) |
*e++ = 13; /* Boot File Size */ |
*cnt += 1; |
*e++ = 13; /* Boot File Size */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH) |
*e++ = 17; /* Boot path */ |
*cnt += 1; |
*e++ = 17; /* Boot path */ |
*cnt += 1; |
#endif |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN) |
*e++ = 40; /* NIS Domain name request */ |
*cnt += 1; |
*e++ = 40; /* NIS Domain name request */ |
*cnt += 1; |
#endif |
*e++ = 255; /* End of the list */ |
*e++ = 255; /* End of the list */ |
|
/* Pad to minimal length */ |
/* Pad to minimal length */ |
#ifdef CONFIG_DHCP_MIN_EXT_LEN |
while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN) |
*e++ = 0; |
while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN) |
*e++ = 0; |
#endif |
|
return e - start ; |
return e - start; |
} |
|
#else /* CFG_CMD_DHCP */ |
#else /* CFG_CMD_DHCP */ |
/* |
* Warning: no field size check - change CONFIG_BOOTP_MASK at your own risk! |
*/ |
static int BootpExtended (u8 *e) |
static int BootpExtended(u8 * e) |
{ |
u8 *start = e ; |
u8 *start = e; |
|
*e++ = 99; /* RFC1048 Magic Cookie */ |
*e++ = 130; |
*e++ = 83; |
*e++ = 99; |
*e++ = 99; /* RFC1048 Magic Cookie */ |
*e++ = 130; |
*e++ = 83; |
*e++ = 99; |
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
*e++ = 53; /* DHCP Message Type */ |
*e++ = 1; |
*e++ = DHCP_DISCOVER; |
*e++ = 53; /* DHCP Message Type */ |
*e++ = 1; |
*e++ = DHCP_DISCOVER; |
|
*e++ = 57; /* Maximum DHCP Message Size */ |
*e++ = 2; |
*e++ = (576-312+OPT_SIZE) >> 16; |
*e++ = (576-312+OPT_SIZE) & 0xff; |
#endif /* CFG_CMD_DHCP */ |
*e++ = 57; /* Maximum DHCP Message Size */ |
*e++ = 2; |
*e++ = (576 - 312 + OPT_SIZE) >> 16; |
*e++ = (576 - 312 + OPT_SIZE) & 0xff; |
#endif /* CFG_CMD_DHCP */ |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK) |
*e++ = 1; /* Subnet mask request */ |
*e++ = 4; |
e += 4; |
*e++ = 1; /* Subnet mask request */ |
*e++ = 4; |
e += 4; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY) |
*e++ = 3; /* Default gateway request */ |
*e++ = 4; |
e += 4; |
*e++ = 3; /* Default gateway request */ |
*e++ = 4; |
e += 4; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS) |
*e++ = 6; /* Domain Name Server */ |
*e++ = 4; |
e += 4; |
*e++ = 6; /* Domain Name Server */ |
*e++ = 4; |
e += 4; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME) |
*e++ = 12; /* Host name request */ |
*e++ = 32; |
e += 32; |
*e++ = 12; /* Host name request */ |
*e++ = 32; |
e += 32; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE) |
*e++ = 13; /* Boot file size */ |
*e++ = 2; |
e += 2; |
*e++ = 13; /* Boot file size */ |
*e++ = 2; |
e += 2; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH) |
*e++ = 17; /* Boot path */ |
*e++ = 32; |
e += 32; |
*e++ = 17; /* Boot path */ |
*e++ = 32; |
e += 32; |
#endif |
|
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN) |
*e++ = 40; /* NIS Domain name request */ |
*e++ = 32; |
e += 32; |
*e++ = 40; /* NIS Domain name request */ |
*e++ = 32; |
e += 32; |
#endif |
|
*e++ = 255; /* End of the list */ |
*e++ = 255; /* End of the list */ |
|
return e - start ; |
return e - start; |
} |
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
|
void |
BootpRequest (void) |
void BootpRequest(void) |
{ |
volatile uchar *pkt, *iphdr; |
Bootp_t *bp; |
512,50 → 529,48
dhcp_state = INIT; |
#endif |
|
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ |
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ |
unsigned char bi_enetaddr[6]; |
int reg; |
char *e,*s; |
int reg; |
char *e, *s; |
uchar tmp[64]; |
ulong tst1, tst2, sum, m_mask, m_value = 0; |
|
if (BootpTry ==0) { |
if (BootpTry == 0) { |
/* get our mac */ |
reg = getenv_r ("ethaddr", tmp, sizeof(tmp)); |
reg = getenv_r("ethaddr", tmp, sizeof(tmp)); |
s = (reg > 0) ? tmp : NULL; |
|
for (reg=0; reg<6; ++reg) { |
for (reg = 0; reg < 6; ++reg) { |
bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0; |
if (s) { |
s = (*e) ? e+1 : e; |
s = (*e) ? e + 1 : e; |
} |
} |
#ifdef DEBUG |
printf("BootpRequest => Our Mac: "); |
for (reg=0; reg<6; reg++) { |
printf ("%x%c", |
bi_enetaddr[reg], |
reg==5 ? '\n' : ':'); |
for (reg = 0; reg < 6; reg++) { |
printf("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':'); |
} |
#endif /* DEBUG */ |
|
/* Mac-Manipulation 2 get seed1 */ |
tst1=0; |
tst2=0; |
for (reg=2; reg<6; reg++) { |
tst1 = 0; |
tst2 = 0; |
for (reg = 2; reg < 6; reg++) { |
tst1 = tst1 << 8; |
tst1 = tst1 | bi_enetaddr[reg]; |
} |
for (reg=0; reg<2; reg++) { |
for (reg = 0; reg < 2; reg++) { |
tst2 = tst2 | bi_enetaddr[reg]; |
tst2 = tst2 << 8; |
} |
|
seed1 = tst1^tst2; |
seed1 = tst1 ^ tst2; |
|
/* Mirror seed1*/ |
m_mask=0x1; |
for (reg=1;reg<=32;reg++) { |
/* Mirror seed1 */ |
m_mask = 0x1; |
for (reg = 1; reg <= 32; reg++) { |
m_value |= (m_mask & seed1); |
seed1 = seed1 >> 1; |
m_value = m_value << 1; |
566,29 → 581,29
|
/* Random Number Generator */ |
|
for (reg=0;reg<=0;reg++) { |
for (reg = 0; reg <= 0; reg++) { |
sum = seed1 + seed2; |
if (sum < seed1 || sum < seed2) |
sum++; |
seed2 = seed1; |
seed2 = seed1; |
seed1 = sum; |
|
if (BootpTry<=2) { /* Start with max 1024 * 1ms */ |
sum = sum >> (22-BootpTry); |
} else { /*After 3rd BOOTP request max 8192 * 1ms */ |
if (BootpTry <= 2) { /* Start with max 1024 * 1ms */ |
sum = sum >> (22 - BootpTry); |
} else { /*After 3rd BOOTP request max 8192 * 1ms */ |
sum = sum >> 19; |
} |
} |
|
printf ("Random delay: %ld ms...\n", sum); |
for (reg=0; reg <sum; reg++) { |
udelay(1000); /*Wait 1ms*/ |
printf("Random delay: %ld ms...\n", sum); |
for (reg = 0; reg < sum; reg++) { |
udelay(1000); /*Wait 1ms */ |
} |
#endif /* CONFIG_BOOTP_RANDOM_DELAY */ |
#endif /* CONFIG_BOOTP_RANDOM_DELAY */ |
|
printf("BOOTP broadcast %d\n", ++BootpTry); |
pkt = NetTxPacket; |
memset ((void*)pkt, 0, PKTSIZE); |
memset((void *)pkt, 0, PKTSIZE); |
|
NetSetEther(pkt, NetBcastAddr, PROT_IP); |
pkt += ETHER_HDR_SIZE; |
600,21 → 615,21
* C. Hallinan, DS4.COM, Inc. |
*/ |
/* NetSetIP(pkt, 0xffffffffL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */ |
iphdr = pkt; /* We need this later for NetSetIP() */ |
iphdr = pkt; /* We need this later for NetSetIP() */ |
pkt += IP_HDR_SIZE; |
|
bp = (Bootp_t *)pkt; |
bp = (Bootp_t *) pkt; |
bp->bp_op = OP_BOOTREQUEST; |
bp->bp_htype = HWT_ETHER; |
bp->bp_hlen = HWL_ETHER; |
bp->bp_hops = 0; |
bp->bp_secs = SWAP16( get_timer(0) / CFG_HZ); |
bp->bp_secs = SWAP16(get_timer(0) / CFG_HZ); |
bp->bp_ciaddr = 0; |
bp->bp_yiaddr = 0; |
bp->bp_siaddr = 0; |
bp->bp_giaddr = 0; |
NetCopyEther(bp->bp_chaddr, NetOurEther); |
copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file)); |
copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file)); |
|
/* Request additional information from the BOOTP/DHCP server */ |
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
621,16 → 636,16
ext_len = DhcpExtended(bp->bp_vend, DHCP_DISCOVER, 0, 0); |
#else |
ext_len = BootpExtended(bp->bp_vend); |
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
|
/* |
* Bootp ID is the lower 4 bytes of our ethernet address |
* plus the current time in HZ. |
* Bootp ID is the lower 4 bytes of our ethernet address |
* plus the current time in HZ. |
*/ |
BootpID = ((ulong)NetOurEther[2] << 24) |
| ((ulong)NetOurEther[3] << 16) |
| ((ulong)NetOurEther[4] << 8) |
| (ulong)NetOurEther[5]; |
BootpID = ((ulong) NetOurEther[2] << 24) |
| ((ulong) NetOurEther[3] << 16) |
| ((ulong) NetOurEther[4] << 8) |
| (ulong) NetOurEther[5]; |
BootpID += get_timer(0); |
bp->bp_id = BootpID; |
|
648,7 → 663,7
NetSetHandler(DhcpHandler); |
#else |
NetSetHandler(BootpHandler); |
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
NetSendPacket(NetTxPacket, pktlen); |
} |
|
658,54 → 673,52
char *end = popt + BOOTP_HDR_SIZE; |
int oplen, size; |
|
while ( popt < end && *popt != 0xff ) { |
while (popt < end && *popt != 0xff) { |
oplen = *(popt + 1); |
switch(*popt) { |
case 1: |
NetOurSubnetMask = *(IPaddr_t *)(popt + 2); |
switch (*popt) { |
case 1: |
NetOurSubnetMask = *(IPaddr_t *) (popt + 2); |
break; |
case 3: |
NetOurGatewayIP = *(IPaddr_t *) (popt + 2); |
break; |
case 6: |
NetOurDNSIP = *(IPaddr_t *) (popt + 2); |
break; |
case 12: |
size = truncate_sz("Host Name", |
sizeof(NetOurHostName), oplen); |
memcpy(&NetOurHostName, popt + 2, size); |
NetOurHostName[size] = 0; |
break; |
case 15: /* Ignore Domain Name Option */ |
break; |
case 17: |
size = truncate_sz("Root Path", |
sizeof(NetOurRootPath), oplen); |
memcpy(&NetOurRootPath, popt + 2, size); |
NetOurRootPath[size] = 0; |
break; |
case 51: |
dhcp_leasetime = *(unsigned int *)(popt + 2); |
break; |
case 53: /* Ignore Message Type Option */ |
break; |
case 54: |
NetServerIP = *(IPaddr_t *) (popt + 2); |
break; |
case 58: /* Ignore Renewal Time Option */ |
break; |
case 59: /* Ignore Rebinding Time Option */ |
break; |
default: |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX) |
if (dhcp_vendorex_proc(popt)) |
break; |
case 3: |
NetOurGatewayIP = *(IPaddr_t *)(popt + 2); |
break; |
case 6: |
NetOurDNSIP = *(IPaddr_t *)(popt +2); |
break; |
case 12: |
size = truncate_sz ("Host Name", |
sizeof(NetOurHostName), |
oplen); |
memcpy(&NetOurHostName, popt+2, size); |
NetOurHostName[size] = 0 ; |
break; |
case 15: /* Ignore Domain Name Option */ |
break; |
case 17: |
size = truncate_sz ("Root Path", |
sizeof(NetOurRootPath), |
oplen); |
memcpy(&NetOurRootPath, popt+2, size); |
NetOurRootPath[size] = 0 ; |
break; |
case 51: |
dhcp_leasetime = *(unsigned int *)(popt + 2); |
break; |
case 53: /* Ignore Message Type Option */ |
break; |
case 54: |
NetServerIP = *(IPaddr_t *)(popt+2); |
break; |
case 58: /* Ignore Renewal Time Option */ |
break; |
case 59: /* Ignore Rebinding Time Option */ |
break; |
default: |
#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX) |
if (dhcp_vendorex_proc(popt)) |
break; |
#endif |
printf("*** Unhandled DHCP Option in OFFER/ACK: %d\n", |
*popt); |
break; |
printf("*** Unhandled DHCP Option in OFFER/ACK: %d\n", |
*popt); |
break; |
} |
popt += oplen + 2; /* Process next option */ |
} |
713,12 → 726,12
|
static int DhcpMessageType(unsigned char *popt) |
{ |
if ((*(uint *)popt) != BOOTP_VENDOR_MAGIC) |
if ((*(uint *) popt) != BOOTP_VENDOR_MAGIC) |
return -1; |
|
popt += 4; |
while ( *popt != 0xff ) { |
if ( *popt == 53 ) /* DHCP Message Type */ |
while (*popt != 0xff) { |
if (*popt == 53) /* DHCP Message Type */ |
return *(popt + 2); |
popt += *(popt + 1) + 2; /* Scan through all options */ |
} |
725,15 → 738,15
return -1; |
} |
|
void DhcpSendRequestPkt(Bootp_t *bp_offer) |
void DhcpSendRequestPkt(Bootp_t * bp_offer) |
{ |
volatile uchar *pkt, *iphdr; |
Bootp_t *bp; |
int pktlen, iplen, extlen; |
|
debug ("DhcpSendRequestPkt: Sending DHCPREQUEST\n"); |
debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n"); |
pkt = NetTxPacket; |
memset ((void*)pkt, 0, PKTSIZE); |
memset((void *)pkt, 0, PKTSIZE); |
|
NetSetEther(pkt, NetBcastAddr, PROT_IP); |
pkt += ETHER_HDR_SIZE; |
741,16 → 754,16
iphdr = pkt; /* We'll need this later to set proper pkt size */ |
pkt += IP_HDR_SIZE; |
|
bp = (Bootp_t *)pkt; |
bp = (Bootp_t *) pkt; |
bp->bp_op = OP_BOOTREQUEST; |
bp->bp_htype = HWT_ETHER; |
bp->bp_hlen = HWL_ETHER; |
bp->bp_hops = 0; |
bp->bp_secs = SWAP16( get_timer(0) / CFG_HZ); |
bp->bp_ciaddr = bp_offer->bp_ciaddr; |
bp->bp_yiaddr = bp_offer->bp_yiaddr; |
bp->bp_siaddr = bp_offer->bp_siaddr; |
bp->bp_giaddr = bp_offer->bp_giaddr; |
bp->bp_secs = SWAP16(get_timer(0) / CFG_HZ); |
bp->bp_ciaddr = bp_offer->bp_ciaddr; |
bp->bp_yiaddr = bp_offer->bp_yiaddr; |
bp->bp_siaddr = bp_offer->bp_siaddr; |
bp->bp_giaddr = bp_offer->bp_giaddr; |
NetCopyEther(bp->bp_chaddr, NetOurEther); |
|
/* |
762,13 → 775,14
/* |
* Copy options from OFFER packet if present |
*/ |
extlen = DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetServerIP, bp->bp_yiaddr); |
extlen = |
DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetServerIP, bp->bp_yiaddr); |
|
pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen; |
iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen; |
NetSetIP(iphdr, 0xffffffffL, PORT_BOOTPS, PORT_BOOTPC, iplen); |
|
debug ("Transmitting DHCPREQUEST packet: len = %d\n", pktlen); |
debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen); |
NetSendPacket(NetTxPacket, pktlen); |
} |
|
775,19 → 789,19
/* |
* Handle DHCP received packets. |
*/ |
static void |
DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) |
static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) |
{ |
Bootp_t *bp = (Bootp_t *)pkt; |
Bootp_t *bp = (Bootp_t *) pkt; |
|
debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n", |
src, dest, len, dhcp_state); |
debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n", |
src, dest, len, dhcp_state); |
|
if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */ |
return; |
|
debug ("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n", |
src, dest, len, dhcp_state); |
debug |
("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n", |
src, dest, len, dhcp_state); |
|
switch (dhcp_state) { |
case SELECTING: |
797,17 → 811,17
* If filename is in format we recognize, assume it is a valid |
* OFFER from a server we want. |
*/ |
debug ("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file); |
debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file); |
#ifdef CFG_BOOTFILE_PREFIX |
if (strncmp(bp->bp_file, |
CFG_BOOTFILE_PREFIX, |
strlen(CFG_BOOTFILE_PREFIX)) == 0 ) { |
#endif /* CFG_BOOTFILE_PREFIX */ |
strlen(CFG_BOOTFILE_PREFIX)) == 0) { |
#endif /* CFG_BOOTFILE_PREFIX */ |
|
debug ("TRANSITIONING TO REQUESTING STATE\n"); |
debug("TRANSITIONING TO REQUESTING STATE\n"); |
dhcp_state = REQUESTING; |
#if 0 |
if ((*(uint *)bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
if ((*(uint *) bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
DhcpOptionsProcess(&bp->bp_vend[4]); |
|
#endif |
817,17 → 831,17
DhcpSendRequestPkt(bp); |
#ifdef CFG_BOOTFILE_PREFIX |
} |
#endif /* CFG_BOOTFILE_PREFIX */ |
#endif /* CFG_BOOTFILE_PREFIX */ |
|
return; |
break; |
case REQUESTING: |
debug ("DHCP State: REQUESTING\n"); |
debug("DHCP State: REQUESTING\n"); |
|
if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) { |
if (DhcpMessageType(bp->bp_vend) == DHCP_ACK) { |
char *s; |
|
if ((*(uint *)bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
if ((*(uint *) bp->bp_vend) == BOOTP_VENDOR_MAGIC) |
DhcpOptionsProcess(&bp->bp_vend[4]); |
BootpCopyNetParams(bp); /* Store net params from reply */ |
dhcp_state = BOUND; |
858,6 → 872,6
{ |
BootpRequest(); |
} |
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
|
#endif /* CFG_CMD_NET */ |
/orpmon/services/rarp.c
29,12 → 29,11
|
#if (CONFIG_COMMANDS & CFG_CMD_NET) |
|
#define TIMEOUT 5 /* Seconds before trying BOOTP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
#define TIMEOUT 5 /* Seconds before trying BOOTP again */ |
#define TIMEOUT_COUNT 1 /* # of timeouts before giving up */ |
|
int RarpTry; |
|
int RarpTry; |
|
/* |
* Handle a RARP received packet. |
*/ |
44,32 → 43,28
#ifdef DEBUG |
printf("Got good RARP\n"); |
#endif |
TftpStart (); |
TftpStart(); |
} |
|
|
/* |
* Timeout on BOOTP request. |
*/ |
static void |
RarpTimeout(void) |
static void RarpTimeout(void) |
{ |
if (RarpTry >= TIMEOUT_COUNT) { |
puts ("\nRetry count exceeded; starting again\n"); |
NetStartAgain (); |
puts("\nRetry count exceeded; starting again\n"); |
NetStartAgain(); |
} else { |
NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout); |
RarpRequest (); |
NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout); |
RarpRequest(); |
} |
} |
|
|
void |
RarpRequest (void) |
void RarpRequest(void) |
{ |
int i; |
volatile uchar *pkt; |
ARP_t * rarp; |
ARP_t *rarp; |
|
printf("RARP broadcast %d\n", ++RarpTry); |
pkt = NetTxPacket; |
77,16 → 72,16
NetSetEther(pkt, NetBcastAddr, PROT_RARP); |
pkt += ETHER_HDR_SIZE; |
|
rarp = (ARP_t *)pkt; |
rarp = (ARP_t *) pkt; |
|
rarp->ar_hrd = ARP_ETHER; |
rarp->ar_pro = PROT_IP; |
rarp->ar_hln = 6; |
rarp->ar_pln = 4; |
rarp->ar_op = RARPOP_REQUEST; |
rarp->ar_op = RARPOP_REQUEST; |
NetCopyEther(&rarp->ar_data[0], NetOurEther); /* source ET addr */ |
*(IPaddr_t *)(&rarp->ar_data[6]) = NetOurIP; /* source IP addr */ |
NetCopyEther(&rarp->ar_data[10], NetOurEther); /* dest ET addr = source ET addr ??*/ |
*(IPaddr_t *) (&rarp->ar_data[6]) = NetOurIP; /* source IP addr */ |
NetCopyEther(&rarp->ar_data[10], NetOurEther); /* dest ET addr = source ET addr ?? */ |
/* dest. IP addr set to broadcast */ |
for (i = 0; i <= 3; i++) { |
rarp->ar_data[16 + i] = 0xff; |
/orpmon/services/dos.c
19,7 → 19,6
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
*/ |
|
|
//#include "common.h" |
|
#include <stddef.h> |
27,70 → 26,67
#include "dos.h" |
#include "ata.h" |
|
|
/* |
D O S _ O P E N |
*/ |
int dos_open(struct dosparam *params) |
{ |
int error, start_sector, partition; |
unsigned char buf[512]; |
int error, start_sector, partition; |
unsigned char buf[512]; |
|
struct inode *inode = ¶ms->inode; |
struct file *filp = ¶ms->filp; |
struct request *request = ¶ms->request; |
struct inode *inode = ¶ms->inode; |
struct file *filp = ¶ms->filp; |
struct request *request = ¶ms->request; |
|
if( (error = ata_open(inode, filp)) ) |
return error; |
if ((error = ata_open(inode, filp))) |
return error; |
|
/* device opened, read MBR */ |
request->cmd = READ; |
request->sector = 0; |
request->nr_sectors = 1; |
request->buffer = buf; |
|
/* device opened, read MBR */ |
request->cmd = READ; |
request->sector = 0; |
request->nr_sectors = 1; |
request->buffer = buf; |
/* skip bootload (446) bytes */ |
/* currently only support the first partition (partition 4) */ |
/* This is OK, because CompactFLASH devices only have 1 partition */ |
if ((error = ata_request(inode, filp, request))) |
return error; |
|
/* skip bootload (446) bytes */ |
/* currently only support the first partition (partition 4) */ |
/* This is OK, because CompactFLASH devices only have 1 partition */ |
if ( (error = ata_request(inode, filp, request)) ) |
return error; |
partition = 0; /* first partition */ |
partition *= 16; /* 16 bytes per partition table */ |
partition += 446; /* skip bootloader, go to partition table */ |
start_sector = buf[partition + 11] << 24 | |
buf[partition + 10] << 16 | |
buf[partition + 9] << 8 | buf[partition + 8]; |
|
partition = 0; /* first partition */ |
partition *= 16; /* 16 bytes per partition table */ |
partition += 446; /* skip bootloader, go to partition table */ |
start_sector = buf[partition +11] << 24 | |
buf[partition +10] << 16 | |
buf[partition +9] << 8 | |
buf[partition +8]; |
/* device opened, read boot-sector */ |
request->cmd = READ; |
request->sector = start_sector; |
request->nr_sectors = 1; |
request->buffer = buf; |
|
/* device opened, read boot-sector */ |
request->cmd = READ; |
request->sector = start_sector; |
request->nr_sectors = 1; |
request->buffer = buf; |
if ((error = ata_request(inode, filp, request))) |
return error; |
|
if ( (error = ata_request(inode, filp, request)) ) |
return error; |
/* get the necessary data from the boot-sector */ |
params->bytes_per_sector = (buf[12] << 8) | buf[11]; |
params->fats = buf[16]; |
params->sectors_per_fat = (buf[23] << 8) | buf[22]; |
params->root_entries = (buf[18] << 8) | buf[17]; |
params->sectors_per_cluster = buf[13]; |
|
/* get the necessary data from the boot-sector */ |
params->bytes_per_sector = (buf[12]<<8) | buf[11]; |
params->fats = buf[16]; |
params->sectors_per_fat = (buf[23]<<8) | buf[22]; |
params->root_entries = (buf[18]<<8) | buf[17]; |
params->sectors_per_cluster = buf[13]; |
/* set start of current directory to start of root-directory */ |
params->ssector = |
start_sector + params->fats * params->sectors_per_fat + 1; |
|
/* set current sector to start of root-directory */ |
params->csector = params->ssector; |
|
/* set start of current directory to start of root-directory */ |
params->ssector = start_sector + params->fats * params->sectors_per_fat +1; |
/* set start-entry number */ |
params->sentry = 0; |
|
/* set current sector to start of root-directory */ |
params->csector = params->ssector; |
|
/* set start-entry number */ |
params->sentry = 0; |
|
return 0; |
return 0; |
} |
|
/* |
98,7 → 94,7
*/ |
int dos_release(struct dosparam *params) |
{ |
return 0; |
return 0; |
} |
|
/* |
106,126 → 102,124
*/ |
int dos_namecmp(const char *sname, const char *name, const char *ext) |
{ |
char fname[9], fext[4], *p; |
char fname[9], fext[4], *p; |
|
/* filename : */ |
/* copy the filename */ |
strncpy(fname, sname, 8); |
/* filename : */ |
/* copy the filename */ |
strncpy(fname, sname, 8); |
|
/* check if we copied the '.' already, if so terminate string */ |
if ( (p = strchr(fname, '.')) ) |
*p = '\0'; |
/* check if we copied the '.' already, if so terminate string */ |
if ((p = strchr(fname, '.'))) |
*p = '\0'; |
|
/* fill remaining chars with ' ' */ |
strncat(fname, " ", 8-strlen(fname) ); |
/* fill remaining chars with ' ' */ |
strncat(fname, " ", 8 - strlen(fname)); |
|
fname[9] = '\0'; |
fname[9] = '\0'; |
|
/* file-extension */ |
/* search for the '.' in the filename */ |
if ( (p = strchr(sname, '.')) ) |
strncpy(fext, p, 3); |
else |
fext[0] = fext[1] = fext[2] = ' '; |
/* file-extension */ |
/* search for the '.' in the filename */ |
if ((p = strchr(sname, '.'))) |
strncpy(fext, p, 3); |
else |
fext[0] = fext[1] = fext[2] = ' '; |
|
fext[4] = '\0'; |
fext[4] = '\0'; |
|
return ( strcmp(fname, name) && strcmp(fext, ext) ); |
return (strcmp(fname, name) && strcmp(fext, ext)); |
} |
|
|
/* |
D O S _ D I R _ F I N D _ E N T R Y |
*/ |
struct dos_dir_entry *dos_dir_find_entry(struct dosparam *params, const char *name) |
struct dos_dir_entry *dos_dir_find_entry(struct dosparam *params, |
const char *name) |
{ |
struct dos_dir_entry *entry; |
unsigned long entry_no = 0; |
struct dos_dir_entry *entry; |
unsigned long entry_no = 0; |
|
/* go to start of current directory */ |
if (params->csector != params->ssector) |
dos_dir_cluster_reset(params); |
/* go to start of current directory */ |
if (params->csector != params->ssector) |
dos_dir_cluster_reset(params); |
|
/* search for the requested entry */ |
while ( (entry = dos_dir_get_entry(params, entry_no)) && dos_namecmp(name, entry->name, entry->ext) ) |
entry_no++; |
/* search for the requested entry */ |
while ((entry = dos_dir_get_entry(params, entry_no)) |
&& dos_namecmp(name, entry->name, entry->ext)) |
entry_no++; |
|
return entry; |
return entry; |
} |
|
|
/* |
D O S _ D I R _ G E T _ E N T R Y |
*/ |
struct dos_dir_entry *dos_dir_get_entry(struct dosparam *params, unsigned long entry) |
struct dos_dir_entry *dos_dir_get_entry(struct dosparam *params, |
unsigned long entry) |
{ |
char *buf = params->cbuf; |
char *buf = params->cbuf; |
|
if (entry < params->sentry) |
buf = dos_dir_cluster_reset(params); |
if (entry < params->sentry) |
buf = dos_dir_cluster_reset(params); |
|
while ( entry >= (params->sentry + entries_per_cluster(params)) ) |
if ( !(buf = dos_dir_cluster_read_nxt(params)) ) |
return NULL; |
while (entry >= (params->sentry + entries_per_cluster(params))) |
if (!(buf = dos_dir_cluster_read_nxt(params))) |
return NULL; |
|
return (struct dos_dir_entry*)(buf + ( (entry - params->sentry) * sizeof(struct dos_dir_entry)) ); |
return (struct dos_dir_entry *)(buf + |
((entry - |
params->sentry) * |
sizeof(struct dos_dir_entry))); |
} |
|
|
/* |
D O S _ R E A D _ C L U S T E R |
*/ |
char *dos_read_cluster(struct dosparam *params, unsigned long ssector) |
{ |
int error; |
int error; |
|
struct inode *inode = ¶ms->inode; |
struct file *filp = ¶ms->filp; |
struct request *request = ¶ms->request; |
struct inode *inode = ¶ms->inode; |
struct file *filp = ¶ms->filp; |
struct request *request = ¶ms->request; |
|
request->cmd = READ; |
request->sector = ssector; |
request->nr_sectors = params->sectors_per_cluster; |
request->buffer = params->cbuf; |
request->cmd = READ; |
request->sector = ssector; |
request->nr_sectors = params->sectors_per_cluster; |
request->buffer = params->cbuf; |
|
if ( (error = ata_request(inode, filp, request)) ) |
return NULL; |
if ((error = ata_request(inode, filp, request))) |
return NULL; |
|
params->csector = ssector; |
params->csector = ssector; |
|
return params->cbuf; |
return params->cbuf; |
} |
|
|
/* |
D O S _ D I R _ C L U S T E R _ R E A D _ N X T |
*/ |
char *dos_dir_cluster_read_nxt(struct dosparam *params) |
{ |
char *p; |
unsigned long nxt_cluster_start; |
char *p; |
unsigned long nxt_cluster_start; |
|
/* TODO: add FAT lookup */ |
/* TODO: add FAT lookup */ |
|
nxt_cluster_start = params->csector + params->sectors_per_cluster; |
nxt_cluster_start = params->csector + params->sectors_per_cluster; |
|
if ( !(p = dos_read_cluster(params, nxt_cluster_start)) ) |
return NULL; |
if (!(p = dos_read_cluster(params, nxt_cluster_start))) |
return NULL; |
|
params->sentry += entries_per_cluster(params); |
|
params->sentry += entries_per_cluster(params); |
|
return p; |
return p; |
} |
|
|
/* |
D O S _ D I R _ C L U S T E R _ R E S E T |
*/ |
char *dos_dir_cluster_reset(struct dosparam *params) |
{ |
params->sentry = 0; |
return dos_read_cluster(params, params->ssector); |
params->sentry = 0; |
return dos_read_cluster(params, params->ssector); |
} |
|
|
/orpmon/services/net.c
57,7 → 57,6
* Next step: none |
*/ |
|
|
#include "common.h" |
#include "support.h" |
#include "net.h" |
67,7 → 66,7
#include "arp.h" |
#if OC_LAN==1 |
#include "eth.h" |
#else |
#else |
# if SMC91111_LAN==1 |
# include "smc91111.h" |
# endif |
79,202 → 78,203
|
/** BOOTP EXTENTIONS **/ |
|
IPaddr_t NetOurSubnetMask=0; /* Our subnet mask (0=unknown) */ |
IPaddr_t NetOurGatewayIP=0; /* Our gateways IP address */ |
IPaddr_t NetOurDNSIP=0; /* Our DNS IP address */ |
char NetOurNISDomain[32]={0,}; /* Our NIS domain */ |
char NetOurHostName[32]={0,}; /* Our hostname */ |
char NetOurRootPath[64]={0,}; /* Our bootpath */ |
unsigned short NetBootFileSize=0; /* Our bootfile size in blocks */ |
IPaddr_t NetOurSubnetMask = 0; /* Our subnet mask (0=unknown) */ |
IPaddr_t NetOurGatewayIP = 0; /* Our gateways IP address */ |
IPaddr_t NetOurDNSIP = 0; /* Our DNS IP address */ |
char NetOurNISDomain[32] = { 0, }; /* Our NIS domain */ |
char NetOurHostName[32] = { 0, }; /* Our hostname */ |
char NetOurRootPath[64] = { 0, }; /* Our bootpath */ |
|
unsigned short NetBootFileSize = 0; /* Our bootfile size in blocks */ |
|
/** END OF BOOTP EXTENTIONS **/ |
|
unsigned long NetBootFileXferSize; /* The actual transferred size of the bootfile (in bytes) */ |
unsigned char NetOurEther[6]; /* Our ethernet address */ |
unsigned char NetServerEther[6] = /* Boot server enet address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */ |
IPaddr_t NetServerIP; /* Our IP addr (0 = unknown) */ |
volatile unsigned char *NetRxPkt; /* Current receive packet */ |
int NetRxPktLen; /* Current rx packet length */ |
unsigned NetIPID; /* IP packet ID */ |
unsigned char NetBcastAddr[6] = /* Ethernet bcast address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
int NetState; /* Network loop state */ |
unsigned long NetBootFileXferSize; /* The actual transferred size |
of the bootfile (in bytes) */ |
unsigned char NetOurEther[6]; /* Our ethernet address */ |
unsigned char NetServerEther[6] = /* Boot server enet address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
|
char BootFile[128]; /* Boot File name */ |
IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */ |
IPaddr_t NetServerIP; /* Our IP addr (0 = unknown) */ |
volatile unsigned char *NetRxPkt; /* Current receive packet */ |
int NetRxPktLen; /* Current rx packet length */ |
unsigned NetIPID; /* IP packet ID */ |
unsigned char NetBcastAddr[6] = /* Ethernet bcast address */ |
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
|
volatile unsigned char PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN]; |
int NetState; /* Network loop state */ |
|
volatile unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets */ |
char BootFile[128]; /* Boot File name */ |
|
static rxhand_f *packetHandler; /* Current RX packet handler */ |
static thand_f *timeHandler; /* Current timeout handler */ |
static unsigned long timeValue; /* Current timeout value */ |
volatile unsigned char *NetTxPacket = 0; /* THE transmit packet */ |
volatile unsigned char PktBuf[(PKTBUFSRX + 1) * PKTSIZE_ALIGN + PKTALIGN]; |
|
static int net_check_prereq (proto_t protocol); |
volatile unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets*/ |
|
static rxhand_f *packetHandler; /* Current RX packet handler */ |
static thand_f *timeHandler; /* Current timeout handler */ |
static unsigned long timeValue; /* Current timeout value */ |
volatile unsigned char *NetTxPacket = 0; /* THE transmit packet */ |
|
static int net_check_prereq(proto_t protocol); |
|
/**********************************************************************/ |
/* |
* Main network processing loop. |
*/ |
int |
NetLoop(proto_t protocol) |
int NetLoop(proto_t protocol) |
{ |
|
if (!NetTxPacket) { |
int i; |
printf("NetTxPacket begin setup\n"); |
/* |
* Setup packet buffers, aligned correctly. |
*/ |
NetTxPacket = &PktBuf[0] + (PKTALIGN - 1); |
NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN; |
for (i = 0; i < PKTBUFSRX; i++) { |
NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN; |
} |
} |
if (!NetTxPacket) { |
int i; |
printf("NetTxPacket begin setup\n"); |
/* |
* Setup packet buffers, aligned correctly. |
*/ |
NetTxPacket = &PktBuf[0] + (PKTALIGN - 1); |
NetTxPacket -= (unsigned long)NetTxPacket % PKTALIGN; |
for (i = 0; i < PKTBUFSRX; i++) { |
NetRxPackets[i] = NetTxPacket + (i + 1) * PKTSIZE_ALIGN; |
} |
} |
|
eth_halt(); |
eth_init(NetReceive); |
eth_halt(); |
eth_init(NetReceive); |
|
restart: |
restart: |
|
NetCopyEther(NetOurEther, global.eth_add); |
NetCopyEther(NetOurEther, global.eth_add); |
|
NetState = NETLOOP_CONTINUE; |
NetState = NETLOOP_CONTINUE; |
|
/* |
* Start the ball rolling with the given start function. From |
* here on, this code is a state machine driven by received |
* packets and timer events. |
*/ |
/* |
* Start the ball rolling with the given start function. From |
* here on, this code is a state machine driven by received |
* packets and timer events. |
*/ |
|
if (protocol == TFTP) { /* TFTP */ |
NetOurIP = global.ip; |
NetServerIP = global.srv_ip; |
NetOurGatewayIP = global.gw_ip; |
NetOurSubnetMask= global.mask; |
if (protocol == TFTP) { /* TFTP */ |
NetOurIP = global.ip; |
NetServerIP = global.srv_ip; |
NetOurGatewayIP = global.gw_ip; |
NetOurSubnetMask = global.mask; |
|
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
if (net_check_prereq(protocol) != 0) { |
return 0; |
} |
|
/* always use ARP to get server ethernet address */ |
ArpTry = 0; |
/* always use ARP to get server ethernet address */ |
ArpTry = 0; |
|
ArpRequest (); |
ArpRequest(); |
|
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
} else if (protocol == DHCP) { |
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
} else if (protocol == DHCP) { |
if (net_check_prereq(protocol) != 0) { |
return 0; |
} |
|
/* Start with a clean slate... */ |
NetOurIP = 0; |
NetServerIP = 0; |
DhcpRequest(); /* Basically same as BOOTP */ |
/* Start with a clean slate... */ |
NetOurIP = 0; |
NetServerIP = 0; |
DhcpRequest(); /* Basically same as BOOTP */ |
|
#endif /* CFG_CMD_DHCP */ |
#endif /* CFG_CMD_DHCP */ |
|
} else { /* BOOTP or RARP */ |
} else { /* BOOTP or RARP */ |
|
/* |
* initialize our IP addr to 0 in order to accept ANY |
* IP addr assigned to us by the BOOTP / RARP server |
*/ |
NetOurIP = 0; |
NetServerIP = 0; |
/* |
* initialize our IP addr to 0 in order to accept ANY |
* IP addr assigned to us by the BOOTP / RARP server |
*/ |
NetOurIP = 0; |
NetServerIP = 0; |
|
if (net_check_prereq (protocol) != 0) { |
return 0; |
} |
if (net_check_prereq(protocol) != 0) { |
return 0; |
} |
#ifdef BOOTP |
if (protocol == BOOTP) { |
BootpTry = 0; |
BootpRequest (); |
} |
if (protocol == BOOTP) { |
BootpTry = 0; |
BootpRequest(); |
} |
#endif |
#ifdef RARP |
if { |
RarpTry = 0; |
RarpRequest (); |
} |
if { |
RarpTry |
= 0; |
RarpRequest(); |
} |
#endif |
} |
} |
|
NetBootFileXferSize = 0; |
NetBootFileXferSize = 0; |
|
/* |
* Main packet reception loop. Loop receiving packets until |
* someone sets `NetQuit'. |
*/ |
for (;;) { |
// WATCHDOG_RESET(); |
/* |
* Check the ethernet for a new packet. The ethernet |
* receive routine will process it. |
*/ |
eth_rx(); |
/* |
* Main packet reception loop. Loop receiving packets until |
* someone sets `NetQuit'. |
*/ |
for (;;) { |
// WATCHDOG_RESET(); |
/* |
* Check the ethernet for a new packet. The ethernet |
* receive routine will process it. |
*/ |
eth_rx(); |
|
/* |
* Abort if ctrl-c was pressed. |
*/ |
if (ctrlc()) { |
eth_halt(); |
printf("\nAbort\n"); |
return 0; |
} |
/* |
* Abort if ctrl-c was pressed. |
*/ |
if (ctrlc()) { |
eth_halt(); |
printf("\nAbort\n"); |
return 0; |
} |
|
/* |
* Check for a timeout, and run the timeout handler |
* if we have one. |
*/ |
/* |
if (timeHandler && (get_timer(0) > timeValue)) { |
thand_f *x; |
|
/* |
* Check for a timeout, and run the timeout handler |
* if we have one. |
*/ |
/* |
if (timeHandler && (get_timer(0) > timeValue)) { |
thand_f *x; |
x = timeHandler; |
timeHandler = (thand_f *)0; |
(*x)(); |
} |
*/ |
|
x = timeHandler; |
timeHandler = (thand_f *)0; |
(*x)(); |
} |
*/ |
|
switch (NetState) { |
switch (NetState) { |
|
case NETLOOP_RESTART: |
goto restart; |
case NETLOOP_RESTART: |
goto restart; |
|
case NETLOOP_SUCCESS: |
if (NetBootFileXferSize > 0) { |
printf("Bytes transferred = %ld (0x%lx)\n", |
NetBootFileXferSize, |
NetBootFileXferSize); |
case NETLOOP_SUCCESS: |
if (NetBootFileXferSize > 0) { |
printf("Bytes transferred = %ld (0x%lx)\n", |
NetBootFileXferSize, |
NetBootFileXferSize); |
#ifdef TFTP_CALC_CHKSUM |
printf("CHKSUM: 0x%lx\n", TFTP_CHKSUM); |
printf("CHKSUM: 0x%lx\n", TFTP_CHKSUM); |
#endif |
} |
eth_halt(); |
return NetBootFileXferSize; |
} |
eth_halt(); |
return NetBootFileXferSize; |
|
case NETLOOP_FAIL: |
return 0; |
} |
} |
case NETLOOP_FAIL: |
return 0; |
} |
} |
|
} |
|
/**********************************************************************/ |
|
|
#if 1 |
void |
NetStartAgain(void) |
void NetStartAgain(void) |
{ |
NetState = NETLOOP_RESTART; |
NetState = NETLOOP_RESTART; |
} |
|
/**********************************************************************/ |
282,446 → 282,448
* Miscelaneous bits. |
*/ |
|
void |
NetSetHandler(rxhand_f * f) |
void NetSetHandler(rxhand_f * f) |
{ |
packetHandler = f; |
packetHandler = f; |
} |
|
|
void |
NetSetTimeout(int iv, thand_f * f) |
void NetSetTimeout(int iv, thand_f * f) |
{ |
if (iv == 0) { |
timeHandler = (thand_f *)0; |
} else { |
timeHandler = f; |
timeValue = get_timer(0) + iv; |
} |
if (iv == 0) { |
timeHandler = (thand_f *) 0; |
} else { |
timeHandler = f; |
timeValue = get_timer(0) + iv; |
} |
} |
|
|
void |
NetSendPacket(volatile unsigned char * pkt, int len) |
void NetSendPacket(volatile unsigned char *pkt, int len) |
{ |
|
#if OC_LAN==1 |
unsigned char *p = (unsigned char *)0; |
while (p == (unsigned char*) 0) |
p = eth_get_tx_buf(); |
|
memcpy(p, (void *)pkt, len); |
eth_send(p, len); |
unsigned char *p = (unsigned char *)0; |
while (p == (unsigned char *)0) |
p = eth_get_tx_buf(); |
|
memcpy(p, (void *)pkt, len); |
eth_send(p, len); |
#else |
# if SMC91111_LAN==1 |
eth_send(pkt, len); |
eth_send(pkt, len); |
# endif |
#endif |
} |
|
|
|
void |
NetReceive(volatile unsigned char * pkt, int len) |
void NetReceive(volatile unsigned char *pkt, int len) |
{ |
Ethernet_t *et; |
IP_t *ip; |
ARP_t *arp; |
int x; |
IPaddr_t ip_to_check; // Used as a temp variable to check IP |
Ethernet_t *et; |
IP_t *ip; |
ARP_t *arp; |
int x; |
IPaddr_t ip_to_check; // Used as a temp variable to check IP |
|
NetRxPkt = pkt; |
NetRxPktLen = len; |
et = (Ethernet_t *)pkt; |
NetRxPkt = pkt; |
NetRxPktLen = len; |
et = (Ethernet_t *) pkt; |
|
x = SWAP16(et->et_protlen); |
x = SWAP16(et->et_protlen); |
|
if (x < 1514) { |
/* |
* Got a 802 packet. Check the other protocol field. |
*/ |
x = SWAP16(et->et_prot); |
ip = (IP_t *)(pkt + E802_HDR_SIZE); |
len -= E802_HDR_SIZE; |
} else { |
ip = (IP_t *)(pkt + ETHER_HDR_SIZE); |
len -= ETHER_HDR_SIZE; |
} |
if (x < 1514) { |
/* |
* Got a 802 packet. Check the other protocol field. |
*/ |
x = SWAP16(et->et_prot); |
ip = (IP_t *) (pkt + E802_HDR_SIZE); |
len -= E802_HDR_SIZE; |
} else { |
ip = (IP_t *) (pkt + ETHER_HDR_SIZE); |
len -= ETHER_HDR_SIZE; |
} |
|
#ifdef ET_DEBUG |
printf("Receive from protocol 0x%x\n", x); |
printf("Receive from protocol 0x%x\n", x); |
#endif |
|
switch (x) { |
switch (x) { |
|
case PROT_ARP: |
/* |
* We have to deal with two types of ARP packets: |
* - REQUEST packets will be answered by sending our |
* IP address - if we know it. |
* - REPLY packates are expected only after we asked |
* for the TFTP server's or the gateway's ethernet |
* address; so if we receive such a packet, we set |
* the server ethernet address |
*/ |
case PROT_ARP: |
/* |
* We have to deal with two types of ARP packets: |
* - REQUEST packets will be answered by sending our |
* IP address - if we know it. |
* - REPLY packates are expected only after we asked |
* for the TFTP server's or the gateway's ethernet |
* address; so if we receive such a packet, we set |
* the server ethernet address |
*/ |
#ifdef ET_DEBUG |
printf("Got ARP\n"); |
printf("Got ARP\n"); |
#endif |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
if (SWAP16(arp->ar_hrd) != ARP_ETHER) { |
return; |
} |
if (SWAP16(arp->ar_pro) != PROT_IP) { |
return; |
} |
if (arp->ar_hln != 6) { |
return; |
} |
if (arp->ar_pln != 4) { |
return; |
} |
|
memcpy((void*) &ip_to_check, (void*)&arp->ar_data[16], |
sizeof(IPaddr_t)); |
if (NetOurIP == 0 || |
ip_to_check != NetOurIP) { |
return; |
} |
arp = (ARP_t *) ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
if (SWAP16(arp->ar_hrd) != ARP_ETHER) { |
return; |
} |
if (SWAP16(arp->ar_pro) != PROT_IP) { |
return; |
} |
if (arp->ar_hln != 6) { |
return; |
} |
if (arp->ar_pln != 4) { |
return; |
} |
|
switch (SWAP16(arp->ar_op)) { |
case ARPOP_REQUEST: /* reply with our IP address */ |
memcpy((void *)&ip_to_check, (void *)&arp->ar_data[16], |
sizeof(IPaddr_t)); |
if (NetOurIP == 0 || ip_to_check != NetOurIP) { |
return; |
} |
|
switch (SWAP16(arp->ar_op)) { |
case ARPOP_REQUEST: /* reply with our IP address */ |
#ifdef ET_DEBUG |
printf("Got ARP REQUEST, return our IP\n"); |
printf("Got ARP REQUEST, return our IP\n"); |
#endif |
NetSetEther((unsigned char *)et, et->et_src, PROT_ARP); |
arp->ar_op = SWAP16(ARPOP_REPLY); |
NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]); |
NetCopyEther(&arp->ar_data[0], NetOurEther); |
//*(IPaddr_t *)(&arp->ar_data[16]) = *(IPaddr_t *)(&arp->ar_data[6]); |
memcpy((void*)&arp->ar_data[16],(void*) &arp->ar_data[6], |
sizeof(IPaddr_t)); |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; |
memcpy((void*)&arp->ar_data[6],(void*) &NetOurIP, |
sizeof(IPaddr_t)); |
|
NetSendPacket((unsigned char *)et, |
((unsigned char *)arp-pkt)+ARP_HDR_SIZE); |
return; |
case ARPOP_REPLY: /* set TFTP server eth addr */ |
NetSetEther((unsigned char *)et, et->et_src, PROT_ARP); |
arp->ar_op = SWAP16(ARPOP_REPLY); |
NetCopyEther(&arp->ar_data[10], &arp->ar_data[0]); |
NetCopyEther(&arp->ar_data[0], NetOurEther); |
//*(IPaddr_t *)(&arp->ar_data[16]) = *(IPaddr_t *)(&arp->ar_data[6]); |
memcpy((void *)&arp->ar_data[16], |
(void *)&arp->ar_data[6], sizeof(IPaddr_t)); |
//*(IPaddr_t *)(&arp->ar_data[6]) = NetOurIP; |
memcpy((void *)&arp->ar_data[6], (void *)&NetOurIP, |
sizeof(IPaddr_t)); |
|
NetSendPacket((unsigned char *)et, |
((unsigned char *)arp - pkt) + |
ARP_HDR_SIZE); |
return; |
case ARPOP_REPLY: /* set TFTP server eth addr */ |
#ifdef ET_DEBUG |
printf("Got ARP REPLY, set server/gtwy eth addr\n"); |
printf("Got ARP REPLY, set server/gtwy eth addr\n"); |
#endif |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
(*packetHandler)(0,0,0,0); /* start TFTP */ |
return; |
default: |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
(*packetHandler) (0, 0, 0, 0); /* start TFTP */ |
return; |
default: |
#ifdef ET_DEBUG |
printf("Unexpected ARP opcode 0x%x\n", SWAP16(arp->ar_op)); |
printf("Unexpected ARP opcode 0x%x\n", |
SWAP16(arp->ar_op)); |
#endif |
return; |
} |
return; |
} |
|
case PROT_RARP: |
case PROT_RARP: |
#ifdef ET_DEBUG |
printf("Got RARP\n"); |
printf("Got RARP\n"); |
#endif |
arp = (ARP_t *)ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
arp = (ARP_t *) ip; |
if (len < ARP_HDR_SIZE) { |
printf("bad length %d < %d\n", len, ARP_HDR_SIZE); |
return; |
} |
|
if ((SWAP16(arp->ar_op) != RARPOP_REPLY) || |
(SWAP16(arp->ar_hrd) != ARP_ETHER) || |
(SWAP16(arp->ar_pro) != PROT_IP) || |
(arp->ar_hln != 6) || (arp->ar_pln != 4)) { |
if ((SWAP16(arp->ar_op) != RARPOP_REPLY) || |
(SWAP16(arp->ar_hrd) != ARP_ETHER) || |
(SWAP16(arp->ar_pro) != PROT_IP) || |
(arp->ar_hln != 6) || (arp->ar_pln != 4)) { |
|
printf("invalid RARP header\n"); |
} else { |
//NetOurIP = *((IPaddr_t *)&arp->ar_data[16]); |
memcpy((void*) &NetOurIP, (void*) &arp->ar_data[16], |
sizeof(IPaddr_t)); |
//NetServerIP = *((IPaddr_t *)&arp->ar_data[6]); |
memcpy((void*) &NetServerIP,(void*) &arp->ar_data[6], |
sizeof(IPaddr_t)); |
printf("invalid RARP header\n"); |
} else { |
//NetOurIP = *((IPaddr_t *)&arp->ar_data[16]); |
memcpy((void *)&NetOurIP, (void *)&arp->ar_data[16], |
sizeof(IPaddr_t)); |
//NetServerIP = *((IPaddr_t *)&arp->ar_data[6]); |
memcpy((void *)&NetServerIP, (void *)&arp->ar_data[6], |
sizeof(IPaddr_t)); |
|
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
NetCopyEther(NetServerEther, &arp->ar_data[0]); |
|
(*packetHandler)(0,0,0,0); |
} |
break; |
(*packetHandler) (0, 0, 0, 0); |
} |
break; |
|
case PROT_IP: |
case PROT_IP: |
#ifdef ET_DEBUG |
printf("Got IP\n"); |
printf("Got IP\n"); |
#endif |
if (len < IP_HDR_SIZE) { |
debug ("ip header len bad %d < %d\n", len, IP_HDR_SIZE); |
return; |
} |
if (len < SWAP16(ip->ip_len)) { |
printf("ip header (swap) len bad %d < %d\n", len, SWAP16(ip->ip_len)); |
return; |
} |
len = SWAP16(ip->ip_len); |
if (len < IP_HDR_SIZE) { |
debug("ip header len bad %d < %d\n", len, IP_HDR_SIZE); |
return; |
} |
if (len < SWAP16(ip->ip_len)) { |
printf("ip header (swap) len bad %d < %d\n", len, |
SWAP16(ip->ip_len)); |
return; |
} |
len = SWAP16(ip->ip_len); |
#ifdef ET_DEBUG |
printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff); |
printf("len=%d, v=%02x\n", len, ip->ip_hl_v & 0xff); |
#endif |
if ((ip->ip_hl_v & 0xf0) != 0x40) { |
return; |
} |
if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */ |
return; |
} |
if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) { |
//printf("checksum bad\n"); |
return; |
} |
if ((ip->ip_hl_v & 0xf0) != 0x40) { |
return; |
} |
if (ip->ip_off & SWAP16c(0x1fff)) { /* Can't deal w/ fragments */ |
return; |
} |
if (!NetCksumOk((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2)) { |
//printf("checksum bad\n"); |
return; |
} |
|
memcpy((void*)&ip_to_check,(void*)&ip->ip_dst, sizeof (IPaddr_t)); |
memcpy((void *)&ip_to_check, (void *)&ip->ip_dst, |
sizeof(IPaddr_t)); |
|
if (NetOurIP && |
ip_to_check != NetOurIP && |
ip_to_check != 0xFFFFFFFF) { |
return; |
} |
/* |
* watch for ICMP host redirects |
* |
* There is no real handler code (yet). We just watch |
* for ICMP host redirect messages. In case anybody |
* sees these messages: please contact me |
* (wd@denx.de), or - even better - send me the |
* necessary fixes :-) |
* |
* Note: in all cases where I have seen this so far |
* it was a problem with the router configuration, |
* for instance when a router was configured in the |
* BOOTP reply, but the TFTP server was on the same |
* subnet. So this is probably a warning that your |
* configuration might be wrong. But I'm not really |
* sure if there aren't any other situations. |
*/ |
if (ip->ip_p == IPPROTO_ICMP) { |
ICMP_t *icmph = (ICMP_t *)&(ip->udp_src); |
if (NetOurIP && |
ip_to_check != NetOurIP && ip_to_check != 0xFFFFFFFF) { |
return; |
} |
/* |
* watch for ICMP host redirects |
* |
* There is no real handler code (yet). We just watch |
* for ICMP host redirect messages. In case anybody |
* sees these messages: please contact me |
* (wd@denx.de), or - even better - send me the |
* necessary fixes :-) |
* |
* Note: in all cases where I have seen this so far |
* it was a problem with the router configuration, |
* for instance when a router was configured in the |
* BOOTP reply, but the TFTP server was on the same |
* subnet. So this is probably a warning that your |
* configuration might be wrong. But I'm not really |
* sure if there aren't any other situations. |
*/ |
if (ip->ip_p == IPPROTO_ICMP) { |
ICMP_t *icmph = (ICMP_t *) & (ip->udp_src); |
|
if (icmph->type != ICMP_REDIRECT) |
return; |
if (icmph->code != ICMP_REDIR_HOST) |
return; |
printf (" ICMP Host Redirect to "); |
print_IPaddr(icmph->un.gateway); |
putc(' '); |
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */ |
return; |
} |
if (icmph->type != ICMP_REDIRECT) |
return; |
if (icmph->code != ICMP_REDIR_HOST) |
return; |
printf(" ICMP Host Redirect to "); |
print_IPaddr(icmph->un.gateway); |
putc(' '); |
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */ |
return; |
} |
|
/* |
* IP header OK. Pass the packet to the current handler. |
*/ |
(*packetHandler)((unsigned char *)ip +IP_HDR_SIZE, |
SWAP16(ip->udp_dst), |
SWAP16(ip->udp_src), |
SWAP16(ip->udp_len) - 8); |
/* |
* IP header OK. Pass the packet to the current handler. |
*/ |
(*packetHandler) ((unsigned char *)ip + IP_HDR_SIZE, |
SWAP16(ip->udp_dst), |
SWAP16(ip->udp_src), SWAP16(ip->udp_len) - 8); |
|
break; |
} |
break; |
} |
} |
|
|
/**********************************************************************/ |
|
static int net_check_prereq (proto_t protocol) |
static int net_check_prereq(proto_t protocol) |
{ |
switch (protocol) { |
case ARP: /* nothing to do */ |
break; |
switch (protocol) { |
case ARP: /* nothing to do */ |
break; |
|
case TFTP: |
if (NetServerIP == 0) { |
printf ("*** ERROR: `serverip' not set\n"); |
return (1); |
} |
case TFTP: |
if (NetServerIP == 0) { |
printf("*** ERROR: `serverip' not set\n"); |
return (1); |
} |
|
if (NetOurIP == 0) { |
printf ("*** ERROR: `ipaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
if (NetOurIP == 0) { |
printf("*** ERROR: `ipaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
|
case DHCP: |
case RARP: |
case BOOTP: |
if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) { |
printf ("*** ERROR: `ethaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
} |
return (0); /* OK */ |
case DHCP: |
case RARP: |
case BOOTP: |
if (memcmp(NetOurEther, "\0\0\0\0\0\0", 6) == 0) { |
printf("*** ERROR: `ethaddr' not set\n"); |
return (1); |
} |
/* Fall through */ |
} |
return (0); /* OK */ |
} |
|
/**********************************************************************/ |
|
int |
NetCksumOk(unsigned char * ptr, int len) |
int NetCksumOk(unsigned char *ptr, int len) |
{ |
return !((NetCksum(ptr, len) + 1) & 0xfffe); |
return !((NetCksum(ptr, len) + 1) & 0xfffe); |
} |
|
|
unsigned |
NetCksum(unsigned char * ptr, int len) |
unsigned NetCksum(unsigned char *ptr, int len) |
{ |
unsigned long xsum; |
unsigned long xsum; |
|
xsum = 0; |
while (len-- > 0) |
{ |
xsum += (*((unsigned short *)ptr)); |
ptr += sizeof(short); |
} |
|
xsum = (xsum & 0xffff) + (xsum >> 16); |
xsum = (xsum & 0xffff) + (xsum >> 16); |
return (xsum & 0xffff); |
xsum = 0; |
while (len-- > 0) { |
xsum += (*((unsigned short *)ptr)); |
ptr += sizeof(short); |
} |
|
xsum = (xsum & 0xffff) + (xsum >> 16); |
xsum = (xsum & 0xffff) + (xsum >> 16); |
return (xsum & 0xffff); |
} |
|
|
void |
NetCopyEther(volatile unsigned char * to, unsigned char * from) |
void NetCopyEther(volatile unsigned char *to, unsigned char *from) |
{ |
int i; |
int i; |
|
for (i = 0; i < 6; i++) |
*to++ = *from++; |
for (i = 0; i < 6; i++) |
*to++ = *from++; |
} |
|
|
void |
NetSetEther(volatile unsigned char * xet, unsigned char * addr, unsigned long prot) |
NetSetEther(volatile unsigned char *xet, unsigned char *addr, |
unsigned long prot) |
{ |
volatile Ethernet_t *et = (Ethernet_t *)xet; |
volatile Ethernet_t *et = (Ethernet_t *) xet; |
|
NetCopyEther(et->et_dest, addr); |
NetCopyEther(et->et_src, NetOurEther); |
et->et_protlen = SWAP16(prot); |
NetCopyEther(et->et_dest, addr); |
NetCopyEther(et->et_src, NetOurEther); |
et->et_protlen = SWAP16(prot); |
} |
|
|
void |
NetSetIP(volatile unsigned char * xip, IPaddr_t dest, int dport, int sport, int len) |
NetSetIP(volatile unsigned char *xip, IPaddr_t dest, int dport, int sport, |
int len) |
{ |
volatile IP_t *ip = (IP_t *)xip; |
volatile IP_t *ip = (IP_t *) xip; |
|
/* |
* If the data is an odd number of bytes, zero the |
* byte after the last byte so that the checksum |
* will work. |
*/ |
if (len & 1) |
xip[IP_HDR_SIZE + len] = 0; |
/* |
* If the data is an odd number of bytes, zero the |
* byte after the last byte so that the checksum |
* will work. |
*/ |
if (len & 1) |
xip[IP_HDR_SIZE + len] = 0; |
|
/* |
* Construct an IP and UDP header. |
(need to set no fragment bit - XXX) |
*/ |
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ |
ip->ip_tos = 0; |
ip->ip_len = SWAP16(IP_HDR_SIZE + len); |
ip->ip_id = SWAP16(NetIPID++); |
ip->ip_off = SWAP16c(0x4000); /* No fragmentation */ |
ip->ip_ttl = 255; |
ip->ip_p = 17; /* UDP */ |
ip->ip_sum = 0; |
//ip->ip_src = NetOurIP; |
memcpy((void*)&ip->ip_src,(void*) &NetOurIP, |
sizeof(IPaddr_t)); |
//ip->ip_dst = dest; |
memcpy((void*)&ip->ip_dst,(void*) &dest, |
sizeof(IPaddr_t)); |
ip->udp_src = SWAP16(sport); |
ip->udp_dst = SWAP16(dport); |
ip->udp_len = SWAP16(8 + len); |
ip->udp_xsum = 0; |
ip->ip_sum = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2); |
/* |
* Construct an IP and UDP header. |
(need to set no fragment bit - XXX) |
*/ |
ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ |
ip->ip_tos = 0; |
ip->ip_len = SWAP16(IP_HDR_SIZE + len); |
ip->ip_id = SWAP16(NetIPID++); |
ip->ip_off = SWAP16c(0x4000); /* No fragmentation */ |
ip->ip_ttl = 255; |
ip->ip_p = 17; /* UDP */ |
ip->ip_sum = 0; |
//ip->ip_src = NetOurIP; |
memcpy((void *)&ip->ip_src, (void *)&NetOurIP, sizeof(IPaddr_t)); |
//ip->ip_dst = dest; |
memcpy((void *)&ip->ip_dst, (void *)&dest, sizeof(IPaddr_t)); |
ip->udp_src = SWAP16(sport); |
ip->udp_dst = SWAP16(dport); |
ip->udp_len = SWAP16(8 + len); |
ip->udp_xsum = 0; |
ip->ip_sum = ~NetCksum((unsigned char *)ip, IP_HDR_SIZE_NO_UDP / 2); |
} |
|
void copy_filename (unsigned char *dst, unsigned char *src, int size) |
void copy_filename(unsigned char *dst, unsigned char *src, int size) |
{ |
if (*src && (*src == '"')) { |
++src; |
--size; |
} |
if (*src && (*src == '"')) { |
++src; |
--size; |
} |
|
while ((--size > 0) && *src && (*src != '"')) { |
*dst++ = *src++; |
} |
*dst = '\0'; |
while ((--size > 0) && *src && (*src != '"')) { |
*dst++ = *src++; |
} |
*dst = '\0'; |
} |
|
void ip_to_string (IPaddr_t x, char *s) |
void ip_to_string(IPaddr_t x, char *s) |
{ |
char num[] = "0123456789ABCDEF"; |
int i; |
char num[] = "0123456789ABCDEF"; |
int i; |
|
x = SWAP32(x); |
|
for(i = 28; i >= 0; i -= 4) |
*s++ = num[((x >> i) & 0x0f)]; |
*s = 0; |
x = SWAP32(x); |
|
for (i = 28; i >= 0; i -= 4) |
*s++ = num[((x >> i) & 0x0f)]; |
*s = 0; |
} |
|
void print_IPaddr (IPaddr_t x) |
void print_IPaddr(IPaddr_t x) |
{ |
char tmp[12]; |
char tmp[12]; |
|
ip_to_string(x, tmp); |
ip_to_string(x, tmp); |
|
printf(tmp); |
printf(tmp); |
} |
|
static unsigned int i2a(char* dest,unsigned int x) { |
register unsigned int tmp=x; |
register unsigned int len=0; |
if (x>=100) { *dest++=tmp/100+'0'; tmp=tmp%100; ++len; } |
if (x>=10) { *dest++=tmp/10+'0'; tmp=tmp%10; ++len; } |
*dest++=tmp+'0'; |
return len+1; |
static unsigned int i2a(char *dest, unsigned int x) |
{ |
register unsigned int tmp = x; |
register unsigned int len = 0; |
if (x >= 100) { |
*dest++ = tmp / 100 + '0'; |
tmp = tmp % 100; |
++len; |
} |
if (x >= 10) { |
*dest++ = tmp / 10 + '0'; |
tmp = tmp % 10; |
++len; |
} |
*dest++ = tmp + '0'; |
return len + 1; |
} |
|
char *inet_ntoa(unsigned long in) { |
static char buf[20]; |
unsigned int len; |
unsigned char *ip=(unsigned char*)∈ |
char *inet_ntoa(unsigned long in) |
{ |
static char buf[20]; |
unsigned int len; |
unsigned char *ip = (unsigned char *)∈ |
|
len=i2a(buf,ip[0]); buf[len]='.'; ++len; |
len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len; |
len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len; |
len+=i2a(buf+ len,ip[3]); buf[len]=0; |
return buf; |
len = i2a(buf, ip[0]); |
buf[len] = '.'; |
++len; |
len += i2a(buf + len, ip[1]); |
buf[len] = '.'; |
++len; |
len += i2a(buf + len, ip[2]); |
buf[len] = '.'; |
++len; |
len += i2a(buf + len, ip[3]); |
buf[len] = 0; |
return buf; |
} |
|
unsigned long inet_aton(const char *cp) |
{ |
unsigned long a[4]; |
unsigned long ret; |
char *p = (char *)cp; |
int i,d; |
if (strcmp(cp, "255.255.255.255") == 0) |
return -1; |
|
for(i = 0; i < 4; i++) { |
a[i] = strtoul(p, 0, 0); |
for(d=1; (p[d] != '.') && (i < 3); d++); |
p = &p[d+1]; |
} |
unsigned long a[4]; |
unsigned long ret; |
char *p = (char *)cp; |
int i, d; |
if (strcmp(cp, "255.255.255.255") == 0) |
return -1; |
|
ret = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]; |
return ret; |
for (i = 0; i < 4; i++) { |
a[i] = strtoul(p, 0, 0); |
for (d = 1; (p[d] != '.') && (i < 3); d++) ; |
p = &p[d + 1]; |
} |
|
ret = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]; |
return ret; |
} |
|
#endif |
/orpmon/services/arp.h
21,7 → 21,6
* MA 02111-1307 USA |
*/ |
|
|
#ifndef __ARP_H__ |
#define __ARP_H__ |
|
32,9 → 31,8
|
extern int ArpTry; |
|
extern void ArpRequest (void); /* Send a ARP request */ |
extern void ArpRequest(void); /* Send a ARP request */ |
|
/**********************************************************************/ |
|
#endif /* __ARP_H__ */ |
|
/orpmon/services/bootp.h
19,33 → 19,32
* BOOTP header. |
*/ |
#if (CONFIG_COMMANDS & CFG_CMD_DHCP) |
#define OPT_SIZE 312 /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */ |
#define OPT_SIZE 312 /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */ |
#else |
#define OPT_SIZE 64 |
#endif |
|
typedef struct |
{ |
unsigned char bp_op; /* Operation */ |
typedef struct { |
unsigned char bp_op; /* Operation */ |
# define OP_BOOTREQUEST 1 |
# define OP_BOOTREPLY 2 |
unsigned char bp_htype; /* Hardware type */ |
unsigned char bp_htype; /* Hardware type */ |
# define HWT_ETHER 1 |
unsigned char bp_hlen; /* Hardware address length */ |
unsigned char bp_hlen; /* Hardware address length */ |
# define HWL_ETHER 6 |
unsigned char bp_hops; /* Hop count (gateway thing) */ |
unsigned long bp_id; /* Transaction ID */ |
unsigned short bp_secs; /* Seconds since boot */ |
unsigned short bp_spare1; /* Alignment */ |
IPaddr_t bp_ciaddr; /* Client IP address */ |
IPaddr_t bp_yiaddr; /* Your (client) IP address */ |
IPaddr_t bp_siaddr; /* Server IP address */ |
IPaddr_t bp_giaddr; /* Gateway IP address */ |
unsigned char bp_chaddr[16]; /* Client hardware address */ |
char bp_sname[64]; /* Server host name */ |
char bp_file[128]; /* Boot file name */ |
char bp_vend[OPT_SIZE]; /* Vendor information */ |
} Bootp_t; |
unsigned char bp_hops; /* Hop count (gateway thing) */ |
unsigned long bp_id; /* Transaction ID */ |
unsigned short bp_secs; /* Seconds since boot */ |
unsigned short bp_spare1; /* Alignment */ |
IPaddr_t bp_ciaddr; /* Client IP address */ |
IPaddr_t bp_yiaddr; /* Your (client) IP address */ |
IPaddr_t bp_siaddr; /* Server IP address */ |
IPaddr_t bp_giaddr; /* Gateway IP address */ |
unsigned char bp_chaddr[16]; /* Client hardware address */ |
char bp_sname[64]; /* Server host name */ |
char bp_file[128]; /* Boot file name */ |
char bp_vend[OPT_SIZE]; /* Vendor information */ |
} Bootp_t; |
|
#define BOOTP_HDR_SIZE sizeof (Bootp_t) |
#define BOOTP_SIZE (ETHER_HDR_SIZE + IP_HDR_SIZE + BOOTP_HDR_SIZE) |
56,16 → 55,15
*/ |
|
/* bootp.c */ |
extern unsigned long BootpID; /* ID of cur BOOTP request */ |
extern char BootFile[128]; /* Boot file name */ |
extern int BootpTry; |
extern unsigned long BootpID; /* ID of cur BOOTP request */ |
extern char BootFile[128]; /* Boot file name */ |
extern int BootpTry; |
#ifdef CONFIG_BOOTP_RANDOM_DELAY |
unsigned long seed1, seed2; /* seed for random BOOTP delay */ |
unsigned long seed1, seed2; /* seed for random BOOTP delay */ |
#endif |
|
|
/* Send a BOOTP request */ |
extern void BootpRequest (void); |
extern void BootpRequest(void); |
|
/****************** DHCP Support *********************/ |
extern void DhcpRequest(void); |
72,13 → 70,14
|
/* DHCP States */ |
typedef enum { INIT, |
INIT_REBOOT, |
REBOOTING, |
SELECTING, |
REQUESTING, |
REBINDING, |
BOUND, |
RENEWING } dhcp_state_t; |
INIT_REBOOT, |
REBOOTING, |
SELECTING, |
REQUESTING, |
REBINDING, |
BOUND, |
RENEWING |
} dhcp_state_t; |
|
#define DHCP_DISCOVER 1 |
#define DHCP_OFFER 2 |
/orpmon/services/rarp.h
21,7 → 21,6
* MA 02111-1307 USA |
*/ |
|
|
#ifndef __RARP_H__ |
#define __RARP_H__ |
|
29,15 → 28,14
#include "net.h" |
#endif /* __NET_H__ */ |
|
|
/**********************************************************************/ |
/* |
* Global functions and variables. |
*/ |
|
extern int RarpTry; |
extern int RarpTry; |
|
extern void RarpRequest (void); /* Send a RARP request */ |
extern void RarpRequest(void); /* Send a RARP request */ |
|
/**********************************************************************/ |
|
/orpmon/services/tftp.c
10,13 → 10,12
#include "tftp.h" |
#include "bootp.h" |
|
#define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ |
#define TIMEOUT 2 /* Seconds to timeout for a lost pkt */ |
#define TIMEOUT_COUNT 10 /* # of timeouts before giving up */ |
/* (for checking the image size) */ |
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */ |
|
#define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ |
#define TIMEOUT 2 /* Seconds to timeout for a lost pkt */ |
#define TIMEOUT_COUNT 10 /* # of timeouts before giving up */ |
/* (for checking the image size) */ |
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */ |
|
/* |
* TFTP operations. |
*/ |
26,13 → 25,12
#define TFTP_ACK 4 |
#define TFTP_ERROR 5 |
|
|
static int TftpServerPort; /* The UDP port at their end */ |
static int TftpOurPort; /* The UDP port at our end */ |
static int TftpTimeoutCount; |
static unsigned TftpBlock; |
static unsigned TftpLastBlock; |
static int TftpState; |
static int TftpServerPort; /* The UDP port at their end */ |
static int TftpOurPort; /* The UDP port at our end */ |
static int TftpTimeoutCount; |
static unsigned TftpBlock; |
static unsigned TftpLastBlock; |
static int TftpState; |
#define STATE_RRQ 1 |
#define STATE_DATA 2 |
#define STATE_TOO_LARGE 3 |
40,7 → 38,6
|
char *tftp_filename; |
|
|
// running TFTP CRC value |
unsigned long TFTP_CHKSUM; |
|
49,13 → 46,13
#endif |
|
static __inline__ void |
store_block (unsigned block, unsigned char * src, unsigned len) |
store_block(unsigned block, unsigned char *src, unsigned len) |
{ |
unsigned long offset = block * 512, newsize = offset + len; |
#ifdef CFG_DIRECT_FLASH_TFTP |
int i, rc = 0; |
|
for (i=0; i<CFG_MAX_FLASH_BANKS; i++) { |
for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) { |
/* start address in flash? */ |
if (global.src_addr + offset >= flash_info[i].start[0]) { |
rc = 1; |
63,23 → 60,30
} |
} |
|
if (rc) { /* Flash is destination for this packet */ |
rc = flash_write ((unsigned char *)src, (unsigned long)(global.src_addr+offset), len); |
if (rc) { /* Flash is destination for this packet */ |
rc = flash_write((unsigned char *)src, |
(unsigned long)(global.src_addr + offset), |
len); |
switch (rc) { |
case 0: /* OK */ |
break; |
case 1: printf ("Timeout writing to Flash\n"); |
case 1: |
printf("Timeout writing to Flash\n"); |
break; |
case 2: printf ("Flash not Erased\n"); |
case 2: |
printf("Flash not Erased\n"); |
break; |
case 4: printf ("Can't write to protected Flash sectors\n"); |
case 4: |
printf("Can't write to protected Flash sectors\n"); |
break; |
case 8: printf ("Outside available Flash\n"); |
case 8: |
printf("Outside available Flash\n"); |
break; |
case 16:printf ("Size must be aligned (multiple of 8?)\n"); |
case 16: |
printf("Size must be aligned (multiple of 8?)\n"); |
break; |
default: |
printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc); |
printf("%s[%d] FIXME: rc=%d\n", __FILE__, __LINE__, rc); |
break; |
} |
if (rc) { |
86,86 → 90,84
NetState = NETLOOP_FAIL; |
return; |
} |
} |
else |
} else |
#endif /* CFG_DIRECT_FLASH_TFTP */ |
|
//#define QUICK_ETHPACKET_COPY |
//#define QUICK_ETHPACKET_COPY |
#ifdef QUICK_ETHPACKET_COPY |
{ |
unsigned char * dst = (unsigned char*)(global.src_addr + offset); |
//printf("quick ethpacket copy: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
// First, align the destination address so we can copy words |
// If either src or dst are not word aligned, then we will never |
// be able to do word copies |
while((len) && ((((unsigned long)dst) & 0x3) || (((unsigned long)src) & 0x3))) |
{ |
// printf("bc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
|
} |
unsigned long *wdst, *wsrc; |
wdst = (unsigned long*) dst; |
wsrc = (unsigned long*) src; |
while(len >= 4) |
{ |
//printf("wc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
wdst[0] = wsrc[0]; |
wdst++; wsrc++; |
len -= 4; |
dst+=4; |
src+=4; |
{ |
unsigned char *dst = |
(unsigned char *)(global.src_addr + offset); |
//printf("quick ethpacket copy: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
// First, align the destination address so we can copy words |
// If either src or dst are not word aligned, then we will never |
// be able to do word copies |
while ((len) |
&& ((((unsigned long)dst) & 0x3) |
|| (((unsigned long)src) & 0x3))) { |
// printf("bc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
|
} |
while (len) |
{ |
//printf("cu: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
} |
} |
} |
unsigned long *wdst, *wsrc; |
wdst = (unsigned long *)dst; |
wsrc = (unsigned long *)src; |
while (len >= 4) { |
//printf("wc: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
wdst[0] = wsrc[0]; |
wdst++; |
wsrc++; |
len -= 4; |
dst += 4; |
src += 4; |
|
} |
while (len) { |
//printf("cu: src: 0x%x dst: 0x%x, len: %d\n",(unsigned long)src, (unsigned long)dst, len); |
dst[0] = src[0]; |
len--; |
dst++; |
src++; |
} |
} |
#else |
|
|
#ifdef TFTP_CALC_CRC |
// Call special memcpy that calculates CRC for us: |
TFTP_CHKSUM += memcpy_crc((void *)(global.src_addr + offset), src, len); |
// Call special memcpy that calculates CRC for us: |
TFTP_CHKSUM += |
memcpy_crc((void *)(global.src_addr + offset), src, len); |
#else |
// Standard memcpy: |
(void)memcpy((void *)(global.src_addr + offset), src, len); |
// Standard memcpy: |
(void)memcpy((void *)(global.src_addr + offset), src, len); |
#endif |
|
|
#endif |
#endif |
|
if (NetBootFileXferSize < newsize) |
NetBootFileXferSize = newsize; |
} |
|
static void TftpSend (void); |
static void TftpTimeout (void); |
static void TftpSend(void); |
static void TftpTimeout(void); |
|
/**********************************************************************/ |
|
static void |
TftpSend (void) |
static void TftpSend(void) |
{ |
volatile unsigned char * pkt; |
volatile unsigned char * xp; |
int len = 0; |
volatile unsigned char *pkt; |
volatile unsigned char *xp; |
int len = 0; |
|
#ifdef ET_DEBUG |
printf("TftpSend: %d\n", TftpState); |
#endif |
|
|
/* |
* We will always be sending some sort of packet, so |
* cobble together the packet headers now. |
* We will always be sending some sort of packet, so |
* cobble together the packet headers now. |
*/ |
pkt = NetTxPacket + ETHER_HDR_SIZE + IP_HDR_SIZE; |
|
175,10 → 177,10
xp = pkt; |
(*((unsigned short *)pkt)) = SWAP16c(TFTP_RRQ); |
pkt += sizeof(short); |
strcpy ((char *)pkt, tftp_filename); |
strcpy((char *)pkt, tftp_filename); |
pkt += strlen(tftp_filename) + 1; |
strcpy ((char *)pkt, "octet"); |
pkt += 5 /*strlen("octet")*/ + 1; |
strcpy((char *)pkt, "octet"); |
pkt += 5 /*strlen("octet") */ + 1; |
len = pkt - xp; |
|
break; |
198,8 → 200,8
pkt += sizeof(short); |
*((unsigned short *)pkt) = SWAP16(3); |
pkt += sizeof(short); |
strcpy ((char *)pkt, "File too large"); |
pkt += 14 /*strlen("File too large")*/ + 1; |
strcpy((char *)pkt, "File too large"); |
pkt += 14 /*strlen("File too large") */ + 1; |
len = pkt - xp; |
break; |
|
209,25 → 211,24
pkt += sizeof(short); |
*((unsigned short *)pkt) = SWAP16(2); |
pkt += sizeof(short); |
strcpy ((char *)pkt, "File has bad magic"); |
pkt += 18 /*strlen("File has bad magic")*/ + 1; |
strcpy((char *)pkt, "File has bad magic"); |
pkt += 18 /*strlen("File has bad magic") */ + 1; |
len = pkt - xp; |
break; |
} |
|
NetSetEther (NetTxPacket, NetServerEther, PROT_IP); |
NetSetIP (NetTxPacket + ETHER_HDR_SIZE, NetServerIP, |
TftpServerPort, TftpOurPort, len); |
NetSendPacket (NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len); |
NetSetEther(NetTxPacket, NetServerEther, PROT_IP); |
NetSetIP(NetTxPacket + ETHER_HDR_SIZE, NetServerIP, |
TftpServerPort, TftpOurPort, len); |
NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + IP_HDR_SIZE + len); |
|
} |
|
|
static void |
TftpHandler (unsigned char * pkt, unsigned dest, unsigned src, unsigned len) |
TftpHandler(unsigned char *pkt, unsigned dest, unsigned src, unsigned len) |
{ |
#ifdef ET_DEBUG |
// printf("TftpHandler\n"); |
// printf("TftpHandler\n"); |
#endif |
if (dest != TftpOurPort) { |
return; |
245,22 → 246,22
case TFTP_RRQ: |
case TFTP_WRQ: |
case TFTP_ACK: |
pkt += sizeof(short); |
pkt += sizeof(short); |
break; |
default: |
break; |
|
case TFTP_DATA: |
pkt += sizeof(short); |
pkt += sizeof(short); |
if (len < 2) |
return; |
len -= 2; |
TftpBlock = SWAP16(*(unsigned short *)pkt); |
if (((TftpBlock - 1) % 10) == 0) { |
putc ('#'); |
putc('#'); |
TftpTimeoutCount = 0; |
} else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0) { |
printf ("\n\t "); |
printf("\n\t "); |
} |
|
if (TftpState == STATE_RRQ) { |
268,13 → 269,11
TftpServerPort = src; |
TftpLastBlock = 0; |
|
|
if (TftpBlock != 1) { /* Assertion */ |
printf ("\nTFTP error: " |
"First block is not block 1 (%d)\n" |
"Starting again\n\n", |
TftpBlock); |
NetStartAgain (); |
printf("\nTFTP error: " |
"First block is not block 1 (%d)\n" |
"Starting again\n\n", TftpBlock); |
NetStartAgain(); |
break; |
} |
} |
281,115 → 280,108
|
if (TftpBlock == TftpLastBlock) { |
#ifdef ET_DEBUG |
printf("block %d - repeated\n",TftpLastBlock); |
printf("block %d - repeated\n", TftpLastBlock); |
#endif |
/* |
* Same block again; resend ack (maybe got lost last time) |
*/ |
TftpSend (); |
break; |
} |
else |
{ |
/* |
* Same block again; resend ack (maybe got lost last time) |
*/ |
TftpSend(); |
break; |
} else { |
#ifdef ET_DEBUG |
printf("block %d - OK\n",TftpLastBlock); |
printf("block %d - OK\n", TftpLastBlock); |
#endif |
TftpLastBlock = TftpBlock; |
NetSetTimeout (TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
|
store_block (TftpBlock - 1, pkt + 2, len); |
} |
|
TftpLastBlock = TftpBlock; |
NetSetTimeout(TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
|
store_block(TftpBlock - 1, pkt + 2, len); |
} |
|
/* |
* Acknoledge the block just received, which will prompt |
* the server for the next one. |
* Acknoledge the block just received, which will prompt |
* the server for the next one. |
*/ |
TftpSend (); |
|
TftpSend(); |
|
if (len < 512) { |
/* |
* We received the whole thing. Try to |
* run it. |
* We received the whole thing. Try to |
* run it. |
*/ |
printf ("\ndone\n"); |
printf("\ndone\n"); |
NetState = NETLOOP_SUCCESS; |
} |
break; |
|
case TFTP_ERROR: |
pkt += sizeof(short); |
printf ("\nTFTP error: '%s' (%d)\n", |
pkt + 2, SWAP16(*(unsigned short *)pkt)); |
printf ("Starting again\n\n"); |
NetStartAgain (); |
pkt += sizeof(short); |
printf("\nTFTP error: '%s' (%d)\n", |
pkt + 2, SWAP16(*(unsigned short *)pkt)); |
printf("Starting again\n\n"); |
NetStartAgain(); |
break; |
} |
|
|
} |
|
|
static void |
TftpTimeout (void) |
static void TftpTimeout(void) |
{ |
if (++TftpTimeoutCount >= TIMEOUT_COUNT) { |
printf ("\nRetry count exceeded; starting again\n"); |
NetStartAgain (); |
printf("\nRetry count exceeded; starting again\n"); |
NetStartAgain(); |
} else { |
printf ("T "); |
NetSetTimeout (TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
TftpSend (); |
printf("T "); |
NetSetTimeout(TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
TftpSend(); |
} |
} |
|
|
void |
TftpStart (void) |
void TftpStart(void) |
{ |
#ifdef ET_DEBUG |
printf ("\nServer ethernet address %02x:%02x:%02x:%02x:%02x:%02x\n", |
NetServerEther[0], |
NetServerEther[1], |
NetServerEther[2], |
NetServerEther[3], |
NetServerEther[4], |
NetServerEther[5] |
); |
printf("\nServer ethernet address %02x:%02x:%02x:%02x:%02x:%02x\n", |
NetServerEther[0], |
NetServerEther[1], |
NetServerEther[2], |
NetServerEther[3], NetServerEther[4], NetServerEther[5] |
); |
#endif /* DEBUG */ |
|
TFTP_CHKSUM = 0; // Reset checksum |
TFTP_CHKSUM = 0; // Reset checksum |
|
printf ("TFTP from server "); print_IPaddr (NetServerIP); |
printf ("; our IP address is "); print_IPaddr (NetOurIP); |
printf("TFTP from server "); |
print_IPaddr(NetServerIP); |
printf("; our IP address is "); |
print_IPaddr(NetOurIP); |
|
// Check if we need to send across this subnet |
if (NetOurGatewayIP && NetOurSubnetMask) { |
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; |
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask; |
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; |
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask; |
|
if (OurNet != ServerNet) { |
printf ("; sending through gateway "); |
print_IPaddr (NetOurGatewayIP) ; |
} |
if (OurNet != ServerNet) { |
printf("; sending through gateway "); |
print_IPaddr(NetOurGatewayIP); |
} |
} |
putc ('\n'); |
putc('\n'); |
|
printf ("Filename '%s'.", tftp_filename); |
printf("Filename '%s'.", tftp_filename); |
|
if (NetBootFileSize) { |
printf (" Size is %d%s kB => %x Bytes", |
NetBootFileSize/2, |
(NetBootFileSize%2) ? ".5" : "", |
NetBootFileSize<<9); |
printf(" Size is %d%s kB => %x Bytes", |
NetBootFileSize / 2, |
(NetBootFileSize % 2) ? ".5" : "", NetBootFileSize << 9); |
} |
|
putc ('\n'); |
putc('\n'); |
|
printf ("Load address: 0x%lx\n", global.src_addr); |
printf("Load address: 0x%lx\n", global.src_addr); |
|
printf ("Loading: *\b"); |
printf("Loading: *\b"); |
|
NetSetTimeout (TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
NetSetHandler (TftpHandler); |
NetSetTimeout(TIMEOUT * TICKS_PER_SEC, TftpTimeout); |
NetSetHandler(TftpHandler); |
|
TftpServerPort = WELL_KNOWN_PORT; |
TftpTimeoutCount = 0; |
396,6 → 388,5
TftpState = STATE_RRQ; |
TftpOurPort = 1024 + (get_timer(0) % 3072); |
|
TftpSend (); |
TftpSend(); |
} |
|
/orpmon/cmds/load.c
1,4 → 1,4
#include "common.h" |
#include "common.h" |
#include "support.h" |
#include "flash.h" |
#include "net.h" |
13,8 → 13,8
extern unsigned long fprog_addr; |
extern char *tftp_filename; |
|
static flash_cfg_struct gcfg = |
{ BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR }; |
static flash_cfg_struct gcfg = |
{ BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR }; |
|
// Not booting from flash, so just set these from board.h -- jb |
//static flash_cfg_struct __attribute__ ((section(".config"))) gcfg = { BOARD_DEF_IP, BOARD_DEF_MASK, BOARD_DEF_GW, BOARD_DEF_TBOOT_SRVR }; |
27,12 → 27,10
// so that the tftp images would download quicker |
#define COPY_AND_BOOT_WORD_ALIGNED |
#ifdef COPY_AND_BOOT_WORD_ALIGNED |
void copy_and_boot(unsigned long src, |
unsigned long dst, |
unsigned long len, |
int tx_next) |
void copy_and_boot(unsigned long src, |
unsigned long dst, unsigned long len, int tx_next) |
{ |
__asm__ __volatile__(" ;\ |
__asm__ __volatile__(" ;\ |
l.addi r8,r0,0x1 ;\ |
l.mtspr r0,r8,0x11 ;\ |
l.nop ;\ |
55,12 → 53,10
l.nop"); |
} |
#else |
void copy_and_boot(unsigned long src, |
unsigned long dst, |
unsigned long len, |
int tx_next) |
void copy_and_boot(unsigned long src, |
unsigned long dst, unsigned long len, int tx_next) |
{ |
__asm__ __volatile__(" ;\ |
__asm__ __volatile__(" ;\ |
l.addi r8,r0,0x1 ;\ |
l.mtspr r0,r8,0x11 ;\ |
l.nop ;\ |
87,261 → 83,274
-- it may corrupt what have we loaded; |
start_addr should be 0xffffffff if only copying should be made |
no return, when start_addr != 0xffffffff, if successful */ |
int copy_memory_run (register unsigned long src_addr, |
register unsigned long dst_addr, |
register unsigned long length, |
register int erase, |
register unsigned long start_addr) |
int copy_memory_run(register unsigned long src_addr, |
register unsigned long dst_addr, |
register unsigned long length, |
register int erase, register unsigned long start_addr) |
{ |
unsigned long i, flags; |
unsigned long i, flags; |
|
register char *dst = (char *) dst_addr; |
register const char *src = (const char *) src_addr; |
register char *dst = (char *)dst_addr; |
register const char *src = (const char *)src_addr; |
|
if (dst_addr >= FLASH_BASE_ADDR) { |
if (dst_addr + length >= FLASH_BASE_ADDR + FLASH_SIZE) { |
printf ("error: region does not fit into flash.\n"); |
return 1; |
} |
if (dst_addr >= FLASH_BASE_ADDR) { |
if (dst_addr + length >= FLASH_BASE_ADDR + FLASH_SIZE) { |
printf("error: region does not fit into flash.\n"); |
return 1; |
} |
#ifndef CFG_IN_FLASH |
fl_program (src_addr, dst_addr, length, erase, 1 /* do verify */); |
fl_program(src_addr, dst_addr, length, erase, |
1 /* do verify */ ); |
#else |
/* we must disable interrupts! */ |
flags=mfspr(SPR_SR); |
mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE)); |
|
printf("Unlocking flash... "); |
for(i = 0; i < length; i += FLASH_BLOCK_SIZE) |
fl_ext_unlock(dst_addr + i); |
printf("done\n"); |
|
printf("Erasing flash... "); |
for(i = 0; i < length; i += FLASH_BLOCK_SIZE) |
fl_ext_erase(dst_addr+i); |
printf("done\n"); |
|
printf("Programing flash:\n\t"); |
for (i = 0; i < length; i += INC_ADDR) { |
if(((i+INC_ADDR) % 1000) == 0) |
printf("#"); |
if((i % (65*1000)) == 0) |
printf("\n\t"); |
if (fl_ext_program (dst_addr + i, reg_read(src_addr + i))) { |
printf("error programing at 0x%08lx!\n", dst_addr+i); |
return 1; |
} |
} |
printf("Verifying flash... "); |
for(i = 0; i < length; i += INC_ADDR) { |
if( reg_read(dst_addr+i) != reg_read(src_addr + i)) { |
printf ("error at %08lx: %08lx != %08lx\n", src_addr + i, |
reg_read(src_addr + i), reg_read(dst_addr + i)); |
return 1; |
} |
} |
printf("OK!\n"); |
mtspr(SPR_SR, flags); |
/* we must disable interrupts! */ |
flags = mfspr(SPR_SR); |
mtspr(SPR_SR, flags & ~(SPR_SR_TEE | SPR_SR_IEE)); |
|
printf("Unlocking flash... "); |
for (i = 0; i < length; i += FLASH_BLOCK_SIZE) |
fl_ext_unlock(dst_addr + i); |
printf("done\n"); |
|
printf("Erasing flash... "); |
for (i = 0; i < length; i += FLASH_BLOCK_SIZE) |
fl_ext_erase(dst_addr + i); |
printf("done\n"); |
|
printf("Programing flash:\n\t"); |
for (i = 0; i < length; i += INC_ADDR) { |
if (((i + INC_ADDR) % 1000) == 0) |
printf("#"); |
if ((i % (65 * 1000)) == 0) |
printf("\n\t"); |
if (fl_ext_program |
(dst_addr + i, reg_read(src_addr + i))) { |
printf("error programing at 0x%08lx!\n", |
dst_addr + i); |
return 1; |
} |
} |
printf("Verifying flash... "); |
for (i = 0; i < length; i += INC_ADDR) { |
if (reg_read(dst_addr + i) != reg_read(src_addr + i)) { |
printf("error at %08lx: %08lx != %08lx\n", |
src_addr + i, reg_read(src_addr + i), |
reg_read(dst_addr + i)); |
return 1; |
} |
} |
printf("OK!\n"); |
mtspr(SPR_SR, flags); |
#endif |
if(start_addr == 0xffffffff) |
return 0; |
} |
else { |
while (length--) *dst++ = *src++; |
if (start_addr == 0xffffffff) |
return 0; |
} |
/* Run the program */ |
((void (*)(void)) start_addr)(); |
return 0; /* just to satisfy the cc */ |
if (start_addr == 0xffffffff) |
return 0; |
} else { |
while (length--) |
*dst++ = *src++; |
if (start_addr == 0xffffffff) |
return 0; |
} |
/* Run the program */ |
((void (*)(void))start_addr) (); |
return 0; /* just to satisfy the cc */ |
} |
|
void bf_jump(unsigned long addr) |
{ |
asm("l.jr r3"); |
asm("l.nop 0x0"); |
asm("l.jr r3"); |
asm("l.nop 0x0"); |
} |
|
int boot_flash_cmd(int argc, char *argv[]) |
{ |
unsigned long addr,val,jaddr; |
addr = 17; |
val = 0; |
/* clear SR */ |
unsigned long addr, val, jaddr; |
addr = 17; |
val = 0; |
/* clear SR */ |
|
asm("l.mtspr %0,%1,0": : "r" (addr), "r" (val)); |
/* jump */ |
if(argc == 0) |
bf_jump(FLASH_BASE_ADDR+0x100); |
else { |
jaddr = strtoul(argv[0], 0, 0); |
bf_jump(jaddr); |
} |
return 0; |
asm("l.mtspr %0,%1,0": :"r"(addr), "r"(val)); |
/* jump */ |
if (argc == 0) |
bf_jump(FLASH_BASE_ADDR + 0x100); |
else { |
jaddr = strtoul(argv[0], 0, 0); |
bf_jump(jaddr); |
} |
return 0; |
} |
|
void |
init_load (void) |
void init_load(void) |
{ |
#if 0 // JB - removing flash stuff |
#if 0 // JB - removing flash stuff |
# ifdef CFG_IN_FLASH |
copy_memory_run((unsigned long)&fl_word_program, (unsigned long)&fprog_addr, |
95, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_block_erase, (unsigned long)&fprog_addr+96, |
119, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_unlock_one_block, |
(unsigned long)&fprog_addr+96+120, |
115, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_word_program, |
(unsigned long)&fprog_addr, 95, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_block_erase, |
(unsigned long)&fprog_addr + 96, 119, 0, 0xffffffff); |
copy_memory_run((unsigned long)&fl_unlock_one_block, |
(unsigned long)&fprog_addr + 96 + 120, 115, 0, |
0xffffffff); |
|
fl_ext_program = (t_fl_ext_program)&fprog_addr; |
fl_ext_erase = (t_fl_erase)&fprog_addr+96; |
fl_ext_unlock = (t_fl_erase)&fprog_addr+96+120; |
fl_ext_program = (t_fl_ext_program) & fprog_addr; |
fl_ext_erase = (t_fl_erase) & fprog_addr + 96; |
fl_ext_unlock = (t_fl_erase) & fprog_addr + 96 + 120; |
|
# if 0 |
printf("fl_word_program(): 0x%x\tfl_ext_program(): 0x%x\n", |
&fl_word_program, fl_ext_program); |
printf("fl_block_erase: 0x%x\tfl_ext_erase(): 0x%x\n", |
&fl_block_erase, fl_ext_erase); |
printf("fl_unlock_one_block(): 0x%x\tfl_ext_unlock(): 0x%x\n", |
&fl_unlock_one_block, fl_ext_unlock); |
printf("fl_word_program(): 0x%x\tfl_ext_program(): 0x%x\n", |
&fl_word_program, fl_ext_program); |
printf("fl_block_erase: 0x%x\tfl_ext_erase(): 0x%x\n", |
&fl_block_erase, fl_ext_erase); |
printf("fl_unlock_one_block(): 0x%x\tfl_ext_unlock(): 0x%x\n", |
&fl_unlock_one_block, fl_ext_unlock); |
# endif |
|
# else /* not CFG_IN_FLASH */ |
fl_ext_program = (t_fl_ext_program)&fl_word_program; |
fl_ext_erase = (t_fl_erase)&fl_block_erase; |
fl_ext_unlock = (t_fl_erase)&fl_unlock_one_block; |
# else /* not CFG_IN_FLASH */ |
fl_ext_program = (t_fl_ext_program) & fl_word_program; |
fl_ext_erase = (t_fl_erase) & fl_block_erase; |
fl_ext_unlock = (t_fl_erase) & fl_unlock_one_block; |
# endif /* CFG_IN_FLASH */ |
#endif |
|
/* |
global.ip = gcfg.eth_ip; |
global.gw_ip = gcfg.eth_gw; |
global.mask = gcfg.eth_mask; |
global.srv_ip = gcfg.tftp_srv_ip; |
global.src_addr = 0x100000; |
tftp_filename = "boot.img"; |
*/ |
/* |
global.ip = gcfg.eth_ip; |
global.gw_ip = gcfg.eth_gw; |
global.mask = gcfg.eth_mask; |
global.srv_ip = gcfg.tftp_srv_ip; |
global.src_addr = 0x100000; |
tftp_filename = "boot.img"; |
*/ |
|
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
global.srv_ip = BOARD_DEF_TBOOT_SRVR; |
global.src_addr = BOARD_DEF_LOAD_SPACE; |
tftp_filename = BOARD_DEF_IMAGE_NAME; |
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
global.srv_ip = BOARD_DEF_TBOOT_SRVR; |
global.src_addr = BOARD_DEF_LOAD_SPACE; |
tftp_filename = BOARD_DEF_IMAGE_NAME; |
|
/*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename)); |
tftp_filename[strlen(gcfg.tftp_filename)] = '\0';*/ |
/*memcpy(tftp_filename, gcfg.tftp_filename, strlen(gcfg.tftp_filename)); |
tftp_filename[strlen(gcfg.tftp_filename)] = '\0'; */ |
} |
|
int tftp_cmd (int argc, char *argv[]) |
int tftp_cmd(int argc, char *argv[]) |
{ |
switch (argc) { |
case 0: tftp_filename = "boot.img"; |
break; |
case 3: global.src_addr = strtoul (argv[2], 0, 0); |
case 2: global.srv_ip = parse_ip (argv[1]); |
case 1: tftp_filename = &argv[0][0]; |
break; |
} |
NetLoop(TFTP); |
return 0; |
switch (argc) { |
case 0: |
tftp_filename = "boot.img"; |
break; |
case 3: |
global.src_addr = strtoul(argv[2], 0, 0); |
case 2: |
global.srv_ip = parse_ip(argv[1]); |
case 1: |
tftp_filename = &argv[0][0]; |
break; |
} |
|
NetLoop(TFTP); // TFTP is enumerated value in net.h |
|
return 0; |
} |
|
int tftp_conf_cmd(int argc, char *argv[]) |
{ |
switch(argc) { |
case 0: |
printf("Image filename: %s", tftp_filename); |
printf("\nSrc addr: 0x%lx", global.src_addr); |
printf("\nServer IP: %s", inet_ntoa(global.srv_ip)); |
return 0; |
case 3: |
global.src_addr = strtoul(argv[2], 0, 0); |
global.srv_ip = inet_aton(argv[1]); |
tftp_filename = argv[0]; |
tftp_filename[strlen(argv[0])] = '\0'; |
break; |
case 2: |
global.srv_ip = inet_aton(argv[1]); |
tftp_filename = argv[0]; |
break; |
case 1: |
tftp_filename = argv[0]; |
break; |
} |
return 0; |
switch (argc) { |
case 0: |
printf("Image filename: %s", tftp_filename); |
printf("\nSrc addr: 0x%lx", global.src_addr); |
printf("\nServer IP: %s", inet_ntoa(global.srv_ip)); |
return 0; |
case 3: |
global.src_addr = strtoul(argv[2], 0, 0); |
global.srv_ip = inet_aton(argv[1]); |
tftp_filename = argv[0]; |
tftp_filename[strlen(argv[0])] = '\0'; |
break; |
case 2: |
global.srv_ip = inet_aton(argv[1]); |
tftp_filename = argv[0]; |
break; |
case 1: |
tftp_filename = argv[0]; |
break; |
} |
return 0; |
} |
|
void save_global_cfg(flash_cfg_struct cfg) |
{ |
unsigned long dst = (unsigned long)&gcfg, src = (unsigned long)&cfg; |
unsigned long i, end, flags; |
unsigned long dst = (unsigned long)&gcfg, src = (unsigned long)&cfg; |
unsigned long i, end, flags; |
|
end = (unsigned long)&cfg + sizeof(flash_cfg_struct); |
end = (unsigned long)&cfg + sizeof(flash_cfg_struct); |
|
printf("Saving global cfg from 0x%lx (end: 0x%lx) to 0x%lx...", src, end, dst); |
printf("Saving global cfg from 0x%lx (end: 0x%lx) to 0x%lx...", src, |
end, dst); |
|
/* we must disable interrupts! */ |
flags=mfspr(SPR_SR); |
mtspr(SPR_SR,flags & ~(SPR_SR_TEE | SPR_SR_IEE)); |
/* printf("Unlocking... ");*/ |
for(i = 0; (src+i <= end); i += FLASH_BLOCK_SIZE) { |
fl_ext_unlock(dst+i); |
} |
/* printf("done\n");*/ |
/* printf("Erasing... ");*/ |
for(i = 0; (src+i <= end); i += FLASH_BLOCK_SIZE) |
fl_ext_erase(dst); |
/* printf("done\n");*/ |
/* printf("Programing... ");*/ |
for(i = 0; (src+i <= end); i +=INC_ADDR) { |
if(fl_ext_program(dst+i, reg_read(src+i))) { |
printf("Error ocurred while saving.\n"); |
return; |
} |
} |
printf("done\n"); |
/* we must disable interrupts! */ |
flags = mfspr(SPR_SR); |
mtspr(SPR_SR, flags & ~(SPR_SR_TEE | SPR_SR_IEE)); |
/* printf("Unlocking... "); */ |
for (i = 0; (src + i <= end); i += FLASH_BLOCK_SIZE) { |
fl_ext_unlock(dst + i); |
} |
/* printf("done\n"); */ |
/* printf("Erasing... "); */ |
for (i = 0; (src + i <= end); i += FLASH_BLOCK_SIZE) |
fl_ext_erase(dst); |
/* printf("done\n"); */ |
/* printf("Programing... "); */ |
for (i = 0; (src + i <= end); i += INC_ADDR) { |
if (fl_ext_program(dst + i, reg_read(src + i))) { |
printf("Error ocurred while saving.\n"); |
return; |
} |
} |
printf("done\n"); |
|
/* and than enable it back */ |
mtspr(SPR_SR, flags); |
return; |
/* and than enable it back */ |
mtspr(SPR_SR, flags); |
return; |
} |
|
int save_conf_cmd(int argc, char *argv[]) |
{ |
flash_cfg_struct newCfg; |
flash_cfg_struct newCfg; |
|
newCfg = gcfg; |
newCfg = gcfg; |
|
newCfg.eth_ip = global.ip; |
newCfg.eth_mask = global.mask; |
newCfg.eth_gw = global.gw_ip; |
newCfg.tftp_srv_ip = global.srv_ip; |
/* memcpy(newCfg.tftp_filename, tftp_filename, strlen(tftp_filename));*/ |
newCfg.eth_ip = global.ip; |
newCfg.eth_mask = global.mask; |
newCfg.eth_gw = global.gw_ip; |
newCfg.tftp_srv_ip = global.srv_ip; |
/* memcpy(newCfg.tftp_filename, tftp_filename, strlen(tftp_filename)); */ |
|
save_global_cfg(newCfg); |
return 0; |
save_global_cfg(newCfg); |
return 0; |
} |
int copy_cmd (int argc, char *argv[]) |
|
int copy_cmd(int argc, char *argv[]) |
{ |
switch (argc) { |
case 3: global.src_addr = strtoul (argv[2], 0, 0); |
case 2: global.length = strtoul (argv[2], 0, 0); |
case 1: global.src_addr = strtoul (argv[2], 0, 0); |
case 0: return copy_memory_run (global.src_addr, global.dst_addr, |
global.length, global.erase_method, |
0xffffffff); |
} |
return -1; |
switch (argc) { |
case 3: |
global.src_addr = strtoul(argv[2], 0, 0); |
case 2: |
global.length = strtoul(argv[2], 0, 0); |
case 1: |
global.src_addr = strtoul(argv[2], 0, 0); |
case 0: |
return copy_memory_run(global.src_addr, global.dst_addr, |
global.length, global.erase_method, |
0xffffffff); |
} |
return -1; |
} |
|
void |
images_info(void) |
void images_info(void) |
{ |
int i; |
printf("Number of images: 0x%lx\n", gcfg.img_number); |
for(i = 0; i < gcfg.img_number; i++) |
printf("%d. image size: 0x%lx (at 0x%08lx)\n", i+1, |
gcfg.img_length[i], gcfg.img_start_addr[i]); |
int i; |
printf("Number of images: 0x%lx\n", gcfg.img_number); |
for (i = 0; i < gcfg.img_number; i++) |
printf("%d. image size: 0x%lx (at 0x%08lx)\n", i + 1, |
gcfg.img_length[i], gcfg.img_start_addr[i]); |
} |
|
/* |
351,348 → 360,351
* a hole between images, that is big enough (but as small as possible). |
* |
*/ |
unsigned long |
get_good_addr(unsigned int size) |
unsigned long get_good_addr(unsigned int size) |
{ |
unsigned long start_addr[MAX_IMAGES], end_addr[MAX_IMAGES]; |
unsigned long free[MAX_IMAGES], st_addr[MAX_IMAGES]; |
unsigned long tmpval; |
unsigned int i = 0, j; |
unsigned long start_addr[MAX_IMAGES], end_addr[MAX_IMAGES]; |
unsigned long free[MAX_IMAGES], st_addr[MAX_IMAGES]; |
unsigned long tmpval; |
unsigned int i = 0, j; |
|
flash_cfg_struct myCfg; |
myCfg = gcfg; |
flash_cfg_struct myCfg; |
myCfg = gcfg; |
|
/* we are full */ |
if(gcfg.img_number == MAX_IMAGES) |
return 0xffffffff; |
/* we are full */ |
if (gcfg.img_number == MAX_IMAGES) |
return 0xffffffff; |
|
if(gcfg.img_number == 0) |
return FLASH_IMAGES_BASE; |
if (gcfg.img_number == 0) |
return FLASH_IMAGES_BASE; |
|
for(i = 0; i < MAX_IMAGES; i++) { |
start_addr[i] = 0; |
end_addr[i] = 0; |
free[i] = 0; |
st_addr[i] = 0; |
} |
for (i = 0; i < MAX_IMAGES; i++) { |
start_addr[i] = 0; |
end_addr[i] = 0; |
free[i] = 0; |
st_addr[i] = 0; |
} |
|
for(i = 0; i < myCfg.img_number; i++) { |
start_addr[i] = myCfg.img_start_addr[i]; |
end_addr[i] = ALIGN((myCfg.img_start_addr[i] + myCfg.img_length[i]), |
FLASH_BLOCK_SIZE); |
} |
/* printf("\n"); |
for(i = 0; i < myCfg.img_number; i++) |
printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]); |
printf("\n");*/ |
/* bubble sorting by start_addr */ |
for (i = 0; i < myCfg.img_number; i++) { |
start_addr[i] = myCfg.img_start_addr[i]; |
end_addr[i] = |
ALIGN((myCfg.img_start_addr[i] + myCfg.img_length[i]), |
FLASH_BLOCK_SIZE); |
} |
/* printf("\n"); |
for(i = 0; i < myCfg.img_number; i++) |
printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]); |
printf("\n"); */ |
/* bubble sorting by start_addr */ |
|
for(j = myCfg.img_number - 1; j > 0; j--) |
for(i = 0; i < j; i++) |
if(start_addr[i] > start_addr[i+1]) { |
tmpval = start_addr[i]; |
start_addr[i] = start_addr[i+1]; |
start_addr[i+1] = tmpval; |
tmpval = end_addr[i]; |
end_addr[i] = end_addr[i+1]; |
end_addr[i+1] = tmpval; |
} |
for (j = myCfg.img_number - 1; j > 0; j--) |
for (i = 0; i < j; i++) |
if (start_addr[i] > start_addr[i + 1]) { |
tmpval = start_addr[i]; |
start_addr[i] = start_addr[i + 1]; |
start_addr[i + 1] = tmpval; |
tmpval = end_addr[i]; |
end_addr[i] = end_addr[i + 1]; |
end_addr[i + 1] = tmpval; |
} |
|
/* for(i = 0; i < myCfg.img_number; i++) |
printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]); |
printf("\n");*/ |
/* for(i = 0; i < myCfg.img_number; i++) |
printf("start: 0x%08x, end: 0x%08x\n", start_addr[i], end_addr[i]); |
printf("\n"); */ |
|
/* now we calculate free space betwens segments */ |
for(i = 1; i < myCfg.img_number; i++) { |
st_addr[i] = end_addr[i - 1]; |
free[i] = start_addr[i] - end_addr[i - 1]; |
} |
/* now we calculate free space betwens segments */ |
for (i = 1; i < myCfg.img_number; i++) { |
st_addr[i] = end_addr[i - 1]; |
free[i] = start_addr[i] - end_addr[i - 1]; |
} |
|
/* here we calcuta first position (starting with FLASH_IMAGES_BASE)... */ |
st_addr[0] = FLASH_IMAGES_BASE + 0; |
free[0] = start_addr[0] - FLASH_IMAGES_BASE; |
/* ... and last one (ending with FLASH_IMAGES_BASE + FLASH_SIZE). */ |
st_addr[myCfg.img_number] = end_addr[myCfg.img_number-1]; |
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) - |
end_addr[myCfg.img_number-1]; |
/* here we calcuta first position (starting with FLASH_IMAGES_BASE)... */ |
st_addr[0] = FLASH_IMAGES_BASE + 0; |
free[0] = start_addr[0] - FLASH_IMAGES_BASE; |
/* ... and last one (ending with FLASH_IMAGES_BASE + FLASH_SIZE). */ |
st_addr[myCfg.img_number] = end_addr[myCfg.img_number - 1]; |
free[myCfg.img_number] = (FLASH_IMAGES_BASE + FLASH_SIZE) - |
end_addr[myCfg.img_number - 1]; |
|
/* yet another bubble sort by free (space) */ |
for(j = myCfg.img_number; j > 0; j--) |
for(i = 0; i < j; i++) |
if(free[i] > free[i+1]) { |
tmpval = free[i]; |
free[i] = free[i+1]; |
free[i+1] = tmpval; |
tmpval = st_addr[i]; |
st_addr[i] = st_addr[i+1]; |
st_addr[i+1] = tmpval; |
} |
/* yet another bubble sort by free (space) */ |
for (j = myCfg.img_number; j > 0; j--) |
for (i = 0; i < j; i++) |
if (free[i] > free[i + 1]) { |
tmpval = free[i]; |
free[i] = free[i + 1]; |
free[i + 1] = tmpval; |
tmpval = st_addr[i]; |
st_addr[i] = st_addr[i + 1]; |
st_addr[i + 1] = tmpval; |
} |
|
/* now we pick the smallest but just big enough for our size */ |
for(i = 0; i <= myCfg.img_number; i++) |
if(free[i] >= size) |
return st_addr[i]; |
/* now we pick the smallest but just big enough for our size */ |
for (i = 0; i <= myCfg.img_number; i++) |
if (free[i] >= size) |
return st_addr[i]; |
|
/* there is not enough space (in one segment) left */ |
return 0; |
/* there is not enough space (in one segment) left */ |
return 0; |
} |
|
unsigned long |
prepare_img_data(unsigned int num, unsigned int size) |
unsigned long prepare_img_data(unsigned int num, unsigned int size) |
{ |
int i; |
unsigned long addr=0; |
flash_cfg_struct newCfg; |
int i; |
unsigned long addr = 0; |
flash_cfg_struct newCfg; |
|
newCfg = gcfg; |
newCfg = gcfg; |
|
if(newCfg.img_number >= MAX_IMAGES) { |
printf("Maximum images exceeded: %d\n", MAX_IMAGES); |
return 0xffffffff; |
} |
if (newCfg.img_number >= MAX_IMAGES) { |
printf("Maximum images exceeded: %d\n", MAX_IMAGES); |
return 0xffffffff; |
} |
|
newCfg.img_number++; |
newCfg.img_number++; |
|
if((num > newCfg.img_number) || (num == 0)) |
num = newCfg.img_number; |
if ((num > newCfg.img_number) || (num == 0)) |
num = newCfg.img_number; |
|
addr = get_good_addr(size); |
if(addr == 0x00) { |
printf("Can not find suitable place in flash. (None of free segments are big enough)\n"); |
return 0xffffffff; |
} |
addr = get_good_addr(size); |
if (addr == 0x00) { |
printf |
("Can not find suitable place in flash. (None of free segments are big enough)\n"); |
return 0xffffffff; |
} |
|
if(num < newCfg.img_number) |
for(i=newCfg.img_number-1; i >= num; i--) { |
newCfg.img_length[i] = newCfg.img_length[i-1]; |
newCfg.img_start_addr[i] = newCfg.img_start_addr[i-1]; |
} |
if (num < newCfg.img_number) |
for (i = newCfg.img_number - 1; i >= num; i--) { |
newCfg.img_length[i] = newCfg.img_length[i - 1]; |
newCfg.img_start_addr[i] = newCfg.img_start_addr[i - 1]; |
} |
|
newCfg.img_length[num-1] = size; |
newCfg.img_start_addr[num-1] = addr; |
newCfg.img_length[num - 1] = size; |
newCfg.img_start_addr[num - 1] = addr; |
|
save_global_cfg(newCfg); |
return addr; |
save_global_cfg(newCfg); |
return addr; |
} |
|
int |
del_image_cmd(int argc, char *argv[]) |
int del_image_cmd(int argc, char *argv[]) |
{ |
unsigned num, i; |
flash_cfg_struct newCfg = gcfg; |
unsigned num, i; |
flash_cfg_struct newCfg = gcfg; |
|
newCfg.img_number = gcfg.img_number; |
for(i = 0; i < MAX_IMAGES; i++) |
newCfg.img_length[i] = gcfg.img_length[i]; |
newCfg.img_number = gcfg.img_number; |
for (i = 0; i < MAX_IMAGES; i++) |
newCfg.img_length[i] = gcfg.img_length[i]; |
|
printf("Number of images available: 0x%lx\n", newCfg.img_number); |
printf("Number of images available: 0x%lx\n", newCfg.img_number); |
|
if(argc == 0) { |
newCfg.img_number = 0; |
for(i = 0; i < MAX_IMAGES; i++) { |
newCfg.img_length[i] = 0; |
newCfg.img_start_addr[i] = 0; |
} |
save_global_cfg(newCfg); |
return 0; |
} |
else { |
num = strtoul(argv[0], 0, 0); |
} |
if (argc == 0) { |
newCfg.img_number = 0; |
for (i = 0; i < MAX_IMAGES; i++) { |
newCfg.img_length[i] = 0; |
newCfg.img_start_addr[i] = 0; |
} |
save_global_cfg(newCfg); |
return 0; |
} else { |
num = strtoul(argv[0], 0, 0); |
} |
|
if(newCfg.img_number == 0) { |
printf("Nothing to delete!\n"); |
return 0; |
} |
if((num == 0) || (num > newCfg.img_number)) |
num = newCfg.img_number; |
if (newCfg.img_number == 0) { |
printf("Nothing to delete!\n"); |
return 0; |
} |
if ((num == 0) || (num > newCfg.img_number)) |
num = newCfg.img_number; |
|
for(i=num-1; i < newCfg.img_number; i++) { |
newCfg.img_length[i] = newCfg.img_length[i+1]; |
newCfg.img_start_addr[i] = newCfg.img_start_addr[i+1]; |
} |
|
newCfg.img_number--; |
save_global_cfg(newCfg); |
return 0; |
for (i = num - 1; i < newCfg.img_number; i++) { |
newCfg.img_length[i] = newCfg.img_length[i + 1]; |
newCfg.img_start_addr[i] = newCfg.img_start_addr[i + 1]; |
} |
|
newCfg.img_number--; |
save_global_cfg(newCfg); |
return 0; |
} |
|
int |
boot_cmd(int argc, char *argv[]) |
int boot_cmd(int argc, char *argv[]) |
{ |
int num; |
extern int tx_next; |
int num; |
extern int tx_next; |
|
if(argc == 0) { |
images_info(); |
return 0; |
} |
if (argc == 0) { |
images_info(); |
return 0; |
} |
|
num = strtoul(argv[0],0,0); |
if(gcfg.img_number < num) { |
printf("There are only %lu images, you requested %d!\n", |
gcfg.img_number, num); |
return -1; |
} |
num = strtoul(argv[0], 0, 0); |
if (gcfg.img_number < num) { |
printf("There are only %lu images, you requested %d!\n", |
gcfg.img_number, num); |
return -1; |
} |
|
printf("Copying image number %d from 0x%lx, size: 0x%lx...", |
num, gcfg.img_start_addr[num-1], gcfg.img_length[num-1]); |
printf("Copying image number %d from 0x%lx, size: 0x%lx...", |
num, gcfg.img_start_addr[num - 1], gcfg.img_length[num - 1]); |
|
printf("booting...\n"); |
copy_and_boot(gcfg.img_start_addr[num-1], 0x0, gcfg.img_length[num-1], |
tx_next); |
return 0; |
printf("booting...\n"); |
copy_and_boot(gcfg.img_start_addr[num - 1], 0x0, |
gcfg.img_length[num - 1], tx_next); |
return 0; |
} |
|
int mGetData(unsigned long); |
|
#if 0 // Disable sboot - JB |
int sboot_cmd (int argc, char *argv[]) |
#if 0 // Disable sboot - JB |
int sboot_cmd(int argc, char *argv[]) |
{ |
int copied; |
unsigned int num = 0xffffffff, addr = 0x0; |
int copied; |
unsigned int num = 0xffffffff, addr = 0x0; |
|
switch(argc) { |
case 0: |
num = 0xffffffff; |
break; |
case 1: |
num = strtoul(argv[0], 0, 0); |
break; |
} |
switch (argc) { |
case 0: |
num = 0xffffffff; |
break; |
case 1: |
num = strtoul(argv[0], 0, 0); |
break; |
} |
|
copied = mGetData(global.src_addr); |
if(copied <= 0) { |
printf("sboot: error while getting the image!"); |
return -1; |
} |
printf("image size: 0x%x\n", copied); |
copied = mGetData(global.src_addr); |
if (copied <= 0) { |
printf("sboot: error while getting the image!"); |
return -1; |
} |
printf("image size: 0x%x\n", copied); |
|
if(num != 0xffffffff) { |
addr = prepare_img_data(num, copied); |
if(addr == 0xffffffff) |
printf("Image not written to flash!\n"); |
else { |
printf("Copying image to flash, image number: %d, dst_addr: 0x%x\n", |
num, addr); |
copy_memory_run(global.src_addr, gcfg.img_start_addr[num-1], copied, 2, 0xffffffff); |
} |
} |
if (num != 0xffffffff) { |
addr = prepare_img_data(num, copied); |
if (addr == 0xffffffff) |
printf("Image not written to flash!\n"); |
else { |
printf |
("Copying image to flash, image number: %d, dst_addr: 0x%x\n", |
num, addr); |
copy_memory_run(global.src_addr, |
gcfg.img_start_addr[num - 1], copied, 2, |
0xffffffff); |
} |
} |
|
return 0; |
return 0; |
} |
#endif |
|
void relocate_code(void* destination, void* function, int length_words) |
void relocate_code(void *destination, void *function, int length_words) |
{ |
// Just copy the function word at a time from one place to another |
int i; |
unsigned long * p1 = (unsigned long*) destination; |
unsigned long * p2 = (unsigned long*) function; |
for(i=0;i<length_words;i++) |
p1[i] = p2[i]; |
// Just copy the function word at a time from one place to another |
int i; |
unsigned long *p1 = (unsigned long *)destination; |
unsigned long *p2 = (unsigned long *)function; |
for (i = 0; i < length_words; i++) |
p1[i] = p2[i]; |
} |
|
// DC disable command in cpu.c |
extern int dc_disable_cmd(int argc, char *argv[]); |
|
int tboot_cmd (int argc, char *argv[]) |
int tboot_cmd(int argc, char *argv[]) |
{ |
int copied; |
unsigned int num = 0xffffffff, addr = 0x0; |
extern int tx_next; |
// NetTxPacket wasn't getting cleared before we used it... |
NetTxPacket = 0; |
NetBootFileSize = 0; |
int copied; |
unsigned int num = 0xffffffff, addr = 0x0; |
extern int tx_next; |
// NetTxPacket wasn't getting cleared before we used it... |
NetTxPacket = 0; |
NetBootFileSize = 0; |
|
switch (argc) { |
case 0: |
num = 0xffffffff; |
break; |
case 1: |
printf("argv[0] %p\n", argv[0]); |
num = strtoul(argv[0], 0, 0); |
printf("num %d\n", num); |
break; |
} |
switch (argc) { |
case 0: |
num = 0xffffffff; |
break; |
case 1: |
printf("argv[0] %p\n", argv[0]); |
num = strtoul(argv[0], 0, 0); |
printf("num %d\n", num); |
break; |
} |
|
// Disable data cache if present |
if (mfspr(SPR_SR) & SPR_SR_DCE) |
{ |
printf("Disabling data cache\n"); |
dc_disable_cmd(0, 0); |
} |
|
// Kick off copy |
copied =NetLoop(TFTP); |
if (copied <= 0) { |
printf("tboot: error while getting the image '%s'", tftp_filename); |
return -1; |
} |
// Disable data cache if present |
if (mfspr(SPR_SR) & SPR_SR_DCE) { |
printf("Disabling data cache\n"); |
dc_disable_cmd(0, 0); |
} |
// Kick off copy |
copied = NetLoop(TFTP); |
if (copied <= 0) { |
printf("tboot: error while getting the image '%s'", |
tftp_filename); |
return -1; |
} |
|
if (global.src_addr > 0) |
{ |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, copied); |
} |
if (global.src_addr > 0) { |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, copied); |
} |
// Disable timer: clear it all! |
mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE); |
mtspr(SPR_TTMR, 0); |
|
// Disable timer: clear it all! |
mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE); |
mtspr(SPR_TTMR, 0); |
|
// Put the copyboot program at 24MB mark in memory |
#define COPYBOOT_LOCATION (1024*1024*24) |
printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION); |
// Setup where we'll copy the relocation function to |
void (*relocated_function)(unsigned long, unsigned long, unsigned long, int) |
= (void*) COPYBOOT_LOCATION; |
// Now copy the function there, 32 words worth, increase this if needed... |
relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32); |
// Indicate we'll jump there... |
printf("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", copied, (unsigned long) global.src_addr); |
// Now do the copy and boot |
(*relocated_function)(global.src_addr, 0x0, 0x0 + copied, tx_next); |
// Put the copyboot program at 24MB mark in memory |
#define COPYBOOT_LOCATION (1024*1024*24) |
printf("tboot: relocating copy loop to 0x%x ...\n", |
(unsigned long)COPYBOOT_LOCATION); |
// Setup where we'll copy the relocation function to |
void (*relocated_function) (unsigned long, unsigned long, unsigned long, |
int) |
= (void *)COPYBOOT_LOCATION; |
// Now copy the function there, 32 words worth, increase this if needed... |
relocate_code((void *)COPYBOOT_LOCATION, copy_and_boot, 32); |
// Indicate we'll jump there... |
printf |
("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", |
copied, (unsigned long)global.src_addr); |
// Now do the copy and boot |
(*relocated_function) (global.src_addr, 0x0, 0x0 + copied, tx_next); |
|
return 0; |
return 0; |
} |
|
int sdboot_cmd (int argc, char *argv[]) |
int sdboot_cmd(int argc, char *argv[]) |
{ |
VOLINFO vi; |
VOLINFO vi; |
unsigned char *buf_ptr; |
|
|
unsigned char sector[SECTOR_SIZE], sector2[SECTOR_SIZE]; |
FILEINFO fi; |
unsigned long int pstart,psize, i,fisz; |
unsigned char pactive, ptype; |
unsigned long int pstart, psize, i, fisz; |
unsigned char pactive, ptype; |
DIRINFO di; |
DIRENT de; |
unsigned long int cache; |
|
// Obtain pointer to first partition on first (only) unit |
// Disable data cache if present |
if (mfspr(SPR_SR) & SPR_SR_DCE) |
{ |
printf("Disabling data cache\n"); |
dc_disable_cmd(0, 0); |
} |
|
|
buf_ptr=global.src_addr; |
|
|
// Obtain pointer to first partition on first (only) unit |
// Disable data cache if present |
if (mfspr(SPR_SR) & SPR_SR_DCE) { |
printf("Disabling data cache\n"); |
dc_disable_cmd(0, 0); |
} |
|
buf_ptr = global.src_addr; |
|
printf("SD-BOOT start \n"); |
i=init_fat(&vi); |
|
|
|
i = init_fat(&vi); |
|
printf("Volume label '%-11.11s'\n", vi.label); |
printf("%d sector/s per cluster, %d reserved sector/s, volume total %d sectors.\n", vi.secperclus, vi.reservedsecs, vi.numsecs); |
printf("%d sectors per FAT, first FAT at sector #%d, root dir at #%d.\n",vi.secperfat,vi.fat1,vi.rootdir); |
printf("(For FAT32, the root dir is a CLUSTER number, FAT12/16 it is a SECTOR number)\n"); |
printf("%d root dir entries, data area commences at sector #%d.\n",vi.rootentries,vi.dataarea); |
printf("%d clusters (%d bytes) in data area, filesystem IDd as ", vi.numclusters, vi.numclusters * vi.secperclus * SECTOR_SIZE); |
printf |
("%d sector/s per cluster, %d reserved sector/s, volume total %d sectors.\n", |
vi.secperclus, vi.reservedsecs, vi.numsecs); |
printf |
("%d sectors per FAT, first FAT at sector #%d, root dir at #%d.\n", |
vi.secperfat, vi.fat1, vi.rootdir); |
printf |
("(For FAT32, the root dir is a CLUSTER number, FAT12/16 it is a SECTOR number)\n"); |
printf("%d root dir entries, data area commences at sector #%d.\n", |
vi.rootentries, vi.dataarea); |
printf("%d clusters (%d bytes) in data area, filesystem IDd as ", |
vi.numclusters, vi.numclusters * vi.secperclus * SECTOR_SIZE); |
if (vi.filesystem == FAT12) |
printf("FAT12.\n"); |
else if (vi.filesystem == FAT16) |
701,76 → 713,85
printf("FAT32.\n"); |
else |
printf("[unknown]\n"); |
|
|
|
|
if (DFS_OpenDir(&vi, "", &di)) { |
printf("Error opening root directory\n"); |
printf("Error opening root directory\n"); |
return -1; |
} |
|
|
printf("Readback test\n"); |
if (DFS_OpenFile(&vi,"vmlinux.bin", DFS_READ, sector, &fi)) { |
printf("error opening file\n"); |
|
if (DFS_OpenFile(&vi, "vmlinux.bin", DFS_READ, sector, &fi)) { |
printf("error opening file\n"); |
|
return -1; |
} |
|
printf("fi.filen %d, pointer adress:%d, data:%d \n", fi.filelen, buf_ptr, *buf_ptr); |
|
|
|
printf("fi.filen %d, pointer adress:%d, data:%d \n", fi.filelen, |
buf_ptr, *buf_ptr); |
|
DFS_ReadFile(&fi, sector, buf_ptr, &i, fi.filelen); |
printf("\n read complete %d bytes (expected %d) pointer %d\n", i, fi.filelen, fi.pointer); |
|
|
|
if (global.src_addr > 0) |
{ |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, i); |
} |
printf("\n read complete %d bytes (expected %d) pointer %d\n", i, |
fi.filelen, fi.pointer); |
|
|
|
if (global.src_addr > 0) { |
/* the point of no return */ |
printf("tboot: copying 0x%lx -> 0x0, image size 0x%x...\n", |
global.src_addr, i); |
} |
|
// Disable timer: clear it all! |
mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE); |
mtspr(SPR_TTMR, 0); |
|
// Put the copyboot program at 24MB mark in memory |
#define COPYBOOT_LOCATION (1024*1024*24) |
printf("tboot: relocating copy loop to 0x%x ...\n", (unsigned long)COPYBOOT_LOCATION); |
// Setup where we'll copy the relocation function to |
void (*relocated_function)(unsigned long, unsigned long, unsigned long, int) |
= (void*) COPYBOOT_LOCATION; |
// Now copy the function there, 32 words worth, increase this if needed... |
relocate_code((void*)COPYBOOT_LOCATION, copy_and_boot, 32); |
// Indicate we'll jump there... |
printf("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", i, (unsigned long) global.src_addr); |
// Now do the copy and boot |
(*relocated_function)(global.src_addr, 0x0, 0x0 + i, 0); |
|
return 0; |
|
// Disable timer: clear it all! |
mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_TEE); |
mtspr(SPR_TTMR, 0); |
|
// Put the copyboot program at 24MB mark in memory |
#define COPYBOOT_LOCATION (1024*1024*24) |
printf("tboot: relocating copy loop to 0x%x ...\n", |
(unsigned long)COPYBOOT_LOCATION); |
// Setup where we'll copy the relocation function to |
void (*relocated_function) (unsigned long, unsigned long, unsigned long, |
int) |
= (void *)COPYBOOT_LOCATION; |
// Now copy the function there, 32 words worth, increase this if needed... |
relocate_code((void *)COPYBOOT_LOCATION, copy_and_boot, 32); |
// Indicate we'll jump there... |
printf |
("tboot: Relocate (%d bytes from 0x%x to 0) and boot image, ...\n", |
i, (unsigned long)global.src_addr); |
// Now do the copy and boot |
(*relocated_function) (global.src_addr, 0x0, 0x0 + i, 0); |
|
return 0; |
|
} |
|
void module_load_init (void) |
void module_load_init(void) |
{ |
|
register_command ("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", "TFTP configuration", tftp_conf_cmd); |
register_command ("tboot", "[<image number>]", "Bootstrap image downloaded via tftp", tboot_cmd); |
register_command ("sdboot", "[<image number>]", "Read image from SD-CARD", sdboot_cmd); |
register_command("tftp_conf", "[ <file> [ <srv_ip> [ <src_addr>]]]", |
"TFTP configuration", tftp_conf_cmd); |
register_command("tboot", "[<image number>]", |
"Bootstrap image downloaded via tftp", tboot_cmd); |
register_command("sdboot", "[<image number>]", |
"Read image from SD-CARD", sdboot_cmd); |
#if 0 |
register_command ("tftp", "[<file> [<srv_ip> [<src_addr>]]]", "TFTP download", tftp_cmd); |
register_command ("copy", "[<dst_addr> [<src_addr [<length>]]]", "Copy memory", copy_cmd); |
register_command ("sboot", "[<image number>]", "Bootstrap image downloaded via serial (Y/X modem)", sboot_cmd); |
register_command ("boot", "[<image number>]", "Bootstrap image copied from flash.", boot_cmd); |
register_command ("del_image", "[<image number>]", "Delete image", del_image_cmd); |
register_command ("save_conf", "", "Save current configuration into flash", save_conf_cmd); |
register_command ("boot_flash", "[<start_addr>]", "Boot image from <start_addr> (default from flash)", boot_flash_cmd); |
register_command("tftp", "[<file> [<srv_ip> [<src_addr>]]]", |
"TFTP download", tftp_cmd); |
register_command("copy", "[<dst_addr> [<src_addr [<length>]]]", |
"Copy memory", copy_cmd); |
register_command("sboot", "[<image number>]", |
"Bootstrap image downloaded via serial (Y/X modem)", |
sboot_cmd); |
register_command("boot", "[<image number>]", |
"Bootstrap image copied from flash.", boot_cmd); |
register_command("del_image", "[<image number>]", "Delete image", |
del_image_cmd); |
register_command("save_conf", "", |
"Save current configuration into flash", |
save_conf_cmd); |
register_command("boot_flash", "[<start_addr>]", |
"Boot image from <start_addr> (default from flash)", |
boot_flash_cmd); |
#endif |
init_load(); |
init_load(); |
|
} |
/orpmon/cmds/eth.c
9,393 → 9,458
extern int tx_pointer_index; |
unsigned long dest_mac_addr[6]; |
|
|
void show_tx_bd(int start, int max) |
{ |
int i; |
|
for(i = start; i <= max; i++) { |
/* Read Tx BD */ |
printf ("LEN:%04lx", REG32(ETH_BD_BASE + (i << 3)) >> 16); |
printf (" RD:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 15) & 0x1); |
printf (" IRQ:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 14) & 0x1); |
printf (" WR:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 13) & 0x1); |
printf (" PAD:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 12) & 0x1); |
printf (" CRC:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 11) & 0x1); |
printf (" UR:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 8) & 0x1); |
printf (" RTRY:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 4) & 0xf); |
printf (" RL:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 3) & 0x1); |
printf (" LC:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 2) & 0x1); |
printf (" DF:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 1) & 0x1); |
printf (" CS:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 0) & 0x1); |
printf ("\nTx Buffer Pointer: %08lx\n", REG32(ETH_BD_BASE + (i << 3) + 4)); |
} |
int i; |
|
for (i = start; i <= max; i++) { |
/* Read Tx BD */ |
printf("LEN:%04lx", REG32(ETH_BD_BASE + (i << 3)) >> 16); |
printf(" RD:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 15) & 0x1); |
printf(" IRQ:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 14) & 0x1); |
printf(" WR:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 13) & 0x1); |
printf(" PAD:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 12) & 0x1); |
printf(" CRC:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 11) & 0x1); |
printf(" UR:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 8) & 0x1); |
printf(" RTRY:%04lx", |
(REG32(ETH_BD_BASE + (i << 3)) >> 4) & 0xf); |
printf(" RL:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 3) & 0x1); |
printf(" LC:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 2) & 0x1); |
printf(" DF:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 1) & 0x1); |
printf(" CS:%04lx", (REG32(ETH_BD_BASE + (i << 3)) >> 0) & 0x1); |
printf("\nTx Buffer Pointer: %08lx\n", |
REG32(ETH_BD_BASE + (i << 3) + 4)); |
} |
} |
|
void show_rx_bd (int start, int max) |
void show_rx_bd(int start, int max) |
{ |
int i; |
unsigned long rx_bd_base, rx_bd_num; |
int i; |
unsigned long rx_bd_base, rx_bd_num; |
|
rx_bd_num = REG32(ETH_REG_BASE + ETH_RXBD_NUM); |
rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2); |
rx_bd_num = REG32(ETH_REG_BASE + ETH_RXBD_NUM); |
rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2); |
|
for(i = start; i <= max; i++){ |
/* Read Rx BD */ |
printf ("LEN:%04lx", REG32(rx_bd_base + (i << 3)) >> 16); |
printf (" E:%04lx", (REG32(rx_bd_base + (i << 3)) >> 15) & 0x1); |
printf (" IRQ:%04lx", (REG32(rx_bd_base + (i << 3)) >> 14) & 0x1); |
printf (" WR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 13) & 0x1); |
printf (" M:%04lx", (REG32(rx_bd_base + (i << 3)) >> 7) & 0x1); |
printf (" OR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 6) & 0x1); |
printf (" IS:%04lx", (REG32(rx_bd_base + (i << 3)) >> 5) & 0x1); |
printf (" DN:%04lx", (REG32(rx_bd_base + (i << 3)) >> 4) & 0x1); |
printf (" TL:%04lx", (REG32(rx_bd_base + (i << 3)) >> 3) & 0x1); |
printf (" SF:%04lx", (REG32(rx_bd_base + (i << 3)) >> 2) & 0x1); |
printf (" CRC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 1) & 0x1); |
printf (" LC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 0) & 0x1); |
printf ("\nRx Buffer Pointer: %08lx\n", REG32(rx_bd_base + (i << 3) + 4)); |
} |
for (i = start; i <= max; i++) { |
/* Read Rx BD */ |
printf("LEN:%04lx", REG32(rx_bd_base + (i << 3)) >> 16); |
printf(" E:%04lx", (REG32(rx_bd_base + (i << 3)) >> 15) & 0x1); |
printf(" IRQ:%04lx", |
(REG32(rx_bd_base + (i << 3)) >> 14) & 0x1); |
printf(" WR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 13) & 0x1); |
printf(" M:%04lx", (REG32(rx_bd_base + (i << 3)) >> 7) & 0x1); |
printf(" OR:%04lx", (REG32(rx_bd_base + (i << 3)) >> 6) & 0x1); |
printf(" IS:%04lx", (REG32(rx_bd_base + (i << 3)) >> 5) & 0x1); |
printf(" DN:%04lx", (REG32(rx_bd_base + (i << 3)) >> 4) & 0x1); |
printf(" TL:%04lx", (REG32(rx_bd_base + (i << 3)) >> 3) & 0x1); |
printf(" SF:%04lx", (REG32(rx_bd_base + (i << 3)) >> 2) & 0x1); |
printf(" CRC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 1) & 0x1); |
printf(" LC:%04lx", (REG32(rx_bd_base + (i << 3)) >> 0) & 0x1); |
printf("\nRx Buffer Pointer: %08lx\n", |
REG32(rx_bd_base + (i << 3) + 4)); |
} |
} |
|
void show_buffer(unsigned long start_addr, unsigned long len) |
{ |
show_mem(start_addr, start_addr + len - 1); |
show_mem(start_addr, start_addr + len - 1); |
} |
|
void show_rx_buffs(int max, int show_all) |
{ |
|
int i; |
unsigned long rx_bd_base, rx_bd_num; |
int i; |
unsigned long rx_bd_base, rx_bd_num; |
|
rx_bd_num = REG32(ETH_REG_BASE + ETH_RXBD_NUM); |
rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2); |
rx_bd_num = REG32(ETH_REG_BASE + ETH_RXBD_NUM); |
rx_bd_base = ETH_BD_BASE + (rx_bd_num << 2); |
|
for(i=0; i<=max; i++) |
{ |
if (!(REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_EMPTY) || show_all) |
{ |
printf ("Rx BD No. %04x located at %08lx\n", i, rx_bd_base + (i << 3)); |
show_rx_bd(i, i); |
show_buffer(REG32(rx_bd_base + (i << 3) + 4), REG32(rx_bd_base + (i << 3)) >> 16); |
printf ("\n"); |
} |
if (REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_WRAP) |
return; |
} |
for (i = 0; i <= max; i++) { |
if (!(REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_EMPTY) |
|| show_all) { |
printf("Rx BD No. %04x located at %08lx\n", i, |
rx_bd_base + (i << 3)); |
show_rx_bd(i, i); |
show_buffer(REG32(rx_bd_base + (i << 3) + 4), |
REG32(rx_bd_base + (i << 3)) >> 16); |
printf("\n"); |
} |
if (REG32(rx_bd_base + (i << 3)) & ETH_RX_BD_WRAP) |
return; |
} |
} |
|
void show_tx_buffs(int max) |
{ |
int i; |
int i; |
|
for(i=0; i<=max; i++) |
{ |
if (1) |
{ |
printf ("Tx BD No. %04x located at %08x\n", i, ETH_BD_BASE + (i << 3)); |
show_tx_bd(i, i); |
show_buffer(REG32(ETH_BD_BASE + (i << 3) + 4), REG32(ETH_BD_BASE + (i << 3)) >> 16); |
printf ("\n"); |
} |
if (REG32(ETH_BD_BASE + (i << 3)) & ETH_TX_BD_WRAP) |
return; |
} |
for (i = 0; i <= max; i++) { |
if (1) { |
printf("Tx BD No. %04x located at %08x\n", i, |
ETH_BD_BASE + (i << 3)); |
show_tx_bd(i, i); |
show_buffer(REG32(ETH_BD_BASE + (i << 3) + 4), |
REG32(ETH_BD_BASE + (i << 3)) >> 16); |
printf("\n"); |
} |
if (REG32(ETH_BD_BASE + (i << 3)) & ETH_TX_BD_WRAP) |
return; |
} |
} |
|
void show_phy_reg (unsigned long start_addr, unsigned long stop_addr) |
void show_phy_reg(unsigned long start_addr, unsigned long stop_addr) |
{ |
|
unsigned long addr; |
unsigned long addr; |
|
if (start_addr == stop_addr) |
{ |
printf ("\nSet MII RGAD ADDRESS to %08lx", start_addr); |
printf ("\nMII Command = Read Status\n"); |
} |
if (start_addr == stop_addr) { |
printf("\nSet MII RGAD ADDRESS to %08lx", start_addr); |
printf("\nMII Command = Read Status\n"); |
} |
|
for (addr = start_addr; addr <= stop_addr; addr++) |
{ |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr<<8; |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_RSTAT; |
for (addr = start_addr; addr <= stop_addr; addr++) { |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr << 8; |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_RSTAT; |
|
printf ("PHY %04lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS) & 0x1f); |
printf (", addr %04lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS) >> 8); |
printf (": %08lx\n", REG32(ETH_REG_BASE + ETH_MIIRX_DATA)); |
} |
printf("PHY %04lx", |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) & 0x1f); |
printf(", addr %04lx", |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) >> 8); |
printf(": %08lx\n", REG32(ETH_REG_BASE + ETH_MIIRX_DATA)); |
} |
} |
|
void set_phy_reg (unsigned long addr, unsigned long val) |
void set_phy_reg(unsigned long addr, unsigned long val) |
{ |
printf ("\nSet MII RGAD ADDRESS to %08lx", addr); |
printf("\nSet MII RGAD ADDRESS to %08lx", addr); |
|
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr<<8; |
REG32(ETH_REG_BASE + ETH_MIIADDRESS) = addr << 8; |
|
printf ("\nMII Command = Write Control Data\n"); |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_WCTRLDATA; |
printf("\nMII Command = Write Control Data\n"); |
REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_WCTRLDATA; |
|
REG32(ETH_REG_BASE + ETH_MIITX_DATA) = val; |
REG32(ETH_REG_BASE + ETH_MIITX_DATA) = val; |
|
show_phy_reg(addr, addr); |
show_phy_reg(addr, addr); |
} |
|
void send_packet (unsigned long len, unsigned long start_data, int num_of_packets) |
void send_packet(unsigned long len, unsigned long start_data, |
int num_of_packets) |
{ |
unsigned long i, TxBD; |
unsigned long i, TxBD; |
|
while (num_of_packets--) { |
unsigned long *data = (unsigned long *)eth_get_tx_buf (); |
while (num_of_packets--) { |
unsigned long *data = (unsigned long *)eth_get_tx_buf(); |
|
/* Set dest & src address */ |
*data++ = dest_mac_addr[0] << 24 | |
dest_mac_addr[1] << 16 | |
dest_mac_addr[2] << 8 | |
dest_mac_addr[3] << 0; |
/* Set dest & src address */ |
*data++ = dest_mac_addr[0] << 24 | |
dest_mac_addr[1] << 16 | |
dest_mac_addr[2] << 8 | dest_mac_addr[3] << 0; |
|
*data++ = dest_mac_addr[4] << 24 | |
dest_mac_addr[5] << 16 | |
ETH_MACADDR0 << 8 | |
ETH_MACADDR1 << 0; |
*data++ = dest_mac_addr[4] << 24 | |
dest_mac_addr[5] << 16 | |
ETH_MACADDR0 << 8 | ETH_MACADDR1 << 0; |
|
*data++ = ETH_MACADDR2 << 24 | |
ETH_MACADDR3 << 16 | |
ETH_MACADDR4 << 8 | |
ETH_MACADDR5 << 0; |
*data++ = ETH_MACADDR2 << 24 | |
ETH_MACADDR3 << 16 | ETH_MACADDR4 << 8 | ETH_MACADDR5 << 0; |
|
/* Write data to buffer */ |
for(i = 12; i < len; i += 4) |
*data++ = (i + start_data - 12) << 24 | (i + start_data + 1 - 12) << 16 | |
(i + start_data + 2 - 12) << 8 | (i + start_data + 3 - 12); |
/* Write data to buffer */ |
for (i = 12; i < len; i += 4) |
*data++ = |
(i + start_data - 12) << 24 | (i + start_data + 1 - |
12) << 16 | (i + |
start_data |
+ 2 - |
12) << 8 |
| (i + start_data + 3 - 12); |
|
eth_send (data, len); |
printf ("."); |
} |
eth_send(data, len); |
printf("."); |
} |
} |
|
int eth_init_cmd (int argc, char *argv[]) |
int eth_init_cmd(int argc, char *argv[]) |
{ |
if (argc) return -1; |
eth_init (0); |
return 0; |
if (argc) |
return -1; |
eth_init(0); |
return 0; |
} |
|
int show_txbd_cmd (int argc, char *argv[]) |
int show_txbd_cmd(int argc, char *argv[]) |
{ |
int i; |
int start, max; |
|
if (argc == 1) show_tx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0)); |
else if (argc == 2) show_tx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0)); |
else show_tx_bd (0, 63); |
return 0; |
int i; |
int start, max; |
|
if (argc == 1) |
show_tx_bd(strtoul(argv[0], NULL, 0), |
strtoul(argv[0], NULL, 0)); |
else if (argc == 2) |
show_tx_bd(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0)); |
else |
show_tx_bd(0, 63); |
return 0; |
} |
|
int show_rxbd_cmd (int argc, char *argv[]) |
int show_rxbd_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) show_rx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0)); |
else if (argc == 2) show_rx_bd (strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0)); |
else show_rx_bd (0, 63); |
return 0; |
if (argc == 1) |
show_rx_bd(strtoul(argv[0], NULL, 0), |
strtoul(argv[0], NULL, 0)); |
else if (argc == 2) |
show_rx_bd(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0)); |
else |
show_rx_bd(0, 63); |
return 0; |
} |
|
int send_packet_cmd (int argc, char *argv[]) |
int send_packet_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) send_packet(strtoul (argv[0], NULL, 0), 31, 1); |
else if (argc == 2) send_packet(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0), 1); |
else if (argc == 3) send_packet(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0), strtoul (argv[2], NULL, 0)); |
else return -1; |
return 0; |
if (argc == 1) |
send_packet(strtoul(argv[0], NULL, 0), 31, 1); |
else if (argc == 2) |
send_packet(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0), 1); |
else if (argc == 3) |
send_packet(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0), strtoul(argv[2], NULL, |
0)); |
else |
return -1; |
return 0; |
} |
|
int set_dest_addr_cmd (int argc, char *argv[]) |
int set_dest_addr_cmd(int argc, char *argv[]) |
{ |
if (argc == 3) { |
dest_mac_addr[0] = (strtoul (argv[0], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[1] = (strtoul (argv[0], NULL, 0) >> 0) & 0xff; |
dest_mac_addr[2] = (strtoul (argv[1], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[3] = (strtoul (argv[1], NULL, 0) >> 0) & 0xff; |
dest_mac_addr[4] = (strtoul (argv[2], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[5] = (strtoul (argv[2], NULL, 0) >> 0) & 0xff; |
} else return -1; |
return 0; |
if (argc == 3) { |
dest_mac_addr[0] = (strtoul(argv[0], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[1] = (strtoul(argv[0], NULL, 0) >> 0) & 0xff; |
dest_mac_addr[2] = (strtoul(argv[1], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[3] = (strtoul(argv[1], NULL, 0) >> 0) & 0xff; |
dest_mac_addr[4] = (strtoul(argv[2], NULL, 0) >> 8) & 0xff; |
dest_mac_addr[5] = (strtoul(argv[2], NULL, 0) >> 0) & 0xff; |
} else |
return -1; |
return 0; |
} |
|
int init_txbd_pool_cmd (int argc, char *argv[]) |
int init_txbd_pool_cmd(int argc, char *argv[]) |
{ |
#if 0 |
if (argc == 1) init_tx_bd_pool(strtoul (argv[0], NULL, 0)); |
else return -1; |
if (argc == 1) |
init_tx_bd_pool(strtoul(argv[0], NULL, 0)); |
else |
return -1; |
#endif |
return 0; |
return 0; |
} |
|
int init_rxbd_pool_cmd (int argc, char *argv[]) |
int init_rxbd_pool_cmd(int argc, char *argv[]) |
{ |
//if (argc == 1) init_rx_bd_pool(strtoul (argv[0], NULL, 0)); |
//else return -1; |
init_rx_bd_pool(); |
//if (argc == 1) init_rx_bd_pool(strtoul (argv[0], NULL, 0)); |
//else return -1; |
init_rx_bd_pool(); |
|
return 0; |
return 0; |
} |
|
int show_phy_reg_cmd (int argc, char *argv[]) |
int show_phy_reg_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) show_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[0], NULL, 0)); |
else if (argc == 2) show_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0)); |
else show_phy_reg(0, 30); |
return 0; |
if (argc == 1) |
show_phy_reg(strtoul(argv[0], NULL, 0), |
strtoul(argv[0], NULL, 0)); |
else if (argc == 2) |
show_phy_reg(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0)); |
else |
show_phy_reg(0, 30); |
return 0; |
} |
|
int set_phy_reg_cmd (int argc, char *argv[]) |
int set_phy_reg_cmd(int argc, char *argv[]) |
{ |
if (argc == 2) set_phy_reg(strtoul (argv[0], NULL, 0), strtoul (argv[1], NULL, 0)); |
else return -1; |
return 0; |
if (argc == 2) |
set_phy_reg(strtoul(argv[0], NULL, 0), |
strtoul(argv[1], NULL, 0)); |
else |
return -1; |
return 0; |
} |
|
int show_mac_regs_cmd (int argc, char *argv[]) |
int show_mac_regs_cmd(int argc, char *argv[]) |
{ |
if (argc) return -1; |
printf ("\n %08x", ETH_REG_BASE + ETH_MODER); |
printf (" MODER: %08lx",REG32(ETH_REG_BASE + ETH_MODER)); |
if (argc) |
return -1; |
printf("\n %08x", ETH_REG_BASE + ETH_MODER); |
printf(" MODER: %08lx", REG32(ETH_REG_BASE + ETH_MODER)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_INT); |
printf (" INT: %08lx", REG32(ETH_REG_BASE + ETH_INT)); |
printf("\n %08x", ETH_REG_BASE + ETH_INT); |
printf(" INT: %08lx", REG32(ETH_REG_BASE + ETH_INT)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_INT_MASK); |
printf (" INT_MASK: %08lx", REG32(ETH_REG_BASE + ETH_INT_MASK)); |
printf("\n %08x", ETH_REG_BASE + ETH_INT_MASK); |
printf(" INT_MASK: %08lx", REG32(ETH_REG_BASE + ETH_INT_MASK)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_IPGT); |
printf (" IPGT: %08lx", REG32(ETH_REG_BASE + ETH_IPGT)); |
printf("\n %08x", ETH_REG_BASE + ETH_IPGT); |
printf(" IPGT: %08lx", REG32(ETH_REG_BASE + ETH_IPGT)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_IPGR1); |
printf (" IPGR1: %08lx", REG32(ETH_REG_BASE + ETH_IPGR1)); |
printf("\n %08x", ETH_REG_BASE + ETH_IPGR1); |
printf(" IPGR1: %08lx", REG32(ETH_REG_BASE + ETH_IPGR1)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_IPGR2); |
printf (" IPGR2: %08lx", REG32(ETH_REG_BASE + ETH_IPGR2)); |
printf("\n %08x", ETH_REG_BASE + ETH_IPGR2); |
printf(" IPGR2: %08lx", REG32(ETH_REG_BASE + ETH_IPGR2)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_PACKETLEN); |
printf (" PACKETLEN: %08lx", REG32(ETH_REG_BASE + ETH_PACKETLEN)); |
printf("\n %08x", ETH_REG_BASE + ETH_PACKETLEN); |
printf(" PACKETLEN: %08lx", REG32(ETH_REG_BASE + ETH_PACKETLEN)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_COLLCONF); |
printf (" COLLCONF: %08lx", REG32(ETH_REG_BASE + ETH_COLLCONF)); |
printf("\n %08x", ETH_REG_BASE + ETH_COLLCONF); |
printf(" COLLCONF: %08lx", REG32(ETH_REG_BASE + ETH_COLLCONF)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_RXBD_NUM); |
printf (" RX_BD_NUM: %08lx", REG32(ETH_REG_BASE + ETH_RXBD_NUM)); |
printf("\n %08x", ETH_REG_BASE + ETH_RXBD_NUM); |
printf(" RX_BD_NUM: %08lx", REG32(ETH_REG_BASE + ETH_RXBD_NUM)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_CTRLMODER); |
printf (" CTRLMODER: %08lx", REG32(ETH_REG_BASE + ETH_CTRLMODER)); |
printf("\n %08x", ETH_REG_BASE + ETH_CTRLMODER); |
printf(" CTRLMODER: %08lx", REG32(ETH_REG_BASE + ETH_CTRLMODER)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIIMODER); |
printf (" MIIMODER: %08lx", REG32(ETH_REG_BASE + ETH_MIIMODER)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIIMODER); |
printf(" MIIMODER: %08lx", REG32(ETH_REG_BASE + ETH_MIIMODER)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIICOMMAND); |
printf (" MIICOMMAND: %08lx", REG32(ETH_REG_BASE + ETH_MIICOMMAND)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIICOMMAND); |
printf(" MIICOMMAND: %08lx", REG32(ETH_REG_BASE + ETH_MIICOMMAND)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIIADDRESS); |
printf (" MIIADDRESS: %08lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIIADDRESS); |
printf(" MIIADDRESS: %08lx", REG32(ETH_REG_BASE + ETH_MIIADDRESS)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIITX_DATA); |
printf (" MIITX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIITX_DATA)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIITX_DATA); |
printf(" MIITX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIITX_DATA)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIIRX_DATA); |
printf (" MIIRX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIIRX_DATA)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIIRX_DATA); |
printf(" MIIRX_DATA: %08lx", REG32(ETH_REG_BASE + ETH_MIIRX_DATA)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MIISTATUS); |
printf (" MIISTATUS: %08lx", REG32(ETH_REG_BASE + ETH_MIISTATUS)); |
printf("\n %08x", ETH_REG_BASE + ETH_MIISTATUS); |
printf(" MIISTATUS: %08lx", REG32(ETH_REG_BASE + ETH_MIISTATUS)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR0); |
printf (" MAC_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR0)); |
printf("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR0); |
printf(" MAC_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR0)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR1); |
printf (" MAC_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR1)); |
printf("\n %08x", ETH_REG_BASE + ETH_MAC_ADDR1); |
printf(" MAC_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_MAC_ADDR1)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR0); |
printf (" ETH_HASH_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR0)); |
printf("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR0); |
printf(" ETH_HASH_ADDR0: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR0)); |
|
printf ("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR1); |
printf (" ETH_HASH_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR1)); |
printf("\n %08x", ETH_REG_BASE + ETH_HASH_ADDR1); |
printf(" ETH_HASH_ADDR1: %08lx", REG32(ETH_REG_BASE + ETH_HASH_ADDR1)); |
|
printf ("\n"); |
return 0; |
printf("\n"); |
return 0; |
} |
|
int eth_int_enable_cmd (int argc, char *argv[]) |
int eth_int_enable_cmd(int argc, char *argv[]) |
{ |
if (argc) return -1; |
eth_int_enable (); |
return 0; |
if (argc) |
return -1; |
eth_int_enable(); |
return 0; |
} |
int show_rx_buffs_cmd (int argc, char *argv[]) |
|
int show_rx_buffs_cmd(int argc, char *argv[]) |
{ |
if (argc == 0) show_rx_buffs(63, 0); |
else if (argc == 1) show_rx_buffs(63, 1); |
else return -1; |
return 0; |
if (argc == 0) |
show_rx_buffs(63, 0); |
else if (argc == 1) |
show_rx_buffs(63, 1); |
else |
return -1; |
return 0; |
} |
|
int show_tx_buffs_cmd (int argc, char *argv[]) |
int show_tx_buffs_cmd(int argc, char *argv[]) |
{ |
if (argc == 0) show_tx_buffs(63); |
else return -1; |
return 0; |
if (argc == 0) |
show_tx_buffs(63); |
else |
return -1; |
return 0; |
} |
#endif |
|
int eth_conf_cmd(int argc, char *argv[]) |
{ |
switch(argc) { |
case 0: |
printf("IP: %s", inet_ntoa(global.ip)); |
printf("\nmask: %s", inet_ntoa(global.mask)); |
printf("\nGW: %s", inet_ntoa(global.gw_ip)); |
return 0; |
case 3: |
global.gw_ip = inet_aton(argv[2]); |
case 2: |
global.mask = inet_aton(argv[1]); |
case 1: |
global.ip = inet_aton(argv[0]); |
break; |
} |
printf("Restarting network with new parameters..."); |
NetStartAgain(); |
switch (argc) { |
case 0: |
printf("IP: %s", inet_ntoa(global.ip)); |
printf("\nmask: %s", inet_ntoa(global.mask)); |
printf("\nGW: %s", inet_ntoa(global.gw_ip)); |
return 0; |
case 3: |
global.gw_ip = inet_aton(argv[2]); |
case 2: |
global.mask = inet_aton(argv[1]); |
case 1: |
global.ip = inet_aton(argv[0]); |
break; |
} |
printf("Restarting network with new parameters..."); |
NetStartAgain(); |
|
return 0; |
return 0; |
} |
|
void toggle_eth_traffic_monitor_cmd(void) |
{ |
eth_toggle_traffic_mon(); |
eth_toggle_traffic_mon(); |
} |
|
|
void module_eth_init (void) |
void module_eth_init(void) |
{ |
#if 1 |
register_command ("eth_init", "", "init ethernet", eth_init_cmd); |
register_command ("show_txbd", "[<start BD>] [<max>]", "show Tx buffer desc", show_txbd_cmd); |
register_command ("show_rxbd", "[<start BD>] [<max>]", "show Rx buffer desc", show_rxbd_cmd); |
register_command ("send_packet", "<length> [<start data>] [<num_of_packets>]", "create & send packet(s)", send_packet_cmd); |
register_command ("set_dest_addr", "<addrhi> <addrmid> <addrlo>", "set destination address (for send_packet)", set_dest_addr_cmd); |
register_command ("init_txbd_pool", "<max>", "initialize Tx buffer descriptors", init_txbd_pool_cmd); |
register_command ("init_rxbd_pool", "<max>", "initialize Rx buffer descriptors", init_rxbd_pool_cmd); |
register_command ("show_phy_reg", "[<start_addr>] [<end addr>]", "show PHY registers", show_phy_reg_cmd); |
register_command ("set_phy_reg", "<addr> <value>", "set PHY register", set_phy_reg_cmd); |
register_command ("show_mac_regs", "", "show all MAC registers", show_mac_regs_cmd); |
register_command ("eth_int_enable", "", "enable ethernet interrupt", eth_int_enable_cmd); |
register_command ("show_rx_buffs", "[<show_all>]", "show receive buffers (optional arg will also show empty buffers)", show_rx_buffs_cmd); |
register_command ("show_tx_buffs", "", "show transmit buffers", show_rx_buffs_cmd); |
register_command ("eth_toggle_mon", "", "Toggle traffic monitor", toggle_eth_traffic_monitor_cmd ); |
register_command("eth_init", "", "init ethernet", eth_init_cmd); |
register_command("show_txbd", "[<start BD>] [<max>]", |
"show Tx buffer desc", show_txbd_cmd); |
register_command("show_rxbd", "[<start BD>] [<max>]", |
"show Rx buffer desc", show_rxbd_cmd); |
register_command("send_packet", |
"<length> [<start data>] [<num_of_packets>]", |
"create & send packet(s)", send_packet_cmd); |
register_command("set_dest_addr", "<addrhi> <addrmid> <addrlo>", |
"set destination address (for send_packet)", |
set_dest_addr_cmd); |
register_command("init_txbd_pool", "<max>", |
"initialize Tx buffer descriptors", |
init_txbd_pool_cmd); |
register_command("init_rxbd_pool", "<max>", |
"initialize Rx buffer descriptors", |
init_rxbd_pool_cmd); |
register_command("show_phy_reg", "[<start_addr>] [<end addr>]", |
"show PHY registers", show_phy_reg_cmd); |
register_command("set_phy_reg", "<addr> <value>", "set PHY register", |
set_phy_reg_cmd); |
register_command("show_mac_regs", "", "show all MAC registers", |
show_mac_regs_cmd); |
register_command("eth_int_enable", "", "enable ethernet interrupt", |
eth_int_enable_cmd); |
register_command("show_rx_buffs", "[<show_all>]", |
"show receive buffers (optional arg will also show empty buffers)", |
show_rx_buffs_cmd); |
register_command("show_tx_buffs", "", "show transmit buffers", |
show_rx_buffs_cmd); |
register_command("eth_toggle_mon", "", "Toggle traffic monitor", |
toggle_eth_traffic_monitor_cmd); |
#endif |
/* Initialize controller */ |
register_command ("eth_conf", "[<ip> [<mask> [<gw>]]]", "Get/set ethernet configuration", eth_conf_cmd); |
/* Initialize controller */ |
register_command("eth_conf", "[<ip> [<mask> [<gw>]]]", |
"Get/set ethernet configuration", eth_conf_cmd); |
#if 0 |
eth_init(); |
printf ("Ethernet not initialized (run eth_init command)\n"); |
init_rx_bd_pool(0); |
init_tx_bd_pool(3); |
eth_init(); |
printf("Ethernet not initialized (run eth_init command)\n"); |
init_rx_bd_pool(0); |
init_tx_bd_pool(3); |
#endif |
} |
|
/orpmon/cmds/global.c
3,88 → 3,109
|
global_struct global; |
|
int src_addr_cmd (int argc, char *argv[]) |
int src_addr_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.src_addr = strtoul (argv[0], 0, 0); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.src_addr = strtoul(argv[0], 0, 0); |
return 0; |
} else |
return -1; |
} |
|
int dst_addr_cmd (int argc, char *argv[]) |
int dst_addr_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.dst_addr = strtoul (argv[0], 0, 0); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.dst_addr = strtoul(argv[0], 0, 0); |
return 0; |
} else |
return -1; |
} |
|
int length_cmd (int argc, char *argv[]) |
int length_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.length = strtoul (argv[0], 0, 0); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.length = strtoul(argv[0], 0, 0); |
return 0; |
} else |
return -1; |
} |
|
int ip_cmd (int argc, char *argv[]) |
int ip_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.ip = parse_ip (argv[0]); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.ip = parse_ip(argv[0]); |
return 0; |
} else |
return -1; |
} |
|
int srv_ip_cmd (int argc, char *argv[]) |
int srv_ip_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.srv_ip = parse_ip (argv[0]); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.srv_ip = parse_ip(argv[0]); |
return 0; |
} else |
return -1; |
} |
|
int erase_method_cmd (int argc, char *argv[]) |
int erase_method_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
int a = strtoul (argv[0], 0, 0); |
if (a < 0 || a > 2) return -1; |
global.erase_method = a; |
return 0; |
} else return -1; |
if (argc == 1) { |
int a = strtoul(argv[0], 0, 0); |
if (a < 0 || a > 2) |
return -1; |
global.erase_method = a; |
return 0; |
} else |
return -1; |
} |
|
int start_addr_cmd (int argc, char *argv[]) |
int start_addr_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) { |
global.start_addr = strtoul (argv[0], 0, 0); |
return 0; |
} else return -1; |
if (argc == 1) { |
global.start_addr = strtoul(argv[0], 0, 0); |
return 0; |
} else |
return -1; |
} |
|
#if HELP_ENABLED |
int globals_cmd (int argc, char *argv[]) |
int globals_cmd(int argc, char *argv[]) |
{ |
const char *erase_method_desc[] = {"do not erase", "fully", "as needed"}; |
if (argc) return -1; |
printf ("src_addr = %08lx\n", global.src_addr); |
printf ("dst_addr = %08lx\n", global.dst_addr); |
printf ("start_addr = %08lx\n", global.start_addr); |
printf ("length = %08lx\n", global.length); |
printf ("ip = %08lx\n", global.ip); |
printf ("srv_ip = %08lx\n", global.srv_ip); |
printf ("erase_method = %i (%s)\n", (int)global.erase_method, erase_method_desc[global.erase_method]); |
return 0; |
const char *erase_method_desc[] = |
{ "do not erase", "fully", "as needed" }; |
if (argc) |
return -1; |
printf("src_addr = %08lx\n", global.src_addr); |
printf("dst_addr = %08lx\n", global.dst_addr); |
printf("start_addr = %08lx\n", global.start_addr); |
printf("length = %08lx\n", global.length); |
printf("ip = %08lx\n", global.ip); |
printf("srv_ip = %08lx\n", global.srv_ip); |
printf("erase_method = %i (%s)\n", (int)global.erase_method, |
erase_method_desc[global.erase_method]); |
return 0; |
} |
#endif /* HELP_ENABLED */ |
|
void module_global_init (void) |
void module_global_init(void) |
{ |
register_command ("src_addr", "<value>", "sets global parameter source address", src_addr_cmd); |
register_command ("dst_addr", "<value>", "sets global parameter destination address", dst_addr_cmd); |
register_command ("start_addr", "<value>", "sets start address", start_addr_cmd); |
register_command ("length", "<value>", "sets global parameter length", length_cmd); |
register_command ("ip", "<value> <value> <value>", "sets global parameter ip address", ip_cmd); |
register_command ("srv_ip", "<value> <value> <value>", "sets global parameter server ip address", srv_ip_cmd); |
register_command ("erase_method", "<value> <value> <value>", "sets flash erase method (0 = do not erase, 1 = fully, 2 = as needed)", erase_method_cmd); |
if (HELP_ENABLED) register_command ("globals", "", "show globals", globals_cmd); |
register_command("src_addr", "<value>", |
"sets global parameter source address", src_addr_cmd); |
register_command("dst_addr", "<value>", |
"sets global parameter destination address", |
dst_addr_cmd); |
register_command("start_addr", "<value>", "sets start address", |
start_addr_cmd); |
register_command("length", "<value>", "sets global parameter length", |
length_cmd); |
register_command("ip", "<value> <value> <value>", |
"sets global parameter ip address", ip_cmd); |
register_command("srv_ip", "<value> <value> <value>", |
"sets global parameter server ip address", srv_ip_cmd); |
register_command("erase_method", "<value> <value> <value>", |
"sets flash erase method (0 = do not erase, 1 = fully, 2 = as needed)", |
erase_method_cmd); |
if (HELP_ENABLED) |
register_command("globals", "", "show globals", globals_cmd); |
} |
/orpmon/cmds/touch.c
2,50 → 2,47
#include "support.h" |
#include "spi.h" |
|
int touch_cmd (int argc, char *argv[]) |
int touch_cmd(int argc, char *argv[]) |
{ |
unsigned long x, y, z1, z2; |
float res; |
unsigned long x, y, z1, z2; |
float res; |
|
if (argc == 0) { |
printf("usage: -r read coordinates\n"); |
printf(" -c read coordinates in a loop (press any key to exit)\n"); |
} |
else if (argc == 1) { |
if (!strcmp(argv[0], "-r")) { |
spi_init(0, 1000000, 21, 0, 1, 0); |
printf("X = %.3lx\n", spi_xmit(0xd3l << 13) & 0xfff); |
printf("Y = %.3lx\n", spi_xmit(0x93l << 13) & 0xfff); |
} |
else if (!strcmp(argv[0], "-c")) { |
spi_init(0, 1000000, 21, 0, 1, 0); |
while (1) { |
x = spi_xmit(0xd3l << 13) & 0xfff; |
z1 = spi_xmit(0xb3l << 13) & 0xfff; |
z2 = spi_xmit(0xc3l << 13) & 0xfff; |
res = (z2/z1) - 1; |
res = ((float)x * res)/4096; |
if ((int)res < 20) { |
y = spi_xmit(0x93l << 13) & 0xfff; |
printf("X = %.3lx\n", x); |
printf("Y = %.3lx\n\n", y); |
} |
if (testc()) |
break; |
} |
} |
} |
else { |
printf("usage: -r read coordinates\n"); |
printf(" -c read coordinates in a loop (press any key to exit)\n"); |
} |
if (argc == 0) { |
printf("usage: -r read coordinates\n"); |
printf |
(" -c read coordinates in a loop (press any key to exit)\n"); |
} else if (argc == 1) { |
if (!strcmp(argv[0], "-r")) { |
spi_init(0, 1000000, 21, 0, 1, 0); |
printf("X = %.3lx\n", spi_xmit(0xd3l << 13) & 0xfff); |
printf("Y = %.3lx\n", spi_xmit(0x93l << 13) & 0xfff); |
} else if (!strcmp(argv[0], "-c")) { |
spi_init(0, 1000000, 21, 0, 1, 0); |
while (1) { |
x = spi_xmit(0xd3l << 13) & 0xfff; |
z1 = spi_xmit(0xb3l << 13) & 0xfff; |
z2 = spi_xmit(0xc3l << 13) & 0xfff; |
res = (z2 / z1) - 1; |
res = ((float)x * res) / 4096; |
if ((int)res < 20) { |
y = spi_xmit(0x93l << 13) & 0xfff; |
printf("X = %.3lx\n", x); |
printf("Y = %.3lx\n\n", y); |
} |
if (testc()) |
break; |
} |
} |
} else { |
printf("usage: -r read coordinates\n"); |
printf |
(" -c read coordinates in a loop (press any key to exit)\n"); |
} |
|
return 0; |
return 0; |
} |
|
void module_touch_init (void) |
|
void module_touch_init(void) |
{ |
register_command ("touch", "", "touch screen utility", touch_cmd); |
register_command("touch", "", "touch screen utility", touch_cmd); |
} |
|
|
/orpmon/cmds/atabug.c
19,7 → 19,6
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
*/ |
|
|
#include "support.h" |
#include "common.h" |
#include "atabug.h" |
41,7 → 40,6
/* buffer for ata-data */ |
static unsigned char buf[512]; |
|
|
/**********************************************************************/ |
/* */ |
/* A T A B U G */ |
52,49 → 50,70
|
initializes the ATA core, and registers it with ORPmon |
*/ |
void module_ata_init (void) |
void module_ata_init(void) |
{ |
ata_num_commands = 0; |
ata_num_commands = 0; |
|
register_command ("atabug", "", "ATA debugger. Type 'atabug help' for help", atabug); |
register_command("atabug", "", |
"ATA debugger. Type 'atabug help' for help", atabug); |
|
register_ata_command ("help", "", "Display this help message", atabug_help); |
register_ata_command ("exit", "", "Exit atabug and return to ORPmon", atabug_exit); |
register_ata_command ("open", "<device> [<mode>]", "Opens the requested device. Device=<0|1>, Mode=<r>eadonly|read<w>rite.", ata_open_cmd); |
register_ata_command ("close", "", "Closes the device.", ata_close_cmd); |
register_ata_command ("reset", "<mode>", "Reset ata device(s).", ata_reset_cmd); |
register_ata_command ("enable", "", "Enables ATA host controller, clears all resets", ata_enable_cmd); |
register_ata_command ("dump_dev_regs", "", "Dump the (readable) ata device registers.", ata_dump_device_regs_cmd); |
register_ata_command ("dump_host_regs", "", "Dump the ata host registers.", ata_dump_host_regs_cmd); |
register_ata_command ("exec_cmd", "<cmd>", "Execute ata command <cmd> (hex)", ata_exec_cmd_cmd); |
register_ata_command ("identify_device", "", "Dumps device's IDENTIFY DEVICE block.", ata_identify_device_cmd); |
register_ata_command ("program_timing", "<PIO mode>", "Programs the device to the selected PIO mode.", ata_set_piomode_cmd); |
register_ata_command ("read_sectors", "<startsector> [<sectorcount>]", "Reads sector", ata_read_sectors_cmd); |
register_ata_command ("read_mbr", "<partition>", "Reads the Master Boot Record.", ata_read_mbr_cmd); |
register_ata_command ("read_dosboot", "<sector>", "Reads the device's bootsector (FAT).", ata_read_dosboot_cmd); |
register_ata_command ("select_device", "<device_no>", "Select ata device. device_no=<0|1>", ata_select_device_cmd); |
register_ata_command("help", "", "Display this help message", |
atabug_help); |
register_ata_command("exit", "", "Exit atabug and return to ORPmon", |
atabug_exit); |
register_ata_command("open", "<device> [<mode>]", |
"Opens the requested device. Device=<0|1>, Mode=<r>eadonly|read<w>rite.", |
ata_open_cmd); |
register_ata_command("close", "", "Closes the device.", ata_close_cmd); |
register_ata_command("reset", "<mode>", "Reset ata device(s).", |
ata_reset_cmd); |
register_ata_command("enable", "", |
"Enables ATA host controller, clears all resets", |
ata_enable_cmd); |
register_ata_command("dump_dev_regs", "", |
"Dump the (readable) ata device registers.", |
ata_dump_device_regs_cmd); |
register_ata_command("dump_host_regs", "", |
"Dump the ata host registers.", |
ata_dump_host_regs_cmd); |
register_ata_command("exec_cmd", "<cmd>", |
"Execute ata command <cmd> (hex)", |
ata_exec_cmd_cmd); |
register_ata_command("identify_device", "", |
"Dumps device's IDENTIFY DEVICE block.", |
ata_identify_device_cmd); |
register_ata_command("program_timing", "<PIO mode>", |
"Programs the device to the selected PIO mode.", |
ata_set_piomode_cmd); |
register_ata_command("read_sectors", "<startsector> [<sectorcount>]", |
"Reads sector", ata_read_sectors_cmd); |
register_ata_command("read_mbr", "<partition>", |
"Reads the Master Boot Record.", ata_read_mbr_cmd); |
register_ata_command("read_dosboot", "<sector>", |
"Reads the device's bootsector (FAT).", |
ata_read_dosboot_cmd); |
register_ata_command("select_device", "<device_no>", |
"Select ata device. device_no=<0|1>", |
ata_select_device_cmd); |
} |
|
|
int atabug(int argc, char **argv) |
{ |
|
/* take care of commandline options */ |
if (argc == 0) |
{ |
/* start atabug */ |
while ( !ata_mon_command() ); |
} |
else |
return execute_ata_command(argv[0], argc -1, &argv[1]); |
/* take care of commandline options */ |
if (argc == 0) { |
/* start atabug */ |
while (!ata_mon_command()) ; |
} else |
return execute_ata_command(argv[0], argc - 1, &argv[1]); |
|
return 0; |
return 0; |
} |
|
int atabug_exit(int argc, char **argv) |
{ |
ata_close_cmd(argc, argv); |
return -2; |
ata_close_cmd(argc, argv); |
return -2; |
} |
|
/* |
108,110 → 127,107
/* Process command-line, generate arguments */ |
int ata_mon_command(void) |
{ |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
|
/* Show prompt */ |
printf("\natabug> "); |
|
/* Show prompt */ |
printf ("\natabug> "); |
/* Get characters from UART */ |
c = getc(); |
while (c != '\r' && c != '\f' && c != '\n') { |
if (c == '\b') |
pstr--; |
else |
*pstr++ = c; |
putc(c); |
c = getc(); |
} |
*pstr = '\0'; |
printf("\n"); |
|
/* Skip leading blanks */ |
pstr = str; |
while (isspace(*pstr)) |
pstr++; |
|
/* Get characters from UART */ |
c = getc(); |
while (c != '\r' && c != '\f' && c != '\n') |
{ |
if (c == '\b') |
pstr--; |
else |
*pstr++ = c; |
putc(c); |
c = getc(); |
} |
*pstr = '\0'; |
printf ("\n"); |
/* Get command from the string */ |
command_str = pstr; |
|
/* Skip leading blanks */ |
pstr = str; |
while ( isspace(*pstr) ) pstr++; |
while (1) { |
/* Go to next argument */ |
while (isgraph(*pstr)) |
pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while (isspace(*pstr)) |
pstr++; |
argv[argc++] = pstr; |
} else |
break; |
} |
|
/* Get command from the string */ |
command_str = pstr; |
|
while (1) { |
/* Go to next argument */ |
while ( isgraph(*pstr) ) pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while ( isspace(*pstr) ) pstr++; |
argv[argc++] = pstr; |
} |
else |
break; |
} |
|
return execute_ata_command(command_str, argc, argv); |
return execute_ata_command(command_str, argc, argv); |
} |
|
|
int execute_ata_command(char *command_str, int argc, char **argv) |
{ |
int i, found = 0; |
int i, found = 0; |
|
for (i = 0; i < ata_num_commands; i++) |
if ( !strcmp(command_str, ata_command[i].name) ) |
{ |
switch ( ata_command[i].func(argc, argv) ) |
{ |
case -1: |
printf ("Missing/wrong parameters, usage: %s %s\n", ata_command[i].name, ata_command[i].params); |
break; |
for (i = 0; i < ata_num_commands; i++) |
if (!strcmp(command_str, ata_command[i].name)) { |
switch (ata_command[i].func(argc, argv)) { |
case -1: |
printf |
("Missing/wrong parameters, usage: %s %s\n", |
ata_command[i].name, |
ata_command[i].params); |
break; |
|
case -2: |
return -1; |
} |
case -2: |
return -1; |
} |
|
found++; |
break; |
} |
|
if (!found) |
printf ("Unknown command. Type 'ata help' for help.\n"); |
found++; |
break; |
} |
|
return 0; |
if (!found) |
printf("Unknown command. Type 'ata help' for help.\n"); |
|
return 0; |
} |
|
|
void register_ata_command (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]) ) |
void register_ata_command(const char *name, const char *params, |
const char *help, int (*func) (int argc, |
char *argv[])) |
{ |
if (ata_num_commands < MAX_ATA_COMMANDS) |
{ |
ata_command[ata_num_commands].name = name; |
ata_command[ata_num_commands].params = params; |
ata_command[ata_num_commands].help = help; |
ata_command[ata_num_commands].func = func; |
ata_num_commands++; |
} |
else |
printf ("ata-command '%s' ignored; MAX_COMMANDS limit reached\n", name); |
if (ata_num_commands < MAX_ATA_COMMANDS) { |
ata_command[ata_num_commands].name = name; |
ata_command[ata_num_commands].params = params; |
ata_command[ata_num_commands].help = help; |
ata_command[ata_num_commands].func = func; |
ata_num_commands++; |
} else |
printf("ata-command '%s' ignored; MAX_COMMANDS limit reached\n", |
name); |
} |
|
int atabug_help(int argc, char **argv) |
{ |
int i; |
int i; |
|
for (i = 0; i < ata_num_commands; i++) |
printf ("%-15s %-17s -%s\n", ata_command[i].name, ata_command[i].params, ata_command[i].help); |
for (i = 0; i < ata_num_commands; i++) |
printf("%-15s %-17s -%s\n", ata_command[i].name, |
ata_command[i].params, ata_command[i].help); |
|
return 0; |
return 0; |
} |
|
|
|
|
/**********************************************************************/ |
/* */ |
/* A T A B U G C O M M A N D S E T */ |
225,12 → 241,11
*/ |
int ata_close_cmd(int argc, char **argv) |
{ |
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
|
return ata_release(inode, filp); |
return ata_release(inode, filp); |
} |
|
|
/* |
A T A _ D U M P _ D E V I C E _ R E G S |
|
239,23 → 254,28
*/ |
int ata_dump_device_regs_cmd(int argc, char **argv) |
{ |
if (argc) |
printf("\nWARNING: Ignoring invalid argument(s)\n\n"); |
if (argc) |
printf("\nWARNING: Ignoring invalid argument(s)\n\n"); |
|
printf("Alternate status register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_ASR)); |
printf("Cylinder high register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_CHR)); |
printf("Cylinder low register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_CLR)); |
printf("Device head register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_DHR)); |
printf("Error register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_ERR)); |
printf("Sector count register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_SCR)); |
printf("Sector number register : 0x%02lX\n", |
REG32(ATA_BASE_ADDR + ATA_SNR)); |
printf("Status register (see alternate status register)\n"); |
|
printf("Alternate status register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_ASR) ); |
printf("Cylinder high register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_CHR) ); |
printf("Cylinder low register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_CLR) ); |
printf("Device head register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_DHR) ); |
printf("Error register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_ERR) ); |
printf("Sector count register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_SCR) ); |
printf("Sector number register : 0x%02lX\n", REG32(ATA_BASE_ADDR + ATA_SNR) ); |
printf("Status register (see alternate status register)\n" ); |
|
return 0; |
return 0; |
} |
|
|
/* |
A T A _ D U M P _ H O S T _ R E G S |
|
263,22 → 283,27
*/ |
int ata_dump_host_regs_cmd(int argc, char **argv) |
{ |
if (argc) |
printf("\nWARNING: Ignoring invalid argument(s)\n\n"); |
if (argc) |
printf("\nWARNING: Ignoring invalid argument(s)\n\n"); |
|
printf("Control register CTRL : 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_CTRL)); |
printf("Status register STAT : 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_STAT)); |
printf("Pio command timing register PCTR : 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_PCTR)); |
printf("Pio fast timing register (device0) PFTR0: 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_PFTR0)); |
printf("Pio fast timing register (device1) PFTR1: 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_PFTR1)); |
printf("Dma timing register (device0) DTR0 : 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_DTR0)); |
printf("Dma timing register (device1) DTR1 : 0x%08lX\n", |
REG32(ATA_BASE_ADDR + ATA_DTR1)); |
|
printf("Control register CTRL : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_CTRL) ); |
printf("Status register STAT : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_STAT) ); |
printf("Pio command timing register PCTR : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PCTR) ); |
printf("Pio fast timing register (device0) PFTR0: 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PFTR0) ); |
printf("Pio fast timing register (device1) PFTR1: 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_PFTR1) ); |
printf("Dma timing register (device0) DTR0 : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_DTR0) ); |
printf("Dma timing register (device1) DTR1 : 0x%08lX\n", REG32(ATA_BASE_ADDR + ATA_DTR1) ); |
|
return 0; |
return 0; |
} |
|
|
/* |
A T A _ E N A B L E |
|
286,29 → 311,28
*/ |
int ata_enable_cmd(int argc, char **argv) |
{ |
if (argc != 0) |
printf("Ignoring invalid parameters\n"); |
if (argc != 0) |
printf("Ignoring invalid parameters\n"); |
|
inode->i_rdev = (ATA_BASE_ADDR >> 16); |
inode->i_rdev = (ATA_BASE_ADDR >> 16); |
|
// clear hardware reset bit |
if ( ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_HW_RST) ) |
return -1; |
// clear hardware reset bit |
if (ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_HW_RST)) |
return -1; |
|
// clear software reset bit |
if ( ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_SW_RST) ) |
return -1; |
// clear software reset bit |
if (ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, CLR | ARG_SW_RST)) |
return -1; |
|
// enable ATA Hostcontroller core |
if ( ata_ioctl(inode, filp, ATA_IOCTL_ENABLE_HOST, 0) ) |
return -1; |
// enable ATA Hostcontroller core |
if (ata_ioctl(inode, filp, ATA_IOCTL_ENABLE_HOST, 0)) |
return -1; |
|
printf("ATA host controller enabled\n"); |
printf("ATA host controller enabled\n"); |
|
return 0; |
return 0; |
} |
|
|
/* |
A T A _ E X E C _ C M D |
|
316,16 → 340,15
*/ |
int ata_exec_cmd_cmd(int argc, char **argv) |
{ |
if (argc != 1) |
return -1; |
if (argc != 1) |
return -1; |
|
inode->i_rdev = (ATA_BASE_ADDR >> 16); |
|
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, strtoul(*argv, argv, 16) ); |
return 0; |
inode->i_rdev = (ATA_BASE_ADDR >> 16); |
|
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, strtoul(*argv, argv, 16)); |
return 0; |
} |
|
|
/* |
A T A _ I D E N T I F Y _ D E V I C E |
|
333,37 → 356,35
*/ |
int ata_identify_device_cmd(int argc, char **argv) |
{ |
unsigned char checksum; |
unsigned char checksum; |
|
if (argc != 0) |
printf("Ignoring invalid parameters\n"); |
if (argc != 0) |
printf("Ignoring invalid parameters\n"); |
|
/* check for busy flag */ |
if (ata_dev_busy(ATA_BASE_ADDR)) |
printf("Selected ata device busy, ignoring command\n"); |
else { |
/* execute identify device */ |
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE); |
|
/* check for busy flag */ |
if ( ata_dev_busy(ATA_BASE_ADDR) ) |
printf("Selected ata device busy, ignoring command\n"); |
else |
{ |
/* execute identify device */ |
ata_ioctl(inode, filp, ATA_IOCTL_EXEC_CMD, IDENTIFY_DEVICE); |
/* read block from ata-device */ |
buf[0] = 0; |
buf[1] = 1; |
ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long)buf); |
|
/* read block from ata-device */ |
buf[0] = 0; |
buf[1] = 1; |
ata_ioctl(inode, filp, ATA_IOCTL_READ, (unsigned long) buf); |
/* dump data to the screen */ |
checksum = atabug_dump_data(buf, 512); |
|
/* dump data to the screen */ |
checksum = atabug_dump_data(buf, 512); |
|
if (buf[512] == 0xa5) |
printf("Checksum = 0x%02X (%s)\n", checksum, checksum ? "error" : "OK"); |
else |
printf("No checksum supported\n"); |
} |
return 0; |
if (buf[512] == 0xa5) |
printf("Checksum = 0x%02X (%s)\n", checksum, |
checksum ? "error" : "OK"); |
else |
printf("No checksum supported\n"); |
} |
return 0; |
} |
|
|
/* |
A T A _ O P E N |
|
371,32 → 392,33
*/ |
int ata_open_cmd(int argc, char **argv) |
{ |
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
|
filp->f_mode = FMODE_READ; |
filp->f_mode = FMODE_READ; |
|
if (*argv[1] == 'w') |
filp->f_mode |= FMODE_WRITE; |
if (*argv[1] == 'w') |
filp->f_mode |= FMODE_WRITE; |
|
switch( ata_open(inode, filp) ) { |
case EOPENIDEV: |
printf( "Error: Invalid device (invalid MINOR %02X)\n", MINOR(inode->i_rdev) ); |
break; |
switch (ata_open(inode, filp)) { |
case EOPENIDEV: |
printf("Error: Invalid device (invalid MINOR %02X)\n", |
MINOR(inode->i_rdev)); |
break; |
|
case EOPENNODEV: |
printf( "Error: Requested device not found\n" ); |
break; |
case EOPENNODEV: |
printf("Error: Requested device not found\n"); |
break; |
|
case EOPENIHOST: |
printf( "Error: Invalid host (invalid MAJOR %02X)\n", MAJOR(inode->i_rdev) ); |
default: |
break; |
} |
case EOPENIHOST: |
printf("Error: Invalid host (invalid MAJOR %02X)\n", |
MAJOR(inode->i_rdev)); |
default: |
break; |
} |
|
return 0; |
return 0; |
} |
|
|
/* |
A T A _ S E T _ P I O M O D E |
|
404,10 → 426,9
*/ |
int ata_set_piomode_cmd(int argc, char **argv) |
{ |
return 0; |
return 0; |
} |
|
|
/* |
A T A _ R E A D _ S E C T O R S |
|
415,56 → 436,54
*/ |
int ata_read_sectors_cmd(int argc, char **argv) |
{ |
struct request request; |
unsigned long sector_cnt, sector; |
struct request request; |
unsigned long sector_cnt, sector; |
|
sector = strtoul(argv[0], argv, 10); |
sector = strtoul(argv[0], argv, 10); |
|
switch (argc) { |
case 2: |
sector_cnt = strtoul(argv[1], argv, 10); |
break; |
switch (argc) { |
case 2: |
sector_cnt = strtoul(argv[1], argv, 10); |
break; |
|
case 1: |
sector_cnt = 1; |
break; |
case 1: |
sector_cnt = 1; |
break; |
|
default: |
return -1; |
} |
default: |
return -1; |
} |
|
if ( !sector_cnt ) |
{ |
printf( "Invalid number of sectors.\n" ); |
return 0; |
} |
if (!sector_cnt) { |
printf("Invalid number of sectors.\n"); |
return 0; |
} |
|
/* check for busy flag */ |
if ( ata_dev_busy(ATA_BASE_ADDR) ) |
printf("Selected ata device busy, ignoring command\n"); |
else |
{ |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = sector; |
request.nr_sectors = sector_cnt; |
request.buffer = buf; |
/* check for busy flag */ |
if (ata_dev_busy(ATA_BASE_ADDR)) |
printf("Selected ata device busy, ignoring command\n"); |
else { |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = sector; |
request.nr_sectors = sector_cnt; |
request.buffer = buf; |
|
if ( ata_request(inode, filp, &request) ) |
{ |
printf("Error while executing READ_SECTOR(S) command\n"); |
printf("Status register = 0x%02lX, error register = 0x%02lX\n", ata_astatus(ATA_BASE_ADDR), ata_error(ATA_BASE_ADDR) ); |
if (ata_request(inode, filp, &request)) { |
printf |
("Error while executing READ_SECTOR(S) command\n"); |
printf |
("Status register = 0x%02lX, error register = 0x%02lX\n", |
ata_astatus(ATA_BASE_ADDR), |
ata_error(ATA_BASE_ADDR)); |
} else { |
/* dump data to the screen */ |
atabug_dump_data(buf, 512 * sector_cnt); |
} |
} |
else |
{ |
/* dump data to the screen */ |
atabug_dump_data(buf, 512 * sector_cnt); |
} |
} |
return 0; |
return 0; |
} |
|
|
/* |
A T A _ R E A D _ M B R |
|
472,71 → 491,88
*/ |
int ata_read_mbr_cmd(int argc, char **argv) |
{ |
struct request request; |
unsigned int partition; |
struct request request; |
unsigned int partition; |
|
// get requested partition number |
partition = 0; |
if (argc) |
partition = strtoul(*argv, argv, 10); |
// get requested partition number |
partition = 0; |
if (argc) |
partition = strtoul(*argv, argv, 10); |
|
/* check for busy flag */ |
if ( ata_dev_busy(ATA_BASE_ADDR) ) |
printf("Selected ata device busy, ignoring command\n"); |
else |
{ |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = 0; |
request.nr_sectors = 1; |
request.buffer = buf; |
/* check for busy flag */ |
if (ata_dev_busy(ATA_BASE_ADDR)) |
printf("Selected ata device busy, ignoring command\n"); |
else { |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = 0; |
request.nr_sectors = 1; |
request.buffer = buf; |
|
if ( ata_request(inode, filp, &request) ) |
{ |
printf("Error while reading master boot sector.\n"); |
printf("Status register = 0x%02lX, error register = 0x%02lX\n", ata_astatus(ATA_BASE_ADDR), ata_error(ATA_BASE_ADDR) ); |
} |
else |
{ |
printf( "Skipping bootloader (446bytes)\n" ); |
printf( "Partition %1d:\n", partition); |
if (ata_request(inode, filp, &request)) { |
printf("Error while reading master boot sector.\n"); |
printf |
("Status register = 0x%02lX, error register = 0x%02lX\n", |
ata_astatus(ATA_BASE_ADDR), |
ata_error(ATA_BASE_ADDR)); |
} else { |
printf("Skipping bootloader (446bytes)\n"); |
printf("Partition %1d:\n", partition); |
|
// abuse partitionnumber to get offset in MBR record |
partition *= 16; |
partition += 446; |
// abuse partitionnumber to get offset in MBR record |
partition *= 16; |
partition += 446; |
|
printf( "Bootindicator: 0x%2X (%s)\n", buf[partition], buf[partition] ? "bootable" : "non-bootable"); |
printf( "Partition start (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n", |
buf[partition +1], (buf[partition +2] & 0xc0) << 2 | buf[partition +3] ,buf[partition +2] & 0x3f ); |
printf( "Systemindicator: 0x%02X (", buf[partition +4]); |
printf("Bootindicator: 0x%2X (%s)\n", buf[partition], |
buf[partition] ? "bootable" : "non-bootable"); |
printf |
("Partition start (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n", |
buf[partition + 1], |
(buf[partition + 2] & 0xc0) << 2 | buf[partition + |
3], |
buf[partition + 2] & 0x3f); |
printf("Systemindicator: 0x%02X (", buf[partition + 4]); |
|
switch (buf[partition +4]) |
{ |
case 0: printf ("Non DOS"); break; |
case 1: printf ("DOS FAT12"); break; |
case 4: printf ("DOS FAT16"); break; |
case 5: printf ("DOS extended"); break; |
case 6: printf ("DOS >32MByte"); break; |
switch (buf[partition + 4]) { |
case 0: |
printf("Non DOS"); |
break; |
case 1: |
printf("DOS FAT12"); |
break; |
case 4: |
printf("DOS FAT16"); |
break; |
case 5: |
printf("DOS extended"); |
break; |
case 6: |
printf("DOS >32MByte"); |
break; |
|
default : printf ("unkown"); |
}; |
printf (")\n"); |
printf( "Partition end (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n", |
buf[partition +5], (buf[partition +6] & 0xc0) << 2 | buf[partition +7] ,buf[partition +6] & 0x3f ); |
printf( "Physical Startsector: 0x%08X\n", buf[partition +11] << 24 | |
buf[partition +10] << 16 | |
buf[partition +9] << 8 | |
buf[partition +8]); |
printf( "Sector count: 0x%08X\n", buf[partition +15] << 24 | |
buf[partition +14] << 16 | |
buf[partition +13] << 8 | |
buf[partition +12]); |
} |
} |
return 0; |
default: |
printf("unkown"); |
}; |
printf(")\n"); |
printf |
("Partition end (head: 0x%02X cyl: 0x%03X sect: 0x%02X)\n", |
buf[partition + 5], |
(buf[partition + 6] & 0xc0) << 2 | buf[partition + |
7], |
buf[partition + 6] & 0x3f); |
printf("Physical Startsector: 0x%08X\n", |
buf[partition + 11] << 24 | buf[partition + |
10] << 16 | |
buf[partition + 9] << 8 | buf[partition + 8]); |
printf("Sector count: 0x%08X\n", |
buf[partition + 15] << 24 | buf[partition + |
14] << 16 | |
buf[partition + 13] << 8 | buf[partition + 12]); |
} |
} |
return 0; |
} |
|
|
/* |
A T A _ R E A D _ D O S B O O T |
|
544,57 → 580,65
*/ |
int ata_read_dosboot_cmd(int argc, char **argv) |
{ |
struct request request; |
unsigned int sector; |
char txt[8]; |
struct request request; |
unsigned int sector; |
char txt[8]; |
|
sector = 0; |
if (argc) |
sector = strtoul(*argv, argv, 0); |
sector = 0; |
if (argc) |
sector = strtoul(*argv, argv, 0); |
|
/* check for busy flag */ |
if ( ata_dev_busy(ATA_BASE_ADDR) ) |
printf("Selected ata device busy, ignoring command\n"); |
else |
{ |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = sector; |
request.nr_sectors = 1; |
request.buffer = buf; |
/* check for busy flag */ |
if (ata_dev_busy(ATA_BASE_ADDR)) |
printf("Selected ata device busy, ignoring command\n"); |
else { |
/* fill the request structure */ |
request.cmd = READ; |
request.sector = sector; |
request.nr_sectors = 1; |
request.buffer = buf; |
|
if ( ata_request(inode, filp, &request) ) |
{ |
printf("Error whilereading boot sector 0x%02X.\n", sector); |
printf("Status register = 0x%02lX, error register = 0x%02lX\n", ata_astatus(ATA_BASE_ADDR), ata_error(ATA_BASE_ADDR) ); |
} |
else |
{ |
printf( "Reading boot sector 0x%02X\n", sector ); |
printf( "ID number: 0x%2X%2X%2X\n", buf[0], buf[1], buf[2] ); |
if (ata_request(inode, filp, &request)) { |
printf("Error whilereading boot sector 0x%02X.\n", |
sector); |
printf |
("Status register = 0x%02lX, error register = 0x%02lX\n", |
ata_astatus(ATA_BASE_ADDR), |
ata_error(ATA_BASE_ADDR)); |
} else { |
printf("Reading boot sector 0x%02X\n", sector); |
printf("ID number: 0x%2X%2X%2X\n", buf[0], buf[1], |
buf[2]); |
|
printf( "OEM-name and number: " ); |
memcpy(txt, &buf[3], 8); |
txt[8] = '\0'; |
printf( "%s\n", txt ); |
printf("OEM-name and number: "); |
memcpy(txt, &buf[3], 8); |
txt[8] = '\0'; |
printf("%s\n", txt); |
|
printf( "Bytes per sector: %5d\n", (buf[12]<<8) | buf[11] ); |
printf( "Sectors per cluster: %3d\n", buf[13] ); |
printf( "Reserved IM-sectors: %5d\n", (buf[15]<<8) | buf[14] ); |
printf( "Number of FATs: %3d\n", buf[16] ); |
printf( "Number of entries in the root-directory: %5d\n", (buf[18]<<8) | buf[17] ); |
printf( "Number of logical sectors: %5d\n", (buf[20]<<8) | buf[19] ); |
printf( "Medium descriptor byte: %02X\n", buf[21] ); |
printf( "Sectors per FAT: %5d\n", (buf[23]<<8) | buf[22] ); |
printf( "Sectors per track: %5d\n", (buf[25]<<8) | buf[24] ); |
printf( "Number of heads: %5d\n", (buf[27]<<8) | buf[26] ); |
printf( "Number of hidden sectors: %5d\n", (buf[29]<<8) | buf[28] ); |
} |
} |
return 0; |
printf("Bytes per sector: %5d\n", |
(buf[12] << 8) | buf[11]); |
printf("Sectors per cluster: %3d\n", buf[13]); |
printf("Reserved IM-sectors: %5d\n", |
(buf[15] << 8) | buf[14]); |
printf("Number of FATs: %3d\n", buf[16]); |
printf("Number of entries in the root-directory: %5d\n", |
(buf[18] << 8) | buf[17]); |
printf("Number of logical sectors: %5d\n", |
(buf[20] << 8) | buf[19]); |
printf("Medium descriptor byte: %02X\n", buf[21]); |
printf("Sectors per FAT: %5d\n", |
(buf[23] << 8) | buf[22]); |
printf("Sectors per track: %5d\n", |
(buf[25] << 8) | buf[24]); |
printf("Number of heads: %5d\n", |
(buf[27] << 8) | buf[26]); |
printf("Number of hidden sectors: %5d\n", |
(buf[29] << 8) | buf[28]); |
} |
} |
return 0; |
} |
|
|
/* |
A T A _ R E S E T |
|
602,13 → 646,12
*/ |
int ata_reset_cmd(int argc, char **argv) |
{ |
if (argc != 1) |
return -1; |
if (argc != 1) |
return -1; |
|
return ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, SET | (**argv - '0') ); |
return ata_ioctl(inode, filp, ATA_IOCTL_SET_RST, SET | (**argv - '0')); |
} |
|
|
/* |
A T A _ S E L E C T _ D E V I C E |
|
616,20 → 659,18
*/ |
int ata_select_device_cmd(int argc, char **argv) |
{ |
if (argc != 1) |
return -1; |
if (argc != 1) |
return -1; |
|
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
inode->i_rdev = (ATA_BASE_ADDR >> 16) | (*argv[0] - '0'); |
|
ata_ioctl(inode, filp, ATA_IOCTL_SELECT_DEVICE, **argv - '0'); |
ata_ioctl(inode, filp, ATA_IOCTL_SELECT_DEVICE, **argv - '0'); |
|
printf("Ata device %1d selected.\n", REG32(ATA_BASE_ADDR + ATA_DHR) & ATA_DHR_DEV ? 1 : 0); |
return 0; |
printf("Ata device %1d selected.\n", |
REG32(ATA_BASE_ADDR + ATA_DHR) & ATA_DHR_DEV ? 1 : 0); |
return 0; |
} |
|
|
|
|
/**********************************************************************/ |
/* */ |
/* A T A B U G T O O L S */ |
647,36 → 688,32
*/ |
unsigned char atabug_dump_data(unsigned char *buffer, int cnt) |
{ |
int i, n, bytes_per_line = 16; |
unsigned char c, checksum; |
unsigned char *buf_ptr; |
int i, n, bytes_per_line = 16; |
unsigned char c, checksum; |
unsigned char *buf_ptr; |
|
/* prepare stored data for display & calculate checksum */ |
checksum = 0; |
buf_ptr = buffer; |
/* prepare stored data for display & calculate checksum */ |
checksum = 0; |
buf_ptr = buffer; |
|
/* display data */ |
for (i=0; i < cnt; i += bytes_per_line) |
{ |
printf("%3X ", i); |
/* display data */ |
for (i = 0; i < cnt; i += bytes_per_line) { |
printf("%3X ", i); |
|
/* print hexadecimal notation */ |
for (n=0; n < bytes_per_line; n++) |
printf("%02X ", *buf_ptr++); |
/* print hexadecimal notation */ |
for (n = 0; n < bytes_per_line; n++) |
printf("%02X ", *buf_ptr++); |
|
buf_ptr -= bytes_per_line; /* back to the start (of this block) */ |
buf_ptr -= bytes_per_line; /* back to the start (of this block) */ |
|
/* print ASCII notation & calculate checksum */ |
for (n=0; n < bytes_per_line; n++) |
{ |
c = *buf_ptr++; |
printf("%c", isprint(c) ? c : '.'); |
checksum += c; |
} |
printf("\n"); |
} |
/* print ASCII notation & calculate checksum */ |
for (n = 0; n < bytes_per_line; n++) { |
c = *buf_ptr++; |
printf("%c", isprint(c) ? c : '.'); |
checksum += c; |
} |
printf("\n"); |
} |
|
return checksum; |
return checksum; |
} |
|
|
/orpmon/cmds/dhry.c
29,10 → 29,10
{ |
unsigned long val; |
|
val = SPR_TTMR_SR | 0x0fffffff; |
asm("l.mtspr r0,%0,%1": : "r" (val), "i" (SPR_TTMR)); |
val = SPR_TTMR_SR | 0x0fffffff; |
asm("l.mtspr r0,%0,%1": :"r"(val), "i"(SPR_TTMR)); |
val = 0; |
asm("l.mtspr r0,%0,%1": : "r" (val), "i" (SPR_TTCR)); |
asm("l.mtspr r0,%0,%1": :"r"(val), "i"(SPR_TTCR)); |
} |
|
unsigned long read_timer(void) |
40,7 → 40,7
#if 0 |
unsigned long val; |
|
asm("l.mfspr %0,r0,%1": "=r" (val) : "i" (SPR_TTCR)); |
asm("l.mfspr %0,r0,%1": "=r"(val):"i"(SPR_TTCR)); |
return val; |
#else |
return timestamp; |
49,25 → 49,22
|
/* Global Variables: */ |
|
Rec_Pointer Ptr_Glob, |
Next_Ptr_Glob; |
int Int_Glob; |
Boolean Bool_Glob; |
char Ch_1_Glob, |
Ch_2_Glob; |
int Arr_1_Glob [50]; |
int Arr_2_Glob [50] [50]; |
Rec_Pointer Ptr_Glob, Next_Ptr_Glob; |
int Int_Glob; |
Boolean Bool_Glob; |
char Ch_1_Glob, Ch_2_Glob; |
int Arr_1_Glob[50]; |
int Arr_2_Glob[50][50]; |
|
|
/* forward declaration necessary since Enumeration may not simply be int */ |
|
#ifndef REG |
Boolean Reg = false; |
Boolean Reg = false; |
#define REG |
/* REG becomes defined as empty */ |
/* i.e. no register variables */ |
/* REG becomes defined as empty */ |
/* i.e. no register variables */ |
#else |
Boolean Reg = true; |
Boolean Reg = true; |
#endif |
|
/* variables for time measurement: */ |
74,84 → 71,65
|
#define Too_Small_Time US_PER_TICK |
|
|
#define TIMER0 0 |
#define TIMER1 1 |
|
unsigned int Begin_Time, |
End_Time, User_Time, Microseconds, Dhrystones_Per_Second; |
|
|
|
|
unsigned int Begin_Time, |
End_Time, |
User_Time, |
Microseconds, |
Dhrystones_Per_Second; |
|
/* end of variables for time measurement */ |
|
|
void Proc_1(REG Rec_Pointer Ptr_Val_Par); |
void Proc_2(One_Fifty *Int_Par_Ref); |
void Proc_3(Rec_Pointer *Ptr_Ref_Par); |
void Proc_2(One_Fifty * Int_Par_Ref); |
void Proc_3(Rec_Pointer * Ptr_Ref_Par); |
void Proc_4(void); |
void Proc_5(void); |
void Proc_6( |
Enumeration Enum_Val_Par, |
Enumeration *Enum_Ref_Par); |
void Proc_7( |
One_Fifty Int_1_Par_Val, |
One_Fifty Int_2_Par_Val, |
One_Fifty *Int_Par_Ref); |
void Proc_8( |
Arr_1_Dim Arr_1_Par_Ref, |
Arr_2_Dim Arr_2_Par_Ref, |
int Int_1_Par_Val, |
int Int_2_Par_Val); |
Enumeration Func_1(Capital_Letter Ch_1_Par_Val, |
Capital_Letter Ch_2_Par_Val); |
void Proc_6(Enumeration Enum_Val_Par, Enumeration * Enum_Ref_Par); |
void Proc_7(One_Fifty Int_1_Par_Val, |
One_Fifty Int_2_Par_Val, One_Fifty * Int_Par_Ref); |
void Proc_8(Arr_1_Dim Arr_1_Par_Ref, |
Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val); |
Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val); |
Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref); |
Boolean Func_3(Enumeration Enum_Par_Val); |
Boolean Func_3(Enumeration Enum_Par_Val); |
|
int dhry_main (int num_runs) |
int dhry_main(int num_runs) |
/*****/ |
|
/* main program, corresponds to procedures */ |
/* Main and Proc_0 in the Ada version */ |
{ |
One_Fifty Int_1_Loc; |
REG One_Fifty Int_2_Loc; |
One_Fifty Int_3_Loc; |
REG char Ch_Index; |
Enumeration Enum_Loc; |
Str_30 Str_1_Loc; |
Str_30 Str_2_Loc; |
REG int Run_Index; |
REG int Number_Of_Runs; |
Rec_Type x, y; |
One_Fifty Int_1_Loc; |
REG One_Fifty Int_2_Loc; |
One_Fifty Int_3_Loc; |
REG char Ch_Index; |
Enumeration Enum_Loc; |
Str_30 Str_1_Loc; |
Str_30 Str_2_Loc; |
REG int Run_Index; |
REG int Number_Of_Runs; |
Rec_Type x, y; |
|
/* Initializations */ |
/* Initializations */ |
|
Next_Ptr_Glob = (Rec_Pointer) &x; |
Ptr_Glob = (Rec_Pointer) &y; |
Next_Ptr_Glob = (Rec_Pointer) & x; |
Ptr_Glob = (Rec_Pointer) & y; |
|
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; |
Ptr_Glob->Discr = Ident_1; |
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; |
Ptr_Glob->variant.var_1.Int_Comp = 40; |
strcpy (Ptr_Glob->variant.var_1.Str_Comp, |
"DHRYSTONE PROGRAM, SOME STRING"); |
strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); |
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; |
Ptr_Glob->Discr = Ident_1; |
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; |
Ptr_Glob->variant.var_1.Int_Comp = 40; |
strcpy(Ptr_Glob->variant.var_1.Str_Comp, |
"DHRYSTONE PROGRAM, SOME STRING"); |
strcpy(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); |
|
Arr_2_Glob [8][7] = 10; |
/* Was missing in published program. Without this statement, */ |
/* Arr_2_Glob [8][7] would have an undefined value. */ |
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ |
/* overflow may occur for this array element. */ |
Arr_2_Glob[8][7] = 10; |
/* Was missing in published program. Without this statement, */ |
/* Arr_2_Glob [8][7] would have an undefined value. */ |
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ |
/* overflow may occur for this array element. */ |
|
/* Initalize Data and Instruction Cache */ |
|
|
/* printf ("\n"); |
printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n"); |
printf ("\n"); |
167,114 → 145,112
} |
printf ("Please give the number of runs through the benchmark: "); |
*/ |
{ |
int n; |
/* scanf ("%d", &n); |
*/ |
n = num_runs; |
Number_Of_Runs = n; |
} |
printf ("\n"); |
{ |
int n; |
/* scanf ("%d", &n); |
*/ |
n = num_runs; |
Number_Of_Runs = n; |
} |
printf("\n"); |
|
printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs); |
|
printf("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs); |
|
/***************/ |
/* Start timer */ |
/* Start timer */ |
/***************/ |
|
|
/* printf("%d", my_test2(Number_Of_Runs));*/ |
//start_timer(); |
Begin_Time = read_timer(); |
//start_timer(); |
Begin_Time = read_timer(); |
|
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) |
{ |
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { |
|
Proc_5(); |
Proc_4(); |
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ |
Int_1_Loc = 2; |
Int_2_Loc = 3; |
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); |
Enum_Loc = Ident_2; |
|
Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc); |
/* Bool_Glob == 1 */ |
while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ |
{ |
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; |
/* Int_3_Loc == 7 */ |
Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc); |
/* Int_3_Loc == 7 */ |
Int_1_Loc += 1; |
} /* while */ |
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ |
Proc_5(); |
Proc_4(); |
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ |
Int_1_Loc = 2; |
Int_2_Loc = 3; |
strcpy(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); |
Enum_Loc = Ident_2; |
|
Bool_Glob = !Func_2(Str_1_Loc, Str_2_Loc); |
/* Bool_Glob == 1 */ |
while (Int_1_Loc < Int_2_Loc) { /* loop body executed once */ |
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; |
/* Int_3_Loc == 7 */ |
Proc_7(Int_1_Loc, Int_2_Loc, &Int_3_Loc); |
/* Int_3_Loc == 7 */ |
Int_1_Loc += 1; |
} /* while */ |
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ |
#if DBG |
printf("a) Int_1_Loc: %x\n", Int_1_Loc); |
printf("a) Int_2_Loc: %x\n", Int_2_Loc); |
printf("a) Int_3_Loc: %x\n\n", Int_3_Loc); |
printf("a) Int_1_Loc: %x\n", Int_1_Loc); |
printf("a) Int_2_Loc: %x\n", Int_2_Loc); |
printf("a) Int_3_Loc: %x\n\n", Int_3_Loc); |
#endif |
Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); |
/* Int_Glob == 5 */ |
Proc_8(Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); |
/* Int_Glob == 5 */ |
#if DBG |
printf("b) Int_1_Loc: %x\n", Int_1_Loc); |
printf("b) Int_2_Loc: %x\n", Int_2_Loc); |
printf("b) Int_3_Loc: %x\n\n", Int_3_Loc); |
printf("b) Int_1_Loc: %x\n", Int_1_Loc); |
printf("b) Int_2_Loc: %x\n", Int_2_Loc); |
printf("b) Int_3_Loc: %x\n\n", Int_3_Loc); |
#endif |
|
Proc_1 (Ptr_Glob); |
Proc_1(Ptr_Glob); |
#if DBG |
printf("c) Int_1_Loc: %x\n", Int_1_Loc); |
printf("c) Int_2_Loc: %x\n", Int_2_Loc); |
printf("c) Int_3_Loc: %x\n\n", Int_3_Loc); |
printf("c) Int_1_Loc: %x\n", Int_1_Loc); |
printf("c) Int_2_Loc: %x\n", Int_2_Loc); |
printf("c) Int_3_Loc: %x\n\n", Int_3_Loc); |
#endif |
|
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) |
/* loop body executed twice */ |
{ |
if (Enum_Loc == Func_1 (Ch_Index, 'C')) |
/* then, not executed */ |
{ |
Proc_6 (Ident_1, &Enum_Loc); |
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); |
Int_2_Loc = Run_Index; |
Int_Glob = Run_Index; |
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) |
/* loop body executed twice */ |
{ |
if (Enum_Loc == Func_1(Ch_Index, 'C')) |
/* then, not executed */ |
{ |
Proc_6(Ident_1, &Enum_Loc); |
strcpy(Str_2_Loc, |
"DHRYSTONE PROGRAM, 3'RD STRING"); |
Int_2_Loc = Run_Index; |
Int_Glob = Run_Index; |
#if DBG |
printf("d) Int_1_Loc: %x\n", Int_1_Loc); |
printf("d) Int_2_Loc: %x\n", Int_2_Loc); |
printf("d) Int_3_Loc: %x\n\n", Int_3_Loc); |
printf("d) Int_1_Loc: %x\n", Int_1_Loc); |
printf("d) Int_2_Loc: %x\n", Int_2_Loc); |
printf("d) Int_3_Loc: %x\n\n", Int_3_Loc); |
#endif |
} |
} |
} |
} |
|
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ |
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ |
#if DBG |
printf("e) Int_1_Loc: %x\n", Int_1_Loc); |
printf("e) Int_2_Loc: %x\n", Int_2_Loc); |
printf("e) Int_3_Loc: %x\n", Int_3_Loc); |
printf("e) Ch_1_Glob: %c\n\n", Ch_1_Glob); |
printf("e) Int_1_Loc: %x\n", Int_1_Loc); |
printf("e) Int_2_Loc: %x\n", Int_2_Loc); |
printf("e) Int_3_Loc: %x\n", Int_3_Loc); |
printf("e) Ch_1_Glob: %c\n\n", Ch_1_Glob); |
#endif |
Int_2_Loc = Int_2_Loc * Int_1_Loc; |
Int_1_Loc = Int_2_Loc * Int_3_Loc; |
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; |
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ |
Proc_2 (&Int_1_Loc); |
Int_2_Loc = Int_2_Loc * Int_1_Loc; |
Int_1_Loc = Int_2_Loc * Int_3_Loc; |
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; |
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ |
Proc_2(&Int_1_Loc); |
|
/* Int_1_Loc == 5 */ |
/* Int_1_Loc == 5 */ |
#if DBG |
printf("f) Int_1_Loc: %x\n", Int_1_Loc); |
printf("f) Int_2_Loc: %x\n", Int_2_Loc); |
printf("f) Int_3_Loc: %x\n\n", Int_3_Loc); |
printf("f) Int_1_Loc: %x\n", Int_1_Loc); |
printf("f) Int_2_Loc: %x\n", Int_2_Loc); |
printf("f) Int_3_Loc: %x\n\n", Int_3_Loc); |
#endif |
|
} /* loop "for Run_Index" */ |
} /* loop "for Run_Index" */ |
|
/**************/ |
/* Stop timer */ |
/* Stop timer */ |
/**************/ |
|
End_Time = read_timer(); |
|
End_Time = read_timer(); |
|
/* printf ("Execution ends\n"); |
printf ("\n"); |
printf ("Final values of the variables used in the benchmark:\n"); |
329,52 → 305,45
|
*/ |
|
User_Time = End_Time - Begin_Time; |
|
printf("Timer ticks, %d/Sec, (%d - %d) =\t%d\n", TICKS_PER_SEC, |
End_Time, Begin_Time, User_Time); |
|
User_Time = End_Time - Begin_Time; |
/* microseconds */ |
|
printf("Timer ticks, %d/Sec, (%d - %d) =\t%d\n",TICKS_PER_SEC, |
End_Time, Begin_Time, User_Time); |
printf("\nNumber of Runs %i", num_runs); |
printf("\nElapsed time %d.%d%ds\n", |
(User_Time / TICKS_PER_SEC), |
(User_Time / (TICKS_PER_SEC / 10)) % 10, |
(User_Time / (TICKS_PER_SEC / 100)) % 10); |
|
/* microseconds */ |
|
printf ("\nNumber of Runs %i", num_runs); |
printf ("\nElapsed time %d.%d%ds\n", |
(User_Time/TICKS_PER_SEC), |
(User_Time/(TICKS_PER_SEC/10))%10, |
(User_Time/( TICKS_PER_SEC/100))%10); |
if (User_Time < (5 * TICKS_PER_SEC)) { |
printf |
("Measured time too small to obtain meaningful results\n"); |
printf("Please increase number of runs\n"); |
printf("\n"); |
} else { |
printf("Processor at %d MHz\n", (IN_CLK / 1000000)); |
|
|
if (User_Time < (5*TICKS_PER_SEC)) |
{ |
printf ("Measured time too small to obtain meaningful results\n"); |
printf ("Please increase number of runs\n"); |
printf ("\n"); |
} |
else |
{ |
printf("Processor at %d MHz\n",(IN_CLK/1000000)); |
// User_Time is ticks in resolution TICKS_PER_SEC, so to convert to uS |
Microseconds = (User_Time * (1000000 / TICKS_PER_SEC)); |
|
Dhrystones_Per_Second = |
Number_Of_Runs / (User_Time / TICKS_PER_SEC); |
|
// User_Time is ticks in resolution TICKS_PER_SEC, so to convert to uS |
Microseconds = (User_Time * (1000000/TICKS_PER_SEC)); |
|
Dhrystones_Per_Second = Number_Of_Runs / (User_Time/TICKS_PER_SEC); |
|
printf ("Microseconds for one run through Dhrystone: "); |
printf ("( %d uS / %dk ) = %d uS\n", Microseconds,(Number_Of_Runs/1000), |
Microseconds / Number_Of_Runs); |
printf ("Dhrystones per Second: "); |
printf ("%d \n", Dhrystones_Per_Second); |
} |
return 0; |
printf("Microseconds for one run through Dhrystone: "); |
printf("( %d uS / %dk ) = %d uS\n", Microseconds, |
(Number_Of_Runs / 1000), Microseconds / Number_Of_Runs); |
printf("Dhrystones per Second: "); |
printf("%d \n", Dhrystones_Per_Second); |
} |
return 0; |
} |
|
|
void Proc_1(Ptr_Val_Par) |
/******************/ |
|
REG Rec_Pointer Ptr_Val_Par; |
REG Rec_Pointer Ptr_Val_Par; |
/* executed once */ |
{ |
REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; |
382,11 → 351,10
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ |
/* corresponds to "rename" in Ada, "with" in Pascal */ |
|
|
structassign(*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); |
Ptr_Val_Par->variant.var_1.Int_Comp = 5; |
Next_Record->variant.var_1.Int_Comp |
= Ptr_Val_Par->variant.var_1.Int_Comp; |
= Ptr_Val_Par->variant.var_1.Int_Comp; |
Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; |
Proc_3(&Next_Record->Ptr_Comp); |
/* |
393,85 → 361,73
* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp |
*/ |
if (Next_Record->Discr == Ident_1) |
/* then, executed */ |
/* then, executed */ |
{ |
Next_Record->variant.var_1.Int_Comp = 6; |
Proc_6(Ptr_Val_Par->variant.var_1.Enum_Comp, |
&Next_Record->variant.var_1.Enum_Comp); |
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; |
Proc_7(Next_Record->variant.var_1.Int_Comp, 10, |
&Next_Record->variant.var_1.Int_Comp); |
} else /* not executed */ |
structassign(*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); |
Next_Record->variant.var_1.Int_Comp = 6; |
Proc_6(Ptr_Val_Par->variant.var_1.Enum_Comp, |
&Next_Record->variant.var_1.Enum_Comp); |
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; |
Proc_7(Next_Record->variant.var_1.Int_Comp, 10, |
&Next_Record->variant.var_1.Int_Comp); |
} else /* not executed */ |
structassign(*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); |
|
} /* Proc_1 */ |
} /* Proc_1 */ |
|
|
void |
Proc_2(Int_Par_Ref) |
void Proc_2(Int_Par_Ref) |
/******************/ |
/* executed once */ |
/* *Int_Par_Ref == 1, becomes 4 */ |
|
One_Fifty *Int_Par_Ref; |
One_Fifty *Int_Par_Ref; |
{ |
One_Fifty Int_Loc; |
Enumeration Enum_Loc = 0; |
One_Fifty Int_Loc; |
Enumeration Enum_Loc = 0; |
|
|
Int_Loc = *Int_Par_Ref + 10; |
do /* executed once */ |
if (Ch_1_Glob == 'A') |
/* then, executed */ |
{ |
Int_Loc -= 1; |
*Int_Par_Ref = Int_Loc - Int_Glob; |
Enum_Loc = Ident_1; |
} /* if */ |
while (Enum_Loc != Ident_1);/* true */ |
} /* Proc_2 */ |
do /* executed once */ |
if (Ch_1_Glob == 'A') |
/* then, executed */ |
{ |
Int_Loc -= 1; |
*Int_Par_Ref = Int_Loc - Int_Glob; |
Enum_Loc = Ident_1; |
} /* if */ |
while (Enum_Loc != Ident_1) ; /* true */ |
} /* Proc_2 */ |
|
|
void |
Proc_3(Ptr_Ref_Par) |
void Proc_3(Ptr_Ref_Par) |
/******************/ |
/* executed once */ |
/* Ptr_Ref_Par becomes Ptr_Glob */ |
Rec_Pointer *Ptr_Ref_Par; |
|
Rec_Pointer *Ptr_Ref_Par; |
|
{ |
|
if (Ptr_Glob != Null) |
/* then, executed */ |
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; |
/* then, executed */ |
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; |
Proc_7(10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); |
} /* Proc_3 */ |
} /* Proc_3 */ |
|
|
void |
Proc_4() |
{ /* without parameters */ |
void Proc_4() |
{ /* without parameters */ |
/*******/ |
/* executed once */ |
Boolean Bool_Loc; |
Boolean Bool_Loc; |
|
|
Bool_Loc = Ch_1_Glob == 'A'; |
Bool_Glob = Bool_Loc | Bool_Glob; |
Ch_2_Glob = 'B'; |
} /* Proc_4 */ |
} /* Proc_4 */ |
|
|
void |
Proc_5() |
{ /* without parameters */ |
void Proc_5() |
{ /* without parameters */ |
/*******/ |
/* executed once */ |
|
Ch_1_Glob = 'A'; |
Bool_Glob = false; |
} /* Proc_5 */ |
} /* Proc_5 */ |
|
/* @(#)dhry_2.c 1.2 92/05/28 14:44:54, AMD */ |
/* |
497,52 → 453,48
/* i.e. no register variables */ |
#ifdef _AM29K |
#undef REG |
#define REG register /* Define REG; saves room on 127-char MS-DOS cmd line */ |
#define REG register /* Define REG; saves room on 127-char MS-DOS cmd line */ |
#endif |
#endif |
|
|
void |
Proc_6(Enum_Val_Par, Enum_Ref_Par) |
void Proc_6(Enum_Val_Par, Enum_Ref_Par) |
/*********************************/ |
/* executed once */ |
/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ |
|
Enumeration Enum_Val_Par; |
Enumeration *Enum_Ref_Par; |
Enumeration Enum_Val_Par; |
Enumeration *Enum_Ref_Par; |
{ |
#if PROC_6 |
|
*Enum_Ref_Par = Enum_Val_Par; |
if (!Func_3(Enum_Val_Par)) |
/* then, not executed */ |
*Enum_Ref_Par = Ident_4; |
switch (Enum_Val_Par) { |
case Ident_1: |
*Enum_Ref_Par = Ident_1; |
break; |
case Ident_2: |
if (Int_Glob > 100) |
/* then */ |
*Enum_Ref_Par = Ident_1; |
else |
*Enum_Ref_Par = Ident_4; |
break; |
case Ident_3: /* executed */ |
*Enum_Ref_Par = Ident_2; |
break; |
case Ident_4: |
break; |
case Ident_5: |
*Enum_Ref_Par = Ident_3; |
break; |
} /* switch */ |
*Enum_Ref_Par = Enum_Val_Par; |
if (!Func_3(Enum_Val_Par)) |
/* then, not executed */ |
*Enum_Ref_Par = Ident_4; |
switch (Enum_Val_Par) { |
case Ident_1: |
*Enum_Ref_Par = Ident_1; |
break; |
case Ident_2: |
if (Int_Glob > 100) |
/* then */ |
*Enum_Ref_Par = Ident_1; |
else |
*Enum_Ref_Par = Ident_4; |
break; |
case Ident_3: /* executed */ |
*Enum_Ref_Par = Ident_2; |
break; |
case Ident_4: |
break; |
case Ident_5: |
*Enum_Ref_Par = Ident_3; |
break; |
} /* switch */ |
#endif |
return; |
return; |
} /* Proc_6 */ |
|
void |
Proc_7(Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) |
void Proc_7(Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) |
/**********************************************/ |
/* executed three times */ |
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ |
551,152 → 503,141
/* Int_Par_Ref becomes 17 */ |
/* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ |
/* Int_Par_Ref becomes 18 */ |
One_Fifty Int_1_Par_Val; |
One_Fifty Int_2_Par_Val; |
One_Fifty *Int_Par_Ref; |
One_Fifty Int_1_Par_Val; |
One_Fifty Int_2_Par_Val; |
One_Fifty *Int_Par_Ref; |
{ |
One_Fifty Int_Loc; |
One_Fifty Int_Loc; |
|
|
Int_Loc = Int_1_Par_Val + 2; |
*Int_Par_Ref = Int_2_Par_Val + Int_Loc; |
Int_Loc = Int_1_Par_Val + 2; |
*Int_Par_Ref = Int_2_Par_Val + Int_Loc; |
} /* Proc_7 */ |
|
|
void |
Proc_8(Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) |
void Proc_8(Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) |
/*********************************************************************/ |
/* executed once */ |
/* Int_Par_Val_1 == 3 */ |
/* Int_Par_Val_2 == 7 */ |
Arr_1_Dim Arr_1_Par_Ref; |
Arr_2_Dim Arr_2_Par_Ref; |
int Int_1_Par_Val; |
int Int_2_Par_Val; |
Arr_1_Dim Arr_1_Par_Ref; |
Arr_2_Dim Arr_2_Par_Ref; |
int Int_1_Par_Val; |
int Int_2_Par_Val; |
{ |
REG One_Fifty Int_Index; |
REG One_Fifty Int_Loc; |
REG One_Fifty Int_Index; |
REG One_Fifty Int_Loc; |
|
#if DBG |
printf("X) Int_1_Par_Val: %x\n", Int_1_Par_Val); |
printf("X) Int_2_Par_Val: %x\n", Int_2_Par_Val); |
printf("X) Int_1_Par_Val: %x\n", Int_1_Par_Val); |
printf("X) Int_2_Par_Val: %x\n", Int_2_Par_Val); |
#endif |
|
Int_Loc = Int_1_Par_Val + 5; |
Arr_1_Par_Ref[Int_Loc] = Int_2_Par_Val; |
Arr_1_Par_Ref[Int_Loc + 1] = Arr_1_Par_Ref[Int_Loc]; |
Arr_1_Par_Ref[Int_Loc + 30] = Int_Loc; |
for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index) |
Arr_2_Par_Ref[Int_Loc][Int_Index] = Int_Loc; |
Arr_2_Par_Ref[Int_Loc][Int_Loc - 1] += 1; |
Arr_2_Par_Ref[Int_Loc + 20][Int_Loc] = Arr_1_Par_Ref[Int_Loc]; |
Int_Glob = 5; |
|
Int_Loc = Int_1_Par_Val + 5; |
Arr_1_Par_Ref[Int_Loc] = Int_2_Par_Val; |
Arr_1_Par_Ref[Int_Loc + 1] = Arr_1_Par_Ref[Int_Loc]; |
Arr_1_Par_Ref[Int_Loc + 30] = Int_Loc; |
for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index) |
Arr_2_Par_Ref[Int_Loc][Int_Index] = Int_Loc; |
Arr_2_Par_Ref[Int_Loc][Int_Loc - 1] += 1; |
Arr_2_Par_Ref[Int_Loc + 20][Int_Loc] = Arr_1_Par_Ref[Int_Loc]; |
Int_Glob = 5; |
|
#if DBG |
printf("Y) Int_1_Par_Val: %x\n", Int_1_Par_Val); |
printf("Y) Int_2_Par_Val: %x\n", Int_2_Par_Val); |
printf("Y) Int_1_Par_Val: %x\n", Int_1_Par_Val); |
printf("Y) Int_2_Par_Val: %x\n", Int_2_Par_Val); |
#endif |
|
} /* Proc_8 */ |
|
|
Enumeration |
Func_1(Ch_1_Par_Val, Ch_2_Par_Val) |
Enumeration Func_1(Ch_1_Par_Val, Ch_2_Par_Val) |
/*************************************************/ |
/* executed three times */ |
/* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ |
/* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ |
/* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ |
|
Capital_Letter Ch_1_Par_Val; |
Capital_Letter Ch_2_Par_Val; |
Capital_Letter Ch_1_Par_Val; |
Capital_Letter Ch_2_Par_Val; |
{ |
Capital_Letter Ch_1_Loc; |
Capital_Letter Ch_2_Loc; |
Capital_Letter Ch_1_Loc; |
Capital_Letter Ch_2_Loc; |
|
|
Ch_1_Loc = Ch_1_Par_Val; |
Ch_2_Loc = Ch_1_Loc; |
if (Ch_2_Loc != Ch_2_Par_Val) |
/* then, executed */ |
return (Ident_1); |
else { /* not executed */ |
Ch_1_Glob = Ch_1_Loc; |
return (Ident_2); |
} |
Ch_1_Loc = Ch_1_Par_Val; |
Ch_2_Loc = Ch_1_Loc; |
if (Ch_2_Loc != Ch_2_Par_Val) |
/* then, executed */ |
return (Ident_1); |
else { /* not executed */ |
Ch_1_Glob = Ch_1_Loc; |
return (Ident_2); |
} |
} /* Func_1 */ |
|
|
Boolean |
Func_2(Str_1_Par_Ref, Str_2_Par_Ref) |
Boolean Func_2(Str_1_Par_Ref, Str_2_Par_Ref) |
/*************************************************/ |
/* executed once */ |
/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ |
/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ |
|
Str_30 Str_1_Par_Ref; |
Str_30 Str_2_Par_Ref; |
Str_30 Str_1_Par_Ref; |
Str_30 Str_2_Par_Ref; |
{ |
REG One_Thirty Int_Loc; |
Capital_Letter Ch_Loc = 0; |
REG One_Thirty Int_Loc; |
Capital_Letter Ch_Loc = 0; |
|
|
Int_Loc = 2; |
while (Int_Loc <= 2) /* loop body executed once */ |
if (Func_1(Str_1_Par_Ref[Int_Loc], |
Str_2_Par_Ref[Int_Loc + 1]) == Ident_1) |
/* then, executed */ |
{ |
Ch_Loc = 'A'; |
Int_Loc += 1; |
} /* if, while */ |
|
if (Ch_Loc >= 'W' && Ch_Loc < 'Z') |
/* then, not executed */ |
Int_Loc = 7; |
if (Ch_Loc == 'R') |
/* then, not executed */ |
return (true); |
else { /* executed */ |
if (strcmp(Str_1_Par_Ref, Str_2_Par_Ref) > 0) |
/* then, not executed */ |
{ |
Int_Loc += 7; |
Int_Glob = Int_Loc; |
return (true); |
} else /* executed */ |
return (false); |
} /* if Ch_Loc */ |
Int_Loc = 2; |
while (Int_Loc <= 2) /* loop body executed once */ |
if (Func_1(Str_1_Par_Ref[Int_Loc], |
Str_2_Par_Ref[Int_Loc + 1]) == Ident_1) |
/* then, executed */ |
{ |
Ch_Loc = 'A'; |
Int_Loc += 1; |
} |
/* if, while */ |
if (Ch_Loc >= 'W' && Ch_Loc < 'Z') |
/* then, not executed */ |
Int_Loc = 7; |
if (Ch_Loc == 'R') |
/* then, not executed */ |
return (true); |
else { /* executed */ |
if (strcmp(Str_1_Par_Ref, Str_2_Par_Ref) > 0) |
/* then, not executed */ |
{ |
Int_Loc += 7; |
Int_Glob = Int_Loc; |
return (true); |
} else /* executed */ |
return (false); |
} /* if Ch_Loc */ |
} /* Func_2 */ |
|
|
Boolean |
Func_3(Enum_Par_Val) |
Boolean Func_3(Enum_Par_Val) |
/***************************/ |
/* executed once */ |
/* Enum_Par_Val == Ident_3 */ |
Enumeration Enum_Par_Val; |
Enumeration Enum_Par_Val; |
{ |
Enumeration Enum_Loc; |
Enumeration Enum_Loc; |
|
Enum_Loc = Enum_Par_Val; |
if (Enum_Loc == Ident_3) |
/* then, executed */ |
return (true); |
else /* not executed */ |
return (false); |
Enum_Loc = Enum_Par_Val; |
if (Enum_Loc == Ident_3) |
/* then, executed */ |
return (true); |
else /* not executed */ |
return (false); |
} /* Func_3 */ |
|
int dhry_cmd (int argc, char *argv[]) |
int dhry_cmd(int argc, char *argv[]) |
{ |
if (argc == 1) dhry_main(strtoul (argv[0], 0, 0)); |
else if (argc == 0) dhry_main(20); |
else return -1; |
return 0; |
if (argc == 1) |
dhry_main(strtoul(argv[0], 0, 0)); |
else if (argc == 0) |
dhry_main(20); |
else |
return -1; |
return 0; |
} |
|
void module_dhry_init (void) |
void module_dhry_init(void) |
{ |
register_command ("dhry", "[<num_runs>]", "run dhrystone", dhry_cmd); |
register_command("dhry", "[<num_runs>]", "run dhrystone", dhry_cmd); |
} |
/orpmon/cmds/cpu.c
2,124 → 2,133
#include "support.h" |
#include "spr-defs.h" |
|
int ic_enable_cmd (int argc, char *argv[]) |
int ic_enable_cmd(int argc, char *argv[]) |
{ |
unsigned long addr; |
unsigned long sr; |
unsigned long addr; |
unsigned long sr; |
|
if (argc) return -1; |
/* Invalidate IC */ |
for (addr = 0; addr < 8192; addr += 16) |
asm("l.mtspr r0,%0,%1": : "r" (addr), "i" (SPR_ICBIR)); |
|
/* Enable IC */ |
asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR)); |
sr |= SPR_SR_ICE; |
asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
if (argc) |
return -1; |
/* Invalidate IC */ |
for (addr = 0; addr < 8192; addr += 16) |
asm("l.mtspr r0,%0,%1": :"r"(addr), "i"(SPR_ICBIR)); |
|
/* Enable IC */ |
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR)); |
sr |= SPR_SR_ICE; |
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
} |
|
int ic_disable_cmd (int argc, char *argv[]) |
int ic_disable_cmd(int argc, char *argv[]) |
{ |
unsigned long sr; |
unsigned long sr; |
|
if (argc) return -1; |
/* Disable IC */ |
asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR)); |
sr &= ~SPR_SR_ICE; |
asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
if (argc) |
return -1; |
/* Disable IC */ |
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR)); |
sr &= ~SPR_SR_ICE; |
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
} |
|
int dc_enable_cmd (int argc, char *argv[]) |
int dc_enable_cmd(int argc, char *argv[]) |
{ |
unsigned long addr; |
unsigned long sr; |
unsigned long addr; |
unsigned long sr; |
|
if (argc) return -1; |
/* Invalidate DC */ |
for (addr = 0; addr < 8192; addr += 16) |
asm("l.mtspr r0,%0,%1": : "r" (addr), "i" (SPR_DCBIR)); |
|
/* Enable DC */ |
asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR)); |
sr |= SPR_SR_DCE; |
asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
if (argc) |
return -1; |
/* Invalidate DC */ |
for (addr = 0; addr < 8192; addr += 16) |
asm("l.mtspr r0,%0,%1": :"r"(addr), "i"(SPR_DCBIR)); |
|
/* Enable DC */ |
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR)); |
sr |= SPR_SR_DCE; |
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
} |
|
int dc_disable_cmd (int argc, char *argv[]) |
int dc_disable_cmd(int argc, char *argv[]) |
{ |
|
if (argc) return -1; |
if (argc) |
return -1; |
|
unsigned long sr = mfspr(SPR_SR); |
|
// If it's enabled and write back is on, we'd better flush it first |
// (CWS=1 is write back) |
unsigned long sr = mfspr(SPR_SR); |
|
unsigned long dccfgr = mfspr(SPR_DCCFGR); |
int i; |
int bs= (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16; |
int ways = (1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3)); |
for(i=0;i<ways;i++) |
mtspr(SPR_DCBFR, i*bs); |
// If it's enabled and write back is on, we'd better flush it first |
// (CWS=1 is write back) |
|
/* Disable DC */ |
sr &= ~SPR_SR_DCE; |
asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
unsigned long dccfgr = mfspr(SPR_DCCFGR); |
int i; |
int bs = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16; |
int ways = (1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3)); |
for (i = 0; i < ways; i++) |
mtspr(SPR_DCBFR, i * bs); |
|
/* Disable DC */ |
sr &= ~SPR_SR_DCE; |
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR)); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
asm("l.nop"); |
return 0; |
} |
|
int mfspr_cmd (int argc, char *argv[]) |
int mfspr_cmd(int argc, char *argv[]) |
{ |
unsigned long val, addr; |
unsigned long val, addr; |
|
if (argc == 1) { |
addr = strtoul (argv[0], 0, 0); |
/* Read SPR */ |
asm("l.mfspr %0,%1,0": "=r" (val) : "r" (addr)); |
printf ("\nSPR %04lx: %08lx", addr, val); |
} else return -1; |
if (argc == 1) { |
addr = strtoul(argv[0], 0, 0); |
/* Read SPR */ |
asm("l.mfspr %0,%1,0": "=r"(val):"r"(addr)); |
printf("\nSPR %04lx: %08lx", addr, val); |
} else |
return -1; |
return 0; |
} |
|
int mtspr_cmd (int argc, char *argv[]) |
int mtspr_cmd(int argc, char *argv[]) |
{ |
unsigned long val, addr; |
if (argc == 2) { |
addr = strtoul (argv[0], 0, 0); |
val = strtoul (argv[1], 0, 0); |
/* Write SPR */ |
asm("l.mtspr %0,%1,0": : "r" (addr), "r" (val)); |
asm("l.mfspr %0,%1,0": "=r" (val) : "r" (addr)); |
printf ("\nSPR %04lx: %08lx", addr, val); |
} else return -1; |
unsigned long val, addr; |
if (argc == 2) { |
addr = strtoul(argv[0], 0, 0); |
val = strtoul(argv[1], 0, 0); |
/* Write SPR */ |
asm("l.mtspr %0,%1,0": :"r"(addr), "r"(val)); |
asm("l.mfspr %0,%1,0": "=r"(val):"r"(addr)); |
printf("\nSPR %04lx: %08lx", addr, val); |
} else |
return -1; |
return 0; |
} |
|
void module_cpu_init (void) |
void module_cpu_init(void) |
{ |
register_command ("ic_enable", "", "enable instruction cache", ic_enable_cmd); |
register_command ("ic_disable", "", "disable instruction cache", ic_disable_cmd); |
register_command ("dc_enable", "", "enable data cache", dc_enable_cmd); |
register_command ("dc_disable", "", "disable data cache", dc_disable_cmd); |
register_command ("mfspr", "<spr_addr>", "show SPR", mfspr_cmd); |
register_command ("mtspr", "<spr_addr> <value>", "set SPR", mtspr_cmd); |
register_command("ic_enable", "", "enable instruction cache", |
ic_enable_cmd); |
register_command("ic_disable", "", "disable instruction cache", |
ic_disable_cmd); |
register_command("dc_enable", "", "enable data cache", dc_enable_cmd); |
register_command("dc_disable", "", "disable data cache", |
dc_disable_cmd); |
register_command("mfspr", "<spr_addr>", "show SPR", mfspr_cmd); |
register_command("mtspr", "<spr_addr> <value>", "set SPR", mtspr_cmd); |
} |
/orpmon/cmds/camera.c
4,143 → 4,238
+int camera_pos_x;
+int camera_move_speed = 1;
+int current_buf;
+void camera_int(void)
+{
+
+ /* Change base addresse of camera */
+ set_mem32(CAMERA_BASE, CAMERA_BUF(current_buf)); /* Set address to store to */
-int camera_pos_x;
-int camera_move_speed = 1;
-int current_buf;
+ /* Change base addresse of crt */
+ set_mem32(CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
+printf("\n %08x\n ", CAMERA_BUF(current_buf));
+current_buf = 1 - current_buf;
-void camera_int (void)
-{
- /* Change base addresse of camera */
- set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf)); /* Set address to store to */
-
- /* Change base addresse of crt */
- set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
- printf ("\n %08x\n ", CAMERA_BUF(current_buf));
-
- current_buf = 1 - current_buf;
-
- /* move the camera screen around */
- camera_pos_x += camera_move_speed;
- if (camera_pos_x >= SCREEN_X - CAMERA_X || camera_pos_x <= 0)
- camera_move_speed = -camera_move_speed;
- mtspr(SPR_PICSR, 0);
-}
+ /* move the camera screen around */
+ camera_pos_x += camera_move_speed;
+if (camera_pos_x >= SCREEN_X - CAMERA_X || camera_pos_x <= 0)
+camera_move_speed = -camera_move_speed;
+mtspr(SPR_PICSR, 0);
+}
+
+int crt_enable_cmd(int argc, char *argv[])
+{
+int i, x, y;
+if (argc)
+ return -1;
+
+ /* Init CRT */
+ set_mem32(CRT_BASE + 4, FRAME_BUF); /* Frame buffer start */
+set_mem32(CRT_BASE, get_mem32(CRT_BASE) | 1); /* Enable CRT only */
-int crt_enable_cmd (int argc, char *argv[])
-{
- int i, x, y;
-
- if (argc) return -1;
- /* Init CRT */
- set_mem32 (CRT_BASE + 4, FRAME_BUF); /* Frame buffer start */
- set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 1); /* Enable CRT only */
-
- /* Init palette */
- for (i = 0; i < 32; i++) {
- set_palette (8 * i + 0, 0x00, 0x00, 0x00); /* black */
- set_palette (8 * i + 1, 0xff, 0xff, 0xff); /* white */
- set_palette (8 * i + 2, 0x7f, 0x7f, 0x7f); /* gray */
- set_palette (8 * i + 3, 0xff, 0x00, 0x00); /* red */
- set_palette (8 * i + 4, 0x00, 0xff, 0x00); /* green */
- set_palette (8 * i + 5, 0x00, 0x00, 0xff); /* blue */
- set_palette (8 * i + 6, 0x00, 0xff, 0xff); /* cyan */
- set_palette (8 * i + 7, 0xff, 0x00, 0xff); /* purple */
- }
- for (x = 0; x < SCREEN_X; x++)
- for (y = 0; y < SCREEN_Y; y++)
- put_pixel(x, y, 3);
- return 0;
-}
+ /* Init palette */
+ for (i = 0; i < 32; i++) {
+set_palette(8 * i + 0, 0x00, 0x00, 0x00); /* black */
+set_palette(8 * i + 1, 0xff, 0xff, 0xff); /* white */
+set_palette(8 * i + 2, 0x7f, 0x7f, 0x7f); /* gray */
+set_palette(8 * i + 3, 0xff, 0x00, 0x00); /* red */
+set_palette(8 * i + 4, 0x00, 0xff, 0x00); /* green */
+set_palette(8 * i + 5, 0x00, 0x00, 0xff); /* blue */
+set_palette(8 * i + 6, 0x00, 0xff, 0xff); /* cyan */
+set_palette(8 * i + 7, 0xff, 0x00, 0xff); /* purple */
+}
+for (x = 0; x < SCREEN_X; x++)
+for (y = 0; y < SCREEN_Y; y++)
+put_pixel(x, y, 3);
+return 0;
+}
+
+int crt_test_cmd(int argc, char *argv[])
+{
+int i, x, y;
+if (argc)
+ return -1;
+for (x = 0; x < SCREEN_X; x++)
+for (y = 0; y < SCREEN_Y; y++)
+put_pixel(x, y, 0);
+
+ /* Draw gray X */
+ for (i = 0; i < SCREEN_Y; i++) {
+put_pixel(i, i, 2);
+put_pixel(SCREEN_X - i - 1, i, 1);
+}
-int crt_test_cmd (int argc, char *argv[])
-{
- int i, x, y;
- if (argc) return -1;
- for (x = 0; x < SCREEN_X; x++)
- for (y = 0; y < SCREEN_Y; y++)
- put_pixel(x, y, 0);
- /* Draw gray X */
- for (i = 0; i < SCREEN_Y; i++) {
- put_pixel (i, i, 2);
- put_pixel (SCREEN_X - i - 1, i, 1);
- }
-
- /* Draw color boxes */
- for (y = 0; y < 50; y++)
- for (x = 0; x < 50; x++)
- for (i = 0; i < 8; i++)
- put_pixel (i * 50 + x, y, i);
- return 0;
-}
+ /* Draw color boxes */
+ for (y = 0; y < 50; y++)
+for (x = 0; x < 50; x++)
+for (i = 0; i < 8; i++)
+put_pixel(i * 50 + x, y, i);
+return 0;
+}
+
+int crt_disable_cmd(int argc, char *argv[])
+{
+if (argc)
+ return -1;
+set_mem32(CRT_BASE, get_mem32(CRT_BASE) & ~1); /* Disable CRT */
+return 0;
+}
+
+int camera_enable_cmd(int argc, char *argv[])
+{
+if (argc)
+ return -1;
+
+ /* Init Camera */
+ set_mem32(CAMERA_BASE, CAMERA_BUF(current_buf = 0)); /* Set address to store to */
+set_mem32(CAMERA_BASE + 4, 1); /* Enable it */
-int crt_disable_cmd (int argc, char *argv[])
-{
- if (argc) return -1;
- set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~1); /* Disable CRT */
- return 0;
-}
+ /* Init CRT to display camera */
+ set_mem32(CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
+camera_pos_x = 0;
+set_mem32(CRT_BASE + 0xc, CAMERA_POS);
+set_mem32(CRT_BASE, get_mem32(CRT_BASE) | 2); /* Enable camera overlay */
-int camera_enable_cmd (int argc, char *argv[])
-{
- if (argc) return -1;
- /* Init Camera */
- set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf = 0)); /* Set address to store to */
- set_mem32 (CAMERA_BASE + 4, 1); /* Enable it */
+ /* Enable interrupts */
+ mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
+mtspr(SPR_PICMR, mfspr(SPR_PICSR) | (1 << 13));
+return 0;
+}
+
+int camera_disable_cmd(int argc, char *argv[])
+{
+if (argc)
+ return -1;
+
+ /* Disable interrupts */
+ mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
+mtspr(SPR_PICMR, mfspr(SPR_PICSR) & ~(1 << 13));
- /* Init CRT to display camera */
- set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
- camera_pos_x = 0;
- set_mem32 (CRT_BASE + 0xc, CAMERA_POS);
- set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 2); /* Enable camera overlay */
-
- /* Enable interrupts */
- mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
- mtspr (SPR_PICMR, mfspr(SPR_PICSR) | (1 << 13));
- return 0;
-}
-
-int camera_disable_cmd (int argc, char *argv[])
-{
- if (argc) return -1;
- /* Disable interrupts */
- mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
- mtspr (SPR_PICMR, mfspr(SPR_PICSR) & ~(1 << 13));
-
- /* Disable Camera */
- set_mem32 (CAMERA_BASE + 4, 1); /* Enable it */
- set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~2); /* Disable camera overlay */
- return 0;
-}
-
-void module_camera_init (void)
-{
- register_command ("crt_enable", "", "enables CRT", crt_enable_cmd);
- register_command ("crt_disable", "", "disables CRT", crt_disable_cmd);
- register_command ("crt_test", "", "enables CRT and displays some test patterns", crt_test_cmd);
- register_command ("camera_enable", "", "enables camera", camera_enable_cmd);
- register_command ("camera_disable", "", "disables camera", camera_disable_cmd);
-}
+ /* Disable Camera */
+ set_mem32(CAMERA_BASE + 4, 1); /* Enable it */
+set_mem32(CRT_BASE, get_mem32(CRT_BASE) & ~2); /* Disable camera overlay */
+return 0;
+}
+
+void module_camera_init(void)
+{
+register_command("crt_enable", "", "enables CRT", crt_enable_cmd);
+register_command("crt_disable", "", "disables CRT", crt_disable_cmd);
+register_command("crt_test", "",
+ "enables CRT and displays some test patterns",
+ crt_test_cmd);
+register_command("camera_enable", "", "enables camera",
+ camera_enable_cmd);
+register_command("camera_disable", "", "disables camera",
+ camera_disable_cmd);
+}
|
/* Camera and CRT test. |
Draws gray cross across the screen, few color boxes at top left and moves around camera captured screen left/right |
in the middle. */ |
|
in the middle. */ |
|
#define CAMERA_BASE 0x88000000 |
#define CRT_BASE 0xc0000000 |
#define VIDEO_RAM_START 0xa8000000 /* till including a83ffffc */ |
|
|
#define SCREEN_X 640 |
#define SCREEN_Y 480 |
|
|
#define CAMERA_X 352 |
#define CAMERA_Y 288 |
|
|
#define CAMERA_BUF(idx) (VIDEO_RAM_START + (idx) * CAMERA_X * CAMERA_Y) |
#define FRAME_BUF (CAMERA_BUF(2)) |
|
|
#define CAMERA_POS (camera_pos_x + ((SCREEN_Y - CAMERA_Y) / 2) * SCREEN_X) |
|
|
#define MIN(x,y) ((x) < (y) ? (x) : (y)) |
|
|
#define set_mem32(addr,val) (*((unsigned long *) (addr)) = (val)) |
#define get_mem32(addr) (*((unsigned long *) (addr))) |
#define set_palette(idx,r,g,b) set_mem32 (CRT_BASE + 0x400 + (idx) * 4, (((r) >> 3) << 11) | (((g) >> 2) << 5) | (((b) >> 3) << 0)) |
#define put_pixel(xx,yy,idx) (*(unsigned char *)(FRAME_BUF + (xx) + (yy) * SCREEN_X) = (idx)) |
/orpmon/cmds/memory.c
3,272 → 3,309
#include "spr-defs.h" |
#include "spincursor.h" |
|
void show_mem (int start, int stop) |
void show_mem(int start, int stop) |
{ |
unsigned long i = start; |
if ((i & 0xf) != 0x0) printf ("\n%08lx: ", i); |
for(; i <= stop; i += 4) { |
if ((i & 0xf) == 0x0) printf ("\n%08lx: ", i); |
/* Read one word */ |
printf ("%08lx ", REG32(i)); |
} |
printf ("\n"); |
unsigned long i = start; |
if ((i & 0xf) != 0x0) |
printf("\n%08lx: ", i); |
for (; i <= stop; i += 4) { |
if ((i & 0xf) == 0x0) |
printf("\n%08lx: ", i); |
/* Read one word */ |
printf("%08lx ", REG32(i)); |
} |
printf("\n"); |
} |
|
void testram (unsigned long start_addr, unsigned long stop_addr, unsigned long testno) |
void testram(unsigned long start_addr, unsigned long stop_addr, |
unsigned long testno) |
{ |
unsigned long addr; |
unsigned long err_addr = 0; |
unsigned long err_no = 0; |
unsigned long addr; |
unsigned long err_addr = 0; |
unsigned long err_no = 0; |
|
/* Test 1: Write locations with their addresses */ |
if ((testno == 1) || (testno == 0)) { |
printf ("\n1. Writing locations with their addresses: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = addr; |
/* Test 1: Write locations with their addresses */ |
if ((testno == 1) || (testno == 0)) { |
printf("\n1. Writing locations with their addresses: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = addr; |
|
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != addr) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr); |
else printf ("Passed"); |
err_no = 0; |
} |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != addr) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) |
printf("%04lx times failed. Last at location %08lx", |
err_no, err_addr); |
else |
printf("Passed"); |
err_no = 0; |
} |
|
/* Test 2: Write locations with their inverse address */ |
if ((testno == 2) || (testno == 0)) { |
printf ("\n2. Writing locations with their inverse addresses: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = ~addr; |
|
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != ~addr) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr); |
else printf ("Passed"); |
err_no = 0; |
} |
/* Test 2: Write locations with their inverse address */ |
if ((testno == 2) || (testno == 0)) { |
printf("\n2. Writing locations with their inverse addresses: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = ~addr; |
|
/* Test 3: Write locations with walking ones */ |
if ((testno == 3) || (testno == 0)) { |
printf ("\n3. Writing locations with walking ones: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = 1 << (addr >> 2); |
|
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != (1 << (addr >> 2))) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr); |
else printf ("Passed"); |
err_no = 0; |
} |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != ~addr) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) |
printf("%04lx times failed. Last at location %08lx", |
err_no, err_addr); |
else |
printf("Passed"); |
err_no = 0; |
} |
|
/* Test 4: Write locations with walking zeros */ |
if ((testno == 4) || (testno == 0)) { |
printf ("\n4. Writing locations with walking zeros: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = ~(1 << (addr >> 2)); |
/* Test 3: Write locations with walking ones */ |
if ((testno == 3) || (testno == 0)) { |
printf("\n3. Writing locations with walking ones: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = 1 << (addr >> 2); |
|
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != ~(1 << (addr >> 2))) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) printf ("%04lx times failed. Last at location %08lx", err_no, err_addr); |
else printf ("Passed"); |
err_no = 0; |
} |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != (1 << (addr >> 2))) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) |
printf("%04lx times failed. Last at location %08lx", |
err_no, err_addr); |
else |
printf("Passed"); |
err_no = 0; |
} |
|
/* Test 4: Write locations with walking zeros */ |
if ((testno == 4) || (testno == 0)) { |
printf("\n4. Writing locations with walking zeros: "); |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
REG32(addr) = ~(1 << (addr >> 2)); |
|
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 4) |
if (REG32(addr) != ~(1 << (addr >> 2))) { |
err_no++; |
err_addr = addr; |
} |
if (err_no) |
printf("%04lx times failed. Last at location %08lx", |
err_no, err_addr); |
else |
printf("Passed"); |
err_no = 0; |
} |
} |
|
|
// Do proper walking 0 as byte writes |
void better_ram_test (unsigned long start_addr, unsigned long stop_addr, unsigned test_no ) |
void better_ram_test(unsigned long start_addr, unsigned long stop_addr, |
unsigned test_no) |
{ |
unsigned long addr; |
unsigned long err_addr = 0; |
unsigned long err_no = 0; |
int b; |
printf ("\nSetting memory contents to all 1'b1 "); |
//enable_spincursor(); |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
REG8(addr) = 0xff; |
//disable_spincursor(); |
printf ("\rVerifying memory contents all set to 1'b1: "); |
//enable_spincursor(); |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
{ |
if (REG8(addr) != 0xff) { |
err_no++; |
err_addr = addr; |
unsigned long addr; |
unsigned long err_addr = 0; |
unsigned long err_no = 0; |
int b; |
printf("\nSetting memory contents to all 1'b1 "); |
//enable_spincursor(); |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
REG8(addr) = 0xff; |
//disable_spincursor(); |
printf ("\n%04lx times failed. Last at location %08lx ", |
err_no, err_addr); |
printf("\rVerifying memory contents all set to 1'b1: "); |
//enable_spincursor(); |
} |
} |
|
if (err_no==0) |
printf ("Passed"); |
else |
printf ("Finished"); |
|
err_no = 0; |
|
printf ("\nWalking zero through memory, verify just itself: "); |
for (addr = start_addr; addr <= stop_addr; addr += 1) |
{ |
for(b=0;b<8;b++) |
{ |
// Write, verify |
REG8(addr) = ~(1<<b); |
/* Verify */ |
for (addr = start_addr; addr <= stop_addr; addr += 1) { |
if (REG8(addr) != 0xff) { |
err_no++; |
err_addr = addr; |
//disable_spincursor(); |
printf("\n%04lx times failed. Last at location %08lx ", |
err_no, err_addr); |
//enable_spincursor(); |
} |
} |
|
if (REG8(addr) != ~(1<<b)) |
{ |
err_no++; |
err_addr = addr; |
printf ("\n%04lx times failed. Last at location %08lx", err_no, err_addr); |
} |
REG8(addr) = 0xff; |
if (err_no == 0) |
printf("Passed"); |
else |
printf("Finished"); |
|
err_no = 0; |
|
printf("\nWalking zero through memory, verify just itself: "); |
for (addr = start_addr; addr <= stop_addr; addr += 1) { |
for (b = 0; b < 8; b++) { |
// Write, verify |
REG8(addr) = ~(1 << b); |
|
if (REG8(addr) != ~(1 << b)) { |
err_no++; |
err_addr = addr; |
printf |
("\n%04lx times failed. Last at location %08lx", |
err_no, err_addr); |
} |
REG8(addr) = 0xff; |
} |
} |
} |
if (err_no == 0) |
printf ("Passed"); |
else |
printf ("Finished"); |
err_no = 0; |
|
printf ("\nWriting across rows, row size configured as %d bytes",SDRAM_ROW_SIZE); |
unsigned long start_row = start_addr / SDRAM_ROW_SIZE; |
unsigned long end_row = stop_addr / SDRAM_ROW_SIZE; |
for (addr = start_row; addr <= end_row; addr += 1) |
{ |
REG32(addr*SDRAM_ROW_SIZE) = addr; |
} |
|
printf ("\rVerifying row write test: "); |
|
for (addr = start_row; addr <= end_row; addr += 1) |
{ |
if (REG32(addr*SDRAM_ROW_SIZE) != addr) |
{ |
err_no++; |
err_addr = addr*SDRAM_ROW_SIZE; |
printf ("\n%04lx times failed. Last at location %08lx (row %d)", err_no, err_addr, addr); |
if (err_no == 0) |
printf("Passed"); |
else |
printf("Finished"); |
err_no = 0; |
|
printf("\nWriting across rows, row size configured as %d bytes", |
SDRAM_ROW_SIZE); |
unsigned long start_row = start_addr / SDRAM_ROW_SIZE; |
unsigned long end_row = stop_addr / SDRAM_ROW_SIZE; |
for (addr = start_row; addr <= end_row; addr += 1) { |
REG32(addr * SDRAM_ROW_SIZE) = addr; |
} |
} |
|
if (err_no == 0) |
printf ("Passed"); |
else |
printf ("Finished"); |
err_no = 0; |
|
|
printf("\rVerifying row write test: "); |
|
for (addr = start_row; addr <= end_row; addr += 1) { |
if (REG32(addr * SDRAM_ROW_SIZE) != addr) { |
err_no++; |
err_addr = addr * SDRAM_ROW_SIZE; |
printf |
("\n%04lx times failed. Last at location %08lx (row %d)", |
err_no, err_addr, addr); |
} |
} |
|
if (err_no == 0) |
printf("Passed"); |
else |
printf("Finished"); |
err_no = 0; |
|
} |
|
|
int dm_cmd (int argc, char *argv[]) |
int dm_cmd(int argc, char *argv[]) |
{ |
unsigned long a1,a2; |
a1 = strtoul(argv[0], 0, 0); |
switch (argc) { |
case 1: show_mem (a1, a1); return 0; |
case 2: |
a2 = strtoul(argv[1], 0, 0); |
show_mem (a1, a2); return 0; |
default: return -1; |
} |
unsigned long a1, a2; |
a1 = strtoul(argv[0], 0, 0); |
switch (argc) { |
case 1: |
show_mem(a1, a1); |
return 0; |
case 2: |
a2 = strtoul(argv[1], 0, 0); |
show_mem(a1, a2); |
return 0; |
default: |
return -1; |
} |
} |
|
int pm_cmd (int argc, char *argv[]) |
int pm_cmd(int argc, char *argv[]) |
{ |
unsigned long addr, stop_addr, value; |
if ((argc == 3) || (argc == 2)) { |
addr = strtoul (argv[0], 0, 0); |
|
if (argc == 2) { |
stop_addr = strtoul (argv[0], 0, 0); |
value = strtoul (argv[1], 0, 0); |
} else { |
stop_addr = strtoul (argv[1], 0, 0); |
value = strtoul (argv[2], 0, 0); |
} |
|
for (; addr <= stop_addr; addr += 4) REG32(addr) = value; |
|
/*show_mem(strtoul (argv[0], 0, 0), stop_addr);*/ |
} else return -1; |
return 0; |
unsigned long addr, stop_addr, value; |
if ((argc == 3) || (argc == 2)) { |
addr = strtoul(argv[0], 0, 0); |
|
if (argc == 2) { |
stop_addr = strtoul(argv[0], 0, 0); |
value = strtoul(argv[1], 0, 0); |
} else { |
stop_addr = strtoul(argv[1], 0, 0); |
value = strtoul(argv[2], 0, 0); |
} |
|
for (; addr <= stop_addr; addr += 4) |
REG32(addr) = value; |
|
/*show_mem(strtoul (argv[0], 0, 0), stop_addr); */ |
} else |
return -1; |
return 0; |
} |
|
int ram_test_cmd (int argc, char *argv[]) |
int ram_test_cmd(int argc, char *argv[]) |
{ |
switch (argc) { |
case 2: testram(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), 0); return 0; |
case 3: testram(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), strtoul (argv[2], 0, 0)); return 0; |
default: return -1; |
} |
switch (argc) { |
case 2: |
testram(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0), 0); |
return 0; |
case 3: |
testram(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0), |
strtoul(argv[2], 0, 0)); |
return 0; |
default: |
return -1; |
} |
} |
|
int better_ram_test_cmd (int argc, char *argv[]) |
int better_ram_test_cmd(int argc, char *argv[]) |
{ |
if (argc < 2) |
return -1; |
|
better_ram_test(strtoul (argv[0], 0, 0), strtoul (argv[1], 0, 0), 0); |
return 0; |
if (argc < 2) |
return -1; |
|
better_ram_test(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0), 0); |
return 0; |
} |
|
unsigned long crc32 (unsigned long crc, const unsigned char *buf, unsigned long len) |
unsigned long crc32(unsigned long crc, const unsigned char *buf, |
unsigned long len) |
{ |
/* Create bitwise CRC table first */ |
unsigned long crc_table[256]; |
int i, k; |
for (i = 0; i < 256; i++) { |
unsigned long c = (unsigned long)i; |
for (k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >> 1) : c >> 1; |
crc_table[i] = c; |
} |
/* Create bitwise CRC table first */ |
unsigned long crc_table[256]; |
int i, k; |
for (i = 0; i < 256; i++) { |
unsigned long c = (unsigned long)i; |
for (k = 0; k < 8; k++) |
c = c & 1 ? 0xedb88320 ^ (c >> 1) : c >> 1; |
crc_table[i] = c; |
} |
|
/* Calculate crc on buf */ |
crc = crc ^ 0xffffffffL; |
while (len--) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); |
return crc ^ 0xffffffffL; |
/* Calculate crc on buf */ |
crc = crc ^ 0xffffffffL; |
while (len--) |
crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); |
return crc ^ 0xffffffffL; |
} |
|
int crc_cmd (int argc, char *argv[]) |
int crc_cmd(int argc, char *argv[]) |
{ |
unsigned long addr = global.src_addr; |
unsigned long len = global.length; |
unsigned long init_crc = 0; |
|
switch (argc) { |
case 3: init_crc = strtoul (argv[2], 0, 0); |
case 2: len = strtoul (argv[1], 0, 0); |
case 1: addr = strtoul (argv[0], 0, 0); |
case 0: |
printf ("CRC [%08lx-%08lx] = %08lx\n", addr, addr + len - 1, crc32 (init_crc, (unsigned char *)addr, len)); |
return 0; |
} |
return -1; |
unsigned long addr = global.src_addr; |
unsigned long len = global.length; |
unsigned long init_crc = 0; |
|
switch (argc) { |
case 3: |
init_crc = strtoul(argv[2], 0, 0); |
case 2: |
len = strtoul(argv[1], 0, 0); |
case 1: |
addr = strtoul(argv[0], 0, 0); |
case 0: |
printf("CRC [%08lx-%08lx] = %08lx\n", addr, addr + len - 1, |
crc32(init_crc, (unsigned char *)addr, len)); |
return 0; |
} |
return -1; |
} |
|
void module_memory_init (void) |
void module_memory_init(void) |
{ |
register_command ("dm", "<start addr> [<end addr>]", "display 32-bit memory location(s)", dm_cmd); |
register_command ("pm", "<addr> [<stop_addr>] <value>", "patch 32-bit memory location(s)", pm_cmd); |
register_command ("ram_test", "<start_addr> <stop_addr> [<test_no>]", "run a simple RAM test", ram_test_cmd); |
register_command ("better_ram_test", "<start_addr> <stop_addr>", "run a better RAM test", better_ram_test_cmd); |
register_command("dm", "<start addr> [<end addr>]", |
"display 32-bit memory location(s)", dm_cmd); |
register_command("pm", "<addr> [<stop_addr>] <value>", |
"patch 32-bit memory location(s)", pm_cmd); |
register_command("ram_test", "<start_addr> <stop_addr> [<test_no>]", |
"run a simple RAM test", ram_test_cmd); |
register_command("better_ram_test", "<start_addr> <stop_addr>", |
"run a better RAM test", better_ram_test_cmd); |
|
register_command ("crc", "[<src_addr> [<length> [<init_crc>]]]", "Calculates a 32-bit CRC on specified memory region", crc_cmd); |
register_command("crc", "[<src_addr> [<length> [<init_crc>]]]", |
"Calculates a 32-bit CRC on specified memory region", |
crc_cmd); |
} |
/orpmon/cmds/hdbug.c
19,7 → 19,6
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
*/ |
|
|
#include "support.h" |
#include "common.h" |
#include "dos.h" |
26,7 → 25,6
#include "hdbug.h" |
#include <ctype.h> |
|
|
static int hdbug_num_commands; |
static command_struct hdbug_command[MAX_HDBUG_COMMANDS]; |
|
33,7 → 31,6
static struct dosparam _dos_params; |
static struct dosparam *dos_params = &_dos_params; |
|
|
/**********************************************************************/ |
/* */ |
/* H D B U G */ |
45,20 → 42,25
initializes the ata core, mounts the DOS file system, and |
provides methods for accessing DOS drives |
*/ |
void module_hdbug_init (void) |
void module_hdbug_init(void) |
{ |
hdbug_num_commands = 0; |
hdbug_num_commands = 0; |
|
register_command ("hdbug", "<device> [<mode>]", "Opens ata device <device> & mounts DOS filesystem", hdbug_mount_cmd); |
register_hdbug_command ("umount", "", "Unmounts DOS filesystem & Closes device", hdbug_umount_cmd); |
register_command("hdbug", "<device> [<mode>]", |
"Opens ata device <device> & mounts DOS filesystem", |
hdbug_mount_cmd); |
register_hdbug_command("umount", "", |
"Unmounts DOS filesystem & Closes device", |
hdbug_umount_cmd); |
|
register_hdbug_command ("dir", "", "dos 'dir' command.", hdbug_dir_cmd); |
register_hdbug_command ("cd", "", "dos 'cd' command.", hdbug_cd_cmd); |
register_hdbug_command ("help", "", "Display this help message", hdbug_help); |
register_hdbug_command ("exit", "", "Exit hdbug and return to ORPmon", hdbug_umount_cmd); |
register_hdbug_command("dir", "", "dos 'dir' command.", hdbug_dir_cmd); |
register_hdbug_command("cd", "", "dos 'cd' command.", hdbug_cd_cmd); |
register_hdbug_command("help", "", "Display this help message", |
hdbug_help); |
register_hdbug_command("exit", "", "Exit hdbug and return to ORPmon", |
hdbug_umount_cmd); |
} |
|
|
/* |
The next code is graceously taken from the "common.c" file |
and slightly modified. |
70,110 → 72,108
/* Process command-line, generate arguments */ |
int hdbug_mon_command(void) |
{ |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
|
/* Show prompt */ |
printf("\nhdbug> "); |
|
/* Show prompt */ |
printf ("\nhdbug> "); |
/* Get characters from UART */ |
c = getc(); |
while (c != '\r' && c != '\f' && c != '\n') { |
if (c == '\b') |
pstr--; |
else |
*pstr++ = c; |
putc(c); |
c = getc(); |
} |
*pstr = '\0'; |
printf("\n"); |
|
/* Skip leading blanks */ |
pstr = str; |
while (isspace(*pstr)) |
pstr++; |
|
/* Get characters from UART */ |
c = getc(); |
while (c != '\r' && c != '\f' && c != '\n') |
{ |
if (c == '\b') |
pstr--; |
else |
*pstr++ = c; |
putc(c); |
c = getc(); |
} |
*pstr = '\0'; |
printf ("\n"); |
/* Get command from the string */ |
command_str = pstr; |
|
/* Skip leading blanks */ |
pstr = str; |
while ( isspace(*pstr) ) pstr++; |
while (1) { |
/* Go to next argument */ |
while (isgraph(*pstr)) |
pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while (isspace(*pstr)) |
pstr++; |
argv[argc++] = pstr; |
} else |
break; |
} |
|
/* Get command from the string */ |
command_str = pstr; |
|
while (1) { |
/* Go to next argument */ |
while ( isgraph(*pstr) ) pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while ( isspace(*pstr) ) pstr++; |
argv[argc++] = pstr; |
} |
else |
break; |
} |
|
return execute_hdbug_command(command_str, argc, argv); |
return execute_hdbug_command(command_str, argc, argv); |
} |
|
|
int execute_hdbug_command(char *command_str, int argc, char **argv) |
{ |
int i, found = 0; |
int i, found = 0; |
|
for (i = 0; i < hdbug_num_commands; i++) |
if ( !strcmp(command_str, hdbug_command[i].name) ) |
{ |
switch ( hdbug_command[i].func(argc, argv) ) |
{ |
case -1: |
printf ("Missing/wrong parameters, usage: %s %s\n", hdbug_command[i].name, hdbug_command[i].params); |
break; |
for (i = 0; i < hdbug_num_commands; i++) |
if (!strcmp(command_str, hdbug_command[i].name)) { |
switch (hdbug_command[i].func(argc, argv)) { |
case -1: |
printf |
("Missing/wrong parameters, usage: %s %s\n", |
hdbug_command[i].name, |
hdbug_command[i].params); |
break; |
|
case -2: |
return -1; |
} |
case -2: |
return -1; |
} |
|
found++; |
break; |
} |
found++; |
break; |
} |
|
if (!found) |
printf ("Unknown command. Type 'hdbug help' for help.\n"); |
if (!found) |
printf("Unknown command. Type 'hdbug help' for help.\n"); |
|
return 0; |
return 0; |
} |
|
|
void register_hdbug_command (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[]) ) |
void register_hdbug_command(const char *name, const char *params, |
const char *help, int (*func) (int argc, |
char *argv[])) |
{ |
if (hdbug_num_commands < MAX_HDBUG_COMMANDS) |
{ |
hdbug_command[hdbug_num_commands].name = name; |
hdbug_command[hdbug_num_commands].params = params; |
hdbug_command[hdbug_num_commands].help = help; |
hdbug_command[hdbug_num_commands].func = func; |
hdbug_num_commands++; |
} |
else |
printf ("hdbug-command '%s' ignored; MAX_COMMANDS limit reached\n", name); |
if (hdbug_num_commands < MAX_HDBUG_COMMANDS) { |
hdbug_command[hdbug_num_commands].name = name; |
hdbug_command[hdbug_num_commands].params = params; |
hdbug_command[hdbug_num_commands].help = help; |
hdbug_command[hdbug_num_commands].func = func; |
hdbug_num_commands++; |
} else |
printf |
("hdbug-command '%s' ignored; MAX_COMMANDS limit reached\n", |
name); |
} |
|
int hdbug_help(int argc, char **argv) |
{ |
int i; |
int i; |
|
for (i = 0; i < hdbug_num_commands; i++) |
printf ("%-15s %-17s -%s\n", hdbug_command[i].name, hdbug_command[i].params, hdbug_command[i].help); |
for (i = 0; i < hdbug_num_commands; i++) |
printf("%-15s %-17s -%s\n", hdbug_command[i].name, |
hdbug_command[i].params, hdbug_command[i].help); |
|
return 0; |
return 0; |
} |
|
|
|
|
/**********************************************************************/ |
/* */ |
/* H D B U G C O M M A N D S E T */ |
187,59 → 187,54
*/ |
int hdbug_mount_cmd(int argc, char **argv) |
{ |
int error; |
int error; |
|
if (argc != 2) |
return -1; |
if (argc != 2) |
return -1; |
|
/* try to open the requested device (read-only) */ |
dos_params->inode.i_rdev = (ATA_BASE_ADDR >> 16) | (**argv - '0'); |
dos_params->filp.f_mode = FMODE_READ; |
|
/* try to open the requested device (read-only) */ |
dos_params->inode.i_rdev = (ATA_BASE_ADDR >> 16) | (**argv - '0'); |
dos_params->filp.f_mode = FMODE_READ; |
/* open device */ |
if ((error = dos_open(dos_params))) { |
switch (error) { |
case EINVAL: |
printf("Error, device busy.\n"); /* standard response to EINVAL */ |
break; |
|
/* open device */ |
if ( (error = dos_open(dos_params)) ) |
{ |
switch (error) { |
case EINVAL: |
printf( "Error, device busy.\n" ); /* standard response to EINVAL */ |
break; |
case EIOCTLIARG: |
printf("Error, invalid IOCTL call.\n"); |
break; |
|
case EIOCTLIARG: |
printf( "Error, invalid IOCTL call.\n" ); |
break; |
case EOPENIDEV: |
printf("Error, invalid device.\n"); |
break; |
|
case EOPENIDEV: |
printf( "Error, invalid device.\n" ); |
break; |
case EOPENIHOST: |
printf("Error, ata host controller not found.\n"); |
break; |
|
case EOPENIHOST: |
printf( "Error, ata host controller not found.\n" ); |
break; |
case EOPENNODEV: |
printf("Error, ata-device not found.\n"); |
break; |
|
case EOPENNODEV: |
printf( "Error, ata-device not found.\n" ); |
break; |
default: |
printf("Unkown error.\n"); |
break; |
} |
} else { |
printf("directory startsector: 0x%08lX\n", dos_params->ssector); |
printf("cluster startsector : 0x%08lX\n", dos_params->csector); |
printf("cluster startentry : 0x%08lX\n", dos_params->sentry); |
|
default: |
printf( "Unkown error.\n" ); |
break; |
} |
} |
else |
{ |
printf( "directory startsector: 0x%08lX\n", dos_params->ssector ); |
printf( "cluster startsector : 0x%08lX\n", dos_params->csector ); |
printf( "cluster startentry : 0x%08lX\n", dos_params->sentry ); |
/* device is opened, filesystem is mounted, start command prompt */ |
while (!hdbug_mon_command()) ; |
} |
|
/* device is opened, filesystem is mounted, start command prompt */ |
while ( !hdbug_mon_command() ); |
} |
|
return 0; |
return 0; |
} |
|
|
/* |
H D B U G _ U M O U N T |
|
247,157 → 242,152
*/ |
int hdbug_umount_cmd(int argc, char **argv) |
{ |
dos_release(dos_params); |
dos_release(dos_params); |
|
return -2; |
return -2; |
} |
|
|
/* |
H D B U G _ C D |
*/ |
int hdbug_cd_cmd(int argc, char **argv) |
{ |
struct dos_dir_entry *entry; |
struct dos_dir_entry *entry; |
|
switch (argc) { |
case 0: |
/* display present working directory */ |
printf( "FIXME: present working directory\n" ); |
return 0; |
switch (argc) { |
case 0: |
/* display present working directory */ |
printf("FIXME: present working directory\n"); |
return 0; |
|
case 1: |
break; |
case 1: |
break; |
|
default: |
printf( "Too many arguments.\n" ); |
return 0; |
} |
default: |
printf("Too many arguments.\n"); |
return 0; |
} |
|
/* search for the requested directory */ |
if ( !(entry = dos_dir_find_entry(dos_params, *argv)) ) |
{ |
printf( "The system cannot find the specified path.\n" ); |
return 0; |
} |
/* search for the requested directory */ |
if (!(entry = dos_dir_find_entry(dos_params, *argv))) { |
printf("The system cannot find the specified path.\n"); |
return 0; |
} |
|
|
return 0; |
return 0; |
} |
|
|
/* |
H D B U G _ D I R |
*/ |
int hdbug_dir_cmd(int argc, char **argv) |
{ |
register int i; |
register int i; |
|
/* read the directory structures from the current directory |
and display the results */ |
/* read the directory structures from the current directory |
and display the results */ |
|
/* TODO: Add sub-directories */ |
/* TODO: Add sub-directories */ |
|
/* get first cluster of current directory */ |
dos_dir_cluster_reset(dos_params); |
/* get first cluster of current directory */ |
dos_dir_cluster_reset(dos_params); |
|
for (i=0; i < dos_params->root_entries; i++) |
hdbug_dir_print( dos_dir_get_entry(dos_params, i) ); |
for (i = 0; i < dos_params->root_entries; i++) |
hdbug_dir_print(dos_dir_get_entry(dos_params, i)); |
|
return 0; |
return 0; |
} |
|
|
int hdbug_dir_print(struct dos_dir_entry *entry) |
{ |
unsigned long ltmp; |
unsigned short stmp; |
unsigned long ltmp; |
unsigned short stmp; |
|
char txt[9]; |
char txt[9]; |
|
switch (entry->name[0]) { |
case 0x00: |
/* empty entry */ |
break; |
switch (entry->name[0]) { |
case 0x00: |
/* empty entry */ |
break; |
|
case 0xe5: |
/* deleted/removed entry */ |
break; |
case 0xe5: |
/* deleted/removed entry */ |
break; |
|
default: |
/* check if entry is a label */ |
if (entry->attribute & ATT_LAB) |
{ |
printf( "LABEL: " ); |
memcpy(txt, entry->name, 8); |
txt[8] = '\0'; |
printf( "%s", txt); |
memcpy(txt, entry->ext, 3); |
txt[3] = '\0'; |
printf( "%s\n", txt); |
} |
else |
{ |
/* display date & time */ |
stmp = entry->date; |
swap(&stmp, sizeof(short) ); |
printf( "%02d-%02d-%4d ",stmp & 0x1f, (stmp >> 5) & 0xf, ((stmp >> 9) & 0xffff) +1980); |
default: |
/* check if entry is a label */ |
if (entry->attribute & ATT_LAB) { |
printf("LABEL: "); |
memcpy(txt, entry->name, 8); |
txt[8] = '\0'; |
printf("%s", txt); |
memcpy(txt, entry->ext, 3); |
txt[3] = '\0'; |
printf("%s\n", txt); |
} else { |
/* display date & time */ |
stmp = entry->date; |
swap(&stmp, sizeof(short)); |
printf("%02d-%02d-%4d ", stmp & 0x1f, |
(stmp >> 5) & 0xf, |
((stmp >> 9) & 0xffff) + 1980); |
|
stmp = entry->time; |
swap(&stmp, sizeof(short) ); |
printf( "%02d:%02d ", (stmp >> 11) & 0x1f, (stmp >> 5) & 0x3f ); |
stmp = entry->time; |
swap(&stmp, sizeof(short)); |
printf("%02d:%02d ", (stmp >> 11) & 0x1f, |
(stmp >> 5) & 0x3f); |
|
/* display directory bit */ |
printf( "%s ", entry->attribute & ATT_DIR ? "<DIR>" : " " ); |
/* display directory bit */ |
printf("%s ", |
entry->attribute & ATT_DIR ? "<DIR>" : " "); |
|
/* display filesize */ |
ltmp = entry->size; |
swap(<mp, sizeof(unsigned long) ); |
printf( "%12ld ", ltmp ); |
/* display filesize */ |
ltmp = entry->size; |
swap(<mp, sizeof(unsigned long)); |
printf("%12ld ", ltmp); |
|
/* replace the first 'space' in the name by an null char */ |
*(char*)memchr(entry->name, 0x20, 8) = '\0'; |
printf( "%s", entry->name); |
/* replace the first 'space' in the name by an null char */ |
*(char *)memchr(entry->name, 0x20, 8) = '\0'; |
printf("%s", entry->name); |
|
/* add extension */ |
if (entry->ext[0] != 0x20) |
{ |
printf( ".%3s", entry->ext); |
} |
/* add extension */ |
if (entry->ext[0] != 0x20) { |
printf(".%3s", entry->ext); |
} |
|
printf("\n"); |
break; |
} |
} |
printf("\n"); |
break; |
} |
} |
|
return 0; |
return 0; |
} |
|
|
/* |
H D B U G T O O L S |
*/ |
inline void *swap(void *var, size_t size) |
{ |
switch(size) { |
case 1: |
return var; |
switch (size) { |
case 1: |
return var; |
|
case 2: |
{ |
unsigned short p = *(unsigned short*)var; |
*(unsigned short*)var = (p << 8) | (p >> 8); |
return var; |
} |
case 2: |
{ |
unsigned short p = *(unsigned short *)var; |
*(unsigned short *)var = (p << 8) | (p >> 8); |
return var; |
} |
|
case 4: |
{ |
unsigned long *p = (unsigned long*)var; |
*p = (*p << 24) | ( (*p & 0x0000ff00) << 8) | ( (*p & 0x00ff0000) >> 8) | (*p >> 24); |
return var; |
} |
case 4: |
{ |
unsigned long *p = (unsigned long *)var; |
*p = (*p << 24) | ((*p & 0x0000ff00) << 8) | |
((*p & 0x00ff0000) >> 8) | (*p >> 24); |
return var; |
} |
|
default: |
return NULL; |
} |
default: |
return NULL; |
} |
} |
/orpmon/common/dosfs.c
//#include
//#include "or32_utils.h"
#include "dosfs.h"
#include "sdc.h"
-
+
#include "common.h"
#include "support.h"
#include "uart.h"
+unsigned long int init_fat(VOLINFO * vis)
+{
+unsigned char sector[SECTOR_SIZE];
+unsigned long int pstart, psize, i, fisz;
+unsigned char pactive, ptype;
+VOLINFO vi;
+ //uart_init(DEFAULT_UART);
+ printf("FAT INIT START\n");
+memCardInit();
+pstart = DFS_GetPtnStart(0, sector, 0, &pactive, &ptype, &psize);
+if (pstart == 0xffffffff) {
+printf("Cannot find first partition\n");
+return -1;
+}
+printf
+ ("Partition 0 start sector 0x%-08.8lX active %-02.2hX type %-02.2hX size %-08.8lX\n",
+ pstart, pactive, ptype, psize);
+if (DFS_GetVolInfo(0, sector, pstart, &vi)) {
+printf("Error getting volume information\n");
+return -1;
+}
+*vis = vi;
+}
+
+unsigned long int DFS_ReadSector(unsigned char unit, unsigned char *buffer,
+ unsigned long int sector,
+ unsigned long int count)
+{
+unsigned long int block_add = 0;
+int i;
+for (i = 0; i < count; i++) {
+block_add = sector + i;
+DBGA("\n readSector %u, block_addr %u \n", sector, block_add);
+setup_bd_transfer(READ_OP, block_add, buffer);
+if (finnish_bd_transfer() == FALSE)
+return 0xff;
+}
+return 0;
+}
+
+unsigned long int DFS_WriteSector(unsigned char unit, unsigned char *buffer,
+ unsigned long int sector,
+ unsigned long int count)
+{
+unsigned long int block_add = 0;
+unsigned char scr[SECTOR_SIZE];
+block_add = sector;
+DBGA("\n writeSector %u, block_addr2 %u \n", sector, block_add);
+setup_bd_transfer(WRITE_OP, block_add, buffer);
+if (finnish_bd_transfer() == FALSE) {
+printf("TRANSACTION FAILED, Buffer %x \n", buffer);
+ //reset_card();
+ // sd_wait_rsp();
+ // SD_REG(SD_SOFTWARE_RST)=1;
+
+ //SD_REG(SD_SOFTWARE_RST)=0;
+DBGA("FREE BD TX/RX: 0x%x \n", SD_REG(BD_STATUS));
+DBGA("TRY READ SECTOR \n");
+setup_bd_transfer(READ_OP, 526571008, scr);
+finnish_bd_transfer();
+DBGA("PRINT test wreite to 526571008 \n");
+setup_bd_transfer(WRITE_OP, 526571008, scr);
+finnish_bd_transfer();
+setup_bd_transfer(WRITE_OP, block_add, buffer);
+if (finnish_bd_transfer() == FALSE) {
+printf("TRANSACTION FAILED AGAIN!, Buffer %x \n",
+ buffer);
+return 0xff;
+}
+}
+return 0;
+}
+
-unsigned long int init_fat(VOLINFO *vis){
-
-
-
- unsigned char sector[SECTOR_SIZE];
- unsigned long int pstart,psize, i,fisz;
- unsigned char pactive, ptype;
- VOLINFO vi;
-
-
- //uart_init(DEFAULT_UART);
- printf("FAT INIT START\n");
- memCardInit();
-
-
- pstart = DFS_GetPtnStart(0, sector, 0, &pactive, &ptype, &psize);
- if (pstart == 0xffffffff) {
- printf("Cannot find first partition\n");
- return -1;
- }
-
- printf("Partition 0 start sector 0x%-08.8lX active %-02.2hX type %-02.2hX size %-08.8lX\n", pstart, pactive, ptype, psize);
-
- if (DFS_GetVolInfo(0, sector, pstart, &vi)) {
- printf("Error getting volume information\n");
- return -1;
- }
-
-
-
-
- *vis=vi;
-
-
-
-}
-
-
-unsigned long int DFS_ReadSector(unsigned char unit, unsigned char *buffer, unsigned long int sector, unsigned long int count)
-{
-
- unsigned long int block_add = 0;
- int i ;
-
-
-
- for (i=0; i 3)
+return DFS_ERRMISC;
-unsigned long int DFS_GetPtnStart(unsigned char unit, unsigned char *scratchsector, unsigned char pnum, unsigned char *pactive, unsigned char *pptype, unsigned long int *psize)
-{
- unsigned long int result;
- PMBR mbr = (PMBR) scratchsector;
+ // Read MBR from target media
+ if (DFS_ReadSector(unit, scratchsector, 0, 1)) {
+return DFS_ERRMISC;
+}
+result = (unsigned long int)mbr->ptable[pnum].start_0 |
+ (((unsigned long int)mbr->ptable[pnum].start_1) << 8) |
+ (((unsigned long int)mbr->ptable[pnum].start_2) << 16) |
+ (((unsigned long int)mbr->ptable[pnum].start_3) << 24);
- // DOS ptable supports maximum 4 partitions
- if (pnum > 3)
- return DFS_ERRMISC;
+ //unsigned char active; // 0x80 if partition active
+ //unsigned char start_h; // starting head
+ //unsigned char start_cs_l; // starting cylinder and sector (low byte)
+ //unsigned char start_cs_h; // starting cylinder and sector (high byte)
+printf("active 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].active,
+ mbr->ptable[pnum].start_h, mbr->ptable[pnum].start_cs_l,
+ mbr->ptable[pnum].start_cs_h);
+printf("start 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].start_0,
+ mbr->ptable[pnum].start_1, mbr->ptable[pnum].start_2,
+ mbr->ptable[pnum].start_3);
+if (pactive)
+*pactive = mbr->ptable[pnum].active;
+if (pptype)
+*pptype = mbr->ptable[pnum].type;
+if (psize) {
+*psize = (unsigned long int)mbr->ptable[pnum].size_0 |
+ (((unsigned long int)mbr->ptable[pnum].size_1) << 8) |
+ (((unsigned long int)mbr->ptable[pnum].size_2) << 16) |
+ (((unsigned long int)mbr->ptable[pnum].size_3) << 24);
+printf("size 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].size_0,
+ mbr->ptable[pnum].size_1, mbr->ptable[pnum].size_2,
+ mbr->ptable[pnum].size_3);
+}
+return result;
+}
+
+ldiv_t ldiv(long int numer, long int denom)
+{
+ldiv_t result;
+result.quot = numer / denom;
+result.rem = numer % denom;
- // Read MBR from target media
- if (DFS_ReadSector(unit,scratchsector,0,1)) {
- return DFS_ERRMISC;
- }
+ /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
+ NUMER / DENOM is to be computed in infinite precision. In
+ other words, we should always truncate the quotient towards
+ zero, never -infinity. Machine division and remainer may
+ work either way when one or both of NUMER or DENOM is
+ negative. If only one is negative and QUOT has been
+ truncated towards -infinity, REM will have the same sign as
+ DENOM and the opposite sign of NUMER; if both are negative
+ and QUOT has been truncated towards -infinity, REM will be
+ positive (will have the opposite sign of NUMER). These are
+ considered `wrong'. If both are NUM and DENOM are positive,
+ RESULT will always be positive. This all boils down to: if
+ NUMER >= 0, but REM < 0, we got the wrong answer. In that
+ case, to get the right answer, add 1 to QUOT and subtract
+ DENOM from REM. */
+if (numer >= 0 && result.rem < 0)
+ {
+++result.quot;
+result.rem -= denom;
+}
+return result;
+}
+
+div_t div(int numer, int denom)
+{
+div_t result;
+result.quot = numer / denom;
+result.rem = numer % denom;
- result = (unsigned long int) mbr->ptable[pnum].start_0 |
- (((unsigned long int) mbr->ptable[pnum].start_1) << 8) |
- (((unsigned long int) mbr->ptable[pnum].start_2) << 16) |
- (((unsigned long int) mbr->ptable[pnum].start_3) << 24);
-
-
- //unsigned char active; // 0x80 if partition active
- //unsigned char start_h; // starting head
- //unsigned char start_cs_l; // starting cylinder and sector (low byte)
- //unsigned char start_cs_h; // starting cylinder and sector (high byte)
-
- printf("active 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].active, mbr->ptable[pnum].start_h, mbr->ptable[pnum].start_cs_l,mbr->ptable[pnum].start_cs_h);
-
- printf("start 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].start_0, mbr->ptable[pnum].start_1,mbr->ptable[pnum].start_2,mbr->ptable[pnum].start_3);
- if (pactive)
- *pactive = mbr->ptable[pnum].active;
+ /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
+ NUMER / DENOM is to be computed in infinite precision. In
+ other words, we should always truncate the quotient towards
+ zero, never -infinity. Machine division and remainer may
+ work either way when one or both of NUMER or DENOM is
+ negative. If only one is negative and QUOT has been
+ truncated towards -infinity, REM will have the same sign as
+ DENOM and the opposite sign of NUMER; if both are negative
+ and QUOT has been truncated towards -infinity, REM will be
+ positive (will have the opposite sign of NUMER). These are
+ considered `wrong'. If both are NUM and DENOM are positive,
+ RESULT will always be positive. This all boils down to: if
+ NUMER >= 0, but REM < 0, we got the wrong answer. In that
+ case, to get the right answer, add 1 to QUOT and subtract
+ DENOM from REM. */
+if (numer >= 0 && result.rem < 0)
+ {
+++result.quot;
+result.rem -= denom;
+}
+return result;
+}
+
- if (pptype)
- *pptype = mbr->ptable[pnum].type;
-
- if (psize){
- *psize = (unsigned long int) mbr->ptable[pnum].size_0 |
- (((unsigned long int) mbr->ptable[pnum].size_1) << 8) |
- (((unsigned long int) mbr->ptable[pnum].size_2) << 16) |
- (((unsigned long int) mbr->ptable[pnum].size_3) << 24);
- printf("size 0:%x 1:%x 2:%x 3:%x \n", mbr->ptable[pnum].size_0, mbr->ptable[pnum].size_1,mbr->ptable[pnum].size_2,mbr->ptable[pnum].size_3);
- }
-
- return result;
-}
-
-
-
- ldiv_t ldiv (long int numer, long int denom)
-{
- ldiv_t result;
-
- result.quot = numer / denom;
- result.rem = numer % denom;
-
- /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
- NUMER / DENOM is to be computed in infinite precision. In
- other words, we should always truncate the quotient towards
- zero, never -infinity. Machine division and remainer may
- work either way when one or both of NUMER or DENOM is
- negative. If only one is negative and QUOT has been
- truncated towards -infinity, REM will have the same sign as
- DENOM and the opposite sign of NUMER; if both are negative
- and QUOT has been truncated towards -infinity, REM will be
- positive (will have the opposite sign of NUMER). These are
- considered `wrong'. If both are NUM and DENOM are positive,
- RESULT will always be positive. This all boils down to: if
- NUMER >= 0, but REM < 0, we got the wrong answer. In that
- case, to get the right answer, add 1 to QUOT and subtract
- DENOM from REM. */
-
- if (numer >= 0 && result.rem < 0)
- {
- ++result.quot;
- result.rem -= denom;
- }
-
- return result;
-}
-
- div_t div ( int numer, int denom)
-{
- div_t result;
-
- result.quot = numer / denom;
- result.rem = numer % denom;
-
- /* The ANSI standard says that |QUOT| <= |NUMER / DENOM|, where
- NUMER / DENOM is to be computed in infinite precision. In
- other words, we should always truncate the quotient towards
- zero, never -infinity. Machine division and remainer may
- work either way when one or both of NUMER or DENOM is
- negative. If only one is negative and QUOT has been
- truncated towards -infinity, REM will have the same sign as
- DENOM and the opposite sign of NUMER; if both are negative
- and QUOT has been truncated towards -infinity, REM will be
- positive (will have the opposite sign of NUMER). These are
- considered `wrong'. If both are NUM and DENOM are positive,
- RESULT will always be positive. This all boils down to: if
- NUMER >= 0, but REM < 0, we got the wrong answer. In that
- case, to get the right answer, add 1 to QUOT and subtract
- DENOM from REM. */
-
- if (numer >= 0 && result.rem < 0)
- {
- ++result.quot;
- result.rem -= denom;
- }
-
- return result;
-}
/*
Retrieve volume info from BPB and store it in a VOLINFO structure
You must provide the unit and starting sector of the filesystem, and
@@ -259,94 +380,158 @@
a pointer to a sector buffer for scratch
Attempts to read BPB and glean information about the FS from that.
Returns 0 OK, nonzero for any error.
-*/
-unsigned long int DFS_GetVolInfo(unsigned char unit, unsigned char *scratchsector, unsigned long int startsector, PVOLINFO volinfo)
-{
- PLBR lbr = (PLBR) scratchsector;
- volinfo->unit = unit;
- volinfo->startsector = startsector;
+*/
+unsigned long int DFS_GetVolInfo(unsigned char unit,
+ unsigned char *scratchsector,
+ unsigned long int startsector,
+ PVOLINFO volinfo)
+{
+PLBR lbr = (PLBR) scratchsector;
+volinfo->unit = unit;
+volinfo->startsector = startsector;
+if (DFS_ReadSector(unit, scratchsector, startsector, 1))
+return DFS_ERRMISC;
- if(DFS_ReadSector(unit,scratchsector,startsector,1))
- return DFS_ERRMISC;
-
// tag: OEMID, refer dosfs.h
-// strncpy(volinfo->oemid, lbr->oemid, 8);
-// volinfo->oemid[8] = 0;
+// strncpy(volinfo->oemid, lbr->oemid, 8);
+// volinfo->oemid[8] = 0;
+volinfo->secperclus = lbr->bpb.secperclus;
+volinfo->reservedsecs = (unsigned short)lbr->bpb.reserved_l |
+ (((unsigned short)lbr->bpb.reserved_h) << 8);
+volinfo->numsecs = (unsigned short)lbr->bpb.sectors_s_l |
+ (((unsigned short)lbr->bpb.sectors_s_h) << 8);
+if (!volinfo->numsecs)
+volinfo->numsecs = (unsigned long int)lbr->bpb.sectors_l_0 |
+ (((unsigned long int)lbr->bpb.sectors_l_1) << 8) |
+ (((unsigned long int)lbr->bpb.sectors_l_2) << 16) |
+ (((unsigned long int)lbr->bpb.sectors_l_3) << 24);
- volinfo->secperclus = lbr->bpb.secperclus;
- volinfo->reservedsecs = (unsigned short) lbr->bpb.reserved_l |
- (((unsigned short) lbr->bpb.reserved_h) << 8);
+ // If secperfat is 0, we must be in a FAT32 volume; get secperfat
+ // from the FAT32 EBPB. The volume label and system ID string are also
+ // in different locations for FAT12/16 vs FAT32.
+ volinfo->secperfat = (unsigned short)lbr->bpb.secperfat_l |
+ (((unsigned short)lbr->bpb.secperfat_h) << 8);
+if (!volinfo->secperfat) {
+volinfo->secperfat =
+ (unsigned long int)lbr->ebpb.ebpb32.
+ fatsize_0 |
+(((unsigned long int)lbr->ebpb.ebpb32.
+(((unsigned long int)lbr->ebpb.
+ ebpb32.
+(((unsigned
+ long int)
+ lbr->ebpb.
+ ebpb32.
+ fatsize_3)
+ << 24);
+memcpy(volinfo->label, lbr->ebpb.ebpb32.label, 11);
+volinfo->label[11] = 0;
- volinfo->numsecs = (unsigned short) lbr->bpb.sectors_s_l |
- (((unsigned short) lbr->bpb.sectors_s_h) << 8);
-
- if (!volinfo->numsecs)
- volinfo->numsecs = (unsigned long int) lbr->bpb.sectors_l_0 |
- (((unsigned long int) lbr->bpb.sectors_l_1) << 8) |
- (((unsigned long int) lbr->bpb.sectors_l_2) << 16) |
- (((unsigned long int) lbr->bpb.sectors_l_3) << 24);
-
- // If secperfat is 0, we must be in a FAT32 volume; get secperfat
- // from the FAT32 EBPB. The volume label and system ID string are also
- // in different locations for FAT12/16 vs FAT32.
- volinfo->secperfat = (unsigned short) lbr->bpb.secperfat_l |
- (((unsigned short) lbr->bpb.secperfat_h) << 8);
- if (!volinfo->secperfat) {
- volinfo->secperfat = (unsigned long int) lbr->ebpb.ebpb32.fatsize_0 |
- (((unsigned long int) lbr->ebpb.ebpb32.fatsize_1) << 8) |
- (((unsigned long int) lbr->ebpb.ebpb32.fatsize_2) << 16) |
- (((unsigned long int) lbr->ebpb.ebpb32.fatsize_3) << 24);
-
- memcpy(volinfo->label, lbr->ebpb.ebpb32.label, 11);
- volinfo->label[11] = 0;
-
// tag: OEMID, refer dosfs.h
-// memcpy(volinfo->system, lbr->ebpb.ebpb32.system, 8);
-// volinfo->system[8] = 0;
- }
- else {
- memcpy(volinfo->label, lbr->ebpb.ebpb.label, 11);
- volinfo->label[11] = 0;
+// memcpy(volinfo->system, lbr->ebpb.ebpb32.system, 8);
+// volinfo->system[8] = 0;
+ }
+ else {
+memcpy(volinfo->label, lbr->ebpb.ebpb.label, 11);
+volinfo->label[11] = 0;
+
// tag: OEMID, refer dosfs.h
-// memcpy(volinfo->system, lbr->ebpb.ebpb.system, 8);
-// volinfo->system[8] = 0;
- }
+// memcpy(volinfo->system, lbr->ebpb.ebpb.system, 8);
+// volinfo->system[8] = 0;
+ }
- // note: if rootentries is 0, we must be in a FAT32 volume.
- volinfo->rootentries = (unsigned short) lbr->bpb.rootentries_l |
- (((unsigned short) lbr->bpb.rootentries_h) << 8);
+ // note: if rootentries is 0, we must be in a FAT32 volume.
+ volinfo->rootentries = (unsigned short)lbr->bpb.rootentries_l |
+ (((unsigned short)lbr->bpb.rootentries_h) << 8);
- // after extracting raw info we perform some useful precalculations
- volinfo->fat1 = startsector + volinfo->reservedsecs;
+ // after extracting raw info we perform some useful precalculations
+ volinfo->fat1 = startsector + volinfo->reservedsecs;
- // The calculation below is designed to round up the root directory size for FAT12/16
- // and to simply ignore the root directory for FAT32, since it's a normal, expandable
- // file in that situation.
- if (volinfo->rootentries) {
- volinfo->rootdir = volinfo->fat1 + (volinfo->secperfat * 2);
- volinfo->dataarea = volinfo->rootdir + (((volinfo->rootentries * 32) + (SECTOR_SIZE - 1)) / SECTOR_SIZE);
- }
- else {
- volinfo->dataarea = volinfo->fat1 + (volinfo->secperfat * 2);
- volinfo->rootdir = (unsigned long int) lbr->ebpb.ebpb32.root_0 |
- (((unsigned long int) lbr->ebpb.ebpb32.root_1) << 8) |
- (((unsigned long int) lbr->ebpb.ebpb32.root_2) << 16) |
- (((unsigned long int) lbr->ebpb.ebpb32.root_3) << 24);
- }
+ // The calculation below is designed to round up the root directory size for FAT12/16
+ // and to simply ignore the root directory for FAT32, since it's a normal, expandable
+ // file in that situation.
+ if (volinfo->rootentries) {
+volinfo->rootdir = volinfo->fat1 + (volinfo->secperfat * 2);
+volinfo->dataarea =
+ volinfo->rootdir +
+ (((volinfo->rootentries * 32) +
+ (SECTOR_SIZE - 1)) / SECTOR_SIZE);
+}
+
+ else {
+volinfo->dataarea = volinfo->fat1 + (volinfo->secperfat * 2);
+volinfo->rootdir =
+ (unsigned long int)lbr->ebpb.ebpb32.
+(((unsigned long int)lbr->ebpb.ebpb32.root_1) <<
+(((unsigned long int)lbr->ebpb.ebpb32.
+(((unsigned long int)
+ lbr->ebpb.ebpb32.
+ root_3) << 24);
- // Calculate number of clusters in data area and infer FAT type from this information.
- volinfo->numclusters = (volinfo->numsecs - volinfo->dataarea) / volinfo->secperclus;
- if (volinfo->numclusters < 4085)
- volinfo->filesystem = FAT12;
- else if (volinfo->numclusters < 65525)
- volinfo->filesystem = FAT16;
- else
- volinfo->filesystem = FAT32;
+ // Calculate number of clusters in data area and infer FAT type from this information.
+ volinfo->numclusters =
+ (volinfo->numsecs - volinfo->dataarea) / volinfo->secperclus;
+if (volinfo->numclusters < 4085)
+volinfo->filesystem = FAT12;
+
+ else if (volinfo->numclusters < 65525)
+volinfo->filesystem = FAT16;
+
+ else
+volinfo->filesystem = FAT32;
+return DFS_OK;
+}
+
- return DFS_OK;
-}
-
/*
Fetch FAT entry for specified cluster number
You must provide a scratch buffer for one sector (SECTOR_SIZE) and a populated VOLINFO
@@ -354,86 +539,136 @@
FAT entry.
scratchcache should point to a UINT32. This variable caches the physical sector number
last read into the scratch buffer for performance enhancement reasons.
-*/
-unsigned long int DFS_GetFAT(PVOLINFO volinfo, unsigned char *scratch, unsigned long int *scratchcache, unsigned long int cluster)
-{
- unsigned long int offset, sector, result;
+*/
+unsigned long int DFS_GetFAT(PVOLINFO volinfo, unsigned char *scratch,
+ unsigned long int *scratchcache,
+ unsigned long int cluster)
+{
+unsigned long int offset, sector, result;
+if (volinfo->filesystem == FAT12) {
+offset = cluster + (cluster / 2);
+}
+
+ else if (volinfo->filesystem == FAT16) {
+offset = cluster * 2;
+}
+
+ else if (volinfo->filesystem == FAT32) {
+offset = cluster * 4;
+}
+
+ else
+return 0x0ffffff7; // FAT32 bad cluster
+
+ // at this point, offset is the BYTE offset of the desired sector from the start
+ // of the FAT. Calculate the physical sector containing this FAT entry.
+ sector = ldiv(offset, SECTOR_SIZE).quot + volinfo->fat1;
- if (volinfo->filesystem == FAT12) {
- offset = cluster + (cluster / 2);
- }
- else if (volinfo->filesystem == FAT16) {
- offset = cluster * 2;
- }
- else if (volinfo->filesystem == FAT32) {
- offset = cluster * 4;
- }
- else
- return 0x0ffffff7; // FAT32 bad cluster
+ // If this is not the same sector we last read, then read it into RAM
+ if (sector != *scratchcache) {
+if (DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
+
+ // avoid anyone assuming that this cache value is still valid, which
+ // might cause disk corruption
+ *scratchcache = 0;
+return 0x0ffffff7; // FAT32 bad cluster
+ }
+*scratchcache = sector;
+}
- // at this point, offset is the BYTE offset of the desired sector from the start
- // of the FAT. Calculate the physical sector containing this FAT entry.
- sector = ldiv(offset, SECTOR_SIZE).quot + volinfo->fat1;
+ // At this point, we "merely" need to extract the relevant entry.
+ // This is easy for FAT16 and FAT32, but a royal PITA for FAT12 as a single entry
+ // may span a sector boundary. The normal way around this is always to read two
+ // FAT sectors, but that luxury is (by design intent) unavailable to DOSFS.
+ offset = ldiv(offset, SECTOR_SIZE).rem;
+if (volinfo->filesystem == FAT12) {
+
+ // Special case for sector boundary - Store last byte of current sector.
+ // Then read in the next sector and put the first byte of that sector into
+ // the high byte of result.
+ if (offset == SECTOR_SIZE - 1) {
+result = (unsigned long int)scratch[offset];
+sector++;
+if (DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
+
+ // avoid anyone assuming that this cache value is still valid, which
+ // might cause disk corruption
+ *scratchcache = 0;
+return 0x0ffffff7; // FAT32 bad cluster
+ }
+*scratchcache = sector;
+
+ // Thanks to Claudio Leonel for pointing out this missing line.
+ result |= ((unsigned long int)scratch[0]) << 8;
+}
+
+ else {
+result = (unsigned long int)scratch[offset] |
+ ((unsigned long int)scratch[offset + 1]) << 8;
+if (cluster & 1)
+result = result >> 4;
+
+ else
+result = result & 0xfff;
+}
+
+ else if (volinfo->filesystem == FAT16) {
+result = (unsigned long int)scratch[offset] |
+ ((unsigned long int)scratch[offset + 1]) << 8;
+}
+
+ else if (volinfo->filesystem == FAT32) {
+result = ((unsigned long int)scratch[offset] |
+ ((unsigned long int)scratch[offset + 1]) << 8 |
+ ((unsigned long int)scratch[offset + 2]) << 16 |
+ ((unsigned long int)scratch[offset + 3]) << 24) &
+ 0x0fffffff;
+}
+
+ else
+result = 0x0ffffff7; // FAT32 bad cluster
+ return result;
+}
+
- // If this is not the same sector we last read, then read it into RAM
- if (sector != *scratchcache) {
- if(DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
- // avoid anyone assuming that this cache value is still valid, which
- // might cause disk corruption
- *scratchcache = 0;
- return 0x0ffffff7; // FAT32 bad cluster
- }
- *scratchcache = sector;
- }
-
- // At this point, we "merely" need to extract the relevant entry.
- // This is easy for FAT16 and FAT32, but a royal PITA for FAT12 as a single entry
- // may span a sector boundary. The normal way around this is always to read two
- // FAT sectors, but that luxury is (by design intent) unavailable to DOSFS.
- offset = ldiv(offset, SECTOR_SIZE).rem;
-
- if (volinfo->filesystem == FAT12) {
- // Special case for sector boundary - Store last byte of current sector.
- // Then read in the next sector and put the first byte of that sector into
- // the high byte of result.
- if (offset == SECTOR_SIZE - 1) {
- result = (unsigned long int) scratch[offset];
- sector++;
- if(DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
- // avoid anyone assuming that this cache value is still valid, which
- // might cause disk corruption
- *scratchcache = 0;
- return 0x0ffffff7; // FAT32 bad cluster
- }
- *scratchcache = sector;
- // Thanks to Claudio Leonel for pointing out this missing line.
- result |= ((unsigned long int) scratch[0]) << 8;
- }
- else {
- result = (unsigned long int) scratch[offset] |
- ((unsigned long int) scratch[offset+1]) << 8;
- }
- if (cluster & 1)
- result = result >> 4;
- else
- result = result & 0xfff;
- }
- else if (volinfo->filesystem == FAT16) {
- result = (unsigned long int) scratch[offset] |
- ((unsigned long int) scratch[offset+1]) << 8;
- }
- else if (volinfo->filesystem == FAT32) {
- result = ((unsigned long int) scratch[offset] |
- ((unsigned long int) scratch[offset+1]) << 8 |
- ((unsigned long int) scratch[offset+2]) << 16 |
- ((unsigned long int) scratch[offset+3]) << 24) & 0x0fffffff;
- }
- else
- result = 0x0ffffff7; // FAT32 bad cluster
- return result;
-}
-
-
/*
Set FAT entry for specified cluster number
You must provide a scratch buffer for one sector (SECTOR_SIZE) and a populated VOLINFO
@@ -449,171 +684,326 @@
If you are operating DOSFS over flash, you are strongly advised to implement a writeback
cache in your physical I/O driver. This will speed up your code significantly and will
also conserve power and flash write life.
-*/
-unsigned long int DFS_SetFAT(PVOLINFO volinfo, unsigned char *scratch, unsigned long int *scratchcache, unsigned long int cluster, unsigned long int new_contents)
-{
- unsigned long int offset, sector, result;
- if (volinfo->filesystem == FAT12) {
- offset = cluster + (cluster / 2);
- new_contents &=0xfff;
- }
- else if (volinfo->filesystem == FAT16) {
- offset = cluster * 2;
- new_contents &=0xffff;
- }
- else if (volinfo->filesystem == FAT32) {
- offset = cluster * 4;
- new_contents &=0x0fffffff; // FAT32 is really "FAT28"
- }
- else
- return DFS_ERRMISC;
+*/
+unsigned long int DFS_SetFAT(PVOLINFO volinfo, unsigned char *scratch,
+ unsigned long int *scratchcache,
+ unsigned long int cluster,
+ unsigned long int new_contents)
+{
+unsigned long int offset, sector, result;
+if (volinfo->filesystem == FAT12) {
+offset = cluster + (cluster / 2);
+new_contents &= 0xfff;
+}
+
+ else if (volinfo->filesystem == FAT16) {
+offset = cluster * 2;
+new_contents &= 0xffff;
+}
+
+ else if (volinfo->filesystem == FAT32) {
+offset = cluster * 4;
+new_contents &= 0x0fffffff; // FAT32 is really "FAT28"
+ }
+
+ else
+return DFS_ERRMISC;
- // at this point, offset is the BYTE offset of the desired sector from the start
- // of the FAT. Calculate the physical sector containing this FAT entry.
- sector = ldiv(offset, SECTOR_SIZE).quot + volinfo->fat1;
+ // at this point, offset is the BYTE offset of the desired sector from the start
+ // of the FAT. Calculate the physical sector containing this FAT entry.
+ sector = ldiv(offset, SECTOR_SIZE).quot + volinfo->fat1;
- // If this is not the same sector we last read, then read it into RAM
- if (sector != *scratchcache) {
- if(DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
- // avoid anyone assuming that this cache value is still valid, which
- // might cause disk corruption
- *scratchcache = 0;
- return DFS_ERRMISC;
- }
- *scratchcache = sector;
- }
+ // If this is not the same sector we last read, then read it into RAM
+ if (sector != *scratchcache) {
+if (DFS_ReadSector(volinfo->unit, scratch, sector, 1)) {
+
+ // avoid anyone assuming that this cache value is still valid, which
+ // might cause disk corruption
+ *scratchcache = 0;
+return DFS_ERRMISC;
+}
+*scratchcache = sector;
+}
- // At this point, we "merely" need to extract the relevant entry.
- // This is easy for FAT16 and FAT32, but a royal PITA for FAT12 as a single entry
- // may span a sector boundary. The normal way around this is always to read two
- // FAT sectors, but that luxury is (by design intent) unavailable to DOSFS.
- offset = ldiv(offset, SECTOR_SIZE).rem;
+ // At this point, we "merely" need to extract the relevant entry.
+ // This is easy for FAT16 and FAT32, but a royal PITA for FAT12 as a single entry
+ // may span a sector boundary. The normal way around this is always to read two
+ // FAT sectors, but that luxury is (by design intent) unavailable to DOSFS.
+ offset = ldiv(offset, SECTOR_SIZE).rem;
+if (volinfo->filesystem == FAT12) {
- if (volinfo->filesystem == FAT12) {
+ // If this is an odd cluster, pre-shift the desired new contents 4 bits to
+ // make the calculations below simpler
+ if (cluster & 1)
+new_contents = new_contents << 4;
- // If this is an odd cluster, pre-shift the desired new contents 4 bits to
- // make the calculations below simpler
- if (cluster & 1)
- new_contents = new_contents << 4;
+ // Special case for sector boundary
+ if (offset == SECTOR_SIZE - 1) {
- // Special case for sector boundary
- if (offset == SECTOR_SIZE - 1) {
+ // Odd cluster: High 12 bits being set
+ if (cluster & 1) {
+scratch[offset] =
+ (scratch[offset] & 0x0f) | new_contents &
+ 0xf0;
+}
+
+ // Even cluster: Low 12 bits being set
+ else {
+scratch[offset] = new_contents & 0xff;
+}
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ *scratchcache, 1);
+
+ // mirror the FAT into copy 2
+ if (DFS_OK == result)
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ (*scratchcache) +
+ volinfo->secperfat, 1);
- // Odd cluster: High 12 bits being set
- if (cluster & 1) {
- scratch[offset] = (scratch[offset] & 0x0f) | new_contents & 0xf0;
- }
- // Even cluster: Low 12 bits being set
- else {
- scratch[offset] = new_contents & 0xff;
- }
- result = DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
- // mirror the FAT into copy 2
- if (DFS_OK == result)
- result = DFS_WriteSector(volinfo->unit, scratch, (*scratchcache)+volinfo->secperfat, 1);
+ // If we wrote that sector OK, then read in the subsequent sector
+ // and poke the first byte with the remainder of this FAT entry.
+ if (DFS_OK == result) {
+*scratchcache++;
+result =
+ DFS_ReadSector(volinfo->unit, scratch,
+ *scratchcache, 1);
+if (DFS_OK == result) {
+
+ // Odd cluster: High 12 bits being set
+ if (cluster & 1) {
+scratch[0] =
+ new_contents & 0xff00;
+}
+
+ // Even cluster: Low 12 bits being set
+ else {
+scratch[0] =
+ (scratch[0] & 0xf0) |
+ new_contents & 0x0f;
+}
+result =
+ DFS_WriteSector(volinfo->unit,
+ scratch,
+ *scratchcache, 1);
+
+ // mirror the FAT into copy 2
+ if (DFS_OK == result)
+result =
+ DFS_WriteSector(volinfo->
+ unit,
+ scratch,
+ (*scratchcache)
+ +
+ volinfo->
+ secperfat,
+ 1);
+}
+
+ else {
+
+ // avoid anyone assuming that this cache value is still valid, which
+ // might cause disk corruption
+ *scratchcache = 0;
+}
+}
+} // if (offset == SECTOR_SIZE - 1)
+
+ // Not a sector boundary. But we still have to worry about if it's an odd
+ // or even cluster number.
+ else {
+
+ // Odd cluster: High 12 bits being set
+ if (cluster & 1) {
+scratch[offset] =
+ (scratch[offset] & 0x0f) | new_contents &
+ 0xf0;
+scratch[offset + 1] = new_contents & 0xff00;
+}
+
+ // Even cluster: Low 12 bits being set
+ else {
+scratch[offset] = new_contents & 0xff;
+scratch[offset + 1] =
+ (scratch[offset + 1] & 0xf0) | new_contents
+ & 0x0f;
+}
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ *scratchcache, 1);
+
+ // mirror the FAT into copy 2
+ if (DFS_OK == result)
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ (*scratchcache) +
+ volinfo->secperfat, 1);
+}
+}
+
+ else if (volinfo->filesystem == FAT16) {
+scratch[offset] = (new_contents & 0xff);
+scratch[offset + 1] = (new_contents & 0xff00) >> 8;
+result =
+ DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
+
+ // mirror the FAT into copy 2
+ if (DFS_OK == result)
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ (*scratchcache) +
+ volinfo->secperfat, 1);
+}
+
+ else if (volinfo->filesystem == FAT32) {
+scratch[offset] = (new_contents & 0xff);
+scratch[offset + 1] = (new_contents & 0xff00) >> 8;
+scratch[offset + 2] = (new_contents & 0xff0000) >> 16;
+scratch[offset + 3] =
+ (scratch[offset + 3] & 0xf0) | ((new_contents & 0x0f000000)
+ >> 24);
+
+ // Note well from the above: Per Microsoft's guidelines we preserve the upper
+ // 4 bits of the FAT32 cluster value. It's unclear what these bits will be used
+ // for; in every example I've encountered they are always zero.
+ result =
+ DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
+
+ // mirror the FAT into copy 2
+ if (DFS_OK == result)
+result =
+ DFS_WriteSector(volinfo->unit, scratch,
+ (*scratchcache) +
+ volinfo->secperfat, 1);
+}
+
+ else
+result = DFS_ERRMISC;
+return result;
+}
+
- // If we wrote that sector OK, then read in the subsequent sector
- // and poke the first byte with the remainder of this FAT entry.
- if (DFS_OK == result) {
- *scratchcache++;
- result = DFS_ReadSector(volinfo->unit, scratch, *scratchcache, 1);
- if (DFS_OK == result) {
- // Odd cluster: High 12 bits being set
- if (cluster & 1) {
- scratch[0] = new_contents & 0xff00;
- }
- // Even cluster: Low 12 bits being set
- else {
- scratch[0] = (scratch[0] & 0xf0) | new_contents & 0x0f;
- }
- result = DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
- // mirror the FAT into copy 2
- if (DFS_OK == result)
- result = DFS_WriteSector(volinfo->unit, scratch, (*scratchcache)+volinfo->secperfat, 1);
- }
- else {
- // avoid anyone assuming that this cache value is still valid, which
- // might cause disk corruption
- *scratchcache = 0;
- }
- }
- } // if (offset == SECTOR_SIZE - 1)
-
- // Not a sector boundary. But we still have to worry about if it's an odd
- // or even cluster number.
- else {
- // Odd cluster: High 12 bits being set
- if (cluster & 1) {
- scratch[offset] = (scratch[offset] & 0x0f) | new_contents & 0xf0;
- scratch[offset+1] = new_contents & 0xff00;
- }
- // Even cluster: Low 12 bits being set
- else {
- scratch[offset] = new_contents & 0xff;
- scratch[offset+1] = (scratch[offset+1] & 0xf0) | new_contents & 0x0f;
- }
- result = DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
- // mirror the FAT into copy 2
- if (DFS_OK == result)
- result = DFS_WriteSector(volinfo->unit, scratch, (*scratchcache)+volinfo->secperfat, 1);
- }
- }
- else if (volinfo->filesystem == FAT16) {
- scratch[offset] = (new_contents & 0xff);
- scratch[offset+1] = (new_contents & 0xff00) >> 8;
- result = DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
- // mirror the FAT into copy 2
- if (DFS_OK == result)
- result = DFS_WriteSector(volinfo->unit, scratch, (*scratchcache)+volinfo->secperfat, 1);
- }
- else if (volinfo->filesystem == FAT32) {
- scratch[offset] = (new_contents & 0xff);
- scratch[offset+1] = (new_contents & 0xff00) >> 8;
- scratch[offset+2] = (new_contents & 0xff0000) >> 16;
- scratch[offset+3] = (scratch[offset+3] & 0xf0) | ((new_contents & 0x0f000000) >> 24);
- // Note well from the above: Per Microsoft's guidelines we preserve the upper
- // 4 bits of the FAT32 cluster value. It's unclear what these bits will be used
- // for; in every example I've encountered they are always zero.
- result = DFS_WriteSector(volinfo->unit, scratch, *scratchcache, 1);
- // mirror the FAT into copy 2
- if (DFS_OK == result)
- result = DFS_WriteSector(volinfo->unit, scratch, (*scratchcache)+volinfo->secperfat, 1);
- }
- else
- result = DFS_ERRMISC;
-
- return result;
-}
-
/*
Convert a filename element from canonical (8.3) to directory entry (11) form
src must point to the first non-separator character.
dest must point to a 12-byte buffer.
-*/
-unsigned char *DFS_CanonicalToDir(unsigned char *dest, unsigned char *src)
-{
- unsigned char *destptr = dest;
+*/
+unsigned char *DFS_CanonicalToDir(unsigned char *dest, unsigned char *src)
+{
+unsigned char *destptr = dest;
+memset(dest, ' ', 11);
+dest[11] = 0;
+while (*src && (*src != DIR_SEPARATOR) && (destptr - dest < 11)) {
+if (*src >= 'a' && *src <= 'z') {
+*destptr++ = (*src - 'a') + 'A';
+src++;
+}
+
+ else if (*src == '.') {
+src++;
+destptr = dest + 8;
+}
+
+ else {
+*destptr++ = *src++;
+}
+}
+return dest;
+}
+
- memset(dest, ' ', 11);
- dest[11] = 0;
-
- while (*src && (*src != DIR_SEPARATOR) && (destptr - dest < 11)) {
- if (*src >= 'a' && *src <='z') {
- *destptr++ = (*src - 'a') + 'A';
- src++;
- }
- else if (*src == '.') {
- src++;
- destptr = dest + 8;
- }
- else {
- *destptr++ = *src++;
- }
- }
-
- return dest;
-}
-
/*
Find the first unused FAT entry
You must provide a scratch buffer for one sector (SECTOR_SIZE) and a populated VOLINFO
@@ -620,23 +1010,33 @@
Returns a FAT32 BAD_CLUSTER value for any error, otherwise the contents of the desired
FAT entry.
Returns FAT32 bad_sector (0x0ffffff7) if there is no free cluster available
-*/
-unsigned long int DFS_GetFreeFAT(PVOLINFO volinfo, unsigned char *scratch)
-{
- unsigned long int i, result = 0xffffffff, scratchcache = 0;
-
- // Search starts at cluster 2, which is the first usable cluster
- // NOTE: This search can't terminate at a bad cluster, because there might
- // legitimately be bad clusters on the disk.
- for (i=2; i < volinfo->numclusters; i++) {
- result = DFS_GetFAT(volinfo, scratch, &scratchcache, i);
- if (!result) {
- return i;
- }
- }
- return 0x0ffffff7; // Can't find a free cluster
-}
+*/
+unsigned long int DFS_GetFreeFAT(PVOLINFO volinfo, unsigned char *scratch)
+{
+unsigned long int i, result = 0xffffffff, scratchcache = 0;
+ // Search starts at cluster 2, which is the first usable cluster
+ // NOTE: This search can't terminate at a bad cluster, because there might
+ // legitimately be bad clusters on the disk.
+ for (i = 2; i < volinfo->numclusters; i++) {
+result = DFS_GetFAT(volinfo, scratch, &scratchcache, i);
+if (!result) {
+return i;
+}
+}
+return 0x0ffffff7; // Can't find a free cluster
+}
+
/*
Open a directory for enumeration by DFS_GetNextDirEnt
@@ -644,106 +1044,209 @@
The empty string or a string containing only the directory separator are
considered to be the root directory.
Returns 0 OK, nonzero for any error.
-*/
-unsigned long int DFS_OpenDir(PVOLINFO volinfo, unsigned char *dirname, PDIRINFO dirinfo)
-{
- // Default behavior is a regular search for existing entries
- dirinfo->flags = 0;
+*/
+unsigned long int DFS_OpenDir(PVOLINFO volinfo, unsigned char *dirname,
+ PDIRINFO dirinfo)
+{
+
+ // Default behavior is a regular search for existing entries
+ dirinfo->flags = 0;
+if (!strlen((char *)dirname)
+ || (strlen((char *)dirname) == 1
+ && dirname[0] == DIR_SEPARATOR)) {
+if (volinfo->filesystem == FAT32) {
+dirinfo->currentcluster = volinfo->rootdir;
+dirinfo->currentsector = 0;
+dirinfo->currententry = 0;
- if (!strlen((char *) dirname) || (strlen((char *) dirname) == 1 && dirname[0] == DIR_SEPARATOR)) {
- if (volinfo->filesystem == FAT32) {
- dirinfo->currentcluster = volinfo->rootdir;
- dirinfo->currentsector = 0;
- dirinfo->currententry = 0;
+ // read first sector of directory
+ return DFS_ReadSector(volinfo->unit,
+ dirinfo->scratch,
+ volinfo->dataarea +
+ ((volinfo->rootdir -
+ 2) * volinfo->secperclus),
+ 1);
+}
+
+ else {
+dirinfo->currentcluster = 0;
+dirinfo->currentsector = 0;
+dirinfo->currententry = 0;
- // read first sector of directory
- return DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->dataarea + ((volinfo->rootdir - 2) * volinfo->secperclus), 1);
- }
- else {
- dirinfo->currentcluster = 0;
- dirinfo->currentsector = 0;
- dirinfo->currententry = 0;
+ // read first sector of directory
+ return DFS_ReadSector(volinfo->unit,
+ dirinfo->scratch,
+ volinfo->rootdir, 1);
+}
+}
- // read first sector of directory
- return DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->rootdir, 1);
- }
- }
+ // This is not the root directory. We need to find the start of this subdirectory.
+ // We do this by devious means, using our own companion function DFS_GetNext.
+ else {
+unsigned char tmpfn[12];
+unsigned char *ptr = dirname;
+unsigned long int result;
+DIRENT de;
+if (volinfo->filesystem == FAT32) {
+dirinfo->currentcluster = volinfo->rootdir;
+dirinfo->currentsector = 0;
+dirinfo->currententry = 0;
- // This is not the root directory. We need to find the start of this subdirectory.
- // We do this by devious means, using our own companion function DFS_GetNext.
- else {
- unsigned char tmpfn[12];
- unsigned char *ptr = dirname;
- unsigned long int result;
- DIRENT de;
+ // read first sector of directory
+ if (DFS_ReadSector
+ (volinfo->unit, dirinfo->scratch,
+ volinfo->dataarea +
+ ((volinfo->rootdir - 2) * volinfo->secperclus),
+ 1))
+return DFS_ERRMISC;
+}
+
+ else {
+dirinfo->currentcluster = 0;
+dirinfo->currentsector = 0;
+dirinfo->currententry = 0;
- if (volinfo->filesystem == FAT32) {
- dirinfo->currentcluster = volinfo->rootdir;
- dirinfo->currentsector = 0;
- dirinfo->currententry = 0;
+ // read first sector of directory
+ if (DFS_ReadSector
+ (volinfo->unit, dirinfo->scratch,
+ volinfo->rootdir, 1))
+return DFS_ERRMISC;
+}
- // read first sector of directory
- if (DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->dataarea + ((volinfo->rootdir - 2) * volinfo->secperclus), 1))
- return DFS_ERRMISC;
- }
- else {
- dirinfo->currentcluster = 0;
- dirinfo->currentsector = 0;
- dirinfo->currententry = 0;
+ // skip leading path separators
+ while (*ptr == DIR_SEPARATOR && *ptr)
+ptr++;
- // read first sector of directory
- if (DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->rootdir, 1))
- return DFS_ERRMISC;
- }
+ // Scan the path from left to right, finding the start cluster of each entry
+ // Observe that this code is inelegant, but obviates the need for recursion.
+ while (*ptr) {
+DFS_CanonicalToDir(tmpfn, ptr);
+de.name[0] = 0;
- // skip leading path separators
- while (*ptr == DIR_SEPARATOR && *ptr)
- ptr++;
+ do {
+result = DFS_GetNext(volinfo, dirinfo, &de);
+} while (!result && memcmp2(de.name, tmpfn, 11));
+if (!memcmp2(de.name, tmpfn, 11)
+ && ((de.attr & ATTR_DIRECTORY) ==
+ ATTR_DIRECTORY)) {
+if (volinfo->filesystem == FAT32) {
+dirinfo->currentcluster =
+ (unsigned long int)de.
+ startclus_l_l |
+((unsigned long int)de.
+((unsigned
+ long int)
+ de.
+ startclus_h_l)
+((unsigned long int)de.
+ startclus_h_h) << 24;
+}
+
+ else {
+dirinfo->currentcluster =
+ (unsigned long int)de.
+ startclus_l_l |
+((unsigned long int)de.
+ startclus_l_h) << 8;
+dirinfo->currentsector = 0;
+dirinfo->currententry = 0;
+if (DFS_ReadSector
+ (volinfo->unit, dirinfo->scratch,
+ volinfo->dataarea +
+ ((dirinfo->currentcluster -
+ 2) * volinfo->secperclus), 1))
+return DFS_ERRMISC;
+}
+
+ else if (!memcmp2(de.name, tmpfn, 11)
+ && !(de.attr & ATTR_DIRECTORY))
+return DFS_NOTFOUND;
- // Scan the path from left to right, finding the start cluster of each entry
- // Observe that this code is inelegant, but obviates the need for recursion.
- while (*ptr) {
- DFS_CanonicalToDir(tmpfn, ptr);
+ // seek to next item in list
+ while (*ptr != DIR_SEPARATOR && *ptr)
+ptr++;
+if (*ptr == DIR_SEPARATOR)
+ptr++;
+}
+if (!dirinfo->currentcluster)
+return DFS_NOTFOUND;
+}
+return DFS_OK;
+}
+
- de.name[0] = 0;
-
- do {
- result = DFS_GetNext(volinfo, dirinfo, &de);
- } while (!result && memcmp2(de.name, tmpfn, 11));
-
- if (!memcmp2(de.name, tmpfn, 11) && ((de.attr & ATTR_DIRECTORY) == ATTR_DIRECTORY)) {
- if (volinfo->filesystem == FAT32) {
- dirinfo->currentcluster = (unsigned long int) de.startclus_l_l |
- ((unsigned long int) de.startclus_l_h) << 8 |
- ((unsigned long int) de.startclus_h_l) << 16 |
- ((unsigned long int) de.startclus_h_h) << 24;
- }
- else {
- dirinfo->currentcluster = (unsigned long int) de.startclus_l_l |
- ((unsigned long int) de.startclus_l_h) << 8;
- }
- dirinfo->currentsector = 0;
- dirinfo->currententry = 0;
-
- if (DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->dataarea + ((dirinfo->currentcluster - 2) * volinfo->secperclus), 1))
- return DFS_ERRMISC;
- }
- else if (!memcmp2(de.name, tmpfn, 11) && !(de.attr & ATTR_DIRECTORY))
- return DFS_NOTFOUND;
-
- // seek to next item in list
- while (*ptr != DIR_SEPARATOR && *ptr)
- ptr++;
- if (*ptr == DIR_SEPARATOR)
- ptr++;
- }
-
- if (!dirinfo->currentcluster)
- return DFS_NOTFOUND;
- }
- return DFS_OK;
-}
-
/*
Get next entry in opened directory structure. Copies fields into the dirent
structure, updates dirinfo. Note that it is the _caller's_ responsibility to
@@ -753,78 +1256,138 @@
automatically. Long file name entries will be returned as NULL.
returns DFS_EOF if there are no more entries, DFS_OK if this entry is valid,
or DFS_ERRMISC for a media error
-*/
-unsigned long int DFS_GetNext(PVOLINFO volinfo, PDIRINFO dirinfo, PDIRENT dirent)
-{
- unsigned long int tempint; // required by DFS_GetFAT
+*/
+unsigned long int DFS_GetNext(PVOLINFO volinfo, PDIRINFO dirinfo,
+ PDIRENT dirent)
+{
+unsigned long int tempint; // required by DFS_GetFAT
+
+ // Do we need to read the next sector of the directory?
+ if (dirinfo->currententry >= SECTOR_SIZE / sizeof(DIRENT)) {
+dirinfo->currententry = 0;
+dirinfo->currentsector++;
- // Do we need to read the next sector of the directory?
- if (dirinfo->currententry >= SECTOR_SIZE / sizeof(DIRENT)) {
- dirinfo->currententry = 0;
- dirinfo->currentsector++;
+ // Root directory; special case handling
+ // Note that currentcluster will only ever be zero if both:
+ // (a) this is the root directory, and
+ // (b) we are on a FAT12/16 volume, where the root dir can't be expanded
+ if (dirinfo->currentcluster == 0) {
+
+ // Trying to read past end of root directory?
+ if (dirinfo->currentsector *
+ (SECTOR_SIZE / sizeof(DIRENT)) >=
+ volinfo->rootentries)
+return DFS_EOF;
- // Root directory; special case handling
- // Note that currentcluster will only ever be zero if both:
- // (a) this is the root directory, and
- // (b) we are on a FAT12/16 volume, where the root dir can't be expanded
- if (dirinfo->currentcluster == 0) {
- // Trying to read past end of root directory?
- if (dirinfo->currentsector * (SECTOR_SIZE / sizeof(DIRENT)) >= volinfo->rootentries)
- return DFS_EOF;
+ // Otherwise try to read the next sector
+ if (DFS_ReadSector
+ (volinfo->unit, dirinfo->scratch,
+ volinfo->rootdir + dirinfo->currentsector, 1))
+return DFS_ERRMISC;
+}
- // Otherwise try to read the next sector
- if (DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->rootdir + dirinfo->currentsector, 1))
- return DFS_ERRMISC;
- }
+ // Normal handling
+ else {
+if (dirinfo->currentsector >= volinfo->secperclus) {
+dirinfo->currentsector = 0;
+if ((dirinfo->currentcluster >= 0xff7
+ && volinfo->filesystem == FAT12)
+(dirinfo->currentcluster >= 0xfff7
+ && volinfo->filesystem == FAT16)
+(dirinfo->currentcluster >= 0x0ffffff7
+ && volinfo->filesystem == FAT32)) {
- // Normal handling
- else {
- if (dirinfo->currentsector >= volinfo->secperclus) {
- dirinfo->currentsector = 0;
- if ((dirinfo->currentcluster >= 0xff7 && volinfo->filesystem == FAT12) ||
- (dirinfo->currentcluster >= 0xfff7 && volinfo->filesystem == FAT16) ||
- (dirinfo->currentcluster >= 0x0ffffff7 && volinfo->filesystem == FAT32)) {
-
- // We are at the end of the directory chain. If this is a normal
- // find operation, we should indicate that there is nothing more
- // to see.
- if (!(dirinfo->flags & DFS_DI_BLANKENT))
- return DFS_EOF;
-
- // On the other hand, if this is a "find free entry" search,
- // we need to tell the caller to allocate a new cluster
- else
- return DFS_ALLOCNEW;
- }
- dirinfo->currentcluster = DFS_GetFAT(volinfo, dirinfo->scratch, &tempint, dirinfo->currentcluster);
- }
- if (DFS_ReadSector(volinfo->unit, dirinfo->scratch, volinfo->dataarea + ((dirinfo->currentcluster - 2) * volinfo->secperclus) + dirinfo->currentsector, 1))
- return DFS_ERRMISC;
- }
- }
+ // We are at the end of the directory chain. If this is a normal
+ // find operation, we should indicate that there is nothing more
+ // to see.
+ if (!
+ (dirinfo->
+ flags & DFS_DI_BLANKENT))
+return DFS_EOF;
- memcpy(dirent, &(((PDIRENT) dirinfo->scratch)[dirinfo->currententry]), sizeof(DIRENT));
-
- if (dirent->name[0] == 0) { // no more files in this directory
+ // On the other hand, if this is a "find free entry" search,
+ // we need to tell the caller to allocate a new cluster
+ else
+return DFS_ALLOCNEW;
+}
+dirinfo->currentcluster =
+ DFS_GetFAT(volinfo, dirinfo->scratch,
+ &tempint,
+ dirinfo->currentcluster);
+}
+if (DFS_ReadSector
+ (volinfo->unit, dirinfo->scratch,
+ volinfo->dataarea +
+ ((dirinfo->currentcluster -
+ 2) * volinfo->secperclus) +
+ dirinfo->currentsector, 1))
+return DFS_ERRMISC;
+}
+}
+memcpy(dirent, &(((PDIRENT) dirinfo->scratch)[dirinfo->currententry]),
+ sizeof(DIRENT));
+if (dirent->name[0] == 0) { // no more files in this directory
// If this is a "find blank" then we can reuse this name.
- if (dirinfo->flags & DFS_DI_BLANKENT)
- return DFS_OK;
- else
- return DFS_EOF;
- }
-
- if (dirent->name[0] == 0xe5) // handle deleted file entries
- dirent->name[0] = 0;
- else if ((dirent->attr & ATTR_LONG_NAME) == ATTR_LONG_NAME)
- dirent->name[0] = 0;
+ if (dirinfo->flags & DFS_DI_BLANKENT)
+return DFS_OK;
+
+ else
+return DFS_EOF;
+}
+if (dirent->name[0] == 0xe5) // handle deleted file entries
+ dirent->name[0] = 0;
+
+ else if ((dirent->attr & ATTR_LONG_NAME) == ATTR_LONG_NAME)
+dirent->name[0] = 0;
+
else if (dirent->name[0] == 0x05) // handle kanji filenames beginning with 0xE5
- dirent->name[0] = 0xe5;
+ dirent->name[0] = 0xe5;
+dirinfo->currententry++;
+return DFS_OK;
+}
+
- dirinfo->currententry++;
-
- return DFS_OK;
-}
-
/*
INTERNAL
Find a free directory entry in the directory specified by path
@@ -834,66 +1397,118 @@
de is a scratch structure
Returns DFS_ERRMISC if a new entry could not be located or created
de is updated with the same return information you would expect from DFS_GetNext
-*/
-unsigned long int DFS_GetFreeDirEnt(PVOLINFO volinfo, unsigned char *path, PDIRINFO di, PDIRENT de)
-{
- unsigned long int tempclus,i;
+*/
+unsigned long int DFS_GetFreeDirEnt(PVOLINFO volinfo, unsigned char *path,
+ PDIRINFO di, PDIRENT de)
+{
+unsigned long int tempclus, i;
+if (DFS_OpenDir(volinfo, path, di))
+return DFS_NOTFOUND;
- if (DFS_OpenDir(volinfo, path, di))
- return DFS_NOTFOUND;
+ // Set "search for empty" flag so DFS_GetNext knows what we're doing
+ di->flags |= DFS_DI_BLANKENT;
- // Set "search for empty" flag so DFS_GetNext knows what we're doing
- di->flags |= DFS_DI_BLANKENT;
+ // We seek through the directory looking for an empty entry
+ // Note we are reusing tempclus as a temporary result holder.
+ tempclus = 0;
+
+ do {
+tempclus = DFS_GetNext(volinfo, di, de);
- // We seek through the directory looking for an empty entry
- // Note we are reusing tempclus as a temporary result holder.
- tempclus = 0;
- do {
- tempclus = DFS_GetNext(volinfo, di, de);
+ // Empty entry found
+ if (tempclus == DFS_OK && (!de->name[0])) {
+return DFS_OK;
+}
- // Empty entry found
- if (tempclus == DFS_OK && (!de->name[0])) {
- return DFS_OK;
- }
+ // End of root directory reached
+ else if (tempclus == DFS_EOF)
+return DFS_ERRMISC;
- // End of root directory reached
- else if (tempclus == DFS_EOF)
- return DFS_ERRMISC;
+ else if (tempclus == DFS_ALLOCNEW) {
+tempclus = DFS_GetFreeFAT(volinfo, di->scratch);
+if (tempclus == 0x0ffffff7)
+return DFS_ERRMISC;
+
+ // write out zeroed sectors to the new cluster
+ memset(di->scratch, 0, SECTOR_SIZE);
+for (i = 0; i < volinfo->secperclus; i++) {
+if (DFS_WriteSector
+ (volinfo->unit, di->scratch,
+ volinfo->dataarea +
+ ((tempclus - 2) * volinfo->secperclus) +
+ i, 1))
+return DFS_ERRMISC;
+}
- else if (tempclus == DFS_ALLOCNEW) {
- tempclus = DFS_GetFreeFAT(volinfo, di->scratch);
- if (tempclus == 0x0ffffff7)
- return DFS_ERRMISC;
+ // Point old end cluster to newly allocated cluster
+ i = 0;
+DFS_SetFAT(volinfo, di->scratch, &i,
+ di->currentcluster, tempclus);
- // write out zeroed sectors to the new cluster
- memset(di->scratch, 0, SECTOR_SIZE);
- for (i=0;isecperclus;i++) {
- if (DFS_WriteSector(volinfo->unit, di->scratch, volinfo->dataarea + ((tempclus - 2) * volinfo->secperclus) + i, 1))
- return DFS_ERRMISC;
- }
- // Point old end cluster to newly allocated cluster
- i = 0;
- DFS_SetFAT(volinfo, di->scratch, &i, di->currentcluster, tempclus);
-
- // Update DIRINFO so caller knows where to place the new file
- di->currentcluster = tempclus;
- di->currentsector = 0;
- di->currententry = 1; // since the code coming after this expects to subtract 1
+ // Update DIRINFO so caller knows where to place the new file
+ di->currentcluster = tempclus;
+di->currentsector = 0;
+di->currententry = 1; // since the code coming after this expects to subtract 1
- // Mark newly allocated cluster as end of chain
- switch(volinfo->filesystem) {
- case FAT12: tempclus = 0xff8; break;
- case FAT16: tempclus = 0xfff8; break;
- case FAT32: tempclus = 0x0ffffff8; break;
- default: return DFS_ERRMISC;
- }
- DFS_SetFAT(volinfo, di->scratch, &i, di->currentcluster, tempclus);
- }
- } while (!tempclus);
+ // Mark newly allocated cluster as end of chain
+ switch (volinfo->filesystem) {
+case FAT12:
+ tempclus = 0xff8;
+ break;
+case FAT16:
+ tempclus = 0xfff8;
+ break;
+case FAT32:
+ tempclus = 0x0ffffff8;
+ break;
+default:
+ return DFS_ERRMISC;
+}
+DFS_SetFAT(volinfo, di->scratch, &i,
+ di->currentcluster, tempclus);
+}
+} while (!tempclus);
- // We shouldn't get here
- return DFS_ERRMISC;
-}
+ // We shouldn't get here
+ return DFS_ERRMISC;
+}
+
/*
Open a file for reading or writing. You supply populated VOLINFO, a path to the file,
@@ -901,164 +1516,301 @@
provide a pointer to a sector-sized scratch buffer.
Returns various DFS_* error states. If the result is DFS_OK, fileinfo can be used
to access the file from this point on.
-*/
-unsigned long int DFS_OpenFile(PVOLINFO volinfo, unsigned char *path, unsigned char mode, unsigned char *scratch, PFILEINFO fileinfo)
-{
- unsigned char tmppath[MAX_PATH];
- unsigned char filename[12];
- unsigned char *p;
- DIRINFO di;
- DIRENT de;
+*/
+unsigned long int DFS_OpenFile(PVOLINFO volinfo, unsigned char *path,
+ unsigned char mode, unsigned char *scratch,
+ PFILEINFO fileinfo)
+{
+unsigned char tmppath[MAX_PATH];
+unsigned char filename[12];
+unsigned char *p;
+DIRINFO di;
+DIRENT de;
- // larwe 2006-09-16 +1 zero out file structure
- memset(fileinfo, 0, sizeof(FILEINFO));
+ // larwe 2006-09-16 +1 zero out file structure
+ memset(fileinfo, 0, sizeof(FILEINFO));
- // save access mode
- fileinfo->mode = mode;
+ // save access mode
+ fileinfo->mode = mode;
- // Get a local copy of the path. If it's longer than MAX_PATH, abort.
- strcpy2((char *) tmppath, (char *) path);
- tmppath[MAX_PATH - 1] = 0;
- if (strcmp2((char *) path,(char *) tmppath)) {
- return DFS_PATHLEN;
- }
+ // Get a local copy of the path. If it's longer than MAX_PATH, abort.
+ strcpy2((char *)tmppath, (char *)path);
+tmppath[MAX_PATH - 1] = 0;
+if (strcmp2((char *)path, (char *)tmppath)) {
+return DFS_PATHLEN;
+}
-
- // strip leading path separators
- while (tmppath[0] == DIR_SEPARATOR)
- strcpy2((char *) tmppath, (char *) tmppath + 1);
+ // strip leading path separators
+ while (tmppath[0] == DIR_SEPARATOR)
+strcpy2((char *)tmppath, (char *)tmppath + 1);
- // Parse filename off the end of the supplied path
- p = tmppath;
- while (*(p++));
+ // Parse filename off the end of the supplied path
+ p = tmppath;
+while (*(p++)) ;
+p--;
+while (p > tmppath && *p != DIR_SEPARATOR) // larwe 9/16/06 ">=" to ">" bugfix
+ p--;
+if (*p == DIR_SEPARATOR)
+p++;
+DFS_CanonicalToDir(filename, p);
+if (p > tmppath)
+p--;
+if (*p == DIR_SEPARATOR || p == tmppath) // larwe 9/16/06 +"|| p == tmppath" bugfix
+ *p = 0;
- p--;
- while (p > tmppath && *p != DIR_SEPARATOR) // larwe 9/16/06 ">=" to ">" bugfix
- p--;
- if (*p == DIR_SEPARATOR)
- p++;
+ // At this point, if our path was MYDIR/MYDIR2/FILE.EXT, filename = "FILE EXT" and
+ // tmppath = "MYDIR/MYDIR2".
+ di.scratch = scratch;
+if (DFS_OpenDir(volinfo, tmppath, &di))
+return DFS_NOTFOUND;
+while (!DFS_GetNext(volinfo, &di, &de)) {
+if (!memcmp2(de.name, filename, 11)) {
+
+ // You can't use this function call to open a directory.
+ if (de.attr & ATTR_DIRECTORY)
+return DFS_NOTFOUND;
+printf("get enxt \n");
+fileinfo->volinfo = volinfo;
+fileinfo->pointer = 0;
+
+ // The reason we store this extra info about the file is so that we can
+ // speedily update the file size, modification date, etc. on a file that is
+ // opened for writing.
+ if (di.currentcluster == 0)
+fileinfo->dirsector =
+ volinfo->rootdir + di.currentsector;
+
+ else
+fileinfo->dirsector =
+ volinfo->dataarea +
+ ((di.currentcluster -
+ 2) * volinfo->secperclus) +
+ di.currentsector;
+fileinfo->diroffset = di.currententry - 1;
+if (volinfo->filesystem == FAT32) {
+fileinfo->cluster =
+ (unsigned long int)de.
+((unsigned long int)de.
+ startclus_l_h) << 8 |
+((unsigned long int)de.
+((unsigned long
+ int)de.
+ startclus_h_h) <<
+ 24;
+}
+
+ else {
+fileinfo->cluster =
+ (unsigned long int)de.
+((unsigned long int)de.
+ startclus_l_h) << 8;
+fileinfo->firstcluster = fileinfo->cluster;
+fileinfo->filelen =
+ (unsigned long int)de.
+((unsigned long int)de.
+((unsigned long
+ int)de.
+ filesize_2) <<
+((unsigned long int)de.filesize_3) << 24;
+return DFS_OK;
+}
+}
- DFS_CanonicalToDir(filename, p);
+ // At this point, we KNOW the file does not exist. If the file was opened
+ // with write access, we can create it.
+ if (mode & DFS_WRITE) {
+unsigned long int cluster, temp;
- if (p > tmppath)
- p--;
- if (*p == DIR_SEPARATOR || p == tmppath) // larwe 9/16/06 +"|| p == tmppath" bugfix
- *p = 0;
+ // Locate or create a directory entry for this file
+ if (DFS_OK != DFS_GetFreeDirEnt(volinfo, tmppath, &di, &de))
+return DFS_ERRMISC;
- // At this point, if our path was MYDIR/MYDIR2/FILE.EXT, filename = "FILE EXT" and
- // tmppath = "MYDIR/MYDIR2".
- di.scratch = scratch;
- if (DFS_OpenDir(volinfo, tmppath, &di))
- return DFS_NOTFOUND;
+ // put sane values in the directory entry
+ memset(&de, 0, sizeof(de));
+memcpy(de.name, filename, 11);
+de.crttime_l = 0x20; // 01:01:00am, Jan 1, 2006.
+ de.crttime_h = 0x08;
+de.crtdate_l = 0x11;
+de.crtdate_h = 0x34;
+de.lstaccdate_l = 0x11;
+de.lstaccdate_h = 0x34;
+de.wrttime_l = 0x20;
+de.wrttime_h = 0x08;
+de.wrtdate_l = 0x11;
+de.wrtdate_h = 0x34;
- while (!DFS_GetNext(volinfo, &di, &de)) {
-
- if (!memcmp2(de.name, filename, 11)) {
- // You can't use this function call to open a directory.
- if (de.attr & ATTR_DIRECTORY)
- return DFS_NOTFOUND;
- printf("get enxt \n");
- fileinfo->volinfo = volinfo;
- fileinfo->pointer = 0;
- // The reason we store this extra info about the file is so that we can
- // speedily update the file size, modification date, etc. on a file that is
- // opened for writing.
- if (di.currentcluster == 0)
- fileinfo->dirsector = volinfo->rootdir + di.currentsector;
- else
- fileinfo->dirsector = volinfo->dataarea + ((di.currentcluster - 2) * volinfo->secperclus) + di.currentsector;
- fileinfo->diroffset = di.currententry - 1;
- if (volinfo->filesystem == FAT32) {
- fileinfo->cluster = (unsigned long int) de.startclus_l_l |
- ((unsigned long int) de.startclus_l_h) << 8 |
- ((unsigned long int) de.startclus_h_l) << 16 |
- ((unsigned long int) de.startclus_h_h) << 24;
- }
- else {
- fileinfo->cluster = (unsigned long int) de.startclus_l_l |
- ((unsigned long int) de.startclus_l_h) << 8;
- }
- fileinfo->firstcluster = fileinfo->cluster;
- fileinfo->filelen = (unsigned long int) de.filesize_0 |
- ((unsigned long int) de.filesize_1) << 8 |
- ((unsigned long int) de.filesize_2) << 16 |
- ((unsigned long int) de.filesize_3) << 24;
+ // allocate a starting cluster for the directory entry
+ cluster = DFS_GetFreeFAT(volinfo, scratch);
+de.startclus_l_l = cluster & 0xff;
+de.startclus_l_h = (cluster & 0xff00) >> 8;
+de.startclus_h_l = (cluster & 0xff0000) >> 16;
+de.startclus_h_h = (cluster & 0xff000000) >> 24;
- return DFS_OK;
- }
- }
-
- // At this point, we KNOW the file does not exist. If the file was opened
- // with write access, we can create it.
- if (mode & DFS_WRITE) {
- unsigned long int cluster, temp;
-
- // Locate or create a directory entry for this file
- if (DFS_OK != DFS_GetFreeDirEnt(volinfo, tmppath, &di, &de))
- return DFS_ERRMISC;
-
- // put sane values in the directory entry
- memset(&de, 0, sizeof(de));
- memcpy(de.name, filename, 11);
- de.crttime_l = 0x20; // 01:01:00am, Jan 1, 2006.
- de.crttime_h = 0x08;
- de.crtdate_l = 0x11;
- de.crtdate_h = 0x34;
- de.lstaccdate_l = 0x11;
- de.lstaccdate_h = 0x34;
- de.wrttime_l = 0x20;
- de.wrttime_h = 0x08;
- de.wrtdate_l = 0x11;
- de.wrtdate_h = 0x34;
-
- // allocate a starting cluster for the directory entry
- cluster = DFS_GetFreeFAT(volinfo, scratch);
-
- de.startclus_l_l = cluster & 0xff;
- de.startclus_l_h = (cluster & 0xff00) >> 8;
- de.startclus_h_l = (cluster & 0xff0000) >> 16;
- de.startclus_h_h = (cluster & 0xff000000) >> 24;
-
- // update FILEINFO for our caller's sake
- fileinfo->volinfo = volinfo;
- fileinfo->pointer = 0;
- // The reason we store this extra info about the file is so that we can
- // speedily update the file size, modification date, etc. on a file that is
- // opened for writing.
- if (di.currentcluster == 0)
- fileinfo->dirsector = volinfo->rootdir + di.currentsector;
- else
- fileinfo->dirsector = volinfo->dataarea + ((di.currentcluster - 2) * volinfo->secperclus) + di.currentsector;
- fileinfo->diroffset = di.currententry - 1;
- fileinfo->cluster = cluster;
- fileinfo->firstcluster = cluster;
- fileinfo->filelen = 0;
+ // update FILEINFO for our caller's sake
+ fileinfo->volinfo = volinfo;
+fileinfo->pointer = 0;
- // write the directory entry
- // note that we no longer have the sector containing the directory entry,
- // tragically, so we have to re-read it
- if (DFS_ReadSector(volinfo->unit, scratch, fileinfo->dirsector, 1))
- return DFS_ERRMISC;
- memcpy(&(((PDIRENT) scratch)[di.currententry-1]), &de, sizeof(DIRENT));
- if (DFS_WriteSector(volinfo->unit, scratch, fileinfo->dirsector, 1))
- return DFS_ERRMISC;
+ // The reason we store this extra info about the file is so that we can
+ // speedily update the file size, modification date, etc. on a file that is
+ // opened for writing.
+ if (di.currentcluster == 0)
+fileinfo->dirsector =
+ volinfo->rootdir + di.currentsector;
+
+ else
+fileinfo->dirsector =
+ volinfo->dataarea +
+ ((di.currentcluster - 2) * volinfo->secperclus) +
+ di.currentsector;
+fileinfo->diroffset = di.currententry - 1;
+fileinfo->cluster = cluster;
+fileinfo->firstcluster = cluster;
+fileinfo->filelen = 0;
- // Mark newly allocated cluster as end of chain
- switch(volinfo->filesystem) {
- case FAT12: cluster = 0xff8; break;
- case FAT16: cluster = 0xfff8; break;
- case FAT32: cluster = 0x0ffffff8; break;
- default: return DFS_ERRMISC;
- }
- temp = 0;
- DFS_SetFAT(volinfo, scratch, &temp, fileinfo->cluster, cluster);
+ // write the directory entry
+ // note that we no longer have the sector containing the directory entry,
+ // tragically, so we have to re-read it
+ if (DFS_ReadSector
+ (volinfo->unit, scratch, fileinfo->dirsector, 1))
+return DFS_ERRMISC;
+memcpy(&(((PDIRENT) scratch)[di.currententry - 1]), &de,
+ sizeof(DIRENT));
+if (DFS_WriteSector
+ (volinfo->unit, scratch, fileinfo->dirsector, 1))
+return DFS_ERRMISC;
- return DFS_OK;
- }
+ // Mark newly allocated cluster as end of chain
+ switch (volinfo->filesystem) {
+case FAT12:
+ cluster = 0xff8;
+ break;
+case FAT16:
+ cluster = 0xfff8;
+ break;
+case FAT32:
+ cluster = 0x0ffffff8;
+ break;
+default:
+ return DFS_ERRMISC;
+}
+temp = 0;
+DFS_SetFAT(volinfo, scratch, &temp, fileinfo->cluster,
+ cluster);
+return DFS_OK;
+}
+return DFS_NOTFOUND;
+}
+
- return DFS_NOTFOUND;
-}
-
/*
Read an open file
You must supply a prepopulated FILEINFO as provided by DFS_OpenFile, and a
@@ -1065,122 +1817,212 @@
pointer to a SECTOR_SIZE scratch buffer.
Note that returning DFS_EOF is not an error condition. This function updates the
successcount field with the number of bytes actually read.
-*/
-unsigned long int DFS_ReadFile(PFILEINFO fileinfo, unsigned char *scratch, unsigned char *buffer, unsigned long int *successcount, unsigned long int len)
-{
- unsigned long int remain;
- unsigned long int result = DFS_OK;
- unsigned long int sector;
- unsigned long int bytesread;
-
- // Don't try to read past EOF
- if (len > fileinfo->filelen - fileinfo->pointer)
- len = fileinfo->filelen - fileinfo->pointer;
+*/
+unsigned long int DFS_ReadFile(PFILEINFO fileinfo, unsigned char *scratch,
+ unsigned char *buffer,
+ unsigned long int *successcount,
+ unsigned long int len)
+{
+unsigned long int remain;
+unsigned long int result = DFS_OK;
+unsigned long int sector;
+unsigned long int bytesread;
- remain = len;
- *successcount = 0;
+ // Don't try to read past EOF
+ if (len > fileinfo->filelen - fileinfo->pointer)
+len = fileinfo->filelen - fileinfo->pointer;
+remain = len;
+*successcount = 0;
+while (remain && result == DFS_OK) {
+
+ // This is a bit complicated. The sector we want to read is addressed at a cluster
+ // granularity by the fileinfo->cluster member. The file pointer tells us how many
+ // extra sectors to add to that number.
+ sector = fileinfo->volinfo->dataarea +
+ ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
+div(div
+ (fileinfo->pointer,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).rem,
+ SECTOR_SIZE).quot;
- while (remain && result == DFS_OK) {
- // This is a bit complicated. The sector we want to read is addressed at a cluster
- // granularity by the fileinfo->cluster member. The file pointer tells us how many
- // extra sectors to add to that number.
- sector = fileinfo->volinfo->dataarea +
- ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
- div(div(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
+ // Case 1 - File pointer is not on a sector boundary
+ if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
+unsigned short tempreadsize;
- // Case 1 - File pointer is not on a sector boundary
- if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
-
- unsigned short tempreadsize;
-
-
- // We always have to go through scratch in this case
- result = DFS_ReadSector(fileinfo->volinfo->unit, scratch, sector, 1);
+ // We always have to go through scratch in this case
+ result =
+ DFS_ReadSector(fileinfo->volinfo->unit, scratch,
+ sector, 1);
- // This is the number of bytes that we actually care about in the sector
- // just read.
-
- tempreadsize = SECTOR_SIZE - (div(fileinfo->pointer, SECTOR_SIZE).rem);
-
+ // This is the number of bytes that we actually care about in the sector
+ // just read.
+tempreadsize =
+ SECTOR_SIZE -
+ (div(fileinfo->pointer, SECTOR_SIZE).rem);
+
+ // Case 1A - We want the entire remainder of the sector. After this
+ // point, all passes through the read loop will be aligned on a sector
+ // boundary, which allows us to go through the optimal path 2A below.
+ if (remain >= tempreadsize) {
+memcpy(buffer,
+ scratch + (SECTOR_SIZE - tempreadsize),
+ tempreadsize);
+bytesread = tempreadsize;
+buffer += tempreadsize;
+fileinfo->pointer += tempreadsize;
+remain -= tempreadsize;
+}
- // Case 1A - We want the entire remainder of the sector. After this
- // point, all passes through the read loop will be aligned on a sector
- // boundary, which allows us to go through the optimal path 2A below.
- if (remain >= tempreadsize) {
- memcpy(buffer, scratch + (SECTOR_SIZE - tempreadsize), tempreadsize);
- bytesread = tempreadsize;
- buffer += tempreadsize;
- fileinfo->pointer += tempreadsize;
- remain -= tempreadsize;
- }
- // Case 1B - This read concludes the file read operation
- else {
- memcpy(buffer, scratch + (SECTOR_SIZE - tempreadsize), remain);
+ // Case 1B - This read concludes the file read operation
+ else {
+memcpy(buffer,
+ scratch + (SECTOR_SIZE - tempreadsize),
+ remain);
+buffer += remain;
+fileinfo->pointer += remain;
+bytesread = remain;
+remain = 0;
+}
+}
+
+ // Case 2 - File pointer is on sector boundary
+ else {
- buffer += remain;
- fileinfo->pointer += remain;
- bytesread = remain;
- remain = 0;
- }
- }
- // Case 2 - File pointer is on sector boundary
- else {
-
- // Case 2A - We have at least one more full sector to read and don't have
- // to go through the scratch buffer. You could insert optimizations here to
- // read multiple sectors at a time, if you were thus inclined (note that
- // the maximum multi-read you could perform is a single cluster, so it would
- // be advantageous to have code similar to case 1A above that would round the
- // pointer to a cluster boundary the first pass through, so all subsequent
- // [large] read requests would be able to go a cluster at a time).
- if (remain >= SECTOR_SIZE) {
-
- result = DFS_ReadSector(fileinfo->volinfo->unit, buffer, sector, 1);
+ // Case 2A - We have at least one more full sector to read and don't have
+ // to go through the scratch buffer. You could insert optimizations here to
+ // read multiple sectors at a time, if you were thus inclined (note that
+ // the maximum multi-read you could perform is a single cluster, so it would
+ // be advantageous to have code similar to case 1A above that would round the
+ // pointer to a cluster boundary the first pass through, so all subsequent
+ // [large] read requests would be able to go a cluster at a time).
+ if (remain >= SECTOR_SIZE) {
+result =
+ DFS_ReadSector(fileinfo->volinfo->unit,
+ buffer, sector, 1);
+remain -= SECTOR_SIZE;
+buffer += SECTOR_SIZE;
+fileinfo->pointer += SECTOR_SIZE;
+bytesread = SECTOR_SIZE;
+}
- remain -= SECTOR_SIZE;
-
- buffer += SECTOR_SIZE;
-
- fileinfo->pointer += SECTOR_SIZE;
-
- bytesread = SECTOR_SIZE;
-
- }
- // Case 2B - We are only reading a partial sector
- else {
-
- result = DFS_ReadSector(fileinfo->volinfo->unit, scratch, sector, 1);
- memcpy(buffer, scratch, remain);
- buffer += remain;
- fileinfo->pointer += remain;
- bytesread = remain;
- remain = 0;
- }
- }
+ // Case 2B - We are only reading a partial sector
+ else {
+result =
+ DFS_ReadSector(fileinfo->volinfo->unit,
+ scratch, sector, 1);
+memcpy(buffer, scratch, remain);
+buffer += remain;
+fileinfo->pointer += remain;
+bytesread = remain;
+remain = 0;
+}
+}
+*successcount += bytesread;
- *successcount += bytesread;
-
-
- // check to see if we stepped over a cluster boundary
- if (div(fileinfo->pointer - bytesread, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
- div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
- // An act of minor evil - we use bytesread as a scratch integer, knowing that
- // its value is not used after updating *successcount above
+ // check to see if we stepped over a cluster boundary
+ if (div
+ (fileinfo->pointer - bytesread,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
+div(fileinfo->pointer,
+ fileinfo->volinfo->secperclus *
+ SECTOR_SIZE).quot) {
- bytesread = 0;
-
- if (((fileinfo->volinfo->filesystem == FAT12) && (fileinfo->cluster >= 0xff8)) ||
- ((fileinfo->volinfo->filesystem == FAT16) && (fileinfo->cluster >= 0xfff8)) ||
- ((fileinfo->volinfo->filesystem == FAT32) && (fileinfo->cluster >= 0x0ffffff8)))
- result = DFS_EOF;
- else
- fileinfo->cluster = DFS_GetFAT(fileinfo->volinfo, scratch, &bytesread, fileinfo->cluster);
- }
- }
-
-
- return result;
-}
+ // An act of minor evil - we use bytesread as a scratch integer, knowing that
+ // its value is not used after updating *successcount above
+bytesread = 0;
+if (((fileinfo->volinfo->filesystem == FAT12)
+ && (fileinfo->cluster >= 0xff8))
+((fileinfo->volinfo->filesystem == FAT16)
+ && (fileinfo->cluster >= 0xfff8))
+((fileinfo->volinfo->filesystem == FAT32)
+ && (fileinfo->cluster >= 0x0ffffff8)))
+result = DFS_EOF;
+
+ else
+fileinfo->cluster =
+ DFS_GetFAT(fileinfo->volinfo, scratch,
+ &bytesread, fileinfo->cluster);
+}
+}
+return result;
+}
+
/*
Seek file pointer to a given position
@@ -1187,306 +2029,574 @@
This function does not return status - refer to the fileinfo->pointer value
to see where the pointer wound up.
Requires a SECTOR_SIZE scratch buffer
-*/
-void DFS_Seek(PFILEINFO fileinfo, unsigned long int offset, unsigned char *scratch)
-{
- unsigned long int tempint;
+*/
+void DFS_Seek(PFILEINFO fileinfo, unsigned long int offset,
+ unsigned char *scratch)
+{
+unsigned long int tempint;
- // larwe 9/16/06 bugfix split case 0a/0b and changed fallthrough handling
- // Case 0a - Return immediately for degenerate case
- if (offset == fileinfo->pointer) {
- return;
- }
-
- // Case 0b - Don't allow the user to seek past the end of the file
- if (offset > fileinfo->filelen) {
- offset = fileinfo->filelen;
- // NOTE NO RETURN HERE!
- }
+ // larwe 9/16/06 bugfix split case 0a/0b and changed fallthrough handling
+ // Case 0a - Return immediately for degenerate case
+ if (offset == fileinfo->pointer) {
+return;
+}
- // Case 1 - Simple rewind to start
- // Note _intentional_ fallthrough from Case 0b above
- if (offset == 0) {
- fileinfo->cluster = fileinfo->firstcluster;
- fileinfo->pointer = 0;
- return; // larwe 9/16/06 +1 bugfix
- }
- // Case 2 - Seeking backwards. Need to reset and seek forwards
- else if (offset < fileinfo->pointer) {
- fileinfo->cluster = fileinfo->firstcluster;
- fileinfo->pointer = 0;
- // NOTE NO RETURN HERE!
- }
+ // Case 0b - Don't allow the user to seek past the end of the file
+ if (offset > fileinfo->filelen) {
+offset = fileinfo->filelen;
+
+ // NOTE NO RETURN HERE!
+ }
- // Case 3 - Seeking forwards
- // Note _intentional_ fallthrough from Case 2 above
+ // Case 1 - Simple rewind to start
+ // Note _intentional_ fallthrough from Case 0b above
+ if (offset == 0) {
+fileinfo->cluster = fileinfo->firstcluster;
+fileinfo->pointer = 0;
+return; // larwe 9/16/06 +1 bugfix
+ }
+
+ // Case 2 - Seeking backwards. Need to reset and seek forwards
+ else if (offset < fileinfo->pointer) {
+fileinfo->cluster = fileinfo->firstcluster;
+fileinfo->pointer = 0;
+
+ // NOTE NO RETURN HERE!
+ }
- // Case 3a - Seek size does not cross cluster boundary -
- // very simple case
- // larwe 9/16/06 changed .rem to .quot in both div calls, bugfix
- if (div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot ==
- div(fileinfo->pointer + offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
- fileinfo->pointer = offset;
- }
- // Case 3b - Seeking across cluster boundary(ies)
- else {
- // round file pointer down to cluster boundary
- fileinfo->pointer = div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot *
- fileinfo->volinfo->secperclus * SECTOR_SIZE;
+ // Case 3 - Seeking forwards
+ // Note _intentional_ fallthrough from Case 2 above
+
+ // Case 3a - Seek size does not cross cluster boundary -
+ // very simple case
+ // larwe 9/16/06 changed .rem to .quot in both div calls, bugfix
+ if (div
+ (fileinfo->pointer,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot ==
+div(fileinfo->pointer + offset,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
+fileinfo->pointer = offset;
+}
+
+ // Case 3b - Seeking across cluster boundary(ies)
+ else {
+
+ // round file pointer down to cluster boundary
+ fileinfo->pointer =
+ div(fileinfo->pointer,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot *
+fileinfo->volinfo->secperclus * SECTOR_SIZE;
- // seek by clusters
- // larwe 9/30/06 bugfix changed .rem to .quot in both div calls
- while (div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
- div(fileinfo->pointer + offset, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
+ // seek by clusters
+ // larwe 9/30/06 bugfix changed .rem to .quot in both div calls
+ while (div
+ (fileinfo->pointer,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
+div(fileinfo->pointer + offset,
+ fileinfo->volinfo->secperclus *
+ SECTOR_SIZE).quot) {
+fileinfo->cluster =
+ DFS_GetFAT(fileinfo->volinfo, scratch, &tempint,
+ fileinfo->cluster);
+
+ // Abort if there was an error
+ if (fileinfo->cluster == 0x0ffffff7) {
+fileinfo->pointer = 0;
+fileinfo->cluster = fileinfo->firstcluster;
+return;
+}
+fileinfo->pointer +=
+ SECTOR_SIZE * fileinfo->volinfo->secperclus;
+}
- fileinfo->cluster = DFS_GetFAT(fileinfo->volinfo, scratch, &tempint, fileinfo->cluster);
- // Abort if there was an error
- if (fileinfo->cluster == 0x0ffffff7) {
- fileinfo->pointer = 0;
- fileinfo->cluster = fileinfo->firstcluster;
- return;
- }
- fileinfo->pointer += SECTOR_SIZE * fileinfo->volinfo->secperclus;
- }
+ // since we know the cluster is right, we have no more work to do
+ fileinfo->pointer = offset;
+}
+}
+
- // since we know the cluster is right, we have no more work to do
- fileinfo->pointer = offset;
- }
-}
-
/*
Delete a file
scratch must point to a sector-sized buffer
-*/
-unsigned long int DFS_UnlinkFile(PVOLINFO volinfo, unsigned char *path, unsigned char *scratch)
-{
- PDIRENT de = (PDIRENT) scratch;
- FILEINFO fi;
- unsigned long int cache = 0;
- unsigned long int tempclus;
+*/
+unsigned long int DFS_UnlinkFile(PVOLINFO volinfo, unsigned char *path,
+ unsigned char *scratch)
+{
+PDIRENT de = (PDIRENT) scratch;
+FILEINFO fi;
+unsigned long int cache = 0;
+unsigned long int tempclus;
- // DFS_OpenFile gives us all the information we need to delete it
- if (DFS_OK != DFS_OpenFile(volinfo, path, DFS_READ, scratch, &fi))
- return DFS_NOTFOUND;
+ // DFS_OpenFile gives us all the information we need to delete it
+ if (DFS_OK != DFS_OpenFile(volinfo, path, DFS_READ, scratch, &fi))
+return DFS_NOTFOUND;
- // First, read the directory sector and delete that entry
- if (DFS_ReadSector(volinfo->unit, scratch, fi.dirsector, 1))
- return DFS_ERRMISC;
- ((PDIRENT) scratch)[fi.diroffset].name[0] = 0xe5;
- if (DFS_WriteSector(volinfo->unit, scratch, fi.dirsector, 1))
- return DFS_ERRMISC;
+ // First, read the directory sector and delete that entry
+ if (DFS_ReadSector(volinfo->unit, scratch, fi.dirsector, 1))
+return DFS_ERRMISC;
+((PDIRENT) scratch)[fi.diroffset].name[0] = 0xe5;
+if (DFS_WriteSector(volinfo->unit, scratch, fi.dirsector, 1))
+return DFS_ERRMISC;
- // Now follow the cluster chain to free the file space
- while (!((volinfo->filesystem == FAT12 && fi.firstcluster >= 0x0ff7) ||
- (volinfo->filesystem == FAT16 && fi.firstcluster >= 0xfff7) ||
- (volinfo->filesystem == FAT32 && fi.firstcluster >= 0x0ffffff7))) {
- tempclus = fi.firstcluster;
+ // Now follow the cluster chain to free the file space
+ while (!
+ ((volinfo->filesystem == FAT12 && fi.firstcluster >= 0x0ff7)
+(volinfo->filesystem == FAT16
+ && fi.firstcluster >= 0xfff7)
+(volinfo->filesystem == FAT32
+ && fi.firstcluster >= 0x0ffffff7))) {
+tempclus = fi.firstcluster;
+fi.firstcluster =
+ DFS_GetFAT(volinfo, scratch, &cache, fi.firstcluster);
+DFS_SetFAT(volinfo, scratch, &cache, tempclus, 0);
+}
+return DFS_OK;
+}
+
- fi.firstcluster = DFS_GetFAT(volinfo, scratch, &cache, fi.firstcluster);
- DFS_SetFAT(volinfo, scratch, &cache, tempclus, 0);
-
- }
- return DFS_OK;
-}
-
-
/*
Write an open file
You must supply a prepopulated FILEINFO as provided by DFS_OpenFile, and a
pointer to a SECTOR_SIZE scratch buffer.
This function updates the successcount field with the number of bytes actually written.
-*/
-unsigned long int DFS_WriteFile(PFILEINFO fileinfo, unsigned char *scratch, unsigned char *buffer, unsigned long int *successcount, unsigned long int len)
-{
- unsigned long int remain;
- unsigned long int result = DFS_OK;
- unsigned long int sector;
- unsigned long int byteswritten;
+*/
+unsigned long int DFS_WriteFile(PFILEINFO fileinfo, unsigned char *scratch,
+ unsigned char *buffer,
+ unsigned long int *successcount,
+ unsigned long int len)
+{
+unsigned long int remain;
+unsigned long int result = DFS_OK;
+unsigned long int sector;
+unsigned long int byteswritten;
- // Don't allow writes to a file that's open as readonly
- if (!(fileinfo->mode & DFS_WRITE))
- return DFS_ERRMISC;
+ // Don't allow writes to a file that's open as readonly
+ if (!(fileinfo->mode & DFS_WRITE))
+return DFS_ERRMISC;
+remain = len;
+*successcount = 0;
+while (remain && result == DFS_OK) {
+
+ // This is a bit complicated. The sector we want to read is addressed at a cluster
+ // granularity by the fileinfo->cluster member. The file pointer tells us how many
+ // extra sectors to add to that number.
+ sector = fileinfo->volinfo->dataarea +
+ ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
+div(div
+ (fileinfo->pointer,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).rem,
+ SECTOR_SIZE).quot;
- remain = len;
- *successcount = 0;
+ // Case 1 - File pointer is not on a sector boundary
+ if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
+unsigned short tempsize;
+printf("CASE 1 \n");
+
+ // We always have to go through scratch in this case
+ result =
+ DFS_ReadSector(fileinfo->volinfo->unit, scratch,
+ sector, 1);
- while (remain && result == DFS_OK) {
- // This is a bit complicated. The sector we want to read is addressed at a cluster
- // granularity by the fileinfo->cluster member. The file pointer tells us how many
- // extra sectors to add to that number.
- sector = fileinfo->volinfo->dataarea +
- ((fileinfo->cluster - 2) * fileinfo->volinfo->secperclus) +
- div(div(fileinfo->pointer,fileinfo->volinfo->secperclus * SECTOR_SIZE).rem, SECTOR_SIZE).quot;
+ // This is the number of bytes that we don't want to molest in the
+ // scratch sector just read.
+ tempsize = div(fileinfo->pointer, SECTOR_SIZE).rem;
- // Case 1 - File pointer is not on a sector boundary
- if (div(fileinfo->pointer, SECTOR_SIZE).rem) {
- unsigned short tempsize;
- printf("CASE 1 \n");
- // We always have to go through scratch in this case
- result = DFS_ReadSector(fileinfo->volinfo->unit, scratch, sector, 1);
-
- // This is the number of bytes that we don't want to molest in the
- // scratch sector just read.
- tempsize = div(fileinfo->pointer, SECTOR_SIZE).rem;
-
- // Case 1A - We are writing the entire remainder of the sector. After
- // this point, all passes through the read loop will be aligned on a
- // sector boundary, which allows us to go through the optimal path
- // 2A below.
- if (remain >= SECTOR_SIZE - tempsize) {
- memcpy(scratch + tempsize, buffer, SECTOR_SIZE - tempsize);
- if (!result)
- result = DFS_WriteSector(fileinfo->volinfo->unit, scratch, sector, 1);
-
- byteswritten = SECTOR_SIZE - tempsize;
- buffer += SECTOR_SIZE - tempsize;
- fileinfo->pointer += SECTOR_SIZE - tempsize;
- if (fileinfo->filelen < fileinfo->pointer) {
- fileinfo->filelen = fileinfo->pointer;
- }
- remain -= SECTOR_SIZE - tempsize;
- }
- // Case 1B - This concludes the file write operation
- else {
- printf("CASE 1B \n");
- memcpy(scratch + tempsize, buffer, remain);
- if (!result)
- result = DFS_WriteSector(fileinfo->volinfo->unit, scratch, sector, 1);
-
- buffer += remain;
- fileinfo->pointer += remain;
- if (fileinfo->filelen < fileinfo->pointer) {
- fileinfo->filelen = fileinfo->pointer;
- }
- byteswritten = remain;
- remain = 0;
- }
- } // case 1
+ // Case 1A - We are writing the entire remainder of the sector. After
+ // this point, all passes through the read loop will be aligned on a
+ // sector boundary, which allows us to go through the optimal path
+ // 2A below.
+ if (remain >= SECTOR_SIZE - tempsize) {
+memcpy(scratch + tempsize, buffer,
+ SECTOR_SIZE - tempsize);
+if (!result)
+result =
+ DFS_WriteSector(fileinfo->volinfo->
+ unit, scratch,
+ sector, 1);
+byteswritten = SECTOR_SIZE - tempsize;
+buffer += SECTOR_SIZE - tempsize;
+fileinfo->pointer += SECTOR_SIZE - tempsize;
+if (fileinfo->filelen < fileinfo->pointer) {
+fileinfo->filelen = fileinfo->pointer;
+}
+remain -= SECTOR_SIZE - tempsize;
+}
+
+ // Case 1B - This concludes the file write operation
+ else {
+printf("CASE 1B \n");
+memcpy(scratch + tempsize, buffer, remain);
+if (!result)
+result =
+ DFS_WriteSector(fileinfo->volinfo->
+ unit, scratch,
+ sector, 1);
+buffer += remain;
+fileinfo->pointer += remain;
+if (fileinfo->filelen < fileinfo->pointer) {
+fileinfo->filelen = fileinfo->pointer;
+}
+byteswritten = remain;
+remain = 0;
+}
+} // case 1
// Case 2 - File pointer is on sector boundary
- else {
- printf("CASE 2 \n");
- // Case 2A - We have at least one more full sector to write and don't have
- // to go through the scratch buffer. You could insert optimizations here to
- // write multiple sectors at a time, if you were thus inclined. Refer to
- // similar notes in DFS_ReadFile.
- if (remain >= SECTOR_SIZE) {
- result = DFS_WriteSector(fileinfo->volinfo->unit, buffer, sector, 1);
- remain -= SECTOR_SIZE;
- buffer += SECTOR_SIZE;
- fileinfo->pointer += SECTOR_SIZE;
- if (fileinfo->filelen < fileinfo->pointer) {
- fileinfo->filelen = fileinfo->pointer;
- }
- byteswritten = SECTOR_SIZE;
- }
- // Case 2B - We are only writing a partial sector and potentially need to
- // go through the scratch buffer.
- else {
- printf("CASE 2B \n");
- // If the current file pointer is not yet at or beyond the file
- // length, we are writing somewhere in the middle of the file and
- // need to load the original sector to do a read-modify-write.
- if (fileinfo->pointer < fileinfo->filelen) {
- result = DFS_ReadSector(fileinfo->volinfo->unit, scratch, sector, 1);
- if (!result) {
- memcpy(scratch, buffer, remain);
- result = DFS_WriteSector(fileinfo->volinfo->unit, scratch, sector, 1);
- }
- }
- else {
- result = DFS_WriteSector(fileinfo->volinfo->unit, buffer, sector, 1);
- }
+ else {
+printf("CASE 2 \n");
+
+ // Case 2A - We have at least one more full sector to write and don't have
+ // to go through the scratch buffer. You could insert optimizations here to
+ // write multiple sectors at a time, if you were thus inclined. Refer to
+ // similar notes in DFS_ReadFile.
+ if (remain >= SECTOR_SIZE) {
+result =
+ DFS_WriteSector(fileinfo->volinfo->unit,
+ buffer, sector, 1);
+remain -= SECTOR_SIZE;
+buffer += SECTOR_SIZE;
+fileinfo->pointer += SECTOR_SIZE;
+if (fileinfo->filelen < fileinfo->pointer) {
+fileinfo->filelen = fileinfo->pointer;
+}
+byteswritten = SECTOR_SIZE;
+}
+
+ // Case 2B - We are only writing a partial sector and potentially need to
+ // go through the scratch buffer.
+ else {
+printf("CASE 2B \n");
+
+ // If the current file pointer is not yet at or beyond the file
+ // length, we are writing somewhere in the middle of the file and
+ // need to load the original sector to do a read-modify-write.
+ if (fileinfo->pointer < fileinfo->filelen) {
+result =
+ DFS_ReadSector(fileinfo->volinfo->
+ unit, scratch,
+ sector, 1);
+if (!result) {
+memcpy(scratch, buffer,
+ remain);
+result =
+ DFS_WriteSector(fileinfo->
+ volinfo->
+ unit,
+ scratch,
+ sector, 1);
+}
+}
+
+ else {
+result =
+ DFS_WriteSector(fileinfo->volinfo->
+ unit, buffer,
+ sector, 1);
+}
+buffer += remain;
+fileinfo->pointer += remain;
+if (fileinfo->filelen < fileinfo->pointer) {
+fileinfo->filelen = fileinfo->pointer;
+}
+byteswritten = remain;
+remain = 0;
+}
+}
+*successcount += byteswritten;
+printf("Writen byte %d \n", *successcount);
+
+ // check to see if we stepped over a cluster boundary
+ if (div
+ (fileinfo->pointer - byteswritten,
+ fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
+div(fileinfo->pointer,
+ fileinfo->volinfo->secperclus *
+ SECTOR_SIZE).quot) {
+unsigned long int lastcluster;
- buffer += remain;
- fileinfo->pointer += remain;
- if (fileinfo->filelen < fileinfo->pointer) {
- fileinfo->filelen = fileinfo->pointer;
- }
- byteswritten = remain;
- remain = 0;
- }
- }
+ // We've transgressed into another cluster. If we were already at EOF,
+ // we need to allocate a new cluster.
+ // An act of minor evil - we use byteswritten as a scratch integer, knowing
+ // that its value is not used after updating *successcount above
+ byteswritten = 0;
+lastcluster = fileinfo->cluster;
+fileinfo->cluster =
+ DFS_GetFAT(fileinfo->volinfo, scratch,
+ &byteswritten, fileinfo->cluster);
- *successcount += byteswritten;
- printf("Writen byte %d \n", *successcount );
- // check to see if we stepped over a cluster boundary
- if (div(fileinfo->pointer - byteswritten, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot !=
- div(fileinfo->pointer, fileinfo->volinfo->secperclus * SECTOR_SIZE).quot) {
- unsigned long int lastcluster;
+ // Allocate a new cluster?
+ if (((fileinfo->volinfo->filesystem == FAT12)
+ && (fileinfo->cluster >= 0xff8))
+((fileinfo->volinfo->filesystem == FAT16)
+ && (fileinfo->cluster >= 0xfff8))
+((fileinfo->volinfo->filesystem == FAT32)
+ && (fileinfo->cluster >= 0x0ffffff8))) {
+unsigned long int tempclus;
+tempclus =
+ DFS_GetFreeFAT(fileinfo->volinfo, scratch);
+byteswritten = 0; // invalidate cache
+ if (tempclus == 0x0ffffff7)
+return DFS_ERRMISC;
- // We've transgressed into another cluster. If we were already at EOF,
- // we need to allocate a new cluster.
- // An act of minor evil - we use byteswritten as a scratch integer, knowing
- // that its value is not used after updating *successcount above
- byteswritten = 0;
+ // Link new cluster onto file
+ DFS_SetFAT(fileinfo->volinfo, scratch,
+ &byteswritten, lastcluster,
+ tempclus);
+fileinfo->cluster = tempclus;
- lastcluster = fileinfo->cluster;
- fileinfo->cluster = DFS_GetFAT(fileinfo->volinfo, scratch, &byteswritten, fileinfo->cluster);
+ // Mark newly allocated cluster as end of chain
+ switch (fileinfo->volinfo->filesystem) {
+case FAT12:
+ tempclus = 0xff8;
+ break;
+case FAT16:
+ tempclus = 0xfff8;
+ break;
+case FAT32:
+ tempclus = 0x0ffffff8;
+ break;
+default:
+ return DFS_ERRMISC;
+}
+DFS_SetFAT(fileinfo->volinfo, scratch,
+ &byteswritten, fileinfo->cluster,
+ tempclus);
+result = DFS_OK;
+}
- // Allocate a new cluster?
- if (((fileinfo->volinfo->filesystem == FAT12) && (fileinfo->cluster >= 0xff8)) ||
- ((fileinfo->volinfo->filesystem == FAT16) && (fileinfo->cluster >= 0xfff8)) ||
- ((fileinfo->volinfo->filesystem == FAT32) && (fileinfo->cluster >= 0x0ffffff8))) {
- unsigned long int tempclus;
+ // No else clause is required.
+ }
+}
- tempclus = DFS_GetFreeFAT(fileinfo->volinfo, scratch);
- byteswritten = 0; // invalidate cache
- if (tempclus == 0x0ffffff7)
- return DFS_ERRMISC;
-
- // Link new cluster onto file
- DFS_SetFAT(fileinfo->volinfo, scratch, &byteswritten, lastcluster, tempclus);
- fileinfo->cluster = tempclus;
-
- // Mark newly allocated cluster as end of chain
- switch(fileinfo->volinfo->filesystem) {
- case FAT12: tempclus = 0xff8; break;
- case FAT16: tempclus = 0xfff8; break;
- case FAT32: tempclus = 0x0ffffff8; break;
- default: return DFS_ERRMISC;
- }
- DFS_SetFAT(fileinfo->volinfo, scratch, &byteswritten, fileinfo->cluster, tempclus);
-
- result = DFS_OK;
- }
- // No else clause is required.
- }
- }
+ // Update directory entry
+ if (DFS_ReadSector
+ (fileinfo->volinfo->unit, scratch, fileinfo->dirsector, 1))
+return DFS_ERRMISC;
+((PDIRENT) scratch)[fileinfo->diroffset].filesize_0 =
+ fileinfo->filelen & 0xff;
+((PDIRENT) scratch)[fileinfo->diroffset].filesize_1 =
+ (fileinfo->filelen & 0xff00) >> 8;
+((PDIRENT) scratch)[fileinfo->diroffset].filesize_2 =
+ (fileinfo->filelen & 0xff0000) >> 16;
+((PDIRENT) scratch)[fileinfo->diroffset].filesize_3 =
+ (fileinfo->filelen & 0xff000000) >> 24;
+if (DFS_WriteSector
+ (fileinfo->volinfo->unit, scratch, fileinfo->dirsector, 1))
+return DFS_ERRMISC;
+return result;
+}
+
+int memcmp2(const void *s1, const void *s2, size_t n)
+{
+const unsigned char *p1 = s1, *p2 = s2;
+while (n--)
+if (*p1 != *p2)
+return *p1 - *p2;
- // Update directory entry
- if (DFS_ReadSector(fileinfo->volinfo->unit, scratch, fileinfo->dirsector, 1))
- return DFS_ERRMISC;
- ((PDIRENT) scratch)[fileinfo->diroffset].filesize_0 = fileinfo->filelen & 0xff;
- ((PDIRENT) scratch)[fileinfo->diroffset].filesize_1 = (fileinfo->filelen & 0xff00) >> 8;
- ((PDIRENT) scratch)[fileinfo->diroffset].filesize_2 = (fileinfo->filelen & 0xff0000) >> 16;
- ((PDIRENT) scratch)[fileinfo->diroffset].filesize_3 = (fileinfo->filelen & 0xff000000) >> 24;
- if (DFS_WriteSector(fileinfo->volinfo->unit, scratch, fileinfo->dirsector, 1))
- return DFS_ERRMISC;
- return result;
-}
-
-int memcmp2(const void* s1, const void* s2,size_t n)
-{
- const unsigned char *p1 = s1, *p2 = s2;
- while(n--)
- if( *p1 != *p2 )
- return *p1 - *p2;
- else
- *p1++,*p2++;
- return 0;
-}
-
-char *strcpy2(char *dest, char* src)
-{
- char *ret = dest;
- while (*dest++ = *src++)
- ;
- return ret;
-}
-
-int strcmp2(const char* s1, const char* s2)
-{
- while(*s1 && (*s1==*s2))
- s1++,s2++;
- return *(const unsigned char*)s1-*(const unsigned char*)s2;
-}
+ else
+*p1++, *p2++;
+return 0;
+}
+
+char *strcpy2(char *dest, char *src)
+{
+char *ret = dest;
+while (*dest++ = *src++)
+;
+return ret;
+}
+
+int strcmp2(const char *s1, const char *s2)
+{
+while (*s1 && (*s1 == *s2))
+s1++, s2++;
+return *(const unsigned char *)s1 - *(const unsigned char *)s2;
+}
6,132 → 6,197
-
//#include payment of royalty, regardless of the license(s) you choose for those projects. |
|
You cannot re-copyright or restrict use of the code as released by Lewin Edwards. |
*/ |
|
*/ |
|
/* |
@2010, adam.edvardsson@orsoc.se |
Added local copy of the functions, |
div_t, memcmp2,strcpy2,strcmp2. The one from the string library is not comatible |
|
*/ |
*/ |
/orpmon/common/screen.c
11,86 → 11,96
extern unsigned char font[256][12]; |
static char screen[CHARSY][CHARSX]; |
|
void put_char_xy (int x, int y, char c) { |
int i, j; |
screen[y][x] = c; |
x *= CHAR_WIDTH; |
y *= CHAR_HEIGHT; |
for (i = 0; i < CHAR_HEIGHT; i++) { |
int t = font[(unsigned char)c][i]; |
for (j = 0; j < CHAR_WIDTH; j++) { |
PUT_PIXEL(x + j, y + i, (t & 1) ? fg_color : bg_color); |
t >>= 1; |
} |
} |
void put_char_xy(int x, int y, char c) |
{ |
int i, j; |
screen[y][x] = c; |
x *= CHAR_WIDTH; |
y *= CHAR_HEIGHT; |
for (i = 0; i < CHAR_HEIGHT; i++) { |
int t = font[(unsigned char)c][i]; |
for (j = 0; j < CHAR_WIDTH; j++) { |
PUT_PIXEL(x + j, y + i, (t & 1) ? fg_color : bg_color); |
t >>= 1; |
} |
} |
} |
|
static void scroll (void) { |
int x,y; |
static void scroll(void) |
{ |
int x, y; |
#if 1 |
for (y = 1; y < CHARSY; y++) |
for (x = 0; x < CHARSX; x++) |
put_char_xy (x, y-1, screen[y][x]); |
for (y = 1; y < CHARSY; y++) |
for (x = 0; x < CHARSX; x++) |
put_char_xy(x, y - 1, screen[y][x]); |
#else |
memcpy ( (unsigned char *)FB_BASE_ADDR, ((unsigned char *)FB_BASE_ADDR) + RESX * CHAR_HEIGHT, (RESY - CHAR_HEIGHT) * RESX); |
memcpy (&screen[0][0], &screen[1][0], (CHARSY - 1) * CHARSX); |
memcpy((unsigned char *)FB_BASE_ADDR, |
((unsigned char *)FB_BASE_ADDR) + RESX * CHAR_HEIGHT, |
(RESY - CHAR_HEIGHT) * RESX); |
memcpy(&screen[0][0], &screen[1][0], (CHARSY - 1) * CHARSX); |
#endif |
for (x = 0; x < CHARSX; x++) |
put_char_xy (x, CHARSY-1, ' '); |
cy--; |
for (x = 0; x < CHARSX; x++) |
put_char_xy(x, CHARSY - 1, ' '); |
cy--; |
} |
|
void screen_putc (char c) { |
int t; |
switch (c) { |
case '\n': |
cy++; |
cx = 0; |
if (cy >= CHARSY) |
scroll(); |
break; |
case '\r': |
cx = 0; |
break; |
case '\t': |
for (t = 0; t < 8 - (cx & 7); t++) |
screen_putc (' '); |
break; |
case '\b': |
if (cx > 0) cx--; |
put_char_xy(cx, cy, ' '); |
break; |
default: |
put_char_xy(cx, cy, c); |
cx++; |
if(cx >= CHARSX) screen_putc ('\n'); |
break; |
} |
void screen_putc(char c) |
{ |
int t; |
switch (c) { |
case '\n': |
cy++; |
cx = 0; |
if (cy >= CHARSY) |
scroll(); |
break; |
case '\r': |
cx = 0; |
break; |
case '\t': |
for (t = 0; t < 8 - (cx & 7); t++) |
screen_putc(' '); |
break; |
case '\b': |
if (cx > 0) |
cx--; |
put_char_xy(cx, cy, ' '); |
break; |
default: |
put_char_xy(cx, cy, c); |
cx++; |
if (cx >= CHARSX) |
screen_putc('\n'); |
break; |
} |
} |
|
void screen_clear () { |
memset ((unsigned char *)FB_BASE_ADDR, bg_color, RESX * RESY); |
memset (&screen[0][0], ' ', CHARSX * CHARSY); |
cx = cy = 0; |
void screen_clear() |
{ |
memset((unsigned char *)FB_BASE_ADDR, bg_color, RESX * RESY); |
memset(&screen[0][0], ' ', CHARSX * CHARSY); |
cx = cy = 0; |
} |
|
void screen_puts (char *s) { |
while (*s) { |
screen_putc (*s); |
s++; |
} |
void screen_puts(char *s) |
{ |
while (*s) { |
screen_putc(*s); |
s++; |
} |
} |
|
void screen_init () { |
screen_clear (); |
SET_PALLETE(COLOR_BLACK, 0, 0, 0); |
SET_PALLETE(COLOR_WHITE, 127, 127, 127); |
void screen_init() |
{ |
screen_clear(); |
SET_PALLETE(COLOR_BLACK, 0, 0, 0); |
SET_PALLETE(COLOR_WHITE, 127, 127, 127); |
|
/* Set screen offset */ |
*((unsigned long *)CRT_BUFFER_REG) = FB_BASE_ADDR; |
/* Set screen offset */ |
*((unsigned long *)CRT_BUFFER_REG) = FB_BASE_ADDR; |
|
/* Turn screen on */ |
*((unsigned long *)CRT_REG) = 0x00000001; |
/* Turn screen on */ |
*((unsigned long *)CRT_REG) = 0x00000001; |
} |
|
#endif /* CRT_ENABLED */ |
/orpmon/common/ctype.c
22,34 → 22,33
|
#include <ctype.h> |
|
const unsigned char __ctype_table[256] = |
{ |
/* only the first 128 characters are really defined 0 1 2 3 4 5 6 7 */ |
0, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*0 NUL SOH STX ETX EOT ENQ ACK BEL */ |
__CT_c, __CT_b, __CT_s, __CT_b, __CT_s, __CT_s, __CT_c, __CT_c, /*1 BS HT LF VT FF CR SO SI */ |
__CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*2 DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ |
__CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*3 CAN EM SUB ESC FS GS RS US */ |
__CT_b, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*4 SP ! " # $ % & ' */ |
__CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*5 ( ) * + , - . / */ |
__CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, /*6 0 1 2 3 4 5 6 7 */ |
__CT_d, __CT_d, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*7 8 9 : ; < = > ? */ |
__CT_p, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_u, /*8 @ A B C D E F G */ |
__CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, /*9 H I J K L M N O */ |
__CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, /*a P Q R S T U V W */ |
__CT_u, __CT_u, __CT_u, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*b X Y Z [ \ ] ^ _ */ |
__CT_p, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_l, /*c ` a b c d e f g */ |
__CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, /*d h i j k l m n o */ |
__CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, /*e p q r s t u v w */ |
__CT_l, __CT_l, __CT_l, __CT_p, __CT_p, __CT_p, __CT_p, __CT_c, /*f x y z { | } ~ DEL */ |
const unsigned char __ctype_table[256] = { |
/* only the first 128 characters are really defined 0 1 2 3 4 5 6 7 */ |
0, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*0 NUL SOH STX ETX EOT ENQ ACK BEL */ |
__CT_c, __CT_b, __CT_s, __CT_b, __CT_s, __CT_s, __CT_c, __CT_c, /*1 BS HT LF VT FF CR SO SI */ |
__CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*2 DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ |
__CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, __CT_c, /*3 CAN EM SUB ESC FS GS RS US */ |
__CT_b, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*4 SP ! " # $ % & ' */ |
__CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*5 ( ) * + , - . / */ |
__CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, __CT_d, /*6 0 1 2 3 4 5 6 7 */ |
__CT_d, __CT_d, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*7 8 9 : ; < = > ? */ |
__CT_p, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_ux, __CT_u, /*8 @ A B C D E F G */ |
__CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, /*9 H I J K L M N O */ |
__CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, __CT_u, /*a P Q R S T U V W */ |
__CT_u, __CT_u, __CT_u, __CT_p, __CT_p, __CT_p, __CT_p, __CT_p, /*b X Y Z [ \ ] ^ _ */ |
__CT_p, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_lx, __CT_l, /*c ` a b c d e f g */ |
__CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, /*d h i j k l m n o */ |
__CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, __CT_l, /*e p q r s t u v w */ |
__CT_l, __CT_l, __CT_l, __CT_p, __CT_p, __CT_p, __CT_p, __CT_c, /*f x y z { | } ~ DEL */ |
|
/* The other 128 characters are system dependant */ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
/* The other 128 characters are system dependant */ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
}; |
/orpmon/common/cprintf.c
182,7 → 182,8
#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */ |
#define DEFPREC 6 |
|
static char *cvt _PARAMS((struct _reent *, double, int, int, char *, int *, int, int *)); |
static char *cvt |
_PARAMS((struct _reent *, double, int, int, char *, int *, int, int *)); |
static int exponent _PARAMS((char *, int, int)); |
|
#else /* no FLOATING_POINT */ |
201,15 → 202,15
/* |
* Flags used during conversion. |
*/ |
#define ALT 0x001 /* alternate form */ |
#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ |
#define LADJUST 0x004 /* left adjustment */ |
#define LONGDBL 0x008 /* long double; unimplemented */ |
#define LONGINT 0x010 /* long integer */ |
#define QUADINT 0x020 /* quad integer */ |
#define SHORTINT 0x040 /* short integer */ |
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ |
#define FPT 0x100 /* Floating point number */ |
#define ALT 0x001 /* alternate form */ |
#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ |
#define LADJUST 0x004 /* left adjustment */ |
#define LONGDBL 0x008 /* long double; unimplemented */ |
#define LONGINT 0x010 /* long integer */ |
#define QUADINT 0x020 /* quad integer */ |
#define SHORTINT 0x040 /* short integer */ |
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ |
#define FPT 0x100 /* Floating point number */ |
|
/* |
* Choose PADSIZE to trade efficiency vs. size. If larger printf |
217,29 → 218,35
* below longer. |
*/ |
#define PADSIZE 16 /* pad chunk size */ |
static _CONST char blanks[PADSIZE] = |
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; |
static _CONST char zeroes[PADSIZE] = |
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; |
static _CONST char blanks[PADSIZE] = |
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', |
' ' }; |
static _CONST char zeroes[PADSIZE] = |
{ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
'0' }; |
|
inline void pc (_CONST char c) { |
inline void pc(_CONST char c) |
{ |
#ifdef OR1K |
putc (c); |
putc(c); |
#else |
printf ("%c", c); |
printf("%c", c); |
#endif |
} |
|
/* |
* BEWARE, these `goto error' on error, and PAD uses `n'. |
*/ |
inline void PRINT(_CONST char *ptr, int len) { |
int i; |
for (i = 0; i < len; i++) |
pc(*(ptr++)); |
inline void PRINT(_CONST char *ptr, int len) |
{ |
int i; |
for (i = 0; i < len; i++) |
pc(*(ptr++)); |
} |
|
inline void PAD(int howmany, _CONST char *with) { |
int n; |
inline void PAD(int howmany, _CONST char *with) |
{ |
int n; |
if ((n = howmany) > 0) { |
while (n > PADSIZE) { |
PRINT(with, PADSIZE); |
249,11 → 256,11
} |
} |
|
int printf(const char *fmt0, ...) |
{ |
int printf(const char *fmt0, ...) |
{ |
register char *fmt; /* format string */ |
register int ch; /* character from fmt */ |
int n; /* handy integers (short term usage) */ |
int n; /* handy integers (short term usage) */ |
register char *cp; /* handy char pointer (short term usage) */ |
register int flags; /* flags as above */ |
int ret; /* return value accumulator */ |
261,7 → 268,7
int prec; /* precision from format (%.3d), or -1 */ |
char sign; /* sign prefix (' ', '+', '-', or \0) */ |
va_list ap; |
|
|
#ifdef FLOATING_POINT |
char *decimal_point = localeconv()->decimal_point; |
char softsign; /* temporary negative sign for floats */ |
276,8 → 283,12
#if 0 |
double _double; /* double precision arguments %[eEfgG] */ |
#else |
/* double precision arguments %[eEfgG] */ |
union { int i; double d; } _double_ = {0}; |
/* double precision arguments %[eEfgG] */ |
union { |
int i; |
double d; |
} _double_ = { |
0}; |
#define _double (_double_.d) |
#endif |
int expt; /* integer value of exponent */ |
296,15 → 307,15
#else |
u_long _uquad; |
#endif |
enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */ |
enum { OCT, DEC, HEX } base; /* base for [diouxX] conversion */ |
int dprec; /* a copy of prec if [diouxX], 0 otherwise */ |
int realsz; /* field size expanded by dprec */ |
int size; /* size of converted field or string */ |
char *xdigs = (char *)0; /* digits for [xX] conversion */ |
char *xdigs = (char *)0; /* digits for [xX] conversion */ |
#define NIOV 8 |
|
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ |
char ox[2]; /* space for 0x hex-prefix */ |
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ |
char ox[2]; /* space for 0x hex-prefix */ |
|
#define FLUSH() |
|
334,7 → 345,7
(u_long)va_arg(ap, u_int)) |
#endif |
|
va_start (ap, fmt0); |
va_start(ap, fmt0); |
fmt = (char *)fmt0; |
ret = 0; |
|
342,16 → 353,16
* Scan the format for conversions (`%' character). |
*/ |
for (;;) { |
|
while (*fmt != 0 && *fmt != '%') { |
pc (*fmt); |
fmt++; |
ret++; |
} |
|
while (*fmt != 0 && *fmt != '%') { |
pc(*fmt); |
fmt++; |
ret++; |
} |
if (!*fmt) |
goto done; |
goto done; |
|
fmt++; /* Skip % */ |
fmt++; /* Skip % */ |
flags = 0; |
dprec = 0; |
width = 0; |
364,7 → 375,7
/* |
* ``If the space and + flags both appear, the space |
* flag will be ignored.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
*/ |
if (!sign) |
sign = ' '; |
376,11 → 387,11
/* |
* ``A negative field width argument is taken as a |
* - flag followed by a positive field width.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
* They don't exclude field widths read from args. |
*/ |
if ((width = va_arg(ap, int)) >= 0) |
goto rflag; |
goto rflag; |
width = -width; |
/* FALLTHROUGH */ |
case '-': |
406,12 → 417,19
/* |
* ``Note that 0 is taken as a flag, not as the |
* beginning of a field width.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
*/ |
flags |= ZEROPAD; |
goto rflag; |
case '1': case '2': case '3': case '4': |
case '5': case '6': case '7': case '8': case '9': |
case '1': |
case '2': |
case '3': |
case '4': |
case '5': |
case '6': |
case '7': |
case '8': |
case '9': |
n = 0; |
do { |
n = 10 * n + to_digit(ch); |
445,14 → 463,13
break; |
case 'D': |
flags |= LONGINT; |
/*FALLTHROUGH*/ |
case 'd': |
/*FALLTHROUGH*/ case 'd': |
case 'i': |
_uquad = SARG(); |
#ifndef _NO_LONGLONG |
if ((quad_t)_uquad < 0) |
if ((quad_t) _uquad < 0) |
#else |
if ((long) _uquad < 0) |
if ((long)_uquad < 0) |
#endif |
{ |
|
474,7 → 491,7
} |
|
if (flags & LONGDBL) { |
_double = (double) va_arg(ap, long double); |
_double = (double)va_arg(ap, long double); |
} else { |
_double = va_arg(ap, double); |
} |
495,13 → 512,13
|
flags |= FPT; |
cp = cvt(data, _double, prec, flags, &softsign, |
&expt, ch, &ndig); |
&expt, ch, &ndig); |
if (ch == 'g' || ch == 'G') { |
if (expt <= -4 || expt > prec) |
ch = (ch == 'g') ? 'e' : 'E'; |
else |
ch = 'g'; |
} |
} |
if (ch <= 'e') { /* 'e' or 'E' fmt */ |
--expt; |
expsize = exponent(expstr, expt, ch); |
508,7 → 525,7
size = expsize + ndig; |
if (ndig > 1 || flags & ALT) |
++size; |
} else if (ch == 'f') { /* f fmt */ |
} else if (ch == 'f') { /* f fmt */ |
if (expt > 0) { |
size = expt; |
if (prec || flags & ALT) |
520,8 → 537,7
if (flags & ALT) |
++size; |
} else |
size = ndig + (expt > 0 ? |
1 : 2 - expt); |
size = ndig + (expt > 0 ? 1 : 2 - expt); |
|
if (softsign) |
sign = '-'; |
531,7 → 547,7
#ifndef _NO_LONGLONG |
if (flags & QUADINT) |
*va_arg(ap, quad_t *) = ret; |
else |
else |
#endif |
if (flags & LONGINT) |
*va_arg(ap, long *) = ret; |
542,8 → 558,7
continue; /* no output */ |
case 'O': |
flags |= LONGINT; |
/*FALLTHROUGH*/ |
case 'o': |
/*FALLTHROUGH*/ case 'o': |
_uquad = UARG(); |
base = OCT; |
goto nosign; |
553,10 → 568,11
* value of the pointer is converted to a sequence |
* of printable characters, in an implementation- |
* defined manner.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
*/ |
/* NOSTRICT */ |
_uquad = (u_long)(unsigned _POINTER_INT)va_arg(ap, void *); |
_uquad = |
(u_long) (unsigned _POINTER_INT)va_arg(ap, void *); |
base = HEX; |
xdigs = "0123456789abcdef"; |
flags |= HEXPREFIX; |
585,8 → 601,7
break; |
case 'U': |
flags |= LONGINT; |
/*FALLTHROUGH*/ |
case 'u': |
/*FALLTHROUGH*/ case 'u': |
_uquad = UARG(); |
base = DEC; |
goto nosign; |
602,19 → 617,19
flags |= HEXPREFIX; |
|
/* unsigned conversions */ |
nosign: sign = '\0'; |
nosign: sign = '\0'; |
/* |
* ``... diouXx conversions ... if a precision is |
* specified, the 0 flag will be ignored.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
*/ |
number: if ((dprec = prec) >= 0) |
number: if ((dprec = prec) >= 0) |
flags &= ~ZEROPAD; |
|
/* |
* ``The result of converting a zero value with an |
* explicit precision of zero is no characters.'' |
* -- ANSI X3J11 |
* -- ANSI X3J11 |
*/ |
cp = buf + BUF; |
if (_uquad != 0 || prec != 0) { |
657,7 → 672,7
} |
} |
size = buf + BUF - cp; |
skipsize: |
skipsize: |
break; |
default: /* "%?" prints ?, unless ? is NUL */ |
if (ch == '\0') |
688,10 → 703,10
if (sign) |
realsz++; |
else if (flags & HEXPREFIX) |
realsz+= 2; |
realsz += 2; |
|
/* right-adjusting blank padding */ |
if ((flags & (LADJUST|ZEROPAD)) == 0) |
if ((flags & (LADJUST | ZEROPAD)) == 0) |
PAD(width - realsz, blanks); |
|
/* prefix */ |
704,7 → 719,7
} |
|
/* right-adjusting zero padding */ |
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) |
if ((flags & (LADJUST | ZEROPAD)) == ZEROPAD) |
PAD(width - realsz, zeroes); |
|
/* leading zeroes from decimal precision */ |
737,7 → 752,7
PRINT(cp, expt); |
cp += expt; |
PRINT(".", 1); |
PRINT(cp, ndig-expt); |
PRINT(cp, ndig - expt); |
} |
} else { /* 'e' or 'E' */ |
if (ndig > 1 || flags & ALT) { |
745,7 → 760,7
ox[1] = '.'; |
PRINT(ox, 2); |
if (_double || flags & ALT == 0) { |
PRINT(cp, ndig-1); |
PRINT(cp, ndig - 1); |
} else /* 0.[0..] */ |
/* __dtoa irregularity */ |
PAD(ndig - 1, zeroes); |
767,7 → 782,7
FLUSH(); /* copy out the I/O vectors */ |
} |
done: |
va_end (ap); |
va_end(ap); |
FLUSH(); |
return (ret); |
/* NOTREACHED */ |
778,19 → 793,18
extern char *_dtoa_r _PARAMS((struct _reent *, double, int, |
int, int *, int *, char **)); |
|
static char * |
cvt(data, value, ndigits, flags, sign, decpt, ch, length) |
struct _reent *data; |
double value; |
int ndigits, flags, *decpt, ch, *length; |
char *sign; |
static char *cvt(data, value, ndigits, flags, sign, decpt, ch, length) |
struct _reent *data; |
double value; |
int ndigits, flags, *decpt, ch, *length; |
char *sign; |
{ |
int mode, dsgn; |
char *digits, *bp, *rve; |
union double_union tmp; |
union double_union tmp; |
|
if (ch == 'f') { |
mode = 3; /* ndigits after the decimal point */ |
mode = 3; /* ndigits after the decimal point */ |
} else { |
/* To obtain ndigits after the decimal point for the 'e' |
* and 'E' formats, round to ndigits + 1 significant |
799,14 → 813,14
if (ch == 'e' || ch == 'E') { |
ndigits++; |
} |
mode = 2; /* ndigits significant digits */ |
mode = 2; /* ndigits significant digits */ |
} |
|
tmp.d = value; |
if (word0(tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */ |
tmp.d = value; |
if (word0(tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */ |
value = -value; |
*sign = '-'; |
} else |
} else |
*sign = '\000'; |
digits = _dtoa_r(data, value, mode, ndigits, decpt, &dsgn, &rve); |
if ((ch != 'g' && ch != 'G') || flags & ALT) { /* Print trailing zeros */ |
825,10 → 839,9
return (digits); |
} |
|
static int |
exponent(p0, exp, fmtch) |
char *p0; |
int exp, fmtch; |
static int exponent(p0, exp, fmtch) |
char *p0; |
int exp, fmtch; |
{ |
register char *p, *t; |
char expbuf[MAXEXP]; |
838,8 → 851,7
if (exp < 0) { |
exp = -exp; |
*p++ = '-'; |
} |
else |
} else |
*p++ = '+'; |
t = expbuf + MAXEXP; |
if (exp > 9) { |
847,9 → 859,8
*--t = to_char(exp % 10); |
} while ((exp /= 10) > 9); |
*--t = to_char(exp); |
for (; t < expbuf + MAXEXP; *p++ = *t++); |
} |
else { |
for (; t < expbuf + MAXEXP; *p++ = *t++) ; |
} else { |
*p++ = '0'; |
*p++ = to_char(exp); |
} |
/orpmon/common/font.c
2,308 → 2,262
#if CRT_ENABLED |
|
unsigned char font[256][12] = { |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0, 00h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1, 01h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2, 02h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3, 03h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4, 04h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5, 05h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6, 06h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7, 07h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8, 08h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9, 09h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10, 0ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11, 0bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12, 0ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13, 0dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14, 0eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15, 0fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16, 10h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17, 11h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18, 12h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19, 13h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20, 14h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21, 15h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22, 16h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 23, 17h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 24, 18h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 25, 19h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 26, 1ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 27, 1bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 28, 1ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 29, 1dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 30, 1eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 31, 1fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 32, 20h, ' ' */ |
{0x00, 0x0c, 0x1e, 0x1e, 0x1e, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00, 0x00}, /* 33, 21h, '!' */ |
{0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 34, 22h, '"' */ |
{0x00, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x00}, /* 35, 23h, '#' */ |
{0x0c, 0x0c, 0x3e, 0x03, 0x03, 0x1e, 0x30, 0x30, 0x1f, 0x0c, 0x0c, 0x00}, /* 36, 24h, '$' */ |
{0x00, 0x00, 0x00, 0x23, 0x33, 0x18, 0x0c, 0x06, 0x33, 0x31, 0x00, 0x00}, /* 37, 25h, '%' */ |
{0x00, 0x0e, 0x1b, 0x1b, 0x0e, 0x5f, 0x7b, 0x33, 0x3b, 0x6e, 0x00, 0x00}, /* 38, 26h, '&' */ |
{0x00, 0x0c, 0x0c, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 39, 27h, ''' */ |
{0x00, 0x30, 0x18, 0x0c, 0x06, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x00}, /* 40, 28h, '(' */ |
{0x00, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00}, /* 41, 29h, ')' */ |
{0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00}, /* 42, 2ah, '*' */ |
{0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 43, 2bh, '+' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x06, 0x00}, /* 44, 2ch, ',' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 45, 2dh, '-' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00}, /* 46, 2eh, '.' */ |
{0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00}, /* 47, 2fh, '/' */ |
{0x00, 0x3e, 0x63, 0x73, 0x7b, 0x6b, 0x6f, 0x67, 0x63, 0x3e, 0x00, 0x00}, /* 48, 30h, '0' */ |
{0x00, 0x08, 0x0c, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3f, 0x00, 0x00}, /* 49, 31h, '1' */ |
{0x00, 0x1e, 0x33, 0x33, 0x30, 0x18, 0x0c, 0x06, 0x33, 0x3f, 0x00, 0x00}, /* 50, 32h, '2' */ |
{0x00, 0x1e, 0x33, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x33, 0x1e, 0x00, 0x00}, /* 51, 33h, '3' */ |
{0x00, 0x30, 0x38, 0x3c, 0x36, 0x33, 0x7f, 0x30, 0x30, 0x78, 0x00, 0x00}, /* 52, 34h, '4' */ |
{0x00, 0x3f, 0x03, 0x03, 0x03, 0x1f, 0x30, 0x30, 0x33, 0x1e, 0x00, 0x00}, /* 53, 35h, '5' */ |
{0x00, 0x1c, 0x06, 0x03, 0x03, 0x1f, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 54, 36h, '6' */ |
{0x00, 0x7f, 0x63, 0x63, 0x60, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x00, 0x00}, /* 55, 37h, '7' */ |
{0x00, 0x1e, 0x33, 0x33, 0x37, 0x1e, 0x3b, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 56, 38h, '8' */ |
{0x00, 0x1e, 0x33, 0x33, 0x33, 0x3e, 0x18, 0x18, 0x0c, 0x0e, 0x00, 0x00}, /* 57, 39h, '9' */ |
{0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00}, /* 58, 3ah, ':' */ |
{0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x18, 0x0c, 0x00}, /* 59, 3bh, ';' */ |
{0x00, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x00}, /* 60, 3ch, '<' */ |
{0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 61, 3dh, '=' */ |
{0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00}, /* 62, 3eh, '>' */ |
{0x00, 0x1e, 0x33, 0x30, 0x18, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00, 0x00}, /* 63, 3fh, '?' */ |
{0x00, 0x3e, 0x63, 0x63, 0x7b, 0x7b, 0x7b, 0x03, 0x03, 0x3e, 0x00, 0x00}, /* 64, 40h, '@' */ |
{0x00, 0x0c, 0x1e, 0x33, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 65, 41h, 'A' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x66, 0x66, 0x66, 0x3f, 0x00, 0x00}, /* 66, 42h, 'B' */ |
{0x00, 0x3c, 0x66, 0x63, 0x03, 0x03, 0x03, 0x63, 0x66, 0x3c, 0x00, 0x00}, /* 67, 43h, 'C' */ |
{0x00, 0x1f, 0x36, 0x66, 0x66, 0x66, 0x66, 0x66, 0x36, 0x1f, 0x00, 0x00}, /* 68, 44h, 'D' */ |
{0x00, 0x7f, 0x46, 0x06, 0x26, 0x3e, 0x26, 0x06, 0x46, 0x7f, 0x00, 0x00}, /* 69, 45h, 'E' */ |
{0x00, 0x7f, 0x66, 0x46, 0x26, 0x3e, 0x26, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 70, 46h, 'F' */ |
{0x00, 0x3c, 0x66, 0x63, 0x03, 0x03, 0x73, 0x63, 0x66, 0x7c, 0x00, 0x00}, /* 71, 47h, 'G' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 72, 48h, 'H' */ |
{0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 73, 49h, 'I' */ |
{0x00, 0x78, 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 74, 4ah, 'J' */ |
{0x00, 0x67, 0x66, 0x36, 0x36, 0x1e, 0x36, 0x36, 0x66, 0x67, 0x00, 0x00}, /* 75, 4bh, 'K' */ |
{0x00, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x46, 0x66, 0x66, 0x7f, 0x00, 0x00}, /* 76, 4ch, 'L' */ |
{0x00, 0x63, 0x77, 0x7f, 0x7f, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00}, /* 77, 4dh, 'M' */ |
{0x00, 0x63, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x00, 0x00}, /* 78, 4eh, 'N' */ |
{0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00}, /* 79, 4fh, 'O' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 80, 50h, 'P' */ |
{0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x73, 0x7b, 0x3e, 0x30, 0x78, 0x00}, /* 81, 51h, 'Q' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x36, 0x66, 0x66, 0x67, 0x00, 0x00}, /* 82, 52h, 'R' */ |
{0x00, 0x1e, 0x33, 0x33, 0x03, 0x0e, 0x18, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 83, 53h, 'S' */ |
{0x00, 0x3f, 0x2d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 84, 54h, 'T' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 85, 55h, 'U' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x00}, /* 86, 56h, 'V' */ |
{0x00, 0x63, 0x63, 0x63, 0x63, 0x6b, 0x6b, 0x36, 0x36, 0x36, 0x00, 0x00}, /* 87, 57h, 'W' */ |
{0x00, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x1e, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 88, 58h, 'X' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 89, 59h, 'Y' */ |
{0x00, 0x7f, 0x73, 0x19, 0x18, 0x0c, 0x06, 0x46, 0x63, 0x7f, 0x00, 0x00}, /* 90, 5ah, 'Z' */ |
{0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00}, /* 91, 5bh, '[' */ |
{0x00, 0x00, 0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00}, /* 92, 5ch, '\' */ |
{0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00}, /* 93, 5dh, ']' */ |
{0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 94, 5eh, '^' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00}, /* 95, 5fh, '_' */ |
{0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 96, 60h, '`' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 97, 61h, 'a' */ |
{0x00, 0x07, 0x06, 0x06, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3b, 0x00, 0x00}, /* 98, 62h, 'b' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x03, 0x03, 0x33, 0x1e, 0x00, 0x00}, /* 99, 63h, 'c' */ |
{0x00, 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 100, 64h, 'd' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x3f, 0x03, 0x33, 0x1e, 0x00, 0x00}, /* 101, 65h, 'e' */ |
{0x00, 0x1c, 0x36, 0x06, 0x06, 0x1f, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 102, 66h, 'f' */ |
{0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x33, 0x1e}, /* 103, 67h, 'g' */ |
{0x00, 0x07, 0x06, 0x06, 0x36, 0x6e, 0x66, 0x66, 0x66, 0x67, 0x00, 0x00}, /* 104, 68h, 'h' */ |
{0x00, 0x18, 0x18, 0x00, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00}, /* 105, 69h, 'i' */ |
{0x00, 0x30, 0x30, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1e}, /* 106, 6ah, 'j' */ |
{0x00, 0x07, 0x06, 0x06, 0x66, 0x36, 0x1e, 0x36, 0x66, 0x67, 0x00, 0x00}, /* 107, 6bh, 'k' */ |
{0x00, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00}, /* 108, 6ch, 'l' */ |
{0x00, 0x00, 0x00, 0x00, 0x3f, 0x6b, 0x6b, 0x6b, 0x6b, 0x63, 0x00, 0x00}, /* 109, 6dh, 'm' */ |
{0x00, 0x00, 0x00, 0x00, 0x1f, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 110, 6eh, 'n' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 111, 6fh, 'o' */ |
{0x00, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x0f}, /* 112, 70h, 'p' */ |
{0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x78}, /* 113, 71h, 'q' */ |
{0x00, 0x00, 0x00, 0x00, 0x37, 0x76, 0x6e, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 114, 72h, 'r' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x06, 0x18, 0x33, 0x1e, 0x00, 0x00}, /* 115, 73h, 's' */ |
{0x00, 0x00, 0x04, 0x06, 0x3f, 0x06, 0x06, 0x06, 0x36, 0x1c, 0x00, 0x00}, /* 116, 74h, 't' */ |
{0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 117, 75h, 'u' */ |
{0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x00}, /* 118, 76h, 'v' */ |
{0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x6b, 0x6b, 0x36, 0x36, 0x00, 0x00}, /* 119, 77h, 'w' */ |
{0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1c, 0x1c, 0x36, 0x63, 0x00, 0x00}, /* 120, 78h, 'x' */ |
{0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x30, 0x18, 0x0f}, /* 121, 79h, 'y' */ |
{0x00, 0x00, 0x00, 0x00, 0x3f, 0x31, 0x18, 0x06, 0x23, 0x3f, 0x00, 0x00}, /* 122, 7ah, 'z' */ |
{0x00, 0x38, 0x0c, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x0c, 0x38, 0x00, 0x00}, /* 123, 7bh, '{' */ |
{0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00}, /* 124, 7ch, '|' */ |
{0x00, 0x07, 0x0c, 0x0c, 0x18, 0x30, 0x18, 0x0c, 0x0c, 0x07, 0x00, 0x00}, /* 125, 7dh, '}' */ |
{0x00, 0xce, 0x5b, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 126, 7eh, '~' */ |
{0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x00, 0x00, 0x00}, /* 127, 7fh, '' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 128, 80h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 129, 81h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 130, 82h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 131, 83h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 132, 84h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 133, 85h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 134, 86h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 135, 87h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 136, 88h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 137, 89h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 138, 8ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 139, 8bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 140, 8ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 141, 8dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 142, 8eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 143, 8fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 144, 90h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 145, 91h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 146, 92h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 147, 93h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 148, 94h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 149, 95h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 150, 96h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 151, 97h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 152, 98h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 153, 99h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 154, 9ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 155, 9bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 156, 9ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 157, 9dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 158, 9eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 159, 9fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 160, a0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 161, a1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 162, a2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 163, a3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 164, a4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 165, a5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 166, a6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 167, a7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 168, a8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 169, a9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 170, aah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 171, abh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 172, ach */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 173, adh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 174, aeh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 175, afh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 176, b0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 177, b1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 178, b2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 179, b3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 180, b4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 181, b5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 182, b6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 183, b7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 184, b8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 185, b9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 186, bah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 187, bbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 188, bch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 189, bdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 190, beh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 191, bfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 192, c0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 193, c1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 194, c2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 195, c3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 196, c4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 197, c5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 198, c6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 199, c7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 200, c8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 201, c9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 202, cah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 203, cbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 204, cch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 205, cdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 206, ceh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 207, cfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 208, d0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 209, d1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 210, d2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 211, d3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 212, d4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 213, d5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 214, d6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 215, d7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 216, d8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 217, d9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 218, dah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 219, dbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 220, dch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 221, ddh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 222, deh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 223, dfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 224, e0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 225, e1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 226, e2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 227, e3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 228, e4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 229, e5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 230, e6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 231, e7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 232, e8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 233, e9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 234, eah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 235, ebh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 236, ech */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 237, edh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 238, eeh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 239, efh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 240, f0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 241, f1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 242, f2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 243, f3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 244, f4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 245, f5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 246, f6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 247, f7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 248, f8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 249, f9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 250, fah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 251, fbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 252, fch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 253, fdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 254, feh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};/* 255, ffh */ |
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0, 00h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1, 01h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2, 02h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3, 03h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4, 04h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5, 05h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6, 06h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7, 07h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8, 08h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9, 09h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10, 0ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11, 0bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12, 0ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13, 0dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14, 0eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15, 0fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16, 10h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17, 11h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18, 12h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19, 13h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20, 14h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21, 15h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22, 16h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 23, 17h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 24, 18h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 25, 19h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 26, 1ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 27, 1bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 28, 1ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 29, 1dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 30, 1eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 31, 1fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 32, 20h, ' ' */ |
{0x00, 0x0c, 0x1e, 0x1e, 0x1e, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00, 0x00}, /* 33, 21h, '!' */ |
{0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 34, 22h, '"' */ |
{0x00, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x00}, /* 35, 23h, '#' */ |
{0x0c, 0x0c, 0x3e, 0x03, 0x03, 0x1e, 0x30, 0x30, 0x1f, 0x0c, 0x0c, 0x00}, /* 36, 24h, '$' */ |
{0x00, 0x00, 0x00, 0x23, 0x33, 0x18, 0x0c, 0x06, 0x33, 0x31, 0x00, 0x00}, /* 37, 25h, '%' */ |
{0x00, 0x0e, 0x1b, 0x1b, 0x0e, 0x5f, 0x7b, 0x33, 0x3b, 0x6e, 0x00, 0x00}, /* 38, 26h, '&' */ |
{0x00, 0x0c, 0x0c, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 39, 27h, ''' */ |
{0x00, 0x30, 0x18, 0x0c, 0x06, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x00}, /* 40, 28h, '(' */ |
{0x00, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00}, /* 41, 29h, ')' */ |
{0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00}, /* 42, 2ah, '*' */ |
{0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 43, 2bh, '+' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x06, 0x00}, /* 44, 2ch, ',' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 45, 2dh, '-' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00}, /* 46, 2eh, '.' */ |
{0x00, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00}, /* 47, 2fh, '/' */ |
{0x00, 0x3e, 0x63, 0x73, 0x7b, 0x6b, 0x6f, 0x67, 0x63, 0x3e, 0x00, 0x00}, /* 48, 30h, '0' */ |
{0x00, 0x08, 0x0c, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3f, 0x00, 0x00}, /* 49, 31h, '1' */ |
{0x00, 0x1e, 0x33, 0x33, 0x30, 0x18, 0x0c, 0x06, 0x33, 0x3f, 0x00, 0x00}, /* 50, 32h, '2' */ |
{0x00, 0x1e, 0x33, 0x30, 0x30, 0x1c, 0x30, 0x30, 0x33, 0x1e, 0x00, 0x00}, /* 51, 33h, '3' */ |
{0x00, 0x30, 0x38, 0x3c, 0x36, 0x33, 0x7f, 0x30, 0x30, 0x78, 0x00, 0x00}, /* 52, 34h, '4' */ |
{0x00, 0x3f, 0x03, 0x03, 0x03, 0x1f, 0x30, 0x30, 0x33, 0x1e, 0x00, 0x00}, /* 53, 35h, '5' */ |
{0x00, 0x1c, 0x06, 0x03, 0x03, 0x1f, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 54, 36h, '6' */ |
{0x00, 0x7f, 0x63, 0x63, 0x60, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x00, 0x00}, /* 55, 37h, '7' */ |
{0x00, 0x1e, 0x33, 0x33, 0x37, 0x1e, 0x3b, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 56, 38h, '8' */ |
{0x00, 0x1e, 0x33, 0x33, 0x33, 0x3e, 0x18, 0x18, 0x0c, 0x0e, 0x00, 0x00}, /* 57, 39h, '9' */ |
{0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x00}, /* 58, 3ah, ':' */ |
{0x00, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1c, 0x1c, 0x18, 0x0c, 0x00}, /* 59, 3bh, ';' */ |
{0x00, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x00}, /* 60, 3ch, '<' */ |
{0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 61, 3dh, '=' */ |
{0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00}, /* 62, 3eh, '>' */ |
{0x00, 0x1e, 0x33, 0x30, 0x18, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00, 0x00}, /* 63, 3fh, '?' */ |
{0x00, 0x3e, 0x63, 0x63, 0x7b, 0x7b, 0x7b, 0x03, 0x03, 0x3e, 0x00, 0x00}, /* 64, 40h, '@' */ |
{0x00, 0x0c, 0x1e, 0x33, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 65, 41h, 'A' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x66, 0x66, 0x66, 0x3f, 0x00, 0x00}, /* 66, 42h, 'B' */ |
{0x00, 0x3c, 0x66, 0x63, 0x03, 0x03, 0x03, 0x63, 0x66, 0x3c, 0x00, 0x00}, /* 67, 43h, 'C' */ |
{0x00, 0x1f, 0x36, 0x66, 0x66, 0x66, 0x66, 0x66, 0x36, 0x1f, 0x00, 0x00}, /* 68, 44h, 'D' */ |
{0x00, 0x7f, 0x46, 0x06, 0x26, 0x3e, 0x26, 0x06, 0x46, 0x7f, 0x00, 0x00}, /* 69, 45h, 'E' */ |
{0x00, 0x7f, 0x66, 0x46, 0x26, 0x3e, 0x26, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 70, 46h, 'F' */ |
{0x00, 0x3c, 0x66, 0x63, 0x03, 0x03, 0x73, 0x63, 0x66, 0x7c, 0x00, 0x00}, /* 71, 47h, 'G' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x3f, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 72, 48h, 'H' */ |
{0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 73, 49h, 'I' */ |
{0x00, 0x78, 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 74, 4ah, 'J' */ |
{0x00, 0x67, 0x66, 0x36, 0x36, 0x1e, 0x36, 0x36, 0x66, 0x67, 0x00, 0x00}, /* 75, 4bh, 'K' */ |
{0x00, 0x0f, 0x06, 0x06, 0x06, 0x06, 0x46, 0x66, 0x66, 0x7f, 0x00, 0x00}, /* 76, 4ch, 'L' */ |
{0x00, 0x63, 0x77, 0x7f, 0x7f, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00}, /* 77, 4dh, 'M' */ |
{0x00, 0x63, 0x63, 0x67, 0x6f, 0x7f, 0x7b, 0x73, 0x63, 0x63, 0x00, 0x00}, /* 78, 4eh, 'N' */ |
{0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00}, /* 79, 4fh, 'O' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 80, 50h, 'P' */ |
{0x00, 0x1c, 0x36, 0x63, 0x63, 0x63, 0x73, 0x7b, 0x3e, 0x30, 0x78, 0x00}, /* 81, 51h, 'Q' */ |
{0x00, 0x3f, 0x66, 0x66, 0x66, 0x3e, 0x36, 0x66, 0x66, 0x67, 0x00, 0x00}, /* 82, 52h, 'R' */ |
{0x00, 0x1e, 0x33, 0x33, 0x03, 0x0e, 0x18, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 83, 53h, 'S' */ |
{0x00, 0x3f, 0x2d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 84, 54h, 'T' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 85, 55h, 'U' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x00}, /* 86, 56h, 'V' */ |
{0x00, 0x63, 0x63, 0x63, 0x63, 0x6b, 0x6b, 0x36, 0x36, 0x36, 0x00, 0x00}, /* 87, 57h, 'W' */ |
{0x00, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x1e, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 88, 58h, 'X' */ |
{0x00, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00}, /* 89, 59h, 'Y' */ |
{0x00, 0x7f, 0x73, 0x19, 0x18, 0x0c, 0x06, 0x46, 0x63, 0x7f, 0x00, 0x00}, /* 90, 5ah, 'Z' */ |
{0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00}, /* 91, 5bh, '[' */ |
{0x00, 0x00, 0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00}, /* 92, 5ch, '\' */ |
{0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00}, /* 93, 5dh, ']' */ |
{0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 94, 5eh, '^' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00}, /* 95, 5fh, '_' */ |
{0x0c, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 96, 60h, '`' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x3e, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 97, 61h, 'a' */ |
{0x00, 0x07, 0x06, 0x06, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3b, 0x00, 0x00}, /* 98, 62h, 'b' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x03, 0x03, 0x33, 0x1e, 0x00, 0x00}, /* 99, 63h, 'c' */ |
{0x00, 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 100, 64h, 'd' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x3f, 0x03, 0x33, 0x1e, 0x00, 0x00}, /* 101, 65h, 'e' */ |
{0x00, 0x1c, 0x36, 0x06, 0x06, 0x1f, 0x06, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 102, 66h, 'f' */ |
{0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x33, 0x1e}, /* 103, 67h, 'g' */ |
{0x00, 0x07, 0x06, 0x06, 0x36, 0x6e, 0x66, 0x66, 0x66, 0x67, 0x00, 0x00}, /* 104, 68h, 'h' */ |
{0x00, 0x18, 0x18, 0x00, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00}, /* 105, 69h, 'i' */ |
{0x00, 0x30, 0x30, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1e}, /* 106, 6ah, 'j' */ |
{0x00, 0x07, 0x06, 0x06, 0x66, 0x36, 0x1e, 0x36, 0x66, 0x67, 0x00, 0x00}, /* 107, 6bh, 'k' */ |
{0x00, 0x1e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00}, /* 108, 6ch, 'l' */ |
{0x00, 0x00, 0x00, 0x00, 0x3f, 0x6b, 0x6b, 0x6b, 0x6b, 0x63, 0x00, 0x00}, /* 109, 6dh, 'm' */ |
{0x00, 0x00, 0x00, 0x00, 0x1f, 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00}, /* 110, 6eh, 'n' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x00, 0x00}, /* 111, 6fh, 'o' */ |
{0x00, 0x00, 0x00, 0x00, 0x3b, 0x66, 0x66, 0x66, 0x66, 0x3e, 0x06, 0x0f}, /* 112, 70h, 'p' */ |
{0x00, 0x00, 0x00, 0x00, 0x6e, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x30, 0x78}, /* 113, 71h, 'q' */ |
{0x00, 0x00, 0x00, 0x00, 0x37, 0x76, 0x6e, 0x06, 0x06, 0x0f, 0x00, 0x00}, /* 114, 72h, 'r' */ |
{0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x06, 0x18, 0x33, 0x1e, 0x00, 0x00}, /* 115, 73h, 's' */ |
{0x00, 0x00, 0x04, 0x06, 0x3f, 0x06, 0x06, 0x06, 0x36, 0x1c, 0x00, 0x00}, /* 116, 74h, 't' */ |
{0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x6e, 0x00, 0x00}, /* 117, 75h, 'u' */ |
{0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x1e, 0x0c, 0x00, 0x00}, /* 118, 76h, 'v' */ |
{0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x6b, 0x6b, 0x36, 0x36, 0x00, 0x00}, /* 119, 77h, 'w' */ |
{0x00, 0x00, 0x00, 0x00, 0x63, 0x36, 0x1c, 0x1c, 0x36, 0x63, 0x00, 0x00}, /* 120, 78h, 'x' */ |
{0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x30, 0x18, 0x0f}, /* 121, 79h, 'y' */ |
{0x00, 0x00, 0x00, 0x00, 0x3f, 0x31, 0x18, 0x06, 0x23, 0x3f, 0x00, 0x00}, /* 122, 7ah, 'z' */ |
{0x00, 0x38, 0x0c, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x0c, 0x38, 0x00, 0x00}, /* 123, 7bh, '{' */ |
{0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00}, /* 124, 7ch, '|' */ |
{0x00, 0x07, 0x0c, 0x0c, 0x18, 0x30, 0x18, 0x0c, 0x0c, 0x07, 0x00, 0x00}, /* 125, 7dh, '}' */ |
{0x00, 0xce, 0x5b, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 126, 7eh, '~' */ |
{0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63, 0x7f, 0x00, 0x00, 0x00}, /* 127, 7fh, '' */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 128, 80h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 129, 81h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 130, 82h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 131, 83h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 132, 84h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 133, 85h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 134, 86h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 135, 87h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 136, 88h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 137, 89h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 138, 8ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 139, 8bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 140, 8ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 141, 8dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 142, 8eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 143, 8fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 144, 90h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 145, 91h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 146, 92h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 147, 93h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 148, 94h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 149, 95h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 150, 96h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 151, 97h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 152, 98h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 153, 99h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 154, 9ah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 155, 9bh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 156, 9ch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 157, 9dh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 158, 9eh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 159, 9fh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 160, a0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 161, a1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 162, a2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 163, a3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 164, a4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 165, a5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 166, a6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 167, a7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 168, a8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 169, a9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 170, aah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 171, abh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 172, ach */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 173, adh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 174, aeh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 175, afh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 176, b0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 177, b1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 178, b2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 179, b3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 180, b4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 181, b5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 182, b6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 183, b7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 184, b8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 185, b9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 186, bah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 187, bbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 188, bch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 189, bdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 190, beh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 191, bfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 192, c0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 193, c1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 194, c2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 195, c3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 196, c4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 197, c5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 198, c6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 199, c7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 200, c8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 201, c9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 202, cah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 203, cbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 204, cch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 205, cdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 206, ceh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 207, cfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 208, d0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 209, d1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 210, d2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 211, d3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 212, d4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 213, d5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 214, d6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 215, d7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 216, d8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 217, d9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 218, dah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 219, dbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 220, dch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 221, ddh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 222, deh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 223, dfh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 224, e0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 225, e1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 226, e2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 227, e3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 228, e4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 229, e5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 230, e6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 231, e7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 232, e8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 233, e9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 234, eah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 235, ebh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 236, ech */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 237, edh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 238, eeh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 239, efh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 240, f0h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 241, f1h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 242, f2h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 243, f3h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 244, f4h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 245, f5h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 246, f6h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 247, f7h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 248, f8h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 249, f9h */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 250, fah */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 251, fbh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 252, fch */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 253, fdh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 254, feh */ |
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
}; /* 255, ffh */ |
|
#endif /* CRT_ENABLED */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/orpmon/common/string.c
32,13 → 32,13
*/ |
size_t strlen(const char *s) |
{ |
size_t cnt = 0; |
size_t cnt = 0; |
|
/* count the length of string s, not including the \0 character */ |
while (*s++) |
cnt++; |
/* count the length of string s, not including the \0 character */ |
while (*s++) |
cnt++; |
|
return cnt; |
return cnt; |
} |
|
/* |
48,217 → 48,198
*/ |
char *strcpy(char *dest, const char *src) |
{ |
char *d = dest; |
char *d = dest; |
|
/* copy src to dest */ |
while ( (*dest++ = *src++) ) |
; |
/* copy src to dest */ |
while ((*dest++ = *src++)) ; |
|
return d; |
return d; |
} |
|
|
char *strncpy(char *dest, const char *src, size_t n) |
{ |
char *d = dest; |
char *d = dest; |
|
/* copy src to dest */ |
while ( *src && n ) { |
*dest++ = *src++; |
n--; |
} |
/* copy src to dest */ |
while (*src && n) { |
*dest++ = *src++; |
n--; |
} |
|
/* fill the remainder of d with nulls */ |
while (n--) |
*dest++ = '\0'; |
/* fill the remainder of d with nulls */ |
while (n--) |
*dest++ = '\0'; |
|
return d; |
return d; |
} |
|
|
char *strcat(char *dest, const char *src) |
{ |
char *d = dest; |
char *d = dest; |
|
/* find the end of the destination string */ |
while (*dest++) |
; |
/* find the end of the destination string */ |
while (*dest++) ; |
|
/* append the source string to the destination string */ |
while ( (*dest++ = *src++) ) |
; |
/* append the source string to the destination string */ |
while ((*dest++ = *src++)) ; |
|
return d; |
return d; |
} |
|
|
char *strncat(char *dest, const char *src, size_t n) |
{ |
char *d = dest; |
char *d = dest; |
|
/* find the end of the destination string */ |
while (*dest++) |
; |
/* find the end of the destination string */ |
while (*dest++) ; |
|
/* copy src to dest */ |
while ( (*dest = *src) && n-- ) { |
dest++; |
src++; |
} |
/* copy src to dest */ |
while ((*dest = *src) && n--) { |
dest++; |
src++; |
} |
|
/* add terminating '\0' character */ |
*dest = '\0'; |
|
/* add terminating '\0' character */ |
*dest = '\0'; |
|
return d; |
return d; |
} |
|
|
int strcmp(const char *s1, const char *s2) |
{ |
while ( *s1 && (*s1 == *s2) ) { |
s1++; |
s2++; |
} |
while (*s1 && (*s1 == *s2)) { |
s1++; |
s2++; |
} |
|
return *s1 - *s2; |
return *s1 - *s2; |
} |
|
|
int strncmp(const char *s1, const char *s2, size_t n) |
{ |
while ( *s1 && (*s1 == *s2) && n-- ) { |
s1++; |
s2++; |
} |
while (*s1 && (*s1 == *s2) && n--) { |
s1++; |
s2++; |
} |
|
return *s1 - *s2; |
return *s1 - *s2; |
} |
|
|
char *strchr(const char *s, int c) |
{ |
/* search for the character c */ |
while (*s && (*s != c) ) |
s++; |
/* search for the character c */ |
while (*s && (*s != c)) |
s++; |
|
return (char *)s; |
return (char *)s; |
} |
|
|
char *strrchr(const char *s, int c) |
{ |
char *fnd = NULL; |
char *fnd = NULL; |
|
/* search for the character c */ |
while (*s) { |
if (*s == c) |
fnd = (char *)s; |
s++; |
} |
/* search for the character c */ |
while (*s) { |
if (*s == c) |
fnd = (char *)s; |
s++; |
} |
|
return fnd; |
return fnd; |
} |
|
|
/* Basic mem functions */ |
void *memcpy(void *dest, const void *src, size_t n) |
{ |
/* check if 'src' and 'dest' are on LONG boundaries */ |
if ( (sizeof(unsigned long) -1) & ((unsigned long)dest | (unsigned long)src) ) |
{ |
/* no, do a byte-wide copy */ |
char *cs = (char *) src; |
char *cd = (char *) dest; |
/* check if 'src' and 'dest' are on LONG boundaries */ |
if ((sizeof(unsigned long) - |
1) & ((unsigned long)dest | (unsigned long)src)) { |
/* no, do a byte-wide copy */ |
char *cs = (char *)src; |
char *cd = (char *)dest; |
|
while (n--) |
*cd++ = *cs++; |
} |
else |
{ |
/* yes, speed up copy process */ |
/* copy as many LONGs as possible */ |
long *ls = (long *)src; |
long *ld = (long *)dest; |
while (n--) |
*cd++ = *cs++; |
} else { |
/* yes, speed up copy process */ |
/* copy as many LONGs as possible */ |
long *ls = (long *)src; |
long *ld = (long *)dest; |
|
size_t cnt = n >> 2; |
while (cnt--) |
*ld++ = *ls++; |
size_t cnt = n >> 2; |
while (cnt--) |
*ld++ = *ls++; |
|
/* finally copy the remaining bytes */ |
char *cs = (char *) (src + (n & ~0x03)); |
char *cd = (char *) (dest + (n & ~0x03)); |
/* finally copy the remaining bytes */ |
char *cs = (char *)(src + (n & ~0x03)); |
char *cd = (char *)(dest + (n & ~0x03)); |
|
cnt = n & 0x3; |
while (cnt--) |
*cd++ = *cs++; |
} |
cnt = n & 0x3; |
while (cnt--) |
*cd++ = *cs++; |
} |
|
return dest; |
return dest; |
} |
|
/* memcpy, return checksum of bytes copied instead of pointer to dest */ |
unsigned char memcpy_crc(void *dest, const void *src, size_t n) |
{ |
unsigned char sum = 0; |
unsigned char tmp; |
unsigned char sum = 0; |
unsigned char tmp; |
|
char *cs = (char *) src; |
char *cd = (char *) dest; |
|
while (n--) |
{ |
tmp = *cs++; |
sum += tmp; |
*cd++ = tmp; |
} |
return sum; |
char *cs = (char *)src; |
char *cd = (char *)dest; |
|
while (n--) { |
tmp = *cs++; |
sum += tmp; |
*cd++ = tmp; |
} |
return sum; |
} |
|
void *memmove(void *dest, void *src, size_t n) |
{ |
char *d = dest; |
char *s = src; |
char *d = dest; |
char *s = src; |
|
while (n--) |
*d++ = *s++; |
while (n--) |
*d++ = *s++; |
|
return dest; |
return dest; |
} |
|
|
int memcmp(const void *s1, const void *s2, size_t n) |
{ |
char *p1 = (void *)s1; |
char *p2 = (void *)s2; |
char *p1 = (void *)s1; |
char *p2 = (void *)s2; |
|
while ( (*p1 == *p2) && n-- ) { |
p1++; |
p2++; |
} |
while ((*p1 == *p2) && n--) { |
p1++; |
p2++; |
} |
|
return *p1 - *p2; |
return *p1 - *p2; |
} |
|
|
void *memchr(const void *s, char c, size_t n) |
{ |
char *p = (void *)s; |
char *p = (void *)s; |
|
/* search for the character c */ |
while ( (*p != c) && n-- ) |
p++; |
/* search for the character c */ |
while ((*p != c) && n--) |
p++; |
|
return (*p == c) ? p : NULL; |
return (*p == c) ? p : NULL; |
} |
|
|
void *memset(void *s, int c, size_t n) |
{ |
char *p = s; |
char *p = s; |
|
while (n--) |
*p++ = c; |
while (n--) |
*p++ = c; |
|
return s; |
return s; |
} |
/orpmon/common/spincursor.c
4,52 → 4,49
|
int spin_cursor_enabled = 0; |
|
|
void enable_spincursor(void) |
{ |
spin_cursor_enabled = 1; |
spin_cursor_enabled = 1; |
} |
|
|
void disable_spincursor(void) |
{ |
spin_cursor_enabled = 0; |
spin_cursor_enabled = 0; |
|
} |
|
void spincursor(void) |
{ |
static int last_spin_char = 0; |
static int last_spin_ticks = 0; |
|
if (!spin_cursor_enabled) |
return; |
|
if ((get_timer(0) - last_spin_ticks) < (TICKS_PER_US*2000)) |
return; |
|
// Put a backspace |
uart_putc(0x8); |
if (last_spin_char == 0) |
uart_putc("/"); |
else if (last_spin_char == 1) |
uart_putc("-"); |
else if (last_spin_char == 2) |
uart_putc("\\"); |
else if (last_spin_char == 3) |
uart_putc("|"); |
else if (last_spin_char == 4) |
uart_putc("/"); |
else if (last_spin_char == 5) |
uart_putc("-"); |
else if (last_spin_char == 6) |
uart_putc("\\"); |
else if (last_spin_char == 7) |
{ |
uart_putc("|"); |
last_spin_char=-1; |
} |
|
last_spin_char++; |
last_spin_ticks = get_timer(0); |
static int last_spin_char = 0; |
static int last_spin_ticks = 0; |
|
if (!spin_cursor_enabled) |
return; |
|
if ((get_timer(0) - last_spin_ticks) < (TICKS_PER_US * 2000)) |
return; |
|
// Put a backspace |
uart_putc(0x8); |
if (last_spin_char == 0) |
uart_putc("/"); |
else if (last_spin_char == 1) |
uart_putc("-"); |
else if (last_spin_char == 2) |
uart_putc("\\"); |
else if (last_spin_char == 3) |
uart_putc("|"); |
else if (last_spin_char == 4) |
uart_putc("/"); |
else if (last_spin_char == 5) |
uart_putc("-"); |
else if (last_spin_char == 6) |
uart_putc("\\"); |
else if (last_spin_char == 7) { |
uart_putc("|"); |
last_spin_char = -1; |
} |
|
last_spin_char++; |
last_spin_ticks = get_timer(0); |
} |
/orpmon/common/common.c
20,182 → 20,186
|
command_struct command[MAX_COMMANDS]; |
|
void putc (const char c) |
void putc(const char c) |
{ |
debug ("putc %i, %i = %c\n", bd.bi_console_type, c, c); |
switch (bd.bi_console_type) { |
case CT_NONE: |
break; |
case CT_UART: |
uart_putc (c); |
break; |
debug("putc %i, %i = %c\n", bd.bi_console_type, c, c); |
switch (bd.bi_console_type) { |
case CT_NONE: |
break; |
case CT_UART: |
uart_putc(c); |
break; |
#if CRT_ENABLED==1 |
case CT_CRT: |
screen_putc (c); |
break; |
case CT_CRT: |
screen_putc(c); |
break; |
#endif |
case CT_SIM: |
__printf ("%c", c); |
break; |
} |
case CT_SIM: |
__printf("%c", c); |
break; |
} |
} |
|
int getc () |
int getc() |
{ |
int ch = 0; |
debug ("getc %i\n", bd.bi_console_type); |
switch (bd.bi_console_type) { |
int ch = 0; |
debug("getc %i\n", bd.bi_console_type); |
switch (bd.bi_console_type) { |
#if KBD_ENABLED==1 |
case CT_CRT: |
while ((volatile int)kbd_head == (volatile int)kbd_tail); |
ch = kbd_buf[kbd_tail]; |
kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE; |
return ch; |
case CT_CRT: |
while ((volatile int)kbd_head == (volatile int)kbd_tail) ; |
ch = kbd_buf[kbd_tail]; |
kbd_tail = (kbd_tail + 1) % KBDBUF_SIZE; |
return ch; |
#endif |
case CT_UART: |
return uart_getc (); |
break; |
case CT_NONE: /* just to satisfy the compiler */ |
case CT_SIM: |
break; |
} |
return -1; |
case CT_UART: |
return uart_getc(); |
break; |
case CT_NONE: /* just to satisfy the compiler */ |
case CT_SIM: |
break; |
} |
return -1; |
} |
|
int testc () |
int testc() |
{ |
debug ("testc %i\n", bd.bi_console_type); |
switch (bd.bi_console_type) { |
debug("testc %i\n", bd.bi_console_type); |
switch (bd.bi_console_type) { |
#if KBD_ENABLED |
case CT_CRT: |
if (kbd_head == kbd_tail) return 0; |
else return getc (); |
case CT_CRT: |
if (kbd_head == kbd_tail) |
return 0; |
else |
return getc(); |
#endif |
case CT_UART: |
return uart_testc (); |
break; |
case CT_NONE: /* just to satisfy the compiler */ |
case CT_SIM: |
break; |
} |
return -1; |
case CT_UART: |
return uart_testc(); |
break; |
case CT_NONE: /* just to satisfy the compiler */ |
case CT_SIM: |
break; |
} |
return -1; |
} |
|
int ctrlc () |
int ctrlc() |
{ |
if (testc ()) { |
switch (getc ()) { |
case 0x03: /* ^C - Control C */ |
return 1; |
default: |
break; |
} |
} |
return 0; |
if (testc()) { |
switch (getc()) { |
case 0x03: /* ^C - Control C */ |
return 1; |
default: |
break; |
} |
} |
return 0; |
} |
|
void |
print_or1k_cache_info() |
void print_or1k_cache_info() |
{ |
// Read out UPR, check what modules we have |
unsigned long upr = mfspr(SPR_UPR); |
printf("Instruction cache:\t"); |
if (upr & SPR_UPR_ICP) |
{ |
// We have instruction cache, read out ICCFGR |
|
unsigned long iccfgr = mfspr(SPR_ICCFGR); |
unsigned int cbs; // cache block size |
unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); |
if (iccfgr & SPR_ICCFGR_CBS) |
cbs = 32; |
else |
cbs = 16; |
// Read out UPR, check what modules we have |
unsigned long upr = mfspr(SPR_UPR); |
printf("Instruction cache:\t"); |
if (upr & SPR_UPR_ICP) { |
// We have instruction cache, read out ICCFGR |
|
printf("%dkB (BS: %d Sets: %d)\n", |
(cbs * ncs)/1024, cbs, ncs); |
|
} |
else |
printf(" not present\n"); |
unsigned long iccfgr = mfspr(SPR_ICCFGR); |
unsigned int cbs; // cache block size |
unsigned long ncs = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); |
if (iccfgr & SPR_ICCFGR_CBS) |
cbs = 32; |
else |
cbs = 16; |
|
printf("Data cache:\t\t"); |
if (upr & SPR_UPR_DCP) |
{ |
// We have instruction cache, read out DCCFGR |
|
unsigned long iccfgr = mfspr(SPR_DCCFGR); |
unsigned int cbs; // cache block size |
unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3); |
if (iccfgr & SPR_DCCFGR_CBS) |
cbs = 32; |
else |
cbs = 16; |
printf("%dkB (BS: %d Sets: %d)\n", |
(cbs * ncs) / 1024, cbs, ncs); |
|
printf("%dkB (BS: %d Sets: %d)\n", |
(cbs * ncs)/1024, cbs, ncs); |
|
} |
else |
printf(" not present\n"); |
|
} else |
printf(" not present\n"); |
|
printf("Data cache:\t\t"); |
if (upr & SPR_UPR_DCP) { |
// We have instruction cache, read out DCCFGR |
|
unsigned long iccfgr = mfspr(SPR_DCCFGR); |
unsigned int cbs; // cache block size |
unsigned long ncs = 1 << ((iccfgr & SPR_DCCFGR_NCS) >> 3); |
if (iccfgr & SPR_DCCFGR_CBS) |
cbs = 32; |
else |
cbs = 16; |
|
printf("%dkB (BS: %d Sets: %d)\n", |
(cbs * ncs) / 1024, cbs, ncs); |
|
} else |
printf(" not present\n"); |
|
} |
|
unsigned long parse_ip (char *ip) |
unsigned long parse_ip(char *ip) |
{ |
unsigned long num; |
num = strtoul (ip, &ip, 10) & 0xff; |
if (*ip++ != '.') return 0; |
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff); |
if (*ip++ != '.') return 0; |
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff); |
if (*ip++ != '.') return 0; |
num = (num << 8) | (strtoul (ip, &ip, 10) & 0xff); |
return num; |
unsigned long num; |
num = strtoul(ip, &ip, 10) & 0xff; |
if (*ip++ != '.') |
return 0; |
num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff); |
if (*ip++ != '.') |
return 0; |
num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff); |
if (*ip++ != '.') |
return 0; |
num = (num << 8) | (strtoul(ip, &ip, 10) & 0xff); |
return num; |
} |
|
void change_console_type (enum bi_console_type_t con_type) |
void change_console_type(enum bi_console_type_t con_type) |
{ |
debug ("Console change %i -> %i\n", bd.bi_console_type, con_type); |
/* Close previous */ |
switch (bd.bi_console_type) { |
case CT_NONE: |
case CT_UART: |
case CT_CRT: |
case CT_SIM: |
break; |
} |
bd.bi_console_type = con_type; |
/* Initialize new */ |
switch (bd.bi_console_type) { |
case CT_NONE: |
break; |
case CT_UART: |
uart_init (); |
break; |
case CT_CRT: |
debug("Console change %i -> %i\n", bd.bi_console_type, con_type); |
/* Close previous */ |
switch (bd.bi_console_type) { |
case CT_NONE: |
case CT_UART: |
case CT_CRT: |
case CT_SIM: |
break; |
} |
bd.bi_console_type = con_type; |
/* Initialize new */ |
switch (bd.bi_console_type) { |
case CT_NONE: |
break; |
case CT_UART: |
uart_init(); |
break; |
case CT_CRT: |
#if CRT_ENABLED==1 |
screen_init (); |
screen_init(); |
#endif |
#if KBD_ENABLED |
kbd_init (); |
kbd_init(); |
#endif |
break; |
case CT_SIM: |
break; |
} |
break; |
case CT_SIM: |
break; |
} |
} |
|
void register_command_func (const char *name, const char *params, const char *help, int (*func)(int argc, char *argv[])) |
void register_command_func(const char *name, const char *params, |
const char *help, int (*func) (int argc, |
char *argv[])) |
{ |
debug ("register_command '%s'\n", name); |
if (num_commands < MAX_COMMANDS) { |
command[num_commands].name = name; |
command[num_commands].params = params; |
command[num_commands].help = help; |
command[num_commands].func = func; |
num_commands++; |
} else printf ("Command '%s' ignored; MAX_COMMANDS limit reached\n", name); |
debug("register_command '%s'\n", name); |
if (num_commands < MAX_COMMANDS) { |
command[num_commands].name = name; |
command[num_commands].params = params; |
command[num_commands].help = help; |
command[num_commands].func = func; |
num_commands++; |
} else |
printf("Command '%s' ignored; MAX_COMMANDS limit reached\n", |
name); |
} |
|
/* Process command and arguments by executing |
202,192 → 206,188
specific function. */ |
void mon_command(void) |
{ |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
int chcnt = 0; |
char c = '\0'; |
char str[1000]; |
char *pstr = str; |
char *command_str; |
char *argv[20]; |
int argc = 0; |
int chcnt = 0; |
|
/* Show prompt */ |
printf ("\n" BOARD_DEF_NAME"> "); |
/* Show prompt */ |
printf("\n" BOARD_DEF_NAME "> "); |
|
while(1) |
{ |
c=getc(); |
while (1) { |
c = getc(); |
|
if (c == 0x7f) // Backspace on picocom is showing up as 0x7f |
c = '\b'; |
if (c == 0x7f) // Backspace on picocom is showing up as 0x7f |
c = '\b'; |
|
if (c == '\r' || c == '\f' || c == '\n') |
{ |
// Mark end of string |
*pstr = '\0'; |
putc('\n'); |
break; |
if (c == '\r' || c == '\f' || c == '\n') { |
// Mark end of string |
*pstr = '\0'; |
putc('\n'); |
break; |
} else if (c == '\b') // Backspace |
{ |
if (chcnt > 0) { |
putc(c); |
putc(' '); // cover char with space |
putc(c); |
pstr--; |
chcnt--; |
} |
} else { |
putc(c); |
*pstr++ = c; |
chcnt++; |
} |
} |
else if (c == '\b') // Backspace |
{ |
if (chcnt > 0) |
{ |
putc(c); |
putc(' '); // cover char with space |
putc(c); |
pstr--; |
chcnt--; |
} |
} |
else |
{ |
putc(c); |
*pstr++ = c; |
chcnt++; |
} |
} |
|
/* Skip leading blanks */ |
pstr = str; |
while (*pstr == ' ' && *pstr != '\0') pstr++; |
/* Skip leading blanks */ |
pstr = str; |
while (*pstr == ' ' && *pstr != '\0') |
pstr++; |
|
/* Get command from the string */ |
command_str = pstr; |
/* Get command from the string */ |
command_str = pstr; |
|
while (1) { |
/* Go to next argument */ |
while (*pstr != ' ' && *pstr != '\0') pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while (*pstr == ' ') pstr++; |
argv[argc++] = pstr; |
} |
else |
break; |
} |
while (1) { |
/* Go to next argument */ |
while (*pstr != ' ' && *pstr != '\0') |
pstr++; |
if (*pstr) { |
*pstr++ = '\0'; |
while (*pstr == ' ') |
pstr++; |
argv[argc++] = pstr; |
} else |
break; |
} |
|
{ |
int i, found = 0; |
{ |
int i, found = 0; |
|
for (i = 0; i < num_commands; i++) |
if (strcmp (command_str, command[i].name) == 0) |
{ |
switch ( command[i].func(argc, &argv[0]) ) |
{ |
case -1: |
printf ("Missing/wrong parameters, usage: %s %s\n", |
command[i].name, command[i].params); |
break; |
} |
for (i = 0; i < num_commands; i++) |
if (strcmp(command_str, command[i].name) == 0) { |
switch (command[i].func(argc, &argv[0])) { |
case -1: |
printf |
("Missing/wrong parameters, usage: %s %s\n", |
command[i].name, |
command[i].params); |
break; |
} |
|
found++; |
break; |
} |
/* 'built-in' build command */ |
if(strcmp(command_str, "build") == 0) { |
printf("Build tag: %s", BUILD_VERSION); |
found++; |
} |
if (!found) |
printf ("Unknown command. Type 'help' for help.\n"); |
} |
|
found++; |
break; |
} |
/* 'built-in' build command */ |
if (strcmp(command_str, "build") == 0) { |
printf("Build tag: %s", BUILD_VERSION); |
found++; |
} |
if (!found) |
printf("Unknown command. Type 'help' for help.\n"); |
} |
|
} |
|
#if HELP_ENABLED |
extern unsigned long _src_addr; // Stack section ends here, will print it out |
extern unsigned long _src_addr; // Stack section ends here, will print it out |
/* Displays help screen */ |
int help_cmd (int argc, char *argv[]) |
int help_cmd(int argc, char *argv[]) |
{ |
int i; |
for (i = 0; i < num_commands; i++) |
printf ("%-10s %-20s - %s\n", command[i].name, command[i].params, command[i].help); |
int i; |
for (i = 0; i < num_commands; i++) |
printf("%-10s %-20s - %s\n", command[i].name, command[i].params, |
command[i].help); |
|
// Build info.... |
printf("\n"); |
printf("CPU info\n"); |
printf("Frequency\t\t%dMHz\n", IN_CLK/1000000); |
print_or1k_cache_info(); |
printf("\n"); |
printf("Info: Stack section addr 0x%x\n",(unsigned long) &_src_addr); |
printf("Build tag: %s", BUILD_VERSION); |
// Build info.... |
printf("\n"); |
printf("CPU info\n"); |
printf("Frequency\t\t%dMHz\n", IN_CLK / 1000000); |
print_or1k_cache_info(); |
printf("\n"); |
printf("Info: Stack section addr 0x%x\n", (unsigned long)&_src_addr); |
printf("Build tag: %s", BUILD_VERSION); |
|
return 0; |
return 0; |
} |
#endif /* HELP_ENABLED */ |
|
void module_cpu_init (void); |
void module_memory_init (void); |
void module_eth_init (void); |
void module_dhry_init (void); |
void module_coremark_init (void); |
void module_camera_init (void); |
void module_load_init (void); |
void module_cpu_init(void); |
void module_memory_init(void); |
void module_eth_init(void); |
void module_dhry_init(void); |
void module_coremark_init(void); |
void module_camera_init(void); |
void module_load_init(void); |
void tick_init(void); |
void module_touch_init (void); |
void module_ata_init (void); |
void module_hdbug_init (void); |
void module_touch_init(void); |
void module_ata_init(void); |
void module_hdbug_init(void); |
|
|
/* List of all initializations */ |
void mon_init (void) |
void mon_init(void) |
{ |
/* Set defaults */ |
global.erase_method = 2; /* as needed */ |
global.src_addr = (unsigned long)&_src_addr; |
global.dst_addr = FLASH_BASE_ADDR; |
global.eth_add[0] = ETH_MACADDR0; |
global.eth_add[1] = ETH_MACADDR1; |
global.eth_add[2] = ETH_MACADDR2; |
global.eth_add[3] = ETH_MACADDR3; |
global.eth_add[4] = ETH_MACADDR4; |
global.eth_add[5] = ETH_MACADDR5; |
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
/* Set defaults */ |
global.erase_method = 2; /* as needed */ |
global.src_addr = (unsigned long)&_src_addr; |
global.dst_addr = FLASH_BASE_ADDR; |
global.eth_add[0] = ETH_MACADDR0; |
global.eth_add[1] = ETH_MACADDR1; |
global.eth_add[2] = ETH_MACADDR2; |
global.eth_add[3] = ETH_MACADDR3; |
global.eth_add[4] = ETH_MACADDR4; |
global.eth_add[5] = ETH_MACADDR5; |
global.ip = BOARD_DEF_IP; |
global.gw_ip = BOARD_DEF_GW; |
global.mask = BOARD_DEF_MASK; |
|
#define CPU_CMDS |
#define MEM_CMDS |
#define DHRY_CMDS |
#define COREMARK_CMDS |
//#define CAMERA_CMDS |
//#define CAMERA_CMDS |
#define LOAD_CMDS |
//#define TOUCHSCREEN_CMDS |
//#define ATA_CMDS |
//#define HDBUG_CMDS |
//#define TOUCHSCREEN_CMDS |
//#define ATA_CMDS |
//#define HDBUG_CMDS |
#define TICK_CMDS |
#define ETH_CMDS |
#define LOAD_CMDS |
|
/* Init modules */ |
|
/* Init modules */ |
#ifdef CPU_CMDS |
module_cpu_init (); |
module_cpu_init(); |
#endif |
#ifdef MEM_CMDS |
module_memory_init (); |
module_memory_init(); |
#endif |
#ifdef ETH_CMDS |
module_eth_init (); |
module_eth_init(); |
#endif |
#ifdef DHRY_CMDS |
module_dhry_init (); |
module_dhry_init(); |
#endif |
#ifdef COREMARK_CMDS |
module_coremark_init (); |
module_coremark_init(); |
#endif |
#ifdef CAMERA_CMDS |
module_camera_init (); |
module_camera_init(); |
#endif |
#ifdef LOAD_CMDS |
module_load_init (); |
module_load_init(); |
#endif |
#ifdef TOUCHSCREEN_CMDS |
module_touch_init (); |
module_touch_init(); |
#endif |
#ifdef ATA_CMDS |
module_ata_init (); |
module_ata_init(); |
#endif |
#ifdef HDBUG_CMDS |
module_hdbug_init (); |
module_hdbug_init(); |
#endif |
|
#ifdef TICK_CMDS |
394,49 → 394,49
#endif |
|
} |
int tboot_cmd (int argc, char *argv[]); |
|
int tboot_cmd(int argc, char *argv[]); |
/* Main shell loop */ |
int main(int argc, char **argv) |
{ |
extern unsigned long calc_mycrc32 (void); |
extern unsigned long calc_mycrc32(void); |
|
#if 0 |
extern unsigned long mycrc32, mysize; |
extern unsigned long mycrc32, mysize; |
#endif |
|
timestamp = 0; // clear timer counter |
|
int_init (); |
timestamp = 0; // clear timer counter |
|
change_console_type (CONSOLE_TYPE); |
int_init(); |
|
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE); |
change_console_type(CONSOLE_TYPE); |
|
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE); |
|
#if SELF_CHECK |
printf ("Self check... "); |
if ((t = calc_mycrc32 ())) |
printf ("FAILED!!!\n"); |
else |
printf ("OK\n"); |
printf("Self check... "); |
if ((t = calc_mycrc32())) |
printf("FAILED!!!\n"); |
else |
printf("OK\n"); |
#endif /* SELF_CHECK */ |
|
num_commands=0; |
mon_init (); |
num_commands = 0; |
mon_init(); |
|
disable_spincursor(); |
|
tick_init(); |
disable_spincursor(); |
|
tick_init(); |
|
if (HELP_ENABLED) register_command ("help", "", "shows this help", help_cmd); |
if (HELP_ENABLED) |
register_command("help", "", "shows this help", help_cmd); |
|
printf ("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n"); |
printf("\tbuild: %s", BUILD_VERSION); |
printf("\n" BOARD_DEF_NAME " monitor (type 'help' for help)\n"); |
printf("\tbuild: %s", BUILD_VERSION); |
|
// Loop forever, accepting commands |
while(1) |
{ |
mon_command(); |
} |
// Loop forever, accepting commands |
while (1) { |
mon_command(); |
} |
|
} |
/orpmon/common/support.c
12,11 → 12,11
void int_main(void); |
|
/* return value by making a syscall */ |
void exit (int i) |
void exit(int i) |
{ |
asm("l.add r3,r0,%0": : "r" (i)); |
asm("l.nop %0": :"K" (NOP_EXIT)); |
while (1); |
asm("l.add r3,r0,%0": :"r"(i)); |
asm("l.nop %0": :"K"(NOP_EXIT)); |
while (1) ; |
} |
|
/* activate printf support in simulator */ |
23,11 → 23,11
void __printf(const char *fmt, ...) |
{ |
#if 0 |
va_list args; |
va_start(args, fmt); |
__asm__ __volatile__ (" l.addi\tr3,%1,0\n \ |
va_list args; |
va_start(args, fmt); |
__asm__ __volatile__(" l.addi\tr3,%1,0\n \ |
l.addi\tr4,%2,0\n \ |
l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r" (args) : "r3", "r4"); |
l.nop %0"::"K"(NOP_PRINTF), "r"(fmt), "r"(args):"r3", "r4"); |
#endif |
} |
|
34,8 → 34,8
/* print long */ |
void report(unsigned long value) |
{ |
asm("l.addi\tr3,%0,0": :"r" (value)); |
asm("l.nop %0": :"K" (NOP_REPORT)); |
asm("l.addi\tr3,%0,0": :"r"(value)); |
asm("l.nop %0": :"K"(NOP_REPORT)); |
} |
|
/* just to satisfy linker */ |
46,86 → 46,87
/* For writing into SPR. */ |
void mtspr(unsigned long spr, unsigned long value) |
{ |
asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value)); |
asm("l.mtspr\t\t%0,%1,0": :"r"(spr), "r"(value)); |
} |
|
/* For reading SPR. */ |
unsigned long mfspr(unsigned long spr) |
{ |
unsigned long value; |
asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr)); |
return value; |
unsigned long value; |
asm("l.mfspr\t\t%0,%1,0": "=r"(value):"r"(spr)); |
return value; |
} |
|
|
|
/* Parses hex or decimal number */ |
unsigned long strtoul (const char *str, char **endptr, int base) |
unsigned long strtoul(const char *str, char **endptr, int base) |
{ |
|
{ |
{ |
|
unsigned long number = 0; |
char *pos = (char *) str; |
char *fail_char = (char *) str; |
unsigned long number = 0; |
char *pos = (char *)str; |
char *fail_char = (char *)str; |
|
while (isspace(*pos)) |
pos++; /* skip leading whitespace */ |
|
while (isspace(*pos)) pos++; /* skip leading whitespace */ |
if ((base == 16) && (*pos == '0')) { /* handle option prefix */ |
++pos; |
fail_char = pos; |
if ((*pos == 'x') || (*pos == 'X')) |
++pos; |
} |
|
if ((base == 16) && (*pos == '0')) { /* handle option prefix */ |
++pos; |
fail_char = pos; |
if ((*pos == 'x') || (*pos == 'X')) ++pos; |
} |
if (base == 0) { /* dynamic base */ |
base = 10; /* default is 10 */ |
if (*pos == '0') { |
++pos; |
base -= 2; /* now base is 8 (or 16) */ |
fail_char = pos; |
if ((*pos == 'x') || (*pos == 'X')) { |
base += 8; /* base is 16 */ |
++pos; |
} |
} |
} |
|
if (base == 0) { /* dynamic base */ |
base = 10; /* default is 10 */ |
if (*pos == '0') { |
++pos; |
base -= 2; /* now base is 8 (or 16) */ |
fail_char = pos; |
if ((*pos == 'x') || (*pos == 'X')) { |
base += 8; /* base is 16 */ |
++pos; |
} |
} |
} |
/* check for illegal base */ |
if (!((base < 2) || (base > 36))) |
while (1) { |
int digit = 40; |
if ((*pos >= '0') && (*pos <= '9')) { |
digit = (*pos - '0'); |
} else if (*pos >= 'a') { |
digit = (*pos - 'a' + 10); |
} else if (*pos >= 'A') { |
digit = (*pos - 'A' + 10); |
} else |
break; |
|
/* check for illegal base */ |
if ( !((base < 2) || (base > 36)) ) |
while (1) { |
int digit = 40; |
if ((*pos >= '0') && (*pos <= '9')) { |
digit = (*pos - '0'); |
} else if (*pos >= 'a') { |
digit = (*pos - 'a' + 10); |
} else if (*pos >= 'A') { |
digit = (*pos - 'A' + 10); |
} else break; |
if (digit >= base) |
break; |
|
if (digit >= base) break; |
fail_char = ++pos; |
number = number * base + digit; |
} |
|
fail_char = ++pos; |
number = number * base + digit; |
} |
if (endptr) |
*endptr = fail_char; { |
return number; |
} |
} |
} |
|
if (endptr) *endptr = fail_char; { |
return number; |
} |
} |
} |
|
unsigned long get_timer (unsigned long base) |
unsigned long get_timer(unsigned long base) |
{ |
/* |
__printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__); |
__printf(" timestamp = %.8lx base = %.8lx\n", timestamp, base); |
*/ |
return (timestamp - base); |
/* |
__printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__); |
__printf(" timestamp = %.8lx base = %.8lx\n", timestamp, base); |
*/ |
return (timestamp - base); |
} |
|
void set_timer (unsigned long t) |
|
void set_timer(unsigned long t) |
{ |
timestamp = t; |
timestamp = t; |
} |
|
/orpmon/coremark/core_portme.c
35,7 → 35,7
volatile ee_s32 seed1_volatile; |
volatile ee_s32 seed2_volatile; |
volatile ee_s32 seed3_volatile; |
volatile ee_s32 seed4_volatile = 0; // Iterations defaults to 0 |
volatile ee_s32 seed4_volatile = 0; // Iterations defaults to 0 |
volatile ee_s32 seed5_volatile = 0; |
|
/* Porting : Timing functions |
47,7 → 47,7
CORETIMETYPE barebones_clock() |
{ |
//#error "You must implement a method to measure time in |
//barebones_clock()! This function should return current time.\n" |
//barebones_clock()! This function should return current time.\n" |
return timestamp; |
} |
|
131,60 → 131,58
void portable_init(core_portable * p, int *argc, char *argv[]) |
{ |
|
// In ORPmon - UART already initialised: uart_init(DEFAULT_UART); |
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) { |
ee_printf |
("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n"); |
while (1) ; // FINISH |
} |
if (sizeof(ee_u32) != 4) { |
ee_printf |
("ERROR! Please define ee_u32 to a 32b unsigned type!\n"); |
while (1) ; // FINISH |
} |
// In ORPmon - things already initialised |
// Clear timer variable |
//clear_timer_ticks(); |
// init timer |
//enable_timer(); |
|
// |
// In ORPmon - UART already initialised: uart_init(DEFAULT_UART); |
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) { |
ee_printf |
("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n"); |
while (1) ; // FINISH |
} |
if (sizeof(ee_u32) != 4) { |
ee_printf |
("ERROR! Please define ee_u32 to a 32b unsigned type!\n"); |
while (1) ; // FINISH |
} |
// In ORPmon - things already initialised |
// Clear timer variable |
//clear_timer_ticks(); |
// init timer |
//enable_timer(); |
|
// Parse argv and figure out what kind of run we do |
if (argc > 0) |
{ |
switch((char) argv[0][0]) |
{ |
case 'p': |
//PERFORMANCE_RUN |
seed1_volatile = 0x0; |
seed2_volatile = 0x0; |
seed3_volatile = 0x66; |
break; |
case 'o': |
//PROFILE_RUN |
seed1_volatile = 0x8; |
seed2_volatile = 0x8; |
seed3_volatile = 0x8; |
break; |
default: |
//VALIDATION_RUN |
seed1_volatile = 0x3415; |
seed2_volatile = 0x3415; |
seed3_volatile = 0x66; |
break; |
// |
|
// Parse argv and figure out what kind of run we do |
if (argc > 0) { |
switch ((char)argv[0][0]) { |
case 'p': |
//PERFORMANCE_RUN |
seed1_volatile = 0x0; |
seed2_volatile = 0x0; |
seed3_volatile = 0x66; |
break; |
case 'o': |
//PROFILE_RUN |
seed1_volatile = 0x8; |
seed2_volatile = 0x8; |
seed3_volatile = 0x8; |
break; |
default: |
//VALIDATION_RUN |
seed1_volatile = 0x3415; |
seed2_volatile = 0x3415; |
seed3_volatile = 0x66; |
break; |
} |
} |
} |
|
if (argc > 1) |
seed4_volatile = strtoul(argv[1],0,0); // Iterations as second argument |
else |
seed4_volatile = 0; // Zero (test runs a minimum amount of time) |
|
seed5_volatile = 0; |
|
p->portable_id = 1; |
|
if (argc > 1) |
seed4_volatile = strtoul(argv[1], 0, 0); // Iterations as second argument |
else |
seed4_volatile = 0; // Zero (test runs a minimum amount of time) |
|
seed5_volatile = 0; |
|
p->portable_id = 1; |
|
} |
|
/* Function : portable_fini |
/orpmon/coremark/core_list_join.c
15,7 → 15,7
EEMBC |
4354 Town Center Blvd. Suite 114-200 |
El Dorado Hills, CA, 95762 |
*/ |
*/ |
|
#include "coremark.h" |
/* |
50,57 → 50,67
|
/* local functions */ |
|
list_head *core_list_find(list_head *list,list_data *info); |
list_head *core_list_reverse(list_head *list); |
list_head *core_list_remove(list_head *item); |
list_head *core_list_undo_remove(list_head *item_removed, list_head *item_modified); |
list_head *core_list_insert_new(list_head *insert_point |
, list_data *info, list_head **memblock, list_data **datablock |
, list_head *memblock_end, list_data *datablock_end); |
typedef ee_s32(*list_cmp)(list_data *a, list_data *b, core_results *res); |
list_head *core_list_mergesort(list_head *list, list_cmp cmp, core_results *res); |
list_head *core_list_find(list_head * list, list_data * info); |
list_head *core_list_reverse(list_head * list); |
list_head *core_list_remove(list_head * item); |
list_head *core_list_undo_remove(list_head * item_removed, |
list_head * item_modified); |
list_head *core_list_insert_new(list_head * insert_point, list_data * info, |
list_head ** memblock, list_data ** datablock, |
list_head * memblock_end, |
list_data * datablock_end); |
typedef ee_s32(*list_cmp) (list_data * a, list_data * b, core_results * res); |
list_head *core_list_mergesort(list_head * list, list_cmp cmp, |
core_results * res); |
|
ee_s16 calc_func(ee_s16 *pdata, core_results *res) { |
ee_s16 data=*pdata; |
ee_s16 calc_func(ee_s16 * pdata, core_results * res) |
{ |
ee_s16 data = *pdata; |
ee_s16 retval; |
ee_u8 optype=(data>>7) & 1; /* bit 7 indicates if the function result has been cached */ |
if (optype) /* if cached, use cache */ |
ee_u8 optype = (data >> 7) & 1; /* bit 7 indicates if the function result has been cached */ |
if (optype) /* if cached, use cache */ |
return (data & 0x007f); |
else { /* otherwise calculate and cache the result */ |
ee_s16 flag=data & 0x7; /* bits 0-2 is type of function to perform */ |
ee_s16 dtype=((data>>3) & 0xf); /* bits 3-6 is specific data for the operation */ |
dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */ |
else { /* otherwise calculate and cache the result */ |
ee_s16 flag = data & 0x7; /* bits 0-2 is type of function to perform */ |
ee_s16 dtype = ((data >> 3) & 0xf); /* bits 3-6 is specific data for the operation */ |
dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */ |
switch (flag) { |
case 0: |
if (dtype<0x22) /* set min period for bit corruption */ |
dtype=0x22; |
retval=core_bench_state(res->size,res->memblock[3],res->seed1,res->seed2,dtype,res->crc); |
if (res->crcstate==0) |
res->crcstate=retval; |
break; |
case 1: |
retval=core_bench_matrix(&(res->mat),dtype,res->crc); |
if (res->crcmatrix==0) |
res->crcmatrix=retval; |
break; |
default: |
retval=data; |
break; |
case 0: |
if (dtype < 0x22) /* set min period for bit corruption */ |
dtype = 0x22; |
retval = |
core_bench_state(res->size, res->memblock[3], |
res->seed1, res->seed2, dtype, |
res->crc); |
if (res->crcstate == 0) |
res->crcstate = retval; |
break; |
case 1: |
retval = |
core_bench_matrix(&(res->mat), dtype, res->crc); |
if (res->crcmatrix == 0) |
res->crcmatrix = retval; |
break; |
default: |
retval = data; |
break; |
} |
res->crc=crcu16(retval,res->crc); |
retval &= 0x007f; |
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */ |
res->crc = crcu16(retval, res->crc); |
retval &= 0x007f; |
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */ |
return retval; |
} |
} |
|
/* Function: cmp_complex |
Compare the data item in a list cell. |
|
Can be used by mergesort. |
*/ |
ee_s32 cmp_complex(list_data *a, list_data *b, core_results *res) { |
ee_s16 val1=calc_func(&(a->data16),res); |
ee_s16 val2=calc_func(&(b->data16),res); |
ee_s32 cmp_complex(list_data * a, list_data * b, core_results * res) |
{ |
ee_s16 val1 = calc_func(&(a->data16), res); |
ee_s16 val2 = calc_func(&(b->data16), res); |
return val1 - val2; |
} |
|
109,17 → 119,19
|
Can be used by mergesort. |
*/ |
ee_s32 cmp_idx(list_data *a, list_data *b, core_results *res) { |
if (res==NULL) { |
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16>>8)); |
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16>>8)); |
ee_s32 cmp_idx(list_data * a, list_data * b, core_results * res) |
{ |
if (res == NULL) { |
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16 >> 8)); |
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16 >> 8)); |
} |
return a->idx - b->idx; |
} |
|
void copy_info(list_data *to,list_data *from) { |
to->data16=from->data16; |
to->idx=from->idx; |
void copy_info(list_data * to, list_data * from) |
{ |
to->data16 = from->data16; |
to->idx = from->idx; |
} |
|
/* Benchmark for linked list: |
129,74 → 141,76
- Single remove/reinsert |
* At the end of this function, the list is back to original state |
*/ |
ee_u16 core_bench_list(core_results *res, ee_s16 finder_idx) { |
ee_u16 retval=0; |
ee_u16 found=0,missed=0; |
list_head *list=res->list; |
ee_s16 find_num=res->seed3; |
ee_u16 core_bench_list(core_results * res, ee_s16 finder_idx) |
{ |
ee_u16 retval = 0; |
ee_u16 found = 0, missed = 0; |
list_head *list = res->list; |
ee_s16 find_num = res->seed3; |
list_head *this_find; |
list_head *finder, *remover; |
list_data info; |
ee_s16 i; |
|
info.idx=finder_idx; |
info.idx = finder_idx; |
/* find <find_num> values in the list, and change the list each time (reverse and cache if value found) */ |
for (i=0; i<find_num; i++) { |
info.data16= (i & 0xff) ; |
this_find=core_list_find(list,&info); |
list=core_list_reverse(list); |
if (this_find==NULL) { |
for (i = 0; i < find_num; i++) { |
info.data16 = (i & 0xff); |
this_find = core_list_find(list, &info); |
list = core_list_reverse(list); |
if (this_find == NULL) { |
missed++; |
retval+=(list->next->info->data16 >> 8) & 1; |
} |
else { |
retval += (list->next->info->data16 >> 8) & 1; |
} else { |
found++; |
if (this_find->info->data16 & 0x1) /* use found value */ |
retval+=(this_find->info->data16 >> 9) & 1; |
if (this_find->info->data16 & 0x1) /* use found value */ |
retval += (this_find->info->data16 >> 9) & 1; |
/* and cache next item at the head of the list (if any) */ |
if (this_find->next != NULL) { |
finder = this_find->next; |
this_find->next = finder->next; |
finder->next=list->next; |
list->next=finder; |
finder->next = list->next; |
list->next = finder; |
} |
} |
if (info.idx>=0) |
if (info.idx >= 0) |
info.idx++; |
#if CORE_DEBUG |
ee_printf("List find %d: [%d,%d,%d]\n",i,retval,missed,found); |
ee_printf("List find %d: [%d,%d,%d]\n", i, retval, missed, |
found); |
#endif |
} |
retval+=found*4-missed; |
/* sort the list by data content and remove one item*/ |
if (finder_idx>0) |
list=core_list_mergesort(list,cmp_complex,res); |
remover=core_list_remove(list->next); |
retval += found * 4 - missed; |
/* sort the list by data content and remove one item */ |
if (finder_idx > 0) |
list = core_list_mergesort(list, cmp_complex, res); |
remover = core_list_remove(list->next); |
/* CRC data content of list from location of index N forward, and then undo remove */ |
finder=core_list_find(list,&info); |
finder = core_list_find(list, &info); |
if (!finder) |
finder=list->next; |
finder = list->next; |
while (finder) { |
retval=crc16(list->info->data16,retval); |
finder=finder->next; |
retval = crc16(list->info->data16, retval); |
finder = finder->next; |
} |
#if CORE_DEBUG |
ee_printf("List sort 1: %04x\n",retval); |
ee_printf("List sort 1: %04x\n", retval); |
#endif |
remover=core_list_undo_remove(remover,list->next); |
remover = core_list_undo_remove(remover, list->next); |
/* sort the list by index, in effect returning the list to original state */ |
list=core_list_mergesort(list,cmp_idx,NULL); |
list = core_list_mergesort(list, cmp_idx, NULL); |
/* CRC data content of list */ |
finder=list->next; |
finder = list->next; |
while (finder) { |
retval=crc16(list->info->data16,retval); |
finder=finder->next; |
retval = crc16(list->info->data16, retval); |
finder = finder->next; |
} |
#if CORE_DEBUG |
ee_printf("List sort 2: %04x\n",retval); |
ee_printf("List sort 2: %04x\n", retval); |
#endif |
return retval; |
} |
|
/* Function: core_list_init |
Initialize list with data. |
|
210,55 → 224,59
Pointer to the head of the list. |
|
*/ |
list_head *core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed) { |
list_head *core_list_init(ee_u32 blksize, list_head * memblock, ee_s16 seed) |
{ |
/* calculated pointers for the list */ |
ee_u32 per_item=16+sizeof(struct list_data_s); |
ee_u32 size=(blksize/per_item)-2; /* to accomodate systems with 64b pointers, and make sure same code is executed, set max list elements */ |
list_head *memblock_end=memblock+size; |
list_data *datablock=(list_data *)(memblock_end); |
list_data *datablock_end=datablock+size; |
ee_u32 per_item = 16 + sizeof(struct list_data_s); |
ee_u32 size = (blksize / per_item) - 2; /* to accomodate systems with 64b pointers, and make sure same code is executed, set max list elements */ |
list_head *memblock_end = memblock + size; |
list_data *datablock = (list_data *) (memblock_end); |
list_data *datablock_end = datablock + size; |
/* some useful variables */ |
ee_u32 i; |
list_head *finder,*list=memblock; |
list_head *finder, *list = memblock; |
list_data info; |
|
/* create a fake items for the list head and tail */ |
list->next=NULL; |
list->info=datablock; |
list->info->idx=0x0000; |
list->info->data16=(ee_s16)0x8080; |
list->next = NULL; |
list->info = datablock; |
list->info->idx = 0x0000; |
list->info->data16 = (ee_s16) 0x8080; |
memblock++; |
datablock++; |
info.idx=0x7fff; |
info.data16=(ee_s16)0xffff; |
core_list_insert_new(list,&info,&memblock,&datablock,memblock_end,datablock_end); |
|
info.idx = 0x7fff; |
info.data16 = (ee_s16) 0xffff; |
core_list_insert_new(list, &info, &memblock, &datablock, memblock_end, |
datablock_end); |
|
/* then insert size items */ |
for (i=0; i<size; i++) { |
ee_u16 datpat=((ee_u16)(seed^i) & 0xf); |
ee_u16 dat=(datpat<<3) | (i&0x7); /* alternate between algorithms */ |
info.data16=(dat<<8) | dat; /* fill the data with actual data and upper bits with rebuild value */ |
core_list_insert_new(list,&info,&memblock,&datablock,memblock_end,datablock_end); |
for (i = 0; i < size; i++) { |
ee_u16 datpat = ((ee_u16) (seed ^ i) & 0xf); |
ee_u16 dat = (datpat << 3) | (i & 0x7); /* alternate between algorithms */ |
info.data16 = (dat << 8) | dat; /* fill the data with actual data and upper bits with rebuild value */ |
core_list_insert_new(list, &info, &memblock, &datablock, |
memblock_end, datablock_end); |
} |
/* and now index the list so we know initial seed order of the list */ |
finder=list->next; |
i=1; |
while (finder->next!=NULL) { |
if (i<size/5) /* first 20% of the list in order */ |
finder->info->idx=i++; |
else { |
ee_u16 pat=(ee_u16)(i++ ^ seed); /* get a pseudo random number */ |
finder->info->idx=0x3fff & (((i & 0x07) << 8) | pat); /* make sure the mixed items end up after the ones in sequence */ |
finder = list->next; |
i = 1; |
while (finder->next != NULL) { |
if (i < size / 5) /* first 20% of the list in order */ |
finder->info->idx = i++; |
else { |
ee_u16 pat = (ee_u16) (i++ ^ seed); /* get a pseudo random number */ |
finder->info->idx = 0x3fff & (((i & 0x07) << 8) | pat); /* make sure the mixed items end up after the ones in sequence */ |
} |
finder=finder->next; |
finder = finder->next; |
} |
list = core_list_mergesort(list,cmp_idx,NULL); |
list = core_list_mergesort(list, cmp_idx, NULL); |
#if CORE_DEBUG |
ee_printf("Initialized list:\n"); |
finder=list; |
finder = list; |
while (finder) { |
ee_printf("[%04x,%04x]",finder->info->idx,(ee_u16)finder->info->data16); |
finder=finder->next; |
ee_printf("[%04x,%04x]", finder->info->idx, |
(ee_u16) finder->info->data16); |
finder = finder->next; |
} |
ee_printf("\n"); |
#endif |
279,24 → 297,27
Returns: |
Pointer to new item. |
*/ |
list_head *core_list_insert_new(list_head *insert_point, list_data *info, list_head **memblock, list_data **datablock |
, list_head *memblock_end, list_data *datablock_end) { |
list_head *core_list_insert_new(list_head * insert_point, list_data * info, |
list_head ** memblock, list_data ** datablock, |
list_head * memblock_end, |
list_data * datablock_end) |
{ |
list_head *newitem; |
|
if ((*memblock+1) >= memblock_end) |
|
if ((*memblock + 1) >= memblock_end) |
return NULL; |
if ((*datablock+1) >= datablock_end) |
if ((*datablock + 1) >= datablock_end) |
return NULL; |
|
newitem=*memblock; |
|
newitem = *memblock; |
(*memblock)++; |
newitem->next=insert_point->next; |
insert_point->next=newitem; |
|
newitem->info=*datablock; |
newitem->next = insert_point->next; |
insert_point->next = newitem; |
|
newitem->info = *datablock; |
(*datablock)++; |
copy_info(newitem->info,info); |
|
copy_info(newitem->info, info); |
|
return newitem; |
} |
|
313,16 → 334,17
Returns: |
Removed item. |
*/ |
list_head *core_list_remove(list_head *item) { |
list_head *core_list_remove(list_head * item) |
{ |
list_data *tmp; |
list_head *ret=item->next; |
list_head *ret = item->next; |
/* swap data pointers */ |
tmp=item->info; |
item->info=ret->info; |
ret->info=tmp; |
tmp = item->info; |
item->info = ret->info; |
ret->info = tmp; |
/* and eliminate item */ |
item->next=item->next->next; |
ret->next=NULL; |
item->next = item->next->next; |
ret->next = NULL; |
return ret; |
} |
|
342,15 → 364,17
The item that was linked back to the list. |
|
*/ |
list_head *core_list_undo_remove(list_head *item_removed, list_head *item_modified) { |
list_head *core_list_undo_remove(list_head * item_removed, |
list_head * item_modified) |
{ |
list_data *tmp; |
/* swap data pointers */ |
tmp=item_removed->info; |
item_removed->info=item_modified->info; |
item_modified->info=tmp; |
tmp = item_removed->info; |
item_removed->info = item_modified->info; |
item_modified->info = tmp; |
/* and insert item */ |
item_removed->next=item_modified->next; |
item_modified->next=item_removed; |
item_removed->next = item_modified->next; |
item_modified->next = item_removed; |
return item_removed; |
} |
|
367,17 → 391,19
Returns: |
Found item, or NULL if not found. |
*/ |
list_head *core_list_find(list_head *list,list_data *info) { |
if (info->idx>=0) { |
list_head *core_list_find(list_head * list, list_data * info) |
{ |
if (info->idx >= 0) { |
while (list && (list->info->idx != info->idx)) |
list=list->next; |
list = list->next; |
return list; |
} else { |
while (list && ((list->info->data16 & 0xff) != info->data16)) |
list=list->next; |
list = list->next; |
return list; |
} |
} |
|
/* Function: core_list_reverse |
Reverse a list |
|
392,16 → 418,18
Found item, or NULL if not found. |
*/ |
|
list_head *core_list_reverse(list_head *list) { |
list_head *next=NULL, *tmp; |
list_head *core_list_reverse(list_head * list) |
{ |
list_head *next = NULL, *tmp; |
while (list) { |
tmp=list->next; |
list->next=next; |
next=list; |
list=tmp; |
tmp = list->next; |
list->next = next; |
next = list; |
list = tmp; |
} |
return next; |
} |
|
/* Function: core_list_mergesort |
Sort the list in place without recursion. |
|
423,73 → 451,84
but the algorithm could theoretically modify where the list starts. |
|
*/ |
list_head *core_list_mergesort(list_head *list, list_cmp cmp, core_results *res) { |
list_head *p, *q, *e, *tail; |
ee_s32 insize, nmerges, psize, qsize, i; |
list_head *core_list_mergesort(list_head * list, list_cmp cmp, |
core_results * res) |
{ |
list_head *p, *q, *e, *tail; |
ee_s32 insize, nmerges, psize, qsize, i; |
|
insize = 1; |
insize = 1; |
|
while (1) { |
p = list; |
list = NULL; |
tail = NULL; |
while (1) { |
p = list; |
list = NULL; |
tail = NULL; |
|
nmerges = 0; /* count number of merges we do in this pass */ |
nmerges = 0; /* count number of merges we do in this pass */ |
|
while (p) { |
nmerges++; /* there exists a merge to be done */ |
/* step `insize' places along from p */ |
q = p; |
psize = 0; |
for (i = 0; i < insize; i++) { |
psize++; |
q = q->next; |
if (!q) break; |
} |
while (p) { |
nmerges++; /* there exists a merge to be done */ |
/* step `insize' places along from p */ |
q = p; |
psize = 0; |
for (i = 0; i < insize; i++) { |
psize++; |
q = q->next; |
if (!q) |
break; |
} |
|
/* if q hasn't fallen off end, we have two lists to merge */ |
qsize = insize; |
/* if q hasn't fallen off end, we have two lists to merge */ |
qsize = insize; |
|
/* now we have two lists; merge them */ |
while (psize > 0 || (qsize > 0 && q)) { |
/* now we have two lists; merge them */ |
while (psize > 0 || (qsize > 0 && q)) { |
|
/* decide whether next element of merge comes from p or q */ |
if (psize == 0) { |
/* p is empty; e must come from q. */ |
e = q; q = q->next; qsize--; |
/* p is empty; e must come from q. */ |
e = q; |
q = q->next; |
qsize--; |
} else if (qsize == 0 || !q) { |
/* q is empty; e must come from p. */ |
e = p; p = p->next; psize--; |
} else if (cmp(p->info,q->info,res) <= 0) { |
/* First element of p is lower (or same); e must come from p. */ |
e = p; p = p->next; psize--; |
/* q is empty; e must come from p. */ |
e = p; |
p = p->next; |
psize--; |
} else if (cmp(p->info, q->info, res) <= 0) { |
/* First element of p is lower (or same); e must come from p. */ |
e = p; |
p = p->next; |
psize--; |
} else { |
/* First element of q is lower; e must come from q. */ |
e = q; q = q->next; qsize--; |
/* First element of q is lower; e must come from q. */ |
e = q; |
q = q->next; |
qsize--; |
} |
|
/* add the next element to the merged list */ |
/* add the next element to the merged list */ |
if (tail) { |
tail->next = e; |
tail->next = e; |
} else { |
list = e; |
list = e; |
} |
tail = e; |
} |
} |
|
/* now p has stepped `insize' places along, and q has too */ |
p = q; |
} |
|
tail->next = NULL; |
} |
|
/* If we have done only one merge, we're finished. */ |
if (nmerges <= 1) /* allow for nmerges==0, the empty list case */ |
return list; |
tail->next = NULL; |
|
/* Otherwise repeat, merging lists twice the size */ |
insize *= 2; |
} |
/* If we have done only one merge, we're finished. */ |
if (nmerges <= 1) /* allow for nmerges==0, the empty list case */ |
return list; |
|
/* Otherwise repeat, merging lists twice the size */ |
insize *= 2; |
} |
#if COMPILER_REQUIRES_SORT_RETURN |
return list; |
#endif |
/orpmon/coremark/core_util.c
15,7 → 15,7
EEMBC |
4354 Town Center Blvd. Suite 114-200 |
El Dorado Hills, CA, 95762 |
*/ |
*/ |
#include "coremark.h" |
/* Function: get_seed |
Get a values that cannot be determined at compile time. |
31,78 → 31,82
e.g. read the value on GPIO pins connected to switches, or invoke special simulator functions. |
*/ |
#if (SEED_METHOD==SEED_VOLATILE) |
extern volatile ee_s32 seed1_volatile; |
extern volatile ee_s32 seed2_volatile; |
extern volatile ee_s32 seed3_volatile; |
extern volatile ee_s32 seed4_volatile; |
extern volatile ee_s32 seed5_volatile; |
ee_s32 get_seed_32(int i) { |
ee_s32 retval; |
switch (i) { |
case 1: |
retval=seed1_volatile; |
break; |
case 2: |
retval=seed2_volatile; |
break; |
case 3: |
retval=seed3_volatile; |
break; |
case 4: |
retval=seed4_volatile; |
break; |
case 5: |
retval=seed5_volatile; |
break; |
default: |
retval=0; |
break; |
} |
return retval; |
extern volatile ee_s32 seed1_volatile; |
extern volatile ee_s32 seed2_volatile; |
extern volatile ee_s32 seed3_volatile; |
extern volatile ee_s32 seed4_volatile; |
extern volatile ee_s32 seed5_volatile; |
ee_s32 get_seed_32(int i) |
{ |
ee_s32 retval; |
switch (i) { |
case 1: |
retval = seed1_volatile; |
break; |
case 2: |
retval = seed2_volatile; |
break; |
case 3: |
retval = seed3_volatile; |
break; |
case 4: |
retval = seed4_volatile; |
break; |
case 5: |
retval = seed5_volatile; |
break; |
default: |
retval = 0; |
break; |
} |
return retval; |
} |
#elif (SEED_METHOD==SEED_ARG) |
ee_s32 parseval(char *valstring) { |
ee_s32 retval=0; |
ee_s32 neg=1; |
int hexmode=0; |
ee_s32 parseval(char *valstring) |
{ |
ee_s32 retval = 0; |
ee_s32 neg = 1; |
int hexmode = 0; |
if (*valstring == '-') { |
neg=-1; |
neg = -1; |
valstring++; |
} |
if ((valstring[0] == '0') && (valstring[1] == 'x')) { |
hexmode=1; |
valstring+=2; |
hexmode = 1; |
valstring += 2; |
} |
/* first look for digits */ |
/* first look for digits */ |
if (hexmode) { |
while (((*valstring >= '0') && (*valstring <= '9')) || ((*valstring >= 'a') && (*valstring <= 'f'))) { |
ee_s32 digit=*valstring-'0'; |
if (digit>9) |
digit=10+*valstring-'a'; |
retval*=16; |
retval+=digit; |
while (((*valstring >= '0') && (*valstring <= '9')) |
|| ((*valstring >= 'a') && (*valstring <= 'f'))) { |
ee_s32 digit = *valstring - '0'; |
if (digit > 9) |
digit = 10 + *valstring - 'a'; |
retval *= 16; |
retval += digit; |
valstring++; |
} |
} else { |
while ((*valstring >= '0') && (*valstring <= '9')) { |
ee_s32 digit=*valstring-'0'; |
retval*=10; |
retval+=digit; |
ee_s32 digit = *valstring - '0'; |
retval *= 10; |
retval += digit; |
valstring++; |
} |
} |
/* now add qualifiers */ |
if (*valstring=='K') |
retval*=1024; |
if (*valstring=='M') |
retval*=1024*1024; |
if (*valstring == 'K') |
retval *= 1024; |
if (*valstring == 'M') |
retval *= 1024 * 1024; |
|
retval*=neg; |
retval *= neg; |
return retval; |
} |
|
ee_s32 get_seed_args(int i, int argc, char *argv[]) { |
if (argc>i) |
ee_s32 get_seed_args(int i, int argc, char *argv[]) |
{ |
if (argc > i) |
return parseval(argv[i]); |
return 0; |
} |
109,27 → 113,28
|
#elif (SEED_METHOD==SEED_FUNC) |
/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */ |
ee_s32 get_seed_32(int i) { |
ee_s32 get_seed_32(int i) |
{ |
ee_s32 retval; |
switch (i) { |
case 1: |
retval=portme_sys1(); |
break; |
case 2: |
retval=portme_sys2(); |
break; |
case 3: |
retval=portme_sys3(); |
break; |
case 4: |
retval=portme_sys4(); |
break; |
case 5: |
retval=portme_sys5(); |
break; |
default: |
retval=0; |
break; |
case 1: |
retval = portme_sys1(); |
break; |
case 2: |
retval = portme_sys2(); |
break; |
case 3: |
retval = portme_sys3(); |
break; |
case 4: |
retval = portme_sys4(); |
break; |
case 5: |
retval = portme_sys5(); |
break; |
default: |
retval = 0; |
break; |
} |
return retval; |
} |
139,46 → 144,50
Service functions to calculate 16b CRC code. |
|
*/ |
ee_u16 crcu8(ee_u8 data, ee_u16 crc ) |
ee_u16 crcu8(ee_u8 data, ee_u16 crc) |
{ |
ee_u8 i=0,x16=0,carry=0; |
ee_u8 i = 0, x16 = 0, carry = 0; |
|
for (i = 0; i < 8; i++) |
{ |
x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1)); |
for (i = 0; i < 8; i++) { |
x16 = (ee_u8) ((data & 1) ^ ((ee_u8) crc & 1)); |
data >>= 1; |
|
if (x16 == 1) |
{ |
crc ^= 0x4002; |
carry = 1; |
} |
else |
if (x16 == 1) { |
crc ^= 0x4002; |
carry = 1; |
} else |
carry = 0; |
crc >>= 1; |
if (carry) |
crc |= 0x8000; |
crc |= 0x8000; |
else |
crc &= 0x7fff; |
} |
crc &= 0x7fff; |
} |
return crc; |
} |
ee_u16 crcu16(ee_u16 newval, ee_u16 crc) { |
crc=crcu8( (ee_u8) (newval) ,crc); |
crc=crcu8( (ee_u8) ((newval)>>8) ,crc); |
} |
|
ee_u16 crcu16(ee_u16 newval, ee_u16 crc) |
{ |
crc = crcu8((ee_u8) (newval), crc); |
crc = crcu8((ee_u8) ((newval) >> 8), crc); |
return crc; |
} |
ee_u16 crcu32(ee_u32 newval, ee_u16 crc) { |
crc=crc16((ee_s16) newval ,crc); |
crc=crc16((ee_s16) (newval>>16) ,crc); |
|
ee_u16 crcu32(ee_u32 newval, ee_u16 crc) |
{ |
crc = crc16((ee_s16) newval, crc); |
crc = crc16((ee_s16) (newval >> 16), crc); |
return crc; |
} |
ee_u16 crc16(ee_s16 newval, ee_u16 crc) { |
return crcu16((ee_u16)newval, crc); |
|
ee_u16 crc16(ee_s16 newval, ee_u16 crc) |
{ |
return crcu16((ee_u16) newval, crc); |
} |
|
ee_u8 check_data_types() { |
ee_u8 retval=0; |
ee_u8 check_data_types() |
{ |
ee_u8 retval = 0; |
if (sizeof(ee_u8) != 1) { |
ee_printf("ERROR: ee_u8 is not an 8b datatype!\n"); |
retval++; |
200,11 → 209,13
retval++; |
} |
if (sizeof(ee_ptr_int) != sizeof(int *)) { |
ee_printf("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n"); |
ee_printf |
("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n"); |
retval++; |
} |
if (retval>0) { |
ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n"); |
if (retval > 0) { |
ee_printf |
("ERROR: Please modify the datatypes in core_portme.h!\n"); |
} |
return retval; |
} |
/orpmon/coremark/fmod.c
3,17 → 3,14
typedef signed int int32_t; |
|
// Big endian struct... |
typedef union |
{ |
double value; |
struct |
{ |
u_int32_t msw; |
u_int32_t lsw; |
} parts; |
typedef union { |
double value; |
struct { |
u_int32_t msw; |
u_int32_t lsw; |
} parts; |
} ieee_double_shape_type; |
|
|
/* |
typedef union |
{ |
87,10 → 84,9
/* A union which permits us to convert between a float and a 32 bit |
int. */ |
|
typedef union |
{ |
float value; |
u_int32_t word; |
typedef union { |
float value; |
u_int32_t word; |
} ieee_float_shape_type; |
|
/* Get a 32 bit int from a float. */ |
111,49 → 107,48
(d) = sf_u.value; \ |
} while (0) |
|
|
static const double one = 1.0; |
|
double modf(double x, double *iptr) |
{ |
int32_t i0,i1,j0; |
int32_t i0, i1, j0; |
u_int32_t i; |
EXTRACT_WORDS(i0,i1,x); |
j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ |
if(j0<20) { /* integer part in high x */ |
if(j0<0) { /* |x|<1 */ |
INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ |
EXTRACT_WORDS(i0, i1, x); |
j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */ |
if (j0 < 20) { /* integer part in high x */ |
if (j0 < 0) { /* |x|<1 */ |
INSERT_WORDS(*iptr, i0 & 0x80000000, 0); /* *iptr = +-0 */ |
return x; |
} else { |
i = (0x000fffff) >> j0; |
if (((i0 & i) | i1) == 0) { /* x is integral */ |
u_int32_t high; |
*iptr = x; |
GET_HIGH_WORD(high, x); |
INSERT_WORDS(x, high & 0x80000000, 0); /* return +-0 */ |
return x; |
} else { |
INSERT_WORDS(*iptr, i0 & (~i), 0); |
return x - *iptr; |
} |
} |
} else if (j0 > 51) { /* no fraction part */ |
u_int32_t high; |
*iptr = x * one; |
GET_HIGH_WORD(high, x); |
INSERT_WORDS(x, high & 0x80000000, 0); /* return +-0 */ |
return x; |
} else { |
i = (0x000fffff)>>j0; |
if(((i0&i)|i1)==0) { /* x is integral */ |
u_int32_t high; |
*iptr = x; |
GET_HIGH_WORD(high,x); |
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ |
return x; |
} else { /* fraction part in low x */ |
i = ((u_int32_t) (0xffffffff)) >> (j0 - 20); |
if ((i1 & i) == 0) { /* x is integral */ |
u_int32_t high; |
*iptr = x; |
GET_HIGH_WORD(high, x); |
INSERT_WORDS(x, high & 0x80000000, 0); /* return +-0 */ |
return x; |
} else { |
INSERT_WORDS(*iptr,i0&(~i),0); |
return x - *iptr; |
INSERT_WORDS(*iptr, i0, i1 & (~i)); |
return x - *iptr; |
} |
} |
} else if (j0>51) { /* no fraction part */ |
u_int32_t high; |
*iptr = x*one; |
GET_HIGH_WORD(high,x); |
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ |
return x; |
} else { /* fraction part in low x */ |
i = ((u_int32_t)(0xffffffff))>>(j0-20); |
if((i1&i)==0) { /* x is integral */ |
u_int32_t high; |
*iptr = x; |
GET_HIGH_WORD(high,x); |
INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ |
return x; |
} else { |
INSERT_WORDS(*iptr,i0,i1&(~i)); |
return x - *iptr; |
} |
} |
} |
/orpmon/coremark/core_state.c
15,10 → 15,11
EEMBC |
4354 Town Center Blvd. Suite 114-200 |
El Dorado Hills, CA, 95762 |
*/ |
*/ |
#include "coremark.h" |
/* local functions */ |
enum CORE_STATE core_state_transition( ee_u8 **instr , ee_u32 *transition_count); |
enum CORE_STATE core_state_transition(ee_u8 ** instr, |
ee_u32 * transition_count); |
|
/* |
Topic: Description |
40,69 → 41,77
|
Go over the input twice, once direct, and once after introducing some corruption. |
*/ |
ee_u16 core_bench_state(ee_u32 blksize, ee_u8 *memblock, |
ee_s16 seed1, ee_s16 seed2, ee_s16 step, ee_u16 crc) |
ee_u16 core_bench_state(ee_u32 blksize, ee_u8 * memblock, |
ee_s16 seed1, ee_s16 seed2, ee_s16 step, ee_u16 crc) |
{ |
ee_u32 final_counts[NUM_CORE_STATES]; |
ee_u32 track_counts[NUM_CORE_STATES]; |
ee_u8 *p=memblock; |
ee_u8 *p = memblock; |
ee_u32 i; |
|
|
#if CORE_DEBUG |
ee_printf("State Bench: %d,%d,%d,%04x\n",seed1,seed2,step,crc); |
ee_printf("State Bench: %d,%d,%d,%04x\n", seed1, seed2, step, crc); |
#endif |
for (i=0; i<NUM_CORE_STATES; i++) { |
final_counts[i]=track_counts[i]=0; |
for (i = 0; i < NUM_CORE_STATES; i++) { |
final_counts[i] = track_counts[i] = 0; |
} |
/* run the state machine over the input */ |
while (*p!=0) { |
enum CORE_STATE fstate=core_state_transition(&p,track_counts); |
while (*p != 0) { |
enum CORE_STATE fstate = |
core_state_transition(&p, track_counts); |
final_counts[fstate]++; |
#if CORE_DEBUG |
ee_printf("%d,",fstate); |
ee_printf("%d,", fstate); |
} |
ee_printf("\n"); |
#else |
} |
#endif |
p=memblock; |
while (p < (memblock+blksize)) { /* insert some corruption */ |
if (*p!=',') |
*p^=(ee_u8)seed1; |
p+=step; |
p = memblock; |
while (p < (memblock + blksize)) { /* insert some corruption */ |
if (*p != ',') |
*p ^= (ee_u8) seed1; |
p += step; |
} |
p=memblock; |
p = memblock; |
/* run the state machine over the input again */ |
while (*p!=0) { |
enum CORE_STATE fstate=core_state_transition(&p,track_counts); |
while (*p != 0) { |
enum CORE_STATE fstate = |
core_state_transition(&p, track_counts); |
final_counts[fstate]++; |
#if CORE_DEBUG |
ee_printf("%d,",fstate); |
ee_printf("%d,", fstate); |
} |
ee_printf("\n"); |
#else |
} |
#endif |
p=memblock; |
while (p < (memblock+blksize)) { /* undo corruption is seed1 and seed2 are equal */ |
if (*p!=',') |
*p^=(ee_u8)seed2; |
p+=step; |
p = memblock; |
while (p < (memblock + blksize)) { /* undo corruption is seed1 and seed2 are equal */ |
if (*p != ',') |
*p ^= (ee_u8) seed2; |
p += step; |
} |
/* end timing */ |
for (i=0; i<NUM_CORE_STATES; i++) { |
crc=crcu32(final_counts[i],crc); |
crc=crcu32(track_counts[i],crc); |
for (i = 0; i < NUM_CORE_STATES; i++) { |
crc = crcu32(final_counts[i], crc); |
crc = crcu32(track_counts[i], crc); |
} |
return crc; |
} |
|
/* Default initialization patterns */ |
static ee_u8 *intpat[4] ={(ee_u8 *)"5012",(ee_u8 *)"1234",(ee_u8 *)"-874",(ee_u8 *)"+122"}; |
static ee_u8 *floatpat[4]={(ee_u8 *)"35.54400",(ee_u8 *)".1234500",(ee_u8 *)"-110.700",(ee_u8 *)"+0.64400"}; |
static ee_u8 *scipat[4] ={(ee_u8 *)"5.500e+3",(ee_u8 *)"-.123e-2",(ee_u8 *)"-87e+832",(ee_u8 *)"+0.6e-12"}; |
static ee_u8 *errpat[4] ={(ee_u8 *)"T0.3e-1F",(ee_u8 *)"-T.T++Tq",(ee_u8 *)"1T3.4e4z",(ee_u8 *)"34.0e-T^"}; |
static ee_u8 *intpat[4] = |
{ (ee_u8 *) "5012", (ee_u8 *) "1234", (ee_u8 *) "-874", (ee_u8 *) "+122" }; |
static ee_u8 *floatpat[4] = |
{ (ee_u8 *) "35.54400", (ee_u8 *) ".1234500", (ee_u8 *) "-110.700", |
(ee_u8 *) "+0.64400" }; |
static ee_u8 *scipat[4] = |
{ (ee_u8 *) "5.500e+3", (ee_u8 *) "-.123e-2", (ee_u8 *) "-87e+832", |
(ee_u8 *) "+0.6e-12" }; |
static ee_u8 *errpat[4] = |
{ (ee_u8 *) "T0.3e-1F", (ee_u8 *) "-T.T++Tq", (ee_u8 *) "1T3.4e4z", |
(ee_u8 *) "34.0e-T^" }; |
|
/* Function: core_init_state |
Initialize the input data for the state machine. |
113,61 → 122,63
Note: |
The seed parameter MUST be supplied from a source that cannot be determined at compile time |
*/ |
void core_init_state(ee_u32 size, ee_s16 seed, ee_u8 *p) { |
ee_u32 total=0,next=0,i; |
ee_u8 *buf=0; |
void core_init_state(ee_u32 size, ee_s16 seed, ee_u8 * p) |
{ |
ee_u32 total = 0, next = 0, i; |
ee_u8 *buf = 0; |
#if CORE_DEBUG |
ee_u8 *start=p; |
ee_printf("State: %d,%d\n",size,seed); |
ee_u8 *start = p; |
ee_printf("State: %d,%d\n", size, seed); |
#endif |
size--; |
next=0; |
while ((total+next+1)<size) { |
if (next>0) { |
for(i=0;i<next;i++) |
*(p+total+i)=buf[i]; |
*(p+total+i)=','; |
total+=next+1; |
next = 0; |
while ((total + next + 1) < size) { |
if (next > 0) { |
for (i = 0; i < next; i++) |
*(p + total + i) = buf[i]; |
*(p + total + i) = ','; |
total += next + 1; |
} |
seed++; |
switch (seed & 0x7) { |
case 0: /* int */ |
case 1: /* int */ |
case 2: /* int */ |
buf=intpat[(seed>>3) & 0x3]; |
next=4; |
case 0: /* int */ |
case 1: /* int */ |
case 2: /* int */ |
buf = intpat[(seed >> 3) & 0x3]; |
next = 4; |
break; |
case 3: /* float */ |
case 4: /* float */ |
buf=floatpat[(seed>>3) & 0x3]; |
next=8; |
case 3: /* float */ |
case 4: /* float */ |
buf = floatpat[(seed >> 3) & 0x3]; |
next = 8; |
break; |
case 5: /* scientific */ |
case 6: /* scientific */ |
buf=scipat[(seed>>3) & 0x3]; |
next=8; |
case 5: /* scientific */ |
case 6: /* scientific */ |
buf = scipat[(seed >> 3) & 0x3]; |
next = 8; |
break; |
case 7: /* invalid */ |
buf=errpat[(seed>>3) & 0x3]; |
next=8; |
case 7: /* invalid */ |
buf = errpat[(seed >> 3) & 0x3]; |
next = 8; |
break; |
default: /* Never happen, just to make some compilers happy */ |
default: /* Never happen, just to make some compilers happy */ |
break; |
} |
} |
size++; |
while (total<size) { /* fill the rest with 0 */ |
*(p+total)=0; |
while (total < size) { /* fill the rest with 0 */ |
*(p + total) = 0; |
total++; |
} |
#if CORE_DEBUG |
ee_printf("State Input: %s\n",start); |
ee_printf("State Input: %s\n", start); |
#endif |
} |
|
static ee_u8 ee_isdigit(ee_u8 c) { |
static ee_u8 ee_isdigit(ee_u8 c) |
{ |
ee_u8 retval; |
retval = ((c>='0') & (c<='9')) ? 1 : 0; |
retval = ((c >= '0') & (c <= '9')) ? 1 : 0; |
return retval; |
} |
|
181,28 → 192,26
The input pointer is updated to point to the end of the token, and the end state is returned (either specific format determined or invalid). |
*/ |
|
enum CORE_STATE core_state_transition( ee_u8 **instr , ee_u32 *transition_count) { |
ee_u8 *str=*instr; |
enum CORE_STATE core_state_transition(ee_u8 ** instr, ee_u32 * transition_count) |
{ |
ee_u8 *str = *instr; |
ee_u8 NEXT_SYMBOL; |
enum CORE_STATE state=CORE_START; |
for( ; *str && state != CORE_INVALID; str++ ) { |
enum CORE_STATE state = CORE_START; |
for (; *str && state != CORE_INVALID; str++) { |
NEXT_SYMBOL = *str; |
if (NEXT_SYMBOL==',') /* end of this input */ { |
if (NEXT_SYMBOL == ',') { /* end of this input */ |
str++; |
break; |
} |
switch(state) { |
switch (state) { |
case CORE_START: |
if(ee_isdigit(NEXT_SYMBOL)) { |
if (ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_INT; |
} |
else if( NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-' ) { |
} else if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') { |
state = CORE_S1; |
} |
else if( NEXT_SYMBOL == '.' ) { |
} else if (NEXT_SYMBOL == '.') { |
state = CORE_FLOAT; |
} |
else { |
} else { |
state = CORE_INVALID; |
transition_count[CORE_INVALID]++; |
} |
209,61 → 218,55
transition_count[CORE_START]++; |
break; |
case CORE_S1: |
if(ee_isdigit(NEXT_SYMBOL)) { |
if (ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_INT; |
transition_count[CORE_S1]++; |
} |
else if( NEXT_SYMBOL == '.' ) { |
} else if (NEXT_SYMBOL == '.') { |
state = CORE_FLOAT; |
transition_count[CORE_S1]++; |
} |
else { |
} else { |
state = CORE_INVALID; |
transition_count[CORE_S1]++; |
} |
break; |
case CORE_INT: |
if( NEXT_SYMBOL == '.' ) { |
if (NEXT_SYMBOL == '.') { |
state = CORE_FLOAT; |
transition_count[CORE_INT]++; |
} |
else if(!ee_isdigit(NEXT_SYMBOL)) { |
} else if (!ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_INVALID; |
transition_count[CORE_INT]++; |
} |
break; |
case CORE_FLOAT: |
if( NEXT_SYMBOL == 'E' || NEXT_SYMBOL == 'e' ) { |
if (NEXT_SYMBOL == 'E' || NEXT_SYMBOL == 'e') { |
state = CORE_S2; |
transition_count[CORE_FLOAT]++; |
} |
else if(!ee_isdigit(NEXT_SYMBOL)) { |
} else if (!ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_INVALID; |
transition_count[CORE_FLOAT]++; |
} |
break; |
case CORE_S2: |
if( NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-' ) { |
if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') { |
state = CORE_EXPONENT; |
transition_count[CORE_S2]++; |
} |
else { |
} else { |
state = CORE_INVALID; |
transition_count[CORE_S2]++; |
} |
break; |
case CORE_EXPONENT: |
if(ee_isdigit(NEXT_SYMBOL)) { |
if (ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_SCIENTIFIC; |
transition_count[CORE_EXPONENT]++; |
} |
else { |
} else { |
state = CORE_INVALID; |
transition_count[CORE_EXPONENT]++; |
} |
break; |
case CORE_SCIENTIFIC: |
if(!ee_isdigit(NEXT_SYMBOL)) { |
if (!ee_isdigit(NEXT_SYMBOL)) { |
state = CORE_INVALID; |
transition_count[CORE_INVALID]++; |
} |
272,6 → 275,6
break; |
} |
} |
*instr=str; |
*instr = str; |
return state; |
} |
/orpmon/coremark/ee_printf.c
53,154 → 53,164
|
static size_t strnlen(const char *s, size_t count) |
{ |
const char *sc; |
for (sc = s; *sc != '\0' && count--; ++sc); |
return sc - s; |
const char *sc; |
for (sc = s; *sc != '\0' && count--; ++sc) ; |
return sc - s; |
} |
|
static int skip_atoi(const char **s) |
{ |
int i = 0; |
while (is_digit(**s)) i = i*10 + *((*s)++) - '0'; |
return i; |
int i = 0; |
while (is_digit(**s)) |
i = i * 10 + *((*s)++) - '0'; |
return i; |
} |
|
static char *number(char *str, long num, int base, int size, int precision, int type) |
static char *number(char *str, long num, int base, int size, int precision, |
int type) |
{ |
char c, sign, tmp[66]; |
char *dig = digits; |
int i; |
char c, sign, tmp[66]; |
char *dig = digits; |
int i; |
|
if (type & UPPERCASE) dig = upper_digits; |
if (type & LEFT) type &= ~ZEROPAD; |
if (base < 2 || base > 36) return 0; |
|
c = (type & ZEROPAD) ? '0' : ' '; |
sign = 0; |
if (type & SIGN) |
{ |
if (num < 0) |
{ |
sign = '-'; |
num = -num; |
size--; |
} |
else if (type & PLUS) |
{ |
sign = '+'; |
size--; |
} |
else if (type & SPACE) |
{ |
sign = ' '; |
size--; |
} |
} |
if (type & UPPERCASE) |
dig = upper_digits; |
if (type & LEFT) |
type &= ~ZEROPAD; |
if (base < 2 || base > 36) |
return 0; |
|
if (type & HEX_PREP) |
{ |
if (base == 16) |
size -= 2; |
else if (base == 8) |
size--; |
} |
c = (type & ZEROPAD) ? '0' : ' '; |
sign = 0; |
if (type & SIGN) { |
if (num < 0) { |
sign = '-'; |
num = -num; |
size--; |
} else if (type & PLUS) { |
sign = '+'; |
size--; |
} else if (type & SPACE) { |
sign = ' '; |
size--; |
} |
} |
|
i = 0; |
if (type & HEX_PREP) { |
if (base == 16) |
size -= 2; |
else if (base == 8) |
size--; |
} |
|
if (num == 0) |
tmp[i++] = '0'; |
else |
{ |
while (num != 0) |
{ |
tmp[i++] = dig[((unsigned long) num) % (unsigned) base]; |
num = ((unsigned long) num) / (unsigned) base; |
} |
} |
i = 0; |
|
if (i > precision) precision = i; |
size -= precision; |
if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' '; |
if (sign) *str++ = sign; |
|
if (type & HEX_PREP) |
{ |
if (base == 8) |
*str++ = '0'; |
else if (base == 16) |
{ |
*str++ = '0'; |
*str++ = digits[33]; |
} |
} |
if (num == 0) |
tmp[i++] = '0'; |
else { |
while (num != 0) { |
tmp[i++] = dig[((unsigned long)num) % (unsigned)base]; |
num = ((unsigned long)num) / (unsigned)base; |
} |
} |
|
if (!(type & LEFT)) while (size-- > 0) *str++ = c; |
while (i < precision--) *str++ = '0'; |
while (i-- > 0) *str++ = tmp[i]; |
while (size-- > 0) *str++ = ' '; |
if (i > precision) |
precision = i; |
size -= precision; |
if (!(type & (ZEROPAD | LEFT))) |
while (size-- > 0) |
*str++ = ' '; |
if (sign) |
*str++ = sign; |
|
return str; |
if (type & HEX_PREP) { |
if (base == 8) |
*str++ = '0'; |
else if (base == 16) { |
*str++ = '0'; |
*str++ = digits[33]; |
} |
} |
|
if (!(type & LEFT)) |
while (size-- > 0) |
*str++ = c; |
while (i < precision--) |
*str++ = '0'; |
while (i-- > 0) |
*str++ = tmp[i]; |
while (size-- > 0) |
*str++ = ' '; |
|
return str; |
} |
|
static char *eaddr(char *str, unsigned char *addr, int size, int precision, int type) |
static char *eaddr(char *str, unsigned char *addr, int size, int precision, |
int type) |
{ |
char tmp[24]; |
char *dig = digits; |
int i, len; |
char tmp[24]; |
char *dig = digits; |
int i, len; |
|
if (type & UPPERCASE) dig = upper_digits; |
len = 0; |
for (i = 0; i < 6; i++) |
{ |
if (i != 0) tmp[len++] = ':'; |
tmp[len++] = dig[addr[i] >> 4]; |
tmp[len++] = dig[addr[i] & 0x0F]; |
} |
if (type & UPPERCASE) |
dig = upper_digits; |
len = 0; |
for (i = 0; i < 6; i++) { |
if (i != 0) |
tmp[len++] = ':'; |
tmp[len++] = dig[addr[i] >> 4]; |
tmp[len++] = dig[addr[i] & 0x0F]; |
} |
|
if (!(type & LEFT)) while (len < size--) *str++ = ' '; |
for (i = 0; i < len; ++i) *str++ = tmp[i]; |
while (len < size--) *str++ = ' '; |
if (!(type & LEFT)) |
while (len < size--) |
*str++ = ' '; |
for (i = 0; i < len; ++i) |
*str++ = tmp[i]; |
while (len < size--) |
*str++ = ' '; |
|
return str; |
return str; |
} |
|
static char *iaddr(char *str, unsigned char *addr, int size, int precision, int type) |
static char *iaddr(char *str, unsigned char *addr, int size, int precision, |
int type) |
{ |
char tmp[24]; |
int i, n, len; |
char tmp[24]; |
int i, n, len; |
|
len = 0; |
for (i = 0; i < 4; i++) |
{ |
if (i != 0) tmp[len++] = '.'; |
n = addr[i]; |
|
if (n == 0) |
tmp[len++] = digits[0]; |
else |
{ |
if (n >= 100) |
{ |
tmp[len++] = digits[n / 100]; |
n = n % 100; |
tmp[len++] = digits[n / 10]; |
n = n % 10; |
} |
else if (n >= 10) |
{ |
tmp[len++] = digits[n / 10]; |
n = n % 10; |
} |
len = 0; |
for (i = 0; i < 4; i++) { |
if (i != 0) |
tmp[len++] = '.'; |
n = addr[i]; |
|
tmp[len++] = digits[n]; |
} |
} |
if (n == 0) |
tmp[len++] = digits[0]; |
else { |
if (n >= 100) { |
tmp[len++] = digits[n / 100]; |
n = n % 100; |
tmp[len++] = digits[n / 10]; |
n = n % 10; |
} else if (n >= 10) { |
tmp[len++] = digits[n / 10]; |
n = n % 10; |
} |
|
if (!(type & LEFT)) while (len < size--) *str++ = ' '; |
for (i = 0; i < len; ++i) *str++ = tmp[i]; |
while (len < size--) *str++ = ' '; |
tmp[len++] = digits[n]; |
} |
} |
|
return str; |
if (!(type & LEFT)) |
while (len < size--) |
*str++ = ' '; |
for (i = 0; i < len; ++i) |
*str++ = tmp[i]; |
while (len < size--) |
*str++ = ' '; |
|
return str; |
} |
|
#ifdef HAS_FLOAT |
207,213 → 217,205
|
char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); |
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf); |
static void ee_bufcpy(char *d, char *s, int count); |
|
void ee_bufcpy(char *pd, char *ps, int count) { |
char *pe=ps+count; |
while (ps!=pe) |
*pd++=*ps++; |
static void ee_bufcpy(char *d, char *s, int count); |
|
void ee_bufcpy(char *pd, char *ps, int count) |
{ |
char *pe = ps + count; |
while (ps != pe) |
*pd++ = *ps++; |
} |
|
static void parse_float(double value, char *buffer, char fmt, int precision) |
{ |
int decpt, sign, exp, pos; |
char *digits = NULL; |
char cvtbuf[80]; |
int capexp = 0; |
int magnitude; |
int decpt, sign, exp, pos; |
char *digits = NULL; |
char cvtbuf[80]; |
int capexp = 0; |
int magnitude; |
|
if (fmt == 'G' || fmt == 'E') |
{ |
capexp = 1; |
fmt += 'a' - 'A'; |
} |
if (fmt == 'G' || fmt == 'E') { |
capexp = 1; |
fmt += 'a' - 'A'; |
} |
|
if (fmt == 'g') |
{ |
digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf); |
magnitude = decpt - 1; |
if (magnitude < -4 || magnitude > precision - 1) |
{ |
fmt = 'e'; |
precision -= 1; |
} |
else |
{ |
fmt = 'f'; |
precision -= decpt; |
} |
} |
if (fmt == 'g') { |
digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf); |
magnitude = decpt - 1; |
if (magnitude < -4 || magnitude > precision - 1) { |
fmt = 'e'; |
precision -= 1; |
} else { |
fmt = 'f'; |
precision -= decpt; |
} |
} |
|
if (fmt == 'e') |
{ |
digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf); |
if (fmt == 'e') { |
digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf); |
|
if (sign) *buffer++ = '-'; |
*buffer++ = *digits; |
if (precision > 0) *buffer++ = '.'; |
ee_bufcpy(buffer, digits + 1, precision); |
buffer += precision; |
*buffer++ = capexp ? 'E' : 'e'; |
if (sign) |
*buffer++ = '-'; |
*buffer++ = *digits; |
if (precision > 0) |
*buffer++ = '.'; |
ee_bufcpy(buffer, digits + 1, precision); |
buffer += precision; |
*buffer++ = capexp ? 'E' : 'e'; |
|
if (decpt == 0) |
{ |
if (value == 0.0) |
exp = 0; |
else |
exp = -1; |
} |
else |
exp = decpt - 1; |
if (decpt == 0) { |
if (value == 0.0) |
exp = 0; |
else |
exp = -1; |
} else |
exp = decpt - 1; |
|
if (exp < 0) |
{ |
*buffer++ = '-'; |
exp = -exp; |
} |
else |
*buffer++ = '+'; |
if (exp < 0) { |
*buffer++ = '-'; |
exp = -exp; |
} else |
*buffer++ = '+'; |
|
buffer[2] = (exp % 10) + '0'; |
exp = exp / 10; |
buffer[1] = (exp % 10) + '0'; |
exp = exp / 10; |
buffer[0] = (exp % 10) + '0'; |
buffer += 3; |
} |
else if (fmt == 'f') |
{ |
digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf); |
if (sign) *buffer++ = '-'; |
if (*digits) |
{ |
if (decpt <= 0) |
{ |
*buffer++ = '0'; |
*buffer++ = '.'; |
for (pos = 0; pos < -decpt; pos++) *buffer++ = '0'; |
while (*digits) *buffer++ = *digits++; |
} |
else |
{ |
pos = 0; |
while (*digits) |
{ |
if (pos++ == decpt) *buffer++ = '.'; |
*buffer++ = *digits++; |
} |
} |
} |
else |
{ |
*buffer++ = '0'; |
if (precision > 0) |
{ |
*buffer++ = '.'; |
for (pos = 0; pos < precision; pos++) *buffer++ = '0'; |
} |
} |
} |
buffer[2] = (exp % 10) + '0'; |
exp = exp / 10; |
buffer[1] = (exp % 10) + '0'; |
exp = exp / 10; |
buffer[0] = (exp % 10) + '0'; |
buffer += 3; |
} else if (fmt == 'f') { |
digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf); |
if (sign) |
*buffer++ = '-'; |
if (*digits) { |
if (decpt <= 0) { |
*buffer++ = '0'; |
*buffer++ = '.'; |
for (pos = 0; pos < -decpt; pos++) |
*buffer++ = '0'; |
while (*digits) |
*buffer++ = *digits++; |
} else { |
pos = 0; |
while (*digits) { |
if (pos++ == decpt) |
*buffer++ = '.'; |
*buffer++ = *digits++; |
} |
} |
} else { |
*buffer++ = '0'; |
if (precision > 0) { |
*buffer++ = '.'; |
for (pos = 0; pos < precision; pos++) |
*buffer++ = '0'; |
} |
} |
} |
|
*buffer = '\0'; |
*buffer = '\0'; |
} |
|
static void decimal_point(char *buffer) |
{ |
while (*buffer) |
{ |
if (*buffer == '.') return; |
if (*buffer == 'e' || *buffer == 'E') break; |
buffer++; |
} |
while (*buffer) { |
if (*buffer == '.') |
return; |
if (*buffer == 'e' || *buffer == 'E') |
break; |
buffer++; |
} |
|
if (*buffer) |
{ |
int n = strnlen(buffer,256); |
while (n > 0) |
{ |
buffer[n + 1] = buffer[n]; |
n--; |
} |
if (*buffer) { |
int n = strnlen(buffer, 256); |
while (n > 0) { |
buffer[n + 1] = buffer[n]; |
n--; |
} |
|
*buffer = '.'; |
} |
else |
{ |
*buffer++ = '.'; |
*buffer = '\0'; |
} |
*buffer = '.'; |
} else { |
*buffer++ = '.'; |
*buffer = '\0'; |
} |
} |
|
static void cropzeros(char *buffer) |
{ |
char *stop; |
char *stop; |
|
while (*buffer && *buffer != '.') buffer++; |
if (*buffer++) |
{ |
while (*buffer && *buffer != 'e' && *buffer != 'E') buffer++; |
stop = buffer--; |
while (*buffer == '0') buffer--; |
if (*buffer == '.') buffer--; |
while (buffer!=stop) |
*++buffer=0; |
} |
while (*buffer && *buffer != '.') |
buffer++; |
if (*buffer++) { |
while (*buffer && *buffer != 'e' && *buffer != 'E') |
buffer++; |
stop = buffer--; |
while (*buffer == '0') |
buffer--; |
if (*buffer == '.') |
buffer--; |
while (buffer != stop) |
*++buffer = 0; |
} |
} |
|
static char *flt(char *str, double num, int size, int precision, char fmt, int flags) |
static char *flt(char *str, double num, int size, int precision, char fmt, |
int flags) |
{ |
char tmp[80]; |
char c, sign; |
int n, i; |
char tmp[80]; |
char c, sign; |
int n, i; |
|
// Left align means no zero padding |
if (flags & LEFT) flags &= ~ZEROPAD; |
// Left align means no zero padding |
if (flags & LEFT) |
flags &= ~ZEROPAD; |
|
// Determine padding and sign char |
c = (flags & ZEROPAD) ? '0' : ' '; |
sign = 0; |
if (flags & SIGN) |
{ |
if (num < 0.0) |
{ |
sign = '-'; |
num = -num; |
size--; |
} |
else if (flags & PLUS) |
{ |
sign = '+'; |
size--; |
} |
else if (flags & SPACE) |
{ |
sign = ' '; |
size--; |
} |
} |
// Determine padding and sign char |
c = (flags & ZEROPAD) ? '0' : ' '; |
sign = 0; |
if (flags & SIGN) { |
if (num < 0.0) { |
sign = '-'; |
num = -num; |
size--; |
} else if (flags & PLUS) { |
sign = '+'; |
size--; |
} else if (flags & SPACE) { |
sign = ' '; |
size--; |
} |
} |
// Compute the precision value |
if (precision < 0) |
precision = 6; // Default precision: 6 |
|
// Compute the precision value |
if (precision < 0) |
precision = 6; // Default precision: 6 |
// Convert floating point number to text |
parse_float(num, tmp, fmt, precision); |
|
// Convert floating point number to text |
parse_float(num, tmp, fmt, precision); |
if ((flags & HEX_PREP) && precision == 0) |
decimal_point(tmp); |
if (fmt == 'g' && !(flags & HEX_PREP)) |
cropzeros(tmp); |
|
if ((flags & HEX_PREP) && precision == 0) decimal_point(tmp); |
if (fmt == 'g' && !(flags & HEX_PREP)) cropzeros(tmp); |
n = strnlen(tmp, 256); |
|
n = strnlen(tmp,256); |
// Output number with alignment and padding |
size -= n; |
if (!(flags & (ZEROPAD | LEFT))) |
while (size-- > 0) |
*str++ = ' '; |
if (sign) |
*str++ = sign; |
if (!(flags & LEFT)) |
while (size-- > 0) |
*str++ = c; |
for (i = 0; i < n; i++) |
*str++ = tmp[i]; |
while (size-- > 0) |
*str++ = ' '; |
|
// Output number with alignment and padding |
size -= n; |
if (!(flags & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' '; |
if (sign) *str++ = sign; |
if (!(flags & LEFT)) while (size-- > 0) *str++ = c; |
for (i = 0; i < n; i++) *str++ = tmp[i]; |
while (size-- > 0) *str++ = ' '; |
|
return str; |
return str; |
} |
|
#endif |
420,188 → 422,202
|
static int ee_vsprintf(char *buf, const char *fmt, va_list args) |
{ |
int len; |
unsigned long num; |
int i, base; |
char *str; |
char *s; |
int len; |
unsigned long num; |
int i, base; |
char *str; |
char *s; |
|
int flags; // Flags to number() |
int flags; // Flags to number() |
|
int field_width; // Width of output field |
int precision; // Min. # of digits for integers; max number of chars for from string |
int qualifier; // 'h', 'l', or 'L' for integer fields |
int field_width; // Width of output field |
int precision; // Min. # of digits for integers; max number of chars for from string |
int qualifier; // 'h', 'l', or 'L' for integer fields |
|
for (str = buf; *fmt; fmt++) |
{ |
if (*fmt != '%') |
{ |
*str++ = *fmt; |
continue; |
} |
|
// Process flags |
flags = 0; |
for (str = buf; *fmt; fmt++) { |
if (*fmt != '%') { |
*str++ = *fmt; |
continue; |
} |
// Process flags |
flags = 0; |
repeat: |
fmt++; // This also skips first '%' |
switch (*fmt) |
{ |
case '-': flags |= LEFT; goto repeat; |
case '+': flags |= PLUS; goto repeat; |
case ' ': flags |= SPACE; goto repeat; |
case '#': flags |= HEX_PREP; goto repeat; |
case '0': flags |= ZEROPAD; goto repeat; |
} |
|
// Get field width |
field_width = -1; |
if (is_digit(*fmt)) |
field_width = skip_atoi(&fmt); |
else if (*fmt == '*') |
{ |
fmt++; |
field_width = va_arg(args, int); |
if (field_width < 0) |
{ |
field_width = -field_width; |
flags |= LEFT; |
} |
} |
fmt++; // This also skips first '%' |
switch (*fmt) { |
case '-': |
flags |= LEFT; |
goto repeat; |
case '+': |
flags |= PLUS; |
goto repeat; |
case ' ': |
flags |= SPACE; |
goto repeat; |
case '#': |
flags |= HEX_PREP; |
goto repeat; |
case '0': |
flags |= ZEROPAD; |
goto repeat; |
} |
|
// Get the precision |
precision = -1; |
if (*fmt == '.') |
{ |
++fmt; |
if (is_digit(*fmt)) |
precision = skip_atoi(&fmt); |
else if (*fmt == '*') |
{ |
++fmt; |
precision = va_arg(args, int); |
} |
if (precision < 0) precision = 0; |
} |
// Get field width |
field_width = -1; |
if (is_digit(*fmt)) |
field_width = skip_atoi(&fmt); |
else if (*fmt == '*') { |
fmt++; |
field_width = va_arg(args, int); |
if (field_width < 0) { |
field_width = -field_width; |
flags |= LEFT; |
} |
} |
// Get the precision |
precision = -1; |
if (*fmt == '.') { |
++fmt; |
if (is_digit(*fmt)) |
precision = skip_atoi(&fmt); |
else if (*fmt == '*') { |
++fmt; |
precision = va_arg(args, int); |
} |
if (precision < 0) |
precision = 0; |
} |
// Get the conversion qualifier |
qualifier = -1; |
if (*fmt == 'l' || *fmt == 'L') { |
qualifier = *fmt; |
fmt++; |
} |
// Default base |
base = 10; |
|
// Get the conversion qualifier |
qualifier = -1; |
if (*fmt == 'l' || *fmt == 'L') |
{ |
qualifier = *fmt; |
fmt++; |
} |
switch (*fmt) { |
case 'c': |
if (!(flags & LEFT)) |
while (--field_width > 0) |
*str++ = ' '; |
*str++ = (unsigned char)va_arg(args, int); |
while (--field_width > 0) |
*str++ = ' '; |
continue; |
|
// Default base |
base = 10; |
case 's': |
s = va_arg(args, char *); |
if (!s) |
s = "<NULL>"; |
len = strnlen(s, precision); |
if (!(flags & LEFT)) |
while (len < field_width--) |
*str++ = ' '; |
for (i = 0; i < len; ++i) |
*str++ = *s++; |
while (len < field_width--) |
*str++ = ' '; |
continue; |
|
switch (*fmt) |
{ |
case 'c': |
if (!(flags & LEFT)) while (--field_width > 0) *str++ = ' '; |
*str++ = (unsigned char) va_arg(args, int); |
while (--field_width > 0) *str++ = ' '; |
continue; |
case 'p': |
if (field_width == -1) { |
field_width = 2 * sizeof(void *); |
flags |= ZEROPAD; |
} |
str = |
number(str, (unsigned long)va_arg(args, void *), 16, |
field_width, precision, flags); |
continue; |
|
case 's': |
s = va_arg(args, char *); |
if (!s) s = "<NULL>"; |
len = strnlen(s, precision); |
if (!(flags & LEFT)) while (len < field_width--) *str++ = ' '; |
for (i = 0; i < len; ++i) *str++ = *s++; |
while (len < field_width--) *str++ = ' '; |
continue; |
case 'A': |
flags |= UPPERCASE; |
|
case 'p': |
if (field_width == -1) |
{ |
field_width = 2 * sizeof(void *); |
flags |= ZEROPAD; |
} |
str = number(str, (unsigned long) va_arg(args, void *), 16, field_width, precision, flags); |
continue; |
case 'a': |
if (qualifier == 'l') |
str = |
eaddr(str, va_arg(args, unsigned char *), |
field_width, precision, flags); |
else |
str = |
iaddr(str, va_arg(args, unsigned char *), |
field_width, precision, flags); |
continue; |
|
case 'A': |
flags |= UPPERCASE; |
// Integer number formats - set up the flags and "break" |
case 'o': |
base = 8; |
break; |
|
case 'a': |
if (qualifier == 'l') |
str = eaddr(str, va_arg(args, unsigned char *), field_width, precision, flags); |
else |
str = iaddr(str, va_arg(args, unsigned char *), field_width, precision, flags); |
continue; |
case 'X': |
flags |= UPPERCASE; |
|
// Integer number formats - set up the flags and "break" |
case 'o': |
base = 8; |
break; |
case 'x': |
base = 16; |
break; |
|
case 'X': |
flags |= UPPERCASE; |
case 'd': |
case 'i': |
flags |= SIGN; |
|
case 'x': |
base = 16; |
break; |
case 'u': |
break; |
|
case 'd': |
case 'i': |
flags |= SIGN; |
|
case 'u': |
break; |
|
#ifdef HAS_FLOAT |
|
case 'f': |
str = flt(str, va_arg(args, double), field_width, precision, *fmt, flags | SIGN); |
continue; |
case 'f': |
str = |
flt(str, va_arg(args, double), field_width, |
precision, *fmt, flags | SIGN); |
continue; |
|
#endif |
|
default: |
if (*fmt != '%') *str++ = '%'; |
if (*fmt) |
*str++ = *fmt; |
else |
--fmt; |
continue; |
} |
default: |
if (*fmt != '%') |
*str++ = '%'; |
if (*fmt) |
*str++ = *fmt; |
else |
--fmt; |
continue; |
} |
|
if (qualifier == 'l') |
num = va_arg(args, unsigned long); |
else if (flags & SIGN) |
num = va_arg(args, int); |
else |
num = va_arg(args, unsigned int); |
if (qualifier == 'l') |
num = va_arg(args, unsigned long); |
else if (flags & SIGN) |
num = va_arg(args, int); |
else |
num = va_arg(args, unsigned int); |
|
str = number(str, num, base, field_width, precision, flags); |
} |
str = number(str, num, base, field_width, precision, flags); |
} |
|
*str = '\0'; |
return str - buf; |
*str = '\0'; |
return str - buf; |
} |
|
void uart_send_char(char c) { |
|
uart_putc(c); |
void uart_send_char(char c) |
{ |
|
uart_putc(c); |
|
} |
|
int ee_printf(const char *fmt, ...) |
{ |
char buf[256],*p; |
va_list args; |
int n=0; |
char buf[256], *p; |
va_list args; |
int n = 0; |
|
va_start(args, fmt); |
ee_vsprintf(buf, fmt, args); |
va_end(args); |
p=buf; |
while (*p) { |
uart_send_char(*p); |
n++; |
p++; |
} |
va_start(args, fmt); |
ee_vsprintf(buf, fmt, args); |
va_end(args); |
p = buf; |
while (*p) { |
uart_send_char(*p); |
n++; |
p++; |
} |
|
return n; |
return n; |
} |
|
/orpmon/coremark/core_main.c
112,7 → 112,6
|
*/ |
|
|
#if MAIN_HAS_NOARGC |
MAIN_RETURN_TYPE coremark_main(void) |
{ |
145,8 → 144,8
results[0].iterations = 1; |
#endif |
results[0].execs = get_seed_32(5); |
if (results[0].execs == 0) { |
/* if not supplied, execute all algorithms */ |
if (results[0].execs == 0) { |
/* if not supplied, execute all algorithms */ |
results[0].execs = ALL_ALGORITHMS_MASK; |
} |
/* put in some default values based on one seed only for easy testing */ |
290,7 → 289,7
ee_printf("6k performance run parameters for coremark.\n"); |
break; |
case 0x7b05: /* seed1=0x3415, seed2=0x3415, seed3=0x66, |
size 2000 per algorithm */ |
size 2000 per algorithm */ |
known_id = 1; |
ee_printf("6k validation run parameters for coremark.\n"); |
break; |
305,7 → 304,7
ee_printf("2K performance run parameters for coremark.\n"); |
break; |
case 0x18f2: /* seed1=0x3415, seed2=0x3415, seed3=0x66, |
size 666 per algorithm */ |
size 666 per algorithm */ |
known_id = 4; |
ee_printf("2K validation run parameters for coremark.\n"); |
break; |
431,17 → 430,15
return MAIN_RETURN_VAL; |
} |
|
int coremark_cmd(int argc, char *argv[]) |
{ |
return coremark_main(argc, argv); |
|
|
int coremark_cmd (int argc, char *argv[]) |
{ |
return coremark_main(argc, argv); |
|
} |
|
void module_coremark_init (void) |
void module_coremark_init(void) |
{ |
register_command ("coremark", "[<mode>] [<iterations>]", |
"run coremark, mode: p - performance run, o - profile run, default - validation run", |
coremark_cmd); |
register_command("coremark", "[<mode>] [<iterations>]", |
"run coremark, mode: p - performance run, o - profile run, default - validation run", |
coremark_cmd); |
} |
/orpmon/coremark/core_matrix.c
15,7 → 15,7
EEMBC |
4354 Town Center Blvd. Suite 114-200 |
El Dorado Hills, CA, 95762 |
*/ |
*/ |
#include "coremark.h" |
/* |
Topic: Description |
33,13 → 33,13
|
The actual values for A and B must be derived based on input that is not available at compile time. |
*/ |
ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val); |
ee_s16 matrix_sum(ee_u32 N, MATRES *C, MATDAT clipval); |
void matrix_mul_const(ee_u32 N, MATRES *C, MATDAT *A, MATDAT val); |
void matrix_mul_vect(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B); |
void matrix_mul_matrix(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B); |
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B); |
void matrix_add_const(ee_u32 N, MATDAT *A, MATDAT val); |
ee_s16 matrix_test(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B, MATDAT val); |
ee_s16 matrix_sum(ee_u32 N, MATRES * C, MATDAT clipval); |
void matrix_mul_const(ee_u32 N, MATRES * C, MATDAT * A, MATDAT val); |
void matrix_mul_vect(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B); |
void matrix_mul_matrix(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B); |
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B); |
void matrix_add_const(ee_u32 N, MATDAT * A, MATDAT val); |
|
#define matrix_test_next(x) (x+1) |
#define matrix_clip(x,y) ((y) ? (x) & 0x0ff : (x) & 0x0ffff) |
47,26 → 47,29
#define bit_extract(x,from,to) (((x)>>(from)) & (~(0xffffffff << (to)))) |
|
#if CORE_DEBUG |
void printmat(MATDAT *A, ee_u32 N, char *name) { |
ee_u32 i,j; |
ee_printf("Matrix %s [%dx%d]:\n",name,N,N); |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
if (j!=0) |
void printmat(MATDAT * A, ee_u32 N, char *name) |
{ |
ee_u32 i, j; |
ee_printf("Matrix %s [%dx%d]:\n", name, N, N); |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
if (j != 0) |
ee_printf(","); |
ee_printf("%d",A[i*N+j]); |
ee_printf("%d", A[i * N + j]); |
} |
ee_printf("\n"); |
} |
} |
void printmatC(MATRES *C, ee_u32 N, char *name) { |
ee_u32 i,j; |
ee_printf("Matrix %s [%dx%d]:\n",name,N,N); |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
if (j!=0) |
|
void printmatC(MATRES * C, ee_u32 N, char *name) |
{ |
ee_u32 i, j; |
ee_printf("Matrix %s [%dx%d]:\n", name, N, N); |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
if (j != 0) |
ee_printf(","); |
ee_printf("%d",C[i*N+j]); |
ee_printf("%d", C[i * N + j]); |
} |
ee_printf("\n"); |
} |
78,14 → 81,15
Iterate <matrix_test> N times, |
changing the matrix values slightly by a constant amount each time. |
*/ |
ee_u16 core_bench_matrix(mat_params *p, ee_s16 seed, ee_u16 crc) { |
ee_u32 N=p->N; |
MATRES *C=p->C; |
MATDAT *A=p->A; |
MATDAT *B=p->B; |
MATDAT val=(MATDAT)seed; |
ee_u16 core_bench_matrix(mat_params * p, ee_s16 seed, ee_u16 crc) |
{ |
ee_u32 N = p->N; |
MATRES *C = p->C; |
MATDAT *A = p->A; |
MATDAT *B = p->B; |
MATDAT val = (MATDAT) seed; |
|
crc=crc16(matrix_test(N,C,A,B,val),crc); |
crc = crc16(matrix_test(N, C, A, B, val), crc); |
|
return crc; |
} |
114,36 → 118,37
|
After the last step, matrix A is back to original contents. |
*/ |
ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val) { |
ee_u16 crc=0; |
MATDAT clipval=matrix_big(val); |
ee_s16 matrix_test(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B, MATDAT val) |
{ |
ee_u16 crc = 0; |
MATDAT clipval = matrix_big(val); |
|
matrix_add_const(N,A,val); /* make sure data changes */ |
matrix_add_const(N, A, val); /* make sure data changes */ |
#if CORE_DEBUG |
printmat(A,N,"matrix_add_const"); |
printmat(A, N, "matrix_add_const"); |
#endif |
matrix_mul_const(N,C,A,val); |
crc=crc16(matrix_sum(N,C,clipval),crc); |
matrix_mul_const(N, C, A, val); |
crc = crc16(matrix_sum(N, C, clipval), crc); |
#if CORE_DEBUG |
printmatC(C,N,"matrix_mul_const"); |
printmatC(C, N, "matrix_mul_const"); |
#endif |
matrix_mul_vect(N,C,A,B); |
crc=crc16(matrix_sum(N,C,clipval),crc); |
matrix_mul_vect(N, C, A, B); |
crc = crc16(matrix_sum(N, C, clipval), crc); |
#if CORE_DEBUG |
printmatC(C,N,"matrix_mul_vect"); |
printmatC(C, N, "matrix_mul_vect"); |
#endif |
matrix_mul_matrix(N,C,A,B); |
crc=crc16(matrix_sum(N,C,clipval),crc); |
matrix_mul_matrix(N, C, A, B); |
crc = crc16(matrix_sum(N, C, clipval), crc); |
#if CORE_DEBUG |
printmatC(C,N,"matrix_mul_matrix"); |
printmatC(C, N, "matrix_mul_matrix"); |
#endif |
matrix_mul_matrix_bitextract(N,C,A,B); |
crc=crc16(matrix_sum(N,C,clipval),crc); |
matrix_mul_matrix_bitextract(N, C, A, B); |
crc = crc16(matrix_sum(N, C, clipval), crc); |
#if CORE_DEBUG |
printmatC(C,N,"matrix_mul_matrix_bitextract"); |
printmatC(C, N, "matrix_mul_matrix_bitextract"); |
#endif |
|
matrix_add_const(N,A,-val); /* return matrix to initial value */ |
|
matrix_add_const(N, A, -val); /* return matrix to initial value */ |
return crc; |
} |
|
162,43 → 167,45
Note: |
The seed parameter MUST be supplied from a source that cannot be determined at compile time |
*/ |
ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, mat_params *p) { |
ee_u32 N=0; |
ee_u32 core_init_matrix(ee_u32 blksize, void *memblk, ee_s32 seed, |
mat_params * p) |
{ |
ee_u32 N = 0; |
MATDAT *A; |
MATDAT *B; |
ee_s32 order=1; |
ee_s32 order = 1; |
MATDAT val; |
ee_u32 i=0,j=0; |
if (seed==0) |
seed=1; |
while (j<blksize) { |
ee_u32 i = 0, j = 0; |
if (seed == 0) |
seed = 1; |
while (j < blksize) { |
i++; |
j=i*i*2*4; |
j = i * i * 2 * 4; |
} |
N=i-1; |
A=(MATDAT *)align_mem(memblk); |
B=A+N*N; |
N = i - 1; |
A = (MATDAT *) align_mem(memblk); |
B = A + N * N; |
|
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
seed = ( ( order * seed ) % 65536 ); |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
seed = ((order * seed) % 65536); |
val = (seed + order); |
val=matrix_clip(val,0); |
B[i*N+j] = val; |
val = (val + order); |
val=matrix_clip(val,1); |
A[i*N+j] = val; |
val = matrix_clip(val, 0); |
B[i * N + j] = val; |
val = (val + order); |
val = matrix_clip(val, 1); |
A[i * N + j] = val; |
order++; |
} |
} |
|
p->A=A; |
p->B=B; |
p->C=(MATRES *)align_mem(B+N*N); |
p->N=N; |
p->A = A; |
p->B = B; |
p->C = (MATRES *) align_mem(B + N * N); |
p->N = N; |
#if CORE_DEBUG |
printmat(A,N,"A"); |
printmat(B,N,"B"); |
printmat(A, N, "A"); |
printmat(B, N, "B"); |
#endif |
return N; |
} |
213,21 → 220,22
|
Otherwise, reset the accumulator and add 10 to the result. |
*/ |
ee_s16 matrix_sum(ee_u32 N, MATRES *C, MATDAT clipval) { |
MATRES tmp=0,prev=0,cur=0; |
ee_s16 ret=0; |
ee_u32 i,j; |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
cur=C[i*N+j]; |
tmp+=cur; |
if (tmp>clipval) { |
ret+=10; |
tmp=0; |
ee_s16 matrix_sum(ee_u32 N, MATRES * C, MATDAT clipval) |
{ |
MATRES tmp = 0, prev = 0, cur = 0; |
ee_s16 ret = 0; |
ee_u32 i, j; |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
cur = C[i * N + j]; |
tmp += cur; |
if (tmp > clipval) { |
ret += 10; |
tmp = 0; |
} else { |
ret += (cur>prev) ? 1 : 0; |
ret += (cur > prev) ? 1 : 0; |
} |
prev=cur; |
prev = cur; |
} |
} |
return ret; |
237,11 → 245,12
Multiply a matrix by a constant. |
This could be used as a scaler for instance. |
*/ |
void matrix_mul_const(ee_u32 N, MATRES *C, MATDAT *A, MATDAT val) { |
ee_u32 i,j; |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
C[i*N+j]=(MATRES)A[i*N+j] * (MATRES)val; |
void matrix_mul_const(ee_u32 N, MATRES * C, MATDAT * A, MATDAT val) |
{ |
ee_u32 i, j; |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
C[i * N + j] = (MATRES) A[i * N + j] * (MATRES) val; |
} |
} |
} |
249,11 → 258,12
/* Function: matrix_add_const |
Add a constant value to all elements of a matrix. |
*/ |
void matrix_add_const(ee_u32 N, MATDAT *A, MATDAT val) { |
ee_u32 i,j; |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
A[i*N+j] += val; |
void matrix_add_const(ee_u32 N, MATDAT * A, MATDAT val) |
{ |
ee_u32 i, j; |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
A[i * N + j] += val; |
} |
} |
} |
262,12 → 272,13
Multiply a matrix by a vector. |
This is common in many simple filters (e.g. fir where a vector of coefficients is applied to the matrix.) |
*/ |
void matrix_mul_vect(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) { |
ee_u32 i,j; |
for (i=0; i<N; i++) { |
C[i]=0; |
for (j=0; j<N; j++) { |
C[i]+=(MATRES)A[i*N+j] * (MATRES)B[j]; |
void matrix_mul_vect(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B) |
{ |
ee_u32 i, j; |
for (i = 0; i < N; i++) { |
C[i] = 0; |
for (j = 0; j < N; j++) { |
C[i] += (MATRES) A[i * N + j] * (MATRES) B[j]; |
} |
} |
} |
276,14 → 287,16
Multiply a matrix by a matrix. |
Basic code is used in many algorithms, mostly with minor changes such as scaling. |
*/ |
void matrix_mul_matrix(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) { |
ee_u32 i,j,k; |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
C[i*N+j]=0; |
for(k=0;k<N;k++) |
{ |
C[i*N+j]+=(MATRES)A[i*N+k] * (MATRES)B[k*N+j]; |
void matrix_mul_matrix(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B) |
{ |
ee_u32 i, j, k; |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
C[i * N + j] = 0; |
for (k = 0; k < N; k++) { |
C[i * N + j] += |
(MATRES) A[i * N + k] * (MATRES) B[k * N + |
j]; |
} |
} |
} |
293,15 → 306,19
Multiply a matrix by a matrix, and extract some bits from the result. |
Basic code is used in many algorithms, mostly with minor changes such as scaling. |
*/ |
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B) { |
ee_u32 i,j,k; |
for (i=0; i<N; i++) { |
for (j=0; j<N; j++) { |
C[i*N+j]=0; |
for(k=0;k<N;k++) |
{ |
MATRES tmp=(MATRES)A[i*N+k] * (MATRES)B[k*N+j]; |
C[i*N+j]+=bit_extract(tmp,2,4)*bit_extract(tmp,5,7); |
void matrix_mul_matrix_bitextract(ee_u32 N, MATRES * C, MATDAT * A, MATDAT * B) |
{ |
ee_u32 i, j, k; |
for (i = 0; i < N; i++) { |
for (j = 0; j < N; j++) { |
C[i * N + j] = 0; |
for (k = 0; k < N; k++) { |
MATRES tmp = |
(MATRES) A[i * N + k] * (MATRES) B[k * N + |
j]; |
C[i * N + j] += |
bit_extract(tmp, 2, 4) * bit_extract(tmp, 5, |
7); |
} |
} |
} |
/orpmon/coremark/cvt.c
1,105 → 1,99
//#include <math.h> |
|
double modf(double x, double *iptr); // Our local version of modf() |
double modf(double x, double *iptr); // Our local version of modf() |
|
#define CVTBUFSIZE 80 |
static char CVTBUF[CVTBUFSIZE]; |
|
static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag) |
static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, |
int eflag) |
{ |
int r2; |
double fi, fj; |
char *p, *p1; |
int r2; |
double fi, fj; |
char *p, *p1; |
|
if (ndigits < 0) ndigits = 0; |
if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2; |
r2 = 0; |
*sign = 0; |
p = &buf[0]; |
if (arg < 0) |
{ |
*sign = 1; |
arg = -arg; |
} |
arg = modf(arg, &fi); |
p1 = &buf[CVTBUFSIZE]; |
if (ndigits < 0) |
ndigits = 0; |
if (ndigits >= CVTBUFSIZE - 1) |
ndigits = CVTBUFSIZE - 2; |
r2 = 0; |
*sign = 0; |
p = &buf[0]; |
if (arg < 0) { |
*sign = 1; |
arg = -arg; |
} |
arg = modf(arg, &fi); |
p1 = &buf[CVTBUFSIZE]; |
|
if (fi != 0) |
{ |
p1 = &buf[CVTBUFSIZE]; |
while (fi != 0) |
{ |
fj = modf(fi / 10, &fi); |
*--p1 = (int)((fj + .03) * 10) + '0'; |
r2++; |
} |
while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++; |
} |
else if (arg > 0) |
{ |
while ((fj = arg * 10) < 1) |
{ |
arg = fj; |
r2--; |
} |
} |
p1 = &buf[ndigits]; |
if (eflag == 0) p1 += r2; |
*decpt = r2; |
if (p1 < &buf[0]) |
{ |
buf[0] = '\0'; |
return buf; |
} |
while (p <= p1 && p < &buf[CVTBUFSIZE]) |
{ |
arg *= 10; |
arg = modf(arg, &fj); |
*p++ = (int) fj + '0'; |
} |
if (p1 >= &buf[CVTBUFSIZE]) |
{ |
buf[CVTBUFSIZE - 1] = '\0'; |
return buf; |
} |
p = p1; |
*p1 += 5; |
while (*p1 > '9') |
{ |
*p1 = '0'; |
if (p1 > buf) |
++*--p1; |
else |
{ |
*p1 = '1'; |
(*decpt)++; |
if (eflag == 0) |
{ |
if (p > buf) *p = '0'; |
p++; |
} |
} |
} |
*p = '\0'; |
return buf; |
if (fi != 0) { |
p1 = &buf[CVTBUFSIZE]; |
while (fi != 0) { |
fj = modf(fi / 10, &fi); |
*--p1 = (int)((fj + .03) * 10) + '0'; |
r2++; |
} |
while (p1 < &buf[CVTBUFSIZE]) |
*p++ = *p1++; |
} else if (arg > 0) { |
while ((fj = arg * 10) < 1) { |
arg = fj; |
r2--; |
} |
} |
p1 = &buf[ndigits]; |
if (eflag == 0) |
p1 += r2; |
*decpt = r2; |
if (p1 < &buf[0]) { |
buf[0] = '\0'; |
return buf; |
} |
while (p <= p1 && p < &buf[CVTBUFSIZE]) { |
arg *= 10; |
arg = modf(arg, &fj); |
*p++ = (int)fj + '0'; |
} |
if (p1 >= &buf[CVTBUFSIZE]) { |
buf[CVTBUFSIZE - 1] = '\0'; |
return buf; |
} |
p = p1; |
*p1 += 5; |
while (*p1 > '9') { |
*p1 = '0'; |
if (p1 > buf) |
++ * --p1; |
else { |
*p1 = '1'; |
(*decpt)++; |
if (eflag == 0) { |
if (p > buf) |
*p = '0'; |
p++; |
} |
} |
} |
*p = '\0'; |
return buf; |
} |
|
char *ecvt(double arg, int ndigits, int *decpt, int *sign) |
{ |
return cvt(arg, ndigits, decpt, sign, CVTBUF, 1); |
return cvt(arg, ndigits, decpt, sign, CVTBUF, 1); |
} |
|
char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) |
{ |
return cvt(arg, ndigits, decpt, sign, buf, 1); |
return cvt(arg, ndigits, decpt, sign, buf, 1); |
} |
|
char *fcvt(double arg, int ndigits, int *decpt, int *sign) |
{ |
return cvt(arg, ndigits, decpt, sign, CVTBUF, 0); |
return cvt(arg, ndigits, decpt, sign, CVTBUF, 0); |
} |
|
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf) |
{ |
return cvt(arg, ndigits, decpt, sign, buf, 0); |
return cvt(arg, ndigits, decpt, sign, buf, 0); |
} |
/orpmon/drivers/eth.c
387,22 → 387,31
|
retry_eth_send: |
bd[tx_last].len_status &= 0x0000ffff & ~ETH_TX_BD_STATS; |
|
if (eth_monitor_enabled) // enable IRQ when sending |
bd[tx_last].len_status |= ETH_TX_BD_IRQ; |
|
bd[tx_last].len_status |= len << 16 | ETH_TX_BD_READY; |
|
/* |
while (bd[tx_last].len_status & ETH_TX_BD_READY); |
printf("packet tx\n"); |
// Check it was sent OK |
if ( bd[tx_last].len_status & 0x2) |
if (!eth_monitor_enabled) // If we're not running the network sniffer... |
{ |
printf("eth_send: carrier sense lost (txbd: 0x%x), deferred, retrying\n", |
bd[tx_last].len_status); |
sleep(1000); |
goto retry_eth_send; |
while (bd[tx_last].len_status & ETH_TX_BD_READY); |
|
//printf("packet tx\n"); |
// Check it was sent OK |
/* |
BUG with current implementation - constantly getting carrier sense |
lost, and deferred indication, so ignore it for now. |
if ( bd[tx_last].len_status & 0xf) |
{ |
printf("eth_send: carrier sense lost (txbd: 0x%x), deferred, retrying\n", |
bd[tx_last].len_status); |
sleep(1); |
goto retry_eth_send; |
} |
*/ |
} |
*/ |
|
tx_last++; |
|
if (tx_last == ETH_TXBD_NUM) |
/orpmon/drivers/int.c
72,5 → 72,41
i++; |
} |
} |
|
|
void |
int_error(int vect) |
{ |
printf("\n\nERROR - "); |
switch(vect) |
{ |
case 2: |
printf("BUS ERROR (0x200)\n"); |
break; |
case 6: |
printf("ALIGN ERROR (0x600)\n"); |
break; |
case 7: |
printf("ILLEGAL INSN ERROR (0x700)\n"); |
break; |
default: |
printf("UNKNOWN ERROR (%d)\n",vect); |
break; |
} |
|
printf("\n"); |
|
// TODO - print some more diagnostics here |
|
printf("Attemping to reset...\n\n"); |
|
asm volatile("l.ori r3, r0, 0x100"); |
asm volatile("l.jr r3"); |
asm volatile("l.nop"); |
|
// Stay here forever. |
//while(1); |
|
} |
|
#endif |