- Duplicate functionality files removed;
- Refactoring of file handling functions;
- Removed broken impliments.
Gears (C + TinyGL):
- Removed because it duplicates an existing example on Fasm and uses unsupported wrappers on the KOS API.
KosJS:
- Removed. The MuJS port is too old and not used anywhere. Support is not profitable.
Backy:
- Removed useless GCC version. Support is not profitable.
DGen-SDL and SQLite3
- Fix after removing broken "dirent.h".
Fridge:
- Moving the KOS API wrapper to avoid compilation errors.
Udis86, uARM and 8086tiny:
- Fix after removing redundant "kos_LoadConsole.h".


git-svn-id: svn://kolibrios.org@9952 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat
2024-01-04 22:20:35 +00:00
parent c6d4aab9c5
commit 9562f01892
112 changed files with 344 additions and 22302 deletions

View File

@@ -116,10 +116,9 @@ CORE_SRCS:= \
sys/clock_gettime.c \
sys/close.c \
sys/conio.c \
sys/create.c \
sys/chdir.c \
sys/getcwd.c \
sys/errno.c \
sys/finfo.c \
sys/fsize.c \
sys/fstat.c \
sys/gettod.c \
sys/io.c \
@@ -473,16 +472,6 @@ STDIO_SRCS= \
wscanf.c \
wsetup.c
DIRENT_SRCS= dir.c \
closedir.c \
opendir.c \
readdir.c \
rewinddir.c \
seekdir.c \
telldir.c \
scandir.c \
alphasort.c
MATH_SRCS = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c e_exp.c e_fmod.c \
e_hypot.c e_j0.c e_j1.c e_jn.c e_log.c e_log10.c e_pow.c e_rem_pio2.c \
e_remainder.c e_scalb.c e_sinh.c e_sqrt.c ef_acos.c ef_acosh.c ef_asin.c \
@@ -539,9 +528,6 @@ STRING_OBJS = $(patsubst %.S, string/%.o, $(patsubst %.asm, string/%.o,\
STDLIB_OBJS = $(patsubst %.S, stdlib/%.o, $(patsubst %.asm, stdlib/%.o,\
$(patsubst %.c, stdlib/%.o, $(STDLIB_SRCS))))
DIRENT_OBJS = $(patsubst %.S, dirent/%.o, $(patsubst %.asm, dirent/%.o,\
$(patsubst %.c, dirent/%.o, $(DIRENT_SRCS))))
MATH_OBJS = $(patsubst %.S, math/%.o, $(patsubst %.asm, math/%.o,\
$(patsubst %.c, math/%.o, $(MATH_SRCS))))

View File

@@ -1,461 +0,0 @@
CC = kos32-gcc
AR = kos32-ar
LD = kos32-ld
CFLAGS = -c -O2 -march=pentium-mmx -fomit-frame-pointer -DBUILD_DLL -DMISSING_SYSCALL_NAMES
LDFLAGS = -nostdlib -shared -s -T libcdll.lds --output-def libc.orig.def --out-implib libc.dll.a --image-base 0
ARFLAGS = crs
SDK_DIR:= $(abspath ../../..)
LIBC_TOPDIR = .
LIBC_INCLUDES = $(LIBC_TOPDIR)/include
NAME:= libc
DEFINES:= -D_IEEE_LIBM
INCLUDES:= -I $(LIBC_INCLUDES)
LIBPATH:= -L$(SDK_DIR)/lib -L/home/autobuild/tools/win32/mingw32/lib
STATIC_SRCS:= \
crt/start.S \
crt/crt1.c \
crt/crt2.c \
crt/chkstk.S \
crt/exit.S \
pe/crtloader.c
LIBDLL_SRCS:= \
crt/dllstart.c \
crt/chkstk.S \
crt/exit.S \
crt/pseudo-reloc.c \
crt/setjmp.S
LIBCDLL_SRCS:= \
crt/crtdll.c \
crt/pseudo-reloc.c \
crt/chkstk.S \
crt/exit.S \
pe/loader.c
LIBCRT_SRCS:= \
crt/start.S \
crt/chkstk.S \
crt/crt3.c \
crt/pseudo-reloc.c \
pe/crtloader.c
CORE_SRCS:= \
argz/buf_findstr.c \
argz/envz_get.c \
crt/emutls.c \
crt/thread.S \
crt/tls.S \
crt/setjmp.S \
crt/cpu_features.c \
ctype/ctype_.c \
ctype/isascii.c \
ctype/isblank.c \
ctype/isalnum.c \
ctype/isalpha.c \
ctype/iscntrl.c \
ctype/isdigit.c \
ctype/islower.c \
ctype/isupper.c \
ctype/isprint.c \
ctype/ispunct.c \
ctype/isspace.c \
ctype/iswctype.c \
ctype/iswalnum.c \
ctype/iswalpha.c \
ctype/iswblank.c \
ctype/iswcntrl.c \
ctype/iswdigit.c \
ctype/iswgraph.c \
ctype/iswlower.c \
ctype/iswprint.c \
ctype/iswpunct.c \
ctype/iswspace.c \
ctype/iswupper.c \
ctype/iswxdigit.c \
ctype/isxdigit.c \
ctype/toascii.c \
ctype/tolower.c \
ctype/toupper.c \
ctype/towctrans.c \
ctype/towlower.c \
ctype/towupper.c \
ctype/wctrans.c \
ctype/wctype.c \
errno/errno.c \
locale/locale.c \
locale/lctype.c \
locale/ldpart.c \
reent/impure.c \
reent/init_reent.c \
reent/getreent.c \
reent/mutex.c \
reent/gettimeofdayr.c \
reent/isattyr.c \
reent/openr.c \
reent/closer.c \
reent/linkr.c \
reent/readr.c \
reent/lseekr.c \
reent/fstatr.c \
reent/writer.c \
reent/timesr.c \
reent/unlinkr.c \
search/qsort.c \
search/bsearch.c \
signal/signal.c \
sys/close.c \
sys/create.c \
sys/delete.c \
sys/errno.c \
sys/finfo.c \
sys/fsize.c \
sys/fstat.c \
sys/gettod.c \
sys/io.c \
sys/ioread.c \
sys/iowrite.c \
sys/isatty.c \
sys/lseek.c \
sys/open.c \
sys/read.c \
sys/unlink.c \
sys/write.c \
sys/io_alloc.S \
time/asctime.c \
time/asctime_r.c \
time/clock.c \
time/ctime.c \
time/ctime_r.c \
time/difftime.c \
time/gettzinfo.c \
time/gmtime.c \
time/gmtime_r.c \
time/mktime.c \
time/mktm_r.c \
time/lcltime.c \
time/lcltime_r.c \
time/strftime.c \
time/time.c \
time/timelocal.c \
time/tzlock.c \
time/tzvars.c
STDLIB_SRCS= \
__atexit.c \
__call_atexit.c \
abort.c \
abs.c \
assert.c \
atexit.c \
atof.c \
atoi.c \
atol.c \
div.c \
dtoa.c \
dtoastub.c \
exit.c \
gdtoa-gethex.c \
gdtoa-hexnan.c \
getenv.c \
mprec.c \
mbtowc.c \
mbtowc_r.c \
mbrtowc.c \
mlock.c \
calloc.c \
malloc.c \
mallocr.c \
rand.c \
rand_r.c \
rand48.c \
realloc.c \
seed48.c \
srand48.c \
strtod.c \
strtol.c \
strtold.c \
strtoll.c \
strtoll_r.c \
strtoul.c \
strtoull.c \
strtoull_r.c \
system.c \
wcrtomb.c \
wctomb_r.c
STRING_SRCS= memcpy.c \
memcmp.c \
memmove.c \
memset.c \
memchr.c \
stpcpy.c \
stpncpy.c \
strcat.c \
strchr.c \
strcmp.c \
strcoll.c \
strcasecmp.c \
strncasecmp.c \
strncat.c \
strncmp.c \
strncpy.c \
strndup.c \
strndup_r.c \
strnlen.c \
strcasestr.c \
strdup.c \
strdup_r.c \
strerror.c \
strlen.c \
strrchr.c \
strpbrk.c \
strsep.c \
strstr.c \
strtok.c \
strtok_r.c \
strupr.c \
strcspn.c \
strspn.c \
strcpy.c \
u_strerr.c
STDIO_SRCS= \
clearerr.c \
diprintf.c \
dprintf.c \
printf.c \
putchar.c \
fgetc.c \
fgets.c \
fopen.c \
fclose.c \
fdopen.c \
fflush.c \
flags.c \
fileno.c \
findfp.c \
fiprintf.c \
fiscanf.c \
fprintf.c \
fputc.c \
fputs.c \
fputwc.c \
fread.c \
freopen.c \
fscanf.c \
fseek.c \
fseeko.c \
ftell.c \
ftello.c \
fwrite.c \
fvwrite.c \
fwalk.c \
putc.c \
puts.c \
refill.c \
rget.c \
remove.c \
setvbuf.c \
stdio.c \
tmpfile.c \
tmpnam.c \
ungetc.c \
vasniprintf.c \
vasnprintf.c \
vdprintf.c \
vdiprintf.c \
vscanf.c \
vsprintf.c \
vsnprintf.c \
vsscanf.c \
makebuf.c \
wsetup.c \
wbuf.c \
sccl.c \
siprintf.c \
sniprintf.c \
snprintf.c \
sprintf.c \
sscanf.c
MATH_SRCS = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c e_exp.c e_fmod.c \
e_hypot.c e_j0.c e_j1.c e_jn.c e_log.c e_log10.c e_pow.c e_rem_pio2.c \
e_remainder.c e_scalb.c e_sinh.c e_sqrt.c ef_acos.c ef_acosh.c ef_asin.c \
ef_atan2.c ef_atanh.c ef_cosh.c ef_exp.c ef_fmod.c ef_hypot.c ef_j0.c ef_j1.c \
ef_jn.c ef_log.c ef_log10.c ef_pow.c ef_rem_pio2.c ef_remainder.c ef_scalb.c \
ef_sinh.c ef_sqrt.c er_gamma.c er_lgamma.c erf_gamma.c erf_lgamma.c f_exp.c \
f_expf.c f_llrint.c f_llrintf.c f_llrintl.c f_lrint.c f_lrintf.c f_lrintl.c \
f_pow.c f_powf.c f_rint.c f_rintf.c f_rintl.c k_cos.c k_rem_pio2.c k_sin.c \
k_standard.c k_tan.c kf_cos.c kf_rem_pio2.c kf_sin.c kf_tan.c s_asinh.c \
s_atan.c s_cbrt.c s_ceil.c s_copysign.c s_cos.c s_erf.c s_exp10.c s_expm1.c \
s_fabs.c s_fdim.c s_finite.c s_floor.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
s_frexp.c s_ilogb.c s_infconst.c s_infinity.c s_isinf.c s_isinfd.c s_isnan.c \
s_isnand.c s_ldexp.c s_lib_ver.c s_llrint.c s_llround.c s_log1p.c s_log2.c \
s_logb.c s_lrint.c s_lround.c s_matherr.c s_modf.c s_nan.c s_nearbyint.c \
s_nextafter.c s_pow10.c s_remquo.c s_rint.c s_round.c s_scalbln.c s_scalbn.c \
s_signbit.c s_signif.c s_sin.c s_tan.c s_tanh.c s_trunc.c scalblnl.c scalbnl.c \
sf_asinh.c sf_atan.c sf_cbrt.c sf_ceil.c sf_copysign.c sf_cos.c sf_erf.c \
sf_exp10.c sf_expm1.c sf_fabs.c sf_fdim.c sf_finite.c sf_floor.c sf_fma.c \
sf_fmax.c sf_fmin.c sf_fpclassify.c sf_frexp.c sf_ilogb.c sf_infinity.c \
sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c sf_ldexp.c sf_llrint.c \
sf_llround.c sf_log1p.c sf_log2.c sf_logb.c sf_lrint.c sf_lround.c sf_modf.c \
sf_nan.c sf_nearbyint.c sf_nextafter.c sf_pow10.c sf_remquo.c sf_rint.c \
sf_round.c sf_scalbln.c sf_scalbn.c sf_signif.c sf_sin.c sf_tan.c sf_tanh.c \
sf_trunc.c w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c w_cosh.c w_drem.c \
w_exp.c w_exp2.c w_fmod.c w_gamma.c w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c \
w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sincos.c w_sinh.c w_sqrt.c \
w_tgamma.c wf_acos.c wf_acosh.c wf_asin.c wf_atan2.c wf_atanh.c wf_cosh.c \
wf_drem.c wf_exp.c wf_exp2.c wf_fmod.c wf_gamma.c wf_hypot.c wf_j0.c wf_j1.c \
wf_jn.c wf_lgamma.c wf_log.c wf_log10.c wf_pow.c wf_remainder.c wf_scalb.c \
wf_sincos.c wf_sinh.c wf_sqrt.c wf_tgamma.c wr_gamma.c wr_lgamma.c wrf_gamma.c \
wrf_lgamma.c \
f_atan2.S f_atan2f.S f_frexp.S f_frexpf.S f_ldexp.S f_ldexpf.S f_log.S \
f_log10.S f_log10f.S f_logf.S f_tan.S f_tanf.S
STATIC_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(STATIC_SRCS)))
LIBCRT_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(LIBCRT_SRCS)))
LIBDLL_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(LIBDLL_SRCS)))
LIBCDLL_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(LIBCDLL_SRCS)))
CORE_OBJS = $(patsubst %.S, %.o, $(patsubst %.asm, %.obj,\
$(patsubst %.c, %.o, $(CORE_SRCS))))
STDIO_OBJS = $(patsubst %.c, stdio/%.o,$(STDIO_SRCS))
STRING_OBJS = $(patsubst %.S, string/%.o, $(patsubst %.asm, string/%.o,\
$(patsubst %.c, string/%.o, $(STRING_SRCS))))
STDLIB_OBJS = $(patsubst %.S, stdlib/%.o, $(patsubst %.asm, stdlib/%.o,\
$(patsubst %.c, stdlib/%.o, $(STDLIB_SRCS))))
MATH_OBJS = $(patsubst %.S, math/%.o, $(patsubst %.asm, math/%.o,\
$(patsubst %.c, math/%.o, $(MATH_SRCS))))
PRINTF_OBJS= stdio/vfprintf.o \
stdio/vfiprintf.o \
stdio/svfprintf.o \
stdio/svfiprintf.o \
stdio/vfscanf.o \
stdio/vfiscanf.o \
stdio/svscanf.o \
stdio/svfiscanf.o
ifeq ($(findstring static,$(MAKECMDGOALS)),static)
LIB_SRCS:= $(STATIC_SRCS)
LIB_OBJS:= $(STATIC_OBJS)
else
LIB_SRCS:= $(LIBCDLL_SRCS)
LIB_OBJS:= $(LIBCDLL_OBJS)
endif
LIB_SRCS+= \
$(CORE_SRCS) \
$(STDIO_SRCS) \
$(STRING_SRCS) \
$(STDLIB_SRCS)
LIB_OBJS+= \
$(CORE_OBJS) \
$(STRING_OBJS) \
$(STDLIB_OBJS) \
$(STDIO_OBJS) \
$(PRINTF_OBJS) \
$(MATH_OBJS)
shared: $(NAME).dll libapp.a libdll.a
$(NAME).dll: $(LIB_OBJS) $(SRC_DEP) Makefile
$(LD) $(LDFLAGS) $(LIBPATH) -o $@ $(LIB_OBJS) -lgcc --version-script libc.ver
#sed -e "s/ @[^ ]*//" libc.orig.def > libc.def
#sed -f cmd2.sed libc.def > mem
#sed -f newlib.sed mem > libc.inc
install: libc.dll libc.dll.a libapp.a libdll.a
mv -f libc.dll $(SDK_DIR)/bin
mv -f libc.dll.a $(SDK_DIR)/lib
mv -f libapp.a $(SDK_DIR)/lib
mv -f libdll.a $(SDK_DIR)/lib
libapp.a: $(LIBCRT_OBJS) Makefile
$(AR) $(ARFLAGS) libapp.a $(LIBCRT_OBJS)
libdll.a: $(LIBDLL_OBJS) Makefile
$(AR) $(ARFLAGS) libdll.a $(LIBDLL_OBJS)
static: $(NAME).a
$(NAME).a: $(LIB_OBJS) $(SRC_DEP) Makefile
$(AR) $(ARFLAGS) $(NAME).a $(LIB_OBJS)
stdio/vfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DFLOATING_POINT -c stdio/vfprintf.c -o $@
stdio/vfiprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -c stdio/vfprintf.c -o $@
stdio/svfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DSTRING_ONLY -c stdio/vfprintf.c -o $@
stdio/svfiprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c stdio/vfprintf.c -o $@
stdio/vfscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) stdio/vfscanf.c -o $@
stdio/vfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
%.obj : %.asm Makefile
fasm $< $
%.o : %.c Makefile
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
clean:
-rm -f */*.o

View File

@@ -99,10 +99,9 @@ CORE_SRCS = {
"sys/clock_gettime.c",
"sys/close.c",
"sys/conio.c",
"sys/create.c",
"sys/chdir.c",
"sys/getcwd.c",
"sys/errno.c",
"sys/finfo.c",
"sys/fsize.c",
"sys/fstat.c",
"sys/gettod.c",
"sys/io.c",
@@ -455,18 +454,6 @@ STDIO_SRCS = {
"wsetup.c"
}
DIRENT_SRCS = {
"dir.c",
"closedir.c",
"opendir.c",
"readdir.c",
"rewinddir.c",
"seekdir.c",
"telldir.c",
"scandir.c",
"alphasort.c",
}
MATH_SRCS = {
"e_acos.c", "e_acosh.c", "e_asin.c", "e_atan2.c", "e_atanh.c", "e_cosh.c", "e_exp.c", "e_fmod.c",
"e_hypot.c", "e_j0.c", "e_j1.c", "e_jn.c", "e_log.c", "e_log10.c", "e_pow.c", "e_rem_pio2.c",
@@ -518,7 +505,6 @@ LIB_SRCS += CORE_SRCS
LIB_SRCS += prepend("stdio/", STDIO_SRCS)
LIB_SRCS += prepend("string/", STRING_SRCS)
LIB_SRCS += prepend("stdlib/", STDLIB_SRCS)
LIB_SRCS += prepend("dirent/", DIRENT_SRCS)
LIB_SRCS += prepend("math/", MATH_SRCS)
ALL_OBJS = {}

View File

@@ -200,6 +200,7 @@ public_jmp con_gets2, 12
public_jmp con_cls, 0
public_jmp con_getch2, 0
public_jmp con_getch, 0
public_jmp con_kbhit, 0
public_jmp con_set_cursor_pos, 8
public_jmp con_get_cursor_pos, 8
public_jmp con_write_string, 8
@@ -257,6 +258,7 @@ import console, \
con_cls, 'con_cls', \
con_getch2, 'con_getch2', \
con_getch, 'con_getch', \
con_kbhit, 'con_kbhit', \
con_set_cursor_pos, 'con_set_cursor_pos',\
con_get_cursor_pos, 'con_get_cursor_pos', \
con_write_string, 'con_write_string',\

View File

@@ -17,7 +17,6 @@
#include <stdio.h>
#include <unistd.h>
#include <setjmp.h>
#include <sys/kos_io.h>
struct app_hdr
{

View File

@@ -1,7 +0,0 @@
#include <string.h>
#include <dirent.h>
int alphasort(const struct dirent **a, const struct dirent **b)
{
return strcoll((*a)->d_name, (*b)->d_name);
}

View File

@@ -1,14 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
#include <stdlib.h>
int closedir(DIR *dir){
if(dir == NULL){
return -1;
}else{
free(dir->objs);
free(dir);
return 0;
}
}

View File

@@ -1,26 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include "ksys_fs.h"
int rmdir(const char* dir){
return _ksys_file_delete(dir);
}
int mkdir(const char* dir, unsigned fake_mode){
return _ksys_mkdir(dir);
}
int chdir(char* dir){
_ksys_setcwd(dir);
return 0;
}
char *getcwd(char *buf, unsigned size){
if(!buf){
if((buf = malloc(size))==NULL){
return NULL;
}
}
_ksys_getcwd(buf, size);
return(buf);
}

View File

@@ -1,120 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#ifndef _KSYS_FS_H_
#define _KSYS_FS_H_
#include <stdint.h>
#include <stddef.h>
#define asm_inline __asm__ __volatile__
#pragma pack(push,1)
typedef struct{
unsigned p00;
union{
uint64_t p04;
struct {
unsigned p04dw;
unsigned p08dw;
};
};
unsigned p12;
union {
unsigned p16;
const char *new_name;
void *bdfe;
void *buf16;
const void *cbuf16;
};
char p20;
const char *p21;
}ksys70_t;
typedef struct {
unsigned attributes;
unsigned name_cp;
char creation_time[4];
char creation_date[4];
char last_access_time[4];
char last_access_date[4];
char last_modification_time[4];
char last_modification_date[4];
unsigned long long size;
char name[0];
}ksys_bdfe_t;
#pragma pack(pop)
static inline
int _ksys_work_files(const ksys70_t *k)
{
int status;
asm_inline(
"int $0x40"
:"=a"(status)
:"a"(70), "b"(k)
:"memory"
);
return status;
}
static inline
int _ksys_file_delete(const char *name)
{
ksys70_t k;
k.p00 = 8;
k.p20 = 0;
k.p21 = name;
return _ksys_work_files(&k);
}
static inline
int _ksys_mkdir(const char *path)
{
ksys70_t dir_opt;
dir_opt.p00 = 9;
dir_opt.p21 = path;
return _ksys_work_files(&dir_opt);
}
static inline
void _ksys_setcwd(char* dir){
asm_inline(
"int $0x40"
::"a"(30), "b"(1), "c"(dir)
);
}
static inline
void* _ksys_alloc(size_t size){
void *val;
asm_inline(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(12),"c"(size)
);
return val;
}
static inline
int _ksys_free(void *mem)
{
int val;
asm_inline(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(13),"c"(mem)
);
return val;
}
static inline
int _ksys_getcwd(char* buf, int bufsize){
register int val;
asm_inline(
"int $0x40"
:"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)
);
return val;
}
#endif

View File

@@ -1,53 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
#include "ksys_fs.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#define CHECK_DIR_ERR() if(_ksys_work_files(&inf)){ \
free((void*)inf.p16); \
errno = ENOTDIR; \
return NULL; \
}
DIR* opendir(const char* path)
{
DIR* list = malloc(sizeof(DIR));
if(list==NULL){
errno = ENOMEM;
return NULL;
}
list->pos=0;
unsigned num_of_file=0;
static ksys70_t inf;
inf.p00 = 1;
inf.p04 = 0;
inf.p12 = 2;
inf.p16 = (unsigned) malloc(32+inf.p12*560);
inf.p20 = 0;
inf.p21 = (char*)path;
CHECK_DIR_ERR();
num_of_file = *(unsigned*)(inf.p16+8);
inf.p12 = num_of_file;
free((void*)inf.p16);
inf.p16 = (unsigned)_ksys_alloc(32+inf.p12*560);
list->objs = (struct dirent*) malloc(num_of_file*sizeof(struct dirent));
CHECK_DIR_ERR();
for(int i=0; i<num_of_file; i++){
list->objs[i].d_ino = i;
list->objs[i].d_type = *(unsigned*)(inf.p16+32+(264+40)*i);
strcpy(list->objs[i].d_name,(char*)(inf.p16+32+40+(264+40)*i));
}
list->num_objs = num_of_file;
return list;
}

View File

@@ -1,14 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
#include <stdlib.h>
struct dirent* readdir(DIR *dir)
{
if(dir->num_objs>dir->pos){
dir->pos++;
return &dir->objs[dir->pos-1];
}else{
return NULL;
}
}

View File

@@ -1,9 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
void rewinddir(DIR *dir){
if(dir!=NULL){
dir->pos=0;
}
}

View File

@@ -1,46 +0,0 @@
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stddef.h>
#define SIZE_MAX 256
int scandir(const char *path, struct dirent ***res,
int (*sel)(const struct dirent *),
int (*cmp)(const struct dirent **, const struct dirent **))
{
DIR *d = opendir(path);
struct dirent *de, **names=0, **tmp;
size_t cnt=0, len=0;
int old_errno = errno;
if (!d) return -1;
while ((errno=0), (de = readdir(d))) {
if (sel && !sel(de)) continue;
if (cnt >= len) {
len = 2*len+1;
if (len > SIZE_MAX/sizeof *names) break;
tmp = realloc(names, len * sizeof *names);
if (!tmp) break;
names = tmp;
}
names[cnt] = malloc(sizeof(struct dirent));
if (!names[cnt]) break;
memcpy(names[cnt++], de, sizeof(struct dirent));
}
closedir(d);
if (errno) {
if (names) while (cnt-->0) free(names[cnt]);
free(names);
return -1;
}
errno = old_errno;
if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
*res = names;
return cnt;
}

View File

@@ -1,12 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
void seekdir(DIR *dir, unsigned pos)
{
if(dir==NULL || pos>dir->num_objs){
return;
}
dir->pos=pos;
return;
}

View File

@@ -1,12 +0,0 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
#include <sys/dirent.h>
unsigned telldir(DIR *dir)
{
if(dir!=NULL){
return dir->pos;
}else{
return 0;
}
}

View File

@@ -1,16 +0,0 @@
#ifndef _DIRENT_H_
#define _DIRENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/cdefs.h>
#include <sys/dirent.h>
#if !defined(MAXNAMLEN) && __BSD_VISIBLE
#define MAXNAMLEN 1024
#endif
#ifdef __cplusplus
}
#endif
#endif /*_DIRENT_H_*/

