Adding Windows.

This commit is contained in:
Brad Nelson
2021-01-04 15:55:51 -08:00
parent f9bf1c005f
commit a7fdad4a8a
5 changed files with 112 additions and 24 deletions

View File

@ -3,17 +3,44 @@ GEN = $(OUT)/gen
RES = $(OUT)/resources
WEB = $(OUT)/web
POSIX = $(OUT)/posix
WINDOWS = $(OUT)/windows
ARDUINO = $(OUT)/arduino
CFLAGS=-O2 -Wall -Werror -I ./ -I $(OUT)
CFLAGS = -Wall -Werror \
-O2 \
-fno-exceptions \
-s \
-fomit-frame-pointer \
-fno-stack-protector \
-fno-ident -Wl,--build-id=none \
-ffunction-sections -fdata-sections \
-Wl,--gc-sections \
-fmerge-all-constants \
-I ./ -I $(OUT)
STRIP_ARGS = -S \
--strip-unneeded \
--remove-section=.note.gnu.gold-version \
--remove-section=.comment \
--remove-section=.note \
--remove-section=.note.gnu.build-id \
--remove-section=.note.ABI-tag
LIBS=-ldl
WIN_ARCH=i686
WINFLAGS = -mwindows -luser32
TARGETS = $(WEB)/terminal.html \
$(WEB)/ueforth.js \
$(POSIX)/ueforth \
$(WINDOWS)/uEforth.exe \
$(ARDUINO)/ueforth.ino
all: $(TARGETS) $(RES)/eforth.ico tests
all: $(TARGETS) tests
clean:
rm -rf $(OUT)
# ---- TESTS ----
tests: core_test
@ -22,6 +49,8 @@ core_test: $(POSIX)/ueforth common/core_test.fs \
echo "include common/core_test.fs" | $< | \
diff - common/core_test.fs.golden
# ---- GENERATED ----
$(GEN):
mkdir -p $@
@ -29,6 +58,10 @@ POSIX_BOOT = common/boot.fs posix/posix.fs
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@
WINDOWS_BOOT = common/boot.fs
$(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN)
echo "ok" | cat $(WINDOWS_BOOT) - | $< boot >$@
ARDUINO_BOOT = common/boot.fs
$(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN)
echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@
@ -42,6 +75,8 @@ $(GEN)/web_cases.js: $(GEN)/dump_web_opcodes | $(GEN)
$(GEN)/web_dict.js: $(GEN)/dump_web_opcodes | $(GEN)
$< dict >$@
# ---- RESOURCES ----
$(RES):
mkdir -p $@
@ -65,6 +100,13 @@ ICON_SIZES = $(RES)/eforth256x256.png \
$(RES)/eforth.ico: $(ICON_SIZES)
convert $^ $< $@
WINDOWS_RESOURCES = $(RES)/ueforth_res.o
$(WINDOWS_RESOURCES): windows/ueforth.rc $(RES)/eforth.ico
$(WIN_ARCH)-w64-mingw32-windres $< $@
# ---- WEB ----
$(WEB):
mkdir -p $(WEB)
@ -79,6 +121,8 @@ $(WEB)/ueforth.js: \
$(GEN)/web_cases.js | $(WEB)
$^ >$@
# ---- POSIX ----
$(POSIX):
mkdir -p $@
@ -89,6 +133,22 @@ $(POSIX)/ueforth: \
$(GEN)/posix_boot.h | $(POSIX)
$(CC) $(CFLAGS) $< -o $@ $(LIBS)
# ---- WINDOWS ----
$(WINDOWS):
mkdir -p $@
$(WINDOWS)/uEforth.exe: \
windows/windows_main.c \
common/opcodes.h \
common/core.h \
$(GEN)/windows_boot.h \
$(WINDOWS_RESOURCES) | $(WINDOWS)
$(WIN_ARCH)-w64-mingw32-gcc \
$(CFLAGS) $(WINFLAGS) $< $(WINDOWS_RESOURCES) -o $@
# ---- ARDUINO ----
$(ARDUINO):
mkdir -p $@
@ -100,5 +160,3 @@ $(ARDUINO)/ueforth.ino: \
$(GEN)/arduino_boot.h | $(ARDUINO)
$^ >$@
clean:
rm -rf $(OUT)

20
ueforth/common/calling.h Normal file
View File

