- no lto git-svn-id: http://moon:8086/svn/mips@139 a8ebac50-d88d-4704-bea3-6648445a41b3
131 lines
2.6 KiB
C
131 lines
2.6 KiB
C
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include "board.h"
|
|
#include "../../irq.h"
|
|
#include "../../uart.h"
|
|
#include "../../console.h"
|
|
#include "../../regdef.h"
|
|
|
|
extern uart_if_t uart_if[];
|
|
#ifdef WITH_ROM_DEBUGGER
|
|
const fp_xcpt_t dbg_func = (fp_xcpt_t)0xbfc01fc0;
|
|
#else
|
|
#ifdef WITH_GDB_STUB
|
|
extern void handle_exception (unsigned long *registers);
|
|
#else
|
|
extern int dbg_handler(struct xcptcontext * xcp);
|
|
#endif
|
|
|
|
int dbg_stub(struct xcptcontext * xcp) __attribute__ ((section (".dbg_stub"))) __attribute__ ((used));
|
|
int dbg_stub(struct xcptcontext * xcp)
|
|
{
|
|
#ifdef WITH_GDB_STUB
|
|
handle_exception((unsigned long *)xcp);
|
|
return 0;
|
|
#else
|
|
return dbg_handler(xcp);
|
|
#endif
|
|
}
|
|
|
|
const fp_xcpt_t dbg_func = (fp_xcpt_t)dbg_stub;
|
|
#endif
|
|
|
|
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
|
|
|
const con_if_entry_t con_if_entry[] =
|
|
{
|
|
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
|
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
|
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
|
{3, "UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
|
{4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
|
|
};
|
|
|
|
const con_if_t con_if =
|
|
{
|
|
con_if_entry, ARRAYSIZE(con_if_entry)
|
|
};
|
|
|
|
void dbg_uart_isr(struct xcptcontext *xcp)
|
|
{
|
|
if(SYS_UART_BIT_RX_AVAIL & *uart_if[UART_DEBUGGER].pCTRL)
|
|
{
|
|
char c = *uart_if[UART_DEBUGGER].pDATA;
|
|
if (c == 3)
|
|
{
|
|
dbg_func(xcp);
|
|
}
|
|
}
|
|
}
|
|
|
|
void dbg_uart_setup()
|
|
{
|
|
const int UART_INT = SYS_INT_UART;
|
|
*uart_if[UART_DEBUGGER].pCTRL = SYS_UART_BIT_RX_INTEN;
|
|
interrupt_register(UART_INT, dbg_uart_isr);
|
|
interrupt_enable(UART_INT);
|
|
}
|
|
|
|
void dbg_init()
|
|
{
|
|
xcpt_register(EXC_ADEL, dbg_func);
|
|
xcpt_register(EXC_ADES, dbg_func);
|
|
xcpt_register(EXC_IBE, dbg_func);
|
|
xcpt_register(EXC_DBE, dbg_func);
|
|
xcpt_register(EXC_BP, dbg_func);
|
|
xcpt_register(EXC_RI, dbg_func);
|
|
xcpt_register(EXC_CPU, dbg_func);
|
|
xcpt_register(EXC_OV, dbg_func);
|
|
}
|
|
|
|
void board_init(void)
|
|
{
|
|
uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL;
|
|
|
|
// Disable timers
|
|
*pITIM_ctrl = 0;
|
|
|
|
// Setup syscall support
|
|
syscalls_init();
|
|
|
|
// Setup Uart ISR
|
|
dbg_uart_setup();
|
|
|
|
// Setup debugger
|
|
dbg_init();
|
|
|
|
// Setup interrupt support
|
|
interrupt_init();
|
|
interrupt_global_enable();
|
|
|
|
// Do some initializations here
|
|
}
|
|
|
|
void dbg_putchar(char c)
|
|
{
|
|
if (c == 0x0A)
|
|
{
|
|
UART_writechar(&uart_if[UART_DEBUGGER], 0x0D);
|
|
}
|
|
UART_writechar(&uart_if[UART_DEBUGGER], c);
|
|
}
|
|
|
|
char dbg_getchar()
|
|
{
|
|
int c;
|
|
|
|
// busy read
|
|
do
|
|
{
|
|
c = UART_readchar(&uart_if[UART_DEBUGGER]);
|
|
|
|
} while(c < 0);
|
|
|
|
return (char)c;
|
|
}
|