Commit 20eb3a51 by triazo

Make serial work more reliably

parent 47bb3424
/*
asm.c contains x86 specific functions for executing low level code
*/
#include "asm.h"
// Wrapper for outb
// Stolen from http://wiki.osdev.org/Inline_Assembly/Examples
static inline void outb(uint16_t port, uint8_t val) {
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
}
// Wrapper for inb
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
/* /*
asm.h exports archatecture specific functions for hardware interaction asm.h contains x86 specific functions for executing low level code
*/ */
#pragma once
#include <stdint.h> #include <stdint.h>
// Functions for reading and writing to/from x86 IO ports // Wrapper for outb
static inline void outb(uint16_t port, uint8_t val); // Stolen from http://wiki.osdev.org/Inline_Assembly/Examples
static inline uint8_t inb(uint16_t port); inline void outb(uint16_t port, uint8_t val) {
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
}
// Wrapper for inb
inline uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
...@@ -110,7 +110,8 @@ void kernel_main() { ...@@ -110,7 +110,8 @@ void kernel_main() {
* yet, '\n' will produce some VGA specific character instead. * yet, '\n' will produce some VGA specific character instead.
* This is normal. * This is normal.
*/ */
terminal_writestring("Hello, kernel World!\n");
serial_init(); serial_init();
serial_writestring("Hello, kernel World!\n"); serial_writestring("First Serial Test!\n");
terminal_writestring("Hello, kernel World!\n");
serial_writestring("Second Serial Test\n");
} }
...@@ -6,3 +6,4 @@ all: ...@@ -6,3 +6,4 @@ all:
$C -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib *.o -lgcc $C -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib *.o -lgcc
clean: clean:
rm *.o *.bin
...@@ -27,7 +27,7 @@ void serial_writechar(char a) { ...@@ -27,7 +27,7 @@ void serial_writechar(char a) {
} }
void serial_writestring(char* s) { void serial_writestring(char* s) {
while (s) { while (*s) {
serial_writechar(*s); serial_writechar(*s);
s++; s++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment