Wrote a very simple UART driver together
This commit is contained in:
parent
488bf0ce0a
commit
6fcb55bdd8
3 changed files with 39 additions and 1 deletions
2
Makefile
2
Makefile
|
|
@ -6,7 +6,7 @@ include config.mk
|
|||
# Add new source files (C or Assembler) here,
|
||||
# preferentially in alphabetical order.
|
||||
KERNEL_SOURCES_x86_64 := \
|
||||
x86_64/init.S \
|
||||
x86_64/uart.c \
|
||||
# end of x86_64 specific kernel sources list
|
||||
|
||||
# Architecture-agnostic kernel sources.
|
||||
|
|
|
|||
4
kernel.c
4
kernel.c
|
|
@ -40,6 +40,8 @@ typedef unsigned long int uint64_t;
|
|||
|
||||
#include "bootboot.h"
|
||||
|
||||
extern void write_string(const char *string);
|
||||
|
||||
/* imported virtual addresses, see linker script */
|
||||
extern BOOTBOOT bootboot; // see bootboot.h
|
||||
extern unsigned char environment[4096]; // configuration, UTF-8 text key=value pairs
|
||||
|
|
@ -88,6 +90,8 @@ extern volatile unsigned char _binary_font_psf_start;
|
|||
|
||||
void puts(char *s)
|
||||
{
|
||||
write_string(s);
|
||||
|
||||
psf2_t *font = (psf2_t*)&_binary_font_psf_start;
|
||||
int x,y,kx=0,line,mask,offs;
|
||||
int bpl=(font->width+7)/8;
|
||||
|
|
|
|||
34
x86_64/uart.c
Normal file
34
x86_64/uart.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#define COM1_BASE_PORT 0x3F8
|
||||
|
||||
int
|
||||
inb(int port)
|
||||
{
|
||||
unsigned char value;
|
||||
__asm__ ("inb %%dx" : "=a"(value) : "d"(port));
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
outb(int port, int value)
|
||||
{
|
||||
__asm__ ("outb %%dx" :: "d"(port), "a"(value));
|
||||
}
|
||||
|
||||
void
|
||||
write_char(char c)
|
||||
{
|
||||
while (1) {
|
||||
int line_status = inb(COM1_BASE_PORT + 5);
|
||||
if (line_status & 0x20) break;
|
||||
}
|
||||
|
||||
outb(COM1_BASE_PORT, c);
|
||||
}
|
||||
|
||||
void
|
||||
write_string(const char *string)
|
||||
{
|
||||
for (const char *c = string; *c != 0; c++) {
|
||||
write_char(*c);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue