added seperate x86 UART routines for HW debugging (115200 baud, 8N1)
This commit is contained in:
parent
5a20e0953f
commit
f0f3a6d4f6
5 changed files with 151 additions and 7 deletions
|
@ -100,11 +100,6 @@ inline static void outportl(unsigned short _port, unsigned int _data)
|
||||||
asm volatile("outl %1, %0"::"dN"(_port), "a"(_data));
|
asm volatile("outl %1, %0"::"dN"(_port), "a"(_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void uart_putchar(unsigned char _data)
|
|
||||||
{
|
|
||||||
outportb(UART_PORT, _data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read a byte from CMOS
|
* read a byte from CMOS
|
||||||
* @param offset CMOS offset
|
* @param offset CMOS offset
|
||||||
|
|
74
arch/x86/include/asm/uart.h
Normal file
74
arch/x86/include/asm/uart.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 Steffen Vogel, Chair for Operating Systems,
|
||||||
|
* RWTH Aachen University
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of MetalSVM.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steffen Vogel
|
||||||
|
* @file arch/x86/include/asm/uart.h
|
||||||
|
* @brief COM port related code
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARCH_UART_H__
|
||||||
|
#define __ARCH_UART_H__
|
||||||
|
|
||||||
|
#include <metalsvm/stddef.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_UART
|
||||||
|
|
||||||
|
/** @brief Initialize VGA output and clear the screen */
|
||||||
|
void uart_init(void);
|
||||||
|
|
||||||
|
/** @brief Send a single character to the uart
|
||||||
|
*
|
||||||
|
* @return The original input character casted to int
|
||||||
|
*/
|
||||||
|
void uart_putchar(char c);
|
||||||
|
|
||||||
|
/** @brief Receive a single character on the uart
|
||||||
|
*
|
||||||
|
* @return The original input character casted to int
|
||||||
|
*/
|
||||||
|
char uart_getchar(void);
|
||||||
|
|
||||||
|
/** @brief Simple string output on screen.
|
||||||
|
*
|
||||||
|
* If you want a new line you will have to "\\n".
|
||||||
|
*
|
||||||
|
* @return Length of output in bytes
|
||||||
|
*/
|
||||||
|
void uart_puts(const char *str);
|
||||||
|
|
||||||
|
/** @brief Simple string output on screen.
|
||||||
|
*
|
||||||
|
* If you want a new line you will have to "\\n".
|
||||||
|
*
|
||||||
|
* @return Length of output in bytes
|
||||||
|
*/
|
||||||
|
int uart_gets(char *str, size_t len);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,4 +1,4 @@
|
||||||
C_source := gdt.c kb.c timer.c irq.c isrs.c idt.c vga.c multiboot.c apic.c pci.c processor.c
|
C_source := gdt.c kb.c timer.c irq.c isrs.c idt.c vga.c uart.c multiboot.c apic.c pci.c processor.c
|
||||||
ASM_source := entry$(BIT).asm string$(BIT).asm
|
ASM_source := entry$(BIT).asm string$(BIT).asm
|
||||||
MODULE := arch_x86_kernel
|
MODULE := arch_x86_kernel
|
||||||
|
|
||||||
|
|
68
arch/x86/kernel/uart.c
Normal file
68
arch/x86/kernel/uart.c
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Steffen Vogel, Chair for Operating Systems,
|
||||||
|
* RWTH Aachen University
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of MetalSVM.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asm/uart.h>
|
||||||
|
#include <asm/io.h>
|
||||||
|
|
||||||
|
static inline int is_transmit_empty()
|
||||||
|
{
|
||||||
|
return inportb(UART_PORT + 5) & 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int received()
|
||||||
|
{
|
||||||
|
return inportb(UART_PORT + 5) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_init()
|
||||||
|
{
|
||||||
|
outportb(UART_PORT + 1, 0x00); // Disable all interrupts
|
||||||
|
outportb(UART_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
|
||||||
|
outportb(UART_PORT + 0, 0x0C); // Set divisor to 12 (lo byte) 9600 baud
|
||||||
|
outportb(UART_PORT + 1, 0x00); // (hi byte)
|
||||||
|
outportb(UART_PORT + 3, 0x03); // 8 bits, no parity, one stop bit (8N1)
|
||||||
|
outportb(UART_PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
|
||||||
|
outportb(UART_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
|
||||||
|
}
|
||||||
|
|
||||||
|
char uart_getchar()
|
||||||
|
{
|
||||||
|
while (!received());
|
||||||
|
return inportb(UART_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_putchar(char chr)
|
||||||
|
{
|
||||||
|
while (!is_transmit_empty());
|
||||||
|
outportb(UART_PORT, chr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_puts(const char* str)
|
||||||
|
{
|
||||||
|
while (*str) uart_putchar(*(str++));
|
||||||
|
}
|
||||||
|
|
||||||
|
int uart_gets(char* str, size_t len)
|
||||||
|
{
|
||||||
|
size_t ret = 0;
|
||||||
|
while (ret < len)
|
||||||
|
str[ret] = uart_getchar();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -163,8 +163,12 @@ int kputchar(int c)
|
||||||
vga_putchar(c);
|
vga_putchar(c);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_UART
|
#ifdef CONFIG_UART
|
||||||
if (early_print & UART_EARLY_PRINT)
|
if (early_print & UART_EARLY_PRINT) {
|
||||||
|
if (c == '\n')
|
||||||
|
uart_putchar('\r');
|
||||||
|
|
||||||
uart_putchar(c);
|
uart_putchar(c);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (early_print != NO_EARLY_PRINT)
|
if (early_print != NO_EARLY_PRINT)
|
||||||
|
@ -189,6 +193,9 @@ int kputs(const char *str)
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_UART
|
#ifdef CONFIG_UART
|
||||||
if (early_print & UART_EARLY_PRINT)
|
if (early_print & UART_EARLY_PRINT)
|
||||||
|
if (str[i] == '\n')
|
||||||
|
uart_putchar('\r');
|
||||||
|
|
||||||
uart_putchar(str[i]);
|
uart_putchar(str[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue