When exiting a COMBOOT/COM32 module, reset the stack instead of saving
authorH. Peter Anvin <hpa@zytor.com>
Thu, 17 Aug 2006 21:24:43 +0000 (14:24 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 17 Aug 2006 21:24:43 +0000 (14:24 -0700)
and restoring it.  The former option left crap on the stack.

abort.inc
bcopy32.inc
com32.inc
comboot.inc
extlinux.asm
isolinux.asm
ldlinux.asm
pxelinux.asm
stack.inc [new file with mode: 0644]

index 78347d5..5b87c68 100644 (file)
--- a/abort.inc
+++ b/abort.inc
@@ -1,7 +1,6 @@
-; $Id$
 ; -----------------------------------------------------------------------
 ;
-;   Copyright 2005 H. Peter Anvin - All Rights Reserved
+;   Copyright 2005-2006 H. Peter Anvin - All Rights Reserved
 ;
 ;   This program is free software; you can redistribute it and/or modify
 ;   it under the terms of the GNU General Public License as published by
@@ -50,16 +49,7 @@ abort_load:
                 mov ax,cs                       ; Restore CS = DS = ES
                 mov ds,ax
                 mov es,ax
-%if IS_SYSLINUX || IS_EXTLINUX
-                mov ss,ax                       ; Just in case...
-                mov sp,StackBuf-2*3                    ; Reset stack
-%elif IS_PXELINUX
-               lss esp,[BaseStack]
-%elif IS_ISOLINUX
-               lss sp,[StackPtr]
-%else
-               NEED TO KNOW HOW TO RESET STACK
-%endif
+               RESET_STACK
                sti
                 call cwritestr                  ; Expects SI -> error msg
 
index 652c4b3..237eb81 100644 (file)
@@ -453,6 +453,5 @@ __bcopy_size        equ $-__bcopy_start
                section .earlybss
                alignb 2
 EntryPoint     resd 1                  ; CS:IP for shuffle_and_boot
-SavedSSSP      resd 1                  ; Saved real mode SS:SP
 A20Test                resw 1                  ; Counter for testing status of A20
 A20Tries       resb 1                  ; Times until giving up on A20
index e607537..07d0c1c 100644 (file)
--- a/com32.inc
+++ b/com32.inc
@@ -75,8 +75,8 @@ com32_enter_pm:
                cli
                mov ax,cs
                mov ds,ax
-               mov [SavedSSSP],sp
-               mov [SavedSSSP+2],ss
+               mov [RealModeSSSP],sp
+               mov [RealModeSSSP+2],ss
                cld
                call a20_test
                jnz .a20ok
@@ -200,7 +200,7 @@ com32_enter_rm:
                mov es,ax
                mov fs,ax
                mov gs,ax
-               lss sp,[SavedSSSP]      ; Restore stack
+               lss sp,[RealModeSSSP]   ; Restore stack
                jmp bx                  ; Go to whereever we need to go...
 
 com32_done:
@@ -303,10 +303,10 @@ com32_intcall:
 com32_syscall:
                cld
 
-               movzx edi,word [word SavedSSSP]
-               movzx ebx,word [word SavedSSSP+2]
+               movzx edi,word [word RealModeSSSP]
+               movzx ebx,word [word RealModeSSSP+2]
                sub edi,54              ; Allocate 54 bytes
-               mov [word SavedSSSP],di
+               mov [word RealModeSSSP],di
                shl ebx,4
                add edi,ebx             ; Create linear address
 
@@ -331,8 +331,8 @@ com32_syscall:
                ; real-mode stack, plus the 10 additional bytes used
                ; by the target address (see above.)
 com32_sys_resume:
-               movzx esi,word [word SavedSSSP]
-               movzx eax,word [word SavedSSSP+2]
+               movzx esi,word [word RealModeSSSP]
+               movzx eax,word [word RealModeSSSP+2]
                mov edi,[esp+12*4]      ; Dest regs
                shl eax,4
                add esi,eax             ; Create linear address
@@ -343,7 +343,7 @@ com32_sys_resume:
                mov cl,11               ; 44 bytes
                rep movsd               ; Copy register block
 
-               add dword [word SavedSSSP],54   ; Remove from stack
+               add dword [word RealModeSSSP],54        ; Remove from stack
 
                popad
                popfd
@@ -353,6 +353,7 @@ com32_sys_resume:
 
                section .bss
                alignb 4
+RealModeSSSP   resd 1                  ; Real-mode SS:SP
 PMESP          resd 1                  ; Protected-mode ESP
 Com32SysSP     resw 1                  ; SP saved during COM32 syscall
 
index eaeab5c..91a7da9 100644 (file)
@@ -132,9 +132,6 @@ is_comboot_image:
                call getfssec
 
                ; And invoke the program...
-               mov [SavedSSSP],sp
-               mov [SavedSSSP+2],ss    ; Save away SS:SP
-
                mov ax,es
                mov ds,ax
                mov ss,ax
@@ -213,7 +210,7 @@ comboot_exit_special:
                xor dx,dx
                mov ds,dx
                mov es,dx
-               lss sp,[SavedSSSP]
+               RESET_STACK
                sti
                cld
                call adjust_screen      ; The COMBOOT program might have changed the screen
index 0b93e0a..123c4f6 100644 (file)
@@ -1,12 +1,11 @@
 ; -*- fundamental -*- (asm-mode sucks)
-; $Id$
 ; ****************************************************************************
 ;
 ;  extlinux.asm
 ;
 ;  A program to boot Linux kernels off an ext2/ext3 filesystem.
 ;
-;   Copyright (C) 1994-2005  H. Peter Anvin
+;   Copyright (C) 1994-2006  H. Peter Anvin
 ;
 ;  This program is free software; you can redistribute it and/or modify
 ;  it under the terms of the GNU General Public License as published by
 ; ****************************************************************************
 
 %define IS_EXTLINUX 1
-%include "macros.inc"
-%include "config.inc"
-%include "kernel.inc"
-%include "bios.inc"
-%include "tracers.inc"
-%include "layout.inc"
-
+%include "head.inc"
 %include "ext2_fs.inc"
 
 ;
index 113fba1..4d2a472 100644 (file)
@@ -1,5 +1,4 @@
 ; -*- fundamental -*- (asm-mode sucks)
-; $Id$
 ; ****************************************************************************
 ;
 ;  isolinux.asm
@@ -9,7 +8,7 @@
 ;  available.  It is based on the SYSLINUX boot loader for MS-DOS
 ;  floppies.
 ;
-;   Copyright (C) 1994-2005  H. Peter Anvin
+;   Copyright (C) 1994-2006  H. Peter Anvin
 ;
 ;  This program is free software; you can redistribute it and/or modify
 ;  it under the terms of the GNU General Public License as published by
 ; ****************************************************************************
 
 %define IS_ISOLINUX 1
-%include "macros.inc"
-%include "config.inc"
-%include "kernel.inc"
-%include "bios.inc"
-%include "tracers.inc"
-%include "layout.inc"
+%include "head.inc"
 
 ;
 ; Some semi-configurable constants... change on your own risk.
index 0f5c0cd..dfb2397 100644 (file)
 %ifndef IS_MDSLINUX
 %define IS_SYSLINUX 1
 %endif
-%include "macros.inc"
-%include "config.inc"
-%include "kernel.inc"
-%include "bios.inc"
-%include "tracers.inc"
-%include "layout.inc"
+%include "head.inc"
+
 ;
 ; Some semi-configurable constants... change on your own risk.
 ;
index 90e7a5c..5809a47 100644 (file)
@@ -1,5 +1,4 @@
 ; -*- fundamental -*- (asm-mode sucks)
-; $Id$
 ; ****************************************************************************
 ;
 ;  pxelinux.asm
@@ -8,7 +7,7 @@
 ;  network booting API.  It is based on the SYSLINUX boot loader for
 ;  MS-DOS floppies.
 ;
-;   Copyright (C) 1994-2005  H. Peter Anvin
+;   Copyright (C) 1994-2006  H. Peter Anvin
 ;
 ;  This program is free software; you can redistribute it and/or modify
 ;  it under the terms of the GNU General Public License as published by
 ; ****************************************************************************
 
 %define IS_PXELINUX 1
-%include "macros.inc"
-%include "config.inc"
-%include "kernel.inc"
-%include "bios.inc"
-%include "tracers.inc"
+%include "head.inc"
 %include "pxe.inc"
-%include "layout.inc"
 
 ;
 ; Some semi-configurable constants... change on your own risk.
@@ -1897,48 +1891,6 @@ unload_pxe:
                jmp .call_loop
 
 .call_done:
-;
-; This isn't necessary anymore; we can use the memory area previously
-; used by the PXE stack indefinitely, and the chainload code sets up
-; a new stack independently.  Leave the source code in here for now,
-; but expect to rip it out soonish.
-;
-%if 0 ; USE_PXE_PROVIDED_STACK
-               ; We need to switch to our local stack here...
-               pusha
-               pushf
-               push gs
-
-               mov si,sp
-               mov ax,ss
-               mov gs,ax
-               sub ax,[BaseStack+4]            ; Are we using the base stack
-               je .is_base_stack               ; (as opposed to the COMBOOT stack)?
-
-               lgs si,[SavedSSSP]              ; COMBOOT stack
-.is_base_stack:
-
-               mov cx,[InitStack]
-               mov di,StackBuf
-               mov [BaseStack],di
-               mov [BaseStack+4],es
-               sub cx,si
-               sub di,cx
-               mov [SavedSSSP],di              ; New SP
-               mov [SavedSSSP+2],es
-               gs rep movsb
-
-               and ax,ax                       ; Remember which stack
-               jne .combootstack
-
-               ; Update the base stack pointer since it's in use
-               lss sp,[SavedSSSP]
-
-.combootstack:
-               pop gs
-               popf
-               popa
-%endif
                mov bx,0FF00h
 
                mov dx,[RealBaseMem]
diff --git a/stack.inc b/stack.inc
new file mode 100644 (file)
index 0000000..c3297ed
--- /dev/null
+++ b/stack.inc
@@ -0,0 +1,38 @@
+; -----------------------------------------------------------------------
+;
+;   Copyright 2005-2006 H. Peter Anvin - All Rights Reserved
+;
+;   This program is free software; you can redistribute it and/or modify
+;   it under the terms of the GNU General Public License as published by
+;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+;   Boston MA 02111-1307, USA; either version 2 of the License, or
+;   (at your option) any later version; incorporated herein by reference.
+;
+; -----------------------------------------------------------------------
+
+;
+; stack.inc
+;
+; How to reset the stack pointer
+;
+
+%ifndef _STACK_INC
+%define _STACK_INC
+
+;
+; This macro resets the stack pointer.  It assumes CS == DS.
+;
+%macro RESET_STACK 0
+%if IS_SYSLINUX || IS_EXTLINUX
+                mov ss,ax                       ; Just in case...
+                mov sp,StackBuf-2*3                    ; Reset stack
+%elif IS_PXELINUX
+               lss esp,[BaseStack]
+%elif IS_ISOLINUX
+               lss sp,[StackPtr]
+%else
+               NEED TO KNOW HOW TO RESET STACK
+%endif
+%endmacro
+
+%endif ; _STACK_INC