View File

@@ -1,679 +0,0 @@
#ifndef __KOS_32_SYS_H__
#define __KOS_32_SYS_H__
#include <newlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
//#ifdef CONFIG_DEBUF
// #define DBG(format,...) printf(format,##__VA_ARGS__)
//#else
// #define DBG(format,...)
//#endif
#define TYPE_3_BORDER_WIDTH 5
#define WIN_STATE_MINIMIZED 0x02
#define WIN_STATE_ROLLED 0x04
typedef unsigned int color_t;
typedef union __attribute__((packed))
{
uint32_t val;
struct
{
short x;
short y;
};
}pos_t;
typedef union __attribute__((packed))
{
uint32_t val;
struct
{
uint8_t state;
uint8_t code;
uint16_t ctrl_key;
};
}oskey_t;
typedef struct
{
unsigned handle;
unsigned io_code;
void *input;
int inp_size;
void *output;
int out_size;
}ioctl_t;
#pragma pack(push, 1)
struct proc_info
{
unsigned long cpu_usage;
unsigned short pos_in_stack;
unsigned short slot;
unsigned short reserved2;
char name[12];
unsigned long address;
unsigned long memory_usage;
unsigned long ID;
unsigned long left,top;
unsigned long width,height;
unsigned short thread_state;
unsigned short reserved3;
unsigned long cleft, ctop, cwidth, cheight;
unsigned char window_state;
unsigned char reserved4[1024-71];
};
#pragma pack(pop)
struct kolibri_system_colors {
color_t frame_area;
color_t grab_bar;
color_t grab_bar_button;
color_t grab_button_text;
color_t grab_text;
color_t work_area;
color_t work_button;
color_t work_button_text;
color_t work_text;
color_t work_graph;
};
static inline void begin_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
static inline
void end_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
static inline void
put_image(uint16_t x_coord, uint16_t y_coord,
uint16_t size_x, uint16_t size_y, void *img)
{
__asm__ __volatile__("int $0x40"
::"a"(25),
"b"(img),
"c"(size_x<<16 | size_y),
"d"(x_coord<<16 | y_coord));
};
static inline
void sys_create_window(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | ((w-1) & 0xFFFF)),
"c"((y << 16) | ((h-1) & 0xFFFF)),
"d"((style << 24) | (workcolor & 0xFFFFFF)),
"D"(name),
"S"(0) : "memory");
};
#define OLD -1
static inline
void sys_change_window(int new_x, int new_y, int new_w, int new_h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
static inline
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(8),
"b"(x_w),
"c"(y_h),
"d"(id),
"S"(color));
};
static inline
void draw_line(int xs, int ys, int xe, int ye, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((xs << 16) | xe),
"c"((ys << 16) | ye));
}
static inline
void draw_bar(int x, int y, int w, int h, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
static inline
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
static inline
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color)
:"memory");
}
/*
void define_button_text(int x, int y, int w, int h, uint32_t id, uint32_t color, char* text)
{
define_button(x * 65536 + w, y * 65536 + h, id, color);
int tx = ((((-strlen(text))*8)+w)/2)+x;
int ty = h/2-7+y;
draw_text_sys(text, tx, ty, strlen(text), 0x90000000);
};
*/
static inline
uint32_t get_skin_height(void)
{
uint32_t height;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(height)
:"a"(48),"b"(4));
return height;
};
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
__attribute__ ((alias ("sys_create_window")));
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
__attribute__ ((alias ("draw_line")));
static inline void DrawBar(int x, int y, int w, int h, color_t color)
__attribute__ ((alias ("draw_bar")));
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
__attribute__ ((alias ("draw_bitmap")));
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
#define POS_SCREEN 0
#define POS_WINDOW 1
static inline
pos_t get_mouse_pos(int origin)
{
pos_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(origin));
return val;
}
static inline
uint32_t get_mouse_buttons(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
static inline
uint32_t get_mouse_wheels(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
static inline uint32_t load_cursor(void *path, uint32_t flags)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
static inline uint32_t set_cursor(uint32_t cursor)
{
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=a"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
};
#define EVM_REDRAW 1
#define EVM_KEY 2
#define EVM_BUTTON 4
#define EVM_EXIT 8
#define EVM_BACKGROUND 16
#define EVM_MOUSE 32
#define EVM_IPC 64
#define EVM_STACK 128
#define EVM_DEBUG 256
#define EVM_STACK2 512
#define EVM_MOUSE_FILTER 0x80000000
#define EVM_CURSOR_FILTER 0x40000000
static inline uint32_t set_wanted_events_mask(uint32_t event_mask)
{
uint32_t old_event_mask;
__asm__ __volatile__(
"int $0x40"
:"=a"(old_event_mask)
:"a"(40),"b"(event_mask));
return old_event_mask;
};
static inline int destroy_cursor(uint32_t cursor)
{
int ret;
__asm__ __volatile__(
"int $0x40"
:"=a"(ret)
:"a"(37), "b"(6), "c"(cursor)
:"memory");
return ret;
};
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor")));
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
static inline
uint32_t wait_for_event(uint32_t time)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
static inline uint32_t check_os_event(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline uint32_t get_os_event(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
static inline
uint32_t get_tick_count(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(26),"b"(9));
return val;
};
static inline
uint64_t get_ns_count(void)
{
uint64_t val;
__asm__ __volatile__(
"int $0x40"
:"=A"(val)
:"a"(26), "b"(10));
return val;
};
static inline
oskey_t get_key(void)
{
oskey_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(2));
return val;
}
static inline
uint32_t get_os_button(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
static inline uint32_t
heap_init(void)
{
uint32_t heapsize;
__asm__ __volatile__(
"int $0x40"
:"=a"(heapsize)
:"a"(68),"b"(11)
);
return heapsize;
}
static inline uint32_t get_service(char *name)
{
uint32_t retval = 0;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(16),"c"(name)
:"memory");
return retval;
};
static inline int call_service(ioctl_t *io)
{
int retval;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(17),"c"(io)
:"memory","cc");
return retval;
};
static inline void yield(void)
{
__asm__ __volatile__(
"int $0x40"
::"a"(68), "b"(1));
};
static inline void delay(uint32_t time)
{
__asm__ __volatile__(
"int $0x40"
::"a"(5), "b"(time)
:"memory");
};
static inline
void *user_alloc(size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(12),"c"(size));
return val;
}
static inline
int user_free(void *mem)
{
int val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(13),"c"(mem));
return val;
}
static inline
void* user_realloc(void *mem, size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(20),"c"(size),"d"(mem)
:"memory");
return val;
};
static inline
int *user_unmap(void *base, size_t offset, size_t size)
{
int *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
return val;
};
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
typedef union
{
struct
{
void *data;
size_t size;
};
unsigned long long raw;
}ufile_t;
static inline ufile_t load_file(const char *path)
{
ufile_t uf;
__asm__ __volatile__ (
"int $0x40"
:"=A"(uf.raw)
:"a" (68), "b"(27),"c"(path));
return uf;
};
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
static inline int GetScreenSize(void)
{
int retval;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(61), "b"(1));
return retval;
}
static inline
pos_t max_screen_size()
{
pos_t size;
pos_t size_tmp;
__asm__ __volatile__(
"int $0x40"
:"=a"(size_tmp)
:"a"(14));
size.x = size_tmp.y;
size.y = size_tmp.x;
return size;
};
static inline void get_system_colors(struct kolibri_system_colors *color_table)
{
__asm__ volatile ("int $0x40"
:
:"a"(48),"b"(3),"c"(color_table),"d"(40)
);
}
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
int srcx;
int srcy;
int srcw;
int srch;
void *bitmap;
int stride;
};
static inline void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride)
{
volatile struct blit_call bc;
bc.dstx = dst_x;
bc.dsty = dst_y;
bc.w = w;
bc.h = h;
bc.srcx = src_x;
bc.srcy = src_y;
bc.srcw = src_w;
bc.srch = src_h;
bc.stride = stride;
bc.bitmap = bitmap;
__asm__ __volatile__(
"int $0x40"
::"a"(73),"b"(0),"c"(&bc.dstx));
};
#define TLS_KEY_PID 0
#define TLS_KEY_TID 4
#define TLS_KEY_LOW_STACK 8
#define TLS_KEY_HIGH_STACK 12
#define TLS_KEY_LIBC 16
unsigned int tls_alloc(void);
int tls_free(unsigned int key);
static inline int tls_set(unsigned int key, void *val)
{
int ret = -1;
if(key < 4096)
{
__asm__ __volatile__(
"movl %0, %%fs:(%1)"
::"r"(val),"r"(key));
ret = 0;
}
return ret;
};
static inline void *tls_get(unsigned int key)
{
void *val = (void*)-1;
if(key < 4096)
{
__asm__ __volatile__(
"movl %%fs:(%1), %0"
:"=r"(val)
:"r"(key));
};
return val;
}
int create_thread(int (*proc)(void *param), void *param, int stack_size);
void* load_library(const char *name);
void* get_proc_address(void *handle, const char *proc_name);
void enumerate_libraries(int (*callback)(void *handle, const char* name,
uint32_t base, uint32_t size, void *user_data),
void *user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,14 +0,0 @@
/* BSD predecessor of POSIX.1 <dirent.h> and struct dirent */
#ifndef _SYS_DIR_H_
#define _SYS_DIR_H_
#include <dirent.h>
#define direct dirent
extern int chdir(char* dir);
extern int rmdir(const char* dir);
extern int mkdir(const char* dir, unsigned fake_mode);
#endif /*_SYS_DIR_H_*/

View File

@@ -1,41 +0,0 @@
/* <dirent.h> includes <sys/dirent.h>, which is this file. On a
system which supports <dirent.h>, this file is overridden by
dirent.h in the libc/sys/.../sys directory. On a system which does
not support <dirent.h>, we will get this file which uses #error to force
an error. */
#ifdef __cplusplus
extern "C" {
#endif
#define DT_DIR 16
#define DT_REG 0
#include <limits.h>
#include <sys/types.h>
struct dirent{
ino_t d_ino;
unsigned d_type;
char d_name[256];
};
typedef struct{
struct dirent* objs;
ino_t pos;
ino_t num_objs;
}DIR;
extern int closedir(DIR *dir);
extern DIR* opendir(const char *path);
extern struct dirent* readdir(DIR *);
extern void rewinddir(DIR *dir);
extern void seekdir(DIR *dir, unsigned pos);
extern unsigned telldir(DIR *dir);
extern int scandir(const char *path, struct dirent ***res, int (*sel)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **));
extern int alphasort(const struct dirent **a, const struct dirent **b);
#ifdef __cplusplus
}
#endif

