axle OS
x86_32 UNIX-like hobby OS
common.h
1 #ifndef STD_COMMON_H
2 #define STD_COMMON_H
3 
4 #include "std_base.h"
5 #include <stdint.h>
6 
7 __BEGIN_DECLS
8 
9 #define kernel_begin_critical() __asm__("cli");
10 #define kernel_end_critical() __asm__("sti");
11 
12 //if the memory layout of this changes, kernel/util/interrupts/interrupt.s must be changed as well
13 //to correct offsets
14 typedef struct registers {
15  unsigned int gs, fs, es, ds; //segment registers
16  unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; //pushed by pusha
17  unsigned int int_no, err_code; //interrupt number and error code
18  unsigned int eip, cs, eflags, useresp, ss; //pushed by the processor automatically
19 } registers_t;
20 
21 //write byte to port
22 STDAPI void outb(uint16_t port, uint8_t val);
23 //write word to port
24 STDAPI void outw(uint16_t port, uint16_t val);
25 //write 32bits to port
26 STDAPI void outl(uint16_t port, uint32_t val);
27 
28 //read byte from port
29 STDAPI uint8_t inb(uint16_t port);
30 //read word from port
31 STDAPI uint16_t inw(uint16_t port);
32 //read 32bits from port
33 STDAPI uint32_t inl(uint16_t port);
34 
35 //force wait for i/o operation to complete
36 //this should only be used when there's nothing like
37 //a status register or IRQ to tell you info has been received
38 STDAPI void io_wait(void);
39 
40 //returns if interrupts are on
41 STDAPI char interrupts_enabled(void);
42 
43 //requests CPUID
44 STDAPI void cpuid(int code, uint32_t* a, uint32_t* d);
45 
46 __END_DECLS
47 
48 #endif // STD_COMMON_H
Definition: common.h:14