Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 73e0c01cbf73
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 739e41b5fe55
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 17, 2016

  1. Copy the full SHA
    069a95e View commit details
  2. Copy the full SHA
    739e41b View commit details
Showing with 153 additions and 7 deletions.
  1. +2 −0 misoc/software/libbase/crt0-or1k.S
  2. +150 −6 misoc/software/libbase/exception.c
  3. +1 −1 misoc/software/libcompiler-rt/Makefile
2 changes: 2 additions & 0 deletions misoc/software/libbase/crt0-or1k.S
Original file line number Diff line number Diff line change
@@ -202,6 +202,8 @@ _exception_handler:
l.mfspr r5, r0, SPR_EPCR_BASE
/* Extract exception effective address */
l.mfspr r6, r0, SPR_EEAR_BASE
/* Extract exception SR */
l.mfspr r7, r0, SPR_ESR_BASE
/* Call exception handler with the link address as argument */
l.jal exception_handler
l.nop
156 changes: 150 additions & 6 deletions misoc/software/libbase/exception.c
Original file line number Diff line number Diff line change
@@ -6,11 +6,13 @@ void isr(void);

#ifdef __or1k__

#include <hw/flags.h>

#define EXTERNAL_IRQ 0x8

static void emerg_printf(const char *fmt, ...)
{
char buf[128];
char buf[512];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
@@ -23,17 +25,158 @@ static void emerg_printf(const char *fmt, ...)
}
}

static char emerg_getc()
{
while(uart_rxempty_read());
char c = uart_rxtx_read();
uart_ev_pending_write(UART_EV_RX);
return c;
}

static const char hex[] = "0123456789abcdef";

static void gdb_send(const char *txbuf)
{
unsigned char cksum = 0;
const char *p = txbuf;
while(*p) cksum += *p++;
emerg_printf("+$%s#%c%c", txbuf, hex[cksum >> 4], hex[cksum & 0xf]);
}

static void gdb_recv(char *rxbuf, size_t size)
{
size_t pos = (size_t)-1;
for(;;) {
char c = emerg_getc();
if(c == '$')
pos = 0;
else if(c == '#')
return;
else if(pos < size - 1) {
rxbuf[pos++] = c;
rxbuf[pos] = 0;
}
}
}

static void gdb_stub(unsigned long pc, unsigned long sr,
unsigned long r1, unsigned long *regs)
{
gdb_send("S05");

char buf[385];
for(;;) {
gdb_recv(buf, sizeof(buf));

switch(buf[0]) {
case '?': {
snprintf(buf, sizeof(buf), "S05");
break;
}

case 'g': {
snprintf(buf, sizeof(buf),
"%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
"%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
"%08x%08x%08x",
0, r1, regs[2], regs[3], regs[4], regs[5], regs[6], regs[7],
regs[8], regs[9], regs[10], regs[11], regs[12], regs[13], regs[14], regs[15],
regs[16], regs[17], regs[18], regs[19], regs[20], regs[21], regs[22], regs[23],
regs[24], regs[25], regs[26], regs[27], regs[28], regs[29], regs[30], regs[31],
pc-4, pc, sr);
break;
}

case 'm': {
unsigned long addr, len;
char *endptr = &buf[0];
addr = strtoul(endptr + 1, &endptr, 16);
len = strtoul(endptr + 1, &endptr, 16);
unsigned char *ptr = (unsigned char *)addr;
if(len > sizeof(buf) / 2) len = sizeof(buf) / 2;
for(size_t i = 0; i < len; i++) {
buf[i*2 ] = hex[ptr[i] >> 4];
buf[i*2+1] = hex[ptr[i] & 15];
buf[i*2+2] = 0;
}
break;
}

case 'p': {
unsigned long reg, value;
char *endptr = &buf[0];
reg = strtoul(endptr + 1, &endptr, 16);
if(reg == 0)
value = 0;
else if(reg == 1)
value = r1;
else if(reg >= 2 && reg <= 31)
value = regs[reg];
else if(reg == 33)
value = pc;
else if(reg == 34)
value = sr;
else {
snprintf(buf, sizeof(buf), "E01");
break;
}
snprintf(buf, sizeof(buf), "%08x", value);
break;
}

case 'P': {
unsigned long reg, value;
char *endptr = &buf[0];
reg = strtoul(endptr + 1, &endptr, 16);
value = strtoul(endptr + 1, &endptr, 16);
if(reg == 0)
/* ignore */;
else if(reg == 1)
r1 = value;
else if(reg >= 2 && reg <= 31)
regs[reg] = value;
else if(reg == 33)
pc = value;
else if(reg == 34)
sr = value;
else {
snprintf(buf, sizeof(buf), "E01");
break;
}
snprintf(buf, sizeof(buf), "OK");
break;
}

case 'c': {
if(buf[1] != '\0') {
snprintf(buf, sizeof(buf), "E01");
break;
}
return;
}

default:
snprintf(buf, sizeof(buf), "");
break;
}

do {
gdb_send(buf);
} while(emerg_getc() == '-');
}
}

void exception_handler(unsigned long vect, unsigned long *regs,
unsigned long pc, unsigned long ea);
unsigned long pc, unsigned long ea, unsigned long sr);
void exception_handler(unsigned long vect, unsigned long *regs,
unsigned long pc, unsigned long ea)
unsigned long pc, unsigned long ea, unsigned long sr)
{
if(vect == EXTERNAL_IRQ) {
isr();
} else {
emerg_printf("\n *** Unhandled exception %d *** \n", vect);
emerg_printf(" pc %08x ea %08x\n",
pc, ea);
emerg_printf(" pc %08x sr %08x ea %08x\n",
pc, sr, ea);
unsigned long r1 = (unsigned long)regs + 4*32;
regs -= 2;
emerg_printf(" r0 %08x r1 %08x r2 %08x r3 %08x\n",
@@ -61,7 +204,8 @@ void exception_handler(unsigned long vect, unsigned long *regs,
}
emerg_printf("\n");
}
for(;;);
emerg_printf(" waiting for gdb... ");
gdb_stub(pc, sr, r1, regs);
}
}
#endif
2 changes: 1 addition & 1 deletion misoc/software/libcompiler-rt/Makefile
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ CFLAGS+=-D_YUGA_LITTLE_ENDIAN=0 -D_YUGA_BIG_ENDIAN=1 -Wno-missing-prototypes
OBJECTS=divsi3.o modsi3.o comparesf2.o comparedf2.o negsf2.o negdf2.o addsf3.o subsf3.o mulsf3.o divsf3.o lshrdi3.o muldi3.o divdi3.o ashldi3.o ashrdi3.o udivmoddi4.o \
floatsisf.o floatunsisf.o fixsfsi.o fixdfdi.o fixunssfsi.o fixunsdfdi.o adddf3.o subdf3.o muldf3.o divdf3.o floatsidf.o floatunsidf.o floatdidf.o fixdfsi.o fixunsdfsi.o \
clzsi2.o ctzsi2.o udivdi3.o umoddi3.o moddi3.o ucmpdi2.o \
powidf2.o
powidf2.o powisf2.o mulodi4.o floatundisf.o floatundidf.o extendsfdf2.o truncdfsf2.o

all: libcompiler-rt.a