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

📄 skyeye硬件模拟平台,第三部分 硬件仿真实现之一.htm

📁 你想没有硬件就跑μc OS吗
💻 HTM
📖 第 1 页 / 共 4 页
字号:
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct {
        cpu_config_t *cpu;
        machine_config_t *mach;
        mem_config_t mem;
        net_config_t net[NET_MAXNICNUM_PER_HOST];
        uart_config_t uart;
        log_config_t log;
        ARMword start_address;
	    ARMword no_lcd;
        char config_file[MAX_FILE_NAME];
} skyeye_config_t;
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>skyeye_config_t结构包含了CPU核心配置信息-cpu、开发板配置信息-mach、memory map 
      配置信息-mem、网络芯片和网络环境配置信息-net、面向主机的输入输出配置信息-uart、测试记录输出配置信息-log、模拟执行起始地址配置信息-start_address、是否有LCD-no_lcd和记录文件名信息-config_file。这里面与模拟硬件紧密相关的是CPU核心配置信息、开发板配置信息、memory 
      map 配置信息、网络芯片和网络环境、LCD配置信息。</P>
      <P><A name=IDAKPMKC><SPAN class=atitle3>2. cpu_config_t数据结构 
      </SPAN></A><BR>描述CPU核心的结构定义在cpu_config_t数据结构中,具体内容如下:</P><A 
      name=IDAQPMKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct {
        const char *cpu_arch_name; 
        const char *cpu_name; 
        ARMword cpu_val;
        ARMword cpu_mask; 
        ARMword cachetype;
} cpu_config_t;
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>其具体描述解释如下:</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>cpu_arch_name:描述了arm cpu体系结构的名称,根据ARM 
        CPU内核的发展,其体系结构已经从Version1发展到了Version5,其最新版本为Version5TE。而Intel在其基础上又进行了自己的扩展体系结构StrongARM(基于ARM 
        version4)和XScale(基于ARM 
        version5)。目前SkyEye支持"armv3"、"armv4"、"arm5"、"arm5TE"、"xscale"的体系结构。 
        <LI>cpu_name:描述了具体的arm cpu名称,如arm7TDMI、ARM720T、StrongARM1100/1110、XScale 
        PXA2xx等。目前SkyEye支持"arm710"、"arm7TDMI"、"arm720t"、"sa1100"、"xscale"等。 
        <LI>cpu_val:这是用来表示process id,一般而言每种具体的ARM CPU 都有一个ID,更详细的描述可参考《ARM 
        Architecture Reference Manual》的B2-6。操作系统根据这个ID来识别cpu的类型并执行相关配置。 
        <LI>cpu_mask:这是用来确定process id的屏蔽位数。由于process 
        id中的某些位用于其它目的,并不用来表示具体的CPU类型。实际上操作系统在确定CPU类型时用到的数字是cpu_val&amp;cpu_mask。 

        <LI>cache_type:基于ARM内核的CPU种类繁多,但如果根据CACHE类型来分,可分为三种:无CACHE类型、统一结构CACHE类型和哈佛结构CACHE类型。SkyEye支持这三种类型。统一结构CACHE类型的CPU中,指令和数据共用同一个CACHE;而哈佛结构CACHE类型的CPU中,存在相互独立的数据CACHE和指令CACHE。无CACHE的CPU尺寸比有CACHE的CPU尺寸要小很多,成本上有优势,但在性能上要低于有CACHE的CPU。 
        </LI></UL>
      <P>SkyEye定义了一个cpu_config_t结构的数组(位于skyeye_option.c中),结构如下:</P><A 
      name=IDACIRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
cpu_config_t arm_cpu[] = {
      {"armv3", "arm710",      0x41007100, 0xfff8ff00, DATACACHE},
      {"armv3", "arm7tdmi",   0x41007700, 0xfff8ff00, NONCACHE},
      {"armv4", "arm720t",     0x41807200, 0xffffff00,  DATACACHE},
      {"armv4", "sa1110",       0x6901b110, 0xfffffff0,   INSTCACHE},
      {"armv4", "sa1100",       0x4401a100, 0xffffffe0,   INSTCACHE},
      {"xscale", "xscale",         0x69052100, 0xfffffff0,   INSTCACHE}
};
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P><A name=IDAJIRKC><SPAN class=atitle3>3. 
      machine_config_t数据结构</SPAN></A><BR>machine_config_t结构描述了开发板配置信息,定义在skyeye_config.h中,具体内容如下:</P><A 
      name=IDAPIRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct machine_config{
    const char *machine_name;  
    void (*mach_init)(ARMul_State *state,\
                      struct machine_config *this_mach);
    void (*mach_io_do_cycle)(ARMul_State *state);
    void (*mach_io_reset)(ARMul_State *state);
    void (*mach_update_int)(ARMul_State *state);
    ARMword (*mach_io_read_byte)(ARMul_State *state, ARMword addr);
    void (*mach_io_write_byte)(ARMul_State *state, ARMword addr,\   
                                 ARMword data);
    ARMword (*mach_io_read_halfword)(ARMul_State *state, \
                                           ARMword addr);
    void (*mach_io_write_halfword)(ARMul_State *state, ARMword addr,\
                                     ARMword data);
    ARMword (*mach_io_read_word)(ARMul_State *state, ARMword addr);
    void (*mach_io_write_word)(ARMul_State *state, ARMword addr,\   
                                 ARMword data);} machine_config_t;
}machine_config_t
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>其具体描述解释如下:</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>machine_name:开发板的名称。目前支持的开发板有:atmel的基于AT91X40 CPU的开发板、基于Cirrus Logic 
        ep7312的开发板、基于Intel StrongARM的adsbitsy开发板、基于Intel XScale 
        PXA25x的Lubbock开发板等。 
        <LI>mach_init:开发板初始化配置函数,主要初始化一些与开发板相关的变量和配置mach_io_do_cycyle、mach_io_read/write_byte/halfword/word函数。mach_init函数被wrappe.c中的init函数调用。 

        <LI>mach_io_reset:开发板运行初始化函数。主要初始化与开发板相关的变量。 
        <LI>mach_update_int :定义了与开发板相关的中断处理函数。 
        <LI>mach_io_read/write_*:分别定义与开发板相关的I/O函数。 </LI></UL>
      <P>SkyEye定义了一个machine_config_t结构的数组(位于skyeye_option.c中),结构如下:</P><A 
      name=IDA4IRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
machine_config_t arm_machines[] = {     
      {"at91",              at91_mach_init,          NULL, ......},
      {"ep7312",         ep7312_mach_init,      NULL, ......},
      {"s3c4510b",      s3c4510b_mach_init,  NULL, ......},
      {"s3c44b0",        s3c44b0_mach_init,    NULL, ......},
      {"sa1100",          sa1100_mach_init,      NULL, ......},
      {"pxa_lubbock",  pxa_mach_init,           NULL, ......} …… 
};
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P><A name=IDAFJRKC><SPAN class=atitle3>4. 
      mem_config_t和mem_bank_t数据结构</SPAN></A><BR>SkyEye的内存映射配置结构由mem_config_t和mem_bank_t数据结构描述。ARM体系结构与x86体系结构在I/O内存映射上有所不同。X86体系结构可以使用I/O端口来映射外部设备上的寄存器和设备内存;而ARM体系结构是通过标准的memory地址空间来映射外设的寄存器或设备内存,而且在通常情况下,I/O地址空间不会通过CACHE进行缓存。目前SkyEye支持三种类型的内存映射:ROM 
      SPACE(只读)、RAM SPACE(可读写)、IO 
      SPACE(可读写,与特定开发板相关)。SkyEye对这三种类型的内存映射的处理是不同的。在SkyEye中把一段连续的地址空间称为一个mem_bank,多个mem_bank之间不一定连续。mem_config_t数据结构的具体内容如下:</P><A 
      name=IDALJRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct {
        int bank_num;
        int current_num;
        mem_bank_t mem_banks[MAX_BANK];
} mem_config_t;
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>其中 
      bank_num用来记录当前的硬件配置中的mem_bank总数,current_num是用于解析skyeye.conf中的mem_bank配置信息的一个辅助变量,mem_banks数组具体记录了每个mem_bank的类型和相关的访问函数。mem_bank_t数据结构的具体内容如下:</P><A 
      name=IDATJRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct mem_bank_t {
  ARMword (*read_byte)(ARMul_State *state, ARMword addr);
  void (*write_byte)(ARMul_State *state, ARMword addr, ARMword data);
  ARMword (*read_halfword)(ARMul_State *state, ARMword addr);
  void(*write_halfword)(ARMul_State *state, ARMword addr, ARMword data);
  ARMword (*read_word)(ARMul_State *state, ARMword addr);
  void (*write_word)(ARMul_State *state, ARMword addr, ARMword data);
  unsigned long   addr, len;
  char    filename[MAX_STR];
  unsigned type;
} mem_bank_t;
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>其中的read/write_* 
      函数指针分别对应了不同类型内存映射的访问函数;addr表示mem_bank的起始地址;len表示mem_bank_的大小;filename是binary 
      image文件名;type表示mem_bank的类型。函数指针赋值等配置过程由skyeye_options.c中的函数do_mem_bank_option完成。如果在skyeye.conf中存在binary 
      image文件名,则do_mem_bank_option函数会把文件内容读入到对应的mem_bank中。</P>
      <P><A name=IDA1JRKC><SPAN class=atitle2>5. 
      net_config_t数据结构</SPAN></A><BR>SkyEye支持网络模拟,目前描述网络配置的数据结构是net_config_t,它的具体内容如下:</P><A 
      name=IDABKRKC><B></B></A><BR>
      <TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#cccccc 
        border=1><TBODY>
        <TR>
          <TD><PRE><CODE>
