Esempio n. 1
0
void gc_cleanup(void)
{
  for(int i = 0; i < GCT_SIZEOF_; i++)
    {
#ifndef NDEBUG
      int count;
      char * typename;
      char * t_gfxbuf = "gfxbuf";
      char * t_widget = "widget";
      char * t_cave   = "cave";
      char * t_theme  = "theme";
      char * t_string = "string";
      char * t_image  = "image";
      switch(i)
        {
        case GCT_GFXBUF:    typename = t_gfxbuf; break;
        case GCT_WIDGET:    typename = t_widget; break;
        case GCT_CAVE:      typename = t_cave;   break;
        case GCT_THEME:     typename = t_theme;  break;
        case GCT_STRING:    typename = t_string; break;
        case GCT_IMAGE:     typename = t_image;  break;
        default: assert(0); typename = NULL;     break;
        }
      count = 0;
      for(unsigned int j = 0; j < gcdata[i].stack->size; j++)
        if(gcdata[i].stack->data[j] != NULL)
          {
            char * bt;
            
            printf("GC-%s: not collected %p\n", typename, gcdata[i].stack->data[j]);
            switch(i)
              {
              case GCT_GFXBUF:
#ifdef WITH_OPENGL
                bt = ((struct gfxbuf *) gcdata[i].stack->data[j])->backtrace;
                gfxbuf_dump(gcdata[i].stack->data[j]);
#endif
                break;
              case GCT_WIDGET:
                bt = ((struct widget *) gcdata[i].stack->data[j])->backtrace_;
                widget_dump(gcdata[i].stack->data[j]);
                break;
              case GCT_STRING:
                bt = NULL;
                printf(" string = %s\n", (char *) gcdata[i].stack->data[j]);
                break;
              case GCT_IMAGE:
                bt = ((struct image *) gcdata[i].stack->data[j])->backtrace;
                image_dump(gcdata[i].stack->data[j], 0);
                break;
              case GCT_SIZEOF_:
                bt = NULL;
                break;
              }
            if(bt != NULL)
              printf("Backtrace:\n%s\n", bt);
            
            count++;
          }
      printf("GC-%s: not collected: total %d items\n", typename, count);
#endif

      bool done;

      done = false;
      while(done == false)
        {
          done = true;
          for(unsigned int j = 0; done == false && j < gcdata[i].stack->size; j++)
            if(gcdata[i].stack->data[j] != NULL)
              {
                if(i == GCT_STRING)
                  {
                    free(gcdata[i].stack->data[j]);
                  }
#ifdef WITH_OPENGL
                else if(i == GCT_GFXBUF)
                  {
                    done = false;
                    gfxbuf_free(gcdata[i].stack->data[j]);
                  }
#endif
                gcdata[i].stack->data[j] = NULL;
              }
        }
      gcdata[i].stack = stack_free(gcdata[i].stack);
    }
Esempio n. 2
0
int
main (void)
{
    led_t leds[LEDS_NUM];
    usb_cdc_t usb_cdc;
    int i;

    /* Initialise LEDs.  */
    for (i = 0; i < LEDS_NUM; i++)
	leds[i] = led_init (&leds_cfg[i]);

    led_set (leds[0], 0);
    led_set (leds[1], 0);
    led_set (leds[2], 0);

    usb_cdc = usb_cdc_init ();
    
    sys_redirect_stdin ((void *)usb_cdc_read, usb_cdc);
    sys_redirect_stdout ((void *)usb_cdc_write, usb_cdc);
    sys_redirect_stderr ((void *)usb_cdc_write, usb_cdc);

    tcm8230_init (&cfg);

    /* Wait until USB configured.  */
    while (! usb_cdc_update ())
        continue;

    led_set (leds[0], 1);

    while (1)
    {
        int32_t ret;

        led_set (leds[1], 1);
        while ( tcm8230_frame_ready_p ())
            continue;

        led_set (leds[1], 0);
        while (! tcm8230_frame_ready_p ())
            continue;

        led_set (leds[1], 1);

        ret = tcm8230_capture (image, sizeof(image), 200);

        if (usb_cdc_update ())
        {
            led_set (leds[0], 1);
            led_set (leds[2], 1);

            if (ret < 0)
                fprintf (stderr, "TCM8230 error: %d\r\n", (int)ret);
            else
                image_dump(image, SQCIF_HEIGHT, SQCIF_WIDTH);
            led_set (leds[2], 0);
        }
        else
        {
            /* USB disconnected.  */
            led_set (leds[0], 0);
        }
    }
}
Esempio n. 3
0
File: vm.c Progetto: endeav0r/ravm
int main (int argc, char * argv[]) {
    char * filename = NULL;
    char * output_filename = NULL;
    int opt_god_mode = 0;
    int c;
    int memory_view_offset = VM_MEMORY_SIZE - 32;
    int memory_view_bytes  = 32;
    int print_info = 0;
    int step = 0;
    int error;
    struct _vm * vm;
    
    while ((c = getopt(argc, argv, "b:gi:m:o:sp")) != -1) {
        switch (c) {
            case 'b' :
                memory_view_bytes = strtoul(optarg, NULL, 16);
                break;
            case 'g' :
                opt_god_mode = 1;
                break;
            case 'i' :
                filename = optarg;
                break;
            case 'm' :
                memory_view_offset = strtoul(optarg, NULL, 16);
                break;
            case 'o' :
                output_filename = optarg;
                break;
            case 'p' :
                print_info = 1;
                break;
            case 's' :
                step = 1;
                print_info = 1;
                break;
            case '?' :
                if ((optopt == 'f') || (optopt == 'o')) {
                    fprintf(stderr, "option %c requires argument\n", optopt);
                    exit(0);
                }
                else {
                    fprintf(stderr, "Unknown option: %c\n", optopt);
                    exit(0);
                }
        }
    }
    
    if (filename == NULL) {
        fprintf(stderr, "Usage: %s [-ps] [-o output] -i image\n", argv[0]);
        fprintf(stderr, "Runs an assembled image for the rnp_vm\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "  -b [hex]   BYTES of memory to view in debug output\n");
        fprintf(stderr, "  -g         god mode allows visualization of memory\n");
        fprintf(stderr, "  -i [path]  path to IMAGE\n");
        fprintf(stderr, "  -m [hex]   OFFSET in memory to view in debug output\n");
        fprintf(stderr, "  -o [path]  path to OUTPUT memory dump at HLT\n");
        fprintf(stderr, "  -p         PRINT info at each step\n");
        fprintf(stderr, "  -s         STEP through instruction (implies PRINT)\n");
        exit(0);
    }
    
    vm = (struct _vm *) malloc(sizeof(struct _vm));
    vm_initialize(vm);
    
    if ((error = image_load(vm, filename)) != 0) {
        fprintf(stderr, "error %d\n", error);
        exit(error);
    }
    
    if (opt_god_mode) {
        god_mode(vm);
    }
    else {    
        if (step | print_info)
            vm->step = 1;

        if (print_info) {
            debug_view_memory(vm,
                              memory_view_offset,
                              memory_view_bytes);
            debug_view_registers(vm);
            fflush(stdout);
            printf("%s\n", debug_instruction_description(&(vm->memory[vm->IP])));
            printf("\n");
        }

        while (vm_run(vm)) {
            if (print_info) {
                debug_view_memory(vm,
                                  memory_view_offset,
                                  memory_view_bytes);
                debug_view_registers(vm);
                fflush(stdout);
                printf("%s\n", debug_instruction_description(&(vm->memory[vm->IP])));
                printf("\n");
            }
            if (step) getc(stdin);
        }
    }
    
    if (output_filename != NULL) {
        if ((error = image_dump(vm, output_filename)) != 0) {
            fprintf(stderr, "error dumping memory to file: %d\n", error);
            exit(error);
        }
    }
    
    free(vm);
    
    return 0;
}