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 cpu_relax(void)
37 asm volatile("rep ; nop": : :"memory");
40 static inline void nop(void)
45 static inline void hlt(void)
50 void *memset(void *s, int c, size_t n);
51 void *memcpy(void *d1, const void *s1, size_t len);
56 outb(PIC1_IRQ5, PORT_PIC1);
62 outb(PIC2_IRQ13, PORT_PIC2);
66 // Call a function with a specified register state. Note that on
67 // return, the interrupt enable/disable flag may be altered.
69 void call16(struct bregs *callregs)
75 "calll __call16_from32\n"
77 : "+a" (callregs), "+m" (*callregs)
79 : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
83 void __call16_int(struct bregs *callregs, u16 offset)
85 callregs->cs = SEG_BIOS;
86 callregs->ip = offset;
91 #define call16_int(nr, callregs) do { \
92 extern void irq_trampoline_ ##nr (); \
93 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
96 #include "../out/rom16.offset.auto.h"
97 #define call16_int(nr, callregs) \
98 __call16_int((callregs), OFFSET_irq_trampoline_ ##nr )
102 void BX_PANIC(const char *fmt, ...)
103 __attribute__ ((format (printf, 1, 2)))
104 __attribute__ ((noreturn));
105 void BX_INFO(const char *fmt, ...)
106 __attribute__ ((format (printf, 1, 2)));
107 void printf(const char *fmt, ...)
108 __attribute__ ((format (printf, 1, 2)));
109 void __debug_enter(const char *fname, struct bregs *regs);
110 void __debug_fail(const char *fname, struct bregs *regs);
111 void __debug_stub(const char *fname, struct bregs *regs);
112 void __debug_isr(const char *fname);
113 #define debug_enter(regs) \
114 __debug_enter(__func__, regs)
115 #define debug_stub(regs) \
116 __debug_stub(__func__, regs)
117 #define debug_isr(regs) \
118 __debug_isr(__func__)
120 // Frequently used return codes
121 #define RET_EUNSUPPORTED 0x86
123 set_success(struct bregs *regs)
129 set_code_success(struct bregs *regs)
135 void __set_fail(const char *fname, struct bregs *regs);
136 void __set_code_fail(const char *fname, struct bregs *regs, u8 code);
138 #define set_fail(regs) \
139 __set_fail(__func__, (regs))
140 #define set_code_fail(regs, code) \
141 __set_code_fail(__func__, (regs), (code))
144 void handle_15c2(struct bregs *regs);
148 void debug_serial_setup();
149 void debug_serial(char c);
154 void handle_1583(struct bregs *regs);
157 void VISIBLE16 handle_1553(struct bregs *regs);
160 void handle_1ab1(struct bregs *regs);
163 u8 checksum(u8 *far_data, u32 len);
164 void usleep(u32 count);
167 void rombios32_init(void);
170 void printf_bootdev(u16 bootdev);
173 void interactive_bootmenu();