Changeset 79460ae in mainline for libc/generic/io/stream.c


Ignore:
Timestamp:
2006-05-30T10:40:17Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44c6d88d
Parents:
f25b73d6
Message:

Basic support for console driver.
Does not provide separate screens yet.
TODO fix many unhandled states.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/io/stream.c

    rf25b73d6 r79460ae  
    88#include <ipc/fb.h>
    99#include <ipc/services.h>
     10#include <console.h>
    1011
    1112#define FDS 32
     
    1718} stream_t;
    1819
    19 
    20 typedef struct vfb_descriptor_t {
    21         int phone;
    22         int vfb;
    23 } vfb_descriptor_t;
    24 
     20int console_phone = -1;
    2521
    2622stream_t streams[FDS] = {{0, 0, 0}};
     
    3329}*/
    3430
    35 static void vfb_send_char(vfb_descriptor_t *d, char c)
     31static ssize_t write_stderr(void *param, const void *buf, size_t count)
     32{
     33        return count;
     34        //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
     35}
     36
     37static char read_stdin(void)
    3638{
    3739        ipcarg_t r0,r1;
    38         ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1);
     40        ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1);
     41       
     42        return r0;
     43        //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
    3944}
    40                                
    41 static ssize_t write_vfb(void *param, const void *buf, size_t count)
     45static ssize_t write_stdout(void *param, const void *buf, size_t count)
    4246{
    4347        int i;
     48        ipcarg_t r0,r1;
     49
    4450        for (i = 0; i < count; i++)
    45                 vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);
     51                ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1);
    4652       
    4753        return count;
     
    5056
    5157
    52 static ssize_t write_stderr(void *param, const void *buf, size_t count)
    53 {
    54         return count;
    55         //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
    56 }
    5758
    58 
    59 stream_t open_vfb(void)
     59static stream_t open_stdin(void)
    6060{
    6161        stream_t stream;
    62         vfb_descriptor_t *vfb;
    6362        int phoneid;
    6463        int res;
    65         ipcarg_t vfb_no;
    6664       
    67         while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
    68                 volatile int a;
    69                
    70                 for (a = 0; a < 1048576; a++);
     65        if (console_phone < 0) {
     66                while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
     67                        volatile int a;
     68                        for (a = 0; a < 1048576; a++);
     69                }
    7170        }
    7271       
    73         ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
    74         vfb = malloc(sizeof(vfb_descriptor_t));
    75        
    76         vfb->phone = phoneid;
    77         vfb->vfb = vfb_no;
    78        
    79         stream.w = write_vfb;
    80         stream.param = vfb;
     72        stream.r = read_stdin;
     73        stream.param = 0;
    8174        return stream;
    8275}
    8376
     77static stream_t open_stdout(void)
     78{
     79        stream_t stream;
     80        int res;
     81       
     82        if (console_phone < 0) {
     83                while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
     84                        volatile int a;
     85                        for (a = 0; a < 1048576; a++);
     86                }
     87        }
     88       
     89        stream.w = write_stdout;
     90        stream.param = 0;
     91        return stream;
     92}
    8493
    8594fd_t open(const char *fname, int flags)
     
    93102       
    94103        if (!strcmp(fname, "stdin")) {
    95                 streams[c].r = (preadfn_t)1;
     104                streams[c] = open_stdin();
    96105                return c;
    97106        }
     
    100109                //streams[c].w = write_stdout;
    101110                //return c;
    102                 streams[c] = open_vfb();
     111                streams[c] = open_stdout();
    103112                return c;
    104113        }
Note: See TracChangeset for help on using the changeset viewer.