summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/pc386/console
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/i386/pc386/console')
-rw-r--r--c/src/lib/libbsp/i386/pc386/console/inch.c10
-rw-r--r--c/src/lib/libbsp/i386/pc386/console/keyboard.c55
-rw-r--r--c/src/lib/libbsp/i386/pc386/console/vt.c13
3 files changed, 39 insertions, 39 deletions
diff --git a/c/src/lib/libbsp/i386/pc386/console/inch.c b/c/src/lib/libbsp/i386/pc386/console/inch.c
index 047269e4f0..f5d5079236 100644
--- a/c/src/lib/libbsp/i386/pc386/console/inch.c
+++ b/c/src/lib/libbsp/i386/pc386/console/inch.c
@@ -260,13 +260,17 @@ int BSP_wait_polled_input(void)
int rtems_kbpoll( void )
{
int rc;
- rtems_interrupt_level level;
- rtems_interrupt_disable(level);
+ /*
+ * The locking or disable of interrupts does not help
+ * there because if interrupts are enabled after leave of this
+ * function the state can change without notice anyway.
+ */
+ RTEMS_COMPILER_MEMORY_BARRIER();
rc = ( kbd_first != kbd_last ) ? TRUE : FALSE;
- rtems_interrupt_enable(level);
+ RTEMS_COMPILER_MEMORY_BARRIER();
return rc;
}
diff --git a/c/src/lib/libbsp/i386/pc386/console/keyboard.c b/c/src/lib/libbsp/i386/pc386/console/keyboard.c
index 3a33c54acc..0c8991b829 100644
--- a/c/src/lib/libbsp/i386/pc386/console/keyboard.c
+++ b/c/src/lib/libbsp/i386/pc386/console/keyboard.c
@@ -9,6 +9,7 @@
#include <rtems/kd.h>
#include <bsp.h>
#include <bsp/bootcard.h>
+#include <stdatomic.h>
#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
@@ -28,59 +29,53 @@
#define KBD_DEFLOCK 0
#endif
-static int set_bit(int nr, unsigned long * addr)
+static int kbd_test_and_set_bit(int nr, atomic_uint_least32_t * addr)
{
- int mask;
+ uint_least32_t mask;
int retval;
- rtems_interrupt_level level;
addr += nr >> 5;
- mask = 1 << (nr & 0x1f);
- rtems_interrupt_disable(level);
- retval = (mask & *addr) != 0;
- *addr |= mask;
- rtems_interrupt_enable(level);
+ mask = 1UL << (nr & 0x1f);
+
+ retval = (atomic_fetch_or(addr, mask) & mask) != 0;
+
return retval;
}
-static int clear_bit(int nr, unsigned long * addr)
+static int kbd_test_and_clear_bit(int nr, atomic_uint_least32_t * addr)
{
- int mask;
+ uint_least32_t mask;
int retval;
- rtems_interrupt_level level;
addr += nr >> 5;
- mask = 1 << (nr & 0x1f);
- rtems_interrupt_disable(level);
- retval = (mask & *addr) != 0;
- *addr &= ~mask;
- rtems_interrupt_enable(level);
+ mask = 1UL << (nr & 0x1f);
+
+ retval = (atomic_fetch_and(addr, ~mask) & mask) != 0;
+
return retval;
}
-static int test_bit(int nr, unsigned long * addr)
+static int kbd_test_bit(int nr, atomic_uint_least32_t * addr)
{
- int mask;
+ unsigned long mask;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
- return ((mask & *addr) != 0);
+ return ((mask & atomic_load(addr)) != 0);
}
-#define test_and_set_bit(x,y) set_bit(x,y)
-#define test_and_clear_bit(x,y) clear_bit(x,y)
-
/*
* global state includes the following, and various static variables
* in this module: prev_scancode, shift_state, diacr, npadch, dead_key_next.
* (last_console is now a global variable)
*/
-#define BITS_PER_LONG (sizeof(long)*CHAR_BIT)
+#define KBD_BITS_PER_ELEMENT (sizeof(atomic_uint_least32_t)*CHAR_BIT)
/* shift state counters.. */
static unsigned char k_down[NR_SHIFT] = {0, };
/* keyboard key bitmap */
-static unsigned long key_down[256/BITS_PER_LONG] = { 0, };
+static atomic_uint_least32_t
+ key_down[(256 + KBD_BITS_PER_ELEMENT - 1) / KBD_BITS_PER_ELEMENT] = { 0, };
static int dead_key_next = 0;
/*
@@ -243,10 +238,10 @@ void handle_scancode(unsigned char scancode, int down)
if (up_flag) {
rep = 0;
- if(!test_and_clear_bit(keycode, key_down))
+ if(!kbd_test_and_clear_bit(keycode, key_down))
up_flag = kbd_unexpected_up(keycode);
} else
- rep = test_and_set_bit(keycode, key_down);
+ rep = kbd_test_and_set_bit(keycode, key_down);
#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */
if (keycode == SYSRQ_KEY) {
@@ -695,10 +690,10 @@ void compute_shiftstate(void)
k_down[i] = 0;
for(i=0; i < SIZE(key_down); i++)
- if(key_down[i]) { /* skip this word if not a single bit on */
- k = i*BITS_PER_LONG;
- for(j=0; j<BITS_PER_LONG; j++,k++)
- if(test_bit(k, key_down)) {
+ if(atomic_load(key_down + i)) { /* skip this word if not a single bit on */
+ k = i*KBD_BITS_PER_ELEMENT;
+ for(j=0; j<KBD_BITS_PER_ELEMENT; j++,k++)
+ if(kbd_test_bit(k, key_down)) {
sym = U(plain_map[k]);
if(KTYP(sym) == KT_SHIFT) {
val = KVAL(sym);
diff --git a/c/src/lib/libbsp/i386/pc386/console/vt.c b/c/src/lib/libbsp/i386/pc386/console/vt.c
index 4a38f9deba..022cb5d461 100644
--- a/c/src/lib/libbsp/i386/pc386/console/vt.c
+++ b/c/src/lib/libbsp/i386/pc386/console/vt.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <errno.h>
+#include <bsp.h>
#include <i386_io.h>
#include <rtems.h>
#include <rtems/kd.h>
@@ -69,21 +70,21 @@ static void
_kd_mksound(unsigned int hz, unsigned int ticks)
{
unsigned int count = 0;
- rtems_interrupt_level level;
+ rtems_interrupt_lock_context lock_context;
if (hz > 20 && hz < 32767)
count = 1193180 / hz;
- rtems_interrupt_disable(level);
+ rtems_interrupt_lock_acquire(&rtems_i386_i8254_access_lock, &lock_context);
/* del_timer(&sound_timer); */
if (count) {
/* enable counter 2 */
outb_p(inb_p(0x61)|3, 0x61);
/* set command for counter 2, 2 byte write */
- outb_p(0xB6, 0x43);
+ outb_p(0xB6, TIMER_MODE);
/* select desired HZ */
- outb_p(count & 0xff, 0x42);
- outb((count >> 8) & 0xff, 0x42);
+ outb_p(count & 0xff, TIMER_CNTR2);
+ outb((count >> 8) & 0xff, TIMER_CNTR2);
/*
if (ticks) {
@@ -94,7 +95,7 @@ _kd_mksound(unsigned int hz, unsigned int ticks)
} else
kd_nosound(0);
- rtems_interrupt_enable(level);
+ rtems_interrupt_lock_release(&rtems_i386_i8254_access_lock, &lock_context);
return;
}