// 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 //----------------------------------------------------------------------------// #define MAX_RFRAME_IDX 255 // // Register frames // reg_t **rfs = NULL; size_t current_idx = 0; size_t rfs_used = 0; #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) { 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 = 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[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; } long cpudev_poweroff(ctx_t *ctx, dev_t *dev) { if (rfs) free(rfs); return 0; } //----------------------------------------------------------------------------// dev_t cpudev = { .type = "cpu", .name = "K-CPU", .modl = "Prisma 1", .vend = "The OS/K Team", .major = KARCH_MAJOR, .minor = KARCH_MINOR, .revis = KARCH_REVIS, .fpwon = cpudev_poweron, };