Added libshell for TCC

git-svn-id: svn://kolibrios.org@9207 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat
2021-09-26 19:56:07 +00:00
parent 8918a376d9
commit d38b3890d2
17 changed files with 226 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
CC = kos32-tcc
AR = ar
CFLAGS = -c -I../../libc.obj/include
LIB = libshell.a
OBJS = \
shell_exit.o \
shell_puts.o \
shell_get_pid.o \
shell_ping.o \
shell_getc.o \
shell_cls.o \
shell_init.o \
shell_gets.o \
shell_printf.o \
shell_putc.o
$(LIB): $(OBJS)
$(AR) -crs $@ $(OBJS)
%.o : %.c Makefile
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -rf $(OBJS) $(LIB)

View File

@@ -0,0 +1 @@
-I../../libc.obj/include

View File

@@ -0,0 +1,8 @@
#include <shell_api.h>
void shell_cls()
{
__shell_init();
*__shell_shm = SHELL_CLS;
__SHELL_WAIT();
}

View File

@@ -0,0 +1,11 @@
#include <shell_api.h>
#include <sys/ksys.h>
void shell_exit()
{
if(__shell_is_init){
*__shell_shm = SHELL_EXIT;
__SHELL_WAIT();
_ksys_shm_close(__shell_shm_name);
}
}

View File

@@ -0,0 +1,12 @@
#include <shell_api.h>
#include <string.h>
unsigned shell_get_pid()
{
unsigned pid;
__shell_init();
*__shell_shm = SHELL_PID;
__SHELL_WAIT();
memcpy(&pid, __shell_shm+1, sizeof(unsigned));
return pid;
}

View File

@@ -0,0 +1,9 @@
#include "shell_api.h"
char shell_getc()
{
__shell_init();
*__shell_shm = SHELL_GETC;
__SHELL_WAIT();
return *(__shell_shm+1);
}

View File

@@ -0,0 +1,10 @@
#include <shell_api.h>
#include <string.h>
void shell_gets(char *str, int n)
{
__shell_init();
*__shell_shm = SHELL_GETS;
__SHELL_WAIT();
strncpy(str, __shell_shm+1, n);
}

View File

@@ -0,0 +1,44 @@
#include <sys/ksys.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <shell_api.h>
char app_name[13];
char __shell_shm_name[32];
char*__shell_shm=NULL;
int __shell_is_init=0;
int __shell_shm_init()
{
__shell_is_init=1;
ksys_thread_t *proc_info = (ksys_thread_t*)malloc(sizeof(ksys_thread_t));
if(proc_info == NULL){
return -1;
}
unsigned PID;
_ksys_thread_info(proc_info, -1);
PID = proc_info->pid;
strncpy(app_name, proc_info->name, 12);
free(proc_info);
itoa(PID, __shell_shm_name);
strcat(__shell_shm_name, "-SHELL");
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
}
void __shell_init()
{
if(!__shell_is_init){
if(__shell_shm_init()){
debug_printf("%s: shell problems detected!\n", app_name);
_ksys_exit();
}
if(!shell_ping()){
debug_printf("%s: no shell found!\n", app_name);
_ksys_exit();
}
}
}

View File

@@ -0,0 +1,13 @@
#include <shell_api.h>
#include <sys/ksys.h>
int shell_ping()
{
__shell_init();
*__shell_shm = SHELL_PING;
_ksys_delay(10);
if(*__shell_shm==SHELL_OK){
return 1;
}
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <shell_api.h>
#include <stdio.h>
void shell_printf(const char *format,...)
{
va_list ap;
va_start (ap, format);
*__shell_shm=SHELL_PUTS;
vsnprintf(__shell_shm+1, SHELL_SHM_MAX, format, ap);
va_end(ap);
__SHELL_WAIT();
}

View File

@@ -0,0 +1,9 @@
#include <shell_api.h>
void shell_putc(char c)
{
__shell_init();
*__shell_shm = SHELL_PUTC;
*(__shell_shm+1) = c;
__SHELL_WAIT();
}

View File

@@ -0,0 +1,10 @@
#include <shell_api.h>
#include <string.h>
void shell_puts(const char *str)
{
__shell_init();
*__shell_shm = SHELL_PUTS;
strcpy(__shell_shm+1, str);
__SHELL_WAIT();
}