2019-06-05 19:31:48 +02:00
|
|
|
// The OS/K Team licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
2019-06-13 23:12:11 +02:00
|
|
|
#include <pc/dev.h>
|
2019-06-05 19:31:48 +02:00
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-06-15 13:42:30 +02:00
|
|
|
#define MAX_RFRAME_IDX 255
|
|
|
|
|
|
|
|
//
|
2019-06-15 14:20:35 +02:00
|
|
|
// Register frames
|
2019-06-15 13:42:30 +02:00
|
|
|
//
|
|
|
|
reg_t **rfs = NULL;
|
2019-06-15 14:20:35 +02:00
|
|
|
|
|
|
|
size_t current_idx = 0;
|
2019-06-15 13:42:30 +02:00
|
|
|
size_t rfs_used = 0;
|
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
#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 = 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)
|
2019-06-05 19:48:56 +02:00
|
|
|
{
|
2019-06-15 14:20:35 +02:00
|
|
|
CHK_INDEX(ax0);
|
|
|
|
|
|
|
|
if (ax0 == 0)
|
|
|
|
_except(ctx, E_UDF, "cpudev: deactivating rframe #0 (arch_r)");
|
2019-06-05 22:11:45 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-06-05 19:48:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-06-05 22:11:45 +02:00
|
|
|
long cpudev_poweron(ctx_t *ctx, dev_t *dev)
|
2019-06-05 19:48:56 +02:00
|
|
|
{
|
2019-06-15 14:20:35 +02:00
|
|
|
rfs = calloc(MAX_RFRAME_IDX + 2, sizeof(reg_t *));
|
2019-06-15 13:42:30 +02:00
|
|
|
|
|
|
|
if (rfs == NULL)
|
|
|
|
return -1;
|
2019-06-05 19:48:56 +02:00
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
rfs[0] = ctx->r;
|
|
|
|
rfs_used = 1;
|
|
|
|
|
2019-06-05 19:48:56 +02:00
|
|
|
dev->state = DEVGOOD;
|
2019-06-15 13:42:30 +02:00
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
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;
|
2019-06-15 13:42:30 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
long cpudev_poweroff(ctx_t *ctx, dev_t *dev)
|
|
|
|
{
|
|
|
|
if (rfs)
|
|
|
|
free(rfs);
|
2019-06-05 22:11:45 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-06-05 19:48:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-15 14:20:35 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-06-05 19:31:48 +02:00
|
|
|
dev_t cpudev =
|
|
|
|
{
|
|
|
|
.type = "cpu",
|
|
|
|
.name = "K-CPU",
|
2019-06-05 22:11:45 +02:00
|
|
|
.modl = "Prisma 1",
|
2019-06-05 19:31:48 +02:00
|
|
|
.vend = "The OS/K Team",
|
|
|
|
|
2019-06-13 23:12:11 +02:00
|
|
|
.major = KARCH_MAJOR,
|
|
|
|
.minor = KARCH_MINOR,
|
|
|
|
.revis = KARCH_REVIS,
|
2019-06-05 19:48:56 +02:00
|
|
|
|
|
|
|
.fpwon = cpudev_poweron,
|
2019-06-05 19:31:48 +02:00
|
|
|
};
|
|
|
|
|