- is now a native dynamic library (ms coff)
- removed unnecessary files. 
- updated ssl_client1 example

git-svn-id: svn://kolibrios.org@9076 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2021-07-23 19:43:38 +00:00
parent 351b8e3ae8
commit 7828dfa68a
37 changed files with 2689 additions and 1698 deletions

View File

@ -1 +0,0 @@
#### port of mbedtls-2.16.6 library for KolibriOS

View File

@ -1,5 +0,0 @@
on windows:
- how to build mdebtls static library:
- cd to library/
- to build: mingw32-make
- to clean: mingw32-make clean WINDOWS=1

View File

@ -1,16 +0,0 @@
option(INSTALL_MBEDTLS_HEADERS "Install mbed TLS headers." ON)
if(INSTALL_MBEDTLS_HEADERS)
file(GLOB headers "mbedtls/*.h")
install(FILES ${headers}
DESTINATION include/mbedtls
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif(INSTALL_MBEDTLS_HEADERS)
# Make config.h available in an out-of-source build. ssl-opt.sh requires it.
if (ENABLE_TESTING AND NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
link_to_source(mbedtls)
endif()

View File

@ -1,37 +0,0 @@
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
CC = kos32-gcc
AR = kos32-ar
CFLAGS ?= -O2
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
LDFLAGS ?=
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I $(NEWLIB_INCLUDES) -I include -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =
AR_DASH ?= -
ARFLAGS = $(AR_DASH)src
OBJS= socket.o network.o dlfcn.o
.PHONY: all static clean
all: static
static: libkosnet.a
libkosnet.a: $(OBJS)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS)
.c.o:
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
clean:
ifndef WINDOWS
rm -f *.o libkosnet.a
else
del /Q /F *.o libkosnet.a
endif

View File

@ -1,92 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "kosnet/dlfcn.h"
#include "kosnet/kos32sys1.h"
typedef struct {
char *name;
void *ptr;
} KosExp;
typedef struct {
void **importNames;
char * libraryName;
} KosImp;
static int __attribute__ ((stdcall)) dll_Load(KosImp *importTableEntry);
static const char *__error;
static int __attribute__ ((stdcall)) dll_Load(KosImp *importTableEntry) {
for (; importTableEntry->importNames; importTableEntry++) {
char libPath[256] = "/sys/lib/";
KosExp *exports = NULL;
void **libImports = importTableEntry->importNames;
strcat(libPath, importTableEntry->libraryName);
if (!(exports = dlopen(libPath, 0))) { return 1; }
for (; *libImports; libImports++) {
if (!(*libImports = dlsym(exports, *libImports))) { return 1; }
}
}
return 0;
}
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlopen.html
// Current implementation fully ignores "mode" parameter
void *dlopen(const char *name, int mode) {
KosExp *exports = NULL;
// load library using syscall
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(name));
if (!exports) {
char libPath[256] = "/sys/lib/";
strcat(libPath, name);
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(libPath));
if (!exports) {
__error = "Library not found in \"/sys/lib/\" nor current folder";
return NULL;
}
}
// call anything starting with "lib_"
for (KosExp *export = exports; export->name; export++) {
if (!memcmp(export->name, "lib_", 4)) {
asm volatile (
"call *%4" ::
"a"(0),
"b"(0),
"c"(0),
"d"(dll_Load),
"r"(export->ptr));
// was asm volatile ("call *%4" ::"a"(sysmalloc),"b"(sysfree),"c"(sysrealloc),"d"(dll_Load),"r"(export->ptr));
}
}
return exports;
}
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
void *dlsym(void *handle, const char *name) {
KosExp *exp = handle;
for (; exp->name; exp++) {
if (!strcmp(exp->name, name)) {
return exp->ptr;
}
}
__error = "Symbol not found";
return NULL;
}
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlclose.html
int dlclose(void *handle) {
return 0;
}
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlerror.html
char *dlerror(void) {
char *ret = __error ? strdup(__error) : NULL;
__error = NULL;
return ret;
}

View File

@ -1,14 +0,0 @@
#ifndef _DLFCN_H
#define _DLFCN_H
#define RTLD_LAZY 0x00001
#define RTLD_NOW 0x00002
#define RTLD_GLOBAL 0x00100
#define RTLD_LOCAL 0
int dlclose(void *handle);
char *dlerror(void);
void *dlopen(const char *name, int mode);
void *dlsym(void *restrict handle, const char *restrict name);
#endif

View File

