Thomas Gleixner | 97873a3 | 2019-06-04 10:11:30 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 2 | /* ----------------------------------------------------------------------- * |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright 2007 rPath, Inc. - All Rights Reserved |
| 6 | * |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 7 | * ----------------------------------------------------------------------- */ |
| 8 | |
| 9 | /* |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 10 | * The actual transition into protected mode |
| 11 | */ |
| 12 | |
| 13 | #include <asm/boot.h> |
H. Peter Anvin | 02a7b42 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 15 | #include <asm/segment.h> |
Cyrill Gorcunov | 324bda9e4 | 2009-02-14 00:50:21 +0300 | [diff] [blame] | 16 | #include <linux/linkage.h> |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 17 | |
| 18 | .text |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 19 | .code16 |
| 20 | |
| 21 | /* |
| 22 | * void protected_mode_jump(u32 entrypoint, u32 bootparams); |
| 23 | */ |
Jiri Slaby | 37818af | 2019-10-11 13:50:56 +0200 | [diff] [blame] | 24 | SYM_FUNC_START_NOALIGN(protected_mode_jump) |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 25 | movl %edx, %esi # Pointer to boot_params table |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 26 | |
| 27 | xorl %ebx, %ebx |
| 28 | movw %cs, %bx |
| 29 | shll $4, %ebx |
| 30 | addl %ebx, 2f |
H. Peter Anvin | 2ee2394 | 2008-06-30 15:42:47 -0700 | [diff] [blame] | 31 | jmp 1f # Short jump to serialize on 386/486 |
| 32 | 1: |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 33 | |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 34 | movw $__BOOT_DS, %cx |
H. Peter Anvin | 8808951 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 35 | movw $__BOOT_TSS, %di |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 36 | |
| 37 | movl %cr0, %edx |
H. Peter Anvin | 02a7b42 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 38 | orb $X86_CR0_PE, %dl # Protected mode |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 39 | movl %edx, %cr0 |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 40 | |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 41 | # Transition to 32-bit mode |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 42 | .byte 0x66, 0xea # ljmpl opcode |
Jiri Slaby | 30a2441 | 2019-10-11 11:22:13 +0200 | [diff] [blame] | 43 | 2: .long .Lin_pm32 # offset |
H. Peter Anvin | 7052fdd | 2007-07-11 12:18:53 -0700 | [diff] [blame] | 44 | .word __BOOT_CS # segment |
Jiri Slaby | 37818af | 2019-10-11 13:50:56 +0200 | [diff] [blame] | 45 | SYM_FUNC_END(protected_mode_jump) |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 46 | |
| 47 | .code32 |
H. Peter Anvin | be72169 | 2009-03-17 15:26:06 -0700 | [diff] [blame] | 48 | .section ".text32","ax" |
Jiri Slaby | deff8a2 | 2019-10-11 13:50:47 +0200 | [diff] [blame] | 49 | SYM_FUNC_START_LOCAL_NOALIGN(.Lin_pm32) |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 50 | # Set up data segments for flat 32-bit mode |
| 51 | movl %ecx, %ds |
| 52 | movl %ecx, %es |
| 53 | movl %ecx, %fs |
| 54 | movl %ecx, %gs |
| 55 | movl %ecx, %ss |
| 56 | # The 32-bit code sets up its own stack, but this way we do have |
| 57 | # a valid stack if some debugging hack wants to use it. |
| 58 | addl %ebx, %esp |
| 59 | |
H. Peter Anvin | 8808951 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 60 | # Set up TR to make Intel VT happy |
| 61 | ltr %di |
| 62 | |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 63 | # Clear registers to allow for future extensions to the |
| 64 | # 32-bit boot protocol |
| 65 | xorl %ecx, %ecx |
| 66 | xorl %edx, %edx |
| 67 | xorl %ebx, %ebx |
| 68 | xorl %ebp, %ebp |
| 69 | xorl %edi, %edi |
| 70 | |
H. Peter Anvin | 8808951 | 2008-01-30 13:33:02 +0100 | [diff] [blame] | 71 | # Set up LDTR to make Intel VT happy |
| 72 | lldt %cx |
| 73 | |
H. Peter Anvin | c4d9ba6 | 2008-01-30 13:33:01 +0100 | [diff] [blame] | 74 | jmpl *%eax # Jump to the 32-bit entrypoint |
Jiri Slaby | deff8a2 | 2019-10-11 13:50:47 +0200 | [diff] [blame] | 75 | SYM_FUNC_END(.Lin_pm32) |