diff --git a/Makefile b/Makefile index 7b1f952..5cfcb1d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: kas kpc: @cd vm && make --no-print-directory verbose=no -kas: kpc as/k-as.py as/regs.lst +kas: kpc as/k-as.py as/regs.lst as/ @cp vm/in/instrs.lst as DOSK = $(shell find ka -name '*.k') @@ -16,7 +16,7 @@ vm/a.out: $(DOSK) .PHONY: clean clean: - @cd vm && make clean + @cd vm && make clean --no-print-directory @rm -f vm/a.out vm/k.exe vm/stdout.txt as/instrs.lst test: kas vm/a.out diff --git a/ka/main.k b/ka/main.k index 028db5f..743928a 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,7 +5,6 @@ ; Main function ; main: - call itoa_test ret stosb_test: diff --git a/vm/Makefile b/vm/Makefile index 0ae0bf1..d2f1981 100644 --- a/vm/Makefile +++ b/vm/Makefile @@ -32,7 +32,7 @@ all: k.exe $(OBJDIR)/%.o: %.c @mkdir -p $(shell dirname $@) @cc $(FLAGS) -c $< -o $@ - @if true || [ $(verbose) = "yes" ]; then \ + @if [ $(verbose) = "yes" ]; then \ echo ${CL2}[$@] ${CL}object file generated.${CL3};\ fi @@ -47,7 +47,7 @@ in/instrs.lst: in/INSTRS in/arch_i.py @cd in && python3 arch_i.py clean: - @rm -f $(OBJDIR)/*/*.o in/arch_i.h + @rm -f $(OBJDIR)/*/*.o in/arch_i.h in/instrs.lst @rm -f $(OBJDIR)/*/*.d k.exe: in/instrs.lst $(obj) diff --git a/vm/dv/cpu.c b/vm/dv/cpudev.c similarity index 84% rename from vm/dv/cpu.c rename to vm/dv/cpudev.c index 1b0c5d1..d35ec35 100644 --- a/vm/dv/cpu.c +++ b/vm/dv/cpudev.c @@ -1,7 +1,7 @@ // The OS/K Team licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#include +#include long cpudev_testfn(ctx_t *ctx, dev_t *dev) { @@ -30,9 +30,9 @@ dev_t cpudev = .modl = "Prisma 1", .vend = "The OS/K Team", - .major = 0, - .minor = 1, - .revis = 0, + .major = KARCH_MAJOR, + .minor = KARCH_MINOR, + .revis = KARCH_REVIS, .fpwon = cpudev_poweron, }; diff --git a/vm/dv/memdev.c b/vm/dv/memdev.c new file mode 100644 index 0000000..bda7951 --- /dev/null +++ b/vm/dv/memdev.c @@ -0,0 +1,26 @@ +// The OS/K Team licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include + +long memdev_poweron(ctx_t *ctx, dev_t *dev) +{ + dev->state = DEVGOOD; + + return 0; +} + +dev_t memdev = +{ + .type = "ram", + .name = "K-RAM", + .modl = "", + .vend = "The OS/K Team", + + .major = KARCH_MAJOR, + .minor = KARCH_MINOR, + .revis = KARCH_REVIS, + + .fpwon = memdev_poweron, +}; + diff --git a/vm/dv/devctl.c b/vm/in/devctl.c similarity index 98% rename from vm/dv/devctl.c rename to vm/in/devctl.c index 678733c..d339823 100644 --- a/vm/dv/devctl.c +++ b/vm/in/devctl.c @@ -1,7 +1,7 @@ // The OS/K Team licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#include +#include #include // diff --git a/vm/dv/DEVAPI b/vm/pc/DEVAPI similarity index 96% rename from vm/dv/DEVAPI rename to vm/pc/DEVAPI index 4e3866e..1a13d66 100644 --- a/vm/dv/DEVAPI +++ b/vm/pc/DEVAPI @@ -32,7 +32,6 @@ They consist of the following functions: 3 ptr Write device vendor into buffer 4 rax=major, rdx=minor 5 rax=feats, rdx=revis - 6-31 (reserved) The slots for "iocall" are device-defined. (They correspond to the "fslots" array of the dev_t structure.) See that diff --git a/vm/pc/arch.h b/vm/pc/arch.h index 2f7028c..40c5f7a 100644 --- a/vm/pc/arch.h +++ b/vm/pc/arch.h @@ -35,6 +35,10 @@ typedef struct dev_t dev_t; void log(const char *, ...); void vlog(const char *, va_list); +#define KARCH_MAJOR 0 +#define KARCH_MINOR 1 +#define KARCH_REVIS 0 + struct ctx_t { reg_t *r; diff --git a/vm/dv/dev.c b/vm/pc/dev.c similarity index 74% rename from vm/dv/dev.c rename to vm/pc/dev.c index 7e15799..349f4bd 100644 --- a/vm/dv/dev.c +++ b/vm/pc/dev.c @@ -1,9 +1,50 @@ // The OS/K Team licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#include +#include -static_assert(sizeof(dev_t) % 8 == 0, ""); +//----------------------------------------------------------------------------// + +// +// Add new builtin devices here +// + +extern dev_t cpudev, memdev; + +static dev_t *arch_d[] = +{ + &cpudev, + &memdev, + + NULL, +}; + + +int devinitall(ctx_t *ctx) +{ + size_t it; + + for (it = 0; arch_d[it] != NULL; it++) { + // log("Adding device %s\n", arch_d[it]->name); + if (devinit(ctx, arch_d[it]) < 0) + return -1; + } + + return 0; +} + +int devfiniall(ctx_t *ctx) +{ + int failed = 0; + + while (ctx->dh) + if (devfini(ctx, ctx->dh) < 0) + failed = -1; + + return failed; +} + +//----------------------------------------------------------------------------// dev_t *devalloc(void) { @@ -17,6 +58,8 @@ void devfree(dev_t *dev) free(dev); } +//----------------------------------------------------------------------------// + dev_t *devget(ctx_t *ctx, int idx) { if (idx < 0) @@ -65,6 +108,8 @@ int devinit(ctx_t *ctx, dev_t *dev) return 0; } +//----------------------------------------------------------------------------// + // NEVER detach while some assembly code // may still be running on the vm! void devdetach(ctx_t *ctx, dev_t *dev) @@ -109,20 +154,3 @@ err: devdetach(ctx, dev); return -1; } - -int devinitall(ctx_t *ctx) -{ - return devinit(ctx, &cpudev); -} - -int devfiniall(ctx_t *ctx) -{ - int failed = 0; - - while (ctx->dh) - if (devfini(ctx, ctx->dh) < 0) - failed = -1; - - return failed; -} - diff --git a/vm/dv/dev.h b/vm/pc/dev.h similarity index 100% rename from vm/dv/dev.h rename to vm/pc/dev.h diff --git a/vm/pc/except.c b/vm/pc/except.c index 0e0a140..3b39b0b 100644 --- a/vm/pc/except.c +++ b/vm/pc/except.c @@ -1,7 +1,7 @@ // The OS/K Team licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#include +#include #include void _except(ctx_t *ctx, int code, char *fmt, ...) diff --git a/vm/pc/main.c b/vm/pc/main.c index 84437fe..2c0dc45 100644 --- a/vm/pc/main.c +++ b/vm/pc/main.c @@ -2,7 +2,7 @@ // See the LICENSE file in the project root for more information. #include -#include +#include #include #include