xref: /OK3568_Linux_fs/kernel/arch/x86/boot/pmjump.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun/* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun/* ----------------------------------------------------------------------- *
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun *   Copyright (C) 1991, 1992 Linus Torvalds
5*4882a593Smuzhiyun *   Copyright 2007 rPath, Inc. - All Rights Reserved
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * ----------------------------------------------------------------------- */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun/*
10*4882a593Smuzhiyun * The actual transition into protected mode
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun#include <asm/boot.h>
14*4882a593Smuzhiyun#include <asm/processor-flags.h>
15*4882a593Smuzhiyun#include <asm/segment.h>
16*4882a593Smuzhiyun#include <linux/linkage.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun	.text
19*4882a593Smuzhiyun	.code16
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun/*
22*4882a593Smuzhiyun * void protected_mode_jump(u32 entrypoint, u32 bootparams);
23*4882a593Smuzhiyun */
24*4882a593SmuzhiyunSYM_FUNC_START_NOALIGN(protected_mode_jump)
25*4882a593Smuzhiyun	movl	%edx, %esi		# Pointer to boot_params table
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun	xorl	%ebx, %ebx
28*4882a593Smuzhiyun	movw	%cs, %bx
29*4882a593Smuzhiyun	shll	$4, %ebx
30*4882a593Smuzhiyun	addl	%ebx, 2f
31*4882a593Smuzhiyun	jmp	1f			# Short jump to serialize on 386/486
32*4882a593Smuzhiyun1:
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun	movw	$__BOOT_DS, %cx
35*4882a593Smuzhiyun	movw	$__BOOT_TSS, %di
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun	movl	%cr0, %edx
38*4882a593Smuzhiyun	orb	$X86_CR0_PE, %dl	# Protected mode
39*4882a593Smuzhiyun	movl	%edx, %cr0
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	# Transition to 32-bit mode
42*4882a593Smuzhiyun	.byte	0x66, 0xea		# ljmpl opcode
43*4882a593Smuzhiyun2:	.long	.Lin_pm32		# offset
44*4882a593Smuzhiyun	.word	__BOOT_CS		# segment
45*4882a593SmuzhiyunSYM_FUNC_END(protected_mode_jump)
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	.code32
48*4882a593Smuzhiyun	.section ".text32","ax"
49*4882a593SmuzhiyunSYM_FUNC_START_LOCAL_NOALIGN(.Lin_pm32)
50*4882a593Smuzhiyun	# Set up data segments for flat 32-bit mode
51*4882a593Smuzhiyun	movl	%ecx, %ds
52*4882a593Smuzhiyun	movl	%ecx, %es
53*4882a593Smuzhiyun	movl	%ecx, %fs
54*4882a593Smuzhiyun	movl	%ecx, %gs
55*4882a593Smuzhiyun	movl	%ecx, %ss
56*4882a593Smuzhiyun	# The 32-bit code sets up its own stack, but this way we do have
57*4882a593Smuzhiyun	# a valid stack if some debugging hack wants to use it.
58*4882a593Smuzhiyun	addl	%ebx, %esp
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun	# Set up TR to make Intel VT happy
61*4882a593Smuzhiyun	ltr	%di
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun	# Clear registers to allow for future extensions to the
64*4882a593Smuzhiyun	# 32-bit boot protocol
65*4882a593Smuzhiyun	xorl	%ecx, %ecx
66*4882a593Smuzhiyun	xorl	%edx, %edx
67*4882a593Smuzhiyun	xorl	%ebx, %ebx
68*4882a593Smuzhiyun	xorl	%ebp, %ebp
69*4882a593Smuzhiyun	xorl	%edi, %edi
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun	# Set up LDTR to make Intel VT happy
72*4882a593Smuzhiyun	lldt	%cx
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun	jmpl	*%eax			# Jump to the 32-bit entrypoint
75*4882a593SmuzhiyunSYM_FUNC_END(.Lin_pm32)
76