redesign of the IO interface
- all messages are stored in a ring buffer - new devices (e.g. UART) are able to print previous messages
This commit is contained in:
parent
7a15541d82
commit
4a9440dd62
6 changed files with 129 additions and 55 deletions
|
@ -60,12 +60,6 @@ int uart_puts(const char *text);
|
||||||
*/
|
*/
|
||||||
int uart_putchar(unsigned char c);
|
int uart_putchar(unsigned char c);
|
||||||
|
|
||||||
/** @brief Start thread to handle inputs on the serial device
|
|
||||||
*
|
|
||||||
* @return error code of create_kernel_thread
|
|
||||||
*/
|
|
||||||
int uart_enable_input(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <eduos/string.h>
|
#include <eduos/string.h>
|
||||||
#include <eduos/mailbox.h>
|
#include <eduos/mailbox.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
#include <asm/page.h>
|
||||||
#include <asm/uart.h>
|
#include <asm/uart.h>
|
||||||
#include <asm/irq.h>
|
#include <asm/irq.h>
|
||||||
#include <asm/irqflags.h>
|
#include <asm/irqflags.h>
|
||||||
|
@ -79,23 +80,32 @@
|
||||||
#define UART_LCR_STOP 0x04 /* Stop bits: 0=1 bit, 1=2 bits */
|
#define UART_LCR_STOP 0x04 /* Stop bits: 0=1 bit, 1=2 bits */
|
||||||
#define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */
|
#define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */
|
||||||
|
|
||||||
|
static uint8_t mmio = 0;
|
||||||
static uint32_t iobase = 0;
|
static uint32_t iobase = 0;
|
||||||
static tid_t id;
|
static tid_t id;
|
||||||
static mailbox_uint8_t input_queue;
|
static mailbox_uint8_t input_queue;
|
||||||
|
|
||||||
#define MEMMAPIO
|
static inline unsigned char read_from_uart(uint32_t off)
|
||||||
#if 1
|
{
|
||||||
#define READ_FROM_UART(x) inportb(iobase + x)
|
if (mmio)
|
||||||
#define WRITE_TO_UART(x, y) outportb(iobase + x, y)
|
return *((volatile unsigned char*) (iobase + off));
|
||||||
#else
|
else
|
||||||
#define READ_FROM_UART(x) inportb(iobase + x)
|
return inportb(iobase + off);
|
||||||
#define WRITE_TO_UART(x, y) outportb(iobase + x, y)
|
}
|
||||||
#endif
|
|
||||||
|
static void write_to_uart(uint32_t off, unsigned char c)
|
||||||
|
{
|
||||||
|
if (mmio)
|
||||||
|
*((volatile unsigned char*) (iobase + off)) = c;
|
||||||
|
else
|
||||||
|
outportb(iobase + off, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get a single character on a serial device */
|
/* Get a single character on a serial device */
|
||||||
static unsigned char uart_getchar(void)
|
static unsigned char uart_getchar(void)
|
||||||
{
|
{
|
||||||
return READ_FROM_UART(UART_RX);
|
return read_from_uart(UART_RX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Puts a single character on a serial device */
|
/* Puts a single character on a serial device */
|
||||||
|
@ -104,7 +114,7 @@ int uart_putchar(unsigned char c)
|
||||||
if (!iobase)
|
if (!iobase)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
WRITE_TO_UART(UART_TX, c);
|
write_to_uart(UART_TX, c);
|
||||||
|
|
||||||
return (int) c;
|
return (int) c;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +136,7 @@ int uart_puts(const char *text)
|
||||||
/* Handles all UART's interrupt */
|
/* Handles all UART's interrupt */
|
||||||
static void uart_handler(struct state *s)
|
static void uart_handler(struct state *s)
|
||||||
{
|
{
|
||||||
unsigned char c = READ_FROM_UART(UART_IIR);
|
unsigned char c = read_from_uart(UART_IIR);
|
||||||
|
|
||||||
while (!(c & UART_IIR_NO_INT)) {
|
while (!(c & UART_IIR_NO_INT)) {
|
||||||
if (c & UART_IIR_RDI) {
|
if (c & UART_IIR_RDI) {
|
||||||
|
@ -135,7 +145,7 @@ static void uart_handler(struct state *s)
|
||||||
mailbox_uint8_post(&input_queue, c);
|
mailbox_uint8_post(&input_queue, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
c = READ_FROM_UART(UART_IIR);
|
c = read_from_uart(UART_IIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,18 +163,6 @@ static int uart_thread(void* arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_enable_input(void)
|
|
||||||
{
|
|
||||||
int err = create_kernel_task(&id, uart_thread, NULL, HIGH_PRIO);
|
|
||||||
|
|
||||||
if (BUILTIN_EXPECT(err, 0))
|
|
||||||
kprintf("Failed to create task (uart): %d\n", err);
|
|
||||||
else
|
|
||||||
kputs("Create task to handle incoming messages (uart)\n");
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uart_config(void)
|
static void uart_config(void)
|
||||||
{
|
{
|
||||||
mailbox_uint8_init(&input_queue);
|
mailbox_uint8_init(&input_queue);
|
||||||
|
@ -174,7 +172,7 @@ static void uart_config(void)
|
||||||
* clear RX and TX FIFO
|
* clear RX and TX FIFO
|
||||||
* set irq trigger to 8 bytes
|
* set irq trigger to 8 bytes
|
||||||
*/
|
*/
|
||||||
WRITE_TO_UART(UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_1);
|
write_to_uart(UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 8bit word length
|
* 8bit word length
|
||||||
|
@ -183,19 +181,25 @@ static void uart_config(void)
|
||||||
* set DLAB=1
|
* set DLAB=1
|
||||||
*/
|
*/
|
||||||
char lcr = UART_LCR_WLEN8 | UART_LCR_DLAB;
|
char lcr = UART_LCR_WLEN8 | UART_LCR_DLAB;
|
||||||
WRITE_TO_UART(UART_LCR, lcr);
|
write_to_uart(UART_LCR, lcr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set baudrate to 115200 (on qemu)
|
* set baudrate to 115200 (on qemu)
|
||||||
*/
|
*/
|
||||||
WRITE_TO_UART(UART_DLL, 0x01);
|
write_to_uart(UART_DLL, 0x01);
|
||||||
WRITE_TO_UART(UART_DLM, 0x00);
|
write_to_uart(UART_DLM, 0x00);
|
||||||
|
|
||||||
/* set DLAB=0 */
|
/* set DLAB=0 */
|
||||||
WRITE_TO_UART(UART_LCR, lcr & (~UART_LCR_DLAB));
|
write_to_uart(UART_LCR, lcr & (~UART_LCR_DLAB));
|
||||||
|
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
WRITE_TO_UART(UART_IER, UART_IER_RDI | UART_IER_RLSI | UART_IER_THRI);
|
write_to_uart(UART_IER, UART_IER_RDI | UART_IER_RLSI | UART_IER_THRI);
|
||||||
|
|
||||||
|
int err = create_kernel_task(&id, uart_thread, NULL, HIGH_PRIO);
|
||||||
|
if (BUILTIN_EXPECT(err, 0))
|
||||||
|
kprintf("Failed to create task for the uart device: %d\n", err);
|
||||||
|
|
||||||
|
koutput_add_uart();
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_init(void)
|
int uart_init(void)
|
||||||
|
@ -213,12 +217,25 @@ int uart_init(void)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
Lsuccess:
|
Lsuccess:
|
||||||
// we use COM1
|
if (pci_info.type[0]) {
|
||||||
iobase = 0x03f8;
|
// we use COM1
|
||||||
irq_install_handler(32+4, uart_handler);
|
mmio = 0;
|
||||||
|
iobase = 0x3F8;
|
||||||
|
irq_install_handler(32+4, uart_handler);
|
||||||
|
} else {
|
||||||
|
mmio = 1;
|
||||||
|
iobase = pci_info.base[0];
|
||||||
|
irq_install_handler(32+pci_info.irq, uart_handler);
|
||||||
|
page_map(iobase & PAGE_MASK, iobase & PAGE_MASK, 1, PG_GLOBAL | PG_RW | PG_PCD);
|
||||||
|
}
|
||||||
|
|
||||||
// configure uart
|
// configure uart
|
||||||
uart_config();
|
uart_config();
|
||||||
|
#else
|
||||||
|
// we use COM1
|
||||||
|
mmio = 0;
|
||||||
|
iobase = 0x3F8;
|
||||||
|
irq_install_handler(32+4, uart_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
||||||
#define CACHE_LINE 64
|
#define CACHE_LINE 64
|
||||||
#define KERNEL_STACK_SIZE (8<<10) /* 8 KiB */
|
#define KERNEL_STACK_SIZE (8<<10) /* 8 KiB */
|
||||||
#define BITMAP_SIZE (128<<5) /* for 128 MiB of RAM */
|
#define BITMAP_SIZE (128<<5) /* for 128 MiB of RAM */
|
||||||
|
#define KMSG_SIZE (8*1024)
|
||||||
#define INT_SYSCALL 0x80
|
#define INT_SYSCALL 0x80
|
||||||
#define MAILBOX_SIZE 32
|
#define MAILBOX_SIZE 32
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,11 @@ int ksnprintf(char *str, size_t size, const char *format, ...);
|
||||||
*/
|
*/
|
||||||
int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix, va_list ap);
|
int kvprintf(char const *fmt, void (*func) (int, void *), void *arg, int radix, va_list ap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add UART device to dump kernel messages
|
||||||
|
*/
|
||||||
|
int koutput_add_uart(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -117,14 +117,14 @@ static int eduos_init(void)
|
||||||
// initialize .bss section
|
// initialize .bss section
|
||||||
memset((void*)&bss_start, 0x00, ((size_t) &bss_end - (size_t) &bss_start));
|
memset((void*)&bss_start, 0x00, ((size_t) &bss_end - (size_t) &bss_start));
|
||||||
|
|
||||||
|
koutput_init();
|
||||||
system_init();
|
system_init();
|
||||||
irq_init();
|
irq_init();
|
||||||
timer_init();
|
timer_init();
|
||||||
koutput_init();
|
|
||||||
multitasking_init();
|
multitasking_init();
|
||||||
memory_init();
|
memory_init();
|
||||||
#ifdef CONFIG_UART
|
#ifdef CONFIG_UART
|
||||||
uart_enable_input();
|
uart_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -29,16 +29,30 @@
|
||||||
#include <eduos/string.h>
|
#include <eduos/string.h>
|
||||||
#include <eduos/stdarg.h>
|
#include <eduos/stdarg.h>
|
||||||
#include <eduos/spinlock.h>
|
#include <eduos/spinlock.h>
|
||||||
#include <asm/uart.h>
|
#include <asm/atomic.h>
|
||||||
|
#include <asm/processor.h>
|
||||||
|
#ifdef CONFIG_VGA
|
||||||
#include <asm/vga.h>
|
#include <asm/vga.h>
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_UART
|
||||||
|
#include <asm/uart.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NO_EARLY_PRINT 0x00
|
||||||
|
#define VGA_EARLY_PRINT 0x01
|
||||||
|
#define UART_EARLY_PRINT 0x02
|
||||||
|
|
||||||
|
#ifdef CONFIG_VGA
|
||||||
|
static uint32_t early_print = VGA_EARLY_PRINT;
|
||||||
|
#else
|
||||||
|
static uint32_t early_print = NO_EARLY_PRINT;
|
||||||
|
#endif
|
||||||
static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT;
|
static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT;
|
||||||
|
static atomic_int32_t kmsg_counter = ATOMIC_INIT(0);
|
||||||
|
static unsigned char kmessages[KMSG_SIZE] __attribute__ ((section(".kmsg"))) = {[0 ... KMSG_SIZE-1] = 0x00};
|
||||||
|
|
||||||
int koutput_init(void)
|
int koutput_init(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_UART
|
|
||||||
uart_init();
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_VGA
|
#ifdef CONFIG_VGA
|
||||||
vga_init();
|
vga_init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,24 +62,67 @@ int koutput_init(void)
|
||||||
|
|
||||||
int kputchar(int c)
|
int kputchar(int c)
|
||||||
{
|
{
|
||||||
spinlock_irqsave_lock(&olock);
|
int pos;
|
||||||
#ifdef CONFIG_UART
|
|
||||||
uart_putchar(c);
|
if (early_print != NO_EARLY_PRINT)
|
||||||
#endif
|
spinlock_irqsave_lock(&olock);
|
||||||
|
|
||||||
|
pos = atomic_int32_inc(&kmsg_counter);
|
||||||
|
kmessages[pos % KMSG_SIZE] = (unsigned char) c;
|
||||||
|
|
||||||
#ifdef CONFIG_VGA
|
#ifdef CONFIG_VGA
|
||||||
vga_putchar(c);
|
if (early_print & VGA_EARLY_PRINT)
|
||||||
|
vga_putchar(c);
|
||||||
#endif
|
#endif
|
||||||
spinlock_irqsave_unlock(&olock);
|
#ifdef CONFIG_UART
|
||||||
|
if (early_print & UART_EARLY_PRINT)
|
||||||
|
uart_putchar(c);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (early_print != NO_EARLY_PRINT)
|
||||||
|
spinlock_irqsave_unlock(&olock);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kputs(const char *str)
|
int kputs(const char *str)
|
||||||
{
|
{
|
||||||
int i;
|
int pos, i, len = strlen(str);
|
||||||
|
|
||||||
for(i=0; str[i] != '\0'; i++)
|
if (early_print != NO_EARLY_PRINT)
|
||||||
kputchar((int) str[i]);
|
spinlock_irqsave_lock(&olock);
|
||||||
|
|
||||||
return i;
|
for(i=0; i<len; i++) {
|
||||||
|
pos = atomic_int32_inc(&kmsg_counter);
|
||||||
|
kmessages[pos % KMSG_SIZE] = str[i];
|
||||||
|
#ifdef CONFIG_VGA
|
||||||
|
if (early_print & VGA_EARLY_PRINT)
|
||||||
|
vga_putchar(str[i]);
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_UART
|
||||||
|
if (early_print & UART_EARLY_PRINT)
|
||||||
|
uart_putchar(str[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (early_print != NO_EARLY_PRINT)
|
||||||
|
spinlock_irqsave_unlock(&olock);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int koutput_add_uart(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_UART
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
early_print |= UART_EARLY_PRINT;
|
||||||
|
|
||||||
|
for(i=0; i<atomic_int32_read(&kmsg_counter); i++)
|
||||||
|
uart_putchar(kmessages[i % KMSG_SIZE]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return -EINVAL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue