Commit 16252da6 authored by Jens Rottmann's avatar Jens Rottmann Committed by H. Peter Anvin

x86 setup: don't recalculate ss:esp unless really necessary

In order to work around old LILO versions providing an invalid ss
register, the current setup code always sets up a new stack,
immediately following .bss and the heap. But this breaks LOADLIN.

This rewrite of the workaround checks for an invalid stack (ss!=ds)
first, and leaves ss:sp alone otherwise (apart from aligning esp).

[hpa note: LOADLIN has a number of arbitrary hard-coded limits that
are being pushed up against.  Without some major revision of LOADLIN
itself it will not be sustainable keeping it alive.  This gives it
another brief lease on life, however.  This patch also helps the
cmdline truncation problem with old versions of SYSLINUX.]

Signed-off-by: Jens Rottmann <JRottmann at LiPPERT-AT. de>
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
parent 09f345da
...@@ -236,39 +236,30 @@ start_of_setup: ...@@ -236,39 +236,30 @@ start_of_setup:
movw %ax, %es movw %ax, %es
cld cld
# Apparently some ancient versions of LILO invoked the kernel # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
# with %ss != %ds, which happened to work by accident for the # which happened to work by accident for the old code. Recalculate the stack
# old code. If the CAN_USE_HEAP flag is set in loadflags, or # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
# %ss != %ds, then adjust the stack pointer. # stack behind its own code, so we can't blindly put it directly past the heap.
# Smallest possible stack we can tolerate
movw $(_end+STACK_SIZE), %cx
movw heap_end_ptr, %dx
addw $512, %dx
jnc 1f
xorw %dx, %dx # Wraparound - whole segment available
1: testb $CAN_USE_HEAP, loadflags
jnz 2f
# No CAN_USE_HEAP
movw %ss, %dx movw %ss, %dx
cmpw %ax, %dx # %ds == %ss? cmpw %ax, %dx # %ds == %ss?
movw %sp, %dx movw %sp, %dx
# If so, assume %sp is reasonably set, otherwise use je 2f # -> assume %sp is reasonably set
# the smallest possible stack.
jne 4f # -> Smallest possible stack... # Invalid %ss, make up a new stack
movw $_end, %dx
testb $CAN_USE_HEAP, loadflags
jz 1f
movw heap_end_ptr, %dx
1: addw $STACK_SIZE, %dx
jnc 2f
xorw %dx, %dx # Prevent wraparound
# Make sure the stack is at least minimum size. Take a value 2: # Now %dx should point to the end of our stack space
# of zero to mean "full segment."
2:
andw $~3, %dx # dword align (might as well...) andw $~3, %dx # dword align (might as well...)
jnz 3f jnz 3f
movw $0xfffc, %dx # Make sure we're not zero movw $0xfffc, %dx # Make sure we're not zero
3: cmpw %cx, %dx 3: movw %ax, %ss
jnb 5f
4: movw %cx, %dx # Minimum value we can possibly use
5: movw %ax, %ss
movzwl %dx, %esp # Clear upper half of %esp movzwl %dx, %esp # Clear upper half of %esp
sti # Now we should have a working stack sti # Now we should have a working stack
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment