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 // Call a C function with current register list as an
37 // argument. This backs up the registers and sets %eax
38 // to point to the backup. On return, the registers are
39 // restored from the structure.
40 .macro ENTRY_ARG cfunc
43 pushl %eax // Save registers (matches struct bregs)
51 movw %ss, %ax // Move %ss to %ds
53 movl %esp, %ebx // Backup %esp, then zero high bits
55 movl %esp, %eax // First arg is pointer to struct bregs
57 movl %ebx, %esp // Restore %esp (including high bits)
58 popw %ds // Restore registers (from struct bregs)
68 // As above, but don't mangle %esp
69 .macro ENTRY_ARG_ESP cfunc
72 pushl %eax // Save registers (matches struct bregs)
80 movw %ss, %ax // Move %ss to %ds
82 movl %esp, %eax // First arg is pointer to struct bregs
84 popw %ds // Restore registers (from struct bregs)
94 // Reset stack, transition to 32bit mode, and call a C function.
96 .macro ENTRY_INTO32 cfunc
99 movl $ BUILD_STACK_ADDR , %esp
104 // Declare a function
106 .section .text.asm.\func
110 // Define an entry point for an interrupt (no args passed).
118 // Define an entry point for an interrupt (can read/modify args).
119 .macro IRQ_ENTRY_ARG num
122 ENTRY_ARG handle_\num
126 // Macros that put each handler into its own section
127 .macro DECL_IRQ_ENTRY num
128 .section .text.asm.entry_\num
131 .macro DECL_IRQ_ENTRY_ARG num
132 .section .text.asm.entry_\num