Esempio n. 1
0
uint32_t protoss_dump_debug_reg(uint32_t reg) {
    //IOLog("dbg_map = %p\n", dbg_map);
    uint32_t result;
    begin_debug();
    read_debug(197);
    result = read_debug(reg);
    end_debug();
    return result;
}
Esempio n. 2
0
void protoss_stop() {
    if(trace_going || watch_going) {
        begin_debug(); // interrupts disabled
        read_debug(197);
        uint32_t dbgdscr = read_debug(34);
        dbgdscr |= 0x8000; // turn on debug
        write_debug(34, dbgdscr);
        for(int i = 0; i < 16; i++) {
            // bcr and wcr
            write_debug(80 + i, 0);
            write_debug(112 + i, 0);
        }

        dbgdscr = read_debug(34);
        dbgdscr &= ~0x8000;
        write_debug(34, dbgdscr);
        end_debug();
    }

    if(trace_going) {
        trace_going = false;
    }
    
    watch_going = false;

#ifdef WATCH{OINTS
    if(ter_patched) {
        memset(debug_stuff, 0, sizeof(debug_stuff));
        old_ie = ml_set_interrupts_enabled(0);

        for(int i = 0; i < 4; i++) ter_patch_loc[i] = ter_orig[i];
    
        flush_cache(ter_patch_loc, sizeof(ter_orig));

        ter_patched = false;

        ml_set_interrupts_enabled(old_ie);
    }
#endif

    if(prefetch_saved) {
        vector_base()[3+8] = prefetch_saved;
        prefetch_saved = NULL;
    }

    if(data_saved) {
        vector_base()[4+8] = data_saved;
        data_saved = NULL;
    }
}
Esempio n. 3
0
int protoss_write_debug_reg(uint32_t reg, uint32_t val) {
    //IOLog("%d %d\n", reg, val);
    begin_debug();
    read_debug(197);
    write_debug(reg, val);
    end_debug();
    return 0;
}
Esempio n. 4
0
int protoss_go() {
    if(trace_going || watch_going) {
        IOLog("protoss_go: already enabled\n");
        return -1;
    }
    
    if(vector_base()[3] != (void *) 0xe59ff018) {
        return -1;
    }
    
    trace_going = true;

    if(!trace_start) trace_start = IOMalloc(num_trace_entries * sizeof(struct trace_entry));
    memset(trace_start, 0, (num_trace_entries - 1) * sizeof(struct trace_entry));
    memset(&trace_start[num_trace_entries - 1], 0xff, sizeof(struct trace_entry));
    trace_ptr = &trace_start[1];

    // We can't ever branch to 80xxxxxx, so overwrite it here
    prefetch_saved = vector_base()[3+8];
    vector_base()[3+8] = (void *) trace_prefetch_handler;

    union dbgbcr dbgbcr5, dbgbcr4;
    dbgbcr5.val = dbgbcr4.val = 0;
    uint32_t dbgbvr5, dbgbvr4;

    dbgbcr5.z1 = 0;
    dbgbcr5.address_range_mask = 0;
    dbgbcr5.z2 = 0;
    dbgbcr5.dbgbvr_match_or_mismatch = 1; // mismatch
    dbgbcr5.dbgbvr_iva_or_context_id = 0; // IVA
    dbgbcr5.dbgbvr_unlinked_or_linked = 1; // linked
    dbgbcr5.linked_brp_num = 4;
    dbgbcr5.security_state_control = 0; // match in either security state
    dbgbcr5.byte_address_select = 0xf; // I don't understand why this exists.
    dbgbcr5.z4 = 0;
    dbgbcr5.privileged_mode_control = 0; // user, system, svc *but not* exception
    dbgbcr5.breakpoint_enable = 1; // woo
    
    dbgbvr5 = 0xdeadbeec; // asm will fill this in for single stepping
    
    dbgbcr4.z1 = 0;
    dbgbcr4.address_range_mask = 0; // exact (but it's step-two for thumb :()
    dbgbcr4.z2 = 0;
    dbgbcr4.dbgbvr_match_or_mismatch = 0; // match
    dbgbcr4.dbgbvr_iva_or_context_id = 1; // Context ID
    dbgbcr4.dbgbvr_unlinked_or_linked = 1;
    dbgbcr4.linked_brp_num = 5;
    dbgbcr4.security_state_control = 0;
    dbgbcr4.byte_address_select = 0xf;
    dbgbcr4.z4 = 0;
    dbgbcr4.privileged_mode_control = 0;
    dbgbcr4.breakpoint_enable = 1;

    IOLog("%08x %08x\n", dbgbcr5.val, dbgbcr4.val);

    // get current context ID
    asm("mrc p15, 0, %0, c13, c0, 1" :"=r"(dbgbvr4) :);
    
    begin_debug(); // interrupts disabled
    read_debug(197);
    uint32_t dbgdscr = read_debug(34);
    dbgdscr |= 0x8000; // turn on debug
    write_debug(34, dbgdscr);
    for(int i = 0; i < 16; i++) {
        write_debug(80 + i, 0);
        write_debug(112 + i, 0);
    }
    for(int i = 0; i < 16; i++) {
        uint32_t bvr = 0, bcr = 0;
        if(i == 4) {
            bvr = dbgbvr4;
            bcr = dbgbcr4.val;
        } else if(i == 5) {
            bvr = dbgbvr5;
            bcr = dbgbcr5.val;
        }
        write_debug(64 + i, bvr);
        write_debug(80 + i, bcr);
        write_debug(112 + i, read_debug(112 + i));
    }
    end_debug();
    
    return 0;
}
Esempio n. 5
0
int memory_debug_line_m(struct _memory *memory, uint32_t address)
{
  return read_debug(memory, address);
}
Esempio n. 6
0
int memory_debug_line(struct _asm_context *asm_context, uint32_t address)
{
  return read_debug(&asm_context->memory, address);
}
Esempio n. 7
0
int main(int argc, char* argv[]) {
	int rv;
	unsigned int ret;
	USBContext context;
	USBBuffer buffer(65);
	//context.setDebug(4);
	USBDevice::Ptr device = context.openDeviceWithVidPid(0x04b4, 0x1004);

#ifndef WIN32
	if(device->isKernelDriverActive(0)) device->detachKernelDriver(0);
#endif

	device->setConfiguration(1);
	device->claimInterface(0);
	device->setInterfaceAltSetting(0, 0);

	libusb_device_handle *hndl = device->getDeviceHandle();

	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	printf("AdslSniffer Test\n");
	printf("RESET\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x90,
		0x11,
		0x22,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}

	ret = buffer.controlTransfer(*device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x94, 0x11, 0x22, buffer.getBufferSize()-1);
	if(ret < buffer.getBufferSize()) {
		unsigned char *cBuffer = buffer.getBuffer();
		cBuffer[ret] = '\0';
		std::cout << cBuffer << std::endl;
	} else {
		std::cerr << "Error during version grabbing" << std::endl;
	}

	ret = buffer.controlTransfer(*device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x95, 0x11, 0x22, buffer.getBufferSize()-1);
	if(ret == 4) {
		unsigned int *rate = (unsigned int *)buffer.getBuffer();
		std::cout << "Sample rate: " << *rate << std::endl;
	} else {
		std::cerr << "Error during sample rate grabbing" << std::endl;
	}

	printf("Enable debug\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x91,
		0x01,
		0x22,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL(Debug) Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}

	read_debug(hndl, 1000);
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	printf("Print test\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x99,
		0x00,
		0x22,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL(Debug) Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}

	read_debug(hndl, 1000);
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);


	printf("Start Test\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x92,
		0xffff,
		0xffff,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL(Start) Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}
	read_debug(hndl, 0);
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	USBRequest request(8, 2048);

	context.start<>();

	// Send request
	bench_start();
	request.send(device, 0x82, BENCH_DATA_SIZE, usb_cb);
	bench_inc();
	request.wait();
	bench_stop();

	context.stop();
	context.wait();

	printf("Stop Test\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x93,
		0xffff,
		0xffff,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL(Stop) Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}
	read_debug(hndl, 0);
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	printf("Print test\n");
	rv = libusb_control_transfer(hndl,
		LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
		0x99,
		0x00,
		0x22,
		0,
		0,
		0);
	if(rv != 0) {
		printf ( "CONTROL(Debug) Transfer failed: %s(%d)\n", libusb_error_name(rv), rv);
		return rv;
	}
	read_debug(hndl, 0);
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	// Empty debug
	while(read_debug(hndl) != LIBUSB_ERROR_TIMEOUT);

	// Close device
	device->releaseInterface(0);
	device.reset();

	printf("Test end\n");
	bench_stats();

	return 0;
}
Esempio n. 8
0
const wchar_t *
el_wgets(EditLine *el, int *nread)
{
	int retval;
	el_action_t cmdnum = 0;
	int num;		/* how many chars we have read at NL */
	wchar_t wc;
	wchar_t ch, *cp;
	int crlf = 0;
	int nrb;

	if (nread == NULL)
		nread = &nrb;
	*nread = 0;

	if (el->el_flags & NO_TTY) {
		size_t idx;

		cp = el->el_line.buffer;
		while ((num = (*el->el_read->read_char)(el, &wc)) == 1) {
			*cp = wc;
			/* make sure there is space for next character */
			if (cp + 1 >= el->el_line.limit) {
				idx = (size_t)(cp - el->el_line.buffer);
				if (!ch_enlargebufs(el, (size_t)2))
					break;
				cp = &el->el_line.buffer[idx];
			}
			cp++;
			if (el->el_flags & UNBUFFERED)
				break;
			if (cp[-1] == '\r' || cp[-1] == '\n')
				break;
		}
		if (num == -1) {
			if (errno == EINTR)
				cp = el->el_line.buffer;
			el->el_errno = errno;
		}

		goto noedit;
	}


#ifdef FIONREAD
	if (el->el_tty.t_mode == EX_IO && el->el_chared.c_macro.level < 0) {
		int chrs = 0;

		(void) ioctl(el->el_infd, FIONREAD, &chrs);
		if (chrs == 0) {
			if (tty_rawmode(el) < 0) {
				errno = 0;
				*nread = 0;
				return NULL;
			}
		}
	}
#endif /* FIONREAD */

	if ((el->el_flags & UNBUFFERED) == 0)
		read_prepare(el);

	if (el->el_flags & EDIT_DISABLED) {
		size_t idx;

		if ((el->el_flags & UNBUFFERED) == 0)
			cp = el->el_line.buffer;
		else
			cp = el->el_line.lastchar;

		terminal__flush(el);

		while ((num = (*el->el_read->read_char)(el, &wc)) == 1) {
			*cp = wc;
			/* make sure there is space next character */
			if (cp + 1 >= el->el_line.limit) {
				idx = (size_t)(cp - el->el_line.buffer);
				if (!ch_enlargebufs(el, (size_t)2))
					break;
				cp = &el->el_line.buffer[idx];
			}
			cp++;
			crlf = cp[-1] == '\r' || cp[-1] == '\n';
			if (el->el_flags & UNBUFFERED)
				break;
			if (crlf)
				break;
		}

		if (num == -1) {
			if (errno == EINTR)
				cp = el->el_line.buffer;
			el->el_errno = errno;
		}

		goto noedit;
	}

	for (num = -1; num == -1;) {  /* while still editing this line */
#ifdef DEBUG_EDIT
		read_debug(el);
#endif /* DEBUG_EDIT */
		/* if EOF or error */
		if (read_getcmd(el, &cmdnum, &ch) == -1) {
#ifdef DEBUG_READ
			(void) fprintf(el->el_errfile,
			    "Returning from el_gets\n");
#endif /* DEBUG_READ */
			break;
		}
		if (el->el_errno == EINTR) {
			el->el_line.buffer[0] = '\0';
			el->el_line.lastchar =
			    el->el_line.cursor = el->el_line.buffer;
			break;
		}
		if ((size_t)cmdnum >= el->el_map.nfunc) {	/* BUG CHECK command */
#ifdef DEBUG_EDIT
			(void) fprintf(el->el_errfile,
			    "ERROR: illegal command from key 0%o\r\n", ch);
#endif /* DEBUG_EDIT */
			continue;	/* try again */
		}
		/* now do the real command */
#ifdef DEBUG_READ
		{
			el_bindings_t *b;
			for (b = el->el_map.help; b->name; b++)
				if (b->func == cmdnum)
					break;
			if (b->name)
				(void) fprintf(el->el_errfile,
				    "Executing %ls\n", b->name);
			else
				(void) fprintf(el->el_errfile,
				    "Error command = %d\n", cmdnum);
		}
#endif /* DEBUG_READ */
		/* vi redo needs these way down the levels... */
		el->el_state.thiscmd = cmdnum;
		el->el_state.thisch = ch;
		if (el->el_map.type == MAP_VI &&
		    el->el_map.current == el->el_map.key &&
		    el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) {
			if (cmdnum == VI_DELETE_PREV_CHAR &&
			    el->el_chared.c_redo.pos != el->el_chared.c_redo.buf
			    && iswprint(el->el_chared.c_redo.pos[-1]))
				el->el_chared.c_redo.pos--;
			else
				*el->el_chared.c_redo.pos++ = ch;
		}
		retval = (*el->el_map.func[cmdnum]) (el, ch);
#ifdef DEBUG_READ
		(void) fprintf(el->el_errfile,
			"Returned state %d\n", retval );
#endif /* DEBUG_READ */

		/* save the last command here */
		el->el_state.lastcmd = cmdnum;

		/* use any return value */
		switch (retval) {
		case CC_CURSOR:
			re_refresh_cursor(el);
			break;

		case CC_REDISPLAY:
			re_clear_lines(el);
			re_clear_display(el);
			/* FALLTHROUGH */

		case CC_REFRESH:
			re_refresh(el);
			break;

		case CC_REFRESH_BEEP:
			re_refresh(el);
			terminal_beep(el);
			break;

		case CC_NORM:	/* normal char */
			break;

		case CC_ARGHACK:	/* Suggested by Rich Salz */
			/* <*****@*****.**> */
			continue;	/* keep going... */

		case CC_EOF:	/* end of file typed */
			if ((el->el_flags & UNBUFFERED) == 0)
				num = 0;
			else if (num == -1) {
				*el->el_line.lastchar++ = CONTROL('d');
				el->el_line.cursor = el->el_line.lastchar;
				num = 1;
			}
			break;

		case CC_NEWLINE:	/* normal end of line */
			num = (int)(el->el_line.lastchar - el->el_line.buffer);
			break;

		case CC_FATAL:	/* fatal error, reset to known state */
#ifdef DEBUG_READ
			(void) fprintf(el->el_errfile,
			    "*** editor fatal ERROR ***\r\n\n");
#endif /* DEBUG_READ */
			/* put (real) cursor in a known place */
			re_clear_display(el);	/* reset the display stuff */
			ch_reset(el, 1);	/* reset the input pointers */
			re_refresh(el); /* print the prompt again */
			break;

		case CC_ERROR:
		default:	/* functions we don't know about */
#ifdef DEBUG_READ
			(void) fprintf(el->el_errfile,
			    "*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
			terminal_beep(el);
			terminal__flush(el);
			break;
		}
		el->el_state.argument = 1;
		el->el_state.doingarg = 0;
		el->el_chared.c_vcmd.action = NOP;
		if (el->el_flags & UNBUFFERED)
			break;
	}

	terminal__flush(el);		/* flush any buffered output */
	/* make sure the tty is set up correctly */
	if ((el->el_flags & UNBUFFERED) == 0) {
		read_finish(el);
		*nread = num != -1 ? num : 0;
	} else {
		*nread = (int)(el->el_line.lastchar - el->el_line.buffer);
	}
	goto done;
noedit:
	el->el_line.cursor = el->el_line.lastchar = cp;
	*cp = '\0';
	*nread = (int)(el->el_line.cursor - el->el_line.buffer);
done:
	if (*nread == 0) {
		if (num == -1) {
			*nread = -1;
			errno = el->el_errno;
		}
		return NULL;
	} else
		return el->el_line.buffer;
}