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/super.c

152 lines
3.1 KiB
C
Raw Normal View History

2019-05-30 12:44:56 +02:00
// The OS/K Team licenses this file to you under the MIT license.
2019-05-29 16:57:22 +02:00
// See the LICENSE file in the project root for more information.
2019-06-20 12:31:36 +02:00
#include <unistd.h>
2019-06-23 12:40:18 +02:00
#include <pc/device.h>
2019-06-05 12:53:09 +02:00
#include <in/instrs.h>
2019-06-20 17:44:48 +02:00
#include <pc/console.h>
2019-05-29 16:57:22 +02:00
2019-07-17 20:26:03 +02:00
//----------------------------------------------------------------------------//
2019-06-30 13:46:44 +02:00
2019-07-10 17:17:45 +02:00
void do_hlt(ctx_t *ctx)
2019-06-19 23:16:30 +02:00
{
2019-06-20 12:31:36 +02:00
SDL_Event evt;
while (1)
{
if (SDL_WaitEvent(&evt) == 1)
{
if (evt.type == SDL_QUIT)
die(0);
2019-06-26 21:25:59 +02:00
if (evt.type == SDL_KEYDOWN)
2019-06-30 13:46:44 +02:00
{
2019-06-26 21:25:59 +02:00
console_handle_input(ctx, evt.key.keysym.sym);
2019-06-30 13:46:44 +02:00
if (evt.key.keysym.sym == SDLK_RETURN)
break;
}
2019-06-20 12:31:36 +02:00
}
}
2019-06-19 23:16:30 +02:00
}
2019-07-10 17:17:45 +02:00
2019-07-17 20:26:03 +02:00
//----------------------------------------------------------------------------//
IMPL_START_0(hlt) { CHK_SUPERV(); do_hlt(ctx); } IMPL_END;
IMPL_START_0(stop) { CHK_SUPERV(); _except(ctx, E_SHT, "STOP INSTR"); } IMPL_END;
IMPL_START_0(crash) { CHK_SUPERV(); _except(ctx, 1023, "CRASH instruction"); } IMPL_END;
//----------------------------------------------------------------------------//
IMPL_START_1(trap) {
if (v1 > 255) _except(ctx, E_ILL, "TRAP number greater than 255");
_except(ctx, v1 + 256, "TRAP instruction");
} IMPL_END;
2019-07-10 17:17:45 +02:00
2019-07-17 20:26:03 +02:00
IMPL_START_0(into) { INTO(); } IMPL_END;
IMPL_START_0(iret) {
trace("\nReturning from exception #%ld\n\n", R(R11));
// should do more checks
R(RIP) = R(R13);
rfs_current_idx = R(R12);
ctx->rf = rfs[R(R12)];
2019-07-10 17:17:45 +02:00
}
2019-06-19 23:16:30 +02:00
IMPL_END;
2019-05-29 16:57:22 +02:00
2019-07-17 20:26:03 +02:00
//----------------------------------------------------------------------------//
2019-06-23 12:40:18 +02:00
//
// code common to devctl and iocall
//
dev_t *devctl_common(ctx_t *ctx, ulong v1, ulong v2)
2019-05-29 16:57:22 +02:00
{
2019-06-23 12:40:18 +02:00
dev_t *dev = devget(ctx, v1);
if (!dev)
rax = -2;
else if (dev->state == DEVPWOF)
rax = -3;
else if (dev->state == DEVFERR)
rax = -4;
else if (dev->state == DEVPLUG)
rax = -5;
else
return dev;
return NULL;
}
IMPL_START_2(devctl)
2019-05-29 16:57:22 +02:00
{
CHK_SUPERV();
2019-06-23 12:40:18 +02:00
dev_t *dev = devctl_common(ctx, v1, v2);
if (dev == NULL)
return 0;
switch (v2) {
case 0:
2019-07-10 17:17:45 +02:00
writestr(ctx, ax0, DEVLEN, dev->type);
2019-06-23 12:40:18 +02:00
break;
case 1:
2019-07-10 17:17:45 +02:00
writestr(ctx, ax0, DEVLEN, dev->name);
2019-06-23 12:40:18 +02:00
break;
case 2:
2019-07-10 17:17:45 +02:00
writestr(ctx, ax0, DEVLEN, dev->modl);
2019-06-23 12:40:18 +02:00
break;
case 3:
2019-07-10 17:17:45 +02:00
writestr(ctx, ax0, DEVLEN, dev->vend);
2019-06-23 12:40:18 +02:00
break;
case 4:
rax = dev->major;
rdx = dev->minor;
break;
case 5:
rax = dev->feats;
rdx = dev->revis;
break;
default:
rax = -6;
break;
}
2019-05-29 16:57:22 +02:00
}
IMPL_END;
2019-06-23 12:40:18 +02:00
IMPL_START_2(iocall)
2019-05-29 16:57:22 +02:00
{
2019-06-02 16:33:28 +02:00
CHK_SUPERV();
2019-06-23 12:40:18 +02:00
long rc;
dev_t *dev = devctl_common(ctx, v1, v2);
if (dev == NULL)
return 0;
if (v2 >= DEVSLOTS)
rax = -6;
else if (dev->fslots[v2] == NULL)
rax = -6;
else {
rc = dev->fslots[v2](ctx, dev);
if (rc < 0) rax = rc;
}
2019-05-29 16:57:22 +02:00
}
IMPL_END;
2019-07-17 20:26:03 +02:00
//----------------------------------------------------------------------------//