Beispiel #1
0
void *
xrealloc (void *p, size_t n)
{
#ifdef XMALLOC_DEBUG
        void    *array[1 + XMALLOC_DEPTH];
        size_t   s;
        char   **strings;
#endif
        void *result;

        if (p == 0)
                return xmalloc (n);
        if (n == 0)
                return NULL;
        result = realloc (p, n);

#ifdef XMALLOC_DEBUG
        if (fp){
                s       = backtrace (array, 1 + XMALLOC_DEPTH);
                strings = backtrace_symbols (array, s);

                dump_info (strings, s, '<', p, 0);
                dump_info (strings, s, '>', result, n);

                free (strings);
        }                
#endif  
  
        if (result == NULL)
                error (EXIT_FAILURE, errno, "realloc");
        return result;
}
Beispiel #2
0
CPUThread::CPUThread(CPUThreadType type, const std::string& name, std::function<std::string()> thread_name)
	: m_id(idm::get_last_id())
	, m_type(type)
	, m_name(name)
{
	start(std::move(thread_name), [this]
	{
		g_tls_current_cpu_thread = this;

		Emu.SendDbgCommand(DID_CREATE_THREAD, this);

		std::unique_lock<std::mutex> lock(mutex);

		// check thread status
		while (joinable() && is_alive())
		{
			CHECK_EMU_STATUS;

			// check stop status
			if (!is_stopped())
			{
				if (lock) lock.unlock();

				try
				{
					task();
				}
				catch (CPUThreadReturn)
				{
					;
				}
				catch (CPUThreadStop)
				{
					m_state |= CPU_STATE_STOPPED;
				}
				catch (CPUThreadExit)
				{
					m_state |= CPU_STATE_DEAD;
					break;
				}
				catch (...)
				{
					dump_info();
					throw;
				}

				m_state &= ~CPU_STATE_RETURN;
				continue;
			}

			if (!lock)
			{
				lock.lock();
				continue;
			}

			cv.wait(lock);
		}
	});
}
Beispiel #3
0
char *
xstrdup (const char *str)
{
#ifdef XMALLOC_DEBUG
        void    *array[1 + XMALLOC_DEPTH];
        size_t   s;
        char   **strings;
#endif
        char *p;

        if (str == NULL)
                return NULL;
        p = strdup (str);

#ifdef XMALLOC_DEBUG
        if (fp){
                s       = backtrace (array, 1 + XMALLOC_DEPTH);
                strings = backtrace_symbols (array, s);

                dump_info (strings, s, '+', p, strlen (str));

                free (strings);
        }
#endif  

        if (p == NULL)
                error (EXIT_FAILURE, errno, "strdup");
        return p;
}
Beispiel #4
0
void *
xcalloc (size_t n, size_t s)
{
#ifdef XMALLOC_DEBUG
        void    *array[1 + XMALLOC_DEPTH];
        size_t   cnt;
        char   **strings;
#endif
        void *p;

        if (n == 0 || s == 0)
                return NULL;
        p = calloc (n, s);

#ifdef XMALLOC_DEBUG
        if (fp){
                cnt     = backtrace (array, 1 + XMALLOC_DEPTH);
                strings = backtrace_symbols (array, cnt);

                dump_info (strings, cnt, '+', p, n * s);

                free (strings);
        }
#endif
  
        if (p == NULL)
                error (EXIT_FAILURE, errno, "calloc");
        return p;
}
Beispiel #5
0
void *
xmalloc (size_t n)
{
#ifdef XMALLOC_DEBUG
        void    *array[1 + XMALLOC_DEPTH];
        size_t   s;
        char   **strings;
#endif
        void *p;

        if (n == 0)
                return NULL;
        p = malloc (n);

#ifdef XMALLOC_DEBUG
        if (fp){
                s       = backtrace (array, 1 + XMALLOC_DEPTH);
                strings = backtrace_symbols (array, s);

                dump_info (strings, s, '+', p, n);

                free (strings);
        }
#endif
  
        if (p == NULL)
                error (EXIT_FAILURE, errno, "malloc");
        return p;
}
Beispiel #6
0
END_TEST

START_TEST (test_youtube_play_audio_search)
{
  tiz_youtube_t *p_youtube = NULL;
  int rc = tiz_youtube_init (&p_youtube);
  int i = 0;
  ck_assert (0 == rc);
  ck_assert (p_youtube != NULL);

  rc = tiz_youtube_play_audio_search (p_youtube, YOUTUBE_SEARCH_TERM);
  ck_assert (0 == rc);

  while (i < 5)
  {
    const char *next_url = tiz_youtube_get_next_url (p_youtube, false);
    fprintf (stderr, "url = %s\n", next_url);
    ck_assert (next_url != NULL);

    dump_info(p_youtube);
    play_track(next_url);
    ++i;
 }

  tiz_youtube_destroy (p_youtube);
}
Beispiel #7
0
void Dump_specific_section( uint sect, const uint_8 *data, uint len )
/*******************************************************************/
{
    sort_tables();
    switch( sect ) {
    case DW_DEBUG_ABBREV:
          dump_abbrevs( data, len );
        break;
    case DW_DEBUG_INFO:
        dump_info( data, len );
        break;
    case DW_DEBUG_ARANGES:
          dump_aranges( data, len );
        break;
    case DW_DEBUG_LINE:
          Dump_lines( data, len );
        break;
    case DW_DEBUG_REF:
          dump_ref( data, len );
        break;
    case DW_DEBUG_PUBNAMES:
          dump_pubnames( data, len );
        break;
    default:
        dump_hex( data, len );
        break;
    }
}
Beispiel #8
0
static void init_header(void)
{
	memset(&swsusp_info,0,sizeof(swsusp_info));
	swsusp_info.version_code = LINUX_VERSION_CODE;
	swsusp_info.num_physpages = num_physpages;
	memcpy(&swsusp_info.uts,&system_utsname,sizeof(system_utsname));

	swsusp_info.suspend_pagedir = pagedir_nosave;
	swsusp_info.cpus = num_online_cpus();
	swsusp_info.image_pages = nr_copy_pages;
	dump_info();
}
Beispiel #9
0
void map_client(client_t *c)
{
    XWindowAttributes attr;
    strut_t s = { 0, 0, 0, 0 };
    XWMHints *hints;
    int btn, want_raise = 1;

    XGrabServer(dpy);

    XGetWindowAttributes(dpy, c->win, &attr);
    collect_struts(c, &s);

    if (attr.map_state == IsViewable) {
        c->ignore_unmap++;
        reparent(c, &s);
        if (get_wm_state(c->win) == IconicState) {
            c->ignore_unmap++;
            XUnmapWindow(dpy, c->win);
        } else {
            set_wm_state(c, NormalState);
            do_map(c, want_raise);
        }
    } else {
        if ((hints = XGetWMHints(dpy, c->win))) {
            if (hints->flags & StateHint)
                set_wm_state(c, hints->initial_state);
            XFree(hints);
        } else {
            set_wm_state(c, NormalState);
        }
        if (!init_geom(c, &s) && opt_imap) {
            btn = sweep(c, map_curs, recalc_map, SWEEP_DOWN, &s);
            if (btn == Button2)
                btn = sweep(c, resize_curs, recalc_resize, SWEEP_UP, &s);
            if (btn == Button3)
                want_raise = 0;
        }
#ifdef DEBUG
        dump_geom(c, "set to");
        dump_info(c);
#endif
        reparent(c, &s);
        if (get_wm_state(c->win) == NormalState)
            do_map(c, want_raise);
    }

    XSync(dpy, False);
    c->name = get_wm_name(c->win); // horrible kludge
    XUngrabServer(dpy);
}
Beispiel #10
0
static int close_swap(void)
{
	swp_entry_t entry;
	int error;

	dump_info();
	error = write_page((unsigned long)&swsusp_info, &entry);
	if (!error) { 
		printk( "S" );
		error = mark_swapfiles(entry);
		printk( "|\n" );
	}
	return error;
}
Beispiel #11
0
void main(int argc, char* argv[]) {
    int c;
    for (;;) {
        c = getopt( argc, argv, "fi");
        if (c == EOF) break;
        switch (c) {
            case 'f':
                dryrun = 0;
                break;
            case 'i':

                break;
            default:  // show usage
                usage(argv[0]);
                exit(1);
        }
    }


    i2c_init();
    dump_info();

    if(dryrun) {
        close(i2c_fd);
        return;
    }

    FILE* file = fopen(FW_FILE, "r");
    if(file==NULL) {
        printf("open file failed\n");
        return;
    }

    confirm_sealed();
    enter_rom_mode();

    char buf[8] = {0};
    while(!feof(file)) {
        fscanf(file, "%s", buf); 

        parseData(buf);
    }

    exit_rom_mode();

    close(i2c_fd);
    fclose(file);
    return;
}
Beispiel #12
0
void show_person() {
	char *first_name=NULL, *last_name=NULL, *string;
	printf("First name:\n>");
	scanf("%m[^\n]", &first_name);
	getchar();
	if(!first_name)
		return;
	printf("Last name:\n>");
	scanf("%m[^\n]", &last_name);
	getchar();
	if(last_name)
		dump_info(first_name, last_name, stdout);
	free(first_name);
	free(last_name);
}
Beispiel #13
0
static void do_walk(struct gbr_dump_context *dump_ctx,
		    const char *remote, const git_oid *o1, const git_oid *o2)
{
	struct gbr_sha sha;
	struct gbr_walk_context *ctx;

	if (git_oid_cmp(o1, o2) == 0) {
		/* Skip the costly walking */
		dump_info(remote, gbr_sha(&sha, o2, dump_ctx->abbrev), 0, 0);
		dump_ctx->uptodate_remotes++;
		return;
	}

	ctx = gbr_walk_init(dump_ctx->repo, o1, o2);
	if (ctx == NULL) {
		return;
	}


	/* Walk from the base down towards the head of each commit and
	 * note when they start diverging.
	 */
	while (gbr_walk_next(ctx) != 0) {
		;
	}

	dump_info(remote, gbr_sha(&sha, o2, dump_ctx->abbrev),
		  ctx->count[0], ctx->count[1]);

	gbr_walk_free(ctx);

	if (ctx->count[0] == 0) {
		/* 0 Diverging commits here. */
		dump_ctx->uptodate_remotes++;
	}
}
Beispiel #14
0
void channel_table_parse_process(void)
{
  if((p_table->version != sys_status_get_channel_version())&&
              (p_table->total_node_num > 0))
  {
     CH_DBG("###channel_table_parse_process!\n");
     sys_status_reset_channel_and_nit_version();/***make sure next start up can auto scan*****/
     ui_dbase_delete_all_pg(); 
     db_dvbs_restore_to_factory(PRESET_BLOCK_ID);

    sys_group_reset();
    sys_status_check_group();
    sys_status_save();
    dump_info(p_table);
    save_prog(p_table);
    sys_status_set_channel_version((u8)p_table->version);
  }
    
}
Beispiel #15
0
static const char * __init sanity_check(void)
{
	dump_info();
	if(swsusp_info.version_code != LINUX_VERSION_CODE)
		return "kernel version";
	if(swsusp_info.num_physpages != num_physpages)
		return "memory size";
	if (strcmp(swsusp_info.uts.sysname,system_utsname.sysname))
		return "system type";
	if (strcmp(swsusp_info.uts.release,system_utsname.release))
		return "kernel release";
	if (strcmp(swsusp_info.uts.version,system_utsname.version))
		return "version";
	if (strcmp(swsusp_info.uts.machine,system_utsname.machine))
		return "machine";
	if(swsusp_info.cpus != num_online_cpus())
		return "number of cpus";
	return NULL;
}
Beispiel #16
0
PUBLIC static
void
Apic::init_ap()
{
    dump_info();
    // set some interrupt vectors to appropriate values
    init_lvt();

    // initialize APIC_spiv register
    init_spiv();

    // initialize task-priority register
    init_tpr();

    disable_external_ints();

    // get timer going on this CPU
    timer_set_divisor(1);
    enable_errors();
}
Beispiel #17
0
void
xfree (void *ptr)
{
#ifdef XMALLOC_DEBUG
        void    *array[1 + XMALLOC_DEPTH];
        size_t   s;
        char   **strings;
#endif

        free (ptr);
  
#ifdef XMALLOC_DEBUG
        if (fp){
                s       = backtrace (array, 1 + XMALLOC_DEPTH);
                strings = backtrace_symbols (array, s);

                dump_info (strings, s, '-', ptr, 0);

                free (strings);
        }  
#endif
}
/**
 * Detect any direct relationship between the output color
 */
void
lp_build_tgsi_info(const struct tgsi_token *tokens,
                   struct lp_tgsi_info *info)
{
   struct tgsi_parse_context parse;
   struct analysis_context ctx;
   unsigned index;
   unsigned chan;

   memset(info, 0, sizeof *info);

   tgsi_scan_shader(tokens, &info->base);

   memset(&ctx, 0, sizeof ctx);
   ctx.info = info;

   tgsi_parse_init(&parse, tokens);

   while (!tgsi_parse_end_of_tokens(&parse)) {
      tgsi_parse_token(&parse);

      switch (parse.FullToken.Token.Type) {
      case TGSI_TOKEN_TYPE_DECLARATION:
         break;

      case TGSI_TOKEN_TYPE_INSTRUCTION:
         {
            struct tgsi_full_instruction *inst =
                  &parse.FullToken.FullInstruction;

            if (inst->Instruction.Opcode == TGSI_OPCODE_END ||
                inst->Instruction.Opcode == TGSI_OPCODE_BGNSUB) {
               /* We reached the end of main function body. */
               goto finished;
            }

            analyse_instruction(&ctx, inst);
         }
         break;

      case TGSI_TOKEN_TYPE_IMMEDIATE:
         {
            const unsigned size =
                  parse.FullToken.FullImmediate.Immediate.NrTokens - 1;
            assert(size <= 4);
            if (ctx.num_imms < Elements(ctx.imm)) {
               for (chan = 0; chan < size; ++chan) {
                  float value = parse.FullToken.FullImmediate.u[chan].Float;
                  ctx.imm[ctx.num_imms][chan] = value;

                  if (value < 0.0f || value > 1.0f) {
                     info->unclamped_immediates = TRUE;
                  }
               }
               ++ctx.num_imms;
            }
         }
         break;

      case TGSI_TOKEN_TYPE_PROPERTY:
         break;

      default:
         assert(0);
      }
   }
finished:

   tgsi_parse_free(&parse);


   /*
    * Link the output color values.
    */

   for (index = 0; index < PIPE_MAX_COLOR_BUFS; ++index) {
      const struct lp_tgsi_channel_info null_output[4];
      info->cbuf[index] = null_output;
   }

   for (index = 0; index < info->base.num_outputs; ++index) {
      unsigned semantic_name = info->base.output_semantic_name[index];
      unsigned semantic_index = info->base.output_semantic_index[index];
      if (semantic_name == TGSI_SEMANTIC_COLOR &&
          semantic_index < PIPE_MAX_COLOR_BUFS) {
         info->cbuf[semantic_index] = info->output[index];
      }
   }

