2026-05-25 10:33:29 +01:00
|
|
|
#include <bshell/runtime/opcode.h>
|
2026-05-17 15:33:20 +01:00
|
|
|
#include <fx/int.h>
|
|
|
|
|
|
2026-05-25 10:33:29 +01:00
|
|
|
#define BSHELL_OPCODE_MAX 0xFF
|
|
|
|
|
#define ARG_MAX 0xFFFFFF
|
2026-05-17 15:33:20 +01:00
|
|
|
|
|
|
|
|
bshell_instruction bshell_instruction_encode(
|
|
|
|
|
enum bshell_opcode opcode,
|
|
|
|
|
uint32_t arg)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
if (opcode > BSHELL_OPCODE_MAX) {
|
2026-05-17 15:33:20 +01:00
|
|
|
return BSHELL_INSTRUCTION_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 10:33:29 +01:00
|
|
|
return fx_u32_htob((opcode & BSHELL_OPCODE_MAX) | (arg & ARG_MAX) << 8);
|
2026-05-17 15:33:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void bshell_instruction_decode(
|
|
|
|
|
bshell_instruction instr,
|
|
|
|
|
enum bshell_opcode *out_opcode,
|
|
|
|
|
uint32_t *out_arg)
|
|
|
|
|
{
|
|
|
|
|
instr = fx_u32_btoh(instr);
|
2026-05-25 10:33:29 +01:00
|
|
|
*out_opcode = (instr & BSHELL_OPCODE_MAX);
|
2026-05-17 15:33:20 +01:00
|
|
|
*out_arg = ((instr >> 8) & ARG_MAX);
|
|
|
|
|
}
|