sh-dis/c/state_helpers.h
Zack Buhman 7debad83b9 add support for non-FPU/UBC/MMU/cache SH4 instructions
Previously, ast transformations were performed informally as ad-hoc
modifications to the generated C source code. In this commit, the
same transformations are performed by rewriting the ast prior to code
generation time.

The most significant new transformer is transform_assignment_list.
This transforms assignments such as:

  a, b, c = f(b, c, d)

To:

  a = f(&b, &c, d)

The former syntax is used frequently in the manual's description of
FPU-related instructions.
2024-04-22 20:59:34 +08:00

89 lines
2.6 KiB
C

#pragma once
#include <stddef.h>
#include <assert.h>
#include "state.h"
#include "memory_map.h"
#include "status_bits.h"
static inline bool is_delay_slot(struct architectural_state * state)
{
return state->is_delay_slot;
}
static inline struct sr_bits _sr_bits(uint32_t sr)
{
union {
struct sr_bits bits;
uint32_t value;
} sr_union;
sr_union.value = sr;
return sr_union.bits;
}
static inline bool fpu_is_disabled(uint32_t sr)
{
return _sr_bits(sr).fd;
}
static inline void sleep(struct architectural_state * state)
{
}
static inline void ocbp(struct architectural_state * state, uint32_t address)
{
}
static inline uint8_t read_memory8(struct memory_map * map, uint32_t address)
{
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return 0;
uint32_t relative_address = physical_address(address) - entry->start;
return entry->access.read_memory8(entry->mem, relative_address);
}
static inline uint16_t read_memory16(struct memory_map * map, uint32_t address)
{
assert((address & 0b1) == 0);
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return 0;
uint32_t relative_address = physical_address(address) - entry->start;
return entry->access.read_memory16(entry->mem, relative_address);
}
static inline uint32_t read_memory32(struct memory_map * map, uint32_t address)
{
assert((address & 0b11) == 0);
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return 0;
uint32_t relative_address = physical_address(address) - entry->start;
return entry->access.read_memory32(entry->mem, relative_address);
}
static inline void write_memory8(struct memory_map * map, uint32_t address, uint8_t value)
{
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return;
uint32_t relative_address = physical_address(address) - entry->start;
entry->access.write_memory8(entry->mem, relative_address, value);
}
static inline void write_memory16(struct memory_map * map, uint32_t address, uint16_t value)
{
assert((address & 0b1) == 0);
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return;
uint32_t relative_address = physical_address(address) - entry->start;
entry->access.write_memory16(entry->mem, relative_address, value);
}
static inline void write_memory32(struct memory_map * map, uint32_t address, uint32_t value)
{
assert((address & 0b11) == 0);
struct memory_map_entry * entry = find_entry(map, address);
if (entry == NULL) return;
uint32_t relative_address = physical_address(address) - entry->start;
entry->access.write_memory32(entry->mem, relative_address, value);
}