   if (gallivm_debug & GALLIVM_DEBUG_TGSI) {
      dump_info(tokens, info);
   }
}
Beispiel #19
0
client_t *new_client(Window w)
{
    client_t *c;
    XWindowAttributes attr;
    XColor exact;
    long supplied;
    Atom win_type;

    c = malloc(sizeof *c);
    c->next = head;
    head = c;

    c->name = get_wm_name(w);
    c->win = w;
    c->frame = None;
    c->size.flags = 0;
    c->ignore_unmap = 0;
#ifdef SHAPE
    c->shaped = 0;
#endif
    c->shaded = 0;
    c->zoomed = 0;
    c->decor = 1;

    XGetWMNormalHints(dpy, c->win, &c->size, &supplied);
    XGetTransientForHint(dpy, c->win, &c->trans);

    XGetWindowAttributes(dpy, c->win, &attr);
    c->geom.x = attr.x;
    c->geom.y = attr.y;
    c->geom.w = attr.width;
    c->geom.h = attr.height;
    c->cmap = attr.colormap;
    c->old_bw = attr.border_width;

#ifdef DEBUG
    dump_name(c, "creating", 'w');
    dump_geom(c, "initial");
#endif

    XAllocNamedColor(dpy, c->cmap, opt_fg, &fg, &exact);
    XAllocNamedColor(dpy, c->cmap, opt_bg, &bg, &exact);
    XAllocNamedColor(dpy, c->cmap, opt_bd, &bd, &exact);

    if (get_atoms(c->win, net_wm_wintype, XA_ATOM, 0, &win_type, 1, NULL))
        c->decor = HAS_DECOR(win_type);

    if (get_atoms(c->win, net_wm_desk, XA_CARDINAL, 0, &c->desk, 1, NULL)) {
        if (c->desk == -1) c->desk = DESK_ALL; /* FIXME */
        if (c->desk >= ndesks && c->desk != DESK_ALL)
            c->desk = cur_desk;
    } else {
        set_atoms(c->win, net_wm_desk, XA_CARDINAL, &cur_desk, 1);
        c->desk = cur_desk;
    }
#ifdef DEBUG
    dump_info(c);
#endif

    check_states(c);

    /* We are not actually keeping the stack one in order. However, every
     * fancy panel uses it and nothing else, no matter what the spec says.
     * (I'm not sure why, as rearranging the list every time the stacking
     * changes would be distracting. GNOME's window list applet doesn't.) */
    append_atoms(root, net_client_list, XA_WINDOW, &c->win, 1);
    append_atoms(root, net_client_stack, XA_WINDOW, &c->win, 1);

    return c;
}
/**
 * \brief Application entry point.
 *
 * Configure USART in synchronous master/slave mode to start a transmission
 * between two boards.
 * \return Unused.
 */
