SayoriOS 0.3.3

ports.h
1 #pragma once
2
3 #include <common.h>
4 #include <sys/timer.h>
5
6 #define PORT_COM1 0x3f8
7 #define PORT_COM2 0x2F8
8 #define PORT_COM3 0x3E8
9 #define PORT_COM4 0x2E8
10 #define PORT_COM5 0x5F8
11 #define PORT_COM6 0x4F8
12 #define PORT_COM7 0x5E8
13 #define PORT_COM8 0x4E8
14
15 #define LOG_WITH_TIME 0
16
17 extern void (*default_qemu_printf)(const char *text, ...) __attribute__((format(printf, 1, 2)));
18
19 #ifndef RELEASE
20 #if LOG_WITH_TIME == 0
21 #define qemu_log(M, ...) default_qemu_printf("[LOG] (%s:%s:%d) " M "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
22 #define qemu_note(M, ...) default_qemu_printf("[\033[36;1mNOTE\033[33;0m] (%s:%s:%d) \033[36;1m" M "\033[0m\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
23 #define qemu_warn(M, ...) default_qemu_printf("[\033[33;1mWARN\033[33;0m] (%s:%s:%d) \033[33;1m" M "\033[0m\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
24 #define qemu_ok(M, ...) default_qemu_printf("[\033[32;1mOK\033[33;0m] (%s:%s:%d) \033[32;1m" M "\033[0m\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
25 #define qemu_err(M, ...) default_qemu_printf("[\033[31;1mERROR\033[33;0m] (%s:%s:%d) \033[31;1m" M "\033[0m\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
26 #else
27 #define qemu_log(M, ...) qemu_printf("[LOG] [%d] (%s:%s:%d) " M "\033[0m\n", timestamp(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
28 #define qemu_note(M, ...) qemu_printf("[\033[36;1mWARN\033[33;0m] [%d] (%s:%s:%d) \033[36;1m" M "\033[0m\n", timestamp(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
29 #define qemu_warn(M, ...) qemu_printf("[\033[33;1mWARN\033[33;0m] [%d] (%s:%s:%d) \033[33;1m" M "\033[0m\n", timestamp(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
30 #define qemu_ok(M, ...) qemu_printf("[\033[32;1mOK\033[33;0m] [%d] (%s:%s:%d) \033[32;1m" M "\033[0m\n", timestamp(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
31 #define qemu_err(M, ...) qemu_printf("[\033[31;1mERR\033[33;0m] [%d] (%s:%s:%d) \033[31;1m" M "\033[0m\n", timestamp(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
32 #endif
33 #else
34 #define qemu_note(M, ...)
35 #define qemu_log(M, ...)
36 #define qemu_warn(M, ...)
37 #define qemu_ok(M, ...)
38 #define qemu_err(M, ...)
39 #endif
40
41 #define assert(condition, format, ...) do { if (condition) { \
42 qemu_printf("======================================\n"); \
43 qemu_printf("[%s:%s:%d] ASSERT FAILED: " format "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
44 qemu_printf("======================================\n"); \
45 bsod_screen((registers_t){}, "ASSERT_FAIL", "See additional information on COM1 port. (Or Qemu.log if you're using QEMU)", 0xFFFF); \
46 } } while(0)
47
48 // Check if character received.
49 #define is_signal_received(port) (inb(port + 5) & 1)
50
57 SAYORI_INLINE void outb(uint16_t port, uint8_t val) {
58 __asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port));
59 }
60
67 SAYORI_INLINE uint8_t inb(uint16_t port) {
68 uint8_t ret;
69 __asm__ volatile ( "inb %1, %0"
70 : "=a"(ret)
71 : "Nd"(port) );
72 return ret;
73
74 }
75
82 SAYORI_INLINE void outl(uint16_t port, uint32_t val) {
83 __asm__ volatile ( "outl %0, %1" : : "a"(val), "Nd"(port) );
84 }
85
92 SAYORI_INLINE uint32_t inl(uint16_t port) {
93 uint32_t ret;
94 __asm__ volatile( "inl %1, %0" : "=a"(ret) : "Nd"(port) );
95 return ret;
96 }
97
104 SAYORI_INLINE uint16_t inw(uint16_t port) {
105 uint16_t ret;
106 __asm__ volatile ("inw %1, %0" : "=a" (ret) : "Nd" (port));
107 return ret;
108 }
109
116 SAYORI_INLINE void outw(uint16_t port, uint16_t data) {
117 __asm__ volatile ("outw %1, %0" :: "Nd" (port), "a" (data));
118 }
119
120 void insw(uint16_t __port, void *__buf, unsigned long __n);
121 void outsw(uint16_t __port, const void *__buf, unsigned long __n);
122 void insl(uint16_t reg, uint32_t *buffer, int32_t quads);
123 void outsl(uint16_t reg, uint32_t *buffer, int32_t quads);
124
125 void outl(uint16_t port, uint32_t val);
126 uint32_t inl(uint16_t port);
127
128 int32_t com1_is_transmit_empty();
129 int is_com_port(int port);
130 void com1_write_char(char a);
131 void qemu_printf(const char *text, ...);
132 int32_t is_transmit_empty(uint16_t port);
133
134 uint8_t serial_readchar(uint16_t port);
135 void io_wait();
136
137 void new_qemu_printf(const char *format, ...);
common.h
Основные определения ядра
__attribute__
struct registers __attribute__((packed))
Структура данных пакета от мыши
Definition: psf.h:19
qemu_printf
void qemu_printf(const char *text,...)
Вывод QEMU через COM1 информации
Definition: ports.c:149
is_transmit_empty
int32_t is_transmit_empty(uint16_t port)
Проверка занятости порта
Definition: ports.c:67
outsl
void outsl(uint16_t port, uint32_t *buffer, int32_t times)
Запись длинного слова через порт
Definition: ports.c:44
insl
void insl(uint16_t port, uint32_t *buffer, int32_t times)
Чтение длинного слова через порт
Definition: ports.c:30
is_com_port
int is_com_port(int port)
Проверка на тип порта
Definition: ports.c:120
io_wait
void io_wait(void)
Небольшая задержка используя порт 128(0x80)
Definition: ports.c:99