From c79ade6609700b3c3377fb9060c83229ebf1d298 Mon Sep 17 00:00:00 2001 From: julianb0 Date: Sun, 30 Jun 2019 13:46:44 +0200 Subject: [PATCH] m --- ka/dos.k | 2 +- vm/dv/CPUDEV | 5 ++++- vm/dv/DEVCTL | 2 +- vm/in/JUMPS | 23 +++++++++++++++++++++-- vm/in/SUPER | 12 ++++++++++++ vm/in/jumps.c | 21 +++++++++++++++++++++ vm/in/super.c | 11 +++++++++++ vm/la/{karch.lang => kvisc.lang} | 7 +++---- vm/pc/except.c | 2 +- vm/pc/main.c | 1 - vm/pc/sym.c | 2 +- 11 files changed, 76 insertions(+), 12 deletions(-) rename vm/la/{karch.lang => kvisc.lang} (91%) diff --git a/ka/dos.k b/ka/dos.k index da0b667..0d9f860 100644 --- a/ka/dos.k +++ b/ka/dos.k @@ -12,7 +12,7 @@ start: call dir_test - ;hlt + hlt ; Wait for and print input indefinitely .1: diff --git a/vm/dv/CPUDEV b/vm/dv/CPUDEV index bbd83b4..5144ffe 100644 --- a/vm/dv/CPUDEV +++ b/vm/dv/CPUDEV @@ -46,7 +46,10 @@ IDT slots: 513-767 maskable hardware interrupts (see ...), OVERRIDES slot 512 768 a handler in this slot will receive all non-maskable hardware interrupts - 769-1023 non-maskable hardware interrupts (see ...), OVERRIDES slot 768 + 769-1022 non-maskable hardware interrupts (see ...), OVERRIDES slot 768 + + 1023 Uncatchable exception, guarantees shutdown. Only throwable by supervisor + via the CRASH instruction, or by the machine in case of irrecoverable failure A handler for some E/I must use the 'idtdone' iocall to show that it is done dealing with a certain E/I. If that same E/I happens again before that, the following happens: diff --git a/vm/dv/DEVCTL b/vm/dv/DEVCTL index 043a037..6601ac6 100644 --- a/vm/dv/DEVCTL +++ b/vm/dv/DEVCTL @@ -10,7 +10,7 @@ It will take registers ax0-ax7 as its parameters, and return a value in rdx:rax. The return value in rax is a status value: - ≥0 ok (>0 only if meaningful) + ≥0 ok (>0 only when meaningful) -1 unspecified error -2 no such device -3 device powered off diff --git a/vm/in/JUMPS b/vm/in/JUMPS index e7ad97f..cb0f43c 100644 --- a/vm/in/JUMPS +++ b/vm/in/JUMPS @@ -6,7 +6,7 @@ #---------------------------------------------------------------------------# # -# Unconditional jump (JMP) instruction +# Absolute jump (JMP) instruction # # RIP = $1 # @@ -14,7 +14,7 @@ j ri jmp ri # -# RCX-dependent jump (LOOP) instruction +# RCX-dependent absolute jump (LOOP) instruction # # IF (RCX > 0) THEN # RCX = RCX - 1 @@ -22,3 +22,22 @@ jmp ri # FI # loop ri + +# +# Relative jump (BCH) instruction ("branch") +# +# RIP = RIP + $1 +# +b ri +bch ri + +# +# RCX-dependent relative jump (BOOP) instruction +# +# IF (RCX > 0) THEN +# RCX = RCX - 1 +# RIP = RIP + $1 +# FI +# +boop ri + diff --git a/vm/in/SUPER b/vm/in/SUPER index 6e98a2f..119d90f 100644 --- a/vm/in/SUPER +++ b/vm/in/SUPER @@ -5,6 +5,18 @@ # Supervisor only instructions # #---------------------------------------------------------------------------# +# +# Crash virtual machine (CRASH) +# +# THROW #1023 +# +# Throws: +# #SYS if not in supervisor mode +# #ILL if disabled through DV +# #1023 otherwise +# +crash + # # Initiate machine shutdown (STOP) # diff --git a/vm/in/jumps.c b/vm/in/jumps.c index 17d9617..7d672a6 100644 --- a/vm/in/jumps.c +++ b/vm/in/jumps.c @@ -28,3 +28,24 @@ IMPL_START_1(loop) } IMPL_END; +IMPL_START_1(b) +{ + rip += v1; +} +IMPL_END; + +IMPL_START_1(bch) +{ + rip += v1; +} +IMPL_END; + +IMPL_START_1(boop) +{ + if (rcx > 0) { + rcx--; + rip += v1; + } +} +IMPL_END; + diff --git a/vm/in/super.c b/vm/in/super.c index d5b28a2..ad3875c 100644 --- a/vm/in/super.c +++ b/vm/in/super.c @@ -13,6 +13,13 @@ IMPL_START_0(stop) } IMPL_END; +IMPL_START_0(crash) +{ + CHK_SUPERV(); + _except(ctx, 1023, "CRASH instruction"); +} +IMPL_END; + IMPL_START_0(hlt) { CHK_SUPERV(); @@ -26,7 +33,11 @@ IMPL_START_0(hlt) die(0); if (evt.type == SDL_KEYDOWN) + { console_handle_input(ctx, evt.key.keysym.sym); + if (evt.key.keysym.sym == SDLK_RETURN) + break; + } } } } diff --git a/vm/la/karch.lang b/vm/la/kvisc.lang similarity index 91% rename from vm/la/karch.lang rename to vm/la/kvisc.lang index 0525227..578569a 100644 --- a/vm/la/karch.lang +++ b/vm/la/kvisc.lang @@ -5,7 +5,7 @@ --> - + \ @@ -56,14 +56,13 @@ (inv|flg|[re]?pc) - [a-z]x[0-9]+ - [re][a-z]x + [re][a-z][xi]l? + [a-z]x[0-9]+[bwdlq]? [c-gs]s [re]?flags ([gil]d)?tr - [re]?[ds]il? [re]?[sbi]pl? [x-z]mm[0-9]+ [re]?[a-d][xhl] diff --git a/vm/pc/except.c b/vm/pc/except.c index 0aa178b..5eb2381 100644 --- a/vm/pc/except.c +++ b/vm/pc/except.c @@ -32,7 +32,7 @@ void _except(ctx_t *ctx, int _code, char *fmt, ...) exit(-12); } - if (code >= IDT_SLOTS) + if (code >= IDT_SLOTS || code == 1023) goto actually_die; // diff --git a/vm/pc/main.c b/vm/pc/main.c index fd1cad2..a899936 100644 --- a/vm/pc/main.c +++ b/vm/pc/main.c @@ -140,7 +140,6 @@ int main(int argc, char **argv) main_ctx.mz = MEMSIZE; main_ctx.get = bget; - main_ctx.rf[RIP] = MEMOFF; if (main_ctx.mp == 0) { diff --git a/vm/pc/sym.c b/vm/pc/sym.c index f099f0d..68babd2 100644 --- a/vm/pc/sym.c +++ b/vm/pc/sym.c @@ -27,7 +27,7 @@ int create_symtab(const char *name) logerr("Symbol addresses in symbol table not in increasing order\n"); logerr("Previous symbol: '%s' '%lu'\n", symtab[it-1].name, prev_addr); logerr("Current symbol: '%s' '%lu'\n", buf, addr); - exit(-55); + exit(-1); } prev_addr = addr;