Avoid clobbering PM code when loading the kernel
authorH. Peter Anvin <hpa@zytor.com>
Mon, 25 May 2009 02:18:02 +0000 (19:18 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 25 May 2009 02:18:02 +0000 (19:18 -0700)
We can't safely use 1 MB to directly load the kernel, so shift the
kernel just as we do when loading low.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/com32.inc
core/layout.inc
core/runkernel.inc
core/syslinux.ld

index 3dd37b9..1ab4248 100644 (file)
@@ -27,8 +27,7 @@
 ; "mov ax,0x4cff; int 0x21" in 16-bit mode.  This will abort the
 ; program with an error if run in 16-bit mode.
 ;
-
-               extern com32_entry
+com32_entry    equ     free_high_memory
 
                section .text16
 is_com32_image:
index c096c6f..38238b3 100644 (file)
@@ -81,6 +81,8 @@ RBFG_brainfuck:       resb 2048               ; Bigger than an Ethernet packet...
                SECINFO pm_code
                extern __bss_start, __bss_end, __bss_len, __bss_dwords
 
+               extern free_high_memory
+
                global _start
 
                section .text16
@@ -136,7 +138,6 @@ comboot_seg equ real_mode_seg       ; COMBOOT image loading zone
 ; The prefix is a small structure that prefaces the actual code;
 ; it gives the compression program necessary information.
 ;
-               extern __pm_code_lma
 
                section .prefix         nowrite progbits align=16
 pfx_start      dd _start               ; Start of raw chunk
index 083c967..8d0f296 100644 (file)
@@ -257,7 +257,7 @@ read_kernel:
                 mov ecx,8000h                  ; 32K
                sub ecx,esi                     ; Number of bytes to copy
                add esi,(real_mode_seg << 4)    ; Pointer to source
-                mov edi,100000h                 ; Copy to address 100000h
+                mov edi,free_high_memory       ; Copy to free high memory
 
                 call bcopy                     ; Transfer to high memory
 
@@ -412,6 +412,7 @@ setup_move:
                push ds                         ; We need DS == ES == CS here
                pop es
 
+               mov edx,100000h
                test byte [LoadFlags],LOAD_HIGH
                jnz .loading_high
 
@@ -423,20 +424,19 @@ setup_move:
                movzx eax,word [CmdLineEnd]
                stosd
                inc cx
+               mov edx,10000h                  ; Revised target address
+               mov bx,9000h                    ; Revised real mode segment
 
-               mov eax,10000h                  ; Target address of low kernel
+.loading_high:
+               mov eax,edx                     ; Target address of kernel
                stosd
-               mov eax,100000h                 ; Where currently loaded
+               mov eax,free_high_memory        ; Where currently loaded
                stosd
                neg eax
                add eax,[KernelEnd]
                stosd
                inc cx
 
-               mov bx,9000h                    ; Revised real mode segment
-
-.loading_high:
-
                cmp word [InitRDPtr],0          ; Did we have an initrd?
                je .no_initrd
 
index 718f259..97294e8 100644 (file)
@@ -256,7 +256,7 @@ SECTIONS
 
        _end = .;
 
-       /* COM32R binaries are loaded after our own PM code */
+       /* COM32R and kernels are loaded after our own PM code */
        . = ALIGN(4096);
-       com32_entry = .;
+       free_high_memory = .;
 }