1 // Basic x86 asm functions and function defs.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU GPLv3 license.
9 #include "ioport.h" // outb
10 #include "biosvar.h" // struct bregs
12 static inline void irq_disable(void)
14 asm volatile("cli": : :"memory");
17 static inline void irq_enable(void)
19 asm volatile("sti": : :"memory");
22 static inline unsigned long irq_save(void)
25 asm volatile("pushfl ; popl %0" : "=g" (flags));
30 static inline void irq_restore(unsigned long flags)
32 asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
35 static inline void nop(void)
40 static inline void hlt(void)
45 #define BX_PANIC(fmt, args...) bprintf(0, fmt , ##args)
46 #define BX_INFO(fmt, args...) bprintf(0, fmt , ##args)
49 memset(void *s, int c, size_t n)
56 memcpy(void *d1, const void *s1, size_t len)
70 outb(PIC1_IRQ5, PORT_PIC1);
76 outb(PIC2_IRQ13, PORT_PIC2);
81 void call16(struct bregs *callregs)
84 "pushl %%ebp\n" // Save state
89 "calll __call16_from32\n"
91 "popfl\n" // Restore state
93 : "+a" (callregs), "+m" (*callregs)
95 : "ebx", "ecx", "edx", "esi", "edi");
99 void __call16_int(struct bregs *callregs, u16 offset)
101 callregs->cs = SEG_BIOS;
102 callregs->ip = offset;
107 #define call16_int(nr, callregs) do { \
108 extern void irq_trampoline_ ##nr (); \
109 __call16_int((callregs), (u16)&irq_trampoline_ ##nr ); \
112 #include "../out/rom16.offset.auto.h"
113 #define call16_int(nr, callregs) \
114 __call16_int((callregs), OFFSET_irq_trampoline_ ##nr )
118 void bprintf(u16 action, const char *fmt, ...)
119 __attribute__ ((format (printf, 2, 3)));
120 void __debug_enter(const char *fname, struct bregs *regs);
121 void __debug_exit(const char *fname, struct bregs *regs);
122 void __debug_stub(const char *fname, struct bregs *regs);
123 void __debug_isr(const char *fname, struct bregs *regs);
124 #define debug_enter(regs) \
125 __debug_enter(__func__, regs)
126 #define debug_exit(regs) \
127 __debug_exit(__func__, regs)
128 #define debug_stub(regs) \
129 __debug_stub(__func__, regs)
130 #define debug_isr(regs) \
131 __debug_isr(__func__, regs)
132 #define printf(fmt, args...) \
133 bprintf(1, fmt , ##args )
136 void handle_15c2(struct bregs *regs);
139 void handle_1583(struct bregs *regs);
142 void VISIBLE16 handle_1553(struct bregs *regs);
144 // Frequent bios return helper
145 #define RET_EUNSUPPORTED 0x86
147 handle_ret(struct bregs *regs, u8 code)
154 void usleep(u32 count);
157 void rombios32_init(void);