⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 halsimuv.h

📁 一个免费的SMART CARD OS系统。
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef HALSIMUV__H/* ============================================================================   Project Name : jayaCard   Module Name  : proto/hal/simu/halsimuv.h   Version : $Id: halsimuv.h,v 1.18 2004/01/12 21:18:01 dgil Exp $	Description: Hardware Abstract Layer - VARIABLE SIMULATOR    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.	Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   022303 dgil	wrote it from halsimu.h   030103 dgil	Split memory map type of usage and memory map current usage   100503 dgil	Use real memory placement to have better simulation / required				to functional test the TCL input/output buffer overlapping mode				note: this placement is not working yet for the bit data type   ============================================================================*/#define HALSIMUV__H/* =========================================================================	Keep list of important variables   ========================================================================= */void addSimuVar(char* name,jword pos,jbyte size,jbyte type);void delSimuVar(char* name,jbyte type);void dumpAllSimuVar(int step);#define	RAM_FILE_LIVE	0#ifdef DEBUG#define DUMP_VARIABLES(step)	dumpAllSimuVar(step)#else#define DUMP_VARIABLES(step)#endif/* =========================================================================	Kind of variables   ========================================================================= */#define SIMUVAR_IDATA	0x00#define SIMUVAR_XDATA	0x01#define SIMUVAR_LOCAL	0x02#define SIMUVAR_BDATA	0x03#define SIMUVAR_BLOCAL	0x04/* =========================================================================	IDATA memory map type of usage   ========================================================================= */#define IDATA_USAGE_FREE			0x00#define IDATA_USAGE_BIT				0x01#define IDATA_USAGE_STACK			0x02#define IDATA_USAGE_DATAGROUP		0x03#define IDATA_USAGE_REGISTER		0x04/* =========================================================================	XDATA memory map type of usage   ========================================================================= */#define XDATA_USAGE_FREE			0x00#define XDATA_USAGE_XSTACK			0x02#define XDATA_USAGE_XDATAGROUP		0x03#define XDATA_USAGE_COPROCESSOR		0x04/* =========================================================================	IDATA MEMORY MAP   ========================================================================= */class IDATA {	public:		IDATA() {			LOG_DISABLE("SIMUDATA");	/* by default this module doesn't log */			LOG_DISABLE("SimuVar");	/* by default this module doesn't log */			resetAll(jtrue);		}		void resetAll(jbool bFull) {			for (int i=0;i<256;i++) {				if (bFull) m_mem[i] = 0x55;	/* garbage at initialisation */				m_color[i] = 0x00;	/* not use for now */				/* init usage for a 8051 based component */				if (i<8) {					m_usage[i] = IDATA_USAGE_REGISTER;				} else				if ((i>=ADDR_OF_DATAGROUP) && (i<=(ADDR_OF_DATAGROUP+SIZE_OF_DATAGROUP))) {					m_usage[i] = IDATA_USAGE_DATAGROUP;				} else				if ((i>=ADDR_OF_STACK) && (i<=(ADDR_OF_STACK+SIZE_OF_STACK))) {					m_usage[i] = IDATA_USAGE_STACK;				} else				if ((i>=ADDR_OF_BDATA) & (i<=(ADDR_OF_BDATA+SIZE_OF_BDATA))) {					m_usage[i] = IDATA_USAGE_BIT;				} else {					m_usage[i] = IDATA_USAGE_FREE;				}			}			LOG("SIMUDATA","*** DATA/IDATA/BDATA, DATAGROUP and STACK initialized");		}		void setInUse_BDATA(jword bitadr) {			jword	adr;			jbyte	bit;			jbyte	vbit;			adr = bitadr/8;			if (adr>SIZE_OF_BDATA) {				fprintf(stderr,"*** bit address out of range (%Xh) in BDATA !\n",bitadr);				simu_exit(1);			}			adr = adr + ADDR_OF_BDATA;			bit = bitadr%8;			vbit = 1<<bit;			if ((m_color[adr]&vbit)!=0) {				LOG3("SIMUDATA","*** overlay at bit address %Xh (%Xh.%d)",bitadr,adr,bit);			}			m_color[adr] |= vbit;			if (LOG_ISENABLED("SIMUDATA")) { printf("*** bit address %Xh (%Xh.%d) ",bitadr,adr,bit); }		}		void setInUse_IDATA(jword adr,jbyte nsize) {			if ((adr+nsize)>255) {				fprintf(stderr,"*** address out of range (%Xh) in IDATA !\n",adr+nsize);				simu_exit(1);			}			for (jbyte n=0;n<nsize;n++) {				if (m_usage[adr+n]!=IDATA_USAGE_FREE) {					if (m_usage[adr+n]==IDATA_USAGE_DATAGROUP) {						fprintf(stderr,"*** datagroup conflict at %Xh !\n",adr+n);						simu_exit(1);					}					if (m_usage[adr+n]==IDATA_USAGE_STACK) {						fprintf(stderr,"*** stack conflict at %Xh !\n",adr+n);						simu_exit(1);					}					if (m_usage[adr+n]==IDATA_USAGE_REGISTER) {						fprintf(stderr,"*** register conflict at %Xh !\n",adr+n);						simu_exit(1);					}				}				if (m_color[adr+n]!=0x00) {					/* note: overlay on bit area is possible in our scheme */					LOG1("SIMUDATA","*** overlay at %Xh",adr+n);				}				m_color[adr+n] = 0xFF;			}			if (nsize>1) {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** IDATA %Xh-%Xh ",adr,adr+nsize-1); }			} else {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** IDATA %Xh ",adr); }			}		}		void setInUse_DATAGROUP(jword adr,jbyte nsize) {			if ((adr<ADDR_OF_DATAGROUP) || (((adr+nsize)>(ADDR_OF_DATAGROUP+SIZE_OF_DATAGROUP)))) {				fprintf(stderr,"*** address out of range (%Xh) in IDATA DATAGROUP !\n",adr+nsize);				simu_exit(1);			}			for (jbyte n=0;n<nsize;n++) {				if (m_color[adr+n]!=0x00) {					fprintf(stderr,"*** datagroup conflict at %Xh !\n",adr+n);					simu_exit(1);				}				m_color[adr+n] = 0xFF;			}			if (nsize>1) {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** DATAGROUP %Xh-%Xh ",adr,adr+nsize-1); }			} else {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** DATAGROUP %Xh ",adr); }			}		}		void setFree_BDATA(jword bitadr) {			jword	adr;			jbyte	bit;			jbyte	vbit;			adr = bitadr/8;			if (adr>SIZE_OF_BDATA) {				fprintf(stderr,"*** bit address out of range (%Xh) in BDATA !\n",bitadr);				simu_exit(1);			}			adr = adr + ADDR_OF_BDATA;			bit = bitadr%8;			vbit = 1<<bit;			if ((m_color[adr]&vbit)==0) {				fprintf(stderr,"*** bit address %Xh (%Xh.%d) not in use !\n",bitadr,adr,bit);				simu_exit(1);			}			m_color[adr] &= ~vbit;			if (LOG_ISENABLED("SIMUDATA")) { printf("*** free bit address %Xh (%Xh.%d)",bitadr,adr,bit); }		}		void setFree_DATAGROUP(jword adr,jbyte nsize) {			if ((adr<ADDR_OF_DATAGROUP) || (((adr+nsize)>(ADDR_OF_DATAGROUP+SIZE_OF_DATAGROUP)))) {				fprintf(stderr,"*** address out of range (%Xh) in IDATA DATAGROUP !\n",adr+nsize);				simu_exit(1);			}			for (jbyte n=0;n<nsize;n++) {				if (m_color[adr+n]!=0xFF) {					fprintf(stderr,"*** datagroup conflict at %Xh !\n",adr+n);					simu_exit(1);				}				m_color[adr+n] = 0x00;			}			if (nsize>1) {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** free DATAGROUP %Xh-%Xh",adr,adr+nsize-1); }			} else {				if (LOG_ISENABLED("SIMUDATA")) { printf("*** free DATAGROUP %Xh",adr); }			}		}		jword getFree_IDATA(jbyte nsize) {			jword	n;			jbyte	j;			int		ok;			n=0;			while (n<(256-nsize)) {				ok = 1;				for (j=0;j<nsize;j++) {					if (m_usage[n+j]!=IDATA_USAGE_FREE) { ok= 0; }					if (m_color[n+j]!=0x00) { ok = 0; }				}				if (ok) return n;				n++;			}			fprintf(stderr,"*** can't found space for %d bytes in IDATA global area\n",nsize);			simu_exit(1);			return 0;		}		jword getFree_DATAGROUP(jbyte nsize) {			jword	n;			jbyte	j;			int		ok;			n=ADDR_OF_DATAGROUP;			while (n<(ADDR_OF_DATAGROUP+SIZE_OF_DATAGROUP-nsize)) {				ok = 1;				for (j=0;j<nsize;j++) {					if (m_color[n+j]!=0x00) { ok = 0; }				}				if (ok) return n;				n++;			}			fprintf(stderr,"*** can't found space for %d bytes in DATAGROUP area\n",nsize);			simu_exit(1);			return 0;		}		jword getFree_BDATA() {			jword	n;			n=0;			while (n<(ADDR_OF_BDATA*SIZE_OF_BDATA)) {				jbyte adr = n/8;				jbyte nbit = n%8;				jbyte vbit = 1 << nbit;				adr = adr + ADDR_OF_BDATA;				if ((m_color[adr]&vbit)==0) return n;				n++;			}			fprintf(stderr,"*** can't found space for a bit in BDATA global area\n");			simu_exit(1);			return 0;		}		jbyte*	cells() { return m_mem; }	private:		/* memory cells content */		jbyte	m_mem[256];		/* memory cells type of usage */		jbyte	m_usage[256];		/* =0 free cell, =0xFF inuse cell (because each bit of this byte == bit inuse for the BDATA area) */		jbyte	m_color[256];};#ifdef DEFINEIDATA	gIDATA;#elseextern IDATA	gIDATA;#endif/* =========================================================================	variable inside the IDATA map   ========================================================================= */class idataVar {	public:		idataVar(char * s,int siz) {				name=s; msize=siz;				if (LOG_ISENABLED("SIMUDATA")) { printf("SIMUDATA: idata::init() %s size=%d",name,siz); }				if (msize>0) {					mloc = gIDATA.getFree_IDATA(msize); gIDATA.setInUse_IDATA(mloc,msize);				} else {					mloc = gIDATA.getFree_BDATA(); gIDATA.setInUse_BDATA(mloc);				}				if (siz!=-1) {					addSimuVar(s,mloc,siz,SIMUVAR_IDATA);				} else {					addSimuVar(s,mloc,siz,SIMUVAR_BDATA);				}				if (LOG_ISENABLED("SIMUDATA")) { printf("\n"); }			}		idataVar(jword adr,char * s,int siz) {				name=s; msize=siz; mloc=adr;				if (LOG_ISENABLED("SIMUDATA")) { printf("SIMUDATA: idata::init() %s at 0x%.4X size=%d",name,adr,siz); }				if (msize>0) {					gIDATA.setInUse_IDATA(mloc,msize);				} else {					gIDATA.setInUse_BDATA(mloc);				}				if (siz!=-1) {					addSimuVar(s,mloc,siz,SIMUVAR_IDATA);				} else {					addSimuVar(s,mloc,siz,SIMUVAR_BDATA);				}				if (LOG_ISENABLED("SIMUDATA")) { printf("\n"); }			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -