Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


imported SEABIOS source tree
[palacios.git] / bios / seabios / src / entryfuncs.S
1 // Macros for entering C code
2 //
3 // Copyright (C) 2008,2009  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6
7
8 /****************************************************************
9  * Entry macros
10  ****************************************************************/
11
12         // Call a C function - this does the minimal work necessary to
13         // call into C.  It sets up %ds, backs up %es, and backs up
14         // those registers that are call clobbered by the C compiler.
15         .macro ENTRY cfunc
16         cli         // In case something far-calls instead of using "int"
17         cld
18         pushl %eax              // Save registers clobbered by C code
19         pushl %ecx
20         pushl %edx
21         pushw %es
22         pushw %ds
23         movw %ss, %ax           // Move %ss to %ds
24         movw %ax, %ds
25         pushl %esp              // Backup %esp, then clear high bits
26         movzwl %sp, %esp
27         calll \cfunc
28         popl %esp               // Restore %esp (including high bits)
29         popw %ds                // Restore registers saved above
30         popw %es
31         popl %edx
32         popl %ecx
33         popl %eax
34         .endm
35
36         // As above, but get calling function from stack.
37         .macro ENTRY_ST
38         cli
39         cld
40         pushl %ecx
41         pushl %edx
42         pushw %es
43         pushw %ds
44         movw %ss, %cx           // Move %ss to %ds
45         movw %cx, %ds
46         pushl %esp              // Backup %esp, then clear high bits
47         movzwl %sp, %esp
48         movl 16(%esp), %ecx     // Get calling function
49         movl %eax, 16(%esp)     // Save %eax
50         calll *%ecx
51         popl %esp               // Restore %esp (including high bits)
52         popw %ds                // Restore registers saved above
53         popw %es
54         popl %edx
55         popl %ecx
56         popl %eax
57         .endm
58
59         // Call a C function with current register list as an
60         // argument.  This backs up the registers and sets %eax
61         // to point to the backup.  On return, the registers are
62         // restored from the structure.
63         .macro ENTRY_ARG cfunc
64         cli
65         cld
66         pushl %eax              // Save registers (matches struct bregs)
67         pushl %ecx
68         pushl %edx
69         pushl %ebx
70         pushl %ebp
71         pushl %esi
72         pushl %edi
73         pushw %es
74         pushw %ds
75         movw %ss, %ax           // Move %ss to %ds
76         movw %ax, %ds
77         movl %esp, %ebx         // Backup %esp, then zero high bits
78         movzwl %sp, %esp
79         movl %esp, %eax         // First arg is pointer to struct bregs
80         calll \cfunc
81         movl %ebx, %esp         // Restore %esp (including high bits)
82         popw %ds                // Restore registers (from struct bregs)
83         popw %es
84         popl %edi
85         popl %esi
86         popl %ebp
87         popl %ebx
88         popl %edx
89         popl %ecx
90         popl %eax
91         .endm
92
93         // As above, but get calling function from stack.
94         .macro ENTRY_ARG_ST
95         cli
96         cld
97         pushl %ecx
98         pushl %edx
99         pushl %ebx
100         pushl %ebp
101         pushl %esi
102         pushl %edi
103         pushw %es
104         pushw %ds
105         movw %ss, %cx           // Move %ss to %ds
106         movw %cx, %ds
107         movl %esp, %ebx         // Backup %esp, then zero high bits
108         movzwl %sp, %esp
109         movl 28(%esp), %ecx     // Get calling function
110         movl %eax, 28(%esp)     // Save %eax
111         movl %esp, %eax         // First arg is pointer to struct bregs
112         calll *%ecx
113         movl %ebx, %esp         // Restore %esp (including high bits)
114         popw %ds                // Restore registers (from struct bregs)
115         popw %es
116         popl %edi
117         popl %esi
118         popl %ebp
119         popl %ebx
120         popl %edx
121         popl %ecx
122         popl %eax
123         .endm
124
125         // Same as ENTRY_ARG, but don't mangle %esp
126         .macro ENTRY_ARG_ESP cfunc
127         cli
128         cld
129         pushl %eax              // Save registers (matches struct bregs)
130         pushl %ecx
131         pushl %edx
132         pushl %ebx
133         pushl %ebp
134         pushl %esi
135         pushl %edi
136         pushw %es
137         pushw %ds
138         movw %ss, %ax           // Move %ss to %ds
139         movw %ax, %ds
140         movl %esp, %eax         // First arg is pointer to struct bregs
141         calll \cfunc
142         popw %ds                // Restore registers (from struct bregs)
143         popw %es
144         popl %edi
145         popl %esi
146         popl %ebp
147         popl %ebx
148         popl %edx
149         popl %ecx
150         popl %eax
151         .endm
152
153         // Reset stack, transition to 32bit mode, and call a C function.
154         // Clobbers %ax
155         .macro ENTRY_INTO32 cfunc
156         xorw %ax, %ax
157         movw %ax, %ss
158         movl $ BUILD_STACK_ADDR , %esp
159         movl $ \cfunc , %edx
160         jmp transition32
161         .endm
162
163         // Declare a function
164         .macro DECLFUNC func
165         .section .text.asm.\func
166         .global \func
167         .endm
168
169         // Declare an exported function
170         .macro EXPORTFUNC func
171         .section .text.asm.export.\func
172         .global \func
173         .endm