1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/vm/in/misc.c
julianb0 2a610f2d7a
vm
2019-07-17 22:25:50 +02:00

179 lines
4.1 KiB
C

// 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 <pc/console.h>
#include <in/instrs.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
//----------------------------------------------------------------------------//
IMPL_START_0(nop) {} IMPL_END;
IMPL_START_0(cpuid) { rax = rdx = 0; } IMPL_END;
IMPL_START_0(pause) { usleep(5000); } IMPL_END;
IMPL_START_0(xpause) { CHK_SUPERV(); usleep(25000); } IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_0(break)
{
#ifndef NDEBUG
trace("\nExecuting BREAK INSTR\n");
dumpregs(ctx);
do_hlt(ctx);
trace("Resuming execution\n");
#endif
}
IMPL_END;
IMPL_START_1(dump)
{
(void)v1;
#ifndef NDEBUG
if (ctx->dumpsw && !v1)
trace("0x%lX:\t...\n", rpc);
else if (!ctx->dumpsw && v1)
dump_instr(ctx, ctx->cur_in, p1, p2, p3, 0, 0);
ctx->dumpsw = !!v1;
#endif
}
IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_X_NOIN(time) { v1 = time(NULL); } IMPL_OUT;
IMPL_START_X_NOIN(ytime)
{
time_t t = time(NULL);
struct tm *tm = localtime(&t);
v1 = tm->tm_sec + tm->tm_min * 60
+ tm->tm_hour * 60 * 60
+ tm->tm_mday * 60 * 60 * 24;
v2 = tm->tm_mon;
v3 = tm->tm_year + 1900;
}
IMPL_OUT_3;
IMPL_START_1(utime)
{
struct timeval time;
gettimeofday(&time, NULL);
v1 = (time.tv_sec * 1000) + (time.tv_usec / 1000);
}
IMPL_OUT;
//----------------------------------------------------------------------------//
IMPL_START_0(cls) {
R(RAX) = R(RBX) = R(RCX) = R(RDX) = R(RDI) = R(RSI) = R(RFX) = 0;
for (int i = R10; i <= NX7; i++) R(i) = 0;
} IMPL_END;
IMPL_START_0(clr) {
R(RAX) = R(RBX) = R(RCX) = R(RDX) = R(RDI) = R(RSI) = R(RFX) = 0;
for (int i = R10; i <= R15; i++) R(i) = 0;
} IMPL_END;
IMPL_START_0(cla) { for (int i = AX0; i <= AX7; i++) R(i) = 0; } IMPL_END;
IMPL_START_0(cln) { for (int i = NX0; i <= NX7; i++) R(i) = 0; } IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_0(cli) { CHK_SUPERV(); R(CR0) &= ~IF; } IMPL_END;
IMPL_START_0(sti) { CHK_SUPERV(); R(CR0) |= IF; } IMPL_END;
IMPL_START_0(cld) { R(RFX) &= ~DF; } IMPL_END;
IMPL_START_0(clc) { R(RFX) &= ~CF; } IMPL_END;
IMPL_START_0(std) { R(RFX) |= DF; } IMPL_END;
IMPL_START_0(stc) { R(RFX) |= CF; } IMPL_END;
IMPL_START_0(cmc) { R(RFX) = (R(RFX)&CF ? R(RFX)&~CF : R(RFX)|CF); } IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_2(bswap)
{
v1 = ((v2 & 0xFF00000000000000) >> 56)
| ((v2 & 0x00FF000000000000) >> 40)
| ((v2 & 0x0000FF0000000000) >> 24)
| ((v2 & 0x000000FF00000000) >> 8)
| ((v2 & 0x00000000FF000000) << 8)
| ((v2 & 0x0000000000FF0000) << 24)
| ((v2 & 0x000000000000FF00) << 40)
| ((v2 & 0x00000000000000FF) << 56);
}
IMPL_OUT;
IMPL_START_2(wswap)
{
v1 = ((v2 & 0xFFFF000000000000) >> 48)
| ((v2 & 0x0000FFFF00000000) >> 16)
| ((v2 & 0x00000000FFFF0000) << 16)
| ((v2 & 0x000000000000FFFF) << 48);
}
IMPL_OUT;
IMPL_START_2(dswap)
{
v1 = ((v2 & 0xFFFFFFFF00000000) >> 32)
| ((v2 & 0x00000000FFFFFFFF) << 32);
}
IMPL_OUT;
//----------------------------------------------------------------------------//
IMPL_START_0(prn)
{
DECVZX(v1, p1);
// Magic value? :)
if (__builtin_expect(v1 == 0xC15000AF, 0))
console_clear(ctx);
else
{
if (p1->mlen > 1) {
trace("prn warning: large access size\n");
}
if (v1 > 0)
console_putc(ctx, (char)v1);
}
}
IMPL_END
IMPL_START_0(prns)
{
uchar ch = readmemzx(ctx, R(p1->reg), 1);
COMPARE(ch, 0);
if ((R(RFX) & ZF) == 0)
{
console_putc(ctx, ch);
if (R(RFX) & DF)
R(p1->reg)--;
else
R(p1->reg)++;
}
}
IMPL_END
IMPL_START_X_NOIN(scan)
{
v1 = console_scankeybuf(ctx);
}
IMPL_OUT;
//----------------------------------------------------------------------------//