]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
MdeModulePkg/DriverSampleDxe: Make bit fields aligned in C structure
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / NVDataStruc.h
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 NVDataStruc.h\r
15\r
16Abstract:\r
17\r
18 NVData structure used by the sample driver\r
19\r
20Revision History:\r
21\r
22\r
23**/\r
24\r
25#ifndef _NVDATASTRUC_H_\r
26#define _NVDATASTRUC_H_\r
27\r
28#include <Guid/HiiPlatformSetupFormset.h>\r
29#include <Guid/HiiFormMapMethodGuid.h>\r
30#include <Guid/DriverSampleHii.h>\r
31#include <Guid/ZeroGuid.h>\r
32\r
33#define CONFIGURATION_VARSTORE_ID 0x1234\r
34#define BITS_VARSTORE_ID 0x2345\r
35\r
36#pragma pack(1)\r
37\r
38//\r
39// !!! For a structure with a series of bit fields and used as a storage in vfr file, and if the bit fields do not add up to the size of the defined type.\r
40// In the C code use sizeof() to get the size the strucure, the results may vary form the compiler(VS,GCC...).\r
41// But the size of the storage calculated by VfrCompiler is fixed (calculate with alignment).\r
42// To avoid above case, we need to make the total bit width in the structure aligned with the size of the defined type for these bit fields. We can:\r
43// 1. Add bit field (with/without name) with remianing with for padding.\r
44// 2. Add unnamed bit field with 0 for padding, the amount of padding is determined by the alignment characteristics of the members of the structure.\r
45//\r
46typedef struct {\r
47 UINT16 NestByteField;\r
48 UINT8 : 1; // unamed field can be used for padding\r
49 UINT8 NestBitCheckbox : 1;\r
50 UINT8 NestBitOneof : 2;\r
51 UINT8 : 0; // Special width 0 can be used to force alignment at the next word boundary\r
52 UINT8 NestBitNumeric : 4;\r
53} MY_BITS_DATA;\r
54\r
55typedef union {\r
56 UINT16 BitField : 10;\r
57 UINT8 ByteField;\r
58} MY_EFI_UNION_DATA;\r
59\r
60typedef struct {\r
61 UINT16 MyStringData[40];\r
62 UINT16 SomethingHiddenForHtml;\r
63 UINT8 HowOldAreYouInYearsManual;\r
64 UINT16 HowTallAreYouManual;\r
65 UINT8 HowOldAreYouInYears;\r
66 UINT16 HowTallAreYou;\r
67 UINT8 MyFavoriteNumber;\r
68 UINT8 TestLateCheck;\r
69 UINT8 TestLateCheck2;\r
70 UINT8 QuestionAboutTreeHugging;\r
71 UINT8 ChooseToActivateNuclearWeaponry;\r
72 UINT8 SuppressGrayOutSomething;\r
73 UINT8 OrderedList[8];\r
74 UINT16 BootOrder[8];\r
75 UINT8 BootOrderLarge;\r
76 UINT8 DynamicRefresh;\r
77 UINT8 DynamicOneof;\r
78 UINT8 DynamicOrderedList[5];\r
79 UINT8 Reserved;\r
80 EFI_HII_REF RefData;\r
81 UINT8 NameValueVar0;\r
82 UINT16 NameValueVar1;\r
83 UINT16 NameValueVar2[20];\r
84 UINT8 SerialPortNo;\r
85 UINT8 SerialPortStatus;\r
86 UINT16 SerialPortIo;\r
87 UINT8 SerialPortIrq;\r
88 UINT8 GetDefaultValueFromCallBack;\r
89 UINT8 GetDefaultValueFromAccess;\r
90 EFI_HII_TIME Time;\r
91 UINT8 RefreshGuidCount;\r
92 UINT8 Match2;\r
93 UINT8 GetDefaultValueFromCallBackForOrderedList[3];\r
94 UINT8 BitCheckbox : 1;\r
95 UINT8 ReservedBits: 7; // Reserved bit fields for padding.\r
96 UINT16 BitOneof : 6;\r
97 UINT16 : 0; // Width 0 used to force alignment.\r
98 UINT16 BitNumeric : 12;\r
99 MY_BITS_DATA MyBitData;\r
100 MY_EFI_UNION_DATA MyUnionData;\r
101} DRIVER_SAMPLE_CONFIGURATION;\r
102\r
103//\r
104// 2nd NV data structure definition\r
105//\r
106typedef struct {\r
107 UINT8 Field8;\r
108 UINT16 Field16;\r
109 UINT8 OrderedList[3];\r
110 UINT16 SubmittedCallback;\r
111} MY_EFI_VARSTORE_DATA;\r
112\r
113//\r
114// 3rd NV data structure definition\r
115//\r
116typedef struct {\r
117 MY_BITS_DATA BitsData;\r
118 UINT32 EfiBitGrayoutTest : 5;\r
119 UINT32 EfiBitNumeric : 4;\r
120 UINT32 EfiBitOneof : 10;\r
121 UINT32 EfiBitCheckbox : 1;\r
122 UINT32 : 0; // Width 0 used to force alignment.\r
123} MY_EFI_BITS_VARSTORE_DATA;\r
124\r
125//\r
126// Labels definition\r
127//\r
128#define LABEL_UPDATE1 0x1234\r
129#define LABEL_UPDATE2 0x2234\r
130#define LABEL_UPDATE3 0x3234\r
131#define LABEL_END 0x2223\r
132\r
133#pragma pack()\r
134\r
135#endif\r