source: trunk/libs/stdio.c @ 436

Last change on this file since 436 was 435, checked in by alain, 6 years ago

Fix a bad bug in scheduler...

File size: 10.0 KB
Line 
1/*
2 * stdio.c - User side system calls implementation.
3 *
4 * Author     Alain Greiner (2016,2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <shared_syscalls.h>
25#include <hal_user.h>
26#include <stdio.h>
27#include <stdlib.h>
28
29#define  reg_t     int
30
31///////////// POSIX standard system calls ////////////////////////////////////
32
33///////////////////////
34void exit( int status )
35{
36    hal_user_syscall( SYS_EXIT,
37                      (reg_t)status, 0, 0, 0 );
38}
39
40/////////////////////////////////
41int munmap( void         * addr,
42            unsigned int   size )
43{
44    return hal_user_syscall( SYS_MUNMAP,
45                             (reg_t)addr,
46                             (reg_t)size, 0, 0 );
47}
48
49////////////////////////////////
50int open( const char * pathname,
51          int          flags,
52          int          mode )
53{
54    return hal_user_syscall( SYS_OPEN,
55                             (reg_t)pathname,
56                             (reg_t)flags,
57                             (reg_t)mode, 0 );
58}
59
60///////////////////////////////
61void * mmap( void       * addr,
62             unsigned int length,
63             int          prot,
64             int          flags,
65             int          fd,
66             unsigned int offset )
67{
68    mmap_attr_t attr;
69    attr.addr   = addr;
70    attr.length = length;
71    attr.prot   = prot;
72    attr.flags  = flags;
73    attr.fdid   = fd;
74    attr.offset = offset;
75
76    if( hal_user_syscall( SYS_MMAP,
77                          (reg_t)&attr, 0, 0, 0 ) ) return NULL;
78    else                                            return attr.addr;
79}
80
81//////////////////////////
82int read( int          fd,
83          void       * buf,
84          unsigned int count )
85{
86    return hal_user_syscall( SYS_READ,
87                             (reg_t)fd,
88                             (reg_t)buf,
89                             (reg_t)count, 0 );
90}
91
92///////////////////////////
93int write( int          fd,
94           const void * buf,
95           unsigned int count )
96{
97    return hal_user_syscall( SYS_WRITE,
98                             (reg_t)fd,
99                             (reg_t)buf,
100                             (reg_t)count, 0 );
101}
102
103///////////////////////////
104int lseek( int          fd,
105           unsigned int offset,
106           int          whence )
107{
108    return hal_user_syscall( SYS_LSEEK,
109                             (reg_t)fd,
110                             (reg_t)offset,
111                             (reg_t)whence, 0 );
112}
113
114///////////////////
115int close( int fd )
116{
117    return hal_user_syscall( SYS_CLOSE,
118                             (reg_t)fd, 0, 0, 0 );
119}
120
121///////////////////////////////////
122int unlink( const char * pathname )
123{
124    return hal_user_syscall( SYS_UNLINK,
125                             (reg_t)pathname, 0, 0, 0 );
126}
127
128/////////////////////
129int pipe( int fd[2] )
130{
131    return -1;
132}
133
134//////////////////////////////////
135int chdir( const char * pathname )
136{
137    return hal_user_syscall( SYS_CHDIR,
138                             (reg_t)pathname, 0, 0, 0 );
139}
140
141/////////////////////////////////
142int mkdir( const char * pathname,
143           int          mode )
144{
145    return hal_user_syscall( SYS_MKDIR,
146                             (reg_t)pathname,
147                             (reg_t)mode, 0, 0 );
148}
149
150//////////////////////////////////
151int mkfifo( const char * pathname,
152            int          mode )
153{
154    return hal_user_syscall( SYS_MKFIFO,
155                             (reg_t)pathname,
156                             (reg_t)mode, 0, 0 );
157}
158
159//////////////////////////////////////
160DIR * opendir( const char * pathname )
161{
162    DIR   * dirp; 
163    int     error;
164    error = hal_user_syscall( SYS_OPENDIR,
165                              (reg_t)pathname,
166                              (reg_t)&dirp, 0, 0 );
167    if( error ) return NULL;
168    else        return dirp;
169}
170
171/////////////////////////////////////
172struct dirent * readdir( DIR * dirp )
173{
174    struct dirent * dentp;
175    int             error;
176    error = hal_user_syscall( SYS_READDIR,
177                              (reg_t)dirp,
178                              (reg_t)&dentp, 0, 0 );
179    if( error ) return NULL;
180    else        return dentp;
181}
182
183//////////////////////////
184int closedir( DIR * dirp )
185{
186    return hal_user_syscall( SYS_CLOSEDIR,
187                             (reg_t)dirp, 0, 0, 0 );
188}
189
190/////////////////////////////
191int getcwd( char       * buf,
192            unsigned int bytes )
193{
194    return hal_user_syscall( SYS_GETCWD,
195                             (reg_t)buf,
196                             (reg_t)bytes, 0, 0 );
197}
198
199////////////////////////////
200int rmdir( char * pathname )
201{
202    return hal_user_syscall( SYS_RMDIR,
203                             (reg_t)pathname, 0, 0, 0 );
204} 
205
206/////////////////////////////////
207int utls( unsigned int operation,
208          unsigned int value )
209{
210    return hal_user_syscall( SYS_UTLS,
211                             (reg_t)operation,
212                             (reg_t)value, 0, 0 );
213}
214
215///////////////////////////////
216int chmod( char     * pathname,
217           unsigned int   rights )
218{
219    return hal_user_syscall( SYS_CHMOD,
220                             (reg_t)pathname,
221                             (reg_t)rights, 0, 0 );
222}
223
224/////////////////////////////////
225int signal( unsigned int   sigid,
226            void         * handler )
227{
228    return hal_user_syscall( SYS_SIGNAL,
229                             (reg_t)sigid,
230                             (reg_t)handler, 0, 0 );
231}
232
233///////////////////////////////////////
234int gettimeofday( struct timeval  * tv,
235                  struct timezone * tz )
236{
237    return hal_user_syscall( SYS_SIGNAL,
238                             (reg_t)tv,
239                             (reg_t)tz, 0, 0 );
240}
241
242///////////////////////////
243int kill( unsigned int pid,
244          unsigned int sig_id )
245{
246    return hal_user_syscall( SYS_KILL,
247                             (reg_t)pid,
248                             (reg_t)sig_id, 0, 0 );
249}
250
251////////////
252int getpid()
253{
254    return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 );
255}
256
257//////////
258int fork()
259{
260    return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 );
261}
262
263///////////////////////////
264int exec( char  * pathname,
265          char ** argv,
266          char ** envp )
267{
268    return hal_user_syscall( SYS_EXEC,
269                             (reg_t)pathname,
270                             (reg_t)argv,
271                             (reg_t)envp, 0 );
272}
273
274/////////////////////////////////
275int stat( const char  * pathname,
276          struct stat * stat )
277{
278    return hal_user_syscall( SYS_STAT,
279                             (reg_t)pathname,
280                             (reg_t)stat, 0, 0 );
281}
282
283////////////////////////
284int wait( int * status )
285{
286    return hal_user_syscall( SYS_WAIT,
287                             (reg_t)status, 0, 0, 0 );
288}
289
290
291
292/////////////     Non standard system calls ////////////////////////////////////
293
294
295//////////////////////////
296int fg( unsigned int pid )
297{
298    return hal_user_syscall( SYS_FG,
299                             (reg_t)pid, 0, 0, 0 );
300}
301
302//////////////////////////////////////
303int get_config( unsigned int * x_size,
304                unsigned int * y_size,
305                unsigned int * ncores )
306{
307    return hal_user_syscall( SYS_GET_CONFIG,
308                             (reg_t)x_size,
309                             (reg_t)y_size,
310                             (reg_t)ncores, 0 );
311}
312
313/////////////////////////////////
314int get_core( unsigned int * cxy,
315              unsigned int * lid )
316{
317    return hal_user_syscall( SYS_GET_CORE,
318                             (reg_t)cxy,
319                             (reg_t)lid, 0, 0 );
320}
321
322////////////////////////////////////
323void display_string( char * string )
324{
325    hal_user_syscall( SYS_DISPLAY,
326                      DISPLAY_STRING,
327                      (reg_t)string, 0, 0 );
328}
329
330///////////////////////////////////
331int display_vmm( unsigned int pid )
332{
333    return hal_user_syscall( SYS_DISPLAY,
334                             DISPLAY_VMM,
335                             (reg_t)pid, 0, 0 );
336} 
337
338////////////////////////////////
339int display_sched( unsigned int cxy,
340                   unsigned int lid )
341{
342    return hal_user_syscall( SYS_DISPLAY,
343                             DISPLAY_SCHED,
344                             (reg_t)cxy,
345                             (reg_t)lid, 0 );
346} 
347
348/////////////////////////////////////////////////
349int display_cluster_processes( unsigned int cxy )
350{
351    return hal_user_syscall( SYS_DISPLAY,
352                             DISPLAY_CLUSTER_PROCESSES,
353                             (reg_t)cxy, 0, 0 );
354} 
355
356///////////////////
357int display_chdev()
358{
359    return hal_user_syscall( SYS_DISPLAY,
360                             DISPLAY_CHDEV, 0, 0, 0 );
361} 
362
363/////////////////
364int display_vfs()
365{
366    return hal_user_syscall( SYS_DISPLAY,
367                             DISPLAY_VFS, 0, 0, 0 );
368} 
369
370////////////////////////////////////////////////
371int display_txt_processes( unsigned int txt_id )
372{
373    return hal_user_syscall( SYS_DISPLAY,
374                             DISPLAY_TXT_PROCESSES,
375                             (reg_t)txt_id, 0, 0 );
376} 
377
378///////////////////////////////////////////
379int get_cycle( unsigned long long * cycle )
380{
381    return hal_user_syscall( SYS_GET_CYCLE,
382                             (reg_t)cycle, 0, 0, 0 );
383}
384
385//////////////////////////////////
386int trace( unsigned int operation,
387           unsigned int pid, 
388           unsigned int trdid )
389{
390    return hal_user_syscall( SYS_TRACE,
391                             (reg_t)pid,
392                             (reg_t)trdid, 0, 0 );
393}
394
395
Note: See TracBrowser for help on using the repository browser.