<div dir="ltr">After discussion with Chris and a confirmation from Amaan, I have pushed<div>this patch set which means we now have x86_64 and the amd64 BSP.</div><div>Amaan would be the first to tell you that it needs more love but it</div><div>does run hello world and is far enough along where others can </div><div>begin to experiment with and enhance it.</div><div><br></div><div>Thanks Amaan. We all look forward to you guiding this port and</div><div>BSP to maturity.  :)</div><div><br></div><div>--joel</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 9, 2018 at 6:12 AM, Amaan Cheval <span dir="ltr"><<a href="mailto:amaan.cheval@gmail.com" target="_blank">amaan.cheval@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This addition allows us to successfully run the sample hello.exe test.<br>
<br>
Updates #2898.<br>
---<br>
 bsps/x86_64/amd64/console/<wbr>console.c                | 123 +++++----------------<br>
 c/src/lib/libbsp/x86_64/amd64/<wbr>Makefile.am          |   2 +<br>
 .../score/cpu/x86_64/include/<wbr>rtems/score/cpuimpl.h |  14 +++<br>
 .../score/cpu/x86_64/include/<wbr>rtems/score/x86_64.h  |   3 +<br>
 4 files changed, 49 insertions(+), 93 deletions(-)<br>
<br>
diff --git a/bsps/x86_64/amd64/console/<wbr>console.c b/bsps/x86_64/amd64/console/<wbr>console.c<br>
index b272b679d7..5408c57fe7 100644<br>
--- a/bsps/x86_64/amd64/console/<wbr>console.c<br>
+++ b/bsps/x86_64/amd64/console/<wbr>console.c<br>
@@ -24,112 +24,49 @@<br>
  * SUCH DAMAGE.<br>
  */<br>
<br>
-#include <bsp.h><br>
+#include <libchip/ns16550.h><br>
 #include <rtems/bspIo.h><br>
-#include <rtems/libio.h><br>
-<br>
-/*  console_initialize<br>
- *<br>
- *  This routine initializes the console IO driver.<br>
- *<br>
- *  Input parameters: NONE<br>
- *<br>
- *  Output parameters:  NONE<br>
- *<br>
- *  Return values:<br>
- */<br>
+#include <bsp.h><br>
+#include <bsp/console-termios.h><br>
+#include <rtems/score/cpuimpl.h><br>
<br>
-rtems_device_driver console_initialize(<br>
-  rtems_device_major_number  major,<br>
-  rtems_device_minor_number  minor,<br>
-  void                      *arg<br>
-)<br>
+static uint8_t amd64_uart_get_register(<wbr>uintptr_t addr, uint8_t i)<br>
 {<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return RTEMS_SUCCESSFUL;<br>
+  return inport_byte(addr + i);<br>
 }<br>
<br>
-/*<br>
- *  Open entry point<br>
- */<br>
-<br>
-rtems_device_driver console_open(<br>
-  rtems_device_major_number major,<br>
-  rtems_device_minor_number minor,<br>
-  void                    * arg<br>
-)<br>
+static void amd64_uart_set_register(<wbr>uintptr_t addr, uint8_t i, uint8_t val)<br>
 {<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return RTEMS_SUCCESSFUL;<br>
+  outport_byte(addr + i, val);<br>
 }<br>
<br>
-/*<br>
- *  Close entry point<br>
- */<br>
-<br>
-rtems_device_driver console_close(<br>
-  rtems_device_major_number major,<br>
-  rtems_device_minor_number minor,<br>
-  void                    * arg<br>
-)<br>
-{<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return RTEMS_SUCCESSFUL;<br>
-}<br>
+static ns16550_context amd64_uart_context = {<br>
+  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_<wbr>INITIALIZER("UART"),<br>
+  .get_reg = amd64_uart_get_register,<br>
+  .set_reg = amd64_uart_set_register,<br>
+  .port = (uintptr_t) COM1_BASE_IO,<br>
+  .initial_baud = COM1_CLOCK_RATE<br>
+};<br>
<br>
 /*<br>
- * read bytes from the serial port. We only have stdin.<br>
+ * XXX: We should use the interrupt based handler once interrupts are supported<br>
  */<br>
