1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
This commit is contained in:
julianb0 2019-06-16 12:48:30 +02:00
parent 08b931e911
commit ee4f983103
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
12 changed files with 68 additions and 58 deletions

3
ka/ABI
View File

@ -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:

View File

@ -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 #
#---------------------------------------------------------------------------#
#

View File

@ -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
//----------------------------------------------------------------------------//

View File

@ -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;

View File

@ -26,7 +26,7 @@ IMPL_START_1(call)
rsp -= 8;
writemem(ctx, rip, rsp, 8);
JUMP(v1);
rip = v1;
}
IMPL_END;

View File

@ -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 <pc/mem.h>
#include <pc/regs.h>
#include <pc/decd.h>

View File

@ -47,7 +47,6 @@ void decode(ctx_t *ctx)
//
// Process the first word of the instruction
//
w1 = ctx->get(ctx);
// Extract first word flags

View File

@ -2,19 +2,21 @@
// See the LICENSE file in the project root for more information.
#include <pc/dev.h>
#include <termio.h>
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);

View File

@ -15,4 +15,6 @@ enum
NEXCPTS
};
extern int dying;
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));

View File

@ -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 <sys/time.h>
#include <signal.h>
#include <pc/dev.h>
#include <sys/time.h>
#include <termio.h>
#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

View File

@ -3,7 +3,7 @@
#include <pc/arch.h>
reg_t arch_r[NREGS] =
reg_t arch_r[] =
{
// Invalid register
{ "inv", 0, RES },

21
vm/pc/tmio.c Normal file
View File

@ -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 <termio.h>
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);
}