aboutsummaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
Diffstat (limited to 'target')
-rw-r--r--target/kos/.gitignore3
-rw-r--r--target/kos/Makefile13
-rw-r--r--target/kos/crt0.asm68
-rw-r--r--target/kos/main.c14
-rw-r--r--target/kos/package.config4
-rw-r--r--target/unix/main.c17
-rw-r--r--target/unix/platform.h11
7 files changed, 130 insertions, 0 deletions
diff --git a/target/kos/.gitignore b/target/kos/.gitignore
new file mode 100644
index 0000000..722062b
--- /dev/null
+++ b/target/kos/.gitignore
@@ -0,0 +1,3 @@
+.knightos/
+bin/
+*.o
diff --git a/target/kos/Makefile b/target/kos/Makefile
new file mode 100644
index 0000000..db9d68e
--- /dev/null
+++ b/target/kos/Makefile
@@ -0,0 +1,13 @@
+include .knightos/variables.make
+
+#INCLUDE+=add to your include path
+
+HEADERS:=$(wildcard *.h)
+
+ALL_TARGETS:=$(BIN)ducky
+
+$(BIN)ducky: $(OUT)main.o $(OUT)crt0.o $(OUT)../../src/ducky.o
+ mkdir -p $(BIN)
+ scas $(ASFLAGS) $(OUT)crt0.o $(LIBRARIES) $(OUT)main.o $(OUT)../../src/ducky.o -o $(BIN)ducky
+
+include .knightos/sdk.make
diff --git a/target/kos/crt0.asm b/target/kos/crt0.asm
new file mode 100644
index 0000000..51acf08
--- /dev/null
+++ b/target/kos/crt0.asm
@@ -0,0 +1,68 @@
+#include <kernel.inc>
+ .db "KEXC"
+ .db KEXC_ENTRY_POINT
+ .dw __start
+ .db KEXC_STACK_SIZE
+ .dw 20
+ .db KEXC_NAME
+ .dw __name
+ .db KEXC_HEADER_END
+__name:
+ .db "ducky", 0
+__start:
+ call __relocate_data
+ call __initialize_globals
+ jp _main
+
+_exit:
+ ; Note: status code is discarded
+ pcall(exitThread)
+__exit_end:
+.function _exit, _exit, _exit_end
+
+__relocate_data:
+ ; + 4 because the KEXC header has two static pointers
+ ; TODO: There's probably a better way of doing that
+ ld hl, __scas_relocatable_data + 4
+.loop:
+ ld e, (hl) \ inc hl
+ ld d, (hl) \ inc hl
+ ld bc, 0
+ pcall(cpBCDE)
+ ret z
+
+ ex de, hl
+ kld(bc, 0)
+ add hl, bc
+ push de
+ ld e, (hl) \ inc hl
+ ld d, (hl)
+ ex de, hl \ add hl, bc \ ex de, hl
+ ld (hl), d \ dec hl
+ ld (hl), e
+ pop de
+ ex de, hl
+ jr .loop
+
+__initialize_globals:
+ ; Note: this could be more optimized if we could toggle auto-relocation in code
+ ld hl, __s_initialized_end
+ ld bc, __s_initialized
+ scf \ ccf
+ sbc hl, bc
+ ld b, h \ ld c, l
+ ld a, b
+ or c
+ ret z
+ ld hl, __s_initializer
+ ld de, __s_initialized
+ ldir
+ ret
+
+; Assign some labels to the start of some sections
+.area _INITIALIZER
+__s_initializer:
+.area _INITIALIZED
+__s_initialized:
+.area _INITIALIZED_END
+__s_initialized_end:
diff --git a/target/kos/main.c b/target/kos/main.c
new file mode 100644
index 0000000..7326b4f
--- /dev/null
+++ b/target/kos/main.c
@@ -0,0 +1,14 @@
+#include <knightos/display.h>
+#include <knightos/system.h>
+
+/* Warning! C support in KnightOS is highly experimental. Your mileage may vary. */
+
+void main() {
+ SCREEN *screen;
+ get_lcd_lock();
+ screen = screen_allocate();
+ screen_clear(screen);
+ draw_string(screen, 0, 0, "Hello world!");
+ screen_draw(screen);
+ while (1);
+}
diff --git a/target/kos/package.config b/target/kos/package.config
new file mode 100644
index 0000000..9cd874c
--- /dev/null
+++ b/target/kos/package.config
@@ -0,0 +1,4 @@
+name=ducky
+repo=community
+version=0.1.0
+-sdk-template=c
diff --git a/target/unix/main.c b/target/unix/main.c
new file mode 100644
index 0000000..a2db705
--- /dev/null
+++ b/target/unix/main.c
@@ -0,0 +1,17 @@
+#include <ducky.h>
+#include <platform.h>
+
+int main(int argc, char *argv[])
+{
+ if(argc == 2)
+ {
+ int fd = open(argv[1], O_RDONLY);
+ ducky_main(fd);
+ close(fd);
+ }
+ else
+ {
+ printf("Usage: %s FILE\n", argv[0]);
+ }
+ return 0;
+}
diff --git a/target/unix/platform.h b/target/unix/platform.h
new file mode 100644
index 0000000..ca331e2
--- /dev/null
+++ b/target/unix/platform.h
@@ -0,0 +1,11 @@
+#include <bsd/string.h>
+
+#include <fcntl.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>