mirror of
https://github.com/LIV2/amitools.git
synced 2025-12-05 22:22:45 +00:00
removed machine and use external machine68k package
This commit is contained in:
parent
0bd6eb5dba
commit
7ca4406520
@ -1,7 +1,13 @@
|
||||
import time
|
||||
import sys
|
||||
from machine import emu
|
||||
from machine.m68k import *
|
||||
import logging
|
||||
|
||||
try:
|
||||
import machine68k
|
||||
except ImportError:
|
||||
logging.error("package 'machine68k' missing! please install with pip.")
|
||||
sys.exit(1)
|
||||
|
||||
from .regs import *
|
||||
from .opcodes import *
|
||||
from .error import ErrorReporter
|
||||
@ -74,10 +80,6 @@ class Machine(object):
|
||||
000800 RAM begin. useable by applications
|
||||
"""
|
||||
|
||||
CPU_TYPE_68000 = M68K_CPU_TYPE_68000
|
||||
CPU_TYPE_68020 = M68K_CPU_TYPE_68020
|
||||
CPU_TYPE_68040 = M68K_CPU_TYPE_68040
|
||||
|
||||
run_exit_addr = 0x400
|
||||
hw_exc_addr = 0x402
|
||||
ram_begin = 0x800
|
||||
@ -87,7 +89,7 @@ class Machine(object):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
cpu_type=M68K_CPU_TYPE_68000,
|
||||
cpu_type=machine68k.CPUType.M68000,
|
||||
ram_size_kib=1024,
|
||||
use_labels=True,
|
||||
raise_on_main_run=True,
|
||||
@ -96,13 +98,14 @@ class Machine(object):
|
||||
cpu_name=None,
|
||||
):
|
||||
if cpu_name is None:
|
||||
cpu_name = self._get_cpu_name(cpu_type)
|
||||
# setup musashi components
|
||||
cpu_name = machine68k.cpu_type_to_str(cpu_type)
|
||||
self.cpu_type = cpu_type
|
||||
self.cpu_name = cpu_name
|
||||
self.cpu = emu.CPU(cpu_type)
|
||||
self.mem = emu.Memory(ram_size_kib)
|
||||
self.traps = emu.Traps()
|
||||
# setup machine68k
|
||||
self.machine = machine68k.Machine(cpu_type, ram_size_kib)
|
||||
self.cpu = self.machine.cpu
|
||||
self.mem = self.machine.mem
|
||||
self.traps = self.machine.traps
|
||||
# internal state
|
||||
if use_labels:
|
||||
self.label_mgr = LabelManager()
|
||||
@ -169,27 +172,9 @@ class Machine(object):
|
||||
|
||||
@classmethod
|
||||
def parse_cpu_type(cls, cpu_str):
|
||||
if cpu_str in ("68000", "000", "00"):
|
||||
return cls.CPU_TYPE_68000, "68000"
|
||||
elif cpu_str in ("68020", "020", "20"):
|
||||
return cls.CPU_TYPE_68020, "68020"
|
||||
elif cpu_str in ("68030", "030", "30"):
|
||||
# fake 030 CPU only to set AttnFlags accordingly
|
||||
return cls.CPU_TYPE_68020, "68030(fake)"
|
||||
elif cpu_str in ("68040", "040", "40"):
|
||||
return cls.CPU_TYPE_68040, "68040"
|
||||
else:
|
||||
return None, None
|
||||
|
||||
def _get_cpu_name(self, cpu_type):
|
||||
if cpu_type == self.CPU_TYPE_68000:
|
||||
return "68000"
|
||||
elif cpu_type == self.CPU_TYPE_68020:
|
||||
return "68020"
|
||||
elif cpu_type == self.CPU_TYPE_68040:
|
||||
return "68040"
|
||||
else:
|
||||
return None
|
||||
cpu_type = machine68k.cpu_type_from_str(cpu_str)
|
||||
cpu_name = machine68k.cpu_type_to_str(cpu_type)
|
||||
return cpu_type, cpu_name
|
||||
|
||||
def _init_cpu(self):
|
||||
# sp and pc does not matter we will overwrite it anyway
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
from machine68k import CPUType
|
||||
from .hwaccess import HWAccess
|
||||
from amitools.vamos.log import log_mem_map
|
||||
from amitools.vamos.label import LabelRange
|
||||
@ -8,7 +9,7 @@ class MemoryMap(object):
|
||||
def __init__(self, machine):
|
||||
self.machine = machine
|
||||
self.label_mgr = machine.get_label_mgr()
|
||||
self.addr_24_bit = machine.get_cpu_type() == machine.CPU_TYPE_68000
|
||||
self.addr_24_bit = machine.get_cpu_type() == CPUType.M68000
|
||||
self.ram_total = machine.get_ram_total()
|
||||
# options
|
||||
self.hw_access = None
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
include "pycpu.pyx"
|
||||
include "pymem.pyx"
|
||||
include "pytraps.pyx"
|
||||
@ -1,131 +0,0 @@
|
||||
# emu_test.py
|
||||
# test the musashi binding
|
||||
|
||||
from . import emu
|
||||
from . import m68k
|
||||
|
||||
|
||||
def run():
|
||||
print("create CPU, Memory, Traps")
|
||||
# 68k with 128 KiB mem
|
||||
cpu = emu.CPU(m68k.M68K_CPU_TYPE_68000)
|
||||
memory = emu.Memory(128)
|
||||
traps = emu.Traps()
|
||||
|
||||
# get a special range
|
||||
spec_addr = memory.reserve_special_range()
|
||||
print("special range: %06x" % spec_addr)
|
||||
|
||||
def invalid(mode, width, addr):
|
||||
print("MY INVALID: %s(%d): %06x" % (chr(mode), width, addr))
|
||||
|
||||
def trace(mode, width, addr, value):
|
||||
print("TRACE: %s(%d): %06x: %x" % (chr(mode), width, addr, value))
|
||||
return 0
|
||||
|
||||
memory.set_invalid_func(invalid)
|
||||
memory.set_trace_func(trace)
|
||||
memory.set_trace_mode(True)
|
||||
|
||||
def pc_changed(addr):
|
||||
print("pc %06x" % (addr))
|
||||
|
||||
def reset_handler():
|
||||
print("RESET")
|
||||
|
||||
def instr_hook():
|
||||
print("INSTR HOOK")
|
||||
|
||||
cpu.set_pc_changed_callback(pc_changed)
|
||||
cpu.set_reset_instr_callback(reset_handler)
|
||||
cpu.set_instr_hook_callback(instr_hook)
|
||||
|
||||
print("resetting cpu...")
|
||||
cpu.pulse_reset()
|
||||
|
||||
# write mem
|
||||
print("write mem...")
|
||||
memory.w16(0x1000, 0x4E70) # RESET
|
||||
val = memory.r16(0x1000)
|
||||
print("RESET op=%04x" % val)
|
||||
|
||||
# block write
|
||||
print(memory.r_block(0, 4))
|
||||
memory.w_block(0, "woah")
|
||||
print(memory.r_block(0, 4))
|
||||
|
||||
# string
|
||||
memory.clear_block(0, 100, 11)
|
||||
memory.w_cstr(0, "hello, world!")
|
||||
s = memory.r_cstr(0)
|
||||
print(s, type(s))
|
||||
|
||||
# string
|
||||
memory.clear_block(0, 100, 11)
|
||||
memory.w_bstr(0, "hello, world!")
|
||||
s = memory.r_bstr(0)
|
||||
print(s, type(s))
|
||||
|
||||
# copy block
|
||||
memory.w_bstr(0, "hello, world!")
|
||||
memory.copy_block(0, 100, 100)
|
||||
txt = memory.r_bstr(100)
|
||||
print(txt)
|
||||
|
||||
# valid range
|
||||
print("executing...")
|
||||
cpu.w_reg(m68k.M68K_REG_PC, 0x1000)
|
||||
print(cpu.execute(2))
|
||||
|
||||
# invalid range
|
||||
print("executing invalid...")
|
||||
cpu.w_reg(m68k.M68K_REG_PC, spec_addr)
|
||||
print(cpu.execute(2))
|
||||
|
||||
# test traps
|
||||
print("--- traps ---")
|
||||
|
||||
def my_trap(op, pc):
|
||||
print("MY TRAP: %04x @ %08x" % (op, pc))
|
||||
|
||||
tid = traps.setup(my_trap, auto_rts=True)
|
||||
print("trap id=", tid)
|
||||
|
||||
# call trap
|
||||
memory.w16(0x2000, 0xA000 + tid)
|
||||
cpu.w_reg(m68k.M68K_REG_PC, 0x2000)
|
||||
print("call trap")
|
||||
print(cpu.execute(4))
|
||||
|
||||
# free trap
|
||||
traps.free(tid)
|
||||
|
||||
# special read
|
||||
print("special read...")
|
||||
|
||||
def my_r16(addr):
|
||||
print("MY RANGE: %06x" % addr)
|
||||
return 0xDEAD
|
||||
|
||||
memory.set_special_range_read_func(spec_addr, 1, my_r16)
|
||||
v = memory.r16(spec_addr)
|
||||
print("special=%0x" % v)
|
||||
|
||||
# check if mem is in end mode?
|
||||
is_end = memory.is_end()
|
||||
print("mem is_end:", is_end)
|
||||
|
||||
print("get/set register")
|
||||
print("%08x" % cpu.r_reg(m68k.M68K_REG_D0))
|
||||
cpu.w_reg(m68k.M68K_REG_D0, 0xDEADBEEF)
|
||||
print("%08x" % cpu.r_reg(m68k.M68K_REG_D0))
|
||||
|
||||
# disassemble
|
||||
print("disassemble")
|
||||
print(cpu.disassemble(0x1000))
|
||||
|
||||
print("done")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
@ -1,61 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# m68k.py
|
||||
#
|
||||
# constants for musashi m68k CPU emulator
|
||||
#
|
||||
|
||||
# cpu type
|
||||
M68K_CPU_TYPE_INVALID = 0
|
||||
M68K_CPU_TYPE_68000 = 1
|
||||
M68K_CPU_TYPE_68010 = 2
|
||||
M68K_CPU_TYPE_68EC020 = 3
|
||||
M68K_CPU_TYPE_68020 = 4
|
||||
M68K_CPU_TYPE_68030 = 5 # Supported by disassembler ONLY
|
||||
M68K_CPU_TYPE_68040 = 6 # Supported by disassembler ONLY
|
||||
|
||||
# registers
|
||||
M68K_REG_D0 = 0
|
||||
M68K_REG_D1 = 1
|
||||
M68K_REG_D2 = 2
|
||||
M68K_REG_D3 = 3
|
||||
M68K_REG_D4 = 4
|
||||
M68K_REG_D5 = 5
|
||||
M68K_REG_D6 = 6
|
||||
M68K_REG_D7 = 7
|
||||
M68K_REG_A0 = 8
|
||||
M68K_REG_A1 = 9
|
||||
M68K_REG_A2 = 10
|
||||
M68K_REG_A3 = 11
|
||||
M68K_REG_A4 = 12
|
||||
M68K_REG_A5 = 13
|
||||
M68K_REG_A6 = 14
|
||||
M68K_REG_A7 = 15
|
||||
M68K_REG_PC = 16 # Program Counter
|
||||
M68K_REG_SR = 17 # Status Register
|
||||
M68K_REG_SP = 18 # The current Stack Pointer (located in A7)
|
||||
M68K_REG_USP = 19 # User Stack Pointer
|
||||
M68K_REG_ISP = 20 # Interrupt Stack Pointer
|
||||
M68K_REG_MSP = 21 # Master Stack Pointer
|
||||
M68K_REG_SFC = 22 # Source Function Code
|
||||
M68K_REG_DFC = 23 # Destination Function Code
|
||||
M68K_REG_VBR = 24 # Vector Base Register
|
||||
M68K_REG_CACR = 25 # Cache Control Register
|
||||
M68K_REG_CAAR = 26 # Cache Address Register
|
||||
|
||||
M68K_REG_PREF_ADDR = 27 # Virtual Reg: Last prefetch address
|
||||
M68K_REG_PREF_DATA = 28 # Virtual Reg: Last prefetch data
|
||||
|
||||
M68K_REG_PPC = 29 # Previous value in the program counter
|
||||
M68K_REG_IR = 30 # Instruction register
|
||||
M68K_REG_CPU_TYPE = 31 # Type of CPU being run
|
||||
|
||||
# aline callback
|
||||
M68K_ALINE_NONE = 0
|
||||
M68K_ALINE_EXCEPT = 1
|
||||
M68K_ALINE_RTS = 2
|
||||
|
||||
# traps
|
||||
TRAP_DEFAULT = 0
|
||||
TRAP_ONE_SHOT = 1
|
||||
TRAP_AUTO_RTS = 2
|
||||
392
machine/mem.c
392
machine/mem.c
@ -1,392 +0,0 @@
|
||||
/* MusashiCPU <-> vamos memory interface
|
||||
*
|
||||
* written by Christian Vogelgsang <chris@vogelgsang.org>
|
||||
* under the GNU Public License V2
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
/* THOR: I need a *little* more memory than 16MB.
|
||||
** This gives 256MB max.
|
||||
*/
|
||||
#define NUM_PAGES 4096
|
||||
|
||||
/* ----- Data ----- */
|
||||
static uint8_t *ram_data;
|
||||
static uint ram_size;
|
||||
static uint ram_pages;
|
||||
|
||||
static read_func_t r_func[NUM_PAGES][3];
|
||||
static write_func_t w_func[NUM_PAGES][3];
|
||||
static void * r_ctx[NUM_PAGES][3];
|
||||
static void * w_ctx[NUM_PAGES][3];
|
||||
|
||||
static invalid_func_t invalid_func;
|
||||
static void *invalid_ctx;
|
||||
static int mem_trace = 0;
|
||||
static trace_func_t trace_func;
|
||||
static void *trace_ctx;
|
||||
static uint special_page = NUM_PAGES;
|
||||
|
||||
/* ----- RAW Access ----- */
|
||||
extern uint8_t *mem_raw_ptr(void)
|
||||
{
|
||||
return ram_data;
|
||||
}
|
||||
|
||||
extern uint mem_raw_size(void)
|
||||
{
|
||||
return ram_size;
|
||||
}
|
||||
|
||||
/* ----- Default Funcs ----- */
|
||||
static void default_invalid(int mode, int width, uint addr, void *ctx)
|
||||
{
|
||||
printf("INVALID: %c(%d): %06x\n",(char)mode,width,addr);
|
||||
}
|
||||
|
||||
static void default_trace(int mode, int width, uint addr, uint val, void *ctx)
|
||||
{
|
||||
printf("%c(%d): %06x: %x\n",(char)mode,width,addr,val);
|
||||
}
|
||||
|
||||
static uint r8_fail(uint addr, void *ctx)
|
||||
{
|
||||
invalid_func('R', 0, addr, invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint r16_fail(uint addr, void *ctx)
|
||||
{
|
||||
invalid_func('R', 1, addr, invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint r32_fail(uint addr, void *ctx)
|
||||
{
|
||||
invalid_func('R', 2, addr, invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void w8_fail(uint addr, uint val, void *ctx)
|
||||
{
|
||||
invalid_func('W', 0, addr, invalid_ctx);
|
||||
}
|
||||
|
||||
static void w16_fail(uint addr, uint val, void *ctx)
|
||||
{
|
||||
invalid_func('W', 1, addr, invalid_ctx);
|
||||
}
|
||||
|
||||
static void w32_fail(uint addr, uint val, void *ctx)
|
||||
{
|
||||
invalid_func('W', 2, addr, invalid_ctx);
|
||||
}
|
||||
|
||||
/* ----- RAM access ----- */
|
||||
static uint mem_r8_ram(uint addr, void *ctx)
|
||||
{
|
||||
return ram_data[addr];
|
||||
}
|
||||
|
||||
static uint mem_r16_ram(uint addr, void *ctx)
|
||||
{
|
||||
return (ram_data[addr] << 8) | ram_data[addr+1];
|
||||
}
|
||||
|
||||
static uint mem_r32_ram(uint addr, void *ctx)
|
||||
{
|
||||
return (ram_data[addr] << 24) | (ram_data[addr+1] << 16) | (ram_data[addr+2] << 8) | (ram_data[addr+3]);
|
||||
}
|
||||
|
||||
static void mem_w8_ram(uint addr, uint val, void *ctx)
|
||||
{
|
||||
ram_data[addr] = val;
|
||||
}
|
||||
|
||||
static void mem_w16_ram(uint addr, uint val, void *ctx)
|
||||
{
|
||||
ram_data[addr] = val >> 8;
|
||||
ram_data[addr+1] = val & 0xff;
|
||||
}
|
||||
|
||||
static void mem_w32_ram(uint addr, uint val, void *ctx)
|
||||
{
|
||||
ram_data[addr] = val >> 24;
|
||||
ram_data[addr+1] = (val >> 16) & 0xff;
|
||||
ram_data[addr+2] = (val >> 8) & 0xff;
|
||||
ram_data[addr+3] = val & 0xff;
|
||||
}
|
||||
|
||||
/* ----- Musashi Interface ----- */
|
||||
|
||||
#include "m68kcpu.h"
|
||||
|
||||
unsigned int m68k_read_memory_8(unsigned int address)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
uint val = r_func[page][0](address, r_ctx[page][0]);
|
||||
if(mem_trace) {
|
||||
trace_func('R',0,address,val,trace_ctx);
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
invalid_func('R',0,address,invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int m68k_read_memory_16(unsigned int address)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
uint val = r_func[page][1](address, r_ctx[page][1]);
|
||||
if(mem_trace) {
|
||||
trace_func('R',1,address,val,trace_ctx);
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
invalid_func('R',1,address,invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int m68k_read_memory_32(unsigned int address)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
uint val = r_func[page][2](address, r_ctx[page][2]);
|
||||
if(mem_trace) {
|
||||
trace_func('R',2,address,val,trace_ctx);
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
invalid_func('R',2,address,invalid_ctx);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void m68k_write_memory_8(unsigned int address, unsigned int value)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
w_func[page][0](address, value, w_ctx[page][0]);
|
||||
if(mem_trace) {
|
||||
trace_func('W',0,address,value,trace_ctx);
|
||||
}
|
||||
} else {
|
||||
invalid_func('W',0,address,invalid_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void m68k_write_memory_16(unsigned int address, unsigned int value)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
w_func[page][1](address, value, w_ctx[page][1]);
|
||||
if(mem_trace) {
|
||||
trace_func('W',1,address,value,trace_ctx);
|
||||
}
|
||||
} else {
|
||||
invalid_func('W',1,address,invalid_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void m68k_write_memory_32(unsigned int address, unsigned int value)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
w_func[page][2](address, value, w_ctx[page][2]);
|
||||
if(mem_trace) {
|
||||
trace_func('W',2,address,value,trace_ctx);
|
||||
}
|
||||
} else {
|
||||
invalid_func('W',2,address,invalid_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disassemble support */
|
||||
|
||||
unsigned int m68k_read_disassembler_16 (unsigned int address)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
uint val = r_func[page][1](address, r_ctx[page][1]);
|
||||
return val;
|
||||
} else {
|
||||
return 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int m68k_read_disassembler_32 (unsigned int address)
|
||||
{
|
||||
uint page = address >> 16;
|
||||
if (page < NUM_PAGES) {
|
||||
uint val = r_func[page][2](address, r_ctx[page][1]);
|
||||
return val;
|
||||
} else {
|
||||
return 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----- API ----- */
|
||||
|
||||
int mem_init(uint ram_size_kib)
|
||||
{
|
||||
uint i;
|
||||
ram_pages = (ram_size_kib + 63) / 64;
|
||||
ram_size = ram_pages * 64 * 1024;
|
||||
ram_data = (uint8_t *)malloc(ram_size);
|
||||
memset(ram_data, 0, ram_size);
|
||||
|
||||
for(i=0;i<NUM_PAGES;i++) {
|
||||
if(i < ram_pages) {
|
||||
r_func[i][0] = mem_r8_ram;
|
||||
r_func[i][1] = mem_r16_ram;
|
||||
r_func[i][2] = mem_r32_ram;
|
||||
w_func[i][0] = mem_w8_ram;
|
||||
w_func[i][1] = mem_w16_ram;
|
||||
w_func[i][2] = mem_w32_ram;
|
||||
} else {
|
||||
r_func[i][0] = r8_fail;
|
||||
r_func[i][1] = r16_fail;
|
||||
r_func[i][2] = r32_fail;
|
||||
w_func[i][0] = w8_fail;
|
||||
w_func[i][1] = w16_fail;
|
||||
w_func[i][2] = w32_fail;
|
||||
}
|
||||
}
|
||||
|
||||
mem_trace = 0;
|
||||
trace_func = default_trace;
|
||||
invalid_func = default_invalid;
|
||||
|
||||
return (ram_data != NULL);
|
||||
}
|
||||
|
||||
void mem_free(void)
|
||||
{
|
||||
free(ram_data);
|
||||
ram_data = NULL;
|
||||
}
|
||||
|
||||
void mem_set_invalid_func(invalid_func_t func, void *ctx)
|
||||
{
|
||||
if(func == NULL) {
|
||||
func = default_invalid;
|
||||
ctx = NULL;
|
||||
}
|
||||
invalid_func = func;
|
||||
invalid_ctx = ctx;
|
||||
}
|
||||
|
||||
void mem_set_trace_mode(int on)
|
||||
{
|
||||
mem_trace = on;
|
||||
}
|
||||
|
||||
void mem_set_trace_func(trace_func_t func, void *ctx)
|
||||
{
|
||||
if(func == NULL) {
|
||||
func = default_trace;
|
||||
ctx = NULL;
|
||||
}
|
||||
trace_func = func;
|
||||
trace_ctx = ctx;
|
||||
}
|
||||
|
||||
uint mem_reserve_special_range(uint num_pages)
|
||||
{
|
||||
uint begin_page = special_page - num_pages;
|
||||
if(begin_page < ram_pages) {
|
||||
return 0;
|
||||
}
|
||||
special_page = begin_page;
|
||||
return begin_page << 16;
|
||||
}
|
||||
|
||||
void mem_set_special_range_read_func(uint page_addr, uint width, read_func_t func, void *ctx)
|
||||
{
|
||||
uint page = page_addr >> 16;
|
||||
r_func[page][width] = func;
|
||||
r_ctx[page][width] = ctx;
|
||||
}
|
||||
|
||||
void mem_set_special_range_write_func(uint page_addr, uint width, write_func_t func, void *ctx)
|
||||
{
|
||||
uint page = page_addr >> 16;
|
||||
w_func[page][width] = func;
|
||||
w_ctx[page][width] = ctx;
|
||||
}
|
||||
|
||||
/* RAM access */
|
||||
|
||||
int mem_ram_r8(uint addr, uint *val)
|
||||
{
|
||||
if(addr < ram_size) {
|
||||
*val = ram_data[addr];
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int mem_ram_r16(uint addr, uint *val)
|
||||
{
|
||||
if(addr < (ram_size - 1)) {
|
||||
*val = (ram_data[addr] << 8) | ram_data[addr+1];
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int mem_ram_r32(uint addr, uint *val)
|
||||
{
|
||||
if(addr < (ram_size - 3)) {
|
||||
*val = (ram_data[addr] << 24) | (ram_data[addr+1] << 16) | (ram_data[addr+2] << 8) | (ram_data[addr+3]);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int mem_ram_w8(uint addr, uint val)
|
||||
{
|
||||
if(addr < ram_size) {
|
||||
ram_data[addr] = (uint8_t)(val & 0xff);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int mem_ram_w16(uint addr, uint val)
|
||||
{
|
||||
if(addr < (ram_size - 1)) {
|
||||
ram_data[addr] = val >> 8;
|
||||
ram_data[addr+1] = val & 0xff;
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int mem_ram_w32(uint addr, uint val)
|
||||
{
|
||||
if(addr < (ram_size - 3)) {
|
||||
ram_data[addr] = val >> 24;
|
||||
ram_data[addr+1] = (val >> 16) & 0xff;
|
||||
ram_data[addr+2] = (val >> 8) & 0xff;
|
||||
ram_data[addr+3] = val & 0xff;
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
/* MusashiCPU <-> vamos memory interface
|
||||
*
|
||||
* written by Christian Vogelgsang <chris@vogelgsang.org>
|
||||
* under the GNU Public License V2
|
||||
*/
|
||||
|
||||
#ifndef _MEM_H
|
||||
#define _MEM_H
|
||||
|
||||
#include "m68k.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* ------ Types ----- */
|
||||
#ifndef UINT_TYPE
|
||||
#define UINT_TYPE
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
typedef uint (*read_func_t)(uint addr, void *ctx);
|
||||
typedef void (*write_func_t)(uint addr, uint value, void *ctx);
|
||||
|
||||
typedef void (*invalid_func_t)(int mode, int width, uint addr, void *ctx);
|
||||
typedef void (*trace_func_t)(int mode, int width, uint addr, uint val, void *ctx);
|
||||
|
||||
/* ----- API ----- */
|
||||
extern int mem_init(uint ram_size_kib);
|
||||
extern void mem_free(void);
|
||||
|
||||
extern void mem_set_invalid_func(invalid_func_t func, void *ctx);
|
||||
extern void mem_set_trace_mode(int on);
|
||||
extern void mem_set_trace_func(trace_func_t func, void *ctx);
|
||||
|
||||
extern uint mem_reserve_special_range(uint num_pages);
|
||||
extern void mem_set_special_range_read_func(uint page_addr, uint width, read_func_t func, void *ctx);
|
||||
extern void mem_set_special_range_write_func(uint page_addr, uint width, write_func_t func, void *ctx);
|
||||
|
||||
extern uint8_t *mem_raw_ptr(void);
|
||||
extern uint mem_raw_size(void);
|
||||
|
||||
extern unsigned int m68k_read_memory_8(unsigned int address);
|
||||
extern unsigned int m68k_read_memory_16(unsigned int address);
|
||||
extern unsigned int m68k_read_memory_32(unsigned int address);
|
||||
|
||||
extern void m68k_write_memory_8(unsigned int address, unsigned int value);
|
||||
extern void m68k_write_memory_16(unsigned int address, unsigned int value);
|
||||
extern void m68k_write_memory_32(unsigned int address, unsigned int value);
|
||||
|
||||
extern int mem_ram_r8(uint addr, uint *val);
|
||||
extern int mem_ram_r16(uint addr, uint *val);
|
||||
extern int mem_ram_r32(uint addr, uint *val);
|
||||
|
||||
extern int mem_ram_w8(uint addr, uint val);
|
||||
extern int mem_ram_w16(uint addr, uint val);
|
||||
extern int mem_ram_w32(uint addr, uint val);
|
||||
|
||||
#endif
|
||||
@ -1,34 +0,0 @@
|
||||
# Just a basic makefile to quickly test that everyting is working, it just
|
||||
# compiles the .o and the generator
|
||||
|
||||
MUSASHIFILES = m68kcpu.c m68kdasm.c softfloat/softfloat.c
|
||||
MUSASHIGENCFILES = m68kops.c
|
||||
MUSASHIGENHFILES = m68kops.h
|
||||
MUSASHIGENERATOR = m68kmake
|
||||
|
||||
EXE =
|
||||
EXEPATH = ./
|
||||
|
||||
.CFILES = $(MAINFILES) $(OSDFILES) $(MUSASHIFILES) $(MUSASHIGENCFILES)
|
||||
.OFILES = $(.CFILES:%.c=%.o)
|
||||
|
||||
CC = gcc
|
||||
WARNINGS = -Wall -Wextra -pedantic
|
||||
CFLAGS = $(WARNINGS)
|
||||
LFLAGS = $(WARNINGS)
|
||||
|
||||
DELETEFILES = $(MUSASHIGENCFILES) $(MUSASHIGENHFILES) $(.OFILES) $(TARGET) $(MUSASHIGENERATOR)$(EXE)
|
||||
|
||||
|
||||
all: $(.OFILES)
|
||||
|
||||
clean:
|
||||
rm -f $(DELETEFILES)
|
||||
|
||||
m68kcpu.o: $(MUSASHIGENHFILES) m68kfpu.c m68kmmu.h softfloat/softfloat.c softfloat/softfloat.h
|
||||
|
||||
$(MUSASHIGENCFILES) $(MUSASHIGENHFILES): $(MUSASHIGENERATOR)$(EXE)
|
||||
$(EXEPATH)$(MUSASHIGENERATOR)$(EXE)
|
||||
|
||||
$(MUSASHIGENERATOR)$(EXE): $(MUSASHIGENERATOR).c
|
||||
$(CC) -o $(MUSASHIGENERATOR)$(EXE) $(MUSASHIGENERATOR).c
|
||||
@ -1,115 +0,0 @@
|
||||
The history of Musashi for anyone who might be interested:
|
||||
---------------------------------------------------------
|
||||
|
||||
Musashi was born out of sheer boredom.
|
||||
I needed something to code, and so having had fun with a few of the emulators
|
||||
around, I decided to try my hand at CPU emulation.
|
||||
I had owned an Amiga for many years and had done some assembly coding on it so
|
||||
I figured it would be the ideal chip to cut my teeth on.
|
||||
Had I known then how much work was involved in emulating a chip like this, I
|
||||
may not have even started ;-)
|
||||
|
||||
|
||||
15-Jul-2013: Musashi license changed to MIT.
|
||||
|
||||
10-Jun-2002: Musashi 3.4 released
|
||||
- Added various undocumented m68k features thanks to Bart
|
||||
Trzynadlowski's experiments.
|
||||
See http://dynarec.com/~bart/files/68knotes.txt for details.
|
||||
- Fixed a bug that caused privilege violation and illegal
|
||||
instruction exceptions to stack the wrong PC value.
|
||||
- Added emulation of address errors (Note: this only works
|
||||
in 68000 mode. All other CPUs require a LOT of overhead
|
||||
to emulate this. I'm not sure if I'll implement them or not.
|
||||
|
||||
27-Jan-2001: Musashi 3.3 released
|
||||
- Fixed problem when displaying negative numbers in disassembler
|
||||
- Fixed cpu type selector - was allowing 020 instructions to be
|
||||
disassembled when in 000 mode.
|
||||
- Fixed opcode jumptable generator (ambiguous operators in the
|
||||
test for f-line ops)
|
||||
- Fixed signed/unsigned problem in divl and mull opcodes (not
|
||||
sure if this was causing an error but best to be sure)
|
||||
- Cleaned up the naming scheme for the opcode handlers
|
||||
|
||||
14-Aug-2000: Musashi 3.2 released
|
||||
- Fixed RTE bug that killed the program counter when in m68020
|
||||
mode.
|
||||
- Minor fixes in negx and nbcd.
|
||||
- renamed d68k.c to m68kdasm.c and merged d68k.h into m68k.h.
|
||||
d68k_read_xxx() instructions have been renamed to
|
||||
m68k_read_xxx_disassembler().
|
||||
- Rewrote exception processing and fixed 68020 stack frame
|
||||
problems.
|
||||
- FINALLY fixed the mull and divl instructions.
|
||||
- Added 64-bit safe code fixes.
|
||||
- Added 64-bit optimizations (these will only be ANSI compliant
|
||||
under c9x, and so to use them you must turn on M68K_USE_64_BIT
|
||||
in m68kconf.h).
|
||||
|
||||
28-May-2000: Musashi 3.1 released
|
||||
- Fixed bug in m68k_get_reg() that retrieved the wrong value for
|
||||
the status register.
|
||||
- Fixed register bug in movec.
|
||||
- Fixed cpu type comparison problem that caused indexed
|
||||
addressing modes to be incorrectly interpreted when in m68ec020
|
||||
mode.
|
||||
- Added code to speed up busy waiting on some branch instructions.
|
||||
- Fixed some bfxxx opcode bugs.
|
||||
|
||||
05-Apr-2000: Musashi 3.0 released
|
||||
- Major code overhaul.
|
||||
- Rewrote code generator program and changed the format of
|
||||
m68k_in.c.
|
||||
- Added support for m68ec020.
|
||||
- Removed timing from the opcode handlers.
|
||||
- Added correct timing for m68000, m68010, and m68020.
|
||||
Note: 68020 timing is the cache timing from the manual.
|
||||
- Removed the m68k_peek_xxx() and m68k_poke_xxx() instructions and
|
||||
replaced them with m68k_get_reg() and m68k_set_reg().
|
||||
- Added support for function codes.
|
||||
- Revamped m68kconf.h to be easier to configure and more powerful.
|
||||
- Added option to separate immediate and normal reads.
|
||||
- Added support for (undocumented) m68000 instruction prefetch.
|
||||
- Rewrote indexed addressing mode handling.
|
||||
- Rewrote interrupt handling.
|
||||
- Fixed a masking bug for m68k_get_reg() when requesting the PC.
|
||||
- Moved the instruction table sorting routine to m68kmake.c so
|
||||
that it is invoked at compile time rather than at runtime.
|
||||
- Rewrote the exception handling routines to support different
|
||||
stack frames (needed for m68020 emulation).
|
||||
- Rewrote faster status register and condition code flag handling
|
||||
functions / macros.
|
||||
- Fixed function code handling to fetch from program space when
|
||||
using pc-relative addressing.
|
||||
- Fixed initial program counter and stack pointer fetching on
|
||||
reset (loads from program space now).
|
||||
- A lot of code cleanup.
|
||||
- LOTS of bugfixes (especially in the m68020 code).
|
||||
|
||||
13-May-1999: Musashi 2.2 released
|
||||
- Added support for m68020.
|
||||
- Lots of bugfixes.
|
||||
|
||||
25-Mar-1999: Musashi 2.1 released
|
||||
- Added support for m68010.
|
||||
- Many bugfixes.
|
||||
|
||||
17-Mar-1999: Musashi 2.0 released
|
||||
- Major code overhaul.
|
||||
- Replaced monolithic codebase with a code generator program.
|
||||
- Added correct m68000 timing.
|
||||
- Moved timing into the opcode handlers.
|
||||
|
||||
06-Jan-1999: Musashi 1.0 released
|
||||
|
||||
20-Dec-1998: Beta release of Musashi v0.5 that could run Rastan Saga under MAME
|
||||
(barely).
|
||||
|
||||
04-Dec-1998: Final prototype v0.4
|
||||
|
||||
20-Nov-1998: First prototype v0.1
|
||||
|
||||
11-Jun-1998: Early disassembler
|
||||
|
||||
12-May-1998: First outline
|
||||
@ -1,417 +0,0 @@
|
||||
/* ======================================================================== */
|
||||
/* ========================= LICENSING & COPYRIGHT ======================== */
|
||||
/* ======================================================================== */
|
||||
/*
|
||||
* MUSASHI
|
||||
* Version 3.32
|
||||
*
|
||||
* A portable Motorola M680x0 processor emulation engine.
|
||||
* Copyright Karl Stenerud. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef M68K__HEADER
|
||||
#define M68K__HEADER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_LENGTH
|
||||
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================= CONFIGURATION ============================ */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* Import the configuration for this build */
|
||||
#ifdef MUSASHI_CNF
|
||||
#include MUSASHI_CNF
|
||||
#else
|
||||
#include "m68kconf.h"
|
||||
#endif
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================ GENERAL DEFINES =========================== */
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
/* There are 7 levels of interrupt to the 68K.
|
||||
* A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
|
||||
*/
|
||||
#define M68K_IRQ_NONE 0
|
||||
#define M68K_IRQ_1 1
|
||||
#define M68K_IRQ_2 2
|
||||
#define M68K_IRQ_3 3
|
||||
#define M68K_IRQ_4 4
|
||||
#define M68K_IRQ_5 5
|
||||
#define M68K_IRQ_6 6
|
||||
#define M68K_IRQ_7 7
|
||||
|
||||
|
||||
/* Special interrupt acknowledge values.
|
||||
* Use these as special returns from the interrupt acknowledge callback
|
||||
* (specified later in this header).
|
||||
*/
|
||||
|
||||
/* Causes an interrupt autovector (0x18 + interrupt level) to be taken.
|
||||
* This happens in a real 68K if VPA or AVEC is asserted during an interrupt
|
||||
* acknowledge cycle instead of DTACK.
|
||||
*/
|
||||
#define M68K_INT_ACK_AUTOVECTOR 0xffffffff
|
||||
|
||||
/* Causes the spurious interrupt vector (0x18) to be taken
|
||||
* This happens in a real 68K if BERR is asserted during the interrupt
|
||||
* acknowledge cycle (i.e. no devices responded to the acknowledge).
|
||||
*/
|
||||
#define M68K_INT_ACK_SPURIOUS 0xfffffffe
|
||||
|
||||
|
||||
/* CPU types for use in m68k_set_cpu_type() */
|
||||
enum
|
||||
{
|
||||
M68K_CPU_TYPE_INVALID,
|
||||
M68K_CPU_TYPE_68000,
|
||||
M68K_CPU_TYPE_68010,
|
||||
M68K_CPU_TYPE_68EC020,
|
||||
M68K_CPU_TYPE_68020,
|
||||
M68K_CPU_TYPE_68EC030,
|
||||
M68K_CPU_TYPE_68030,
|
||||
M68K_CPU_TYPE_68EC040,
|
||||
M68K_CPU_TYPE_68LC040,
|
||||
M68K_CPU_TYPE_68040,
|
||||
M68K_CPU_TYPE_SCC68070
|
||||
};
|
||||
|
||||
/* Registers used by m68k_get_reg() and m68k_set_reg() */
|
||||
typedef enum
|
||||
{
|
||||
/* Real registers */
|
||||
M68K_REG_D0, /* Data registers */
|
||||
M68K_REG_D1,
|
||||
M68K_REG_D2,
|
||||
M68K_REG_D3,
|
||||
M68K_REG_D4,
|
||||
M68K_REG_D5,
|
||||
M68K_REG_D6,
|
||||
M68K_REG_D7,
|
||||
M68K_REG_A0, /* Address registers */
|
||||
M68K_REG_A1,
|
||||
M68K_REG_A2,
|
||||
M68K_REG_A3,
|
||||
M68K_REG_A4,
|
||||
M68K_REG_A5,
|
||||
M68K_REG_A6,
|
||||
M68K_REG_A7,
|
||||
M68K_REG_PC, /* Program Counter */
|
||||
M68K_REG_SR, /* Status Register */
|
||||
M68K_REG_SP, /* The current Stack Pointer (located in A7) */
|
||||
M68K_REG_USP, /* User Stack Pointer */
|
||||
M68K_REG_ISP, /* Interrupt Stack Pointer */
|
||||
M68K_REG_MSP, /* Master Stack Pointer */
|
||||
M68K_REG_SFC, /* Source Function Code */
|
||||
M68K_REG_DFC, /* Destination Function Code */
|
||||
M68K_REG_VBR, /* Vector Base Register */
|
||||
M68K_REG_CACR, /* Cache Control Register */
|
||||
M68K_REG_CAAR, /* Cache Address Register */
|
||||
|
||||
/* Assumed registers */
|
||||
/* These are cheat registers which emulate the 1-longword prefetch
|
||||
* present in the 68000 and 68010.
|
||||
*/
|
||||
M68K_REG_PREF_ADDR, /* Last prefetch address */
|
||||
M68K_REG_PREF_DATA, /* Last prefetch data */
|
||||
|
||||
/* Convenience registers */
|
||||
M68K_REG_PPC, /* Previous value in the program counter */
|
||||
M68K_REG_IR, /* Instruction register */
|
||||
M68K_REG_CPU_TYPE /* Type of CPU being run */
|
||||
} m68k_register_t;
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* You will have to implement these functions */
|
||||
|
||||
/* read/write functions called by the CPU to access memory.
|
||||
* while values used are 32 bits, only the appropriate number
|
||||
* of bits are relevant (i.e. in write_memory_8, only the lower 8 bits
|
||||
* of value should be written to memory).
|
||||
*
|
||||
* NOTE: I have separated the immediate and PC-relative memory fetches
|
||||
* from the other memory fetches because some systems require
|
||||
* differentiation between PROGRAM and DATA fetches (usually
|
||||
* for security setups such as encryption).
|
||||
* This separation can either be achieved by setting
|
||||
* M68K_SEPARATE_READS in m68kconf.h and defining
|
||||
* the read functions, or by setting M68K_EMULATE_FC and
|
||||
* making a function code callback function.
|
||||
* Using the callback offers better emulation coverage
|
||||
* because you can also monitor whether the CPU is in SYSTEM or
|
||||
* USER mode, but it is also slower.
|
||||
*/
|
||||
|
||||
/* Read from anywhere */
|
||||
unsigned int m68k_read_memory_8(unsigned int address);
|
||||
unsigned int m68k_read_memory_16(unsigned int address);
|
||||
unsigned int m68k_read_memory_32(unsigned int address);
|
||||
|
||||
/* Read data immediately following the PC */
|
||||
unsigned int m68k_read_immediate_16(unsigned int address);
|
||||
unsigned int m68k_read_immediate_32(unsigned int address);
|
||||
|
||||
/* Read data relative to the PC */
|
||||
unsigned int m68k_read_pcrelative_8(unsigned int address);
|
||||
unsigned int m68k_read_pcrelative_16(unsigned int address);
|
||||
unsigned int m68k_read_pcrelative_32(unsigned int address);
|
||||
|
||||
/* Memory access for the disassembler */
|
||||
unsigned int m68k_read_disassembler_8 (unsigned int address);
|
||||
unsigned int m68k_read_disassembler_16 (unsigned int address);
|
||||
unsigned int m68k_read_disassembler_32 (unsigned int address);
|
||||
|
||||
/* Write to anywhere */
|
||||
void m68k_write_memory_8(unsigned int address, unsigned int value);
|
||||
void m68k_write_memory_16(unsigned int address, unsigned int value);
|
||||
void m68k_write_memory_32(unsigned int address, unsigned int value);
|
||||
|
||||
/* Special call to simulate undocumented 68k behavior when move.l with a
|
||||
* predecrement destination mode is executed.
|
||||
* To simulate real 68k behavior, first write the high word to
|
||||
* [address+2], and then write the low word to [address].
|
||||
*
|
||||
* Enable this functionality with M68K_SIMULATE_PD_WRITES in m68kconf.h.
|
||||
*/
|
||||
void m68k_write_memory_32_pd(unsigned int address, unsigned int value);
|
||||
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================== CALLBACKS =============================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* These functions allow you to set callbacks to the host when specific events
|
||||
* occur. Note that you must enable the corresponding value in m68kconf.h
|
||||
* in order for these to do anything useful.
|
||||
* Note: I have defined default callbacks which are used if you have enabled
|
||||
* the corresponding #define in m68kconf.h but either haven't assigned a
|
||||
* callback or have assigned a callback of NULL.
|
||||
*/
|
||||
|
||||
/* Set the callback for an interrupt acknowledge.
|
||||
* You must enable M68K_EMULATE_INT_ACK in m68kconf.h.
|
||||
* The CPU will call the callback with the interrupt level being acknowledged.
|
||||
* The host program must return either a vector from 0x02-0xff, or one of the
|
||||
* special interrupt acknowledge values specified earlier in this header.
|
||||
* If this is not implemented, the CPU will always assume an autovectored
|
||||
* interrupt, and will automatically clear the interrupt request when it
|
||||
* services the interrupt.
|
||||
* Default behavior: return M68K_INT_ACK_AUTOVECTOR.
|
||||
*/
|
||||
void m68k_set_int_ack_callback(int (*callback)(int int_level));
|
||||
|
||||
|
||||
/* Set the callback for a breakpoint acknowledge (68010+).
|
||||
* You must enable M68K_EMULATE_BKPT_ACK in m68kconf.h.
|
||||
* The CPU will call the callback with whatever was in the data field of the
|
||||
* BKPT instruction for 68020+, or 0 for 68010.
|
||||
* Default behavior: do nothing.
|
||||
*/
|
||||
void m68k_set_bkpt_ack_callback(void (*callback)(unsigned int data));
|
||||
|
||||
|
||||
/* Set the callback for the RESET instruction.
|
||||
* You must enable M68K_EMULATE_RESET in m68kconf.h.
|
||||
* The CPU calls this callback every time it encounters a RESET instruction.
|
||||
* Default behavior: do nothing.
|
||||
*/
|
||||
void m68k_set_reset_instr_callback(void (*callback)(void));
|
||||
|
||||
|
||||
/* Set the callback for informing of a large PC change.
|
||||
* You must enable M68K_MONITOR_PC in m68kconf.h.
|
||||
* The CPU calls this callback with the new PC value every time the PC changes
|
||||
* by a large value (currently set for changes by longwords).
|
||||
* Default behavior: do nothing.
|
||||
*/
|
||||
void m68k_set_pc_changed_callback(void (*callback)(unsigned int new_pc));
|
||||
|
||||
/* Set the callback for the TAS instruction.
|
||||
* You must enable M68K_TAS_HAS_CALLBACK in m68kconf.h.
|
||||
* The CPU calls this callback every time it encounters a TAS instruction.
|
||||
* Default behavior: return 1, allow writeback.
|
||||
*/
|
||||
void m68k_set_tas_instr_callback(int (*callback)(void));
|
||||
|
||||
/* Set the callback for illegal instructions.
|
||||
* You must enable M68K_ILLG_HAS_CALLBACK in m68kconf.h.
|
||||
* The CPU calls this callback every time it encounters an illegal instruction
|
||||
* which must return 1 if it handles the instruction normally or 0 if it's really an illegal instruction.
|
||||
* Default behavior: return 0, exception will occur.
|
||||
*/
|
||||
void m68k_set_illg_instr_callback(int (*callback)(int));
|
||||
|
||||
/* Set the callback for CPU function code changes.
|
||||
* You must enable M68K_EMULATE_FC in m68kconf.h.
|
||||
* The CPU calls this callback with the function code before every memory
|
||||
* access to set the CPU's function code according to what kind of memory
|
||||
* access it is (supervisor/user, program/data and such).
|
||||
* Default behavior: do nothing.
|
||||
*/
|
||||
void m68k_set_fc_callback(void (*callback)(unsigned int new_fc));
|
||||
|
||||
|
||||
/* Set a callback for the instruction cycle of the CPU.
|
||||
* You must enable M68K_INSTRUCTION_HOOK in m68kconf.h.
|
||||
* The CPU calls this callback just before fetching the opcode in the
|
||||
* instruction cycle.
|
||||
* Default behavior: do nothing.
|
||||
*/
|
||||
void m68k_set_instr_hook_callback(void (*callback)(unsigned int pc));
|
||||
|
||||
/* CV: operation done after aline callback */
|
||||
#define M68K_ALINE_NONE 0
|
||||
#define M68K_ALINE_EXCEPT 1
|
||||
#define M68K_ALINE_RTS 2
|
||||
|
||||
/* CV: call callback with (opcode, pc) */
|
||||
void m68k_set_aline_hook_callback(int (*callback)(unsigned int, unsigned int));
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* Use this function to set the CPU type you want to emulate.
|
||||
* Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68010,
|
||||
* M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.
|
||||
*/
|
||||
void m68k_set_cpu_type(unsigned int cpu_type);
|
||||
|
||||
/* Do whatever initialisations the core requires. Should be called
|
||||
* at least once at init time.
|
||||
*/
|
||||
void m68k_init(void);
|
||||
|
||||
/* Pulse the RESET pin on the CPU.
|
||||
* You *MUST* reset the CPU at least once to initialize the emulation
|
||||
* Note: If you didn't call m68k_set_cpu_type() before resetting
|
||||
* the CPU for the first time, the CPU will be set to
|
||||
* M68K_CPU_TYPE_68000.
|
||||
*/
|
||||
void m68k_pulse_reset(void);
|
||||
|
||||
/* execute num_cycles worth of instructions. returns number of cycles used */
|
||||
int m68k_execute(int num_cycles);
|
||||
|
||||
/* These functions let you read/write/modify the number of cycles left to run
|
||||
* while m68k_execute() is running.
|
||||
* These are useful if the 68k accesses a memory-mapped port on another device
|
||||
* that requires immediate processing by another CPU.
|
||||
*/
|
||||
int m68k_cycles_run(void); /* Number of cycles run so far */
|
||||
int m68k_cycles_remaining(void); /* Number of cycles left */
|
||||
void m68k_modify_timeslice(int cycles); /* Modify cycles left */
|
||||
void m68k_end_timeslice(void); /* End timeslice now */
|
||||
|
||||
/* Set the IPL0-IPL2 pins on the CPU (IRQ).
|
||||
* A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
|
||||
* Setting IRQ to 0 will clear an interrupt request.
|
||||
*/
|
||||
void m68k_set_irq(unsigned int int_level);
|
||||
|
||||
/* Set the virtual irq lines, where the highest level
|
||||
* active line is automatically selected. If you use this function,
|
||||
* do not use m68k_set_irq.
|
||||
*/
|
||||
void m68k_set_virq(unsigned int level, unsigned int active);
|
||||
unsigned int m68k_get_virq(unsigned int level);
|
||||
|
||||
/* Halt the CPU as if you pulsed the HALT pin. */
|
||||
void m68k_pulse_halt(void);
|
||||
|
||||
|
||||
/* Trigger a bus error exception */
|
||||
void m68k_pulse_bus_error(void);
|
||||
|
||||
|
||||
/* Context switching to allow multiple CPUs */
|
||||
|
||||
/* Get the size of the cpu context in bytes */
|
||||
unsigned int m68k_context_size(void);
|
||||
|
||||
/* Get a cpu context */
|
||||
unsigned int m68k_get_context(void* dst);
|
||||
|
||||
/* set the current cpu context */
|
||||
void m68k_set_context(void* dst);
|
||||
|
||||
/* Register the CPU state information */
|
||||
void m68k_state_register(const char *type, int index);
|
||||
|
||||
|
||||
/* Peek at the internals of a CPU context. This can either be a context
|
||||
* retrieved using m68k_get_context() or the currently running context.
|
||||
* If context is NULL, the currently running CPU context will be used.
|
||||
*/
|
||||
unsigned int m68k_get_reg(void* context, m68k_register_t reg);
|
||||
|
||||
/* Poke values into the internals of the currently running CPU context */
|
||||
void m68k_set_reg(m68k_register_t reg, unsigned int value);
|
||||
|
||||
/* Check if an instruction is valid for the specified CPU type */
|
||||
unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
|
||||
|
||||
/* Disassemble 1 instruction using the epecified CPU type at pc. Stores
|
||||
* disassembly in str_buff and returns the size of the instruction in bytes.
|
||||
*/
|
||||
unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);
|
||||
|
||||
/* Same as above but accepts raw opcode data directly rather than fetching
|
||||
* via the read/write interfaces.
|
||||
*/
|
||||
unsigned int m68k_disassemble_raw(char* str_buff, unsigned int pc, const unsigned char* opdata, const unsigned char* argdata, unsigned int cpu_type);
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================== MAME STUFF ============================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
#if M68K_COMPILE_FOR_MAME == OPT_ON
|
||||
#include "m68kmame.h"
|
||||
#endif /* M68K_COMPILE_FOR_MAME */
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================== END OF FILE ============================= */
|
||||
/* ======================================================================== */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* M68K__HEADER */
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,221 +0,0 @@
|
||||
/* ======================================================================== */
|
||||
/* ========================= LICENSING & COPYRIGHT ======================== */
|
||||
/* ======================================================================== */
|
||||
/*
|
||||
* MUSASHI
|
||||
* Version 3.32
|
||||
*
|
||||
* A portable Motorola M680x0 processor emulation engine.
|
||||
* Copyright Karl Stenerud. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef M68KCONF__HEADER
|
||||
#define M68KCONF__HEADER
|
||||
|
||||
|
||||
/* Configuration switches.
|
||||
* Use OPT_SPECIFY_HANDLER for configuration options that allow callbacks.
|
||||
* OPT_SPECIFY_HANDLER causes the core to link directly to the function
|
||||
* or macro you specify, rather than using callback functions whose pointer
|
||||
* must be passed in using m68k_set_xxx_callback().
|
||||
*/
|
||||
#define OPT_OFF 0
|
||||
#define OPT_ON 1
|
||||
#define OPT_SPECIFY_HANDLER 2
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================== MAME STUFF ============================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* If you're compiling this for MAME, only change M68K_COMPILE_FOR_MAME
|
||||
* to OPT_ON and use m68kmame.h to configure the 68k core.
|
||||
*/
|
||||
#ifndef M68K_COMPILE_FOR_MAME
|
||||
#define M68K_COMPILE_FOR_MAME OPT_OFF
|
||||
#endif /* M68K_COMPILE_FOR_MAME */
|
||||
|
||||
|
||||
#if M68K_COMPILE_FOR_MAME == OPT_OFF
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================= CONFIGURATION ============================ */
|
||||
/* ======================================================================== */
|
||||
|
||||
/* Turn ON if you want to use the following M68K variants */
|
||||
#define M68K_EMULATE_010 OPT_ON
|
||||
#define M68K_EMULATE_EC020 OPT_ON
|
||||
#define M68K_EMULATE_020 OPT_ON
|
||||
#define M68K_EMULATE_030 OPT_ON
|
||||
#define M68K_EMULATE_040 OPT_ON
|
||||
|
||||
|
||||
/* If ON, the CPU will call m68k_read_immediate_xx() for immediate addressing
|
||||
* and m68k_read_pcrelative_xx() for PC-relative addressing.
|
||||
* If off, all read requests from the CPU will be redirected to m68k_read_xx()
|
||||
*/
|
||||
#define M68K_SEPARATE_READS OPT_OFF
|
||||
|
||||
/* If ON, the CPU will call m68k_write_32_pd() when it executes move.l with a
|
||||
* predecrement destination EA mode instead of m68k_write_32().
|
||||
* To simulate real 68k behavior, m68k_write_32_pd() must first write the high
|
||||
* word to [address+2], and then write the low word to [address].
|
||||
*/
|
||||
#define M68K_SIMULATE_PD_WRITES OPT_OFF
|
||||
|
||||
/* If ON, CPU will call the interrupt acknowledge callback when it services an
|
||||
* interrupt.
|
||||
* If off, all interrupts will be autovectored and all interrupt requests will
|
||||
* auto-clear when the interrupt is serviced.
|
||||
*/
|
||||
#define M68K_EMULATE_INT_ACK OPT_OFF
|
||||
#define M68K_INT_ACK_CALLBACK(A) your_int_ack_handler_function(A)
|
||||
|
||||
|
||||
/* If ON, CPU will call the breakpoint acknowledge callback when it encounters
|
||||
* a breakpoint instruction and it is running a 68010+.
|
||||
*/
|
||||
#define M68K_EMULATE_BKPT_ACK OPT_OFF
|
||||
#define M68K_BKPT_ACK_CALLBACK() your_bkpt_ack_handler_function()
|
||||
|
||||
|
||||
/* If ON, the CPU will monitor the trace flags and take trace exceptions
|
||||
*/
|
||||
#define M68K_EMULATE_TRACE OPT_OFF
|
||||
|
||||
|
||||
/* If ON, CPU will call the output reset callback when it encounters a reset
|
||||
* instruction.
|
||||
*/
|
||||
/* CV Patch */
|
||||
#define M68K_EMULATE_RESET OPT_ON
|
||||
#define M68K_RESET_CALLBACK() your_reset_handler_function()
|
||||
|
||||
/* If ON, CPU will call the callback when it encounters a cmpi.l #v, dn
|
||||
* instruction.
|
||||
*/
|
||||
#define M68K_CMPILD_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_CMPILD_CALLBACK(v,r) your_cmpild_handler_function(v,r)
|
||||
|
||||
|
||||
/* If ON, CPU will call the callback when it encounters a rte
|
||||
* instruction.
|
||||
*/
|
||||
#define M68K_RTE_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_RTE_CALLBACK() your_rte_handler_function()
|
||||
|
||||
/* If ON, CPU will call the callback when it encounters a tas
|
||||
* instruction.
|
||||
*/
|
||||
#define M68K_TAS_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_TAS_CALLBACK() your_tas_handler_function()
|
||||
|
||||
/* If ON, CPU will call the callback when it encounters an illegal instruction
|
||||
* passing the opcode as argument. If the callback returns 1, then it's considered
|
||||
* as a normal instruction, and the illegal exception in canceled. If it returns 0,
|
||||
* the exception occurs normally.
|
||||
* The callback looks like int callback(int opcode)
|
||||
* You should put OPT_SPECIFY_HANDLER here if you cant to use it, otherwise it will
|
||||
* use a dummy default handler and you'll have to call m68k_set_illg_instr_callback explicitely
|
||||
*/
|
||||
#define M68K_ILLG_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_ILLG_CALLBACK(opcode) op_illg(opcode)
|
||||
|
||||
/* If ON, CPU will call the set fc callback on every memory access to
|
||||
* differentiate between user/supervisor, program/data access like a real
|
||||
* 68000 would. This should be enabled and the callback should be set if you
|
||||
* want to properly emulate the m68010 or higher. (moves uses function codes
|
||||
* to read/write data from different address spaces)
|
||||
*/
|
||||
#define M68K_EMULATE_FC OPT_OFF
|
||||
#define M68K_SET_FC_CALLBACK(A) your_set_fc_handler_function(A)
|
||||
|
||||
/* If ON, CPU will call the pc changed callback when it changes the PC by a
|
||||
* large value. This allows host programs to be nicer when it comes to
|
||||
* fetching immediate data and instructions on a banked memory system.
|
||||
*/
|
||||
#define M68K_MONITOR_PC OPT_OFF
|
||||
#define M68K_SET_PC_CALLBACK(A) your_pc_changed_handler_function(A)
|
||||
|
||||
|
||||
/* If ON, CPU will call the instruction hook callback before every
|
||||
* instruction.
|
||||
*/
|
||||
/* CV Patch */
|
||||
#define M68K_INSTRUCTION_HOOK OPT_ON
|
||||
#define M68K_INSTRUCTION_CALLBACK(pc) your_instruction_hook_function(pc)
|
||||
|
||||
|
||||
/* If ON, the CPU will emulate the 4-byte prefetch queue of a real 68000 */
|
||||
#define M68K_EMULATE_PREFETCH OPT_OFF
|
||||
|
||||
|
||||
/* If ON, the CPU will generate address error exceptions if it tries to
|
||||
* access a word or longword at an odd address.
|
||||
* NOTE: This is only emulated properly for 68000 mode.
|
||||
*/
|
||||
#define M68K_EMULATE_ADDRESS_ERROR OPT_OFF
|
||||
|
||||
/* ---------- CV AddOns ---------- */
|
||||
|
||||
/* Intercept illegal A-Line opcodes and call hook.
|
||||
Hook prototype is: int hook()
|
||||
If return == 0 then normal A-Line exception handling is performed.
|
||||
Otherwise nothing is done.
|
||||
*/
|
||||
#define M68K_ALINE_HOOK OPT_ON
|
||||
#define M68K_ALINE_CALLBACK() your_aline_hook_function()
|
||||
|
||||
/* Turn ON to enable logging of illegal instruction calls.
|
||||
* M68K_LOG_FILEHANDLE must be #defined to a stdio file stream.
|
||||
* Turn on M68K_LOG_1010_1111 to log all 1010 and 1111 calls.
|
||||
*/
|
||||
#define M68K_LOG_ENABLE OPT_OFF
|
||||
#define M68K_LOG_1010_1111 OPT_OFF
|
||||
#define M68K_LOG_FILEHANDLE some_file_handle
|
||||
|
||||
/* Emulate PMMU : if you enable this, there will be a test to see if the current chip has some enabled pmmu added to every memory access,
|
||||
* so enable this only if it's useful */
|
||||
#define M68K_EMULATE_PMMU OPT_ON
|
||||
|
||||
/* ----------------------------- COMPATIBILITY ---------------------------- */
|
||||
|
||||
/* The following options set optimizations that violate the current ANSI
|
||||
* standard, but will be compliant under the forthcoming C9X standard.
|
||||
*/
|
||||
|
||||
|
||||
/* If ON, the enulation core will use 64-bit integers to speed up some
|
||||
* operations.
|
||||
*/
|
||||
#define M68K_USE_64_BIT OPT_ON
|
||||
|
||||
|
||||
#endif /* M68K_COMPILE_FOR_MAME */
|
||||
|
||||
/* ======================================================================== */
|
||||
/* ============================== END OF FILE ============================= */
|
||||
/* ======================================================================== */
|
||||
|
||||
#endif /* M68KCONF__HEADER */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,321 +0,0 @@
|
||||
/*
|
||||
m68kmmu.h - PMMU implementation for 68851/68030/68040
|
||||
|
||||
By R. Belmont
|
||||
|
||||
Copyright Nicola Salmoria and the MAME Team.
|
||||
Visit http://mamedev.org for licensing and usage restrictions.
|
||||
*/
|
||||
|
||||
/*
|
||||
pmmu_translate_addr: perform 68851/68030-style PMMU address translation
|
||||
*/
|
||||
uint pmmu_translate_addr(uint addr_in)
|
||||
{
|
||||
uint32 addr_out, tbl_entry = 0, tbl_entry2, tamode = 0, tbmode = 0, tcmode = 0;
|
||||
uint root_aptr, root_limit, tofs, is, abits, bbits, cbits;
|
||||
uint resolved, tptr, shift;
|
||||
|
||||
resolved = 0;
|
||||
addr_out = addr_in;
|
||||
|
||||
// if SRP is enabled and we're in supervisor mode, use it
|
||||
if ((m68ki_cpu.mmu_tc & 0x02000000) && (m68ki_get_sr() & 0x2000))
|
||||
{
|
||||
root_aptr = m68ki_cpu.mmu_srp_aptr;
|
||||
root_limit = m68ki_cpu.mmu_srp_limit;
|
||||
}
|
||||
else // else use the CRP
|
||||
{
|
||||
root_aptr = m68ki_cpu.mmu_crp_aptr;
|
||||
root_limit = m68ki_cpu.mmu_crp_limit;
|
||||
}
|
||||
|
||||
// get initial shift (# of top bits to ignore)
|
||||
is = (m68ki_cpu.mmu_tc>>16) & 0xf;
|
||||
abits = (m68ki_cpu.mmu_tc>>12)&0xf;
|
||||
bbits = (m68ki_cpu.mmu_tc>>8)&0xf;
|
||||
cbits = (m68ki_cpu.mmu_tc>>4)&0xf;
|
||||
|
||||
// fprintf(stderr,"PMMU: tcr %08x limit %08x aptr %08x is %x abits %d bbits %d cbits %d\n", m68ki_cpu.mmu_tc, root_limit, root_aptr, is, abits, bbits, cbits);
|
||||
|
||||
// get table A offset
|
||||
tofs = (addr_in<<is)>>(32-abits);
|
||||
|
||||
// find out what format table A is
|
||||
switch (root_limit & 3)
|
||||
{
|
||||
case 0: // invalid, should cause MMU exception
|
||||
case 1: // page descriptor, should cause direct mapping
|
||||
fatalerror("680x0 PMMU: Unhandled root mode\n");
|
||||
break;
|
||||
|
||||
case 2: // valid 4 byte descriptors
|
||||
tofs *= 4;
|
||||
// fprintf(stderr,"PMMU: reading table A entry at %08x\n", tofs + (root_aptr & 0xfffffffc));
|
||||
tbl_entry = m68k_read_memory_32( tofs + (root_aptr & 0xfffffffc));
|
||||
tamode = tbl_entry & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x mode %x tofs %x\n", addr_in, tbl_entry, tamode, tofs);
|
||||
break;
|
||||
|
||||
case 3: // valid 8 byte descriptors
|
||||
tofs *= 8;
|
||||
// fprintf(stderr,"PMMU: reading table A entries at %08x\n", tofs + (root_aptr & 0xfffffffc));
|
||||
tbl_entry2 = m68k_read_memory_32( tofs + (root_aptr & 0xfffffffc));
|
||||
tbl_entry = m68k_read_memory_32( tofs + (root_aptr & 0xfffffffc)+4);
|
||||
tamode = tbl_entry2 & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x entry2 %08x mode %x tofs %x\n", addr_in, tbl_entry, tbl_entry2, tamode, tofs);
|
||||
break;
|
||||
}
|
||||
|
||||
// get table B offset and pointer
|
||||
tofs = (addr_in<<(is+abits))>>(32-bbits);
|
||||
tptr = tbl_entry & 0xfffffff0;
|
||||
|
||||
// find out what format table B is, if any
|
||||
switch (tamode)
|
||||
{
|
||||
case 0: // invalid, should cause MMU exception
|
||||
fatalerror("680x0 PMMU: Unhandled Table A mode %d (addr_in %08x)\n", tamode, addr_in);
|
||||
break;
|
||||
|
||||
case 2: // 4-byte table B descriptor
|
||||
tofs *= 4;
|
||||
// fprintf(stderr,"PMMU: reading table B entry at %08x\n", tofs + tptr);
|
||||
tbl_entry = m68k_read_memory_32( tofs + tptr);
|
||||
tbmode = tbl_entry & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x mode %x tofs %x\n", addr_in, tbl_entry, tbmode, tofs);
|
||||
break;
|
||||
|
||||
case 3: // 8-byte table B descriptor
|
||||
tofs *= 8;
|
||||
// fprintf(stderr,"PMMU: reading table B entries at %08x\n", tofs + tptr);
|
||||
tbl_entry2 = m68k_read_memory_32( tofs + tptr);
|
||||
tbl_entry = m68k_read_memory_32( tofs + tptr + 4);
|
||||
tbmode = tbl_entry2 & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x entry2 %08x mode %x tofs %x\n", addr_in, tbl_entry, tbl_entry2, tbmode, tofs);
|
||||
break;
|
||||
|
||||
case 1: // early termination descriptor
|
||||
tbl_entry &= 0xffffff00;
|
||||
|
||||
shift = is+abits;
|
||||
addr_out = ((addr_in<<shift)>>shift) + tbl_entry;
|
||||
resolved = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// if table A wasn't early-out, continue to process table B
|
||||
if (!resolved)
|
||||
{
|
||||
// get table C offset and pointer
|
||||
tofs = (addr_in<<(is+abits+bbits))>>(32-cbits);
|
||||
tptr = tbl_entry & 0xfffffff0;
|
||||
|
||||
switch (tbmode)
|
||||
{
|
||||
case 0: // invalid, should cause MMU exception
|
||||
fatalerror("680x0 PMMU: Unhandled Table B mode %d (addr_in %08x PC %x)\n", tbmode, addr_in, REG_PC);
|
||||
break;
|
||||
|
||||
case 2: // 4-byte table C descriptor
|
||||
tofs *= 4;
|
||||
// fprintf(stderr,"PMMU: reading table C entry at %08x\n", tofs + tptr);
|
||||
tbl_entry = m68k_read_memory_32(tofs + tptr);
|
||||
tcmode = tbl_entry & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x mode %x tofs %x\n", addr_in, tbl_entry, tbmode, tofs);
|
||||
break;
|
||||
|
||||
case 3: // 8-byte table C descriptor
|
||||
tofs *= 8;
|
||||
// fprintf(stderr,"PMMU: reading table C entries at %08x\n", tofs + tptr);
|
||||
tbl_entry2 = m68k_read_memory_32(tofs + tptr);
|
||||
tbl_entry = m68k_read_memory_32(tofs + tptr + 4);
|
||||
tcmode = tbl_entry2 & 3;
|
||||
// fprintf(stderr,"PMMU: addr %08x entry %08x entry2 %08x mode %x tofs %x\n", addr_in, tbl_entry, tbl_entry2, tbmode, tofs);
|
||||
break;
|
||||
|
||||
case 1: // termination descriptor
|
||||
tbl_entry &= 0xffffff00;
|
||||
|
||||
shift = is+abits+bbits;
|
||||
addr_out = ((addr_in<<shift)>>shift) + tbl_entry;
|
||||
resolved = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!resolved)
|
||||
{
|
||||
switch (tcmode)
|
||||
{
|
||||
case 0: // invalid, should cause MMU exception
|
||||
case 2: // 4-byte ??? descriptor
|
||||
case 3: // 8-byte ??? descriptor
|
||||
fatalerror("680x0 PMMU: Unhandled Table B mode %d (addr_in %08x PC %x)\n", tbmode, addr_in, REG_PC);
|
||||
break;
|
||||
|
||||
case 1: // termination descriptor
|
||||
tbl_entry &= 0xffffff00;
|
||||
|
||||
shift = is+abits+bbits+cbits;
|
||||
addr_out = ((addr_in<<shift)>>shift) + tbl_entry;
|
||||
resolved = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fprintf(stderr,"PMMU: [%08x] => [%08x]\n", addr_in, addr_out);
|
||||
|
||||
return addr_out;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
m68881_mmu_ops: COP 0 MMU opcode handling
|
||||
|
||||
*/
|
||||
|
||||
void m68881_mmu_ops(void)
|
||||
{
|
||||
uint16 modes;
|
||||
uint32 ea = m68ki_cpu.ir & 0x3f;
|
||||
uint64 temp64;
|
||||
|
||||
// catch the 2 "weird" encodings up front (PBcc)
|
||||
if ((m68ki_cpu.ir & 0xffc0) == 0xf0c0)
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PBcc\n");
|
||||
return;
|
||||
}
|
||||
else if ((m68ki_cpu.ir & 0xffc0) == 0xf080)
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PBcc\n");
|
||||
return;
|
||||
}
|
||||
else // the rest are 1111000xxxXXXXXX where xxx is the instruction family
|
||||
{
|
||||
switch ((m68ki_cpu.ir>>9) & 0x7)
|
||||
{
|
||||
case 0:
|
||||
modes = OPER_I_16();
|
||||
|
||||
if ((modes & 0xfde0) == 0x2000) // PLOAD
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PLOAD\n");
|
||||
return;
|
||||
}
|
||||
else if ((modes & 0xe200) == 0x2000) // PFLUSH
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PFLUSH PC=%x\n", REG_PC);
|
||||
return;
|
||||
}
|
||||
else if (modes == 0xa000) // PFLUSHR
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PFLUSHR\n");
|
||||
return;
|
||||
}
|
||||
else if (modes == 0x2800) // PVALID (FORMAT 1)
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PVALID1\n");
|
||||
return;
|
||||
}
|
||||
else if ((modes & 0xfff8) == 0x2c00) // PVALID (FORMAT 2)
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PVALID2\n");
|
||||
return;
|
||||
}
|
||||
else if ((modes & 0xe000) == 0x8000) // PTEST
|
||||
{
|
||||
fprintf(stderr,"680x0: unhandled PTEST\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ((modes>>13) & 0x7)
|
||||
{
|
||||
case 0: // MC68030/040 form with FD bit
|
||||
case 2: // MC68881 form, FD never set
|
||||
if (modes & 0x200)
|
||||
{
|
||||
switch ((modes>>10) & 7)
|
||||
{
|
||||
case 0: // translation control register
|
||||
WRITE_EA_32(ea, m68ki_cpu.mmu_tc);
|
||||
break;
|
||||
|
||||
case 2: // supervisor root pointer
|
||||
WRITE_EA_64(ea, (uint64)m68ki_cpu.mmu_srp_limit<<32 | (uint64)m68ki_cpu.mmu_srp_aptr);
|
||||
break;
|
||||
|
||||
case 3: // CPU root pointer
|
||||
WRITE_EA_64(ea, (uint64)m68ki_cpu.mmu_crp_limit<<32 | (uint64)m68ki_cpu.mmu_crp_aptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"680x0: PMOVE from unknown MMU register %x, PC %x\n", (modes>>10) & 7, REG_PC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ((modes>>10) & 7)
|
||||
{
|
||||
case 0: // translation control register
|
||||
m68ki_cpu.mmu_tc = READ_EA_32(ea);
|
||||
|
||||
if (m68ki_cpu.mmu_tc & 0x80000000)
|
||||
{
|
||||
m68ki_cpu.pmmu_enabled = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m68ki_cpu.pmmu_enabled = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // supervisor root pointer
|
||||
temp64 = READ_EA_64(ea);
|
||||
m68ki_cpu.mmu_srp_limit = (temp64>>32) & 0xffffffff;
|
||||
m68ki_cpu.mmu_srp_aptr = temp64 & 0xffffffff;
|
||||
break;
|
||||
|
||||
case 3: // CPU root pointer
|
||||
temp64 = READ_EA_64(ea);
|
||||
m68ki_cpu.mmu_crp_limit = (temp64>>32) & 0xffffffff;
|
||||
m68ki_cpu.mmu_crp_aptr = temp64 & 0xffffffff;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"680x0: PMOVE to unknown MMU register %x, PC %x\n", (modes>>10) & 7, REG_PC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // MC68030 to/from status reg
|
||||
if (modes & 0x200)
|
||||
{
|
||||
WRITE_EA_32(ea, m68ki_cpu.mmu_sr);
|
||||
}
|
||||
else
|
||||
{
|
||||
m68ki_cpu.mmu_sr = READ_EA_32(ea);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"680x0: unknown PMOVE mode %x (modes %04x) (PC %x)\n", (modes>>13) & 0x7, modes, REG_PC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,"680x0: unknown PMMU instruction group %d\n", (m68ki_cpu.ir>>9) & 0x7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,342 +0,0 @@
|
||||
MUSASHI
|
||||
=======
|
||||
|
||||
Version 4.10
|
||||
|
||||
A portable Motorola M680x0 processor emulation engine.
|
||||
Copyright 1998-2002 Karl Stenerud. All rights reserved.
|
||||
|
||||
|
||||
|
||||
INTRODUCTION:
|
||||
------------
|
||||
|
||||
Musashi is a Motorola 68000, 68010, 68EC020, 68020, 68EC030, 68030, 68EC040 and
|
||||
68040 emulator written in C. This emulator was written with two goals in mind:
|
||||
portability and speed.
|
||||
|
||||
The emulator is written to ANSI C89 specifications. It also uses inline
|
||||
functions, which are C9X compliant.
|
||||
|
||||
It has been successfully running in the MAME project (www.mame.net) for years
|
||||
and so has had time to mature.
|
||||
|
||||
|
||||
|
||||
LICENSE AND COPYRIGHT:
|
||||
---------------------
|
||||
|
||||
Copyright © 1998-2001 Karl Stenerud
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
|
||||
AVAILABILITY:
|
||||
------------
|
||||
The latest version of this code can be obtained at:
|
||||
https://github.com/kstenerud/Musashi
|
||||
|
||||
|
||||
|
||||
CONTACTING THE AUTHOR:
|
||||
---------------------
|
||||
I can be reached at kstenerud@gmail.com
|
||||
|
||||
|
||||
|
||||
BASIC CONFIGURATION:
|
||||
-------------------
|
||||
The basic configuration will give you a standard 68000 that has sufficient
|
||||
functionality to work in a primitive environment.
|
||||
|
||||
This setup assumes that you only have 1 device interrupting it, that the
|
||||
device will always request an autovectored interrupt, and it will always clear
|
||||
the interrupt before the interrupt service routine finishes (but could
|
||||
possibly re-assert the interrupt).
|
||||
You will have only one address space, no tracing, and no instruction prefetch.
|
||||
|
||||
To implement the basic configuration:
|
||||
|
||||
- Open m68kconf.h and verify that the settings for INLINE will work with your
|
||||
compiler. (Currently set to "static __inline__", which works in gcc 2.9.
|
||||
For C9X compliance, it should be "inline")
|
||||
|
||||
- In your host program, implement the following functions:
|
||||
unsigned int m68k_read_memory_8(unsigned int address);
|
||||
unsigned int m68k_read_memory_16(unsigned int address);
|
||||
unsigned int m68k_read_memory_32(unsigned int address);
|
||||
void m68k_write_memory_8(unsigned int address, unsigned int value);
|
||||
void m68k_write_memory_16(unsigned int address, unsigned int value);
|
||||
void m68k_write_memory_32(unsigned int address, unsigned int value);
|
||||
|
||||
- In your host program, be sure to call m68k_pulse_reset() once before calling
|
||||
any of the other functions as this initializes the core.
|
||||
|
||||
- Use m68k_execute() to execute instructions and m68k_set_irq() to cause an
|
||||
interrupt.
|
||||
|
||||
|
||||
|
||||
ADDING PROPER INTERRUPT HANDLING:
|
||||
--------------------------------
|
||||
The interrupt handling in the basic configuration doesn't emulate the
|
||||
interrupt acknowledge phase of the CPU and automatically clears an interrupt
|
||||
request during interrupt processing.
|
||||
While this works for most systems, you may need more accurate interrupt
|
||||
handling.
|
||||
|
||||
To add proper interrupt handling:
|
||||
|
||||
- In m68kconf.h, set M68K_EMULATE_INT_ACK to OPT_SPECIFY_HANDLER
|
||||
|
||||
- In m68kconf.h, set M68K_INT_ACK_CALLBACK(A) to your interrupt acknowledge
|
||||
routine
|
||||
|
||||
- Your interrupt acknowledge routine must return an interrupt vector,
|
||||
M68K_INT_ACK_AUTOVECTOR, or M68K_INT_ACK_SPURIOUS. most m68k
|
||||
implementations just use autovectored interrupts.
|
||||
|
||||
- When the interrupting device is satisfied, you must call m68k_set_irq(0) to
|
||||
remove the interrupt request.
|
||||
|
||||
|
||||
|
||||
MULTIPLE INTERRUPTS:
|
||||
-------------------
|
||||
The above system will work if you have only one device interrupting the CPU,
|
||||
but if you have more than one device, you must do a bit more.
|
||||
|
||||
To add multiple interrupts:
|
||||
|
||||
- You must make an interrupt arbitration device that will take the highest
|
||||
priority interrupt and encode it onto the IRQ pins on the CPU.
|
||||
|
||||
- The interrupt arbitration device should use m68k_set_irq() to set the
|
||||
highest pending interrupt, or 0 for no interrupts pending.
|
||||
|
||||
|
||||
|
||||
SEPARATE IMMEDIATE READS:
|
||||
------------------------
|
||||
You can write faster memory access functions if you know whether you are
|
||||
fetching from ROM or RAM. Immediate reads are always from the program space
|
||||
(Always in ROM unless it is running self-modifying code).
|
||||
|
||||
To enable separate immediate reads:
|
||||
|
||||
- In m68kconf.h, turn on M68K_SEPARATE_READ_IMM.
|
||||
|
||||
- In your host program, implement the following functions:
|
||||
unsigned int m68k_read_immediate_16(unsigned int address);
|
||||
unsigned int m68k_read_immediate_32(unsigned int address);
|
||||
|
||||
Now you also have the pcrelative stuff:
|
||||
unsigned int m68k_read_pcrelative_8(unsigned int address);
|
||||
unsigned int m68k_read_pcrelative_16(unsigned int address);
|
||||
unsigned int m68k_read_pcrelative_32(unsigned int address);
|
||||
|
||||
- If you need to know the current PC (for banking and such), set
|
||||
M68K_MONITOR_PC to OPT_SPECIFY_HANDLER, and set M68K_SET_PC_CALLBACK(A) to
|
||||
your routine.
|
||||
|
||||
- In the unlikely case where you need to emulate some PMMU in the immediate
|
||||
reads and/or pcrealtive stuff, you'll need to explicitely call the
|
||||
translation address mechanism from your user functions this way :
|
||||
|
||||
if (PMMU_ENABLED)
|
||||
address = pmmu_translate_addr(address);
|
||||
|
||||
(this is handled automatically by normal memory accesses).
|
||||
|
||||
ADDRESS SPACES:
|
||||
--------------
|
||||
Most systems will only implement one address space, placing ROM at the lower
|
||||
addresses and RAM at the higher. However, there is the possibility that a
|
||||
system will implement ROM and RAM in the same address range, but in different
|
||||
address spaces.
|
||||
|
||||
In this case, you might get away with assuming that immediate reads are in the
|
||||
program space and all other reads are in the data space, if it weren't for the
|
||||
fact that the exception vectors are fetched from the data space. As a result,
|
||||
anyone implementing this kind of system will have to copy the vector table
|
||||
from ROM to RAM using pc-relative instructions.
|
||||
|
||||
This makes things bad for emulation, because this means that a non-immediate
|
||||
read is not necessarily in the data space.
|
||||
The m68k deals with this by encoding the requested address space on the
|
||||
function code pins:
|
||||
|
||||
FC
|
||||
Address Space 210
|
||||
------------------ ---
|
||||
USER DATA 001
|
||||
USER PROGRAM 010
|
||||
SUPERVISOR DATA 101
|
||||
SUPERVISOR PROGRAM 110
|
||||
CPU SPACE 111 <-- not emulated in this core since we emulate
|
||||
interrupt acknowledge in another way.
|
||||
|
||||
To emulate the function code pins:
|
||||
|
||||
- In m68kconf.h, set M68K_EMULATE_FC to OPT_SPECIFY_HANDLER and set
|
||||
M68K_SET_FC_CALLBACK(A) to your function code handler function.
|
||||
|
||||
- Your function code handler should select the proper address space for
|
||||
subsequent calls to m68k_read_xx (and m68k_write_xx for 68010+).
|
||||
|
||||
Note: immediate reads are always done from program space, so technically you
|
||||
don't need to implement the separate immediate reads, although you could
|
||||
gain more speed improvements leaving them in and doing some clever
|
||||
programming.
|
||||
|
||||
|
||||
|
||||
USING DIFFERENT CPU TYPES:
|
||||
-------------------------
|
||||
The default is to enable only the 68000 cpu type. To change this, change the
|
||||
settings for M68K_EMULATE_010 etc in m68kconf.h.
|
||||
|
||||
To set the CPU type you want to use:
|
||||
|
||||
- Make sure it is enabled in m68kconf.h. Current switches are:
|
||||
M68K_EMULATE_010
|
||||
M68K_EMULATE_EC020
|
||||
M68K_EMULATE_020
|
||||
|
||||
- In your host program, call m68k_set_cpu_type() and then call
|
||||
m68k_pulse_reset(). Valid CPU types are:
|
||||
M68K_CPU_TYPE_68000,
|
||||
M68K_CPU_TYPE_68010,
|
||||
M68K_CPU_TYPE_68EC020,
|
||||
M68K_CPU_TYPE_68020,
|
||||
M68K_CPU_TYPE_68EC030,
|
||||
M68K_CPU_TYPE_68030,
|
||||
M68K_CPU_TYPE_68EC040,
|
||||
M68K_CPU_TYPE_68040,
|
||||
M68K_CPU_TYPE_SCC68070 (which is a 68010 with a 32 bit data bus).
|
||||
|
||||
CLOCK FREQUENCY:
|
||||
---------------
|
||||
In order to emulate the correct clock frequency, you will have to calculate
|
||||
how long it takes the emulation to execute a certain number of "cycles" and
|
||||
vary your calls to m68k_execute() accordingly.
|
||||
As well, it is a good idea to take away the CPU's timeslice when it writes to
|
||||
a memory-mapped port in order to give the device it wrote to a chance to
|
||||
react.
|
||||
|
||||
You can use the functions m68k_cycles_run(), m68k_cycles_remaining(),
|
||||
m68k_modify_timeslice(), and m68k_end_timeslice() to do this.
|
||||
Try to use large cycle values in your calls to m68k_execute() since it will
|
||||
increase throughput. You can always take away the timeslice later.
|
||||
|
||||
|
||||
|
||||
MORE CORRECT EMULATION:
|
||||
----------------------
|
||||
You may need to enable these in order to properly emulate some of the more
|
||||
obscure functions of the m68k:
|
||||
|
||||
- M68K_EMULATE_BKPT_ACK causes the CPU to call a breakpoint handler on a BKPT
|
||||
instruction
|
||||
|
||||
- M68K_EMULATE_TRACE causes the CPU to generate trace exceptions when the
|
||||
trace bits are set
|
||||
|
||||
- M68K_EMULATE_RESET causes the CPU to call a reset handler on a RESET
|
||||
instruction.
|
||||
|
||||
- M68K_EMULATE_PREFETCH emulates the 4-word instruction prefetch that is part
|
||||
of the 68000/68010 (needed for Amiga emulation).
|
||||
NOTE: if the CPU fetches a word or longword at an odd address when this
|
||||
option is on, it will yield unpredictable results, which is why a real
|
||||
68000 will generate an address error exception.
|
||||
|
||||
- M68K_EMULATE_ADDRESS_ERROR will cause the CPU to generate address error
|
||||
exceptions if it attempts to read a word or longword at an odd address.
|
||||
|
||||
- call m68k_pulse_halt() to emulate the HALT pin.
|
||||
|
||||
|
||||
|
||||
CONVENIENCE FUNCTIONS:
|
||||
---------------------
|
||||
These are in here for programmer convenience:
|
||||
|
||||
- M68K_INSTRUCTION_HOOK lets you call a handler before each instruction.
|
||||
|
||||
- M68K_LOG_ENABLE and M68K_LOG_1010_1111 lets you log illegal and A/F-line
|
||||
instructions.
|
||||
|
||||
|
||||
|
||||
MULTIPLE CPU EMULATION:
|
||||
----------------------
|
||||
The default is to use only one CPU. To use more than one CPU in this core,
|
||||
there are some things to keep in mind:
|
||||
|
||||
- To have different cpus call different functions, use OPT_ON instead of
|
||||
OPT_SPECIFY_HANDLER, and use the m68k_set_xxx_callback() functions to set
|
||||
your callback handlers on a per-cpu basis.
|
||||
|
||||
- Be sure to call set_cpu_type() for each CPU you use.
|
||||
|
||||
- Use m68k_set_context() and m68k_get_context() to switch to another CPU.
|
||||
|
||||
|
||||
|
||||
LOAD AND SAVE CPU CONTEXTS FROM DISK:
|
||||
------------------------------------
|
||||
You can use them68k_load_context() and m68k_save_context() functions to load
|
||||
and save the CPU state to disk.
|
||||
|
||||
|
||||
|
||||
GET/SET INFORMATION FROM THE CPU:
|
||||
--------------------------------
|
||||
You can use m68k_get_reg() and m68k_set_reg() to gain access to the internals
|
||||
of the CPU.
|
||||
|
||||
|
||||
|
||||
EXAMPLE:
|
||||
-------
|
||||
|
||||
The subdir example contains a full example (currently linux & Dos only).
|
||||
|
||||
Compilation
|
||||
-----------
|
||||
|
||||
You can use the default Makefile in Musashi's directory, it works like this :
|
||||
1st build m68kmake, which will build m68kops.c and m68kops.h based on the
|
||||
contents of m68k_in.c.
|
||||
Then compile m68kcpu.o and m68kops.o. Add m68kdasm.o if you want the
|
||||
disassemble functions. When linking this to your project you will need libm
|
||||
for the fpu emulation of the 68040.
|
||||
|
||||
Using some custom m68kconf.h outside Musashi's directory
|
||||
--------------------------------------------------------
|
||||
|
||||
It can be useful to keep an untouched musashi directory in a project (from
|
||||
git for example) and maintain a separate m68kconf.h specific to the
|
||||
project. For this, pass -DMUSASHI_CNF="mycustomconfig.h" to gcc (or whatever
|
||||
compiler you use). Notice that if you use an unix shell (or make which uses
|
||||
the shell to launch its commands), then you need to escape the quotes like
|
||||
this : -DMUSASHI_CNF=\"mycustomconfig.h\"
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
MAME note: this package is derived from the following original SoftFloat
|
||||
package and has been "re-packaged" to work with MAME's conventions and
|
||||
build system. The source files come from bits64/ and bits64/templates
|
||||
in the original distribution as MAME requires a compiler with a 64-bit
|
||||
integer type.
|
||||
|
||||
|
||||
Package Overview for SoftFloat Release 2b
|
||||
|
||||
John R. Hauser
|
||||
2002 May 27
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Overview
|
||||
|
||||
SoftFloat is a software implementation of floating-point that conforms to
|
||||
the IEC/IEEE Standard for Binary Floating-Point Arithmetic. SoftFloat is
|
||||
distributed in the form of C source code. Compiling the SoftFloat sources
|
||||
generates two things:
|
||||
|
||||
-- A SoftFloat object file (typically `softfloat.o') containing the complete
|
||||
set of IEC/IEEE floating-point routines.
|
||||
|
||||
-- A `timesoftfloat' program for evaluating the speed of the SoftFloat
|
||||
routines. (The SoftFloat module is linked into this program.)
|
||||
|
||||
The SoftFloat package is documented in four text files:
|
||||
|
||||
SoftFloat.txt Documentation for using the SoftFloat functions.
|
||||
SoftFloat-source.txt Documentation for compiling SoftFloat.
|
||||
SoftFloat-history.txt History of major changes to SoftFloat.
|
||||
timesoftfloat.txt Documentation for using `timesoftfloat'.
|
||||
|
||||
Other files in the package comprise the source code for SoftFloat.
|
||||
|
||||
Please be aware that some work is involved in porting this software to other
|
||||
targets. It is not just a matter of getting `make' to complete without
|
||||
error messages. I would have written the code that way if I could, but
|
||||
there are fundamental differences between systems that can't be hidden.
|
||||
You should not attempt to compile SoftFloat without first reading both
|
||||
`SoftFloat.txt' and `SoftFloat-source.txt'.
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Legal Notice
|
||||
|
||||
SoftFloat was written by me, John R. Hauser. This work was made possible in
|
||||
part by the International Computer Science Institute, located at Suite 600,
|
||||
1947 Center Street, Berkeley, California 94704. Funding was partially
|
||||
provided by the National Science Foundation under grant MIP-9311980. The
|
||||
original version of this code was written as part of a project to build
|
||||
a fixed-point vector processor in collaboration with the University of
|
||||
California at Berkeley, overseen by Profs. Nelson Morgan and John Wawrzynek.
|
||||
|
||||
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
|
||||
has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
|
||||
TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
|
||||
PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL
|
||||
LOSSES, COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO
|
||||
FURTHERMORE EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER
|
||||
SCIENCE INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES,
|
||||
COSTS, OR OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE
|
||||
SOFTWARE.
|
||||
|
||||
Derivative works are acceptable, even for commercial purposes, provided
|
||||
that the minimal documentation requirements stated in the source code are
|
||||
satisfied.
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Contact Information
|
||||
|
||||
At the time of this writing, the most up-to-date information about
|
||||
SoftFloat and the latest release can be found at the Web page `http://
|
||||
www.cs.berkeley.edu/~jhauser/arithmetic/SoftFloat.html'.
|
||||
|
||||
|
||||
@ -1,61 +0,0 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
| One of the macros `BIGENDIAN' or `LITTLEENDIAN' must be defined.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#ifdef LSB_FIRST
|
||||
#define LITTLEENDIAN
|
||||
#else
|
||||
#define BIGENDIAN
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The macro `BITS64' can be defined to indicate that 64-bit integer types are
|
||||
| supported by the compiler.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define BITS64
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Each of the following `typedef's defines the most convenient type that holds
|
||||
| integers of at least as many bits as specified. For example, `uint8' should
|
||||
| be the most convenient type that can hold unsigned integers of as many as
|
||||
| 8 bits. The `flag' type must be able to hold either a 0 or 1. For most
|
||||
| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
|
||||
| to the same as `int'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
typedef sint8 flag;
|
||||
typedef sint8 int8;
|
||||
typedef sint16 int16;
|
||||
typedef sint32 int32;
|
||||
typedef sint64 int64;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Each of the following `typedef's defines a type that holds integers
|
||||
| of _exactly_ the number of bits specified. For instance, for most
|
||||
| implementation of C, `bits16' and `sbits16' should be `typedef'ed to
|
||||
| `unsigned short int' and `signed short int' (or `short int'), respectively.
|
||||
*----------------------------------------------------------------------------*/
|
||||
typedef uint8 bits8;
|
||||
typedef sint8 sbits8;
|
||||
typedef uint16 bits16;
|
||||
typedef sint16 sbits16;
|
||||
typedef uint32 bits32;
|
||||
typedef sint32 sbits32;
|
||||
typedef uint64 bits64;
|
||||
typedef sint64 sbits64;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The `LIT64' macro takes as its argument a textual integer literal and
|
||||
| if necessary ``marks'' the literal as having a 64-bit integer type.
|
||||
| For example, the GNU C Compiler (`gcc') requires that 64-bit literals be
|
||||
| appended with the letters `LL' standing for `long long', which is `gcc's
|
||||
| name for the 64-bit integer type. Some compilers may allow `LIT64' to be
|
||||
| defined as the identity macro: `#define LIT64( a ) a'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define LIT64( a ) a##ULL
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The macro `INLINE' can be used before functions that should be inlined. If
|
||||
| a compiler does not support explicit inlining, this macro should be defined
|
||||
| to be `static'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
// MAME defines INLINE
|
||||
@ -1,42 +0,0 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
|
||||
Package, Release 2b.
|
||||
|
||||
Written by John R. Hauser. This work was made possible in part by the
|
||||
International Computer Science Institute, located at Suite 600, 1947 Center
|
||||
Street, Berkeley, California 94704. Funding was partially provided by the
|
||||
National Science Foundation under grant MIP-9311980. The original version
|
||||
of this code was written as part of a project to build a fixed-point vector
|
||||
processor in collaboration with the University of California at Berkeley,
|
||||
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
|
||||
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
|
||||
arithmetic/SoftFloat.html'.
|
||||
|
||||
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
|
||||
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
|
||||
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
|
||||
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
|
||||
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
|
||||
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
|
||||
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
|
||||
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
|
||||
|
||||
Derivative works are acceptable, even for commercial purposes, so long as
|
||||
(1) the source code for the derivative work includes prominent notice that
|
||||
the work is derivative, and (2) the source code includes prominent notice with
|
||||
these four paragraphs for those parts of this code that are retained.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Include common integer types and flags.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#include "mamesf.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Symbolic Boolean literals.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
@ -1,732 +0,0 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
|
||||
Arithmetic Package, Release 2b.
|
||||
|
||||
Written by John R. Hauser. This work was made possible in part by the
|
||||
International Computer Science Institute, located at Suite 600, 1947 Center
|
||||
Street, Berkeley, California 94704. Funding was partially provided by the
|
||||
National Science Foundation under grant MIP-9311980. The original version
|
||||
of this code was written as part of a project to build a fixed-point vector
|
||||
processor in collaboration with the University of California at Berkeley,
|
||||
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
|
||||
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
|
||||
arithmetic/SoftFloat.html'.
|
||||
|
||||
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
|
||||
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
|
||||
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
|
||||
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
|
||||
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
|
||||
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
|
||||
INSTITUTE (possibly via similar legal notice) AGAINST ALL LOSSES, COSTS, OR
|
||||
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
|
||||
|
||||
Derivative works are acceptable, even for commercial purposes, so long as
|
||||
(1) the source code for the derivative work includes prominent notice that
|
||||
the work is derivative, and (2) the source code includes prominent notice with
|
||||
these four paragraphs for those parts of this code that are retained.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts `a' right by the number of bits given in `count'. If any nonzero
|
||||
| bits are shifted off, they are ``jammed'' into the least significant bit of
|
||||
| the result by setting the least significant bit to 1. The value of `count'
|
||||
| can be arbitrarily large; in particular, if `count' is greater than 32, the
|
||||
| result will be either 0 or 1, depending on whether `a' is zero or nonzero.
|
||||
| The result is stored in the location pointed to by `zPtr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr )
|
||||
{
|
||||
bits32 z;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z = a;
|
||||
}
|
||||
else if ( count < 32 ) {
|
||||
z = ( a>>count ) | ( ( a<<( ( - count ) & 31 ) ) != 0 );
|
||||
}
|
||||
else {
|
||||
z = ( a != 0 );
|
||||
}
|
||||
*zPtr = z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts `a' right by the number of bits given in `count'. If any nonzero
|
||||
| bits are shifted off, they are ``jammed'' into the least significant bit of
|
||||
| the result by setting the least significant bit to 1. The value of `count'
|
||||
| can be arbitrarily large; in particular, if `count' is greater than 64, the
|
||||
| result will be either 0 or 1, depending on whether `a' is zero or nonzero.
|
||||
| The result is stored in the location pointed to by `zPtr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void shift64RightJamming( bits64 a, int16 count, bits64 *zPtr )
|
||||
{
|
||||
bits64 z;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z = a;
|
||||
}
|
||||
else if ( count < 64 ) {
|
||||
z = ( a>>count ) | ( ( a<<( ( - count ) & 63 ) ) != 0 );
|
||||
}
|
||||
else {
|
||||
z = ( a != 0 );
|
||||
}
|
||||
*zPtr = z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by 64
|
||||
| _plus_ the number of bits given in `count'. The shifted result is at most
|
||||
| 64 nonzero bits; this is stored at the location pointed to by `z0Ptr'. The
|
||||
| bits shifted off form a second 64-bit result as follows: The _last_ bit
|
||||
| shifted off is the most-significant bit of the extra result, and the other
|
||||
| 63 bits of the extra result are all zero if and only if _all_but_the_last_
|
||||
| bits shifted off were all zero. This extra result is stored in the location
|
||||
| pointed to by `z1Ptr'. The value of `count' can be arbitrarily large.
|
||||
| (This routine makes more sense if `a0' and `a1' are considered to form
|
||||
| a fixed-point value with binary point between `a0' and `a1'. This fixed-
|
||||
| point value is shifted right by the number of bits given in `count', and
|
||||
| the integer part of the result is returned at the location pointed to by
|
||||
| `z0Ptr'. The fractional part of the result may be slightly corrupted as
|
||||
| described above, and is returned at the location pointed to by `z1Ptr'.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shift64ExtraRightJamming(
|
||||
bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
bits64 z0, z1;
|
||||
int8 negCount = ( - count ) & 63;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z1 = a1;
|
||||
z0 = a0;
|
||||
}
|
||||
else if ( count < 64 ) {
|
||||
z1 = ( a0<<negCount ) | ( a1 != 0 );
|
||||
z0 = a0>>count;
|
||||
}
|
||||
else {
|
||||
if ( count == 64 ) {
|
||||
z1 = a0 | ( a1 != 0 );
|
||||
}
|
||||
else {
|
||||
z1 = ( ( a0 | a1 ) != 0 );
|
||||
}
|
||||
z0 = 0;
|
||||
}
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the
|
||||
| number of bits given in `count'. Any bits shifted off are lost. The value
|
||||
| of `count' can be arbitrarily large; in particular, if `count' is greater
|
||||
| than 128, the result will be 0. The result is broken into two 64-bit pieces
|
||||
| which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shift128Right(
|
||||
bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
bits64 z0, z1;
|
||||
int8 negCount = ( - count ) & 63;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z1 = a1;
|
||||
z0 = a0;
|
||||
}
|
||||
else if ( count < 64 ) {
|
||||
z1 = ( a0<<negCount ) | ( a1>>count );
|
||||
z0 = a0>>count;
|
||||
}
|
||||
else {
|
||||
z1 = ( count < 64 ) ? ( a0>>( count & 63 ) ) : 0;
|
||||
z0 = 0;
|
||||
}
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the
|
||||
| number of bits given in `count'. If any nonzero bits are shifted off, they
|
||||
| are ``jammed'' into the least significant bit of the result by setting the
|
||||
| least significant bit to 1. The value of `count' can be arbitrarily large;
|
||||
| in particular, if `count' is greater than 128, the result will be either
|
||||
| 0 or 1, depending on whether the concatenation of `a0' and `a1' is zero or
|
||||
| nonzero. The result is broken into two 64-bit pieces which are stored at
|
||||
| the locations pointed to by `z0Ptr' and `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shift128RightJamming(
|
||||
bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
bits64 z0, z1;
|
||||
int8 negCount = ( - count ) & 63;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z1 = a1;
|
||||
z0 = a0;
|
||||
}
|
||||
else if ( count < 64 ) {
|
||||
z1 = ( a0<<negCount ) | ( a1>>count ) | ( ( a1<<negCount ) != 0 );
|
||||
z0 = a0>>count;
|
||||
}
|
||||
else {
|
||||
if ( count == 64 ) {
|
||||
z1 = a0 | ( a1 != 0 );
|
||||
}
|
||||
else if ( count < 128 ) {
|
||||
z1 = ( a0>>( count & 63 ) ) | ( ( ( a0<<negCount ) | a1 ) != 0 );
|
||||
}
|
||||
else {
|
||||
z1 = ( ( a0 | a1 ) != 0 );
|
||||
}
|
||||
z0 = 0;
|
||||
}
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' right
|
||||
| by 64 _plus_ the number of bits given in `count'. The shifted result is
|
||||
| at most 128 nonzero bits; these are broken into two 64-bit pieces which are
|
||||
| stored at the locations pointed to by `z0Ptr' and `z1Ptr'. The bits shifted
|
||||
| off form a third 64-bit result as follows: The _last_ bit shifted off is
|
||||
| the most-significant bit of the extra result, and the other 63 bits of the
|
||||
| extra result are all zero if and only if _all_but_the_last_ bits shifted off
|
||||
| were all zero. This extra result is stored in the location pointed to by
|
||||
| `z2Ptr'. The value of `count' can be arbitrarily large.
|
||||
| (This routine makes more sense if `a0', `a1', and `a2' are considered
|
||||
| to form a fixed-point value with binary point between `a1' and `a2'. This
|
||||
| fixed-point value is shifted right by the number of bits given in `count',
|
||||
| and the integer part of the result is returned at the locations pointed to
|
||||
| by `z0Ptr' and `z1Ptr'. The fractional part of the result may be slightly
|
||||
| corrupted as described above, and is returned at the location pointed to by
|
||||
| `z2Ptr'.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shift128ExtraRightJamming(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 a2,
|
||||
int16 count,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2;
|
||||
int8 negCount = ( - count ) & 63;
|
||||
|
||||
if ( count == 0 ) {
|
||||
z2 = a2;
|
||||
z1 = a1;
|
||||
z0 = a0;
|
||||
}
|
||||
else {
|
||||
if ( count < 64 ) {
|
||||
z2 = a1<<negCount;
|
||||
z1 = ( a0<<negCount ) | ( a1>>count );
|
||||
z0 = a0>>count;
|
||||
}
|
||||
else {
|
||||
if ( count == 64 ) {
|
||||
z2 = a1;
|
||||
z1 = a0;
|
||||
}
|
||||
else {
|
||||
a2 |= a1;
|
||||
if ( count < 128 ) {
|
||||
z2 = a0<<negCount;
|
||||
z1 = a0>>( count & 63 );
|
||||
}
|
||||
else {
|
||||
z2 = ( count == 128 ) ? a0 : ( a0 != 0 );
|
||||
z1 = 0;
|
||||
}
|
||||
}
|
||||
z0 = 0;
|
||||
}
|
||||
z2 |= ( a2 != 0 );
|
||||
}
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128-bit value formed by concatenating `a0' and `a1' left by the
|
||||
| number of bits given in `count'. Any bits shifted off are lost. The value
|
||||
| of `count' must be less than 64. The result is broken into two 64-bit
|
||||
| pieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shortShift128Left(
|
||||
bits64 a0, bits64 a1, int16 count, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
|
||||
*z1Ptr = a1<<count;
|
||||
*z0Ptr =
|
||||
( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 63 ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' left
|
||||
| by the number of bits given in `count'. Any bits shifted off are lost.
|
||||
| The value of `count' must be less than 64. The result is broken into three
|
||||
| 64-bit pieces which are stored at the locations pointed to by `z0Ptr',
|
||||
| `z1Ptr', and `z2Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
shortShift192Left(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 a2,
|
||||
int16 count,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2;
|
||||
int8 negCount;
|
||||
|
||||
z2 = a2<<count;
|
||||
z1 = a1<<count;
|
||||
z0 = a0<<count;
|
||||
if ( 0 < count ) {
|
||||
negCount = ( ( - count ) & 63 );
|
||||
z1 |= a2>>negCount;
|
||||
z0 |= a1>>negCount;
|
||||
}
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Adds the 128-bit value formed by concatenating `a0' and `a1' to the 128-bit
|
||||
| value formed by concatenating `b0' and `b1'. Addition is modulo 2^128, so
|
||||
| any carry out is lost. The result is broken into two 64-bit pieces which
|
||||
| are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
add128(
|
||||
bits64 a0, bits64 a1, bits64 b0, bits64 b1, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
bits64 z1;
|
||||
|
||||
z1 = a1 + b1;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = a0 + b0 + ( z1 < a1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Adds the 192-bit value formed by concatenating `a0', `a1', and `a2' to the
|
||||
| 192-bit value formed by concatenating `b0', `b1', and `b2'. Addition is
|
||||
| modulo 2^192, so any carry out is lost. The result is broken into three
|
||||
| 64-bit pieces which are stored at the locations pointed to by `z0Ptr',
|
||||
| `z1Ptr', and `z2Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
add192(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 a2,
|
||||
bits64 b0,
|
||||
bits64 b1,
|
||||
bits64 b2,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2;
|
||||
uint8 carry0, carry1;
|
||||
|
||||
z2 = a2 + b2;
|
||||
carry1 = ( z2 < a2 );
|
||||
z1 = a1 + b1;
|
||||
carry0 = ( z1 < a1 );
|
||||
z0 = a0 + b0;
|
||||
z1 += carry1;
|
||||
z0 += ( z1 < carry1 );
|
||||
z0 += carry0;
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Subtracts the 128-bit value formed by concatenating `b0' and `b1' from the
|
||||
| 128-bit value formed by concatenating `a0' and `a1'. Subtraction is modulo
|
||||
| 2^128, so any borrow out (carry out) is lost. The result is broken into two
|
||||
| 64-bit pieces which are stored at the locations pointed to by `z0Ptr' and
|
||||
| `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
sub128(
|
||||
bits64 a0, bits64 a1, bits64 b0, bits64 b1, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
|
||||
*z1Ptr = a1 - b1;
|
||||
*z0Ptr = a0 - b0 - ( a1 < b1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Subtracts the 192-bit value formed by concatenating `b0', `b1', and `b2'
|
||||
| from the 192-bit value formed by concatenating `a0', `a1', and `a2'.
|
||||
| Subtraction is modulo 2^192, so any borrow out (carry out) is lost. The
|
||||
| result is broken into three 64-bit pieces which are stored at the locations
|
||||
| pointed to by `z0Ptr', `z1Ptr', and `z2Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
sub192(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 a2,
|
||||
bits64 b0,
|
||||
bits64 b1,
|
||||
bits64 b2,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2;
|
||||
uint8 borrow0, borrow1;
|
||||
|
||||
z2 = a2 - b2;
|
||||
borrow1 = ( a2 < b2 );
|
||||
z1 = a1 - b1;
|
||||
borrow0 = ( a1 < b1 );
|
||||
z0 = a0 - b0;
|
||||
z0 -= ( z1 < borrow1 );
|
||||
z1 -= borrow1;
|
||||
z0 -= borrow0;
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Multiplies `a' by `b' to obtain a 128-bit product. The product is broken
|
||||
| into two 64-bit pieces which are stored at the locations pointed to by
|
||||
| `z0Ptr' and `z1Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void mul64To128( bits64 a, bits64 b, bits64 *z0Ptr, bits64 *z1Ptr )
|
||||
{
|
||||
bits32 aHigh, aLow, bHigh, bLow;
|
||||
bits64 z0, zMiddleA, zMiddleB, z1;
|
||||
|
||||
aLow = a;
|
||||
aHigh = a>>32;
|
||||
bLow = b;
|
||||
bHigh = b>>32;
|
||||
z1 = ( (bits64) aLow ) * bLow;
|
||||
zMiddleA = ( (bits64) aLow ) * bHigh;
|
||||
zMiddleB = ( (bits64) aHigh ) * bLow;
|
||||
z0 = ( (bits64) aHigh ) * bHigh;
|
||||
zMiddleA += zMiddleB;
|
||||
z0 += ( ( (bits64) ( zMiddleA < zMiddleB ) )<<32 ) + ( zMiddleA>>32 );
|
||||
zMiddleA <<= 32;
|
||||
z1 += zMiddleA;
|
||||
z0 += ( z1 < zMiddleA );
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Multiplies the 128-bit value formed by concatenating `a0' and `a1' by
|
||||
| `b' to obtain a 192-bit product. The product is broken into three 64-bit
|
||||
| pieces which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and
|
||||
| `z2Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
mul128By64To192(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 b,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2, more1;
|
||||
|
||||
mul64To128( a1, b, &z1, &z2 );
|
||||
mul64To128( a0, b, &z0, &more1 );
|
||||
add128( z0, more1, 0, z1, &z0, &z1 );
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Multiplies the 128-bit value formed by concatenating `a0' and `a1' to the
|
||||
| 128-bit value formed by concatenating `b0' and `b1' to obtain a 256-bit
|
||||
| product. The product is broken into four 64-bit pieces which are stored at
|
||||
| the locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
mul128To256(
|
||||
bits64 a0,
|
||||
bits64 a1,
|
||||
bits64 b0,
|
||||
bits64 b1,
|
||||
bits64 *z0Ptr,
|
||||
bits64 *z1Ptr,
|
||||
bits64 *z2Ptr,
|
||||
bits64 *z3Ptr
|
||||
)
|
||||
{
|
||||
bits64 z0, z1, z2, z3;
|
||||
bits64 more1, more2;
|
||||
|
||||
mul64To128( a1, b1, &z2, &z3 );
|
||||
mul64To128( a1, b0, &z1, &more2 );
|
||||
add128( z1, more2, 0, z2, &z1, &z2 );
|
||||
mul64To128( a0, b0, &z0, &more1 );
|
||||
add128( z0, more1, 0, z1, &z0, &z1 );
|
||||
mul64To128( a0, b1, &more1, &more2 );
|
||||
add128( more1, more2, 0, z2, &more1, &z2 );
|
||||
add128( z0, z1, 0, more1, &z0, &z1 );
|
||||
*z3Ptr = z3;
|
||||
*z2Ptr = z2;
|
||||
*z1Ptr = z1;
|
||||
*z0Ptr = z0;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns an approximation to the 64-bit integer quotient obtained by dividing
|
||||
| `b' into the 128-bit value formed by concatenating `a0' and `a1'. The
|
||||
| divisor `b' must be at least 2^63. If q is the exact quotient truncated
|
||||
| toward zero, the approximation returned lies between q and q + 2 inclusive.
|
||||
| If the exact quotient q is larger than 64 bits, the maximum positive 64-bit
|
||||
| unsigned integer is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline bits64 estimateDiv128To64( bits64 a0, bits64 a1, bits64 b )
|
||||
{
|
||||
bits64 b0, b1;
|
||||
bits64 rem0, rem1, term0, term1;
|
||||
bits64 z;
|
||||
|
||||
if ( b <= a0 ) return LIT64( 0xFFFFFFFFFFFFFFFF );
|
||||
b0 = b>>32;
|
||||
z = ( b0<<32 <= a0 ) ? LIT64( 0xFFFFFFFF00000000 ) : ( a0 / b0 )<<32;
|
||||
mul64To128( b, z, &term0, &term1 );
|
||||
sub128( a0, a1, term0, term1, &rem0, &rem1 );
|
||||
while ( ( (sbits64) rem0 ) < 0 ) {
|
||||
z -= LIT64( 0x100000000 );
|
||||
b1 = b<<32;
|
||||
add128( rem0, rem1, b0, b1, &rem0, &rem1 );
|
||||
}
|
||||
rem0 = ( rem0<<32 ) | ( rem1>>32 );
|
||||
z |= ( b0<<32 <= rem0 ) ? 0xFFFFFFFF : rem0 / b0;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns an approximation to the square root of the 32-bit significand given
|
||||
| by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of
|
||||
| `aExp' (the least significant bit) is 1, the integer returned approximates
|
||||
| 2^31*sqrt(`a'/2^31), where `a' is considered an integer. If bit 0 of `aExp'
|
||||
| is 0, the integer returned approximates 2^31*sqrt(`a'/2^30). In either
|
||||
| case, the approximation returned lies strictly within +/-2 of the exact
|
||||
| value.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline bits32 estimateSqrt32( int16 aExp, bits32 a )
|
||||
{
|
||||
static const bits16 sqrtOddAdjustments[] = {
|
||||
0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
|
||||
0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67
|
||||
};
|
||||
static const bits16 sqrtEvenAdjustments[] = {
|
||||
0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,
|
||||
0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002
|
||||
};
|
||||
int8 index;
|
||||
bits32 z;
|
||||
|
||||
index = ( a>>27 ) & 15;
|
||||
if ( aExp & 1 ) {
|
||||
z = 0x4000 + ( a>>17 ) - sqrtOddAdjustments[ index ];
|
||||
z = ( ( a / z )<<14 ) + ( z<<15 );
|
||||
a >>= 1;
|
||||
}
|
||||
else {
|
||||
z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ index ];
|
||||
z = a / z + z;
|
||||
z = ( 0x20000 <= z ) ? 0xFFFF8000 : ( z<<15 );
|
||||
if ( z <= a ) return (bits32) ( ( (sbits32) a )>>1 );
|
||||
}
|
||||
return ( (bits32) ( ( ( (bits64) a )<<31 ) / z ) ) + ( z>>1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the number of leading 0 bits before the most-significant 1 bit of
|
||||
| `a'. If `a' is zero, 32 is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static int8 countLeadingZeros32( bits32 a )
|
||||
{
|
||||
static const int8 countLeadingZerosHigh[] = {
|
||||
8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
int8 shiftCount;
|
||||
|
||||
shiftCount = 0;
|
||||
if ( a < 0x10000 ) {
|
||||
shiftCount += 16;
|
||||
a <<= 16;
|
||||
}
|
||||
if ( a < 0x1000000 ) {
|
||||
shiftCount += 8;
|
||||
a <<= 8;
|
||||
}
|
||||
shiftCount += countLeadingZerosHigh[ a>>24 ];
|
||||
return shiftCount;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the number of leading 0 bits before the most-significant 1 bit of
|
||||
| `a'. If `a' is zero, 64 is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static int8 countLeadingZeros64( bits64 a )
|
||||
{
|
||||
int8 shiftCount;
|
||||
|
||||
shiftCount = 0;
|
||||
if ( a < ( (bits64) 1 )<<32 ) {
|
||||
shiftCount += 32;
|
||||
}
|
||||
else {
|
||||
a >>= 32;
|
||||
}
|
||||
shiftCount += countLeadingZeros32( a );
|
||||
return shiftCount;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1'
|
||||
| is equal to the 128-bit value formed by concatenating `b0' and `b1'.
|
||||
| Otherwise, returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline flag eq128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 )
|
||||
{
|
||||
|
||||
return ( a0 == b0 ) && ( a1 == b1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less
|
||||
| than or equal to the 128-bit value formed by concatenating `b0' and `b1'.
|
||||
| Otherwise, returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline flag le128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 )
|
||||
{
|
||||
|
||||
return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 <= b1 ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less
|
||||
| than the 128-bit value formed by concatenating `b0' and `b1'. Otherwise,
|
||||
| returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline flag lt128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 )
|
||||
{
|
||||
|
||||
return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 < b1 ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is
|
||||
| not equal to the 128-bit value formed by concatenating `b0' and `b1'.
|
||||
| Otherwise, returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline flag ne128( bits64 a0, bits64 a1, bits64 b0, bits64 b1 )
|
||||
{
|
||||
|
||||
return ( a0 != b0 ) || ( a1 != b1 );
|
||||
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
| Changes the sign of the extended double-precision floating-point value 'a'.
|
||||
| The operation is performed according to the IEC/IEEE Standard for Binary
|
||||
| Floating-Point Arithmetic.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline floatx80 floatx80_chs(floatx80 reg)
|
||||
{
|
||||
reg.high ^= 0x8000;
|
||||
return reg;
|
||||
}
|
||||
|
||||
@ -1,476 +0,0 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
|
||||
Arithmetic Package, Release 2b.
|
||||
|
||||
Written by John R. Hauser. This work was made possible in part by the
|
||||
International Computer Science Institute, located at Suite 600, 1947 Center
|
||||
Street, Berkeley, California 94704. Funding was partially provided by the
|
||||
National Science Foundation under grant MIP-9311980. The original version
|
||||
of this code was written as part of a project to build a fixed-point vector
|
||||
processor in collaboration with the University of California at Berkeley,
|
||||
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
|
||||
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
|
||||
arithmetic/SoftFloat.html'.
|
||||
|
||||
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
|
||||
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
|
||||
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
|
||||
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
|
||||
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
|
||||
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
|
||||
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
|
||||
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
|
||||
|
||||
Derivative works are acceptable, even for commercial purposes, so long as
|
||||
(1) the source code for the derivative work includes prominent notice that
|
||||
the work is derivative, and (2) the source code includes prominent notice with
|
||||
these four paragraphs for those parts of this code that are retained.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
flag float32_is_nan( float32 a );
|
||||
flag float64_is_nan( float64 a );
|
||||
flag floatx80_is_nan( floatx80 a );
|
||||
floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b );
|
||||
flag float128_is_nan( float128 a );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Underflow tininess-detection mode, statically initialized to default value.
|
||||
| (The declaration in `softfloat.h' must match the `int8' type here.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
int8 float_detect_tininess = float_tininess_after_rounding;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Raises the exceptions specified by `flags'. Floating-point traps can be
|
||||
| defined here if desired. It is currently not possible for such a trap to
|
||||
| substitute a result value. If traps are not implemented, this routine
|
||||
| should be simply `float_exception_flags |= flags;'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
void float_raise( int8 flags )
|
||||
{
|
||||
|
||||
float_exception_flags |= flags;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Internal canonical NaN format.
|
||||
*----------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
flag sign;
|
||||
bits64 high, low;
|
||||
} commonNaNT;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The pattern for a default generated single-precision NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define float32_default_nan 0xFFFFFFFF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the single-precision floating-point value `a' is a NaN;
|
||||
| otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float32_is_nan( float32 a )
|
||||
{
|
||||
|
||||
return ( 0xFF000000 < (bits32) ( a<<1 ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the single-precision floating-point value `a' is a signaling
|
||||
| NaN; otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float32_is_signaling_nan( float32 a )
|
||||
{
|
||||
|
||||
return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the single-precision floating-point NaN
|
||||
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static commonNaNT float32ToCommonNaN( float32 a )
|
||||
{
|
||||
commonNaNT z;
|
||||
|
||||
if ( float32_is_signaling_nan( a ) ) float_raise( float_flag_invalid );
|
||||
z.sign = a>>31;
|
||||
z.low = 0;
|
||||
z.high = ( (bits64) a )<<41;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the canonical NaN `a' to the single-
|
||||
| precision floating-point format.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float32 commonNaNToFloat32( commonNaNT a )
|
||||
{
|
||||
|
||||
return ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | ( a.high>>41 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes two single-precision floating-point values `a' and `b', one of which
|
||||
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float32 propagateFloat32NaN( float32 a, float32 b )
|
||||
{
|
||||
flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
|
||||
|
||||
aIsNaN = float32_is_nan( a );
|
||||
aIsSignalingNaN = float32_is_signaling_nan( a );
|
||||
bIsNaN = float32_is_nan( b );
|
||||
bIsSignalingNaN = float32_is_signaling_nan( b );
|
||||
a |= 0x00400000;
|
||||
b |= 0x00400000;
|
||||
if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid );
|
||||
if ( aIsNaN ) {
|
||||
return ( aIsSignalingNaN & bIsNaN ) ? b : a;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The pattern for a default generated double-precision NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define float64_default_nan LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the double-precision floating-point value `a' is a NaN;
|
||||
| otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float64_is_nan( float64 a )
|
||||
{
|
||||
|
||||
return ( LIT64( 0xFFE0000000000000 ) < (bits64) ( a<<1 ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the double-precision floating-point value `a' is a signaling
|
||||
| NaN; otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float64_is_signaling_nan( float64 a )
|
||||
{
|
||||
|
||||
return
|
||||
( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
|
||||
&& ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the double-precision floating-point NaN
|
||||
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static commonNaNT float64ToCommonNaN( float64 a )
|
||||
{
|
||||
commonNaNT z;
|
||||
|
||||
if ( float64_is_signaling_nan( a ) ) float_raise( float_flag_invalid );
|
||||
z.sign = a>>63;
|
||||
z.low = 0;
|
||||
z.high = a<<12;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the canonical NaN `a' to the double-
|
||||
| precision floating-point format.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float64 commonNaNToFloat64( commonNaNT a )
|
||||
{
|
||||
|
||||
return
|
||||
( ( (bits64) a.sign )<<63 )
|
||||
| LIT64( 0x7FF8000000000000 )
|
||||
| ( a.high>>12 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes two double-precision floating-point values `a' and `b', one of which
|
||||
| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float64 propagateFloat64NaN( float64 a, float64 b )
|
||||
{
|
||||
flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
|
||||
|
||||
aIsNaN = float64_is_nan( a );
|
||||
aIsSignalingNaN = float64_is_signaling_nan( a );
|
||||
bIsNaN = float64_is_nan( b );
|
||||
bIsSignalingNaN = float64_is_signaling_nan( b );
|
||||
a |= LIT64( 0x0008000000000000 );
|
||||
b |= LIT64( 0x0008000000000000 );
|
||||
if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid );
|
||||
if ( aIsNaN ) {
|
||||
return ( aIsSignalingNaN & bIsNaN ) ? b : a;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef FLOATX80
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The pattern for a default generated extended double-precision NaN. The
|
||||
| `high' and `low' values hold the most- and least-significant bits,
|
||||
| respectively.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define floatx80_default_nan_high 0xFFFF
|
||||
#define floatx80_default_nan_low LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the extended double-precision floating-point value `a' is a
|
||||
| NaN; otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag floatx80_is_nan( floatx80 a )
|
||||
{
|
||||
|
||||
return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the extended double-precision floating-point value `a' is a
|
||||
| signaling NaN; otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag floatx80_is_signaling_nan( floatx80 a )
|
||||
{
|
||||
bits64 aLow;
|
||||
|
||||
aLow = a.low & ~ LIT64( 0x4000000000000000 );
|
||||
return
|
||||
( ( a.high & 0x7FFF ) == 0x7FFF )
|
||||
&& (bits64) ( aLow<<1 )
|
||||
&& ( a.low == aLow );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the extended double-precision floating-
|
||||
| point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the
|
||||
| invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static commonNaNT floatx80ToCommonNaN( floatx80 a )
|
||||
{
|
||||
commonNaNT z;
|
||||
|
||||
if ( floatx80_is_signaling_nan( a ) ) float_raise( float_flag_invalid );
|
||||
z.sign = a.high>>15;
|
||||
z.low = 0;
|
||||
z.high = a.low<<1;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the canonical NaN `a' to the extended
|
||||
| double-precision floating-point format.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static floatx80 commonNaNToFloatx80( commonNaNT a )
|
||||
{
|
||||
floatx80 z;
|
||||
|
||||
z.low = LIT64( 0xC000000000000000 ) | ( a.high>>1 );
|
||||
z.high = ( ( (bits16) a.sign )<<15 ) | 0x7FFF;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes two extended double-precision floating-point values `a' and `b', one
|
||||
| of which is a NaN, and returns the appropriate NaN result. If either `a' or
|
||||
| `b' is a signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b )
|
||||
{
|
||||
flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
|
||||
|
||||
aIsNaN = floatx80_is_nan( a );
|
||||
aIsSignalingNaN = floatx80_is_signaling_nan( a );
|
||||
bIsNaN = floatx80_is_nan( b );
|
||||
bIsSignalingNaN = floatx80_is_signaling_nan( b );
|
||||
a.low |= LIT64( 0xC000000000000000 );
|
||||
b.low |= LIT64( 0xC000000000000000 );
|
||||
if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid );
|
||||
if ( aIsNaN ) {
|
||||
return ( aIsSignalingNaN & bIsNaN ) ? b : a;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define EXP_BIAS 0x3FFF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the fraction bits of the extended double-precision floating-point
|
||||
| value `a'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline bits64 extractFloatx80Frac( floatx80 a )
|
||||
{
|
||||
|
||||
return a.low;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the exponent bits of the extended double-precision floating-point
|
||||
| value `a'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline int32 extractFloatx80Exp( floatx80 a )
|
||||
{
|
||||
|
||||
return a.high & 0x7FFF;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the sign bit of the extended double-precision floating-point value
|
||||
| `a'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline flag extractFloatx80Sign( floatx80 a )
|
||||
{
|
||||
|
||||
return a.high>>15;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FLOAT128
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The pattern for a default generated quadruple-precision NaN. The `high' and
|
||||
| `low' values hold the most- and least-significant bits, respectively.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define float128_default_nan_high LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
#define float128_default_nan_low LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the quadruple-precision floating-point value `a' is a NaN;
|
||||
| otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float128_is_nan( float128 a )
|
||||
{
|
||||
|
||||
return
|
||||
( LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) )
|
||||
&& ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns 1 if the quadruple-precision floating-point value `a' is a
|
||||
| signaling NaN; otherwise returns 0.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
flag float128_is_signaling_nan( float128 a )
|
||||
{
|
||||
|
||||
return
|
||||
( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
|
||||
&& ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the quadruple-precision floating-point NaN
|
||||
| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static commonNaNT float128ToCommonNaN( float128 a )
|
||||
{
|
||||
commonNaNT z;
|
||||
|
||||
if ( float128_is_signaling_nan( a ) ) float_raise( float_flag_invalid );
|
||||
z.sign = a.high>>63;
|
||||
shortShift128Left( a.high, a.low, 16, &z.high, &z.low );
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the result of converting the canonical NaN `a' to the quadruple-
|
||||
| precision floating-point format.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float128 commonNaNToFloat128( commonNaNT a )
|
||||
{
|
||||
float128 z;
|
||||
|
||||
shift128Right( a.high, a.low, 16, &z.high, &z.low );
|
||||
z.high |= ( ( (bits64) a.sign )<<63 ) | LIT64( 0x7FFF800000000000 );
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes two quadruple-precision floating-point values `a' and `b', one of
|
||||
| which is a NaN, and returns the appropriate NaN result. If either `a' or
|
||||
| `b' is a signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static float128 propagateFloat128NaN( float128 a, float128 b )
|
||||
{
|
||||
flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
|
||||
|
||||
aIsNaN = float128_is_nan( a );
|
||||
aIsSignalingNaN = float128_is_signaling_nan( a );
|
||||
bIsNaN = float128_is_nan( b );
|
||||
bIsSignalingNaN = float128_is_signaling_nan( b );
|
||||
a.high |= LIT64( 0x0000800000000000 );
|
||||
b.high |= LIT64( 0x0000800000000000 );
|
||||
if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid );
|
||||
if ( aIsNaN ) {
|
||||
return ( aIsSignalingNaN & bIsNaN ) ? b : a;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,460 +0,0 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
|
||||
Package, Release 2b.
|
||||
|
||||
Written by John R. Hauser. This work was made possible in part by the
|
||||
International Computer Science Institute, located at Suite 600, 1947 Center
|
||||
Street, Berkeley, California 94704. Funding was partially provided by the
|
||||
National Science Foundation under grant MIP-9311980. The original version
|
||||
of this code was written as part of a project to build a fixed-point vector
|
||||
processor in collaboration with the University of California at Berkeley,
|
||||
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
|
||||
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
|
||||
arithmetic/SoftFloat.html'.
|
||||
|
||||
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
|
||||
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
|
||||
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
|
||||
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
|
||||
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
|
||||
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
|
||||
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
|
||||
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
|
||||
|
||||
Derivative works are acceptable, even for commercial purposes, so long as
|
||||
(1) the source code for the derivative work includes prominent notice that
|
||||
the work is derivative, and (2) the source code includes prominent notice with
|
||||
these four paragraphs for those parts of this code that are retained.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The macro `FLOATX80' must be defined to enable the extended double-precision
|
||||
| floating-point format `floatx80'. If this macro is not defined, the
|
||||
| `floatx80' type will not be defined, and none of the functions that either
|
||||
| input or output the `floatx80' type will be defined. The same applies to
|
||||
| the `FLOAT128' macro and the quadruple-precision format `float128'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define FLOATX80
|
||||
#define FLOAT128
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE floating-point types.
|
||||
*----------------------------------------------------------------------------*/
|
||||
typedef bits32 float32;
|
||||
typedef bits64 float64;
|
||||
#ifdef FLOATX80
|
||||
typedef struct {
|
||||
bits16 high;
|
||||
bits64 low;
|
||||
} floatx80;
|
||||
#endif
|
||||
#ifdef FLOAT128
|
||||
typedef struct {
|
||||
bits64 high, low;
|
||||
} float128;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Primitive arithmetic functions, including multi-word arithmetic, and
|
||||
| division and square root approximations. (Can be specialized to target if
|
||||
| desired.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
#include "softfloat-macros"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE floating-point underflow tininess-detection mode.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern int8 float_detect_tininess;
|
||||
enum {
|
||||
float_tininess_after_rounding = 0,
|
||||
float_tininess_before_rounding = 1
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE floating-point rounding mode.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern int8 float_rounding_mode;
|
||||
enum {
|
||||
float_round_nearest_even = 0,
|
||||
float_round_to_zero = 1,
|
||||
float_round_down = 2,
|
||||
float_round_up = 3
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE floating-point exception flags.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern int8 float_exception_flags;
|
||||
enum {
|
||||
float_flag_invalid = 0x01, float_flag_denormal = 0x02, float_flag_divbyzero = 0x04, float_flag_overflow = 0x08,
|
||||
float_flag_underflow = 0x10, float_flag_inexact = 0x20
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Routine to raise any or all of the software IEC/IEEE floating-point
|
||||
| exception flags.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void float_raise( int8 );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE integer-to-floating-point conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
float32 int32_to_float32( int32 );
|
||||
float64 int32_to_float64( int32 );
|
||||
#ifdef FLOATX80
|
||||
floatx80 int32_to_floatx80( int32 );
|
||||
#endif
|
||||
#ifdef FLOAT128
|
||||
float128 int32_to_float128( int32 );
|
||||
#endif
|
||||
float32 int64_to_float32( int64 );
|
||||
float64 int64_to_float64( int64 );
|
||||
#ifdef FLOATX80
|
||||
floatx80 int64_to_floatx80( int64 );
|
||||
#endif
|
||||
#ifdef FLOAT128
|
||||
float128 int64_to_float128( int64 );
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE single-precision conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
int32 float32_to_int32( float32 );
|
||||
int32 float32_to_int32_round_to_zero( float32 );
|
||||
int64 float32_to_int64( float32 );
|
||||
int64 float32_to_int64_round_to_zero( float32 );
|
||||
float64 float32_to_float64( float32 );
|
||||
#ifdef FLOATX80
|
||||
floatx80 float32_to_floatx80( float32 );
|
||||
#endif
|
||||
#ifdef FLOAT128
|
||||
float128 float32_to_float128( float32 );
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE single-precision operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
float32 float32_round_to_int( float32 );
|
||||
float32 float32_add( float32, float32 );
|
||||
float32 float32_sub( float32, float32 );
|
||||
float32 float32_mul( float32, float32 );
|
||||
float32 float32_div( float32, float32 );
|
||||
float32 float32_rem( float32, float32 );
|
||||
float32 float32_sqrt( float32 );
|
||||
flag float32_eq( float32, float32 );
|
||||
flag float32_le( float32, float32 );
|
||||
flag float32_lt( float32, float32 );
|
||||
flag float32_eq_signaling( float32, float32 );
|
||||
flag float32_le_quiet( float32, float32 );
|
||||
flag float32_lt_quiet( float32, float32 );
|
||||
flag float32_is_signaling_nan( float32 );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE double-precision conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
int32 float64_to_int32( float64 );
|
||||
int32 float64_to_int32_round_to_zero( float64 );
|
||||
int64 float64_to_int64( float64 );
|
||||
int64 float64_to_int64_round_to_zero( float64 );
|
||||
float32 float64_to_float32( float64 );
|
||||
#ifdef FLOATX80
|
||||
floatx80 float64_to_floatx80( float64 );
|
||||
#endif
|
||||
#ifdef FLOAT128
|
||||
float128 float64_to_float128( float64 );
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE double-precision operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
float64 float64_round_to_int( float64 );
|
||||
float64 float64_add( float64, float64 );
|
||||
float64 float64_sub( float64, float64 );
|
||||
float64 float64_mul( float64, float64 );
|
||||
float64 float64_div( float64, float64 );
|
||||
float64 float64_rem( float64, float64 );
|
||||
float64 float64_sqrt( float64 );
|
||||
flag float64_eq( float64, float64 );
|
||||
flag float64_le( float64, float64 );
|
||||
flag float64_lt( float64, float64 );
|
||||
flag float64_eq_signaling( float64, float64 );
|
||||
flag float64_le_quiet( float64, float64 );
|
||||
flag float64_lt_quiet( float64, float64 );
|
||||
flag float64_is_signaling_nan( float64 );
|
||||
|
||||
#ifdef FLOATX80
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE extended double-precision conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
int32 floatx80_to_int32( floatx80 );
|
||||
int32 floatx80_to_int32_round_to_zero( floatx80 );
|
||||
int64 floatx80_to_int64( floatx80 );
|
||||
int64 floatx80_to_int64_round_to_zero( floatx80 );
|
||||
float32 floatx80_to_float32( floatx80 );
|
||||
float64 floatx80_to_float64( floatx80 );
|
||||
#ifdef FLOAT128
|
||||
float128 floatx80_to_float128( floatx80 );
|
||||
#endif
|
||||
floatx80 floatx80_scale(floatx80 a, floatx80 b);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Packs the sign `zSign', exponent `zExp', and significand `zSig' into an
|
||||
| extended double-precision floating-point value, returning the result.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline floatx80 packFloatx80( flag zSign, int32 zExp, bits64 zSig )
|
||||
{
|
||||
floatx80 z;
|
||||
|
||||
z.low = zSig;
|
||||
z.high = ( ( (bits16) zSign )<<15 ) + zExp;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE extended double-precision rounding precision. Valid
|
||||
| values are 32, 64, and 80.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern int8 floatx80_rounding_precision;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE extended double-precision operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
floatx80 floatx80_round_to_int( floatx80 );
|
||||
floatx80 floatx80_add( floatx80, floatx80 );
|
||||
floatx80 floatx80_sub( floatx80, floatx80 );
|
||||
floatx80 floatx80_mul( floatx80, floatx80 );
|
||||
floatx80 floatx80_div( floatx80, floatx80 );
|
||||
floatx80 floatx80_rem( floatx80, floatx80 );
|
||||
floatx80 floatx80_sqrt( floatx80 );
|
||||
flag floatx80_eq( floatx80, floatx80 );
|
||||
flag floatx80_le( floatx80, floatx80 );
|
||||
flag floatx80_lt( floatx80, floatx80 );
|
||||
flag floatx80_eq_signaling( floatx80, floatx80 );
|
||||
flag floatx80_le_quiet( floatx80, floatx80 );
|
||||
flag floatx80_lt_quiet( floatx80, floatx80 );
|
||||
flag floatx80_is_signaling_nan( floatx80 );
|
||||
|
||||
/* int floatx80_fsin(floatx80 &a);
|
||||
int floatx80_fcos(floatx80 &a);
|
||||
int floatx80_ftan(floatx80 &a); */
|
||||
|
||||
floatx80 floatx80_flognp1(floatx80 a);
|
||||
floatx80 floatx80_flogn(floatx80 a);
|
||||
floatx80 floatx80_flog2(floatx80 a);
|
||||
floatx80 floatx80_flog10(floatx80 a);
|
||||
|
||||
// roundAndPackFloatx80 used to be in softfloat-round-pack, is now in softfloat.c
|
||||
floatx80 roundAndPackFloatx80(int8 roundingPrecision, flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FLOAT128
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE quadruple-precision conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
int32 float128_to_int32( float128 );
|
||||
int32 float128_to_int32_round_to_zero( float128 );
|
||||
int64 float128_to_int64( float128 );
|
||||
int64 float128_to_int64_round_to_zero( float128 );
|
||||
float32 float128_to_float32( float128 );
|
||||
float64 float128_to_float64( float128 );
|
||||
#ifdef FLOATX80
|
||||
floatx80 float128_to_floatx80( float128 );
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software IEC/IEEE quadruple-precision operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
float128 float128_round_to_int( float128 );
|
||||
float128 float128_add( float128, float128 );
|
||||
float128 float128_sub( float128, float128 );
|
||||
float128 float128_mul( float128, float128 );
|
||||
float128 float128_div( float128, float128 );
|
||||
float128 float128_rem( float128, float128 );
|
||||
float128 float128_sqrt( float128 );
|
||||
flag float128_eq( float128, float128 );
|
||||
flag float128_le( float128, float128 );
|
||||
flag float128_lt( float128, float128 );
|
||||
flag float128_eq_signaling( float128, float128 );
|
||||
flag float128_le_quiet( float128, float128 );
|
||||
flag float128_lt_quiet( float128, float128 );
|
||||
flag float128_is_signaling_nan( float128 );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Packs the sign `zSign', the exponent `zExp', and the significand formed
|
||||
| by the concatenation of `zSig0' and `zSig1' into a quadruple-precision
|
||||
| floating-point value, returning the result. After being shifted into the
|
||||
| proper positions, the three fields `zSign', `zExp', and `zSig0' are simply
|
||||
| added together to form the most significant 32 bits of the result. This
|
||||
| means that any integer portion of `zSig0' will be added into the exponent.
|
||||
| Since a properly normalized significand will have an integer portion equal
|
||||
| to 1, the `zExp' input should be 1 less than the desired result exponent
|
||||
| whenever `zSig0' and `zSig1' concatenated form a complete, normalized
|
||||
| significand.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline float128
|
||||
packFloat128( flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1 )
|
||||
{
|
||||
float128 z;
|
||||
|
||||
z.low = zSig1;
|
||||
z.high = ( ( (bits64) zSign )<<63 ) + ( ( (bits64) zExp )<<48 ) + zSig0;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
|
||||
| and extended significand formed by the concatenation of `zSig0', `zSig1',
|
||||
| and `zSig2', and returns the proper quadruple-precision floating-point value
|
||||
| corresponding to the abstract input. Ordinarily, the abstract value is
|
||||
| simply rounded and packed into the quadruple-precision format, with the
|
||||
| inexact exception raised if the abstract input cannot be represented
|
||||
| exactly. However, if the abstract value is too large, the overflow and
|
||||
| inexact exceptions are raised and an infinity or maximal finite value is
|
||||
| returned. If the abstract value is too small, the input value is rounded to
|
||||
| a subnormal number, and the underflow and inexact exceptions are raised if
|
||||
| the abstract input cannot be represented exactly as a subnormal quadruple-
|
||||
| precision floating-point number.
|
||||
| The input significand must be normalized or smaller. If the input
|
||||
| significand is not normalized, `zExp' must be 0; in that case, the result
|
||||
| returned is a subnormal number, and it must not require rounding. In the
|
||||
| usual case that the input significand is normalized, `zExp' must be 1 less
|
||||
| than the ``true'' floating-point exponent. The handling of underflow and
|
||||
| overflow follows the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline float128
|
||||
roundAndPackFloat128(
|
||||
flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1, bits64 zSig2 )
|
||||
{
|
||||
int8 roundingMode;
|
||||
flag roundNearestEven, increment, isTiny;
|
||||
|
||||
roundingMode = float_rounding_mode;
|
||||
roundNearestEven = ( roundingMode == float_round_nearest_even );
|
||||
increment = ( (sbits64) zSig2 < 0 );
|
||||
if ( ! roundNearestEven ) {
|
||||
if ( roundingMode == float_round_to_zero ) {
|
||||
increment = 0;
|
||||
}
|
||||
else {
|
||||
if ( zSign ) {
|
||||
increment = ( roundingMode == float_round_down ) && zSig2;
|
||||
}
|
||||
else {
|
||||
increment = ( roundingMode == float_round_up ) && zSig2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( 0x7FFD <= (bits32) zExp ) {
|
||||
if ( ( 0x7FFD < zExp )
|
||||
|| ( ( zExp == 0x7FFD )
|
||||
&& eq128(
|
||||
LIT64( 0x0001FFFFFFFFFFFF ),
|
||||
LIT64( 0xFFFFFFFFFFFFFFFF ),
|
||||
zSig0,
|
||||
zSig1
|
||||
)
|
||||
&& increment
|
||||
)
|
||||
) {
|
||||
float_raise( float_flag_overflow | float_flag_inexact );
|
||||
if ( ( roundingMode == float_round_to_zero )
|
||||
|| ( zSign && ( roundingMode == float_round_up ) )
|
||||
|| ( ! zSign && ( roundingMode == float_round_down ) )
|
||||
) {
|
||||
return
|
||||
packFloat128(
|
||||
zSign,
|
||||
0x7FFE,
|
||||
LIT64( 0x0000FFFFFFFFFFFF ),
|
||||
LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
);
|
||||
}
|
||||
return packFloat128( zSign, 0x7FFF, 0, 0 );
|
||||
}
|
||||
if ( zExp < 0 ) {
|
||||
isTiny =
|
||||
( float_detect_tininess == float_tininess_before_rounding )
|
||||
|| ( zExp < -1 )
|
||||
|| ! increment
|
||||
|| lt128(
|
||||
zSig0,
|
||||
zSig1,
|
||||
LIT64( 0x0001FFFFFFFFFFFF ),
|
||||
LIT64( 0xFFFFFFFFFFFFFFFF )
|
||||
);
|
||||
shift128ExtraRightJamming(
|
||||
zSig0, zSig1, zSig2, - zExp, &zSig0, &zSig1, &zSig2 );
|
||||
zExp = 0;
|
||||
if ( isTiny && zSig2 ) float_raise( float_flag_underflow );
|
||||
if ( roundNearestEven ) {
|
||||
increment = ( (sbits64) zSig2 < 0 );
|
||||
}
|
||||
else {
|
||||
if ( zSign ) {
|
||||
increment = ( roundingMode == float_round_down ) && zSig2;
|
||||
}
|
||||
else {
|
||||
increment = ( roundingMode == float_round_up ) && zSig2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( zSig2 ) float_exception_flags |= float_flag_inexact;
|
||||
if ( increment ) {
|
||||
add128( zSig0, zSig1, 0, 1, &zSig0, &zSig1 );
|
||||
zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven );
|
||||
}
|
||||
else {
|
||||
if ( ( zSig0 | zSig1 ) == 0 ) zExp = 0;
|
||||
}
|
||||
return packFloat128( zSign, zExp, zSig0, zSig1 );
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
|
||||
| and significand formed by the concatenation of `zSig0' and `zSig1', and
|
||||
| returns the proper quadruple-precision floating-point value corresponding
|
||||
| to the abstract input. This routine is just like `roundAndPackFloat128'
|
||||
| except that the input significand has fewer bits and does not have to be
|
||||
| normalized. In all cases, `zExp' must be 1 less than the ``true'' floating-
|
||||
| point exponent.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
static inline float128
|
||||
normalizeRoundAndPackFloat128(
|
||||
flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1 )
|
||||
{
|
||||
int8 shiftCount;
|
||||
bits64 zSig2;
|
||||
|
||||
if ( zSig0 == 0 ) {
|
||||
zSig0 = zSig1;
|
||||
zSig1 = 0;
|
||||
zExp -= 64;
|
||||
}
|
||||
shiftCount = countLeadingZeros64( zSig0 ) - 15;
|
||||
if ( 0 <= shiftCount ) {
|
||||
zSig2 = 0;
|
||||
shortShift128Left( zSig0, zSig1, shiftCount, &zSig0, &zSig1 );
|
||||
}
|
||||
else {
|
||||
shift128ExtraRightJamming(
|
||||
zSig0, zSig1, 0, - shiftCount, &zSig0, &zSig1, &zSig2 );
|
||||
}
|
||||
zExp -= shiftCount;
|
||||
return roundAndPackFloat128( zSign, zExp, zSig0, zSig1, zSig2 );
|
||||
|
||||
}
|
||||
#endif
|
||||
@ -1,39 +0,0 @@
|
||||
// custom musashi config for vamos machine
|
||||
#ifndef MYCONF_H
|
||||
#define MYCONF_H
|
||||
|
||||
#define OPT_OFF 0
|
||||
#define OPT_ON 1
|
||||
#define OPT_SPECIFY_HANDLER 2
|
||||
|
||||
#define M68K_EMULATE_010 OPT_ON
|
||||
#define M68K_EMULATE_EC020 OPT_ON
|
||||
#define M68K_EMULATE_020 OPT_ON
|
||||
#define M68K_EMULATE_030 OPT_ON
|
||||
#define M68K_EMULATE_040 OPT_ON
|
||||
|
||||
#define M68K_SEPARATE_READS OPT_OFF
|
||||
#define M68K_SIMULATE_PD_WRITES OPT_OFF
|
||||
#define M68K_EMULATE_INT_ACK OPT_OFF
|
||||
#define M68K_EMULATE_BKPT_ACK OPT_OFF
|
||||
#define M68K_EMULATE_TRACE OPT_OFF
|
||||
#define M68K_EMULATE_RESET OPT_ON
|
||||
#define M68K_CMPILD_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_RTE_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_TAS_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_ILLG_HAS_CALLBACK OPT_OFF
|
||||
#define M68K_EMULATE_FC OPT_OFF
|
||||
#define M68K_MONITOR_PC OPT_OFF
|
||||
#define M68K_INSTRUCTION_HOOK OPT_ON
|
||||
#define M68K_EMULATE_PREFETCH OPT_OFF
|
||||
#define M68K_EMULATE_ADDRESS_ERROR OPT_OFF
|
||||
#define M68K_ALINE_HOOK OPT_ON
|
||||
|
||||
#define M68K_LOG_ENABLE OPT_OFF
|
||||
#define M68K_LOG_1010_1111 OPT_OFF
|
||||
|
||||
#define M68K_EMULATE_PMMU OPT_ON
|
||||
|
||||
#define M68K_USE_64_BIT OPT_ON
|
||||
|
||||
#endif
|
||||
@ -1,207 +0,0 @@
|
||||
# cython binding for musashi
|
||||
|
||||
from libc.stdlib cimport malloc, free
|
||||
|
||||
# m68k.h
|
||||
cdef extern from "m68k.h":
|
||||
ctypedef enum m68k_register_t:
|
||||
M68K_REG_D0, M68K_REG_D1, M68K_REG_D2, M68K_REG_D3,
|
||||
M68K_REG_D4, M68K_REG_D5, M68K_REG_D6, M68K_REG_D7,
|
||||
M68K_REG_A0, M68K_REG_A1, M68K_REG_A2, M68K_REG_A3,
|
||||
M68K_REG_A4, M68K_REG_A5, M68K_REG_A6, M68K_REG_A7,
|
||||
M68K_REG_PC, M68K_REG_SR,
|
||||
M68K_REG_SP, M68K_REG_USP, M68K_REG_ISP, M68K_REG_MSP,
|
||||
M68K_REG_SFC, M68K_REG_DFC,
|
||||
M68K_REG_VBR,
|
||||
M68K_REG_CACR, M68K_REG_CAAR,
|
||||
M68K_REG_PREF_ADDR, M68K_REG_PREF_DATA,
|
||||
M68K_REG_PPC, M68K_REG_IR,
|
||||
M68K_REG_CPU_TYPE
|
||||
|
||||
void m68k_set_cpu_type(unsigned int cpu_type)
|
||||
void m68k_init()
|
||||
void m68k_pulse_reset()
|
||||
int m68k_execute(int num_cycles)
|
||||
void m68k_end_timeslice()
|
||||
|
||||
unsigned int m68k_get_reg(void* context, m68k_register_t reg)
|
||||
void m68k_set_reg(m68k_register_t reg, unsigned int value)
|
||||
|
||||
void m68k_set_pc_changed_callback(void (*callback)(unsigned int new_pc))
|
||||
void m68k_set_reset_instr_callback(void (*callback)())
|
||||
void m68k_set_illg_instr_callback(int (*callback)(int opcode))
|
||||
void m68k_set_instr_hook_callback(void (*callback)(unsigned int pc))
|
||||
|
||||
unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type)
|
||||
unsigned int m68k_disassemble_raw(char* str_buff, unsigned int pc, const unsigned char* opdata, const unsigned char* argdata, unsigned int cpu_type)
|
||||
|
||||
unsigned int m68k_context_size()
|
||||
unsigned int m68k_get_context(void* dst)
|
||||
void m68k_set_context(void* dst)
|
||||
|
||||
# wrapper
|
||||
cdef object pc_changed_func
|
||||
cdef void pc_changed_func_wrapper(unsigned int new_pc) noexcept:
|
||||
pc_changed_func(new_pc)
|
||||
|
||||
cdef object reset_instr_func
|
||||
cdef void reset_instr_func_wrapper() noexcept:
|
||||
reset_instr_func()
|
||||
|
||||
cdef object instr_hook_func
|
||||
cdef void instr_hook_func_wrapper(unsigned int pc) noexcept:
|
||||
instr_hook_func()
|
||||
|
||||
# public CPUContext
|
||||
cdef class CPUContext:
|
||||
cdef void *data
|
||||
cdef unsigned int size
|
||||
|
||||
def __cinit__(self, unsigned int size):
|
||||
self.data = malloc(size)
|
||||
if self.data == NULL:
|
||||
raise MemoryError()
|
||||
self.size = size
|
||||
|
||||
cdef void *get_data(self):
|
||||
return self.data
|
||||
|
||||
def r_reg(self, int reg):
|
||||
return m68k_get_reg(self.data, <m68k_register_t>reg)
|
||||
|
||||
def r_pc(self):
|
||||
return m68k_get_reg(self.data, M68K_REG_PC)
|
||||
|
||||
def r_sp(self):
|
||||
return m68k_get_reg(self.data, M68K_REG_SP)
|
||||
|
||||
def r_usp(self):
|
||||
return m68k_get_reg(self.data, M68K_REG_USP)
|
||||
|
||||
def r_isp(self):
|
||||
return m68k_get_reg(self.data, M68K_REG_ISP)
|
||||
|
||||
def r_msp(self):
|
||||
return m68k_get_reg(self.data, M68K_REG_MSP)
|
||||
|
||||
def __dealloc__(self):
|
||||
free(self.data)
|
||||
|
||||
# public CPU class
|
||||
cdef class CPU:
|
||||
cdef unsigned int cpu_type
|
||||
|
||||
def __cinit__(self, cpu_type):
|
||||
m68k_set_cpu_type(cpu_type)
|
||||
m68k_init()
|
||||
self.cpu_type = cpu_type
|
||||
|
||||
def cleanup(self):
|
||||
self.set_pc_changed_callback(None)
|
||||
self.set_reset_instr_callback(None)
|
||||
self.set_instr_hook_callback(None)
|
||||
|
||||
cdef unsigned int r_reg_internal(self, m68k_register_t reg):
|
||||
return m68k_get_reg(NULL, reg)
|
||||
|
||||
cdef void w_reg_internal(self, m68k_register_t reg, unsigned int v):
|
||||
m68k_set_reg(reg, v)
|
||||
|
||||
def w_reg(self, reg, val):
|
||||
self.w_reg_internal(reg,val)
|
||||
|
||||
def r_reg(self,reg):
|
||||
return self.r_reg_internal(reg)
|
||||
|
||||
def ws_reg(self, m68k_register_t reg, int val):
|
||||
m68k_set_reg(reg, <unsigned int>(val))
|
||||
|
||||
def rs_reg(self, m68k_register_t reg):
|
||||
return <int>m68k_get_reg(NULL, reg)
|
||||
|
||||
def w_pc(self, val):
|
||||
self.w_reg_internal(M68K_REG_PC,val)
|
||||
|
||||
def r_pc(self):
|
||||
return self.r_reg_internal(M68K_REG_PC)
|
||||
|
||||
def w_sr(self, val):
|
||||
self.w_reg_internal(M68K_REG_SR,val)
|
||||
|
||||
def r_sr(self):
|
||||
return self.r_reg_internal(M68K_REG_SR)
|
||||
|
||||
def w_usp(self, val):
|
||||
self.w_reg_internal(M68K_REG_USP,val)
|
||||
|
||||
def r_usp(self):
|
||||
return self.r_reg_internal(M68K_REG_USP)
|
||||
|
||||
def w_isp(self, val):
|
||||
self.w_reg_internal(M68K_REG_ISP,val)
|
||||
|
||||
def r_isp(self):
|
||||
return self.r_reg_internal(M68K_REG_ISP)
|
||||
|
||||
def w_msp(self, val):
|
||||
self.w_reg_internal(M68K_REG_MSP,val)
|
||||
|
||||
def r_msp(self):
|
||||
return self.r_reg_internal(M68K_REG_MSP)
|
||||
|
||||
def pulse_reset(self):
|
||||
m68k_pulse_reset()
|
||||
|
||||
def execute(self, num_cycles):
|
||||
cdef int cycles = m68k_execute(num_cycles)
|
||||
check_mem_exc()
|
||||
return cycles
|
||||
|
||||
def end(self):
|
||||
m68k_end_timeslice()
|
||||
|
||||
def set_pc_changed_callback(self, py_func):
|
||||
global pc_changed_func
|
||||
pc_changed_func = py_func
|
||||
if py_func is None:
|
||||
m68k_set_pc_changed_callback(NULL)
|
||||
else:
|
||||
m68k_set_pc_changed_callback(pc_changed_func_wrapper)
|
||||
|
||||
def set_reset_instr_callback(self, py_func):
|
||||
global reset_instr_func
|
||||
reset_instr_func = py_func
|
||||
if py_func is None:
|
||||
m68k_set_reset_instr_callback(NULL)
|
||||
else:
|
||||
m68k_set_reset_instr_callback(reset_instr_func_wrapper)
|
||||
|
||||
def set_instr_hook_callback(self, py_func):
|
||||
global instr_hook_func
|
||||
instr_hook_func = py_func
|
||||
if py_func is None:
|
||||
m68k_set_instr_hook_callback(NULL)
|
||||
else:
|
||||
m68k_set_instr_hook_callback(instr_hook_func_wrapper)
|
||||
|
||||
def disassemble(self, unsigned int pc):
|
||||
cdef char line[80]
|
||||
cdef unsigned int size
|
||||
size = m68k_disassemble(line, pc, self.cpu_type)
|
||||
return (size, line.decode('latin-1'))
|
||||
|
||||
def disassemble_raw(self, unsigned int pc, const unsigned char[::1] raw_mem):
|
||||
cdef char line[80]
|
||||
cdef unsigned int size
|
||||
size = m68k_disassemble_raw(line, pc, &raw_mem[0], NULL, self.cpu_type)
|
||||
return (size, line.decode('latin-1'))
|
||||
|
||||
def get_cpu_context(self):
|
||||
cdef unsigned int size = m68k_context_size()
|
||||
cdef CPUContext ctx = CPUContext(size)
|
||||
cdef void *data = ctx.get_data()
|
||||
m68k_get_context(data)
|
||||
return ctx
|
||||
|
||||
def set_cpu_context(self, CPUContext ctx):
|
||||
m68k_set_context(ctx.get_data())
|
||||
@ -1,441 +0,0 @@
|
||||
# mem.h
|
||||
cdef extern from "mem.h":
|
||||
ctypedef unsigned int uint
|
||||
ctypedef uint (*read_func_t)(uint addr, void *ctx)
|
||||
ctypedef void (*write_func_t)(uint addr, uint value, void *ctx)
|
||||
ctypedef void (*invalid_func_t)(int mode, int width, uint addr, void *ctx)
|
||||
ctypedef void (*trace_func_t)(int mode, int width, uint addr, uint val, void *ctx)
|
||||
|
||||
int mem_init(uint ram_size_kib)
|
||||
void mem_free()
|
||||
|
||||
void mem_set_invalid_func(invalid_func_t func, void *ctx)
|
||||
void mem_set_trace_mode(int on)
|
||||
void mem_set_trace_func(trace_func_t func, void *ctx)
|
||||
|
||||
uint mem_reserve_special_range(uint num_pages)
|
||||
void mem_set_special_range_read_func(uint page_addr, uint width, read_func_t func, void *ctx)
|
||||
void mem_set_special_range_write_func(uint page_addr, uint width, write_func_t func, void *ctx)
|
||||
|
||||
unsigned int m68k_read_memory_8(unsigned int address)
|
||||
unsigned int m68k_read_memory_16(unsigned int address)
|
||||
unsigned int m68k_read_memory_32(unsigned int address)
|
||||
|
||||
void m68k_write_memory_8(unsigned int address, unsigned int value)
|
||||
void m68k_write_memory_16(unsigned int address, unsigned int value)
|
||||
void m68k_write_memory_32(unsigned int address, unsigned int value)
|
||||
|
||||
unsigned char *mem_raw_ptr()
|
||||
uint mem_raw_size()
|
||||
|
||||
int mem_ram_r8(uint addr, uint *val)
|
||||
int mem_ram_r16(uint addr, uint *val)
|
||||
int mem_ram_r32(uint addr, uint *val)
|
||||
|
||||
int mem_ram_w8(uint addr, uint val)
|
||||
int mem_ram_w16(uint addr, uint val)
|
||||
int mem_ram_w32(uint addr, uint val)
|
||||
|
||||
# string.h
|
||||
from libc.string cimport memcpy, memset, strlen, strcpy
|
||||
from libc.stdlib cimport malloc, free
|
||||
import sys
|
||||
|
||||
# wrapper functions
|
||||
cdef object mem_callback_exc
|
||||
cdef check_mem_exc():
|
||||
# raise a mem exception
|
||||
global mem_callback_exc
|
||||
if mem_callback_exc:
|
||||
exc = mem_callback_exc
|
||||
mem_callback_exc = None
|
||||
raise exc[0], exc[1], exc[2]
|
||||
|
||||
cdef void trace_func_wrapper(int mode, int width, uint addr, uint val, void *ctx) noexcept:
|
||||
cdef object py_func = <object>ctx
|
||||
try:
|
||||
py_func(chr(mode), width, addr, val)
|
||||
except:
|
||||
global mem_callback_exc
|
||||
mem_callback_exc = sys.exc_info()
|
||||
m68k_end_timeslice()
|
||||
|
||||
cdef void invalid_func_wrapper(int mode, int width, uint addr, void *ctx) noexcept:
|
||||
cdef object py_func = <object>ctx
|
||||
try:
|
||||
py_func(chr(mode), width, addr)
|
||||
except:
|
||||
global mem_callback_exc
|
||||
mem_callback_exc = sys.exc_info()
|
||||
m68k_end_timeslice()
|
||||
|
||||
cdef uint special_read_func_wrapper(uint addr, void *ctx) noexcept:
|
||||
cdef object py_func = <object>ctx
|
||||
try:
|
||||
return py_func(addr)
|
||||
except:
|
||||
global mem_callback_exc
|
||||
mem_callback_exc = sys.exc_info()
|
||||
m68k_end_timeslice()
|
||||
return 0
|
||||
|
||||
cdef void special_write_func_wrapper(uint addr, uint value, void *ctx) noexcept:
|
||||
cdef object py_func = <object>ctx
|
||||
try:
|
||||
py_func(addr, value)
|
||||
except:
|
||||
global mem_callback_exc
|
||||
mem_callback_exc = sys.exc_info()
|
||||
m68k_end_timeslice()
|
||||
|
||||
class MemoryError(Exception):
|
||||
def __init__(self, addr, op, size=None):
|
||||
self.addr = addr
|
||||
self.op = op
|
||||
self.size = size
|
||||
|
||||
def __repr__(self):
|
||||
return "MemoryError(%06x, %s, %s)" % (self.addr, self.op, self.size)
|
||||
|
||||
# public Memory class
|
||||
cdef class Memory:
|
||||
cdef uint ram_size_kib
|
||||
cdef uint ram_bytes
|
||||
cdef unsigned char *ram_ptr
|
||||
# keep python refs of callback funcs otherwise wrapper might loose the object
|
||||
cdef set special_read_funcs
|
||||
cdef set special_write_funcs
|
||||
cdef object trace_func
|
||||
cdef object invalid_func
|
||||
|
||||
def __cinit__(self, ram_size_kib):
|
||||
mem_init(ram_size_kib)
|
||||
self.ram_size_kib = ram_size_kib
|
||||
self.ram_bytes = ram_size_kib * 1024
|
||||
self.ram_ptr = mem_raw_ptr()
|
||||
self.special_read_funcs = set()
|
||||
self.special_write_funcs = set()
|
||||
|
||||
def cleanup(self):
|
||||
self.set_trace_func(None)
|
||||
self.set_invalid_func(None)
|
||||
self.special_read_funcs.clear()
|
||||
self.special_write_funcs.clear()
|
||||
mem_free()
|
||||
|
||||
def get_ram_size_kib(self):
|
||||
return self.ram_size_kib
|
||||
|
||||
def get_ram_size_bytes(self):
|
||||
return self.ram_bytes
|
||||
|
||||
def reserve_special_range(self,num_pages=1):
|
||||
return mem_reserve_special_range(num_pages)
|
||||
|
||||
cpdef set_special_range_read_func(self, uint page_addr, uint width, func):
|
||||
mem_set_special_range_read_func(page_addr, width, special_read_func_wrapper, <void *>func)
|
||||
# keep func ref
|
||||
self.special_read_funcs.add(func)
|
||||
|
||||
cpdef set_special_range_write_func(self,uint page_addr, uint width, func):
|
||||
mem_set_special_range_write_func(page_addr, width, special_write_func_wrapper, <void *>func)
|
||||
# keep func ref
|
||||
self.special_write_funcs.add(func)
|
||||
|
||||
def set_special_range_read_funcs(self, uint addr, uint num_pages=1, r8=None, r16=None, r32=None):
|
||||
for i in range(num_pages):
|
||||
if r8 != None:
|
||||
self.set_special_range_read_func(addr, 0, r8)
|
||||
if r16 != None:
|
||||
self.set_special_range_read_func(addr, 1, r16)
|
||||
if r32 != None:
|
||||
self.set_special_range_read_func(addr, 2, r32)
|
||||
addr += 0x10000
|
||||
|
||||
def set_special_range_write_funcs(self, uint addr, uint num_pages=1, w8=None, w16=None, w32=None):
|
||||
for i in range(num_pages):
|
||||
if w8 != None:
|
||||
self.set_special_range_write_func(addr, 0, w8)
|
||||
if w16 != None:
|
||||
self.set_special_range_write_func(addr, 1, w16)
|
||||
if w32 != None:
|
||||
self.set_special_range_write_func(addr, 2, w32)
|
||||
addr += 0x10000
|
||||
|
||||
def set_trace_mode(self,on):
|
||||
mem_set_trace_mode(on)
|
||||
|
||||
def set_trace_func(self,func):
|
||||
if func is None:
|
||||
mem_set_trace_func(NULL, NULL)
|
||||
else:
|
||||
mem_set_trace_func(trace_func_wrapper, <void *>func)
|
||||
# keep func ref
|
||||
self.trace_func = func
|
||||
|
||||
def set_invalid_func(self,func):
|
||||
if func is None:
|
||||
mem_set_invalid_func(NULL, NULL)
|
||||
else:
|
||||
mem_set_invalid_func(invalid_func_wrapper, <void *>func)
|
||||
# keep func ref
|
||||
self.invalid_func = func
|
||||
|
||||
def _raise_ram_error(self, addr, op, width):
|
||||
raise MemoryError(addr, op, width)
|
||||
|
||||
# CPU-like memory access (not RAM only!)
|
||||
cpdef cpu_r8(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_8(addr)
|
||||
check_mem_exc()
|
||||
return val
|
||||
cpdef cpu_r16(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_16(addr)
|
||||
check_mem_exc()
|
||||
return val
|
||||
cpdef cpu_r32(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_32(addr)
|
||||
check_mem_exc()
|
||||
return val
|
||||
cpdef cpu_w8(self, uint addr, uint value):
|
||||
if value > 0xff:
|
||||
raise OverflowError("value does not fit into byte")
|
||||
m68k_write_memory_8(addr, value)
|
||||
check_mem_exc()
|
||||
cpdef cpu_w16(self, uint addr, uint value):
|
||||
if value > 0xffff:
|
||||
raise OverflowError("value does not fit into word")
|
||||
m68k_write_memory_16(addr, value)
|
||||
check_mem_exc()
|
||||
cpdef cpu_w32(self, uint addr, uint value):
|
||||
m68k_write_memory_32(addr, value)
|
||||
check_mem_exc()
|
||||
|
||||
# CPU-like signed memory access (not RAM only!)
|
||||
cpdef cpu_r8s(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_8(addr)
|
||||
check_mem_exc()
|
||||
# sign extend
|
||||
if val & 0x80 == 0x80:
|
||||
val |= 0xffffff00
|
||||
return <int>(val)
|
||||
cpdef cpu_r16s(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_16(addr)
|
||||
check_mem_exc()
|
||||
# sign extend
|
||||
if val & 0x8000 == 0x8000:
|
||||
val |= 0xffff0000
|
||||
return <int>(val)
|
||||
cpdef cpu_r32s(self, uint addr):
|
||||
cdef uint val = m68k_read_memory_32(addr)
|
||||
check_mem_exc()
|
||||
return <int>(val)
|
||||
cpdef cpu_w8s(self, uint addr, int value):
|
||||
if value < -0x80 or value > 0x7f:
|
||||
raise OverflowError("value does not fit into byte")
|
||||
cdef uint val = <uint>value & 0xff
|
||||
m68k_write_memory_8(addr, val)
|
||||
check_mem_exc()
|
||||
cpdef cpu_w16s(self, uint addr, int value):
|
||||
if value < -0x8000 or value > 0x7fff:
|
||||
raise OverflowError("value does not fit into word")
|
||||
cdef uint val = <uint>value & 0xffff
|
||||
m68k_write_memory_16(addr, val)
|
||||
check_mem_exc()
|
||||
cpdef cpu_w32s(self, uint addr, int value):
|
||||
cdef uint val = <uint>(value)
|
||||
m68k_write_memory_32(addr, val)
|
||||
check_mem_exc()
|
||||
|
||||
# memory access (RAM only!)
|
||||
cpdef r8(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r8(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 0)
|
||||
return val
|
||||
cpdef r16(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r16(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 1)
|
||||
return val
|
||||
cpdef r32(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r32(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 2)
|
||||
return val
|
||||
cpdef w8(self, uint addr, uint value):
|
||||
if value > 0xff:
|
||||
raise OverflowError("value does not fit into byte")
|
||||
if mem_ram_w8(addr, value):
|
||||
self._raise_ram_error(addr, 'W', 0)
|
||||
cpdef w16(self, uint addr, uint value):
|
||||
if value > 0xffff:
|
||||
raise OverflowError("value does not fit into word")
|
||||
if mem_ram_w16(addr, value):
|
||||
self._raise_ram_error(addr, 'W', 1)
|
||||
cpdef w32(self, uint addr, uint value):
|
||||
if mem_ram_w32(addr, value):
|
||||
self._raise_ram_error(addr, 'W', 2)
|
||||
|
||||
# signed memory access (RAM only!)
|
||||
cpdef r8s(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r8(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 0)
|
||||
# sign extend
|
||||
if val & 0x80 == 0x80:
|
||||
val |= 0xffffff00
|
||||
return <int>(val)
|
||||
cpdef r16s(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r16(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 1)
|
||||
# sign extend
|
||||
if val & 0x8000 == 0x8000:
|
||||
val |= 0xffff0000
|
||||
return <int>(val)
|
||||
cpdef r32s(self, uint addr):
|
||||
cdef uint val
|
||||
if mem_ram_r32(addr, &val):
|
||||
self._raise_ram_error(addr, 'R', 2)
|
||||
return <int>(val)
|
||||
cpdef w8s(self, uint addr, int value):
|
||||
if value < -0x80 or value > 0x7f:
|
||||
raise OverflowError("value does not fit into byte")
|
||||
cdef uint val = <uint>value & 0xff
|
||||
if mem_ram_w8(addr, val):
|
||||
self._raise_ram_error(addr, 'W', 0)
|
||||
cpdef w16s(self, uint addr, int value):
|
||||
if value < -0x8000 or value > 0x7fff:
|
||||
raise OverflowError("value does not fit into word")
|
||||
cdef uint val = <uint>value & 0xffff
|
||||
if mem_ram_w16(addr, val):
|
||||
self._raise_ram_error(addr, 'W', 1)
|
||||
cpdef w32s(self, uint addr, int value):
|
||||
cdef uint val = <uint>(value)
|
||||
if mem_ram_w32(addr, val):
|
||||
self._raise_ram_error(addr, 'W', 2)
|
||||
|
||||
# arbitrary width (full range including special)
|
||||
def read(self, uint width, uint addr):
|
||||
if width == 0:
|
||||
return self.r8(addr)
|
||||
elif width == 1:
|
||||
return self.r16(addr)
|
||||
elif width == 2:
|
||||
return self.r32(addr)
|
||||
else:
|
||||
raise ValueError("invalid width!")
|
||||
def write(self, uint width, uint addr, uint value):
|
||||
if width == 0:
|
||||
self.w8(addr, value)
|
||||
elif width == 1:
|
||||
self.w16(addr, value)
|
||||
elif width == 2:
|
||||
self.w32(addr, value)
|
||||
else:
|
||||
raise ValueError("invalid width!")
|
||||
|
||||
# signed arbitrary width (full range including special)
|
||||
def reads(self, uint width, uint addr):
|
||||
if width == 0:
|
||||
return self.r8s(addr)
|
||||
elif width == 1:
|
||||
return self.r16s(addr)
|
||||
elif width == 2:
|
||||
return self.r32s(addr)
|
||||
else:
|
||||
raise ValueError("invalid width!")
|
||||
def writes(self, uint width, uint addr, int value):
|
||||
if width == 0:
|
||||
self.w8s(addr, value)
|
||||
elif width == 1:
|
||||
self.w16s(addr, value)
|
||||
elif width == 2:
|
||||
self.w32s(addr, value)
|
||||
else:
|
||||
raise ValueError("invalid width!")
|
||||
|
||||
# block access via str/bytearray (only RAM!)
|
||||
def r_block(self,uint addr,uint size):
|
||||
if (addr+size) > self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'R', size)
|
||||
res = bytearray(size)
|
||||
cdef unsigned char *ptr = res
|
||||
cdef const unsigned char *ram = self.ram_ptr + addr
|
||||
memcpy(ptr, ram, size)
|
||||
return res
|
||||
def w_block(self,uint addr,data):
|
||||
cdef uint size = len(data)
|
||||
if (addr+size) > self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'W', size)
|
||||
cdef const unsigned char *ptr = data
|
||||
cdef unsigned char *ram = self.ram_ptr + addr
|
||||
memcpy(ram, ptr, size)
|
||||
|
||||
def clear_block(self,uint addr,uint size,unsigned char value):
|
||||
if (addr+size) > self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'W', size)
|
||||
cdef unsigned char *ram = self.ram_ptr + addr
|
||||
memset(ram,value,size)
|
||||
|
||||
def copy_block(self,uint from_addr, uint to_addr, uint size):
|
||||
if (from_addr+size) > self.ram_bytes:
|
||||
self._raise_ram_error(from_addr, 'R', size)
|
||||
if (to_addr+size) > self.ram_bytes:
|
||||
self._raise_ram_error(to_addr, 'W', size)
|
||||
cdef unsigned char *from_ptr = self.ram_ptr + from_addr
|
||||
cdef unsigned char *to_ptr = self.ram_ptr + to_addr
|
||||
memcpy(to_ptr, from_ptr, size)
|
||||
|
||||
# helpers for c-strings (only RAM)
|
||||
cpdef r_cbytes(self,uint addr):
|
||||
if addr >= self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'R', None)
|
||||
cdef unsigned char *ram = self.ram_ptr + addr
|
||||
cdef bytes result = ram
|
||||
return result
|
||||
|
||||
cpdef w_cbytes(self,uint addr,bytes string):
|
||||
if addr >= self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'W', None)
|
||||
cdef const char *ptr = string
|
||||
cdef char *ram = <char *>self.ram_ptr + addr
|
||||
strcpy(ram, ptr)
|
||||
|
||||
def r_cstr(self, uint addr):
|
||||
return self.r_cbytes(addr).decode("latin-1")
|
||||
|
||||
def w_cstr(self, uint addr, str string):
|
||||
self.w_cbytes(addr, string.encode("latin-1"))
|
||||
|
||||
# helpers for bcpl-strings (only RAM)
|
||||
cpdef r_bbytes(self,uint addr):
|
||||
if addr >= self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'R', None)
|
||||
cdef uint size
|
||||
cdef char *data
|
||||
cdef unsigned char *ram = self.ram_ptr + addr + 1
|
||||
size = self.ram_ptr[addr]
|
||||
data = <char *>malloc(size+1)
|
||||
memcpy(data, ram, size)
|
||||
data[size] = '\0'
|
||||
cdef bytes result = data
|
||||
free(data)
|
||||
return result
|
||||
|
||||
cpdef w_bbytes(self,uint addr,bytes string):
|
||||
if addr >= self.ram_bytes:
|
||||
self._raise_ram_error(addr, 'W', None)
|
||||
cdef uint size = len(string)
|
||||
cdef unsigned char *ptr = string
|
||||
cdef unsigned char *ram = self.ram_ptr + addr
|
||||
ram[0] = <unsigned char>size
|
||||
ram += 1
|
||||
memcpy(ram, ptr, size)
|
||||
|
||||
def r_bstr(self, uint addr):
|
||||
return self.r_bbytes(addr).decode("latin-1")
|
||||
|
||||
def w_bstr(self, uint addr, str string):
|
||||
self.w_bbytes(addr, string.encode("latin-1"))
|
||||
@ -1,63 +0,0 @@
|
||||
# traps.h
|
||||
cdef extern from "traps.h":
|
||||
int TRAP_DEFAULT
|
||||
int TRAP_AUTO_RTS
|
||||
int TRAP_ONE_SHOT
|
||||
ctypedef void (*trap_func_t)(uint opcode, uint pc, void *data)
|
||||
void trap_init()
|
||||
int trap_setup(trap_func_t func, int flags, void *data)
|
||||
void trap_free(int id)
|
||||
int trap_aline(uint opcode, uint pc)
|
||||
|
||||
cdef object trap_exc_func
|
||||
|
||||
from cpython.exc cimport PyErr_Print
|
||||
|
||||
cdef void trap_wrapper(uint opcode, uint pc, void *data) noexcept:
|
||||
cdef object py_func = <object>data
|
||||
try:
|
||||
py_func(opcode, pc)
|
||||
except:
|
||||
if trap_exc_func is not None:
|
||||
trap_exc_func(opcode, pc)
|
||||
else:
|
||||
raise
|
||||
|
||||
cdef class Traps:
|
||||
cdef dict func_map
|
||||
|
||||
def __cinit__(self):
|
||||
trap_init()
|
||||
self.func_map = {}
|
||||
|
||||
def cleanup(self):
|
||||
self.set_exc_func(None)
|
||||
|
||||
def set_exc_func(self, func):
|
||||
global trap_exc_func
|
||||
trap_exc_func = func
|
||||
|
||||
def setup(self, py_func, auto_rts=False, one_shot=False):
|
||||
cdef int flags
|
||||
flags = TRAP_DEFAULT
|
||||
if auto_rts:
|
||||
flags |= TRAP_AUTO_RTS
|
||||
if one_shot:
|
||||
flags |= TRAP_ONE_SHOT
|
||||
tid = trap_setup(trap_wrapper, flags, <void *>py_func)
|
||||
if tid != -1:
|
||||
# keep function reference around
|
||||
self.func_map[tid] = py_func
|
||||
return tid
|
||||
|
||||
def free(self, tid):
|
||||
trap_free(tid)
|
||||
del self.func_map[tid]
|
||||
|
||||
def trigger(self, uint opcode, uint pc):
|
||||
return trap_aline(opcode, pc)
|
||||
|
||||
def get_func(self, tid):
|
||||
if tid in self.func_map:
|
||||
return self.func_map[tid]
|
||||
|
||||
109
machine/traps.c
109
machine/traps.c
@ -1,109 +0,0 @@
|
||||
/* a dispatcher for a-line opcodes to be used as traps in vamos
|
||||
*
|
||||
* written by Christian Vogelgsang <chris@vogelgsang.org>
|
||||
* under the GNU Public License V2
|
||||
*/
|
||||
|
||||
#include "traps.h"
|
||||
#include "m68k.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define NUM_TRAPS 0x1000
|
||||
#define TRAP_MASK 0x0fff
|
||||
|
||||
|
||||
|
||||
struct entry {
|
||||
trap_func_t trap;
|
||||
struct entry *next;
|
||||
void *data;
|
||||
int flags;
|
||||
};
|
||||
typedef struct entry entry_t;
|
||||
|
||||
static entry_t traps[NUM_TRAPS];
|
||||
static entry_t *first_free;
|
||||
|
||||
int trap_aline(uint opcode, uint pc)
|
||||
{
|
||||
uint off = opcode & TRAP_MASK;
|
||||
trap_func_t func = traps[off].trap;
|
||||
void *data = traps[off].data;
|
||||
int flags = traps[off].flags;
|
||||
|
||||
/* unbound trap? */
|
||||
if(func == NULL) {
|
||||
/* regular m68k ALINE exception */
|
||||
return M68K_ALINE_EXCEPT;
|
||||
}
|
||||
|
||||
/* a one shot trap is removed before it is triggered
|
||||
** otherwise, trap-functions used to capture "end-of-call"s
|
||||
** of shell processes would never be released.
|
||||
*/
|
||||
if(flags & TRAP_ONE_SHOT) {
|
||||
trap_free(off);
|
||||
}
|
||||
|
||||
func(opcode, pc, data);
|
||||
|
||||
if(flags & TRAP_AUTO_RTS) {
|
||||
return M68K_ALINE_RTS;
|
||||
} else {
|
||||
return M68K_ALINE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void trap_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* setup free list */
|
||||
first_free = &traps[0];
|
||||
for(i=0;i<(NUM_TRAPS-1);i++) {
|
||||
traps[i].trap = NULL;
|
||||
traps[i].next = &traps[i+1];
|
||||
traps[i].flags = 0;
|
||||
traps[i].data = NULL;
|
||||
}
|
||||
traps[NUM_TRAPS-1].trap = NULL;
|
||||
traps[NUM_TRAPS-1].next = NULL;
|
||||
traps[NUM_TRAPS-1].flags = 0;
|
||||
traps[NUM_TRAPS-1].data = NULL;
|
||||
|
||||
/* setup my trap handler */
|
||||
m68k_set_aline_hook_callback(trap_aline);
|
||||
}
|
||||
|
||||
int trap_setup(trap_func_t func, int flags, void *data)
|
||||
{
|
||||
int off;
|
||||
|
||||
/* no more traps available? */
|
||||
if(first_free == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
off = (int)(first_free - traps);
|
||||
|
||||
/* new first free */
|
||||
first_free = traps[off].next;
|
||||
|
||||
/* store trap function */
|
||||
traps[off].trap = func;
|
||||
traps[off].data = data;
|
||||
traps[off].flags = flags;
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
void trap_free(int id)
|
||||
{
|
||||
/* insert trap into free list */
|
||||
traps[id].next = first_free;
|
||||
traps[id].trap = NULL;
|
||||
traps[id].flags = 0;
|
||||
traps[id].data = NULL;
|
||||
first_free = &traps[id];
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
/* a dispatcher for a-line opcodes to be used as traps in vamos
|
||||
*
|
||||
* written by Christian Vogelgsang <chris@vogelgsang.org>
|
||||
* under the GNU Public License V2
|
||||
*/
|
||||
|
||||
#ifndef _TRAPS_H
|
||||
#define _TRAPS_H
|
||||
|
||||
#include "m68k.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define TRAP_DEFAULT 0
|
||||
#define TRAP_ONE_SHOT 1
|
||||
#define TRAP_AUTO_RTS 2
|
||||
|
||||
/* ------ Types ----- */
|
||||
#ifndef UINT_TYPE
|
||||
#define UINT_TYPE
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
typedef void (*trap_func_t)(uint opcode, uint pc, void *data);
|
||||
|
||||
/* ----- API ----- */
|
||||
extern void trap_init(void);
|
||||
extern int trap_aline(uint opcode, uint pc);
|
||||
|
||||
extern int trap_setup(trap_func_t func, int flags, void *data);
|
||||
extern void trap_free(int id);
|
||||
|
||||
#endif
|
||||
@ -1,247 +0,0 @@
|
||||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006-2008 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The name of the author may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
#define INTMAX_C INT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
||||
@ -19,10 +19,13 @@ classifiers = [
|
||||
]
|
||||
dynamic = ["version", "readme"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
vamos = ["machine68k"]
|
||||
|
||||
[tool.setuptools]
|
||||
zip-safe = false
|
||||
include-package-data = true
|
||||
packages = ["amitools", "machine"]
|
||||
packages = ["amitools"]
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
readme = { file="README.md", content-type="text/markdown" }
|
||||
|
||||
220
setup.py
220
setup.py
@ -1,220 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
from setuptools import setup, Extension
|
||||
from pkg_resources import parse_version
|
||||
from distutils.command.build_ext import build_ext
|
||||
from distutils.command.clean import clean
|
||||
from distutils.core import Command
|
||||
from distutils import ccompiler
|
||||
from distutils.dir_util import remove_tree
|
||||
from distutils import log
|
||||
from pkg_resources import parse_version
|
||||
|
||||
# has cython?
|
||||
try:
|
||||
from Cython.Build import cythonize
|
||||
|
||||
has_cython = True
|
||||
except ImportError:
|
||||
has_cython = False
|
||||
|
||||
# use cython?
|
||||
use_cython = has_cython
|
||||
if "--no-cython" in sys.argv:
|
||||
use_cython = False
|
||||
sys.argv.remove("--no-cython")
|
||||
print("use_cython:", use_cython)
|
||||
|
||||
# check cython version
|
||||
if use_cython:
|
||||
try:
|
||||
from Cython import __version__ as cyver
|
||||
|
||||
print("cython version:", cyver)
|
||||
if parse_version(cyver) < parse_version("3.0"):
|
||||
print("cython is too old < 3.0! please update first!")
|
||||
sys.exit(1)
|
||||
except ImportError:
|
||||
print("cython is too old! please update first!")
|
||||
sys.exit(1)
|
||||
|
||||
# if generated file is missing cython is required
|
||||
ext_file = "machine/emu.c"
|
||||
if not os.path.exists(ext_file) and not use_cython:
|
||||
print("generated cython file missing! cython is essential to proceed!")
|
||||
print("please install with: pip3 install cython")
|
||||
sys.exit(1)
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
gen_src = ["m68kopac.c", "m68kopdm.c", "m68kopnz.c", "m68kops.c"]
|
||||
|
||||
gen_tool = "build/m68kmake"
|
||||
gen_tool_src = "machine/musashi/m68kmake.c"
|
||||
gen_tool_obj = "build/machine/musashi/m68kmake.o"
|
||||
gen_input = "machine/musashi/m68k_in.c"
|
||||
gen_dir = "gen"
|
||||
gen_src = list([os.path.join(gen_dir, x) for x in gen_src])
|
||||
build_dir = "build"
|
||||
|
||||
# check compiler
|
||||
is_msvc = sys.platform == "win32" and sys.version.lower().find("msc") != -1
|
||||
|
||||
|
||||
class my_build_ext(build_ext):
|
||||
"""overwrite build_ext to generate code first"""
|
||||
|
||||
def run(self):
|
||||
self.run_command("gen")
|
||||
build_ext.run(self)
|
||||
|
||||
|
||||
class my_clean(clean):
|
||||
"""overwrite clean to clean_gen first"""
|
||||
|
||||
def run(self):
|
||||
self.run_command("clean_gen")
|
||||
clean.run(self)
|
||||
|
||||
|
||||
class GenCommand(Command):
|
||||
"""my custom code generation command"""
|
||||
|
||||
description = "generate code for Musashi CPU emulator"
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
# ensure dir exists
|
||||
if not os.path.isdir(gen_dir):
|
||||
log.info("creating '{}' dir".format(gen_dir))
|
||||
os.mkdir(gen_dir)
|
||||
if not os.path.isdir(build_dir):
|
||||
log.info("creating '{}' dir".format(build_dir))
|
||||
os.mkdir(build_dir)
|
||||
# build tool first?
|
||||
if not os.path.exists(gen_tool):
|
||||
cc = ccompiler.new_compiler()
|
||||
log.info("building '{}' tool".format(gen_tool))
|
||||
# win fixes
|
||||
src = gen_tool_src.replace("/", os.path.sep)
|
||||
print("tool source:", src)
|
||||
obj = gen_tool_obj.replace(".o", cc.obj_extension)
|
||||
obj = obj.replace("/", os.path.sep)
|
||||
print("tool object:", obj)
|
||||
# compile
|
||||
if is_msvc:
|
||||
defines = [("_CRT_SECURE_NO_WARNINGS", None)]
|
||||
else:
|
||||
defines = None
|
||||
cc.compile(sources=[src], output_dir=build_dir, macros=defines)
|
||||
# link
|
||||
if is_msvc:
|
||||
ld_args = ["/MANIFEST"]
|
||||
else:
|
||||
ld_args = None
|
||||
cc.link_executable(
|
||||
objects=[obj], output_progname=gen_tool, extra_postargs=ld_args
|
||||
)
|
||||
# remove
|
||||
os.remove(obj)
|
||||
# generate source?
|
||||
if not os.path.exists(gen_src[0]):
|
||||
log.info("generating source files")
|
||||
cmd = [gen_tool, gen_dir, gen_input]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
class CleanGenCommand(Command):
|
||||
"""my custom code generation cleanup command"""
|
||||
|
||||
description = "remove generated code for Musashi CPU emulator"
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
if os.path.exists(gen_dir):
|
||||
remove_tree(gen_dir, dry_run=self.dry_run)
|
||||
# remove tool
|
||||
if os.path.exists(gen_tool):
|
||||
os.remove(gen_tool)
|
||||
|
||||
|
||||
# my custom commands
|
||||
cmdclass = {
|
||||
"gen": GenCommand,
|
||||
"clean_gen": CleanGenCommand,
|
||||
"build_ext": my_build_ext,
|
||||
"clean": my_clean,
|
||||
}
|
||||
command_options = {}
|
||||
|
||||
|
||||
cython_file = "machine/emu.pyx"
|
||||
sourcefiles = [
|
||||
"machine/traps.c",
|
||||
"machine/mem.c",
|
||||
"machine/musashi/m68kcpu.c",
|
||||
"machine/musashi/m68kdasm.c",
|
||||
"machine/musashi/softfloat/softfloat.c",
|
||||
"gen/m68kops.c",
|
||||
]
|
||||
depends = [
|
||||
"machine/my_conf.h",
|
||||
"machine/pycpu.pyx",
|
||||
"machine/pymem.pyx",
|
||||
"machine/pytraps.pyx",
|
||||
"machine/musashi/m68k.h",
|
||||
"machine/musashi/m68kcpu.h",
|
||||
"machine/mem.h",
|
||||
"machine/traps.h",
|
||||
"machine/musashi/softfloat/mamesf.h",
|
||||
"machine/musashi/softfloat/milieu.h",
|
||||
"machine/musashi/softfloat/softfloat.h",
|
||||
"machine/musashi/softfloat/softfloat-macros",
|
||||
"machine/musashi/softfloat/softfloat-specialize",
|
||||
]
|
||||
inc_dirs = ["machine", "machine/musashi", "gen"]
|
||||
|
||||
# add missing vc headers
|
||||
if is_msvc:
|
||||
inc_dirs.append("machine/win")
|
||||
defines = [("_CRT_SECURE_NO_WARNINGS", None), ("_USE_MATH_DEFINES", None)]
|
||||
else:
|
||||
defines = []
|
||||
# use own musashi config file
|
||||
defines.append(("MUSASHI_CNF", '"my_conf.h"'))
|
||||
|
||||
extensions = [
|
||||
Extension(
|
||||
"machine.emu",
|
||||
sourcefiles,
|
||||
depends=depends,
|
||||
include_dirs=inc_dirs,
|
||||
define_macros=defines,
|
||||
)
|
||||
]
|
||||
|
||||
# use cython?
|
||||
if use_cython:
|
||||
sourcefiles.append(cython_file)
|
||||
extensions = cythonize(extensions, language_level="3str")
|
||||
else:
|
||||
sourcefiles.append(ext_file)
|
||||
|
||||
setup(
|
||||
cmdclass=cmdclass,
|
||||
command_options=command_options,
|
||||
ext_modules=extensions,
|
||||
)
|
||||
setup()
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
import pytest
|
||||
from machine import emu
|
||||
from machine.m68k import *
|
||||
from amitools.vamos.machine import *
|
||||
from amitools.vamos.machine import Machine, CPUState
|
||||
|
||||
|
||||
def machine_emu_cpustate_rw_test():
|
||||
cpu = emu.CPU(M68K_CPU_TYPE_68000)
|
||||
def machine_cpustate_rw_test():
|
||||
machine = Machine()
|
||||
cpu = machine.cpu
|
||||
cpu.w_pc(0)
|
||||
cpu.w_sr(0x2700)
|
||||
for i in range(16):
|
||||
@ -1,35 +0,0 @@
|
||||
import pytest
|
||||
from machine import emu
|
||||
from machine.m68k import *
|
||||
|
||||
|
||||
def machine_emu_cpu_rw_reg_test():
|
||||
cpu = emu.CPU(M68K_CPU_TYPE_68000)
|
||||
cpu.w_reg(M68K_REG_D0, 0xDEADBEEF)
|
||||
assert cpu.r_reg(M68K_REG_D0) == 0xDEADBEEF
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
cpu.w_reg(M68K_REG_D0, 0xDEADBEEF12)
|
||||
with pytest.raises(OverflowError):
|
||||
cpu.w_reg(M68K_REG_D0, -1)
|
||||
with pytest.raises(TypeError):
|
||||
cpu.w_reg(M68K_REG_D0, "hello")
|
||||
|
||||
|
||||
def machine_emu_cpu_rws_reg_test():
|
||||
cpu = emu.CPU(M68K_CPU_TYPE_68000)
|
||||
cpu.ws_reg(M68K_REG_D0, -123)
|
||||
assert cpu.rs_reg(M68K_REG_D0) == -123
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
cpu.ws_reg(M68K_REG_D0, 0x80000000)
|
||||
with pytest.raises(OverflowError):
|
||||
cpu.ws_reg(M68K_REG_D0, -0x80000001)
|
||||
with pytest.raises(TypeError):
|
||||
cpu.ws_reg(M68K_REG_D0, "hello")
|
||||
|
||||
|
||||
def machine_emu_cpu_rw_context_test():
|
||||
cpu = emu.CPU(M68K_CPU_TYPE_68000)
|
||||
ctx = cpu.get_cpu_context()
|
||||
cpu.set_cpu_context(ctx)
|
||||
@ -1,393 +0,0 @@
|
||||
import pytest
|
||||
from machine import emu
|
||||
|
||||
|
||||
def machine_emu_mem_rw_test():
|
||||
mem = emu.Memory(16)
|
||||
assert mem.get_ram_size_kib() == 16
|
||||
|
||||
mem.w8(0x100, 42)
|
||||
assert mem.r8(0x100) == 42
|
||||
|
||||
mem.w16(0x200, 0xDEAD)
|
||||
assert mem.r16(0x200) == 0xDEAD
|
||||
|
||||
mem.w32(0x300, 0xCAFEBABE)
|
||||
assert mem.r32(0x300) == 0xCAFEBABE
|
||||
|
||||
mem.write(0, 0x101, 43)
|
||||
assert mem.read(0, 0x101) == 43
|
||||
|
||||
mem.write(1, 0x202, 0x1234)
|
||||
assert mem.read(1, 0x202) == 0x1234
|
||||
|
||||
mem.write(2, 0x304, 0x11223344)
|
||||
assert mem.read(2, 0x304) == 0x11223344
|
||||
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w8(0x100, 0x100)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w8(0x100, -1)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w16(0x100, 0x10000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w16(0x100, -2)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w32(0x100, 0x100000000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w32(0x100, -3)
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w8(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w16(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w32(0x100, "hello")
|
||||
# invalid width
|
||||
with pytest.raises(ValueError):
|
||||
mem.write(7, 0x202, 12)
|
||||
with pytest.raises(ValueError):
|
||||
mem.read(7, 0x202)
|
||||
|
||||
# out of range
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w8(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w16(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w32(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.write(0, 0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r8(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r16(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r32(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.read(0, 0x10000)
|
||||
|
||||
|
||||
def machine_emu_mem_rws_test():
|
||||
mem = emu.Memory(16)
|
||||
|
||||
mem.w8s(0x100, 42)
|
||||
assert mem.r8s(0x100) == 42
|
||||
mem.w8s(0x100, -23)
|
||||
assert mem.r8s(0x100) == -23
|
||||
|
||||
mem.w16s(0x200, 0x7EAD)
|
||||
assert mem.r16s(0x200) == 0x7EAD
|
||||
mem.w16s(0x200, -0x1000)
|
||||
assert mem.r16s(0x200) == -0x1000
|
||||
|
||||
mem.w32s(0x300, 0x1AFEBABE)
|
||||
assert mem.r32s(0x300) == 0x1AFEBABE
|
||||
mem.w32s(0x300, -0xAFEBABE)
|
||||
assert mem.r32s(0x300) == -0xAFEBABE
|
||||
|
||||
mem.writes(0, 0x101, -43)
|
||||
assert mem.reads(0, 0x101) == -43
|
||||
mem.writes(1, 0x202, -0x1234)
|
||||
assert mem.reads(1, 0x202) == -0x1234
|
||||
mem.writes(2, 0x304, -0x11223344)
|
||||
assert mem.reads(2, 0x304) == -0x11223344
|
||||
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w8s(0x100, 0x80)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w8s(0x100, -0x81)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w16s(0x100, 0x8000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w16s(0x100, -0x8001)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w32s(0x100, 0x80000000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.w32s(0x100, -0x80000001)
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w8s(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w16s(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.w32s(0x100, "hello")
|
||||
# invalid width
|
||||
with pytest.raises(ValueError):
|
||||
mem.writes(7, 0x202, 12)
|
||||
with pytest.raises(ValueError):
|
||||
mem.reads(7, 0x202)
|
||||
|
||||
# out of range
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w8s(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w16s(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.w32s(0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.writes(0, 0x10000, 0)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r8s(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r16s(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.r32s(0x10000)
|
||||
with pytest.raises(emu.MemoryError):
|
||||
mem.reads(0, 0x10000)
|
||||
|
||||
|
||||
class InvalidMemAccess(object):
|
||||
def __init__(self, mem, mode, width, addr):
|
||||
self.mem = mem
|
||||
self.want = (mode, width, addr)
|
||||
|
||||
def __enter__(self):
|
||||
self.mem.set_invalid_func(self.invalid_func)
|
||||
self.match = None
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.mem.set_invalid_func(None)
|
||||
assert self.match == self.want
|
||||
|
||||
def invalid_func(self, mode, width, addr):
|
||||
self.match = (mode, width, addr)
|
||||
|
||||
|
||||
def machine_emu_mem_cpu_rw_test():
|
||||
mem = emu.Memory(16)
|
||||
assert mem.get_ram_size_kib() == 16
|
||||
|
||||
mem.cpu_w8(0x100, 42)
|
||||
assert mem.cpu_r8(0x100) == 42
|
||||
|
||||
mem.cpu_w16(0x200, 0xDEAD)
|
||||
assert mem.cpu_r16(0x200) == 0xDEAD
|
||||
|
||||
mem.cpu_w32(0x300, 0xCAFEBABE)
|
||||
assert mem.cpu_r32(0x300) == 0xCAFEBABE
|
||||
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w8(0x100, 0x100)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w8(0x100, -1)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w16(0x100, 0x10000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w16(0x100, -2)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w32(0x100, 0x100000000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w32(0x100, -3)
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w8(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w16(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w32(0x100, "hello")
|
||||
|
||||
# out of range
|
||||
with InvalidMemAccess(mem, "W", 0, 0x10000):
|
||||
mem.cpu_w8(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "W", 1, 0x10000):
|
||||
mem.cpu_w16(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "W", 2, 0x10000):
|
||||
mem.cpu_w32(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "R", 0, 0x10000):
|
||||
mem.cpu_r8(0x10000)
|
||||
with InvalidMemAccess(mem, "R", 1, 0x10000):
|
||||
mem.cpu_r16(0x10000)
|
||||
with InvalidMemAccess(mem, "R", 2, 0x10000):
|
||||
mem.cpu_r32(0x10000)
|
||||
|
||||
|
||||
def machine_emu_mem_cpu_rws_test():
|
||||
mem = emu.Memory(16)
|
||||
|
||||
mem.cpu_w8s(0x100, 42)
|
||||
assert mem.cpu_r8s(0x100) == 42
|
||||
mem.cpu_w8s(0x100, -23)
|
||||
assert mem.cpu_r8s(0x100) == -23
|
||||
|
||||
mem.cpu_w16s(0x200, 0x7EAD)
|
||||
assert mem.cpu_r16s(0x200) == 0x7EAD
|
||||
mem.cpu_w16s(0x200, -0x1000)
|
||||
assert mem.cpu_r16s(0x200) == -0x1000
|
||||
|
||||
mem.cpu_w32s(0x300, 0x1AFEBABE)
|
||||
assert mem.cpu_r32s(0x300) == 0x1AFEBABE
|
||||
mem.cpu_w32s(0x300, -0xAFEBABE)
|
||||
assert mem.cpu_r32s(0x300) == -0xAFEBABE
|
||||
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w8s(0x100, 0x80)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w8s(0x100, -0x81)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w16s(0x100, 0x8000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w16s(0x100, -0x8001)
|
||||
# invalid values
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w32s(0x100, 0x80000000)
|
||||
with pytest.raises(OverflowError):
|
||||
mem.cpu_w32s(0x100, -0x80000001)
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w8s(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w16s(0x100, "hello")
|
||||
# invalid type
|
||||
with pytest.raises(TypeError):
|
||||
mem.cpu_w32s(0x100, "hello")
|
||||
|
||||
# out of range
|
||||
with InvalidMemAccess(mem, "W", 0, 0x10000):
|
||||
mem.cpu_w8s(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "W", 1, 0x10000):
|
||||
mem.cpu_w16s(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "W", 2, 0x10000):
|
||||
mem.cpu_w32s(0x10000, 0)
|
||||
with InvalidMemAccess(mem, "R", 0, 0x10000):
|
||||
mem.cpu_r8s(0x10000)
|
||||
with InvalidMemAccess(mem, "R", 1, 0x10000):
|
||||
mem.cpu_r16s(0x10000)
|
||||
with InvalidMemAccess(mem, "R", 2, 0x10000):
|
||||
mem.cpu_r32s(0x10000)
|
||||
|
||||
|
||||
def machine_emu_mem_block_test():
|
||||
mem = emu.Memory(16)
|
||||
data = b"hello, world!"
|
||||
mem.w_block(0, data)
|
||||
assert mem.r_block(0, len(data)) == data
|
||||
bdata = bytearray(data)
|
||||
mem.w_block(0x100, bdata)
|
||||
assert mem.r_block(0x100, len(bdata)) == bdata
|
||||
mem.clear_block(0x200, 100, 42)
|
||||
assert mem.r_block(0x200, 100) == bytes([42] * 100)
|
||||
mem.copy_block(0x200, 0x300, 20)
|
||||
assert mem.r_block(0x300, 21) == bytes([42] * 20) + b"\0"
|
||||
|
||||
|
||||
def machine_emu_mem_cstr_test():
|
||||
mem = emu.Memory(16)
|
||||
data = "hello, world"
|
||||
mem.w_cstr(0, data)
|
||||
assert mem.r_cstr(0) == data
|
||||
empty = ""
|
||||
mem.w_cstr(100, empty)
|
||||
assert mem.r_cstr(100) == empty
|
||||
|
||||
|
||||
def machine_emu_mem_bstr_test():
|
||||
mem = emu.Memory(16)
|
||||
data = "hello, world"
|
||||
mem.w_bstr(0, data)
|
||||
assert mem.r_bstr(0) == data
|
||||
empty = ""
|
||||
mem.w_bstr(100, empty)
|
||||
assert mem.r_bstr(100) == empty
|
||||
|
||||
|
||||
class TraceAssert(object):
|
||||
def __init__(self, mem, mode, width, addr, value):
|
||||
self.mem = mem
|
||||
self.want = (mode, width, addr, value)
|
||||
|
||||
def __enter__(self):
|
||||
self.mem.set_trace_mode(True)
|
||||
self.mem.set_trace_func(self.trace_func)
|
||||
self.match = None
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.mem.set_trace_mode(False)
|
||||
self.mem.set_trace_func(None)
|
||||
assert self.match == self.want
|
||||
|
||||
def trace_func(self, mode, width, addr, value):
|
||||
self.match = (mode, width, addr, value)
|
||||
|
||||
|
||||
def machine_emu_mem_trace_test():
|
||||
mem = emu.Memory(16)
|
||||
with TraceAssert(mem, "R", 0, 0x100, 0):
|
||||
mem.cpu_r8(0x100)
|
||||
with TraceAssert(mem, "R", 1, 0x100, 0):
|
||||
mem.cpu_r16(0x100)
|
||||
with TraceAssert(mem, "R", 2, 0x100, 0):
|
||||
mem.cpu_r32(0x100)
|
||||
with TraceAssert(mem, "W", 0, 0x100, 0x42):
|
||||
mem.cpu_w8(0x100, 0x42)
|
||||
with TraceAssert(mem, "W", 1, 0x100, 0xDEAD):
|
||||
mem.cpu_w16(0x100, 0xDEAD)
|
||||
with TraceAssert(mem, "W", 2, 0x100, 0xCAFEBABE):
|
||||
mem.cpu_w32(0x100, 0xCAFEBABE)
|
||||
|
||||
|
||||
def machine_emu_mem_trace_error_test():
|
||||
mem = emu.Memory(16)
|
||||
|
||||
def trace_func(mode, width, addr, value):
|
||||
raise ValueError("bonk!")
|
||||
|
||||
mem.set_trace_mode(True)
|
||||
mem.set_trace_func(trace_func)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_r8(0x100)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_w8(0x100, 0)
|
||||
mem.set_trace_mode(False)
|
||||
mem.set_trace_func(None)
|
||||
|
||||
|
||||
def machine_emu_mem_invalid_access_error_test():
|
||||
mem = emu.Memory(16)
|
||||
|
||||
def invalid_func(mode, width, addr):
|
||||
raise ValueError("bonk!")
|
||||
|
||||
mem.set_invalid_func(invalid_func)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_r8(0x100000)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_w8(0x100000, 0)
|
||||
mem.set_invalid_func(None)
|
||||
|
||||
|
||||
def machine_emu_mem_special_rw_error_test():
|
||||
mem = emu.Memory(16)
|
||||
|
||||
def read(addr):
|
||||
raise ValueError("blonk!")
|
||||
|
||||
def write(addr, val):
|
||||
raise ValueError("blonk!")
|
||||
|
||||
mem.set_special_range_read_funcs(0xBF0000, 1, read, None, None)
|
||||
mem.set_special_range_write_funcs(0xBF0000, 1, write, None, None)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_r8(0xBF0000)
|
||||
with pytest.raises(ValueError):
|
||||
mem.cpu_w8(0xBF0000, 42)
|
||||
@ -1,43 +0,0 @@
|
||||
import pytest
|
||||
import traceback
|
||||
import sys
|
||||
from machine import emu
|
||||
from machine.m68k import *
|
||||
|
||||
|
||||
def machine_emu_traps_trigger_test():
|
||||
traps = emu.Traps()
|
||||
a = []
|
||||
|
||||
def my_func(opcode, pc):
|
||||
a.append(opcode)
|
||||
a.append(pc)
|
||||
|
||||
tid = traps.setup(my_func)
|
||||
assert tid >= 0
|
||||
traps.trigger(tid, 23)
|
||||
assert a == [tid, 23]
|
||||
traps.free(tid)
|
||||
|
||||
|
||||
def machine_emu_traps_raise_test():
|
||||
traps = emu.Traps()
|
||||
a = []
|
||||
b = []
|
||||
|
||||
def exc_func(opcode, pc):
|
||||
a.append(opcode)
|
||||
a.append(pc)
|
||||
b.append(sys.exc_info())
|
||||
|
||||
traps.set_exc_func(exc_func)
|
||||
|
||||
def my_func(opcode, pc):
|
||||
raise ValueError("bla")
|
||||
|
||||
tid = traps.setup(my_func)
|
||||
assert tid >= 0
|
||||
traps.trigger(tid, 23)
|
||||
assert a == [tid, 23]
|
||||
assert b[0][0] == ValueError
|
||||
traps.free(tid)
|
||||
@ -1,4 +1,5 @@
|
||||
from amitools.vamos.machine import Machine, CPUState
|
||||
from machine68k import CPUType
|
||||
from amitools.vamos.machine import Machine
|
||||
from amitools.vamos.machine.opcodes import *
|
||||
from amitools.vamos.error import *
|
||||
from amitools.vamos.log import log_machine
|
||||
@ -9,7 +10,7 @@ import logging
|
||||
log_machine.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
def create_machine(cpu_type=Machine.CPU_TYPE_68000):
|
||||
def create_machine(cpu_type=CPUType.M68000):
|
||||
m = Machine(cpu_type, raise_on_main_run=False)
|
||||
cpu = m.get_cpu()
|
||||
mem = m.get_mem()
|
||||
@ -222,7 +223,7 @@ def machine_machine_cfg_test():
|
||||
)
|
||||
m = Machine.from_cfg(cfg, True)
|
||||
assert m
|
||||
assert m.get_cpu_type() == Machine.CPU_TYPE_68020
|
||||
assert m.get_cpu_type() == CPUType.M68020
|
||||
assert m.get_cpu_name() == "68020"
|
||||
assert m.get_ram_total_kib() == 2048
|
||||
assert m.max_cycles == 128
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user