summaryrefslogtreecommitdiffstats
path: root/contrib/syslinux-4.02/memdisk/start32.S
blob: 4fb05374448396104cedd2a127dd8c01b439b773 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -----------------------------------------------------------------------
 *
 *   Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
 *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * Simple stub to get us to the right point in the 32-bit code;
 * this module must be linked first
 */

	.section ".init", "ax"
	.globl _start
_start:
	/* Zero the bss */
	cld
	movl	$__bss_start, %edi
	movl	$__bss_end, %ecx
	subl	%edi, %ecx
	xorl	%eax, %eax
	shrl	$2, %ecx
	rep ; stosl

	/* Set up the protected-mode IDT and the interrupt jump buffers */
	movl	$idt, %edi
	movl	$ijb, %eax
	movl	$0xee000000, %ebx	/* Interrupt gate */
	movw	%cs, %bx		/* Target segment */

	/* Make the IDT */
	movl	$256, %ecx
1:
	stosl
	stosl
	movl	%ebx, -6(%edi)
	addl	$8, %eax
	loop	1b

	/*
	 * Each entry in the interrupt jump buffer contains the following
	 * instructions:
	 *
	 * 60		pushal
	 * b0xx		movb $xx, %al		# interrupt number
	 * e9xxxxxxxx	jmp handle_interrupt
	 */
	movl	$0xe900b060, %eax
	movl	$256, %ecx
1:
	movl	%eax, (%edi)
	addl	$(1 << 16), %eax
	movl	$handle_interrupt-8, %edx
	subl	%edi, %edx
	movl	%edx, 4(%edi)
	addl	$8, %edi
	loop	1b

	lidtl	idt_ptr
	
	/* Save arguments, switch stacks */
	movl	%esp, %eax		/* Pointer to arguments */
	movl	$__stack_end, %esp
	
	call	setup
	jmp	*(rm_args)		/* First argument is return */

	.section ".text","ax"
	.globl	intcall
	.type	intcall, @function
intcall:
	jmp	*(rm_args+1*4)		/* Intcall is argument 1 */
	.size	intcall, .-intcall

	.type	handle_interrupt, @function
handle_interrupt:
	jmp	*(rm_args+4*4)		/* Interrupt pointer is argument 4 */
	.size	handle_interrupt, .-handle_interrupt

	.section ".rodata","a"
idt_ptr:
	.word	8*256-1
	.long	idt
	.word	0

	.section ".bss.large","aw"
	.balign 2048
idt:
	.space	8*256
ijb:
	.space	8*256

__stack:
	.space	65536
__stack_end: