/ kernel / include / kernel.h
kernel.h
 1  #ifndef KERNEL_H
 2  #define KERNEL_H
 3  
 4  #include "types.h"
 5  
 6  // VGA text mode constants
 7  #define VGA_ADDRESS 0xB8000
 8  #define VGA_WIDTH 80
 9  #define VGA_HEIGHT 25
10  
11  // VGA colors
12  enum vga_color {
13      VGA_COLOR_BLACK = 0,
14      VGA_COLOR_BLUE = 1,
15      VGA_COLOR_GREEN = 2,
16      VGA_COLOR_CYAN = 3,
17      VGA_COLOR_RED = 4,
18      VGA_COLOR_MAGENTA = 5,
19      VGA_COLOR_BROWN = 6,
20      VGA_COLOR_LIGHT_GREY = 7,
21      VGA_COLOR_DARK_GREY = 8,
22      VGA_COLOR_LIGHT_BLUE = 9,
23      VGA_COLOR_LIGHT_GREEN = 10,
24      VGA_COLOR_LIGHT_CYAN = 11,
25      VGA_COLOR_LIGHT_RED = 12,
26      VGA_COLOR_LIGHT_MAGENTA = 13,
27      VGA_COLOR_LIGHT_BROWN = 14,
28      VGA_COLOR_WHITE = 15,
29  };
30  
31  // VGA entry color
32  static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
33      return fg | bg << 4;
34  }
35  
36  // Terminal functions
37  void terminal_init(void);
38  void terminal_putchar(char c);
39  void terminal_write(const char* data, size_t size);
40  void terminal_writestring(const char* data);
41  void terminal_clear(void);
42  void terminal_setcolor(uint8_t color);
43  void terminal_get_cursor(size_t* row, size_t* column);
44  
45  // Kernel panic
46  void kernel_panic(const char* message);
47  
48  // System call initialization
49  void syscall_init(void);
50  
51  // Test io_uring functionality
52  void test_io_uring(void);
53  
54  // Debug output
55  void debug_print(const char* str);
56  
57  // Port I/O functions
58  static inline void outb(uint16_t port, uint8_t value) {
59      __asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
60  }
61  
62  static inline uint8_t inb(uint16_t port) {
63      uint8_t value;
64      __asm__ volatile ("inb %1, %0" : "=a"(value) : "Nd"(port));
65      return value;
66  }
67  
68  static inline void outw(uint16_t port, uint16_t value) {
69      __asm__ volatile ("outw %0, %1" : : "a"(value), "Nd"(port));
70  }
71  
72  static inline uint16_t inw(uint16_t port) {
73      uint16_t value;
74      __asm__ volatile ("inw %1, %0" : "=a"(value) : "Nd"(port));
75      return value;
76  }
77  
78  // CPU control
79  static inline void cli(void) {
80      __asm__ volatile ("cli");
81  }
82  
83  static inline void sti(void) {
84      __asm__ volatile ("sti");
85  }
86  
87  static inline void hlt(void) {
88      __asm__ volatile ("hlt");
89  }
90  
91  #endif // KERNEL_H