1 |
43 |
ultra_embe |
//-----------------------------------------------------------------
|
2 |
|
|
// AltOR32
|
3 |
|
|
// Alternative Lightweight OpenRisc
|
4 |
|
|
// V2.0
|
5 |
|
|
// Ultra-Embedded.com
|
6 |
|
|
// Copyright 2011 - 2014
|
7 |
|
|
//
|
8 |
|
|
// Email: admin@ultra-embedded.com
|
9 |
|
|
//
|
10 |
|
|
// License: LGPL
|
11 |
|
|
//-----------------------------------------------------------------
|
12 |
|
|
//
|
13 |
|
|
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
|
14 |
|
|
//
|
15 |
|
|
// This source file may be used and distributed without
|
16 |
|
|
// restriction provided that this copyright statement is not
|
17 |
|
|
// removed from the file and that any derivative work contains
|
18 |
|
|
// the original copyright notice and the associated disclaimer.
|
19 |
|
|
//
|
20 |
|
|
// This source file is free software; you can redistribute it
|
21 |
|
|
// and/or modify it under the terms of the GNU Lesser General
|
22 |
|
|
// Public License as published by the Free Software Foundation;
|
23 |
|
|
// either version 2.1 of the License, or (at your option) any
|
24 |
|
|
// later version.
|
25 |
|
|
//
|
26 |
|
|
// This source is distributed in the hope that it will be
|
27 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
28 |
|
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
29 |
|
|
// PURPOSE. See the GNU Lesser General Public License for more
|
30 |
|
|
// details.
|
31 |
|
|
//
|
32 |
|
|
// You should have received a copy of the GNU Lesser General
|
33 |
|
|
// Public License along with this source; if not, write to the
|
34 |
|
|
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
35 |
|
|
// Boston, MA 02111-1307 USA
|
36 |
|
|
//-----------------------------------------------------------------
|
37 |
|
|
#include "mem_map.h"
|
38 |
|
|
#include "gdb_hw.h"
|
39 |
|
|
|
40 |
|
|
//-----------------------------------------------------------------
|
41 |
|
|
// Defines:
|
42 |
|
|
//-----------------------------------------------------------------
|
43 |
|
|
#define UART_RX_AVAIL (1<<0)
|
44 |
|
|
#define UART_TX_AVAIL (1<<1)
|
45 |
|
|
#define UART_RX_FULL (1<<2)
|
46 |
|
|
#define UART_TX_BUSY (1<<3)
|
47 |
|
|
#define UART_RX_ERROR (1<<4)
|
48 |
|
|
|
49 |
|
|
// SR Register
|
50 |
|
|
#define SPR_SR (17)
|
51 |
|
|
#define SPR_SR_ICACHE_FLUSH (1 << 17)
|
52 |
|
|
#define SPR_SR_DCACHE_FLUSH (1 << 18)
|
53 |
|
|
|
54 |
|
|
#define MAX_RX_BUF 128
|
55 |
|
|
static char _rx_buf[MAX_RX_BUF];
|
56 |
|
|
static int _rx_head;
|
57 |
|
|
static int _rx_tail;
|
58 |
|
|
|
59 |
|
|
//-----------------------------------------------------------------
|
60 |
|
|
// mfspr: Read from SPR
|
61 |
|
|
//-----------------------------------------------------------------
|
62 |
|
|
static inline unsigned long mfspr(unsigned long spr)
|
63 |
|
|
{
|
64 |
|
|
unsigned long value;
|
65 |
|
|
asm volatile ("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
|
66 |
|
|
return value;
|
67 |
|
|
}
|
68 |
|
|
//-----------------------------------------------------------------
|
69 |
|
|
// mtspr: Write to SPR
|
70 |
|
|
//-----------------------------------------------------------------
|
71 |
|
|
static inline void mtspr(unsigned long spr, unsigned long value)
|
72 |
|
|
{
|
73 |
|
|
asm volatile ("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
|
74 |
|
|
}
|
75 |
|
|
//-----------------------------------------------------------------
|
76 |
|
|
// gdb_pollrx:
|
77 |
|
|
//-----------------------------------------------------------------
|
78 |
|
|
void gdb_pollrx (void)
|
79 |
|
|
{
|
80 |
|
|
if (UART_USR & UART_RX_AVAIL)
|
81 |
|
|
{
|
82 |
|
|
_rx_buf[_rx_tail] = UART_UDR;
|
83 |
|
|
|
84 |
|
|
if (++_rx_tail == MAX_RX_BUF)
|
85 |
|
|
_rx_tail = 0;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
//-----------------------------------------------------------------
|
89 |
|
|
// gdb_putchar:
|
90 |
|
|
//-----------------------------------------------------------------
|
91 |
|
|
void gdb_putchar (char c)
|
92 |
|
|
{
|
93 |
|
|
UART_UDR = c;
|
94 |
|
|
while (UART_USR & UART_TX_BUSY)
|
95 |
|
|
gdb_pollrx();
|
96 |
|
|
}
|
97 |
|
|
//-------------------------------------------------------------
|
98 |
|
|
// gdb_putstr:
|
99 |
|
|
//-------------------------------------------------------------
|
100 |
|
|
void gdb_putstr(const char *str)
|
101 |
|
|
{
|
102 |
|
|
while (*str)
|
103 |
|
|
gdb_putchar(*str++);
|
104 |
|
|
}
|
105 |
|
|
//-----------------------------------------------------------------
|
106 |
|
|
// gdb_getchar:
|
107 |
|
|
//-----------------------------------------------------------------
|
108 |
|
|
int gdb_getchar (void)
|
109 |
|
|
{
|
110 |
|
|
int ch = -1;
|
111 |
|
|
|
112 |
|
|
do
|
113 |
|
|
{
|
114 |
|
|
gdb_pollrx();
|
115 |
|
|
|
116 |
|
|
if (_rx_head != _rx_tail)
|
117 |
|
|
{
|
118 |
|
|
ch = _rx_buf[_rx_head];
|
119 |
|
|
|
120 |
|
|
if (++_rx_head == MAX_RX_BUF)
|
121 |
|
|
_rx_head = 0;
|
122 |
|
|
|
123 |
|
|
break;
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
while (1);
|
127 |
|
|
|
128 |
|
|
return ch;
|
129 |
|
|
}
|
130 |
|
|
//-----------------------------------------------------------------
|
131 |
|
|
// gdb_flush_cache:
|
132 |
|
|
//-----------------------------------------------------------------
|
133 |
|
|
void gdb_flush_cache(void)
|
134 |
|
|
{
|
135 |
|
|
mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_ICACHE_FLUSH | SPR_SR_DCACHE_FLUSH);
|
136 |
|
|
}
|