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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [hppa1.1/] [simhppa/] [tty/] [tty.c] - Blame information for rev 562

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Tty IO Driver
3
 *  This is a "libio" driver based on libc/support/generic/libio interface
4
 *  which is on top of the RTEMS IO manager.
5
 *
6
 *  These provide UNIX-like read and write calls for the C library.
7
 *
8
 *  COPYRIGHT (c) 1994 by Division Incorporated
9
 *
10
 *  The license and distribution terms for this file may be
11
 *  found in the file LICENSE in this distribution or at
12
 *  http://www.OARcorp.com/rtems/license.html.
13
 *
14
 *  $Id: tty.c,v 1.2 2001-09-27 11:59:45 chris Exp $
15
 */
16
 
17
#include <bsp.h>
18
#include <rtems/libio.h>
19
 
20
#include <errno.h>
21
 
22
#define PRINT_BUFFER_SIZE    (16 * 1024)
23
 
24
/*
25
 * NOTE: this structure is dumplicated in print_dump.c utility
26
 */
27
 
28
struct {
29
    int  index;
30
    int  size;
31
    char buffer[PRINT_BUFFER_SIZE];
32
} print_buffer;
33
 
34
/* always use printf buffer if non-zero */
35
int  use_print_buffer;
36
 
37
static int host_read_syscall(int fd, char *buffer, int count);
38
static int host_write_syscall(int fd, char *buffer, int count);
39
 
40
rtems_device_driver
41
tty_initialize(
42
    rtems_device_major_number major,
43
    rtems_device_minor_number minor,
44
    void                    * arg
45
  )
46
{
47
    rtems_status_code status;
48
 
49
    status = rtems_io_register_name("/dev/tty00",
50
                                    major,
51
                                    (rtems_device_minor_number) 0);
52
    if (status != RTEMS_SUCCESSFUL)
53
        rtems_fatal_error_occurred(status);
54
 
55
    return RTEMS_SUCCESSFUL;
56
}
57
 
58
rtems_device_driver
59
tty_open(
60
    rtems_device_major_number major,
61
    rtems_device_minor_number minor,
62
    void                    * arg
63
  )
64
{
65
    return RTEMS_SUCCESSFUL;
66
}
67
 
68
rtems_device_driver
69
tty_close(
70
    rtems_device_major_number major,
71
    rtems_device_minor_number minor,
72
    void                    * arg
73
  )
74
{
75
    return RTEMS_SUCCESSFUL;
76
}
77
 
78
rtems_device_driver
79
tty_control(
80
    rtems_device_major_number major,
81
    rtems_device_minor_number minor,
82
    void                    * arg
83
  )
84
{
85
    return RTEMS_SUCCESSFUL;
86
}
87
 
88
 
89
rtems_device_driver
90
tty_read(
91
    rtems_device_major_number major,
92
    rtems_device_minor_number minor,
93
    void                    * arg
94
  )
95
{
96
    rtems_libio_rw_args_t *rw_args;
97
    int count = 0;
98
 
99
    rw_args = (rtems_libio_rw_args_t *) arg;
100
 
101
    /*
102
     * If we are printing to a buffer, then just return newline on all
103
     * read's.  If we return 0 bytes read, then the pause() calls in
104
     * the RTEMS tests get hosed (pause() does a gets())
105
     */
106
 
107
    if ( use_print_buffer )
108
    {
109
        *rw_args->buffer = '\n';
110
        count = 1;
111
    }
112
    else
113
    {
114
        count = host_read_syscall(0, rw_args->buffer, rw_args->count);
115
    }
116
 
117
    if (count >= 0)
118
    {
119
        rw_args->bytes_moved = count;
120
        return RTEMS_SUCCESSFUL;
121
    }
122
    return RTEMS_UNSATISFIED;
123
}
124
 
125
rtems_device_driver
126
tty_write(
127
    rtems_device_major_number major,
128
    rtems_device_minor_number minor,
129
    void                    * arg
130
  )
131
{
132
    unsigned32 level;
133
    rtems_libio_rw_args_t *rw_args;
134
    int count = 0;
135
    int fd = 1;                 /* XXX fixme; needs to be saved in iop */
136
 
137
    rw_args = (rtems_libio_rw_args_t *) arg;
138
 
139
    /*
140
     * HACK alert
141
     *
142
     * Some of the simulators have real problems when multi cpu and
143
     * using the system calls.  Until this is fixed, if we are multi
144
     * cpu then we write to a printf buffer
145
     */
146
 
147
    if ( use_print_buffer )
148
    {
149
        /* save size in memory for dumper */
150
        if (print_buffer.size == 0)
151
            print_buffer.size = PRINT_BUFFER_SIZE;
152
 
153
        while (rw_args->count-- > 0)
154
        {
155
            rtems_interrupt_disable(level);
156
            print_buffer.buffer[print_buffer.index] = *rw_args->buffer++;
157
            print_buffer.index++;
158
            print_buffer.index &= (PRINT_BUFFER_SIZE - 1);
159
            print_buffer.buffer[print_buffer.index] = 0;
160
            rtems_interrupt_enable(level);
161
            count++;
162
        }
163
    }
164
    else
165
    {
166
#if 1
167
        /*
168
         * if on a multi cpu system and writing to stdout, redirect to stderr
169
         * so we can keep them separate
170
         */
171
 
172
        if ((cpu_number == 1) && (fd == 1))
173
            fd = 2;
174
#endif
175
        count = host_write_syscall(fd, rw_args->buffer, rw_args->count);
176
    }
177
 
178
    if (count >= 0)
179
    {
180
        rw_args->bytes_moved = count;
181
        return RTEMS_SUCCESSFUL;
182
    }
183
    return RTEMS_UNSATISFIED;
184
}
185
 
186
 
187
/*
188
 * Host system call hack.
189
 * This little trick gets all the args in the right registers
190
 * for the system call and permits simpler inline asm.
191
 * Since this whole thing (syscalls under simulator) is a hack,
192
 * this little bit more is not going to hurt anything.
193
 */
194
 
195
 
196
static int
197
host_read_syscall(
198
    int fd,
199
    char *buffer,
200
    int count
201
  )
202
{
203
    unsigned32 level;
204
    int rc;
205
 
206
    rtems_interrupt_disable(level);
207
 
208
    /* This is an HPUX system call, with return value copied out */
209
    asm volatile (" stw     %%r19,-28(0,%%r30)\n\
210
                    ldil    L%%0xc0000000,%%r1\n\
211
                    ble     4(7,%%r1)\n\
212
                    ldi     3,%%r22\n\
213
                    ldw     -28(0,%%r30),%%r19\n\
214
                    copy    %%r28, %0"
215
                  : "=r" (rc)
216
                  : );
217
 
218
    rtems_interrupt_enable(level);
219
    return rc;
220
}
221
 
222
static int
223
host_write_syscall(
224
    int fd,
225
    char *buffer,
226
    int count
227
  )
228
{
229
    unsigned32 level;
230
    int rc;
231
 
232
    rtems_interrupt_disable(level);
233
 
234
    /* This is an HPUX system call, with return value copied out */
235
    asm volatile (" stw     %%r19,-28(0,%%r30)\n\
236
                    ldil    L%%0xc0000000,%%r1\n\
237
                    ble     4(7,%%r1)\n\
238
                    ldi     4,%%r22\n\
239
                    ldw     -28(0,%%r30),%%r19\n\
240
                    copy    %%r28, %0"
241
                  : "=r" (rc)
242
                  : );
243
 
244
    rtems_interrupt_enable(level);
245
    return rc;
246
}
247
 

powered by: WebSVN 2.1.0

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