mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
71 lines
1.5 KiB
C
71 lines
1.5 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_CALL_I, A_IMM32, (MEMOFF+0x13)>>16, (MEMOFF+0x13)&0xFF,
|
|
I_ADD_R_I, RAX, A_IMM16, 1,
|
|
0xFFFF,
|
|
|
|
I_ADD_R_I, RBX, A_IMM16, 1,
|
|
I_RET,
|
|
|
|
/*
|
|
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;
|
|
}
|
|
|