process.cc (13028:9a09c342891e) process.cc (13583:f7482392b097)
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 169 unchanged lines hidden (view full) ---

178 SparcProcess::initState();
179
180 ThreadContext *tc = system->getThreadContext(contextIds[0]);
181 // The process runs in user mode
182 PSTATE pstate = 0;
183 pstate.ie = 1;
184 tc->setMiscReg(MISCREG_PSTATE, pstate);
185
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 169 unchanged lines hidden (view full) ---

178 SparcProcess::initState();
179
180 ThreadContext *tc = system->getThreadContext(contextIds[0]);
181 // The process runs in user mode
182 PSTATE pstate = 0;
183 pstate.ie = 1;
184 tc->setMiscReg(MISCREG_PSTATE, pstate);
185
186 argsInit(sizeof(IntReg), PageBytes);
186 argsInit(sizeof(RegVal), PageBytes);
187}
188
189template<class IntType>
190void
191SparcProcess::argsInit(int pageSize)
192{
193 int intSize = sizeof(IntType);
194

--- 241 unchanged lines hidden (view full) ---

436 initVirtMem.writeBlob(fillStart,
437 (uint8_t*)fillHandler32, sizeof(MachInst) * numFillInsts);
438 initVirtMem.writeBlob(spillStart,
439 (uint8_t*)spillHandler32, sizeof(MachInst) * numSpillInsts);
440}
441
442void Sparc32Process::flushWindows(ThreadContext *tc)
443{
187}
188
189template<class IntType>
190void
191SparcProcess::argsInit(int pageSize)
192{
193 int intSize = sizeof(IntType);
194

--- 241 unchanged lines hidden (view full) ---

436 initVirtMem.writeBlob(fillStart,
437 (uint8_t*)fillHandler32, sizeof(MachInst) * numFillInsts);
438 initVirtMem.writeBlob(spillStart,
439 (uint8_t*)spillHandler32, sizeof(MachInst) * numSpillInsts);
440}
441
442void Sparc32Process::flushWindows(ThreadContext *tc)
443{
444 IntReg Cansave = tc->readIntReg(NumIntArchRegs + 3);
445 IntReg Canrestore = tc->readIntReg(NumIntArchRegs + 4);
446 IntReg Otherwin = tc->readIntReg(NumIntArchRegs + 6);
447 MiscReg CWP = tc->readMiscReg(MISCREG_CWP);
448 MiscReg origCWP = CWP;
444 RegVal Cansave = tc->readIntReg(NumIntArchRegs + 3);
445 RegVal Canrestore = tc->readIntReg(NumIntArchRegs + 4);
446 RegVal Otherwin = tc->readIntReg(NumIntArchRegs + 6);
447 RegVal CWP = tc->readMiscReg(MISCREG_CWP);
448 RegVal origCWP = CWP;
449 CWP = (CWP + Cansave + 2) % NWindows;
450 while (NWindows - 2 - Cansave != 0) {
451 if (Otherwin) {
452 panic("Otherwin non-zero.\n");
453 } else {
454 tc->setMiscReg(MISCREG_CWP, CWP);
455 // Do the stores
449 CWP = (CWP + Cansave + 2) % NWindows;
450 while (NWindows - 2 - Cansave != 0) {
451 if (Otherwin) {
452 panic("Otherwin non-zero.\n");
453 } else {
454 tc->setMiscReg(MISCREG_CWP, CWP);
455 // Do the stores
456 IntReg sp = tc->readIntReg(StackPointerReg);
456 RegVal sp = tc->readIntReg(StackPointerReg);
457 for (int index = 16; index < 32; index++) {
458 uint32_t regVal = tc->readIntReg(index);
459 regVal = htog(regVal);
460 if (!tc->getMemProxy().tryWriteBlob(
461 sp + (index - 16) * 4, (uint8_t *)&regVal, 4)) {
462 warn("Failed to save register to the stack when "
463 "flushing windows.\n");
464 }

--- 6 unchanged lines hidden (view full) ---

471 tc->setIntReg(NumIntArchRegs + 3, Cansave);
472 tc->setIntReg(NumIntArchRegs + 4, Canrestore);
473 tc->setMiscReg(MISCREG_CWP, origCWP);
474}
475
476void
477Sparc64Process::flushWindows(ThreadContext *tc)
478{
457 for (int index = 16; index < 32; index++) {
458 uint32_t regVal = tc->readIntReg(index);
459 regVal = htog(regVal);
460 if (!tc->getMemProxy().tryWriteBlob(
461 sp + (index - 16) * 4, (uint8_t *)&regVal, 4)) {
462 warn("Failed to save register to the stack when "
463 "flushing windows.\n");
464 }

--- 6 unchanged lines hidden (view full) ---

471 tc->setIntReg(NumIntArchRegs + 3, Cansave);
472 tc->setIntReg(NumIntArchRegs + 4, Canrestore);
473 tc->setMiscReg(MISCREG_CWP, origCWP);
474}
475
476void
477Sparc64Process::flushWindows(ThreadContext *tc)
478{
479 IntReg Cansave = tc->readIntReg(NumIntArchRegs + 3);
480 IntReg Canrestore = tc->readIntReg(NumIntArchRegs + 4);
481 IntReg Otherwin = tc->readIntReg(NumIntArchRegs + 6);
482 MiscReg CWP = tc->readMiscReg(MISCREG_CWP);
483 MiscReg origCWP = CWP;
479 RegVal Cansave = tc->readIntReg(NumIntArchRegs + 3);
480 RegVal Canrestore = tc->readIntReg(NumIntArchRegs + 4);
481 RegVal Otherwin = tc->readIntReg(NumIntArchRegs + 6);
482 RegVal CWP = tc->readMiscReg(MISCREG_CWP);
483 RegVal origCWP = CWP;
484 CWP = (CWP + Cansave + 2) % NWindows;
485 while (NWindows - 2 - Cansave != 0) {
486 if (Otherwin) {
487 panic("Otherwin non-zero.\n");
488 } else {
489 tc->setMiscReg(MISCREG_CWP, CWP);
490 // Do the stores
484 CWP = (CWP + Cansave + 2) % NWindows;
485 while (NWindows - 2 - Cansave != 0) {
486 if (Otherwin) {
487 panic("Otherwin non-zero.\n");
488 } else {
489 tc->setMiscReg(MISCREG_CWP, CWP);
490 // Do the stores
491 IntReg sp = tc->readIntReg(StackPointerReg);
491 RegVal sp = tc->readIntReg(StackPointerReg);
492 for (int index = 16; index < 32; index++) {
492 for (int index = 16; index < 32; index++) {
493 IntReg regVal = tc->readIntReg(index);
493 RegVal regVal = tc->readIntReg(index);
494 regVal = htog(regVal);
495 if (!tc->getMemProxy().tryWriteBlob(
496 sp + 2047 + (index - 16) * 8, (uint8_t *)&regVal, 8)) {
497 warn("Failed to save register to the stack when "
498 "flushing windows.\n");
499 }
500 }
501 Canrestore--;
502 Cansave++;
503 CWP = (CWP + 1) % NWindows;
504 }
505 }
506 tc->setIntReg(NumIntArchRegs + 3, Cansave);
507 tc->setIntReg(NumIntArchRegs + 4, Canrestore);
508 tc->setMiscReg(MISCREG_CWP, origCWP);
509}
510
494 regVal = htog(regVal);
495 if (!tc->getMemProxy().tryWriteBlob(
496 sp + 2047 + (index - 16) * 8, (uint8_t *)&regVal, 8)) {
497 warn("Failed to save register to the stack when "
498 "flushing windows.\n");
499 }
500 }
501 Canrestore--;
502 Cansave++;
503 CWP = (CWP + 1) % NWindows;
504 }
505 }
506 tc->setIntReg(NumIntArchRegs + 3, Cansave);
507 tc->setIntReg(NumIntArchRegs + 4, Canrestore);
508 tc->setMiscReg(MISCREG_CWP, origCWP);
509}
510
511IntReg
511RegVal
512Sparc32Process::getSyscallArg(ThreadContext *tc, int &i)
513{
514 assert(i < 6);
515 return bits(tc->readIntReg(FirstArgumentReg + i++), 31, 0);
516}
517
518void
512Sparc32Process::getSyscallArg(ThreadContext *tc, int &i)
513{
514 assert(i < 6);
515 return bits(tc->readIntReg(FirstArgumentReg + i++), 31, 0);
516}
517
518void
519Sparc32Process::setSyscallArg(ThreadContext *tc, int i, IntReg val)
519Sparc32Process::setSyscallArg(ThreadContext *tc, int i, RegVal val)
520{
521 assert(i < 6);
522 tc->setIntReg(FirstArgumentReg + i, bits(val, 31, 0));
523}
524
520{
521 assert(i < 6);
522 tc->setIntReg(FirstArgumentReg + i, bits(val, 31, 0));
523}
524
525IntReg
525RegVal
526Sparc64Process::getSyscallArg(ThreadContext *tc, int &i)
527{
528 assert(i < 6);
529 return tc->readIntReg(FirstArgumentReg + i++);
530}
531
532void
526Sparc64Process::getSyscallArg(ThreadContext *tc, int &i)
527{
528 assert(i < 6);
529 return tc->readIntReg(FirstArgumentReg + i++);
530}
531
532void
533Sparc64Process::setSyscallArg(ThreadContext *tc, int i, IntReg val)
533Sparc64Process::setSyscallArg(ThreadContext *tc, int i, RegVal val)
534{
535 assert(i < 6);
536 tc->setIntReg(FirstArgumentReg + i, val);
537}
538
539void
540SparcProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn sysret)
541{
542 // check for error condition. SPARC syscall convention is to
543 // indicate success/failure in reg the carry bit of the ccr
544 // and put the return value itself in the standard return value reg ().
545 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
546 if (sysret.successful()) {
547 // no error, clear XCC.C
548 tc->setIntReg(NumIntArchRegs + 2,
549 tc->readIntReg(NumIntArchRegs + 2) & 0xEE);
534{
535 assert(i < 6);
536 tc->setIntReg(FirstArgumentReg + i, val);
537}
538
539void
540SparcProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn sysret)
541{
542 // check for error condition. SPARC syscall convention is to
543 // indicate success/failure in reg the carry bit of the ccr
544 // and put the return value itself in the standard return value reg ().
545 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
546 if (sysret.successful()) {
547 // no error, clear XCC.C
548 tc->setIntReg(NumIntArchRegs + 2,
549 tc->readIntReg(NumIntArchRegs + 2) & 0xEE);
550 IntReg val = sysret.returnValue();
550 RegVal val = sysret.returnValue();
551 if (pstate.am)
552 val = bits(val, 31, 0);
553 tc->setIntReg(ReturnValueReg, val);
554 } else {
555 // got an error, set XCC.C
556 tc->setIntReg(NumIntArchRegs + 2,
557 tc->readIntReg(NumIntArchRegs + 2) | 0x11);
551 if (pstate.am)
552 val = bits(val, 31, 0);
553 tc->setIntReg(ReturnValueReg, val);
554 } else {
555 // got an error, set XCC.C
556 tc->setIntReg(NumIntArchRegs + 2,
557 tc->readIntReg(NumIntArchRegs + 2) | 0x11);
558 IntReg val = sysret.errnoValue();
558 RegVal val = sysret.errnoValue();
559 if (pstate.am)
560 val = bits(val, 31, 0);
561 tc->setIntReg(ReturnValueReg, val);
562 }
563}
559 if (pstate.am)
560 val = bits(val, 31, 0);
561 tc->setIntReg(ReturnValueReg, val);
562 }
563}