diff --git a/ka/ABI b/ka/ABI index 9693e39..f1f4a8d 100644 --- a/ka/ABI +++ b/ka/ABI @@ -16,8 +16,7 @@ A function's assembly code looks like this: ... leave ret -'N' is the number of local variables used by the function, -and is omitted if there are none ('enter' alone takes N=0). +'N' is the number of local variables used by the function. The above code is equivalent to the following, but much faster: label: diff --git a/vm/in/INSTRS b/vm/in/INSTRS index 99799a6..0f65246 100644 --- a/vm/in/INSTRS +++ b/vm/in/INSTRS @@ -233,7 +233,7 @@ cmp rim rim # # Unconditional jump (JMP) instruction # -# RIP = CR1 + $1 +# RIP = $1 # j ri jmp ri @@ -243,7 +243,7 @@ jmp ri # # IF (RCX > 0) THEN # RCX = RCX - 1 -# RIP = CR1 + $1 +# RIP = $1 # FI # loop ri @@ -585,7 +585,7 @@ clr cla #---------------------------------------------------------------------------# -# Deprecated and deleted instruction # +# Deprecated instruction # #---------------------------------------------------------------------------# # diff --git a/vm/in/instrs.h b/vm/in/instrs.h index a8f0026..2528458 100644 --- a/vm/in/instrs.h +++ b/vm/in/instrs.h @@ -73,23 +73,5 @@ bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *r1, ulong *r2) \ } \ } while (0) -#define CHK_STACK() /* \ - if (__builtin_expect((rsp % 8 != 0), 0) { \ - _except(ctx, E_STA, "Misaligned stack REGS"); \ - }*/ - -//----------------------------------------------------------------------------// - -#define PUSH(v) \ - rsp -= 8; \ - writemem(ctx, v, rsp, 8); - -#define POP(v) \ - v = readmem(ctx, rsp, 8); \ - rsp += 8; - -#define JUMP(v) \ - rip = v + cr1 - //----------------------------------------------------------------------------// diff --git a/vm/in/jumps.c b/vm/in/jumps.c index 1b67971..17d9617 100644 --- a/vm/in/jumps.c +++ b/vm/in/jumps.c @@ -9,13 +9,13 @@ IMPL_START_1(j) { - JUMP(v1); + rip = v1; } IMPL_END; IMPL_START_1(jmp) { - JUMP(v1); + rip = v1; } IMPL_END; @@ -23,7 +23,7 @@ IMPL_START_1(loop) { if (rcx > 0) { rcx--; - JUMP(v1); + rip = v1; } } IMPL_END; diff --git a/vm/in/stack.c b/vm/in/stack.c index 0d88eb4..d10fad1 100644 --- a/vm/in/stack.c +++ b/vm/in/stack.c @@ -26,7 +26,7 @@ IMPL_START_1(call) rsp -= 8; writemem(ctx, rip, rsp, 8); - JUMP(v1); + rip = v1; } IMPL_END; diff --git a/vm/pc/arch.h b/vm/pc/arch.h index 16a2b51..88c51ed 100644 --- a/vm/pc/arch.h +++ b/vm/pc/arch.h @@ -66,6 +66,9 @@ void dumpmem(ctx_t *, ulong, ulong); void decode(ctx_t *ctx); +void enable_stdin_echoing(void); +void disable_stdin_echoing(void); + #include #include #include diff --git a/vm/pc/decd.c b/vm/pc/decd.c index 3756b2d..25feec5 100644 --- a/vm/pc/decd.c +++ b/vm/pc/decd.c @@ -47,7 +47,6 @@ void decode(ctx_t *ctx) // // Process the first word of the instruction // - w1 = ctx->get(ctx); // Extract first word flags diff --git a/vm/pc/except.c b/vm/pc/except.c index 3b39b0b..008cbe4 100644 --- a/vm/pc/except.c +++ b/vm/pc/except.c @@ -2,19 +2,21 @@ // See the LICENSE file in the project root for more information. #include -#include + +int dying = 0; void _except(ctx_t *ctx, int code, char *fmt, ...) { va_list ap; - // - // Restore stdin echoing - // - struct termios t; - tcgetattr(0, &t); - t.c_lflag |= ECHO; - tcsetattr(0, TCSANOW, &t); + enable_stdin_echoing(); + + if (dying) + { + log("Exception thrown while dying=1\n"); + exit(-12); + } + else dying = 1; log("\nException %d - ", code); diff --git a/vm/pc/except.h b/vm/pc/except.h index f03edc9..b21397e 100644 --- a/vm/pc/except.h +++ b/vm/pc/except.h @@ -15,4 +15,6 @@ enum NEXCPTS }; +extern int dying; + void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__)); diff --git a/vm/pc/main.c b/vm/pc/main.c index 6480b65..b3e393a 100644 --- a/vm/pc/main.c +++ b/vm/pc/main.c @@ -1,10 +1,10 @@ // 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 -#include -#include #define FWPROGSIZE (1024 * 1024 * 1024) static ssize_t fwsize; @@ -14,13 +14,13 @@ ushort bget(ctx_t *ctx) { ulong addr = rip + cr1; - +/* if (addr % 2) { _except(ctx, E_ALI, "Misaligned RIP and/or CR1: " "rip=0x%lX cr1=0x%lX", rip, cr1); } - +*/ if (addr2real(addr) >= ctx->mz) { _except(ctx, E_ACC, "Executing out of memory: " @@ -37,22 +37,29 @@ ushort bget(ctx_t *ctx) ctx_t main_ctx; -void sigint(int _) +void sigcommon(void) { - // - // Enable stdin echoing - // - struct termios t; - tcgetattr(0, &t); - t.c_lflag |= ECHO; - tcsetattr(0, TCSANOW, &t); + dying = 1; + + enable_stdin_echoing(); // // Shut down devices // devfiniall(&main_ctx); - exit(0); + exit(-13); +} + +void sigint(int _) +{ + sigcommon(); +} + +void sigsegv(int _) +{ + log("Segmentation fault\n"); + sigcommon(); } int main(int argc, char **argv) @@ -61,6 +68,8 @@ int main(int argc, char **argv) main_ctx.r = arch_r; main_ctx.i = arch_i; + + disable_stdin_echoing(); // // srand @@ -69,18 +78,11 @@ int main(int argc, char **argv) gettimeofday(&time, NULL); srandom((time.tv_sec * 1000) + (time.tv_usec / 1000)); - // - // Disable stdin echoing - // - struct termios t; - tcgetattr(0, &t); - t.c_lflag &= ~ECHO; - tcsetattr(0, TCSANOW, &t); - // // Signal handling // signal(SIGINT, sigint); + signal(SIGSEGV, sigsegv); // // Load program diff --git a/vm/pc/regs.c b/vm/pc/regs.c index 22082ff..9adce35 100644 --- a/vm/pc/regs.c +++ b/vm/pc/regs.c @@ -3,7 +3,7 @@ #include -reg_t arch_r[NREGS] = +reg_t arch_r[] = { // Invalid register { "inv", 0, RES }, diff --git a/vm/pc/tmio.c b/vm/pc/tmio.c new file mode 100644 index 0000000..bbdfdd4 --- /dev/null +++ b/vm/pc/tmio.c @@ -0,0 +1,21 @@ +// 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 + +void enable_stdin_echoing(void) +{ + struct termios t; + tcgetattr(0, &t); + t.c_lflag |= ECHO; + tcsetattr(0, TCSANOW, &t); +} + +void disable_stdin_echoing(void) +{ + struct termios t; + tcgetattr(0, &t); + t.c_lflag &= ~ECHO; + tcsetattr(0, TCSANOW, &t); +} +