int main(void)
{
	uint8_t uc_char;
	uint8_t *p_data;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Display main menu. */
	display_main_menu();

	/* Configure USART. */
	configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);

	g_uc_transfer_mode = SYNC_MASTER;

	g_uc_state = STATE_WRITE;

	puts("-- USART in MASTER mode --\r");

	while (1) {
		uc_char = 0;
		scanf("%c", (char *)&uc_char);
		switch (uc_char) {
		case '0':
		case '1':
		case '2':
		case '3':
			g_uc_freq_idx = uc_char - '0';
			printf("-- The clock freq is: %luHz.\r\n",
				(unsigned long)g_ul_freq[g_uc_freq_idx]);
			configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);
			break;
		case 'i':
		case 'I':
			if (g_uc_transfer_mode == SYNC_MASTER) {
				printf("-- USART is MASTER at %luHz.\r\n",
					(unsigned long)g_ul_freq[g_uc_freq_idx]);
			} else {
				puts("-- USART is SLAVE \r");
			}
			break;
		case 's':
		case 'S':
			if (g_uc_transfer_mode == SYNC_MASTER) {
				g_uc_transfer_mode = SYNC_SLAVE;
				configure_usart(SYNC_SLAVE, g_ul_freq[g_uc_freq_idx]);
				puts("-- USART in SLAVE mode --\r");
			} else {
				if (g_uc_transfer_mode == SYNC_SLAVE) {
					g_uc_transfer_mode = SYNC_MASTER;
					configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);
					puts("-- USART in MASTER mode --\r");
				}
			}
			break;
		case 'w':
		case 'W':
			g_uc_state = STATE_WRITE;
			p_data = (uint8_t *)&tran_buff[0];
			transmit_mode_sync(p_data, BUFFER_SIZE);

			while (!g_ul_sent_done) {
			}
			if (g_ul_sent_done) {
				printf("-- %s sent done --\r\n",
						g_uc_transfer_mode ? "MASTER" :
						"SLAVE");
			}
			break;
		case 'r':
		case 'R':
			g_uc_state = STATE_READ;
			g_ulcount = 0;
			p_revdata = &g_c_recv_buff[0];
			if (g_uc_transfer_mode == SYNC_MASTER) {
				puts("----USART MASTER Read----\r");
			} else {
				puts("----USART SLAVE Read----\r");
			}

			usart_enable_interrupt(BOARD_USART, US_IER_RXRDY);

			while (!g_ul_recv_done) {
			}
			if (g_ul_recv_done) {
				if (strncmp((char*)g_c_recv_buff, tran_buff, BUFFER_SIZE)) {
					puts(" -F-: Failed!\r");
				} else {
					/* successfully received */
					dump_info((char*)g_c_recv_buff, BUFFER_SIZE);
				}
				puts("----END of read----\r");
				memset(g_c_recv_buff, 0, sizeof(g_c_recv_buff));
				g_ul_recv_done = false;
			}
			break;
		case 'm':
		case 'M':
			display_main_menu();
			break;
		default:
			break;
		}
	}
}
Beispiel #21
0
void go_cl(config c)
{
    cl_int error;
    cl_platform_id platform;
    cl_device_id device;
    cl_context context;
    cl_command_queue commands;
    cl_program program;
    cl_kernel kernel;
    cl_event ev;
    cl_mem mem;
    float *result = NULL;
    char buf[256];
    int work_size[2] = { 128, 128 };
    int offset[2];
    int x, y;

    cl_float4 camera_pos = { c.camera_pos.x, c.camera_pos.y, c.camera_pos.z, 0 };
    cl_float4 camera_dir = { 
        c.camera_target.x - c.camera_pos.x, 
        c.camera_target.y - c.camera_pos.y, 
        c.camera_target.z - c.camera_pos.z, 
        0 };
    cl_float4 light_pos = { c.light_pos.x, c.light_pos.y, c.light_pos.z, 0 };
    cl_int2 image_size = { c.width, c.height };

    sprintf(buf, "-DBAILOUT=%d -DSCALE=%f -DFOV=%f", c.bailout, c.scale, c.fov);

    printf("Starting\n");

    init_cl(&platform, &device, &context, &commands);

    dump_info(platform, device);

    printf("Creating kernel\n");

    program = load_program_from_file("kernel.cl", context, device, buf);
    kernel = create_kernel(program, "test");

    printf("Setting memory\n");

    mem = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(float) * c.width * c.height, NULL, &error);
    check_error(error, "Could not allocate buffer");
    error = clSetKernelArg(kernel, 0, sizeof(cl_mem), &mem);
    error = clSetKernelArg(kernel, 1, sizeof(cl_float4), &camera_pos);
    error = clSetKernelArg(kernel, 2, sizeof(cl_float4), &camera_dir);
    error = clSetKernelArg(kernel, 3, sizeof(cl_float4), &light_pos);
    error = clSetKernelArg(kernel, 4, sizeof(cl_int2), &image_size);

    clFinish(commands);

    printf("Running\n");

    for (x = 0; x < c.width; x += work_size[0])
    {
        for (y = 0; y < c.height; y += work_size[1])
        {
            offset[0] = x;
            offset[1] = y;
            error = clEnqueueNDRangeKernel(commands, kernel, 2, offset, work_size, NULL, 0, NULL, &ev);
            printf(".");
        }
    }

    clFinish(commands);

    printf("\nWriting image\n");

    result = malloc(sizeof(float) * c.width * c.height);
    error = clEnqueueReadBuffer(commands, mem, CL_TRUE, 0, sizeof(float) * c.width * c.height, result, 0, NULL, &ev);

    clFinish(commands);

    save(result, c, 0, 0);

    free(result);
    clReleaseMemObject(mem);
    release_cl(context, program, commands, kernel);
}
Beispiel #22
0
int
ubigen_create(ubi_info_t* u, uint32_t vol_id, uint8_t vol_type,
	      uint32_t eb_size, uint64_t ec, uint32_t alignment,
	      uint8_t version, uint32_t vid_hdr_offset, uint8_t compat_flag,
	      size_t data_size, FILE* fp_in, FILE* fp_out)
{
	int rc = 0;
	ubi_info_t res = NULL;
	uint32_t crc;
	uint32_t data_offset;

	if (alignment == 0) {
		rc = EUBIGEN_INVALID_ALIGNMENT;
		goto ubigen_create_err;
	}
	if ((fp_in == NULL) || (fp_out == NULL)) {
		rc = -EINVAL;
		goto ubigen_create_err;
	}

	res = (ubi_info_t) calloc(1, sizeof(struct ubi_info));
	if (res == NULL) {
		rc = -ENOMEM;
		goto ubigen_create_err;
	}

	res->v = (struct ubi_vid_hdr*) calloc(1, sizeof(struct ubi_vid_hdr));
	if (res->v == NULL) {
		rc = -ENOMEM;
		goto ubigen_create_err;
	}

	res->ec = (struct ubi_ec_hdr*) calloc(1, sizeof(struct ubi_ec_hdr));
	if (res->ec == NULL) {
		rc = -ENOMEM;
		goto ubigen_create_err;
	}

	/* data which is needed in the general process */
	vid_hdr_offset = vid_hdr_offset ? vid_hdr_offset : DEFAULT_VID_OFFSET;
	data_offset = vid_hdr_offset + UBI_VID_HDR_SIZE;
	res->bytes_total = data_size;
	res->eb_size = eb_size ? eb_size : DEFAULT_BLOCKSIZE;
	res->data_pad = (res->eb_size - data_offset) % alignment;
	res->leb_size = res->eb_size - data_offset - res->data_pad;
	res->leb_total = byte_to_blk(data_size, res->leb_size);
	res->alignment = alignment;

	if ((res->eb_size < (vid_hdr_offset + UBI_VID_HDR_SIZE))) {
		rc = EUBIGEN_TOO_SMALL_EB;
		goto ubigen_create_err;
	}
	res->fp_in = fp_in;
	res->fp_out = fp_out;

	/* vid hdr data which doesn't change */
	res->v->magic = cpu_to_ubi32(UBI_VID_HDR_MAGIC);
	res->v->version = version ? version : UBI_VERSION;
	res->v->vol_type = vol_type;
	res->v->vol_id = cpu_to_ubi32(vol_id);
	res->v->compat = compat_flag;
	res->v->data_pad = cpu_to_ubi32(res->data_pad);

	/* static only: used_ebs */
	if (res->v->vol_type == UBI_VID_STATIC) {
		res->v->used_ebs = cpu_to_ubi32(byte_to_blk
						(res->bytes_total,
						 res->leb_size));
	}

	/* ec hdr (fixed, doesn't change) */
	res->ec->magic = cpu_to_ubi32(UBI_EC_HDR_MAGIC);
	res->ec->version = version ? version : UBI_VERSION;
	res->ec->ec = cpu_to_ubi64(ec);
	res->ec->vid_hdr_offset = cpu_to_ubi32(vid_hdr_offset);

	res->ec->data_offset = cpu_to_ubi32(data_offset);

	crc = clc_crc32(crc32_table, UBI_CRC32_INIT, res->ec,
			UBI_EC_HDR_SIZE_CRC);
	res->ec->hdr_crc = cpu_to_ubi32(crc);

	/* prepare a read buffer */
	res->buf = (uint8_t*) malloc (res->eb_size * sizeof(uint8_t));
	if (res->buf == NULL) {
		rc = -ENOMEM;
		goto ubigen_create_err;
	}

	/* point to distinct regions within the buffer */
	res->ptr_ec_hdr = res->buf;
	res->ptr_vid_hdr = res->buf + ubi32_to_cpu(res->ec->vid_hdr_offset);
	res->ptr_data = res->buf + ubi32_to_cpu(res->ec->vid_hdr_offset)
		+ UBI_VID_HDR_SIZE;

	rc = validate_ubi_info(res);
	if (rc != 0) {
		fprintf(stderr, "Volume validation failed: %d\n", rc);
		goto ubigen_create_err;
	}

	dump_info(res);
	*u = res;
	return rc;

 ubigen_create_err:
	if (res) {
		if (res->v)
			free(res->v);
		if (res->ec)
			free(res->ec);
		if (res->buf)
			free(res->buf);
		free(res);
	}
	*u = NULL;
	return rc;
}
Beispiel #23
0
int main(int argc, char **argv)
{
	int c;
	int ret = 0;
	GIOChannel *stdinchannel;
	GMainLoop *mainloop;
	float force_clock;
	bool opt_dump_info = false;
	struct option long_opts[] = {
		{"list-subtests", 0, 0, SUBTEST_OPTS},
		{"run-subtest", 1, 0, SUBTEST_OPTS},
		{"help-description", 0, 0, HELP_DESCRIPTION},
		{"help", 0, 0, 'h'},
		{"yb", 0, 0, Yb_OPT},
		{"yf", 0, 0, Yf_OPT},
		{ 0, 0, 0, 0 }
	};

	igt_skip_on_simulation();

	enter_exec_path( argv );

	while ((c = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) {
		switch (c) {
		case '3':
			test_stereo_modes = 1;
			break;
		case 'i':
			opt_dump_info = true;
			break;
		case 'a':
			test_all_modes = 1;
			break;
		case 'f':
			force_mode = 1;
			if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
				&force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal,
				&force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9)
				usage(argv[0], c);
			force_timing.clock = force_clock*1000;

			break;
		case 's':
			sleep_between_modes = atoi(optarg);
			break;
		case 'j':
			do_dpms = atoi(optarg);
			if (do_dpms == 0)
				do_dpms = DRM_MODE_DPMS_OFF;
			break;
		case 'd':
			depth = atoi(optarg);
			igt_info("using depth %d\n", depth);
			break;
		case 'p':
			if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width,
				   &plane_height, &crtc_x, &crtc_y,
				   &crtc_w, &crtc_h) != 6)
				usage(argv[0], c);
			test_plane = 1;
			break;
		case 'm':
			test_preferred_mode = 1;
			break;
		case 't':
			tiling = LOCAL_I915_FORMAT_MOD_X_TILED;
			break;
		case 'y':
		case Yb_OPT:
			tiling = LOCAL_I915_FORMAT_MOD_Y_TILED;
			break;
		case Yf_OPT:
			tiling = LOCAL_I915_FORMAT_MOD_Yf_TILED;
			break;
		case 'r':
			qr_code = 1;
			break;
		case 'o':
			sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num);
			break;
		case SUBTEST_OPTS:
			/* invalid subtest options */
			exit(IGT_EXIT_INVALID);
			break;
		case HELP_DESCRIPTION:
			igt_info("Tests display functionality.");
			exit(0);
			break;
		default:
			/* fall through */
		case 'h':
			usage(argv[0], c);
			break;
		}
	}

	set_termio_mode();

	if (depth <= 8)
		bpp = 8;
	else if (depth <= 16)
		bpp = 16;
	else if (depth <= 32)
		bpp = 32;

	if (!test_all_modes && !force_mode && !test_preferred_mode &&
	    specified_mode_num == -1 && !test_stereo_modes)
		test_all_modes = 1;

	drm_fd = drm_open_driver(DRIVER_INTEL);

	if (test_stereo_modes &&
	    drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
		igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n");
		goto out_close;
	}

	if (opt_dump_info) {
		dump_info();
		goto out_close;
	}

	kmstest_set_vt_graphics_mode();

	mainloop = g_main_loop_new(NULL, FALSE);
	if (!mainloop) {
		igt_warn("failed to create glib mainloop\n");
		ret = -1;
		goto out_close;
	}

	if (!testdisplay_setup_hotplug()) {
		igt_warn("failed to initialize hotplug support\n");
		goto out_mainloop;
	}

	stdinchannel = g_io_channel_unix_new(0);
	if (!stdinchannel) {
		igt_warn("failed to create stdin GIO channel\n");
		goto out_hotplug;
	}

	ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
			     NULL);
	if (ret < 0) {
		igt_warn("failed to add watch on stdin GIO channel\n");
		goto out_stdio;
	}

	ret = 0;

	if (!update_display()) {
		ret = 1;
		goto out_stdio;
	}

	if (test_all_modes)
		goto out_stdio;

	g_main_loop_run(mainloop);

out_stdio:
	g_io_channel_shutdown(stdinchannel, TRUE, NULL);
out_hotplug:
	testdisplay_cleanup_hotplug();
out_mainloop:
	g_main_loop_unref(mainloop);
out_close:
	close(drm_fd);

	igt_assert_eq(ret, 0);

	igt_exit();
}
Beispiel #24
0
void CLG_(check_command)()
{
    /* check for dumps needed */
    static Char buf[512];
    static Char cmdBuffer[512];
    Char *cmdPos = 0, *cmdNextLine = 0;
    Int fd, bytesRead = 0, do_kill = 0;
    SysRes res;
    Int currentPID;
    static Int check_counter = 0;

    /* Check for PID change, i.e. whether we run as child after a fork.
     * If yes, we setup interactive control for the new process
     */
    currentPID = VG_(getpid)();
    if (thisPID != currentPID) {
	thisPID = currentPID;
	setup_control();
    }

    /* Toggle between 2 command files, with/without ".pid" postfix
     * (needed for compatibility with KCachegrind, which wants to trigger
     *  a dump by writing into a command file without the ".pid" postfix)
     */
    check_counter++;
    if (check_counter % 2) {
	current_command_file = command_file;
	current_result_file  = result_file;
    }
    else {
	current_command_file = command_file2;
	current_result_file  = result_file2;
    }
    
    res = VG_(open)(current_command_file, VKI_O_RDONLY,0);
    if (!res.isError) {
	fd = (Int) res.res;
	bytesRead = VG_(read)(fd,cmdBuffer,500);
	cmdBuffer[500] = 0; /* no command overrun please */
	VG_(close)(fd);
	/* don't delete command file on read error (e.g. EAGAIN) */
	if (bytesRead>0) {
	    cmdPos = cmdBuffer;
	}
    }

    /* force creation of result file if needed */
    fd = -2;

    while((bytesRead>0) && *cmdPos) {
      
	/* Calculate pointer for next line */
	cmdNextLine = cmdPos+1;
	while((bytesRead>0) && *cmdNextLine && (*cmdNextLine != '\n')) {
	  cmdNextLine++;
	  bytesRead--;
	}
	if ((bytesRead>0) && (*cmdNextLine == '\n')) {
	  *cmdNextLine = 0;
	  cmdNextLine++;
	  bytesRead--;
	} 

	/* Command with integer option */
	if ((*cmdPos >= '0') && (*cmdPos <='9')) {
	  int value = *cmdPos-'0';
	  cmdPos++;
	  while((*cmdPos >= '0') && (*cmdPos <='9')) {
	    value = 10*value + (*cmdPos-'0');
	    cmdPos++;
	  }
	  while((*cmdPos == ' ') || (*cmdPos == '\t')) cmdPos++;
	  
	  switch(*cmdPos) {
#if CLG_ENABLE_DEBUG
	    /* verbosity */
	  case 'V':
	  case 'v':
	    CLG_(clo).verbose = value;
	    break;
#endif
	  default:
	    break;	      
	  }

	  cmdPos = cmdNextLine;
	  continue;
	}  

	/* Command with boolean/switch option */
	if ((*cmdPos=='+') || 
	    (*cmdPos=='-')) {
	  int value = (cmdPos[0] == '+');
	  cmdPos++;
	  while((*cmdPos == ' ') || (*cmdPos == '\t')) cmdPos++;
	  
	  switch(*cmdPos) {
	  case 'I':
	  case 'i':
	    CLG_(set_instrument_state)("Command", value);
	    break;

	  default:
	    break;
	  }

	  cmdPos = cmdNextLine;
	  continue;
	}

	/* regular command */
	switch(*cmdPos) {
	case 'D':
	case 'd':
	  /* DUMP */

	  /* skip command */
	  while(*cmdPos && (*cmdPos != ' ')) cmdPos++;
	  if (*cmdPos)
	    VG_(sprintf)(buf, "Dump Command:%s", cmdPos);
	  else
	    VG_(sprintf)(buf, "Dump Command");
	  CLG_(dump_profile)(buf, False);
	  break;
	    
	case 'Z':
	case 'z':
	    CLG_(zero_all_cost)(False);
	    break;

	case 'K':
	case 'k':
	    /* Kill: Delay to be able to remove command file before. */
	    do_kill = 1;
	    break;

	case 'I':
	case 'i':
	    fd = dump_info(fd);
	    break;

	case 's':
	case 'S':
	    fd = dump_state(fd);
	    break;

	case 'O':
	case 'o':
	    /* Options Info */
	    if ( (fd = createRes(fd)) <0) break;

	    VG_(sprintf)(buf, "\ndesc: Option: --skip-plt=%s\n",
			 CLG_(clo).skip_plt ? "yes" : "no");
	    VG_(write)(fd, (void*)buf, VG_(strlen)(buf));	    
	    VG_(sprintf)(buf, "desc: Option: --collect-jumps=%s\n",
			 CLG_(clo).collect_jumps ? "yes" : "no");
	    VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
	    VG_(sprintf)(buf, "desc: Option: --separate-recs=%d\n",
			 CLG_(clo).separate_recursions);
	    VG_(write)(fd, (void*)buf, VG_(strlen)(buf));
	    VG_(sprintf)(buf, "desc: Option: --separate-callers=%d\n",
			 CLG_(clo).separate_callers);
	    VG_(write)(fd, (void*)buf, VG_(strlen)(buf));

	    break;

	default:
	  break;
	}

	cmdPos = cmdNextLine;
    }

    /* If command executed, delete command file */
    if (cmdPos) VG_(unlink)(current_command_file);
    if (fd>=0) VG_(close)(fd);	    

    if (do_kill) {
      VG_(message)(Vg_UserMsg,
		   "Killed because of command from %s", current_command_file);
      CLG_(fini)(0);
      VG_(exit)(1);
    }
}
Beispiel #25
0
int main(int argc, char *argv[])
{
	int monsock;
	int become_daemon,n;

	sigset_t blockset;

	become_daemon = 0;

	while ((n = getopt(argc, argv, "dlv")) != -1) {
		switch (n) {
			case 'd':
				become_daemon = TRUE;
				break;
			case 'v':
				printf("\nldsped logcall version %s\n", LOGCALL_VERSION);
				printf ("Copyright (C) 2010 ON7LDS. All rights reserved.\n\n");
				return 0;
			case '?':
			case ':':
				fprintf(stderr, "usage: ldsped  [-d] [-v]\n");
				return 1;
		}
	}


	writelog(0, "ldsped logcall v%s starting ...",LOGCALL_VERSION); 


	// ------------------------------ start program -----------------------------------------

	if (become_daemon) {
	    if (!daemon_start(FALSE)) {
		writelog(0, "ldsped: cannot become a daemon");
		return 1;
	    } else {
		fclose(stdout);
		fclose(stderr);
		fclose(stdin);
	    }
	} else printf("Started in console mode.\n");


// ------------------------------------------- debug -------------------------------------------
//	file1 = fopen("/tmp/F1", "a");
//	file2 = fopen("/tmp/F2", "a");
// ------------------------------------------- debug -------------------------------------------


	// ------------------------------ initialising ------------------------------------------
	init_ax_config_calls();

	// Set some signal handlers
	signal(SIGPIPE, SIG_IGN);
	signal(SIGTERM, terminate);
	signal(SIGUSR1, signal_action_proc);
	signal(SIGUSR2, signal_action_proc);

	sigemptyset(&blockset);
	sigaddset(&blockset,SIGUSR1);
	sigaddset(&blockset,SIGUSR2);

	sigprocmask(SIG_BLOCK, &blockset, NULL);

	// Open socket for monitoring traffic
	if ((monsock = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
//		writelog(0, "Error opening monitor socket: m/%s", strerror(errno));
		exit(1);
	}

	fcntl(monsock, F_SETFL, O_NONBLOCK);

//	writelog(6,"========> Open fd %i in main",monsock);

	// ------------------------------ start main loop ---------------------------------------
	while (1) {

		// check if there is data on the AX25 socket
		check_monitor(monsock);

		// only process the signals here. We do not want to interrupt
		// the functions above or the accompaying systemcalls
		sigprocmask(SIG_UNBLOCK, &blockset, NULL);
		if (signal_action == SIGUSR1) { dump_info(); signal_action = 0; }
		if (signal_action == SIGUSR2) { ; signal_action = 0; }
		sigprocmask(SIG_BLOCK, &blockset, NULL);

	} // end main while loop

	close(monsock);
	closelog();
	return 0;
}
Beispiel #26
0
usb_dev_handle *open_dev(void)
{
	struct usb_bus *bus;
	struct usb_device *dev;
	usb_dev_handle *handle;
	int rc;

	for(bus = usb_get_busses(); bus; bus = bus->next) {
		for(dev = bus->devices; dev; dev = dev->next) {

#if	REPORT_ALL_DEVICES
			dump_info(dev);
#endif

			//
			//	VendorID,ProductID の一致チェック.
			//
			if(dev->descriptor.idVendor  == MY_VID &&
			        dev->descriptor.idProduct == MY_PID) {
#if	REPORT_MATCH_DEVICE
				if(verbose_mode) {
					dump_info(dev);
				}
#endif

				handle = usb_open(dev);
				int cf=dev->config->bConfigurationValue;
				if((rc = usb_set_configuration(handle, cf))<0) {
					printf("usb_set_configuration error(1) cf=%d\n",cf);
					int fn=dev->config->interface->altsetting->bInterfaceNumber;
					if((rc = usb_detach_kernel_driver_np(handle,fn)) <0 ) {
						printf("usb_detach_kernel_driver_np(%d) error\n",fn);
						usb_close(handle);
						return NULL;
					}

					if((rc = usb_set_configuration(handle, dev->config->bConfigurationValue))<0) {
					printf("usb_set_configuration error(2)\n");
						usb_close(handle);
						return NULL;

					}
				}

				if(usb_claim_interface(handle, 0) < 0) {
					printf("error: claiming interface 0 failed\n");
					usb_close(usb_dev);
					return NULL;
				}


				if( open_dev_check_string(dev,handle) == 1) {
					return handle;	//一致.
				}
				usb_close(handle);
				handle = NULL;
			}
		}
	}
	return NULL;
}
Beispiel #27
0
int main(int argc, char **argv)
{
	int ret = 0, n = 1;
	char *filenames[2];
	int num_files = 0;
	unsigned stage = 0;
	struct ir3_shader_variant v;
	struct ir3_shader s;
	struct ir3_shader_key key = {};
	/* TODO cmdline option to target different gpus: */
	unsigned gpu_id = 320;
	const char *info;
	void *ptr;
	size_t size;

	memset(&s, 0, sizeof(s));
	memset(&v, 0, sizeof(v));

	/* cmdline args which impact shader variant get spit out in a
	 * comment on the first line..  a quick/dirty way to preserve
	 * that info so when ir3test recompiles the shader with a new
	 * compiler version, we use the same shader-key settings:
	 */
	debug_printf("; options:");

	while (n < argc) {
		if (!strcmp(argv[n], "--verbose")) {
			fd_mesa_debug |= FD_DBG_MSGS | FD_DBG_OPTMSGS | FD_DBG_DISASM;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--binning-pass")) {
			debug_printf(" %s", argv[n]);
			key.binning_pass = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--color-two-side")) {
			debug_printf(" %s", argv[n]);
			key.color_two_side = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--half-precision")) {
			debug_printf(" %s", argv[n]);
			key.half_precision = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-s")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_s = key.fsaturate_s = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-t")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_t = key.fsaturate_t = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-r")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_r = key.fsaturate_r = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--astc-srgb")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vastc_srgb = key.fastc_srgb = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--stream-out")) {
			struct pipe_stream_output_info *so = &s.stream_output;
			debug_printf(" %s", argv[n]);
			/* TODO more dynamic config based on number of outputs, etc
			 * rather than just hard-code for first output:
			 */
			so->num_outputs = 1;
			so->stride[0] = 4;
			so->output[0].register_index = 0;
			so->output[0].start_component = 0;
			so->output[0].num_components = 4;
			so->output[0].output_buffer = 0;
			so->output[0].dst_offset = 2;
			so->output[0].stream = 0;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--ucp")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.ucp_enables = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--gpu")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			gpu_id = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--help")) {
			print_usage();
			return 0;
		}

		break;
	}
	debug_printf("\n");

	while (n < argc) {
		char *filename = argv[n];
		char *ext = rindex(filename, '.');

		if (strcmp(ext, ".tgsi") == 0) {
			if (num_files != 0)
				errx(1, "in TGSI mode, only a single file may be specified");
			s.from_tgsi = true;
		} else if (strcmp(ext, ".frag") == 0) {
			if (s.from_tgsi)
				errx(1, "cannot mix GLSL and TGSI");
			if (num_files >= ARRAY_SIZE(filenames))
				errx(1, "too many GLSL files");
			stage = MESA_SHADER_FRAGMENT;
		} else if (strcmp(ext, ".vert") == 0) {
			if (s.from_tgsi)
				errx(1, "cannot mix GLSL and TGSI");
			if (num_files >= ARRAY_SIZE(filenames))
				errx(1, "too many GLSL files");
			stage = MESA_SHADER_VERTEX;
		} else {
			print_usage();
			return -1;
		}

		filenames[num_files++] = filename;

		n++;
	}

	nir_shader *nir;

	if (s.from_tgsi) {
		struct tgsi_token toks[65536];

		ret = read_file(filenames[0], &ptr, &size);
		if (ret) {
			print_usage();
			return ret;
		}

		if (fd_mesa_debug & FD_DBG_OPTMSGS)
			debug_printf("%s\n", (char *)ptr);

		if (!tgsi_text_translate(ptr, toks, ARRAY_SIZE(toks)))
			errx(1, "could not parse `%s'", filenames[0]);

		if (fd_mesa_debug & FD_DBG_OPTMSGS)
			tgsi_dump(toks, 0);

		nir = ir3_tgsi_to_nir(toks);
	} else if (num_files > 0) {
		nir = load_glsl(num_files, filenames, stage);
	} else {
		print_usage();
		return -1;
	}

	s.compiler = ir3_compiler_create(NULL, gpu_id);
	s.nir = ir3_optimize_nir(&s, nir, NULL);

	v.key = key;
	v.shader = &s;

	switch (nir->stage) {
	case MESA_SHADER_FRAGMENT:
		s.type = v.type = SHADER_FRAGMENT;
		break;
	case MESA_SHADER_VERTEX:
		s.type = v.type = SHADER_VERTEX;
		break;
	case MESA_SHADER_COMPUTE:
		s.type = v.type = SHADER_COMPUTE;
		break;
	default:
		errx(1, "unhandled shader stage: %d", nir->stage);
	}

	info = "NIR compiler";
	ret = ir3_compile_shader_nir(s.compiler, &v);
	if (ret) {
		fprintf(stderr, "compiler failed!\n");
		return ret;
	}
	dump_info(&v, info);
}
Beispiel #28
0
int main(int argc, char **argv)
{
	int ret = 0, n = 1;
	const char *filename;
	struct tgsi_token toks[65536];
	struct tgsi_parse_context parse;
	struct ir3_compiler *compiler;
	struct ir3_shader_variant v;
	struct ir3_shader_key key = {};
	const char *info;
	void *ptr;
	size_t size;

	fd_mesa_debug |= FD_DBG_DISASM;

	/* cmdline args which impact shader variant get spit out in a
	 * comment on the first line..  a quick/dirty way to preserve
	 * that info so when ir3test recompiles the shader with a new
	 * compiler version, we use the same shader-key settings:
	 */
	debug_printf("; options:");

	while (n < argc) {
		if (!strcmp(argv[n], "--verbose")) {
			fd_mesa_debug |= FD_DBG_MSGS | FD_DBG_OPTMSGS;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--binning-pass")) {
			debug_printf(" %s", argv[n]);
			key.binning_pass = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--color-two-side")) {
			debug_printf(" %s", argv[n]);
			key.color_two_side = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--half-precision")) {
			debug_printf(" %s", argv[n]);
			key.half_precision = true;
			n++;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-s")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_s = key.fsaturate_s = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-t")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_t = key.fsaturate_t = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--saturate-r")) {
			debug_printf(" %s %s", argv[n], argv[n+1]);
			key.vsaturate_r = key.fsaturate_r = strtol(argv[n+1], NULL, 0);
			n += 2;
			continue;
		}

		if (!strcmp(argv[n], "--help")) {
			print_usage();
			return 0;
		}

		break;
	}
	debug_printf("\n");

	filename = argv[n];

	memset(&v, 0, sizeof(v));
	v.key = key;

	ret = read_file(filename, &ptr, &size);
	if (ret) {
		print_usage();
		return ret;
	}

	if (fd_mesa_debug & FD_DBG_OPTMSGS)
		debug_printf("%s\n", (char *)ptr);

	if (!tgsi_text_translate(ptr, toks, Elements(toks)))
		errx(1, "could not parse `%s'", filename);

	tgsi_parse_init(&parse, toks);
	switch (parse.FullHeader.Processor.Processor) {
	case TGSI_PROCESSOR_FRAGMENT:
		v.type = SHADER_FRAGMENT;
		break;
	case TGSI_PROCESSOR_VERTEX:
		v.type = SHADER_VERTEX;
		break;
	case TGSI_PROCESSOR_COMPUTE:
		v.type = SHADER_COMPUTE;
		break;
	}

	/* TODO cmdline option to target different gpus: */
	compiler = ir3_compiler_create(320);

	info = "NIR compiler";
	ret = ir3_compile_shader_nir(compiler, &v, toks, key);
	if (ret) {
		fprintf(stderr, "compiler failed!\n");
		return ret;
	}
	dump_info(&v, info);
}
Beispiel #29
0
static switch_bool_t ladspa_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
    switch_ladspa_t *pvt = (switch_ladspa_t *) user_data;
    //switch_frame_t *frame = NULL;
    switch_channel_t *channel = switch_core_session_get_channel(pvt->session);

    switch (type) {
    case SWITCH_ABC_TYPE_INIT:
    {
        switch_codec_implementation_t read_impl = { 0 };
        LADSPA_PortDescriptor port_desc;
        int i = 0, j = 0, k = 0, str_idx = 0;

        switch_core_session_get_read_impl(pvt->session, &read_impl);

        if (!(pvt->library_handle = loadLADSPAPluginLibrary(pvt->plugin_name))) {
            return SWITCH_FALSE;
        }

        if (!(pvt->ldesc = findLADSPAPluginDescriptor(pvt->library_handle, pvt->plugin_name, pvt->label_name))) {
            return SWITCH_FALSE;
        }


        pvt->handle = pvt->ldesc->instantiate(pvt->ldesc, read_impl.actual_samples_per_second);

        dump_info(pvt->ldesc);


        for (i = 0; i < pvt->ldesc->PortCount; i++) {
            port_desc = pvt->ldesc->PortDescriptors[i];

            if (LADSPA_IS_PORT_CONTROL(port_desc) && LADSPA_IS_PORT_INPUT(port_desc)) {
                LADSPA_Data dft = 0.0f;
                int found = find_default(pvt->ldesc, i, &dft);

                if (found && !pvt->has_config[j]) {
                    pvt->config[j] = dft;
                    pvt->has_config[j] = 1;
                }

                if (pvt->has_config[j]) {
                    if (!check_range(pvt->ldesc, i, pvt->config[j])) {
                        pvt->config[j] = dft;
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_WARNING, "FALLING TO DEFAULT PARAM %d [%s] (%f)\n",
                                          j+1,
                                          pvt->ldesc->PortNames[i],
                                          pvt->config[j]);
                    }

                    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "ADDING PARAM %d [%s] (%f)\n",
                                      j+1,
                                      pvt->ldesc->PortNames[i],
                                      pvt->config[j]);
                    pvt->ldesc->connect_port(pvt->handle, i, &pvt->config[j++]);
                    usleep(10000);
                }
            }

            if (LADSPA_IS_PORT_INPUT(port_desc) && LADSPA_IS_PORT_AUDIO(port_desc)) {
                int mapped = 0;

                if (pvt->str_idx && !zstr(pvt->str_config[str_idx])) {

                    if (!strcasecmp(pvt->str_config[str_idx], "none")) {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "CONNECT NOTHING to port: %s\n",
                                          pvt->ldesc->PortNames[i]
                                         );
                        mapped = 1;
                    } else if (!strncasecmp(pvt->str_config[str_idx], "file:", 5)) {
                        char *file = pvt->str_config[str_idx] + 5;

                        if (switch_test_flag((&pvt->fh), SWITCH_FILE_OPEN)) {
                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session),
                                              SWITCH_LOG_ERROR, "CAN'T CONNECT FILE [%s] File already mapped\n", file);
                        } else {
                            if (switch_core_file_open(&pvt->fh,
                                                      file,
                                                      read_impl.number_of_channels,
                                                      read_impl.actual_samples_per_second,
                                                      SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_ERROR, "Cannot open file: %s\n", file);
                                return SWITCH_FALSE;
                            }


                            switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "CONNECT FILE [%s] to port: %s\n",
                                              file,
                                              pvt->ldesc->PortNames[i]
                                             );

                            pvt->ldesc->connect_port(pvt->handle, i, pvt->file_buf);
                            mapped = 1;
                        }
                    }

                    str_idx++;
                }

                if (!mapped) {
                    pvt->ldesc->connect_port(pvt->handle, i, pvt->in_buf);
                    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "CONNECT CHANNEL AUDIO to port: %s\n",
                                      pvt->ldesc->PortNames[i]
                                     );
                }

            }

            if (LADSPA_IS_PORT_OUTPUT(port_desc)) {
                if (LADSPA_IS_PORT_AUDIO(port_desc)) {
                    pvt->ldesc->connect_port(pvt->handle, i, pvt->out_buf);
                } else if (k < MAX_INDEX) {
                    pvt->ldesc->connect_port(pvt->handle, i, &pvt->out_ports[k++]);
                }
            }
        }
    }

    break;

    case SWITCH_ABC_TYPE_CLOSE:
    {

        if (switch_test_flag((&pvt->fh), SWITCH_FILE_OPEN)) {
            switch_core_file_close(&pvt->fh);
        }

        if (pvt->handle && pvt->ldesc) {
            pvt->ldesc->cleanup(pvt->handle);
        }

        if (pvt->library_handle) {
            unloadLADSPAPluginLibrary(pvt->library_handle);
        }
    }
    break;

    case SWITCH_ABC_TYPE_WRITE_REPLACE:
    case SWITCH_ABC_TYPE_READ_REPLACE:
    {
        switch_frame_t *rframe;
        int16_t *slin, abuf[SWITCH_RECOMMENDED_BUFFER_SIZE] =  { 0 };
        switch_size_t olen = 0;


        if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
            rframe = switch_core_media_bug_get_read_replace_frame(bug);
        } else {
            rframe = switch_core_media_bug_get_write_replace_frame(bug);
        }

        slin = rframe->data;

        if (switch_channel_media_ready(channel)) {
            switch_short_to_float(slin, pvt->in_buf, rframe->samples);

            if (switch_test_flag((&pvt->fh), SWITCH_FILE_OPEN)) {
                olen = rframe->samples;
                if (switch_core_file_read(&pvt->fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) {
                    switch_codec_implementation_t read_impl = { 0 };
                    char *file = switch_core_session_strdup(pvt->session, pvt->fh.file_path);
                    switch_core_session_get_read_impl(pvt->session, &read_impl);

                    switch_core_file_close(&pvt->fh);

                    if (switch_core_file_open(&pvt->fh,
                                              file,
                                              read_impl.number_of_channels,
                                              read_impl.actual_samples_per_second,
                                              SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_ERROR, "Cannot open file: %s\n", file);
                        return SWITCH_FALSE;
                    }

                    olen = rframe->samples;
                    if (switch_core_file_read(&pvt->fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_ERROR, "Cannot READ file: %s\n", file);
                        return SWITCH_FALSE;
                    }
                }

                switch_short_to_float(abuf, pvt->file_buf, olen);
            }

            pvt->ldesc->run(pvt->handle, rframe->samples);

            switch_float_to_short(pvt->out_buf, slin, rframe->samples);
        }

        if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
            switch_core_media_bug_set_read_replace_frame(bug, rframe);
        } else {
            switch_core_media_bug_set_write_replace_frame(bug, rframe);
        }

        if (pvt->skip && !--pvt->skip) {
            return SWITCH_FALSE;
        }

    }
    break;
    case SWITCH_ABC_TYPE_WRITE:
    default:
        break;
    }

    return SWITCH_TRUE;
}
/**
 * \brief Application entry point.
 *
 * Configure USART in synchronous master/slave mode to start a transmission
 * between two boards.
 * \return Unused.
 */
int main(void)
{
	uint8_t uc_char;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Display main menu. */
	display_main_menu();

	/* Configure USART. */
	configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);

	/* Get board USART PDC base address and enable receiver and transmitter. */
	g_p_pdc = usart_get_pdc_base(BOARD_USART);
	pdc_enable_transfer(g_p_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);

	g_uc_transfer_mode = SYNC_MASTER;

	g_uc_state = STATE_WRITE;

	puts("-- USART in MASTER mode --\r");

	while (1) {
		uc_char = 0;
		scanf("%c", (char *)&uc_char);
		switch (uc_char) {
		case '0':
		case '1':
		case '2':
		case '3':
			g_uc_freq_idx = uc_char - '0';
			printf("-- The clock freq is: %luHz.\r\n",
				(unsigned long)g_ul_freq[g_uc_freq_idx]);
			configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);
			break;
		case 'i':
		case 'I':
			if (g_uc_transfer_mode == SYNC_MASTER) {
				printf("-- USART is MASTER at %luHz.\r\n",
					(unsigned long)g_ul_freq[g_uc_freq_idx]);
			} else {
				puts("-- USART is SLAVE \r");
			}
			break;
		case 's':
		case 'S':
			if (g_uc_transfer_mode == SYNC_MASTER) {
				g_uc_transfer_mode = SYNC_SLAVE;
				configure_usart(SYNC_SLAVE, g_ul_freq[g_uc_freq_idx]);
				puts("-- USART in SLAVE mode --\r");
			} else {
				if (g_uc_transfer_mode == SYNC_SLAVE) {
					g_uc_transfer_mode = SYNC_MASTER;
					configure_usart(SYNC_MASTER, g_ul_freq[g_uc_freq_idx]);
					puts("-- USART in MASTER mode --\r");
				}
			}
			break;
		case 'w':
		case 'W':
			g_uc_state = STATE_WRITE;
			g_st_packet.ul_addr = (uint32_t)tran_buff;
			g_st_packet.ul_size = BUFFER_SIZE;
			pdc_tx_init(g_p_pdc, &g_st_packet, NULL);
			usart_enable_interrupt(BOARD_USART, US_IER_TXBUFE);
			while (!g_ul_sent_done) {
			}
			if (g_ul_sent_done) {
				printf("-- %s sent done --\r\n",
						g_uc_transfer_mode ? "MASTER" :
						"SLAVE");
			}
			break;
		case 'r':
		case 'R':
			g_uc_state = STATE_READ;
			if (g_uc_transfer_mode == SYNC_MASTER) {
				puts("----USART MASTER Read----\r");
			} else {
				puts("----USART SLAVE Read----\r");
			}
			g_st_packet.ul_addr = (uint32_t)g_c_recv_buff;
			g_st_packet.ul_size = BUFFER_SIZE;
			pdc_rx_init(g_p_pdc, &g_st_packet, NULL);
			usart_enable_interrupt(BOARD_USART, US_IER_RXBUFF);
			while (!g_ul_recv_done) {
			}
			if (g_ul_recv_done) {
				if (strncmp((char*)g_c_recv_buff, tran_buff, BUFFER_SIZE)) {
					puts(" -F-: Failed!\r");
				} else {
					/* successfully received */
					dump_info((char*)g_c_recv_buff, BUFFER_SIZE);
				}
				puts("----END of read----\r");
				memset(g_c_recv_buff, 0, sizeof(g_c_recv_buff));
				g_ul_recv_done = false;
			}
			break;
		case 'm':
		case 'M':
			display_main_menu();
			break;
		default:
			break;
		}
	}
}