Example #1
0
void collect_output_affix ()
{   int nr = popi ();
    affix_node affx = popa ();
    value new_val = affx -> val;
    check_for_space ();
    my_cvals[nrofparses][nr] = rdup_value (new_val);
    callq ();
    pusha (affx);
    pushi (nr);
    pushq (collect_output_affix);
};
void queue_insert_u8(queue_t* q, uint8_t data, uint8_t position)
{
	check_for_space(q,1);

	uint8_t* position_ptr = q->front + position;
	uint8_t* data_ptr = q->rear++;
	while (data_ptr >= position_ptr)
	{
		*(data_ptr+1) = *(data_ptr--);
	}

	*position_ptr = data;
	q->length++;
}
void queue_insert_u16(queue_t* q, uint16_t data, uint8_t position)
{
	check_for_space(q,2);

	uint16_t* position_ptr = (uint16_t*)(q->front) + position;
	uint16_t* data_ptr = (uint16_t*)(q->rear);
	q->rear += 2;
	while (data_ptr >= position_ptr)
	{
		uint16_t* new_data_ptr = data_ptr + 1;
		*(new_data_ptr) = *(data_ptr--);
	}

	*position_ptr = data;
	q->length++;
}
void queue_insert_value(queue_t* q, void* data, uint8_t position, uint8_t size)
{
	check_for_space(q,size);

	uint8_t* position_ptr = q->front + (position * size);
	uint8_t* data_ptr = q->rear;
	q->rear += size;
	while (data_ptr >= position_ptr)
	{
		uint8_t* new_data_ptr = data_ptr + size;
		memcpy(new_data_ptr, data_ptr, size);
		data_ptr -= size;
	}

	memcpy(position_ptr, data, size);
	q->length++;
}
bool queue_push_value(queue_t* q, void* data, uint8_t size)
{
	//log_print_stack_string(LOG_FWK, "push");
	if (q->front == NULL)
	{
		q->front = q->start;
		q->rear = q->start;
    }
    else
	{
		if (!check_for_space(q,size))
            return false;

		q->rear += size;
	}

	memcpy(q->rear, data, size);
	q->length++;

    return true;
}
Example #6
0
/**
 * Prepare the MBR and indirect sector for runtime
 * @param fd_barebox barebox image to use
 * @param fd_hd Hard disk image to prepare
 * @param pers_sector_count Count of sectors to skip after MBR for the persistent environment storage
 * @return 0 on success
 *
 * This routine expects a prepared hard disk image file with a partition table
 * in its first sector. This method only is currently supported.
 */
static int barebox_overlay_mbr(int fd_barebox, int fd_hd, long pers_sector_count)
{
	const void *barebox_image;
	void *hd_image;
	int rc;
	struct stat sb;
	struct DAPS *embed;	/* part of the MBR */
	struct DAPS *indirect;	/* sector with indirect DAPS */
	off_t required_size;

	if (fstat(fd_barebox, &sb) == -1) {
		perror("fstat");
		return -1;
	}

	/* the barebox image won't be touched */
	barebox_image = mmap(NULL, sb.st_size,  PROT_READ, MAP_SHARED, fd_barebox, 0);
	if (barebox_image == MAP_FAILED) {
		perror("mmap");
		return -1;
	}

	rc = check_for_valid_mbr(barebox_image, sb.st_size);
	if (rc != 0) {
		fprintf(stderr, "barebox image seems not valid: Bad MBR signature\n");
		goto on_error_hd;
	}

	/*
	 * the persistent environment storage is in front of the main
	 * barebox image. To handle both, we need more space in front of the
	 * the first partition.
	 */
	required_size = sb.st_size + pers_sector_count * SECTOR_SIZE;

	/* the hd image will be modified */
	hd_image = mmap(NULL, required_size,  PROT_READ | PROT_WRITE,
					MAP_SHARED, fd_hd, 0);
	if (hd_image == MAP_FAILED) {
		perror("mmap");
		rc = -1;
		goto on_error_hd;
	}

	/* check for space */
	rc = check_for_space(hd_image, required_size);
	if (rc != 0)
		goto on_error_space;

	/* embed barebox's boot code into the disk drive image */
	memcpy(hd_image, barebox_image, OFFSET_OF_PARTITION_TABLE);

	/*
	 * embed the barebox main image into the disk drive image,
	 * but keep the persistent environment storage untouched
	 * (if defined), e.g. store the main image behind this special area.
	 */
	memcpy(hd_image + ((pers_sector_count + 1) * SECTOR_SIZE),
			barebox_image + SECTOR_SIZE, sb.st_size - SECTOR_SIZE);

	/* now, prepare this hard disk image for BIOS based booting */
	embed = hd_image + PATCH_AREA;
	indirect = hd_image + ((pers_sector_count + 1) * SECTOR_SIZE);

	/*
	 * Fill the embedded DAPS to let the basic boot code find the
	 * indirect sector at runtime
	 */
#ifdef DEBUG
	printf("Debug: Fill in embedded DAPS\n");
#endif
	rc = fill_daps(embed, 1, INDIRECT_AREA, INDIRECT_SEGMENT,
				1 + pers_sector_count);
	if (rc != 0)
		goto on_error_space;
	debugout(embed, 1);

#ifdef DEBUG
	printf("Debug: Fill in indirect sector\n");
#endif
	/*
	 * fill the indirect sector with the remaining DAPS to load the
	 * whole barebox image at runtime
	 */
	rc = barebox_linear_image(indirect, sb.st_size, pers_sector_count);
	if (rc != 0)
		goto on_error_space;

	/*
	 * TODO: Replace the fixed LBA starting number by a calculated one,
	 * to support barebox as a chained loader in a different start
	 * sector than the MBR
	 */
	rc = store_pers_env_info(embed, 1, pers_sector_count);
	if (rc != 0)
		goto on_error_space;

on_error_space:
	munmap(hd_image, required_size);

on_error_hd:
	munmap((void*)barebox_image, sb.st_size);

	return rc;
}