+const console_device console_device_table[] = {<br>
+  {<br>
+    .device_file = "/dev/console",<br>
+    .probe = console_device_probe_default,<br>
+    .handler = &ns16550_handler_polled,<br>
+    .context = &amd64_uart_context.base<br>
+  }<br>
+};<br>
+const size_t console_device_count = RTEMS_ARRAY_SIZE(console_<wbr>device_table);<br>
<br>
-rtems_device_driver console_read(<br>
-  rtems_device_major_number major,<br>
-  rtems_device_minor_number minor,<br>
-  void                    * arg<br>
-)<br>
+static void output_char(char c)<br>
 {<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return RTEMS_SUCCESSFUL;<br>
-}<br>
+  rtems_termios_device_context *ctx = console_device_table[0].<wbr>context;<br>
<br>
-/*<br>
- * write bytes to the serial port. Stdout and stderr are the same.<br>
- */<br>
-<br>
-rtems_device_driver console_write(<br>
-  rtems_device_major_number major,<br>
-  rtems_device_minor_number minor,<br>
-  void                    * arg<br>
-)<br>
-{<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return 0;<br>
-}<br>
-<br>
-/*<br>
- *  IO Control entry point<br>
- */<br>
-<br>
-rtems_device_driver console_control(<br>
-  rtems_device_major_number major,<br>
-  rtems_device_minor_number minor,<br>
-  void                    * arg<br>
-)<br>
-{<br>
-  (void) major;<br>
-  (void) minor;<br>
-  (void) arg;<br>
-  return RTEMS_SUCCESSFUL;<br>
+  ns16550_polled_putchar(ctx, c);<br>
 }<br>
<br>
-BSP_output_char_function_type     BSP_output_char = NULL;<br>
-BSP_polling_getchar_function_<wbr>type BSP_poll_char   = NULL;<br>
+BSP_output_char_function_type BSP_output_char   = output_char;<br>
+BSP_polling_getchar_function_<wbr>type BSP_poll_char = NULL;<br>
diff --git a/c/src/lib/libbsp/x86_64/<wbr>amd64/Makefile.am b/c/src/lib/libbsp/x86_64/<wbr>amd64/Makefile.am<br>
index f05b40f3f9..aa40f6224f 100644<br>
--- a/c/src/lib/libbsp/x86_64/<wbr>amd64/Makefile.am<br>
+++ b/c/src/lib/libbsp/x86_64/<wbr>amd64/Makefile.am<br>
@@ -29,6 +29,8 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/<wbr>start/bspreset-empty.c<br>
 # clock<br>
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/<wbr>dev/clock/clock-simidle.c<br>
 # console<br>
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/<wbr>dev/serial/console-termios-<wbr>init.c<br>
+librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/<wbr>dev/serial/console-termios.c<br>
 librtemsbsp_a_SOURCES += ../../../../../../bsps/x86_64/<wbr>amd64/console/console.c<br>
 # timer<br>
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/<wbr>dev/btimer/btimer-stub.c<br>
diff --git a/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/cpuimpl.h b/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/cpuimpl.h<br>
index bac092c320..67fe712a32 100644<br>
--- a/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/cpuimpl.h<br>
+++ b/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/cpuimpl.h<br>
@@ -28,6 +28,20 @@<br>
 extern "C" {<br>
 #endif<br>
<br>
+static inline uint8_t inport_byte(uint16_t port)<br>
+{<br>
+  uint8_t ret;<br>
+  __asm__ volatile ( "inb %1, %0"<br>
+                     : "=a" (ret)<br>
+                     : "Nd" (port) );<br>
+  return ret;<br>
+}<br>
+<br>
+static inline void outport_byte(uint16_t port, uint8_t val)<br>
+{<br>
+  __asm__ volatile ( "outb %0, %1" : : "a" (val), "Nd" (port) );<br>
+}<br>
+<br>
 #ifdef __cplusplus<br>
 }<br>
 #endif<br>
diff --git a/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/x86_64.h b/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/x86_64.h<br>
index 237d95de98..853e45ab5d 100644<br>
--- a/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/x86_64.h<br>
+++ b/cpukit/score/cpu/x86_64/<wbr>include/rtems/score/x86_64.h<br>
@@ -34,6 +34,9 @@ extern "C" {<br>
 #define CPU_NAME "x86-64"<br>
 #define CPU_MODEL_NAME "XXX: x86-64 generic"<br>
<br>
+#define COM1_BASE_IO 0x3F8<br>
+#define COM1_CLOCK_RATE (115200 * 16)<br>
+<br>
 #ifdef __cplusplus<br>
 }<br>
 #endif<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.15.0<br>
<br>
</font></span></blockquote></div><br></div>