示例#1
0
static int bootlog_module_init(void)
{
    /* Make sure that lib_sysinfo is initialized */
    int ret = lib_get_sysinfo();
    if (ret) {
        return -1;
    }

    struct cbmem_console *console = lib_sysinfo.cbmem_cons;
    if (console == NULL) {
        return -1;
    }
    /* Extract console information */
    char *buffer = (char *)(&(console->body));
    u32 buffer_size = console->size;
    u32 cursor = console->cursor;

    /* The cursor may be bigger than buffer size when the buffer is full */
    if (cursor >= buffer_size) {
        cursor = buffer_size - 1;
    }

    /* Calculate how much characters will be displayed on screen */
    u32 chars_count = calculate_chars_count(buffer, cursor + 1, SCREEN_X, LINES_SHOWN);

    /* Sanity check, chars_count must be padded to full line */
    if (chars_count % SCREEN_X != 0) {
        return -2;
    }

    g_lines_count = chars_count / SCREEN_X;
    g_max_cursor_line = MAX(g_lines_count - 1 - LINES_SHOWN, 0);

    g_buf = malloc(chars_count);
    if (!g_buf) {
        return -3;
    }

    if (sanitize_buffer_for_display(buffer, cursor + 1,
                                    g_buf, chars_count,
                                    SCREEN_X) < 0) {
        free(g_buf);
        g_buf = NULL;
        return -4;
    }

    /* TODO: Maybe a _cleanup hook where we call free()? */

    return 0;
}
示例#2
0
static int timestamps_module_init(void)
{
	/* Make sure that lib_sysinfo is initialized */
	int ret = lib_get_sysinfo();

	if (ret)
		return -1;

	struct timestamp_table *timestamps = lib_sysinfo.tstamp_table;

	if (timestamps == NULL)
		return -1;

	/* Extract timestamps information */
	u64 base_time = timestamps->base_time;
	u16 max_entries = timestamps->max_entries;
	u32 n_entries = timestamps->num_entries;

	timestamp_set_tick_freq(timestamps->tick_freq_mhz);

	char *buffer;
	u32 buff_cur = 0;
	uint64_t prev_stamp;
	uint64_t total_time;

	/* Allocate a buffer big enough to contain all of the possible
	 * entries plus the other information (number entries, total time). */
	buffer = malloc((max_entries + 4) * SCREEN_X * sizeof(char));

	if (buffer == NULL)
		return -3;

	/* Write the content */
	buff_cur += snprintf(buffer, SCREEN_X, "%d entries total:\n\n",
			n_entries);

	prev_stamp = 0;
	timestamp_print_entry(buffer, SCREEN_X, &buff_cur, 0, base_time,
			prev_stamp);
	prev_stamp = base_time;

	total_time = 0;
	for (int i = 0; i < n_entries; i++) {
		uint64_t stamp;
		const struct timestamp_entry *tse = &timestamps->entries[i];

		stamp = tse->entry_stamp + base_time;
		total_time += timestamp_print_entry(buffer, SCREEN_X,
				&buff_cur, tse->entry_id, stamp, prev_stamp);
		prev_stamp = stamp;
	}

	buff_cur += snprintf(buffer + buff_cur, SCREEN_X, "\nTotal Time: ");
	buff_cur += snprintf(buffer + buff_cur, SCREEN_X, "%llu", total_time);
	buff_cur += snprintf(buffer + buff_cur, SCREEN_X, "\n");

	/* Calculate how many characters will be displayed on screen */
	u32 chars_count = calculate_chars_count(buffer, buff_cur + 1,
			SCREEN_X, LINES_SHOWN);

	/* Sanity check, chars_count must be padded to full line */
	if (chars_count % SCREEN_X != 0) {
		free(buffer);
		return -2;
	}

	g_lines_count = chars_count / SCREEN_X;
	g_max_cursor_line = MAX(g_lines_count - 1 - LINES_SHOWN, 0);

	g_buf = malloc(chars_count);
	if (!g_buf) {
		free(buffer);
		return -3;
	}

	if (sanitize_buffer_for_display(buffer, buff_cur + 1, g_buf,
				chars_count, SCREEN_X) < 0) {
		free(buffer);
		free(g_buf);
		g_buf = NULL;
		return -4;
	}

	free(buffer);

	return 0;
}