changeset 3943:e4c1caba98e3

merge
author glihm <bertinp17@icloud.com>
date Tue, 22 May 2018 13:14:07 +0200
parents af350a7c391a (current diff) 27a3c7766ed8 (diff)
children 7986589d0de4
files
diffstat 16 files changed, 232 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Thu May 17 20:18:41 2018 +0200
+++ b/.hgsubstate	Tue May 22 13:14:07 2018 +0200
@@ -1,2 +1,2 @@
 6b4b0bc1e8c6cd3459c2cefe898945641dfbf60c gct/gct
-02ef5d14d6e64cab9e17475582865699e3ea171d libtermui/libtermui
+8219e95e12be71506c24f76a27e02153e9ba58ce libtermui/libtermui
--- a/hexo/Makefile	Thu May 17 20:18:41 2018 +0200
+++ b/hexo/Makefile	Tue May 22 13:14:07 2018 +0200
@@ -1,7 +1,7 @@
 
 enum_headers = include/hexo/power.h
 
-DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED
+DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED -DLOGK_MODULE_ID='"hexo"'
 
 objs = cpu.o interrupt.o enum.o atomic.o bit.o flash.o
 
--- a/libdevice/Makefile	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/Makefile	Tue May 22 13:14:07 2018 +0200
@@ -1,5 +1,5 @@
 
-DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED
+DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED -DLOGK_MODULE_ID='"dev "'
 
 enum_headers = include/device/types.h \
                include/device/driver.h \
--- a/libdevice/device_clock.c	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/device_clock.c	Tue May 22 13:14:07 2018 +0200
@@ -21,6 +21,7 @@
 
 */
 
+#undef LOGK_MODULE_ID
 #define LOGK_MODULE_ID "devc"
 
 #include <device/device.h>
--- a/libdevice/device_usbdev.c	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/device_usbdev.c	Tue May 22 13:14:07 2018 +0200
@@ -20,6 +20,7 @@
 
 */
 
+#undef LOGK_MODULE_ID
 #define LOGK_MODULE_ID "usbd"
 
 #include <device/device.h>
--- a/libdevice/driver.c	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/driver.c	Tue May 22 13:14:07 2018 +0200
@@ -21,8 +21,6 @@
     Copyright (c) 2011 Institut Telecom / Telecom ParisTech
 */
 
-#define LOGK_MODULE_ID "ddrv"
-
 #include <hexo/error.h>
 #include <hexo/ordering.h>
 
@@ -449,7 +447,7 @@
 #endif
       )
     {
-      INIT_DEVREADY_INIT();
+      mutekh_startup_devready();
       device_init_pass = 2;
       order_smp_write();
     }
