[CMAKE]
[reactos.git] / boot / freeldr / freeldr / arch / i386 / i386pxe.S
1 /*
2 * FreeLoader
3 * Copyright (C) 2011 Hervé Poussineau
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 .text
21 .code16
22
23 #define ASM
24
25 #include <arch.h>
26
27 /*
28 * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
29 *
30 * RETURNS:
31 */
32 _pxe_function:
33 .word 0
34 _pxe_entry_point:
35 .long 0
36 _pxe_buffer_segment:
37 .word 0
38 _pxe_buffer_offset:
39 .word 0
40 _pxe_result:
41 .word 0
42
43 EXTERN(_PxeCallApi)
44 .code32
45 pushl %ebp
46 movl %esp,%ebp
47
48 pushal
49 push %es
50
51 /* copy entry point */
52 movl 0x08(%ebp),%eax
53 shll $16,%eax
54 movw 0x0C(%ebp),%ax
55 movl %eax,_pxe_entry_point
56
57 /* copy function */
58 movw 0x10(%ebp),%ax
59 movw %ax,_pxe_function
60
61 /* convert pointer to data buffer to segment/offset */
62 movl 0x14(%ebp),%eax
63 shrl $4,%eax
64 andl $0xf000,%eax
65 movw %ax,_pxe_buffer_segment
66 movl 0x14(%ebp),%eax
67 andl $0xffff,%eax
68 movw %ax,_pxe_buffer_offset
69
70 call switch_to_real
71 .code16
72
73 movw _pxe_buffer_segment,%ax
74 push %ax
75 movw _pxe_buffer_offset,%ax
76 push %ax
77 movw _pxe_function,%ax
78 push %ax
79 lcall *_pxe_entry_point
80 addw $6,%sp
81 movw %ax,_pxe_result
82
83 call switch_to_prot
84 .code32
85
86 pop %es
87 popal
88
89 movl %ebp,%esp
90 popl %ebp
91
92 movw _pxe_result,%ax
93
94 ret
95
96 /* EOF */
97