Esempio n. 1
0
int
main (void)
{
  BMI_Model *self = NULL;

  BMI_Initialize (NULL, &self);

  if (!self)
    return EXIT_FAILURE;

  {
    char name[BMI_MAX_COMPONENT_NAME];
    BMI_Get_component_name (self, name);
    fprintf (stdout, "%s\n", name);
  }

  {
    const char **vars = NULL;
    char **var = NULL;
    //char names[BMI_INPUT_VAR_NAME_COUNT][BMI_MAX_VAR_NAME];
    char *names[BMI_INPUT_VAR_NAME_COUNT];


    {
      int i;

      for (i = 0; i<BMI_INPUT_VAR_NAME_COUNT; i++)
        names[i] = (char*) malloc (sizeof (char) * BMI_MAX_VAR_NAME);

      BMI_Get_input_var_names (self, names);
      for (i = 0; i<BMI_INPUT_VAR_NAME_COUNT; i++)
        print_var_info (self, names[i]);

      BMI_Get_output_var_names (self, names);
      for (i = 0; i<BMI_OUTPUT_VAR_NAME_COUNT; i++)
        print_var_info (self, names[i]);
    }
  }

  BMI_Finalize (self);

  return EXIT_SUCCESS;
}
Esempio n. 2
0
struct Surface * open_fb(char * fbdev) {
    struct Surface * sur;
    struct Surface_ScreenFrameBuffer * app;
    
    sur = malloc(sizeof(struct Surface));
    app = malloc(sizeof(struct Surface_ScreenFrameBuffer));
    
    sur->app_reserved = app;
    sur->data = (unsigned char *) MAP_FAILED;
    app->memsize = 0;

    app->fbfd = open(fb_dev, O_RDWR);

    if (app->fbfd < 0) {
        printf("Unable to open '%s': %s\n", fbdev, strerror(errno));
        free(sur);
        free(app);
        return NULL;
    }

    if (ioctl(app->fbfd, FBIOGET_FSCREENINFO, &app->finfo)) {
        printf("IOCTL FBIOGET_FSCREENINFO Failed\n");
        free(sur);
        free(app);
        return NULL;
    }

    if (ioctl(app->fbfd, FBIOGET_VSCREENINFO, &app->vinfo)) {
        printf("IOCTL FBIOGET_VSCREENINFO Failed\n");
        free(sur);
        free(app);
        return NULL;
    }

    print_fixed_info(&app->finfo, fbdev);
    print_var_info(&app->vinfo, fbdev);

    app->memsize = app->finfo.smem_len;
    sur->data = (unsigned char *) mmap(0, app->memsize, PROT_WRITE, MAP_SHARED, app->fbfd, 0);

    if (sur->data == MAP_FAILED) {
        printf("mmap failed\n");
        free(sur);
        free(app);
        return NULL;
    }
    
    sur->x_res = app->vinfo.xres;
    sur->y_res = app->vinfo.yres;
    sur->bits_per_pixel = app->vinfo.bits_per_pixel;
    sur->destroy = &close_fb;

