Replace manual alignment checks with IS_ALIGNED() and
ADDRESS_IS_ALIGNED().
Convert the following bitmask and modulo forms:
- ((E & ((PowOf2Expr) - ONE)) == ZERO)
- ((E & ((PowOf2Expr) - ONE)) != ZERO)
- ((E % (PowOf2Expr)) == ZERO)
- ((E % (PowOf2Expr)) != ZERO)
to the corresponding helper macro forms:
+ IS_ALIGNED (E, PowOf2Expr)
+ !IS_ALIGNED (E, PowOf2Expr)
PowOf2Expr is limited to known power-of-two expressions, including
SIZE_* and BASE_* macros, EFI_PAGE_SIZE, CPU_STACK_ALIGNMENT,
RUNTIME_PAGE_ALLOCATION_GRANULARITY, sizeof() of UEFI integer types
(e.g. BOOLEAN, CHAR16, UINT32, UINTN) and pointer types, and 1 << E1
expressions.
Address checks that cast the checked value to UINTN are written with
ADDRESS_IS_ALIGNED().
The change was generated with the Coccinelle semantic patch below.
```smpl
@power_of_2_expr@
expression PowOf2Expr;
expression E1;
typedef BOOLEAN, CHAR8, CHAR16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, INTN, UINTN;
type ScalarType = { BOOLEAN, CHAR8, CHAR16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, INTN, UINTN };
type AnyType;
type PointerType = AnyType *;
idexpression ScalarType ScalarValue;
idexpression PointerType PointerValue;
constant SizeBase =~ "^(SIZE|BASE)_(1|2|4|8|16|32|64|128|256|512)[KMGTPE]B$";
constant NamedPowerOf2 =~ "^(EFI_PAGE_SIZE|CPU_STACK_ALIGNMENT|RUNTIME_PAGE_ALLOCATION_GRANULARITY)$";
constant ONE = {1, 1U, 1u};
@@
(
(
SizeBase
|
NamedPowerOf2
|
ONE << E1
|
sizeof (ScalarType)
|
sizeof (PointerType)
|
sizeof (ScalarValue)
|
sizeof (PointerValue)
)
&
PowOf2Expr
)
@aligned depends on power_of_2_expr disable is_zero,isnt_zero@
expression E;
expression power_of_2_expr.PowOf2Expr;
constant ONE = {1, 1U, 1u};
constant ZERO = {0, 0U, 0u};
@@
(
((E & (E - ONE)) == ZERO)
|
- ((E & ((PowOf2Expr) - ONE)) == ZERO)
+ IS_ALIGNED (E, PowOf2Expr)
|
((E & (E - ONE)) != ZERO)
|
- ((E & ((PowOf2Expr) - ONE)) != ZERO)
+ !IS_ALIGNED (E, PowOf2Expr)
|
- ((E % (PowOf2Expr)) == ZERO)
+ IS_ALIGNED (E, PowOf2Expr)
|
- ((E % (PowOf2Expr)) != ZERO)
+ !IS_ALIGNED (E, PowOf2Expr)
)
@address_is_aligned@
typedef UINTN;
expression *Address;
expression Alignment;
@@
- IS_ALIGNED ((UINTN) Address, Alignment)
+ ADDRESS_IS_ALIGNED (Address, Alignment)
@normalize_aligned disable paren expression@
expression E, SZ;
@@
(
- (IS_ALIGNED (E, SZ))
+ IS_ALIGNED (E, SZ)
|
- (!IS_ALIGNED (E, SZ))
+ !IS_ALIGNED (E, SZ)
)
@normalize_macro_args disable paren expression@
expression E, SZ;
@@
(
- IS_ALIGNED ((E), SZ)
+ IS_ALIGNED (E, SZ)
|
- IS_ALIGNED (E, (SZ))
+ IS_ALIGNED (E, SZ)
)
```
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
|
||
|---|---|---|
| .. | ||
| Application/RedfishPlatformConfig | ||
| AutoScanPei | ||
| BootModePei | ||
| CpuRuntimeDxe | ||
| EmuBlockIoDxe | ||
| EmuBusDriverDxe | ||
| EmuGopDxe | ||
| EmuSimpleFileSystemDxe | ||
| EmuSnpDxe | ||
| EmuThunkDxe | ||
| FirmwareVolumePei | ||
| FlashMapPei | ||
| FvbServicesRuntimeDxe | ||
| Include | ||
| Library | ||
| PlatformCI | ||
| PlatformSmbiosDxe | ||
| RealTimeClockRuntimeDxe | ||
| ResetRuntimeDxe | ||
| Sec | ||
| ThunkPpiToProtocolPei | ||
| TimerDxe | ||
| Unix | ||
| Win | ||
| build.sh | ||
| EmulatorPkg.ci.yaml | ||
| EmulatorPkg.dec | ||
| EmulatorPkg.dsc | ||
| EmulatorPkg.fdf | ||
| Readme.md | ||
Overview
EmulatorPkg provides an environment where a UEFI environment can be emulated under an environment where a full UEFI compatible environment is not possible. (For example, running under an OS where an OS process hosts the UEFI emulation environment.)
https://github.com/tianocore/tianocore.github.io/wiki/EmulatorPkg
Status
- Builds and runs under
- a posix-like environment with X windows
- Linux
- OS X
- Windows environment
- Win10 (verified)
- Win8 (not verified)
- a posix-like environment with X windows
How to Build & Run
You can use the following command to build.
-
32bit emulator in Windows:
build -p EmulatorPkg\EmulatorPkg.dsc -t VS2022 -a IA32 -
64bit emulator in Windows:
build -p EmulatorPkg\EmulatorPkg.dsc -t VS2022 -a X64 -
32bit emulator in Linux:
build -p EmulatorPkg\EmulatorPkg.dsc -t GCC -a IA32 -
64bit emulator in Linux:
build -p EmulatorPkg\EmulatorPkg.dsc -t GCC -a X64
You can start/run the emulator using the following command:
-
32bit emulator in Windows:
cd Build\EmulatorIA32\DEBUG_VS2022\IA32\ && WinHost.exe -
64bit emulator in Windows:
cd Build\EmulatorX64\DEBUG_VS2022\X64\ && WinHost.exe -
32bit emulator in Linux:
cd Build/EmulatorIA32/DEBUG_GCC/IA32/ && ./Host -
64bit emulator in Linux:
cd Build/EmulatorX64/DEBUG_GCC/X64/ && ./Host
On posix-like environment with the bash shell you can use EmulatorPkg/build.sh to simplify building and running emulator.
For example, to build + run:
$ EmulatorPkg/build.sh
$ EmulatorPkg/build.sh run
The build architecture will match your host machine's architecture.
On X64 host machines, you can build + run IA32 mode as well:
$ EmulatorPkg/build.sh -a IA32
$ EmulatorPkg/build.sh -a IA32 run