aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/io/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/io/io.c')
-rw-r--r--src/kernel/io/io.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c
index 30dcee2..dc2d59a 100644
--- a/src/kernel/io/io.c
+++ b/src/kernel/io/io.c
@@ -40,21 +40,65 @@ void init_serial() {
send_b(0x3f8 + 3, 0x03);
send_b(0x3f8 + 2, 0xC7);
send_b(0x3f8 + 4, 0x0B);
- write_serial("Installed serial connection!");
+ serial_write("Installed serial connection!\n");
}
int is_transmit_empty() {
return receive_b(0x3f8 + 5) & 0x20;
}
-void write_serial(char *data) {
+void serial_put(char ch) {
+ while (is_transmit_empty() == 0);
+ send_b(0x3f8, ch);
+}
+
+void serial_write(char *data) {
for (size_t i = 0; i < strlen(data); i++) {
- while (is_transmit_empty() == 0);
- send_b(0x3f8, data[i]);
+ serial_put(data[i]);
+ }
+}
+
+void serial_write_hex(int n) {
+ int tmp;
+
+ serial_write("0x");
+ char noZeroes = 1;
+
+ for (int i = 28; i > 0; i -= 4) {
+ tmp = (n >> i) & 0xF;
+ if (tmp == 0 && noZeroes != 0) continue;
+
+ if (tmp >= 0xA) {
+ noZeroes = 0;
+ serial_put(tmp - 0xA + 'a');
+ } else {
+ noZeroes = 0;
+ serial_put(tmp + '0');
+ }
+ }
+
+ tmp = n & 0xF;
+ if (tmp >= 0xA) {
+ serial_put(tmp - 0xA + 'a');
+ } else {
+ serial_put(tmp + '0');
}
- char *linebreak = "\n";
- for (size_t i = 0; i < strlen(linebreak); i++) {
- while (is_transmit_empty() == 0);
- send_b(0x3f8, linebreak[i]);
+}
+
+void serial_write_dec(int n) {
+ if (n == 0) serial_put('0');
+ int acc = n;
+ char c[32];
+ int i = 0;
+ while (acc > 0) {
+ c[i] = '0' + acc % 10;
+ acc /= 10;
+ i++;
}
+ c[i] = 0;
+ static char c2[32];
+ c2[i--] = 0;
+ int j = 0;
+ while (i >= 0) c2[i--] = c[j++];
+ serial_write(c2);
}