Variety of changes (got Cuik compiling with it)

This commit is contained in:
NeGate 2023-01-27 01:50:37 -05:00
parent 1ab4169567
commit 4287d9f601
10 changed files with 154 additions and 142 deletions

View File

@ -2,12 +2,12 @@
:: Compile UTF-8 resource into .obj file :: Compile UTF-8 resource into .obj file
:: this .obj file has to be linked to the executable using it, NOT archived :: this .obj file has to be linked to the executable using it, NOT archived
:: together with ciabatta.lib. :: together with ciabatta.lib.
windres -o utf8.obj utf8.rc rem windres -o utf8.obj utf8.rc
ld -relocatable -o libwinsane.obj utf8.obj
:: Compile chkstk :: Compile chkstk
nasm src\_win\chkstk.asm -ochkstk.o -fwin64 nasm src\_win\chkstk.asm -ochkstk.o -fwin64
:: Compile the rest of the party :: Compile the rest of the party
clang -Wall src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nodefaultlibs -g -mfma rem clang -Wall src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nodefaultlibs -g -mfma
cuik src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nostdlib
lib /nologo /out:ciabatta.lib chkstk.o ciabatta.obj lib /nologo /out:ciabatta.lib chkstk.o ciabatta.obj

View File

@ -6,37 +6,37 @@
#define TSS_DTOR_ITERATIONS 32 #define TSS_DTOR_ITERATIONS 32
#if !defined(_timespec_defined) #if !defined(_timespec_defined)
#define _timespec_defined #define _timespec_defined
typedef unsigned long long time_t; typedef unsigned long long time_t;
struct timespec { struct timespec {
time_t tv_sec; time_t tv_sec;
long tv_nsec; long tv_nsec;
}; };
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
typedef struct cnd_t { typedef struct cnd_t {
int idk_yet; int idk_yet;
} cnd_t; } cnd_t;
typedef struct thrd_t { typedef struct thrd_t {
void* handle; void* handle;
} thrd_t; } thrd_t;
typedef struct tss_t { typedef struct tss_t {
int idk_yet; int idk_yet;
} tss_t; } tss_t;
typedef struct mtx_t { typedef struct mtx_t {
int type; int type;
// Done to handle recursive mutexes // Done to handle recursive mutexes
unsigned long recursion; unsigned long recursion;
unsigned long owner; unsigned long owner;
_Atomic(int) counter; _Atomic(int) counter;
void* semaphore; void* semaphore;
} mtx_t; } mtx_t;
#else #else
#error "Not implemented" #error "Not implemented"
#endif #endif
typedef void(*tss_dtor_t) (void*); typedef void(*tss_dtor_t) (void*);

View File

@ -108,18 +108,9 @@ static int cmdline_to_argv8(const wchar_t *cmd, char **argv) {
return argc; return argc;
} }
static wchar_t *get_wcmdline() {
// That's right, that's where windows hid the command line
TEB *teb = (TEB *)__readgsqword(offsetof(NT_TIB, Self));
PEB *peb = teb->ProcessEnvironmentBlock;
RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters;
UNICODE_STRING command_line_str = params->CommandLine;
return command_line_str.Buffer;
}
static char **get_command_args(int *argc_ptr) { static char **get_command_args(int *argc_ptr) {
static char *argv_buffer[CMDLINE_ARGV_MAX]; static char *argv_buffer[CMDLINE_ARGV_MAX];
wchar_t *cmdline = get_wcmdline(); wchar_t *cmdline = GetCommandLineW();
*argc_ptr = cmdline_to_argv8(cmdline, argv_buffer); *argc_ptr = cmdline_to_argv8(cmdline, argv_buffer);
return argv_buffer; return argv_buffer;
} }

View File

@ -1,10 +1,10 @@
u64 __security_cookie; u64 __security_cookie;
static void __security_init_cookie() { void __security_init_cookie() {
// They say it's a random number so I generated // They say it's a random number so I generated
// one using numbergenerator.org // one using numbergenerator.org
__security_cookie = 0xb26e04cc62ba48a; __security_cookie = 0xb26e04cc62ba48aULL;
} }
void __security_check_cookie(u64 retrieved) { void __security_check_cookie(u64 retrieved) {

View File

@ -4,8 +4,8 @@
#pragma weak WinMain #pragma weak WinMain
int main(int argc, char** argv); int main(int argc, char** argv);
int wmain(int argc, wchar_t** argv, wchar_t **envp); // int wmain(int argc, wchar_t** argv, wchar_t **envp);
int WinMain(HINSTANCE inst, HINSTANCE pinst, LPSTR cmdline, int showcmd); // int WinMain(HINSTANCE inst, HINSTANCE pinst, LPSTR cmdline, int showcmd);
_Noreturn void mainCRTStartup() { _Noreturn void mainCRTStartup() {
_setup_eh(); _setup_eh();
@ -24,7 +24,7 @@ _Noreturn void mainCRTStartup() {
exit(exit_code); exit(exit_code);
} }
_Noreturn void WinMainCRTStartup() { /*_Noreturn void WinMainCRTStartup() {
_setup_eh(); _setup_eh();
_setup_heap(); _setup_heap();
_setup_timer(); _setup_timer();
@ -39,4 +39,4 @@ _Noreturn void WinMainCRTStartup() {
int exit_code = WinMain(inst, 0, cmdline, SW_SHOWDEFAULT); int exit_code = WinMain(inst, 0, cmdline, SW_SHOWDEFAULT);
exit(exit_code); exit(exit_code);
} }*/

View File

@ -12,4 +12,3 @@ static void _setup_eh();
static void _setup_heap(); static void _setup_heap();
static void _setup_io(); static void _setup_io();
static void _close_io(); static void _close_io();
static void __security_init_cookie();

View File

@ -25,15 +25,15 @@
// Intrinsics // Intrinsics
#if !defined(__FMA__) #if !defined(__FMA__)
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
#error "Get a better CPU (the kind that supports FMA) or enable -mfma" #error "Get a better CPU (the kind that supports FMA) or enable -mfma"
#endif #endif
#endif #endif
// xmmintrin.h depends on mm_malloc.h, which itself includes other CRT headers // xmmintrin.h depends on mm_malloc.h, which itself includes other CRT headers
// Which introduces compiler errors. Actually does it really matter? I would // Which introduces compiler errors. Actually does it really matter? I would
// need to check again // need to check again
#undef __STDC_HOSTED__ #undef __STDC_HOSTED__
#include <immintrin.h> // #include <immintrin.h>
#include <xmmintrin.h> #include <xmmintrin.h>
#include "intrin.h" #include "intrin.h"
@ -65,15 +65,15 @@
// Windows stuff // Windows stuff
#if defined(CIABATTA_WIN) #if defined(CIABATTA_WIN)
#include "_win/win.h" #include "_win/win.h"
#include "_win/cookie.c" #include "_win/cookie.c"
#include "_win/assert.c" #include "_win/assert.c"
#include "_win/cmdline.c" #include "_win/cmdline.c"
#include "_win/entry.c" #include "_win/entry.c"
#include "_win/environment.c" #include "_win/environment.c"
#include "_win/heap.c" #include "_win/heap.c"
#include "_win/signal.c" #include "_win/signal.c"
#include "_win/stdio.c" #include "_win/stdio.c"
#include "_win/threads.c" #include "_win/threads.c"
#include "_win/time.c" #include "_win/time.c"
#endif #endif

View File

@ -75,6 +75,28 @@ long double fminl(long double x, long double y) {
return fmin(x, y); return fmin(x, y);
} }
#ifdef __CUIK__
#warning "Cuik doesn't support the FMA intrinsics... fix that NeGate"
double fma(double x, double y, double z) {
return (x * y) + z;
}
float fmaf(float x, float y, float z) {
return (x * y) + z;
}
long double fmal(long double x, long double y, long double z) {
return (x * y) + z;
}
double sqrt(double x) {
return 0.0;
}
float sqrtf(float x) {
return 0.0;
}
#else
double fma(double x, double y, double z) { double fma(double x, double y, double z) {
__m128d xd = _mm_set_sd(x); __m128d xd = _mm_set_sd(x);
__m128d yd = _mm_set_sd(y); __m128d yd = _mm_set_sd(y);
@ -115,4 +137,4 @@ float sqrtf(float x) {
long double sqrtl(long double x) { long double sqrtl(long double x) {
return sqrt(x); return sqrt(x);
} }
#endif

View File

@ -7,7 +7,7 @@ int cnt;
int f(void* thr_data) int f(void* thr_data)
{ {
for(int n = 0; n < 1000; ++n) { for(int n = 0; n < 100000; ++n) {
atomic_fetch_add_explicit(&acnt, 1, memory_order_relaxed); // atomic atomic_fetch_add_explicit(&acnt, 1, memory_order_relaxed); // atomic
++cnt; // undefined behavior, in practice some updates missed ++cnt; // undefined behavior, in practice some updates missed
} }