@@ -484,13 +482,13 @@
  switch (err)
     {
     case 0:
-      logk_debug(" - %p %s done", dev, dev->node.name);
+      logk_debug(" - %s init done", dev->node.name);
       dev->status = DEVICE_INIT_DONE;
       break;
 
     case -EAGAIN:
 #if defined(CONFIG_DEVICE_INIT_PARTIAL) || defined(CONFIG_DEVICE_INIT_ASYNC)
-      logk_debug(" - %p %s ongoing", dev, dev->node.name);
+      logk_debug(" - %s init ongoing", dev->node.name);
       dev->status = DEVICE_INIT_ONGOING;
       break;
 #else
@@ -501,13 +499,13 @@
 #ifdef CONFIG_DEVICE_INIT_PARTIAL
       if (dev->init_mask)
         {
-          logk_debug(" - %p %s partial (err=%i)", dev, dev->node.name, err);
+          logk_debug(" - %s init partial (err=%i)", dev->node.name, err);
           dev->status = DEVICE_INIT_PARTIAL;
         }
       else
 #endif
         {
-          logk_error(" - %p %s fail (err=%i)", dev, dev->node.name, err);
+          logk_error(" - %s fail (err=%i)", dev->node.name, err);
 #ifdef CONFIG_DEVICE_TREE
           assert(device_list_isempty(&dev->node.children));
 #endif
@@ -528,9 +526,6 @@
 void device_async_init_done(struct device_s *dev, error_t err)
 {
   assert(dev->status == DEVICE_INIT_ONGOING);
-
-  logk_debug("Initializing %p %s...", dev, dev->node.name);
-
   device_update_status(dev, err);
 }
 
@@ -763,8 +758,8 @@
 #endif
             default:
             missing:
-              logk_error(" - %p %s dependency error `%s'",
-                     dev, dev->node.name, path);
+              logk_error(" - %s dependency error on `%s'",
+                     dev->node.name, path);
               dev->status = DEVICE_INIT_FAILED;
               return -ENOENT;
 
@@ -795,7 +790,7 @@
     return -EAGAIN;
 #endif
 
-  logk_debug("Initializing %p %s...", dev, dev->node.name);
+  logk_debug("Init %s", dev->node.name);
 
   /* device init */
   err = drv->f_init(dev, cl_missing);
--- a/libdevice/init.c	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/init.c	Tue May 22 13:14:07 2018 +0200
@@ -19,8 +19,6 @@
 
 */
 
-#define LOGK_MODULE_ID "devi"
-
 #include <mutek/startup.h>
 #include <mutek/printk.h>
 
@@ -57,7 +55,7 @@
 
   device_put_accessor(&cpu_dev.base);
 
-  logk_debug(" - %u done", id);
+  logk_debug(" - cpu %u done", id);
 
   mutekh_startup_smp_barrier();
 }
--- a/libdevice/irq.c	Thu May 17 20:18:41 2018 +0200
+++ b/libdevice/irq.c	Tue May 22 13:14:07 2018 +0200
@@ -21,8 +21,6 @@
 
 */
 
-#define LOGK_MODULE_ID "dirq"
-
 #include <device/device.h>
 #include <device/resources.h>
 #include <device/driver.h>
@@ -352,7 +350,7 @@
 
       if (!icu_path)
         {
-          logk_error("Missing icu device resource for device %p", dev);
+          logk_error("%s: Missing icu device resource", dev->node.name);
           return -ENOENT;
         }
 
@@ -360,15 +358,16 @@
 
       if (src_id >= src_count)
         {
-          logk_error("Driver for device %p does not provide source endpoint for IRQ output %u",
-                 dev, src_id);
+          logk_error("%s: Driver does not provide source endpoint for IRQ output %u",
+                 dev->node.name, src_id);
           err = -ENOENT;
           goto error;
         }
 
       if (done[src_id])
         {
-          logk_error("Multiple resource entries for IRQ source endpoint %u", dev, src_id);
+          logk_error("%s: Multiple resource entries for IRQ source endpoint %u",
+                     dev->node.name, src_id);
           err = -ENOENT;
           goto error;
         }
@@ -376,7 +375,8 @@
       struct device_icu_s icu;
       if (device_get_accessor_by_path(&icu.base, &dev->node, icu_path, DRIVER_CLASS_ICU))
         {
-          logk_error("Can not use %s device as an interrupt controller", icu_path);
+          logk_error("%s: Can not use `%s' device as an interrupt controller",
+                     dev->node.name, icu_path);
           err = -EINVAL;
           goto error;
         }
@@ -389,7 +389,8 @@
 
       if (!sink)
         {
-          logk_error("Interrupt controller %p does not have sink endpoint for IRQ input %u", icu_dev, r->u.irq.sink_id);
+          logk_error("%s: Interrupt controller `%s' does not have sink endpoint for IRQ input %u",
+                     dev->node.name, icu_dev->node.name, r->u.irq.sink_id);
           err = -EINVAL;
           goto error;
         }
@@ -410,7 +411,8 @@
         {
           if (irq_id != src->irq_id)
             {
-              logk_error("Irq linked to multiple sinks with different logical ids", icu_dev);
+              logk_error("%s: Irq linked to multiple sinks with different logical ids",
+                         icu_dev->node.name);
               err = -EINVAL;
               goto error;
             }
@@ -425,7 +427,8 @@
           trig_mode &= sink->sense_link;
           if (!trig_mode)
             {
-              logk_error("Icu %p can't share a sink endpoint with a different trigger mode", icu_dev);
+              logk_error("%s: Can't share a sink endpoint with a different trigger modes",
+                         icu_dev->node.name);
               err = -EINVAL;
               goto error;
             }
@@ -440,7 +443,8 @@
               trig_mode &= sink->sense_all;
               if (!trig_mode)
                 {
-                  logk_error("Trigger modes of IRQ source %u of device %p not supported by sink", src_id, dev);
+                  logk_error("%s: Trigger modes of IRQ source %u not supported by sink",
+                             dev->node.name, src_id);
                   err = -EINVAL;
                   goto error;
                 }
@@ -453,7 +457,7 @@
       /* setup interrupt controller */
       if ((err = device_icu_source_link(src, &route_mask)))
         {
-          logk_error("Unable to link IRQ source %u of device %p", src_id, dev);
+          logk_error("%s: Unable to link IRQ source %u", dev->node.name, src_id);
           err = -EINVAL;
           goto error;
         }
@@ -479,7 +483,8 @@
   for (i = 0; i < src_count; i++)
     if (!done[i])
       {
-        logk_error("Unable to link IRQ source endpoint %u of device %p, no IRQ resource entry", i, dev);
+        logk_error("%s: Unable to link IRQ source endpoint %u, no IRQ resource entry",
+                   dev->node.name, i);
         err = -ENOENT;
         goto error;
       }
@@ -634,7 +639,7 @@
 
     err = device_get_accessor_by_path(&icu.base, NULL, icu_name, DRIVER_CLASS_ICU);
     if (err) {
-        logk_error("Error while getting icu \"%s\": %d", icu_name, err);
+        logk_error("Unable to get icu `%s'", icu_name);
         return err;
     }
 
--- a/mutek/Makefile	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/Makefile	Tue May 22 13:14:07 2018 +0200
@@ -1,5 +1,5 @@
 
-DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED
+DIR_CFLAGS = -D_HEXO_INTTYPES_DEPRECATED -DLOGK_MODULE_ID='"mutk"'
 
 objs += startup.o kroutine.o
 
@@ -12,6 +12,7 @@
 objs-$(CONFIG_MUTEK_MEMALLOC_SIMPLE) += memory_allocator_simple.o
 objs-$(CONFIG_COMPILE_INSTRUMENT) += instrument.o
 objs-$(CONFIG_MUTEK_PRINTK) += printk.o
+objs-$(CONFIG_MUTEK_PRINTK_RING) += printk_ring.o
 objs-$(CONFIG_MUTEK_LOGO) += mutek_logo_320x200.o
 objs-$(CONFIG_VMEM_PHYS_ALLOC) += page_alloc.o
 
--- a/mutek/bytecode.t	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/bytecode.t	Tue May 22 13:14:07 2018 +0200
@@ -18,6 +18,7 @@
  * Alexandre Becoulet <alexandre.becoulet@free.fr>
  */
 
+#undef LOGK_MODULE_ID
 #define LOGK_MODULE_ID "bcvm"
 
 #include <mutek/printk.h>
--- a/mutek/fault.c	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/fault.c	Tue May 22 13:14:07 2018 +0200
@@ -20,8 +20,6 @@
 
 */
 
-#define LOGK_MODULE_ID "faul"
-
 #include <mutek/printk.h>
 #include <mutek/startup.h>
 
@@ -53,22 +51,22 @@
   lock_spin(&fault_lock);
 
   logk_error("CPU Fault: cpuid(%u) faultid(%u-%s)", cpu_id(), type, name);
-  logk_error("Execution pointer: %p, Bad address (if any): %p",
+  logk(" - PC: %p, Bad address: %p",
              (void*)execptr, (void*)dataptr);
-  logk_error("Registers:");
+  logk_debug(" - Registers:");
 
   reg_t *r = regs->gpr;
   for (i = 0; i < CPU_CONTEXT_REG_COUNT; i++)
 # ifdef CPU_CONTEXT_REG_NAMES
-    logk_error(" %s=%p", reg_names[i], (void*)*(r + i));
+    logk_debug(" %s=%p", reg_names[i], (void*)*(r + i));
 # else
-    logk_error(" %p", (void*)*(r + i));
+    logk_debug(" %p", (void*)*(r + i));
 # endif
 
-  logk_error("Stack:");
+  logk_debug("Stack:");
 
   for (i = 0; i < 12; i++)
-    logk_error(" %p: %p", &sp[i], (void*)(uintptr_t)sp[i]);
+    logk_debug(" %p: %p", &sp[i], (void*)(uintptr_t)sp[i]);
 
   lock_release(&fault_lock);
 #endif
--- a/mutek/include/mutek/startup.h	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/include/mutek/startup.h	Tue May 22 13:14:07 2018 +0200
@@ -53,6 +53,8 @@
     initializations of the @ref #INIT_SMP group. */
 void mutekh_startup_smp(void);
 
+void mutekh_startup_devready(void);
+
 #ifdef CONFIG_ARCH_SMP
 /** Spin barrier which can be used to synchronize processors when
     performing intializations of the @ref #INIT_SMP group. */
--- a/mutek/mutek.config	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/mutek.config	Tue May 22 13:14:07 2018 +0200
@@ -81,7 +81,7 @@
   after INIT_HEXO_CONTEXT
   after INIT_MUTEK_SCHEDULER_INITSMP
   before INIT_MUTEK_SCHEDULER_START
-  function mutekh_startup_nodev
+  function mutekh_startup_devready
 %init end
 
 %init INIT_CPUS
@@ -232,7 +232,7 @@
   parent CONFIG_MUTEK_PRINTK
   flags value userval
   # example: level >= LOGK_LEVEL_DEBUG || id == 'test'
-  default level >= LOGK_LEVEL_NORMAL
+  default level >= CONFIG_MUTEK_PRINTK_RUNTIME_LEVEL
 %config end
 
 %config CONFIG_MUTEK_PRINTK_RUNTIME_LEVEL
@@ -286,6 +286,26 @@
   default 1
 %config end
 
+%config CONFIG_MUTEK_PRINTK_RING
+  desc Store printk output in a ring buffer
+  parent CONFIG_MUTEK_PRINTK
+  depend CONFIG_MUTEK_SHELL
+  require CONFIG_MUTEK_PRINTK_RING_SIZE>0
+%config end
+
+%config CONFIG_MUTEK_PRINTK_RING_SIZE
+  desc Specifies the size of the ring buffer used store the printk output
+  parent CONFIG_MUTEK_PRINTK_RING
+  flags value
+  default 512
+%config end
+
+%init INIT_MUTEK_PRINTK_RING
+  parent CONFIG_MUTEK_PRINTK_RING
+  during INIT_MUTEK_PRINTK
+  function printk_ring_init
+%init end
+
 ######################################################################
 #		Vmem
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mutek/printk_ring.c	Tue May 22 13:14:07 2018 +0200
@@ -0,0 +1,152 @@
+/*
+    This file is part of MutekH.
+
+    MutekH is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as
+    published by the Free Software Foundation; version 2.1 of the
+    License.
+
+    MutekH is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with MutekH; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301 USA.
+
+    Copyright Alexandre Becoulet <alexandre.becoulet@free.fr> (c) 2018
+*/
+
+#include <mutek/printk.h>
+#include <mutek/startup.h>
+#include <mutek/shell.h>
+#include <termui/term.h>
+
+#include <stdlib.h>
+
+static char printk_ring[CONFIG_MUTEK_PRINTK_RING_SIZE];
+static uint32_t printk_ring_size;
+static uint32_t printk_ring_ptr;
+
+static PRINTK_HANDLER(printk_ring_out)
+{
+  /* skip head of string if longer than buffer */
+  if (len > CONFIG_MUTEK_PRINTK_RING_SIZE)
+    {
+      str += len - CONFIG_MUTEK_PRINTK_RING_SIZE;
+      len = CONFIG_MUTEK_PRINTK_RING_SIZE;
+    }
+
+  uint32_t end = (printk_ring_ptr + printk_ring_size)
+                 % CONFIG_MUTEK_PRINTK_RING_SIZE;
+
+  if (len + printk_ring_size >= CONFIG_MUTEK_PRINTK_RING_SIZE)
+    {
+      /* drop buffer head */
+      printk_ring_ptr = (printk_ring_ptr + len + printk_ring_size) % CONFIG_MUTEK_PRINTK_RING_SIZE;
+      printk_ring_size = CONFIG_MUTEK_PRINTK_RING_SIZE;
+    }
+  else
+    {
+      printk_ring_size += len;
+    }
+
+  /* write tail of string at ring[0] if overflow */
+  uint32_t l = CONFIG_MUTEK_PRINTK_RING_SIZE - end;
+  if (len > l)
+    {
+      memcpy(printk_ring, str + l, len - l);
+      len = l;
+    }
+
+  /* write head of string */
+  memcpy(printk_ring + end, str, len);
+}
+
+static TERMUI_CON_COMMAND_PROTOTYPE(shell_logk_tail)
+{
+  uint_fast16_t lines = argc ? atoi(argv[0]) : 5;
+
+  if (printk_ring_size == 0)
+    return 0;
+
+  uint32_t end = printk_ring_ptr + printk_ring_size;
+  uint32_t lptr = end, ptr = end;
+
+  /* look backward for end of line */
+  while (lines > 0)
+    {
+      if (ptr == printk_ring_ptr)
+        {
+          lptr = ptr;
+          break;
+        }
+
+      if (printk_ring[(ptr + CONFIG_MUTEK_PRINTK_RING_SIZE - 1)
+                      % CONFIG_MUTEK_PRINTK_RING_SIZE] == '\n')
+        {
+          lptr = ptr;
+          lines--;
+        }
+
+      ptr--;
+    }
+
+  /* display buffer tail */
+  ptr = lptr % CONFIG_MUTEK_PRINTK_RING_SIZE;
+
+  if (end % CONFIG_MUTEK_PRINTK_RING_SIZE <= ptr)
+    {
+      termui_con_putsl(con, printk_ring + lptr % CONFIG_MUTEK_PRINTK_RING_SIZE,
+                       CONFIG_MUTEK_PRINTK_RING_SIZE - ptr);
+      termui_con_putsl(con, printk_ring, end % CONFIG_MUTEK_PRINTK_RING_SIZE);
+    }
+  else
+    {
+      termui_con_putsl(con, printk_ring + ptr, end - lptr);
+    }
+
+  return 0;
+}
+
+static TERMUI_CON_COMMAND_PROTOTYPE(shell_logk_write)
+{
+  writek(argv[0], argl[0]);
+  return 0;
+}
+
+static TERMUI_CON_COMMAND_PROTOTYPE(shell_logk_clear)
+{
+  printk_ring_size = 0;
+  printk_ring_ptr = 0;
+  return 0;
+}
+
+static TERMUI_CON_GROUP_DECL(shell_logk_subgroup) =
+{
+  TERMUI_CON_ENTRY(shell_logk_tail, "tail",
+    TERMUI_CON_ARGS(0, 1)
+  )
+
+  TERMUI_CON_ENTRY(shell_logk_write, "write",
+    TERMUI_CON_ARGS(1, 1)
+  )
+
+  TERMUI_CON_ENTRY(shell_logk_clear, "clear",
+  )
+
+  TERMUI_CON_LIST_END
+};
+
+MUTEK_SHELL_ROOT_GROUP(shell_logk_subgroup, "logk");
+
+void printk_ring_init()
+{
+  printk_ring_size = 0;
+  printk_ring_ptr = 0;
+
+  static struct printk_backend_s printk_ring_backend;
+  printk_register(&printk_ring_backend, printk_ring_out);
+}
--- a/mutek/scheduler.c	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/scheduler.c	Tue May 22 13:14:07 2018 +0200
@@ -26,6 +26,8 @@
 
 #include <mutek/semaphore.h>
 #include <mutek/startup.h>
+#include <mutek/printk.h>
+
 #include <hexo/local.h>
 #include <hexo/cpu.h>
 #include <hexo/ipi.h>
@@ -908,11 +910,14 @@
 #endif
 
   cpu_interrupt_disable();
-# ifndef CONFIG_ARCH_SMP
+
   mutekh_startup_smp_barrier();
   if (cpu_isbootstrap())
-# endif
-    sched_started = 1;
+    {
+      sched_started = 1;
+      logk_debug("Starting scheduler loop");
+    }
+
   mutekh_startup_smp_barrier();
   sched_context_idle();
 }
--- a/mutek/startup.c	Thu May 17 20:18:41 2018 +0200
+++ b/mutek/startup.c	Tue May 22 13:14:07 2018 +0200
@@ -173,6 +173,8 @@
   /* call all bootstrap init functions */
   INIT_BOOTSTRAP_INIT();
 
+  logk_debug("Bootstrap init done");
+
 #if defined(CONFIG_DEVICE_CPU)
   const struct cpu_tree_s *cpu = cpu_tree_lookup(CONFIG_ARCH_BOOTSTRAP_CPU_ID);
   assert(cpu != NULL && "processor id not found in the cpu tree.");
@@ -189,15 +191,16 @@
   /* call smp init functions */
   INIT_SMP_INIT();
 
+  logk_error("Reached end of init, halting");
   abort();
 }
 
-#ifndef CONFIG_DEVICE
-void mutekh_startup_nodev()
+void mutekh_startup_devready()
 {
+  logk("System started");
+
   INIT_DEVREADY_INIT();
 }
-#endif
 
 /////////////////////////////////////// user application start