@ -1,836 +0,0 @@
#ifndef __KOS_32_SYS_H__
#define __KOS_32_SYS_H__
#include <stddef.h>
#include <stdarg.h>
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned long long uint64_t;
#ifdef __cplusplus
extern "C" {
#endif
#define TYPE_3_BORDER_WIDTH 5
#define WIN_STATE_MINIMIZED 0x02
#define WIN_STATE_ROLLED 0x04
#define POS_SCREEN 0
#define POS_WINDOW 1
#define IPC_NOBUFFER 1
#define IPC_LOCKED 2
#define IPC_OVERFLOW 3
#define IPC_NOPID 4
#define SHM_OPEN 0x00
#define SHM_OPEN_ALWAYS 0x04
#define SHM_CREATE 0x08
#define SHM_READ 0x00
#define SHM_WRITE 0x01
// for clipboard funtions
#define UTF 0
#define CP866 1
#define CP1251 2
#define TEXT 0
#define IMAGE 1
#define RAW 2
//Read/Write data as type (int char, etc.) at address "addr" with offset "offset". eg DATA(int, buff, 8);
#define DATA(type, addr, offset) *((type*)((uint8_t*)addr+offset))
typedef struct {
uint8_t blue;
uint8_t green;
uint8_t red;
}RGB;
typedef unsigned int color_t;
typedef union __attribute__((packed)) pos_t
{
uint32_t val;
struct
{
short x;
short y;
};
} pos_t;
typedef union __attribute__((packed)) oskey_t
{
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;
typedef union
{
struct
{
void *data;
size_t size;
} x;
unsigned long long raw;
}ufile_t;
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;
};
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
int srcx;
int srcy;
int srcw;
int srch;
void *bitmap;
int stride;
};
struct ipc_message
{
uint32_t pid; // PID of sending thread
uint32_t datalen; // data bytes
char data[0]; // data begin
};
struct ipc_buffer
{
uint32_t lock; // nonzero is locked
uint32_t used; // used bytes in buffer
struct ipc_message data[0]; // data begin
};
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 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");
};
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");
}
static inline
void draw_text_sys_bg(const char *text, int x, int y, int len, color_t color, color_t bg)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color), "D"(bg)
:"memory");
}
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
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;
};
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
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()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline uint32_t get_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
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()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
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 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 int GetScreenSize()
{
int retval;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(61), "b"(1));
return retval;
}
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
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));
};
// newlib exclusive
#ifndef __TINYC__
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);
#endif
// May be next section need to be added in newlibc
enum KOLIBRI_GUI_EVENTS {
KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */
KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */
KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */
KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */
KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */
KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */
KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */
KOLIBRI_EVENT_NETWORK = 8, /* Network event */
KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */
KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
};
// copied from /programs/system/shell/system/kolibri.c
// fn's returned -1 as syserror, 1 as error, 0 as OK
static inline
int kol_clip_num()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0));
return val;
}
static inline
char* kol_clip_get(int n)
// returned buffer must be freed by user_free()
{
register char* val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n));
return val;
}
static inline
int kol_clip_set(int n, char buffer[])
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer));
return val;
}
static inline
int kol_clip_pop()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3));
return val;
}
static inline
int kol_clip_unlock()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4));
return val;
}
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)
);
/* color_table should point to the system color table */
}
static inline void debug_board_write_byte(const char ch){
__asm__ __volatile__(
"int $0x40"
:
:"a"(63), "b"(1), "c"(ch));
}
static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){
register uint32_t fmt;
fmt = len << 16 | 0x80000000; // no leading zeros + width
// fmt = len << 16 | 0x00000000; // leading zeros + width
__asm__ __volatile__(
"int $0x40"
:
:"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
}
static inline void draw_number_sys_bg(int32_t number, int x, int y, int len, color_t color, color_t bg){
register uint32_t fmt;
fmt = len << 16 | 0x80000000; // no leading zeros + width
// fmt = len << 16 | 0x00000000; // leading zeros + width
__asm__ __volatile__(
"int $0x40"
:
:"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg));
}
static inline
uint32_t get_mouse_eventstate(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(3));
return val;
};
static inline
uint32_t set_event_mask(uint32_t mask)
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask));
return val;
}
typedef void (*thread_proc)(void*);
static inline
int start_thread(thread_proc proc, char* stack_top)
{
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top));
return val;
}
static inline
void kos_exit()
{
asm volatile ("int $0x40"::"a"(-1));
}
static inline void focus_window(int slot){
asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot));
}
static inline int get_thread_slot(int tid){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid));
return val;
}
static inline void set_current_folder(char* dir){
asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir));
}
static inline int get_current_folder(char* buf, int bufsize){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize));
return val;
}
static inline
void ipc_set_area(void* buf, int bufsize){
asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
}
static inline
int ipc_send_message(int pid_reciever, void *data, int datalen) {
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
return val;
}
static inline
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
register int val, cod;
asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
if(retsz) *retsz = cod; // errcode if NULL or memsize when open
return (void*)val;
}
static inline
void shm_close(char *shm_name){
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
}
static inline
int start_app(char *app_name, char *args){
register int val;
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;
memset(&file_op, 0, sizeof(file_op));
file_op.fn = 7;
file_op.args = args;
file_op.app_name = app_name;
asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
return val;
}
//added nonstatic inline because incomfortabre stepping in in debugger
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
/* copy body to only one project file
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
while(*str)
debug_board_write_byte(*str++);
}
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
{
va_list ap;
char log_board[300];
va_start (ap, format);
vsnprintf(log_board, sizeof log_board, format, ap);
va_end(ap);
debug_board_write_str(log_board);
}
*/
// TinyC don't support aliasing of static inline funcs, but support #define :)
#ifndef __TINYC__
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")));
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 GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
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")));
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
#else
#define BeginDraw begin_draw
#define EndDraw end_draw
#define DrawWindow sys_create_window
#define DefineButton define_button
#define DrawLine draw_line
#define DrawBar draw_bar
#define DrawBitmap draw_bitmap
#define GetSkinHeight get_skin_height
#define GetMousePos get_mouse_pos
#define GetMouseButtons get_mouse_buttons
#define GetMouseWheels get_mouse_wheels
#define LoadCursor load_cursor
#define SetCursor set_cursor
#define DestroyCursor destroy_cursor
#define GetOsEvent get_os_event
#define UserAlloc user_alloc
#define UserFree user_free
#define UserRealloc user_realloc
#define UserUnmap user_unmap
#define LoadFile load_file
#define GetProcInfo get_proc_info
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,54 +0,0 @@
#ifndef __NETWORK_H
#define __NETWORK_H
#include "kosnet/socket.h"
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_OVERFLOW 14
// Flags for addrinfo
#define AI_PASSIVE 1
#define AI_CANONNAME 2
#define AI_NUMERICHOST 4
#define AI_NUMERICSERV 8
#define AI_ADDRCONFIG 0x400
#pragma pack(push, 1)
struct ARP_entry{
unsigned int IP;
unsigned char MAC[6];
unsigned short status;
unsigned short TTL;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
int ai_addrlen;
char *ai_canonname;
sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#pragma pack(pop)
extern int load_network_obj();
extern int (*inet_addr)(const char* hostname) __attribute__ ((stdcall));
extern char* (*inet_ntoa)(int ip_addr) __attribute__ ((stdcall));
extern int (*getaddrinfo)(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res) __attribute__ ((stdcall));
extern void (*freeaddrinfo)(struct addrinfo* ai) __attribute__ ((stdcall));
#endif

View File

@ -1,107 +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_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)
extern int err_code;
#pragma pack(push,1)
typedef struct{
unsigned short sin_family;
unsigned short sin_port;
unsigned int sin_addr;
unsigned long long sin_zero;
}sockaddr;
#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)
int socket(int domain, int type, int protocol);
int closesocket(int socket);
int bind(int socket, const sockaddr *addres, int addres_len);
int listen(int socket, int backlog);
int connect(int socket, const sockaddr* address, int socket_len);
int accept(int socket, const sockaddr* address, int address_len);
int send(int socket, const void *message, size_t msg_len, int flag);
int recv(int socket, void *buffer, size_t buff_len, int flag);
int setsockopt(int socket,const optstruct* opt);
int getsockopt(int socket, optstruct* opt);
int socketpair(int *sock1, int *sock2);
#endif

View File

@ -1,21 +0,0 @@
#include "kosnet/network.h"
#include "kosnet/dlfcn.h"
int (*inet_addr)(const char* hostname) __attribute__ ((stdcall));
char* (*inet_ntoa)(int ip_addr) __attribute__ ((stdcall));
int (*getaddrinfo)(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res) __attribute__ ((stdcall));
void (*freeaddrinfo)(struct addrinfo* ai) __attribute__ ((stdcall));
int load_network_obj() {
void *network_lib = dlopen("/sys/lib/network.obj", RTLD_GLOBAL);
if (network_lib == NULL) {
return -1;
}
inet_addr = dlsym(network_lib, "inet_addr");
inet_ntoa = dlsym(network_lib, "inet_ntoa");
getaddrinfo = dlsym(network_lib, "getaddrinfo");
freeaddrinfo = dlsym(network_lib, "freeaddrinfo");
dlclose(network_lib);
return 0;
}

View File

