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 // XXX - move this to a c file and use PANIC PORT.
46 #define BX_PANIC(fmt, args...) do { \
47 bprintf(0, fmt , ##args); \
53 #define BX_INFO(fmt, args...) bprintf(0, fmt , ##args)
56 memset(void *s, int c, size_t n)
63 memcpy(void *d1, const void *s1, size_t len)
77 outb(PIC1_IRQ5, PORT_PIC1);
83 outb(PIC2_IRQ13, PORT_PIC2);
87 // Call a function with a specified register state. Note that on
88 // return, the interrupt enable/disable flag may be altered.
90 void call16(struct bregs *callregs)
96 "calll __call16_from32\n"
98 : "+a" (callregs), "+m" (*callregs)
100 : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
104 void __call16_int(struct bregs *callregs, u16 offset)
106 callregs->cs = SEG_BIOS;
107 callregs->ip = offset;
112 #define call16_int(nr, callregs) do { \
113 extern void irq_trampoline_ ##nr (); \
114 __call16_int((callregs), (u16)&irq_trampoline_ ##nr ); \
117 #include "../out/rom16.offset.auto.h"
118 #define call16_int(nr, callregs) \
119 __call16_int((callregs), OFFSET_irq_trampoline_ ##nr )
123 void bprintf(u16 action, const char *fmt, ...)
124 __attribute__ ((format (printf, 2, 3)));
125 void __debug_enter(const char *fname, struct bregs *regs);
126 void __debug_fail(const char *fname, struct bregs *regs);
127 void __debug_stub(const char *fname, struct bregs *regs);
128 void __debug_isr(const char *fname);
129 #define debug_enter(regs) \
130 __debug_enter(__func__, regs)
131 #define debug_stub(regs) \
132 __debug_stub(__func__, regs)
133 #define debug_isr(regs) \
134 __debug_isr(__func__)
135 #define printf(fmt, args...) \
136 bprintf(1, fmt , ##args )
138 // Frequently used return codes
139 #define RET_EUNSUPPORTED 0x86
141 set_success(struct bregs *regs)
147 set_code_success(struct bregs *regs)
153 #define set_fail(regs) do { \
154 __debug_fail(__func__, (regs)); \
158 #define set_code_fail(regs, code) do { \
160 (regs)->ah = (code); \
164 void handle_15c2(struct bregs *regs);
167 void handle_1583(struct bregs *regs);
170 void VISIBLE16 handle_1553(struct bregs *regs);
173 void handle_1ab1(struct bregs *regs);
176 void usleep(u32 count);
179 void rombios32_init(void);