[PATCH 2/2] x86_64/console: Add NS16550 polled console driver

Amaan Cheval amaan.cheval at gmail.com
Thu Jul 12 16:37:16 UTC 2018


Thanks a lot for the kind words! It definitely wouldn't have come even
this far without this brilliant community, so I really can't take most
of the credit. Thanks for all the help!

P.S. - For those interested, documentation on running is coming soon!

On Thu, Jul 12, 2018 at 2:14 AM, Joel Sherrill <joel at rtems.org> wrote:
> After discussion with Chris and a confirmation from Amaan, I have pushed
> this patch set which means we now have x86_64 and the amd64 BSP.
> Amaan would be the first to tell you that it needs more love but it
> does run hello world and is far enough along where others can
> begin to experiment with and enhance it.
>
> Thanks Amaan. We all look forward to you guiding this port and
> BSP to maturity.  :)
>
> --joel
>
> On Mon, Jul 9, 2018 at 6:12 AM, Amaan Cheval <amaan.cheval at gmail.com> wrote:
>>
>> This addition allows us to successfully run the sample hello.exe test.
>>
>> Updates #2898.
>> ---
>>  bsps/x86_64/amd64/console/console.c                | 123
>> +++++----------------
>>  c/src/lib/libbsp/x86_64/amd64/Makefile.am          |   2 +
>>  .../score/cpu/x86_64/include/rtems/score/cpuimpl.h |  14 +++
>>  .../score/cpu/x86_64/include/rtems/score/x86_64.h  |   3 +
>>  4 files changed, 49 insertions(+), 93 deletions(-)
>>
>> diff --git a/bsps/x86_64/amd64/console/console.c
>> b/bsps/x86_64/amd64/console/console.c
>> index b272b679d7..5408c57fe7 100644
>> --- a/bsps/x86_64/amd64/console/console.c
>> +++ b/bsps/x86_64/amd64/console/console.c
>> @@ -24,112 +24,49 @@
>>   * SUCH DAMAGE.
>>   */
>>
>> -#include <bsp.h>
>> +#include <libchip/ns16550.h>
>>  #include <rtems/bspIo.h>
>> -#include <rtems/libio.h>
>> -
>> -/*  console_initialize
>> - *
>> - *  This routine initializes the console IO driver.
>> - *
>> - *  Input parameters: NONE
>> - *
>> - *  Output parameters:  NONE
>> - *
>> - *  Return values:
>> - */
>> +#include <bsp.h>
>> +#include <bsp/console-termios.h>
>> +#include <rtems/score/cpuimpl.h>
>>
>> -rtems_device_driver console_initialize(
>> -  rtems_device_major_number  major,
>> -  rtems_device_minor_number  minor,
>> -  void                      *arg
>> -)
>> +static uint8_t amd64_uart_get_register(uintptr_t addr, uint8_t i)
>>  {
>> -  (void) major;
>> -  (void) minor;
>> -  (void) arg;
>> -  return RTEMS_SUCCESSFUL;
>> +  return inport_byte(addr + i);
>>  }
>>
>> -/*
>> - *  Open entry point
>> - */
>> -
>> -rtems_device_driver console_open(
>> -  rtems_device_major_number major,
>> -  rtems_device_minor_number minor,
>> -  void                    * arg
>> -)
>> +static void amd64_uart_set_register(uintptr_t addr, uint8_t i, uint8_t
>> val)
>>  {
>> -  (void) major;
>> -  (void) minor;
>> -  (void) arg;
>> -  return RTEMS_SUCCESSFUL;
>> +  outport_byte(addr + i, val);
>>  }
>>
>> -/*
>> - *  Close entry point
>> - */
>> -
>> -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;
>> -}
>> +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
>> +};
>>
>>  /*
>> - * read bytes from the serial port. We only have stdin.
>> + * 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_read(
>> -  rtems_device_major_number major,
>> -  rtems_device_minor_number minor,
>> -  void                    * arg
>> -)
>> +static void output_char(char c)
>>  {
>> -  (void) major;
>> -  (void) minor;
>> -  (void) arg;
>> -  return RTEMS_SUCCESSFUL;
>> -}
>> +  rtems_termios_device_context *ctx = console_device_table[0].context;
>>
>> -/*
>> - * 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;
>> +  ns16550_polled_putchar(ctx, c);
>>  }
>>
>> -BSP_output_char_function_type     BSP_output_char = NULL;
>> -BSP_polling_getchar_function_type BSP_poll_char   = NULL;
>> +BSP_output_char_function_type BSP_output_char   = output_char;
>> +BSP_polling_getchar_function_type BSP_poll_char = NULL;
>> diff --git a/c/src/lib/libbsp/x86_64/amd64/Makefile.am
>> b/c/src/lib/libbsp/x86_64/amd64/Makefile.am
>> index f05b40f3f9..aa40f6224f 100644
>> --- a/c/src/lib/libbsp/x86_64/amd64/Makefile.am
>> +++ b/c/src/lib/libbsp/x86_64/amd64/Makefile.am
>> @@ -29,6 +29,8 @@ librtemsbsp_a_SOURCES +=
>> ../../../../../../bsps/shared/start/bspreset-empty.c
>>  # clock
>>  librtemsbsp_a_SOURCES +=
>> ../../../../../../bsps/shared/dev/clock/clock-simidle.c
>>  # 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
>>  # timer
>>  librtemsbsp_a_SOURCES +=
>> ../../../../../../bsps/shared/dev/btimer/btimer-stub.c
>> diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
>> b/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
>> index bac092c320..67fe712a32 100644
>> --- a/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
>> +++ b/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
>> @@ -28,6 +28,20 @@
>>  extern "C" {
>>  #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
>>  }
>>  #endif
>> diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
>> b/cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
>> index 237d95de98..853e45ab5d 100644
>> --- a/cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
>> +++ b/cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
>> @@ -34,6 +34,9 @@ extern "C" {
>>  #define CPU_NAME "x86-64"
>>  #define CPU_MODEL_NAME "XXX: x86-64 generic"
>>
>> +#define COM1_BASE_IO 0x3F8
>> +#define COM1_CLOCK_RATE (115200 * 16)
>> +
>>  #ifdef __cplusplus
>>  }
>>  #endif
>> --
>> 2.15.0
>>
>



More information about the devel mailing list