@ -1,24 +0,0 @@
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
APP_DYNAMIC_LDS=D:\KOSSDK\newlib/app-dynamic.lds
LIBDIR=D:\KOSSDK\kos32-msys-5.4.0\win32\lib
MAIN_TARGET=libkosnet_demo
CC=kos32-gcc
LD=kos32-ld
OBJCOPY=kos32-objcopy
CCFLAGS=-c -fomit-frame-pointer -I $(NEWLIB_INCLUDES) -I../include -Wall -Wextra
LDFLAGS=-call_shared -nostdlib --subsystem console -T $(APP_DYNAMIC_LDS) --image-base 0 -L $(LIBDIR) -L ../ -lkosnet -lgcc -lapp -lc.dll
all: libkosnet_demo
libkosnet_demo: libkosnet_demo.o
$(LD) libkosnet_demo.o -o $(MAIN_TARGET) $(LDFLAGS)
$(OBJCOPY) $(MAIN_TARGET) -O binary
libkosnet_demo.o: libkosnet_demo.c
$(CC) $(CCFLAGS) libkosnet_demo.c -o libkosnet_demo.o
clean:
del *.o
del $(MAIN_TARGET)

View File

@ -1,60 +0,0 @@
#include "kosnet/network.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
load_network_obj();
char *host = "kolibrios.org";
int port = 80;
printf("Connecting to %s on port %d\n", host, port);
struct addrinfo *addr_info;
char port_str[16]; sprintf(port_str, "%d", port);
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
if (getaddrinfo(host, port_str, 0, &addr_info) != 0) {
printf("Host %s not found!\n", host);
freeaddrinfo(addr_info);
exit(-1);
}
printf("IP address of %s is %s\n", host, inet_ntoa(addr_info->ai_addr->sin_addr));
//printf("Host port = %d\n", addr_info->ai_addr->sin_port >> 8);
char request[256];
sprintf(request, "GET /en/ HTTP/1.1\r\nHost: %s\r\n\r\n", host);
printf("request = %s\n", request);
int sock = socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
puts("Connecting...\n");
if (connect(sock, addr_info->ai_addr, addr_info->ai_addrlen) != 0) {
printf("Connection failed, err_code = %d\n", err_code);
exit(err_code);
}
puts("Connected successfully\n");
puts("Sending request...\n");
if (send(sock, request, strlen(request), MSG_NOFLAG) == -1) {
printf("Sending failed, err_code = %d\n", err_code);
exit(err_code);
}
puts("Request sended successfully, waiting for response...\n");
char buf[512 + 1];
if (recv(sock, buf, 512, MSG_NOFLAG) == -1) {
printf("Receive failed, err_code = %d\n", err_code);
exit(err_code);
}
printf("Response = %s\n", buf);
freeaddrinfo(addr_info);
closesocket(sock);
puts("\n goodbye)\n");
return 0;
}

View File

@ -1 +0,0 @@
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.

View File

@ -1,124 +0,0 @@
#include "kosnet/socket.h"
int err_code = 0;
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;
}
int closesocket(int socket)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
return status;
}
int bind(int socket, const 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;
}
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;
}
int connect(int socket,const 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;
}
int accept(int socket, const 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;
}
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;
}
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;
}
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;
}
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;
}
int socketpair(int *socket1, int *socket2)
{
asm volatile(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
err_code=*socket2;
return *socket1;
}

View File

@ -1 +0,0 @@
*.o

View File

@ -1,187 +0,0 @@
option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
set(src_crypto
aes.c
aesni.c
arc4.c
aria.c
asn1parse.c
asn1write.c
base64.c
bignum.c
blowfish.c
camellia.c
ccm.c
chacha20.c
chachapoly.c
cipher.c
cipher_wrap.c
cmac.c
ctr_drbg.c
des.c
dhm.c
ecdh.c
ecdsa.c
ecjpake.c
ecp.c
ecp_curves.c
entropy.c
entropy_poll.c
error.c
gcm.c
havege.c
hkdf.c
hmac_drbg.c
md.c
md2.c
md4.c
md5.c
md_wrap.c
memory_buffer_alloc.c
nist_kw.c
oid.c
padlock.c
pem.c
pk.c
pk_wrap.c
pkcs12.c
pkcs5.c
pkparse.c
pkwrite.c
platform.c
platform_util.c
poly1305.c
ripemd160.c
rsa.c
rsa_internal.c
sha1.c
sha256.c
sha512.c
threading.c
timing.c
version.c
version_features.c
xtea.c
)
set(src_x509
certs.c
pkcs11.c
x509.c
x509_create.c
x509_crl.c
x509_crt.c
x509_csr.c
x509write_crt.c
x509write_csr.c
)
set(src_tls
debug.c
net_sockets.c
ssl_cache.c
ssl_ciphersuites.c
ssl_cli.c
ssl_cookie.c
ssl_srv.c
ssl_ticket.c
ssl_tls.c
)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
endif(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
endif(CMAKE_COMPILER_IS_CLANG)
if(UNSAFE_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error")
set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error")
endif(UNSAFE_BUILD)
if(WIN32)
set(libs ${libs} ws2_32)
endif(WIN32)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()
if(HAIKU)
set(libs ${libs} network)
endif(HAIKU)
if(USE_PKCS11_HELPER_LIBRARY)
set(libs ${libs} pkcs11-helper)
endif(USE_PKCS11_HELPER_LIBRARY)
if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
if(LINK_WITH_PTHREAD)
set(libs ${libs} pthread)
endif()
if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
set(mbedtls_static_target "mbedtls_static")
set(mbedx509_static_target "mbedx509_static")
set(mbedcrypto_static_target "mbedcrypto_static")
elseif(USE_STATIC_MBEDTLS_LIBRARY)
set(mbedtls_static_target "mbedtls")
set(mbedx509_static_target "mbedx509")
set(mbedcrypto_static_target "mbedcrypto")
endif()
if(USE_STATIC_MBEDTLS_LIBRARY)
add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
target_link_libraries(${mbedcrypto_static_target} ${libs})
add_library(${mbedx509_static_target} STATIC ${src_x509})
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
add_library(${mbedtls_static_target} STATIC ${src_tls})
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
DESTINATION ${LIB_INSTALL_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(USE_STATIC_MBEDTLS_LIBRARY)
if(USE_SHARED_MBEDTLS_LIBRARY)
add_library(mbedcrypto SHARED ${src_crypto})
set_target_properties(mbedcrypto PROPERTIES VERSION 2.16.6 SOVERSION 3)
target_link_libraries(mbedcrypto ${libs})
add_library(mbedx509 SHARED ${src_x509})
set_target_properties(mbedx509 PROPERTIES VERSION 2.16.6 SOVERSION 0)
target_link_libraries(mbedx509 ${libs} mbedcrypto)
add_library(mbedtls SHARED ${src_tls})
set_target_properties(mbedtls PROPERTIES VERSION 2.16.6 SOVERSION 12)
target_link_libraries(mbedtls ${libs} mbedx509)
install(TARGETS mbedtls mbedx509 mbedcrypto
DESTINATION ${LIB_INSTALL_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(USE_SHARED_MBEDTLS_LIBRARY)
add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
endif()

View File

@ -1,28 +1,12 @@
# Also see "include/mbedtls/config.h"
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
KOSNET_INCLUDES=../kosnet/include
CC = kos32-gcc
AR = kos32-ar
FASM = fasm
CLINK= ../../../clink/clink
CFLAGS ?= -O2
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
LDFLAGS ?=
KLIBC_DIR = ../../../ktcc/trunk/libc.obj
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I $(NEWLIB_INCLUDES) -I../include -I $(KOSNET_INCLUDES) -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =
ifdef DEBUG
LOCAL_CFLAGS += -g3
endif
# Set AR_DASH= (empty string) to use an ar implementation that does not accept
# the - prefix for command line options (e.g. llvm-ar)
AR_DASH ?= -
ARFLAGS = $(AR_DASH)src
CFLAGS = -c -nostdinc -I../include -DGNUC -fno-common -Os -fno-delete-null-pointer-checks -fno-ident -fno-builtin -fno-leading-underscore -D__TINYC__ -D_FILE_OFFSET_BITS=64
INCLUDES = -I../include -I.. -I$(KLIBC_DIR)/include
OBJS_CRYPTO= aes.o aesni.o arc4.o \
aria.o asn1parse.o asn1write.o \
@ -55,38 +39,27 @@ OBJS_TLS= debug.o net_sockets.o \
ssl_cache.o ssl_ciphersuites.o \
ssl_cli.o ssl_cookie.o \
ssl_srv.o ssl_ticket.o \
ssl_tls.o
ssl_tls.o
OBJS_OTHER = libtcc/libtcc1.o libtcc/memmove.o \
libtcc/memset.o libtcc/memcpy.o \
libtcc/___chkstk_ms.o \
mbedtls_init.o \
export.o
all: $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER)
ar -crs libmbedtls.a $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER)
$(CLINK) $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER) > clink.log
mv -f a.out.obj mbedtls.obj
strip --strip-unneeded -x mbedtls.obj
kpack mbedtls.obj
cp -f mbedtls.obj /home/max/.kex/root/RD/1/LIB
.SILENT:
%.o : %.c Makefile
$(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
%.o : %.asm Makefile
$(FASM) $< $@
.PHONY: all static clean
all: static
static: libmbedcrypto.a libmbedx509.a libmbedtls.a
# tls
libmbedtls.a: $(OBJS_TLS)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_TLS)
# x509
libmbedx509.a: $(OBJS_X509)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_X509)
# crypto
libmbedcrypto.a: $(OBJS_CRYPTO)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
.c.o:
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
clean:
ifndef WINDOWS
rm -f *.o libmbed*
else
del /Q /F *.o libmbed*
endif
clean:
rm -f $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_LIBC) $(OBJS_OTHER)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
void ___chkstk_ms() {}

View File

@ -0,0 +1,763 @@
/* TCC runtime library.
Parts of this code are (c) 2002 Fabrice Bellard
Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
//#include <stdint.h>
#define TCC_TARGET_I386
#define W_TYPE_SIZE 32
#define BITS_PER_UNIT 8
typedef int Wtype;
typedef unsigned int UWtype;
typedef unsigned int USItype;
typedef long long DWtype;
typedef unsigned long long UDWtype;
struct DWstruct {
Wtype low, high;
};
typedef union
{
struct DWstruct s;
DWtype ll;
} DWunion;
typedef long double XFtype;
#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
/* the following deal with IEEE single-precision numbers */
#define EXCESS 126
#define SIGNBIT 0x80000000
#define HIDDEN (1 << 23)
#define SIGN(fp) ((fp) & SIGNBIT)
#define EXP(fp) (((fp) >> 23) & 0xFF)
#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN)
#define PACK(s,e,m) ((s) | ((e) << 23) | (m))
/* the following deal with IEEE double-precision numbers */
#define EXCESSD 1022
#define HIDDEND (1 << 20)
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
(fp.l.lower >> 22))
#define HIDDEND_LL ((long long)1 << 52)
#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
/* the following deal with x86 long double-precision numbers */
#define EXCESSLD 16382
#define EXPLD(fp) (fp.l.upper & 0x7fff)
#define SIGNLD(fp) ((fp.l.upper) & 0x8000)
/* only for x86 */
union ldouble_long {
long double ld;
struct {
unsigned long long lower;
unsigned short upper;
} l;
};
union double_long {
double d;
#if 1
struct {
unsigned int lower;
int upper;
} l;
#else
struct {
int upper;
unsigned int lower;
} l;
#endif
long long ll;
};
union float_long {
float f;
unsigned int l;
};
/* XXX: we don't support several builtin supports for now */
#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
/* XXX: use gcc/tcc intrinsic ? */
#if defined(TCC_TARGET_I386)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
: "=r" ((USItype) (sh)), \
"=&r" ((USItype) (sl)) \
: "0" ((USItype) (ah)), \
"g" ((USItype) (bh)), \
"1" ((USItype) (al)), \
"g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
__asm__ ("mull %3" \
: "=a" ((USItype) (w0)), \
"=d" ((USItype) (w1)) \
: "%0" ((USItype) (u)), \
"rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
__asm__ ("divl %4" \
: "=a" ((USItype) (q)), \
"=d" ((USItype) (r)) \
: "0" ((USItype) (n0)), \
"1" ((USItype) (n1)), \
"rm" ((USItype) (dv)))
#define count_leading_zeros(count, x) \
do { \
USItype __cbtmp; \
__asm__ ("bsrl %1,%0" \
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
(count) = __cbtmp ^ 31; \
} while (0)
#else
#error unsupported CPU type
#endif
/* most of this code is taken from libgcc2.c from gcc */
UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
{
DWunion ww;
DWunion nn, dd;
DWunion rr;
UWtype d0, d1, n0, n1, n2;
UWtype q0, q1;
UWtype b, bm;
nn.ll = n;
dd.ll = d;
d0 = dd.s.low;
d1 = dd.s.high;
n0 = nn.s.low;
n1 = nn.s.high;
#if !defined(UDIV_NEEDS_NORMALIZATION)
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
/* Remainder in n0. */
}
else
{
/* qq = NN / 0d */
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
udiv_qrnnd (q1, n1, 0, n1, d0);
udiv_qrnnd (q0, n0, n1, n0, d0);
/* Remainder in n0. */
}
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = 0;
*rp = rr.ll;
}
}
#else /* UDIV_NEEDS_NORMALIZATION */
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
count_leading_zeros (bm, d0);
if (bm != 0)
{
/* Normalize, i.e. make the most significant bit of the
denominator set. */
d0 = d0 << bm;
n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
n0 = n0 << bm;
}
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
/* Remainder in n0 >> bm. */
}
else
{
/* qq = NN / 0d */
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
count_leading_zeros (bm, d0);
if (bm == 0)
{
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
conclude (the most significant bit of n1 is set) /\ (the
leading quotient digit q1 = 1).
This special case is necessary, not an optimization.
(Shifts counts of W_TYPE_SIZE are undefined.) */
n1 -= d0;
q1 = 1;
}
else
{
/* Normalize. */
b = W_TYPE_SIZE - bm;
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
udiv_qrnnd (q1, n1, n2, n1, d0);
}
/* n1 != d0... */
udiv_qrnnd (q0, n0, n1, n0, d0);
/* Remainder in n0 >> bm. */
}
if (rp != 0)
{
rr.s.low = n0 >> bm;
rr.s.high = 0;
*rp = rr.ll;
}
}
#endif /* UDIV_NEEDS_NORMALIZATION */
else
{
if (d1 > n1)
{
/* 00 = nn / DD */
q0 = 0;
q1 = 0;
/* Remainder in n1n0. */
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
/* 0q = NN / dd */
count_leading_zeros (bm, d1);
if (bm == 0)
{
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
conclude (the most significant bit of n1 is set) /\ (the
quotient digit q0 = 0 or 1).
This special case is necessary, not an optimization. */
/* The condition on the next line takes advantage of that
n1 >= d1 (true due to program flow). */
if (n1 > d1 || n0 >= d0)
{
q0 = 1;
sub_ddmmss (n1, n0, n1, n0, d1, d0);
}
else
q0 = 0;
q1 = 0;
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
UWtype m1, m0;
/* Normalize. */
b = W_TYPE_SIZE - bm;
d1 = (d1 << bm) | (d0 >> b);
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
udiv_qrnnd (q0, n1, n2, n1, d1);
umul_ppmm (m1, m0, q0, d0);
if (m1 > n1 || (m1 == n1 && m0 > n0))
{
q0--;
sub_ddmmss (m1, m0, m1, m0, d1, d0);
}
q1 = 0;
/* Remainder in (n1n0 - m1m0) >> bm. */
if (rp != 0)
{
sub_ddmmss (n1, n0, n1, n0, m1, m0);
rr.s.low = (n1 << b) | (n0 >> bm);
rr.s.high = n1 >> bm;
*rp = rr.ll;
}
}
}
}
ww.s.low = q0;
ww.s.high = q1;
return ww.ll;
}
#define __negdi2(a) (-(a))
long long __divdi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0) {
c = ~c;
vv.ll = __negdi2 (vv.ll);
}
w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
if (c)
w = __negdi2 (w);
return w;
}
// https://github.com/KaMeHb-UA/UE4m/blob/1d9ad5bfead06520570c7f24dad062f9f8717c1a/\
Engine/Extras/ThirdPartyNotUE/emsdk/emscripten/incoming/system/lib/compiler-rt/lib/\
builtins/divmoddi4.c
long long __divmoddi4(long long a, long long b, long long* rem)
{
long long d = __divdi3(a, b);
*rem = a - (d * b);
return d;
}
long long __moddi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0)
vv.ll = __negdi2 (vv.ll);
__udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w);
if (c)
w = __negdi2 (w);
return w;
}
unsigned long long __udivdi3(unsigned long long u, unsigned long long v)
{
return __udivmoddi4 (u, v, (UDWtype *) 0);
}
unsigned long long __umoddi3(unsigned long long u, unsigned long long v)
{
UDWtype w;
__udivmoddi4 (u, v, &w);
return w;
}
/* XXX: fix tcc's code generator to do this instead */
long long __ashrdi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = u.s.high >> (b - 32);
u.s.high = u.s.high >> 31;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
/* XXX: fix tcc's code generator to do this instead */
unsigned long long __lshrdi3(unsigned long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = (unsigned)u.s.high >> (b - 32);
u.s.high = 0;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = (unsigned)u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
/* XXX: fix tcc's code generator to do this instead */
long long __ashldi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.high = (unsigned)u.s.low << (b - 32);
u.s.low = 0;
} else if (b != 0) {
u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b));
u.s.low = (unsigned)u.s.low << b;
}
return u.ll;
#else
return a << b;
#endif
}
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
long long __tcc_cvt_ftol(long double x)
{
unsigned c0, c1;
long long ret;
__asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
c1 = c0 | 0x0C00;
__asm__ __volatile__ ("fldcw %0" : : "m" (c1));
__asm__ __volatile__ ("fistpll %0" : "=m" (ret));
__asm__ __volatile__ ("fldcw %0" : : "m" (c0));
return ret;
}
#endif
#endif /* !__x86_64__ */
/* XXX: fix tcc's code generator to do this instead */
float __floatundisf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (float)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (float)r;
}
}
double __floatundidf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (double)r;
}
}
long double __floatundixf(unsigned long long a)
{
DWunion uu;
XFtype r;
uu.ll = a;
if (uu.s.high >= 0) {
return (long double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (long double)r;
}
}
unsigned long long __fixunssfdi (float a1)
{
register union float_long fl1;
register int exp;
register unsigned long l;
fl1.f = a1;
if (fl1.l == 0)
return (0);
exp = EXP (fl1.l) - EXCESS - 24;
l = MANT(fl1.l);
if (exp >= 41)
return (unsigned long long)-1;
else if (exp >= 0)
return (unsigned long long)l << exp;
else if (exp >= -23)
return l >> -exp;
else
return 0;
}
unsigned long long __fixunsdfdi (double a1)
{
register union double_long dl1;
register int exp;
register unsigned long long l;
dl1.d = a1;
if (dl1.ll == 0)
return (0);
exp = EXPD (dl1) - EXCESSD - 53;
l = MANTD_LL(dl1);
if (exp >= 12)
return (unsigned long long)-1;
else if (exp >= 0)
return l << exp;
else if (exp >= -52)
return l >> -exp;
else
return 0;
}
unsigned long long __fixunsxfdi (long double a1)
{
register union ldouble_long dl1;
register int exp;
register unsigned long long l;
dl1.ld = a1;
if (dl1.l.lower == 0 && dl1.l.upper == 0)
return (0);
exp = EXPLD (dl1) - EXCESSLD - 64;
l = dl1.l.lower;
if (exp > 0)
return (unsigned long long)-1;
else if (exp >= -63)
return l >> -exp;
else
return 0;
}
long long __fixsfdi (float a1)
{
long long ret; int s;
ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
long long __fixdfdi (double a1)
{
long long ret; int s;
ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
long long __fixxfdi (long double a1)
{
long long ret; int s;
ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
#ifndef __TINYC__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
/* Avoid including stdlib.h because it is not easily available when
cross compiling */
#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */
void *malloc(unsigned long long);
void *memset(void *s, int c, size_t n);
void free(void*);
void abort(void);
#endif
enum __va_arg_type {
__va_gen_reg, __va_float_reg, __va_stack
};
//This should be in sync with the declaration on our include/stdarg.h
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
#undef __va_start
#undef __va_arg
#undef __va_copy
#undef __va_end
void __va_start(__va_list_struct *ap, void *fp)
{
memset(ap, 0, sizeof(__va_list_struct));
*ap = *(__va_list_struct *)((char *)fp - 16);
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
ap->reg_save_area = (char *)fp - 176 - 16;
}
void *__va_arg(__va_list_struct *ap,
enum __va_arg_type arg_type,
int size, int align)
{
size = (size + 7) & ~7;
align = (align + 7) & ~7;
switch (arg_type) {
case __va_gen_reg:
if (ap->gp_offset + size <= 48) {
ap->gp_offset += size;
return ap->reg_save_area + ap->gp_offset - size;
}
goto use_overflow_area;
case __va_float_reg:
if (ap->fp_offset < 128 + 48) {
ap->fp_offset += 16;
return ap->reg_save_area + ap->fp_offset - 16;
}
size = 8;
goto use_overflow_area;
case __va_stack:
use_overflow_area:
ap->overflow_arg_area += size;
ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align);
return ap->overflow_arg_area - size;
default:
#ifndef __TINYC__
fprintf(stderr, "unknown ABI type for __va_arg\n");
#endif
abort();
}
}
#endif /* __x86_64__ */
/* Flushing for tccrun */
#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386)
void __clear_cache(void *beginning, void *end)
{
}
#elif defined(TCC_TARGET_ARM)
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
void __clear_cache(void *beginning, void *end)
{
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
* However, there is no ARM asm parser in tcc so we use it for now */
#if 1
syscall(__ARM_NR_cacheflush, beginning, end, 0);
#else
__asm__ ("push {r7}\n\t"
"mov r7, #0xf0002\n\t"
"mov r2, #0\n\t"
"swi 0\n\t"
"pop {r7}\n\t"
"ret");
#endif
}
#else
#warning __clear_cache not defined for this architecture, avoid using tcc -run
#endif

View File

@ -0,0 +1,20 @@
/* memcpy( void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
void * memcpy( void * s1, const void * s2, size_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
while ( n-- )
{
*dest++ = *src++;
}
return s1;
}

View File

@ -0,0 +1,33 @@
/* memmove( void *, const void *, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
void * memmove( void * s1, const void * s2, size_t n )
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
if ( dest <= src )
{
while ( n-- )
{
*dest++ = *src++;
}
}
else
{
src += n;
dest += n;
while ( n-- )
{
*--dest = *--src;
}
}
return s1;
}

View File

@ -0,0 +1,20 @@
/* memset( void *, int, size_t )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#include <stdint.h>
void * memset( void * s, int c, size_t n )
{
unsigned char * p = ( unsigned char * ) s;
while ( n-- )
{
*p++ = ( unsigned char ) c;
}
return s;
}

View File

@ -0,0 +1,97 @@
format coff
use32 ; Tell compiler to use 32 bit instructions
;section '.export'
section '.text'
include '../../../../proc32.inc'
include '../../../../macros.inc'
include '../../../../debug-fdo.inc'
include '../../../../dll.inc'
public mbedtls_init
;;; Returns 0 on success. -1 on failure.
__DEBUG__ = 1
__DEBUG_LEVEL__ = 2
mbedtls_init:
pushad
stdcall dll.Load, @IMPORT
;int3
test eax, eax
jnz .error
popad
mov eax, 0
ret
.error:
popad
mov eax, -1
ret
gmtime:
jmp [localtime]
;include_debug_strings
section '.data'
align 4
@IMPORT:
library libc, 'libc.obj', networklib, 'network.obj'
import libc, \
memcmp, 'memcmp', \
printf, 'printf', \
free, 'free', \
strlen, 'strlen', \
_strcmp, 'strcmp', \
strstr, 'strstr', \
rand, 'rand', \
vsnprintf, 'vsnprintf', \
socket, 'socket', \
connect, 'connect', \
close , 'close', \
recv, 'recv', \
send, 'send', \
time, 'time', \
strncmp, 'strncmp', \
strncpy, 'strncpy', \
calloc, 'calloc' , \
snprintf, 'snprintf', \
localtime, 'localtime'
import networklib, \
inet_addr, 'inet_addr', \
inet_ntoa, 'inet_ntoa', \
getaddrinfo, 'getaddrinfo', \
freeaddrinfo, 'freeaddrinfo'
public inet_addr
public inet_ntoa
public getaddrinfo
public freeaddrinfo
public rand
public memcmp
public printf
public calloc
public free
public strlen
public _strcmp as 'strcmp'
public strstr
public gmtime
public vsnprintf
public socket
public connect
public close
public recv
public send
public time
public strncmp
public strncpy
public snprintf

View File

@ -44,9 +44,9 @@
#include <string.h>
#include "kosnet/socket.h"
#include "kosnet/network.h"
/*#include <sys/socket.h>
#include <sys/socket.h>
#include <clayer/network.h>
/*
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
@ -68,15 +68,17 @@
*/
static int net_prepare( void )
{
load_network_obj();
//load_network_obj();
return( 0 );
}
/*
* Initialize a context
*/
void mbedtls_net_init( mbedtls_net_context *ctx )
{
//printf("snprintf=%p\n", printf);
ctx->fd = -1;
}
@ -119,7 +121,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host,
break;
}
closesocket( ctx->fd );
close( ctx->fd );
ret = MBEDTLS_ERR_NET_CONNECT_FAILED;
}
@ -205,7 +207,7 @@ void mbedtls_net_free( mbedtls_net_context *ctx )
return;
//shutdown( ctx->fd, 2 );
closesocket( ctx->fd );
close( ctx->fd );
ctx->fd = -1;
}