    return sur;
}
Esempio n. 3
0
static void
initialize_fbdev( void )
{
   char ttystr[1000];
   int fd, vtnumber, ttyfd;
   int sz;

   if (geteuid()) {
      fprintf(stderr, "error: you need to be root\n");
      exit(1);
   }

#if 1
   /* open the framebuffer device */
   FrameBufferFD = open("/dev/fb0", O_RDWR);
   if (FrameBufferFD < 0) {
      fprintf(stderr, "Error opening /dev/fb0: %s\n", strerror(errno));
      exit(1);
   }
#endif

   /* open /dev/tty0 and get the vt number */
   if ((fd = open("/dev/tty0", O_WRONLY, 0)) < 0) {
      fprintf(stderr, "error opening /dev/tty0\n");
      exit(1);
   }
   if (ioctl(fd, VT_OPENQRY, &vtnumber) < 0 || vtnumber < 0) {
      fprintf(stderr, "error: couldn't get a free vt\n");
      exit(1);
   }
   close(fd);

   /* open the console tty */
   sprintf(ttystr, "/dev/tty%d", vtnumber);  /* /dev/tty1-64 */
   ConsoleFD = open(ttystr, O_RDWR | O_NDELAY, 0);
   if (ConsoleFD < 0) {
      fprintf(stderr, "error couldn't open console fd\n");
      exit(1);
   }

   /* save current vt number */
   {
      struct vt_stat vts;
      if (ioctl(ConsoleFD, VT_GETSTATE, &vts) == 0)
         OriginalVT = vts.v_active;
   }

   /* disconnect from controlling tty */
   ttyfd = open("/dev/tty", O_RDWR);
   if (ttyfd >= 0) {
      ioctl(ttyfd, TIOCNOTTY, 0);
      close(ttyfd);
   }

   /* some magic to restore the vt when we exit */
   {
      struct vt_mode vt;
      if (ioctl(ConsoleFD, VT_ACTIVATE, vtnumber) != 0)
         printf("ioctl VT_ACTIVATE: %s\n", strerror(errno));
      if (ioctl(ConsoleFD, VT_WAITACTIVE, vtnumber) != 0)
         printf("ioctl VT_WAITACTIVE: %s\n", strerror(errno));

      if (ioctl(ConsoleFD, VT_GETMODE, &vt) < 0) {
         fprintf(stderr, "error: ioctl VT_GETMODE: %s\n", strerror(errno));
         exit(1);
      }

      vt.mode = VT_PROCESS;
      vt.relsig = SIGUSR1;
      vt.acqsig = SIGUSR1;
      if (ioctl(ConsoleFD, VT_SETMODE, &vt) < 0) {
         fprintf(stderr, "error: ioctl(VT_SETMODE) failed: %s\n",
                 strerror(errno));
         exit(1);
      }
   }

   /* go into graphics mode */
   if (ioctl(ConsoleFD, KDSETMODE, KD_GRAPHICS) < 0) {
      fprintf(stderr, "error: ioctl(KDSETMODE, KD_GRAPHICS) failed: %s\n",
              strerror(errno));
      exit(1);
   }


#if 0
   /* open the framebuffer device */
   FrameBufferFD = open("/dev/fb0", O_RDWR);
   if (FrameBufferFD < 0) {
      fprintf(stderr, "Error opening /dev/fb0: %s\n", strerror(errno));
      exit(1);
   }
#endif

   /* Get the fixed screen info */
   if (ioctl(FrameBufferFD, FBIOGET_FSCREENINFO, &FixedInfo)) {
      fprintf(stderr, "error: ioctl(FBIOGET_FSCREENINFO) failed: %s\n",
              strerror(errno));
      exit(1);
   }

   print_fixed_info(&FixedInfo, "Fixed");


  /* get the variable screen info */
   if (ioctl(FrameBufferFD, FBIOGET_VSCREENINFO, &OrigVarInfo)) {
      fprintf(stderr, "error: ioctl(FBIOGET_VSCREENINFO) failed: %s\n",
              strerror(errno));
      exit(1);
   }

   print_var_info(&OrigVarInfo, "Orig Var");

   /* operate on a copy */
   VarInfo = OrigVarInfo;

   /* set the depth, resolution, etc */
   DesiredDepth = 32;
   if (DesiredDepth)
      VarInfo.bits_per_pixel = DesiredDepth;

   if (VarInfo.bits_per_pixel == 16) {
      VarInfo.red.offset = 11;
      VarInfo.green.offset = 5;
      VarInfo.blue.offset = 0;
      VarInfo.red.length = 5;
      VarInfo.green.length = 6;
      VarInfo.blue.length = 5;
      VarInfo.transp.offset = 0;
      VarInfo.transp.length = 0;
   }
   else if (VarInfo.bits_per_pixel == 32) {
      VarInfo.red.offset = 16;
      VarInfo.green.offset = 8;
      VarInfo.blue.offset = 0;
      VarInfo.transp.offset = 24;
      VarInfo.red.length = 8;
      VarInfo.green.length = 8;
      VarInfo.blue.length = 8;
      VarInfo.transp.length = 8;
   }
   /* timing values taken from /etc/fb.modes (1280x1024 @ 75Hz) */
   VarInfo.xres_virtual = VarInfo.xres = 1280;
   VarInfo.yres_virtual = VarInfo.yres = 1024;
   VarInfo.pixclock = 7408;
   VarInfo.left_margin = 248;
   VarInfo.right_margin = 16;
   VarInfo.upper_margin = 38;
   VarInfo.lower_margin = 1;
   VarInfo.hsync_len = 144;
   VarInfo.vsync_len = 3;

   VarInfo.xoffset = 0;
   VarInfo.yoffset = 0;
   VarInfo.nonstd = 0;
   VarInfo.vmode &= ~FB_VMODE_YWRAP; /* turn off scrolling */

   /* set new variable screen info */
   if (ioctl(FrameBufferFD, FBIOPUT_VSCREENINFO, &VarInfo)) {
      fprintf(stderr, "ioctl(FBIOPUT_VSCREENINFO failed): %s\n",
              strerror(errno));
      exit(1);
   }

   print_var_info(&VarInfo, "New Var");

   if (FixedInfo.visual != FB_VISUAL_TRUECOLOR &&
       FixedInfo.visual != FB_VISUAL_DIRECTCOLOR) {
      fprintf(stderr, "non-TRUE/DIRECT-COLOR visuals (0x%x) not supported by this demo.\n", FixedInfo.visual);
      exit(1);
   }

   /* initialize colormap */
   if (FixedInfo.visual == FB_VISUAL_DIRECTCOLOR) {
      struct fb_cmap cmap;
      unsigned short red[256], green[256], blue[256];
      int i;

      /* we're assuming 256 entries here */
      printf("initializing directcolor colormap\n");
      cmap.start = 0;
      cmap.len = 256;
      cmap.red   = red;
      cmap.green = green;
      cmap.blue  = blue;
      cmap.transp = NULL;
      for (i = 0; i < cmap.len; i++) {
         red[i] = green[i] = blue[i] = (i << 8) | i;
      }
      if (ioctl(FrameBufferFD, FBIOPUTCMAP, (void *) &cmap) < 0) {
         fprintf(stderr, "ioctl(FBIOPUTCMAP) failed [%d]\n", i);
      }
   }

   /*
    * fbdev says the frame buffer is at offset zero, and the mmio region
    * is immediately after.
    */

   /* mmap the framebuffer into our address space */
   FrameBuffer = (caddr_t) mmap(0, /* start */
                                FixedInfo.smem_len, /* bytes */
                                PROT_READ | PROT_WRITE, /* prot */
                                MAP_SHARED, /* flags */
                                FrameBufferFD, /* fd */
                                0 /* offset */);
   if (FrameBuffer == (caddr_t) - 1) {
      fprintf(stderr, "error: unable to mmap framebuffer: %s\n",
              strerror(errno));
      exit(1);
   }
   printf("FrameBuffer = %p\n", FrameBuffer);

#if 1
   /* mmap the MMIO region into our address space */
   MMIOAddress = (caddr_t) mmap(0, /* start */
                                FixedInfo.mmio_len, /* bytes */
                                PROT_READ | PROT_WRITE, /* prot */
                                MAP_SHARED, /* flags */
                                FrameBufferFD, /* fd */
                                FixedInfo.smem_len /* offset */);
   if (MMIOAddress == (caddr_t) - 1) {
      fprintf(stderr, "error: unable to mmap mmio region: %s\n",
              strerror(errno));
   }
   printf("MMIOAddress = %p\n", MMIOAddress);

   /* try out some simple MMIO register reads */
   if (1)
   {
      typedef unsigned int CARD32;
      typedef unsigned char CARD8;
#define RADEON_CONFIG_MEMSIZE               0x00f8
#define RADEON_MEM_SDRAM_MODE_REG           0x0158
#define MMIO_IN32(base, offset) \
	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset))
