From 5eb6770760ebbc5317ac6d2a62ebe1bee8fa06e0 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 13 Dec 2021 15:58:19 +0300 Subject: [PATCH] Improve build on Windows via llvm-mingw --- .gitattributes | 1 + .gitignore | 2 ++ isatty.c | 15 ----------- isatty.h | 6 ----- makefile | 52 +++++++++++++++++++++++++------------ shell.c | 3 +-- test/makefile | 11 +++++--- umka.asm | 36 ++++++++++++++++--------- umka.h | 9 ++++--- {win32 => windows}/pci.c | 4 ++- {win32 => windows}/pci.h | 4 +-- {win32 => windows}/thread.c | 2 ++ 12 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 .gitattributes delete mode 100644 isatty.c delete mode 100644 isatty.h rename {win32 => windows}/pci.c (80%) rename {win32 => windows}/pci.h (56%) rename {win32 => windows}/thread.c (89%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..aba79ee --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.ref.log text eol=auto diff --git a/.gitignore b/.gitignore index 36b3f73..8893771 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ covpreproc *.aml ignore.* t.d +*~ +*.exe diff --git a/isatty.c b/isatty.c deleted file mode 100644 index 6364ee4..0000000 --- a/isatty.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "isatty.h" - -#ifdef _WIN32 - -int isatty(int fd) { - // TODO: Make it work for win32 - return 0; -} - -int fileno(FILE *fp) { - // TODO: Make it work for win32 - return 0; -} - -#endif // _WIN32 diff --git a/isatty.h b/isatty.h deleted file mode 100644 index a4813c3..0000000 --- a/isatty.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include - -int isatty(int fd); -int fileno(FILE *fp); diff --git a/makefile b/makefile index 570ba5d..322274e 100644 --- a/makefile +++ b/makefile @@ -2,32 +2,56 @@ ifndef KOLIBRIOS $(error "Set KOLIBRIOS environment variable to KolibriOS root") endif -FASM ?= fasm -dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 +ifndef HOST + $(error "Set HOST variable to linux/windows") +endif + +FASM_EXE ?= fasm +FASM_INCLUDE=$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash +FASM_FLAGS=-dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 -dHOST=$(HOST) + CC ?= gcc WARNINGS_COMMON=-Wall -Wextra \ -Wnull-dereference -Wshadow -Wformat=2 -Wswitch -Wswitch-enum \ -Wpedantic \ #-Wconversion -Wsign-conversion -NOWARNINGS_COMMON=-Wno-address-of-packed-member -Wno-missing-prototype-for-cc +NOWARNINGS_COMMON=-Wno-address-of-packed-member -ifeq ($(CC),gcc) +ifneq (,$(findstring gcc,$(CC))) WARNINGS=$(WARNINGS_COMMON) -Wduplicated-cond -Wduplicated-branches -Wrestrict -Wlogical-op -Wjump-misses-init NOWARNINGS=$(NOWARNINGS_COMMON) -else ifeq ($(CC),clang) +else ifneq (,$(findstring clang,$(CC))) WARNINGS=$(WARNINGS_COMMON) - NOWARNINGS=$(NOWARNINGS_COMMON) + NOWARNINGS=$(NOWARNINGS_COMMON) -Wno-missing-prototype-for-cc else - $(error compiler $(CC) is not supported) + $(error your compiler is not supported) endif CFLAGS=$(WARNINGS) $(NOWARNINGS) -std=c11 -g -O0 -D_FILE_OFFSET_BITS=64 \ - -DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L -Ilinux -fno-pie + -DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L -I$(HOST) -fno-pie CFLAGS_32=$(CFLAGS) -m32 LDFLAGS=-no-pie LDFLAGS_32=$(LDFLAGS) -m32 +ifeq ($(HOST),linux) + FASM_INCLUDE=$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash + FASM=INCLUDE="$(FASM_INCLUDE)" $(FASM_EXE) $(FASM_FLAGS) +else ifeq ($(HOST),windows) + FASM_INCLUDE=$(KOLIBRIOS)\kernel\trunk;$(KOLIBRIOS)\programs\develop\libraries\libcrash\hash + FASM=set INCLUDE=$(FASM_INCLUDE)&&$(FASM_EXE) $(FASM_FLAGS) +else + $(error your OS is not supported) +endif + +ifeq ($(HOST),linux) all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \ umka.lst tags covpreproc default.skn skin.skn +else ifeq ($(HOST),windows) +all: umka_shell umka.sym umka.prp \ + umka.lst default.skn skin.skn +else + $(error your OS is not supported) +endif .PHONY: test @@ -38,7 +62,7 @@ covpreproc: covpreproc.c $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o vnet.o \ - lodepng.o pci.o thread.o util.o getopt.o isatty.o + lodepng.o pci.o thread.o util.o getopt.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o thread.o @@ -52,17 +76,16 @@ umka_gen_devices_dat: umka_gen_devices_dat.o umka.o pci.o thread.o util.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld umka.o umka.fas: umka.asm - INCLUDE="$(KOLIBRIOS)/kernel/trunk;$(KOLIBRIOS)/programs/develop/libraries/libcrash/hash" \ - $(FASM) $< umka.o -s umka.fas -m 2000000 + $(FASM) $< umka.o -s umka.fas shell.o: shell.c $(CC) $(CFLAGS_32) -c $< -thread.o: linux/thread.c +thread.o: $(HOST)/thread.c $(CC) $(CFLAGS_32) -c $< -pci.o: linux/pci.c - $(CC) $(CFLAGS_32) -c $< +pci.o: $(HOST)/pci.c + $(CC) $(CFLAGS_32) -std=gnu11 -c $< lodepng.o: lodepng.c lodepng.h $(CC) $(CFLAGS_32) -c $< @@ -70,9 +93,6 @@ lodepng.o: lodepng.c lodepng.h getopt.o: getopt.c getopt.h $(CC) $(CFLAGS_32) -c $< -isatty.o: isatty.c isatty.h - $(CC) $(CFLAGS_32) -c $< - util.o: util.c util.h umka.h $(CC) $(CFLAGS_32) -c $< diff --git a/shell.c b/shell.c index e539ec2..cecf5b6 100644 --- a/shell.c +++ b/shell.c @@ -35,7 +35,6 @@ #include #endif -#include "isatty.h" #include "getopt.h" #include "vdisk.h" #include "vnet.h" @@ -45,7 +44,7 @@ #include "util.h" #include "lodepng.h" -#define PATH_MAX 4096 +//#define PATH_MAX 4096 #define FGETS_BUF_LEN 4096 #define MAX_COMMAND_ARGS 42 #define PRINT_BYTES_PER_LINE 32 diff --git a/test/makefile b/test/makefile index c0acc90..d6b3dde 100644 --- a/test/makefile +++ b/test/makefile @@ -1,7 +1,7 @@ ifndef COVERAGE -UMKA_SHELL=../umka_shell +UMKA_SHELL ?= ../umka_shell else -UMKA_SHELL=sudo taskset 1 ../umka_shell -c +UMKA_SHELL ?= sudo taskset 1 ../umka_shell -c endif xfs_tests := $(addsuffix .out.log, $(basename $(wildcard *\#xfs_*.t))) @@ -48,9 +48,14 @@ arp: $(arp_tests) acpi: $(acpi_tests) %.out.log: %.t - $(UMKA_SHELL) < $*.t > $@ + $(UMKA_SHELL) -i $*.t +ifeq ($(HOST),linux) @ cmp $*.out.log $*.ref.log @ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi +else + @ comp /M $*.out.log $*.ref.log +# @ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi +endif collect_coverage: ../covpreproc ../umka.lst 0x34 coverage.* > ../umka.cov diff --git a/umka.asm b/umka.asm index feb2e53..1184627 100644 --- a/umka.asm +++ b/umka.asm @@ -1,9 +1,11 @@ ; TODO: SPDX -if defined WIN32 +if HOST eq windows format MS COFF -else +else if HOST eq linux format ELF +else + error "Your OS is not supported" end if ; win32: @@ -21,7 +23,7 @@ end if ; pubsym name, "name", 20 -> public name as "name" ; pubsym name, "name", no_mangle -> public name as "name" macro pubsym name, marg1, marg2 { - if defined WIN32 + if HOST eq windows if marg1 eq no_mangle public name else if marg1 eqtype 20 @@ -37,12 +39,14 @@ macro pubsym name, marg1, marg2 { else public name as '_' # `name end if - else + else if HOST eq linux if marg1 eqtype 'string' public name as marg1 else public name end if + else + error "Your OS is not supported" end if } @@ -53,14 +57,16 @@ macro pubsym name, marg1, marg2 { ; extrn name -> extrn name ; extrn name, 20 -> extrn name macro extrn name, [argsize] { - if defined WIN32 + if HOST eq windows if argsize eqtype 20 extrn '_' # `name # '@' # `argsize as name else extrn '_' # `name as name end if - else + else if HOST eq linux extrn name + else + error "Your OS is not supported" end if } @@ -192,11 +198,13 @@ include 'macros.inc' macro diff16 msg,blah2,blah3 { if msg eq "end of .data segment" - if defined WIN32 + if HOST eq windows section '.bss.8k' writeable align 8192 - else + else if HOST eq linux ; fasm doesn't align on 65536, but ld script does section '.bss.aligned65k' writeable align 65536 + else + error "Your OS is not supported" end if bss_base: end if @@ -683,14 +691,14 @@ endp proc sys_msg_board cmp cl, 0x0d jz @f -if defined WIN32 +if HOST eq windows extrn putchar pushad push ecx call putchar pop ecx popad -else +else if HOST eq linux pushad mov eax, SYS_WRITE mov ebx, STDOUT @@ -700,6 +708,8 @@ else int 0x80 pop ecx popad +else + error "Your OS is not supported" end if @@: ret @@ -888,11 +898,13 @@ restore sys_msg_board,delay_ms coverage_end: -if defined WIN32 +if HOST eq windows section '.data.8k' writeable align 8192 -else +else if HOST eq linux ; fasm doesn't align on 65536, but ld script does section '.data.aligned65k' writeable align 65536 +else + error "Your OS is not supported" end if pubsym umka_tool umka_tool dd ? diff --git a/umka.h b/umka.h index 2db3313..ca4cbda 100644 --- a/umka.h +++ b/umka.h @@ -3,15 +3,16 @@ #include #include +#include +#define UMKA_PATH_MAX 4096 // TODO: Cleanup #ifndef _WIN32 #include // for irq0: siginfo_t #else -typedef int32_t ssize_t; -typedef int64_t off_t; -#define PATH_MAX 255 -typedef void siginfo_t +//typedef int32_t ssize_t; +//typedef int64_t off_t; +typedef void siginfo_t; #endif #define STDCALL __attribute__((__stdcall__)) diff --git a/win32/pci.c b/windows/pci.c similarity index 80% rename from win32/pci.c rename to windows/pci.c index 5b06210..5fef01f 100755 --- a/win32/pci.c +++ b/windows/pci.c @@ -1,8 +1,10 @@ #include "pci.h" +#include #include +#include "../umka.h" -char pci_path[PATH_MAX] = "."; +char pci_path[UMKA_PATH_MAX] = "."; __attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev, uint32_t fun, uint32_t offset, diff --git a/win32/pci.h b/windows/pci.h similarity index 56% rename from win32/pci.h rename to windows/pci.h index 92ebb42..d8426ba 100755 --- a/win32/pci.h +++ b/windows/pci.h @@ -1,8 +1,8 @@ #ifndef PCI_H_INCLUDED #define PCI_H_INCLUDED -#define PATH_MAX 255 +#include "../umka.h" -extern char pci_path[PATH_MAX]; +extern char pci_path[UMKA_PATH_MAX]; #endif // PCI_H_INCLUDED diff --git a/win32/thread.c b/windows/thread.c similarity index 89% rename from win32/thread.c rename to windows/thread.c index d0bdff2..3a5e994 100755 --- a/win32/thread.c +++ b/windows/thread.c @@ -1,3 +1,5 @@ +#include + void reset_procmask(void) { printf("STUB: %s:%d", __FILE__, __LINE__); }