View File

@@ -1,417 +0,0 @@
/*
sys/kos.h
An attempt to create new C/C++ wrapper for syscalls
Based on kos32sys.h
KolibriOS Team
*/
#include <stdint.h>
#include <string.h>
/*********************** Types *************************/
typedef unsigned int color_t;
// struct for sysfn 70
#pragma pack(push,1)
typedef struct {
unsigned p00;
unsigned p04;
char *p08;
unsigned p12;
unsigned p16;
char p20;
char *p21;
} kos_Struct70;
#pragma pack(pop)
// struct for blitter
struct blit_call {
int dstx;
int dsty;
int w;
int h;
int srcx;
int srcy;
int srcw;
int srch;
void *bitmap;
int stride;
};
// struct for sysfn 9
#pragma pack(push, 1)
struct proc_info {
unsigned long cpu_usage;
unsigned short pos_in_stack;
unsigned short slot;
unsigned short reserved;
char name[12];
unsigned long address;
unsigned long memory_usage;
unsigned long ID;
unsigned long left,top;
unsigned long width,height;
unsigned short thread_state;
unsigned short reserved2;
unsigned long cleft, ctop, cwidth, cheight;
unsigned char window_state;
unsigned char reserved3[1024 - 71];
};
#pragma pack(pop)
// struct for sysfn 48
struct kolibri_system_colors {
color_t frame_area;
color_t grab_bar;
color_t grab_bar_button;
color_t grab_button_text;
color_t grab_text;
color_t work_area;
color_t work_button;
color_t work_button_text;
color_t work_text;
color_t work_graph;
};
typedef union __attribute__((packed)) {
uint32_t val;
struct {
short x;
short y;
};
} pos_t;
/*********************** Window Syscalls *************************/
static inline void kos_BeginDraw(void) {
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
static inline void kos_EndDraw(void) {
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
static inline void kos_DrawWindow(int x, int y, int w, int h, const char *title, color_t bgcolor, uint32_t style) {
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | ((w-1) & 0xFFFF)),
"c"((y << 16) | ((h-1) & 0xFFFF)),
"d"((style << 24) | (bgcolor & 0xFFFFFF)),
"D"(title),
"S"(0) : "memory");
};
#define ZPOS_DESKTOP -2
#define ZPOS_ALWAYS_BACK -1
#define ZPOS_NORMAL 0
#define ZPOS_ALWAYS_TOP 1
static inline void kos_SetWindowLayerBehaviour(int zpos) {
__asm__ __volatile__(
"int $0x40"
::"a"(18),
"b"(25),
"c"(2),
"d"(-1),
"S"(zpos) : "memory");
};
#define OLD -1
static inline void kos_ChangeWindow(int new_x, int new_y, int new_w, int new_h) {
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
/*********************** Other GUI functions *************************/
static inline void kos_DrawText(int x, int y, const char *text, color_t color) {
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(strlen(text)),"c"(color)
:"memory");
}
static inline void kos_DrawButton(int x, int y, int w, int h, int id, color_t color) {
__asm__ __volatile__(
"int $0x40"
::"a"(8),
"b"(x * 65536 + w),
"c"(y * 65536 + h),
"d"(id),
"S"(color));
};
static inline void kos_DrawButtonWithText(int x, int y, int w, int h, int id, color_t color, const char* text) {
kos_DrawButton(x, y, w, h, id, color);
int tx = ((((-strlen(text))*8)+w)/2)+x;
int ty = h/2-7+y;
kos_DrawText(tx, ty, text, 0x90000000);
};
static inline void kos_DrawLine(int x_start, int y_start, int x_end, int y_end, color_t color) {
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((x_start << 16) | x_end),
"c"((y_start << 16) | y_end));
}
static inline void kos_DrawBar(int x, int y, int w, int h, color_t color) {
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
static inline void kos_PutPixel(int x, int y, color_t color) {
__asm__ __volatile__("int $0x40"
::"a"(1),
"b"(x),
"c"(y),
"d"(color));
}
static inline void kos_DrawBitmap(void *bitmap, int x, int y, int w, int h) {
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
static inline void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride)
{
volatile struct blit_call bc;
bc.dstx = dst_x;
bc.dsty = dst_y;
bc.w = w;
bc.h = h;
bc.srcx = src_x;
bc.srcy = src_y;
bc.srcw = src_w;
bc.srch = src_h;
bc.stride = stride;
bc.bitmap = bitmap;
__asm__ __volatile__(
"int $0x40"
::"a"(73),"b"(0),"c"(&bc.dstx));
};
// Get screen part as image
static inline void kos_ScreenShot(char* image, int x, int y, int w, int h) {
__asm__ __volatile__(
"int $0x40"
::"a"(36),
"b"(image),
"c"(w*65536+h),
"d"(x*65536+y) : "memory");
};
/*********************** Skin *************************/
// Get skin height
static inline uint32_t kos_SkinHeight(void) {
uint32_t height;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(height)
:"a"(48),"b"(4));
return height;
};
/*********************** Mouse *************************/
#define POS_SCREEN 0
#define POS_WINDOW 1
static inline pos_t kos_GetMousePos(int origin) {
pos_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(origin));
return val;
}
static inline uint32_t kos_GetMouseButtons(void) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
static inline uint32_t kos_GetMouseWheels(void) {
uint32_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
static inline uint32_t kos_LoadCursor(void *path, uint32_t flags) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
static inline uint32_t kos_SetCursor(uint32_t cursor) {
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=a"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
};
static inline int kos_DestroyCursor(uint32_t cursor) {
int ret;
__asm__ __volatile__(
"int $0x40"
:"=a"(ret)
:"a"(37), "b"(6), "c"(cursor)
:"memory");
return ret;
};
/*********************** OS Events *************************/
#define evReDraw 1
#define evKey 2
#define evButton 3
#define evExit 4
#define evDesktop 5
#define evMouse 6
#define evIPC 7
#define evNetwork 8
#define evDebug 9
static inline uint32_t kos_WaitForEventTimeout(uint32_t time) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
static inline uint32_t kos_CheckForEvent(void) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline uint32_t kos_WaitForEvent(void) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
/*********************** Eventmask *************************/
#define EVM_REDRAW 1
#define EVM_KEY 2
#define EVM_BUTTON 4
#define EVM_EXIT 8
#define EVM_BACKGROUND 16
#define EVM_MOUSE 32
#define EVM_IPC 64
#define EVM_STACK 128
#define EVM_DEBUG 256
#define EVM_STACK2 512
#define EVM_MOUSE_FILTER 0x80000000
#define EVM_CURSOR_FILTER 0x40000000
static inline uint32_t kos_SetMaskForEvents(uint32_t event_mask) {
uint32_t old_event_mask;
__asm__ __volatile__(
"int $0x40"
:"=a"(old_event_mask)
:"a"(40),"b"(event_mask));
return old_event_mask;
};
/*********************** Other *************************/
static inline int kos_GetKey() {
unsigned short key;
__asm__ __volatile__("int $0x40":"=a"(key):"0"(2));
if(!(key & 0xFF)) return (key>>8)&0xFF; else return 0;
}
static inline uint32_t kos_GetButtonID(void) {
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
static inline void kos_Delay(uint32_t time) {
__asm__ __volatile__(
"int $0x40"
::"a"(5), "b"(time)
:"memory");
};
static inline pos_t kos_ScreenSize() {
pos_t size;
__asm__ __volatile__(
"int $0x40"
:"=a"(size)
:"a"(14));
return size;
};
static inline void kos_GetSystemColors(struct kolibri_system_colors *color_table) {
__asm__ __volatile__ ("int $0x40"
:
:"a"(48),"b"(3),"c"(color_table),"d"(40)
);
}
// sysfn 9
static inline void kos_ProcessInfo(char *info) {
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
static inline void kos_RunApp(char* app, char* param) {
kos_Struct70 r;
r.p00 = 7;
r.p04 = 0;
r.p08 = param;
r.p12 = 0;
r.p16 = 0;
r.p20 = 0;
r.p21 = app;
__asm__ __volatile__ ("int $0x40"::"a"(70), "b"(&r));
}

View File

@@ -1,147 +0,0 @@
// Console.obj loading for kos32-gcc
// Writed by rgimad and maxcodehack
//
// Usage:
// #include <sys/kos_LoadConsole.h>
// load_console();
//
#include <string.h>
#include <stdlib.h>
#ifndef CONSOLE_OBJ_H
#define CONSOLE_OBJ_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef cdecl
#define cdecl __attribute__ ((cdecl))
#endif
#ifndef stdcall
#define stdcall __attribute__ ((stdcall))
#endif
typedef unsigned int dword;
typedef unsigned short word;
const char* imports[] = {
"START", "version", "con_init", "con_write_asciiz", "con_write_string",
"con_printf", "con_exit", "con_get_flags", "con_set_flags", "con_kbhit",
"con_getch", "con_getch2", "con_gets", "con_gets2", "con_get_font_height",
"con_get_cursor_height", "con_set_cursor_height", "con_cls",
"con_get_cursor_pos", "con_set_cursor_pos", "con_set_title",
(char*)0
};
dword *version;
typedef int (stdcall * con_gets2_callback)(int keycode, char** pstr, int* pn,
int* ppos);
void stdcall (*con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title) = 0;
void stdcall (*con_exit)(int bCloseWindow) = 0;
void stdcall (*con_set_title)(const char* title) = 0;
void stdcall (*con_write_asciiz)(const char* str) = 0;
void stdcall (*con_write_string)(const char* str, dword length) = 0;
int cdecl (*con_printf)(const char* format, ...) = 0;
dword stdcall (*con_get_flags)(void) = 0;
dword stdcall (*con_set_flags)(dword new_flags) = 0;
int stdcall (*con_get_font_height)(void) = 0;
int stdcall (*con_get_cursor_height)(void) = 0;
int stdcall (*con_set_cursor_height)(int new_height) = 0;
int stdcall (*con_getch)(void) = 0;
word stdcall (*con_getch2)(void) = 0;
int stdcall (*con_kbhit)(void) = 0;
char* stdcall (*con_gets)(char* str, int n) = 0;
char* stdcall (*con_gets2)(con_gets2_callback callback, char* str, int n) = 0;
void stdcall (*con_cls)() = 0;
void stdcall (*con_get_cursor_pos)(int* px, int* py) = 0;
void stdcall (*con_set_cursor_pos)(int x, int y) = 0;
const char lib_path[] = "/sys/lib/console.obj";
void* load_library(const char *name)
{
void *table;
__asm__ __volatile__(
"int $0x40"
:"=a"(table)
:"a"(68), "b"(19), "c"(name));
return table;
}
void *load_library_procedure(void *exports, const char *name)
{
if (exports == NULL) { return 0; }
while (*(dword*)exports != 0)
{
char *str1 = (char*)(*(dword*)exports);
if (strcmp(str1, name) == 0)
{
void *ptr = (void*)*(dword*)(exports + 4);
return ptr;
}
exports += 8;
}
return 0;
}
void output_debug_string(const char *s)
{
unsigned int i = 0;
while(*(s + i))
{
__asm__ __volatile__ ("int $0x40"::"a"(63), "b"(1), "c"(*(s + i)));
i++;
}
}
void load_console()
{
void *lib = load_library(lib_path);
if (!lib)
{
output_debug_string("Console.obj loading error\r\n");
exit(1);
}
dword (*start_lib)(dword) = (dword(*)(dword))load_library_procedure(lib, imports[0]);
version = (dword*)load_library_procedure(lib, imports[1]);
con_init = (void stdcall(*)(dword,dword,dword,dword,const char*))load_library_procedure(lib, imports[2]);
con_write_asciiz = (void stdcall(*)(const char*))load_library_procedure(lib, imports[3]);
con_write_string = (void stdcall(*)(const char*,dword))load_library_procedure(lib, imports[4]);
con_printf = (int cdecl(*)(const char*,...))load_library_procedure(lib, imports[5]);
con_exit = (void stdcall(*)(int))load_library_procedure(lib, imports[6]);
con_get_flags = (dword stdcall(*)(void))load_library_procedure(lib, imports[7]);
con_set_flags = (dword stdcall(*)(dword))load_library_procedure(lib, imports[8]);
con_kbhit = (int stdcall(*)(void))load_library_procedure(lib, imports[9]);
con_getch = (int stdcall(*)(void))load_library_procedure(lib, imports[10]);
con_getch2 = (word stdcall(*)(void))load_library_procedure(lib, imports[11]);
con_gets = (char* stdcall(*)(char*,int))load_library_procedure(lib, imports[12]);
con_gets2 = (char* stdcall(*)(con_gets2_callback,char*,int))load_library_procedure(lib, imports[13]);
con_get_font_height = (int stdcall(*)(void))load_library_procedure(lib, imports[14]);
con_get_cursor_height = (int stdcall(*)(void))load_library_procedure(lib, imports[15]);
con_set_cursor_height = (int stdcall(*)(int))load_library_procedure(lib, imports[16]);
con_cls = (void stdcall(*)(void))load_library_procedure(lib, imports[17]);
con_get_cursor_pos = (void stdcall(*)(int*,int*))load_library_procedure(lib, imports[18]);
con_set_cursor_pos = (void stdcall(*)(int,int))load_library_procedure(lib, imports[19]);
con_set_title = (void stdcall(*)(const char*))load_library_procedure(lib, imports[20]);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,85 +0,0 @@
#ifndef __KOS_IO_H__
#define __KOS_IO_H__
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push, 1)
typedef struct
{
char sec;
char min;
char hour;
char rsv;
}detime_t;
typedef struct
{
char day;
char month;
short year;
}dedate_t;
typedef struct
{
unsigned attr;
unsigned flags;
union
{
detime_t ctime;
unsigned cr_time;
};
union
{
dedate_t cdate;
unsigned cr_date;
};
union
{
detime_t atime;
unsigned acc_time;
};
union
{
dedate_t adate;
unsigned acc_date;
};
union
{
detime_t mtime;
unsigned mod_time;
};
union
{
dedate_t mdate;
unsigned mod_date;
};
unsigned size;
unsigned size_high;
} fileinfo_t;
#pragma pack(pop)
int create_file(const char *path);
int get_fileinfo(const char *path, fileinfo_t *info);
int set_fileinfo(const char *path, fileinfo_t *info);
int read_file(const char *path, void *buff,
size_t offset, size_t count, size_t *reads);
int write_file(const char *path,const void *buff,
size_t offset, size_t count, size_t *writes);
int set_file_size(const char *path, unsigned size);
void unpack(void* packed_data, void* unpacked_data) __attribute__((stdcall)) ;
static inline void set_cwd(const char* cwd)
{
__asm__ __volatile__(
"int $0x40"
::"a"(30),"b"(1),"c"(cwd));
};
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -21,6 +21,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
@@ -82,43 +83,48 @@ typedef struct {
} ksys_ufile_t;
typedef struct {
uint32_t p00;
uint32_t func_num;
union {
uint64_t p04;
uint64_t offset64;
struct {
uint32_t p04dw;
uint32_t p08dw;
union {
uint32_t debug;
uint32_t offset;
};
union {
uint32_t flags;
char* args;
};
};
};
uint32_t p12;
uint32_t data_size;
void* data;
union {
uint32_t p16;
const char* new_name;
void* bdfe;
void* buf16;
const void* cbuf16;
struct {
uint8_t zero;
char* path_ptr;
};
char path[0];
};
char p20;
const char* p21;
} ksys70_t;
} ksys_file_t;
typedef struct {
uint32_t status;
uint32_t rw_bytes;
} ksys70_status_t;
} ksys_file_status_t;
typedef struct {
uint32_t attributes;
uint32_t name_cp;
ksys_time_t creation_time;
ksys_date_t creation_date;
ksys_time_t last_access_time;
ksys_date_t last_access_date;
ksys_time_t last_modification_time;
ksys_date_t last_modification_date;
uint32_t attr;
uint32_t name_enc;
ksys_time_t ctime;
ksys_date_t cdate;
ksys_time_t atime;
ksys_date_t adate;
ksys_time_t mtime;
ksys_date_t mdate;
uint64_t size;
char name[0];
} ksys_bdfe_t;
} ksys_file_info_t;
#define KSYS_THREAD_INFO_SIZE 1024
@@ -1483,125 +1489,166 @@ KOSAPI ksys_ufile_t _ksys_load_file_enc(const char* path, unsigned file_encoding
/*==== Function 70 - work with file system with long names support. ====*/
KOSAPI ksys70_status_t _ksys70(const ksys70_t* k)
enum KSYS_FILE_FUNC {
KSYS_FILE_READ = 0,
KSYS_FILE_READ_DIR,
KSYS_FILE_CREATE,
KSYS_FILE_WRITE,
KSYS_FILE_SET_SIZE,
KSYS_FILE_GET_INFO,
KSYS_FILE_SET_ATTR,
KSYS_FILE_EXEC,
KSYS_FILE_REMOVE,
KSYS_FILE_CREATE_DIR,
KSYS_FILE_RENAME,
};
KOSAPI ksys_file_status_t _ksys_file(const ksys_file_t* info)
{
ksys70_status_t status;
ksys_file_status_t st;
asm_inline(
"int $0x40"
: "=a"(status.status), "=b"(status.rw_bytes)
: "a"(70), "b"(k)
: "=a"(st.status), "=b"(st.rw_bytes)
: "a"(70), "b"(info)
: "memory");
return status;
return st;
}
/*====== Function 70, subfunction 0 - read file with long names support. ======*/
KOSAPI ksys70_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf)
KOSAPI ksys_file_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf)
{
ksys70_t k;
k.p00 = 0;
k.p04 = offset;
k.p12 = size;
k.buf16 = buf;
k.p20 = 0;
k.p21 = name;
return _ksys70(&k);
ksys_file_t f;
f.func_num = KSYS_FILE_READ;
f.offset64 = offset;
f.data_size = size;
f.data = buf;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f);
}
/*===================== Function 70, subfunction 2 =====================*/
/*============ Create/rewrite file with long names support. ============*/
KOSAPI int _ksys_file_create(const char* name)
KOSAPI ksys_file_status_t _ksys_file_create(const char* name)
{
ksys70_t k;
k.p00 = 2;
k.p04dw = 0;
k.p08dw = 0;
k.p12 = 0;
k.p21 = name;
return _ksys70(&k).status;
ksys_file_t f;
f.func_num = KSYS_FILE_CREATE;
f.offset64 = 0;
f.data_size = 0;
f.data = NULL;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f);
}
/*===================== Function 70, subfunction 3 =====================*/
/*=========== Write to existing file with long names support. ==========*/
KOSAPI ksys70_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf)
KOSAPI ksys_file_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf)
{
ksys70_t k;
k.p00 = 3;
k.p04 = offset;
k.p12 = size;
k.cbuf16 = buf;
k.p20 = 0;
k.p21 = name;
return _ksys70(&k);
ksys_file_t f;
f.func_num = KSYS_FILE_WRITE;
f.offset64 = offset;
f.data_size = size;
f.data = (void*)buf;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f);
}
/*========== Function 70, subfunction 4 - set file size. =====*/
KOSAPI int _ksys_file_set_size(const char* name, uint64_t size)
{
ksys_file_t f;
f.func_num = KSYS_FILE_SET_SIZE;
f.offset64 = size;
f.data_size = 0;
f.data = NULL;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f).status;
}
/*========== Function 70, subfunction 5 - get information on file/folder. =====*/
KOSAPI int _ksys_file_info(const char* name, ksys_bdfe_t* bdfe)
KOSAPI int _ksys_file_info(const char* name, ksys_file_info_t* info)
{
ksys70_t k;
k.p00 = 5;
k.p04dw = 0;
k.p08dw = 0;
k.p12 = 0;
k.bdfe = bdfe;
k.p20 = 0;
k.p21 = name;
return _ksys70(&k).status;
ksys_file_t f;
f.func_num = KSYS_FILE_GET_INFO;
f.offset64 = 0;
f.data_size = 0;
f.data = (void*)info;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f).status;
}
#define _ksys_dir_info _ksys_file_info
KOSAPI uint64_t _ksys_file_get_size(const char* name, int* err)
{
ksys_file_info_t info;
*err = _ksys_file_info(name, &info);
return info.size;
}
#define _ksys_dir_info _ksys_file_info
/*=========== Function 70, subfunction 7 - start application. ===========*/
KOSAPI int _ksys_exec(const char* app_name, char* args)
KOSAPI int _ksys_exec(const char* path, char* args, bool debug)
{
ksys70_t file_opt;
file_opt.p00 = 7;
file_opt.p04dw = 0;
file_opt.p08dw = (uint32_t)args;
file_opt.p12 = 0;
file_opt.p16 = 0;
file_opt.p20 = 0;
file_opt.p21 = app_name;
return _ksys70(&file_opt).status;
ksys_file_t f;
f.func_num = KSYS_FILE_EXEC;
f.debug = debug;
f.args = args;
f.zero = 0;
f.path_ptr = (char*)path;
return _ksys_file(&f).status;
}
/*========== Function 70, subfunction 8 - delete file/folder. ==========*/
KOSAPI int _ksys_file_delete(const char* name)
KOSAPI int _ksys_file_delete(const char* path)
{
ksys70_t k;
k.p00 = 8;
k.p20 = 0;
k.p21 = name;
return _ksys70(&k).status;
ksys_file_t f;
f.func_num = KSYS_FILE_REMOVE;
f.offset64 = 0;
f.data_size = 0;
f.data = NULL;
f.zero = 0;
f.path_ptr = (char*)path;
return _ksys_file(&f).status;
}
/*============= Function 70, subfunction 9 - create folder. =============*/
KOSAPI int _ksys_mkdir(const char* path)
{
ksys70_t dir_opt;
dir_opt.p00 = 9;
dir_opt.p21 = path;
return _ksys70(&dir_opt).status;
ksys_file_t f;
f.func_num = KSYS_FILE_CREATE_DIR;
f.offset64 = 0;
f.data_size = 0;
f.data = NULL;
f.zero = 0;
f.path_ptr = (char*)path;
return _ksys_file(&f).status;
}
/*============= Function 70, subfunction 10 - rename/move. =============*/
KOSAPI int _ksys_file_rename(const char* name, const char* new_name)
{
ksys70_t k;
k.p00 = 10;
k.new_name = new_name;
k.p20 = 0;
k.p21 = name;
return _ksys70(&k).status;
ksys_file_t f;
f.func_num = KSYS_FILE_REMOVE;
f.data = (void*)new_name;
f.data_size = 0;
f.zero = 0;
f.path_ptr = (char*)name;
return _ksys_file(&f).status;
}
#define _ksys_dir_rename _ksys_file_rename
@@ -1707,25 +1754,6 @@ KOSAPI int _ksys_posix_pipe2(int pipefd[2], int flags)
return err;
}
/* ######### Old names of functions and structures. Do not use again! ##########*/
#define _ksys_get_event _ksys_wait_event
#define _ksys_file_get_info _ksys_file_info
static inline int _ksys_file_read_file(const char* name, unsigned long long offset, unsigned size, void* buff, unsigned* bytes_read)
{
ksys70_status_t res = _ksys_file_read(name, offset, size, buff);
*bytes_read = res.rw_bytes;
return res.status;
}
static inline int _ksys_file_write_file(const char* name, unsigned long long offset, unsigned size, const void* buff, unsigned* bytes_write)
{
ksys70_status_t res = _ksys_file_write(name, offset, size, buff);
*bytes_write = res.rw_bytes;
return res.status;
}
#ifdef __cplusplus
}
#endif