#define INREG(addr)         MMIO_IN32(MMIOAddress, addr)
      int sz, type;
      const char *typeStr[] = {"SDR", "DDR", "64-bit SDR"};
      sz = INREG(RADEON_CONFIG_MEMSIZE);
      type = INREG(RADEON_MEM_SDRAM_MODE_REG);
      printf("RADEON_CONFIG_MEMSIZE = %d (%d MB)\n", sz, sz / 1024 / 1024);
      printf("RADEON_MEM_SDRAM_MODE_REG >> 30 = %d (%s)\n",
             type >> 30, typeStr[type>>30]);
   }
#endif

}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    rvm_scope_t *scope = rvm_scope_create();


    rvm_scope_addstrname(scope, "a1");
    rvm_scope_addstrname(scope, "a");
    rvm_scope_addstrname(scope, "a");
    rvm_scope_addstrname(scope, "ab");
    rvm_scope_addstrname(scope, "abcd");
    rvm_scope_addstrname(scope, "abce");
    rvm_scope_addstrname(scope, "abcf");

    rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 0);
    rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 1);
    rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 2);
    rvm_scope_addpointer(scope, "a5", r_strlen("a5"), &a[5]);
    print_var_info(scope, "a0");
    print_var_info(scope, "a2");
    print_var_info(scope, "a5");


    rvm_scope_push(scope);
    rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 10);
    rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 11);
    rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 12);

    rvm_scope_push(scope);
    rvm_scope_addoffset(scope, "a0", r_strlen("a0"), 101);
    rvm_scope_addoffset(scope, "a1", r_strlen("a1"), 112);
    rvm_scope_addoffset(scope, "a2", r_strlen("a2"), 223);

    print_var_info(scope, "a0");
    print_var_info(scope, "a2");
    print_var_info(scope, "a5");

    rvm_scope_pop(scope);
    print_var_info(scope, "a0");
    print_var_info(scope, "a2");
    print_var_info(scope, "a5");

    rvm_scope_pop(scope);
    print_var_info(scope, "a0");
    print_var_info(scope, "a2");
    print_var_info(scope, "a5");


    rvm_scope_destroy(scope);



    fprintf(stdout, "Max alloc mem: %ld\n", r_debug_get_maxmem());
    fprintf(stdout, "Leaked mem: %ld\n", r_debug_get_allocmem());
    return 0;
}