source: rtems-tools/tools/4.11/gdb/lm32/gdb-sim-lm32uart.diff @ 47d652c

4.104.115
Last change on this file since 47d652c was 47d652c, checked in by Chris Johns <chrisj@…>, on 05/08/14 at 12:39:07

gdb: Fix lm32 simulator's UART code. Builds on MinGW.

  • Property mode set to 100644
File size: 2.2 KB
  • sim/lm32/dv-lm32uart.c

    old new  
    11/*  Lattice Mico32 UART model.
    22    Contributed by Jon Beniston <jon@beniston.com>
    3    
     3
    44   Copyright (C) 2009-2014 Free Software Foundation, Inc.
    55
    66   This file is part of GDB.
     
    2222#include "hw-main.h"
    2323#include "sim-assert.h"
    2424
    25 #include <stdio.h>
    26 #include <sys/time.h>
    27 
    2825struct lm32uart
    2926{
    3027  unsigned base;                /* Base address of this UART.  */
     
    3835  unsigned char lsr;
    3936  unsigned char msr;
    4037  unsigned char div;
     38  int saved_count;
     39  char saved_byte;
    4140  struct hw_event *event;
    4241};
    4342
     
    8382static void
    8483do_uart_tx_event (struct hw *me, void *data)
    8584{
     85  SIM_DESC sd = hw_system (me);
    8686  struct lm32uart *uart = hw_data (me);
    8787  char c;
    8888
     
    115115      c &= 0x7f;
    116116      break;
    117117    }
    118   printf ("%c", c);
     118  sim_io_write_stdout (sd, &c, 1);
     119  sim_io_flush_stdout (sd);
    119120}
    120121
    121122static unsigned
     
    200201                         void *dest,
    201202                         int space, unsigned_word base, unsigned nr_bytes)
    202203{
     204  SIM_DESC sd = hw_system (me);
    203205  struct lm32uart *uart = hw_data (me);
    204206  int uart_reg;
    205207  int value;
    206208  unsigned char *dest_bytes = dest;
    207   fd_set fd;
    208   struct timeval tv;
    209209
    210210  HW_TRACE ((me, "read 0x%08lx length %d", (long) base, (int) nr_bytes));
    211211
     
    214214  switch (uart_reg)
    215215    {
    216216    case LM32_UART_RBR:
    217       value = getchar ();
     217      value = uart->saved_byte;
     218      --uart->saved_count;;
    218219      uart->lsr &= ~LM32_UART_LSR_RX_RDY;
    219220      break;
    220221    case LM32_UART_IER:
     
    231232      break;
    232233    case LM32_UART_LSR:
    233234      /* Check to see if any data waiting in stdin.  */
    234       FD_ZERO (&fd);
    235       FD_SET (fileno (stdin), &fd);
    236       tv.tv_sec = 0;
    237       tv.tv_usec = 1;
    238       if (select (fileno (stdin) + 1, &fd, NULL, NULL, &tv))
    239         uart->lsr |= LM32_UART_LSR_RX_RDY;
     235      if (uart->saved_count <= 0)
     236        uart->saved_count = sim_io_poll_read (sd, 0/*STDIN*/,
     237                                              &uart->saved_byte, 1);
     238      uart->lsr |= uart->saved_count ? LM32_UART_LSR_RX_RDY : 0;
    240239      value = uart->lsr;
    241240      break;
    242241    case LM32_UART_MSR:
Note: See TracBrowser for help on using the repository browser.