summaryrefslogtreecommitdiff
path: root/Core/EM/AMIDebugRx/binaries/LIBS/StatusCodeLib/DbgrHelp.c
blob: 7d75b33a2affb6fce0d27995dcc07b2f8e52c997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2009, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Header: /Alaska/BIN/Modules/AMIDebugRx/binaries/LIBS/StatusCodeLib/DbgrHelp.c 5     3/17/11 7:54a Sudhirv $
//
// $Revision: 5 $
//
// $Date: 3/17/11 7:54a $
//*****************************************************************
//*****************************************************************
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/AMIDebugRx/binaries/LIBS/StatusCodeLib/DbgrHelp.c $
// 
// 5     3/17/11 7:54a Sudhirv
// Support to Boot with S3 Resume in Core_4.6.5.0
// 
// 4     3/11/11 8:41a Sudhirv
// Added support to return Database Address correctly with Cores older
// than 4.6.4x
// 
// 3     3/09/11 8:18a Sudhirv
// EIP 53658 - AMIDebugRx\Debugger support for PI 1.1
// 
// 2     7/17/09 7:15p Madhans
// DebugRx 1.30.0022
// 
// 4     7/16/09 3:07p Madhans
// To fix the Serial Debugger issuel and To do cleanup.
// 
// 3     7/15/09 5:56p Madhans
// Release mode binaries. With S3 resume Off.
// 
// 2     7/13/09 2:46p Sudhirv
// Update with Coding Standards
// 
// 1     7/07/09 4:46p Sudhirv
// Restructure Binaries Created
// 
// 1     5/01/09 7:48p Madhans
// AMIDebug Rx Module. Intial Checkin.
// 
// 1     4/29/09 7:51a Sudhirv
// AMI Debug Rx module created
// 
// 13    12/12/08 5:14p Madhans
// USB Redirecion Module.
// 
// 11    6/26/08 3:09p Sudhirv
// Uploaded after checking coding standards
// 
// 10    8/29/07 3:49p Madhans
// To resolve AMD Platfrom issues.
// 
// 9     8/29/07 12:44p Madhans
// Common code for 4.x and 3.x
// 
// 8     6/13/07 3:16p Madhans
// Copyright Year updated.
// 
// 7     3/12/07 6:19p Madhans
// !!!coding standards!!!!
// 
// 6     3/10/07 2:22p Madhans
// For non PEI debuggers it should return 0.
// 
// 5     3/01/07 10:44a Madhans
// token.h included
// 
// 4     1/22/07 11:36a Madhans
// Modification made for Binary Release 1.04.0003.
// 
// 3     1/05/07 1:05p Ashrafj
// Latest version 1.04.0001 Beta
// Known issues from previous 1.04.000 Beta release has been fixed.
// 
//*****************************************************************

//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	DbgrHelp.c
//
// Description:	File containing the globals for CAR base address & size.
//
//<AMI_FHDR_END>
//**********************************************************************

#include <EFI.h>
#include <AmiPeiLib.h>

#include "misc.h"
#include "AMIPeiDebug.h"
#ifdef ALASKA_SUPPORT
#include "token.h"
#else
#include "tokens.h"
#endif

//**********************************************************************
#if defined (PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x00010000)
UINTN	AMI_PEIDEBUGGER_DS_BASEADDRESS 	= 0;
UINTN	AMI_PEIDEBUGGER_DS_SIZE			= 0x2048;
#else
const UINTN	AMI_PEIDEBUGGER_DS_BASEADDRESS 	= PEI_DEBUG_DATASECTION_BASEADDRESS;
const UINTN	AMI_PEIDEBUGGER_DS_SIZE			= PEI_DEBUG_DATASECTION_SIZE;
#endif
volatile UINT16 gS3ResumeSupport = AMI_DEBUG_RX_IN_S3_SUPPORT;

VOID CPULib_SaveIdt(DESCRIPTOR_TABLE);

UINTN GetCARBaseAddress()
{
#if defined (PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x00010000)
    EFI_PEI_SERVICES          **PeiServices;
    VOID *PeiDbgData; 
    EFI_GUID  mPeiDbgBasePpiGuid = EFI_PEI_DBG_BASEADDRESS_PPI_GUID;
    EFI_STATUS Status;
	IDTBASE 	Idtr;

#ifndef	EFIx64
	_asm{
		sidt fword ptr Idtr
	}
#else
    CPULib_SaveIdt(&Idtr);
#endif
    PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.IDTBaseAddr - sizeof (UINTN)));

    if (PeiServices == NULL)
		return (Idtr.IDTBaseAddr);	//Point to the area after PEI Services
    else
    {
        Status = (**PeiServices).LocatePpi(
                                 PeiServices,
                                 &mPeiDbgBasePpiGuid,  // GUID
                                 0,               // INSTANCE
                                 NULL,            // EFI_PEI_PPI_DESCRIPTOR
                                 &PeiDbgData     // PPI
                                 );
        if (!EFI_ERROR(Status)) 
            return *((UINTN*)PeiDbgData);
        else
            return (Idtr.IDTBaseAddr);
    }
#else
    return AMI_PEIDEBUGGER_DS_BASEADDRESS;
#endif

}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	IsAmiDbgrBaseValid
//
// Description:	It is a function that helps to behave the status 
//				code redirection through debugger differently 
//				based in SDL tokens in different cases.
//
// Input:		void
//
// Output:		UINT8 
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>

UINT8 IsAmiDbgrBaseValid(void)
{

#if REDIRECTION_ONLY_MODE
	return 1;
#else
#ifndef AMI_PEI_DEBUG_SUPPORT
	return 0;
#else
// if PEI Debugger is enabled
#ifdef	EFIx64
	return 0;
#else
	IDTBASE 	Idtr;
	_asm{
		sidt fword ptr Idtr
	}
#if defined (PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x00010000)
	// Doubtful code recheck again
	if(Idtr.IDTBaseAddr != NULL)
#else
	if(Idtr.IDTBaseAddr == AMI_PEIDEBUGGER_DS_BASEADDRESS)
#endif
		return 1;
	else
		return 0;
#endif
#endif
#endif
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	IsBsp()
//
// Description:	
//
// Input:		void
//
// Output:		UINT8 
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
UINT8 IsBsp(void)
{
#ifdef	EFIx64
	return 1;
#else
	UINT8 IsBsp = 1;
#define	MSR_XAPIC_BASE				0x1B
#define	XAPIC_BASE_BSP_BIT			8
#define	XAPIC_BASE_BSP_BIT_MASK		(1 << XAPIC_BASE_BSP_BIT)
	_asm
	{
		mov ecx,MSR_XAPIC_BASE
		rdmsr
		and eax,0x100
		cmp eax,0x100
		je  BSP
		mov	IsBsp,0
BSP:
	}	
	return IsBsp;
#endif
}

//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2009, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//