4 #include <lib/routix.h>
6 #include <sys/syscalls.h>
10 void sprintn ( unsigned int num
, int base
);
11 void sputchar (char car
);
12 char getascii (char c
);
14 int sleep(int segundos
)
18 _syscall1( SYS_TIMER
| SYS_SLEEP
, retorno
, segundos
);
24 int usleep(int usegundos
)
28 _syscall1( SYS_TIMER
| SYS_USLEEP
, retorno
, usegundos
);
38 _syscall0( SYS_TIMER
| SYS_PROC_DUMP
, retorno
);
43 int proc_dump_v(int pid
)
47 _syscall1( SYS_TIMER
| SYS_PROC_DUMP_V
, retorno
, pid
);
56 _syscall0( SYS_TIMER
| SYS_TIMER_DUMP
, retorno
);
61 int read_debug(int sector
)
65 _syscall1( SYS_MISC
| SYS_READ_DEBUG
, retorno
, sector
);
71 //Entrega una pagina al espacio de usuario
72 void *malloc_page(void)
75 _syscall0( SYS_MEM
| SYS_MALLOC_PAGE
, retorno
);
79 int free_page(void *dir
)
82 _syscall1( SYS_MEM
| SYS_FREE_PAGE
, retorno
, dir
);
89 _syscall0( SYS_MEM
| SYS_FREE_MEM
, retorno
);
93 void perror (char *str
)
96 _syscall1(SYS_PROCESS
| SYS_PERROR
, retorno
, str
);
101 int exec (char *tarea)
104 // _syscall1(SYS_PROCESS | SYS_EXEC, retorno, tarea);
105 printf("Llamando a execve ...\n");
106 return execve(tarea, NULL, NULL);
109 int execve (char *tarea
, char **argv
, char **envp
)
112 _syscall3(SYS_PROCESS
| SYS_EXECVE
, retorno
, tarea
, argv
, envp
);
119 void gets (char *str
)
122 _syscall1(SYS_CONSOLE
| SYS_GETS
, retorno
, str
);
128 _syscall0(SYS_PROCESS
| SYS_FORK
, retorno
);
136 _syscall0(SYS_PROCESS
| SYS_VOID
, retorno
);
139 int renice(word pid
, word prioridad
)
143 _syscall2( SYS_PROCESS
| SYS_RENICE
, retorno
, pid
, prioridad
);
151 _syscall0( SYS_PROCESS
| SYS_GETPID
, retorno
);
158 _syscall0( SYS_PROCESS
| SYS_GETPPID
, retorno
);
165 _syscall1(SYS_PROCESS
| SYS_EXIT
, retorno
, valor
);
171 _syscall1(SYS_PROCESS
| SYS_SHOW
, retorno
, valor
);
174 pid_t
wait(int *valor
)
176 return waitpid(0, valor
, 0);
179 pid_t
waitpid (pid_t pid
, int *valor
, int options
)
182 _syscall3(SYS_PROCESS
| SYS_WAIT
, retorno
, pid
, valor
, options
);
186 int kill(pid_t pid
, int sig
)
189 _syscall2(SYS_SIGNALS
| SYS_KILL
, retorno
, pid
, sig
);
193 void *signal (int signo
, void (*func
)() )
196 _syscall2(SYS_SIGNALS
| SYS_SIGNAL
, retorno
, signo
, func
);
200 int sigaction (int signo
, struct sigaction
*act
, struct sigaction
*oact
)
203 _syscall3(SYS_SIGNALS
| SYS_SIGACTION
, retorno
, signo
, act
, oact
);
208 void *signal_check ()
211 _syscall0(SYS_SIGNALS
| SYS_SIGNAL_CHECK
, retorno
);
215 int sigprocmask(int flag
, const sigset_t
*set
, sigset_t
*old_set
)
218 _syscall3(SYS_SIGNALS
| SYS_SIGPROCMASK
, retorno
, flag
, set
, old_set
);
222 // Funcion de libraria "putchar"
223 int putchar (char car
)
232 // llamada al sistema (similar a write pero hacia stdout)
236 _syscall2(SYS_CONSOLE
| SYS_PRINT
, retorno
, str
, strlen(str
));
242 _syscall0(SYS_CONSOLE
| SYS_CLRSCR
, retorno
);
246 #define MAX_STRING 100
252 //****************************************************************************************************
253 // printf ( char *string, ...) y funciones requeridas por ella
254 //****************************************************************************************************
256 //char getascii_ ( char c );
257 void printn_ ( unsigned int num
, int base
);
259 void printf ( char *string
, ...)
270 va_start(argumentos
, string
);
272 for ( p
=string
; *p
; p
++ ) {
281 car
=va_arg(argumentos
, int);
282 putchar( (char) car
);
286 i
= va_arg(argumentos
, unsigned int );
291 i
= va_arg(argumentos
, int);
292 if (i
> (0xffffffff/2)) {
301 i
= va_arg(argumentos
, unsigned int);
306 i
= va_arg(argumentos
, unsigned int);
311 d
= va_arg(argumentos
, char *);
325 void printn_s ( unsigned int num
, int base
, char *str
, int *index
);
328 int sprintf(char *str
, const char *string
, ...)
330 char *p
=(char *)string
;
335 unsigned int index
= 0; // Posicion dentro de str donde se colocara el proximo dato
339 va_start(argumentos
, string
);
341 for ( p
=(char *)string
; *p
; p
++ ) {
350 car
=va_arg(argumentos
, int);
354 i
= va_arg(argumentos
, unsigned int );
355 printn_s(i
,16, str
, &index
);
358 i
= va_arg(argumentos
, int);
359 if (i
> (0xffffffff/2)) {
361 printn_s(~i
+1,10, str
, &index
);
364 printn_s(i
,10, str
, &index
);
367 i
= va_arg(argumentos
, unsigned int);
368 printn_s(i
,10, str
, &index
);
371 // i = va_arg(argumentos, unsigned int);
375 d
= va_arg(argumentos
, char *);
376 strcat(str
+index
, d
);
393 void printn_ ( unsigned int num
, int base
)
396 if ( (div
=num
/base
) ) printn_(div
,base
);
397 putchar( getascii(num
%base
) );
400 void printn_s ( unsigned int num
, int base
, char *str
, int *index
)
403 if ( (div
=num
/base
) )
404 printn_s(div
,base
, str
, index
);
405 str
[(*index
)++] = ( getascii(num
%base
) );
409 char getascii ( char c
)
411 char valor
= '0' + c
;
413 if ( valor
> '9' ) valor
+= 7;
417 ////////////////// Grupo Misc ///////////////////////////
418 int setvar (char *nombre
, int valor
)
421 _syscall2( SYS_MISC
| SYS_SETVAR
, retorno
, nombre
, valor
);
425 int getvar (char *nombre
)
428 _syscall1( SYS_MISC
| SYS_GETVAR
, retorno
, nombre
);
434 __asm__
__volatile__("int $0x51");
438 int clone(void *func
)
441 _syscall1( SYS_PROCESS
| SYS_CLONE
, retorno
, func
);