extend regs with DWARF registers mappings and read/write machine ops

This commit is contained in:
Nikita Smith
2025-12-16 10:47:05 -08:00
parent 952afd49a7
commit 44123e9712
3 changed files with 93 additions and 0 deletions
+2
View File
@@ -229,6 +229,7 @@
#include "radbin/radbin.h"
#include "regs/regs.h"
#include "regs/rdi/regs_rdi.h"
#include "regs/dwarf/regs_dwarf.h"
#include "dbg_info/dbg_info.h"
#include "disasm/disasm.h"
#include "stap/stap_parse.h"
@@ -281,6 +282,7 @@
#include "radbin/radbin.c"
#include "regs/regs.c"
#include "regs/rdi/regs_rdi.c"
#include "regs/dwarf/regs_dwarf.c"
#include "dbg_info/dbg_info.c"
#include "disasm/disasm.c"
#include "stap/stap_parse.c"
+77
View File
@@ -0,0 +1,77 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal REGS_RegCode
reg_code_from_dw_reg_x64(DW_Reg reg)
{
switch (reg) {
#define X(_SRC, _SRC_ID, _DST_ID, ...) case _SRC_ID: return REGS_RegCodeX64_##_DST_ID;
DW_Regs_X64_XList
#undef X
}
return REGS_RegCodeX64_NULL;
}
internal REGS_RegCode
reg_code_from_dw_reg(Arch arch, DW_Reg reg)
{
REGS_RegCode result = 0;
switch (arch) {
case Arch_Null: {} break;
case Arch_x64: { result = reg_code_from_dw_reg_x64(reg); } break;
case Arch_x86:
case Arch_arm32:
case Arch_arm64: { NotImplemented; } break;
default: { InvalidPath; } break;
}
return result;
}
internal
MACHINE_OP_REG_READ(regs_read_dwarf_x64)
{
// map DWARF register to -> the internal register
REGS_RegBlockX64 *regs = ud;
U64 reg_size = 0; void *reg_bytes = 0;
switch (reg_id) {
#define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break;
DW_Regs_X64_XList
#undef X
default: { InvalidPath; } break;
}
// copy out register value
MachineOpResult status = MachineOpResult_Fail;
if (reg_size > 0) {
AssertAlways(reg_size == buffer_max);
MemoryCopy(buffer, reg_bytes, reg_size);
status = MachineOpResult_Ok;
}
return status;
}
internal
MACHINE_OP_REG_WRITE(regs_write_dwarf_x64)
{
// map DWARF register to -> the internal register
REGS_RegBlockX64 *regs = ud;
U64 reg_size = 0; void *reg_bytes = 0;
switch (reg_id) {
#define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break;
DW_Regs_X64_XList
#undef X
default: { InvalidPath; } break;
}
// write value to the register
MachineOpResult status = MachineOpResult_Fail;
if (reg_size > 0) {
AssertAlways(value_size <= reg_size);
MemoryCopy(reg_bytes, value, value_size);
status = MachineOpResult_Fail;
}
return status;
}
+14
View File
@@ -0,0 +1,14 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef REGS_DWARF_H
#define REGS_DWARF_H
internal REGS_RegCode reg_code_from_dw_reg_x64(DW_Reg reg);
internal REGS_RegCode reg_code_from_dw_reg(Arch arch, DW_Reg reg);
internal MACHINE_OP_REG_READ(regs_read_dwarf_x64);
internal MACHINE_OP_REG_WRITE(regs_write_dwarf_x64);
#endif // REGS_DWARF_H