@ -0,0 +1,20 @@
#define CALLING_OPCODE_LIST \
X("CALL0", OP_CALL0, tos = ((cell_t (*)()) tos)()) \
X("CALL1", OP_CALL1, tos = ((cell_t (*)()) tos)(*sp); --sp) \
X("CALL2", OP_CALL2, tos = ((cell_t (*)()) tos)(sp[-1], *sp); sp -= 2) \
X("CALL3", OP_CALL3, tos = ((cell_t (*)()) tos)(sp[-2], sp[-1], *sp); sp -= 3) \
X("CALL4", OP_CALL4, tos = ((cell_t (*)()) tos)(sp[-3], sp[-2], sp[-1], \
*sp); sp -= 4) \
X("CALL5", OP_CALL5, tos = ((cell_t (*)()) tos)(sp[-4], sp[-3], sp[-2], \
sp[-1], *sp); sp -= 5) \
X("CALL6", OP_CALL6, tos = ((cell_t (*)()) tos)(sp[-5], sp[-4], sp[-3], \
sp[-2], sp[-1], *sp); sp -= 6) \
X("CALL7", OP_CALL7, tos = ((cell_t (*)()) tos)(sp[-6], sp[-5], sp[-4], \
sp[-3], sp[-2], sp[-1], *sp); sp -= 7) \
X("CALL8", OP_CALL8, tos = ((cell_t (*)()) tos)(sp[-7], sp[-6], sp[-5], \
sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 8) \
X("CALL9", OP_CALL9, tos = ((cell_t (*)()) tos)(sp[-8], sp[-7], sp[-6], \
sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 9) \
X("CALL10", OP_CALL10, tos = ((cell_t (*)()) tos)(sp[-9], sp[-8], sp[-7], \
sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 10) \

View File

@ -2,37 +2,21 @@
#include <sys/mman.h>
#include "common/opcodes.h"
#include "common/calling.h"
#define HEAP_SIZE (10 * 1024 * 1024)
#define STACK_SIZE (16 * 1024)
#define PLATFORM_OPCODE_LIST \
X("DLSYM", OP_DLSYM, tos = (cell_t) dlsym((void *) *sp, (void *) tos); --sp) \
X("CALL0", OP_CALL0, tos = ((cell_t (*)()) tos)()) \
X("CALL1", OP_CALL1, tos = ((cell_t (*)()) tos)(*sp); --sp) \
X("CALL2", OP_CALL2, tos = ((cell_t (*)()) tos)(sp[-1], *sp); sp -= 2) \
X("CALL3", OP_CALL3, tos = ((cell_t (*)()) tos)(sp[-2], sp[-1], *sp); sp -= 3) \
X("CALL4", OP_CALL4, tos = ((cell_t (*)()) tos)(sp[-3], sp[-2], sp[-1], \
*sp); sp -= 4) \
X("CALL5", OP_CALL5, tos = ((cell_t (*)()) tos)(sp[-4], sp[-3], sp[-2], \
sp[-1], *sp); sp -= 5) \
X("CALL6", OP_CALL6, tos = ((cell_t (*)()) tos)(sp[-5], sp[-4], sp[-3], \
sp[-2], sp[-1], *sp); sp -= 6) \
X("CALL7", OP_CALL7, tos = ((cell_t (*)()) tos)(sp[-6], sp[-5], sp[-4], \
sp[-3], sp[-2], sp[-1], *sp); sp -= 7) \
X("CALL8", OP_CALL8, tos = ((cell_t (*)()) tos)(sp[-7], sp[-6], sp[-5], \
sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 8) \
X("CALL9", OP_CALL9, tos = ((cell_t (*)()) tos)(sp[-8], sp[-7], sp[-6], \
sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 9) \
X("CALL10", OP_CALL10, tos = ((cell_t (*)()) tos)(sp[-9], sp[-8], sp[-7], \
sp[-6], sp[-5], sp[-4], sp[-3], sp[-2], sp[-1], *sp); sp -= 10) \
CALLING_OPCODE_LIST \
#include "common/core.h"
#include "gen/posix_boot.h"
#define HEAP_SIZE (10 * 1024 * 1024)
int main(int argc, char *argv[]) {
void *heap = mmap(0, HEAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ueforth(argc, argv, heap, boot, sizeof(boot));
return 1;
}

View File

@ -0,0 +1 @@
IDI_MAIN_ICON ICON "out/resources/eforth.ico"

View File

@ -0,0 +1,25 @@
#include "windows.h"
#include "common/opcodes.h"
#include "common/calling.h"
#define HEAP_SIZE (10 * 1024 * 1024)
#define STACK_SIZE (16 * 1024)
#define PLATFORM_OPCODE_LIST \
X("GETPROCADDRES", OP_GETPROCADDRESS, \
tos = (cell_t) GetProcAddress((HMODULE) *sp, (LPCSTR) tos); --sp) \
CALLING_OPCODE_LIST \
#include "common/core.h"
#include "gen/windows_boot.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev,
PSTR pCmdLine, int nCmdShow) {
void *heap = VirtualAlloc(
NULL, HEAP_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
ueforth(0, 0, heap, boot, sizeof(boot));
return 1;
}