1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/karch/main.c
2019-05-16 16:48:45 +02:00

62 lines
1.3 KiB
C

// The OS/K Team licences this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include "arch.h"
// Boot firware, loaded at MEMOFF (1MB)
ushort fwprog[] = {
I_MOV_R_I, RBP, A_IMM32, FWSTACK>>16, FWSTACK&0xFF,
I_MOV_R_I, RSP, A_IMM32, FWSTACK>>16, FWSTACK&0xFF,
I_MOV_M_I, A_MEM, RBP, A_IMM16, 0xAC,
I_SUB_R_I, RBP, A_IMM16, 8,
I_ADD_M_R, A_OFF, 8, RBP, RSP,
I_MOV_R_M, RAX, A_MEM, RBP,
};
ushort bget(ctx_t *ctx)
{
if (addr2real(ctx->r[RIP].val) >= MEMSIZE) {
_except(ctx, E_ACC, "Executing out of memory");
}
ushort c = ctx->mp[addr2real(ctx->r[RIP].val)];
ctx->r[RIP].val++;
return c;
}
extern reg_t arch_r[NREGS];
extern instr_t arch_i[NINSTRS];
int main(void)
{
static ctx_t main_ctx;
main_ctx.r = arch_r;
main_ctx.i = arch_i;
main_ctx.mp = malloc(MEMSIZE);
main_ctx.mz = MEMSIZE;
main_ctx.get = bget;
main_ctx.r[RIP].val = MEMOFF;
if (main_ctx.mp == 0) {
log("Couldn't allocate RAM");
exit(-1);
}
memcpy(&main_ctx.mp[addr2real(main_ctx.r[RIP].val)], fwprog, sizeof(fwprog));
memset(&main_ctx.mp[addr2real(main_ctx.r[RIP].val) + sizeof(fwprog)/2], 0xFF, 0xFF);
while (1) {
decode(&main_ctx);
}
return 0;
}