aboutsummaryrefslogtreecommitdiff
path: root/sim/d30v/alu.h
blob: d39ee3f31a06f439e63727a7af27928a6846461c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Mitsubishi Electric Corp. D30V Simulator.
   Copyright (C) 1997, Free Software Foundation, Inc.
   Contributed by Cygnus Support.

This file is part of GDB, the GNU debugger.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */


#ifndef _D30V_ALU_H_
#define _D30V_ALU_H_

#define ALU_CARRY (PSW_VAL(PSW_C) != 0)

#include "sim-alu.h"

#define ALU16_END(TARG, HIGH)						\
{									\
  unsigned32 mask, value;						\
  if (ALU16_HAD_OVERFLOW) {						\
    mask = BIT32 (PSW_V) | BIT32 (PSW_VA) | BIT32 (PSW_C);		\
    value = BIT32 (PSW_V) | BIT32 (PSW_VA);				\
  }									\
  else {								\
    mask = BIT32 (PSW_V) | BIT32 (PSW_C);				\
    value = 0;								\
  }									\
  if (ALU16_HAD_CARRY_BORROW)						\
    value |= BIT32 (PSW_C);						\
  if (HIGH)								\
    WRITE32_QUEUE_MASK (TARG, ALU16_OVERFLOW_RESULT<<16, 0xffff0000);	\
  else									\
    WRITE32_QUEUE_MASK (TARG, ALU16_OVERFLOW_RESULT, 0x0000ffff);	\
  WRITE32_QUEUE_MASK (&PSW, value, mask);				\
}

#define ALU32_END(TARG)							\
{									\
  unsigned32 mask, value;						\
  if (ALU32_HAD_OVERFLOW) {						\
    mask = BIT32 (PSW_V) | BIT32 (PSW_VA) | BIT32 (PSW_C);		\
    value = BIT32 (PSW_V) | BIT32 (PSW_VA);				\
  }									\
  else {								\
    mask = BIT32 (PSW_V) | BIT32 (PSW_C);				\
    value = 0;								\
  }									\
  if (ALU32_HAD_CARRY_BORROW)						\
    value |= BIT32 (PSW_C);						\
  WRITE32_QUEUE (TARG, ALU32_OVERFLOW_RESULT);				\
  WRITE32_QUEUE_MASK (&PSW, value, mask);				\
}

#define ALU_END(TARG) ALU32_END(TARG)


/* PSW & Flag manipulation */

#define PSW_SET(BIT,VAL) BLIT32(PSW, (BIT), (VAL))
#define PSW_VAL(BIT) EXTRACTED32(PSW, (BIT), (BIT))

#define PSW_F(FLAG) (17 + ((FLAG) % 8) * 2)
#define PSW_FLAG_SET(FLAG,VAL) PSW_SET(PSW_F(FLAG), VAL)
#define PSW_FLAG_VAL(FLAG) PSW_VAL(PSW_F(FLAG))

#define PSW_SET_QUEUE(BIT,VAL)						\
do {									\
  unsigned32 mask = BIT32 (BIT);					\
  unsigned32 bitval = (VAL) ? mask : 0;					\
  WRITE32_QUEUE_MASK (&PSW, bitval, mask);				\
} while (0)

#define PSW_FLAG_SET_QUEUE(FLAG,VAL)					\
do {									\
  unsigned32 mask = BIT32 (PSW_F (FLAG));				\
  unsigned32 bitval = (VAL) ? mask : 0;					\
  WRITE32_QUEUE_MASK (&PSW, bitval, mask);				\
} while (0)

/* Bring data in from the cold */

#define IMEM(EA) \
(sim_core_read_8(STATE_CPU (sd, 0), cia, exec_map, (EA)))

#define MEM(SIGN, EA, NR_BYTES) \
((SIGN##_##NR_BYTES) sim_core_read_unaligned_##NR_BYTES(STATE_CPU (sd, 0), cia, read_map, (EA)))

#define STORE(EA, NR_BYTES, VAL) \
do { \
  sim_core_write_unaligned_##NR_BYTES(STATE_CPU (sd, 0), cia, write_map, (EA), (VAL)); \
} while (0)


#endif