Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/hpa/linux-2.6-x86setup

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux-2.6-x86setup:
  x86 setup: don't recalculate ss:esp unless really necessary
  • Loading branch information
Linus Torvalds committed Nov 30, 2007
2 parents 2e824ad + 16252da commit e1cca7e
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions arch/x86/boot/header.S
Original file line number Diff line number Diff line change
Expand Up @@ -236,39 +236,30 @@ start_of_setup:
movw %ax, %es
cld

# Apparently some ancient versions of LILO invoked the kernel
# with %ss != %ds, which happened to work by accident for the
# old code. If the CAN_USE_HEAP flag is set in loadflags, or
# %ss != %ds, then adjust the stack pointer.
# Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
# which happened to work by accident for the old code. Recalculate the stack
# pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
# 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
cmpw %ax, %dx # %ds == %ss?
movw %sp, %dx
# If so, assume %sp is reasonably set, otherwise use
# the smallest possible stack.
jne 4f # -> Smallest possible stack...
je 2f # -> assume %sp is reasonably set

# 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
# of zero to mean "full segment."
2:
2: # Now %dx should point to the end of our stack space
andw $~3, %dx # dword align (might as well...)
jnz 3f
movw $0xfffc, %dx # Make sure we're not zero
3: cmpw %cx, %dx
jnb 5f
4: movw %cx, %dx # Minimum value we can possibly use
5: movw %ax, %ss
3: movw %ax, %ss
movzwl %dx, %esp # Clear upper half of %esp
sti # Now we should have a working stack

Expand Down

0 comments on commit e1cca7e

Please sign in to comment.