1 // Macros for entering C code
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 /****************************************************************
10 ****************************************************************/
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.
16 cli // In case something far-calls instead of using "int"
18 pushl %eax // Save registers clobbered by C code
23 movw %ss, %ax // Move %ss to %ds
25 pushl %esp // Backup %esp, then clear high bits
28 popl %esp // Restore %esp (including high bits)
29 popw %ds // Restore registers saved above
36 // As above, but get calling function from stack.
44 movw %ss, %cx // Move %ss to %ds
46 pushl %esp // Backup %esp, then clear high bits
48 movl 16(%esp), %ecx // Get calling function
49 movl %eax, 16(%esp) // Save %eax
51 popl %esp // Restore %esp (including high bits)
52 popw %ds // Restore registers saved above
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
66 pushl %eax // Save registers (matches struct bregs)
75 movw %ss, %ax // Move %ss to %ds
77 movl %esp, %ebx // Backup %esp, then zero high bits
79 movl %esp, %eax // First arg is pointer to struct bregs
81 movl %ebx, %esp // Restore %esp (including high bits)
82 popw %ds // Restore registers (from struct bregs)
93 // As above, but get calling function from stack.
105 movw %ss, %cx // Move %ss to %ds
107 movl %esp, %ebx // Backup %esp, then zero high bits
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
113 movl %ebx, %esp // Restore %esp (including high bits)
114 popw %ds // Restore registers (from struct bregs)
125 // Same as ENTRY_ARG, but don't mangle %esp
126 .macro ENTRY_ARG_ESP cfunc
129 pushl %eax // Save registers (matches struct bregs)
138 movw %ss, %ax // Move %ss to %ds
140 movl %esp, %eax // First arg is pointer to struct bregs
142 popw %ds // Restore registers (from struct bregs)
153 // Reset stack, transition to 32bit mode, and call a C function.
155 .macro ENTRY_INTO32 cfunc
158 movl $ BUILD_STACK_ADDR , %esp
163 // Declare a function
165 .section .text.asm.\func
169 // Declare an exported function
170 .macro EXPORTFUNC func
171 .section .text.asm.export.\func