- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserial.c
More file actions
Latest commit
40 lines (33 loc) · 1.08 KB
/
Copy pathserial.c
File metadata and controls
40 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include"types.h"
#defineCOM1 0x3F8
staticinlinevoidoutb(uint16_tport, uint8_tval) {
__asm__ __volatile__ ("outb %0, %1" : : "a"(val), "Nd"(port));
}
staticinlineuint8_tinb(uint16_tport) {
uint8_tret;
__asm__ __volatile__ ("inb %1, %0" : "=a"(ret) : "Nd"(port));
returnret;
}
// Initialize COM1 Serial Port (Baud rate 38400)
voidinit_serial(void) {
outb(COM1+1, 0x00); // Disable interrupts
outb(COM1+3, 0x80); // Enable DLAB (set baud rate divisor)
outb(COM1+0, 0x03); // Set divisor to 3 (38400 baud)
outb(COM1+1, 0x00);
outb(COM1+3, 0x03); // 8 bits, no parity, one stop bit
outb(COM1+2, 0xC7); // Enable FIFO, clear them, 14-byte threshold
outb(COM1+4, 0x0B); // Enable IRQs, RTS/DSR set
}
intis_transmit_empty(void) {
returninb(COM1+5) &0x20;
}
// Write a character to the debug serial log
voidwrite_serial(chara) {
while (is_transmit_empty() ==0);
outb(COM1, a);
}
voidserial_print(constchar*str) {
for (size_ti=0; str[i] !='\0'; i++) {
write_serial(str[i]);
}
}