Add option so that s_queue objects can indirect their buffers via a macro,
authorDavid Given <dg@cowlark.com>
Tue, 7 Jul 2015 18:33:59 +0000 (20:33 +0200)
committerDavid Given <dg@cowlark.com>
Tue, 7 Jul 2015 18:33:59 +0000 (20:33 +0200)
which allows us to put the TTY buffer in high memory.

Kernel/cpu-msp430x/cpu.h
Kernel/devio.c
Kernel/include/kernel.h
Kernel/platform-msp430fr5969/config.h
Kernel/platform-msp430fr5969/devtty.c
Kernel/platform-msp430fr5969/msp430fr5969.ld

index 45a5df0..93c1c39 100644 (file)
@@ -79,6 +79,22 @@ typedef union {            /* this structure is endian dependent */
     } h;
 } ticks_t;
 
+#define __read_hidata(p) \
+       ({ \
+               uint8_t r; \
+               asm ("movx.b 0x10000(%1), %0" \
+                       : "=g" (r) \
+                       : "r" (p)); \
+               r; \
+       })
+
+#define __write_hidata(p, v) \
+       ({ \
+               asm volatile ("movx.b %0, 0x10000(%1)" \
+                       : \
+                       : "g" (v), "r" (p)); \
+       })
+
 #define used(x)
 
 #define cpu_to_le16(x) (x)
index 836c1e6..2a129e1 100644 (file)
@@ -363,7 +363,7 @@ bool insq(struct s_queue * q, unsigned char c)
        if (q->q_count == q->q_size)
                r = false;      // no space left :(
        else {
-               *(q->q_tail) = c;
+               PUTQ(q->q_tail, c);
                ++q->q_count;
                if (++q->q_tail >= q->q_base + q->q_size)
                        q->q_tail = q->q_base;
@@ -384,7 +384,7 @@ bool remq(struct s_queue * q, unsigned char *cp)
        if (!q->q_count)
                r = false;
        else {
-               *cp = *(q->q_head);
+               *cp = GETQ(q->q_head);
                --q->q_count;
                if (++q->q_head >= q->q_base + q->q_size)
                        q->q_head = q->q_base;
@@ -420,7 +420,7 @@ bool uninsq(struct s_queue *q, unsigned char *cp)
                --q->q_count;
                if (--q->q_tail < q->q_base)
                        q->q_tail = q->q_base + q->q_size - 1;
-               *cp = *(q->q_tail);
+               *cp = GETQ(q->q_tail);
                r = true;
        }
        irqrestore(irq);
index 4733689..d6b9bc6 100644 (file)
@@ -11,6 +11,7 @@ From UZI by Doug Braun and UZI280 by Stefan Nitschke.
 #define __FUZIX__KERNEL_DOT_H__
 
 #include <stdbool.h>
+#include <stdint.h>
 
 #include "config.h"
 #include "cpu.h"
@@ -62,14 +63,25 @@ From UZI by Doug Braun and UZI280 by Stefan Nitschke.
 #define NO_FILE   (0xFF)
 
 typedef struct s_queue {
-    unsigned char *q_base;    /* Pointer to data */
-    unsigned char *q_head;    /* Pointer to addr of next char to read. */
-    unsigned char *q_tail;    /* Pointer to where next char to insert goes. */
+       #if defined CONFIG_INDIRECT_QUEUES
+               queueptr_t q_base;    /* Pointer to data */
+               queueptr_t q_head;    /* Pointer to addr of next char to read. */
+               queueptr_t q_tail;    /* Pointer to where next char to insert goes. */
+       #else
+               unsigned char *q_base;    /* Pointer to data */
+               unsigned char *q_head;    /* Pointer to addr of next char to read. */
+               unsigned char *q_tail;    /* Pointer to where next char to insert goes. */
+       #endif
     int   q_size;    /* Max size of queue */
     int   q_count;   /* How many characters presently in queue */
     int   q_wakeup;  /* Threshold for waking up processes waiting on queue */
 } queue_t;
 
+#if !defined CONFIG_INDIRECT_QUEUES
+       #define GETQ(p) (*(p))
+       #define PUTQ(p, v) (*(p) = (v))
+#endif
+
 struct tms {
        clock_t  tms_utime;
        clock_t  tms_stime;
index aed5cb0..b798904 100644 (file)
 /* Video terminal, not a serial tty */
 #undef CONFIG_VT
 
+/* To save space, queues go in high memory. */
+#define CONFIG_INDIRECT_QUEUES
+typedef uint16_t queueptr_t;
+#define GETQ(p) __read_hidata(p)
+#define PUTQ(p, v) __write_hidata((p), (v))
+
 extern int __user_base;
 extern int __user_top;
 
@@ -58,7 +64,6 @@ extern int __swap_size_blocks;
 #define NDEVS    1        /* Devices 0..NDEVS-1 are capable of being mounted */
                           /*  (add new mountable devices to beginning area.) */
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
-#define TTYSIZ   80       /* Size of serial buffer */
 #define NBUFS    4        /* Number of block buffers */
 #define NMOUNTS         1            /* Number of mounts at a time */
 #define UFTSIZE  15       /* Number of user files */
index 141c703..74b77e1 100644 (file)
@@ -7,11 +7,12 @@
 #include <tty.h>
 #include "msp430fr5969.h"
 
-uint8_t tbuf1[TTYSIZ];
+__attribute__ ((section (".hidata"))) uint8_t ttybuf[TTYSIZ];
+#define ttybuf_hi (queueptr_t)ttybuf
 
 struct s_queue ttyinq[NUM_DEV_TTY+1] = { /* ttyinq[0] is never used */
-       { NULL,    NULL,    NULL,    0,        0,       0    },
-       { tbuf1,   tbuf1,   tbuf1,   TTYSIZ,   0,   TTYSIZ/2 },
+       { 0,         0,         0,         0,      0, 0        },
+       { ttybuf_hi, ttybuf_hi, ttybuf_hi, TTYSIZ, 0, TTYSIZ/2 },
 };
 
 /* Output for the system console (kprintf etc) */
index e76c8b4..9f7eb27 100644 (file)
@@ -272,6 +272,11 @@ SECTIONS
        *(COMMON)
   } > SRAM AT> HIROM
 
+  .hidata : {
+       . = ALIGN(2);
+       *(.hidata .hidata.*)
+  } > HIROM
+
   /* Note that crt0 assumes this is a multiple of two; all the
      start/stop symbols are also assumed word-aligned.  */
   PROVIDE(__romdata_start = LOADADDR(.data));