Skip to contentSkip to conversation

: ACPI: preserve the ebx value in acpi_copy_wakeup_routine

PATCH In review Zhang Rui 2 participants 4 messages Jun 1, 2007 – Jun 4, 2007 ACPI

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

PATCH 1/1 : ACPI: preserve the ebx value in acpi_copy_wakeup_routine

From: Tian Kevin <[email protected]>

Register %ebx serves as the "global offset table base register" for position-independent code. For absolute code, %ebx serves as a local register and has no specified role in the function calling sequence. In either case, a function must preserve the register value for the caller.

acpi_copy_wakeup_routine overrides %ebx without saving it, this may corrupt the called data.

Kevin found that most time the value of Sx is saved in %esi, however sometimes compiler also uses %ebx. When this happens, suspends fails since sleep value in ebx is changed by acpi_copy_wakeup_routine.

The same funtion in X86_64 doesn't have this problem.

---
 arch/i386/kernel/acpi/wakeup.S |    2 ++
 1 files changed, 2 insertions(+)
arch/i386/kernel/acpi/wakeup.S +2 -0
Index: linux-2.6.22-rc3/arch/i386/kernel/acpi/wakeup.S
===================================================================
@@ -230,6 +230,7 @@ bogus_magic:
 #
 ENTRY(acpi_copy_wakeup_routine)
 
+	pushl	%ebx
 	sgdt	saved_gdt
 	sidt	saved_idt
 	sldt	saved_ldt
@@ -263,6 +264,7 @@ ENTRY(acpi_copy_wakeup_routine)
 	movl	%edx, video_flags - wakeup_start (%eax)
 	movl	$0x12345678, real_magic - wakeup_start (%eax)
 	movl	$0x12345678, saved_magic
+	popl	%ebx
 	ret
 
 save_registers:
#1 lore raw

Hi!

Quoted 11 lines

From: Tian Kevin <[email protected]>

Register %ebx serves as the "global offset table base register" for position-independent code. For absolute code, %ebx serves as a local register and has no specified role in the function calling sequence. In either case, a function must preserve the register value for the caller.

acpi_copy_wakeup_routine overrides %ebx without saving it, this may corrupt the called data.

Quoted 8 lines

Kevin found that most time the value of Sx is saved in %esi, however sometimes compiler also uses %ebx. When this happens, suspends fails since sleep value in ebx is changed by acpi_copy_wakeup_routine.

The same funtion in X86_64 doesn't have this problem.

Looks okay to me. That routine also corrupts ecx and edx, hopefully that's okay?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#2 lore raw

According to the SYSTEM V APPLICATION BINARY INTERFACE,
Intel386 Architecture:
"ecx and edx: Scratch registers have no specified role in the standard calling sequence. Functions do not have to preserve their values for the caller."

Best regards,
Zhang.Rui(Ray)

-----Original Message-----
From: Pavel Machek [mailto:[email protected]]
Sent: 2007年6月1日 18:17
To: Zhang, Rui
Cc: [email protected]; [email protected]; Tian, Kevin
Subject: Re: [PATCH]: ACPI: preserve the ebx value in acpi_copy_wakeup_routine

Hi!

Quoted 11 lines

From: Tian Kevin <[email protected]>

Register %ebx serves as the "global offset table base register" for position-independent code. For absolute code, %ebx serves as a local register and has no specified role in the function calling sequence. In either case, a function must preserve the register value for the caller.

acpi_copy_wakeup_routine overrides %ebx without saving it, this may corrupt the called data.

Quoted 8 lines

Kevin found that most time the value of Sx is saved in %esi, however sometimes compiler also uses %ebx. When this happens, suspends fails since sleep value in ebx is changed by acpi_copy_wakeup_routine.

The same funtion in X86_64 doesn't have this problem.

Looks okay to me. That routine also corrupts ecx and edx, hopefully that's okay?
Pavel

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Hi!

Quoted 5 lines

According to the SYSTEM V APPLICATION BINARY INTERFACE,
Intel386 Architecture:
"ecx and edx: Scratch registers have no specified role in the standard calling sequence. Functions do not have to preserve their values for the caller."

Thanks for confirming.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html