dasm -> dasmi; make room for new dasm_cache layer

This commit is contained in:
Ryan Fleury
2024-03-28 09:45:41 -07:00
parent dbb0c1e0a4
commit f46691d79a
10 changed files with 208 additions and 201 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
ctrl_init(); ctrl_init();
#endif #endif
#if defined(DASM_H) #if defined(DASM_H)
dasm_init(); dasmi_init();
#endif #endif
#if defined(OS_GRAPHICAL_H) #if defined(OS_GRAPHICAL_H)
os_graphical_init(); os_graphical_init();
+111 -111
View File
@@ -5,30 +5,30 @@
//~ rjf: Main Layer Initialization //~ rjf: Main Layer Initialization
internal void internal void
dasm_init(void) dasmi_init(void)
{ {
Arena *arena = arena_alloc(); Arena *arena = arena_alloc();
dasm_shared = push_array(arena, DASM_Shared, 1); dasmi_shared = push_array(arena, DASMI_Shared, 1);
dasm_shared->arena = arena; dasmi_shared->arena = arena;
dasm_shared->entity_map.slots_count = 1024; dasmi_shared->entity_map.slots_count = 1024;
dasm_shared->entity_map.slots = push_array(arena, DASM_EntitySlot, dasm_shared->entity_map.slots_count); dasmi_shared->entity_map.slots = push_array(arena, DASMI_EntitySlot, dasmi_shared->entity_map.slots_count);
dasm_shared->entity_map_stripes.count = 64; dasmi_shared->entity_map_stripes.count = 64;
dasm_shared->entity_map_stripes.v = push_array(arena, DASM_Stripe, dasm_shared->entity_map_stripes.count); dasmi_shared->entity_map_stripes.v = push_array(arena, DASMI_Stripe, dasmi_shared->entity_map_stripes.count);
for(U64 idx = 0; idx < dasm_shared->entity_map_stripes.count; idx += 1) for(U64 idx = 0; idx < dasmi_shared->entity_map_stripes.count; idx += 1)
{ {
dasm_shared->entity_map_stripes.v[idx].arena = arena_alloc(); dasmi_shared->entity_map_stripes.v[idx].arena = arena_alloc();
dasm_shared->entity_map_stripes.v[idx].rw_mutex = os_rw_mutex_alloc(); dasmi_shared->entity_map_stripes.v[idx].rw_mutex = os_rw_mutex_alloc();
dasm_shared->entity_map_stripes.v[idx].cv = os_condition_variable_alloc(); dasmi_shared->entity_map_stripes.v[idx].cv = os_condition_variable_alloc();
} }
dasm_shared->u2d_ring_mutex = os_mutex_alloc(); dasmi_shared->u2d_ring_mutex = os_mutex_alloc();
dasm_shared->u2d_ring_cv = os_condition_variable_alloc(); dasmi_shared->u2d_ring_cv = os_condition_variable_alloc();
dasm_shared->u2d_ring_size = KB(64); dasmi_shared->u2d_ring_size = KB(64);
dasm_shared->u2d_ring_base = push_array_no_zero(arena, U8, dasm_shared->u2d_ring_size); dasmi_shared->u2d_ring_base = push_array_no_zero(arena, U8, dasmi_shared->u2d_ring_size);
dasm_shared->decode_thread_count = Max(1, os_logical_core_count()-1); dasmi_shared->decode_thread_count = Max(1, os_logical_core_count()-1);
dasm_shared->decode_threads = push_array(arena, OS_Handle, dasm_shared->decode_thread_count); dasmi_shared->decode_threads = push_array(arena, OS_Handle, dasmi_shared->decode_thread_count);
for(U64 idx = 0; idx < dasm_shared->decode_thread_count; idx += 1) for(U64 idx = 0; idx < dasmi_shared->decode_thread_count; idx += 1)
{ {
dasm_shared->decode_threads[idx] = os_launch_thread(dasm_decode_thread_entry_point, (void *)idx, 0); dasmi_shared->decode_threads[idx] = os_launch_thread(dasmi_decode_thread_entry_point, (void *)idx, 0);
} }
} }
@@ -36,7 +36,7 @@ dasm_init(void)
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
internal U64 internal U64
dasm_hash_from_string(String8 string) dasmi_hash_from_string(String8 string)
{ {
U64 result = 5381; U64 result = 5381;
for(U64 i = 0; i < string.size; i += 1) for(U64 i = 0; i < string.size; i += 1)
@@ -50,13 +50,13 @@ dasm_hash_from_string(String8 string)
//~ rjf: Instruction Type Functions //~ rjf: Instruction Type Functions
internal void internal void
dasm_inst_chunk_list_push(Arena *arena, DASM_InstChunkList *list, U64 cap, DASM_Inst *inst) dasmi_inst_chunk_list_push(Arena *arena, DASMI_InstChunkList *list, U64 cap, DASMI_Inst *inst)
{ {
DASM_InstChunkNode *node = list->last; DASMI_InstChunkNode *node = list->last;
if(node == 0 || node->count >= node->cap) if(node == 0 || node->count >= node->cap)
{ {
node = push_array(arena, DASM_InstChunkNode, 1); node = push_array(arena, DASMI_InstChunkNode, 1);
node->v = push_array_no_zero(arena, DASM_Inst, cap); node->v = push_array_no_zero(arena, DASMI_Inst, cap);
node->cap = cap; node->cap = cap;
SLLQueuePush(list->first, list->last, node); SLLQueuePush(list->first, list->last, node);
list->node_count += 1; list->node_count += 1;
@@ -66,23 +66,23 @@ dasm_inst_chunk_list_push(Arena *arena, DASM_InstChunkList *list, U64 cap, DASM_
list->inst_count += 1; list->inst_count += 1;
} }
internal DASM_InstArray internal DASMI_InstArray
dasm_inst_array_from_chunk_list(Arena *arena, DASM_InstChunkList *list) dasmi_inst_array_from_chunk_list(Arena *arena, DASMI_InstChunkList *list)
{ {
DASM_InstArray array = {0}; DASMI_InstArray array = {0};
array.count = list->inst_count; array.count = list->inst_count;
array.v = push_array_no_zero(arena, DASM_Inst, array.count); array.v = push_array_no_zero(arena, DASMI_Inst, array.count);
U64 idx = 0; U64 idx = 0;
for(DASM_InstChunkNode *n = list->first; n != 0; n = n->next) for(DASMI_InstChunkNode *n = list->first; n != 0; n = n->next)
{ {
MemoryCopy(array.v+idx, n->v, sizeof(DASM_Inst)*n->count); MemoryCopy(array.v+idx, n->v, sizeof(DASMI_Inst)*n->count);
idx += n->count; idx += n->count;
} }
return array; return array;
} }
internal U64 internal U64
dasm_inst_array_idx_from_off__linear_scan(DASM_InstArray *array, U64 off) dasmi_inst_array_idx_from_off__linear_scan(DASMI_InstArray *array, U64 off)
{ {
U64 result = 0; U64 result = 0;
for(U64 idx = 0; idx < array->count; idx += 1) for(U64 idx = 0; idx < array->count; idx += 1)
@@ -97,7 +97,7 @@ dasm_inst_array_idx_from_off__linear_scan(DASM_InstArray *array, U64 off)
} }
internal U64 internal U64
dasm_inst_array_off_from_idx(DASM_InstArray *array, U64 idx) dasmi_inst_array_off_from_idx(DASMI_InstArray *array, U64 idx)
{ {
U64 off = 0; U64 off = 0;
if(idx < array->count) if(idx < array->count)
@@ -119,10 +119,10 @@ dasm_inst_array_off_from_idx(DASM_InstArray *array, U64 idx)
#include "third_party/udis86/libudis86/syn.c" #include "third_party/udis86/libudis86/syn.c"
#include "third_party/udis86/libudis86/udis86.c" #include "third_party/udis86/libudis86/udis86.c"
internal DASM_InstChunkList internal DASMI_InstChunkList
dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data) dasmi_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data)
{ {
DASM_InstChunkList inst_list = {0}; DASMI_InstChunkList inst_list = {0};
switch(arch) switch(arch)
{ {
default:{}break; default:{}break;
@@ -157,8 +157,8 @@ dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_coun
// rjf: push // rjf: push
String8 string = push_str8f(arena, "%s", udc.asm_buf); String8 string = push_str8f(arena, "%s", udc.asm_buf);
DASM_Inst inst = {string, off, rel_voff}; DASMI_Inst inst = {string, off, rel_voff};
dasm_inst_chunk_list_push(arena, &inst_list, 1024, &inst); dasmi_inst_chunk_list_push(arena, &inst_list, 1024, &inst);
// rjf: increment // rjf: increment
off += size; off += size;
@@ -178,21 +178,21 @@ dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_coun
//- rjf: opening handles & correllation with module //- rjf: opening handles & correllation with module
internal DASM_Handle internal DASMI_Handle
dasm_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle process, Rng1U64 vaddr_range, Architecture arch) dasmi_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle process, Rng1U64 vaddr_range, Architecture arch)
{ {
DASM_Handle result = {0}; DASMI_Handle result = {0};
if(machine != 0 && process.u64[0] != 0) if(machine != 0 && process.u64[0] != 0)
{ {
U64 hash = dasm_hash_from_string(str8_struct(&process)); U64 hash = dasmi_hash_from_string(str8_struct(&process));
U64 slot_idx = hash%dasm_shared->entity_map.slots_count; U64 slot_idx = hash%dasmi_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count; U64 stripe_idx = slot_idx%dasmi_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx]; DASMI_EntitySlot *slot = &dasmi_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx]; DASMI_Stripe *stripe = &dasmi_shared->entity_map_stripes.v[stripe_idx];
OS_MutexScopeW(stripe->rw_mutex) OS_MutexScopeW(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->machine_id == machine && if(e->machine_id == machine &&
dmn_handle_match(e->process, process) && dmn_handle_match(e->process, process) &&
@@ -205,13 +205,13 @@ dasm_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle proc
} }
if(entity == 0) if(entity == 0)
{ {
entity = push_array(stripe->arena, DASM_Entity, 1); entity = push_array(stripe->arena, DASMI_Entity, 1);
SLLQueuePush(slot->first, slot->last, entity); SLLQueuePush(slot->first, slot->last, entity);
entity->machine_id = machine; entity->machine_id = machine;
entity->process = process; entity->process = process;
entity->vaddr_range= vaddr_range; entity->vaddr_range= vaddr_range;
entity->arch = arch; entity->arch = arch;
entity->id = ins_atomic_u64_inc_eval(&dasm_shared->entity_id_gen); entity->id = ins_atomic_u64_inc_eval(&dasmi_shared->entity_id_gen);
entity->decode_inst_arena = arena_alloc__sized(MB(256), KB(64)); entity->decode_inst_arena = arena_alloc__sized(MB(256), KB(64));
entity->decode_string_arena = arena_alloc__sized(GB(1), KB(64)); entity->decode_string_arena = arena_alloc__sized(GB(1), KB(64));
} }
@@ -224,21 +224,21 @@ dasm_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle proc
//- rjf: asking for top-level info of a handle //- rjf: asking for top-level info of a handle
internal DASM_BinaryInfo internal DASMI_BinaryInfo
dasm_binary_info_from_handle(Arena *arena, DASM_Handle handle) dasmi_binary_info_from_handle(Arena *arena, DASMI_Handle handle)
{ {
DASM_BinaryInfo info = {0}; DASMI_BinaryInfo info = {0};
{ {
U64 hash = handle.u64[0]; U64 hash = handle.u64[0];
U64 id = handle.u64[1]; U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count; U64 slot_idx = hash%dasmi_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count; U64 stripe_idx = slot_idx%dasmi_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx]; DASMI_EntitySlot *slot = &dasmi_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx]; DASMI_Stripe *stripe = &dasmi_shared->entity_map_stripes.v[stripe_idx];
OS_MutexScopeR(stripe->rw_mutex) OS_MutexScopeR(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
@@ -261,23 +261,23 @@ dasm_binary_info_from_handle(Arena *arena, DASM_Handle handle)
//- rjf: asking for decoded instructions //- rjf: asking for decoded instructions
internal DASM_InstArray internal DASMI_InstArray
dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us) dasmi_inst_array_from_handle(Arena *arena, DASMI_Handle handle, U64 endt_us)
{ {
DASM_InstArray result = {0}; DASMI_InstArray result = {0};
if(handle.u64[0] != 0 || handle.u64[1] != 0) if(handle.u64[0] != 0 || handle.u64[1] != 0)
{ {
U64 hash = handle.u64[0]; U64 hash = handle.u64[0];
U64 id = handle.u64[1]; U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count; U64 slot_idx = hash%dasmi_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count; U64 stripe_idx = slot_idx%dasmi_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx]; DASMI_EntitySlot *slot = &dasmi_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx]; DASMI_Stripe *stripe = &dasmi_shared->entity_map_stripes.v[stripe_idx];
B32 sent = 0; B32 sent = 0;
OS_MutexScopeR(stripe->rw_mutex) for(;;) OS_MutexScopeR(stripe->rw_mutex) for(;;)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
@@ -294,8 +294,8 @@ dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us)
if(bytes_processed == bytes_to_process && bytes_processed != 0) if(bytes_processed == bytes_to_process && bytes_processed != 0)
{ {
result.count = entity->decode_inst_array.count; result.count = entity->decode_inst_array.count;
result.v = push_array_no_zero(arena, DASM_Inst, result.count); result.v = push_array_no_zero(arena, DASMI_Inst, result.count);
MemoryCopy(result.v, entity->decode_inst_array.v, sizeof(DASM_Inst)*result.count); MemoryCopy(result.v, entity->decode_inst_array.v, sizeof(DASMI_Inst)*result.count);
for(U64 idx = 0; idx < result.count; idx += 1) for(U64 idx = 0; idx < result.count; idx += 1)
{ {
result.v[idx].string = push_str8_copy(arena, result.v[idx].string); result.v[idx].string = push_str8_copy(arena, result.v[idx].string);
@@ -305,8 +305,8 @@ dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us)
} }
if(!sent && entity != 0 && last_time_sent_us+10000 <= os_now_microseconds()) if(!sent && entity != 0 && last_time_sent_us+10000 <= os_now_microseconds())
{ {
DASM_DecodeRequest req = {handle}; DASMI_DecodeRequest req = {handle};
sent = dasm_u2d_enqueue_request(&req, endt_us); sent = dasmi_u2d_enqueue_request(&req, endt_us);
ins_atomic_u64_eval_assign(&entity->last_time_sent_us, os_now_microseconds()); ins_atomic_u64_eval_assign(&entity->last_time_sent_us, os_now_microseconds());
} }
if(os_now_microseconds() >= endt_us) if(os_now_microseconds() >= endt_us)
@@ -323,70 +323,70 @@ dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us)
//~ rjf: Decode Threads //~ rjf: Decode Threads
internal B32 internal B32
dasm_u2d_enqueue_request(DASM_DecodeRequest *req, U64 endt_us) dasmi_u2d_enqueue_request(DASMI_DecodeRequest *req, U64 endt_us)
{ {
B32 result = 0; B32 result = 0;
OS_MutexScope(dasm_shared->u2d_ring_mutex) for(;;) OS_MutexScope(dasmi_shared->u2d_ring_mutex) for(;;)
{ {
U64 unconsumed_size = (dasm_shared->u2d_ring_write_pos-dasm_shared->u2d_ring_read_pos); U64 unconsumed_size = (dasmi_shared->u2d_ring_write_pos-dasmi_shared->u2d_ring_read_pos);
U64 available_size = (dasm_shared->u2d_ring_size-unconsumed_size); U64 available_size = (dasmi_shared->u2d_ring_size-unconsumed_size);
if(available_size >= sizeof(*req)) if(available_size >= sizeof(*req))
{ {
result = 1; result = 1;
dasm_shared->u2d_ring_write_pos += ring_write_struct(dasm_shared->u2d_ring_base, dasm_shared->u2d_ring_size, dasm_shared->u2d_ring_write_pos, req); dasmi_shared->u2d_ring_write_pos += ring_write_struct(dasmi_shared->u2d_ring_base, dasmi_shared->u2d_ring_size, dasmi_shared->u2d_ring_write_pos, req);
dasm_shared->u2d_ring_write_pos += 7; dasmi_shared->u2d_ring_write_pos += 7;
dasm_shared->u2d_ring_write_pos -= dasm_shared->u2d_ring_write_pos%8; dasmi_shared->u2d_ring_write_pos -= dasmi_shared->u2d_ring_write_pos%8;
break; break;
} }
if(os_now_microseconds() >= endt_us) if(os_now_microseconds() >= endt_us)
{ {
break; break;
} }
os_condition_variable_wait(dasm_shared->u2d_ring_cv, dasm_shared->u2d_ring_mutex, endt_us); os_condition_variable_wait(dasmi_shared->u2d_ring_cv, dasmi_shared->u2d_ring_mutex, endt_us);
} }
if(result) if(result)
{ {
os_condition_variable_broadcast(dasm_shared->u2d_ring_cv); os_condition_variable_broadcast(dasmi_shared->u2d_ring_cv);
} }
return result; return result;
} }
internal DASM_DecodeRequest internal DASMI_DecodeRequest
dasm_u2d_dequeue_request(void) dasmi_u2d_dequeue_request(void)
{ {
DASM_DecodeRequest req = {0}; DASMI_DecodeRequest req = {0};
OS_MutexScope(dasm_shared->u2d_ring_mutex) for(;;) OS_MutexScope(dasmi_shared->u2d_ring_mutex) for(;;)
{ {
U64 unconsumed_size = (dasm_shared->u2d_ring_write_pos-dasm_shared->u2d_ring_read_pos); U64 unconsumed_size = (dasmi_shared->u2d_ring_write_pos-dasmi_shared->u2d_ring_read_pos);
if(unconsumed_size >= sizeof(DASM_DecodeRequest)) if(unconsumed_size >= sizeof(DASMI_DecodeRequest))
{ {
dasm_shared->u2d_ring_read_pos += ring_read_struct(dasm_shared->u2d_ring_base, dasm_shared->u2d_ring_size, dasm_shared->u2d_ring_read_pos, &req); dasmi_shared->u2d_ring_read_pos += ring_read_struct(dasmi_shared->u2d_ring_base, dasmi_shared->u2d_ring_size, dasmi_shared->u2d_ring_read_pos, &req);
dasm_shared->u2d_ring_read_pos += 7; dasmi_shared->u2d_ring_read_pos += 7;
dasm_shared->u2d_ring_read_pos -= dasm_shared->u2d_ring_read_pos%8; dasmi_shared->u2d_ring_read_pos -= dasmi_shared->u2d_ring_read_pos%8;
break; break;
} }
os_condition_variable_wait(dasm_shared->u2d_ring_cv, dasm_shared->u2d_ring_mutex, max_U64); os_condition_variable_wait(dasmi_shared->u2d_ring_cv, dasmi_shared->u2d_ring_mutex, max_U64);
} }
os_condition_variable_broadcast(dasm_shared->u2d_ring_cv); os_condition_variable_broadcast(dasmi_shared->u2d_ring_cv);
return req; return req;
} }
internal void internal void
dasm_decode_thread_entry_point(void *p) dasmi_decode_thread_entry_point(void *p)
{ {
for(;;) for(;;)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
//- rjf: get next request & unpack //- rjf: get next request & unpack
DASM_DecodeRequest req = dasm_u2d_dequeue_request(); DASMI_DecodeRequest req = dasmi_u2d_dequeue_request();
DASM_Handle handle = req.handle; DASMI_Handle handle = req.handle;
U64 hash = handle.u64[0]; U64 hash = handle.u64[0];
U64 id = handle.u64[1]; U64 id = handle.u64[1];
U64 slot_idx = hash%dasm_shared->entity_map.slots_count; U64 slot_idx = hash%dasmi_shared->entity_map.slots_count;
U64 stripe_idx = slot_idx%dasm_shared->entity_map_stripes.count; U64 stripe_idx = slot_idx%dasmi_shared->entity_map_stripes.count;
DASM_EntitySlot *slot = &dasm_shared->entity_map.slots[slot_idx]; DASMI_EntitySlot *slot = &dasmi_shared->entity_map.slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->entity_map_stripes.v[stripe_idx]; DASMI_Stripe *stripe = &dasmi_shared->entity_map_stripes.v[stripe_idx];
//- rjf: request -> ctrl info //- rjf: request -> ctrl info
B32 is_first_to_task = 0; B32 is_first_to_task = 0;
@@ -397,8 +397,8 @@ dasm_decode_thread_entry_point(void *p)
U64 *bytes_processed_counter = 0; U64 *bytes_processed_counter = 0;
OS_MutexScopeR(stripe->rw_mutex) OS_MutexScopeR(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
@@ -432,8 +432,8 @@ dasm_decode_thread_entry_point(void *p)
{ {
OS_MutexScopeW(stripe->rw_mutex) OS_MutexScopeW(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
@@ -463,14 +463,14 @@ dasm_decode_thread_entry_point(void *p)
//- rjf: read next chunk & decode //- rjf: read next chunk & decode
String8 data = {0}; String8 data = {0};
DASM_InstChunkList inst_list = {0}; DASMI_InstChunkList inst_list = {0};
if(good_task) if(good_task)
{ {
data.str = push_array_no_zero(scratch.arena, U8, dim_1u64(chunk_vaddr_range)); data.str = push_array_no_zero(scratch.arena, U8, dim_1u64(chunk_vaddr_range));
data.size = dmn_process_read(ctrl_process, chunk_vaddr_range, data.str); data.size = dmn_process_read(ctrl_process, chunk_vaddr_range, data.str);
if(data.size != 0) if(data.size != 0)
{ {
inst_list = dasm_inst_chunk_list_from_arch_addr_data(scratch.arena, bytes_processed_counter, arch, chunk_vaddr_range.min, data); inst_list = dasmi_inst_chunk_list_from_arch_addr_data(scratch.arena, bytes_processed_counter, arch, chunk_vaddr_range.min, data);
} }
} }
@@ -478,8 +478,8 @@ dasm_decode_thread_entry_point(void *p)
{ {
OS_MutexScopeW(stripe->rw_mutex) OS_MutexScopeW(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
@@ -489,11 +489,11 @@ dasm_decode_thread_entry_point(void *p)
} }
if(entity != 0) if(entity != 0)
{ {
DASM_Inst *new_chunk_base = push_array(entity->decode_inst_arena, DASM_Inst, inst_list.inst_count); DASMI_Inst *new_chunk_base = push_array(entity->decode_inst_arena, DASMI_Inst, inst_list.inst_count);
U64 off = 0; U64 off = 0;
for(DASM_InstChunkNode *node = inst_list.first; node != 0; node = node->next) for(DASMI_InstChunkNode *node = inst_list.first; node != 0; node = node->next)
{ {
MemoryCopy(new_chunk_base+off, node->v, sizeof(DASM_Inst)*node->count); MemoryCopy(new_chunk_base+off, node->v, sizeof(DASMI_Inst)*node->count);
off += node->count; off += node->count;
} }
for(U64 idx = 0; idx < inst_list.inst_count; idx += 1) for(U64 idx = 0; idx < inst_list.inst_count; idx += 1)
@@ -517,8 +517,8 @@ dasm_decode_thread_entry_point(void *p)
{ {
OS_MutexScopeR(stripe->rw_mutex) OS_MutexScopeR(stripe->rw_mutex)
{ {
DASM_Entity *entity = 0; DASMI_Entity *entity = 0;
for(DASM_Entity *e = slot->first; e != 0; e = e->next) for(DASMI_Entity *e = slot->first; e != 0; e = e->next)
{ {
if(e->id == id) if(e->id == id)
{ {
+54 -54
View File
@@ -7,8 +7,8 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: Handle Type //~ rjf: Handle Type
typedef struct DASM_Handle DASM_Handle; typedef struct DASMI_Handle DASMI_Handle;
struct DASM_Handle struct DASMI_Handle
{ {
U64 u64[2]; U64 u64[2];
}; };
@@ -16,64 +16,64 @@ struct DASM_Handle
//////////////////////////////// ////////////////////////////////
//~ rjf: Instruction Types //~ rjf: Instruction Types
typedef struct DASM_Inst DASM_Inst; typedef struct DASMI_Inst DASMI_Inst;
struct DASM_Inst struct DASMI_Inst
{ {
String8 string; String8 string;
U64 off; U64 off;
U64 addr; U64 addr;
}; };
typedef struct DASM_InstChunkNode DASM_InstChunkNode; typedef struct DASMI_InstChunkNode DASMI_InstChunkNode;
struct DASM_InstChunkNode struct DASMI_InstChunkNode
{ {
DASM_InstChunkNode *next; DASMI_InstChunkNode *next;
DASM_Inst *v; DASMI_Inst *v;
U64 cap; U64 cap;
U64 count; U64 count;
}; };
typedef struct DASM_InstChunkList DASM_InstChunkList; typedef struct DASMI_InstChunkList DASMI_InstChunkList;
struct DASM_InstChunkList struct DASMI_InstChunkList
{ {
DASM_InstChunkNode *first; DASMI_InstChunkNode *first;
DASM_InstChunkNode *last; DASMI_InstChunkNode *last;
U64 node_count; U64 node_count;
U64 inst_count; U64 inst_count;
}; };
typedef struct DASM_InstArray DASM_InstArray; typedef struct DASMI_InstArray DASMI_InstArray;
struct DASM_InstArray struct DASMI_InstArray
{ {
DASM_Inst *v; DASMI_Inst *v;
U64 count; U64 count;
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Striped Access Types //~ rjf: Striped Access Types
typedef struct DASM_Stripe DASM_Stripe; typedef struct DASMI_Stripe DASMI_Stripe;
struct DASM_Stripe struct DASMI_Stripe
{ {
Arena *arena; Arena *arena;
OS_Handle cv; OS_Handle cv;
OS_Handle rw_mutex; OS_Handle rw_mutex;
}; };
typedef struct DASM_StripeTable DASM_StripeTable; typedef struct DASMI_StripeTable DASMI_StripeTable;
struct DASM_StripeTable struct DASMI_StripeTable
{ {
U64 count; U64 count;
DASM_Stripe *v; DASMI_Stripe *v;
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Entity Cache Types //~ rjf: Entity Cache Types
typedef struct DASM_Entity DASM_Entity; typedef struct DASMI_Entity DASMI_Entity;
struct DASM_Entity struct DASMI_Entity
{ {
DASM_Entity *next; DASMI_Entity *next;
// rjf: key info // rjf: key info
CTRL_MachineID machine_id; CTRL_MachineID machine_id;
@@ -91,28 +91,28 @@ struct DASM_Entity
// rjf: decoded instruction data // rjf: decoded instruction data
Arena *decode_inst_arena; Arena *decode_inst_arena;
Arena *decode_string_arena; Arena *decode_string_arena;
DASM_InstArray decode_inst_array; DASMI_InstArray decode_inst_array;
}; };
typedef struct DASM_EntitySlot DASM_EntitySlot; typedef struct DASMI_EntitySlot DASMI_EntitySlot;
struct DASM_EntitySlot struct DASMI_EntitySlot
{ {
DASM_Entity *first; DASMI_Entity *first;
DASM_Entity *last; DASMI_Entity *last;
}; };
typedef struct DASM_EntityMap DASM_EntityMap; typedef struct DASMI_EntityMap DASMI_EntityMap;
struct DASM_EntityMap struct DASMI_EntityMap
{ {
U64 slots_count; U64 slots_count;
DASM_EntitySlot *slots; DASMI_EntitySlot *slots;
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Introspection Info Types //~ rjf: Introspection Info Types
typedef struct DASM_BinaryInfo DASM_BinaryInfo; typedef struct DASMI_BinaryInfo DASMI_BinaryInfo;
struct DASM_BinaryInfo struct DASMI_BinaryInfo
{ {
CTRL_MachineID machine_id; CTRL_MachineID machine_id;
DMN_Handle process; DMN_Handle process;
@@ -124,23 +124,23 @@ struct DASM_BinaryInfo
//////////////////////////////// ////////////////////////////////
//~ rjf: Decode Request Types //~ rjf: Decode Request Types
typedef struct DASM_DecodeRequest DASM_DecodeRequest; typedef struct DASMI_DecodeRequest DASMI_DecodeRequest;
struct DASM_DecodeRequest struct DASMI_DecodeRequest
{ {
DASM_Handle handle; DASMI_Handle handle;
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Shared State //~ rjf: Shared State
typedef struct DASM_Shared DASM_Shared; typedef struct DASMI_Shared DASMI_Shared;
struct DASM_Shared struct DASMI_Shared
{ {
Arena *arena; Arena *arena;
// rjf: entity table // rjf: entity table
DASM_EntityMap entity_map; DASMI_EntityMap entity_map;
DASM_StripeTable entity_map_stripes; DASMI_StripeTable entity_map_stripes;
U64 entity_id_gen; U64 entity_id_gen;
// rjf: user -> decode ring // rjf: user -> decode ring
@@ -159,49 +159,49 @@ struct DASM_Shared
//////////////////////////////// ////////////////////////////////
//~ rjf: Globals //~ rjf: Globals
global DASM_Shared *dasm_shared = 0; global DASMI_Shared *dasmi_shared = 0;
//////////////////////////////// ////////////////////////////////
//~ rjf: Main Layer Initialization //~ rjf: Main Layer Initialization
internal void dasm_init(void); internal void dasmi_init(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
internal U64 dasm_hash_from_string(String8 string); internal U64 dasmi_hash_from_string(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: Instruction Type Functions //~ rjf: Instruction Type Functions
internal void dasm_inst_chunk_list_push(Arena *arena, DASM_InstChunkList *list, U64 cap, DASM_Inst *inst); internal void dasmi_inst_chunk_list_push(Arena *arena, DASMI_InstChunkList *list, U64 cap, DASMI_Inst *inst);
internal DASM_InstArray dasm_inst_array_from_chunk_list(Arena *arena, DASM_InstChunkList *list); internal DASMI_InstArray dasmi_inst_array_from_chunk_list(Arena *arena, DASMI_InstChunkList *list);
internal U64 dasm_inst_array_idx_from_off__linear_scan(DASM_InstArray *array, U64 off); internal U64 dasmi_inst_array_idx_from_off__linear_scan(DASMI_InstArray *array, U64 off);
internal U64 dasm_inst_array_off_from_idx(DASM_InstArray *array, U64 idx); internal U64 dasmi_inst_array_off_from_idx(DASMI_InstArray *array, U64 idx);
//////////////////////////////// ////////////////////////////////
//~ rjf: Disassembly Functions //~ rjf: Disassembly Functions
internal DASM_InstChunkList dasm_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data); internal DASMI_InstChunkList dasmi_inst_chunk_list_from_arch_addr_data(Arena *arena, U64 *bytes_processed_counter, Architecture arch, U64 addr, String8 data);
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Lookups //~ rjf: Cache Lookups
//- rjf: opening handles & correllation with module //- rjf: opening handles & correllation with module
internal DASM_Handle dasm_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle process, Rng1U64 vaddr_range, Architecture arch); internal DASMI_Handle dasmi_handle_from_ctrl_process_range_arch(CTRL_MachineID machine, DMN_Handle process, Rng1U64 vaddr_range, Architecture arch);
//- rjf: asking for top-level info of a handle //- rjf: asking for top-level info of a handle
internal DASM_BinaryInfo dasm_binary_info_from_handle(Arena *arena, DASM_Handle handle); internal DASMI_BinaryInfo dasmi_binary_info_from_handle(Arena *arena, DASMI_Handle handle);
//- rjf: asking for decoded instructions //- rjf: asking for decoded instructions
internal DASM_InstArray dasm_inst_array_from_handle(Arena *arena, DASM_Handle handle, U64 endt_us); internal DASMI_InstArray dasmi_inst_array_from_handle(Arena *arena, DASMI_Handle handle, U64 endt_us);
//////////////////////////////// ////////////////////////////////
//~ rjf: Decode Threads //~ rjf: Decode Threads
internal B32 dasm_u2d_enqueue_request(DASM_DecodeRequest *req, U64 endt_us); internal B32 dasmi_u2d_enqueue_request(DASMI_DecodeRequest *req, U64 endt_us);
internal DASM_DecodeRequest dasm_u2d_dequeue_request(void); internal DASMI_DecodeRequest dasmi_u2d_dequeue_request(void);
internal void dasm_decode_thread_entry_point(void *p); internal void dasmi_decode_thread_entry_point(void *p);
#endif //DASM_H #endif //DASM_H
View File
+7
View File
@@ -0,0 +1,7 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DASM_CACHE_H
#define DASM_CACHE_H
#endif // DASM_CACHE_H
+2 -2
View File
@@ -1400,11 +1400,11 @@ df_txti_handle_from_entity(DF_Entity *entity)
//- rjf: entity -> disasm info //- rjf: entity -> disasm info
internal DASM_Handle internal DASMI_Handle
df_dasm_handle_from_process_vaddr(DF_Entity *process, U64 vaddr) df_dasm_handle_from_process_vaddr(DF_Entity *process, U64 vaddr)
{ {
Rng1U64 disasm_vaddr_rng = r1u64(AlignDownPow2(vaddr, KB(4)), AlignDownPow2(vaddr, KB(4)) + KB(16)); Rng1U64 disasm_vaddr_rng = r1u64(AlignDownPow2(vaddr, KB(4)), AlignDownPow2(vaddr, KB(4)) + KB(16));
DASM_Handle dasm_handle = dasm_handle_from_ctrl_process_range_arch(process->ctrl_machine_id, process->ctrl_handle, disasm_vaddr_rng, process->arch); DASMI_Handle dasm_handle = dasmi_handle_from_ctrl_process_range_arch(process->ctrl_machine_id, process->ctrl_handle, disasm_vaddr_rng, process->arch);
return dasm_handle; return dasm_handle;
} }
+1 -1
View File
@@ -1404,7 +1404,7 @@ internal DF_EntityFuzzyItemArray df_entity_fuzzy_item_array_from_entity_array_ne
internal TXTI_Handle df_txti_handle_from_entity(DF_Entity *entity); internal TXTI_Handle df_txti_handle_from_entity(DF_Entity *entity);
//- rjf: entity -> disasm info //- rjf: entity -> disasm info
internal DASM_Handle df_dasm_handle_from_process_vaddr(DF_Entity *process, U64 vaddr); internal DASMI_Handle df_dasm_handle_from_process_vaddr(DF_Entity *process, U64 vaddr);
//- rjf: full path building, from file/folder entities //- rjf: full path building, from file/folder entities
internal String8 df_full_path_from_entity(Arena *arena, DF_Entity *entity); internal String8 df_full_path_from_entity(Arena *arena, DF_Entity *entity);
+1 -1
View File
@@ -10926,7 +10926,7 @@ df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor,
} }
internal B32 internal B32
df_do_dasm_controls(DASM_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column) df_do_dasm_controls(DASMI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
B32 change = 0; B32 change = 0;
+1 -1
View File
@@ -1048,7 +1048,7 @@ internal DF_CodeSliceSignal df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx,
internal B32 df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column); internal B32 df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column);
internal B32 df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column); internal B32 df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column);
internal B32 df_do_dasm_controls(DASM_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column); internal B32 df_do_dasm_controls(DASMI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column);
//////////////////////////////// ////////////////////////////////
//~ rjf: UI Widgets: Fancy Labels //~ rjf: UI Widgets: Fancy Labels
+30 -30
View File
@@ -6008,12 +6008,12 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
}break; }break;
case DF_CoreCmdKind_ToggleBreakpointAtCursor: case DF_CoreCmdKind_ToggleBreakpointAtCursor:
{ {
DASM_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr); DASMI_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr);
DASM_BinaryInfo dasm_info = dasm_binary_info_from_handle(scratch.arena, dasm_handle); DASMI_BinaryInfo dasm_info = dasmi_binary_info_from_handle(scratch.arena, dasm_handle);
DASM_InstArray insts = dasm_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100); DASMI_InstArray insts = dasmi_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100);
if(insts.count != 0) if(insts.count != 0)
{ {
U64 off = dasm_inst_array_off_from_idx(&insts, dv->cursor.line-1); U64 off = dasmi_inst_array_off_from_idx(&insts, dv->cursor.line-1);
U64 vaddr = dasm_info.vaddr_range.min+off; U64 vaddr = dasm_info.vaddr_range.min+off;
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.vaddr = vaddr; params.vaddr = vaddr;
@@ -6024,12 +6024,12 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
}break; }break;
case DF_CoreCmdKind_ToggleWatchPinAtCursor: case DF_CoreCmdKind_ToggleWatchPinAtCursor:
{ {
DASM_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr); DASMI_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr);
DASM_BinaryInfo dasm_info = dasm_binary_info_from_handle(scratch.arena, dasm_handle); DASMI_BinaryInfo dasm_info = dasmi_binary_info_from_handle(scratch.arena, dasm_handle);
DASM_InstArray insts = dasm_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100); DASMI_InstArray insts = dasmi_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100);
if(insts.count != 0) if(insts.count != 0)
{ {
U64 off = dasm_inst_array_off_from_idx(&insts, dv->cursor.line-1); U64 off = dasmi_inst_array_off_from_idx(&insts, dv->cursor.line-1);
U64 vaddr = dasm_info.vaddr_range.min+off; U64 vaddr = dasm_info.vaddr_range.min+off;
DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); DF_CmdParams p = df_cmd_params_from_view(ws, panel, view);
p.vaddr = vaddr; p.vaddr = vaddr;
@@ -6041,12 +6041,12 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
}break; }break;
case DF_CoreCmdKind_RunToCursor: case DF_CoreCmdKind_RunToCursor:
{ {
DASM_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr); DASMI_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr);
DASM_BinaryInfo dasm_info = dasm_binary_info_from_handle(scratch.arena, dasm_handle); DASMI_BinaryInfo dasm_info = dasmi_binary_info_from_handle(scratch.arena, dasm_handle);
DASM_InstArray insts = dasm_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100); DASMI_InstArray insts = dasmi_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100);
if(insts.count != 0) if(insts.count != 0)
{ {
U64 off = dasm_inst_array_off_from_idx(&insts, dv->cursor.line-1); U64 off = dasmi_inst_array_off_from_idx(&insts, dv->cursor.line-1);
U64 vaddr = dasm_info.vaddr_range.min+off; U64 vaddr = dasm_info.vaddr_range.min+off;
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.vaddr = vaddr; params.vaddr = vaddr;
@@ -6056,14 +6056,14 @@ DF_VIEW_CMD_FUNCTION_DEF(Disassembly)
}break; }break;
case DF_CoreCmdKind_SetNextStatement: case DF_CoreCmdKind_SetNextStatement:
{ {
DASM_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr); DASMI_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr);
DASM_BinaryInfo dasm_info = dasm_binary_info_from_handle(scratch.arena, dasm_handle); DASMI_BinaryInfo dasm_info = dasmi_binary_info_from_handle(scratch.arena, dasm_handle);
DASM_InstArray insts = dasm_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100); DASMI_InstArray insts = dasmi_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100);
DF_Entity *thread = df_entity_from_handle(params.entity); DF_Entity *thread = df_entity_from_handle(params.entity);
S64 line_num = (cmd->params.text_point.line == 0 ? dv->cursor.line : cmd->params.text_point.line); S64 line_num = (cmd->params.text_point.line == 0 ? dv->cursor.line : cmd->params.text_point.line);
if(insts.count != 0) if(insts.count != 0)
{ {
U64 off = dasm_inst_array_off_from_idx(&insts, line_num-1); U64 off = dasmi_inst_array_off_from_idx(&insts, line_num-1);
U64 vaddr = dasm_info.vaddr_range.min+off; U64 vaddr = dasm_info.vaddr_range.min+off;
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.vaddr = vaddr; params.vaddr = vaddr;
@@ -6175,12 +6175,12 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
//- rjf: unpack entity info //- rjf: unpack entity info
// //
DF_Entity *process = df_entity_from_handle(dv->process); DF_Entity *process = df_entity_from_handle(dv->process);
DASM_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr); DASMI_Handle dasm_handle = df_dasm_handle_from_process_vaddr(process, dv->base_vaddr);
DASM_BinaryInfo dasm_info = dasm_binary_info_from_handle(scratch.arena, dasm_handle); DASMI_BinaryInfo dasm_info = dasmi_binary_info_from_handle(scratch.arena, dasm_handle);
Rng1U64 disasm_vaddr_rng = dasm_info.vaddr_range; Rng1U64 disasm_vaddr_rng = dasm_info.vaddr_range;
DF_Entity *module = df_module_from_process_vaddr(process, disasm_vaddr_rng.min); DF_Entity *module = df_module_from_process_vaddr(process, disasm_vaddr_rng.min);
DF_Entity *binary = df_binary_file_from_module(module); DF_Entity *binary = df_binary_file_from_module(module);
DASM_InstArray insts = dasm_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100); DASMI_InstArray insts = dasmi_inst_array_from_handle(scratch.arena, dasm_handle, os_now_microseconds()+100);
B32 has_disasm = (insts.count != 0); B32 has_disasm = (insts.count != 0);
B32 is_loading = (!has_disasm && !df_entity_is_nil(process) && dim_1u64(disasm_vaddr_rng) != 0 && !df_ctrl_targets_running()); B32 is_loading = (!has_disasm && !df_entity_is_nil(process) && dim_1u64(disasm_vaddr_rng) != 0 && !df_ctrl_targets_running());
@@ -6270,7 +6270,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
for(S64 line_num = visible_line_num_range.min; line_num < visible_line_num_range.max; line_num += 1) for(S64 line_num = visible_line_num_range.min; line_num < visible_line_num_range.max; line_num += 1)
{ {
U64 idx = line_num-visible_line_num_range.min; U64 idx = line_num-visible_line_num_range.min;
DASM_Inst *inst = &insts.v[visible_line_num_range.min+idx-1]; DASMI_Inst *inst = &insts.v[visible_line_num_range.min+idx-1];
String8 symbol_name = {0}; String8 symbol_name = {0};
if(inst->addr != 0) if(inst->addr != 0)
{ {
@@ -6312,7 +6312,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
if(contains_1u64(disasm_vaddr_rng, rip_vaddr)) if(contains_1u64(disasm_vaddr_rng, rip_vaddr))
{ {
U64 rip_off = rip_vaddr - disasm_vaddr_rng.min; U64 rip_off = rip_vaddr - disasm_vaddr_rng.min;
S64 line_num = dasm_inst_array_idx_from_off__linear_scan(&insts, rip_off)+1; S64 line_num = dasmi_inst_array_idx_from_off__linear_scan(&insts, rip_off)+1;
if(contains_1s64(visible_line_num_range, line_num)) if(contains_1s64(visible_line_num_range, line_num))
{ {
U64 slice_line_idx = (line_num-visible_line_num_range.min); U64 slice_line_idx = (line_num-visible_line_num_range.min);
@@ -6332,7 +6332,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
if(bp->flags & DF_EntityFlag_HasVAddr && contains_1u64(disasm_vaddr_rng, bp->vaddr)) if(bp->flags & DF_EntityFlag_HasVAddr && contains_1u64(disasm_vaddr_rng, bp->vaddr))
{ {
U64 off = bp->vaddr-disasm_vaddr_rng.min; U64 off = bp->vaddr-disasm_vaddr_rng.min;
U64 idx = dasm_inst_array_idx_from_off__linear_scan(&insts, off); U64 idx = dasmi_inst_array_idx_from_off__linear_scan(&insts, off);
S64 line_num = (S64)(idx+1); S64 line_num = (S64)(idx+1);
if(contains_1s64(visible_line_num_range, line_num)) if(contains_1s64(visible_line_num_range, line_num))
{ {
@@ -6353,7 +6353,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
if(pin->flags & DF_EntityFlag_HasVAddr && contains_1u64(disasm_vaddr_rng, pin->vaddr)) if(pin->flags & DF_EntityFlag_HasVAddr && contains_1u64(disasm_vaddr_rng, pin->vaddr))
{ {
U64 off = pin->vaddr-disasm_vaddr_rng.min; U64 off = pin->vaddr-disasm_vaddr_rng.min;
U64 idx = dasm_inst_array_idx_from_off__linear_scan(&insts, off); U64 idx = dasmi_inst_array_idx_from_off__linear_scan(&insts, off);
S64 line_num = (S64)(idx+1); S64 line_num = (S64)(idx+1);
if(contains_1s64(visible_line_num_range, line_num)) if(contains_1s64(visible_line_num_range, line_num))
{ {
@@ -6370,7 +6370,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
DF_Entity *binary = df_binary_file_from_module(module); DF_Entity *binary = df_binary_file_from_module(module);
for(S64 line_num = visible_line_num_range.min; line_num < visible_line_num_range.max; line_num += 1) for(S64 line_num = visible_line_num_range.min; line_num < visible_line_num_range.max; line_num += 1)
{ {
U64 vaddr = disasm_vaddr_rng.min + dasm_inst_array_off_from_idx(&insts, line_num-1); U64 vaddr = disasm_vaddr_rng.min + dasmi_inst_array_off_from_idx(&insts, line_num-1);
U64 voff = df_voff_from_vaddr(module, vaddr); U64 voff = df_voff_from_vaddr(module, vaddr);
U64 slice_idx = line_num-visible_line_num_range.min; U64 slice_idx = line_num-visible_line_num_range.min;
DF_TextLineDasm2SrcInfoNode *dasm2src_n = push_array(scratch.arena, DF_TextLineDasm2SrcInfoNode, 1); DF_TextLineDasm2SrcInfoNode *dasm2src_n = push_array(scratch.arena, DF_TextLineDasm2SrcInfoNode, 1);
@@ -6397,7 +6397,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
{ {
U64 vaddr = dv->goto_vaddr; U64 vaddr = dv->goto_vaddr;
dv->goto_vaddr = 0; dv->goto_vaddr = 0;
U64 line_idx = dasm_inst_array_idx_from_off__linear_scan(&insts, vaddr-disasm_vaddr_rng.min); U64 line_idx = dasmi_inst_array_idx_from_off__linear_scan(&insts, vaddr-disasm_vaddr_rng.min);
S64 line_num = (S64)(line_idx+1); S64 line_num = (S64)(line_idx+1);
dv->cursor = dv->mark = txt_pt(line_num, 1); dv->cursor = dv->mark = txt_pt(line_num, 1);
dv->center_cursor = !dv->contain_cursor || (line_num < visible_line_num_range.min+8 || visible_line_num_range.max-8 < line_num); dv->center_cursor = !dv->contain_cursor || (line_num < visible_line_num_range.min+8 || visible_line_num_range.max-8 < line_num);
@@ -6446,7 +6446,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
DF_Eval eval = df_eval_from_string(scratch.arena, scope, &ctrl_ctx, &parse_ctx, &eval_string2expr_map_nil, expr); DF_Eval eval = df_eval_from_string(scratch.arena, scope, &ctrl_ctx, &parse_ctx, &eval_string2expr_map_nil, expr);
if(eval.mode != EVAL_EvalMode_NULL) if(eval.mode != EVAL_EvalMode_NULL)
{ {
U64 off = dasm_inst_array_off_from_idx(&insts, sig.mouse_expr_rng.min.line-1); U64 off = dasmi_inst_array_off_from_idx(&insts, sig.mouse_expr_rng.min.line-1);
U64 vaddr = disasm_vaddr_rng.min+off; U64 vaddr = disasm_vaddr_rng.min+off;
df_set_hover_eval(ws, sig.mouse_expr_baseline_pos, ctrl_ctx, process, sig.mouse_pt, vaddr, expr); df_set_hover_eval(ws, sig.mouse_expr_baseline_pos, ctrl_ctx, process, sig.mouse_pt, vaddr, expr);
} }
@@ -6470,7 +6470,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
if(sig.clicked_margin_line_num != 0) if(sig.clicked_margin_line_num != 0)
{ {
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.vaddr = disasm_vaddr_rng.min+dasm_inst_array_off_from_idx(&insts, sig.clicked_margin_line_num-1); params.vaddr = disasm_vaddr_rng.min+dasmi_inst_array_off_from_idx(&insts, sig.clicked_margin_line_num-1);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualAddr); df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualAddr);
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_AddressBreakpoint)); df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_AddressBreakpoint));
} }
@@ -6478,7 +6478,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
//- rjf: dropped entity onto line? -> do drop //- rjf: dropped entity onto line? -> do drop
if(sig.dropped_entity_line_num != 0 && !df_entity_is_nil(sig.dropped_entity)) if(sig.dropped_entity_line_num != 0 && !df_entity_is_nil(sig.dropped_entity))
{ {
U64 drop_vaddr = disasm_vaddr_rng.min+dasm_inst_array_off_from_idx(&insts, sig.dropped_entity_line_num-1); U64 drop_vaddr = disasm_vaddr_rng.min+dasmi_inst_array_off_from_idx(&insts, sig.dropped_entity_line_num-1);
DF_Entity *dropped_entity = sig.dropped_entity; DF_Entity *dropped_entity = sig.dropped_entity;
switch(dropped_entity->kind) switch(dropped_entity->kind)
{ {
@@ -6541,7 +6541,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
if(sig.run_to_line_num != 0 && contains_1s64(visible_line_num_range, sig.run_to_line_num)) if(sig.run_to_line_num != 0 && contains_1s64(visible_line_num_range, sig.run_to_line_num))
{ {
DF_CmdParams params = df_cmd_params_from_window(ws); DF_CmdParams params = df_cmd_params_from_window(ws);
params.vaddr = disasm_vaddr_rng.min+dasm_inst_array_off_from_idx(&insts, sig.run_to_line_num-1); params.vaddr = disasm_vaddr_rng.min+dasmi_inst_array_off_from_idx(&insts, sig.run_to_line_num-1);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualAddr); df_cmd_params_mark_slot(&params, DF_CmdParamSlot_VirtualAddr);
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunToAddress)); df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunToAddress));
} }
@@ -6549,7 +6549,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly)
//- rjf: go to source //- rjf: go to source
if(sig.goto_src_line_num != 0 && contains_1s64(visible_line_num_range, sig.goto_src_line_num)) if(sig.goto_src_line_num != 0 && contains_1s64(visible_line_num_range, sig.goto_src_line_num))
{ {
U64 vaddr = disasm_vaddr_rng.min+dasm_inst_array_off_from_idx(&insts, sig.goto_src_line_num-1); U64 vaddr = disasm_vaddr_rng.min+dasmi_inst_array_off_from_idx(&insts, sig.goto_src_line_num-1);
DF_Entity *module = df_module_from_process_vaddr(process, vaddr); DF_Entity *module = df_module_from_process_vaddr(process, vaddr);
DF_Entity *binary = df_binary_file_from_module(module); DF_Entity *binary = df_binary_file_from_module(module);
U64 voff = df_voff_from_vaddr(module, vaddr); U64 voff = df_voff_from_vaddr(module, vaddr);