Exemplo n.º 1
0
uint8_t ihx_check_line(char line[]) {
  // :ccaaaattxxxxss
  uint8_t byte_count, record_type, checksum, sum, i;
  uint16_t address;
  
  if (line[0] != ':')
    return IHX_INVALID;
  
  byte_count = hex8(&line[1]);
  address = ihx_record_address(line);
  record_type = ihx_record_type(line);

  if (byte_count > IHX_MAX_LEN)
    return IHX_RECORD_TOO_LONG;
  
  checksum = ihx_data_byte(line, byte_count);

  if (record_type > 0x01 && (record_type < 0x22 || record_type > 0x25))
    return IHX_BAD_RECORD_TYPE;
    
  if (record_type == IHX_RECORD_DATA && (address < USER_CODE_BASE || address > FLASH_SIZE))
   return IHX_BAD_ADDRESS;
   
  sum = 0;
  i = 0;
  for (i=0; i<byte_count+5; i++) {
    sum += hex8(&line[1 + i*2]);
  }
  
  if (sum != 0)
    return IHX_BAD_CHECKSUM;
    
  return IHX_OK;
}
Exemplo n.º 2
0
static void
dump_pe_header (MonoPEHeader *pe)
{
	printf ("\nPE Header:\n");
	hex16 ("         Magic (0x010b)", pe->pe_magic);
	hex8  ("             LMajor (6)", pe->pe_major);
	hex8  ("             LMinor (0)", pe->pe_minor);
	hex32 ("              Code Size", pe->pe_code_size);
	hex32 ("  Initialized Data Size", pe->pe_data_size);
	hex32 ("Uninitialized Data Size", pe->pe_uninit_data_size);
	hex32 ("        Entry Point RVA", pe->pe_rva_entry_point);
	hex32 (" 	  Code Base RVA", pe->pe_rva_code_base);
	hex32 ("	  Data Base RVA", pe->pe_rva_data_base);
	printf ("\n");
}
Exemplo n.º 3
0
void ihx_write(char line[]) {
  // :ccaaaattxxxxss
  uint8_t byte_count, record_type, i;
  uint16_t address;
  __xdata uint8_t buff[65];
  
  byte_count = hex8(&line[1]);
  address = ihx_record_address(line);
  record_type = ihx_record_type(line);
  
  switch (record_type) {
    case IHX_RECORD_DATA:
      buff[0] = 0xFF; // Padding in case the flash start address is not even.
      for (i=0; i<byte_count; i++)
        buff[i+1] = ihx_data_byte(line, i);
      buff[byte_count+1] = 0xFF; // If there are not an even no. of bytes, pad with 0xFF to preserve flash.
      
      if (address & 1) {
        // Odd start address
        // (byte_count+1)/2 == number of 16-bit words to transfer, rounded up
        flash_check_erase_and_write((uint16_t*)buff, (byte_count+2)/2, address-1);
      } else {
        // Even start address
        // (byte_count+1)/2 == number of 16-bit words to transfer, rounded up
        flash_check_erase_and_write((uint16_t*)(buff+1), (byte_count+1)/2, address);
      }
      
      break;
    case IHX_RECORD_EOF:
      break;
  }
}
Exemplo n.º 4
0
void WriteEncodedInt(unsigned int v)
{
	if (DEBUG) printf("EncInt: ");

	while(1)
	{
		if (v < 128)
			break;

		WriteByte(v & 0x7f);

		if (DEBUG) hex8(v & 0x7f);

		v >>= 7;
	}

	WriteByte(v | 0x80);
	if (DEBUG) hex8(v | 0x80);

	if (DEBUG) printf("\n");

	return;
}
Exemplo n.º 5
0
static int
hexreadn(int fd, void *p, int n)
{
	char hex[RCALLMAX*2];
	int nr, i;
	char *cp = p;
	
	nr = fdreadn(fd, hex, n*2);
	if(nr < 0)
		return -1;

	for(i=0; i < nr/2; i++)
		cp[i] = hex8(hex + i*2);

	return nr/2;
}
Exemplo n.º 6
0
void GBLoadSymbols(struct mDebuggerSymbols* st, struct VFile* vf) {
	char line[512];

	while (true) {
		ssize_t bytesRead = vf->readline(vf, line, sizeof(line));
		if (bytesRead <= 0) {
			break;
		}
		if (line[bytesRead - 1] == '\n') {
			line[bytesRead - 1] = '\0';
		}
		int segment = -1;
		uint32_t address = 0;

		uint8_t byte;
		const char* buf = line;
		while (buf) {
			buf = hex8(buf, &byte);
			if (!buf) {
				break;
			}
			address <<= 8;
			address += byte;

			if (buf[0] == ':') {
				segment = address;
				address = 0;
				++buf;
			}
			if (isspace((int) buf[0])) {
				break;
			}
		}
		if (!buf) {
			continue;
		}

		while (isspace((int) buf[0])) {
			++buf;
		}

		mDebuggerSymbolAdd(st, buf, address, segment);
	}
}
Exemplo n.º 7
0
int nesds_about()
{
	static int tipnum = -1;
	int i;
	int fresh = 0;

	if(tipnum < 0) {
		fresh = 1;
		tipnum = 0;
	}
	if(menu_stat == 5) {
		menu_stat = 6;
		fresh = 1;
	}
	
	i=do_touchstrings(aboutext,0);
	if(touchstate==4) {
		switch(i) {
			case 0: 
				tipnum--;
				if(tipnum < 0)
					tipnum = sizeof(tips)/sizeof(tips[0]) - 1;
				fresh = 1;
				break;
			case 1:
				tipnum++;
				if(tipnum >= sizeof(tips)/sizeof(tips[0]))
					tipnum = 0;
				fresh = 1;
				break;
		}
	}
	
	if(fresh) {
		clearconsole();
		hex8(64*4+30, tipnum);
		consoletext(64*6, tips[tipnum], 0x0000); 
	}

	return 0;
}
Exemplo n.º 8
0
bool GBACheatAddVBALine(struct GBACheatSet* cheats, const char* line) {
	uint32_t address;
	uint8_t op;
	uint32_t value = 0;
	int width = 0;
	const char* lineNext = hex32(line, &address);
	if (!lineNext) {
		return false;
	}
	if (lineNext[0] != ':') {
		return false;
	}
	++lineNext;
	while (width < 4) {
		lineNext = hex8(lineNext, &op);
		if (!lineNext) {
			break;
		}
		value <<= 8;
		value |= op;
		++width;
	}
	if (width == 0 || width == 3) {
		return false;
	}

	struct mCheat* cheat = mCheatListAppend(&cheats->d.list);
	cheat->address = address;
	cheat->operandOffset = 0;
	cheat->addressOffset = 0;
	cheat->repeat = 1;
	cheat->type = CHEAT_ASSIGN;
	cheat->width = width;
	cheat->operand = value;
	return true;
}
Exemplo n.º 9
0
uint8_t ihx_data_byte(char line[], uint8_t n) {
  return hex8(&line[9 + n*2]);
}
Exemplo n.º 10
0
uint8_t ihx_record_type(char line[]) {
  return hex8(&line[7]);
}
Exemplo n.º 11
0
uint16_t hex16(char s[]) {
  // Converts a string representation of a 16-bit hexadecimal word into a uint16.
  // TODO: handle the case of hex8 failing.
  return hex8(&s[2]) + 256*(uint16_t)hex8(&s[0]);
}
Exemplo n.º 12
0
void
srvrxpeek()
{
	uint8_t length;
	uint8_t in_byte;
	char nibbles[2];
	int bytes_to_read;

	if (rxstate != Urxing){
		return;
	}
	GREEN=1;

	dprint("start of reading ---- ");

	nibbles[0] = usb_getchar();

	if(nibbles[0] == 1){
		dprint("info request\n");
		usb_putchar(1);
		dprint("flush\n");
		usb_flush();
		rxstate = Uready;
		GREEN = 0;
		return;
	}
	GREEN=0;

	dprint("%c ", nibbles[0]);
	nibbles[1] = usb_getchar();
	dprint("%c ", nibbles[1]);
	in_byte = hex8(&nibbles[0]);
	dprint("(%x) ", in_byte);

	if (nrx == 0) {
		if (in_byte == 0) {
			dprint("getting 0 size. error\n");
			while (1) {;}
        		rxstate = Uready;
			flag &= ~Frxcall;
			return;
		}

		if (in_byte == 0xff) {
			dprint("radio reset\n");
        		rxstate = Uready;
			flag &= ~Frxcall;
			return;
		}

		// if the index is still at 0, here is the length
		rxcall[nrx++] = in_byte;
	}

	length = rxcall[0];
	while (nrx < length) {
		nibbles[0] = usb_getchar();
		dprint("%c ", nibbles[0]);
		nibbles[1] = usb_getchar();
		dprint("%c ", nibbles[1]);
		in_byte = hex8(&nibbles[0]);
		dprint("(%x) ", in_byte);

		rxcall[nrx++] = in_byte;
		if(nrx == sizeof rxcall)
			panic("usb: rxcall overrun");
	}

	if (nrx == length) {
		rxstate = Uidle;
		flag |= Frxcall;
		dprint(" ---- read %d\n", length);
	} else {
		// if we didn't read everything, let's let
		// WD take over here
		dprint(" ---- only read %d out of %d\n", nrx, length);
		while (1) {;}
	}
}