2017-11-22 05:24:51 +00:00
|
|
|
#ifndef _VM_SEGMENT_H_
|
|
|
|
#define _VM_SEGMENT_H_
|
|
|
|
|
2017-12-02 19:05:53 +00:00
|
|
|
#include "vm_bits.h"
|
2017-12-09 21:16:56 +00:00
|
|
|
#include "log.h"
|
2017-11-22 05:24:51 +00:00
|
|
|
|
2017-12-07 03:37:14 +00:00
|
|
|
/*
|
|
|
|
* The bounds check is just some inline code to try and cut down on the
|
|
|
|
* cost of it.
|
|
|
|
*/
|
|
|
|
#define vm_segment_bounds_check(segment, index) \
|
|
|
|
(index == index % segment->size)
|
|
|
|
|
2017-11-22 05:24:51 +00:00
|
|
|
typedef struct {
|
2017-12-07 03:37:14 +00:00
|
|
|
/*
|
|
|
|
* The size of our memory segment. This is used for bounds checking.
|
|
|
|
*/
|
2017-11-22 05:24:51 +00:00
|
|
|
size_t size;
|
2017-12-07 03:37:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the actual chunk of memory we allocate.
|
|
|
|
*/
|
2017-12-02 19:05:53 +00:00
|
|
|
vm_8bit *memory;
|
2017-11-22 05:24:51 +00:00
|
|
|
} vm_segment;
|
|
|
|
|
2017-12-09 21:16:56 +00:00
|
|
|
extern int vm_segment_copy(vm_segment *, vm_segment *, size_t, size_t, size_t);
|
2017-11-22 05:24:51 +00:00
|
|
|
extern vm_segment *vm_segment_create(size_t);
|
2017-12-02 19:05:53 +00:00
|
|
|
extern void vm_segment_free(vm_segment *);
|
|
|
|
extern vm_8bit vm_segment_get(vm_segment *, size_t);
|
2017-12-09 21:16:56 +00:00
|
|
|
extern int vm_segment_set(vm_segment *, size_t, vm_8bit);
|
2017-11-22 05:24:51 +00:00
|
|
|
|
|
|
|
#endif
|