View File

@@ -1,216 +0,0 @@
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include <stddef.h>
// Socket Types
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
// IP protocols
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_RAW 255
// IP options
#define IP_TTL 2
// Address families
#define AF_UNSPEC 0
#define AF_LOCAL 1
#define AF_INET 2 // Default INET=IPv4
#define AF_INET4 2 // IPv4
#define AF_INET6 10 // IPv6
#define PF_UNSPEC AF_UNSPEC
#define PF_LOCAL AF_LOCAL
#define PF_INET4 AF_INET4
#define PF_INET6 AF_INET6
// internal definition
#define AI_SUPPORTED 0x40F
// for system function 76
#define API_ETH (0<<16)
#define API_IPv4 (1<<16)
#define API_ICMP (2<<16)
#define API_UDP (3<<16)
#define API_TCP (4<<16)
#define API_ARP (5<<16)
#define API_PPPOE (6<<16)
// Socket flags for user calls
#define MSG_NOFLAG 0
#define MSG_PEEK 0x02
#define MSG_DONTWAIT 0x40
// Socket levels
#define SOL_SOCKET 0xffff
//Socket options
#define SO_BINDTODEVICE (1<<9)
#define SO_NONBLOCK (1<<31)
// Error Codes
#define ENOBUFS 1
#define EINPROGRESS 2
#define EOPNOTSUPP 4
#define EWOULDBLOCK 6
#define ENOTCONN 9
#define EALREADY 10
#define EINVALUE 11
#define EMSGSIZE 12
#define ENOMEM 18
#define EADDRINUSE 20
#define ECONNREFUSED 61
#define ECONNRESET 52
#define EISCONN 56
#define ETIMEDOUT 60
#define ECONNABORTED 53
#define PORT(X) (X<<8)
int err_code;
#pragma pack(push,1)
struct sockaddr{
unsigned short sin_family;
unsigned short sin_port;
unsigned int sin_addr;
unsigned long long sin_zero;
};
#pragma pack(pop)
#pragma pack(push,1)
typedef struct{
unsigned int level;
unsigned int optionname;
unsigned int optlenght;
unsigned char options;
}optstruct;
#pragma pack(pop)
static inline int socket(int domain, int type, int protocol)
{
int socket;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(socket)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
return socket;
}
static inline int close(int socket)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
return status;
}
static inline int bind(int socket, const struct sockaddr *addres, int addres_len)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
return status;
}
static inline int listen(int socket, int backlog)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
return status;
}
static inline int connect(int socket, const struct sockaddr* address, int socket_len)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
return status;
}
static inline int accept(int socket, const struct sockaddr *address, int address_len)
{
int new_socket;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(new_socket)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
return new_socket;
}
static inline int send(int socket, const void *message, size_t msg_len, int flag)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
return status;
}
static inline int recv(int socket, void *buffer, size_t buff_len, int flag)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
return status;
}
static inline int setsockopt(int socket,const optstruct* opt)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
return status;
}
static inline int getsockopt(int socket, optstruct* opt)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
return status;
}
static inline int socketpair(int *socket1, int *socket2)
{
asm volatile(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
err_code=*socket2;
return *socket1;
}
#endif

View File

@@ -10,6 +10,7 @@ extern "C" {
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/_timespec.h>
#include <sys/ksys.h>
/* dj's stat defines _STAT_H_ */
#ifndef _STAT_H_
@@ -147,11 +148,12 @@ struct stat
int _EXFUN(chmod,( const char *__path, mode_t __mode ));
int _EXFUN(fchmod,(int __fd, mode_t __mode));
int _EXFUN(fstat,( int __fd, struct stat *__sbuf ));
int _EXFUN(mkdir,( const char *_path, mode_t __mode ));
int _EXFUN(mkfifo,( const char *__path, mode_t __mode ));
int _EXFUN(stat,( const char *__restrict __path, struct stat *__restrict __sbuf ));
mode_t _EXFUN(umask,( mode_t __mask ));
#define mkdir(path, mode) _ksys_mkdir(path)
#if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(lstat,( const char *__restrict __path, struct stat *__restrict __buf ));
int _EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev ));

View File

@@ -1,522 +0,0 @@
EXPORTS
_Balloc
_Bfree
_Exit DATA
__assert
__assert_func
__ctype_ptr__ DATA
__emutls_get_address
__errno
__fpclassifyd
__fpclassifyf
__mutex_lock
__signbitd
__signbitf
__srget_r
__swbuf_r
_atoi_r
_atol_r
_buf_findstr
_calloc_r
_cleanup
_cleanup_r
_close_r
_ctype_ DATA
_daylight DATA
_diprintf_r
_dprintf_r
_dtoa_r
_exit DATA
_f_atan2 DATA
_f_atan2f DATA
_f_exp
_f_expf
_f_frexp DATA
_f_frexpf DATA
_f_ldexp DATA
_f_ldexpf DATA
_f_llrint
_f_llrintf
_f_llrintl
_f_log DATA
_f_log10 DATA
_f_log10f DATA
_f_logf DATA
_f_lrint
_f_lrintf
_f_lrintl
_f_pow
_f_powf
_f_rint
_f_rintf
_f_rintl
_f_tan DATA
_f_tanf DATA
_fclose_r
_fdopen_r
_fflush_r
_fgetc_r
_fgets_r
_findenv
_fiprintf_r
_fiscanf_r
_fopen_r
_fprintf_r
_fputc_r
_fputs_r
_fputwc_r
_fread_r
_free_r
_freopen_r
_fscanf_r
_fseek_r
_fseeko_r
_fstat_r
_ftell_r
_ftello_r
_fwalk
_fwalk_reent
_fwrite_r
_gettimeofday
_gettimeofday_r
_global_impure_ptr DATA
_grow_handles
_init_signal
_init_signal_r
_isatty
_isatty_r
_kill_r
_localeconv_r
_lseek_r
_malloc_r
_mbrtowc_r
_mbtowc_r
_mktm_r
_mprec_log10
_open_r
_printf_r
_putc_r
_putchar_r
_puts_r
_raise_r
_read
_read_r
_realloc_r
_remove_r
_rename_r
_seed48_r
_setlocale_r
_sfread_r
_signal_r
_siprintf_r
_sniprintf_r
_snprintf_r
_sprintf_r
_srand48_r
_sscanf_r
_strdup_r
_strerror_r
_strndup_r
_strtod_r
_strtol_r
_strtoll_r
_strtoul_r
_strtoull_r
_sungetc_r
_svfiprintf_r
_svfprintf_r
_system_r
_tempnam_r
_times_r
_timezone DATA
_tls_map DATA
_tmpfile_r
_tmpnam_r
_towctrans_r
_tzname DATA
_ungetc_r
_user_strerror
_vasniprintf_r
_vasnprintf_r
_vdiprintf_r
_vdprintf_r
_vfiprintf_r
_vfiscanf_r
_vfprintf_r
_vfscanf_r
_vscanf_r
_vsnprintf_r
_vsprintf_r
_vsscanf_r
_wcrtomb_r
_wctomb_r
_wctrans_r
_wctype_r
_write_r
abort
abs
acos
acosf
acosh
acoshf
asctime
asctime_r
asin
asinf
asinh
asinhf
atan
atan2
atan2f
atanf
atanh
atanhf
atexit
atof
atoi
atol
bsearch
calloc
cbrt
cbrtf
ceil
ceilf
clearerr
clock
close
copysign
copysignf
cos
cosf
cosh
coshf
create_file
create_image
create_thread
ctime
ctime_r
debugwrite
delete_file
difftime
diprintf
div
dprintf
drem
dremf
entry DATA
envz_get
erf
erfc
erfcf
erff
exit
exp
exp10
exp10f
exp2
exp2f
expf
expm1
expm1f
fabs
fabsf
fclose
fdim
fdimf
fdopen
fflush
fgetc
fgets
fileno
finite
finitef
fiprintf
fiscanf
floor
floorf
fma
fmaf
fmax
fmaxf
fmin
fminf
fmod
fmodf
fopen
fprintf
fputc
fputs
fputwc
fread
free
freopen
frexp
frexpf
fscanf
fseek
fseeko
fstat
ftell
ftello
fwrite
gamma
gamma_r
gammaf
gammaf_r
get_entry_point
get_fileinfo
get_proc_address
getenv
gettimeofday
gmtime
gmtime_r
hypot
hypotf
ilogb
ilogbf
infinity
infinityf
init_global_reent
init_loader
init_reent
isalnum
isalpha
isascii
isblank
iscntrl
isdigit
isgraph
isinf
isinff
islower
isnan
isnanf
isprint
ispunct
isspace
isupper
iswalnum
iswalpha
iswblank
iswcntrl
iswctype
iswdigit
iswgraph
iswlower
iswprint
iswpunct
iswspace
iswupper
iswxdigit
isxdigit
j0
j0f
j1
j1f
jn
jnf
ldexp
ldexpf
lgamma
lgamma_r
lgammaf
lgammaf_r
libc_crt_startup
link_app
link_image
llrint
llrintf
llrintl
llround
llroundf
load_library
loader_env DATA
localeconv
localtime
localtime_r
log
log10
log10f
log1p
log1pf
log2
log2f
logb
logbf
logf
longjmp
lrint
lrintf
lrintl
lround
lroundf
lseek
malloc
matherr
mbrtowc
mbtowc
memalign
memchr
memcmp
memcpy
memmove
memset
mktime
modf
modff
nan
nanf
nearbyint
nearbyintf
nextafter
nextafterf
open
path_list DATA
pow
pow10
pow10f
powf
printf
putc
putchar
puts
qsort
raise
rand
rand_r
read
read_file
realloc
remainder
remainderf
remove
remquo
remquof
rename
rint
rintf
rintl
round
roundf
scalb
scalbf
scalbln
scalblnf
scalbn
scalbnf
seed48
set_file_size
setjmp
setlocale
setvbuf
signal
significand
significandf
sin
sincos
sincosf
sinf
sinh
sinhf
siprintf
sniprintf
snprintf
sprintf
sqrt
sqrtf
srand
srand48
sscanf
stpcpy
stpncpy
strcasecmp
strcasestr
strcat
strchr
strcmp
strcoll
strcpy
strcspn
strdup
strerror
strftime
strlen
strncasecmp
strncat
strncmp
strncpy
strndup
strnlen
strpbrk
strrchr
strsep
strspn
strstr
strtod
strtof
strtok
strtok_r
strtol
strtoll
strtoul
strtoull
strupr
system
tan
tanf
tanh
tanhf
tempnam
tgamma
tgammaf
time
tls_alloc DATA
tmpfile
tmpnam
toascii
tolower
toupper
towctrans
towlower
towupper
trunc
truncf
ungetc
user_alloc
validate_pe
vasniprintf
vasnprintf
vdiprintf
vdprintf
vfiprintf
vfiscanf
vfprintf
vfscanf
vscanf
vsnprintf
vsprintf
vsscanf
wcrtomb
wctrans
wctype
write
write_file
y0
y0f
y1
y1f
yn
ynf
alphasort
opendir
closedir
readdir
rewinddir
seekdir
telldir
scandir
mkdir
rmdir
chdir
dirname
getcwd

