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
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(hlt) { CHK_SUPERV(); do_hlt(ctx); return 0; }
|
|
|
|
IMPL_START(stop) { CHK_SUPERV(); _except(ctx, E_SHT, "STOP INSTR"); }
|
|
|
|
IMPL_START(crash) { CHK_SUPERV(); _except(ctx, 1023, "CRASH instruction"); }
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(trap)
|
|
|
|
{
|
|
|
|
if (p1->val > 255) _except(ctx, E_ILL, "TRAP number greater than 255");
|
|
|
|
_except(ctx, p1->val + 256, "TRAP instruction");
|
|
|
|
}
|
2019-07-10 17:17:45 +02:00
|
|
|
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(iret) {
|
2019-07-17 22:25:50 +02:00
|
|
|
if (ctx->dumpsw)
|
2019-07-22 13:18:13 +02:00
|
|
|
trace("\nReturning from exception #%ld\n\n", R(R13));
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
// should do more checks
|
2019-07-22 13:18:13 +02:00
|
|
|
R(RIP) = R(R15);
|
|
|
|
rfs_current_idx = R(R14);
|
|
|
|
ctx->rf = rfs[R(R14)];
|
2019-07-24 16:52:26 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-07-10 17:17:45 +02:00
|
|
|
}
|
2019-05-29 16:57:22 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(cli) { CHK_SUPERV(); R(CR0) &= ~IF; return 0; }
|
|
|
|
IMPL_START(sti) { CHK_SUPERV(); R(CR0) |= IF; return 0; }
|
2019-07-18 22:49:31 +02:00
|
|
|
|
2019-07-17 20:26:03 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
//
|
|
|
|
// code common to devctl and iocall
|
|
|
|
//
|
2019-07-24 16:52:26 +02:00
|
|
|
dev_t *devctl_common(ctx_t *ctx, ulong idx)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
2019-07-24 16:52:26 +02:00
|
|
|
dev_t *dev = devget(ctx, idx);
|
2019-06-23 12:40:18 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
if (!dev) R(RAX) = -2;
|
|
|
|
else if (dev->state == DEVPWOF) R(RAX) = -3;
|
|
|
|
else if (dev->state == DEVFERR) R(RAX) = -4;
|
|
|
|
else if (dev->state == DEVPLUG) R(RAX) = -5;
|
2019-07-17 22:25:50 +02:00
|
|
|
else return dev;
|
2019-06-23 12:40:18 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(devctl)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
|
|
|
CHK_SUPERV();
|
2019-06-23 12:40:18 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
dev_t *dev = devctl_common(ctx, p1->val);
|
2019-06-23 12:40:18 +02:00
|
|
|
|
|
|
|
if (dev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
switch (p2->val) {
|
|
|
|
case 0: writestr(ctx, R(AX0), DEVLEN, dev->type); break;
|
|
|
|
case 1: writestr(ctx, R(AX0), DEVLEN, dev->name); break;
|
|
|
|
case 2: writestr(ctx, R(AX0), DEVLEN, dev->modl); break;
|
|
|
|
case 3: writestr(ctx, R(AX0), DEVLEN, dev->vend); break;
|
|
|
|
case 4: R(RAX) = dev->major; R(RDX) = dev->minor; break;
|
|
|
|
case 5: R(RAX) = dev->feats; R(RDX) = dev->revis; break;
|
|
|
|
default: R(RAX) = -6; break;
|
2019-06-23 12:40:18 +02:00
|
|
|
}
|
2019-07-24 16:52:26 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-05-29 16:57:22 +02:00
|
|
|
}
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
IMPL_START(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;
|
2019-07-24 16:52:26 +02:00
|
|
|
dev_t *dev = devctl_common(ctx, p1->val);
|
2019-06-23 12:40:18 +02:00
|
|
|
|
2019-07-17 22:25:50 +02:00
|
|
|
if (dev == NULL) return 0;
|
2019-07-24 16:52:26 +02:00
|
|
|
else if (p2->val >= DEVSLOTS || dev->fslots[p2->val] == NULL) R(RAX) = -6;
|
2019-06-23 12:40:18 +02:00
|
|
|
|
|
|
|
else {
|
2019-07-24 16:52:26 +02:00
|
|
|
rc = dev->fslots[p2->val](ctx, dev);
|
|
|
|
if (rc < 0) { R(RAX) = rc; R(RDX) = 0; }
|
2019-06-23 12:40:18 +02:00
|
|
|
}
|
2019-07-24 16:52:26 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-05-29 16:57:22 +02:00
|
|
|
}
|
|
|
|
|
2019-07-17 20:26:03 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|