1/// @file
2///  IPF specific Processor Status Register accessing functions
3///
4/// Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5/// This program and the accompanying materials
6/// are licensed and made available under the terms and conditions of the BSD License
7/// which accompanies this distribution.  The full text of the license may be found at
8/// http://opensource.org/licenses/bsd-license.php.
9///
10/// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11/// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12///
13/// Module Name: AccessPsr.s
14///
15///
16
17#define CpuModeMask           0x0000001008020000
18
19#define CpuInVirtualMode             0x1
20#define CpuInPhysicalMode            0x0
21#define CpuInMixMode                 (0x0 - 0x1)
22
23//---------------------------------------------------------------------------------
24//++
25// AsmReadPsr
26//
27// This routine is used to read the current value of Processor Status Register (PSR).
28//
29// Arguments :
30//
31// On Entry :
32//
33// Return Value: The current PSR value.
34//
35//--
36//----------------------------------------------------------------------------------
37.text
38.type   AsmReadPsr, @function
39.proc   AsmReadPsr
40
41AsmReadPsr::
42        mov             r8 = psr;;
43        br.ret.dpnt     b0;;
44.endp   AsmReadPsr
45
46//---------------------------------------------------------------------------------
47//++
48// AsmWritePsr
49//
50// This routine is used to write the value of Processor Status Register (PSR).
51//
52// Arguments :
53//
54// On Entry : The value need to be written.
55//
56// Return Value: The value have been written.
57//
58//--
59//----------------------------------------------------------------------------------
60.text
61.type   AsmWritePsr, @function
62.proc   AsmWritePsr
63.regstk 1, 0, 0, 0
64
65AsmWritePsr::
66        mov             psr.l = in0
67        mov             r8 = in0;;
68        srlz.d;;
69        srlz.i;;
70        br.ret.dpnt     b0;;
71.endp   AsmWritePsr
72
73//---------------------------------------------------------------------------------
74//++
75// AsmCpuVirtual
76//
77// This routine is used to determines if the CPU is currently executing
78// in virtual, physical, or mixed mode.
79//
80// If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
81// If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
82// If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
83// and -1 is returned.
84//
85// Arguments:
86//
87// On Entry: None
88//
89// Return Value: The CPU mode flag
90//               return  1  The CPU is in virtual mode.
91//               return  0  The CPU is in physical mode.
92//               return -1  The CPU is in mixed mode.
93//
94//--
95//----------------------------------------------------------------------------------
96.text
97.type   AsmCpuVirtual, @function
98.proc   AsmCpuVirtual
99
100AsmCpuVirtual::
101        mov            r29 = psr
102        movl           r30 = CpuModeMask;;
103        and            r28 = r30, r29;;
104        cmp.eq         p6, p7 = r30, r28;;
105(p6)    mov            r8 = CpuInVirtualMode;;
106(p6)    br.ret.dpnt    b0;;
107(p7)    cmp.eq         p6, p7 = 0x0, r28;;
108(p6)    mov            r8 = CpuInPhysicalMode;;
109(p7)    mov            r8 = CpuInMixMode;;
110        br.ret.dpnt    b0;;
111.endp   AsmCpuVirtual
112