Files
CAR/helpers.c
2026-07-16 13:46:13 -05:00

59 lines
1.7 KiB
C

/*
* Source file for helper functions.
*
* CAR (Cool ARM Ripoff) copyright (c) 2026 David J Goeke. All rights reserved.
* Unauthorized (re)distribution is prohibited.
*/
#include <stdio.h>
#include "include/defs.h"
void dump_regs(pstate_t* s)
{
printf("r0: 0x%08x r1: 0x%08x r2: 0x%08x, r3: 0x%08x\n", s->gprs[0], s->gprs[1], s->gprs[2], s->gprs[3]);
printf("r4: 0x%08x r5: 0x%08x r6: 0x%08x, r7: 0x%08x\n", s->gprs[4], s->gprs[5], s->gprs[6], s->gprs[7]);
printf("r8: 0x%08x r9: 0x%08x r10: 0x%08x, r11: 0x%08x\n", s->gprs[8], s->gprs[9], s->gprs[10], s->gprs[11]);
printf("r12: 0x%08x r13: 0x%08x r14: 0x%08x, r15: 0x%08x\n", s->gprs[12], s->gprs[13], s->gprs[14], s->gprs[15]);
printf("sp: 0x%04x pc: 0x%04x\n", s->sp, s->pc);
printf("\n");
}
misc_instruction_t convert_raw2misc(raw_instruction_t* r)
{
misc_instruction_t i;
uint32_t inst = (uint32_t) *r;
inst = __builtin_bswap32(inst);
i.opcode = (inst >> 23) & 0x3f;
i.imm = 0xffffff;
return i;
}
register_instruction_t convert_raw2register(raw_instruction_t* r)
{
register_instruction_t i;
uint32_t inst = (uint32_t) *r;
i.opcode = (inst >> 23) & 0x7f;
i.dest = (inst >> 18) & 0x1f;
i.src1 = (inst >> 13) & 0x1f;
i.src2 = (inst >> 8) & 0x1f;
#ifdef _DEBUG
printf("convert_raw2register: opcode: 0b%04b, dest: 0b%05b, src1: 0b%021b, src2: 0b%021b\n", i.opcode, i.dest, i.src1, i.src2);
#endif
return i;
}
ls_instruction_t convert_raw2ls(raw_instruction_t* r)
{
ls_instruction_t i;
uint32_t inst = (uint32_t) *r;
i.opcode = (inst >> 26) & 0xf;
i.reg = (inst >> 21) & 0x1f;
i.imm = inst & 0x1FFFFF;
#ifdef _DEBUG
printf("convert_raw2ls: opcode: 0b%04b, reg: 0b%05b, imm: 0b%021b\n", i.opcode, i.reg, i.imm);
#endif
return i;
}