From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Date: Mon, 26 May 97 10:42:35 +0200
To: linux-m68k@phil.uni-sb.de
Subject: L68K: Misc 2.1.38
X-Yow: Well, here I am in AMERICA..  I LIKE it.  I HATE it.
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: linux-m68k@phil.uni-sb.de

I LIKE it.  I HATE it.  I LIKE it.  I HATE it.  I LIKE it.
I HATE it.  I LIKE..  EMOTIONS are SWEEPING over me!!

I have changed the default atari keymap to make it `meta-complete' (i.e.,
dumpkeys will use alt_is_meta), to fill a few holes and to fix Control +
[-/_], which should produce US (0x1f), not DEL.

The semaphore implementation was slightly broken when i copied it from the
i386 header, fix it for the m68k as well.

Implementation of palette escapes in the console driver, stolen from
Geert's abscon patch.  Annoying side effect: you'll get a boot time
message about calling kmem_alloc with a NULL pointer (it's not yet
initialized).  This is currently harmless (kmalloc returns NULL,
alloc_cmap will cope with it), but should be fixed someday.

Add a few more init declarations.  Don't export lp_init, it should never
ever be called from a module.

Andreas.

--- linux/arch/m68k/atari/atakeyb.c.~1~	Wed May 14 17:40:43 1997
+++ linux/arch/m68k/atari/atakeyb.c	Wed May 21 20:50:24 1997
@@ -139,7 +139,7 @@
 
 static u_short atactrl_map[NR_KEYS] = {
 	0xf200, 0xf200, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e,
-	0xf01f, 0xf07f, 0xf200, 0xf200, 0xf07f, 0xf200, 0xf008, 0xf200,
+	0xf01f, 0xf07f, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf200,
 	0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
 	0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf201, 0xf702, 0xf001, 0xf013,
 	0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
@@ -158,18 +158,18 @@
 
 static u_short atashift_ctrl_map[NR_KEYS] = {
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf008, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf201, 0xf702, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf700, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf700, 0xf200,
-	0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf117,
+	0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf200,
+	0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+	0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
+	0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+	0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
+	0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf07f, 0xf700, 0xf200,
+	0xf703, 0xf200, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+	0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf200, 0xf200, 0xf117,
 	0xf603, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
-	0xf600, 0xf200, 0xf115, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+	0xf600, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
+	0xf200, 0xf1ff, 0xf11b, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
 	0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
 	0xf300, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
@@ -207,7 +207,7 @@
 	0xf118, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
 	0xf119, 0xf200, 0xf115, 0xf87f, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
+	0xf200, 0xf1ff, 0xf11b, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
 	0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
 	0xf300, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
@@ -215,7 +215,7 @@
 
 static u_short atactrl_alt_map[NR_KEYS] = {
 	0xf200, 0xf200, 0xf200, 0xf800, 0xf81b, 0xf81c, 0xf81d, 0xf81e,
-	0xf81f, 0xf87f, 0xf200, 0xf200, 0xf87f, 0xf200, 0xf808, 0xf200,
+	0xf81f, 0xf87f, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf200,
 	0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
 	0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf201, 0xf702, 0xf801, 0xf813,
 	0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
@@ -224,7 +224,7 @@
 	0xf703, 0xf800, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
 	0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf200, 0xf200, 0xf114,
 	0xf603, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
-	0xf600, 0xf200, 0xf115, 0xf07f, 0xf200, 0xf200, 0xf200, 0xf200,
+	0xf600, 0xf200, 0xf115, 0xf87f, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf1ff, 0xf202, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
 	0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
@@ -234,18 +234,18 @@
 
 static u_short atashift_ctrl_alt_map[NR_KEYS] = {
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf808, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf201, 0xf702, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf700, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf700, 0xf200,
-	0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf117,
+	0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf200,
+	0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+	0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
+	0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+	0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
+	0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf87f, 0xf700, 0xf200,
+	0xf703, 0xf200, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+	0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf200, 0xf200, 0xf117,
 	0xf603, 0xf200, 0xf30b, 0xf601, 0xf200, 0xf602, 0xf30a, 0xf200,
-	0xf600, 0xf200, 0xf115, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+	0xf600, 0xf200, 0xf115, 0xf87f, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
-	0xf200, 0xf200, 0xf200, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
+	0xf200, 0xf1ff, 0xf11b, 0xf312, 0xf313, 0xf30d, 0xf30c, 0xf307,
 	0xf308, 0xf309, 0xf304, 0xf305, 0xf306, 0xf301, 0xf302, 0xf303,
 	0xf300, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
 	0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
--- linux/arch/m68k/kernel/console.c.~1~	Mon Apr 14 18:00:07 1997
+++ linux/arch/m68k/kernel/console.c	Sat May 24 16:29:09 1997
@@ -109,7 +109,6 @@
 #include <linux/interrupt.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
-#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/errno.h>
@@ -119,6 +118,7 @@
 #include <linux/major.h>
 #include <linux/mm.h>
 #include <linux/ioport.h>
+#include <linux/init.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -159,6 +159,8 @@
 extern void vesa_blank(void);
 extern void vesa_unblank(void);
 extern void compute_shiftstate(void);
+extern void reset_palette(int currcons);
+extern void set_palette(void);
 void poke_blanked_console(void);
 void do_blank_screen(int);
 
@@ -257,6 +259,7 @@
 #define	ulcolor		(vc_cons[currcons].d->vc_ulcolor)
 #define	halfcolor	(vc_cons[currcons].d->vc_halfcolor)
 #define tab_stop	(vc_cons[currcons].d->vc_tab_stop)
+#define palette		(vc_cons[currcons].d->vc_palette)
 #define bell_pitch	(vc_cons[currcons].d->vc_bell_pitch)
 #define bell_duration	(vc_cons[currcons].d->vc_bell_duration)
 #define sw		(vc_cons[currcons].d->vc_sw)
@@ -539,6 +542,14 @@
 static unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
 				       8,12,10,14, 9,13,11,15 };
 
+/* the default colour table, for VGA+ colour systems */
+int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
+    0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
+int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
+    0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
+int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
+    0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
+
 /*
  * gotoxy() must verify all boundaries, because the arguments
  * might also be negative. If the given position is out of
@@ -1655,7 +1666,7 @@
 				if (nextx == cols) {
 					sw->con_putc(vc_cons[currcons].d,
 						     *putcs_buf, y, x);
-					((unsigned short *)pos)--;
+					pos--;
 					need_wrap = decawm;
 					continue;
 				}
@@ -1837,9 +1848,7 @@
 			    vc_state = ESpalette;
 			    continue;
 			} else if (c=='R') {   /* reset palette */
-#if 0
 			    reset_palette (currcons);
-#endif
 			    vc_state = ESnormal;
 			} else
 			    vc_state = ESnormal;
@@ -1848,7 +1857,6 @@
 			if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
 			    par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ;
 			    if (npar==7) {
-#if 0
 				int i = par[0]*3, j = 1;
 				palette[i] = 16*par[j++];
 				palette[i++] += par[j++];
@@ -1857,7 +1865,6 @@
 				palette[i] = 16*par[j++];
 				palette[i] += par[j];
 				set_palette() ;
-#endif
 				vc_state = ESnormal;
 			    }
 			} else
@@ -2283,7 +2290,7 @@
  * Reads the information preserved by setup.s to determine the current display
  * type and sets everything accordingly.
  */
-unsigned long con_init(unsigned long kmem_start)
+__initfunc(unsigned long con_init(unsigned long kmem_start))
 {
 	const char *display_desc = "????";
 	unsigned int currcons = 0;
@@ -2617,22 +2624,61 @@
  * map, 3 bytes per colour, 16 colours, range from 0 to 255.
  */
 
+static int set_get_cmap(unsigned char *arg, int set)
+{
+	int i, j, k;
+
+	for (i = 0; i < 16; i++)
+		if (set) {
+			get_user(default_red[i], arg++);
+			get_user(default_grn[i], arg++);
+			get_user(default_blu[i], arg++);
+		} else {
+			put_user(default_red[i], arg++);
+			put_user(default_grn[i], arg++);
+			put_user(default_blu[i], arg++);
+		}
+	if (set) {
+		for (i = 0; i < MAX_NR_CONSOLES; i++)
+			if (vc_cons_allocated(i))
+				for (j = k = 0; j < 16; j++) {
+					vc_cons[i].d->vc_palette[k++] =
+						default_red[j];
+					vc_cons[i].d->vc_palette[k++] =
+						default_grn[j];
+					vc_cons[i].d->vc_palette[k++] =
+						default_blu[j];
+				}
+		set_palette();
+	}
+	return 0;
+}
+
 int con_set_cmap (unsigned char *arg)
 {
-	return -EINVAL;
+	return set_get_cmap (arg, 1);
 }
 
 int con_get_cmap (unsigned char *arg)
 {
-	return -EINVAL;
+	return set_get_cmap (arg, 0);
 }
 
 void reset_palette(int currcons)
 {
+	int j, k;
+	for (j = k = 0; j < 16; j++) {
+		palette[k++] = default_red[j];
+		palette[k++] = default_grn[j];
+		palette[k++] = default_blu[j];
+	}
+	set_palette() ;
 }
 
 void set_palette(void)
 {
+	if (vt_cons[fg_console]->vc_mode != KD_GRAPHICS)
+		conswitchp->con_set_palette(vc_cons[fg_console].d, color_table);
 }
 
 /*
--- linux/drivers/char/atarimouse.c.~1~	Tue May 20 17:47:07 1997
+++ linux/drivers/char/atarimouse.c	Tue May 20 18:41:01 1997
@@ -176,7 +176,7 @@
 #define	MIN_THRESHOLD 1
 #define	MAX_THRESHOLD 20	/* more seems not reasonable... */
 
-void atari_mouse_setup( char *str, int *ints )
+void __init atari_mouse_setup( char *str, int *ints )
 {
     if (ints[0] < 1) {
 	printk( "atari_mouse_setup: no arguments!\n" );
--- drivers/char/lp_m68k.c.~1~	Tue May 20 17:47:27 1997
+++ drivers/char/lp_m68k.c	Wed May 14 18:03:08 1997
@@ -462,7 +462,6 @@
 EXPORT_SYMBOL(lp_table);
 EXPORT_SYMBOL(lp_irq);
 EXPORT_SYMBOL(lp_interrupt);
-EXPORT_SYMBOL(lp_init);
 EXPORT_SYMBOL(register_parallel);
 EXPORT_SYMBOL(unregister_parallel);
 
--- linux/include/asm-m68k/semaphore.h.~1~	Tue May 20 17:51:05 1997
+++ linux/include/asm-m68k/semaphore.h	Fri May 16 20:03:15 1997
@@ -20,8 +20,8 @@
 	struct wait_queue * wait;
 };
 
-#define MUTEX ((struct semaphore) { { 1 }, { 0 }, NULL })
-#define MUTEX_LOCKED ((struct semaphore) { { 0 }, { 0 }, NULL })
+#define MUTEX ((struct semaphore) { ATOMIC_INIT(1), ATOMIC_INIT(0), NULL })
+#define MUTEX_LOCKED ((struct semaphore) { ATOMIC_INIT(0), ATOMIC_INIT(0), NULL })
 
 asmlinkage void __down_failed(void /* special register calling convention */);
 asmlinkage int  __down_failed_interruptible(void  /* params in registers */);
@@ -73,7 +73,7 @@
  * "down_failed" is a special asm handler that calls the C
  * routine that actually waits. See arch/m68k/lib/semaphore.S
  */
-extern inline void do_down(struct semaphore * sem, void (*failed)(void))
+extern inline void down(struct semaphore * sem)
 {
 	register struct semaphore *sem1 __asm__ ("%a1") = sem;
 	__asm__ __volatile__(
@@ -84,15 +84,34 @@
 		".section .text.lock,\"ax\"\n"
 		".even\n"
 		"2:\tpea 1b\n\t"
-		"jbra %1\n"
+		"jbra __down_failed\n"
 		".previous"
 		: /* no outputs */
-		: "a" (sem1), "m" (*(unsigned char *)failed)
+		: "a" (sem1)
 		: "memory");
 }
 
-#define down(sem) do_down((sem),__down_failed)
-#define down_interruptible(sem) do_down((sem),__down_failed_interruptible)
+extern inline int down_interruptible(struct semaphore * sem)
+{
+	register struct semaphore *sem1 __asm__ ("%a1") = sem;
+	register int result __asm__ ("%d0");
+
+	__asm__ __volatile__(
+		"| atomic interruptible down operation\n\t"
+		"subql #1,%1@\n\t"
+		"jmi 2f\n\t"
+		"clrl %0\n"
+		"1:\n"
+		".section .text.lock,\"ax\"\n"
+		".even\n"
+		"2:\tpea 1b\n\t"
+		"jbra __down_failed_interruptible\n"
+		".previous"
+		: "=d" (result)
+		: "a" (sem1)
+		: "%d0", "memory");
+	return result;
+}
 
 /*
  * Note! This is subtle. We jump to wake people up only if
@@ -111,10 +130,10 @@
 		".section .text.lock,\"ax\"\n"
 		".even\n"
 		"2:\tpea 1b\n\t"
-		"jbra %1\n"
+		"jbra __up_wakeup\n"
 		".previous"
 		: /* no outputs */
-		: "a" (sem1), "m" (*(unsigned char *)__up_wakeup)
+		: "a" (sem1)
 		: "memory");
 }
 
