last backups of BBB and GUI s/w

This commit is contained in:
2022-04-22 14:43:58 -07:00
commit 011d4431fd
276 changed files with 121700 additions and 0 deletions
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
Copyright (c) 2011, Arctica Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Arctica Technologies nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+8
View File
@@ -0,0 +1,8 @@
CC=arm-none-linux-gnueabi-gcc
objs = prudbg.o cmdinput.o cmd.o printhelp.o da.o uio.o
prudebug : ${objs}
${CC} ${objs} -o prudebug
+189
View File
@@ -0,0 +1,189 @@
Prudebug Version 0.25
(C) Copyright 2011, 2013 by Arctica Technologies
Written by Steven Anderson
Prudebug is a very small program that was initially intended to be 100-200 lines of code to start/stop the PRU and load a binary in the PRU.
As I worked through my PRU development project I added several addition features (some I needed for debugging the project, and a few just
because they seemed nice). After completing the PRU coding project this program sat unused for about a year before I decided that maybe
someone else out there needed a PRU debugger. After all, if you need a hard realtime process and you're using Linux, a PRU is an easy
way to go.
THIS PROGRAM HAS VERY LIMITED TESTING - USE AT YOUR OWN RISK.
I did test the features that I used, but there are many features I didn't need for my project. I attempted a couple quick tests with the
unused features, but it would be very easy to miss something. For example, I only used PRU0 for my coding, so very little testing was done
with PRU1. I'm sure the user interface has bugs but I haven't hit them yet....it's easy to miss issues when you know how it's supposed
to work. As I continue to add code, I'll try to do a more complete job of testing, but I will continue to use feedback for locating most
bugs.
RELEASE NOTES for prudebug
---------------------------------------------------------------------
Version 0.24
Improvements:
Added support for UIO PRUSS driver
Moved to dynamic processor selection - user can pick a processor on the command line
Fixed watchpoints and breakpoints to support different values on different PRUs
Version 0.25
Bug fixes provided by Shoji Suzuki
Correction to the QBA instruction decode
Fix backspace code for terminals using 0x7f
Corrected issue with writing numbers greater than 0x7fffffff to PRU memory with the wr command
BUGS
---------------------------------------------------------------------
Please let me know if you find any bugs or you have comments on prudebug (steve.anderson@arcticatechnologies.com). You can also log a bug
on the SourceForge page. I will try to fix bugs as time permits.
No known bugs at the time of v0.25 release
USE WITH PRUSS v2
---------------------------------------------------------------------
prudebug should work fine with the PRUSSv2. It does not support any new features of the PRUSSv2, but I will try to add some as
time permits. I have done some testing on both the AM1707 (PRUSSv1) and AM3358 (PRUSSv2) processors.
CONTRIBUTORS
---------------------------------------------------------------------
Christian Joly - bug fixes, and modifications to make prudebug work with PRUSSv2.
Shoji Suzuki - bug fixes for v0.25
INSTALLATION
---------------------------------------------------------------------
To build just run make in the source code directory (make sure you have the correct cross-compiler in place and in the path -
arm-none-linux-gnueabi-gcc). The binary is called prudebug.
USAGE
---------------------------------------------------------------------
Usage: prudebug [-a pruss-address] [-u] [-m] [-p processor]
-a - pruss-address is the memory address of the PRU in ARM memory space
-u - force the use of UIO to map PRU memory space
-m - force the use of /dev/mem to map PRU memory space
if neither the -u or -m options are used then it will try the UIO first
-p - select processor to use (sets the PRU memory locations)
AM1707 - AM1707
AM335X - AM335x
Generally the -a option should not be used. If it is used, then prudebug will use the -a address for the PRU base with
the selected processor as the various PRU subsystem offsets. -u and -m control the way the PRU base address is mapped for
program access (either the /dev/mem or /dev/uio* device). If -u or -m are selected then it will only used the selected
method or fail. If neither the -u or -m are selected then prudebug will try to use the UIO device driver, and if that fails
then it will use /dev/mem. The -p option allows you to select the processor. If your processor is not listed then determine
if one of the listed processors has compatible PRU (same base address and PRU subsystem offsets). If not, you'll need to
modify prudbg.c and prudbg.h (see remarks near the beginning of prudbg.c). If you do add to the list of processors, please
send me the diff so I can add it into future releases.
COMMAND HELP
I would like to spend a little time writing up a command document, but in the meantime the following will have to do.
The command line takes the command 'help' to provide a detailed help, and 'hb' for a brief help. Listed below is both.
PRU0> hb
Command help
BR [breakpoint_number [address]] - View or set an instruction breakpoint
D memory_location_wa [length] - Raw dump of PRU data memory (32-bit word offset from beginning of full PRU memory block - all PRUs)
DD memory_location_wa [length] - Dump data memory (32-bit word offset from beginning of PRU data memory)
DI memory_location_wa [length] - Dump instruction memory (32-bit word offset from beginning of PRU instruction memory)
DIS memory_location_wa [length] - Disassemble instruction memory (32-bit word offset from beginning of PRU instruction memory)
G - Start processor execution of instructions (at current IP)
GSS - Start processor execution using automatic single stepping - this allows running a program with breakpoints
HALT - Halt the processor
L memory_location_iwa file_name - Load program file into instruction memory
PRU pru_number - Set the active PRU where pru_number ranges from 0 to 1
Q - Quit the debugger and return to shell prompt.
R - Display the current PRU registers.
RESET - Reset the current PRU
SS - Single step the current instruction.
WA [watch_num [address [value]]] - Clear or set a watch point
WR memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to a raw (offset from beginning of full PRU memory block)
WRD memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to PRU data memory for current PRU
WRI memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to PRU instruction memory for current PRU
PRU0> help
Command help
Commands are case insensitive
Address and numeric values can be dec (ex 12), hex (ex 0xC), or octal (ex 014)
Memory addresses can be wa=32-bit word address, ba=byte address. Suffix of i=instruction or d=data memory
Return without a command will rerun a previous d, dd, or di command while displaying the next block
BR [breakpoint_number [address]]
View or set an instruction breakpoint
'b' by itself will display current breakpoints
breakpoint_number is the breakpoint reference and ranges from 0 to 4
address is the instruction word address that the processor should stop at (instruction is not executed)
if no address is provided, then the breakpoint is cleared
D memory_location_wa [length]
Raw dump of PRU data memory (32-bit word offset from beginning of full PRU memory block - all PRUs)
DD memory_location_wa [length]
Dump data memory (32-bit word offset from beginning of PRU data memory)
DI memory_location_wa [length]
Dump instruction memory (32-bit word offset from beginning of PRU instruction memory)
DIS memory_location_wa [length]
Disassemble instruction memory (32-bit word offset from beginning of PRU instruction memory)
G
Start processor execution of instructions (at current IP)
GSS
Start processor execution using automatic single stepping - this allows running a program with breakpoints
HALT
Halt the processor
L memory_location_iwa file_name
Load program file into instruction memory at 32-bit word address provided (offset from beginning of instruction memory
PRU pru_number
Set the active PRU where pru_number ranges from 0 to 1
Some debugger commands do action on active PRU (such as halt and reset)
Q
Quit the debugger and return to shell prompt.
R
Display the current PRU registers.
RESET
Reset the current PRU
SS
Single step the current instruction.
WA [watch_num [address [value]]]
Clear or set a watch point
format 1: wa - print watch point list
format 2: wa watch_num - clear watch point watch_num
format 3: wa watch_num address - set a watch point (watch_num) so any change at that word address
in data memory will be printed during program execution with gss command
format 4: wa watch_num address value - set a watch point (watch_num) so that the program (run with gss) will
be halted when the memory location equals the value
NOTE: for watchpoints to work, you must use gss command to run the program
WR memory_location_wa value1 [value2 [value3 ...]]
Write a 32-bit value to a raw (offset from beginning of full PRU memory block - all PRUs)
memory_location is a 32-bit word index from the beginning of the PRU subsystem memory block
WRD memory_location_wa value1 [value2 [value3 ...]]
Write a 32-bit value to PRU data memory (32-bit word offset from beginning of PRU data memory)
WRI memory_location_wa value1 [value2 [value3 ...]]
Write a 32-bit value to PRU instruction memory (32-bit word offset from beginning of PRU instruction memory)
A brief version of help is available with the command hb
+317
View File
@@ -0,0 +1,317 @@
/*
*
* PRU Debug Program
* (c) Copyright 2011, 2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include "prudbg.h"
// breakpoint management
int cmd_print_breakpoints()
{
int i;
printf("## Address\n");
for (i=0; i<MAX_BREAKPOINTS; i++) {
if (bp[pru_num][i].state == BP_ACTIVE) {
printf("%02u 0x%04x\n", i, bp[pru_num][i].address);
} else {
printf("%02u UNUSED\n", i);
}
}
printf("\n");
}
// set breakpoint
int cmd_set_breakpoint (unsigned int bpnum, unsigned int addr)
{
bp[pru_num][bpnum].state = BP_ACTIVE;
bp[pru_num][bpnum].address = addr;
}
// clear breakpoint
int cmd_clear_breakpoint (unsigned int bpnum)
{
bp[pru_num][bpnum].state = BP_UNUSED;
}
// dump data memory
int cmd_d (int offset, int addr, int len)
{
int i, j;
for (i=0; i<len; ) {
printf ("[0x%04x] ", addr+i);
for (j=0;(i<len)&&(j<4); i++,j++) printf ("0x%08x ", pru[offset+addr+i]);
printf ("\n");
}
printf("\n");
}
// disassemble instruction memory
int cmd_dis (int offset, int addr, int len)
{
int i, j;
char inst_str[50];
unsigned int status_reg;
char *pc[] = {" ", ">>"};
int pc_on = 0;
status_reg = (pru[pru_ctrl_base[pru_num] + PRU_STATUS_REG]) & 0xFFFF;
for (i=0; i<len; i++) {
if (status_reg == (addr + i)) pc_on = 1; else pc_on = 0;
disassemble(inst_str, pru[offset+addr+i]);
printf ("[0x%04x] 0x%08x %s %s\n", addr+i, pru[offset+addr+i], pc[pc_on], inst_str);
}
printf("\n");
}
// halt the current PRU
void cmd_halt()
{
unsigned int ctrl_reg;
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg &= ~PRU_REG_PROC_EN;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
printf("PRU%u Halted.\n", pru_num);
}
// load program into instruction memory
int cmd_loadprog(unsigned int addr, char *fn)
{
int f, r;
struct stat file_info;
r = stat(fn, &file_info);
if (r == -1) {
printf("ERROR: could not open file\n");
return 1;
}
if (((file_info.st_size/4)*4) != file_info.st_size) {
printf("ERROR: file size is not evenly divisible by 4\n");
} else {
f = open(fn, O_RDONLY);
if (f == -1) {
printf("ERROR: could not open file 2\n");
} else {
read(f, &pru[pru_inst_base[pru_num] + addr], file_info.st_size);
close(f);
printf("Binary file of size %u bytes loaded into PRU%u instruction RAM.\n", file_info.st_size, pru_num);
}
}
return 0;
}
// print current PRU registers
void cmd_printregs()
{
unsigned int ctrl_reg, reset_pc, status_reg;
char *run_state, *single_step, *cycle_cnt_en, *pru_sleep, *proc_en;
unsigned int i;
char inst_str[50];
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
status_reg = pru[pru_ctrl_base[pru_num] + PRU_STATUS_REG];
reset_pc = (ctrl_reg >> 16);
if (ctrl_reg&PRU_REG_RUNSTATE)
run_state = "RUNNING";
else
run_state = "STOPPED";
if (ctrl_reg&PRU_REG_SINGLE_STEP)
single_step = "SINGLE_STEP";
else
single_step = "FREE_RUN";
if (ctrl_reg&PRU_REG_COUNT_EN)
cycle_cnt_en = "COUNTER_ENABLED";
else
cycle_cnt_en = "COUNTER_DISABLED";
if (ctrl_reg&PRU_REG_SLEEPING)
pru_sleep = "SLEEPING";
else
pru_sleep = "NOT_SLEEPING";
if (ctrl_reg&PRU_REG_PROC_EN)
proc_en = "PROC_ENABLED";
else
proc_en = "PROC_DISABLED";
printf("Register info for PRU%u\n", pru_num);
printf(" Control register: 0x%08x\n", ctrl_reg);
printf(" Reset PC:0x%04x %s, %s, %s, %s, %s\n\n", reset_pc, run_state, single_step, cycle_cnt_en, pru_sleep, proc_en);
disassemble(inst_str, pru[pru_inst_base[pru_num] + (status_reg&0xFFFF)]);
printf(" Program counter: 0x%04x\n", (status_reg&0xFFFF));
printf(" Current instruction: %s\n\n", inst_str);
if (ctrl_reg&PRU_REG_RUNSTATE) {
printf(" Rxx registers not available since PRU is RUNNING.\n");
} else {
for (i=0; i<8; i++) printf(" R%02u: 0x%08x R%02u: 0x%08x R%02u: 0x%08x R%02u: 0x%08x\n", i, pru[pru_ctrl_base[pru_num] + PRU_INTGPR_REG + i], i+8, pru[pru_ctrl_base[pru_num] + PRU_INTGPR_REG + i + 8], i+16, pru[pru_ctrl_base[pru_num] + PRU_INTGPR_REG + i + 16], i+24, pru[pru_ctrl_base[pru_num] + PRU_INTGPR_REG + i + 24]);
}
printf("\n");
}
// start PRU running
void cmd_run()
{
unsigned int ctrl_reg;
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg |= PRU_REG_PROC_EN;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
}
// run PRU in a single stepping mode - used for breakpoints and watch variables
void cmd_runss()
{
unsigned int i, addr;
unsigned int done = 0;
unsigned int ctrl_reg;
unsigned long t_cyc = 0;
fd_set rd_fdset;
struct timeval tv;
int r;
printf("Running (will run until a breakpoint is hit or a key is pressed)....\n");
// enter single-step loop
do {
// prep some 'select' magic to detect keypress to escape
FD_ZERO(&rd_fdset);
FD_SET(STDIN_FILENO, &rd_fdset);
tv.tv_sec = 0;
tv.tv_usec = 0;
// set single step mode and enable processor
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg |= PRU_REG_PROC_EN | PRU_REG_SINGLE_STEP;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
// check if we've hit a breakpoint
addr = pru[pru_ctrl_base[pru_num] + PRU_STATUS_REG] & 0xFFFF;
for (i=0; i<MAX_BREAKPOINTS; i++) if ((bp[pru_num][i].state == BP_ACTIVE) && (bp[pru_num][i].address == addr)) done = 1;
// check if we've hit a watch point
// addr = pru[pru_ctrl_base[pru_num] + PRU_STATUS_REG] & 0xFFFF;
for (i=0; i<MAX_WATCH; i++) {
if ((wa[pru_num][i].state == WA_PRINT_ON_ANY) && (wa[pru_num][i].old_value != pru[pru_data_base[pru_num] + wa[pru_num][i].address])) {
printf("[0x%04x] 0x%04x t=%lu\n", wa[pru_num][i].address, pru[pru_data_base[pru_num] + wa[pru_num][i].address], t_cyc);
wa[pru_num][i].old_value = pru[pru_data_base[pru_num] + wa[pru_num][i].address];
} else if ((wa[pru_num][i].state == WA_HALT_ON_VALUE) && (wa[pru_num][i].value == pru[pru_data_base[pru_num] + wa[pru_num][i].address])) {
printf("[0x%04x] 0x%04x t=%lu\n", wa[pru_num][i].address, pru[pru_data_base[pru_num] + wa[pru_num][i].address], t_cyc);
done = 1;
}
}
// check if we are on a HALT instruction - if so, stop single step execution
if (pru[pru_inst_base[pru_num] + addr] == 0x2a000000) {
printf("\nHALT instruction hit.\n");
done = 1;
}
// check if the user has attempted to stop execution of the PRU with a keypress
r = select (STDIN_FILENO+1, &rd_fdset, NULL, NULL, &tv);
// increase time
t_cyc++;
} while ((!done) && (r == 0));
// if there is a character in the stdin queue, read the character
if (r > 0) getchar();
printf("\n");
// print the registers
cmd_printregs();
}
void cmd_single_step()
{
unsigned int ctrl_reg;
// set single step mode and enable processor
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg |= PRU_REG_PROC_EN | PRU_REG_SINGLE_STEP;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
// print the registers
cmd_printregs();
// disable single step mode and disable processor
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg &= ~PRU_REG_PROC_EN;
ctrl_reg &= ~PRU_REG_SINGLE_STEP;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
}
void cmd_soft_reset()
{
unsigned int ctrl_reg;
ctrl_reg = pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG];
ctrl_reg &= ~PRU_REG_SOFT_RESET;
pru[pru_ctrl_base[pru_num] + PRU_CTRL_REG] = ctrl_reg;
printf("PRU%u reset.\n", pru_num);
}
// print list of watches
void cmd_print_watch()
{
int i;
printf("## Address Value\n");
for (i=0; i<MAX_WATCH; i++) {
if (wa[pru_num][i].state == WA_PRINT_ON_ANY) {
printf("%02u 0x%04x Print on any\n", i, wa[pru_num][i].address);
} else if (wa[pru_num][i].state == WA_HALT_ON_VALUE) {
printf("%02u 0x%04x Halt = 0x%04x\n", i, wa[pru_num][i].address, wa[pru_num][i].value);
} else {
printf("%02u UNUSED\n", i);
}
}
printf("\n");
}
// clear a watch from list
void cmd_clear_watch (unsigned int wanum)
{
wa[pru_num][wanum].state = WA_UNUSED;
}
// set a watch for any change in value and no halt
void cmd_set_watch_any (unsigned int wanum, unsigned int addr)
{
wa[pru_num][wanum].state = WA_PRINT_ON_ANY;
wa[pru_num][wanum].address = addr;
wa[pru_num][wanum].old_value = pru[pru_data_base[pru_num] + addr];
}
// set a watch for a specific value and halt
void cmd_set_watch (unsigned int wanum, unsigned int addr, unsigned int value)
{
wa[pru_num][wanum].state = WA_HALT_ON_VALUE;
wa[pru_num][wanum].address = addr;
wa[pru_num][wanum].value = value;
}
Binary file not shown.
+77
View File
@@ -0,0 +1,77 @@
/*
*
* PRU Debug Program - command input function
* (c) Copyright 2011, 2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include "prudbg.h"
int cmd_input(char *prompt, char *cmd, char *cmdargs, unsigned int *argptrs, unsigned int *numargs)
{
unsigned int i, j, full_len, on_zero;
char c, last_char;
char buf[MAX_COMMAND_LINE];
// print prompt
printf("%s", prompt);
// collect command until space or return
i = 0;
do {
c = getchar();
// check for backspace
if (c == 0x08 || c == 0x7F) {
if (i != 0) {
putchar(0x08);
putchar(' ');
putchar(0x08);
i--;
}
// just a normal character
} else {
buf[i] = c;
printf("%c", buf[i]);
if (i < (MAX_COMMAND_LINE - 1)) i++;
}
} while (c != '\n');
buf[i-1] = 0;
// replace spaces and return with zeros
full_len = strlen(buf);
for (i=0; i<full_len; i++) if (buf[i] == ' ') buf[i] = 0;
// copy command (first word) to cmd argument and shift to upper case
for (i=0; i<(strlen(buf)+1); i++) cmd[i] = toupper(buf[i]);
// build index array and count number of arguments
for (i=strlen(cmd), on_zero=TRUE, numargs[0]=0; i<full_len; i++) {
if (on_zero) {
if (buf[i] != 0) {
on_zero = FALSE;
argptrs[numargs[0]++] = i;
}
} else {
if (buf[i] == 0) on_zero = TRUE;
}
}
for (i=0; i<full_len+1; i++) cmdargs[i] = buf[i];
return 0;
}
Binary file not shown.
+238
View File
@@ -0,0 +1,238 @@
/*
*
* PRU Debug Program - disassembly routines
* (c) Copyright 2011 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include "prudbg.h"
// util function to decode BurstLen in Format 6 instructions
void GetBurstLen(char *tempstr, unsigned int BurstLen)
{
if (BurstLen < 124) {
sprintf(tempstr, "%u", BurstLen+1);
} else if (BurstLen == 124) {
sprintf(tempstr, "b0");
} else if (BurstLen == 125) {
sprintf(tempstr, "b1");
} else if (BurstLen == 126) {
sprintf(tempstr, "b2");
} else if (BurstLen == 127) {
sprintf(tempstr, "b3");
} else {
sprintf(tempstr, "XX");
}
}
// disassemble the inst instruction and place string in str
void disassemble(char *str, unsigned int inst)
{
unsigned short Imm;
unsigned char OP, ALUOP, Rs2Sel, Rs2, Rs1Sel, Rs1, RdSel, Rd, IO, Imm2, SUBOP, Test;
unsigned char LoadStore, BurstLen, RxByteAddr, Rx, Ro, RoSel, Rb;
short BrOff;
char tempstr[50];
char *f1_inst[] = {"ADD", "ADC", "SUB", "SUC", "LSL", "LSR", "RSB", "RSC", "AND", "OR", "XOR", "NOT", "MIN", "MAX", "CLR", "SET"};
char *f2_inst[] = {
"JMP", "JAL", "LDI", "LMBD", "SCAN", "HALT",
"RESERVED", "RESERVED", "RESERVED", "RESERVED", "RESERVED", "RESERVED", "RESERVED", "RESERVED", "RESERVED",
"SLP"
};
char *f4_inst[] = {"xx", "LT", "EQ", "LE", "GT", "NE", "GE", "A"};
char *f5_inst[] = {"xx", "BC", "BS", "xx"};
char *f6_7_inst[] = {"SBBO", "LBBO"};
char *f6_4_inst[] = {"SBCO", "LBCO"};
char *sis[] = {".b0", ".b1", ".b2", ".b3", ".w0", ".w1", ".w2", ""};
char *bytenum[] = {"", ".b1", ".b2", ".b3"};
OP = (inst & 0xE0000000) >> 29;
switch (OP) {
case 0: // format 1
ALUOP = (inst & 0x1E000000) >> 25;
IO = (inst & 0x01000000) >> 24;
Rs1Sel = (inst & 0x0000E000) >> 13;
Rs1 = (inst & 0x00001F00) >> 8;
RdSel = (inst & 0x000000E0) >> 5;
Rd = (inst & 0x0000001F);
if (IO) {
Imm2 = (inst & 0x00FF0000) >> 16;
sprintf(str, "%s R%u%s, R%u%s, 0x%02x", f1_inst[ALUOP], Rd, sis[RdSel], Rs1, sis[Rs1Sel], Imm2);
} else {
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
sprintf(str, "%s R%u%s, R%u%s, R%u%s", f1_inst[ALUOP], Rd, sis[RdSel], Rs1, sis[Rs1Sel], Rs2, sis[Rs2Sel]);
}
break;
case 1: // format 2
SUBOP = (inst & 0x1E000000) >> 25;
switch (SUBOP) {
case 0: // JMP & JAL
case 1:
IO = (inst & 0x01000000) >> 24;
RdSel = (inst & 0x000000E0) >> 5;
Rd = (inst & 0x0000001F);
if (IO) {
Imm = (inst & 0x00FFFF00) >> 8;
if (SUBOP == 0)
sprintf(str, "%s 0x%04x", f2_inst[SUBOP], Imm);
else
sprintf(str, "%s R%u%s, 0x%04x", f2_inst[SUBOP], Rd, sis[RdSel], Imm);
} else {
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
if (SUBOP == 0)
sprintf(str, "%s R%u%s", f2_inst[SUBOP], Rs2, sis[Rs2Sel]);
else
sprintf(str, "%s R%u%s, R%u%s", f2_inst[SUBOP], Rd, sis[RdSel], Rs2, sis[Rs2Sel]);
}
break;
case 2: // LDI
Imm = (inst & 0x00FFFF00) >> 8;
RdSel = (inst & 0x000000E0) >> 5;
Rd = (inst & 0x0000001F);
sprintf(str, "%s R%u%s, 0x%04x", f2_inst[SUBOP], Rd, sis[RdSel], Imm);
break;
case 3: // LMBD
IO = (inst & 0x01000000) >> 24;
Rs1Sel = (inst & 0x0000E000) >> 13;
Rs1 = (inst & 0x00001F00) >> 8;
RdSel = (inst & 0x000000E0) >> 5;
Rd = (inst & 0x0000001F);
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
Imm2 = (inst & 0x00FF0000) >> 16;
if (IO) {
sprintf(str, "%s R%u%s, R%u%s, 0x%04x", f2_inst[SUBOP], Rd, sis[RdSel], Rs1, sis[Rs1Sel], Imm2);
} else {
sprintf(str, "%s R%u%s, R%u%s, R%u%s", f2_inst[SUBOP], Rd, sis[RdSel], Rs1, sis[Rs1Sel], Rs2, sis[Rs2Sel]);
}
break;
case 4: // SCAN
IO = (inst & 0x01000000) >> 24;
RdSel = (inst & 0x000000E0) >> 5;
Rd = (inst & 0x0000001F);
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
Imm2 = (inst & 0x00FF0000) >> 16;
if (IO) {
sprintf(str, "%s R%u%s, 0x%04x", f2_inst[SUBOP], Rd, sis[RdSel], Rs1, sis[Rs1Sel], Imm2);
} else {
sprintf(str, "%s R%u%s, R%u%s", f2_inst[SUBOP], Rd, sis[RdSel], Rs2, sis[Rs2Sel]);
}
break;
case 5: // HALT
sprintf(str, "%s", f2_inst[SUBOP]);
break;
case 15: // SLP
Imm = (inst & 0x00800000) >> 23;
sprintf(str, "%s %u", f2_inst[SUBOP], Imm);
break;
default:
sprintf(str, "UNKNOWN-F2");
break;
}
break;
case 2: // Format 4a & 4b - Quick Arithmetic Test and Branch
case 3:
Test = (inst & 0x38000000) >> 27;
IO = (inst & 0x01000000) >> 24;
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
Rs1Sel = (inst & 0x0000E000) >> 13;
Rs1 = (inst & 0x00001F00) >> 8;
Imm = (inst & 0x00FF0000) >> 16;
BrOff = ((inst & 0x06000000) >> 17) | (inst & 0x000000FF);
if (BrOff & 0x0200) BrOff |= 0xFC00;
if (Test == 7) {
sprintf(str, "QBA %d", BrOff);
} else {
if (IO) {
sprintf(str, "QB%s %d, R%u%s, %u", f4_inst[Test], BrOff, Rs1, sis[Rs1Sel], Imm);
} else {
sprintf(str, "QB%s %d, R%u%s, R%u%s", f4_inst[Test], BrOff, Rs1, sis[Rs1Sel], Rs2, sis[Rs2Sel]);
}
}
break;
case 6: // Format 5 - Quick bit test and banch instructions
Test = (inst & 0x18000000) >> 27;
IO = (inst & 0x01000000) >> 24;
Rs2Sel = (inst & 0x00E00000) >> 21;
Rs2 = (inst & 0x001F0000) >> 16;
Rs1Sel = (inst & 0x0000E000) >> 13;
Rs1 = (inst & 0x00001F00) >> 8;
Imm = (inst & 0x001F0000) >> 16;
BrOff = ((inst & 0x06000000) >> 17) | (inst & 0x000000FF);
if (BrOff & 0x0200) BrOff |= 0xFC00;
if (IO) {
sprintf(str, "QB%s %d, R%u%s, %u", f5_inst[Test], BrOff, Rs1, sis[Rs1Sel], Imm);
} else {
sprintf(str, "QB%s %d, R%u%s, R%u%s", f5_inst[Test], BrOff, Rs1, sis[Rs1Sel], Rs2, sis[Rs2Sel]);
}
break;
case 4:
case 7: // Format 6 - LBBO/SBBO/LBCO/SBCO instructions
LoadStore = (inst & 0x10000000) >> 28;
BurstLen = ((inst & 0x0E000000) >> 21) | ((inst & 0x0000E000) >> 12) | ((inst & 0x00000080) >> 7);
IO = (inst & 0x01000000) >> 24;
RxByteAddr = (inst & 0x00000060) >> 5;
Rx = (inst & 0x0000001F);
RoSel = (inst & 0x00E00000) >> 21;
Ro = (inst & 0x001F0000) >> 16;
Rb = (inst & 0x00001F00) >> 8;
Imm = (inst & 0x00FF0000) >> 16;
GetBurstLen(tempstr, BurstLen);
if (OP == 7) {
if (IO) {
sprintf(str, "%s R%u%s, R%u, %u, %s", f6_7_inst[LoadStore], Rx, bytenum[RxByteAddr], Rb, Imm, tempstr);
} else {
sprintf(str, "%s R%u%s, R%u, R%u%s, %s", f6_7_inst[LoadStore], Rx, bytenum[RxByteAddr], Rb, Ro, sis[RoSel], tempstr);
}
} else { // OP==4
if (IO) {
sprintf(str, "%s R%u%s, C%u, %u, %s", f6_4_inst[LoadStore], Rx, bytenum[RxByteAddr], Rb, Imm, tempstr);
} else {
sprintf(str, "%s R%u%s, C%u, R%u%s, %s", f6_4_inst[LoadStore], Rx, bytenum[RxByteAddr], Rb, Ro, sis[RoSel], tempstr);
}
}
break;
default:
sprintf(str, "UNKNOWN");
break;
}
}
Binary file not shown.
+117
View File
@@ -0,0 +1,117 @@
/*
*
* PRU Debug Program
* (c) Copyright 2011 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include "prudbg.h"
void printhelp()
{
printf("Command help\n\n");
printf(" Commands are case insensitive\n");
printf(" Address and numeric values can be dec (ex 12), hex (ex 0xC), or octal (ex 014)\n");
printf(" Memory addresses can be wa=32-bit word address, ba=byte address. Suffix of i=instruction or d=data memory\n");
printf(" Return without a command will rerun a previous d, dd, or di command while displaying the next block\n\n");
printf(" BR [breakpoint_number [address]]\n");
printf(" View or set an instruction breakpoint\n");
printf(" 'b' by itself will display current breakpoints\n");
printf(" breakpoint_number is the breakpoint reference and ranges from 0 to %u\n", MAX_BREAKPOINTS - 1);
printf(" address is the instruction word address that the processor should stop at (instruction is not executed)\n");
printf(" if no address is provided, then the breakpoint is cleared\n\n");
printf(" D memory_location_wa [length]\n");
printf(" Raw dump of PRU data memory (32-bit word offset from beginning of full PRU memory block - all PRUs)\n\n");
printf(" DD memory_location_wa [length]\n");
printf(" Dump data memory (32-bit word offset from beginning of PRU data memory)\n\n");
printf(" DI memory_location_wa [length]\n");
printf(" Dump instruction memory (32-bit word offset from beginning of PRU instruction memory)\n\n");
printf(" DIS memory_location_wa [length]\n");
printf(" Disassemble instruction memory (32-bit word offset from beginning of PRU instruction memory)\n\n");
printf(" G\n");
printf(" Start processor execution of instructions (at current IP)\n\n");
printf(" GSS\n");
printf(" Start processor execution using automatic single stepping - this allows running a program with breakpoints\n\n");
printf(" HALT\n");
printf(" Halt the processor\n\n");
printf(" L memory_location_iwa file_name\n");
printf(" Load program file into instruction memory at 32-bit word address provided (offset from beginning of instruction memory\n\n");
printf(" PRU pru_number\n");
printf(" Set the active PRU where pru_number ranges from 0 to %u\n", NUM_OF_PRU - 1);
printf(" Some debugger commands do action on active PRU (such as halt and reset)\n\n");
printf(" Q\n");
printf(" Quit the debugger and return to shell prompt.\n\n");
printf(" R\n");
printf(" Display the current PRU registers.\n\n");
printf(" RESET\n");
printf(" Reset the current PRU\n\n");
printf(" SS\n");
printf(" Single step the current instruction.\n\n");
printf(" WA [watch_num [address [value]]]\n");
printf(" Clear or set a watch point\n");
printf(" format 1: wa - print watch point list\n");
printf(" format 2: wa watch_num - clear watch point watch_num\n");
printf(" format 3: wa watch_num address - set a watch point (watch_num) so any change at that word address\n");
printf(" in data memory will be printed during program execution with gss command\n");
printf(" format 4: wa watch_num address value - set a watch point (watch_num) so that the program (run with gss) will\n");
printf(" be halted when the memory location equals the value\n");
printf(" NOTE: for watchpoints to work, you must use gss command to run the program\n\n");
printf(" WR memory_location_wa value1 [value2 [value3 ...]]\n");
printf(" Write a 32-bit value to a raw (offset from beginning of full PRU memory block - all PRUs)\n");
printf(" memory_location is a 32-bit word index from the beginning of the PRU subsystem memory block\n\n");
printf(" WRD memory_location_wa value1 [value2 [value3 ...]]\n");
printf(" Write a 32-bit value to PRU data memory (32-bit word offset from beginning of PRU data memory)\n\n");
printf(" WRI memory_location_wa value1 [value2 [value3 ...]]\n");
printf(" Write a 32-bit value to PRU instruction memory (32-bit word offset from beginning of PRU instruction memory)\n\n");
printf("A brief version of help is available with the command hb\n");
printf("\n");
}
void printhelpbrief()
{
printf("Command help\n\n");
printf(" BR [breakpoint_number [address]] - View or set an instruction breakpoint\n");
printf(" D memory_location_wa [length] - Raw dump of PRU data memory (32-bit word offset from beginning of full PRU memory block - all PRUs)\n");
printf(" DD memory_location_wa [length] - Dump data memory (32-bit word offset from beginning of PRU data memory)\n");
printf(" DI memory_location_wa [length] - Dump instruction memory (32-bit word offset from beginning of PRU instruction memory)\n");
printf(" DIS memory_location_wa [length] - Disassemble instruction memory (32-bit word offset from beginning of PRU instruction memory)\n");
printf(" G - Start processor execution of instructions (at current IP)\n");
printf(" GSS - Start processor execution using automatic single stepping - this allows running a program with breakpoints\n");
printf(" HALT - Halt the processor\n");
printf(" L memory_location_iwa file_name - Load program file into instruction memory\n");
printf(" PRU pru_number - Set the active PRU where pru_number ranges from 0 to %u\n", NUM_OF_PRU - 1);
printf(" Q - Quit the debugger and return to shell prompt.\n");
printf(" R - Display the current PRU registers.\n");
printf(" RESET - Reset the current PRU\n");
printf(" SS - Single step the current instruction.\n");
printf(" WA [watch_num [address [value]]] - Clear or set a watch point\n");
printf(" WR memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to a raw (offset from beginning of full PRU memory block)\n");
printf(" WRD memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to PRU data memory for current PRU\n");
printf(" WRI memory_location_wa value1 [value2 [value3 ...]] - Write a 32-bit value to PRU instruction memory for current PRU\n");
printf("\n");
}
Binary file not shown.
+579
View File
@@ -0,0 +1,579 @@
/*
*
* PRU Debug Program
* (c) Copyright 2011, 2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include "prudbg.h"
#include "uio.h"
// global variable definitions
unsigned int *pru;
unsigned int pru_inst_base[MAX_NUM_OF_PRUS];
unsigned int pru_ctrl_base[MAX_NUM_OF_PRUS];
unsigned int pru_data_base[MAX_NUM_OF_PRUS];
unsigned int pru_num = 0;
unsigned int last_offset, last_addr, last_len, last_cmd;
struct breakpoints bp[MAX_NUM_OF_PRUS][MAX_BREAKPOINTS];
struct watchvariable wa[MAX_NUM_OF_PRUS][MAX_WATCH];
// processor database
typedef struct offsets_tag {
unsigned int pruss_inst;
unsigned int pruss_data;
unsigned int pruss_ctrl;
} offsets_t;
struct pdb_tag {
char processor[MAX_PROC_NAME];
char short_name[MAX_PROC_NAME];
unsigned int pruss_address;
unsigned int pruss_len;
unsigned int num_of_pruss;
const offsets_t offsets[MAX_NUM_OF_PRUS];
} pdb[] = {
// The following is a "database" of available processors.
// To add another processor please copy one of the existing structures to
// the end before the END MARKER structure. "processor" is the long name
// for the processor (used for displaying info), "short_name" is used to
// select a processor at the command prompt (should be short and no spaces),
// "pruss_address" is the byte address of the beginning of the PRUSS memory
// space on the ARM, "pruss_len" is the memory allocated starting at the
// pruss_address address, "num_of_pruss" is the number of PRUs in the ARM
// processor (currently 2 is the only valid value), and "offsets" is an
// array of 32-bit word address/index values used to locate the instruction,
// data, and control memory locations for a specific PRU. This offsets
// array much contain num_of_pruss entries. If you add a processor to
// this structure then you should also add a DEFINE to the beginning of
// the prudbg.h file to represent the processor index in the structure
// array. This is only used for the DEFAULT_PROCESSOR_INDEX in the
// prudbg.h file (this sets the processor used if none is selected
// on the command line).
{
.processor = "AM1707",
.short_name = "AM1707",
.pruss_address = 0x01C30000,
.pruss_len = 0x20000,
.num_of_pruss = 2,
.offsets = {
{
.pruss_inst = 0x2000,
.pruss_data = 0x0000,
.pruss_ctrl = 0x1C00
},
{
.pruss_inst = 0x3000,
.pruss_data = 0x0800,
.pruss_ctrl = 0x1E00
}
}
},
{
.processor = "AM335x",
.short_name = "AM335X",
.pruss_address = 0x4A300000,
.pruss_len = 0x40000,
.num_of_pruss = 2,
.offsets = {
{
.pruss_inst = 0xD000,
.pruss_data = 0x0000,
.pruss_ctrl = 0x8800
},
{
.pruss_inst = 0xE000,
.pruss_data = 0x0800,
.pruss_ctrl = 0x9000
}
}
},
{ // end marker
.processor = "NONE",
.short_name = "NONE",
.num_of_pruss = 0
}
};
int strcmpci(char *str1, char *str2, int m) {
unsigned int i;
char c1, c2;
int r;
r = 1;
for (i=0; str1[i] != 0 && i<m; i++) {
c1 = str1[i];
c2 = str2[i];
if (c1>96 && c1<123) c1 = c1 - 32;
if (c2>96 && c2<123) c2 = c2 - 32;
if (c1 != c2) r = 0;
}
if ((i==m) || (str2[i] != 0)) r = 0;
return r;
}
// main entry point for program
int main(int argc, char *argv[])
{
int fd;
char prompt_str[20];
char cmd[MAX_CMD_LEN], cmdargs[MAX_CMDARGS_LEN];
unsigned int argptrs[MAX_ARGS], numargs;
struct termios oldT, newT;
unsigned int i;
unsigned int addr, len, bpnum, offset, wanum, value;
int opt;
unsigned long opt_pruss_addr;
int pru_access_mode, pi, pitemp;
char uio_dev_file[50];
// say hello
printf ("PRU Debugger v0.25\n");
printf ("(C) Copyright 2011, 2013 by Arctica Technologies. All rights reserved.\n");
printf ("Written by Steven Anderson\n");
printf ("\n");
// get command line options
opt_pruss_addr = 0;
pru_access_mode = ACCESS_GUESS;
pi = DEFAULT_PROCESSOR_INDEX;
while ((opt = getopt(argc, argv, "?a:p:um")) != -1) {
switch (opt) {
case 'a':
opt_pruss_addr = strtol(optarg, NULL, 0);
break;
case 'u':
pru_access_mode = ACCESS_UIO;
break;
case 'm':
pru_access_mode = ACCESS_MEM;
break;
case 'p':
pitemp = -1;
for(i=0; pdb[i].num_of_pruss != 0; i++) if (strcmpci(optarg, pdb[i].short_name, MAX_PROC_NAME)) pitemp = i;
if (pitemp == -1) {
printf("WARNING: unrecognized processor - will use the compiled-in default processor.\n\n");
} else {
pi = pitemp;
}
break;
case '?':
default: /* '?' */
printf("Usage: prudebug [-a pruss-address] [-u] [-m] [-p processor]\n");
printf(" -a - pruss-address is the memory address of the PRU in ARM memory space\n");
printf(" -u - force the use of UIO to map PRU memory space\n");
printf(" -m - force the use of /dev/mem to map PRU memory space\n");
printf(" if neither the -u or -m options are used then it will try the UIO first\n");
printf(" -p - select processor to use (sets the PRU memory locations)\n");
for(i=0; pdb[i].num_of_pruss != 0; i++) {
printf(" %s - %s\n", pdb[i].short_name, pdb[i].processor);
}
return(-1);
}
}
// setup PRU memory offsets
for (i=0; i<pdb[pi].num_of_pruss ;i++) {
pru_inst_base[i] = pdb[pi].offsets[i].pruss_inst;
pru_data_base[i] = pdb[pi].offsets[i].pruss_data;
pru_ctrl_base[i] = pdb[pi].offsets[i].pruss_ctrl;
}
// if user hasn't requested a different PRU base address on the CLI, then use the PRU DB address
if (opt_pruss_addr == 0) opt_pruss_addr = pdb[pi].pruss_address;
// determine how to obtain the PRU base memory pointer (/dev/mem or a UIO PRUSS driver file - /dev/uio*)
if (pru_access_mode == ACCESS_GUESS || pru_access_mode == ACCESS_UIO) {
// get the UIO info (a UIO device file for the PRUSS)
uio_getprussfile(uio_dev_file);
if (uio_dev_file[0] != 0) {
// there is a valid UIO/PRUSS file so open it and use the pointer
fd = open (uio_dev_file, O_RDWR | O_SYNC);
if (fd == -1) {
printf ("ERROR: could not open /dev/mem.\n\n");
return 1;
}
pru = mmap (0, pdb[pi].pruss_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (pru == MAP_FAILED) {
printf ("ERROR: could not map memory.\n\n");
return 1;
}
close(fd);
printf ("Using UIO PRUSS device.\n");
} else if (pru_access_mode == ACCESS_UIO) {
// user wanted only UIO device and none found - generate an error and exit
printf ("ERROR: UIO PRUSS device requested and none found.\n\n");
return (1);
} else {
// no valid UIO device file and user wants a guess so open /dev/mem
fd = open ("/dev/mem", O_RDWR | O_SYNC);
if (fd == -1) {
printf ("ERROR: could not open /dev/mem.\n\n");
return 1;
}
pru = mmap (0, pdb[pi].pruss_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, opt_pruss_addr);
if (pru == MAP_FAILED) {
printf ("ERROR: could not map memory.\n\n");
return 1;
}
close(fd);
printf ("Using /dev/mem device.\n");
}
} else {
// user requested the use of /dev/mem
fd = open ("/dev/mem", O_RDWR | O_SYNC);
if (fd == -1) {
printf ("ERROR: could not open /dev/mem.\n\n");
return 1;
}
pru = mmap (0, pdb[pi].pruss_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, opt_pruss_addr);
if (pru == MAP_FAILED) {
printf ("ERROR: could not map memory.\n\n");
return 1;
}
close(fd);
printf ("Using /dev/mem device.\n");
}
// get memory pointer for PRU from /dev/mem
// clear breakpoints
for (i=0; i<MAX_BREAKPOINTS; i++) {
bp[pru_num][i].state = BP_UNUSED;
}
// clear watch variables
for (i=0; i<MAX_WATCH; i++) {
wa[pru_num][i].state = WA_UNUSED;
}
// print some useful info
printf("Processor type %s\n", pdb[pi].processor);
printf("PRUSS memory address 0x%08x\n", opt_pruss_addr);
printf("PRUSS memory length 0x%08x\n\n", pdb[pi].pruss_len);
printf(" offsets below are in 32-bit word addresses (not ARM byte addresses)\n");
printf(" PRU Instruction Data Ctrl\n");
for (i=0; i<pdb[pi].num_of_pruss; i++) {
printf(" %-15d0x%08x 0x%08x 0x%08x\n", i, pdb[pi].offsets[i].pruss_inst, pdb[pi].offsets[i].pruss_data, pdb[pi].offsets[i].pruss_ctrl);
}
printf("\n");
// setup the terminal for more flexible IO
ioctl(0,TCGETS,&oldT);
newT=oldT;
newT.c_lflag &= ~ECHO;
newT.c_lflag &= ~ICANON;
ioctl(0,TCSETS,&newT);
// Command prompt handler
do {
// get command from user
sprintf(prompt_str, "PRU%u> ", pru_num);
cmd_input(prompt_str, cmd, cmdargs, argptrs, &numargs);
// do something with command info
if (!strcmp(cmd, "?") || !strcmp(cmd, "HELP")) { // HELP - help command
last_cmd = LAST_CMD_NONE;
printhelp();
}
else if (!strcmp(cmd, "HB")) { // brief HELP
last_cmd = LAST_CMD_NONE;
printhelpbrief();
}
else if (!strcmp(cmd, "BR")) { // BR - Breakpoint command
last_cmd = LAST_CMD_NONE;
if (numargs == 0) {
cmd_print_breakpoints();
} else if (numargs == 1) {
bpnum = strtol(&cmdargs[argptrs[0]], NULL, 0);
if (bpnum < MAX_BREAKPOINTS) {
cmd_clear_breakpoint (bpnum);
} else {
printf("ERROR: breakpoint number must be equal to or between 0 and %u\n", MAX_BREAKPOINTS-1);
}
} else if (numargs == 2) {
bpnum = strtol(&cmdargs[argptrs[0]], NULL, 0);
addr = strtol(&cmdargs[argptrs[1]], NULL, 0);
if (bpnum < MAX_BREAKPOINTS) {
cmd_set_breakpoint (bpnum, addr);
} else {
printf("ERROR: breakpoint number must be equal to or between 0 and %u\n", MAX_BREAKPOINTS-1);
}
} else {
printf("ERROR: invalid breakpoint command\n");
}
}
else if ((!strcmp(cmd, "D")) || (!strcmp(cmd, "DD")) || (!strcmp(cmd, "DI"))) { // D - Dump command
if (numargs > 2) {
printf("ERROR: too many arguments\n");
} else {
if (numargs == 2) {
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
len = strtol(&cmdargs[argptrs[1]], NULL, 0);
} else if (numargs == 0) {
addr = 0;
len = 16;
} else {
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
len = 16;
}
if ((addr < 0) || (addr > MAX_PRU_MEM - 1) || (len < 0) || (addr+len > MAX_PRU_MEM)) {
printf("ERROR: arguments out of range.\n");
} else if (numargs > 2) {
printf("ERROR: Incorrect format. Please use help command to get command details.\n");
} else {
if (!strcmp(cmd, "DD")) {
offset = pru_data_base[pru_num];
last_cmd = LAST_CMD_DD;
} else if (!strcmp(cmd, "DI")) {
offset = pru_inst_base[pru_num];
last_cmd = LAST_CMD_DI;
} else {
offset = 0;
last_cmd = LAST_CMD_D;
}
last_offset = offset;
last_addr = addr + len;
last_len = len;
printf ("Absolute addr = 0x%04x, offset = 0x%04x, Len = %u\n", addr + offset, addr, len);
cmd_d(offset, addr, len);
}
}
}
else if (!strcmp(cmd, "DIS")) { // DIS - disassemble command
if (numargs > 2) {
printf("ERROR: too many arguments\n");
} else {
if (numargs == 2) {
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
len = strtol(&cmdargs[argptrs[1]], NULL, 0);
} else if (numargs == 0) {
addr = 0;
len = 16;
} else {
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
len = 16;
}
if ((addr < 0) || (addr > MAX_PRU_MEM - 1) || (len < 0) || (addr+len > MAX_PRU_MEM)) {
printf("ERROR: arguments out of range.\n");
} else if (numargs > 2) {
printf("ERROR: Incorrect format. Please use help command to get command details.\n");
} else {
offset = pru_inst_base[pru_num];
last_cmd = LAST_CMD_DIS;
last_offset = offset;
last_addr = addr + len;
last_len = len;
printf ("Absolute addr = 0x%04x, offset = 0x%04x, Len = %u\n", addr + offset, addr, len);
cmd_dis(offset, addr, len);
}
}
}
else if (!strcmp(cmd, "G")) { // G - Start program
last_cmd = LAST_CMD_NONE;
if (numargs > 1) {
printf("ERROR: too many arguments\n");
} else if (numargs == 0) {
// start processor
cmd_run();
} else {
// set instruction pointer
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
// start processor
// cmd_run_at(addr);
printf("NOT IMPLEMENTED YET.\n");
}
}
else if (!strcmp(cmd, "GSS")) { // GSS - Start program using single stepping to provde BP/Watch
last_cmd = LAST_CMD_NONE;
if (numargs > 0) {
printf("ERROR: too many arguments\n");
} else {
// halt the processor
cmd_runss();
}
}
else if (!strcmp(cmd, "HALT")) { // HALT - Halt PRU
last_cmd = LAST_CMD_NONE;
if (numargs > 0) {
printf("ERROR: too many arguments\n");
} else {
// halt the processor
cmd_halt();
}
}
else if (!strcmp(cmd, "L")) { // L - Load PRU program
last_cmd = LAST_CMD_NONE;
if (numargs != 2) {
printf("ERROR: incorrect number of arguments\n");
} else {
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
cmd_loadprog(addr, &cmdargs[argptrs[1]]);
}
}
else if (!strcmp(cmd, "PRU")) { // PRU - Select the active PRU
last_cmd = LAST_CMD_NONE;
if (numargs != 1) {
printf("ERROR: incorrect number of arguments\n");
} else {
pru_num = strtol(&cmdargs[argptrs[0]], NULL, 0);
printf("Active PRU is PRU%u.\n\n", pru_num);
}
}
else if (!strcmp(cmd, "R")) { // R - Print PRU registers
last_cmd = LAST_CMD_NONE;
if (numargs != 0) {
printf("ERROR: incorrect number of arguments\n");
} else {
cmd_printregs();
}
}
else if (!strcmp(cmd, "RESET")) { // RESET - Reset PRU
last_cmd = LAST_CMD_NONE;
if (numargs > 0) {
printf("ERROR: too many arguments\n");
} else {
// reset the processor
cmd_soft_reset();
printf("\n");
}
}
else if (!strcmp(cmd, "SS")) { // SS - Single step
last_cmd = LAST_CMD_SS;
if (numargs > 0) {
printf("ERROR: too many arguments\n");
} else {
// reset the processor
cmd_single_step();
}
}
else if (!strcmp(cmd, "WA")) { // WA - Watch command
last_cmd = LAST_CMD_NONE;
if (numargs == 0) {
cmd_print_watch();
} else if (numargs == 1) {
wanum = strtol(&cmdargs[argptrs[0]], NULL, 0);
if (wanum < MAX_WATCH) {
cmd_clear_watch (wanum);
} else {
printf("ERROR: breakpoint number must be equal to or between 0 and %u\n", MAX_WATCH-1);
}
} else if (numargs == 2) {
wanum = strtol(&cmdargs[argptrs[0]], NULL, 0);
addr = strtol(&cmdargs[argptrs[1]], NULL, 0);
if (wanum < MAX_WATCH) {
cmd_set_watch_any (wanum, addr);
} else {
printf("ERROR: breakpoint number must be equal to or between 0 and %u\n", MAX_WATCH-1);
}
} else if (numargs == 3) {
wanum = strtol(&cmdargs[argptrs[0]], NULL, 0);
addr = strtol(&cmdargs[argptrs[1]], NULL, 0);
value = strtol(&cmdargs[argptrs[2]], NULL, 0);
if (wanum < MAX_WATCH) {
cmd_set_watch (wanum, addr, value);
} else {
printf("ERROR: breakpoint number must be equal to or between 0 and %u\n", MAX_WATCH-1);
}
} else {
printf("ERROR: invalid breakpoint command\n");
}
}
else if ((!strcmp(cmd, "WR")) || (!strcmp(cmd, "WRD")) || (!strcmp(cmd, "WRI"))) { // WR - Write Raw
last_cmd = LAST_CMD_NONE;
addr = strtol(&cmdargs[argptrs[0]], NULL, 0);
if (numargs < 2) {
printf("ERROR: too few arguments\n");
} else {
if ((addr < 0) || (addr > MAX_PRU_MEM - 1)) {
printf("ERROR: arguments out of range.\n");
} else {
if (!strcmp(cmd, "WRD")) {
offset = pru_data_base[pru_num];
} else if (!strcmp(cmd, "WRI")) {
offset = pru_inst_base[pru_num];
} else {
offset = 0;
}
printf("Write to absolute address 0x%04x\n", offset+addr);
for (i=1; i<numargs; i++) pru[offset+addr+i-1] = (unsigned int) (strtoll(&cmdargs[argptrs[i]], NULL, 0) & 0xFFFFFFFF);
}
}
}
else if (!strcmp(cmd, "Q")) { // dummy so it's a valid command
}
else if (!strcmp(cmd, "")) { // repeat display command option
switch(last_cmd) {
case LAST_CMD_D:
case LAST_CMD_DD:
case LAST_CMD_DI:
printf ("Absolute addr = 0x%04x, offset = 0x%04x, Len = %u\n", last_addr + last_offset, last_addr, last_len);
cmd_d(last_offset, last_addr, last_len);
last_addr += last_len;
break;
case LAST_CMD_SS:
cmd_single_step();
break;
default:
break;
}
}
else {
printf("Invalid command.\n\n");
}
} while (strcmp(cmd, "Q"));
printf("\nGoodbye.\n\n");
// restore terminal IO settings
ioctl(0,TCSETS,&oldT);
return 0;
}
+105
View File
@@ -0,0 +1,105 @@
/*
*
* PRU Debug Program header file
* (c) Copyright 2011, 2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#ifndef PRUDBG_H
#define PRUDBG_H
// default processor to use if none is specified on the command line when prudebug is started
#define DEFAULT_PROCESSOR_INDEX AM335x
// list of processors to use in the define above (DEFAULT_PROCESSOR_INDEX)
// value for define must match the array index in the processor structure
// in the prudbg.c file.
#define AM1707 0
#define AM335x 1
// general settings
#define MAX_CMD_LEN 25
#define MAX_CMDARGS_LEN 200
#define MAX_COMMAND_LINE (MAX_CMD_LEN + MAX_CMDARGS_LEN + 1)
#define MAX_ARGS 10
#define MAX_PRU_MEM 0xFFFF
#define NUM_OF_PRU 2
#define MAX_NUM_OF_PRUS 16 // maximum number of PRUs to expect in any processor
#define MAX_BREAKPOINTS 5
#define MAX_WATCH 5
#define MAX_PROC_NAME 20
// register offsets
#define PRU_CTRL_REG 0x0000
#define PRU_STATUS_REG 0x0001
#define PRU_INTGPR_REG 0x0100
// PRU control register bit flags
#define PRU_REG_PCRESET_MASK 0x0000FFFF
#define PRU_REG_RUNSTATE 0x00008000
#define PRU_REG_SINGLE_STEP 0x00000100
#define PRU_REG_COUNT_EN 0x00000008
#define PRU_REG_SLEEPING 0x00000004
#define PRU_REG_PROC_EN 0x00000002
#define PRU_REG_SOFT_RESET 0x00000001
// defines for PRU memory mapping method requeste by user
#define ACCESS_GUESS 0
#define ACCESS_UIO 1
#define ACCESS_MEM 2
// defines for command repeats
#define LAST_CMD_NONE 0
#define LAST_CMD_D 1
#define LAST_CMD_DD 2
#define LAST_CMD_DI 3
#define LAST_CMD_DIS 4
#define LAST_CMD_SS 5
// defines for structures below
#define BP_UNUSED 0
#define BP_ACTIVE 1
#define WA_UNUSED 0
#define WA_PRINT_ON_ANY 1
#define WA_HALT_ON_VALUE 2
#define TRUE 1
#define FALSE 0
// global structures
struct breakpoints {
unsigned char state;
unsigned int address;
};
struct watchvariable {
unsigned char state;
unsigned int address;
unsigned int value;
unsigned int old_value;
};
// global variables
extern unsigned int *pru;
extern unsigned int pru_inst_base[], pru_ctrl_base[], pru_data_base[];
extern unsigned int pru_num;
extern struct breakpoints bp[MAX_NUM_OF_PRUS][MAX_BREAKPOINTS];
extern struct watchvariable wa[MAX_NUM_OF_PRUS][MAX_WATCH];
// function prototypes
int cmd_input(char *prompt, char *cmd, char *cmdargs, unsigned int *argptrs, unsigned int *numargs);
void printhelp();
int cmd_d (int offset, int addr, int len);
int cmd_loadprog(unsigned int addr, char *fn);
void cmd_run();
void cmd_soft_reset();
void disassemble(char *str, unsigned int inst);
#endif // PRUDBG_H
Binary file not shown.
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
/*
*
* PRU Debug Program - UIO routines
* (c) Copyright 2011,2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include "uio.h"
// get UIO devices and put into structure
int uio_getprussfile(char *devname)
{
DIR *d;
struct dirent *dent;
char fn[UIO_MAX_UIO_FILEPATH];
FILE *fd;
char s_name[UIO_MAX_DEV_NAME];
// clear user buffer
devname[0] = 0;
// open directory /dev and scan for uio* files
d = opendir("/dev");
// read in first entry
dent = readdir(d);
// scan the entries
while (dent != NULL) {
// determine if this is a uio* file
if (dent->d_name[0] == 'u' && dent->d_name[1] == 'i' && dent->d_name[2] == 'o' && devname[0] == 0) {
// get uio device name and version
sprintf(fn, "/sys/class/uio/%s/name", dent->d_name);
fd = fopen (fn, "r");
fgets(s_name, UIO_MAX_DEV_NAME, fd);
s_name[strlen(s_name)-1] = 0;
if (!strncmp(s_name, "pruss", 5)) {
sprintf(devname, "/dev/%s", dent->d_name);
}
fclose(fd);
}
// read next directory entry
dent = readdir(d);
}
// close directory handle
closedir(d);
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
/*
*
* PRU Debug Program - UIO routine header file
* (c) Copyright 2011,2013 by Arctica Technologies
* Written by Steven Anderson
*
*/
#ifndef H_UIO
#define H_UIO
#define UIO_MAX_UIO_FILEPATH 100 // maximum length of the path and name for a uio file (ex. /sys/class/uio/uio7/name)
#define UIO_MAX_DEV_NAME 50
struct uiomap {
unsigned long address;
unsigned long length;
};
struct uiodev {
char *uio_file;
char *name;
char *version;
struct uiomap *maps;
};
// prototypes
int uio_getprussfile(char *devname);
#endif
Binary file not shown.