QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1348|回复: 0

如何在SkyEye里面添加新的CPU模拟

[复制链接]
发表于 2006-12-11 01:16:54 | 显示全部楼层 |阅读模式
How to add new SOC to SkyEye   ([email protected])

1.Overview
Before plan to add new SOC simulation to SkyEye, you need to know if the core of the SOC is supported.If not,we probably add more codes to implement some features specific to the core.It is not the case  we describe in this document.We assume the core is supported. Thus we just need to add some codes related to SOC simulation.
The content in the following sections is based on 1.2 version of SkyEye.Something maybe changed in different version of SkyEye.The latest source code of SkyEye can be downloaded in gro.clinux.org.

2.The data structure we need to implement
For support a new SOC simulation we need to implement machine_config_t structure that is defined in utils/config/skyeye_config.h.  The machine_config_t is registered when the simulator first launch and its member function will be called during runtime .
Here is machine_config_t:
    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);
        ARMword (*mach_flash_read_byte) (ARMul_State * state, ARMword addr);
        void (*mach_flash_write_byte) (ARMul_State * state, ARMword addr,
                                       ARMword data);
        ARMword (*mach_flash_read_halfword) (ARMul_State * state,
                                               ARMword addr);
        void (*mach_flash_write_halfword) (ARMul_State * state, ARMword addr,
                                           ARMword data);
          ARMword (*mach_flash_read_word) (ARMul_State * state, ARMword addr);
        void (*mach_flash_write_word) (ARMul_State * state, ARMword addr,
                                       ARMword data);

        /* for I/O device
         * */
        void (*mach_set_intr) (u32 interrupt);  /*set interrupt pending bit */
        int (*mach_pending_intr) (u32 interrupt);       /*test if interrupt is pending. 1: pending */
        void (*mach_update_intr) (void *mach);  /*update interrupt pending bit */

        int (*mach_mem_read_byte) (void *mach, u32 addr, u32 * data);
        int (*mach_mem_write_byte) (void *mach, u32 addr, u32 data);
         void *state;
        struct device_desc **devices;
        int dev_count;
     }machine_config_t;

Furthermore we will describe these members of machine_config_t in the following:
machine_name is just a string to provire an identity of a simulation SOC.

mach_init will be called when SkyEye first launch.It is responsible to initialize some variables related to SOC simulation.

mach_io_do_cycle plays very important role in SkyEye.It is responsible to judge if an external interrupt happen and mach_io_do_cycle will run in every cycle of instruction execution.For the interrupt simulation of timer peripheral ,it will increase or decrease the counter register of timer in every cycle.For the interrupt simulation of uart peripheral, it probabely detects the input of keyboard.When it think some interrupt arrive, mach_io_do_cycle will set some status bit of interrupt register to tell the whole machine which interrupt is coming.

mach_io_reset will be called when software on SkyEye run again. Thus we can avoid re-initializing some data structures that was done in mach_init.

mach_update_int provide a way to update interrupt status of machine.

The following six mach_io_* members and six mach_flash_* members in machine_config_t, is some read/write  functions for various I/O peripheral simulations such as uart ,DMA ,or other peripherals.When some address is accessed when OS run on the SkyEye.SkyEye will judge if the address fall in the address range of IO peripheral.If so, SkyEye will call read/write function of this peripheral to access some registers or memory located in this peripheral.

The rest members is related to simualtion of devices, such as netcard,graphics card etc.These device is common to all the architecture.So in SkyEye, there is a Common Device Simulation Framework that is responsible to split the simulation of machine and the simulation of device.And we can easily to add various existing devices to new SOC simulation by these members.You can read skyeye_device.c file under device directory to know more detail.  

3.Step by Step Instructions.
We give a step-by-step guide describe how to add a new simulation.we assume you want to add lpc2200 simulation to SkyEye
First step
Add a member in arm_machines array in arch/arm/common/arm_arch_interface.c file like the following:
              {"lpc2200", lpc2200_mach_init, NULL, NULL, NULL}
Tell SkyEye the SOC name you want to simulate is "lpc2200". The name of  initializating function is lpc2200_mach_init.
In the same file you need to add an external declaration for lpc2200_mach_init to avoid compilation error. Just like the following line:
extern void lpc2200_mach_init ();

Second step
Add skyeye_mach_lpc2200.c and lpc2200.h files under arch/arm/mach/.In skyeye_mach_lpc2200 file, you need to implement the machine_config_t structure.In lpc2200.h, you can define some macros that be used in skyeye_mach_lpc2200.c file. The better way to do these thing, is to take another implementation of SOC simulation as a template, such as s3c44b0.h and skyeye_mach_s3c44b0.c.

Third step
Modify Makefile under the top directory of SkyEye source package to add your new files.Add your file name to SIM_MACH_OBJS macro:
    SIM_MACH_OBJS = binary/skyeye_mach_at91.o binary/       skyeye_mach_s3c4510b.o                         binary/skyeye_mach_lpc2200.o

Then add a new line in Makefile like the following:
binary/skyeye_mach_lpc2200.o: $(ARM_MACH_PATH)/skyeye_mach_lpc2200.c $(ARM_MACH_PATH)/lpc2200.h
        $(CC)  $(ALL_CFLAGS) -c $< -o $@

Until now we have just finish some basic thing for adds new simulation to SkyEye. Some function in skyeye_mach_lpc2200.c and lpc2200.h need to be implement.Then you need to spend some time to understand simulated SOC by reading hardware manuals. And write code ,debug code, try to run linux or other OS on your new simulation.

You can see, add a new SOC simulation to SkyEye is not a hard thing for an experinced system-level engineer.Maybe just several days or one week.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-23 07:45 , Processed in 0.038192 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表