OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [libgloss/] [or32/] [write.c] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* write.c. Implementation of the _write syscall for newlib
2
 
3
   Copyright (C) 2004, Jacob Bower
4
   Copyright (C) 2010, Embecosm Limited <info@embecosm.com>
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Newlib.
9
 
10
   The original work by Jacob Bower is provided as-is without any kind of
11
   warranty. Use it at your own risk!
12
 
13
   All subsequent work is bound by version 3 of the GPL as follows.
14
 
15
   This program is free software; you can redistribute it and/or modify it
16
   under the terms of the GNU General Public License as published by the Free
17
   Software Foundation; either version 3 of the License, or (at your option)
18
   any later version.
19
 
20
   This program is distributed in the hope that it will be useful, but WITHOUT
21
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
23
   more details.
24
 
25
   You should have received a copy of the GNU General Public License along
26
   with this program.  If not, see <http:#www.gnu.org/licenses/>.             */
27
/* -------------------------------------------------------------------------- */
28
/* This program is commented throughout in a fashion suitable for processing
29
   with Doxygen.                                                              */
30
/* -------------------------------------------------------------------------- */
31
 
32
#include <errno.h>
33
#include <unistd.h>
34
 
35 527 julius
#include "or1k-support.h"
36 207 jeremybenn
 
37
 
38
#undef errno
39
extern int  errno;
40
 
41
 
42
/* -------------------------------------------------------------------------- */
43
/*!Write a single character to standard output for the simulator
44
 
45
   @param[in] c  The character to write                                       */
46
/* -------------------------------------------------------------------------- */
47
static void
48
outbyte (char  c)
49
{
50 507 julius
 
51
        if (BOARD_HAS_UART)
52
        {
53
                __uart_putc (c);
54
        }
55
        else
56
        {
57
                register char  t1 asm ("r3") = c;
58
 
59
                asm volatile ("\tl.nop\t%0" : : "K" (NOP_PUTC), "r" (t1));
60
        }
61
 
62 207 jeremybenn
}       /* outbyte () */
63
 
64
 
65
/* -------------------------------------------------------------------------- */
66
/*!Write a buffer to a file.
67
 
68
   Only output to stdout or stderr is supported, and both of those are
69
   directed to the single output stream.
70
 
71
   Remember that this function is *not* reentrant, so no static state should
72
   be held.
73
 
74
   @param[in] file  The fileno for output.
75
   @param[in] buf   The bytes to write.
76
   @param[in] nbytes  The number of bytes to write.
77
 
78
   @return  The number of bytes written on success, or -1 with an error code
79
            in the global variable errno on failure.                          */
80
/* -------------------------------------------------------------------------- */
81
int
82
_write (int   file,
83
        char *buf,
84
        int   nbytes)
85
{
86
  int i;
87
 
88
  /* We only handle stdout and stderr */
89
  if ((file != STDOUT_FILENO) && (file != STDERR_FILENO))
90
    {
91
      errno = EBADF;
92
      return -1;
93
    }
94
 
95
  /* Output character at at time */
96
  for (i = 0; i < nbytes; i++)
97
    {
98
      outbyte (buf[i]);
99
    }
100
 
101
  return nbytes;
102
 
103
}       /* _write () */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.