Re: [edk2-devel] [PATCH v2] UefiCpuPkg: Fix nasm warning "signed byte value exceeds"

2022-07-07 Thread Ni, Ray
Reviewed-by: Ray Ni 

> -Original Message-
> From: Liu, Zhiguang 
> Sent: Wednesday, July 6, 2022 9:10 PM
> To: devel@edk2.groups.io
> Cc: Liu, Zhiguang ; Dong, Eric ; 
> Ni, Ray ; Kumar,
> Rahul1 ; De, Debkumar ; Han, 
> Harry ; West,
> Catharine 
> Subject: [PATCH v2] UefiCpuPkg: Fix nasm warning "signed byte value exceeds"
> 
> Currently, "push byte %[Vector]" causes nasm warning when Vector is larger
> than 0x7F. This is because push accepts a signed value, and byte means
> signed int8. Maximum signed int8 is 0x7F.
> When Vector is larger the 0x7F, for example, when Vector is 255, byte 255
> turns to -1, and causes the warning "signed byte value exceeds".
> To avoid such warning, use dword instead of byte, this will increase 3 bytes
> for each IdtVector.
> For IA32, the size of IdtVector will increase from 10 bytes to 13 bytes.
> For X64, the size of IdtVector will increase from 15 bytes to 18 bytes.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> Cc: Debkumar De 
> Cc: Harry Han 
> Cc: Catharine West 
> Signed-off-by: Zhiguang Liu 
> ---
>  .../Library/CpuExceptionHandlerLib/CpuExceptionCommon.h   |  2 +-
>  .../CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm  |  7 +++
>  .../CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm | 11 
> +--
>  3 files changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> index 0f012bccde..fd42c4be0f 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
> @@ -22,7 +22,7 @@
> 
>  #define  CPU_EXCEPTION_NUM32
>  #define  CPU_INTERRUPT_NUM256
> -#define  HOOKAFTER_STUB_SIZE  16
> +#define  HOOKAFTER_STUB_SIZE  18
> 
>  //
>  // Exception Error Code of Page-Fault Exception
> diff --git 
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
> index 8ed2b8f455..31a00449a2 100644
> --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
> +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
> @@ -34,7 +34,7 @@ ALIGN   8
>  AsmIdtVectorBegin:
>  %assign Vector 0
>  %rep  256
> -pushbyte %[Vector];
> +pushstrict dword %[Vector];
>  pusheax
>  mov eax, ASM_PFX(CommonInterruptEntry)
>  jmp eax
> @@ -43,9 +43,8 @@ AsmIdtVectorBegin:
>  AsmIdtVectorEnd:
> 
>  HookAfterStubBegin:
> -db  0x6a; push
> +pushstrict dword 0  ; 0 will be fixed
>  VectorNum:
> -db  0  ; 0 will be fixed
>  pusheax
>  mov eax, HookAfterStubHeaderEnd
>  jmp eax
> @@ -453,5 +452,5 @@ global ASM_PFX(AsmVectorNumFixup)
>  ASM_PFX(AsmVectorNumFixup):
>  mov eax, dword [esp + 8]
>  mov ecx, [esp + 4]
> -mov [ecx + (VectorNum - HookAfterStubBegin)], al
> +mov [ecx + (VectorNum - 4 - HookAfterStubBegin)], al
>  ret
> diff --git 
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
> index 7c0e3d3b0b..9574785742 100644
> --- 
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
> +++ 
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
> @@ -57,18 +57,17 @@ ALIGN   8
>  AsmIdtVectorBegin:
>  %assign Vector 0
>  %rep  256
> -pushbyte %[Vector]
> +pushstrict dword %[Vector] ; This instruction pushes sign-extended 
> 8-byte value on stack
>  pushrax
> -mov rax, strict qword 0 ;mov rax, 
> ASM_PFX(CommonInterruptEntry)
> +mov rax, strict qword 0; mov rax, 
> ASM_PFX(CommonInterruptEntry)
>  jmp rax
>  %assign Vector Vector+1
>  %endrep
>  AsmIdtVectorEnd:
> 
>  HookAfterStubHeaderBegin:
> -db  0x6a; push
> -@VectorNum:
> -db  0  ; 0 will be fixed
> +pushstrict dword 0  ; 0 will be fixed
> +VectorNum:
>  pushrax
>  mov rax, strict qword 0 ; mov rax, HookAfterStubHeaderEnd
>  JmpAbsoluteAddress:
> @@ -478,6 +477,6 @@ ASM_PFX(AsmGetTemplateAddressMap):
>  global ASM_PFX(AsmVectorNumFixup)
>  ASM_PFX(AsmVectorNumFixup):
>  mov rax, rdx
> -mov [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al
> +mov [rcx + (VectorNum - 4 - HookAfterStubHeaderBegin)], al
>  ret
> 
> --
> 2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#91173): https://edk2.groups.io/g/devel/message/91173
Mute This Topic: https://groups.io/mt/92205812/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2] UefiCpuPkg: Fix nasm warning "signed byte value exceeds"

2022-07-06 Thread Zhiguang Liu
Currently, "push byte %[Vector]" causes nasm warning when Vector is larger
than 0x7F. This is because push accepts a signed value, and byte means
signed int8. Maximum signed int8 is 0x7F.
When Vector is larger the 0x7F, for example, when Vector is 255, byte 255
turns to -1, and causes the warning "signed byte value exceeds".
To avoid such warning, use dword instead of byte, this will increase 3 bytes
for each IdtVector.
For IA32, the size of IdtVector will increase from 10 bytes to 13 bytes.
For X64, the size of IdtVector will increase from 15 bytes to 18 bytes.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Debkumar De 
Cc: Harry Han 
Cc: Catharine West 
Signed-off-by: Zhiguang Liu 
---
 .../Library/CpuExceptionHandlerLib/CpuExceptionCommon.h   |  2 +-
 .../CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm  |  7 +++
 .../CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm | 11 +--
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
index 0f012bccde..fd42c4be0f 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
@@ -22,7 +22,7 @@
 
 #define  CPU_EXCEPTION_NUM32
 #define  CPU_INTERRUPT_NUM256
-#define  HOOKAFTER_STUB_SIZE  16
+#define  HOOKAFTER_STUB_SIZE  18
 
 //
 // Exception Error Code of Page-Fault Exception
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
index 8ed2b8f455..31a00449a2 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
@@ -34,7 +34,7 @@ ALIGN   8
 AsmIdtVectorBegin:
 %assign Vector 0
 %rep  256
-pushbyte %[Vector];
+pushstrict dword %[Vector];
 pusheax
 mov eax, ASM_PFX(CommonInterruptEntry)
 jmp eax
@@ -43,9 +43,8 @@ AsmIdtVectorBegin:
 AsmIdtVectorEnd:
 
 HookAfterStubBegin:
-db  0x6a; push
+pushstrict dword 0  ; 0 will be fixed
 VectorNum:
-db  0  ; 0 will be fixed
 pusheax
 mov eax, HookAfterStubHeaderEnd
 jmp eax
@@ -453,5 +452,5 @@ global ASM_PFX(AsmVectorNumFixup)
 ASM_PFX(AsmVectorNumFixup):
 mov eax, dword [esp + 8]
 mov ecx, [esp + 4]
-mov [ecx + (VectorNum - HookAfterStubBegin)], al
+mov [ecx + (VectorNum - 4 - HookAfterStubBegin)], al
 ret
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
index 7c0e3d3b0b..9574785742 100644
--- 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
+++ 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
@@ -57,18 +57,17 @@ ALIGN   8
 AsmIdtVectorBegin:
 %assign Vector 0
 %rep  256
-pushbyte %[Vector]
+pushstrict dword %[Vector] ; This instruction pushes sign-extended 
8-byte value on stack
 pushrax
-mov rax, strict qword 0 ;mov rax, ASM_PFX(CommonInterruptEntry)
+mov rax, strict qword 0; mov rax, ASM_PFX(CommonInterruptEntry)
 jmp rax
 %assign Vector Vector+1
 %endrep
 AsmIdtVectorEnd:
 
 HookAfterStubHeaderBegin:
-db  0x6a; push
-@VectorNum:
-db  0  ; 0 will be fixed
+pushstrict dword 0  ; 0 will be fixed
+VectorNum:
 pushrax
 mov rax, strict qword 0 ; mov rax, HookAfterStubHeaderEnd
 JmpAbsoluteAddress:
@@ -478,6 +477,6 @@ ASM_PFX(AsmGetTemplateAddressMap):
 global ASM_PFX(AsmVectorNumFixup)
 ASM_PFX(AsmVectorNumFixup):
 mov rax, rdx
-mov [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al
+mov [rcx + (VectorNum - 4 - HookAfterStubHeaderBegin)], al
 ret
 
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#9): https://edk2.groups.io/g/devel/message/9
Mute This Topic: https://groups.io/mt/92205812/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-