Adding gem5 source to svn.
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1819 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
1074
simulators/gem5/system/alpha/console/console.c
Normal file
1074
simulators/gem5/system/alpha/console/console.c
Normal file
File diff suppressed because it is too large
Load Diff
213
simulators/gem5/system/alpha/console/dbmentry.S
Normal file
213
simulators/gem5/system/alpha/console/dbmentry.S
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 The Regents of The University of Michigan
|
||||
* Copyright (c) 1993 The Hewlett-Packard Development Company
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Debug Monitor Entry code
|
||||
*/
|
||||
#include "fromHudsonOsf.h"
|
||||
|
||||
.extern myAlphaAccess
|
||||
.text
|
||||
|
||||
/* return address and padding to octaword align */
|
||||
#define STARTFRM 16
|
||||
|
||||
.globl _start
|
||||
.ent _start, 0
|
||||
_start:
|
||||
_entry:
|
||||
br t0, 2f # get the current PC
|
||||
2: ldgp gp, 0(t0) # init gp
|
||||
|
||||
/* Processor 0 start stack frame is begining of physical memory (0)
|
||||
Other processors spin here waiting to get their stacks from
|
||||
Processor 0, then they can progress as normal.
|
||||
*/
|
||||
call_pal PAL_WHAMI_ENTRY
|
||||
beq v0, cpuz
|
||||
ldq t3, m5AlphaAccess
|
||||
addq t3,0x70,t3 # *** If offset in console alpha access struct changes
|
||||
# This must be changed as well!
|
||||
bis zero,8,t4
|
||||
mulq t4,v0,t4
|
||||
addq t3,t4,t3
|
||||
ldah a0, 3(zero) # load arg0 with 65536*3
|
||||
cpuwait: .long 0x6000002 # jsr quiesceNs
|
||||
ldq t4, 0(t3)
|
||||
beq t4, cpuwait
|
||||
bis t4,t4,sp
|
||||
|
||||
|
||||
cpuz: bis sp,sp,s0 /* save sp */
|
||||
|
||||
slave: lda v0,(8*1024)(sp) /* end of page */
|
||||
|
||||
subq zero, 1, t0
|
||||
sll t0, 42, t0
|
||||
bis t0, v0, sp
|
||||
|
||||
lda sp, -STARTFRM(sp) # Create a stack frame
|
||||
stq ra, 0(sp) # Place return address on the stack
|
||||
|
||||
.mask 0x84000000, -8
|
||||
.frame sp, STARTFRM, ra
|
||||
|
||||
/*
|
||||
* Enable the Floating Point Unit
|
||||
*/
|
||||
lda a0, 1(zero)
|
||||
call_pal PAL_WRFEN_ENTRY
|
||||
|
||||
/*
|
||||
* Every good C program has a main()
|
||||
*/
|
||||
|
||||
/* If stack pointer was 0, then this is CPU0*/
|
||||
beq s0,master
|
||||
|
||||
call_pal PAL_WHAMI_ENTRY
|
||||
bis v0,v0,a0
|
||||
jsr ra, SlaveLoop
|
||||
master:
|
||||
jsr ra, main
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The Debug Monitor should never return.
|
||||
* However, just incase...
|
||||
*/
|
||||
ldgp gp, 0(ra)
|
||||
bsr zero, _exit
|
||||
|
||||
.end _start
|
||||
|
||||
|
||||
|
||||
.globl _exit
|
||||
.ent _exit, 0
|
||||
_exit:
|
||||
|
||||
ldq ra, 0(sp) # restore return address
|
||||
lda sp, STARTFRM(sp) # prune back the stack
|
||||
ret zero, (ra) # Back from whence we came
|
||||
.end _exit
|
||||
|
||||
.globl cServe
|
||||
.ent cServe 2
|
||||
cServe:
|
||||
.option O1
|
||||
.frame sp, 0, ra
|
||||
call_pal PAL_CSERVE_ENTRY
|
||||
ret zero, (ra)
|
||||
.end cServe
|
||||
|
||||
.globl wrfen
|
||||
.ent wrfen 2
|
||||
wrfen:
|
||||
.option O1
|
||||
.frame sp, 0, ra
|
||||
call_pal PAL_WRFEN_ENTRY
|
||||
ret zero, (ra)
|
||||
.end wrfen
|
||||
.globl consoleCallback
|
||||
.ent consoleCallback 2
|
||||
consoleCallback:
|
||||
br t0, 2f # get the current PC
|
||||
2: ldgp gp, 0(t0) # init gp
|
||||
lda sp,-64(sp)
|
||||
stq ra,0(sp)
|
||||
jsr CallBackDispatcher
|
||||
ldq ra,0(sp)
|
||||
lda sp,64(sp)
|
||||
ret zero,(ra)
|
||||
.end consoleCallback
|
||||
|
||||
|
||||
.globl consoleFixup
|
||||
.ent consoleFixup 2
|
||||
consoleFixup:
|
||||
br t0, 2f # get the current PC
|
||||
2: ldgp gp, 0(t0) # init gp
|
||||
lda sp,-64(sp)
|
||||
stq ra,0(sp)
|
||||
jsr CallBackFixup
|
||||
ldq ra,0(sp)
|
||||
lda sp,64(sp)
|
||||
ret zero,(ra)
|
||||
.end consoleFixup
|
||||
|
||||
|
||||
|
||||
.globl SpinLock
|
||||
.ent SpinLock 2
|
||||
SpinLock:
|
||||
1:
|
||||
ldq_l a1,0(a0) # interlock complete lock state
|
||||
subl ra,3,v0 # get calling addr[31:0] + 1
|
||||
blbs a1,2f # branch if lock is busy
|
||||
stq_c v0,0(a0) # attempt to acquire lock
|
||||
beq v0,2f # branch if lost atomicity
|
||||
mb # ensure memory coherence
|
||||
ret zero,(ra) # return to caller (v0 is 1)
|
||||
2:
|
||||
br zero,1b
|
||||
.end SpinLock
|
||||
|
||||
.globl loadContext
|
||||
.ent loadContext 2
|
||||
loadContext:
|
||||
.option O1
|
||||
.frame sp, 0, ra
|
||||
call_pal PAL_SWPCTX_ENTRY
|
||||
ret zero, (ra)
|
||||
.end loadContext
|
||||
|
||||
|
||||
.globl SlaveSpin # Very carefully spin wait
|
||||
.ent SlaveSpin 2 # and swap context without
|
||||
SlaveSpin: # using any stack space
|
||||
.option O1
|
||||
.frame sp, 0, ra
|
||||
mov a0, t0 # cpu number
|
||||
mov a1, t1 # cpu rpb pointer (virtual)
|
||||
mov a2, t2 # what to spin on
|
||||
ldah a0, 3(zero) # load arg0 with 65536
|
||||
test: .long 0x6000002 # jsr quiesceNs # wait 65us*3
|
||||
ldl t3, 0(t2)
|
||||
beq t3, test
|
||||
zapnot t1,0x1f,a0 # make rpb physical
|
||||
call_pal PAL_SWPCTX_ENTRY # switch to pcb
|
||||
mov t0, a0 # setup args for SlaveCmd
|
||||
mov t1, a1
|
||||
jsr SlaveCmd # call SlaveCmd
|
||||
ret zero, (ra) # Should never be reached
|
||||
.end SlaveSpin
|
||||
|
||||
|
||||
174
simulators/gem5/system/alpha/console/paljtokern.S
Normal file
174
simulators/gem5/system/alpha/console/paljtokern.S
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 The Regents of The University of Michigan
|
||||
* Copyright (c) 1993 The Hewlett-Packard Development Company
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "dc21164FromGasSources.h" // DECchip 21164 specific definitions
|
||||
#include "ev5_defs.h"
|
||||
#include "fromHudsonOsf.h" // OSF/1 specific definitions
|
||||
#include "fromHudsonMacros.h" // Global macro definitions
|
||||
|
||||
/* Jump to kernel
|
||||
* args:
|
||||
* Kernel address - a0
|
||||
* PCBB - a1
|
||||
* First free PFN - a3?
|
||||
*
|
||||
* Enable kseg addressing in ICSR
|
||||
* Enable kseg addressing in MCSR
|
||||
* Set VTBR -- Set to 1GB as per SRM, or maybe 8GB??
|
||||
* Set PCBB -- pass pointer in arg
|
||||
* Set PTBR -- get it out of PCB
|
||||
* Set KSP -- get it out of PCB
|
||||
*
|
||||
* Jump to kernel address
|
||||
*
|
||||
* Kernel args-
|
||||
* s0 first free PFN
|
||||
* s1 ptbr
|
||||
* s2 argc 0
|
||||
* s3 argv NULL
|
||||
* s5 osf_param (sysconfigtab) NULL
|
||||
*/
|
||||
|
||||
.global palJToKern
|
||||
.text 3
|
||||
palJToKern:
|
||||
ALIGN_BRANCH
|
||||
|
||||
ldq_p a0, 0(zero)
|
||||
ldq_p a1, 8(zero)
|
||||
ldq_p a3, 16(zero)
|
||||
|
||||
/* Point the Vptbr at 8GB */
|
||||
lda t0, 0x1(zero)
|
||||
sll t0, 33, t0
|
||||
|
||||
mtpr t0, mVptBr // Load Mbox copy
|
||||
mtpr t0, iVptBr // Load Ibox copy
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
|
||||
/* Turn on superpage mapping in the mbox and icsr */
|
||||
lda t0, (2<<MCSR_V_SP)(zero) // Get a '10' (binary) in MCSR<SP>
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr t0, mcsr // Set the super page mode enable bit
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
|
||||
lda t0, 0(zero)
|
||||
mtpr t0, dtbAsn
|
||||
mtpr t0, itbAsn
|
||||
|
||||
LDLI (t1,0x20000000)
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mfpr t0, icsr // Enable superpage mapping
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
bis t0, t1, t0
|
||||
mtpr t0, icsr
|
||||
|
||||
STALL // Required stall to update chip ...
|
||||
STALL
|
||||
STALL
|
||||
STALL
|
||||
STALL
|
||||
|
||||
ldq_p s0, PCB_Q_PTBR(a1)
|
||||
sll s0, VA_S_OFF, s0 // Shift PTBR into position
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr s0, ptPtbr // PHYSICAL MBOX INST -> MT PT20 IN 0,1
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
ldq_p sp, PCB_Q_KSP(a1)
|
||||
|
||||
mtpr a0, excAddr // Load the dispatch address.
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
bis a3, zero, a0 // first free PFN
|
||||
ldq_p a1, PCB_Q_PTBR(a1) // ptbr
|
||||
ldq_p a2, 24(zero) // argc
|
||||
ldq_p a3, 32(zero) // argv
|
||||
ldq_p a4, 40(zero) // environ
|
||||
lda a5, 0(zero) // osf_param
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr zero, dtbIa // Flush all D-stream TB entries
|
||||
mtpr zero, itbIa // Flush all I-stream TB entries
|
||||
br zero, 2f
|
||||
|
||||
ALIGN_BLOCK
|
||||
|
||||
2: NOP
|
||||
mtpr zero, icFlush // Flush the icache.
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 1-10
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 11-20
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 21-30
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 31-40
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 41-44
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
hw_rei_stall // Dispatch to kernel
|
||||
161
simulators/gem5/system/alpha/console/paljtoslave.S
Normal file
161
simulators/gem5/system/alpha/console/paljtoslave.S
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 The Regents of The University of Michigan
|
||||
* Copyright (c) 1993 The Hewlett-Packard Development Company
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "dc21164FromGasSources.h" // DECchip 21164 specific definitions
|
||||
#include "ev5_defs.h"
|
||||
#include "fromHudsonOsf.h" // OSF/1 specific definitions
|
||||
#include "fromHudsonMacros.h" // Global macro definitions
|
||||
|
||||
/*
|
||||
* args:
|
||||
* a0: here
|
||||
* a1: boot location
|
||||
* a2: CSERVE_J_KTOPAL
|
||||
* a3: restrart_pv
|
||||
* a4: vptb
|
||||
* a5: my_rpb
|
||||
*
|
||||
* SRM Console Architecture III 3-26
|
||||
*/
|
||||
|
||||
.global palJToSlave
|
||||
.text 3
|
||||
palJToSlave:
|
||||
|
||||
ALIGN_BRANCH
|
||||
|
||||
bis a3, zero, pv
|
||||
bis zero, zero, t11
|
||||
bis zero, zero, ra
|
||||
|
||||
/* Point the Vptbr to a2 */
|
||||
|
||||
mtpr a4, mVptBr // Load Mbox copy
|
||||
mtpr a4, iVptBr // Load Ibox copy
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
|
||||
/* Turn on superpage mapping in the mbox and icsr */
|
||||
lda t0, (2<<MCSR_V_SP)(zero) // Get a '10' (binary) in MCSR<SP>
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr t0, mcsr // Set the super page mode enable bit
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
|
||||
lda t0, 0(zero)
|
||||
mtpr t0, dtbAsn
|
||||
mtpr t0, itbAsn
|
||||
|
||||
LDLI (t1,0x20000000)
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mfpr t0, icsr // Enable superpage mapping
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
bis t0, t1, t0
|
||||
mtpr t0, icsr
|
||||
|
||||
STALL // Required stall to update chip ...
|
||||
STALL
|
||||
STALL
|
||||
STALL
|
||||
STALL
|
||||
|
||||
ldq_p s0, PCB_Q_PTBR(a5)
|
||||
sll s0, VA_S_OFF, s0 // Shift PTBR into position
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr s0, ptPtbr // PHYSICAL MBOX INST -> MT PT20 IN 0,1
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
ldq_p sp, PCB_Q_KSP(a5)
|
||||
|
||||
mtpr zero, dtbIa // Flush all D-stream TB entries
|
||||
mtpr zero, itbIa // Flush all I-stream TB entries
|
||||
|
||||
mtpr a1, excAddr // Load the dispatch address.
|
||||
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
STALL // don't dual issue the load with mtpr -pb
|
||||
mtpr zero, dtbIa // Flush all D-stream TB entries
|
||||
mtpr zero, itbIa // Flush all I-stream TB entries
|
||||
br zero, 2f
|
||||
|
||||
ALIGN_BLOCK
|
||||
|
||||
2: NOP
|
||||
mtpr zero, icFlush // Flush the icache.
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 1-10
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 11-20
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 21-30
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 31-40
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
NOP // Required NOPs ... 41-44
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
hw_rei_stall // Dispatch to kernel
|
||||
|
||||
301
simulators/gem5/system/alpha/console/printf.c
Normal file
301
simulators/gem5/system/alpha/console/printf.c
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 The Regents of The University of Michigan
|
||||
* Copyright (c) 1993 The Hewlett-Packard Development Company
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include "m5op.h"
|
||||
|
||||
/* The string s is terminated by a '\0' */
|
||||
void
|
||||
PutString(const char *s)
|
||||
{
|
||||
while (*s)
|
||||
PutChar(*s++);
|
||||
}
|
||||
|
||||
/* print c count times */
|
||||
void
|
||||
PutRepChar(char c, int count)
|
||||
{
|
||||
while (count--)
|
||||
PutChar(c);
|
||||
}
|
||||
|
||||
/* put string reverse */
|
||||
void
|
||||
PutStringReverse(const char *s, int index)
|
||||
{
|
||||
while (index-- > 0)
|
||||
PutChar(s[index]);
|
||||
}
|
||||
|
||||
/*
|
||||
* prints value in radix, in a field width width, with fill
|
||||
* character fill
|
||||
* if radix is negative, print as signed quantity
|
||||
* if width is negative, left justify
|
||||
* if width is 0, use whatever is needed
|
||||
* if fill is 0, use ' '
|
||||
*/
|
||||
void
|
||||
PutNumber(long value, int radix, int width, char fill)
|
||||
{
|
||||
char buffer[40];
|
||||
uint bufferindex = 0;
|
||||
ulong uvalue;
|
||||
ushort digit;
|
||||
ushort left = 0;
|
||||
ushort negative = 0;
|
||||
|
||||
if (fill == 0)
|
||||
fill = ' ';
|
||||
|
||||
if (width < 0) {
|
||||
width = -width;
|
||||
left = 1;
|
||||
}
|
||||
|
||||
if (width < 0 || width > 80)
|
||||
width = 0;
|
||||
|
||||
if (radix < 0) {
|
||||
radix = -radix;
|
||||
if (value < 0) {
|
||||
negative = 1;
|
||||
value = -value;
|
||||
}
|
||||
}
|
||||
|
||||
switch (radix) {
|
||||
case 8:
|
||||
case 10:
|
||||
case 16:
|
||||
break;
|
||||
|
||||
default:
|
||||
PutString("****");
|
||||
return;
|
||||
}
|
||||
|
||||
uvalue = value;
|
||||
|
||||
do {
|
||||
if (radix != 16) {
|
||||
digit = (ushort)(uvalue % radix);
|
||||
uvalue /= radix;
|
||||
} else {
|
||||
digit = (ushort)(uvalue & 0xf);
|
||||
uvalue = uvalue >> 4;
|
||||
}
|
||||
buffer[bufferindex] = digit + ((digit <= 9) ? '0' : ('A' - 10));
|
||||
bufferindex += 1;
|
||||
} while (uvalue != 0);
|
||||
|
||||
/* fill # ' ' and negative cannot happen at once */
|
||||
if (negative) {
|
||||
buffer[bufferindex] = '-';
|
||||
bufferindex += 1;
|
||||
}
|
||||
|
||||
if ((uint)width <= bufferindex) {
|
||||
PutStringReverse(buffer, bufferindex);
|
||||
} else {
|
||||
width -= bufferindex;
|
||||
if (!left)
|
||||
PutRepChar(fill, width);
|
||||
PutStringReverse(buffer, bufferindex);
|
||||
if (left)
|
||||
PutRepChar(fill, width);
|
||||
}
|
||||
}
|
||||
|
||||
ulong
|
||||
power(long base, long n)
|
||||
{
|
||||
ulong p;
|
||||
|
||||
for (p = 1; n > 0; --n)
|
||||
p = p * base;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
putFloat(double a, int fieldwidth, char fill)
|
||||
{
|
||||
int i;
|
||||
ulong b;
|
||||
|
||||
/*
|
||||
* Put out everything before the decimal place.
|
||||
*/
|
||||
PutNumber(((ulong) a), 10, fieldwidth, fill);
|
||||
|
||||
/*
|
||||
* Output the decimal place.
|
||||
*/
|
||||
PutChar('.' & 0x7f);
|
||||
|
||||
/*
|
||||
* Output the n digits after the decimal place.
|
||||
*/
|
||||
for (i = 1; i < 6; i++) {
|
||||
b = (ulong)(power(10, i) * (double)(a - (ulong) a));
|
||||
PutChar((char)(b % 10) + '0');
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
FormatItem(const char *f, va_list *ap)
|
||||
{
|
||||
char c;
|
||||
int fieldwidth = 0;
|
||||
int leftjust = 0;
|
||||
int radix = 0;
|
||||
char fill = ' ';
|
||||
|
||||
if (*f == '0')
|
||||
fill = '0';
|
||||
|
||||
while (c = *f++) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
fieldwidth = (fieldwidth * 10) + (c - '0');
|
||||
} else {
|
||||
switch (c) {
|
||||
case '\000':
|
||||
return(--f);
|
||||
case '%':
|
||||
PutChar('%');
|
||||
return(f);
|
||||
case '-':
|
||||
leftjust = 1;
|
||||
break;
|
||||
case 'c': {
|
||||
char a = (char)va_arg(*ap, int);
|
||||
|
||||
if (leftjust)
|
||||
PutChar(a & 0x7f);
|
||||
if (fieldwidth > 0)
|
||||
PutRepChar(fill, fieldwidth - 1);
|
||||
if (!leftjust)
|
||||
PutChar(a & 0x7f);
|
||||
return(f);
|
||||
}
|
||||
case 's': {
|
||||
const char *a = va_arg(*ap, const char *);
|
||||
|
||||
if (leftjust)
|
||||
PutString((const char *) a);
|
||||
if (fieldwidth > strlen((const char *) a))
|
||||
PutRepChar(fill, fieldwidth - strlen((const char *)a));
|
||||
if (!leftjust)
|
||||
PutString((const char *) a);
|
||||
return(f);
|
||||
}
|
||||
case 'd':
|
||||
radix = -10;
|
||||
break;
|
||||
case 'u':
|
||||
radix = 10;
|
||||
break;
|
||||
case 'x':
|
||||
radix = 16;
|
||||
break;
|
||||
case 'X':
|
||||
radix = 16;
|
||||
break;
|
||||
case 'o':
|
||||
radix = 8;
|
||||
break;
|
||||
case 'f': {
|
||||
double a = va_arg(*ap, double);
|
||||
|
||||
putFloat(a, fieldwidth, fill);
|
||||
return(f);
|
||||
}
|
||||
default: /* unknown switch! */
|
||||
radix = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (radix)
|
||||
break;
|
||||
}
|
||||
|
||||
if (leftjust)
|
||||
fieldwidth = -fieldwidth;
|
||||
|
||||
long a = va_arg(*ap, long);
|
||||
PutNumber(a, radix, fieldwidth, fill);
|
||||
|
||||
return(f);
|
||||
}
|
||||
|
||||
int
|
||||
printf(const char *f, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, f);
|
||||
|
||||
while (*f) {
|
||||
if (*f == '%')
|
||||
f = FormatItem(f + 1, &ap);
|
||||
else
|
||||
PutChar(*f++);
|
||||
}
|
||||
|
||||
if (*(f - 1) == '\n') {
|
||||
/* add a line-feed (SimOS console output goes to shell */
|
||||
PutChar('\r');
|
||||
}
|
||||
|
||||
va_end(ap); /* clean up */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
panic(const char *f, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, f);
|
||||
|
||||
printf("CONSOLE PANIC (looping): ");
|
||||
while (*f) {
|
||||
if (*f == '%')
|
||||
f = FormatItem(f + 1, &ap);
|
||||
else
|
||||
PutChar(*f++);
|
||||
}
|
||||
|
||||
va_end(ap); /* clean up */
|
||||
m5_panic();
|
||||
}
|
||||
Reference in New Issue
Block a user