View File

@@ -1,509 +0,0 @@
EXPORTS
_Balloc @1
_Bfree @2
_Exit @3 DATA
__assert @4
__assert_func @5
__ctype_ptr__ @6 DATA
__emutls_get_address @7
__errno @8
__fpclassifyd @9
__fpclassifyf @10
__mutex_lock @11
__signbitd @12
__signbitf @13
__srget_r @14
__swbuf_r @15
_atoi_r @16
_atol_r @17
_buf_findstr @18
_calloc_r @19
_cleanup @20
_cleanup_r @21
_close_r @22
_ctype_ @23 DATA
_daylight @24 DATA
_diprintf_r @25
_dprintf_r @26
_dtoa_r @27
_exit @28 DATA
_f_atan2 @29 DATA
_f_atan2f @30 DATA
_f_exp @31
_f_expf @32
_f_frexp @33 DATA
_f_frexpf @34 DATA
_f_ldexp @35 DATA
_f_ldexpf @36 DATA
_f_llrint @37
_f_llrintf @38
_f_llrintl @39
_f_log @40 DATA
_f_log10 @41 DATA
_f_log10f @42 DATA
_f_logf @43 DATA
_f_lrint @44
_f_lrintf @45
_f_lrintl @46
_f_pow @47
_f_powf @48
_f_rint @49
_f_rintf @50
_f_rintl @51
_f_tan @52 DATA
_f_tanf @53 DATA
_fclose_r @54
_fdopen_r @55
_fflush_r @56
_fgetc_r @57
_fgets_r @58
_findenv @59
_fiprintf_r @60
_fiscanf_r @61
_fopen_r @62
_fprintf_r @63
_fputc_r @64
_fputs_r @65
_fputwc_r @66
_fread_r @67
_free_r @68
_freopen_r @69
_fscanf_r @70
_fseek_r @71
_fseeko_r @72
_fstat_r @73
_ftell_r @74
_ftello_r @75
_fwalk @76
_fwalk_reent @77
_fwrite_r @78
_gettimeofday @79
_gettimeofday_r @80
_global_impure_ptr @81 DATA
_grow_handles @82
_init_signal @83
_init_signal_r @84
_isatty @85
_isatty_r @86
_kill_r @87
_localeconv_r @88
_lseek_r @89
_malloc_r @90
_mbrtowc_r @91
_mbtowc_r @92
_mktm_r @93
_mprec_log10 @94
_open_r @95
_printf_r @96
_putc_r @97
_putchar_r @98
_puts_r @99
_raise_r @100
_read @101
_read_r @102
_realloc_r @103
_remove_r @104
_rename_r @105
_seed48_r @106
_setlocale_r @107
_sfread_r @108
_signal_r @109
_siprintf_r @110
_sniprintf_r @111
_snprintf_r @112
_sprintf_r @113
_srand48_r @114
_sscanf_r @115
_strdup_r @116
_strerror_r @117
_strndup_r @118
_strtod_r @119
_strtol_r @120
_strtoll_r @121
_strtoul_r @122
_strtoull_r @123
_sungetc_r @124
_svfiprintf_r @125
_svfprintf_r @126
_system_r @127
_tempnam_r @128
_times_r @129
_timezone @130 DATA
_tls_map @131 DATA
_tmpfile_r @132
_tmpnam_r @133
_towctrans_r @134
_tzname @135 DATA
_ungetc_r @136
_user_strerror @137
_vasniprintf_r @138
_vasnprintf_r @139
_vdiprintf_r @140
_vdprintf_r @141
_vfiprintf_r @142
_vfiscanf_r @143
_vfprintf_r @144
_vfscanf_r @145
_vscanf_r @146
_vsnprintf_r @147
_vsprintf_r @148
_vsscanf_r @149
_wcrtomb_r @150
_wctomb_r @151
_wctrans_r @152
_wctype_r @153
_write_r @154
abort @155
abs @156
acos @157
acosf @158
acosh @159
acoshf @160
asctime @161
asctime_r @162
asin @163
asinf @164
asinh @165
asinhf @166
atan @167
atan2 @168
atan2f @169
atanf @170
atanh @171
atanhf @172
atexit @173
atof @174
atoi @175
atol @176
bsearch @177
calloc @178
cbrt @179
cbrtf @180
ceil @181
ceilf @182
clearerr @183
clock @184
close @185
copysign @186
copysignf @187
cos @188
cosf @189
cosh @190
coshf @191
create_file @192
create_image @193
create_thread @194
ctime @195
ctime_r @196
debugwrite @197
delete_file @198
difftime @199
diprintf @200
div @201
dprintf @202
drem @203
dremf @204
entry @205 DATA
envz_get @206
erf @207
erfc @208
erfcf @209
erff @210
exit @211
exp @212
exp10 @213
exp10f @214
exp2 @215
exp2f @216
expf @217
expm1 @218
expm1f @219
fabs @220
fabsf @221
fclose @222
fdim @223
fdimf @224
fdopen @225
fflush @226
fgetc @227
fgets @228
fileno @229
finite @230
finitef @231
fiprintf @232
fiscanf @233
floor @234
floorf @235
fma @236
fmaf @237
fmax @238
fmaxf @239
fmin @240
fminf @241
fmod @242
fmodf @243
fopen @244
fprintf @245
fputc @246
fputs @247
fputwc @248
fread @249
free @250
freopen @251
frexp @252
frexpf @253
fscanf @254
fseek @255
fseeko @256
fstat @257
ftell @258
ftello @259
fwrite @260
gamma @261
gamma_r @262
gammaf @263
gammaf_r @264
get_entry_point @265
get_fileinfo @266
get_proc_address @267
getenv @268
gettimeofday @269
gmtime @270
gmtime_r @271
hypot @272
hypotf @273
ilogb @274
ilogbf @275
infinity @276
infinityf @277
init_global_reent @278
init_loader @279
init_reent @280
isalnum @281
isalpha @282
isascii @283
isblank @284
iscntrl @285
isdigit @286
isgraph @287
isinf @288
isinff @289
islower @290
isnan @291
isnanf @292
isprint @293
ispunct @294
isspace @295
isupper @296
iswalnum @297
iswalpha @298
iswblank @299
iswcntrl @300
iswctype @301
iswdigit @302
iswgraph @303
iswlower @304
iswprint @305
iswpunct @306
iswspace @307
iswupper @308
iswxdigit @309
isxdigit @310
j0 @311
j0f @312
j1 @313
j1f @314
jn @315
jnf @316
ldexp @317
ldexpf @318
lgamma @319
lgamma_r @320
lgammaf @321
lgammaf_r @322
libc_crt_startup @323
link_app @324
link_image @325
llrint @326
llrintf @327
llrintl @328
llround @329
llroundf @330
load_library @331
loader_env @332 DATA
localeconv @333
localtime @334
localtime_r @335
log @336
log10 @337
log10f @338
log1p @339
log1pf @340
log2 @341
log2f @342
logb @343
logbf @344
logf @345
longjmp @346
lrint @347
lrintf @348
lrintl @349
lround @350
lroundf @351
lseek @352
malloc @353
matherr @354
mbrtowc @355
mbtowc @356
memalign @357
memchr @358
memcmp @359
memcpy @360
memmove @361
memset @362
mktime @363
modf @364
modff @365
nan @366
nanf @367
nearbyint @368
nearbyintf @369
nextafter @370
nextafterf @371
open @372
path_list @373 DATA
pow @374
pow10 @375
pow10f @376
powf @377
printf @378
putc @379
putchar @380
puts @381
qsort @382
raise @383
rand @384
rand_r @385
read @386
read_file @387
realloc @388
remainder @389
remainderf @390
remove @391
remquo @392
remquof @393
rename @394
rint @395
rintf @396
rintl @397
round @398
roundf @399
scalb @400
scalbf @401
scalbln @402
scalblnf @403
scalbn @404
scalbnf @405
seed48 @406
set_file_size @407
setjmp @408
setlocale @409
setvbuf @410
signal @411
significand @412
significandf @413
sin @414
sincos @415
sincosf @416
sinf @417
sinh @418
sinhf @419
siprintf @420
sniprintf @421
snprintf @422
sprintf @423
sqrt @424
sqrtf @425
srand @426
srand48 @427
sscanf @428
stpcpy @429
stpncpy @430
strcasecmp @431
strcasestr @432
strcat @433
strchr @434
strcmp @435
strcoll @436
strcpy @437
strcspn @438
strdup @439
strerror @440
strftime @441
strlen @442
strncasecmp @443
strncat @444
strncmp @445
strncpy @446
strndup @447
strnlen @448
strpbrk @449
strrchr @450
strsep @451
strspn @452
strstr @453
strtod @454
strtof @455
strtok @456
strtok_r @457
strtol @458
strtoll @459
strtoul @460
strtoull @461
strupr @462
system @463
tan @464
tanf @465
tanh @466
tanhf @467
tempnam @468
tgamma @469
tgammaf @470
time @471
tls_alloc @472 DATA
tmpfile @473
tmpnam @474
toascii @475
tolower @476
toupper @477
towctrans @478
towlower @479
towupper @480
trunc @481
truncf @482
ungetc @483
user_alloc @484
validate_pe @485
vasniprintf @486
vasnprintf @487
vdiprintf @488
vdprintf @489
vfiprintf @490
vfiscanf @491
vfprintf @492
vfscanf @493
vscanf @494
vsnprintf @495
vsprintf @496
vsscanf @497
wcrtomb @498
wctrans @499
wctype @500
write @501
write_file @502
y0 @503
y0f @504
y1 @505
y1f @506
yn @507
ynf @508

View File

@@ -355,7 +355,6 @@ import libc,\
_cosf,'cosf',\
_cosh,'cosh',\
_coshf,'coshf',\
_create_file,'create_file',\
_create_image,'create_image',\
_create_thread,'create_thread',\
_ctime,'ctime',\
@@ -429,7 +428,6 @@ import libc,\
_gammaf,'gammaf',\
_gammaf_r,'gammaf_r',\
_get_entry_point,'get_entry_point',\
_get_fileinfo,'get_fileinfo',\
_get_proc_address,'get_proc_address',\
_getenv,'getenv',\
_gettimeofday,'gettimeofday',\
@@ -550,7 +548,6 @@ import libc,\
_rand,'rand',\
_rand_r,'rand_r',\
_read,'read',\
_read_file,'read_file',\
_realloc,'realloc',\
_remainder,'remainder',\
_remainderf,'remainderf',\
@@ -570,7 +567,6 @@ import libc,\
_scalbn,'scalbn',\
_scalbnf,'scalbnf',\
_seed48,'seed48',\
_set_file_size,'set_file_size',\
_setjmp,'setjmp',\
_setlocale,'setlocale',\
_setvbuf,'setvbuf',\
@@ -665,7 +661,6 @@ import libc,\
_wctrans,'wctrans',\
_wctype,'wctype',\
_write,'write',\
_write_file,'write_file',\
_y0,'y0',\
_y0f,'y0f',\
_y1,'y1',\