typedef struct {
   int state;
   unsigned char macaddr[6];
   unsigned char  hostip[4]; 
   int ethmod;
   int fd;                     
   int hubindex; 
   int (*net_init)(int index, unsigned char *macaddr, unsigned char *hostip);
   unsigned char (*net_output)(int if_fd, ARMul_State *state,\
                   unsigned char startpage,unsigned short packet_len);
   void  (*net_input)(int if_fd, ARMul_State *state);
}net_config_t;
</CODE></PRE></TD></TR></TBODY></TABLE>
      <P>其中各个field的含义描述如下:</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>state是一个布尔变量,它为1表示网络芯片工作,它为0表示网络芯片不工作。 
        <LI>macaddr用来保存网络芯片的mac地址 
        <LI>hostip用来保存主机上与SkyEye进行网络通信所用的IP地址 
        <LI>ethmod:表示与主机的模拟网络交互的方式;目前定义的交互方式有: 
        <UL>
          <LI>#define NET_MOD_LINUX 0 
          <LI>#define NET_MOD_TUNTAP 1 
          <LI>#define NET_MOD_WIN 2 
          <LI>#define NET_MOD_VNET 3 </LI></UL></LI></UL>
      <P>目前可以使用的两种方式有 NET_MOD_VNET(与SkyEye提供的vnet.o内核模块进行网络交互)和 
      NET_MOD_TUNTAP(与linux的tun.on内核模块进行网络交互)。</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>fd:表示SkyEye用于与主机进行网络交互的设备文件描述符。 
        <LI>hubindex:用于NET_MOD_VNET方式,表示所处的是第几个虚拟hub网段。如果它的值是i,则处于第i个hub网段中。 
        <LI>net_init/net_input/net_output:这三个函数与具体的模拟网络交互方式有关,分别完成初始化操作和与主机网络的输入输出操作。相关的实现在文件skyeye_net_*.c中。 
        </LI></UL>
      <P>有关8019AS模拟芯片(NE2000兼容)的具体配置与实现位于文件skyeye-ne2k.[ch]中。有关网络模拟的具体实现可参考错误!未找到引用源。节。</P>
      <P><A name=IDA0KRKC><SPAN class=atitle3>6. 
      ARMul_State数据结构</SPAN></A><BR>上面讲述的是与SkyEye的硬件配置相关的数据结构,可以理解为一种静态硬件配置的数据结构,这些数据结构中的域基本不随着SkyEye模拟硬件的运行而改变。而ARMul_State描述的是一种动态硬件配置的数据结构,它保存了随着SkyEye模拟硬件的运行而时刻改变的硬件数据。由于ARMul_State中的域数量繁多,大体分为</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>与CPU模拟相关的域 
        <LI>与协处理器模拟相关的域 
        <LI>与内存和MMU/CACHE相关的域
        <UL>
          <LI>与统计相关的域 
          <LI>与具体开发板相关的io部分 </LI></UL></LI></UL>
      <P>这里只描述其中关键的部分:</P>
      <UL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:dw="http://www.ibm.com/developerWorks/">
        <LI>与CPU模拟相关的域 
        <UL>
          <LI>ARMword Reg[16]:CPU当前模式下的寄存器值 
          <LI>ARMword RegBank[7][16]:CPU所有七种模式下的寄存器值 
          <LI>ARMword Cpsr:CPU的当前程序状态寄存器 
          <LI>ARMword Spsr[7]:CPU所有七种模式下的程序状态保存寄存器 
          <LI>ARMdword Accumulator:40bit的累加寄存器,目前用于xscale体系结构中 
          <LI>ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags, Sflag,TFlag:各种状态位 
          <LI>ARMword Bank:CPU对应模式寄存器组的索引值 

⌨️ 快捷键说明

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