📄 gen_tool.c
字号:
/***************************************************************************
* *
* Copyright 1995 Symbios Logic Incorporated. All rights reserved. *
* *
* This software was written by Symbios Logic Inc. to develop and test new *
* products. Symbios Logic assumes no liability for its use. This software*
* is released to the public domain to illustrate certain programming *
* techniques for testing the 53c8xx chips *
* *
***************************************************************************/
/* Name: GEN_TOOL.C
* Title: Validation test code generic tools
* $Workfile: $
* $Revision: $
* $Modtime: $
* Programmer: Symbios Logic
* Creation Date: 11/29/95
*
* Version History
* ---------------
*
* Date Who? Description
* -------- ---- -------------------------------------------------------
#BeginRevision
* 03/06/96 SYM - Made general formatting changes and documentation
* additions
* - Changed IORead/Write32 to inline assembly functions
* - Added Random buffer init to InitBuffer function
* - Fixed problem with InitBuffer func. 1. It wouldn't
* increment by fill value, just by 1 always.
* - Changed Writelog Detail output so that it won't put
* /n's in the String. Carraige returns are now at the
* descretion of the user.
* - Changed all fprintf's that went to stderr to go to
* stdout instead.
*
#EndRevision
*
* 11/29/95 SYM Initial Revision.
*
#BeginDescription
*
* This file contains generic functions which allow manipulation of
* data buffers, determination of physical addresses, log file entries
* and other general purpose tools. These routines are not device
* specific and can be ported to other hardware interfaces.
*
#EndDescription
*
*-------------------------------------------------------------------------
*
* $Header: $
*
*/
#include "valtypes.h"
#include "gen_tool.h"
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
/* This tells the compiler that there is assembly code in this file */
#pragma inline
/* Function prototypes */
VULONG getPhysAddr(void far * addr);
VUBYTE IORead8(VULONG IO_Addr);
void IOWrite8(VULONG IO_Addr, VUBYTE value);
VULONG IORead32(VULONG IO_Addr);
void IOWrite32(VULONG IO_Addr, VULONG value);
void far *ByteAlignBuffer(void far *buffer, VINT alignment);
void far *CacheAlignBuffer(void far *buffer, VINT cls, VINT offset);
void InitBuffer(VUBYTE far *buffer, VUINT size, VINT operation,
VUBYTE fill_val);
VULONG Get_Time(void);
VINT HasTimeElapsed(VULONG StartTime, VINT Seconds);
VINT WriteLog(VINT P_F, VINT B_D, VCHAR *Str1, VCHAR *Str2);
/******************************************************************************
Function: getPhysAddr
Purpose: To determine the physical address of a given pointer
Input: far pointer to a data buffer
Output: Physical address of the pointer
Assumptions: Executable is currently running in DOS real mode.
Restrictions: This function will not work properly unless it is
running in DOS real mode. This does not include
a Windows DOS shell or any other type of DOS
shell running under a protected mode Operating system
Other functions called: none
******************************************************************************/
VULONG getPhysAddr(void far * addr)
{
VULONG seg, off;
seg = FP_SEG(addr); /* get segment of pointer */
off = FP_OFF(addr); /* get offset of pointer */
return ((seg << 4) + off);
}
/******************************************************************************
Function: IORead8
Purpose: To read a byte from an io port
Input: IO address of byte to be read
Output: byte read from io port
Assumptions: That the IO port actually exists
Restrictions: Although IO_Addr is defined as a VULONG it must not
exceed 16 bits in length as this is the maximum
IO address the X86 archtecture can produce
Other functions called: inportb to read the io port
******************************************************************************/
VUBYTE IORead8(VULONG IO_Addr)
{
return (inportb((VUINT) IO_Addr));
}
/******************************************************************************
Function: IOWrite8
Purpose: To write a byte out to an IO port
Input: Value to be written and IO port address
Output: None
Assumptions: That the IO port actually exists
Restrictions: Although IO_Addr is defined as a VULONG it must not
exceed 16 bits in length as this is the maximum
IO address the X86 archtecture can produce
Other functions called: outportb to write to the io port
******************************************************************************/
void IOWrite8(VULONG IO_Addr, VUBYTE value)
{
outportb((VUINT) IO_Addr, value);
}
/******************************************************************************
Function: IORead32
Purpose: To read a dword (32 bits) from an io port
Input: IO address of dword to be read
Output: dword read from io port
Assumptions: That the IO port actually exists
Restrictions: Although IO_Addr is defined as a VULONG it must not
exceed 16 bits in length as this is the maximum
IO address the X86 archtecture can produce
Other functions called: none
******************************************************************************/
VULONG IORead32(VULONG IO_Addr)
{
VULONG result;
asm
{
.386
mov dx, [IO_Addr]
in eax, dx
mov [result], eax
}
return(result);
}
/******************************************************************************
Function: IOWrite32
Purpose: To write a dword (32 bits) out to an IO port
Input: Value to be written and IO port address
Output: None
Assumptions: That the IO port actually exists
Restrictions: Although IO_Addr is defined as a VULONG it must not
exceed 16 bits in length as this is the maximum
IO address the X86 archtecture can produce
Other functions called: none
******************************************************************************/
void IOWrite32(VULONG IO_Addr, VULONG value)
{
asm
{
.386
mov dx, [IO_Addr]
mov eax, [value]
out dx, eax
}
}
/******************************************************************************
Function: ByteAlignBuffer
Purpose: To align a buffer to a given byte alignment
Input: Pointer to buffer to be aligned. Buffer should be 3 bytes
larger than it's desired size.
Desired alignment of the given buffer.
0 = dword (32-bit) aligned
1 = byte (8-bit) aligned
2 = word (16-bit) aligned
3 = 3byte (24-bit) aligned
Output: Pointer to requested buffer alignment. The pointer will
be as close to the buffer start address as possible.
Assumptions: Executable is currently running in DOS real mode.
Restrictions: This function will not work properly unless it is
running in DOS real mode. This does not include
a Windows DOS shell or any other type of DOS
shell running under a protected mode Operating system
Other functions called: FP_SEG to get buffer segment
FP_OFF to get buffer offset
MK_FP to create a new far pointer to the
requested buffer alignment
******************************************************************************/
void far *ByteAlignBuffer(void far *buffer, VINT alignment)
{
VUINT seg;
VUINT off;
seg = FP_SEG(buffer);
off = FP_OFF(buffer) + (((4+alignment) - (FP_OFF(buffer)&0x03)) & 0x03);
return(MK_FP(seg,off));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -