Example #1
0
void dataset_convert(dataset_t* data, stream_t* out)
{
    void* m;
    int i;

    printf("Allocating %d bytes.\n", ACTUAL_MEMORY_SIZE(out));
    m = malloc(ACTUAL_MEMORY_SIZE(out));
    if(m == NULL)
    {
        printf("Cannot allocate memory.\n");
        return;
    }
    memset(m, 0, ACTUAL_MEMORY_SIZE(out));

    for(i = 0; i < data->n_records / MEMORY_RECORDS(out); i++)
    {
        memcpy(m, data->records + (i * MEMORY_RECORDS(out) * RECORD_SIZE(out)), MEMORY_RECORDS(out) * RECORD_SIZE(out));
        memory_write(out, m, MEMORY_RECORDS(out));
        stats_print();
    }
    if(data->n_records % MEMORY_RECORDS(out))
    {
        memcpy(m, data->records + (i * MEMORY_RECORDS(out) * RECORD_SIZE(out)), (data->n_records % MEMORY_RECORDS(out)) * RECORD_SIZE(out));
        memory_write(out, m, data->n_records % MEMORY_RECORDS(out));
        stats_print();
    }
    free(m);
}
Example #2
0
static int
test1(void)
{
    int nret = EXIT_FAILURE;
    unsigned char *ptr = malloc(16);

#ifdef HAVE_LIBCURL
    sixel_chunk_t chunk = {0, 0, 0, NULL};
    int nread;

    nread = memory_write(NULL, 1, 1, NULL);
    if (nread != 0) {
        goto error;
    }

    nread = memory_write(ptr, 1, 1, &chunk);
    if (nread != 0) {
        goto error;
    }

    nread = memory_write(ptr, 0, 1, &chunk);
    if (nread != 0) {
        goto error;
    }
#else
    nret = EXIT_SUCCESS;
    goto error;
#endif  /* HAVE_LIBCURL */
    nret = EXIT_SUCCESS;

error:
    free(ptr);
    return nret;
}
Example #3
0
void init_timer(void) {
	out_byte(0x43, 0x34);
	out_byte(0x40, 47726 % 256);
	out_byte(0x40, 47726 / 256);

	memory_write(0, 8*4, (uint_16)timer_int);
	memory_write(0, 8*4+2, SEGMENT);
	}
