コード例 #1
0
ファイル: user_main.c プロジェクト: cal101/cal_gdbstub
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
//    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    os_printf("Blinky, SDK version:%s\n", system_get_sdk_version());
    gdb_stub_init();

    // Initialize the GPIO subsystem.
    gpio_init();

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 1000, 1);

    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    gdb_breakpoint();
}
コード例 #2
0
ファイル: wrapper.cpp プロジェクト: embisi-github/embisi_gip
/*f main
 */
extern int main( int argc, char **argv )
{
	int i, okay, gdb_enabled;
	int cycles;
    int r;
    unsigned int regs[16];
    char *symbol_map;
    char *eth_device;
    unsigned int memory_regions[8][3];
    unsigned int execution_regions[8][3];
    file_desc files_to_load [8];
    int nfiles_to_load = 0;
    int must_launch_minicom = 0;
    int use_single_pipeline = 0;

    memset (files_to_load, 0, sizeof(files_to_load));

    /*b Set default values
     */
    for (i=0; i<8; i++)
    {
        memory_regions[i][0] = 0;
        memory_regions[i][1] = 0;
        memory_regions[i][2] = 100;
        execution_regions[i][0] = 0;
        execution_regions[i][1] = 0;
        execution_regions[i][2] = 0;
    }
//	f=stdin;
	cycles=1000;
	gdb_enabled = 0;
    symbol_map = "../../os/linux/System.map";
    eth_device = "eth3";
    for (i=0; i<16; i++)
    {
        regs[i] = 0xdeadcafe;
    }
    
//    tty_fd = run_console ();

//    ether_init(eth_device);
    
    /*b Parse arguments
     */
	for (i=1; i<argc; i++)
	{
        /*b '--'
         */
        if (!strcmp( argv[i], "--" ))
        {
            files_to_load[nfiles_to_load++].fp = stdin;
            continue;
        }
        /*b '-a'
         */
        if (!strcmp( argv[i], "-a" ))
        {
            i++;
            if (i<argc)
            {
                int base;
                if (sscanf( argv[i], "%x", &base)!=1)
                {
                    fprintf( stderr, "Failed to parse '%s' for base address of load\n", argv[i] );
                }
                files_to_load[nfiles_to_load].addr = base;
            }
            continue;
        }
        /*b '-b'
         */
        if (!strcmp( argv[i], "-b" ))
        {
            files_to_load[nfiles_to_load].binary=1;
            continue;
        }
        /*b '-d'
         */
        if (!strcmp( argv[i], "-d" ))
        {
            i++;
            if (i<argc)
            {
                if (sscanf( argv[i], "%d", &debug_level)!=1)
                {
                    fprintf( stderr, "Failed to parse '%s' for debug mask\n", argv[i] );
                }
            }
            continue;
        }
        /*b '-e'
         */
        if (!strcmp( argv[i], "-e" ))
        {
            i++;
            if (i<argc)
            {
                eth_device = argv[i];
            }
            continue;
        }
        /*b '-f'
         */
        if (!strcmp( argv[i], "-f" ))
        {
            i++;
            if (i<argc)
            {
                FILE * fp = fopen(argv[i],"r");
                if (!fp)
                {
                    fprintf( stderr, "Failed to open file '%s'\n", argv[i] );
                }
                files_to_load[nfiles_to_load].name = argv[i];
                files_to_load[nfiles_to_load++].fp = fp;
            }
            continue;
        }
        /*b '-g'
         */
        if (!strncmp (argv[i], "-g", 2))
        {
            gdb_enabled = 1;
            continue;
        }
        /*b '-h'
         */
        if (!strncmp (argv[i], "-h", 2))
        {
            usage();
            exit(0);
        }
        /*b '-r'
         */
        if (!strncmp( argv[i], "-r", 2 ))
        {
            i++;
            if (i<argc)
            {
                if (sscanf( argv[i-1], "-r%d", &r)!=1)
                {
                    fprintf( stderr, "Failed to parse '%s' for register initialization\n", argv[i] );
                }
                regs[r&0xf] = strtoul(argv[i], NULL, 0);
            }
            continue;
        }
        /*b '-s'
         */
        if (!strncmp( argv[i], "-s", 2 ))
        {
            i++;
            if (i<argc)
            {
                symbol_map = argv[i];
            }
            continue;
        }
        /*b '-t'
         */
        if (!strcmp( argv[i], "-t" ))
        {
            i++;
            if (i<argc)
            {
                if (sscanf( argv[i], "%d", &cycles)!=1)
                {
                    fprintf( stderr, "Failed to parse '%s' for length of run\n", argv[i] );
                }
            }
            continue;
        }
        /*b '-S'
         */
        if (!strcmp( argv[i], "-S" ))
        {
            use_single_pipeline=1;
            continue;
        }
        /*b '-M'
         */
        if (!strcmp( argv[i], "-M" ))
        {
            i+=3;
            if (i<argc)
            {
                int j;
                for (j=0; j<8; j++)
                {
                    if (memory_regions[j][2]>4)
                    {
                        break;
                    }
                }
                if (j<8)
                {
                    if ( (sscanf( argv[i-2], "%08x", &memory_regions[j][0])!=1) ||
                         (sscanf( argv[i-1], "%08x", &memory_regions[j][1])!=1) ||
                         (sscanf( argv[i], "%d", &memory_regions[j][2])!=1) )
                    {
                        fprintf( stderr, "Failed to parse arguments (hex start, hex end, int level) for memory tracing\n" );
                    }
                }
            }
            continue;
        }
        /*b '-T'
         */
        if (!strcmp( argv[i], "-T" ))
        {
            i+=3;
            if (i<argc)
            {
                int j;
                if ((sscanf( argv[i-2], "%d", &j )==1) && (j>=0) && (j<8))
                {
                    if ( (sscanf( argv[i-1], "%08x", &execution_regions[j][0])!=1) ||
                         (sscanf( argv[i], "%08x", &execution_regions[j][1])!=1) )
                    {
                        fprintf( stderr, "Failed to parse arguments (region, hex start, hex end) for exec tracing\n" );
                    }
                    else
                    {
                        execution_regions[j][2] = 1;
                    }
                }
            }
            continue;
        }
        /*b '-m'
         */
        if (!strcmp (argv[i], "-m"))
        {
            must_launch_minicom = 1;
        }
        /*b All done
         */
	}

    /*b Connect to system components (console, ethernet)
     */
    tty_fd = run_console();
    if (must_launch_minicom)
        launch_minicom();
    ether_init(eth_device);

    /*b Build system
     */
   	ram = new c_ram_model( 1<<24 ); // Create RAM of size 1<<24 = 16MB
   	memory = new c_memory_model();

    if (0 && use_single_pipeline)
    {
//        c_gip_pipeline_single *gip_single;
//        gip_single = new c_gip_pipeline_single( memory );
//        gip = (c_execution_model_class *)gip_single;
    }
    else
    {
        c_gip_full *gip_full;
        gip_full = new c_gip_full( memory );
        gip = (c_execution_model_class *)gip_full;
    }

   	zero_page_ram = new c_ram_model( 1<<24 ); // Create zero-pagee RAM of size 1<<24 = 16MB
   	mmio = new c_mmio_model( gip ); // Create our standard MMIO model

    zero_page_ram->register_with_memory_map( memory, 0x00000000, 0x10000000 ); // Register zero-page RAM at 0x00000000 to 0xd0000000
    ram->register_with_memory_map( memory, 0xc0000000, 0x10000000 ); // Register RAM at 0xc0000000 to 0xd0000000
    mmio->register_with_memory_map( memory, 0xff000000, 0x00ffffff ); // Register MMIO at 0xff000000 to 0xfffffff
    memory->register_debug_handler( NULL, memory_model_debug );

//    microkernel * ukernel = new microkernel(gip);
//    gip->register_microkernel (ukernel);
    
    /*b Load code and symbols
     */
    for (i = 0; i < nfiles_to_load; i++)
    {
	file_desc * fdp = files_to_load + i;
	if (fdp->binary)
	{
		printf ("Loading binary file '%s' at %08x\n", fdp->name, fdp->addr);
        gip->load_code_binary( fdp->fp, fdp->addr );
	}
	else
	{
		printf ("Loading text file '%s' at %08x\n", fdp->name, fdp->addr);
        gip->load_code( fdp->fp, fdp->addr );
	}
    }
    for (i=0; i<16; i++)
    {
        gip->set_register( i, regs[i] );
    }
    symbol_initialize( symbol_map );

    /*b Set a signal handler
     */
    signal (SIGUSR1, handle_user1);
    signal (SIGUSR2, handle_user2);
    
    /*b Enable memory logging and tracing of GIP
     */
//    memory->set_log_file( "memory_model.log" );
    for (i=0; i<8; i++)
    {
        if (memory_regions[i][2]<4)
        {
            memory->set_log_level( memory_regions[i][0], memory_regions[i][1]-memory_regions[i][0], memory_regions[i][2] );
        }
    }

    gip->trace_set_file( "gip_exec_trace.log" );
    for (i=0; i<8; i++)
    {
        if (execution_regions[i][2])
        {
            gip->trace_region( i, execution_regions[i][0], execution_regions[i][1] ); // Trace execution in main ram
        }
    }

    /*b Initialize GDB server if required
     */
    if (gdb_enabled)
    {
	    printf ("Starting GDB interface...\n");
        gdb_stub_init( gip, memory, mmio );
    }
    else
    {
        gdb_stub_disable();
    }
    
    /*b Run until completion, or forever if under gdb
     */
//    time_to_next_irq = 100000;
    if (gdb_enabled)
    {
        int next_timer = get_ticks() + 1;
        int instruction_count;
        while (1)
        {
            if (sigusr1)
            {
                sigusr1 = 0;
                gdb_trap (5);
            }
            instruction_count = gdb_poll( okay );
            if (instruction_count<=0)
            {
                instruction_count = 100000;
            }

            if (instruction_count > 50) instruction_count = 50;
//            if (instruction_count > time_to_next_irq)
//                instruction_count = time_to_next_irq;
	    
            int actual_count = gip->step( &okay, instruction_count );

//            time_to_next_irq -= actual_count;

//	    if (ether_poll())
//		ukernel->handle_interrupt (2);
	    
//	    if (keyboard_poll ())
//		    ukernel->handle_interrupt (1);
	    
            if (get_ticks() > next_timer)
            {
                next_timer++;
//		    ukernel->handle_interrupt (0);

            }
        }
    }
    else
    {
        int next_timer = get_ticks() + 1;
//	struct timeval tv;
        int instruction_count;
        int actual_count;
        int total_instructions = 0;
        int start_time = get_ticks();
	
        okay = 0;
        while ((cycles>0) && (!okay))
        {
            if (sigusr1)
            {
                sigusr1 = 0;
            }

            instruction_count = cycles;

//            if (instruction_count > time_to_next_irq)
//              instruction_count = time_to_next_irq;
	   
//	    if (instruction_count > 500) instruction_count = 500;
            if (instruction_count > 50) instruction_count = 50;
	    
            actual_count = gip->step( &okay, instruction_count );
            cycles -= actual_count;
            total_instructions += actual_count;
	    
//	    if (ether_poll())
//		    ukernel->handle_interrupt (2);

//	    if (keyboard_poll ())
//		    ukernel->handle_interrupt (1);

            if (get_ticks() > next_timer)
            {
                next_timer++;
//		    ukernel->handle_interrupt (0);

            }
        }
    }

    /*b Done
     */
}