📄 gen_tool.c
字号:
/******************************************************************************
Function: CacheAlignBuffer
Purpose: To align a buffer to a given cache alignment
Input: pointer to data buffer to be aligned. Buffer should be a
cache line size larger than the desired buffer size.
The cache line size to be aligned to. This does not have
to be the cache line size of the system.
An offset from the cache line boundary
Output: A pointer to the cache line boundary plus the offset based
on the provided cache line size. The pointer will be as
close to the begining of the buffer 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 *CacheAlignBuffer(void far *buffer, VINT cls, VINT offset)
{
VUINT seg;
VUINT off;
seg = FP_SEG(buffer);
off = FP_OFF(buffer) + (((cls*4+offset) - (FP_OFF(buffer)&(cls*4-1))) & (cls*4-1));
return (MK_FP(seg, off));
}
/******************************************************************************
Function: InitBuffer
Purpose: To initialize a buffer to a known value
Input: Far pointer to a byte data buffer.
The size of the data buffer.
The fill/increment value for the buffer
The operation to be performed on the buffer
0 - fill buffer with fill value
1 - fill buffer with incrementing pattern, increment by
the fill value and start at 0.
2 - fill buffer with random values.
default is to fill buffer with 0's.
Output: Initialized buffer
Assumptions: none
Restrictions: Buffer size cannot exceed 64k
Other functions called: none
******************************************************************************/
void InitBuffer(VUBYTE far *buffer, VUINT size, VINT operation,
VUBYTE fill_val)
{
VUINT i;
switch(operation)
{
case 0x00: for(i=0; i < size; i++) buffer[i] = fill_val;
break;
case 0x01: buffer[0] = 0;
for(i=1; i < size; i++) buffer[i] = buffer[i-1] + fill_val;
break;
case 0x02: for(i=0; i < size; i++) buffer[i] = rand() % fill_val;
break;
default: for(i=0; i < size; i++) buffer[i] = 0;
}
}
/******************************************************************************
Function: Get_Time
Purpose: Gets the current timer tick value from the system bios
data area. The timer ticks 18.2 times every second.
Input: none
Output: Current value of the timer
Assumptions: None
Restrictions: None
Other functions called: MK_FP to create a pointer to the timer tick
memory location
enable to enable interrupts
disable to disable interrupts
******************************************************************************/
VULONG Get_Time(void)
{
VULONG far *timer_ptr;
VULONG time;
/* force ptr to point to timer in bios area */
timer_ptr = MK_FP(0x40, 0x6C);
/* shut off interrupts */
disable();
/* get current time */
time = *timer_ptr;
/* turn interrupts back on */
enable();
return(time);
}
/******************************************************************************
Function: HasTimeElapsed
Purpose: To determine if a given amount of time in seconds has elapsed
Input: A start time for a given time period to be measured
The number of seconds to have elapsed
Output: True (1) if the number of seconds has elapsed
False (0) if not
Assumptions: The system timers is ticking at 18.2 ticks per second.
To reduce complexity the ticks per second is rounded up
to 19. This results in slightly higher actual elapsed
time periods but it is felt this will not pose a
substantial problem as this function will be mainly
used as a watchdog type timer.
Restrictions: None
Other functions called: Get_Time to get the current time.
******************************************************************************/
VINT HasTimeElapsed(VULONG StartTime, VINT Seconds)
{
VULONG CurrentTime;
VULONG ElapsedTime;
CurrentTime = Get_Time();
ElapsedTime = CurrentTime - StartTime;
if (ElapsedTime > Seconds*19) return(1);
else return(0);
}
/******************************************************************************
Function: WriteLog
Purpose: To write a standard string out to an output file. If
the log file is an actual file (not stdout) then the
file is opened appended to and closed to prevent any
loss of information do to some hardware failure.
Input: P_F - indicates a passing or failing log entry
(The macros LOG_PASS and LOG_FAIL in gen_tool.h can be
used for this parameter)
B_D - indicates a basic or detail log entry
(The macros LOG_BASIC and LOG_DETAIL in gen_tool.h can be
used for this parameter)
Str1 - Test name in a basic log entry & entire output string
in a detail entry. This string should not contain a
newline symbol (\n)
Str2 - Parameter list in a basic entry, not used in detail entry
This string should not contain a newline symbol (\n)
logfilename_ptr - This is a global pointer that points to
the name of the log file name. If it is null
then the strings above are written to stdout
Output: Given the two parameter P_F and B_D four different strings
are written to either the log file or stdout or both. The
following chart spells out the variations.
LOG_BASIC, LOG_PASS - "PASS Test:(Str1) Par:(Str2)\n"
LOG_BASIC, LOG_FAIL - "FAIL Test:(Str1) Par:(Str2)\n"
LOG_DETAIL, LOG_PASS - "(Str1)\n"
LOG_DETAIL, LOG_FAIL - "(Str1)\n"
(Note that the final option (DETAIL, FAIL) is written
to both the log file and stderr if necessary, all
other options go to just the log file or stdout)
Assumptions: logfilename_ptr is properly assigned
Restrictions: Str1 and Str2 must not contain the newline symbol (\n)
Other functions called: fopen to open the log file (if not stdout)
fclose to close the log file (if not stdout)
fprintf to print the strings
******************************************************************************/
VINT WriteLog( VINT P_F, VINT B_D, VCHAR *Str1, VCHAR *Str2)
{
FILE *logfile;
if (logfilename_ptr == NULL)
logfile = stdout;
else
logfile = fopen(logfilename_ptr, "at");
/* we open and close the log file on each entry to prevent lost info */
/* in the event of a hang during testing */
if (logfile != NULL)
{
/* Basic or detail */
if (B_D == LOG_BASIC)
{
/* Basic log entry */
/* pass or fail */
if (P_F == LOG_PASS)
fprintf(logfile, "PASS Test:%s Par:%s\n", Str1, Str2);
else
fprintf(logfile, "FAIL Test:%s Par:%s\n", Str1, Str2);
}
else /* Detail log entry */
{
/* A detail passing log entry will go only to the log file */
/* A detail failing log entry will go to stdout and the log file */
/* if it isn't assigned to stdout */
if (P_F == LOG_PASS)
fprintf(logfile, "%s", Str1);
else
{
fprintf(stdout, "%s", Str1);
if (logfile != stdout)
fprintf(logfile, "%s", Str1);
}
}
}
else /* Whoops! */
{
fprintf(stdout, "Error. Can't open log file!!\n");
return(LOG_FAIL);
}
if (logfile != stdout) fclose(logfile);
return(LOG_PASS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -