mirror of
https://github.com/pevans/erc-c.git
synced 2025-07-25 05:24:02 +00:00
Remove the map_mach abstraction in favor of vm_di
This commit is contained in:
@@ -13,20 +13,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "vm_di.h"
|
||||
#include "vm_segment.h"
|
||||
|
||||
/*
|
||||
* This is sort of regrettable, but we need a machine pointer that we
|
||||
* can pass into the read/write map functions (which will assume to have
|
||||
* access to the machine architecture). The alternative is an update to
|
||||
* a lot more of the codebase to add machine pointers -- void pointers
|
||||
* at that -- which is even uglier.
|
||||
*
|
||||
* FIXME: we might consider a dependency injection container at some
|
||||
* point.
|
||||
*/
|
||||
static void *map_mach = NULL;
|
||||
|
||||
/*
|
||||
* Create a new segment, such that it contains a number of bytes indicated
|
||||
* by `size`.
|
||||
@@ -111,6 +100,8 @@ vm_segment_set(vm_segment *segment, size_t index, vm_8bit value)
|
||||
return ERR_OOB;
|
||||
}
|
||||
|
||||
void *map_mach = vm_di_get(VM_MACHINE);
|
||||
|
||||
// Check if we have a write mapper
|
||||
if (segment->write_table[index]) {
|
||||
segment->write_table[index](segment, index, value, map_mach);
|
||||
@@ -139,6 +130,8 @@ vm_segment_get(vm_segment *segment, size_t index)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *map_mach = vm_di_get(VM_MACHINE);
|
||||
|
||||
// We may have a read mapper for this address
|
||||
if (segment->read_table[index]) {
|
||||
return segment->read_table[index](segment, index, map_mach);
|
||||
@@ -305,24 +298,6 @@ vm_segment_fwrite(vm_segment *seg, FILE *stream, size_t off, size_t len)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the internal notion of the machine used by map functions
|
||||
*/
|
||||
void
|
||||
vm_segment_set_map_machine(void *mach)
|
||||
{
|
||||
map_mach = mach;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the map machine
|
||||
*/
|
||||
void *
|
||||
vm_segment_get_map_machine()
|
||||
{
|
||||
return map_mach;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is similar in spirit to the get16 function, but obviously more
|
||||
* practically similar to the set() function. Given a 16-bit value, we
|
||||
|
Reference in New Issue
Block a user