1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
--- gdb-7.7.orig/sim/lm32/dv-lm32uart.c 2014-05-08 12:07:13.000000000 +0000
+++ gdb-7.7/sim/lm32/dv-lm32uart.c 2014-05-08 12:07:46.000000000 +0000
@@ -1,6 +1,6 @@
/* Lattice Mico32 UART model.
Contributed by Jon Beniston <jon@beniston.com>
-
+
Copyright (C) 2009-2014 Free Software Foundation, Inc.
This file is part of GDB.
@@ -22,9 +22,6 @@
#include "hw-main.h"
#include "sim-assert.h"
-#include <stdio.h>
-#include <sys/time.h>
-
struct lm32uart
{
unsigned base; /* Base address of this UART. */
@@ -38,6 +35,8 @@
unsigned char lsr;
unsigned char msr;
unsigned char div;
+ int saved_count;
+ char saved_byte;
struct hw_event *event;
};
@@ -83,6 +82,7 @@
static void
do_uart_tx_event (struct hw *me, void *data)
{
+ SIM_DESC sd = hw_system (me);
struct lm32uart *uart = hw_data (me);
char c;
@@ -115,7 +115,8 @@
c &= 0x7f;
break;
}
- printf ("%c", c);
+ sim_io_write_stdout (sd, &c, 1);
+ sim_io_flush_stdout (sd);
}
static unsigned
@@ -200,12 +201,11 @@
void *dest,
int space, unsigned_word base, unsigned nr_bytes)
{
+ SIM_DESC sd = hw_system (me);
struct lm32uart *uart = hw_data (me);
int uart_reg;
int value;
unsigned char *dest_bytes = dest;
- fd_set fd;
- struct timeval tv;
HW_TRACE ((me, "read 0x%08lx length %d", (long) base, (int) nr_bytes));
@@ -214,7 +214,8 @@
switch (uart_reg)
{
case LM32_UART_RBR:
- value = getchar ();
+ value = uart->saved_byte;
+ --uart->saved_count;;
uart->lsr &= ~LM32_UART_LSR_RX_RDY;
break;
case LM32_UART_IER:
@@ -231,12 +232,10 @@
break;
case LM32_UART_LSR:
/* Check to see if any data waiting in stdin. */
- FD_ZERO (&fd);
- FD_SET (fileno (stdin), &fd);
- tv.tv_sec = 0;
- tv.tv_usec = 1;
- if (select (fileno (stdin) + 1, &fd, NULL, NULL, &tv))
- uart->lsr |= LM32_UART_LSR_RX_RDY;
+ if (uart->saved_count <= 0)
+ uart->saved_count = sim_io_poll_read (sd, 0/*STDIN*/,
+ &uart->saved_byte, 1);
+ uart->lsr |= uart->saved_count ? LM32_UART_LSR_RX_RDY : 0;
value = uart->lsr;
break;
case LM32_UART_MSR:
|