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

62 lines
1.3 KiB
C
Raw Normal View History

2019-05-15 19:26:40 +02:00
// The OS/K Team licences this file to you under the MIT license.
2019-05-15 21:56:42 +02:00
// See the LICENSE file in the project root for more information.
2019-05-15 19:26:40 +02:00
#include "arch.h"
2019-05-16 16:48:45 +02:00
// Boot firware, loaded at MEMOFF (1MB)
2019-05-16 10:03:01 +02:00
ushort fwprog[] = {
2019-05-16 16:48:45 +02:00
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,
2019-05-15 19:26:40 +02:00
};
ushort bget(ctx_t *ctx)
{
2019-05-16 10:03:01 +02:00
if (addr2real(ctx->r[RIP].val) >= MEMSIZE) {
_except(ctx, E_ACC, "Executing out of memory");
2019-05-15 19:26:40 +02:00
}
2019-05-16 10:03:01 +02:00
ushort c = ctx->mp[addr2real(ctx->r[RIP].val)];
ctx->r[RIP].val++;
return c;
2019-05-15 19:26:40 +02:00
}
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;
2019-05-16 10:03:01 +02:00
main_ctx.mp = malloc(MEMSIZE);
main_ctx.mz = MEMSIZE;
2019-05-15 19:26:40 +02:00
main_ctx.get = bget;
2019-05-16 10:03:01 +02:00
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);
2019-05-15 19:26:40 +02:00
2019-05-16 10:03:01 +02:00
while (1) {
2019-05-15 19:26:40 +02:00
decode(&main_ctx);
}
return 0;
}