/* tools.c Revision 3.0 11/93 */ #include #include #include #include #include "types.h" #include "tools.h" #include "siop.h" #include "main.h" /**************************************************************** This function writes a byte to an SIOP register. It will work for both I/O and memory mapped chips. ****************************************************************/ void write_reg(T_reg,data) int T_reg; unsigned char data; { extern unsigned int MEM_MAP; extern unsigned int C7XX_SEG; extern unsigned int seg, off; if(MEM_MAP==TRUE) pokeb(seg, off+T_reg, data); /* Memory mapped */ else outportb(C7XX_SEG + T_reg, data); /* I/O mapped */ } /******************************************************************* This function reads a byte from an SIOP register. It uses the globals MEM_MAP,7XX_SEG, seg, and off to find the chip, regardless of whether it's memory or I/O mapped. ******************************************************************/ unsigned char read_reg(T_reg) int T_reg; { extern unsigned int MEM_MAP; extern unsigned int C7XX_SEG; extern unsigned int seg, off; if(MEM_MAP==TRUE) return(peekb(seg, off+T_reg)); /* Memory mapped */ else return(inportb(C7XX_SEG+T_reg)); /* I/O mapped */ } /* end reg_read */ /****************************************************************** This function is used to copy a 32-bit value into an SIOP register. It currently does it a 4 byte writes. ******************************************************************/ void write_long_reg(int reg, uquad addr) { int i; extern unsigned int MEM_MAP; extern unsigned int C7XX_SEG; extern unsigned int seg, off; if (MEM_MAP==TRUE) for (i = 0; i < 4; i++) pokeb(seg, off + reg + i,((addr >> 8 * i) & 0xff)); /* Mem map */ else for (i = 0; i < 4; i++) outportb(C7XX_SEG + reg + i, ((addr >> 8 * i) & 0xff)); /* I/O map */ } /* This function returns the physical 20-bit addres to a far pointer that is * passed. This is needed because the SIOP only understands true addresses, * not segment:offset. */ uquad getPhysAddr(void far * addr) { return (((uquad)FP_SEG(addr) << 4) + FP_OFF(addr)); } #define TABLE_WIDTH 16 /* This function prints a table with the values in buffer. The table * includes labels and has the hex and ascii values. */ void print_buffer(ubyte *buffer, unsigned length) { int j, k; for (j = 0; j < length; j++) { if (j % TABLE_WIDTH == 0) { printf("\n%3x: ", j); } printf("%02x ", buffer[j]); if (j % TABLE_WIDTH == TABLE_WIDTH - 1) { printf(" "); for (k = j - TABLE_WIDTH + 1; k <= j; k++) { if (isprint(buffer[k])) { printf("%c", buffer[k]); } else { printf("."); } } } } printf("\n\n"); } /*************************************************************** This function allocates memory like a normal malloc, but it assures that the buffer is longword aligned which is required for the Scripts and the DSA table. ***************************************************************/ void * my_malloc(size_t size) { ubyte *block; block = malloc(size+3); /* To fix */ if (block == NULL) { printf("Out of memory\n"); exit(1); } switch(FP_OFF(block)&0x03) { case 0 : break; case 1 : (char *)block = (char *)block + 3; break; case 2 : (char *)block = (char *)block + 2; break; case 3 : (char *)block = (char *)block + 1; break; default : printf("This should never happen - Linda Miquelon\n"); } return(block); }