mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
cr1
This commit is contained in:
parent
08b931e911
commit
ee4f983103
3
ka/ABI
3
ka/ABI
@ -16,8 +16,7 @@ A function's assembly code looks like this:
|
|||||||
...
|
...
|
||||||
leave
|
leave
|
||||||
ret
|
ret
|
||||||
'N' is the number of local variables used by the function,
|
'N' is the number of local variables used by the function.
|
||||||
and is omitted if there are none ('enter' alone takes N=0).
|
|
||||||
|
|
||||||
The above code is equivalent to the following, but much faster:
|
The above code is equivalent to the following, but much faster:
|
||||||
label:
|
label:
|
||||||
|
@ -233,7 +233,7 @@ cmp rim rim
|
|||||||
#
|
#
|
||||||
# Unconditional jump (JMP) instruction
|
# Unconditional jump (JMP) instruction
|
||||||
#
|
#
|
||||||
# RIP = CR1 + $1
|
# RIP = $1
|
||||||
#
|
#
|
||||||
j ri
|
j ri
|
||||||
jmp ri
|
jmp ri
|
||||||
@ -243,7 +243,7 @@ jmp ri
|
|||||||
#
|
#
|
||||||
# IF (RCX > 0) THEN
|
# IF (RCX > 0) THEN
|
||||||
# RCX = RCX - 1
|
# RCX = RCX - 1
|
||||||
# RIP = CR1 + $1
|
# RIP = $1
|
||||||
# FI
|
# FI
|
||||||
#
|
#
|
||||||
loop ri
|
loop ri
|
||||||
@ -585,7 +585,7 @@ clr
|
|||||||
cla
|
cla
|
||||||
|
|
||||||
#---------------------------------------------------------------------------#
|
#---------------------------------------------------------------------------#
|
||||||
# Deprecated and deleted instruction #
|
# Deprecated instruction #
|
||||||
#---------------------------------------------------------------------------#
|
#---------------------------------------------------------------------------#
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -73,23 +73,5 @@ bool i_##name(ctx_t *ctx, acc_t *p1, acc_t *p2, ulong *r1, ulong *r2) \
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} 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
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
IMPL_START_1(j)
|
IMPL_START_1(j)
|
||||||
{
|
{
|
||||||
JUMP(v1);
|
rip = v1;
|
||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
|
||||||
IMPL_START_1(jmp)
|
IMPL_START_1(jmp)
|
||||||
{
|
{
|
||||||
JUMP(v1);
|
rip = v1;
|
||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ IMPL_START_1(loop)
|
|||||||
{
|
{
|
||||||
if (rcx > 0) {
|
if (rcx > 0) {
|
||||||
rcx--;
|
rcx--;
|
||||||
JUMP(v1);
|
rip = v1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
@ -26,7 +26,7 @@ IMPL_START_1(call)
|
|||||||
rsp -= 8;
|
rsp -= 8;
|
||||||
writemem(ctx, rip, rsp, 8);
|
writemem(ctx, rip, rsp, 8);
|
||||||
|
|
||||||
JUMP(v1);
|
rip = v1;
|
||||||
}
|
}
|
||||||
IMPL_END;
|
IMPL_END;
|
||||||
|
|
||||||
|
@ -66,6 +66,9 @@ void dumpmem(ctx_t *, ulong, ulong);
|
|||||||
|
|
||||||
void decode(ctx_t *ctx);
|
void decode(ctx_t *ctx);
|
||||||
|
|
||||||
|
void enable_stdin_echoing(void);
|
||||||
|
void disable_stdin_echoing(void);
|
||||||
|
|
||||||
#include <pc/mem.h>
|
#include <pc/mem.h>
|
||||||
#include <pc/regs.h>
|
#include <pc/regs.h>
|
||||||
#include <pc/decd.h>
|
#include <pc/decd.h>
|
||||||
|
@ -47,7 +47,6 @@ void decode(ctx_t *ctx)
|
|||||||
//
|
//
|
||||||
// Process the first word of the instruction
|
// Process the first word of the instruction
|
||||||
//
|
//
|
||||||
|
|
||||||
w1 = ctx->get(ctx);
|
w1 = ctx->get(ctx);
|
||||||
|
|
||||||
// Extract first word flags
|
// Extract first word flags
|
||||||
|
@ -2,19 +2,21 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
#include <pc/dev.h>
|
#include <pc/dev.h>
|
||||||
#include <termio.h>
|
|
||||||
|
int dying = 0;
|
||||||
|
|
||||||
void _except(ctx_t *ctx, int code, char *fmt, ...)
|
void _except(ctx_t *ctx, int code, char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
//
|
enable_stdin_echoing();
|
||||||
// Restore stdin echoing
|
|
||||||
//
|
if (dying)
|
||||||
struct termios t;
|
{
|
||||||
tcgetattr(0, &t);
|
log("Exception thrown while dying=1\n");
|
||||||
t.c_lflag |= ECHO;
|
exit(-12);
|
||||||
tcsetattr(0, TCSANOW, &t);
|
}
|
||||||
|
else dying = 1;
|
||||||
|
|
||||||
log("\nException %d - ", code);
|
log("\nException %d - ", code);
|
||||||
|
|
||||||
|
@ -15,4 +15,6 @@ enum
|
|||||||
NEXCPTS
|
NEXCPTS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int dying;
|
||||||
|
|
||||||
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));
|
void _except(ctx_t *, int, char *, ...) __attribute__((__noreturn__));
|
||||||
|
44
vm/pc/main.c
44
vm/pc/main.c
@ -1,10 +1,10 @@
|
|||||||
// The OS/K Team licenses this file to you under the MIT license.
|
// The OS/K Team licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <pc/dev.h>
|
#include <pc/dev.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <termio.h>
|
|
||||||
|
|
||||||
#define FWPROGSIZE (1024 * 1024 * 1024)
|
#define FWPROGSIZE (1024 * 1024 * 1024)
|
||||||
static ssize_t fwsize;
|
static ssize_t fwsize;
|
||||||
@ -14,13 +14,13 @@ ushort bget(ctx_t *ctx)
|
|||||||
{
|
{
|
||||||
ulong addr = rip + cr1;
|
ulong addr = rip + cr1;
|
||||||
|
|
||||||
|
/*
|
||||||
if (addr % 2) {
|
if (addr % 2) {
|
||||||
_except(ctx, E_ALI, "Misaligned RIP and/or CR1: "
|
_except(ctx, E_ALI, "Misaligned RIP and/or CR1: "
|
||||||
"rip=0x%lX cr1=0x%lX",
|
"rip=0x%lX cr1=0x%lX",
|
||||||
rip, cr1);
|
rip, cr1);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (addr2real(addr) >= ctx->mz) {
|
if (addr2real(addr) >= ctx->mz) {
|
||||||
_except(ctx, E_ACC, "Executing out of memory: "
|
_except(ctx, E_ACC, "Executing out of memory: "
|
||||||
@ -37,22 +37,29 @@ ushort bget(ctx_t *ctx)
|
|||||||
|
|
||||||
ctx_t main_ctx;
|
ctx_t main_ctx;
|
||||||
|
|
||||||
void sigint(int _)
|
void sigcommon(void)
|
||||||
{
|
{
|
||||||
//
|
dying = 1;
|
||||||
// Enable stdin echoing
|
|
||||||
//
|
enable_stdin_echoing();
|
||||||
struct termios t;
|
|
||||||
tcgetattr(0, &t);
|
|
||||||
t.c_lflag |= ECHO;
|
|
||||||
tcsetattr(0, TCSANOW, &t);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Shut down devices
|
// Shut down devices
|
||||||
//
|
//
|
||||||
devfiniall(&main_ctx);
|
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)
|
int main(int argc, char **argv)
|
||||||
@ -61,6 +68,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
main_ctx.r = arch_r;
|
main_ctx.r = arch_r;
|
||||||
main_ctx.i = arch_i;
|
main_ctx.i = arch_i;
|
||||||
|
|
||||||
|
disable_stdin_echoing();
|
||||||
|
|
||||||
//
|
//
|
||||||
// srand
|
// srand
|
||||||
@ -69,18 +78,11 @@ int main(int argc, char **argv)
|
|||||||
gettimeofday(&time, NULL);
|
gettimeofday(&time, NULL);
|
||||||
srandom((time.tv_sec * 1000) + (time.tv_usec / 1000));
|
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 handling
|
||||||
//
|
//
|
||||||
signal(SIGINT, sigint);
|
signal(SIGINT, sigint);
|
||||||
|
signal(SIGSEGV, sigsegv);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Load program
|
// Load program
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <pc/arch.h>
|
#include <pc/arch.h>
|
||||||
|
|
||||||
reg_t arch_r[NREGS] =
|
reg_t arch_r[] =
|
||||||
{
|
{
|
||||||
// Invalid register
|
// Invalid register
|
||||||
{ "inv", 0, RES },
|
{ "inv", 0, RES },
|
||||||
|
21
vm/pc/tmio.c
Normal file
21
vm/pc/tmio.c
Normal 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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user