Example #4
0
unsigned int ascii_wzerovalue(void *out, unsigned int count, unsigned int value, unsigned int base, unsigned int padding, unsigned int offset)
{

    char num[FUDGE_NSIZE];
    unsigned int bcount = ascii_fromint(num, FUDGE_NSIZE, value, base);

    memory_write(out, count, "00000000000000000000000000000000", padding, offset);
    memory_write(out, count, num, bcount, offset + padding - bcount);

    return padding;

}
Example #5
0
int main( int argc, char **argv ){

	//	Init the instructions
	init_instr_memory();

	// CLOCK CYCLE LOOP
	int instr_buffer;
	while( 1 ){
	
		//	NOTE: Order matters. All functions should fetch value
		//	from pipelined reg before the previous stage override the 
		//	reg values
		write_back();
		memory_write();
		execute_2();
		execute_1();
		instruction_decode();
		instruction_fetch();
		
		clk++;		
	}
	
	free( instruction_memory );
	free( data_memory );

exit( 0 );
}
Example #6
0
static unsigned int readdirectory(struct service_backend *backend, void *buffer, unsigned int count, unsigned int current, struct cpio_header *header)
{

    struct record *record = buffer;
    struct cpio_header eheader;
    unsigned char name[1024];

    if (!current)
        return 0;

    if (!readheader(backend, &eheader, current))
        return 0;

    if (!readname(backend, &eheader, current, name, 1024))
        return 0;

    record->id = current;
    record->size = cpio_filesize(&eheader);
    record->length = memory_read(record->name, RECORD_NAMESIZE, name, eheader.namesize - 1, header->namesize);

    switch (eheader.mode & 0xF000)
    {

    case 0x4000:
        record->length += memory_write(record->name, RECORD_NAMESIZE, "/", 1, record->length);

        break;

    }

    return sizeof (struct record);

}
void  memory_write(memory_content&  content, address const  begin, uint128_t  value, bool const  write_data_in_big_endian)
{
    byte*  b = value.data();
    if (write_data_in_big_endian == is_this_little_endian_machine())
        std::reverse(b,b + value.size());
    memory_write(content,begin,(byte const*)b,value.size());
}
Example #8
0
unsigned int ascii_wvalue(void *out, unsigned int count, unsigned int value, unsigned int base, unsigned int offset)
{

    char num[FUDGE_NSIZE];

    return memory_write(out, count, num, ascii_fromint(num, FUDGE_NSIZE, value, base), offset);

}
Example #9
0
static char *
test_memory_write_writes_to_byte_zero(void)
{
    word location;
    location.WORD = 0;
    printf("test_memory_write_writes_to_byte_zero\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory_write(location, 1);
    mu_assert("Incorrect byte written", memory[0] == 1);
    memory_destroy();
    return 0;
}
Example #10
0
static char *
test_memory_write_writes_correct_byte(void)
{
    word location;
    byte value = 0x12;
    location.WORD = 0x100;
    printf("test_memory_write_writes_correct_byte\n");
    mu_assert("Memory init failed", memory_init(4096));
    memory_write(location, value);
    mu_assert("Write failed(expected 0x12)", memory[location.WORD] == 0x12);
    memory_destroy();
    return 0;
}
Example #11
0
File: netcat.c Project: jezze/fudge
static void send(struct ipv4_socket *sender, struct ipv4_socket *target, void *buffer, unsigned int count)
{

    struct {struct ctrl_conheader header; char buffer[FUDGE_BSIZE];} packet;

    memory_copy(&packet.header.sender, sender, sizeof (struct ipv4_socket));
    memory_copy(&packet.header.target, target, sizeof (struct ipv4_socket));

    packet.header.count = memory_write(packet.buffer, FUDGE_BSIZE, buffer, count, 0);

    file_writeall(FILE_L1, &packet, sizeof (struct ctrl_conheader) + packet.header.count);

}
Example #12
0
void external_dataset_sort(external_dataset_t* data)
{
    struct runtime rt;
    void* results = NULL;
    size_t i;
    
    stream_t* tmp;
    stream_t* stream = data->stream;
    stream_seek(stream, 0);
    tmp = stream_create(stream->config, "tmp.stream");
    stream_open(tmp, O_CREAT | O_TRUNC | O_RDWR | O_SYNC);
    /* sort each individual chunk of memory size */
    for(i = 0; i < data->n_records / MEMORY_RECORDS(stream); i++)
    {
        memory_read(stream, RECORDS(data->mem), MEMORY_RECORDS(stream));
        N_RECORDS(data->mem) = MEMORY_RECORDS(stream);
        results = NULL;
        start_timing(&rt);
        fp_im_sort(data->context, RECORDS(data->mem), N_RECORDS(data->mem), &results);
        stop_timing(&rt);
        printf("Sort time: %f\n", get_runtime(rt));
        memory_write(tmp, RECORDS(data->mem), N_RECORDS(data->mem));
        dataset_print(data->mem, TRUE);

    }
    if(data->n_records % MEMORY_RECORDS(stream))
    {
        memory_read(stream, RECORDS(data->mem), data->n_records % MEMORY_RECORDS(stream));
        N_RECORDS(data->mem) = data->n_records % MEMORY_RECORDS(stream);
        start_timing(&rt);
        results = NULL;
        fp_im_sort(data->context, RECORDS(data->mem), N_RECORDS(data->mem), &results);
        stop_timing(&rt);
        memory_write(tmp, RECORDS(data->mem), N_RECORDS(data->mem));
        dataset_print(data->mem, TRUE);
    }
    /* merge memory chunks block by block */
}
Example #13
0
static unsigned int findmodulesymbol(unsigned int count, char *symbolname)
{

    unsigned int length = memory_findbyte(symbolname, count, '_') - 1;
    unsigned int offset = 0;
    unsigned int address;
    char module[32];

    offset += memory_write(module, 32, symbolname, length, offset);
    offset += memory_write(module, 32, ".ko", 4, offset);

    if (!file_walkfrom(CALL_L2, CALL_L1, module))
        return 0;

    file_open(CALL_L2);

    address = findsymbol(CALL_L2, count, symbolname);

    file_close(CALL_L2);

    return address;

}
Example #14
0
/**
 * Save memory block
 * \param addr Target address to save data
 * \param buf Source buffer
 * \param len Save size (must < MEM_BLOCK_SIZE)
 */
static uint32_t _app_save_block(void *addr, void *buf, uint32_t len)
{
	uint8_t *p_u8 = (uint8_t *)buf;
	if (len < MEM_BLOCK_SIZE) {
		/* Padding with MEM_BLANK_VALUE */
		for (; len < MEM_BLOCK_SIZE; len++) {
			p_u8[len] = MEM_BLANK_VALUE;
		}
	}

	/* Save one block */
	memory_write(addr, buf);

	/* Toggle the led when app load. */
	_app_led_toggle(DBG_LED_PIN);

	return MEM_BLOCK_SIZE;
}
/****************************************************************************
 **                                                                        **
 ** Name:        usim_api_write()                                          **
 **                                                                        **
 ** Description: Writes data to the USIM application                       **
 **                                                                        **
 ** Inputs:      data:          Pointer to the USIM application data       **
 **              Others:        None                                       **
 **                                                                        **
 ** Outputs:     None                                                      **
 **              Return:        RETURNerror, RETURNok                      **
 **              Others:        None                                       **
 **                                                                        **
 ***************************************************************************/
int usim_api_write(const usim_data_t* data)
{
  LOG_FUNC_IN;

  /* Get USIM application pathname */
  char* path = memory_get_path(USIM_API_NVRAM_DIRNAME,
                               USIM_API_NVRAM_FILENAME);

  if (path == NULL) {
    LOG_TRACE(ERROR, "USIM-API  - Failed to get USIM pathname");
    LOG_FUNC_RETURN (RETURNerror);
  }

  /* Write USIM application data */
  if (memory_write(path, data, sizeof(usim_data_t)) != RETURNok) {

    LOG_TRACE(ERROR, "USIM-API  - Unable to write USIM file %s", path);
    free(path);
    LOG_FUNC_RETURN (RETURNerror);
  }

  free(path);
  LOG_FUNC_RETURN (RETURNok);
}
Example #16
0
/* a non-destructive memory-write function. memory_write alters the source val */
int memory_write_wrapper(struct memory *mem, size_t address, glong val, int size,
			int convert, gclock_t *cycles)
{
	return memory_write(mem, address, &val, size, convert, cycles);
}
Example #17
0
File: main.c Project: jezze/fudge
static unsigned int videointerface_writedata(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset)
{

    return memory_write(gaddress, videointerface.settings.w * videointerface.settings.h * videointerface.settings.bpp, buffer, count, offset);

}
Example #18
0
/*
  access memory (read/write) according to the read_write bit setting
*/
void access_memory() {
    if(read_write==READ)
        memory_read();
    else
        memory_write();
}
Example #19
0
File: mboot.c Project: jezze/fudge
static unsigned int write(struct service_state *state, void *buffer, unsigned int count, unsigned int offset)
{

    return memory_write((void *)address, limit, buffer, count, offset);

}
Example #20
0
File: mbr.c Project: jezze/fudge
void main(void)
{

    struct mbr mbr;
    unsigned int i;

    file_open(FILE_PI);
    file_readall(FILE_PI, &mbr, 512);
    file_close(FILE_PI);

    if (mbr.signature[0] != 0x55 || mbr.signature[1] != 0xAA)
        return;

    file_open(FILE_PO);

    for (i = 0; i < 4; i++)
    {

        unsigned int start = (mbr.partition[i].sectorlba[3] << 24) | (mbr.partition[i].sectorlba[2] << 16) | (mbr.partition[i].sectorlba[1] << 8) | (mbr.partition[i].sectorlba[0]);
        unsigned int sectors = (mbr.partition[i].sectortotal[3] << 24) | (mbr.partition[i].sectortotal[2] << 16) | (mbr.partition[i].sectortotal[1] << 8) | (mbr.partition[i].sectortotal[0]);
        unsigned int cstart = mbr.partition[i].cylinderbase | ((mbr.partition[i].sectorbase & 0xC0) << 8);
        unsigned int cend = mbr.partition[i].cylinderlimit | ((mbr.partition[i].sectorlimit & 0xC0) << 8);
        unsigned int hstart = mbr.partition[i].headbase;
        unsigned int hend = mbr.partition[i].headlimit;
        unsigned int sstart = mbr.partition[i].sectorbase & 0x2F;
        unsigned int send = mbr.partition[i].sectorlimit & 0x2F;
        char data[64];
        unsigned int count;

        write_keydec(FILE_PO, "Partition", i);

        if (!mbr.partition[i].systemid)
            continue;

        write_keyhex(FILE_PO, "    Boot", mbr.partition[i].boot);
        write_keyhex(FILE_PO, "    Id", mbr.partition[i].systemid);
        write_keydec(FILE_PO, "    Start", start);
        write_keydec(FILE_PO, "    End", start + sectors - 1);
        write_keydec(FILE_PO, "    Sectors", sectors);

        count = 0;
        count += ascii_wvalue(data + count, 64, cstart, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, hstart, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, sstart, 10);

        write_keybuffer(FILE_PO, "    Start-C/H/S", data, count);

        count = 0;
        count += ascii_wvalue(data + count, 64, cend, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, hend, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, send, 10);

        write_keybuffer(FILE_PO, "    End-C/H/S", data, count);

    }

    file_close(FILE_PO);

}
Example #21
0
int main(int argc, char const *argv[]) {

    unsigned flit;
    unsigned flit_type;
    unsigned payload;
    unsigned packet_counter = 1;

    /* Test UART */
    setup_uart(CPU_SPEED, UART_BAUDRATE);
    uart_puts("UART TEST: If you can read this, then UART output works!\n");

    #if (UART_IN_TEST == 1)

    uart_puts("Please press letter 'b' on the UART terminal:\n");
    char uart_in = uart_getch();

    if (uart_in == 'b')
    {
        uart_puts("UART INPUT TEST PASSED!\n\n");
    }

    else
    {
        uart_puts("UART INPUT TEST FAILED!\n");
        uart_puts("Received following letter: {ASCII:HEX}\n");
        uart_putchar(uart_in);
        uart_putchar(':');
        uart_print_hex(uart_in);
        uart_puts("\n\n");
    }

    #endif

    #if (GPIO_TEST == 1)

    /* Test GPIO */
    unsigned gpio_in = memory_read(GPIOA_IN);
    memory_write(GPIO0_SET, gpio_in);

    #endif

    uart_puts("\n\nBeginning communication test\n\n");


    ni_write(build_header(DST_ADDR, 3));
    ni_write(0b1111111111111111111111111111);
    ni_write(0);

    while (packet_counter <= SEND_PACKET_COUNT)
    {
        if ((ni_read_flags() & NI_READ_MASK) == 0)
        {
            flit = ni_read();
            flit_type = get_flit_type(flit);

            if (flit_type == FLIT_TYPE_HEADER)
            {
                uart_puts("Sending packet number ");
                uart_print_num(packet_counter, 10, 0);
                uart_putchar('\n');
                ni_write(build_header(DST_ADDR, 3));
                packet_counter++;
            }
            else
            {
                payload = get_flit_payload(flit);
                ni_write(payload);
            }
        }
    }

    /* Run CPU test */
    test_plasma_funcitons();

    return 0;
}
Example #22
0
static int memory_puts(BIO *bp, const char *str)
{
	return memory_write(bp, str, strlen(str));
}
Example #23
0
void
memory_w8(memory * mem, word addr, byte data)
{
	memory_write(mem, addr, data);
}
Example #24
0
void
memory_w16(memory * mem, word addr, word data)
{
	memory_write(mem, addr, data & 0x00FF);
	memory_write(mem, addr + 1, data >> 8);
}
Example #25
0
int memory_write_gdb(pid_t tid, uint64_t addr, uint8_t *data, size_t size) {
  int ret;
  ret = memory_write(tid, addr, data, size, true /* breakpoint check */);
  return ret;
}