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

2018-07-09 Thread Amaan Cheval
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 
+#include 
 #include 
-#include 
-
-/*  console_initialize
- *
- *  This routine initializes the console IO driver.
- *
- *  Input parameters: NONE
- *
- *  Output parameters:  NONE
- *
- *  Return values:
- */
+#include 
+#include 
+#include 
 
-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 = _handler_polled,
+.context = _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)
+  

[PATCH 1/2] bsp/x86_64: Minimal bootable BSP

2018-07-09 Thread Amaan Cheval
Current state:

  - Basic context initialization and switching code.
  - Stubbed console (empty functions).
  - Mostly functional linker script (may need tweaks if we ever want to move
away from the large code model (see: CPU_CFLAGS).
  - Fully functional boot, by using FreeBSD's bootloader to load RTEMS's ELF for
UEFI-awareness.

In short, the current state with this commit lets us boot, go through the system
initialization functions, and then call user application's Init task too.

Updates #2898.
---
 bsps/x86_64/amd64/config/amd64.cfg |  13 +
 bsps/x86_64/amd64/console/console.c| 135 
 bsps/x86_64/amd64/headers.am   |   7 +
 bsps/x86_64/amd64/include/bsp.h|  51 +++
 bsps/x86_64/amd64/include/start.h  |  47 +++
 bsps/x86_64/amd64/include/tm27.h   |   1 +
 bsps/x86_64/amd64/start/bsp_specs  |   9 +
 bsps/x86_64/amd64/start/bspstart.c |  32 ++
 bsps/x86_64/amd64/start/linkcmds   | 281 
 bsps/x86_64/amd64/start/start.c|  36 +++
 c/src/aclocal/rtems-cpu-subdirs.m4 |   1 +
 c/src/lib/libbsp/x86_64/Makefile.am|   7 +
 c/src/lib/libbsp/x86_64/acinclude.m4   |  10 +
 c/src/lib/libbsp/x86_64/amd64/Makefile.am  |  40 +++
 c/src/lib/libbsp/x86_64/amd64/configure.ac |  19 ++
 c/src/lib/libbsp/x86_64/configure.ac   |  20 ++
 cpukit/configure.ac|   1 +
 cpukit/librpc/src/xdr/xdr_float.c  |   3 +-
 cpukit/score/cpu/x86_64/Makefile.am|  12 +
 cpukit/score/cpu/x86_64/cpu.c  |  83 +
 cpukit/score/cpu/x86_64/headers.am |  16 +
 .../score/cpu/x86_64/include/machine/elf_machdep.h |   4 +
 cpukit/score/cpu/x86_64/include/rtems/asm.h| 134 
 cpukit/score/cpu/x86_64/include/rtems/score/cpu.h  | 359 +
 .../cpu/x86_64/include/rtems/score/cpuatomic.h |  14 +
 .../score/cpu/x86_64/include/rtems/score/cpuimpl.h |  37 +++
 .../score/cpu/x86_64/include/rtems/score/x86_64.h  |  41 +++
 .../score/cpu/x86_64/x86_64-context-initialize.c   |  95 ++
 cpukit/score/cpu/x86_64/x86_64-context-switch.S|  98 ++
 29 files changed, 1605 insertions(+), 1 deletion(-)
 create mode 100644 bsps/x86_64/amd64/config/amd64.cfg
 create mode 100644 bsps/x86_64/amd64/console/console.c
 create mode 100644 bsps/x86_64/amd64/headers.am
 create mode 100644 bsps/x86_64/amd64/include/bsp.h
 create mode 100644 bsps/x86_64/amd64/include/start.h
 create mode 100644 bsps/x86_64/amd64/include/tm27.h
 create mode 100644 bsps/x86_64/amd64/start/bsp_specs
 create mode 100644 bsps/x86_64/amd64/start/bspstart.c
 create mode 100644 bsps/x86_64/amd64/start/linkcmds
 create mode 100644 bsps/x86_64/amd64/start/start.c
 create mode 100644 c/src/lib/libbsp/x86_64/Makefile.am
 create mode 100644 c/src/lib/libbsp/x86_64/acinclude.m4
 create mode 100644 c/src/lib/libbsp/x86_64/amd64/Makefile.am
 create mode 100644 c/src/lib/libbsp/x86_64/amd64/configure.ac
 create mode 100644 c/src/lib/libbsp/x86_64/configure.ac
 create mode 100644 cpukit/score/cpu/x86_64/Makefile.am
 create mode 100644 cpukit/score/cpu/x86_64/cpu.c
 create mode 100644 cpukit/score/cpu/x86_64/headers.am
 create mode 100644 cpukit/score/cpu/x86_64/include/machine/elf_machdep.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/asm.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpuatomic.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
 create mode 100644 cpukit/score/cpu/x86_64/x86_64-context-initialize.c
 create mode 100644 cpukit/score/cpu/x86_64/x86_64-context-switch.S

diff --git a/bsps/x86_64/amd64/config/amd64.cfg 
b/bsps/x86_64/amd64/config/amd64.cfg
new file mode 100644
index 00..3c4492d9d3
--- /dev/null
+++ b/bsps/x86_64/amd64/config/amd64.cfg
@@ -0,0 +1,13 @@
+include $(RTEMS_ROOT)/make/custom/default.cfg
+
+RTEMS_CPU = x86_64
+
+CFLAGS_OPTIMIZE_V += -O2 -g
+CFLAGS_OPTIMIZE_V += -ffunction-sections -fdata-sections
+
+# We can't have the red zone because interrupts will not respect that area.
+CPU_CFLAGS  = -mno-red-zone
+# This flag tells GCC to not assume values will fit in 32-bit registers. This
+# way we can avoid linker-time relocation errors spawning from values being
+# larger than their optimized container sizes.
+CPU_CFLAGS += -mcmodel=large
diff --git a/bsps/x86_64/amd64/console/console.c 
b/bsps/x86_64/amd64/console/console.c
new file mode 100644
index 00..b272b679d7
--- /dev/null
+++ b/bsps/x86_64/amd64/console/console.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2018.
+ * Amaan Cheval 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * 

[PATCH 0/2] [GSoC - x86_64] Minimal BSP patch

2018-07-09 Thread Amaan Cheval
This patchset is also available on Github as a pull-request for anyone who would
rather review it there (personally that's what I'd prefer):

  https://github.com/AmaanC/rtems-gsoc18/pull/2

For posterity, my concerns (also listed in the PR description) are:

- The use of '-mcmodel=large' in 'amd64.cfg'

- The lack of of 'LDFLAGS = -Wl,--gc-sections' in 'amd64.cfg' (see

https://github.com/AmaanC/rtems-gsoc18/commit/153c1c7addec6f95ee15505c1de17220b8257ecb
  for why)

- The folder structure and filenames (where do we use 'console/console.c',
  vs. just 'console.c'? Where do we place files that _may_ be shared for other
  BSPs in the same computer family (for eg. 'x86_64/amd64/include/start.h')?)

- 'XXX' comments in code - I'm not sure if all of them should be upstream, and
  would appreciate someone keeping an eye out for any that may be out of place
  or should simply be tickets on Trac instead

- The way 'x86_64-context-switch.S' works directly on the 'Context_Control'
  structure (Ctrl+F 'CPU_SIZEOF_POINTER')

Amaan Cheval (2):
  bsp/x86_64: Minimal bootable BSP
  x86_64/console: Add NS16550 polled console driver

 bsps/x86_64/amd64/config/amd64.cfg |  13 +
 bsps/x86_64/amd64/console/console.c|  72 +
 bsps/x86_64/amd64/headers.am   |   7 +
 bsps/x86_64/amd64/include/bsp.h|  51 +++
 bsps/x86_64/amd64/include/start.h  |  47 +++
 bsps/x86_64/amd64/include/tm27.h   |   1 +
 bsps/x86_64/amd64/start/bsp_specs  |   9 +
 bsps/x86_64/amd64/start/bspstart.c |  32 ++
 bsps/x86_64/amd64/start/linkcmds   | 281 
 bsps/x86_64/amd64/start/start.c|  36 +++
 c/src/aclocal/rtems-cpu-subdirs.m4 |   1 +
 c/src/lib/libbsp/x86_64/Makefile.am|   7 +
 c/src/lib/libbsp/x86_64/acinclude.m4   |  10 +
 c/src/lib/libbsp/x86_64/amd64/Makefile.am  |  42 +++
 c/src/lib/libbsp/x86_64/amd64/configure.ac |  19 ++
 c/src/lib/libbsp/x86_64/configure.ac   |  20 ++
 cpukit/configure.ac|   1 +
 cpukit/librpc/src/xdr/xdr_float.c  |   3 +-
 cpukit/score/cpu/x86_64/Makefile.am|  12 +
 cpukit/score/cpu/x86_64/cpu.c  |  83 +
 cpukit/score/cpu/x86_64/headers.am |  16 +
 .../score/cpu/x86_64/include/machine/elf_machdep.h |   4 +
 cpukit/score/cpu/x86_64/include/rtems/asm.h| 134 
 cpukit/score/cpu/x86_64/include/rtems/score/cpu.h  | 359 +
 .../cpu/x86_64/include/rtems/score/cpuatomic.h |  14 +
 .../score/cpu/x86_64/include/rtems/score/cpuimpl.h |  51 +++
 .../score/cpu/x86_64/include/rtems/score/x86_64.h  |  44 +++
 .../score/cpu/x86_64/x86_64-context-initialize.c   |  95 ++
 cpukit/score/cpu/x86_64/x86_64-context-switch.S|  98 ++
 29 files changed, 1561 insertions(+), 1 deletion(-)
 create mode 100644 bsps/x86_64/amd64/config/amd64.cfg
 create mode 100644 bsps/x86_64/amd64/console/console.c
 create mode 100644 bsps/x86_64/amd64/headers.am
 create mode 100644 bsps/x86_64/amd64/include/bsp.h
 create mode 100644 bsps/x86_64/amd64/include/start.h
 create mode 100644 bsps/x86_64/amd64/include/tm27.h
 create mode 100644 bsps/x86_64/amd64/start/bsp_specs
 create mode 100644 bsps/x86_64/amd64/start/bspstart.c
 create mode 100644 bsps/x86_64/amd64/start/linkcmds
 create mode 100644 bsps/x86_64/amd64/start/start.c
 create mode 100644 c/src/lib/libbsp/x86_64/Makefile.am
 create mode 100644 c/src/lib/libbsp/x86_64/acinclude.m4
 create mode 100644 c/src/lib/libbsp/x86_64/amd64/Makefile.am
 create mode 100644 c/src/lib/libbsp/x86_64/amd64/configure.ac
 create mode 100644 c/src/lib/libbsp/x86_64/configure.ac
 create mode 100644 cpukit/score/cpu/x86_64/Makefile.am
 create mode 100644 cpukit/score/cpu/x86_64/cpu.c
 create mode 100644 cpukit/score/cpu/x86_64/headers.am
 create mode 100644 cpukit/score/cpu/x86_64/include/machine/elf_machdep.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/asm.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpu.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpuatomic.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
 create mode 100644 cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h
 create mode 100644 cpukit/score/cpu/x86_64/x86_64-context-initialize.c
 create mode 100644 cpukit/score/cpu/x86_64/x86_64-context-switch.S

-- 
2.15.0

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel