simutil.h
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
* simutil.h
*
* Error handling headers for SimOS.
*
* Author: $Author: blythe $
* Date: $Date: 2002/05/29 01:09:09 $
****************************************************************/
#ifndef _UTILITIES_H
#define _UTILITIES_H
#include <stdio.h>
#include <stdlib.h>
#include "simtypes.h"
/*
* Include prototypes for the "standard" bcopy/bzero we use.
*/
#ifdef __svr4__
# include <string.h>
# define bzero(dst,len) memset((char *)dst, 0, len)
# define bcopy(src,dst,len) memcpy((char *)dst, (char *)src, len)
# define bcmp(src,dst,len) memcmp((char *)dst, (char *)src, len)
int getpagesize(void);
#endif /* def __svr4__ */
#if defined(sun) && !defined(__svr4__)
# include <strings.h>
#endif /* def sgi */
#ifdef sgi
# include <bstring.h>
#endif /* def sgi */
extern int GetLineFromFile(FILE *f, char *buf, int bufLen);
extern int GetLog2(int);
extern SimTime NanoSecsToCycles(SimTime);
extern SimTime CyclesToNanoSecs(SimTime);
/* *****************************************************
* Wrappers to deal with %lld vs %ld problems
* *****************************************************/
extern void SubstituteLLx(char *out, const char *text, int maxlen);
/* each of these returns the number of characters copied to the string */
extern int PrintLLD(char *string, int64 val);
extern int PrintLLU(char *string, uint64 val);
extern int PrintLLX(char *string, int64 val);
/* **************************************************************
* TimeDelay: uniform way of handling averages and std deviations
* **************************************************************/
typedef struct TimeDelay {
uint count,zerocount;
SimTime total,min,max;
uint64 total2;
} TimeDelay;
extern void SaveTimeDelay(TimeDelay *t,SimTime delay);
extern void PrintTimeDelay(FILE *f, char *s, TimeDelay *t);
/*
* Simulator memory allocation routines:
* MALLOC to be used for conventionnal malloc/free data stuctures
* ZMALLOC bzeros the allocated region on top of that
*
*/
#define MALLOC(_size, _name) malloc((_size))
#define ZMALLOC(_size,_name) calloc(1,(_size))
#if defined(SIMOS_PURE)
#define ZALLOC_PERM(_size,_name) ZMALLOC((_size),_name)
#else
#define ZALLOC_PERM(_size,_name) AllocZeroMem(_size,_name)
#endif
/* ********************************************************************
* MallocShared can only be called before the processes are forked. It is
* called by the original process to allocated shared backdoor space.
* **********************************************************************/
void *MallocShared(unsigned nbytes, char *name);
/* ********************************************************************
* SaveString. Save the string parameter into the private space.
* **********************************************************************/
char *SaveString(char *string);
/* ********************************************************************
* MemAlign. Allocate memory that is aligned
* ********************************************************************/
void *MemAlign(int alignment,int size);
/* ********************************************************************
* AllocZeroMem. Allocates initialized memory that is permanently
* needed, ie, that will never be freed.
* **********************************************************************/
void *AllocZeroMem(int size, char *name);
void InitZeroMem(char * startAddr,char * endAddr,int redzone);
/* ********************************************************************
* StripPath. Return the name of the file.
* **********************************************************************/
char *StripPath(char *string);
/*****************************************************************
* Dump the real-life time for simulation timing purposes
****************************************************************/
void PrintRealTime(char *string);
void toLowerStr(char *dest, char *src);
void toUpperStr(char *dest, char *src);
/*
* MakeFile
*/
extern int MakeFile(char *directoryname,
char *filename, int length, int unlinkit);
#endif