Adding Windows.
This commit is contained in:
@ -3,17 +3,44 @@ GEN = $(OUT)/gen
|
|||||||
RES = $(OUT)/resources
|
RES = $(OUT)/resources
|
||||||
WEB = $(OUT)/web
|
WEB = $(OUT)/web
|
||||||
POSIX = $(OUT)/posix
|
POSIX = $(OUT)/posix
|
||||||
|
WINDOWS = $(OUT)/windows
|
||||||
ARDUINO = $(OUT)/arduino
|
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
|
LIBS=-ldl
|
||||||
|
|
||||||
|
WIN_ARCH=i686
|
||||||
|
WINFLAGS = -mwindows -luser32
|
||||||
|
|
||||||
TARGETS = $(WEB)/terminal.html \
|
TARGETS = $(WEB)/terminal.html \
|
||||||
$(WEB)/ueforth.js \
|
$(WEB)/ueforth.js \
|
||||||
$(POSIX)/ueforth \
|
$(POSIX)/ueforth \
|
||||||
|
$(WINDOWS)/uEforth.exe \
|
||||||
$(ARDUINO)/ueforth.ino
|
$(ARDUINO)/ueforth.ino
|
||||||
|
|
||||||
all: $(TARGETS) $(RES)/eforth.ico tests
|
all: $(TARGETS) tests
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OUT)
|
||||||
|
|
||||||
|
# ---- TESTS ----
|
||||||
|
|
||||||
tests: core_test
|
tests: core_test
|
||||||
|
|
||||||
@ -22,6 +49,8 @@ core_test: $(POSIX)/ueforth common/core_test.fs \
|
|||||||
echo "include common/core_test.fs" | $< | \
|
echo "include common/core_test.fs" | $< | \
|
||||||
diff - common/core_test.fs.golden
|
diff - common/core_test.fs.golden
|
||||||
|
|
||||||
|
# ---- GENERATED ----
|
||||||
|
|
||||||
$(GEN):
|
$(GEN):
|
||||||
mkdir -p $@
|
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)
|
$(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN)
|
||||||
echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@
|
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
|
ARDUINO_BOOT = common/boot.fs
|
||||||
$(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN)
|
$(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN)
|
||||||
echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@
|
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)
|
$(GEN)/web_dict.js: $(GEN)/dump_web_opcodes | $(GEN)
|
||||||
$< dict >$@
|
$< dict >$@
|
||||||
|
|
||||||
|
# ---- RESOURCES ----
|
||||||
|
|
||||||
$(RES):
|
$(RES):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
@ -65,6 +100,13 @@ ICON_SIZES = $(RES)/eforth256x256.png \
|
|||||||
$(RES)/eforth.ico: $(ICON_SIZES)
|
$(RES)/eforth.ico: $(ICON_SIZES)
|
||||||
convert $^ $< $@
|
convert $^ $< $@
|
||||||
|
|
||||||
|
WINDOWS_RESOURCES = $(RES)/ueforth_res.o
|
||||||
|
|
||||||
|
$(WINDOWS_RESOURCES): windows/ueforth.rc $(RES)/eforth.ico
|
||||||
|
$(WIN_ARCH)-w64-mingw32-windres $< $@
|
||||||
|
|
||||||
|
# ---- WEB ----
|
||||||
|
|
||||||
$(WEB):
|
$(WEB):
|
||||||
mkdir -p $(WEB)
|
mkdir -p $(WEB)
|
||||||
|
|
||||||
@ -79,6 +121,8 @@ $(WEB)/ueforth.js: \
|
|||||||
$(GEN)/web_cases.js | $(WEB)
|
$(GEN)/web_cases.js | $(WEB)
|
||||||
$^ >$@
|
$^ >$@
|
||||||
|
|
||||||
|
# ---- POSIX ----
|
||||||
|
|
||||||
$(POSIX):
|
$(POSIX):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
@ -89,6 +133,22 @@ $(POSIX)/ueforth: \
|
|||||||
$(GEN)/posix_boot.h | $(POSIX)
|
$(GEN)/posix_boot.h | $(POSIX)
|
||||||
$(CC) $(CFLAGS) $< -o $@ $(LIBS)
|
$(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):
|
$(ARDUINO):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
@ -100,5 +160,3 @@ $(ARDUINO)/ueforth.ino: \
|
|||||||
$(GEN)/arduino_boot.h | $(ARDUINO)
|
$(GEN)/arduino_boot.h | $(ARDUINO)
|
||||||
$^ >$@
|
$^ >$@
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(OUT)
|
|
||||||
|
|||||||
20
ueforth/common/calling.h
Normal file
20
ueforth/common/calling.h
Normal 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) \
|
||||||
|
|
||||||
@ -2,37 +2,21 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "common/opcodes.h"
|
#include "common/opcodes.h"
|
||||||
|
#include "common/calling.h"
|
||||||
|
|
||||||
|
#define HEAP_SIZE (10 * 1024 * 1024)
|
||||||
#define STACK_SIZE (16 * 1024)
|
#define STACK_SIZE (16 * 1024)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
X("DLSYM", OP_DLSYM, tos = (cell_t) dlsym((void *) *sp, (void *) tos); --sp) \
|
X("DLSYM", OP_DLSYM, tos = (cell_t) dlsym((void *) *sp, (void *) tos); --sp) \
|
||||||
X("CALL0", OP_CALL0, tos = ((cell_t (*)()) tos)()) \
|
CALLING_OPCODE_LIST \
|
||||||
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) \
|
|
||||||
|
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
|
|
||||||
#include "gen/posix_boot.h"
|
#include "gen/posix_boot.h"
|
||||||
|
|
||||||
#define HEAP_SIZE (10 * 1024 * 1024)
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
void *heap = mmap(0, HEAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
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));
|
ueforth(argc, argv, heap, boot, sizeof(boot));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
1
ueforth/windows/ueforth.rc
Normal file
1
ueforth/windows/ueforth.rc
Normal file
@ -0,0 +1 @@
|
|||||||
|
IDI_MAIN_ICON ICON "out/resources/eforth.ico"
|
||||||
25
ueforth/windows/windows_main.c
Normal file
25
ueforth/windows/windows_main.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user