xref: /haiku/src/system/boot/platform/pxe_ia32/pxe_bios.S (revision f7110a4231047dd786bc52dfbf4c0c0d559998c7)
1/*
2** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3** Copyright 2006, Marcus Overhagen, marcus@overhagen.de. All rights reserved.
4** Distributed under the terms of the Haiku License.
5*/
6
7
8/** This file contains code to call PXE BIOS functions out of a protected
9 *	mode environment. It doesn't use the virtual86 mode - it switches
10 *	to real mode, make the BIOS call, and switch back to protected
11 *	mode again. It's meant to be used in a single-threaded boot loader,
12 *	not in a multi-tasking operating system.
13 *	It relies on the real mode segment descriptors found in pxe_stage1.S,
14 *	and uses support functions from ../bios_ia32/bios.S
15 */
16
17#define FUNCTION(x) .globl x ; x ## :
18
19#define REAL_MODE_STACK	0x9000
20	// the location of the stack in real mode
21
22#define SAVED_EAX		0x10000
23	// we're overwriting the start of our boot loader to hold some
24	// temporary values - the first 1024 bytes of it are used at
25	// startup only, and we avoid some linking issues this way
26
27
28.text
29.code32
30
31
32/** uint16 call_pxe_bios(void *pxe, uint16 opcode, void *param)
33 *	Does a call to the PXE BIOS functions in real mode.
34 *  Both pxe and param must be as linear pointer in lower 1 MB,
35 *  pxe is the pointer to the !PXE structure.
36 */
37
38FUNCTION(call_pxe_bios)
39
40	pushal
41	pushfl
42
43	// make sure the correct IDT is in place
44	lidt 	idt_descriptor
45
46	// !PXE
47	movl	40(%esp), %eax
48	// entry point SEG:OFS
49	movl	0x10(%eax), %ebx
50
51	// opcode
52	movl	44(%esp), %ecx
53
54	// param
55	movl	48(%esp), %edx
56
57	call	switch_to_real_mode
58
59	.code16
60
61	// SEG param
62	movl	%edx, %eax
63	shrl	$4, %eax
64	pushw	%ax
65
66	// OFS param
67	andw	$0xf, %dx
68	pushw	%dx
69
70	// opcode
71	pushw	%cx
72
73	// call PXE entry point
74	call *	%ebx
75
76	addw	$6, %sp
77
78	// save %ax from the call
79	xorl	%ebx, %ebx
80	movw	%ax, %bx
81	movl	%ebx, (SAVED_EAX - 0x10000)
82
83	// back to protected mode
84	call	switch_to_protected_mode
85	.code32
86
87	popfl
88	popal
89
90	movl	SAVED_EAX, %eax
91
92	ret
93