This commit is contained in:
julianb0 2019-06-15 14:20:35 +02:00
parent 6e88d42473
commit 24ef00ab3e
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
2 changed files with 97 additions and 12 deletions

View File

@ -8,12 +8,13 @@ CPU device function slots:
16 - - - - getmaxidx rax = maximal index for a register frame
17 - - - - getrfusage rax = number of register frames active
18 - - - - getcuridx rax = index of the current register frame
19 i - - - isactive rax = is register frame #ax0 active?
20 i - - y activate activates register frame #ax0
21 i - - y deactivate deactivates register frame #ax0 (losing all its contents!)
22 i i - y copyframe copy contents of frame #ax1 into (active) frame #ax0
23 i i - y moveframe move frame #ax1 to (inactive) frame index #ax0
24-31 - - - - (reserved) (reserved)
19 - - - - leastavail rax = least index among inactive frames, -1 if none
20 i - - - isactive rax = is register frame #ax0 active?
21 i - - y activate activates register frame #ax0 (filling it with 0's)
22 i - - y deactivate deactivates register frame #ax0 (losing all its contents!)
23 i i - y copyframe copy contents of frame #ax1 into (active) frame #ax0
24 i i - y moveframe move frame #ax1 to (inactive) frame index #ax0
25-31 - - - - (reserved) (reserved)
32 i - - - loadargs load registers ax0-ax7 from frame #ax0
33 i r - - loadreg rax = register #ax1 from frame #ax0
34-47 - - - - (reserved) (reserved)

View File

@ -3,32 +3,114 @@
#include <pc/dev.h>
//----------------------------------------------------------------------------//
#define MAX_RFRAME_IDX 255
//
// Register frales
// Register frames
//
reg_t **rfs = NULL;
size_t current_idx = 0;
size_t rfs_used = 0;
long cpudev_testfn(ctx_t *ctx, dev_t *dev)
#define CHK_INDEX(idx) \
if ((ulong)idx > MAX_RFRAME_IDX) \
_except(ctx, E_UDF, "cpudev: invalid rframe index: #%u", idx);
//----------------------------------------------------------------------------//
long cpudev_getmaxidx(ctx_t *ctx, dev_t *dev)
{
rax = 4;
rdx = 3;
rax = MAX_RFRAME_IDX;
return 0;
}
long cpudev_getrfusage(ctx_t *ctx, dev_t *dev)
{
rax = rfs_used;
return 0;
}
long cpudev_getcuridx(ctx_t *ctx, dev_t *dev)
{
rax = current_idx;
return 0;
}
long cpudev_leastavail(ctx_t *ctx, dev_t *dev)
{
size_t it;
for (it = 0; it <= MAX_RFRAME_IDX; it++)
{
if (rfs[it] == NULL)
{
rax = it;
return 0;
}
}
rax = -1;
return 0;
}
//----------------------------------------------------------------------------//
long cpudev_isactive(ctx_t *ctx, dev_t *dev)
{
CHK_INDEX(ax0);
rax = (rfs[ax0] != NULL);
return 0;
}
long cpudev_activate(ctx_t *ctx, dev_t *dev)
{
CHK_INDEX(ax0);
if (rfs[ax0] != NULL)
_except(ctx, E_UDF,
"cpudev: activating already activated rframe: #%u", ax0);
return 0;
}
long cpudev_deactivate(ctx_t *ctx, dev_t *dev)
{
CHK_INDEX(ax0);
if (ax0 == 0)
_except(ctx, E_UDF, "cpudev: deactivating rframe #0 (arch_r)");
return 0;
}
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
long cpudev_poweron(ctx_t *ctx, dev_t *dev)
{
rfs = malloc(sizeof(reg_t *) * (MAX_RFRAME_IDX + 1));
rfs = calloc(MAX_RFRAME_IDX + 2, sizeof(reg_t *));
if (rfs == NULL)
return -1;
rfs[0] = ctx->r;
rfs_used = 1;
dev->state = DEVGOOD;
dev->fslots[0] = cpudev_testfn;
dev->fslots[16] = cpudev_getmaxidx;
dev->fslots[17] = cpudev_getrfusage;
dev->fslots[18] = cpudev_getcuridx;
dev->fslots[19] = cpudev_leastavail;
dev->fslots[20] = cpudev_isactive;
dev->fslots[21] = cpudev_activate;
dev->fslots[22] = cpudev_deactivate;
return 0;
}
@ -41,6 +123,8 @@ long cpudev_poweroff(ctx_t *ctx, dev_t *dev)
return 0;
}
//----------------------------------------------------------------------------//
dev_t cpudev =
{
.type = "cpu",