/* * 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 #include /** * @author Steffen Vogel */ 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; }