From c580c473b540620323fa568ea6cc21cb1c5e5860 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 7 Jul 2015 20:33:59 +0200 Subject: [PATCH] Add option so that s_queue objects can indirect their buffers via a macro, which allows us to put the TTY buffer in high memory. --- Kernel/cpu-msp430x/cpu.h | 16 ++++++++++++++++ Kernel/devio.c | 6 +++--- Kernel/include/kernel.h | 18 +++++++++++++++--- Kernel/platform-msp430fr5969/config.h | 7 ++++++- Kernel/platform-msp430fr5969/devtty.c | 7 ++++--- Kernel/platform-msp430fr5969/msp430fr5969.ld | 5 +++++ 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/Kernel/cpu-msp430x/cpu.h b/Kernel/cpu-msp430x/cpu.h index 45a5df0d..93c1c393 100644 --- a/Kernel/cpu-msp430x/cpu.h +++ b/Kernel/cpu-msp430x/cpu.h @@ -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) diff --git a/Kernel/devio.c b/Kernel/devio.c index 836c1e6d..2a129e11 100644 --- a/Kernel/devio.c +++ b/Kernel/devio.c @@ -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); diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 4733689b..d6b9bc6d 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -11,6 +11,7 @@ From UZI by Doug Braun and UZI280 by Stefan Nitschke. #define __FUZIX__KERNEL_DOT_H__ #include +#include #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; diff --git a/Kernel/platform-msp430fr5969/config.h b/Kernel/platform-msp430fr5969/config.h index aed5cb05..b7989041 100644 --- a/Kernel/platform-msp430fr5969/config.h +++ b/Kernel/platform-msp430fr5969/config.h @@ -28,6 +28,12 @@ /* 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 */ diff --git a/Kernel/platform-msp430fr5969/devtty.c b/Kernel/platform-msp430fr5969/devtty.c index 141c703f..74b77e19 100644 --- a/Kernel/platform-msp430fr5969/devtty.c +++ b/Kernel/platform-msp430fr5969/devtty.c @@ -7,11 +7,12 @@ #include #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) */ diff --git a/Kernel/platform-msp430fr5969/msp430fr5969.ld b/Kernel/platform-msp430fr5969/msp430fr5969.ld index e76c8b42..9f7eb276 100644 --- a/Kernel/platform-msp430fr5969/msp430fr5969.ld +++ b/Kernel/platform-msp430fr5969/msp430fr5969.ld @@ -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)); -- 2.34.1