View File

@@ -0,0 +1,11 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <sys/ksys.h>
int chdir(char* dir){
_ksys_setcwd(dir);
return 0;
}

View File

@@ -15,7 +15,7 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
#include "glue.h"
#include "io.h"

View File

@@ -1,3 +1,8 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <_ansi.h>
#include <stdio.h>
#include <sys/unistd.h>
@@ -16,28 +21,8 @@ static int console_read(const char *path, void *buff,
size_t offset, size_t count, size_t *done)
{
char *p = buff;
/*int cnt = 0;
short c;
char ch;*/
con_gets(p, count+1);
*done = strlen(p);
// __asm__ volatile("int3");
/*
do
{
c = con_getch2();
printf("%d\n",(char)c);
ch = (char)c;
if(ch != 0)
{
p[cnt] = ch != 0x0D ? ch : 0x0A;
con_write_string(p+cnt, 1);
cnt++;
}
}while(ch != 0x0D);
*done = cnt;
*/
return 0;
}
@@ -48,7 +33,7 @@ static int console_write(const char *path, const void *buff,
*writes = count;
return 0;
};
}
void __init_conio()
{

View File

@@ -1,25 +0,0 @@
#include <sys/types.h>
#include <sys/kos_io.h>
int create_file(const char *path)
{
int retval;
__asm__ __volatile__ (
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %1, 1(%%esp) \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $2 \n\t"
"movl %%esp, %%ebx \n\t"
"movl $70, %%eax \n\t"
"int $0x40 \n\t"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"r" (path)
:"ebx");
return retval;
};

View File

@@ -1,48 +0,0 @@
#include <sys/types.h>
#include <sys/kos_io.h>
int get_fileinfo(const char *path, fileinfo_t *info)
{
int retval;
__asm__ __volatile__ (
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %1, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $5 \n\t"
"movl %%esp, %%ebx \n\t"
"movl $70, %%eax \n\t"
"int $0x40 \n\t"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"r" (path), "b" (info));
return retval;
};
int set_fileinfo(const char *path, fileinfo_t *info)
{
int retval;
__asm__ __volatile__ (
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %1, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $6 \n\t"
"movl %%esp, %%ebx \n\t"
"movl $70, %%eax \n\t"
"int $0x40 \n\t"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"r" (path), "b" (info));
return retval;
};

View File

@@ -1,26 +0,0 @@
#include <sys/types.h>
#include <sys/kos_io.h>
int set_file_size(const char *path, unsigned size)
{
int retval;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl $0 \n\t"
"pushl %%ebx \n\t"
"push $4 \n\t"
"movl %%esp, %%ebx \n\t"
"movl $70, %%eax \n\t"
"int $0x40 \n\t"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a" (path), "b" (size));
return retval;
};

View File

@@ -15,7 +15,7 @@
#include <errno.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
#include <sys/stat.h>
#include "glue.h"
#include "io.h"
@@ -25,7 +25,7 @@ _DEFUN (fstat, (fd, buf),
int fd _AND
struct stat *buf)
{
fileinfo_t info;
ksys_file_info_t info;
struct tm time;
__io_handle *ioh;
@@ -33,8 +33,8 @@ _DEFUN (fstat, (fd, buf),
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return (-1);
};
return -1;
}
memset (buf, 0, sizeof (* buf));
@@ -47,7 +47,7 @@ _DEFUN (fstat, (fd, buf),
{
ioh = &__io_tab[fd];
get_fileinfo(ioh->name, &info);
_ksys_file_info(ioh->name, &info);
if (info.attr & 0x10)
buf->st_mode = S_IFDIR;

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <stdlib.h>
#include <sys/ksys.h>
char *getcwd(char *buf, unsigned size){
if(!buf){
if((buf = malloc(size))==NULL){
return NULL;
}
}
_ksys_getcwd(buf, size);
return(buf);
}

View File

@@ -1,31 +1,15 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <sys/types.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
int read_file(const char *path, void *buff,
size_t offset, size_t count, size_t *reads)
{
int retval;
int d0;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $0 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads));
return retval == 6 ? 0 : retval;
};
ksys_file_status_t st = _ksys_file_read(path, offset, count, buff);
*reads = st.rw_bytes;
return st.status == KSYS_FS_ERR_EOF ? 0 : st.status;
}

View File

@@ -1,33 +1,20 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <sys/types.h>
#include <errno.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
int write_file(const char *path,const void *buff,
int write_file(const char *path, const void *buff,
size_t offset, size_t count, size_t *writes)
{
int retval;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $3 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes));
if(retval == 0)
ksys_file_status_t st = _ksys_file_write(path, offset, count, buff);
*writes = st.rw_bytes;
if(!st.status)
return 0;
else if (retval == 8)
else if (st.status == KSYS_FS_ERR_8)
return ENOSPC;
return -1;
};
}

View File

@@ -1,28 +1,30 @@
/*
* Copyright (C) KolibriOS team 2004-2024. All rights reserved.
* Distributed under terms of the GNU General Public License
*/
#include <errno.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
#include "glue.h"
#include "io.h"
_off_t
_DEFUN (lseek, (fd, pos, whence),
int fd _AND
_off_t pos _AND
int whence)
{
fileinfo_t info;
ksys_file_info_t info;
__io_handle *ioh;
_off_t ret;
if( (fd < 0) || (fd >=64) )
if ((fd < 0) || (fd >=64))
{
errno = EBADF;
return (-1);
};
}
ioh = &__io_tab[fd];
@@ -36,16 +38,16 @@ _DEFUN (lseek, (fd, pos, whence),
break;
case SEEK_END:
{
get_fileinfo(ioh->name, &info);
_ksys_file_info(ioh->name, &info);
ret = pos + info.size;
break;
}
default:
errno = EINVAL;
return (-1);
};
return -1;
}
ioh->offset = ret;
return( ret );
};
return ret;
}

View File

@@ -15,13 +15,20 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
#include "glue.h"
#include "io.h"
#undef erro
#undef errno
extern int errno;
extern int write_file(const char *path,const void *buff,
size_t offset, size_t count, size_t *writes);
extern int read_file(const char *path, void *buff,
size_t offset, size_t count, size_t *reads);
static inline int is_slash(char c)
{
return c=='/' || c=='\\';
@@ -49,7 +56,7 @@ void fix_slashes(char * in,char * out)
}
}
*out='\0';
};
}
void buildpath(char *buf, const char* file)
@@ -89,26 +96,14 @@ __do_until_slash:
*ptr++ = *file++;
}
*ptr = 0;
};
static char *getccwd(char *buf, size_t size)
{
int bsize;
__asm__ __volatile__(
"int $0x40"
:"=a"(bsize)
:"a"(30),"b"(2),"c"(buf), "d"(size)
:"memory");
return buf;
};
}
int open (const char * filename, int flags, ...)
{
char buf[1024];
__io_handle *ioh;
fileinfo_t info;
ksys_file_info_t info;
int iomode, rwmode, offset;
int hid;
int err;
@@ -127,28 +122,28 @@ int open (const char * filename, int flags, ...)
}
else
{
getccwd(buf, 1024);
_ksys_getcwd(buf, 1024);
buildpath(buf, filename);
}
err = get_fileinfo(buf, &info);
err = _ksys_file_info(buf, &info);
if( flags & O_EXCL &&
if (flags & O_EXCL &&
flags & O_CREAT )
{
if( !err )
if (!err)
{
errno = EEXIST;
__io_free(hid);
return (-1);
};
}
}
if( err )
if (err)
{
if(flags & O_CREAT)
err=create_file(buf);
if( err )
err = _ksys_file_create(buf).status;
if(err)
{
errno = EACCES;
__io_free(hid);
@@ -156,8 +151,8 @@ int open (const char * filename, int flags, ...)
};
};
if( flags & O_TRUNC )
set_file_size(buf, 0);
if (flags & O_TRUNC)
_ksys_file_set_size(buf, 0);
ioh = &__io_tab[hid];
@@ -166,25 +161,28 @@ int open (const char * filename, int flags, ...)
iomode = 0;
offset = 0;
if( rwmode == O_RDWR )
if (rwmode == O_RDWR)
iomode |= _READ | _WRITE;
else if( rwmode == O_RDONLY)
else if (rwmode == O_RDONLY)
iomode |= _READ;
else if( rwmode == O_WRONLY)
else if (rwmode == O_WRONLY)
iomode |= _WRITE;
if( flags & O_APPEND )
if (flags & O_APPEND)
{
iomode |= _APPEND;
offset = info.size;
};
}
if( flags & (O_BINARY|O_TEXT) )
if (flags & (O_BINARY|O_TEXT))
{
if( flags & O_BINARY )
if (flags & O_BINARY)
iomode |= _BINARY;
} else
}
else
{
iomode |= _BINARY;
}
ioh->name = strdup(buf);
ioh->offset = offset;
@@ -193,6 +191,4 @@ int open (const char * filename, int flags, ...)
ioh->write = write_file;
return hid;
};
}

View File

@@ -29,7 +29,7 @@ ssize_t read(int fd, void *buf, size_t cnt)
char *buffer = buf;
int rc;
int h;
unsigned amount_read;
size_t amount_read;
int err;
__io_handle *ioh;

View File

@@ -13,7 +13,7 @@
* they apply.
*/
#include <sys/stat.h>
#include <sys/kos_io.h>
#include <sys/ksys.h>
#include <errno.h>
#include <time.h>
#include <string.h>
@@ -28,16 +28,16 @@ _DEFUN (stat, (path, buf),
struct stat *buf)
{
fileinfo_t info;
ksys_file_info_t info;
struct tm time;
if( get_fileinfo(path, &info))
if (_ksys_file_info(path, &info))
{
errno = ENOENT;
return (-1);
};
}
memset (buf, 0, sizeof (* buf));
memset(buf, 0, sizeof (*buf));
buf->st_size = info.size;
@@ -91,4 +91,3 @@ _DEFUN (lstat, (path, buf),
{
return stat(path, buf);
}

View File

@@ -15,7 +15,6 @@
#include <errno.h>
#include <unistd.h>
#include <alloca.h>
#include <sys/kos_io.h>
#include "io.h"
#undef erro