forked from Imagelibrary/rtems
x86_64/console: Add NS16550 polled console driver
This addition allows us to successfully run the sample hello.exe test. Updates #2898.
This commit is contained in:
committed by
Joel Sherrill
parent
76c03152e1
commit
cf811a4eb2
@@ -24,112 +24,49 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <bsp.h>
|
#include <libchip/ns16550.h>
|
||||||
#include <rtems/bspIo.h>
|
#include <rtems/bspIo.h>
|
||||||
#include <rtems/libio.h>
|
#include <bsp.h>
|
||||||
|
#include <bsp/console-termios.h>
|
||||||
|
#include <rtems/score/cpuimpl.h>
|
||||||
|
|
||||||
/* console_initialize
|
static uint8_t amd64_uart_get_register(uintptr_t addr, uint8_t i)
|
||||||
*
|
|
||||||
* This routine initializes the console IO driver.
|
|
||||||
*
|
|
||||||
* Input parameters: NONE
|
|
||||||
*
|
|
||||||
* Output parameters: NONE
|
|
||||||
*
|
|
||||||
* Return values:
|
|
||||||
*/
|
|
||||||
|
|
||||||
rtems_device_driver console_initialize(
|
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void *arg
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
(void) major;
|
return inport_byte(addr + i);
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
|
||||||
return RTEMS_SUCCESSFUL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void amd64_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
|
||||||
|
{
|
||||||
|
outport_byte(addr + i, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ns16550_context amd64_uart_context = {
|
||||||
|
.base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART"),
|
||||||
|
.get_reg = amd64_uart_get_register,
|
||||||
|
.set_reg = amd64_uart_set_register,
|
||||||
|
.port = (uintptr_t) COM1_BASE_IO,
|
||||||
|
.initial_baud = COM1_CLOCK_RATE
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open entry point
|
* XXX: We should use the interrupt based handler once interrupts are supported
|
||||||
*/
|
*/
|
||||||
|
const console_device console_device_table[] = {
|
||||||
|
{
|
||||||
|
.device_file = "/dev/console",
|
||||||
|
.probe = console_device_probe_default,
|
||||||
|
.handler = &ns16550_handler_polled,
|
||||||
|
.context = &amd64_uart_context.base
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
|
||||||
|
|
||||||
rtems_device_driver console_open(
|
static void output_char(char c)
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void * arg
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
(void) major;
|
rtems_termios_device_context *ctx = console_device_table[0].context;
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
ns16550_polled_putchar(ctx, c);
|
||||||
return RTEMS_SUCCESSFUL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
BSP_output_char_function_type BSP_output_char = output_char;
|
||||||
* Close entry point
|
BSP_polling_getchar_function_type BSP_poll_char = NULL;
|
||||||
*/
|
|
||||||
|
|
||||||
rtems_device_driver console_close(
|
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void * arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void) major;
|
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
|
||||||
return RTEMS_SUCCESSFUL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* read bytes from the serial port. We only have stdin.
|
|
||||||
*/
|
|
||||||
|
|
||||||
rtems_device_driver console_read(
|
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void * arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void) major;
|
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
|
||||||
return RTEMS_SUCCESSFUL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* write bytes to the serial port. Stdout and stderr are the same.
|
|
||||||
*/
|
|
||||||
|
|
||||||
rtems_device_driver console_write(
|
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void * arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void) major;
|
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* IO Control entry point
|
|
||||||
*/
|
|
||||||
|
|
||||||
rtems_device_driver console_control(
|
|
||||||
rtems_device_major_number major,
|
|
||||||
rtems_device_minor_number minor,
|
|
||||||
void * arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
(void) major;
|
|
||||||
(void) minor;
|
|
||||||
(void) arg;
|
|
||||||
return RTEMS_SUCCESSFUL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BSP_output_char_function_type BSP_output_char = NULL;
|
|
||||||
BSP_polling_getchar_function_type BSP_poll_char = NULL;
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/start/bspreset-empty.c
|
|||||||
# clock
|
# clock
|
||||||
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/clock/clock-simidle.c
|
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/clock/clock-simidle.c
|
||||||
# console
|
# console
|
||||||
|
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios-init.c
|
||||||
|
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
|
||||||
librtemsbsp_a_SOURCES += ../../../../../../bsps/x86_64/amd64/console/console.c
|
librtemsbsp_a_SOURCES += ../../../../../../bsps/x86_64/amd64/console/console.c
|
||||||
# timer
|
# timer
|
||||||
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/btimer/btimer-stub.c
|
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/btimer/btimer-stub.c
|
||||||
|
|||||||
@@ -28,6 +28,20 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline uint8_t inport_byte(uint16_t port)
|
||||||
|
{
|
||||||
|
uint8_t ret;
|
||||||
|
__asm__ volatile ( "inb %1, %0"
|
||||||
|
: "=a" (ret)
|
||||||
|
: "Nd" (port) );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void outport_byte(uint16_t port, uint8_t val)
|
||||||
|
{
|
||||||
|
__asm__ volatile ( "outb %0, %1" : : "a" (val), "Nd" (port) );
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ extern "C" {
|
|||||||
#define CPU_NAME "x86-64"
|
#define CPU_NAME "x86-64"
|
||||||
#define CPU_MODEL_NAME "XXX: x86-64 generic"
|
#define CPU_MODEL_NAME "XXX: x86-64 generic"
|
||||||
|
|
||||||
|
#define COM1_BASE_IO 0x3F8
|
||||||
|
#define COM1_CLOCK_RATE (115200 * 16)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user