utility.cc revision 13611:c8b7847b4171
112334Sgabeblack@google.com/*
212334Sgabeblack@google.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
312334Sgabeblack@google.com * All rights reserved.
412334Sgabeblack@google.com *
512334Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612334Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712334Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912334Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112334Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212334Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312334Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412334Sgabeblack@google.com * this software without specific prior written permission.
1512334Sgabeblack@google.com *
1612334Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712334Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812334Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912334Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012334Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112334Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212334Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312334Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412334Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512334Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612334Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712334Sgabeblack@google.com *
2812334Sgabeblack@google.com * Authors: Gabe Black
2912334Sgabeblack@google.com *          Ali Saidi
3012334Sgabeblack@google.com */
3112334Sgabeblack@google.com
3212334Sgabeblack@google.com#include "arch/sparc/utility.hh"
3312334Sgabeblack@google.com
3412334Sgabeblack@google.com#include "arch/sparc/faults.hh"
3512334Sgabeblack@google.com#include "arch/sparc/vtophys.hh"
3612334Sgabeblack@google.com#include "mem/fs_translating_port_proxy.hh"
3712334Sgabeblack@google.com
3812334Sgabeblack@google.comnamespace SparcISA {
3912334Sgabeblack@google.com
4012334Sgabeblack@google.com
4112334Sgabeblack@google.com// The caller uses %o0-%05 for the first 6 arguments even if their floating
4212334Sgabeblack@google.com// point. Double precision floating point values take two registers/args.
4312334Sgabeblack@google.com// Quads, structs, and unions are passed as pointers. All arguments beyond
4412334Sgabeblack@google.com// the sixth are passed on the stack past the 16 word window save area,
4512334Sgabeblack@google.com// space for the struct/union return pointer, and space reserved for the
4612334Sgabeblack@google.com// first 6 arguments which the caller may use but doesn't have to.
4712334Sgabeblack@google.comuint64_t
4812334Sgabeblack@google.comgetArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
4912334Sgabeblack@google.com{
5012334Sgabeblack@google.com    if (!FullSystem) {
5112334Sgabeblack@google.com        panic("getArgument() only implemented for full system\n");
5212334Sgabeblack@google.com        M5_DUMMY_RETURN
5312334Sgabeblack@google.com    }
5412334Sgabeblack@google.com
5512334Sgabeblack@google.com    const int NumArgumentRegs = 6;
5612334Sgabeblack@google.com    if (number < NumArgumentRegs) {
5712334Sgabeblack@google.com        return tc->readIntReg(8 + number);
5812334Sgabeblack@google.com    } else {
5912334Sgabeblack@google.com        Addr sp = tc->readIntReg(StackPointerReg);
6012334Sgabeblack@google.com        FSTranslatingPortProxy &vp = tc->getVirtProxy();
6112334Sgabeblack@google.com        uint64_t arg = vp.read<uint64_t>(sp + 92 +
6212334Sgabeblack@google.com                            (number-NumArgumentRegs) * sizeof(uint64_t));
6312334Sgabeblack@google.com        return arg;
6412334Sgabeblack@google.com    }
6512334Sgabeblack@google.com}
6612334Sgabeblack@google.com
6712334Sgabeblack@google.comvoid
6812334Sgabeblack@google.comcopyMiscRegs(ThreadContext *src, ThreadContext *dest)
6912334Sgabeblack@google.com{
7012334Sgabeblack@google.com
7112334Sgabeblack@google.com    uint8_t tl = src->readMiscRegNoEffect(MISCREG_TL);
7212334Sgabeblack@google.com
7312334Sgabeblack@google.com    // Read all the trap level dependent registers and save them off
7412334Sgabeblack@google.com    for (int i = 1; i <= MaxTL; i++) {
7512334Sgabeblack@google.com        src->setMiscRegNoEffect(MISCREG_TL, i);
7612334Sgabeblack@google.com        dest->setMiscRegNoEffect(MISCREG_TL, i);
7712334Sgabeblack@google.com
7812334Sgabeblack@google.com        dest->setMiscRegNoEffect(MISCREG_TT,
7912334Sgabeblack@google.com                src->readMiscRegNoEffect(MISCREG_TT));
8012334Sgabeblack@google.com        dest->setMiscRegNoEffect(MISCREG_TPC,
8112334Sgabeblack@google.com                src->readMiscRegNoEffect(MISCREG_TPC));
8212334Sgabeblack@google.com        dest->setMiscRegNoEffect(MISCREG_TNPC,
8312334Sgabeblack@google.com                src->readMiscRegNoEffect(MISCREG_TNPC));
8412334Sgabeblack@google.com        dest->setMiscRegNoEffect(MISCREG_TSTATE,
8512334Sgabeblack@google.com                src->readMiscRegNoEffect(MISCREG_TSTATE));
8612334Sgabeblack@google.com    }
8712334Sgabeblack@google.com
8812334Sgabeblack@google.com    // Save off the traplevel
8912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_TL, tl);
9012334Sgabeblack@google.com    src->setMiscRegNoEffect(MISCREG_TL, tl);
9112334Sgabeblack@google.com
9212334Sgabeblack@google.com
9312334Sgabeblack@google.com    // ASRs
9412334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_Y,
9512334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_Y));
9612334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_CCR,
9712334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_CCR));
9812334Sgabeblack@google.com    dest->setMiscReg(MISCREG_ASI,
9912334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_ASI));
10012334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_TICK,
10112334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_TICK));
10212334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_FPRS,
10312334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_FPRS));
10412334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SOFTINT,
10512334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SOFTINT));
10612334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_TICK_CMPR,
10712334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_TICK_CMPR));
10812334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_STICK,
10912334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_STICK));
11012334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_STICK_CMPR,
11112334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_STICK_CMPR));
11212334Sgabeblack@google.com
11312334Sgabeblack@google.com    // Priv Registers
11412334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_TICK,
11512334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_TICK));
11612334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_TBA,
11712334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_TBA));
11812334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_PSTATE,
11912334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_PSTATE));
12012334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_PIL,
12112334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_PIL));
12212334Sgabeblack@google.com    dest->setMiscReg(MISCREG_CWP,
12312334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_CWP));
12412334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_CANSAVE,
12512334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_CANSAVE));
12612334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_CANRESTORE,
12712334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_CANRESTORE));
12812334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_OTHERWIN,
12912334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_OTHERWIN));
13012334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_CLEANWIN,
13112334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_CLEANWIN));
13212334Sgabeblack@google.com//    dest->setMiscRegNoEffect(MISCREG_WSTATE,
13312334Sgabeblack@google.com//            src->readMiscRegNoEffect(MISCREG_WSTATE));
13412334Sgabeblack@google.com    dest->setMiscReg(MISCREG_GL, src->readMiscRegNoEffect(MISCREG_GL));
13512334Sgabeblack@google.com
13612334Sgabeblack@google.com    // Hyperprivilged registers
13712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_HPSTATE,
13812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_HPSTATE));
13912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_HINTP,
14012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_HINTP));
14112334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_HTBA,
14212334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_HTBA));
14312334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_STRAND_STS_REG,
14412334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_STRAND_STS_REG));
14512334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_HSTICK_CMPR,
14612334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_HSTICK_CMPR));
14712334Sgabeblack@google.com
14812334Sgabeblack@google.com    // FSR
14912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_FSR,
15012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_FSR));
15112334Sgabeblack@google.com
15212334Sgabeblack@google.com    // Strand Status Register
15312334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_STRAND_STS_REG,
15412334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_STRAND_STS_REG));
15512334Sgabeblack@google.com
15612334Sgabeblack@google.com    // MMU Registers
15712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_MMU_P_CONTEXT,
15812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_MMU_P_CONTEXT));
15912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_MMU_S_CONTEXT,
16012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_MMU_S_CONTEXT));
16112334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_MMU_PART_ID,
16212334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_MMU_PART_ID));
16312334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_MMU_LSU_CTRL,
16412334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_MMU_LSU_CTRL));
16512334Sgabeblack@google.com
16612334Sgabeblack@google.com    // Scratchpad Registers
16712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R0,
16812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R0));
16912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R1,
17012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R1));
17112334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R2,
17212334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R2));
17312334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R3,
17412334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R3));
17512334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R4,
17612334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R4));
17712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R5,
17812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R5));
17912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R6,
18012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R6));
18112334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_SCRATCHPAD_R7,
18212334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_SCRATCHPAD_R7));
18312334Sgabeblack@google.com
18412334Sgabeblack@google.com    // Queue Registers
18512334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_HEAD,
18612334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_HEAD));
18712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_TAIL,
18812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_CPU_MONDO_TAIL));
18912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_HEAD,
19012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_HEAD));
19112334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_TAIL,
19212334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_DEV_MONDO_TAIL));
19312334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_HEAD,
19412334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_HEAD));
19512334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_TAIL,
19612334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_RES_ERROR_TAIL));
19712334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_HEAD,
19812334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_HEAD));
19912334Sgabeblack@google.com    dest->setMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_TAIL,
20012334Sgabeblack@google.com            src->readMiscRegNoEffect(MISCREG_QUEUE_NRES_ERROR_TAIL));
20112334Sgabeblack@google.com}
20212334Sgabeblack@google.com
20312334Sgabeblack@google.comvoid
20412334Sgabeblack@google.comcopyRegs(ThreadContext *src, ThreadContext *dest)
20512334Sgabeblack@google.com{
20612334Sgabeblack@google.com    // First loop through the integer registers.
20712334Sgabeblack@google.com    int old_gl = src->readMiscRegNoEffect(MISCREG_GL);
20812334Sgabeblack@google.com    int old_cwp = src->readMiscRegNoEffect(MISCREG_CWP);
20912334Sgabeblack@google.com    // Globals
21012334Sgabeblack@google.com    for (int x = 0; x < MaxGL; ++x) {
21112334Sgabeblack@google.com        src->setMiscReg(MISCREG_GL, x);
21212334Sgabeblack@google.com        dest->setMiscReg(MISCREG_GL, x);
21312334Sgabeblack@google.com        // Skip %g0 which is always zero.
21412334Sgabeblack@google.com        for (int y = 1; y < 8; y++)
21512334Sgabeblack@google.com            dest->setIntReg(y, src->readIntReg(y));
21612334Sgabeblack@google.com    }
21712334Sgabeblack@google.com    // Locals and ins. Outs are all also ins.
21812334Sgabeblack@google.com    for (int x = 0; x < NWindows; ++x) {
21912334Sgabeblack@google.com         src->setMiscReg(MISCREG_CWP, x);
22012334Sgabeblack@google.com         dest->setMiscReg(MISCREG_CWP, x);
22112334Sgabeblack@google.com         for (int y = 16; y < 32; y++)
22212334Sgabeblack@google.com             dest->setIntReg(y, src->readIntReg(y));
22312334Sgabeblack@google.com    }
22412334Sgabeblack@google.com    // Microcode reg and pseudo int regs (misc regs in the integer regfile).
22512334Sgabeblack@google.com    for (int y = NumIntArchRegs; y < NumIntArchRegs + NumMicroIntRegs; ++y)
22612334Sgabeblack@google.com        dest->setIntReg(y, src->readIntReg(y));
22712334Sgabeblack@google.com
22812334Sgabeblack@google.com    // Restore src's GL, CWP
22912334Sgabeblack@google.com    src->setMiscReg(MISCREG_GL, old_gl);
23012334Sgabeblack@google.com    src->setMiscReg(MISCREG_CWP, old_cwp);
23112334Sgabeblack@google.com
23212334Sgabeblack@google.com
23312334Sgabeblack@google.com    // Then loop through the floating point registers.
23412334Sgabeblack@google.com    for (int i = 0; i < SparcISA::NumFloatArchRegs; ++i) {
23512334Sgabeblack@google.com        dest->setFloatReg(i, src->readFloatReg(i));
23612334Sgabeblack@google.com    }
23712334Sgabeblack@google.com
23812334Sgabeblack@google.com    // Would need to add condition-code regs if implemented
23912334Sgabeblack@google.com    assert(NumCCRegs == 0);
24012334Sgabeblack@google.com
24112334Sgabeblack@google.com    // Copy misc. registers
24212334Sgabeblack@google.com    copyMiscRegs(src, dest);
24312334Sgabeblack@google.com
24412334Sgabeblack@google.com    // Lastly copy PC/NPC
24512334Sgabeblack@google.com    dest->pcState(src->pcState());
24612334Sgabeblack@google.com}
24712334Sgabeblack@google.com
24812334Sgabeblack@google.comvoid
24912334Sgabeblack@google.comskipFunction(ThreadContext *tc)
25012334Sgabeblack@google.com{
25112334Sgabeblack@google.com    TheISA::PCState newPC = tc->pcState();
25212334Sgabeblack@google.com    newPC.set(tc->readIntReg(ReturnAddressReg));
25312334Sgabeblack@google.com    tc->pcState(newPC);
25412334Sgabeblack@google.com}
25512334Sgabeblack@google.com
25612334Sgabeblack@google.com
257void
258initCPU(ThreadContext *tc, int cpuId)
259{
260    static Fault por = std::make_shared<PowerOnReset>();
261    if (cpuId == 0)
262        por->invoke(tc);
263}
264
265} // namespace SPARC_ISA
266