1 /*
2 
3 Copyright 2021, dettus@dettus.net
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice,
12    this list of conditions and the following disclaimer in the documentation
13    and/or other materials provided with the distribution.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 */
28 
29 #ifndef	VM68K_LOADSTORE_H
30 #define	VM68K_LOADSTORE_H
31 
32 #include "vm68k_datatypes.h"
33 // some helper defines
34 #define DATAREGADDR(addr)	(-((addr)+ 1))
35 #define ADDRREGADDR(addr)	(-((addr)+10))
36 
37 #define	VM68K_LEGAL_AM_DATAREG	(1<< 1)
38 #define	VM68K_LEGAL_AM_ADDRREG	(1<< 2)
39 #define	VM68K_LEGAL_AM_INDIR	(1<< 3)
40 #define	VM68K_LEGAL_AM_POSTINC	(1<< 4)
41 #define	VM68K_LEGAL_AM_PREDEC	(1<< 5)
42 #define	VM68K_LEGAL_AM_DISP16	(1<< 6)
43 #define	VM68K_LEGAL_AM_INDEX	(1<< 7)
44 
45 #define	VM68K_LEGAL_AMX_W	(1<< 8)
46 #define	VM68K_LEGAL_AMX_L	(1<< 9)
47 #define	VM68K_LEGAL_AMX_DATA	(1<<10)
48 #define	VM68K_LEGAL_AMX_PC	(1<<11)
49 #define	VM68K_LEGAL_AMX_INDEX_PC (1<<12)
50 
51 #define	VM68K_LEGAL_CONTROLALTERATEADDRESSING		(VM68K_LEGAL_AM_INDIR|VM68K_LEGAL_AM_DISP16|VM68K_LEGAL_AM_INDEX|VM68K_LEGAL_AMX_W|VM68K_LEGAL_AMX_L|VM68K_LEGAL_AMX_PC|VM68K_LEGAL_AMX_INDEX_PC)
52 #define	VM68K_LEGAL_CONTROLADDRESSING			(VM68K_LEGAL_AM_INDIR|VM68K_LEGAL_AM_DISP16|VM68K_LEGAL_AM_INDEX|VM68K_LEGAL_AMX_W|VM68K_LEGAL_AMX_L|VM68K_LEGAL_AMX_PC|VM68K_LEGAL_AMX_INDEX_PC)
53 #define	VM68K_LEGAL_DATAADDRESSING ( VM68K_LEGAL_AM_DATAREG| VM68K_LEGAL_AM_INDIR|	VM68K_LEGAL_AM_POSTINC| VM68K_LEGAL_AM_PREDEC| VM68K_LEGAL_AM_DISP16| VM68K_LEGAL_AM_INDEX| VM68K_LEGAL_AMX_W| VM68K_LEGAL_AMX_L| VM68K_LEGAL_AMX_DATA| VM68K_LEGAL_AMX_PC| VM68K_LEGAL_AMX_INDEX_PC )
54 #define	VM68K_LEGAL_ALL ( VM68K_LEGAL_AM_DATAREG| VM68K_LEGAL_AM_ADDRREG| VM68K_LEGAL_AM_INDIR|	VM68K_LEGAL_AM_POSTINC| VM68K_LEGAL_AM_PREDEC| VM68K_LEGAL_AM_DISP16| VM68K_LEGAL_AM_INDEX| VM68K_LEGAL_AMX_W| VM68K_LEGAL_AMX_L| VM68K_LEGAL_AMX_DATA| VM68K_LEGAL_AMX_PC| VM68K_LEGAL_AMX_INDEX_PC )
55 #define	VM68K_LEGAL_DATAALTERATE ( VM68K_LEGAL_AM_DATAREG|VM68K_LEGAL_AM_INDIR|VM68K_LEGAL_AM_POSTINC| VM68K_LEGAL_AM_PREDEC| VM68K_LEGAL_AM_DISP16| VM68K_LEGAL_AM_INDEX| VM68K_LEGAL_AMX_W| VM68K_LEGAL_AMX_L)
56 #define	VM68K_LEGAL_MEMORYALTERATE ( VM68K_LEGAL_AM_INDIR|VM68K_LEGAL_AM_POSTINC| VM68K_LEGAL_AM_PREDEC| VM68K_LEGAL_AM_DISP16| VM68K_LEGAL_AM_INDEX| VM68K_LEGAL_AMX_W| VM68K_LEGAL_AMX_L)
57 #define	VM68K_LEGAL_ALTERABLEADRESSING (VM68K_LEGAL_AM_DATAREG|VM68K_LEGAL_AM_ADDRREG|VM68K_LEGAL_AM_INDIR|VM68K_LEGAL_AM_POSTINC|VM68K_LEGAL_AM_PREDEC|VM68K_LEGAL_AM_DISP16|VM68K_LEGAL_AM_INDEX| VM68K_LEGAL_AMX_W|VM68K_LEGAL_AMX_L)
58 
59 
60 
61 #define	FLAGC	(1<<0)
62 #define	FLAGV	(1<<1)
63 #define	FLAGZ	(1<<2)
64 #define	FLAGN	(1<<3)
65 #define	FLAGX	(1<<4)
66 #define	FLAGCZCLR	(1<<5)	// when set, the c and z flag are always cleared.
67 
68 #define	FLAGS_ALL	(FLAGC|FLAGV|FLAGZ|FLAGN|FLAGX)
69 #define	FLAGS_LOGIC	(FLAGZ|FLAGN|FLAGCZCLR)
70 
71 // this function is calculating the number of bytes for a datatype
72 int vm68k_getbytesize(tVM68k_types size);
73 
74 // this function is translating the addressmode/registerpair into a memory address
75 int vm68k_resolve_ea(tVM68k* pVM68k,tVM68k_next *pNext,tVM68k_types size,
76 	tVM68k_addrmodes addrmode,tVM68k_ubyte reg,
77 	tVM68k_uword legal,tVM68k_slong* ea);
78 
79 // this function is loading the operand
80 int vm68k_fetchoperand(tVM68k* pVM68k,tVM68k_bool extendsign,tVM68k_types size,tVM68k_slong ea,tVM68k_ulong* operand);
81 
82 // this function is calculting the status flags
83 int vm68k_calculateflags(tVM68k_next* pNext,tVM68k_ubyte flagmask,tVM68k_types size,tVM68k_ulong operand1,tVM68k_ulong operand2,tVM68k_uint64 result);
84 
85 int vm68k_calculateflags2(tVM68k_next* pNext,tVM68k_ubyte flagmask,tVM68k_instruction instruction,tVM68k_types datatype,tVM68k_ulong operand1,tVM68k_ulong operand2,tVM68k_uint64 result);
86 
87 // this function is storing the result of the operation.
88 int vm68k_storeresult(tVM68k* pVM68k,tVM68k_next* pNext,tVM68k_types size,tVM68k_slong ea,tVM68k_ulong result);
89 
90 
91 
92 #endif
93