2 * Copyright (c) 2007 MIPS Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Korey Sewell
33 #include "arch/mips/isa_traits.hh"
34 #include "arch/mips/utility.hh"
35 #include "config/full_system.hh"
36 #include "cpu/thread_context.hh"
37 #include "cpu/static_inst.hh"
38 #include "sim/serialize.hh"
39 #include "base/bitfield.hh"
40 #include "base/misc.hh"
43 #include "arch/mips/registers.hh"
44 #include "arch/mips/vtophys.hh"
45 #include "mem/vport.hh"
49 using namespace MipsISA
;
55 getArgument(ThreadContext
*tc
, int &number
, uint8_t size
, bool fp
)
60 return tc
->readFloatRegBits(FirstArgumentReg
+ number
);
62 return tc
->readIntReg(FirstArgumentReg
+ number
);
64 Addr sp
= tc
->readIntReg(StackPointerReg
);
65 VirtualPort
*vp
= tc
->getVirtPort();
66 uint64_t arg
= vp
->read
<uint64_t>(sp
+
67 (number
- 4) * sizeof(uint64_t));
71 panic("getArgument() is Full system only\n");
77 fpConvert(ConvertType cvt_type
, double fp_val
)
82 case SINGLE_TO_DOUBLE
:
84 double sdouble_val
= fp_val
;
85 void *sdouble_ptr
= &sdouble_val
;
86 uint64_t sdp_bits
= *(uint64_t *) sdouble_ptr
;
92 int32_t sword_val
= (int32_t) fp_val
;
93 void *sword_ptr
= &sword_val
;
94 uint64_t sword_bits
= *(uint32_t *) sword_ptr
;
100 float wfloat_val
= fp_val
;
101 void *wfloat_ptr
= &wfloat_val
;
102 uint64_t wfloat_bits
= *(uint32_t *) wfloat_ptr
;
108 double wdouble_val
= fp_val
;
109 void *wdouble_ptr
= &wdouble_val
;
110 uint64_t wdp_bits
= *(uint64_t *) wdouble_ptr
;
115 panic("Invalid Floating Point Conversion Type (%d). See \"types.hh\" for List of Conversions\n",cvt_type
);
121 roundFP(double val
, int digits
)
123 double digit_offset
= pow(10.0,digits
);
124 val
= val
* digit_offset
;
127 val
= val
/ digit_offset
;
134 int trunc_val
= (int) val
;
135 return (double) trunc_val
;
139 getCondCode(uint32_t fcsr
, int cc_idx
)
141 int shift
= (cc_idx
== 0) ? 23 : cc_idx
+ 24;
142 bool cc_val
= (fcsr
>> shift
) & 0x00000001;
147 genCCVector(uint32_t fcsr
, int cc_num
, uint32_t cc_val
)
149 int cc_idx
= (cc_num
== 0) ? 23 : cc_num
+ 24;
151 fcsr
= bits(fcsr
, 31, cc_idx
+ 1) << (cc_idx
+ 1) |
153 bits(fcsr
, cc_idx
- 1, 0);
159 genInvalidVector(uint32_t fcsr_bits
)
161 //Set FCSR invalid in "flag" field
162 int invalid_offset
= Invalid
+ Flag_Field
;
163 fcsr_bits
= fcsr_bits
| (1 << invalid_offset
);
165 //Set FCSR invalid in "cause" flag
166 int cause_offset
= Invalid
+ Cause_Field
;
167 fcsr_bits
= fcsr_bits
| (1 << cause_offset
);
173 isNan(void *val_ptr
, int size
)
179 uint32_t val_bits
= *(uint32_t *) val_ptr
;
180 return (bits(val_bits
, 30, 23) == 0xFF);
185 uint64_t val_bits
= *(uint64_t *) val_ptr
;
186 return (bits(val_bits
, 62, 52) == 0x7FF);
190 panic("Type unsupported. Size mismatch\n");
196 isQnan(void *val_ptr
, int size
)
202 uint32_t val_bits
= *(uint32_t *) val_ptr
;
203 return (bits(val_bits
, 30, 22) == 0x1FE);
208 uint64_t val_bits
= *(uint64_t *) val_ptr
;
209 return (bits(val_bits
, 62, 51) == 0xFFE);
213 panic("Type unsupported. Size mismatch\n");
218 isSnan(void *val_ptr
, int size
)
224 uint32_t val_bits
= *(uint32_t *) val_ptr
;
225 return (bits(val_bits
, 30, 22) == 0x1FF);
230 uint64_t val_bits
= *(uint64_t *) val_ptr
;
231 return (bits(val_bits
, 62, 51) == 0xFFF);
235 panic("Type unsupported. Size mismatch\n");
241 zeroRegisters(CPU
*cpu
)
243 // Insure ISA semantics
244 // (no longer very clean due to the change in setIntReg() in the
245 // cpu model. Consider changing later.)
246 cpu
->thread
->setIntReg(ZeroReg
, 0);
247 cpu
->thread
->setFloatReg(ZeroReg
, 0.0);
251 startupCPU(ThreadContext
*tc
, int cpuId
)
253 tc
->activate(0/*tc->threadId()*/);
257 copyRegs(ThreadContext
*src
, ThreadContext
*dest
)
259 panic("Copy Regs Not Implemented Yet\n");
263 copyMiscRegs(ThreadContext
*src
, ThreadContext
*dest
)
265 panic("Copy Misc. Regs Not Implemented Yet\n");
268 skipFunction(ThreadContext
*tc
)
270 Addr newpc
= tc
->readIntReg(ReturnAddressReg
);
272 tc
->setNextPC(tc
->readPC() + sizeof(TheISA::MachInst
));
273 tc
->setNextPC(tc
->readNextPC() + sizeof(TheISA::MachInst
));
277 } // namespace MipsISA