fix libck

git-svn-id: svn://kolibrios.org@7172 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
siemargl 2018-03-05 17:53:31 +00:00
parent df2b9b2d5a
commit b7fe2ec210
18 changed files with 782 additions and 185 deletions

View File

@ -0,0 +1,292 @@
; KolibriOS system functions:
+SF_TERMINATE_PROCESS=-1 // kos_exit()
+SF_CREATE_WINDOW=0 ; define and draw the window //sys_create_window()
SF_PUT_PIXEL=1 ; draw pixel to the window
+SF_GET_KEY=2 ; get code of the pressed key
SF_GET_SYS_TIME=3
+SF_DRAW_TEXT=4 //draw_text_sys()
+SF_SLEEP=5 ; pause process // delay()
+SF_PUT_IMAGE=7 ; draw image to the window //draw_bitmap()
+SF_DEFINE_BUTTON=8 ; define/delete the button
+SF_THREAD_INFO=9 ; information on execution thread // get_proc_info()
+SF_WAIT_EVENT=10 ; wait for event // get_os_event()
+SF_CHECK_EVENT=11 ; check for event and return // check_os_event()
SF_REDRAW=12
+ SSF_BEGIN_DRAW=1
+ SSF_END_DRAW=2
+SF_DRAW_RECT=13 ; draw rectangle to the window // draw_bar()
SF_GET_SCREEN_SIZE=14 ; get screen resolution
SF_BACKGROUND_SET=15
SSF_SIZE_BG=1
SSF_PIXEL_BG=2
SSF_REDRAW_BG=3
SSF_MODE_BG=4
SSF_IMAGE_BG=5
SSF_MAP_BG=6 ; map background image to the address space of the process
SSF_UNMAP_BG=7
SSF_LAST_DRAW=8 ; get coordinates of the last draw to the background
SSF_REDRAW_RECT=9 ; redraws a rectangular part of the background
SF_RD_TO_FLOPPY=16 ; save ramdisk on the floppy
+SF_GET_BUTTON=17 ; get ID of the pressed button // get_os_button()
SF_SYSTEM=18
SSF_UNFOCUS_WINDOW=1 ; take focus from the window of the given thread
SSF_TERMINATE_THREAD=2 ; terminate process/thread by the slot number
+ SSF_FOCUS_WINDOW=3 ; give focus to the window of the given thread
SSF_GET_IDLE_COUNT=4 ; get counter of idle cycles per second
SSF_GET_CPU_REQUENCY=5 ; get CPU clock rate
SSF_RD_TO_HDD=6 ; save ramdisk to the file on hard disk
SSF_GET_ACTIVE_WINDOW=7 ; get slot number of the active window
SSF_SPEAKER=8
SSSF_GET_STATE=1
SSSF_TOGGLE=2
SSF_SHUTDOWN=9 ; system shutdown/reboot
SSF_MINIMIZE_WINDOW=10 ; minimize active window
SSF_INFO_DISC_SYS=11 ; get disk subsystem information
SSF_KERNEL_VERSION=13 ; get kernel version
SSF_WAIT_RETRACE=14 ; wait for screen retrace
SSF_CURSOR_CENTER=15 ; center mouse cursor on the screen
SSF_GET_FREE_RAM=16 ; get size of free RAM
SSF_GET_TOTAL_RAM=17 ; get total amount of RAM
SSF_TERMINATE_THREAD_ID=18 ; Terminate process/thread by the ID
SSF_MOUSE_SETTINGS=19
SSSF_GET_SPEED=0
SSSF_SET_SPEED=1
SSSF_GET_SPEEDUP=2
SSSF_SET_SPEEDUP=3 ; set mouse acceleration
SSSF_SET_POS=4 ; set mouse pointer position
SSSF_SET_BUTTON=5 ; simulate state of mouse buttons
SSSF_GET_DOUBLE_CLICK_DELAY=6
SSSF_SET_DOUBLE_CLICK_DELAY=7
SSF_GET_RAM_INFO=20 ; get information on RAM
+ SSF_GET_THREAD_SLOT=21 ; get slot number of process/thread by the ID
SSF_FOREIGN_WINDOW=22 ; operations with window of another thread by slot/ID
SSSF_MINIMIZE=0
SSSF_MINIMIZE_ID=1
SSSF_RESTORE=2
SSSF_RESTORE_ID=3
SSF_MINIMIZE_ALL=23
SSF_SET_SCREEN_LIMITS=24
SSF_WINDOW_BEHAVIOR=25 ; window focus relation with other windows
SSSF_GET_WB=1
SSSF_SET_WB=2
SF_MIDI=20
SSF_RESET=1
SSF_OUTPUT=2
SF_SYSTEM_SET=21
SSF_MPU_MIDI_BASE=1
SSF_KEYBOARD_LAYOUT=2
SSF_SYS_LANG=5
SSF_ACCESS_HD_LBA=11 ; setting of low-level access to HD
SSF_ACCESS_PCI=12 ; setting of low-level access to PCI
SF_SET_TIME_DATE=22
+SF_WAIT_EVENT_TIMEOUT=23; wait for event with timeout // wait_for_event()
SF_CD=24
SSF_EJECT_TRAY=4
SSF_INSERT_TRAY=5
SF_SCREEN_PUT_IMAGE=25 ; put image on the background layer
SF_SYSTEM_GET=26
; Same as SF_SYSTEM_SET, plus:
+ SSF_TIME_COUNT=9 // get_tick_count()
+ SSF_TIME_COUNT_PRO=10 ; get value of the high precision time counter // get_ns_count()
SF_GET_SYS_DATE=29
SF_CURRENT_FOLDER=30
+ SSF_SET_CF=1 ; set current folder for the thread // set_current_folder()
+ SSF_GET_CF=2 // get_current_folder()
SSF_ADD_SYS_FOLDER=3 ; install the add.system directory for the kernel
SF_GET_PIXEL_OWNER=34 ; get slot number of the screen pixel owner
SF_GET_PIXEL=35 ; read the screen pixel color
SF_GET_IMAGE=36 ; read the screen area
SF_MOUSE_GET=37
+ SSF_SCREEN_POSITION=0 // get_mouse_pos(POS_SCREEN)
+ SSF_WINDOW_POSITION=1 // get_mouse_pos(POS_WINDOW)
+ SSF_BUTTON=2 ; states of the mouse buttons //get_mouse_buttons()
+ SSF_BUTTON_EXT=3 ; states and events of the mouse buttons // get_mouse_eventstate()
+ SSF_LOAD_CURSOR=4
+ SSF_SET_CURSOR=5
+ SSF_DEL_CURSOR=6 // destroy_cursor()
+ SSF_SCROLL_DATA=7 //get_mouse_wheels()
+SF_DRAW_LINE=38
SF_BACKGROUND_GET=39
;SSF_SIZE_BG=1
;SSF_PIXEL_BG=2
;SSF_MODE_BG=4
+SF_SET_EVENTS_MASK=40 ; turn on/off desired events
SF_PORT_IN_OUT=43 ; input/output to a port
SF_SET_PORTS=46 ; reserve/free a group of input/output ports
+SF_DRAW_NUMBER=47 ; draw number to the window // draw_number_sys()
SF_STYLE_SETTINGS=48
SSF_APPLY=0 ; apply screen settings
SSF_SET_BUTTON_STYLE=1
SSF_SET_COLORS=2
+ SSF_GET_COLORS=3 ; get standard window colors // get_system_colors()
+ SSF_GET_SKIN_HEIGHT=4
SSF_GET_SCREEN_AREA=5 ; get screen working area
SSF_SET_SCREEN_AREA=6
SSF_GET_SKIN_MARGINS=7
SSF_SET_SKIN=8
SSF_GET_FONT_SMOOTH=9
SSF_SET_FONT_SMOOTH=10
SSF_GET_FONT_SIZE=11
SSF_SET_FONT_SIZE=12
SF_APM=49
SF_SET_WINDOW_SHAPE=50
+SF_CREATE_THREAD=51 // start_thread()
SF_CLIPBOARD=54
+ SSF_GET_SLOT_COUNT=0 ; get the number of slots in the clipboard // kol_clip_num()
+ SSF_READ_CB=1 // kol_clip_get()
+ SSF_WRITE_CB=2 // kol_clip_set()
+ SSF_DEL_SLOT=3 ; delete the last slot in the clipboard // kol_clip_pop()
+ SSF_UNLOCK_BUFFER=4 ; emergency buffer unlock // kol_clip_unlock()
SF_SPEAKER_PLAY=55
SF_PCI_BIOS=57
SF_IPC=60 ; Inter Process Communication
+ SSF_SET_AREA=1 ; set area for IPC receiving // ipc_set_area()
+ SSF_SEND_MESSAGE=2 // ipc_send_message()
SF_GET_GRAPHICAL_PARAMS=61
+ SSF_SCREEN_SIZE=1 // GetScreenSize()
SSF_BITS_PER_PIXEL=2
SSF_BYTES_PER_LINE=3
SF_PCI=62
SSF_GET_VERSION=0 ; get version of PCI-interface
SSF_GET_LAST_BUS=1 ; get number of the last PCI-bus
SSF_GET_ADRR_MODE=2 ; get addressing mode of the PCI configuration space
SSF_READ_BYTE=4
SSF_READ_WORD=5
SSF_READ_DWORD=6
SSF_WRITE_BYTE=8
SSF_WRITE_WORD=9
SSF_WRITE_DWORD=10
SF_BOARD=63
+ SSF_DEBUG_WRITE=1 // debug_board_write_byte()
SSF_DEBUG_READ=2
SF_MEMORY_RESIZE=64 ; resize total application memory
SF_PUT_IMAGE_EXT=65 ; draw image with palette to the window
SF_KEYBOARD=66
SSF_SET_INPUT_MODE=1
SSF_GET_INPUT_MODE=2
SSF_GET_CONTROL_KEYS=3; get status of control keys
SSF_SET_SYS_HOTKEY=4
SSF_DEL_SYS_HOTKEY=5
SSF_LOCK_INPUT=6 ; block normal input
SSF_UNLOCK_INPUT=7 ; restore normal input
SF_CHANGE_WINDOW=67 ; change position/sizes of the window
SF_SYS_MISC=68
SSF_GET_TASK_SWITCH_COUNT=0
+ SSF_SWITCH_TASK=1 //yield()
SSF_PERFORMANCE=2
SSSF_ALLOW_RDPMC=0
SSSF_CACHE_STATUS=1
SSSF_CACHE_ON=2
SSSF_CACHE_OFF=3
SSF_READ_MSR=3
SSF_WRITE_MSR=4
SSF_HEAP_INIT=11
+ SSF_MEM_ALLOC=12 // user_alloc()
+ SSF_MEM_FREE=13 // user_free()
SSF_WAIT_SIGNAL=14 ; wait for signal from another program/driver
+ SSF_LOAD_DRIVER=16 // get_service()
+ SSF_CONTROL_DRIVER=17 // call_service()
SSF_LOAD_DLL=19
+ SSF_MEM_REALLOC=20 //user_realloc()
SSF_LOAD_DRIVER_PE=21
+ SSF_MEM_OPEN=22 ; open named memory area // shm_open()
+ SSF_MEM_CLOSE=23 // shm_close()
SSF_SET_EXCEPTION_HANDLER=24
SSF_SET_EXCEPTION_STATE=25
+ SSF_MEM_FREE_EXT=26 // user_unmap()
+ SSF_LOAD_FILE=27
SF_DEBUG=69
SSF_SET_MESSAGE_AREA=0
SSF_GET_REGISTERS=1
SSF_SET_REGISTERS=2
SSF_DETACH=3
SSF_SUSPEND=4
SSF_RESUME=5
SSF_READ_MEMORY=6
SSF_WRITE_MEMORY=7
SSF_TERMINATE=8
SSF_DEFINE_BREAKPOINT=9
SF_FILE=70
SSF_READ_FILE=0
SSF_READ_FOLDER=1
SSF_CREATE_FILE=2
SSF_WRITE_FILE=3
SSF_SET_END=4
SSF_GET_INFO=5
SSF_SET_INFO=6
+ SSF_START_APP=7
SSF_DELETE=8
SSF_CREATE_FOLDER=9
SF_SET_CAPTION=71
SF_SEND_MESSAGE=72
+SF_BLITTER=73 //Blit()
SF_NETWORK_GET=74
SSF_DEVICE_COUNT=255 ; get number of active network devices
SSF_DEVICE_TYPE=0
SSF_DEVICE_NAME=1
SSF_RESET_DEVICE=2
SSF_STOP_DEVICE=3
SSF_DEVICE_POINER=4
SSF_TX_PACKET_COUNT=6
SSF_RX_PACKET_COUNT=7
SSF_TX_BYTE_COUNT=8
SSF_RX_BYTE_COUNT=9
SSF_LINK_STATUS=10
SF_NETWORK_SOCKET=75
SSF_OPEN=0
SSF_CLOSE=1
SSF_BIND=2
SSF_LISTEN=3
SSF_CONNECT=4
SSF_ACCEPT=5
SSF_SEND=6
SSF_RECEIVE=7
SSF_SET_OPTIONS=8
SSF_GET_OPTIONS=9
SSF_GET_PAIR=10
SF_NETWORK_PROTOCOL=76
SSF_ETHERNET_READ_MAC=0
SSF_IP4_PACKETS_SENT=10000h
SSF_IP4_PACKETS_RECEIVED=10001h
SSF_IP4_READ_IP=10002h
SSF_IP4_WRITE_IP=10003h
SSF_IP4_READ_DNS=10004h
SSF_IP4_WRITE_DNS=10005h
SSF_IP4_READ_SUBNET=10006h
SSF_IP4_WRITE_SUBNET=10007h
SSF_IP4_READ_GATEWAY=10008h
SSF_IP4_WRITE_GATEWAY=10009h
SSF_ICMP_PACKETS_SENT=20000h
SSF_ICMP_PACKETS_RECEIVED=20001h
SSF_ICMP_ECHO_REPLY=20003h
SSF_UDP_PACKETS_SENT=30000h
SSF_UDP_PACKETS_RECEIVED=30001h
SSF_TCP_PACKETS_SENT=40000h
SSF_TCP_PACKETS_RECEIVED=40001h
SSF_ARP_PACKETS_SENT=50000h
SSF_ARP_PACKETS_RECEIVED=50001h
SSF_ARP_GET_ENTRY_COUNT=50002h
SSF_ARP_READ_ENTRY=50003h
SSF_ARP_ADD_STATIC_ENTRY=50004h
SSF_ARP_DEL_ENTRY=50005h
SSF_ARP_SEND_ANNOUNCE=50006h
SSF_ARP_CONFLICTS_COUNT=50007h
SF_FUTEX=77
SSF_CREATE=0
SSF_DESTROY=1
SSF_WAIT=2
SSF_WAKE=3
; File system errors:
FSERR_SUCCESS=0
FSERR_UNSUPPORTED=2
FSERR_UNKNOWN=3
FSERR_FILE_NOT_FOUND=5
FSERR_END_OF_FILE=6
FSERR_INVALID_BUFFER=7
FSERR_DISK_FULL=8
FSERR_FAIL=9
FSERR_ACCESS_DENIED=10
FSERR_DEVICE_FAIL=11
FSERR_OUT_OF_MEMORY=12

View File

@ -1,4 +1,5 @@
#ifndef __ASSERT_H
#define __ASSERT_H
#ifdef NDEBUG
# define assert(a) (void)0

View File

@ -1,3 +1,5 @@
#ifndef _CTYPE_H
#define _CTYPE_H
/*
** All character classification functions except isascii().
** Integer argument (c) must be in ASCII range (0-127) for
@ -35,3 +37,5 @@ extern unsigned short __is[128];
extern unsigned char tolower(unsigned char c);
extern unsigned char toupper(unsigned char c);
#endif

View File

@ -0,0 +1,6 @@
#ifndef _ERRNO_H
#define _ERRNO_H
#include <stdio.h>
#endif

View File

@ -3,6 +3,8 @@
// file header taken from newlib
// added many sys functions, compatible with tcc
// with gcc USE gcc -mno-ms-bitfields!!!
//#include <newlib.h>
//#include <stdint.h>
@ -42,7 +44,6 @@ extern "C" {
#define SHM_WRITE 0x01
typedef unsigned int color_t;
@ -132,6 +133,22 @@ struct ipc_buffer
struct ipc_message data[0]; // data begin
};
typedef struct __attribute__((packed)) file_op_t
{
uint32_t fn;
uint32_t flags;
char* args;
uint32_t res1, res2;
char zero;
char* app_name
#ifdef __TINYC__
__attribute__((packed))
#endif
;
} file_op_t;
static inline void begin_draw(void)
{
__asm__ __volatile__(
@ -524,7 +541,11 @@ void enumerate_libraries(int (*callback)(void *handle, const char* name,
void *user_data);
#endif
// May be next section need to be added in newlibc
///////////////////////////////////////////////////////////////////////////////
/// May be next section need to be added in newlibc
// Siemargl addenium
#define X_Y(x,y) (((x)<<16)|(y))
enum KOLIBRI_GUI_EVENTS {
KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */
@ -539,6 +560,107 @@ enum KOLIBRI_GUI_EVENTS {
KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
};
enum control_keys {
KM_SHIFT = 0x00010000,
KM_CTRL = 0x00020000,
KM_ALT = 0x00040000,
KM_NUMLOCK = 0x00080000
};
struct __attribute__ ((__packed__)) fs_dirinfo {
uint32_t subfn; // 1 read dir
uint32_t start;
uint32_t flags;
uint32_t size;
uint32_t retval;
union {
struct __attribute__ ((__packed__)) {
uint8_t zero; // 0
char* ppath;
};
char path[5]; // up to 4096
} ;
};
static inline
uint32_t sf_file(int subfn, struct fs_dirinfo* dinfo)
/// SysFn70 call with subfunction
/// retval 0 if ok
{
uint32_t retval;
dinfo->subfn = subfn;
__asm__ __volatile__(
"int $0x40 "
:"=a"(retval)
:"a"(70),"b"(dinfo)
:);
return retval;
};
struct fs_dirheader {
uint32_t version; // 1
uint32_t curn_blocks; // number of read dir items (BDFE)
uint32_t totl_blocks; // directory full size
char other[20]; // reserved 0
};
enum filetype
{
FS_RONLY = 1,
FS_HIDDEN = 2,
FS_SYSTEM = 4,
FS_VOLID = 8,
FS_SUBDIR = 16,
FS_FOLDER = 16,
FS_ARCHIV = 32
};
struct __attribute__ ((__packed__)) fs_filetime {
uint8_t sec;
uint8_t mm;
uint8_t hour;
uint8_t zero;
};
struct __attribute__ ((__packed__)) fs_filedate {
uint8_t day;
uint8_t month;
uint16_t year;
};
/// directory entry cp866
struct fsBDFE {
uint32_t filetype;
uint32_t encoding; // 0 - cp866, 1 - utf16le
struct fs_filetime tm_created;
struct fs_filedate dt_created;
struct fs_filetime tm_accessed;
struct fs_filedate dt_accessed;
struct fs_filetime tm_modified;
struct fs_filedate dt_modified;
uint64_t size;
char fname[264];
}; // must be sized 304
/// directory entry UTF16LE
struct fsBDFE_16 {
uint32_t filetype;
uint32_t encoding; // 0 - cp866, 1 - utf16le
struct fs_filetime tm_created;
struct fs_filedate dt_created;
struct fs_filetime tm_accessed;
struct fs_filedate dt_accessed;
struct fs_filetime tm_modified;
struct fs_filedate dt_modified;
uint64_t size;
wchar_t fname[260];
}; // must be sized 560
// copied from /programs/system/shell/system/kolibri.c
// fn's returned -1 as syserror, 1 as error, 0 as OK
@ -695,15 +817,7 @@ void shm_close(char *shm_name){
static inline
int start_app(char *app_name, char *args){
struct file_op_t
{
uint32_t fn;
uint32_t flags;
char* args;
uint32_t res1, res2;
char zero;
char* app_name __attribute__((packed));
} file_op;
file_op_t file_op;
memset(&file_op, 0, sizeof(file_op));
file_op.fn = 7;
file_op.args = args;
@ -715,6 +829,55 @@ int start_app(char *app_name, char *args){
return val;
}
static inline
uint32_t get_control_keys(void)
{
uint32_t ctrl;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(ctrl)
:"a"(66),"b"(3));
return ctrl;
};
static inline
int get_keyboard_layout(int opt, char* buf)
/// 128 byte buffer
/// opt: 1 - normal, 2 - shifted, 3 - alted, or 9 - return language
{
uint32_t lang;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(lang)
:"a"(26),"b"(2), "c"(opt), "d"(buf));
return lang;
};
static inline
int font_size(int color)
/// decode font size in pixels from color as SysFn4
/// returns (width, hight)
{
int font = color >> 24;
int font_multipl = (font & 7) + 1;
int width_sym, hight_sym;
if (font & 0x10) // 8x16
{
width_sym = 8 * font_multipl;
hight_sym = 16 * font_multipl;
} else // 6x9
{
width_sym = 6 * font_multipl;
hight_sym = 9 * font_multipl;
}
return hight_sym + (width_sym << 16);
}
/*
static inline char *getcwd(char *buf, size_t size)
@ -729,7 +892,28 @@ static inline char *getcwd(char *buf, size_t size)
return buf;
}
*/
// end section
/* not finished
void staticnum_draw(staticnum *st)
{
register uint32_t fmt;
if (st->width < 0)
fmt = (-st->width << 16); // leading zeros, decimal
else
fmt = (st->width << 16) | 0x80000000; // no leading zeros, decimal
__asm__ __volatile__(
"int $0x40"
::"a"(47),
"b"(fmt),
"c"(st->number),
"d"(st->start_xy),
"S"(st->color_flags),
"D"(st->bg_color)
:);
}
*/
//////////// end section
@ -753,6 +937,16 @@ void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
va_end(ap);
debug_board_write_str(log_board);
}
__attribute__ ((noinline)) void trap(int n)
{
// nothing todo, just see n in debugger. use "bp trap" command
__asm__ __volatile__(
"nop"
:
:"a"(n));
}
*/

View File

@ -1,6 +1,8 @@
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#ifndef _MATH_H
#define _MATH_H
//extern int stdcall integer(float number);
@ -189,3 +191,4 @@ long double roundl (long double x);
//#endif /* _USE_LIBM_MATH_H */
//#endif /* !__dj_include_math_h_ */
#endif

View File

@ -28,7 +28,7 @@ typedef struct {
int mode;
} FILE;
#define stderr ((FILE*)3) /* works inly for fprintf!!! */
#define stderr ((FILE*)3) /* works only for fprintf!!! */
#define FILE_OPEN_READ 0

View File

@ -30,7 +30,7 @@ long int strtol (const char* str, char** endptr, int base);
void* calloc (size_t num, size_t size);
#define exit(a) _ksys_exit()
void exit (int status); /* close console if was initialized, also stay window [finished] when status is error < 0 */
#define abort() exit(-1)
typedef struct {

View File

@ -0,0 +1,29 @@
#ifndef _TIME_H
#define _TIME_H
typedef unsigned long int clock_t;
typedef unsigned long int time_t;
#define clock() get_tick_count()
#define CLOCKS_PER_SEC 100
struct tm {
int tm_sec; /* seconds after the minute 0-61*/
int tm_min; /* minutes after the hour 0-59 */
int tm_hour; /* hours since midnight 0-23 */
int tm_mday; /* day of the month 1-31 */
int tm_mon; /* months since January 0-11 */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday 0-6 */
int tm_yday; /* days since January 1 0-365 */
int tm_isdst; /* Daylight Saving Time flag */
};
time_t mktime (struct tm * timeptr);
time_t time (time_t* timer);
struct tm * localtime (const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */
double difftime (time_t end, time_t beginning);
extern struct tm __buffertime;
#endif

View File

@ -29,8 +29,10 @@ proc _ksys_get_filesize stdcall, filename:dword
jnz error_for_file_size
mov eax,[buffer_for_info+32] ;file size
ret
error_for_file_size:
neg eax
ret
endp

View File

@ -43,7 +43,7 @@ char* con_imports[] = {
"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_get_cursor_pos", "con_set_cursor_pos", "con_set_title",
(char*)0
};
@ -68,6 +68,7 @@ void con_lib_link(struct import *exp, char** imports){
con_cls = _ksys_cofflib_getproc(exp, imports[17]);
con_get_cursor_pos = _ksys_cofflib_getproc(exp, imports[18]);
con_set_cursor_pos = _ksys_cofflib_getproc(exp, imports[19]);
con_set_title = _ksys_cofflib_getproc(exp, imports[20]);
}

View File

@ -12,6 +12,8 @@ int fclose(FILE* file)
if(file->buffer)
free(file->buffer);
if(file->filename)
free(file->filename);
free(file);
return 0;

View File

@ -8,7 +8,7 @@ int fgetc(FILE* file)
return EOF;
}
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return EOF;
if ((file->mode & 3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS)==0) return EOF;
if (file->filepos>=file->filesize)
{

View File

@ -7,107 +7,57 @@ extern char __path;
int errno = 0;
const char* getfullpath(const char *path){
int i,j,relpath_pos,localpath_size;
int filename_size;
char local_path;
int relpath_pos, localpath_size;
char *programpath;
char *newpath;
char *prgname;
i=0;
local_path=1; //enable local path
while((*(path+i)!='\0') || (*(path+i)!=0))
if (path[0] == '/') /* root */
{
if (*(path+i)=='.')
return(strdup(path)); /* dup need as free in fclose() */
}
relpath_pos = 0;
if (path[0] == '.' && path[1] == '/')
{
if (*(path+i+1)=='/')
{ //detected relative path
relpath_pos=i+2;
local_path=0;
break;
//detected relative path, begins with ./
relpath_pos=2;
}
}
if (*(path+i)=='/')
{ //disabple local path
local_path=0;
return(path);
}
i++;
}
filename_size=i;
programpath=&__path;
if (local_path==1)
{
i=FILENAME_MAX;
//find local path of program
while(*(programpath+i)!='/')
{
i--;
}
localpath_size=i;
newpath=malloc(FILENAME_MAX);
if(!newpath)
{
errno = E_NOMEM;
return NULL;
}
//if we here than path is a relative or local
prgname = strrchr(programpath, '/');
if (!prgname) return strdup(path);
//copy local path to the new path
for(i=0;i<=localpath_size;i++)
{
*(newpath+i)=*(programpath+i);
}
//copy filename to the new path
for(i=0;i<filename_size;i++)
{
*(newpath+localpath_size+1+i)=*(path+i);
}
return(newpath);
}
localpath_size = prgname - programpath + 1;
//if we here than path is a relative
i=FILENAME_MAX;
//find local path of program
while(*(programpath+i)!='/')
{
i--;
}
localpath_size=i;
i=0;
//find file name size
while((*(path+relpath_pos+i)!='\0') || (*(path+relpath_pos+i)!=0))
{
i++;
}
filename_size=i;
newpath=malloc(FILENAME_MAX);
newpath = malloc(FILENAME_MAX);
if(!newpath)
{
errno = E_NOMEM;
return NULL;
}
//copy local path to the new path
for(i=0;i<=localpath_size;i++)
{
*(newpath+i)=*(programpath+i);
}
strncpy(newpath, programpath, localpath_size);
newpath[localpath_size] = 0;
//copy filename to the new path
for(i=0;i<filename_size;i++)
{
*(newpath+localpath_size+1+i)=*(path+relpath_pos+i);
}
strcpy(newpath + localpath_size, path + relpath_pos);
return(newpath);
}
FILE* fopen(const char* filename, const char *mode)
{
FILE* res;
int imode;
int imode, sz = -1;
char *fullname;
imode=0;
if (*mode=='r')
{
@ -141,7 +91,20 @@ FILE* fopen(const char* filename, const char *mode)
}
if (*mode!=0)
return NULL;
res=malloc(sizeof(FILE));
fullname = (char*)getfullpath(filename);
if ((imode & 3) == FILE_OPEN_READ && fullname) /* check existense */
{
sz = _ksys_get_filesize(fullname);
if (sz < 0)
{
free(fullname);
errno = sz;
return NULL;
}
}
res = malloc(sizeof(FILE));
if (res)
{
res->buffer=malloc(BUFSIZ);
@ -149,7 +112,7 @@ FILE* fopen(const char* filename, const char *mode)
res->filesize=0;
res->filepos=0;
res->mode=imode;
res->filename=(char*)getfullpath(filename);
res->filename=fullname;
}
if(!res || !res->buffer || !res->filename)
{
@ -159,6 +122,9 @@ FILE* fopen(const char* filename, const char *mode)
if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
{
if (sz > 0) /*already got*/
res->filesize = sz;
else
res->filesize=_ksys_get_filesize(res->filename);
}
return res;

View File

@ -12,7 +12,7 @@ int fread(void *buffer,int size,int count,FILE* file)
return 0;
}
if ((file->mode &3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS==0))
if ((file->mode &3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS)==0)
{
errno = E_ACCESS;
return 0;

View File

@ -0,0 +1,61 @@
#include <time.h>
#include <kolibrisys.h>
struct tm __buffertime;
struct tm * localtime (const time_t * timer)
/* non-standard! ignore parameter and return just time now */
{
int kos_date, kos_time;
kos_date = _ksys_get_date();
kos_time = _ksys_get_system_clock();
__buffertime.tm_mday = kos_date >> 16;
__buffertime.tm_mon = ((kos_date & 0xFF00) >> 8) -1;
__buffertime.tm_year = kos_date >> 16 + 100;
__buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
__buffertime.tm_sec = kos_time >> 16;
__buffertime.tm_min = (kos_time & 0xFF00) >> 8;
__buffertime.tm_hour = kos_time & 0xFF;
return &__buffertime;
}
time_t time (time_t* timer)
{
time_t t = mktime(localtime(0));
if (timer) *timer = t;
return t;
}
time_t mktime (struct tm * timeptr)
{
int y, m, d;
time_t t;
y = timeptr->tm_year + 1900;
m = timeptr->tm_mon + 1;
d = timeptr->tm_mday; /* to -1 or not to -1? */
if (m < 3) { m += 12; y -= 1; }
t = y * 365 + y / 4 + y /400 - y / 100; /* years - > days */
t += 30 * m + 3 * (m + 1) / 5 + d; /* add month days */
t -= 719561; /* 01 jan 1970 */
t *= 86400;
t += 3600 * timeptr->tm_hour + 60 * timeptr->tm_min + timeptr->tm_sec;
return t;
}
double difftime (time_t end, time_t beginning)
{
return end - beginning;
}

View File

@ -5,3 +5,123 @@ source/tcc-doc.info or .texi
building Kolibri version
>make -f Makefile.kos32
========= for compiler developers =========
read .\source\readme_kos32.txt
------ TODO -------
-minimal memory allocator
-more libc stardard functions. see report below
-more Kolibly SysFn wrappers. see \libc\KOSfuncs_inc_status.txt
-add stdin, stderr, stdout emulation íå õâàòàåò stdin, stdout - ìîæíî ñäåëàòü êàê stderr!, íî íàäî âîçèòüñÿ çàîäíî ñ ferror & feof
-getchar, gets if returs errorcode (0, null) - you must exit program, because of closed console window
-ïðè íîðìàëüíîì âûõîäå çàêðûâàòü êîíñîëü
-sstrek âèñíåò íà ïîèñêå õåëïà ñ äèñêåòû - just very long reading by one symbol without buffering (need to change gets, getc, ungetc etc)
------ errors ------
-not working: default search path are ./include ./lib from executable (under KOS need to use -Bpath_to_ktcc)
--start.o not found using -B (kos) - put near your.c file
-åñëè ïðîåêò ìíîãîôàéëîâûé - .dbg ãåíåðèò äóáëèðóþùèåñÿ ìåòêè äàííûõ, òèïà L.78 ìîæåò óêàçûâàòü íà äðóãîé ñåãìåíò (
----- fixed errors ------
-if static var sized more than 14096+ -> crash compiled .exe (kos)
(^ default stack size set at compile time tccmeos:177 is below 4k)
FIX - use -stack=1280000 option
-con_set_title is NULL. fixed 180128
========= libc ===========
-no "finished" in title of console program after exit console - use con_exit()
-used system memory allocator (4096 bytes minimum)
libc not complete. overall status:
no files:
limits.h
locale.h
setjmp.h
signal.h
wchar.h
wctype.h
functions absent list:
stdio.h:
remove
rename
tmpfile
tmpnam
freopen
setbuf
setvbuf
stdlib.h:
atexit
getenv
system
bsearch
qsort
mblen
mbtowc
wctomb
mbstowcs
wcstombs
string.h:
strxfrm
time.h: - needs include kos32sys1.h
asctime
ctime
gmtime
localtime - non standard
strftime
Status or libc tests
---FAILED---
strtoul incorrect work with big unsigned > MAX_LONG
---NOT TESTED---
no library fns realized
qsort
time
---HANG---
sscanf
>TEST_F(0x1234p56) - no %a formats
---STACK IS SMALL---
use new -stack=1280000 option to pass test
tstring
strtodlong
--other--
fscanf
-?scanf ignores width specs, '*' and [chars], cant read %a float
-%n counts as parameter
snprintf
-some format misturbances
-may incorrect prints unsigned > 2147483647L
ungetc
-ungetc fails if filepos == 0 - no tricks
all file ops limited to 2Gb

View File

@ -3,7 +3,8 @@ Siemargl port comments
Used github branch https://github.com/TinyCC/tinycc
It have a vesion 0.9.26 with heads up to 0.9.27 - see ChangeLog
Kolibri version errata/changelog:
Kolibri version specifics
errata/changelog - moved to trunk/readme.txt
-added TCC_TARGET_MEOS as needed
-leading_underscore by default is 0 (can use -f[no-]leading-underscore),
@ -15,7 +16,6 @@ otherwise (error) underscoring all symbols, not only cdecl
use -Bpath_to_ktcc and put start.o in current dir)
-when config.h is ready, compiler can be easy builded as [kos32-]gcc tcc.c libtcc.c
see also makefile.kos32
-silent (kos) -> writes to debugboard
-impossible using with mingw-gcc compiled lib, incompatible library format:
.o is PE-format from gcc but ELF from tcc, may be linux-gcc does it ok
-__fastcall incompatible with other compilers. now stack freed by caller.
@ -25,9 +25,6 @@ otherwise (error) underscoring all symbols, not only cdecl
-using __attribute__((packed)) see test82. need naming struct twice as in kos32sys1.h
-using __attribute__ ((alias xxx)) restricted only for non "static inline" functions
-erroneous or "non TCC" member using in nested structs or unions can lead to compiler internal error
-not working: default search path are ./include ./lib from executable
--under KOS need to use -Bpath_to_ktcc
--start.o not found using -B (kos) - put near your.c file
-bench timing coarse (0s or 1s), no usec in newlib gettimeofday. OK
Tests status:
@ -50,84 +47,3 @@ test73 fail compile (no stdint.h), printfloat, ARM specific
test46 no stdin - removed funtionality read from console, but file ops works
libc:
-no "finished" in title of console program after exit console - use con_exit()
-used system memory allocator (4096 bytes minimum)
libc not complete. overall status:
no files:
errno.h - in stdio
limits.h
locale.h
setjmp.h
signal.h
time.h - can use get_tick_count()/100 from kos32sys1.h
wchar.h
wctype.h
functions absent list:
stdio.h:
remove
rename
tmpfile
tmpnam
freopen
setbuf
setvbuf
stdlib.h:
atexit
getenv
system
bsearch
qsort
mblen
mbtowc
wctomb
mbstowcs
wcstombs
string.h
strxfrm
Status or libc tests
---FAILED---
strtoul incorrect work with big unsigned > MAX_LONG
---NOT TESTED---
no library fns realized
qsort
time
---HANG---
sscanf
>TEST_F(0x1234p56) - no %a formats
---STACK IS SMALL---
use new -stack=1280000 option to pass test
tstring
strtodlong
--other--
fscanf
-?scanf ignores width specs, '*' and [chars], cant read %a float
-%n counts as parameter
snprintf
-some format misturbances
-may incorrect prints unsigned > 2147483647L
ungetc
-ungetc fails if filepos == 0 - no tricks
all file ops limited to 2Gb