summaryrefslogtreecommitdiff
path: root/Core/EM/AMIDebugRx/binaries/PeiAMIDebugRx/DBGR/DbgrHdr.c
blob: d0b4a2e155931d22936c0f7b0409abf1bd98ab3a (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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (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/PeiAMIDebugRx/DBGR/DbgrHdr.c 11    4/04/12 4:56p Sudhirv $
//
// $Revision: 11 $
//
// $Date: 4/04/12 4:56p $
//*****************************************************************
//*****************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/AMIDebugRx/binaries/PeiAMIDebugRx/DBGR/DbgrHdr.c $
// 
// 11    4/04/12 4:56p Sudhirv
// To Avoid Build errors in special cases.
// 
// 10    4/03/12 4:43p Sudhirv
// To avoid Build errors for redirection modes.
// 
// 9     3/27/12 12:02p Sudhirv
// [TAG]  		EIP80406
// [Category]  	Improvement
// [Description]  	Debugger support for Dynamic pci express base token
// 
// 8     3/13/12 10:47a Sudhirv
// [TAG]  		EIP60224
// [Category]  	Improvement
// [Description]  Function implement When broken in SMM, show the register
// context for 'outside' SMM.
// 
// [TAG]  		EIP80406
// [Category]  	Improvement
// [Description]  Debugger support for Dynamic pci express base token
// 
// [TAG]  		EIP81423
// [Category]  	Improvement
// [Description]  VeB Debugger - Improve the EFI tab's Handle Display
// feature
// 
// [TAG]  		EIP84201
// [Category]  	Improvement
// [Description]  AMIDebugRx\Debugger Target modules usage of the Port 80
// must be controlable
// 
// 7     8/19/11 8:28p Sudhirv
// Fix To get PCIExBaseaddress correctly for ReadPCI.
// 
// 6     7/22/11 12:19p Sudhirv
// [TAG]  		Compilation Error
// [Description]  	To avoid Compilation errors in some Projects.
// [Files]  		DbgrHdr.c
// 
// 5     7/12/11 5:23p Sudhirv
// [TAG]  		SMM Info
// [Category]  	New Feature
// [Description]  	To support send SMM Info to host
// 
// 4     3/17/11 7:57a Sudhirv
// Support to Boot with S3 Resume in Core_4.6.5.0
// 
// 3     3/09/11 8:21a Sudhirv
// EIP 53658 - AMIDebugRx\Debugger support for PI 1.1
// 
// 2     7/17/09 7:15p Madhans
// DebugRx 1.30.0022
// 
// 2     7/13/09 2:49p Sudhirv
// Updated 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:52a Sudhirv
// AMI Debug Rx module created
// 
// 8     3/27/09 8:38a Sudhirv
// Updated Coding Standards.
// 
// 7     8/29/07 12:47p Madhans
// Common code for 4.x and 3.x
// 
// 6     6/13/07 3:16p Madhans
// Copyright Year updated.
// 
// 5     2/27/07 5:01p Madhans
//
//*****************************************************************

//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	DbgrHdr.c
//
// Description:	File containing the globals for CAR base address & size.
//				Also the code which make use of this so that it can be
//				integrated as it is Debugger eModule of binary.
//
//<AMI_FHDR_END>
//**********************************************************************

#include "pei.h"
#include "misc.h"
#include "AMIPeiDebug.h"
//**********************************************************************
#ifdef ALASKA_SUPPORT
#define CAR_Start_Addr		PEI_DEBUG_DATASECTION_BASEADDRESS		// CAR Size = 8k
#define CAR_End_Addr		PEI_DEBUG_DATASECTION_BASEADDRESS + PEI_DEBUG_DATASECTION_SIZE
#define Code_Start_Addr			0xffffffff - FLASH_SIZE
#define Code_End_Addr			0xffffffff			
#else
#define CAR_Start_Addr			DATA_STACK_BASEADDRESS		// CAR Size = 64k
#define CAR_End_Addr			(DATA_STACK_BASEADDRESS | 0x10000)
#define Code_Start_Addr			0xffdfffff		// Max BootBlock Size = 4Gig - 2MB
#define Code_End_Addr			0xffffffff			
#endif

#ifndef SW_SMI_IO_ADDRESS
#define SW_SMI_IO_ADDRESS 0
#endif
#ifndef SMM_BASE_SAVE_STATE_OFFSET
#define SMM_BASE_SAVE_STATE_OFFSET 0
#endif
#ifndef MAX_SMM_SAVE_STATE_SIZE
#define MAX_SMM_SAVE_STATE_SIZE 0
#endif
#ifndef SMM_BSP_BASE
#define SMM_BSP_BASE 0
#endif
#ifndef TSEG_SIZE
#define TSEG_SIZE 0
#endif
#ifndef PCIEX_BASE_ADDRESS
#define PCIEX_BASE_ADDRESS 0
#endif
#ifndef DYNAMIC_PCIEXBASE_SUPPORT
#define DYNAMIC_PCIEXBASE_SUPPORT 0
#endif
#ifndef DBG_WRITE_IO_SUPPORT
#define DBG_WRITE_IO_SUPPORT 0
#endif
#ifndef DBG_WRITE_IO_80_SUPPORT
#define DBG_WRITE_IO_80_SUPPORT 0
#endif

//To support send SMM Info to host
volatile UINT16 gSMIIOAddress = SW_SMI_IO_ADDRESS;
volatile UINTN gSMMBaseSaveState = SMM_BASE_SAVE_STATE_OFFSET;
volatile UINTN gSMMSaveStateSize = MAX_SMM_SAVE_STATE_SIZE;
volatile UINTN gSMMBspBase = SMM_BSP_BASE;
volatile UINTN gTsegSize = TSEG_SIZE;
//**********************************************************************

volatile UINTN gPCIEXBaseAddress = PCIEX_BASE_ADDRESS;

//EIP 80406 - Debugger support for Dynamic pci express base token
#ifdef DYNAMIC_PCIEXBASE_SUPPORT
volatile UINTN gDynamicPCIExBase = DYNAMIC_PCIEXBASE_SUPPORT;
#else
volatile UINTN gDynamicPCIExBase = 0;
#endif

volatile UINTN gDbgWriteIOSupport = DBG_WRITE_IO_SUPPORT;
volatile UINTN gDbgWriteIO80Support = DBG_WRITE_IO_80_SUPPORT;

//**********************************************************************
//<AMI_SHDR_START>
//
// Name:		PeiDbgDataSection of type PEI_DBG_DATA_SECTION
//
// Description:	The following global data structure is for relocation purpose
//				in order to support debugging after the debugger data section
//				is relocated. This second parameter of the data structure has
//				to be updated by the debugger service PEIM to point to relocated
//				data section into memory.The code section has this module
//				has to relocated before the update of second parameter.
//
//<AMI_SHDR_END>
//**********************************************************************
#if defined (PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x00010000)
PEI_DBG_DATA_SECTION PeiDbgDataSection = {	
	"DBGR",
	0		//This will be updated by debugger service PEIM
};					//after the DBgr data section is relocated to memory from CAR
#else
PEI_DBG_DATA_SECTION PeiDbgDataSection = {	
	"DBGR",
	PEI_DEBUG_DATASECTION_BASEADDRESS		//This will be updated by debugger service PEIM
};					//after the DBgr data section is relocated to memory from CAR

#endif

UINTN GetCARBaseAddress()
{
    EFI_PEI_SERVICES          **PeiServices;
    VOID *PeiDbgData; 
    EFI_GUID  mPeiDbgBasePpiGuid = EFI_PEI_DBG_BASEADDRESS_PPI_GUID;
    EFI_STATUS Status;

	if((PeiDbgDataSection.DATABASEADDRESS)==NULL)
	{
		IDTBASE 	Idtr;
		_asm{
			sidt fword ptr Idtr
		}
        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((UINTN)PeiDbgDataSection.DATABASEADDRESS);
	}
}


//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	IsDbgrInCAR
//
// Description:	Internal Helper function.
//
// Input:		none
//
// Output:		1 - yes or 0 - no (UINT32)
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
UINT32	IsDbgrInCAR()
{
#if defined (PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x00010000)
	if((PeiDbgDataSection.DATABASEADDRESS)==NULL)
#else
	if(PEI_DEBUG_DATA_BASEADDRESS == PEI_DEBUG_DATASECTION_BASEADDRESS)
#endif
		return 1;	//yes
	else
		return 0;	//no
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	IsAddrValidInCAR
//
// Description:	Internal Helper function.
//
// Input:		UINT64 Addr
//
// Output:		1 - TRUE OR 0 - FALSE (INTN)
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
INTN IsAddrValidInCAR (UINT64 Addr) {

	if (Addr >= CAR_Start_Addr && Addr <= CAR_End_Addr) 
		return(1);
	else
		return(0);
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	IsAddrValidInCode
//
// Description:	Internal Helper function.
//
// Input:		UINT64 Addr
//
// Output:		1 OR 0 (INTN)
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
INTN IsAddrValidInCode (UINT64 Addr) {

	if (Addr >= Code_Start_Addr && Addr <= Code_End_Addr) 
		return(1);
	else
		return(0);
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	Get_CAR_EndAddr
//
// Description:	Internal Helper function.
//
// Input:		none
//
// Output:		CAR_End_Addr (UINTN)
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
UINTN	Get_CAR_EndAddr()
{
	return (CAR_End_Addr);
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------
// Procedure:	Get_Code_EndAddr
//
// Description:	Internal Helper function.
//
// Input:		none
//
// Output:		Code_End_Addr (UINTN)
//
//--------------------------------------------------------------------
//<AMI_PHDR_END>
UINTN	Get_Code_EndAddr()
{
	return (Code_End_Addr);
}
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2009, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//