source: mainline/libc/generic/io/stream.c@ afa6e74

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since afa6e74 was afa6e74, checked in by Jakub Vana <jakub.vana@…>, 19 years ago

Earliest version of Userspace Framebuffer driver, with stream support in libc.
Also Virtual framebuffers made as split on main fb and its usage by streams

(please test it and report)

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