View File

@ -70,7 +70,7 @@
* mbedtls_platform_zeroize() to use a suitable implementation for their
* platform and needs.
*/
static void * (* const volatile memset_func)( void *, int, size_t ) = memset;
static void * (* const volatile memset_func)( void *, int, size_t ) = &memset;
void mbedtls_platform_zeroize( void *buf, size_t len )
{
@ -86,7 +86,7 @@ void mbedtls_platform_zeroize( void *buf, size_t len )
#if !defined(_WIN32) && (defined(unix) || \
defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \
defined(__MACH__)))
#include <unistd.h>
//#include <unistd.h>
#endif /* !_WIN32 && (unix || __unix || __unix__ ||
* (__APPLE__ && __MACH__)) */

View File

@ -1 +0,0 @@
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.

View File

@ -1,24 +1,12 @@
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
APP_DYNAMIC_LDS=D:\KOSSDK\newlib/app-dynamic.lds
LIBDIR=D:\KOSSDK\kos32-msys-5.4.0\win32\lib
MAIN_TARGET=ssl_client1
FASM = fasm
TCC_DIR = /home/max/kolibri-svn/programs/develop/ktcc/trunk
TCC= $(TCC_DIR)/bin/kos32-tcc
CC=kos32-gcc
LD=kos32-ld
OBJCOPY=kos32-objcopy
CFLAGS= -I../../include -I$(TCC_DIR)/libc.obj/include -stack=10000
CCFLAGS=-c -fomit-frame-pointer -I $(NEWLIB_INCLUDES) -I../../include -I../../kosnet/include -Wall -Wextra
LDFLAGS=-call_shared -nostdlib --subsystem console -T $(APP_DYNAMIC_LDS) --image-base 0 -L $(LIBDIR) -L ../../kosnet -L ../../library -lmbedtls -lmbedx509 -lmbedcrypto -lkosnet -lgcc -lapp -lc.dll
all: ssl_client1
ssl_client1: ssl_client1.o
$(LD) ssl_client1.o -o $(MAIN_TARGET) $(LDFLAGS)
$(OBJCOPY) $(MAIN_TARGET) -O binary
ssl_client1.o: ssl_client1.c
$(CC) $(CCFLAGS) ssl_client1.c -o ssl_client1.o
all:
$(FASM) load_mbedtls.asm
$(TCC) $(CFLAGS) ssl_client1.c load_mbedtls.o -o ssl_client1 -ltcc -lc.obj
clean:
del *.o
del $(MAIN_TARGET)
rm -f *.o ssl_client1

View File

@ -0,0 +1,153 @@
format elf
use32
section '.text' executable
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
purge section,mov,add,sub
include '../../../../../dll.inc'
public mbedtls_load
public mbedtls_ctr_drbg_free
public mbedtls_ctr_drbg_init
public mbedtls_ctr_drbg_random
public mbedtls_ctr_drbg_seed
public mbedtls_debug_set_threshold
public mbedtls_entropy_free
public mbedtls_entropy_func
public mbedtls_entropy_init
public mbedtls_net_connect
public mbedtls_net_free
public mbedtls_net_init
public mbedtls_net_recv
public mbedtls_net_send
public mbedtls_ssl_close_notify
public mbedtls_ssl_conf_authmode
public mbedtls_ssl_conf_ca_chain
public mbedtls_ssl_conf_dbg
public mbedtls_ssl_config_defaults
public mbedtls_ssl_config_free
public mbedtls_ssl_config_init
public mbedtls_ssl_conf_rng
public mbedtls_ssl_free
public mbedtls_ssl_get_verify_result
public mbedtls_ssl_handshake
public mbedtls_ssl_init
public mbedtls_ssl_read
public mbedtls_ssl_set_bio
public mbedtls_ssl_set_hostname
public mbedtls_ssl_setup
public mbedtls_ssl_write
public mbedtls_strerror
public _mbedtls_test_cas_pem
public _mbedtls_test_cas_pem_len
public mbedtls_x509_crt_free
public mbedtls_x509_crt_init
public mbedtls_x509_crt_parse
public mbedtls_x509_crt_verify_info
public mbedtls_init
public __snprintf_test
__snprintf_test:
ret
;;; Returns 0 on success. -1 on failure.
proc mbedtls_load
stdcall dll.Load, @IMPORT
test eax, eax
jnz error
mov eax, 0
ret
error:
mov eax, -1
ret
endp
mbedtls_ctr_drbg_free: jmp [_mbedtls_ctr_drbg_free ]
mbedtls_ctr_drbg_init: jmp [_mbedtls_ctr_drbg_init ]
mbedtls_ctr_drbg_random: jmp [_mbedtls_ctr_drbg_random ]
mbedtls_ctr_drbg_seed: jmp [_mbedtls_ctr_drbg_seed ]
mbedtls_debug_set_threshold: jmp [_mbedtls_debug_set_threshold ]
mbedtls_entropy_free: jmp [_mbedtls_entropy_free ]
mbedtls_entropy_func: jmp [_mbedtls_entropy_func ]
mbedtls_entropy_init: jmp [_mbedtls_entropy_init ]
mbedtls_net_connect: jmp [_mbedtls_net_connect ]
mbedtls_net_free: jmp [_mbedtls_net_free ]
mbedtls_net_init: jmp [_mbedtls_net_init ]
mbedtls_net_recv: jmp [_mbedtls_net_recv ]
mbedtls_net_send: jmp [_mbedtls_net_send ]
mbedtls_ssl_close_notify: jmp [_mbedtls_ssl_close_notify ]
mbedtls_ssl_conf_authmode: jmp [_mbedtls_ssl_conf_authmode ]
mbedtls_ssl_conf_ca_chain: jmp [_mbedtls_ssl_conf_ca_chain ]
mbedtls_ssl_conf_dbg: jmp [_mbedtls_ssl_conf_dbg ]
mbedtls_ssl_config_defaults: jmp [_mbedtls_ssl_config_defaults ]
mbedtls_ssl_config_free: jmp [_mbedtls_ssl_config_free ]
mbedtls_ssl_config_init: jmp [_mbedtls_ssl_config_init ]
mbedtls_ssl_conf_rng: jmp [_mbedtls_ssl_conf_rng ]
mbedtls_ssl_free: jmp [_mbedtls_ssl_free ]
mbedtls_ssl_get_verify_result: jmp [_mbedtls_ssl_get_verify_result ]
mbedtls_ssl_handshake: jmp [_mbedtls_ssl_handshake ]
mbedtls_ssl_init: jmp [_mbedtls_ssl_init ]
mbedtls_ssl_read: jmp [_mbedtls_ssl_read ]
mbedtls_ssl_set_bio: jmp [_mbedtls_ssl_set_bio ]
mbedtls_ssl_set_hostname: jmp [_mbedtls_ssl_set_hostname ]
mbedtls_ssl_setup: jmp [_mbedtls_ssl_setup ]
mbedtls_ssl_write: jmp [_mbedtls_ssl_write ]
mbedtls_strerror: jmp [_mbedtls_strerror]
;mbedtls_test_cas_pem: jmp [_mbedtls_test_cas_pem ]
;mbedtls_test_cas_pem_len: jmp [_mbedtls_test_cas_pem_len ]
mbedtls_x509_crt_free: jmp [_mbedtls_x509_crt_free ]
mbedtls_x509_crt_init: jmp [_mbedtls_x509_crt_init ]
mbedtls_x509_crt_parse: jmp [_mbedtls_x509_crt_parse]
mbedtls_x509_crt_verify_info: jmp [_mbedtls_x509_crt_verify_info ]
mbedtls_init: jmp [_mbedtls_init]
;__snprintf_test: jmp[___snprintf_test]
section '.data' writable
@IMPORT:
library mbedtls, 'mbedtls.obj'
import mbedtls, \
_mbedtls_init , 'mbedtls_init' ,\
_mbedtls_strerror , 'mbedtls_strerror' ,\
_mbedtls_test_cas_pem , 'mbedtls_test_cas_pem' ,\
_mbedtls_test_cas_pem_len , 'mbedtls_test_cas_pem_len' ,\
_mbedtls_x509_crt_free , 'mbedtls_x509_crt_free' ,\
_mbedtls_x509_crt_init , 'mbedtls_x509_crt_init' ,\
_mbedtls_x509_crt_parse , 'mbedtls_x509_crt_parse' ,\
_mbedtls_x509_crt_verify_info , 'mbedtls_x509_crt_verify_info' ,\
_mbedtls_ctr_drbg_free , 'mbedtls_ctr_drbg_free' ,\
_mbedtls_ctr_drbg_init , 'mbedtls_ctr_drbg_init' ,\
_mbedtls_ctr_drbg_random , 'mbedtls_ctr_drbg_random' ,\
_mbedtls_ctr_drbg_seed , 'mbedtls_ctr_drbg_seed' ,\
_mbedtls_debug_set_threshold , 'mbedtls_debug_set_threshold' ,\
_mbedtls_entropy_free , 'mbedtls_entropy_free' ,\
_mbedtls_entropy_func , 'mbedtls_entropy_func' ,\
_mbedtls_entropy_init , 'mbedtls_entropy_init' ,\
_mbedtls_net_connect , 'mbedtls_net_connect' ,\
_mbedtls_net_free , 'mbedtls_net_free' ,\
_mbedtls_net_init , 'mbedtls_net_init' ,\
_mbedtls_net_recv , 'mbedtls_net_recv' ,\
_mbedtls_net_send , 'mbedtls_net_send' ,\
_mbedtls_ssl_close_notify , 'mbedtls_ssl_close_notify' ,\
_mbedtls_ssl_conf_authmode , 'mbedtls_ssl_conf_authmode' ,\
_mbedtls_ssl_conf_ca_chain , 'mbedtls_ssl_conf_ca_chain' ,\
_mbedtls_ssl_conf_dbg , 'mbedtls_ssl_conf_dbg' ,\
_mbedtls_ssl_config_defaults , 'mbedtls_ssl_config_defaults' ,\
_mbedtls_ssl_config_free , 'mbedtls_ssl_config_free' ,\
_mbedtls_ssl_config_init , 'mbedtls_ssl_config_init' ,\
_mbedtls_ssl_conf_rng , 'mbedtls_ssl_conf_rng' ,\
_mbedtls_ssl_free , 'mbedtls_ssl_free' ,\
_mbedtls_ssl_get_verify_result , 'mbedtls_ssl_get_verify_result' ,\
_mbedtls_ssl_handshake , 'mbedtls_ssl_handshake' ,\
_mbedtls_ssl_init , 'mbedtls_ssl_init' ,\
_mbedtls_ssl_read , 'mbedtls_ssl_read' ,\
_mbedtls_ssl_set_bio , 'mbedtls_ssl_set_bio' ,\
_mbedtls_ssl_set_hostname , 'mbedtls_ssl_set_hostname' ,\
_mbedtls_ssl_setup , 'mbedtls_ssl_setup' ,\
_mbedtls_ssl_write , 'mbedtls_ssl_write'

View File

@ -1 +0,0 @@
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.

View File

@ -20,16 +20,17 @@
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <sys/ksys.h>
//#if defined(MBEDTLS_PLATFORM_C)
//#include "mbedtls/platform.h"
//#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_time time
@ -37,16 +38,16 @@
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#define mbedtls_exit exit
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif /* MBEDTLS_PLATFORM_C */
#define MBEDTLS_EXIT_SUCCESS 0
#define MBEDTLS_EXIT_FAILURE -1
//#endif /* MBEDTLS_PLATFORM_C */
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
//#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
!defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
!defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C) || \
!defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
int main( void )
/*int main( void )
{
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
"MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
@ -55,7 +56,7 @@ int main( void )
"not defined.\n");
return( 0 );
}
#else
//#else*/
#include "mbedtls/net_sockets.h"
#include "mbedtls/debug.h"
@ -70,12 +71,21 @@ int main( void )
//#define SERVER_PORT "443"
//#define SERVER_NAME "wikipedia.org"
//#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
char SERVER_PORT[16];
char SERVER_NAME[128];
char GET_REQUEST[512];
static char SERVER_PORT[16];
static char SERVER_NAME[128];
static char GET_REQUEST[512];
#define DEBUG_LEVEL 1
extern int *_mbedtls_test_cas_pem_len;
extern char* _mbedtls_test_cas_pem;
#define mbedtls_test_cas_pem_len *_mbedtls_test_cas_pem_len
#define mbedtls_test_cas_pem _mbedtls_test_cas_pem
//gmtime(time_t t){puts("gmtime stub");};
//int load_network_obj(){return networklib_init();}
static void my_debug( void *ctx, int level,
const char *file, int line,
@ -90,11 +100,21 @@ static void my_debug( void *ctx, int level,
int main( void )
{
if(mbedtls_load()){
printf("mbedtls.obj not load!\n");
return -1;
}
if(mbedtls_init()){
puts("mbedtls.obj not init!");
return -1;
}
puts("Enter SERVER_NAME : ");
gets(SERVER_NAME);
puts("Enter SERVER_PORT : ");
gets(SERVER_PORT);
sprintf(GET_REQUEST, "GET / HTTP/1.1\r\nHost: %s\r\n\r\n", SERVER_NAME);
//puts(GET_REQUEST);
int ret = 1, len;
int exit_code = MBEDTLS_EXIT_FAILURE;
@ -102,7 +122,6 @@ int main( void )
uint32_t flags;
unsigned char buf[1024];
const char *pers = "ssl_client1";
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
@ -110,7 +129,7 @@ int main( void )
mbedtls_x509_crt cacert;
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold( DEBUG_LEVEL );
// mbedtls_debug_set_threshold( DEBUG_LEVEL );
#endif
/*
@ -121,10 +140,8 @@ int main( void )
mbedtls_ssl_config_init( &conf );
mbedtls_x509_crt_init( &cacert );
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_printf( "\n . Seeding the random number generator..." );
//fflush( stdout );
mbedtls_entropy_init( &entropy );
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
@ -133,15 +150,15 @@ int main( void )
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
goto exit;
}
mbedtls_printf( " ok\n" );
/*
* 0. Initialize certificates
*/
*/;
mbedtls_printf( " . Loading the CA root certificate ..." );
//fflush( stdout );
ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
mbedtls_test_cas_pem_len );
if( ret < 0 )
@ -151,7 +168,7 @@ int main( void )
}
mbedtls_printf( " ok (%d skipped)\n", ret );
/*
* 1. Start the connection
*/
@ -204,7 +221,6 @@ int main( void )
}
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
/*
* 4. Handshake
*/
@ -301,15 +317,14 @@ int main( void )
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
#ifdef MBEDTLS_ERROR_C
//#ifdef MBEDTLS_ERROR_C
if( exit_code != MBEDTLS_EXIT_SUCCESS )
{
char error_buf[100];
static char error_buf[100];
mbedtls_strerror( ret, error_buf, 100 );
mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
#endif
//#endif
mbedtls_net_free( &server_fd );
@ -322,7 +337,7 @@ exit:
return( exit_code );
}
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
/*#endif MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C &&
MBEDTLS_X509_CRT_PARSE_C */

View File

@ -1,6 +0,0 @@
Test KOS image features:
- rev 8498
- kernel unpacked (to run faster in qemu for windows)
- kolibrios/ directory with lib/libc.dll (newlib) inside automatically mounts on start
- DOCKY removed from autorun.dat (cuz its very annoying :D )
- removed 3d, demos, games, fnav, kfm, animage, iconedit, etc. to get free space for things above