Subversion Repositories HelenOS-historic

Rev

Rev 1366 | Rev 1452 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1366 Rev 1451
Line 5... Line 5...
5
#include <libc.h>
5
#include <libc.h>
6
#include <ipc/ipc.h>
6
#include <ipc/ipc.h>
7
#include <ipc/ns.h>
7
#include <ipc/ns.h>
8
#include <ipc/fb.h>
8
#include <ipc/fb.h>
9
#include <ipc/services.h>
9
#include <ipc/services.h>
-
 
10
#include <console.h>
10
 
11
 
11
#define FDS 32
12
#define FDS 32
12
 
13
 
13
typedef struct stream_t {
14
typedef struct stream_t {
14
    pwritefn_t w;
15
    pwritefn_t w;
15
    preadfn_t r;
16
    preadfn_t r;
16
    void * param;
17
    void * param;
17
} stream_t;
18
} stream_t;
18
 
19
 
19
 
-
 
20
typedef struct vfb_descriptor_t {
-
 
21
    int phone;
20
int console_phone = -1;
22
    int vfb;
-
 
23
} vfb_descriptor_t;
-
 
24
 
-
 
25
 
21
 
26
stream_t streams[FDS] = {{0, 0, 0}};
22
stream_t streams[FDS] = {{0, 0, 0}};
27
 
23
 
28
/*
24
/*
29
ssize_t write_stdout(void *param, const void * buf, size_t count);
25
ssize_t write_stdout(void *param, const void * buf, size_t count);
30
ssize_t write_stdout(void *param, const void * buf, size_t count)
26
ssize_t write_stdout(void *param, const void * buf, size_t count)
31
{
27
{
32
    return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
28
    return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
33
}*/
29
}*/
34
 
30
 
35
static void vfb_send_char(vfb_descriptor_t *d, char c)
31
static 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
 
-
 
37
static char read_stdin(void)
36
{
38
{
37
    ipcarg_t r0,r1;
39
    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);
39
}
44
}
40
               
-
 
41
static ssize_t write_vfb(void *param, const void *buf, size_t count)
45
static ssize_t write_stdout(void *param, const void *buf, size_t count)
42
{
46
{
43
    int i;
47
    int i;
-
 
48
    ipcarg_t r0,r1;
-
 
49
 
44
    for (i = 0; i < count; i++)
50
    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);
46
   
52
   
47
    return count;
53
    return count;
48
    //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
54
    //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
49
}
55
}
50
 
56
 
51
 
57
 
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
}
-
 
57
 
-
 
58
 
58
 
59
stream_t open_vfb(void)
59
static stream_t open_stdin(void)
60
{
60
{
61
    stream_t stream;
61
    stream_t stream;
62
    vfb_descriptor_t *vfb;
-
 
63
    int phoneid;
62
    int phoneid;
64
    int res;
63
    int res;
65
    ipcarg_t vfb_no;
-
 
66
   
64
   
-
 
65
    if (console_phone < 0) {
67
    while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
66
        while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
68
        volatile int a;
67
            volatile int a;
69
       
-
 
70
        for (a = 0; a < 1048576; a++);
68
            for (a = 0; a < 1048576; a++);
-
 
69
        }
71
    }
70
    }
72
   
71
   
73
    ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
72
    stream.r = read_stdin;
-
 
73
    stream.param = 0;
-
 
74
    return stream;
-
 
75
}
-
 
76
 
74
    vfb = malloc(sizeof(vfb_descriptor_t));
77
static stream_t open_stdout(void)
-
 
78
{
-
 
79
    stream_t stream;
-
 
80
    int res;
75
   
81
   
76
    vfb->phone = phoneid;
82
    if (console_phone < 0) {
-
 
83
        while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
77
    vfb->vfb = vfb_no;
84
            volatile int a;
-
 
85
            for (a = 0; a < 1048576; a++);
-
 
86
        }
-
 
87
    }
78
   
88
   
79
    stream.w = write_vfb;
89
    stream.w = write_stdout;
80
    stream.param = vfb;
90
    stream.param = 0;
81
    return stream;
91
    return stream;
82
}
92
}
83
 
93
 
84
 
-
 
85
fd_t open(const char *fname, int flags)
94
fd_t open(const char *fname, int flags)
86
{
95
{
87
    int c = 0;
96
    int c = 0;
88
   
97
   
89
    while (((streams[c].w) || (streams[c].r)) && (c < FDS))
98
    while (((streams[c].w) || (streams[c].r)) && (c < FDS))
90
        c++;
99
        c++;
91
    if (c == FDS)
100
    if (c == FDS)
92
        return EMFILE;
101
        return EMFILE;
93
   
102
   
94
    if (!strcmp(fname, "stdin")) {
103
    if (!strcmp(fname, "stdin")) {
95
        streams[c].r = (preadfn_t)1;
104
        streams[c] = open_stdin();
96
        return c;
105
        return c;
97
    }
106
    }
98
   
107
   
99
    if (!strcmp(fname, "stdout")) {
108
    if (!strcmp(fname, "stdout")) {
100
        //streams[c].w = write_stdout;
109
        //streams[c].w = write_stdout;
101
        //return c;
110
        //return c;
102
        streams[c] = open_vfb();
111
        streams[c] = open_stdout();
103
        return c;
112
        return c;
104
    }
113
    }
105
   
114
   
106
    if (!strcmp(fname, "stderr")) {
115
    if (!strcmp(fname, "stderr")) {
107
        streams[c].w = write_stderr;
116
        streams[c].w = write_stderr;