acpi_wakeup.S: simplify logic

acpi_wakeup.S: simplify logic

Post by Pavel Mache » Fri, 06 Dec 2002 23:10:10



Hi!

This simplifies logic in acpi_wakeup.S by putting code and data into
same segment. Plus it kills off-by-3 bug and uses constant instead of
hardcoded value. Please apply,
                                                                Pavel

--- clean/arch/i386/kernel/acpi_wakeup.S        2002-11-19 16:45:58.000000000 +0100

-
 .text
 #include <linux/linkage.h>
 #include <asm/segment.h>
+#include <asm/page.h>

-# Do we need to deal with A20?
+#
+# 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
+#

 ALIGN
-wakeup_start:
+       .align  4096
+ENTRY(wakeup_start)
 wakeup_code:
        wakeup_code_start = .

        movw    $0xb800, %ax
        movw    %ax,%fs
        movw    $0x0e00 + 'L', %fs:(0x10)
+
        cli
        cld
-        
+
        # setup data segment
        movw    %cs, %ax
-
-       addw    $(wakeup_data - wakeup_code) >> 4, %ax
-       movw    %ax, %ds
+       movw    %ax, %ds                                        # Make ds:0 point to wakeup_start
        movw    %ax, %ss
-       mov     $(wakeup_stack - wakeup_data), %sp              # Private stack is needed for ASUS board
-       movw    $0x0e00 + 'S', %fs:(0x12)      
+       mov     wakeup_stack - wakeup_code, %sp                 # Private stack is needed for ASUS board
+       movw    $0x0e00 + 'S', %fs:(0x12)

-       movl    real_magic - wakeup_data, %eax
+       pushl   $0                                              # Kill any dangerous flags
+       popfl
+
+       movl    real_magic - wakeup_code, %eax
        cmpl    $0x12345678, %eax
        jne     bogus_real_magic

-       mov     video_mode - wakeup_data, %ax
+#if 1
+       lcall   $0xc000,$3
+#endif
+#if 0
+       mov     video_mode - wakeup_code, %ax
        call    mode_set
+#endif

        # set up page table
-       movl    (real_save_cr3 - wakeup_data), %eax
+#if 1
+       movl    $swapper_pg_dir-__PAGE_OFFSET, %eax
+#else
+       movl    (real_save_cr3 - wakeup_data), %eax
+#endif
        movl    %eax, %cr3

        # make sure %cr4 is set correctly (features, etc)
-       movl    (real_save_cr4 - wakeup_data), %eax
+       movl    real_save_cr4 - wakeup_code, %eax
        movl    %eax, %cr4
        movw    $0xb800, %ax
        movw    %ax,%fs
        movw    $0x0e00 + 'i', %fs:(0x12)
-
+      
        # need a gdt
-       lgdt    real_save_gdt - wakeup_data
+       lgdt    real_save_gdt - wakeup_code

-       movl    (real_save_cr0 - wakeup_data), %eax
+       movl    real_save_cr0 - wakeup_code, %eax
        movl    %eax, %cr0
+       jmp 1f
+1:
        movw    $0x0e00 + 'n', %fs:(0x14)

-       movl    real_magic - wakeup_data, %eax
+       movl    real_magic - wakeup_code, %eax
        cmpl    $0x12345678, %eax
        jne     bogus_real_magic

        ljmpl   $__KERNEL_CS,$wakeup_pmode_return

+real_save_gdt: .word 0
+               .long 0
+real_save_cr0: .long 0
+real_save_cr3: .long 0
+real_save_cr4: .long 0
+real_magic:    .long 0
+video_mode:    .long 0
+
 bogus_real_magic:
        movw    $0x0e00 + 'B', %fs:(0x12)

        .code32
        ALIGN

-.org   0x300
-wakeup_data:
-               .word 0
-real_save_gdt: .word 0
-               .long 0
-real_save_cr0: .long 0
-real_save_cr3: .long 0
-real_save_cr4: .long 0
-real_magic:    .long 0
-video_mode:    .long 0

-.org   0x500
+.org   0x2000
 wakeup_stack:
-wakeup_end:
+.org   0x3000
+ENTRY(wakeup_end)
+.org   0x4000

 wakeup_pmode_return:

        movw    $0x0e00 + '2', %ds:(0xb8018)
        jmp bogus_magic2

-
 ##
 # acpi_copy_wakeup_routine

        movl    %eax, %edi
        leal    wakeup_start, %esi
-       movl    $(wakeup_end - wakeup_start) >> 2, %ecx
+       movl    $(wakeup_end - wakeup_start + 3) >> 2, %ecx

        rep ;  movsl

        ret
        .p2align 4,,7
 .L1432:
-       movl $104,%eax
-       movw %eax, %ds
+       movl $__KERNEL_DS,%eax
+       movw %ax, %ds
        movl saved_context_esp, %esp
        movl saved_context_ebp, %ebp

 saved_idt:     .long   0,0
 saved_ldt:     .long   0
 saved_tss:     .long   0
-saved_cr0:     .long   0

--
Worst form of spam? Adding advertisment signatures ala sourceforge.net.
What goes next? Inserting advertisment *into* email?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/