diff options
-rw-r--r-- | arch/x86/boot/header.S | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index 6ef5a060fa11..4cc5b0411db5 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S | |||
@@ -236,39 +236,30 @@ start_of_setup: | |||
236 | movw %ax, %es | 236 | movw %ax, %es |
237 | cld | 237 | cld |
238 | 238 | ||
239 | # Apparently some ancient versions of LILO invoked the kernel | 239 | # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds, |
240 | # with %ss != %ds, which happened to work by accident for the | 240 | # which happened to work by accident for the old code. Recalculate the stack |
241 | # old code. If the CAN_USE_HEAP flag is set in loadflags, or | 241 | # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the |
242 | # %ss != %ds, then adjust the stack pointer. | 242 | # stack behind its own code, so we can't blindly put it directly past the heap. |
243 | 243 | ||
244 | # Smallest possible stack we can tolerate | ||
245 | movw $(_end+STACK_SIZE), %cx | ||
246 | |||
247 | movw heap_end_ptr, %dx | ||
248 | addw $512, %dx | ||
249 | jnc 1f | ||
250 | xorw %dx, %dx # Wraparound - whole segment available | ||
251 | 1: testb $CAN_USE_HEAP, loadflags | ||
252 | jnz 2f | ||
253 | |||
254 | # No CAN_USE_HEAP | ||
255 | movw %ss, %dx | 244 | movw %ss, %dx |
256 | cmpw %ax, %dx # %ds == %ss? | 245 | cmpw %ax, %dx # %ds == %ss? |
257 | movw %sp, %dx | 246 | movw %sp, %dx |
258 | # If so, assume %sp is reasonably set, otherwise use | 247 | je 2f # -> assume %sp is reasonably set |
259 | # the smallest possible stack. | 248 | |
260 | jne 4f # -> Smallest possible stack... | 249 | # Invalid %ss, make up a new stack |
250 | movw $_end, %dx | ||
251 | testb $CAN_USE_HEAP, loadflags | ||
252 | jz 1f | ||
253 | movw heap_end_ptr, %dx | ||
254 | 1: addw $STACK_SIZE, %dx | ||
255 | jnc 2f | ||
256 | xorw %dx, %dx # Prevent wraparound | ||
261 | 257 | ||
262 | # Make sure the stack is at least minimum size. Take a value | 258 | 2: # Now %dx should point to the end of our stack space |
263 | # of zero to mean "full segment." | ||
264 | 2: | ||
265 | andw $~3, %dx # dword align (might as well...) | 259 | andw $~3, %dx # dword align (might as well...) |
266 | jnz 3f | 260 | jnz 3f |
267 | movw $0xfffc, %dx # Make sure we're not zero | 261 | movw $0xfffc, %dx # Make sure we're not zero |
268 | 3: cmpw %cx, %dx | 262 | 3: movw %ax, %ss |
269 | jnb 5f | ||
270 | 4: movw %cx, %dx # Minimum value we can possibly use | ||
271 | 5: movw %ax, %ss | ||
272 | movzwl %dx, %esp # Clear upper half of %esp | 263 | movzwl %dx, %esp # Clear upper half of %esp |
273 | sti # Now we should have a working stack | 264 | sti # Now we should have a working stack |
274 | 265 | ||