factor out common s2ram wakeup code
Subsystems (4)
It seems to compile 32/64bit, and work 32bit... Now, video code should be probably shared with kernel/boot; but that was rewritten to C and I'm not sure if I know enough about linkers... basically the C code should replace mode_set() and friends. Peter, can you help?
Pavel
---
Factor out common real-mode part of wakeup_{32,64}.S.
---
commit 2fac1886274433c64e76611e6b1ba2318c5914a4
tree 2d6bdc7c2eda9845b57e1d7128b187df1b1fd2c9
parent 7a9546efcc4d90040a52c003eb9a303200c41f86
author Pavel <[email protected]> Tue, 22 Jan 2008 20:34:03 +0100 committer Pavel <[email protected]> Tue, 22 Jan 2008 20:34:03 +0100
arch/x86/kernel/acpi/wakeup.S | 111 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/acpi/wakeup_32.S | 118 +----------------------------------- arch/x86/kernel/acpi/wakeup_64.S | 125 +------------------------------------- 3 files changed, 116 insertions(+), 238 deletions(-)
arch/x86/kernel/acpi/wakeup.S new file +111 -0
@@ -0,0 +1,111 @@ +# Copyright 2003, 2008 Pavel Machek <[email protected]>, distribute under GPLv2 + +#define BEEP \ + inb $97, %al; \ + outb %al, $0x80; \ + movb $3, %al; \ + outb %al, $97; \ + outb %al, $0x80; \ + movb $-74, %al; \ + outb %al, $67; \ + outb %al, $0x80; \ + movb $-119, %al; \ + outb %al, $66; \ + outb %al, $0x80; \ + movb $15, %al; \ + outb %al, $66; + +ALIGN + .align 4096 +ENTRY(wakeup_start) +wakeup_code: + wakeup_code_start = . + .code16 + + cli + cld + + # setup data segment + movw %cs, %ax + movw %ax, %ds # Make ds:0 point to wakeup_start + movw %ax, %ss + + testl $4, realmode_flags - wakeup_code + jz 1f + BEEP +1: + mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board + + pushl $0 # Kill any dangerous flags + popfl + + + movl real_magic - wakeup_code, %eax + cmpl $0x12345678, %eax + jne bogus_real_magic + + testl $1, realmode_flags - wakeup_code + jz 1f + lcall $0xc000,$3 + movw %cs, %ax + movw %ax, %ds # Bios might have played with that + movw %ax, %ss +1: + + testl $2, realmode_flags - wakeup_code + jz mode_done + mov video_mode - wakeup_code, %ax + call mode_set + jmp mode_done + +/* This code uses an extended set of video mode numbers. These include: + * Aliases for standard modes + * NORMAL_VGA (-1) + * EXTENDED_VGA (-2) + * ASK_VGA (-3) + * Video modes numbered by menu position -- NOT RECOMMENDED because of lack + * of compatibility when extending the table. These are between 0x00 and 0xff. + */ +#define VIDEO_FIRST_MENU 0x0000 + +/* Standard BIOS video modes (BIOS number + 0x0100) */ +#define VIDEO_FIRST_BIOS 0x0100 + +/* VESA BIOS video modes (VESA number + 0x0200) */ +#define VIDEO_FIRST_VESA 0x0200 + +/* Video7 special modes (BIOS number + 0x0900) */ +#define VIDEO_FIRST_V7 0x0900 + +# Setting of user mode (AX=mode ID) => CF=success + +# For now, we only handle VESA modes (0x0200..0x03ff). To handle other +# modes, we should probably compile in the video code from the boot +# directory. +.code16 +mode_set: + movw %ax, %bx + subb $VIDEO_FIRST_VESA>>8, %bh + cmpb $2, %bh + jb check_vesa + +setbad: + clc + ret + +check_vesa: + orw $0x4000, %bx # Use linear frame buffer + movw $0x4f02, %ax # VESA BIOS mode set call + int $0x10 + cmpw $0x004f, %ax # AL=4f if implemented + jnz setbad # AH=0 if OK + + stc + ret + +bogus_real_magic: + jmp bogus_real_magic + +real_magic: .quad 0 +video_mode: .quad 0 +realmode_flags: .quad 0
arch/x86/kernel/acpi/wakeup_32.S +3 -115
136 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +2 -123
144 lines not on this page · raw message
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
H. Peter Anvin
reviewerQuoted 4 lines · Pavel Machek
It seems to compile 32/64bit, and work 32bit... Now, video code should be probably shared with kernel/boot; but that was rewritten to C and I'm not sure if I know enough about linkers... basically the C code should replace
mode_set()and friends. Peter, can you help?
Yes, absolutely. I think we should probably segregate out into a subdirectory the part of the code that should be run in 16-bit mode, and then it's just a matter of pretty much replicating the mechanisms used in arch/x86/boot.
How can I best be of help?
-hpa
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
(Lists added back to CC, I dropped them by mistake).
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
Quoted 4 lines
It seems to compile 32/64bit, and work 32bit... Now, video code should be probably shared with kernel/boot; but that was rewritten to C and I'm not sure if I know enough about linkers... basically the C code should replace
mode_set()and friends. Peter, can you help?Yes, absolutely. I think we should probably segregate out into a subdirectory the part of the code that should be run in 16-bit mode, and then it's just a matter of pretty much replicating the mechanisms used in
arch/x86/boot.I'd basically need second copy of bootup code, placed into page with
wakeup_code. I guess I could let gcc compile .c into .s , and then include that... but perhaps there is better way?Quoted 1 line
How can I best be of help?
Quoted 8 lines
Quoted 2 lines
Teach me how to include .c into
wakeup.S. I should be able to figure the rest...Yes, there is a better way.
The biggest question is if your 16-bit code needs to touch symbols in the 32/64-bit code, or vice versa. That complicates things a little bit, obviously.
The code is in arch/x86/kernel/acpi/wakeup_32.S
. acpi_copy_wakeup_routine needs to know offsets within 16-bit code. I'd like to somehow call code from arch/x86/boot/video*.c ... current version just took (old) .S code, and cut&paste-s it.
Quoted 9 lines
If not, the easiest way is to link the 16-bit code into a separate binary (including both assembly and C code) which can then be included in the kernel proper as a binary blob. If it *does* need to reference outside symbols, then it needs to be part of the overall link, which means mucking with the top-level link script.
That's obviously more complex.Either way, the
Makefilebit of this will be a lot easier if we move the 16-bit code into a separate directory.
I only need arch/x86/boot/video*.c ...
Quoted 2 lines
Let me know which way you think makes more sense, and I can send you a framework patch.
I need to access data in that 16-bit code...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
H. Peter Anvin
reviewerQuoted 7 lines · Pavel Machek
Quoted 2 lines
The biggest question is if your 16-bit code needs to touch symbols in the 32/64-bit code, or vice versa. That complicates things a little bit, obviously.
The code is in
arch/x86/kernel/acpi/wakeup_32.S
.acpi_copy_wakeup_routineneeds to know offsets within 16-bit code. I'd like to somehow call code fromarch/x86/boot/video*.c... current version just took (old) .S code, and cut&paste-s it.
Right, I know.
Quoted 10 lines
Quoted 4 lines
If not, the easiest way is to link the 16-bit code into a separate binary (including both assembly and C code) which can then be included in the kernel proper as a binary blob. If it *does* need to reference outside symbols, then it needs to be part of the overall link, which means mucking with the top-level link script. That's obviously more complex.
Either way, the
Makefilebit of this will be a lot easier if we move the 16-bit code into a separate directory.I only need
arch/x86/boot/video*.c...Quoted 1 line
Let me know which way you think makes more sense, and I can send you a framework patch.
I need to access data in that 16-bit code...
Would a shared structure be OK for that? That's easier than dealing with symbols.
-hpa
Quoted 26 lines · H. Peter Anvin
Quoted 10 lines · Pavel Machek
Quoted 4 lines
The biggest question is if your 16-bit code needs to touch symbols in the 32/64-bit code, or vice versa. That complicates things a little bit, obviously.
The code is in
arch/x86/kernel/acpi/wakeup_32.S
.acpi_copy_wakeup_routineneeds to know offsets within 16-bit code. I'd like to somehow call code fromarch/x86/boot/video*.c
... current version just took (old) .S code, and cut&paste-s it.Right, I know.
Quoted 12 lines
Quoted 9 lines
If not, the easiest way is to link the 16-bit code into a separate binary (including both assembly and C code) which can then be included in the kernel proper as a binary blob. If it *does* need to reference outside symbols, then it needs to be part of the overall link, which means mucking with the top-level link script.
That's obviously more complex.Either way, the
Makefilebit of this will be a lot easier if we move the 16-bit code into a separate directory.I only need
arch/x86/boot/video*.c...
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Let me know which way you think makes more sense, and I can send you a framework patch.
I need to access data in that 16-bit code...
Would a shared structure be OK for that? That's easier than dealing with symbols.
Shared structure would be okay, plus I need pointer to beggining and end of code so that I can copy it to lowmem.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
H. Peter Anvin
reviewerQuoted 4 lines · Pavel Machek
Shared structure would be okay, plus I need pointer to beggining and end of code so that I can copy it to lowmem.
Pavel
OK, that's easy.
-hpa
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 2 lines
Here is a patch which at least compiles (but doesn't link, since the interface to the higher-level ACPI code needs to be adjusted).
Thanks a lot!
Here is patch that seems to work a bit... video settings are hardcoded at mode 6 for now.
Pavel
arch/x86/boot/Makefile +2 -1
@@ -30,7 +30,8 @@ subdir- := compressed setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o setup-y += header.o main.o mca.o memory.o pm.o pmjump.o -setup-y += printf.o string.o tty.o video.o version.o voyager.o +setup-y += printf.o string.o tty.o video.o video-mode.o +setup-y += version.o voyager.o # The link order of the video-*.o modules can matter. In particular, # video-vga.o *must* be listed first, followed by video-vesa.o.
arch/x86/boot/boot.h +5 -0
@@ -285,6 +285,11 @@ int getchar_timeout(void);/* video.c */ void set_video (void ); +/* video-mode.c */ +int set_mode (u16 mode); +int mode_defined (u16 mode); +void probe_cards (int unsafe); +/* video-vesa.c */ void vesa_store_edid (void );
arch/x86/boot/video-bios.c +6 -0
@@ -50,6 +50,7 @@ static int set_bios_mode(u8 mode)if (new_mode == mode)return 0 ;/* Mode change OK */ +#ifndef _WAKEUPif (new_mode != boot_params.screen_info.orig_video_mode) {/* Mode setting failed, but we didn't end up where we started. That's bad. Try to revert to the original
@@ -59,13 +60,18 @@ static int set_bios_mode(u8 mode) : "+a" (ax) : : "ebx", "ecx", "edx", "esi", "edi"); } +#endif return -1 ; }static int bios_probe (void ) {u8 mode; +#ifdef _WAKEUP +u8 saved_mode =0x03 ; +#else u8 saved_mode = boot_params.screen_info.orig_video_mode; +#endif u16 crtc;struct mode_info *mi;int nmodes =0 ;
arch/x86/boot/video-mode.c new file +173 -0
173 lines not on this page · raw message
arch/x86/boot/video-vesa.c +8 -0
@@ -152,7 +152,9 @@ static int vesa_set_mode(struct mode_inf do_restore =1 ; }else {/* Graphics mode */ +#ifndef _WAKEUPvesa_store_mode_params_graphics (); +#endif }return 0 ;
@@ -179,6 +181,7 @@ static void vesa_dac_set_8bits(void) }/* Set the color sizes to the DAC size, and offsets to 0 */ +#ifndef _WAKEUP boot_params.screen_info.red_size = dac_size; boot_params.screen_info.green_size = dac_size; boot_params.screen_info.blue_size = dac_size;
@@ -188,8 +191,11 @@ static void vesa_dac_set_8bits(void) boot_params.screen_info.green_pos =0 ; boot_params.screen_info.blue_pos =0 ; boot_params.screen_info.rsvd_pos =0 ; +#endif } +#ifndef _WAKEUP +/* Save the VESA protected mode info */ static void vesa_store_pm_info (void ) {
@@ -282,6 +288,8 @@ #ifdef CONFIG_FIRMWARE_EDID#endif /* CONFIG_FIRMWARE_EDID */ } +#endif /* not _WAKEUP */ +__videocard video_vesa = { .card_name ="VESA" ,
arch/x86/boot/video-vga.c +10 -2
@@ -210,6 +210,8 @@ static int vga_set_mode(struct mode_info*/ static int vga_probe (void ) { +u16 ega_bx; +static const char *card_name[] = {"CGA/MDA/HGC" ,"EGA" ,"VGA" };
@@ -226,12 +228,16 @@ static int vga_probe(void)u8 vga_flag; asm(INT10 - : "=b" (boot_params.screen_info.orig_video_ega_bx) + : "=b" (ega_bx) : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */ : "ecx", "edx", "esi", "edi"); +#ifndef _WAKEUP + boot_params.screen_info.orig_video_ega_bx = ega_bx; +#endif +/* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ -if ((u8 )boot_params.screen_info.orig_video_ega_bx !=0x10 ) { +if ((u8 )ega_bx !=0x10 ) {/* EGA/VGA */ asm(INT10 : "=a" (vga_flag)
@@ -240,7 +246,9 @@ static int vga_probe(void)if (vga_flag ==0x1a ) { adapter =ADAPTER_VGA ; +#ifndef _WAKEUP boot_params.screen_info.orig_video_isVGA =1 ; +#endif }else { adapter =ADAPTER_EGA ; }
arch/x86/boot/video.c +0 -156
168 lines not on this page · raw message
arch/x86/kernel/acpi/Makefile +8 -1
@@ -1,7 +1,14 @@ +subdir- := rm + obj-$(CONFIG_ACPI) += boot.o -obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_$(BITS).o +obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup_rm.o wakeup_$(BITS).o ifneq ($(CONFIG_ACPI_PROCESSOR),) obj-y += cstate.o processor.o endif +$(obj)/wakeup_rm.o: $(obj)/rm/wakeup.bin + +$(obj)/rm/wakeup.bin: FORCE + $(Q)$(MAKE) $(build)=$(obj)/rm $@ +
arch/x86/kernel/acpi/rm/Makefile new file +55 -0
55 lines not on this page · raw message
arch/x86/kernel/acpi/rm/copy.S new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/copy.S"
arch/x86/kernel/acpi/rm/video-bios.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-bios.c"
arch/x86/kernel/acpi/rm/video-mode.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-mode.c"
arch/x86/kernel/acpi/rm/video-vesa.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vesa.c"
arch/x86/kernel/acpi/rm/video-vga.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../boot/video-vga.c"
arch/x86/kernel/acpi/rm/wakemain.c new file +18 -0
@@ -0,0 +1,18 @@ +#include "wakeup.h" +#include "boot.h" + +extern struct wakeup_header wakeup_header; + +void main (void ) +{ + asmvolatile ("lcallw $0xc000,$3; movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss" ); + +// asm volatile("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66"); + +/* Need to call BIOS */ +probe_cards (0 ); +// set_mode(wakeup_header.video_mode); +set_mode (6 ); + +/* Set up GDT and IDT here, possibly CR4 and EFER */ +}
arch/x86/kernel/acpi/rm/wakeup.S new file +129 -0
129 lines not on this page · raw message
arch/x86/kernel/acpi/rm/wakeup.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Definitions for the wakeup data structure at the head of the +* wakeup code. +*/ + +#ifndef ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H +#define ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H + +#include <linux/types.h> + +/* This must match data at wakeup.S */ +struct wakeup_header { +u16 entry;/* 16-bit entry point */ +u16 total;/* Total number of bytes consumed */ +u16 video_mode;/* Video mode number */ +u16 _jmp1; +u32 pmode_entry;/* Protected mode resume point */ +u16 _jmp2; +u32 pmode_cr0;/* Protected mode cr0 */ +u32 pmode_cr3;/* Protected mode cr3 */ +u32 pmode_cr4;/* Protected mode cr4 */ +u32 pmode_efer_low;/* Protected mode EFER */ +u32 pmode_efer_high; +u64 pmode_gdt; +u32 signature;/* To check we have correct structure */ +u32 real_magic; +} __attribute__((__packed__ )); + +#endif /* ARCH_X86_KERNEL_ACPI_RM_WAKEUP_H */
arch/x86/kernel/acpi/rm/wakeup.ld new file +50 -0
50 lines not on this page · raw message
arch/x86/kernel/acpi/sleep.c +52 -9
94 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup.S +0 -93
97 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_32.S +5 -98
124 lines not on this page · raw message
arch/x86/kernel/acpi/wakeup_64.S +2 -3
@@ -181,10 +181,10 @@ ENTRY(wakeup_end) ## # acpi_copy_wakeup_routine # -# Copy the above routine to low memory. +# Name is misleading, copy is actually done in C, this just fixups it. # # Parameters: -# %rdi: place to copy wakeup routine to +# %rdi: place to fixup wakeup routine at # # Returned address is location of code in low memory (past data and stack) #
@@ -209,7 +209,6 @@ ENTRY(acpi_copy_wakeup_routine) # restore the regs we used popq %rdx popq %rax -ENTRY(do_suspend_lowlevel_s4bios) ret .align 2
arch/x86/kernel/acpi/wakeup_rm.S new file +10 -0
@@ -0,0 +1,10 @@ +/* + * Wrapper script for the realmode binary as a transport object + * before copying to low memory. + */ + .section ".rodata","a" + .globl wakeup_code_start, wakeup_code_end +wakeup_code_start: + .incbin "arch/x86/kernel/acpi/rm/wakeup.bin" +wakeup_code_end: + .size wakeup_code_start, .-wakeup_code_start
drivers/acpi/sleep/main.c +1 -1
@@ -139,7 +139,7 @@ static int acpi_pm_enter(suspend_state_tbreak ; } -/* ACPI 3.0 specs (P62) says that it's the responsabilty +/* ACPI 3.0 specs (P62) says that it's the responsibilty * of the OSPM to clear the status bit [ implying that the * POWER_BUTTON event should not reach userspace ] */
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
H. Peter Anvin
reviewerQuoted 14 lines · Pavel Machek
arch/x86/kernel/acpi/rm/wakemain.c new file +8
-0@@ -0,0 +1,18 @@ +#include "wakeup.h" +#include "boot.h" + +extern struct wakeup_header wakeup_header; + +void main (void ) +{ + asmvolatile ("lcallw $0xc000,$3; movw %cs, %ax; movw %ax, %ds; movw %ax, %es; movw %ax, %ss" );
arch/x86/kernel/acpi/rm/wakemain.c line 18
Quoted 10 lines
arch/x86/kernel/acpi/rm/wakemain.c new file +10
-0+ +// asm volatile("inb $97, %al; outb %al, $0x80; movb $3, %al; outb %al, $97; outb %al, $0x80; movb $-74, %al; outb %al, $67; outb %al, $0x80; movb $-119, %al; outb %al, $66; outb %al, $0x80; movb $15, %al; outb %al, $66"); + +/* Need to call BIOS */ +probe_cards (0 ); +// set_mode(wakeup_header.video_mode); +set_mode (6 ); + +/* Set up GDT and IDT here, possibly CR4 and EFER */ +}
Surely this needs some cleaning up? ;)
Quoted 18 lines
arch/x86/kernel/acpi/rm/wakeup.S new file +12
-0@@ -0,0 +1,129 @@ +/* + * ACPI wakeup real mode startup stub + */ +#include <asm/segment.h> +#include <asm/msr-index.h> + + +#define BEEP \ + inb $97, %al; \ + outb %al, $0x80; \ + movb $3, %al; \ + outb %al, $97; \
arch/x86/kernel/acpi/rm/wakeup.S line 22
Quoted 10 lines
arch/x86/kernel/acpi/rm/wakeup.S new file +10
-0+ outb %al, $0x80; \ + movb $-74, %al; \ + outb %al, $67; \ + outb %al, $0x80; \ + movb $-119, %al; \ + outb %al, $66; \ + outb %al, $0x80; \ + movb $15, %al; \ + outb %al, $66; +
BEEP isn't actually used here and should probably be a C function if needed. Note: in real mode you can also produce a beep by calling int $0x10 with %ax = 0x0e07. Please note that some int $0x10 implementations clobber certain registers... see the INT10 macro in the bootup code.
Seriously cool, though, that you're getting this far.
-hpa
Quoted 2 lines · Pavel Machek
It seems to compile 32/64bit, and work 32bit...
It also works on a 64-bit system.
Thanks,
Rafael
Quoted 428 lines
---
Factor out common real-mode part of wakeup_{32,64}.S.
Signed-off-by Pavel Machek <[email protected]>---
commit2fac1886274433c64e76611e6b1ba2318c5914a4
tree2d6bdc7c2eda9845b57e1d7128b187df1b1fd2c9
parent7a9546efcc4d90040a52c003eb9a303200c41f86
author Pavel <[email protected]> Tue, 22 Jan 2008 20:34:03 +0100 committer Pavel <[email protected]> Tue, 22 Jan 2008 20:34:03 +0100arch/x86/kernel/acpi/wakeup.S | 111 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/acpi/wakeup_32.S | 118 +----------------------------------- arch/x86/kernel/acpi/wakeup_64.S | 125 +------------------------------------- 3 files changed, 116 insertions(+), 238 deletions(-)arch/x86/kernel/acpi/wakeup.S new file +111
-0@@ -0,0 +1,111 @@ +# Copyright 2003, 2008 Pavel Machek <[email protected]>, distribute under GPLv2 + +#define BEEP \ + inb $97, %al; \ + outb %al, $0x80; \ + movb $3, %al; \ + outb %al, $97; \ + outb %al, $0x80; \ + movb $-74, %al; \ + outb %al, $67; \ + outb %al, $0x80; \ + movb $-119, %al; \ + outb %al, $66; \ + outb %al, $0x80; \ + movb $15, %al; \ + outb %al, $66; + +ALIGN + .align 4096 +ENTRY(wakeup_start) +wakeup_code: + wakeup_code_start = . + .code16 + + cli + cld + + # setup data segment + movw %cs, %ax + movw %ax, %ds # Make ds:0 point to wakeup_start + movw %ax, %ss + + testl $4, realmode_flags - wakeup_code + jz 1f + BEEP +1: + mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board + + pushl $0 # Kill any dangerous flags + popfl + + + movl real_magic - wakeup_code, %eax + cmpl $0x12345678, %eax + jne bogus_real_magic + + testl $1, realmode_flags - wakeup_code + jz 1f + lcall $0xc000,$3 + movw %cs, %ax + movw %ax, %ds # Bios might have played with that + movw %ax, %ss +1: + + testl $2, realmode_flags - wakeup_code + jz mode_done + mov video_mode - wakeup_code, %ax + call mode_set + jmp mode_done + +/* This code uses an extended set of video mode numbers. These include: + * Aliases for standard modes + * NORMAL_VGA (-1) + * EXTENDED_VGA (-2) + * ASK_VGA (-3) + * Video modes numbered by menu position -- NOT RECOMMENDED because of lack + * of compatibility when extending the table. These are between 0x00 and 0xff. + */ +#define VIDEO_FIRST_MENU 0x0000 + +/* Standard BIOS video modes (BIOS number + 0x0100) */ +#define VIDEO_FIRST_BIOS 0x0100 + +/* VESA BIOS video modes (VESA number + 0x0200) */ +#define VIDEO_FIRST_VESA 0x0200 + +/* Video7 special modes (BIOS number + 0x0900) */ +#define VIDEO_FIRST_V7 0x0900 + +# Setting of user mode (AX=mode ID) => CF=success + +# For now, we only handle VESA modes (0x0200..0x03ff). To handle other +# modes, we should probably compile in the video code from the boot +# directory. +.code16 +mode_set: + movw %ax, %bx + subb $VIDEO_FIRST_VESA>>8, %bh + cmpb $2, %bh + jb check_vesa + +setbad: + clc + ret + +check_vesa: + orw $0x4000, %bx # Use linear frame buffer + movw $0x4f02, %ax # VESA BIOS mode set call + int $0x10 + cmpw $0x004f, %ax # AL=4f if implemented + jnz setbad # AH=0 if OK + + stc + ret + +bogus_real_magic: + jmp bogus_real_magic + +real_magic: .quad 0 +video_mode: .quad 0 +realmode_flags: .quad 0arch/x86/kernel/acpi/wakeup_32.S +3
-115@@ -3,73 +3,11 @@ #include <linux/linkage.h> #include <asm/segment.h> #include <asm/page.h> -# -# wakeup_code runs in real mode, and at unknown address (determined at run-time). -# Therefore it must only use relative jumps/calls. -# -# Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled -# -# If physical address of wakeup_code is 0x12345, BIOS should call us with -# cs = 0x1234, eip = 0x05 -# - -#define BEEP \ - inb $97, %al; \ - outb %al, $0x80; \ - movb $3, %al; \ - outb %al, $97; \ - outb %al, $0x80; \ - movb $-74, %al; \ - outb %al, $67; \ - outb %al, $0x80; \ - movb $-119, %al; \ - outb %al, $66; \ - outb %al, $0x80; \ - movb $15, %al; \ - outb %al, $66; - -ALIGN - .align 4096 -ENTRY(wakeup_start) -wakeup_code: - wakeup_code_start = . - .code16 - - cli - cld - - # setup data segment - movw %cs, %ax - movw %ax, %ds # Make ds:0 point to wakeup_start - movw %ax, %ss - - testl $4, realmode_flags - wakeup_code - jz 1f - BEEP -1: - mov $(wakeup_stack - wakeup_code), %sp # Private stack is needed for ASUS board +# Copyright 2003, 2008 Pavel Machek <[email protected]>, distribute under GPLv2 - pushl $0 # Kill any dangerous flags - popfl - - movl real_magic - wakeup_code, %eax - cmpl $0x12345678, %eax - jne bogus_real_magic - - testl $1, realmode_flags - wakeup_code - jz 1f - lcall $0xc000,$3 - movw %cs, %ax - movw %ax, %ds # Bios might have played with that - movw %ax, %ss -1: - - testl $2, realmode_flags - wakeup_code - jz 1f - mov video_mode - wakeup_code, %ax - call mode_set -1: +#include "wakeup.S" +mode_done: # set up page table movl $swsusp_pg_dir-__PAGE_OFFSET, %eax movl %eax, %cr3@@ -109,60 +47,10 @@ real_save_gdt: .word 0 real_save_cr0: .long 0 real_save_cr3: .long 0 real_save_cr4: .long 0 -real_magic: .long 0 -video_mode: .long 0 -realmode_flags: .long 0 real_efer_save_restore: .long 0 real_save_efer_edx: .long 0 real_save_efer_eax: .long 0 -bogus_real_magic: - jmp bogus_real_magic - -/* This code uses an extended set of video mode numbers. These include: - * Aliases for standard modes - * NORMAL_VGA (-1) - * EXTENDED_VGA (-2) - * ASK_VGA (-3) - * Video modes numbered by menu position -- NOT RECOMMENDED because of lack - * of compatibility when extending the table. These are between 0x00 and 0xff. - */ -#define VIDEO_FIRST_MENU 0x0000 - -/* Standard BIOS video modes (BIOS number + 0x0100) */ -#define VIDEO_FIRST_BIOS 0x0100 - -/* VESA BIOS video modes (VESA number + 0x0200) */ -#define VIDEO_FIRST_VESA 0x0200 - -/* Video7 special modes (BIOS number + 0x0900) */ -#define VIDEO_FIRST_V7 0x0900 - -# Setting of user mode (AX=mode ID) => CF=success - -# For now, we only handle VESA modes (0x0200..0x03ff). To handle other -# modes, we should probably compile in the video code from the boot -# directory. -mode_set: - movw %ax, %bx - subb $VIDEO_FIRST_VESA>>8, %bh - cmpb $2, %bh - jb check_vesa - -setbad: - clc - ret - -check_vesa: - orw $0x4000, %bx # Use linear frame buffer - movw $0x4f02, %ax # VESA BIOS mode set call - int $0x10 - cmpw $0x004f, %ax # AL=4f if implemented - jnz setbad # AH=0 if OK - - stc - ret - .code32 ALIGNarch/x86/kernel/acpi/wakeup_64.S +2
-123@@ -7,78 +7,10 @@ #include <asm/msr.h> #include <asm/asm-offsets.h> # Copyright 2003 Pavel Machek <[email protected]>, distribute under GPLv2 -# -# wakeup_code runs in real mode, and at unknown address (determined at run-time). -# Therefore it must only use relative jumps/calls. -# -# Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled -# -# If physical address of wakeup_code is 0x12345, BIOS should call us with -# cs = 0x1234, eip = 0x05 -# - -#define BEEP \ - inb $97, %al; \ - outb %al, $0x80; \ - movb $3, %al; \ - outb %al, $97; \ - outb %al, $0x80; \ - movb $-74, %al; \ - outb %al, $67; \ - outb %al, $0x80; \ - movb $-119, %al; \ - outb %al, $66; \ - outb %al, $0x80; \ - movb $15, %al; \ - outb %al, $66; - - -ALIGN - .align 16 -ENTRY(wakeup_start) -wakeup_code: - wakeup_code_start = . - .code16 - -# Running in *copy* of this code, somewhere in low 1MB. - - cli - cld - # setup data segment - movw %cs, %ax - movw %ax, %ds # Make ds:0 point to wakeup_start - movw %ax, %ss - - # Data segment must be set up before we can see whether to beep. - testl $4, realmode_flags - wakeup_code - jz 1f - BEEP -1: - - # Private stack is needed for ASUS board - mov $(wakeup_stack - wakeup_code), %sp - - pushl $0 # Kill any dangerous flags - popfl - movl real_magic - wakeup_code, %eax - cmpl $0x12345678, %eax - jne bogus_real_magic - - testl $1, realmode_flags - wakeup_code - jz 1f - lcall $0xc000,$3 - movw %cs, %ax - movw %ax, %ds # Bios might have played with that - movw %ax, %ss -1: - - testl $2, realmode_flags - wakeup_code - jz 1f - mov video_mode - wakeup_code, %ax - call mode_set -1: +#include "wakeup.S" +mode_done: mov %ds, %ax # Find 32bit wakeup_code addr movzx %ax, %esi # (Convert %ds:gdt to a liner ptr) shll $4, %esi@@ -227,64 +159,11 @@ gdt_48a: .word 0x800 # gdt limit=2048, # 256 GDT entries .long gdta - wakeup_code # gdt base (relocated in later) - -real_magic: .quad 0 -video_mode: .quad 0 -realmode_flags: .quad 0 - -.code16 -bogus_real_magic: - jmp bogus_real_magic .code64 bogus_64_magic: jmp bogus_64_magic -/* This code uses an extended set of video mode numbers. These include: - * Aliases for standard modes - * NORMAL_VGA (-1) - * EXTENDED_VGA (-2) - * ASK_VGA (-3) - * Video modes numbered by menu position -- NOT RECOMMENDED because of lack - * of compatibility when extending the table. These are between 0x00 and 0xff. - */ -#define VIDEO_FIRST_MENU 0x0000 - -/* Standard BIOS video modes (BIOS number + 0x0100) */ -#define VIDEO_FIRST_BIOS 0x0100 - -/* VESA BIOS video modes (VESA number + 0x0200) */ -#define VIDEO_FIRST_VESA 0x0200 - -/* Video7 special modes (BIOS number + 0x0900) */ -#define VIDEO_FIRST_V7 0x0900 - -# Setting of user mode (AX=mode ID) => CF=success - -# For now, we only handle VESA modes (0x0200..0x03ff). To handle other -# modes, we should probably compile in the video code from the boot -# directory. -.code16 -mode_set: - movw %ax, %bx - subb $VIDEO_FIRST_VESA>>8, %bh - cmpb $2, %bh - jb check_vesa - -setbad: - clc - ret - -check_vesa: - orw $0x4000, %bx # Use linear frame buffer - movw $0x4f02, %ax # VESA BIOS mode set call - int $0x10 - cmpw $0x004f, %ax # AL=4f if implemented - jnz setbad # AH=0 if OK - - stc - ret - wakeup_stack_begin: # Stack grows down .org 0xff0
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth