summaryrefslogtreecommitdiff
path: root/hw/xfree86
diff options
context:
space:
mode:
Diffstat (limited to 'hw/xfree86')
-rw-r--r--hw/xfree86/common/atKeynames.h335
-rw-r--r--hw/xfree86/common/compiler.h1460
-rw-r--r--hw/xfree86/common/scoasm.h112
-rw-r--r--hw/xfree86/common/xf86.h743
-rw-r--r--hw/xfree86/common/xf86Config.c3934
-rw-r--r--hw/xfree86/common/xf86Cursor.c326
-rw-r--r--hw/xfree86/common/xf86Events.c1575
-rw-r--r--hw/xfree86/common/xf86Init.c834
-rw-r--r--hw/xfree86/common/xf86Io.c542
-rw-r--r--hw/xfree86/common/xf86Kbd.c407
-rw-r--r--hw/xfree86/common/xf86KbdBSD.c687
-rw-r--r--hw/xfree86/common/xf86KbdLnx.c697
-rw-r--r--hw/xfree86/common/xf86KbdMach.c312
-rw-r--r--hw/xfree86/common/xf86Keymap.h449
-rw-r--r--hw/xfree86/common/xf86Priv.h175
-rw-r--r--hw/xfree86/common/xf86Version.h23
-rw-r--r--hw/xfree86/common/xf86XKB.c118
-rw-r--r--hw/xfree86/common/xf86Xinput.c1264
-rw-r--r--hw/xfree86/common/xf86Xinput.h280
-rw-r--r--hw/xfree86/dixmods/extmod/xf86vmode.c1429
-rw-r--r--hw/xfree86/os-support/README.OS-lib437
-rw-r--r--hw/xfree86/os-support/assyntax.h725
-rw-r--r--hw/xfree86/os-support/bsd/bsd_VTsw.c92
-rw-r--r--hw/xfree86/os-support/bsd/bsd_init.c780
-rw-r--r--hw/xfree86/os-support/bsd/bsd_io.c257
-rw-r--r--hw/xfree86/os-support/bsd/bsd_jstk.c180
-rw-r--r--hw/xfree86/os-support/linux/lnx_init.c274
-rw-r--r--hw/xfree86/os-support/linux/lnx_io.c136
-rw-r--r--hw/xfree86/os-support/linux/lnx_jstk.c173
-rw-r--r--hw/xfree86/os-support/linux/lnx_video.c634
-rw-r--r--hw/xfree86/os-support/lynxos/lynx_init.c198
-rw-r--r--hw/xfree86/os-support/lynxos/lynx_io.c172
-rw-r--r--hw/xfree86/os-support/lynxos/lynx_mmap.c66
-rw-r--r--hw/xfree86/os-support/lynxos/lynx_video.c167
-rw-r--r--hw/xfree86/os-support/misc/xf86_IlHack.c14
-rw-r--r--hw/xfree86/os-support/misc/xf86_Util.c126
-rw-r--r--hw/xfree86/os-support/sco/VTsw_sco.c94
-rw-r--r--hw/xfree86/os-support/sco/sco_init.c261
-rw-r--r--hw/xfree86/os-support/sco/sco_io.c117
-rw-r--r--hw/xfree86/os-support/sco/sco_mouse.c175
-rw-r--r--hw/xfree86/os-support/sco/sco_video.c284
-rw-r--r--hw/xfree86/os-support/shared/VTsw_noop.c51
-rw-r--r--hw/xfree86/os-support/shared/VTsw_usl.c80
-rw-r--r--hw/xfree86/os-support/shared/bios_devmem.c139
-rw-r--r--hw/xfree86/os-support/shared/ioperm_noop.c60
-rw-r--r--hw/xfree86/os-support/shared/posix_tty.c174
-rw-r--r--hw/xfree86/os-support/shared/std_kbdEv.c49
-rw-r--r--hw/xfree86/os-support/shared/sysv_kbd.c105
-rw-r--r--hw/xfree86/os-support/sysv/sysv_init.c257
-rw-r--r--hw/xfree86/os-support/sysv/sysv_io.c98
-rw-r--r--hw/xfree86/os-support/sysv/sysv_video.c589
-rw-r--r--hw/xfree86/os-support/sysv/xqueue.c406
-rw-r--r--hw/xfree86/os-support/xf86_OSlib.h533
-rw-r--r--hw/xfree86/os-support/xf86_OSproc.h394
-rw-r--r--hw/xfree86/utils/kbd_mode/bsd-kbd_mode.c96
-rw-r--r--hw/xfree86/utils/kbd_mode/bsd-kbd_mode.man.pre36
-rw-r--r--hw/xfree86/utils/kbd_mode/sun-kbd_mode.c150
-rw-r--r--hw/xfree86/utils/kbd_mode/sun-kbd_mode.man.pre50
-rw-r--r--hw/xfree86/utils/scanpci/scanpci.c1790
-rw-r--r--hw/xfree86/utils/xorgconfig/Cards2003
-rw-r--r--hw/xfree86/utils/xorgconfig/cards.c285
-rw-r--r--hw/xfree86/utils/xorgconfig/cards.h36
62 files changed, 28445 insertions, 0 deletions
diff --git a/hw/xfree86/common/atKeynames.h b/hw/xfree86/common/atKeynames.h
new file mode 100644
index 000000000..24ae59a30
--- /dev/null
+++ b/hw/xfree86/common/atKeynames.h
@@ -0,0 +1,335 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/atKeynames.h,v 3.9 1996/12/23 06:43:13 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: atKeynames.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */
+
+#ifndef _ATKEYNAMES_H
+#define _ATKEYNAMES_H
+
+#define XK_TECHNICAL
+#define XK_KATAKANA
+#include "keysym.h"
+
+#define GLYPHS_PER_KEY 4
+#define NUM_KEYCODES 150
+#define NUM_STD_KEYCODES 127
+#define MIN_KEYCODE 8
+#define MAX_KEYCODE (NUM_KEYCODES + MIN_KEYCODE - 1)
+#define MAX_STD_KEYCODE (NUM_STD_KEYCODES + MIN_KEYCODE - 1)
+
+#define AltMask Mod1Mask
+#define NumLockMask Mod2Mask
+#define AltLangMask Mod3Mask
+#define KanaMask Mod4Mask
+#define ScrollLockMask Mod5Mask
+
+#define KeyPressed(k) (keyc->down[k >> 3] & (1 << (k & 7)))
+#define ModifierDown(k) ((keyc->state & (k)) == (k))
+
+#define XF86XK_ModeLock 0x1008FF01 /* Mode Switch Lock */
+
+/*
+ * NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three)
+ * sets of scancodes. Set3 can only be generated by a MF keyboard.
+ * Set2 sends a makecode for keypress, and the same code prefixed by a
+ * F0 for keyrelease. This is a little bit ugly to handle. Thus we use
+ * here for X386 the PC/XT compatible Set1. This set uses 8bit scancodes.
+ * Bit 7 ist set if the key is released. The code E0 switches to a
+ * different meaning to add the new MF cursorkeys, while not breaking old
+ * applications. E1 is another special prefix. Since I assume that there
+ * will be further versions of PC/XT scancode compatible keyboards, we
+ * may be in trouble one day.
+ *
+ * IDEA: 1) Use Set2 on AT84 keyboards and translate it to MF Set3.
+ * 2) Use the keyboards native set and translate it to common keysyms.
+ */
+
+/*
+ * definition of the AT84/MF101/MF102 Keyboard:
+ * ============================================================
+ * Defined Key Cap Glyphs Pressed value
+ * Key Name Main Also (hex) (dec)
+ * ---------------- ---------- ------- ------ ------
+ */
+
+#ifndef PC98
+
+#define KEY_Escape /* Escape 0x01 */ 1
+#define KEY_1 /* 1 ! 0x02 */ 2
+#define KEY_2 /* 2 @ 0x03 */ 3
+#define KEY_3 /* 3 # 0x04 */ 4
+#define KEY_4 /* 4 $ 0x05 */ 5
+#define KEY_5 /* 5 % 0x06 */ 6
+#define KEY_6 /* 6 ^ 0x07 */ 7
+#define KEY_7 /* 7 & 0x08 */ 8
+#define KEY_8 /* 8 * 0x09 */ 9
+#define KEY_9 /* 9 ( 0x0a */ 10
+#define KEY_0 /* 0 ) 0x0b */ 11
+#define KEY_Minus /* - (Minus) _ (Under) 0x0c */ 12
+#define KEY_Equal /* = (Equal) + 0x0d */ 13
+#define KEY_BackSpace /* Back Space 0x0e */ 14
+#define KEY_Tab /* Tab 0x0f */ 15
+#define KEY_Q /* Q 0x10 */ 16
+#define KEY_W /* W 0x11 */ 17
+#define KEY_E /* E 0x12 */ 18
+#define KEY_R /* R 0x13 */ 19
+#define KEY_T /* T 0x14 */ 20
+#define KEY_Y /* Y 0x15 */ 21
+#define KEY_U /* U 0x16 */ 22
+#define KEY_I /* I 0x17 */ 23
+#define KEY_O /* O 0x18 */ 24
+#define KEY_P /* P 0x19 */ 25
+#define KEY_LBrace /* [ { 0x1a */ 26
+#define KEY_RBrace /* ] } 0x1b */ 27
+#define KEY_Enter /* Enter 0x1c */ 28
+#define KEY_LCtrl /* Ctrl(left) 0x1d */ 29
+#define KEY_A /* A 0x1e */ 30
+#define KEY_S /* S 0x1f */ 31
+#define KEY_D /* D 0x20 */ 32
+#define KEY_F /* F 0x21 */ 33
+#define KEY_G /* G 0x22 */ 34
+#define KEY_H /* H 0x23 */ 35
+#define KEY_J /* J 0x24 */ 36
+#define KEY_K /* K 0x25 */ 37
+#define KEY_L /* L 0x26 */ 38
+#define KEY_SemiColon /* ;(SemiColon) :(Colon) 0x27 */ 39
+#define KEY_Quote /* ' (Apostr) " (Quote) 0x28 */ 40
+#define KEY_Tilde /* ` (Accent) ~ (Tilde) 0x29 */ 41
+#define KEY_ShiftL /* Shift(left) 0x2a */ 42
+#define KEY_BSlash /* \(BckSlash) |(VertBar)0x2b */ 43
+#define KEY_Z /* Z 0x2c */ 44
+#define KEY_X /* X 0x2d */ 45
+#define KEY_C /* C 0x2e */ 46
+#define KEY_V /* V 0x2f */ 47
+#define KEY_B /* B 0x30 */ 48
+#define KEY_N /* N 0x31 */ 49
+#define KEY_M /* M 0x32 */ 50
+#define KEY_Comma /* , (Comma) < (Less) 0x33 */ 51
+#define KEY_Period /* . (Period) >(Greater)0x34 */ 52
+#define KEY_Slash /* / (Slash) ? 0x35 */ 53
+#define KEY_ShiftR /* Shift(right) 0x36 */ 54
+#define KEY_KP_Multiply /* * 0x37 */ 55
+#define KEY_Alt /* Alt(left) 0x38 */ 56
+#define KEY_Space /* (SpaceBar) 0x39 */ 57
+#define KEY_CapsLock /* CapsLock 0x3a */ 58
+#define KEY_F1 /* F1 0x3b */ 59
+#define KEY_F2 /* F2 0x3c */ 60
+#define KEY_F3 /* F3 0x3d */ 61
+#define KEY_F4 /* F4 0x3e */ 62
+#define KEY_F5 /* F5 0x3f */ 63
+#define KEY_F6 /* F6 0x40 */ 64
+#define KEY_F7 /* F7 0x41 */ 65
+#define KEY_F8 /* F8 0x42 */ 66
+#define KEY_F9 /* F9 0x43 */ 67
+#define KEY_F10 /* F10 0x44 */ 68
+#define KEY_NumLock /* NumLock 0x45 */ 69
+#define KEY_ScrollLock /* ScrollLock 0x46 */ 70
+#define KEY_KP_7 /* 7 Home 0x47 */ 71
+#define KEY_KP_8 /* 8 Up 0x48 */ 72
+#define KEY_KP_9 /* 9 PgUp 0x49 */ 73
+#define KEY_KP_Minus /* - (Minus) 0x4a */ 74
+#define KEY_KP_4 /* 4 Left 0x4b */ 75
+#define KEY_KP_5 /* 5 0x4c */ 76
+#define KEY_KP_6 /* 6 Right 0x4d */ 77
+#define KEY_KP_Plus /* + (Plus) 0x4e */ 78
+#define KEY_KP_1 /* 1 End 0x4f */ 79
+#define KEY_KP_2 /* 2 Down 0x50 */ 80
+#define KEY_KP_3 /* 3 PgDown 0x51 */ 81
+#define KEY_KP_0 /* 0 Insert 0x52 */ 82
+#define KEY_KP_Decimal /* . (Decimal) Delete 0x53 */ 83
+#define KEY_SysReqest /* SysReqest 0x54 */ 84
+ /* NOTUSED 0x55 */
+#define KEY_Less /* < (Less) >(Greater) 0x56 */ 86
+#define KEY_F11 /* F11 0x57 */ 87
+#define KEY_F12 /* F12 0x58 */ 88
+
+#define KEY_Prefix0 /* special 0x60 */ 96
+#define KEY_Prefix1 /* specail 0x61 */ 97
+
+/*
+ * The 'scancodes' below are generated by the server, because the MF101/102
+ * keyboard sends them as sequence of other scancodes
+ */
+#define KEY_Home /* Home 0x59 */ 89
+#define KEY_Up /* Up 0x5a */ 90
+#define KEY_PgUp /* PgUp 0x5b */ 91
+#define KEY_Left /* Left 0x5c */ 92
+#define KEY_Begin /* Begin 0x5d */ 93
+#define KEY_Right /* Right 0x5e */ 94
+#define KEY_End /* End 0x5f */ 95
+#define KEY_Down /* Down 0x60 */ 96
+#define KEY_PgDown /* PgDown 0x61 */ 97
+#define KEY_Insert /* Insert 0x62 */ 98
+#define KEY_Delete /* Delete 0x63 */ 99
+#define KEY_KP_Enter /* Enter 0x64 */ 100
+#define KEY_RCtrl /* Ctrl(right) 0x65 */ 101
+#define KEY_Pause /* Pause 0x66 */ 102
+#define KEY_Print /* Print 0x67 */ 103
+#define KEY_KP_Divide /* Didive 0x68 */ 104
+#define KEY_AltLang /* AtlLang(right) 0x69 */ 105
+#define KEY_Break /* Break 0x6a */ 106
+#define KEY_LMeta /* Left Meta 0x6b */ 107
+#define KEY_RMeta /* Right Meta 0x6c */ 108
+#define KEY_Menu /* Menu 0x6d */ 109
+#define KEY_F13 /* F13 0x6e */ 110
+#define KEY_F14 /* F14 0x6f */ 111
+#define KEY_F15 /* F15 0x70 */ 112
+#define KEY_F16 /* F16 0x71 */ 113
+#define KEY_F17 /* F17 0x72 */ 114
+#define KEY_KP_DEC /* KP_DEC 0x73 */ 115
+#define KEY_SN_KP_7 /* ServerNumLock 7 0x80 */ 128
+#define KEY_SN_KP_8 /* ServerNumLock 8 0x81 */ 129
+#define KEY_SN_KP_9 /* ServerNumLock 9 0x82 */ 130
+#define KEY_SN_KP_4 /* ServerNumLock 4 0x83 */ 131
+#define KEY_SN_KP_5 /* ServerNumLock 5 0x84 */ 132
+#define KEY_SN_KP_6 /* ServerNumLock 6 0x85 */ 133
+#define KEY_SN_KP_1 /* ServerNumLock 1 0x86 */ 134
+#define KEY_SN_KP_2 /* ServerNumLock 2 0x87 */ 135
+#define KEY_SN_KP_3 /* ServerNumLock 4 0x88 */ 136
+#define KEY_SN_KP_0 /* ServerNumLock 0 0x89 */ 137
+#define KEY_SN_KP_Dec /* ServerNumLock Decimal 0x8a */ 138
+#define KEY_SN_KP_Home /* ServerNumLock Home 0x8b */ 139
+#define KEY_SN_KP_Up /* ServerNumLock Up 0x8c */ 140
+#define KEY_SN_KP_Prior /* ServerNumLock Prior 0x8d */ 141
+#define KEY_SN_KP_Left /* ServerNumLock Left 0x8e */ 142
+#define KEY_SN_KP_Begin /* ServerNumLock Begin 0x8f */ 143
+#define KEY_SN_KP_Right /* ServerNumLock Right 0x90 */ 144
+#define KEY_SN_KP_End /* ServerNumLock End 0x91 */ 145
+#define KEY_SN_KP_Down /* ServerNumLock Down 0x92 */ 146
+#define KEY_SN_KP_Next /* ServerNumLock Next 0x93 */ 147
+#define KEY_SN_KP_Ins /* ServerNumLock Ins 0x94 */ 148
+#define KEY_SN_KP_Del /* ServerNumLock Del 0x95 */ 149
+
+#else
+
+#define KEY_Escape /* Escape 0x01 */ 0
+#define KEY_1 /* 1 ! 0x02 */ 1
+#define KEY_2 /* 2 " 0x03 */ 2
+#define KEY_3 /* 3 # 0x04 */ 3
+#define KEY_4 /* 4 $ 0x05 */ 4
+#define KEY_5 /* 5 % 0x06 */ 5
+#define KEY_6 /* 6 & 0x07 */ 6
+#define KEY_7 /* 7 ' 0x08 */ 7
+#define KEY_8 /* 8 ( 0x09 */ 8
+#define KEY_9 /* 9 ) 0x0a */ 9
+#define KEY_0 /* 0 0x0b */ 10
+#define KEY_Minus /* - (Minus) = (Equal) 0x0c */ 11
+#define KEY_Hat /* ^ (Hat) ` 0x0d */ 12
+#define KEY_BSlash /* \(BckSlash) |(VertBar)0x2b */ 13
+#define KEY_BackSpace /* Back Space 0x0e */ 14
+#define KEY_Tab /* Tab 0x0f */ 15
+#define KEY_Q /* Q 0x10 */ 16
+#define KEY_W /* W 0x11 */ 17
+#define KEY_E /* E 0x12 */ 18
+#define KEY_R /* R 0x13 */ 19
+#define KEY_T /* T 0x14 */ 20
+#define KEY_Y /* Y 0x15 */ 21
+#define KEY_U /* U 0x16 */ 22
+#define KEY_I /* I 0x17 */ 23
+#define KEY_O /* O 0x18 */ 24
+#define KEY_P /* P 0x19 */ 25
+#define KEY_At /* @ ~ 0x1a */ 26
+#define KEY_LBrace /* [ { 0x1b */ 27
+#define KEY_Enter /* Enter 0x1c */ 28
+#define KEY_A /* A 0x1d */ 29
+#define KEY_S /* S 0x1e */ 30
+#define KEY_D /* D 0x1f */ 31
+#define KEY_F /* F 0x20 */ 32
+#define KEY_G /* G 0x21 */ 33
+#define KEY_H /* H 0x22 */ 34
+#define KEY_J /* J 0x23 */ 35
+#define KEY_K /* K 0x24 */ 36
+#define KEY_L /* L 0x25 */ 37
+#define KEY_SemiColon /* ;(SemiColon) +(Plus) 0x26 */ 38
+#define KEY_Colon /* :(Colon) *(Quote) 0x27 */ 39
+#define KEY_RBrace /* ] } 0x28 */ 40
+#define KEY_Z /* Z 0x29 */ 41
+#define KEY_X /* X 0x2a */ 42
+#define KEY_C /* C 0x2b */ 43
+#define KEY_V /* V 0x2c */ 44
+#define KEY_B /* B 0x2d */ 45
+#define KEY_N /* N 0x2e */ 46
+#define KEY_M /* M 0x2f */ 47
+#define KEY_Comma /* , (Comma) < (Less) 0x30 */ 48
+#define KEY_Period /* . (Period) >(Greater)0x31 */ 49
+#define KEY_Slash /* / (Slash) ? 0x32 */ 50
+#define KEY_Under /* _ 0x33 */ 51
+#define KEY_Space /* (SpaceBar) 0x34 */ 52
+#define KEY_Xfer /* (XFER) 0x35 */ 53
+#define KEY_PgUp /* PgUp 0x36 */ 54
+#define KEY_Pgdown /* (Roll Down) 0x37 */ 55
+#define KEY_Insert /* Insert 0x38 */ 56
+#define KEY_Delete /* Delete 0x39 */ 57
+#define KEY_Up /* Up 0x3a */ 58
+#define KEY_Left /* Left 0x3b */ 59
+#define KEY_Right /* Right 0x3c */ 60
+#define KEY_Down /* Down 0x3d */ 61
+#define KEY_Home /* Home 0x3e */ 62
+#define KEY_Help /* Help 0x3f */ 63
+#define KEY_KP_Subtract /* - (Minus) 0x40 */ 64
+#define KEY_KP_Minus /* - */ 64
+#define KEY_KP_Divide /* / (Slash) 0x41 */ 65
+#define KEY_KP_7 /* 7 0x42 */ 66
+#define KEY_KP_8 /* 8 0x43 */ 67
+#define KEY_KP_9 /* 9 0x44 */ 68
+#define KEY_KP_Multiply /* * 0x45 */ 69
+#define KEY_KP_4 /* 4 0x46 */ 70
+#define KEY_KP_5 /* 5 0x47 */ 71
+#define KEY_KP_6 /* 6 0x48 */ 72
+#define KEY_KP_Add /* + (Plus) 0x49 */ 73
+#define KEY_KP_Plus /* + */ 73
+#define KEY_KP_1 /* 1 0x4a */ 74
+#define KEY_KP_2 /* 2 0x4b */ 75
+#define KEY_KP_3 /* 3 0x4c */ 76
+#define KEY_KP_Equal /* = 0x4d */ 77
+#define KEY_KP_0 /* 0 0x4e */ 78
+#define KEY_KP_Separator /* , 0x4f */ 79
+#define KEY_KP_Decimal /* . (Decimal) 0x50 */ 80
+#define KEY_Nfer /* (NFER) 0x51 */ 81
+#define KEY_F11 /* F11 0x52 */ 82
+#define KEY_F12 /* F12 0x53 */ 83
+#define KEY_F13 /* F13 0x54 */ 84
+#define KEY_F14 /* F14 0x55 */ 85
+#define KEY_F15 /* F15 0x56 */ 86
+#define KEY_Break /* (Stop) 0x60 */ 96
+#define KEY_Copy /* (Copy) 0x61 */ 97
+#define KEY_Begin /* Begin ?? */ 97
+#define KEY_F1 /* F1 0x62 */ 98
+#define KEY_F2 /* F2 0x63 */ 99
+#define KEY_F3 /* F3 0x64 */ 100
+#define KEY_F4 /* F4 0x65 */ 101
+#define KEY_F5 /* F5 0x66 */ 102
+#define KEY_F6 /* F6 0x67 */ 103
+#define KEY_F7 /* F7 0x68 */ 104
+#define KEY_F8 /* F8 0x69 */ 105
+#define KEY_F9 /* F9 0x6a */ 106
+#define KEY_F10 /* F10 0x6b */ 107
+#define KEY_ShiftL /* Shift(left) 0x70 */ 112
+#define KEY_CapsLock /* CapsLock 0x71 */ 113
+#define KEY_KanaLock /* Kana 0x72 */ 114
+#define KEY_Alt /* Alt(left) 0x73 */ 115
+#define KEY_LCtrl /* Ctrl(left) 0x74 */ 116
+
+#endif /* PC98 */
+
+#endif /* _ATKEYNAMES_H */
diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
new file mode 100644
index 000000000..f85ecd132
--- /dev/null
+++ b/hw/xfree86/common/compiler.h
@@ -0,0 +1,1460 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.24.2.2 1998/02/07 00:44:37 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: compiler.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */
+
+#ifndef _COMPILER_H
+#define _COMPILER_H
+
+#ifndef __STDC__
+# ifdef signed
+# undef signed
+# endif
+# ifdef volatile
+# undef volatile
+# endif
+# ifdef const
+# undef const
+# endif
+# define signed /**/
+# ifdef __GNUC__
+# define volatile __volatile__
+# define const __const__
+# ifdef PC98
+# undef NO_INLINE
+# endif
+# else
+# define const /**/
+# ifdef PC98
+# define __inline__ /**/
+# endif
+# endif /* __GNUC__ */
+#endif /* !__STDC__ */
+
+#if defined(IODEBUG) && defined(__GNUC__)
+#define outb RealOutb
+#define outw RealOutw
+#define outl RealOutl
+#define inb RealInb
+#define inw RealInw
+#define inl RealInl
+#endif
+
+#ifdef NO_INLINE
+
+extern void outb();
+extern void outw();
+extern void outl();
+extern unsigned int inb();
+extern unsigned int inw();
+extern unsigned int inl();
+#if NeedFunctionPrototypes
+extern unsigned char rdinx(unsigned short int, unsigned char);
+extern void wrinx(unsigned short int, unsigned char, unsigned char);
+extern void modinx(unsigned short int, unsigned char, unsigned char, unsigned char);
+extern int testrg(unsigned short int, unsigned char);
+extern int testinx2(unsigned short int, unsigned char, unsigned char);
+extern int testinx(unsigned short int, unsigned char);
+#else /* NeedFunctionProtoypes */
+extern unsigned char rdinx();
+extern void wrinx();
+extern void modinx();
+extern int testrg();
+extern int testinx2();
+extern int testinx();
+#endif /* NeedFunctionProtoypes */
+
+#else /* NO_INLINE */
+
+#ifdef __GNUC__
+
+#if defined(linux) && defined(__alpha__)
+/* for Linux on Alpha, we use the LIBC _inx/_outx routines */
+/* note that the appropriate setup via "ioperm" needs to be done */
+/* *before* any inx/outx is done. */
+
+static __inline__ void
+outb(port, val)
+ unsigned short port;
+ char val;
+{
+ extern void _outb(char val, unsigned short port);
+ _outb(val, port);
+}
+
+static __inline__ void
+outw(port, val)
+ unsigned short port;
+ short val;
+{
+ extern void _outw(short val, unsigned short port);
+ _outw(val, port);
+}
+
+static __inline__ void
+outl(port, val)
+ unsigned short port;
+ int val;
+{
+ extern void _outl(int val, unsigned short port);
+ _outl(val, port);
+}
+
+static __inline__ unsigned int
+inb(port)
+ unsigned short port;
+{
+ extern unsigned int _inb(unsigned short port);
+ return _inb(port);
+}
+
+static __inline__ unsigned int
+inw(port)
+ unsigned short port;
+{
+ extern unsigned int _inw(unsigned short port);
+ return _inw(port);
+}
+
+static __inline__ unsigned int
+inl(port)
+ unsigned short port;
+{
+ extern unsigned int _inl(unsigned short port);
+ return _inl(port);
+}
+
+
+/*
+ * inline functions to do unaligned accesses
+ * from linux/include/asm-alpha/unaligned.h
+ */
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extql %0,%2,%0\n\t"
+ "extqh %1,%2,%1\n\t"
+ "bis %1,%0,%0"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(7+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extll %0,%2,%0\n\t"
+ "extlh %1,%2,%1\n\t"
+ "bis %1,%0,%0"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(3+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+ unsigned long r1,r2;
+ __asm__("ldq_u %0,%3\n\t"
+ "ldq_u %1,%4\n\t"
+ "extwl %0,%2,%0\n\t"
+ "extwh %1,%2,%1\n\t"
+ "bis %1,%0,%0"
+ :"=&r" (r1), "=&r" (r2)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(1+(char *) r11)));
+ return r1;
+}
+
+static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
+{
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "insqh %6,%7,%5\n\t"
+ "insql %6,%7,%4\n\t"
+ "mskqh %3,%7,%3\n\t"
+ "mskql %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(7+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+}
+
+static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
+{
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "inslh %6,%7,%5\n\t"
+ "insll %6,%7,%4\n\t"
+ "msklh %3,%7,%3\n\t"
+ "mskll %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(3+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+}
+
+static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
+{
+ unsigned long r1,r2,r3,r4;
+
+ __asm__("ldq_u %3,%1\n\t"
+ "ldq_u %2,%0\n\t"
+ "inswh %6,%7,%5\n\t"
+ "inswl %6,%7,%4\n\t"
+ "mskwh %3,%7,%3\n\t"
+ "mskwl %2,%7,%2\n\t"
+ "bis %3,%5,%3\n\t"
+ "bis %2,%4,%2\n\t"
+ "stq_u %3,%1\n\t"
+ "stq_u %2,%0"
+ :"=m" (*r11),
+ "=m" (*(unsigned long *)(1+(char *) r11)),
+ "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+ :"r" (r5), "r" (r11));
+}
+
+#define mem_barrier() __asm__ __volatile__("mb" : : : "memory")
+#ifdef __ELF__
+#define write_mem_barrier() __asm__ __volatile__("wmb" : : : "memory")
+#else /* ECOFF gas 2.6 doesn't know "wmb" :-( */
+#define write_mem_barrier() mem_barrier()
+#endif
+
+#else /* defined(linux) && defined(__alpha__) */
+#if defined(__mips__)
+
+unsigned int IOPortBase; /* Memory mapped I/O port area */
+
+static __inline__ void
+outb(port, val)
+ short port;
+ char val;
+{
+ *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outw(port, val)
+ short port;
+ short val;
+{
+ *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ void
+outl(port, val)
+ short port;
+ int val;
+{
+ *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
+}
+
+static __inline__ unsigned int
+inb(port)
+ short port;
+{
+ return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int
+inw(port)
+ short port;
+{
+ return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
+}
+
+static __inline__ unsigned int
+inl(port)
+ short port;
+{
+ return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
+}
+
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(3+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(3+(char *) r11)));
+ return r1;
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+ unsigned long r1;
+ __asm__("lwr %0,%2\n\t"
+ "lwl %0,%3\n\t"
+ :"=&r" (r1)
+ :"r" (r11),
+ "m" (*r11),
+ "m" (*(unsigned long *)(1+(char *) r11)));
+ return r1;
+}
+
+#define stq_u(v,p) stl_u(v,p)
+#define stl_u(v,p) ((unsigned char *)(p)) = (v); \
+ ((unsigned char *)(p)+1) = ((v) >> 8); \
+ ((unsigned char *)(p)+2) = ((v) >> 16); \
+ ((unsigned char *)(p)+3) = ((v) >> 24)
+
+#define stw_u(v,p) ((unsigned char *)(p)) = (v); \
+ ((unsigned char *)(p)+1) = ((v) >> 8)
+
+#define mem_barrier() /* NOP */
+
+#else /* defined(mips) */
+
+#define ldq_u(p) (*((unsigned long *)(p)))
+#define ldl_u(p) (*((unsigned int *)(p)))
+#define ldw_u(p) (*((unsigned short *)(p)))
+#define stq_u(v,p) ((unsigned long *)(p)) = (v)
+#define stl_u(v,p) ((unsigned int *)(p)) = (v)
+#define stw_u(v,p) ((unsigned short *)(p)) = (v)
+#define mem_barrier() /* NOP */
+#define write_mem_barrier() /* NOP */
+
+#if !defined(FAKEIT) && !defined(__mc68000__)
+#ifdef GCCUSESGAS
+
+/*
+ * If gcc uses gas rather than the native assembler, the syntax of these
+ * inlines has to be different. DHD
+ */
+#ifndef PC98
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned char ret;
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned short int ret;
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned int ret;
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+#else /* PC98 */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+_outb(
+unsigned short int port,
+unsigned char val)
+#else
+_outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outb %0,%1" ::"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+_outw(
+unsigned short int port,
+unsigned short int val)
+#else
+_outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outw %0,%1" ::"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+_outl(
+unsigned short int port,
+unsigned int val)
+#else
+_outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+}
+
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inb(
+unsigned short int port)
+#else
+_inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned char ret;
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inw(
+unsigned short int port)
+#else
+_inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned short ret;
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+_inl(
+unsigned short int port)
+#else
+_inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned int ret;
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+
+#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968)
+#define PW_PORT 0x600
+extern short chipID;
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+extern unsigned short _port_tbl[];
+#define port_convert(x) _port_tbl[(unsigned short)x]
+#endif
+
+#if defined(PC98_WAB) || defined(PC98_GANB_WAP)
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+ port <<= 8;
+ port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+ port |= 0xE0;
+ return port;
+}
+#endif /* PC98_WAB || PC98_GANB_WAP */
+
+#if defined(PC98_WABEP)
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+ port &= 0x7f; /* Mask 0000 0000 0111 1111 */
+ port |= 0x0f00;
+ return port;
+}
+#endif /* PC98_WABEP */
+
+#ifdef PC98_WSNA
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+ port <<= 8;
+ port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+ port |= 0xE2;
+ return port;
+}
+#endif /* PC98_WSNA */
+
+#ifdef PC98_NKVNEC
+#ifdef PC98_NEC_CIRRUS2
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+ port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050;
+ return port;
+}
+#else
+static __inline__ unsigned short
+port_convert(unsigned short port)
+{
+ port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0;
+ return port;
+}
+#endif /* PC98_NEC_CIRRUS2 */
+#endif /* PC98_NKVNEC */
+
+#if defined(PC98_TGUI) || defined(PC98_MGA)
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+#endif
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val);
+#else
+ __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short port,
+unsigned short val)
+#else
+outw(port, val)
+unsigned short port;
+unsigned short val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val);
+#else
+ __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val);
+#else
+ __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
+#endif
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short port)
+#else
+inb(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned char ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned char *)((char *)mmioBase+(port));
+#else
+ __asm__ __volatile__("inb %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+#endif
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short port)
+#else
+inw(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned short ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned short *)((char *)mmioBase+(port));
+#else
+ __asm__ __volatile__("inw %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+#endif
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short port)
+#else
+inl(port)
+unsigned short port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned int ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned int *)((char *)mmioBase+(port));
+#else
+ __asm__ __volatile__("inl %1,%0" :
+ "=a" (ret) :
+ "d" (port));
+#endif
+ return ret;
+}
+
+#endif /* PC98 */
+
+#else /* GCCUSESGAS */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+ __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned char ret;
+ __asm__ __volatile__("in%B0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned short int ret;
+ __asm__ __volatile__("in%W0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ unsigned int ret;
+ __asm__ __volatile__("in%L0 (%1)" :
+ "=a" (ret) :
+ "d" (port));
+ return ret;
+}
+
+#endif /* GCCUSESGAS */
+
+#else /* !defined(FAKEIT) && !defined(__mc68000__) */
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outb(
+unsigned short int port,
+unsigned char val)
+#else
+outb(port, val)
+unsigned short int port;
+unsigned char val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outw(
+unsigned short int port,
+unsigned short int val)
+#else
+outw(port, val)
+unsigned short int port;
+unsigned short int val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ void
+#if NeedFunctionPrototypes
+outl(
+unsigned short int port,
+unsigned int val)
+#else
+outl(port, val)
+unsigned short int port;
+unsigned int val;
+#endif /* NeedFunctionPrototypes */
+{
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inb(
+unsigned short int port)
+#else
+inb(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ return 0;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inw(
+unsigned short int port)
+#else
+inw(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ return 0;
+}
+
+static __inline__ unsigned int
+#if NeedFunctionPrototypes
+inl(
+unsigned short int port)
+#else
+inl(port)
+unsigned short int port;
+#endif /* NeedFunctionPrototypes */
+{
+ return 0;
+}
+
+#endif /* FAKEIT */
+
+#endif /* defined(mips) */
+#endif /* defined(AlphaArchitecture) && defined(LinuxArchitecture) */
+
+#else /* __GNUC__ */
+#if !defined(AMOEBA) && !defined(MINIX)
+# if defined(__STDC__) && (__STDC__ == 1)
+# ifndef asm
+# define asm __asm
+# endif
+# endif
+# ifdef SVR4
+# include <sys/types.h>
+# ifndef __HIGHC__
+# ifndef __USLC__
+# define __USLC__
+# endif
+# endif
+# endif
+# ifndef PC98
+# ifndef SCO325
+# include <sys/inline.h>
+# else
+# include "scoasm.h"
+# endif
+# else
+#if defined(PC98_PW) || defined(PC98_XKB) || defined(PC98_NEC) || defined(PC98_PWLB) || defined(PC98_GA968)
+#define PW_PORT 0x600
+extern short chipID;
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+extern unsigned short _port_tbl[];
+#define port_convert(x) _port_tbl[(unsigned short)x]
+#endif
+
+#if defined(PC98_TGUI) || defined(PC98_MGA)
+#if NeedFunctionPrototypes
+extern void *mmioBase;
+#else
+extern unsigned char *mmioBase;
+#endif
+#endif
+
+asm void _outl(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+}
+
+asm void _outw(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ data16
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movw val, %ax
+ data16
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ data16
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movw val, %ax
+ data16
+ outl (%dx)
+}
+
+asm void _outb(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outb (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movb val, %al
+ outb (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outb (%dx)
+%mem port,val;
+ movw port, %dx
+ movb val, %al
+ outb (%dx)
+}
+
+asm int _inl(port)
+{
+%reg port;
+ movl port, %edx
+ inl (%dx)
+%mem port;
+ movw port, %dx
+ inl (%dx)
+}
+
+asm int _inw(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ data16
+ inl (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ data16
+ inl (%dx)
+}
+
+asm int _inb(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ inb (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ inb (%dx)
+}
+
+#if defined(PC98_WAB) || defined(PC98_GANB_WAP)
+static unsigned short
+port_convert(unsigned short port)
+{
+ port <<= 8;
+ port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+ port |= 0xE0;
+ return port;
+}
+#endif /* PC98_WAB || PC98_GANB_WAP */
+
+#if defined(PC98_WABEP)
+static unsigned short
+port_convert(unsigned short port)
+{
+ port &= 0x7f; /* Mask 0000 0000 0111 1111 */
+ port |= 0x0f00;
+ return port;
+}
+#endif /* PC98_WABEP */
+
+#ifdef PC98_WSNA
+static unsigned short
+port_convert(unsigned short port)
+{
+ port <<= 8;
+ port &= 0x7f00; /* Mask 0111 1111 0000 0000 */
+ port |= 0xE2;
+ return port;
+}
+#endif /* PC98_WSNA */
+
+#ifdef PC98_NKVNEC
+#ifdef PC98_NEC_CIRRUS2
+static unsigned short
+port_convert(unsigned short port)
+{
+ port = (port & 0xf) + ((port & 0xf0) << 4) + 0x0050;
+ return port;
+}
+#else
+static unsigned short
+port_convert(unsigned short port)
+{
+ port = (port & 0xf) + ((port & 0xf0) << 4) + 0x00a0;
+ return port;
+}
+#endif /* PC98_NEC_CIRRUS2 */
+#endif /* PC98_NKVNEC */
+
+static void outl(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned int *)((char *)mmioBase+(port)) = (unsigned int)(val);
+#else
+ _outl(port,val);
+#endif
+}
+
+static void outw(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned short *)((char *)mmioBase+(port)) = (unsigned short)(val);
+#else
+ _outw(port,val);
+#endif
+}
+
+static void outb(port,val)
+{
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ *(volatile unsigned char *)((char *)mmioBase+(port)) = (unsigned char)(val);
+#else
+ _outb(port,val);
+#endif
+}
+
+static int inl(port)
+{
+ unsigned int ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned int *)((char *)mmioBase+(port));
+#else
+ ret = _inl(port);
+#endif
+ return ret;
+}
+
+static int inw(port)
+{
+ unsigned short ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned short *)((char *)mmioBase+(port));
+#else
+ ret = _inw(port);
+#endif
+ return ret;
+}
+
+static int inb(port)
+{
+ unsigned char ret;
+
+#if defined(PC98_GANB_WAP) || defined(PC98_NKVNEC) || defined(PC98_WAB) || \
+ defined(PC98_WABEP) || defined(PC98_WSNA) || defined(PC98_PW) || \
+ defined(PC98_XKB) || defined(PC98_NEC)
+ unsigned short tmp;
+ tmp=port_convert(port);
+ port=tmp;
+#endif
+
+#if defined(PC98_NEC)||defined(PC98_PWLB)||defined(PC98_TGUI)||defined(PC98_MGA)
+ ret =*(volatile unsigned char *)((char *)mmioBase+(port));
+#else
+ ret = _inb(port);
+#endif
+ return ret;
+}
+
+
+# endif /* PC98 */
+# if !defined(__HIGHC__) && !defined(SCO325)
+# pragma asm partial_optimization outl
+# pragma asm partial_optimization outw
+# pragma asm partial_optimization outb
+# pragma asm partial_optimization inl
+# pragma asm partial_optimization inw
+# pragma asm partial_optimization inb
+# endif
+#endif
+#define ldq_u(p) (*((unsigned long *)(p)))
+#define ldl_u(p) (*((unsigned int *)(p)))
+#define ldw_u(p) (*((unsigned short *)(p)))
+#define stq_u(v,p) ((unsigned long *)(p)) = (v)
+#define stl_u(v,p) ((unsigned int *)(p)) = (v)
+#define stw_u(v,p) ((unsigned short *)(p)) = (v)
+#define mem_barrier() /* NOP */
+#define write_mem_barrier() /* NOP */
+#endif /* __GNUC__ */
+
+#if defined(IODEBUG) && defined(__GNUC__)
+#undef inb
+#undef inw
+#undef inl
+#undef outb
+#undef outw
+#undef outl
+#define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+#define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+#define inl(a) __extension__ ({unsigned long __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
+
+#define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b))
+#define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b))
+#define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b))
+#endif
+
+/*
+ * This header sometimes gets included where is isn't needed, and on some
+ * OSs this causes problems because the following functions generate
+ * references to inb() and outb() which can't be resolved. Defining
+ * NO_COMPILER_H_EXTRAS avoids this problem.
+ */
+
+#ifndef NO_COMPILER_H_EXTRAS
+/*
+ *-----------------------------------------------------------------------
+ * Port manipulation convenience functions
+ *-----------------------------------------------------------------------
+ */
+
+#ifndef __GNUC__
+#define __inline__ /**/
+#endif
+
+/*
+ * rdinx - read the indexed byte port 'port', index 'ind', and return its value
+ */
+static __inline__ unsigned char
+#ifdef __STDC__
+rdinx(unsigned short int port, unsigned char ind)
+#else
+rdinx(port, ind)
+unsigned short int port;
+unsigned char ind;
+#endif
+{
+ if (port == 0x3C0) /* reset attribute flip-flop */
+ (void) inb(0x3DA);
+ outb(port, ind);
+ return(inb(port+1));
+}
+
+/*
+ * wrinx - write 'val' to port 'port', index 'ind'
+ */
+static __inline__ void
+#ifdef __STDC__
+wrinx(unsigned short int port, unsigned char ind, unsigned char val)
+#else
+wrinx(port, ind, val)
+unsigned short int port;
+unsigned char ind, val;
+#endif
+{
+ outb(port, ind);
+ outb(port+1, val);
+}
+
+/*
+ * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
+ * the other bits are unchanged.
+ */
+static __inline__ void
+#ifdef __STDC__
+modinx(unsigned short int port, unsigned char ind,
+ unsigned char mask, unsigned char new)
+#else
+modinx(port, ind, mask, new)
+unsigned short int port;
+unsigned char ind, mask, new;
+#endif
+{
+ unsigned char tmp;
+
+ tmp = (rdinx(port, ind) & ~mask) | (new & mask);
+ wrinx(port, ind, tmp);
+}
+
+/*
+ * tstrg - returns true iff the bits in 'mask' of register 'port' are
+ * readable & writable.
+ */
+
+static __inline__ int
+#ifdef __STDC__
+testrg(unsigned short int port, unsigned char mask)
+#else
+tstrg(port, mask)
+unsigned short int port;
+unsigned char mask;
+#endif
+{
+ unsigned char old, new1, new2;
+
+ old = inb(port);
+ outb(port, old & ~mask);
+ new1 = inb(port) & mask;
+ outb(port, old | mask);
+ new2 = inb(port) & mask;
+ outb(port, old);
+ return((new1 == 0) && (new2 == mask));
+}
+
+/*
+ * testinx2 - returns true iff the bits in 'mask' of register 'port', index
+ * 'ind' are readable & writable.
+ */
+static __inline__ int
+#ifdef __STDC__
+testinx2(unsigned short int port, unsigned char ind, unsigned char mask)
+#else
+testinx2(port, ind, mask)
+unsigned short int port;
+unsigned char ind, mask;
+#endif
+{
+ unsigned char old, new1, new2;
+
+ old = rdinx(port, ind);
+ wrinx(port, ind, old & ~mask);
+ new1 = rdinx(port, ind) & mask;
+ wrinx(port, ind, old | mask);
+ new2 = rdinx(port, ind) & mask;
+ wrinx(port, ind, old);
+ return((new1 == 0) && (new2 == mask));
+}
+
+/*
+ * testinx - returns true iff all bits of register 'port', index 'ind' are
+ * readable & writable.
+ */
+static __inline__ int
+#ifdef __STDC__
+testinx(unsigned short int port, unsigned char ind)
+#else
+testinx(port, ind, mask)
+unsigned short int port;
+unsigned char ind;
+#endif
+{
+ return(testinx2(port, ind, 0xFF));
+}
+#endif /* NO_COMPILER_H_EXTRAS */
+
+#endif /* NO_INLINE */
+#endif /* _COMPILER_H */
diff --git a/hw/xfree86/common/scoasm.h b/hw/xfree86/common/scoasm.h
new file mode 100644
index 000000000..12fe46693
--- /dev/null
+++ b/hw/xfree86/common/scoasm.h
@@ -0,0 +1,112 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/scoasm.h,v 3.0 1996/10/03 08:34:06 dawes Exp $ */
+
+/*
+ * scoasm.h - used to define inline versions of certain functions which
+ * do NOT appear in sys/inline.h.
+ */
+#ifdef SCO325
+#ifndef _SCOASM_HDR_INC
+#define _SCOASM_HDR_INC
+
+asm void outl(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movl val, %eax
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movl val, %eax
+ outl (%dx)
+}
+
+asm void outw(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ data16
+ outl (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movw val, %ax
+ data16
+ outl (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ data16
+ outl (%dx)
+%mem port,val;
+ movw port, %dx
+ movw val, %ax
+ data16
+ outl (%dx)
+}
+
+asm void outb(port,val)
+{
+%reg port,val;
+ movl port, %edx
+ movl val, %eax
+ outb (%dx)
+%reg port; mem val;
+ movl port, %edx
+ movb val, %al
+ outb (%dx)
+%mem port; reg val;
+ movw port, %dx
+ movl val, %eax
+ outb (%dx)
+%mem port,val;
+ movw port, %dx
+ movb val, %al
+ outb (%dx)
+}
+
+asm int inl(port)
+{
+%reg port;
+ movl port, %edx
+ inl (%dx)
+%mem port;
+ movw port, %dx
+ inl (%dx)
+}
+
+asm int inw(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ data16
+ inl (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ data16
+ inl (%dx)
+}
+
+asm int inb(port)
+{
+%reg port;
+ subl %eax, %eax
+ movl port, %edx
+ inb (%dx)
+%mem port;
+ subl %eax, %eax
+ movw port, %dx
+ inb (%dx)
+}
+
+#endif /* _SCOASM_HDR_INC */
+#endif /* SCO325 */
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
new file mode 100644
index 000000000..ba00913d8
--- /dev/null
+++ b/hw/xfree86/common/xf86.h
@@ -0,0 +1,743 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86.h,v 3.47.2.8 1998/02/24 19:05:53 hohndel Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86.h,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */
+
+#ifndef _XF86_H
+#define _XF86_H
+
+#include "misc.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86_Option.h"
+
+/*
+ * structure common for all modes
+ */
+typedef struct _DispM {
+ struct _DispM *prev,*next;
+ char *name; /* identifier of this mode */
+ /* These are the values that the user sees/provides */
+ int Clock; /* pixel clock */
+ int HDisplay; /* horizontal timing */
+ int HSyncStart;
+ int HSyncEnd;
+ int HTotal;
+ int HSkew;
+ int VDisplay; /* vertical timing */
+ int VSyncStart;
+ int VSyncEnd;
+ int VTotal;
+ int Flags;
+ /* These are the values the hardware uses */
+ int SynthClock; /* Actual clock freq to be programmed */
+ int CrtcHDisplay;
+ int CrtcHSyncStart;
+ int CrtcHSyncEnd;
+ int CrtcHTotal;
+ int CrtcHSkew;
+ int CrtcVDisplay;
+ int CrtcVSyncStart;
+ int CrtcVSyncEnd;
+ int CrtcVTotal;
+ Bool CrtcHAdjusted;
+ Bool CrtcVAdjusted;
+ int PrivSize;
+ INT32 *Private;
+} DisplayModeRec, *DisplayModePtr;
+
+#define V_PHSYNC 0x0001
+#define V_NHSYNC 0x0002
+#define V_PVSYNC 0x0004
+#define V_NVSYNC 0x0008
+#define V_INTERLACE 0x0010
+#define V_DBLSCAN 0x0020
+#define V_CSYNC 0x0040
+#define V_PCSYNC 0x0080
+#define V_NCSYNC 0x0100
+#define V_HSKEW 0x0200 /* hskew provided */
+#define V_PIXMUX 0x1000
+#define V_DBLCLK 0x2000
+#define V_CLKDIV2 0x4000
+
+/* The monitor description */
+
+#define MAX_HSYNC 8
+#define MAX_VREFRESH 8
+
+typedef struct { float hi, lo; } range;
+
+typedef struct {
+ char *id;
+ char *vendor;
+ char *model;
+ float EMPTY;
+ int n_hsync;
+ range hsync[MAX_HSYNC];
+ int n_vrefresh;
+ range vrefresh[MAX_VREFRESH];
+ DisplayModePtr Modes, Last; /* Start and end of monitor's mode list */
+} MonRec, *MonPtr;
+
+#define MAXCLOCKS 128
+#define MAXDACSPEEDS 4 /* for <= 8, 16, 24, 32bpp */
+
+/* Set default max allowed clock to 90MHz */
+#define DEFAULT_MAX_CLOCK 90000
+
+/*
+ * the graphic device
+ */
+typedef struct {
+ Bool configured;
+ int tmpIndex;
+ int scrnIndex;
+ Bool (* Probe)(
+#if NeedNestedPrototypes
+ void
+#endif
+);
+ Bool (* Init)(
+#if NeedNestedPrototypes
+ int scr_index,
+ ScreenPtr pScreen,
+ int argc,
+ char **argv
+#endif
+);
+ int (* ValidMode)(
+#if NeedNestedPrototypes
+ DisplayModePtr target,
+ Bool verbose,
+ int flag
+#endif
+);
+ void (* EnterLeaveVT)(
+#if NeedNestedPrototypes
+ int,
+ int
+#endif
+);
+ void (* EnterLeaveMonitor)(
+#if NeedNestedPrototypes
+ int
+#endif
+);
+ void (* EnterLeaveCursor)(
+#if NeedNestedPrototypes
+ int
+#endif
+);
+ void (* AdjustFrame)(
+#if NeedNestedPrototypes
+ int x,
+ int y
+#endif
+);
+ Bool (* SwitchMode)(
+#if NeedNestedPrototypes
+ DisplayModePtr modes
+#endif
+);
+ void (* DPMSSet)(
+#if NeedNestedPrototypes
+ int level
+#endif
+);
+ void (* PrintIdent)(
+#if NeedNestedPrototypes
+ void
+#endif
+);
+ int depth;
+ xrgb weight;
+ int bitsPerPixel;
+ int defaultVisual;
+ int virtualX,virtualY;
+ int displayWidth;
+ int frameX0, frameY0, frameX1, frameY1;
+ OFlagSet options;
+ OFlagSet clockOptions;
+ OFlagSet xconfigFlag;
+ char *chipset;
+ char *ramdac;
+ int dacSpeeds[MAXDACSPEEDS];
+ int dacSpeedBpp;
+ int clocks;
+ int clock[MAXCLOCKS];
+ int maxClock;
+ int videoRam;
+ int BIOSbase; /* Base address of video BIOS */
+ unsigned long MemBase; /* Frame buffer base address */
+ int width, height; /* real display dimensions */
+ unsigned long speedup; /* Use SpeedUp code */
+ DisplayModePtr modes;
+ MonPtr monitor;
+ char *clockprog;
+ int textclock;
+ Bool bankedMono; /* display supports banking for mono server */
+ char *name;
+ xrgb blackColour;
+ xrgb whiteColour;
+ int *validTokens;
+ char *patchLevel;
+ unsigned int IObase; /* AGX - video card I/O reg base */
+ unsigned int DACbase; /* AGX - dac I/O reg base */
+ unsigned long COPbase; /* AGX - coprocessor memory base */
+ unsigned int POSbase; /* AGX - I/O address of POS regs */
+ int instance; /* AGX - XGA video card instance number */
+ int s3Madjust;
+ int s3Nadjust;
+ int s3MClk;
+ int chipID;
+ int chipRev;
+ unsigned long VGAbase; /* AGX - 64K aperture memory address */
+ int s3RefClk;
+ int s3BlankDelay;
+ int textClockFreq;
+ char *DCConfig;
+ char *DCOptions;
+ int MemClk; /* General flag used for memory clocking */
+ int LCDClk;
+#ifdef XFreeXDGA
+ int directMode;
+ void (*setBank)(
+#if NeedNestedPrototypes
+ int
+#endif
+ );
+ unsigned long physBase;
+ int physSize;
+#endif
+#ifdef XF86SETUP
+ void *device; /* This should be GDevPtr, but it causes
+ problems with include file order */
+#endif
+} ScrnInfoRec, *ScrnInfoPtr;
+
+typedef struct {
+ int token; /* id of the token */
+ char *name; /* pointer to the LOWERCASED name */
+} SymTabRec, *SymTabPtr;
+
+#define VGA_DRIVER 1
+#define V256_DRIVER 2
+#define WGA_DRIVER 3
+#define XGA_DRIVER 4
+
+#define ENTER 1
+#define LEAVE 0
+
+/* These are possible return values for xf86CheckMode() and ValidMode() */
+#define MODE_OK 0
+#define MODE_HSYNC 1 /* hsync out of range */
+#define MODE_VSYNC 2 /* vsync out of range */
+#define MODE_BAD 255 /* unspecified reason */
+
+/* These are the possible flags for ValidMode */
+#define MODE_USED 1 /* this mode is really being used in the */
+ /* modes line of the Display Subsection */
+#define MODE_SUGGESTED 2 /* this mode is included in the available*/
+ /* modes in the Monitor Section */
+#define MODE_VID 3 /* this is called from the VidMode extension */
+
+/* Indicates the level of DPMS support */
+typedef enum {
+ DPMSSupportUnknown,
+ DPMSNotSupported,
+ DPMSFullSupport
+} DPMSSupportStatus;
+
+/* flags for xf86LookupMode */
+#define LOOKUP_DEFAULT 0 /* Use default mode lookup method */
+#define LOOKUP_BEST_REFRESH 1 /* Pick modes with best refresh */
+#define LOOKUP_NO_INTERLACED 2 /* Ignore interlaced modes */
+#define LOOKUP_FORCE_DEFAULT 4 /* Force default lookup method */
+
+#define INTERLACE_REFRESH_WEIGHT 1.5
+
+/* SpeedUp options */
+
+#define SPEEDUP_FILLBOX 1
+#define SPEEDUP_FILLRECT 2
+#define SPEEDUP_BITBLT 4
+#define SPEEDUP_LINE 8
+#define SPEEDUP_TEGBLT8 0x10
+#define SPEEDUP_RECTSTIP 0x20
+
+/*
+ * This is the routines where SpeedUp is quicker than fXF86. The problem is
+ * that the SpeedUp fillbox is better for drawing vertical and horizontal
+ * line segments, and the fXF86 version is significantly better for
+ * more general lines
+ */
+#define SPEEDUP_BEST (SPEEDUP_FILLRECT | SPEEDUP_BITBLT | \
+ SPEEDUP_LINE | SPEEDUP_TEGBLT8 | \
+ SPEEDUP_RECTSTIP)
+/*
+#define SPEEDUP_BEST (SPEEDUP_FILLBOX | SPEEDUP_FILLRECT | \
+ SPEEDUP_BITBLT | SPEEDUP_LINE | \
+ SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP)
+*/
+
+/*
+ * SpeedUp routines which are not dependent on the screen virtual resolution
+ */
+#ifndef SPEEDUP_ANYWIDTH
+#define SPEEDUP_ANYWIDTH (SPEEDUP_FILLRECT | SPEEDUP_BITBLT | \
+ SPEEDUP_LINE | SPEEDUP_FILLBOX)
+#endif
+
+/*
+ * SpeedUp routines which are not dependent on ET4000
+ */
+#ifndef SPEEDUP_ANYCHIPSET
+#define SPEEDUP_ANYCHIPSET (SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP)
+#endif
+
+/* All SpeedUps */
+#define SPEEDUP_ALL (SPEEDUP_FILLBOX | SPEEDUP_FILLRECT | \
+ SPEEDUP_BITBLT | SPEEDUP_LINE | \
+ SPEEDUP_TEGBLT8 | SPEEDUP_RECTSTIP)
+
+/* SpeedUp flags used if SpeedUp is not in XF86Config */
+#define SPEEDUP_DEFAULT SPEEDUP_ALL
+
+extern Bool xf86VTSema;
+
+/* Mouse device private record */
+
+#define MSE_MAPTOX (-1)
+#define MSE_MAPTOY (-2)
+#define MSE_MAXBUTTONS 12
+#define MSE_DFLTBUTTONS 3
+
+typedef struct _MouseDevRec {
+ DeviceProc mseProc; /* procedure for initializing */
+ void (* mseEvents)(
+#if NeedNestedPrototypes
+ struct _MouseDevRec *
+#endif
+ ); /* proc for processing events */
+ DeviceIntPtr device;
+ int mseFd;
+ char *mseDevice;
+ int mseType;
+ int mseModel;
+ int baudRate;
+ int oldBaudRate;
+ int sampleRate;
+ int lastButtons;
+ int threshold, num, den; /* acceleration */
+ int buttons; /* # of buttons */
+ int emulateState; /* automata state for 2 button mode */
+ Bool emulate3Buttons;
+ int emulate3Timeout; /* Timeout for 3 button emulation */
+ Bool chordMiddle;
+ int mouseFlags; /* Flags to Clear after opening mouse dev */
+ int truebuttons; /* Arg to maintain before emulate3buttons timer callback */
+
+ int resolution;
+ int negativeZ;
+ int positiveZ;
+#ifndef MOUSE_PROTOCOL_IN_KERNEL
+ unsigned char protoPara[7];
+#endif
+
+#ifndef CSRG_BASED
+ /* xque part */
+ int xquePending; /* was xqueFd, but nothing uses that */
+ int xqueSema;
+#endif
+#ifdef XINPUT
+ struct _LocalDeviceRec *local;
+#endif
+} MouseDevRec, *MouseDevPtr;
+
+#ifdef XINPUT
+#define MOUSE_DEV(dev) (MouseDevPtr) PRIVATE(dev)
+#else
+#define MOUSE_DEV(dev) (MouseDevPtr) (dev)->public.devicePrivate
+#endif
+
+/* Global data */
+/* xf86Init.c */
+extern double xf86rGamma, xf86gGamma, xf86bGamma;
+
+#ifdef XF86VIDMODE
+extern Bool xf86VidModeEnabled;
+extern Bool xf86VidModeAllowNonLocal;
+#endif
+#ifdef XF86MISC
+extern Bool xf86MiscModInDevEnabled;
+extern Bool xf86MiscModInDevAllowNonLocal;
+#endif
+
+/* PCI probe flags */
+
+
+typedef enum {
+ PCIProbe1 = 0,
+ PCIProbe2,
+ PCIForceConfig1,
+ PCIForceConfig2
+} PciProbeType;
+
+extern PciProbeType xf86PCIFlags;
+
+/* Function Prototypes */
+#ifndef _NO_XF86_PROTOTYPES
+
+/* xf86Init.c */
+void InitOutput(
+#if NeedFunctionPrototypes
+ ScreenInfo *pScreenInfo,
+ int argc,
+ char **argv
+#endif
+);
+
+void InitInput(
+#if NeedFunctionPrototypes
+ int argc,
+ char **argv
+#endif
+);
+
+void ddxGiveUp(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void AbortDDX(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+int ddxProcessArgument(
+#if NeedFunctionPrototypes
+ int argc,
+ char *argv[],
+ int i
+#endif
+);
+
+void ddxUseMsg(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+/* xf86Config.c */
+unsigned int StrToUL(
+#if NeedFunctionPrototypes
+ char *str
+#endif
+);
+
+#ifndef CONFIG_RETURN_TYPE
+#ifdef XF86SETUP
+#define CONFIG_RETURN_TYPE int
+#else
+#define CONFIG_RETURN_TYPE void
+#endif
+#endif
+
+CONFIG_RETURN_TYPE xf86Config(
+#if NeedFunctionPrototypes
+ int vtopen
+#endif
+);
+
+CONFIG_RETURN_TYPE configPointerSection(
+#if NeedFunctionPrototypes
+ MouseDevPtr /*mouse_dev*/,
+ int /*end_tag*/,
+ char** /*devicename*/
+#endif
+);
+
+Bool xf86LookupMode(
+#if NeedFunctionPrototypes
+ DisplayModePtr target,
+ ScrnInfoPtr driver,
+ int flags
+#endif
+);
+
+void xf86VerifyOptions(
+#if NeedFunctionPrototypes
+ OFlagSet *allowedOptions,
+ ScrnInfoPtr driver
+#endif
+);
+
+int xf86CheckMode(
+#if NeedFunctionPrototypes
+ ScrnInfoPtr scrp,
+ DisplayModePtr dispmp,
+ MonPtr monp,
+ int verbose
+#endif
+);
+
+int xf86GetNearestClock(
+#if NeedFunctionPrototypes
+ ScrnInfoPtr Screen,
+ int Frequency
+#endif
+);
+
+/* xf86Cursor.c */
+void xf86InitViewport(
+#if NeedFunctionPrototypes
+ ScrnInfoPtr pScr
+#endif
+);
+
+void xf86SetViewport(
+#if NeedFunctionPrototypes
+ ScreenPtr pScreen,
+ int x,
+ int y
+#endif
+);
+
+void xf86LockZoom(
+#if NeedFunctionPrototypes
+ ScreenPtr pScreen,
+ int lock
+#endif
+);
+
+void xf86ZoomViewport(
+#if NeedFunctionPrototypes
+ ScreenPtr pScreen,
+ int zoom
+#endif
+);
+
+/* xf86Dl.c */
+void*
+xf86LoadModule(
+#if NeedFunctionPrototypes
+ const char * file,
+ const char * path
+#endif
+);
+
+/* xf86Events.c */
+int TimeSinceLastInputEvent(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void SetTimeSinceLastInputEvent(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void ProcessInputEvents(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void xf86PostKbdEvent(
+#if NeedFunctionPrototypes
+ unsigned key
+#endif
+);
+
+void xf86PostMseEvent(
+#if NeedFunctionPrototypes
+ DeviceIntPtr device,
+ int buttons,
+ int dx,
+ int dy
+#endif
+);
+
+void xf86Block(
+#if NeedFunctionPrototypes
+ pointer blockData,
+ OSTimePtr pTimeout,
+ pointer pReadmask
+#endif
+);
+
+void xf86Wakeup(
+#if NeedFunctionPrototypes
+ pointer blockData,
+ int err,
+ pointer pReadmask
+#endif
+);
+
+void xf86SigHandler(
+#if NeedFunctionPrototypes
+ int signo
+#endif
+);
+
+/* xf86Io.c */
+void xf86KbdBell(
+#if NeedFunctionPrototypes
+ int percent,
+ DeviceIntPtr pKeyboard,
+ pointer ctrl,
+ int unused
+#endif
+);
+
+void xf86KbdLeds(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void xf86KbdCtrl(
+#if NeedFunctionPrototypes
+ DevicePtr pKeyboard,
+ KeybdCtrl *ctrl
+#endif
+);
+
+void xf86InitKBD(
+#if NeedFunctionPrototypes
+ Bool init
+#endif
+);
+
+int xf86KbdProc(
+#if NeedFunctionPrototypes
+ DeviceIntPtr pKeyboard,
+ int what
+#endif
+);
+
+void xf86MseCtrl(
+#if NeedFunctionPrototypes
+ DevicePtr pPointer,
+ PtrCtrl *ctrl
+#endif
+);
+
+int GetMotionEvents(
+#if NeedFunctionPrototypes
+ DeviceIntPtr,
+ xTimecoord *,
+ unsigned long,
+ unsigned long,
+ ScreenPtr
+#endif
+);
+
+int xf86MseProc(
+#if NeedFunctionPrototypes
+ DeviceIntPtr pPointer,
+ int what
+#endif
+);
+
+void xf86MseEvents(
+#if NeedFunctionPrototypes
+ MouseDevPtr mouse
+#endif
+);
+
+CARD32 GetTimeInMillis(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+void OsVendorInit(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+/* xf86_Mouse.c */
+Bool xf86MouseSupported(
+#if NeedFunctionPrototypes
+ int mousetype
+#endif
+);
+
+void xf86SetupMouse(
+#if NeedFunctionPrototypes
+ MouseDevPtr mouse
+#endif
+);
+
+void xf86MouseProtocol(
+#if NeedFunctionPrototypes
+ DeviceIntPtr device,
+ unsigned char *rBuf,
+ int nBytes
+#endif
+);
+
+#ifdef XINPUT
+void xf86MouseCtrl(
+#if NeedFunctionPrototypes
+ DeviceIntPtr device,
+ PtrCtrl *ctrl
+#endif
+);
+#endif
+
+/* xf86_PnPMouse.c */
+int xf86GetPnPMouseProtocol(
+#if NeedFunctionPrototypes
+ MouseDevPtr mouse
+#endif
+);
+
+/* xf86Kbd.c */
+Bool LegalModifier(
+#if NeedFunctionPrototypes
+ unsigned int key,
+ DevicePtr pDev
+#endif
+);
+
+void xf86KbdGetMapping(
+#if NeedFunctionPrototypes
+ KeySymsPtr pKeySyms,
+ CARD8 *pModMap
+#endif
+);
+#endif /* _NO_XF86_PROTOTYPES */
+
+/* End of Prototypes */
+
+#endif /* _XF86_H */
+
+
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
new file mode 100644
index 000000000..e523dd0fc
--- /dev/null
+++ b/hw/xfree86/common/xf86Config.c
@@ -0,0 +1,3934 @@
+/*
+ * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.113.2.17 1998/02/24 19:05:54 hohndel Exp $
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $Xorg: xf86Config.c,v 1.3 2000/08/17 19:50:28 cpqbld Exp $ */
+
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#else
+extern double atof();
+extern char *getenv();
+#endif
+
+#define NEED_EVENTS 1
+#include "X.h"
+#include "Xproto.h"
+#include "Xmd.h"
+#include "input.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+
+#ifdef DPMSExtension
+#include "opaque.h"
+extern CARD32 DPMSStandbyTime;
+extern CARD32 DPMSSuspendTime;
+extern CARD32 DPMSOffTime;
+#endif
+
+#define NO_COMPILER_H_EXTRAS
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+#define INIT_CONFIG
+#include "xf86_Config.h"
+
+#ifdef XKB
+#include "inputstr.h"
+#include "XKBsrv.h"
+#endif
+
+#ifdef XF86SETUP
+#include "xfsconf.h"
+#endif
+
+#ifdef XINPUT
+#include "xf86Xinput.h"
+
+#ifndef XF86SETUP
+extern DeviceAssocRec mouse_assoc;
+#endif
+#endif
+
+#ifdef NEED_RETURN_VALUE
+#define HANDLE_RETURN(xx) if (xx == RET_ERROR) return RET_ERROR
+#else
+#define HANDLE_RETURN(xx) xx
+#endif
+
+#define CONFIG_BUF_LEN 1024
+
+static FILE * configFile = NULL;
+static int configStart = 0; /* start of the current token */
+static int configPos = 0; /* current readers position */
+static int configLineNo = 0; /* linenumber */
+static char *configBuf,*configRBuf; /* buffer for lines */
+static char *configPath; /* path to config file */
+static char *fontPath = NULL; /* font path */
+static char *modulePath = NULL; /* module path */
+static int pushToken = LOCK_TOKEN;
+static LexRec val; /* global return value */
+static char DCerr;
+static int scr_index = 0;
+
+#ifdef XF86SETUP
+#define STATIC_OR_NOT
+#else
+#define STATIC_OR_NOT static
+#endif
+STATIC_OR_NOT int n_monitors = 0;
+STATIC_OR_NOT MonPtr monitor_list = NULL;
+STATIC_OR_NOT int n_devices = 0;
+STATIC_OR_NOT GDevPtr device_list = NULL;
+
+static int screenno = -100; /* some little number ... */
+
+extern char *defaultFontPath;
+extern char *rgbPath;
+
+extern Bool xf86fpFlag, xf86coFlag, xf86sFlag;
+extern Bool xf86ScreensOpen;
+
+extern int defaultColorVisualClass;
+extern CARD32 defaultScreenSaverTime, ScreenSaverTime;
+
+char *xf86VisualNames[] = {
+ "StaticGray",
+ "GrayScale",
+ "StaticColor",
+ "PseudoColor",
+ "TrueColor",
+ "DirectColor"
+};
+
+static CONFIG_RETURN_TYPE configFilesSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configServerFlagsSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configKeyboardSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configDeviceSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configScreenSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configDisplaySubsection(
+#if NeedFunctionPrototypes
+ DispPtr disp
+#endif
+);
+static CONFIG_RETURN_TYPE configMonitorSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static CONFIG_RETURN_TYPE configDynamicModuleSection(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+static char *xf86DCSaveLine(
+#if NeedFunctionPrototypes
+char *,
+int
+#endif
+);
+static char *xf86DCOption(
+#if NeedFunctionPrototypes
+char *,
+LexRec
+#endif
+);
+static char * xf86DCConcatOption(
+#if NeedFunctionPrototypes
+char *,
+char *
+#endif
+);
+#ifndef XF86SETUP
+static
+#endif
+CONFIG_RETURN_TYPE findConfigFile(
+#if NeedFunctionPrototypes
+ char *filename,
+ FILE **fp
+#endif
+);
+static int getScreenIndex(
+#if NeedFunctionPrototypes
+ int token
+#endif
+);
+static int getStringToken(
+#if NeedFunctionPrototypes
+ SymTabRec tab[]
+#endif
+);
+static CONFIG_RETURN_TYPE readVerboseMode(
+#if NeedFunctionPrototypes
+ MonPtr monp
+#endif
+);
+static Bool validateGraphicsToken(
+#if NeedFunctionPrototypes
+ int *validTokens,
+ int token
+#endif
+);
+extern char * xf86GetPathElem(
+#if NeedFunctionPrototypes
+ char **pnt
+#endif
+);
+static DisplayModePtr xf86PruneModes(
+#if NeedFunctionPrototypes
+ MonPtr monp,
+ DisplayModePtr allmodes,
+ ScrnInfoPtr scrp,
+ Bool card
+#endif
+);
+static char * xf86ValidateFontPath(
+#if NeedFunctionPrototypes
+ char * /* path */
+#endif
+);
+#ifdef XINPUT
+extern CONFIG_RETURN_TYPE xf86ConfigExtendedInputSection(
+#if NeedFunctionPrototypes
+ LexPtr pval
+#endif
+);
+#endif
+
+#ifdef XKB
+extern char *XkbInitialMap;
+#endif
+
+#define DIR_FILE "/fonts.dir"
+
+/*
+ * xf86GetPathElem --
+ * Extract a single element from the font path string starting at
+ * pnt. The font path element will be returned, and pnt will be
+ * updated to point to the start of the next element, or set to
+ * NULL if there are no more.
+ */
+char *
+xf86GetPathElem(pnt)
+ char **pnt;
+{
+ char *p1;
+
+ p1 = *pnt;
+ *pnt = index(*pnt, ',');
+ if (*pnt != NULL) {
+ **pnt = '\0';
+ *pnt += 1;
+ }
+ return(p1);
+}
+
+/*
+ * StrToUL --
+ *
+ * A portable, but restricted, version of strtoul(). It only understands
+ * hex, octal, and decimal. But it's good enough for our needs.
+ */
+unsigned int StrToUL(str)
+char *str;
+{
+ int base = 10;
+ char *p = str;
+ unsigned int tot = 0;
+
+ if (*p == '0') {
+ p++;
+ if (*p == 'x') {
+ p++;
+ base = 16;
+ }
+ else
+ base = 8;
+ }
+ while (*p) {
+ if ((*p >= '0') && (*p <= ((base == 8)?'7':'9'))) {
+ tot = tot * base + (*p - '0');
+ }
+ else if ((base == 16) && (*p >= 'a') && (*p <= 'f')) {
+ tot = tot * base + 10 + (*p - 'a');
+ }
+ else if ((base == 16) && (*p >= 'A') && (*p <= 'F')) {
+ tot = tot * base + 10 + (*p - 'A');
+ }
+ else {
+ return(tot);
+ }
+ p++;
+ }
+ return(tot);
+}
+
+/*
+ * xf86ValidateFontPath --
+ * Validates the user-specified font path. Each element that
+ * begins with a '/' is checked to make sure the directory exists.
+ * If the directory exists, the existence of a file named 'fonts.dir'
+ * is checked. If either check fails, an error is printed and the
+ * element is removed from the font path.
+ */
+#define CHECK_TYPE(mode, type) ((S_IFMT & (mode)) == (type))
+static char *
+xf86ValidateFontPath(path)
+ char *path;
+{
+ char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem;
+ struct stat stat_buf;
+ int flag;
+ int dirlen;
+
+ tmp_path = (char *)Xcalloc(strlen(path)+1);
+ out_pnt = tmp_path;
+ path_elem = NULL;
+ next = path;
+ while (next != NULL) {
+ path_elem = xf86GetPathElem(&next);
+#ifndef __EMX__
+ if (*path_elem == '/') {
+ dir_elem = (char *)Xcalloc(strlen(path_elem) + 1);
+ if ((p1 = strchr(path_elem, ':')) != 0)
+#else
+ /* OS/2 must prepend X11ROOT */
+ if (*path_elem == '/') {
+ path_elem = (char*)__XOS2RedirRoot(path_elem);
+ dir_elem = (char*)xcalloc(1, strlen(path_elem) + 1);
+ if (p1 = strchr(path_elem+2, ':'))
+#endif
+ dirlen = p1 - path_elem;
+ else
+ dirlen = strlen(path_elem);
+ strncpy(dir_elem, path_elem, dirlen);
+ dir_elem[dirlen] = '\0';
+ flag = stat(dir_elem, &stat_buf);
+ if (flag == 0)
+ if (!CHECK_TYPE(stat_buf.st_mode, S_IFDIR))
+ flag = -1;
+ if (flag != 0) {
+ ErrorF("Warning: The directory \"%s\" does not exist.\n", dir_elem);
+ ErrorF(" Entry deleted from font path.\n");
+ continue;
+ }
+ else {
+ p1 = (char *)xalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
+ strcpy(p1, dir_elem);
+ strcat(p1, DIR_FILE);
+ flag = stat(p1, &stat_buf);
+ if (flag == 0)
+ if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG))
+ flag = -1;
+#ifndef __EMX__
+ xfree(p1);
+#endif
+ if (flag != 0) {
+ ErrorF("Warning: 'fonts.dir' not found (or not valid) in \"%s\".\n",
+ dir_elem);
+ ErrorF(" Entry deleted from font path.\n");
+ ErrorF(" (Run 'mkfontdir' on \"%s\").\n", dir_elem);
+ continue;
+ }
+ }
+ xfree(dir_elem);
+ }
+
+ /*
+ * Either an OK directory, or a font server name. So add it to
+ * the path.
+ */
+ if (out_pnt != tmp_path)
+ *out_pnt++ = ',';
+ strcat(out_pnt, path_elem);
+ out_pnt += strlen(path_elem);
+ }
+ return(tmp_path);
+}
+
+/*
+ * xf86GetToken --
+ * Read next Token form the config file. Handle the global variable
+ * pushToken.
+ */
+int
+xf86GetToken(tab)
+ SymTabRec tab[];
+{
+ int c, i;
+
+ /*
+ * First check whether pushToken has a different value than LOCK_TOKEN.
+ * In this case rBuf[] contains a valid STRING/TOKEN/NUMBER. But in the other
+ * case the next token must be read from the input.
+ */
+ if (pushToken == EOF) return(EOF);
+ else if (pushToken == LOCK_TOKEN)
+ {
+
+ c = configBuf[configPos];
+
+ /*
+ * Get start of next Token. EOF is handled, whitespaces & comments are
+ * skipped.
+ */
+ do {
+ if (!c) {
+ if (fgets(configBuf,CONFIG_BUF_LEN-1,configFile) == NULL)
+ {
+ return( pushToken = EOF );
+ }
+ configLineNo++;
+ configStart = configPos = 0;
+ }
+#ifndef __EMX__
+ while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n'));
+#else
+ while (((c=configBuf[configPos++])==' ') || ( c=='\t') || ( c=='\n')
+ || (c=='\r'));
+#endif
+ if (c == '#') c = '\0';
+ } while (!c);
+
+ /* GJA -- handle '-' and ','
+ * Be careful: "-hsync" is a keyword.
+ */
+ if ( (c == ',') && !isalpha(configBuf[configPos]) ) {
+ configStart = configPos; return COMMA;
+ } else if ( (c == '-') && !isalpha(configBuf[configPos]) ) {
+ configStart = configPos; return DASH;
+ }
+
+ configStart = configPos;
+ /*
+ * Numbers are returned immediately ...
+ */
+ if (isdigit(c))
+ {
+ int base;
+
+ if (c == '0')
+ if ((configBuf[configPos] == 'x') ||
+ (configBuf[configPos] == 'X'))
+ base = 16;
+ else
+ base = 8;
+ else
+ base = 10;
+
+ configRBuf[0] = c; i = 1;
+ while (isdigit(c = configBuf[configPos++]) ||
+ (c == '.') || (c == 'x') ||
+ ((base == 16) && (((c >= 'a') && (c <= 'f')) ||
+ ((c >= 'A') && (c <= 'F')))))
+ configRBuf[i++] = c;
+ configPos--; /* GJA -- one too far */
+ configRBuf[i] = '\0';
+ val.num = StrToUL(configRBuf);
+ val.realnum = atof(configRBuf);
+ return(NUMBER);
+ }
+
+ /*
+ * All Strings START with a \" ...
+ */
+ else if (c == '\"')
+ {
+ i = -1;
+ do {
+ configRBuf[++i] = (c = configBuf[configPos++]);
+#ifndef __EMX__
+ } while ((c != '\"') && (c != '\n') && (c != '\0'));
+#else
+ } while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0'));
+#endif
+ configRBuf[i] = '\0';
+ val.str = (char *)xalloc(strlen(configRBuf) + 1);
+ strcpy(val.str, configRBuf); /* private copy ! */
+ return(STRING);
+ }
+
+ /*
+ * ... and now we MUST have a valid token. The search is
+ * handled later along with the pushed tokens.
+ */
+ else
+ {
+ configRBuf[0] = c;
+ i = 0;
+ do {
+ configRBuf[++i] = (c = configBuf[configPos++]);;
+#ifndef __EMX__
+ } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\0'));
+#else
+ } while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && (c != '\0') );
+#endif
+ configRBuf[i] = '\0'; i=0;
+ }
+
+ }
+ else
+ {
+
+ /*
+ * Here we deal with pushed tokens. Reinitialize pushToken again. If
+ * the pushed token was NUMBER || STRING return them again ...
+ */
+ int temp = pushToken;
+ pushToken = LOCK_TOKEN;
+
+ if (temp == COMMA || temp == DASH) return(temp);
+ if (temp == NUMBER || temp == STRING) return(temp);
+ }
+
+ /*
+ * Joop, at last we have to lookup the token ...
+ */
+ if (tab)
+ {
+ i = 0;
+ while (tab[i].token != -1)
+ if (StrCaseCmp(configRBuf,tab[i].name) == 0)
+ return(tab[i].token);
+ else
+ i++;
+ }
+
+ return(ERROR_TOKEN); /* Error catcher */
+}
+
+/*
+ * xf86GetToken --
+ * Lookup a string if it is actually a token in disguise.
+ */
+static int
+getStringToken(tab)
+ SymTabRec tab[];
+{
+ int i;
+
+ for ( i = 0 ; tab[i].token != -1 ; i++ ) {
+ if ( ! StrCaseCmp(tab[i].name,val.str) ) return tab[i].token;
+ }
+ return(ERROR_TOKEN);
+}
+
+/*
+ * getScreenIndex --
+ * Given the screen token, returns the index in xf86Screens, or -1 if
+ * the screen type is not applicable to this server.
+ */
+static int
+getScreenIndex(token)
+ int token;
+{
+ int i;
+
+ for (i = 0; xf86ScreenNames[i] >= 0 && xf86ScreenNames[i] != token; i++)
+ ;
+ if (xf86ScreenNames[i] < 0)
+ return(-1);
+ else
+ return(i);
+}
+
+/*
+ * validateGraphicsToken --
+ * If token is a graphics token, check it is in the list of validTokens
+ * XXXX This needs modifying to work as it did with the old format
+ */
+static Bool
+validateGraphicsToken(validTokens, token)
+ int *validTokens;
+ int token;
+{
+ int i;
+
+ for (i = 0; ScreenTab[i].token >= 0 && ScreenTab[i].token != token; i++)
+ ;
+ if (ScreenTab[i].token < 0)
+ return(FALSE); /* Not a graphics token */
+
+ for (i = 0; validTokens[i] >= 0 && validTokens[i] != token; i++)
+ ;
+ return(validTokens[i] >= 0);
+}
+
+/*
+ * xf86TokenToString --
+ * returns the string corresponding to token
+ */
+char *
+xf86TokenToString(table, token)
+ SymTabPtr table;
+ int token;
+{
+ int i;
+
+ for (i = 0; table[i].token >= 0 && table[i].token != token; i++)
+ ;
+ if (table[i].token < 0)
+ return("unknown");
+ else
+ return(table[i].name);
+}
+
+/*
+ * xf86StringToToken --
+ * returns the string corresponding to token
+ */
+int
+xf86StringToToken(table, string)
+ SymTabPtr table;
+ char *string;
+{
+ int i;
+
+ for (i = 0; table[i].token >= 0 && StrCaseCmp(string, table[i].name); i++)
+ ;
+ return(table[i].token);
+}
+
+/*
+ * xf86ConfigError --
+ * Print a READABLE ErrorMessage!!! All information that is
+ * interesting is printed. Even a pointer to the erroneous place is
+ * printed. Maybe our e-mail will be less :-)
+ */
+#ifdef XF86SETUP
+int
+XF86SetupXF86ConfigError(msg)
+#else
+void
+xf86ConfigError(msg)
+#endif
+ char *msg;
+{
+ int i,j;
+
+ ErrorF( "\nConfig Error: %s:%d\n\n%s", configPath, configLineNo, configBuf);
+ for (i = 1, j = 1; i < configStart; i++, j++)
+ if (configBuf[i-1] != '\t')
+ ErrorF(" ");
+ else
+ do
+ ErrorF(" ");
+ while (((j++)%8) != 0);
+ for (i = configStart; i <= configPos; i++) ErrorF("^");
+ ErrorF("\n%s\n", msg);
+#ifdef NEED_RETURN_VALUE
+ return RET_ERROR;
+#else
+ exit(-1); /* simple exit ... */
+#endif
+}
+
+#ifndef XF86SETUP
+void
+xf86DeleteMode(infoptr, dispmp)
+ScrnInfoPtr infoptr;
+DisplayModePtr dispmp;
+{
+ if(infoptr->modes == dispmp)
+ infoptr->modes = dispmp->next;
+
+ if(dispmp->next == dispmp)
+ FatalError("No valid modes found.\n");
+
+ ErrorF("%s %s: Removing mode \"%s\" from list of valid modes.\n",
+ XCONFIG_PROBED, infoptr->name, dispmp->name);
+ dispmp->prev->next = dispmp->next;
+ dispmp->next->prev = dispmp->prev;
+
+ xfree(dispmp->name);
+ xfree(dispmp);
+}
+#endif
+
+/*
+ * findConfigFile --
+ * Locate the XF86Config file. Abort if not found.
+ */
+#ifndef XF86SETUP
+static
+#endif
+CONFIG_RETURN_TYPE
+findConfigFile(filename, fp)
+ char *filename;
+ FILE **fp;
+{
+#define configFile (*fp)
+#define MAXPTRIES 6
+ char *home = NULL;
+ char *xconfig = NULL;
+ char *xwinhome = NULL;
+ char *configPaths[MAXPTRIES];
+ int pcount = 0, idx;
+
+ /*
+ * First open if necessary the config file.
+ * If the -xf86config flag was used, use the name supplied there (root only).
+ * If $XF86CONFIG is a pathname, use it as the name of the config file (root)
+ * If $XF86CONFIG is set but doesn't contain a '/', append it to 'XF86Config'
+ * and search the standard places (root only).
+ * If $XF86CONFIG is not set, just search the standard places.
+ */
+ while (!configFile) {
+
+ /*
+ * configPaths[0] is used as a buffer for -xf86config
+ * and $XF86CONFIG if it contains a path
+ * configPaths[1...MAXPTRIES-1] is used to store the paths of each of
+ * the other attempts
+ */
+ for (pcount = idx = 0; idx < MAXPTRIES; idx++)
+ configPaths[idx] = NULL;
+
+ /*
+ * First check if the -xf86config option was used.
+ */
+ configPaths[pcount] = (char *)xalloc(PATH_MAX);
+#ifndef __EMX__
+ if (getuid() == 0 && xf86ConfigFile[0])
+#else
+ if (xf86ConfigFile[0])
+#endif
+ {
+ strcpy(configPaths[pcount], xf86ConfigFile);
+ if ((configFile = fopen(configPaths[pcount], "r")) != 0)
+ break;
+ else
+ FatalError(
+ "Cannot read file \"%s\" specified by the -xf86config flag\n",
+ configPaths[pcount]);
+ }
+ /*
+ * Check if XF86CONFIG is set.
+ */
+#ifndef __EMX__
+ if (getuid() == 0
+ && (xconfig = getenv("XF86CONFIG")) != 0
+ && index(xconfig, '/'))
+#else
+ /* no root available, and filenames start with drive letter */
+ if ((xconfig = getenv("XF86CONFIG")) != 0
+ && isalpha(xconfig[0])
+ && xconfig[1]==':')
+#endif
+ {
+ strcpy(configPaths[pcount], xconfig);
+ if ((configFile = fopen(configPaths[pcount], "r")) != 0)
+ break;
+ else
+ FatalError(
+ "Cannot read file \"%s\" specified by XF86CONFIG variable\n",
+ configPaths[pcount]);
+ }
+
+#ifndef __EMX__
+ /*
+ * ~/XF86Config ...
+ */
+ if (getuid() == 0 && (home = getenv("HOME"))) {
+ configPaths[++pcount] = (char *)xalloc(PATH_MAX);
+ strcpy(configPaths[pcount],home);
+ strcat(configPaths[pcount],"/XF86Config");
+ if (xconfig) strcat(configPaths[pcount],xconfig);
+ if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;
+ }
+
+ /*
+ * /etc/XF86Config
+ */
+ configPaths[++pcount] = (char *)xalloc(PATH_MAX);
+ strcpy(configPaths[pcount], "/etc/XF86Config");
+ if (xconfig) strcat(configPaths[pcount],xconfig);
+ if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;
+
+ /*
+ * $(LIBDIR)/XF86Config.<hostname>
+ */
+
+ configPaths[++pcount] = (char *)xalloc(PATH_MAX);
+ if (getuid() == 0 && (xwinhome = getenv("XWINHOME")) != NULL)
+ sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome);
+ else
+ strcpy(configPaths[pcount], SERVER_CONFIG_FILE);
+ if (getuid() == 0 && xconfig) strcat(configPaths[pcount],xconfig);
+ strcat(configPaths[pcount], ".");
+#ifdef AMOEBA
+ {
+ extern char *XServerHostName;
+
+ strcat(configPaths[pcount], XServerHostName);
+ }
+#else
+ gethostname(configPaths[pcount]+strlen(configPaths[pcount]),
+ MAXHOSTNAMELEN);
+#endif
+ if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;
+#endif /* !__EMX__ */
+
+ /*
+ * $(LIBDIR)/XF86Config
+ */
+ configPaths[++pcount] = (char *)xalloc(PATH_MAX);
+#ifndef __EMX__
+ if (getuid() == 0 && xwinhome)
+ sprintf(configPaths[pcount], "%s/lib/X11/XF86Config", xwinhome);
+ else
+ strcpy(configPaths[pcount], SERVER_CONFIG_FILE);
+ if (getuid() == 0 && xconfig) strcat(configPaths[pcount],xconfig);
+#else
+ /* we explicitly forbid numerous config files everywhere for OS/2;
+ * users should consider them lucky to have one in a standard place
+ * and another one with the -xf86config option
+ */
+ xwinhome = getenv("X11ROOT"); /* get drive letter */
+ if (!xwinhome) FatalError("X11ROOT environment variable not set\n");
+ strcpy(configPaths[pcount], __XOS2RedirRoot("/XFree86/lib/X11/XConfig"));
+#endif
+
+ if ((configFile = fopen( configPaths[pcount], "r" )) != 0) break;
+
+ ErrorF("\nCould not find config file!\n");
+ ErrorF("- Tried:\n");
+ for (idx = 1; idx <= pcount; idx++)
+ if (configPaths[idx] != NULL)
+ ErrorF(" %s\n", configPaths[idx]);
+ FatalError("No config file found!\n%s", getuid() == 0 ? "" :
+ "Note, the X server no longer looks for XF86Config in $HOME");
+ }
+ strcpy(filename, configPaths[pcount]);
+ if (xf86Verbose) {
+ ErrorF("XF86Config: %s\n", filename);
+ ErrorF("%s stands for supplied, %s stands for probed/default values\n",
+ XCONFIG_GIVEN, XCONFIG_PROBED);
+ }
+ for (idx = 0; idx <= pcount; idx++)
+ if (configPaths[idx] != NULL)
+ xfree(configPaths[idx]);
+#undef configFile
+#undef MAXPTRIES
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static DisplayModePtr pNew, pLast;
+static Bool graphFound = FALSE;
+
+/*
+ * xf86GetNearestClock --
+ * Find closest clock to given frequency (in kHz). This assumes the
+ * number of clocks is greater than zero.
+ */
+int
+xf86GetNearestClock(Screen, Frequency)
+ ScrnInfoPtr Screen;
+ int Frequency;
+{
+ int NearestClock = 0;
+ int MinimumGap = abs(Frequency - Screen->clock[0]);
+ int i;
+ for (i = 1; i < Screen->clocks; i++)
+ {
+ int Gap = abs(Frequency - Screen->clock[i]);
+ if (Gap < MinimumGap)
+ {
+ MinimumGap = Gap;
+ NearestClock = i;
+ }
+ }
+ return NearestClock;
+}
+
+/*
+ * xf86Config --
+ * Fill some internal structure with userdefined setups. Many internal
+ * Structs are initialized. The drivers are selected and initialized.
+ * if (! vtopen), XF86Config is read, but devices are not probed.
+ * if (vtopen), devices are probed (and modes resolved).
+ * The vtopen argument was added so that XF86Config information could be
+ * made available before the VT is opened.
+ */
+CONFIG_RETURN_TYPE
+xf86Config (vtopen)
+ int vtopen;
+{
+ int token;
+ int i, j;
+#if defined(SYSV) || defined(linux)
+ int xcpipe[2];
+#endif
+#ifdef XINPUT
+ LocalDevicePtr local;
+#endif
+
+ if (!vtopen)
+ {
+
+ OFLG_ZERO(&GenericXF86ConfigFlag);
+ configBuf = (char*)xalloc(CONFIG_BUF_LEN);
+ configRBuf = (char*)xalloc(CONFIG_BUF_LEN);
+ configPath = (char*)xalloc(PATH_MAX);
+
+ configBuf[0] = '\0'; /* sanity ... */
+
+ /*
+ * Read the XF86Config file with the real uid to avoid security problems
+ *
+ * For SYSV we fork, and send the data back to the parent through a pipe
+ */
+#if defined(SYSV) || defined(linux)
+ if (getuid() != 0) {
+ if (pipe(xcpipe))
+ FatalError("Pipe failed (%s)\n", strerror(errno));
+ switch (fork()) {
+ case -1:
+ FatalError("Fork failed (%s)\n", strerror(errno));
+ break;
+ case 0: /* child */
+ close(xcpipe[0]);
+ setuid(getuid());
+ HANDLE_RETURN(findConfigFile(configPath, &configFile));
+ {
+ unsigned char pbuf[CONFIG_BUF_LEN];
+ int nbytes;
+
+ /* Pass the filename back as the first line */
+ strcat(configPath, "\n");
+ if (write(xcpipe[1], configPath, strlen(configPath)) < 0)
+ FatalError("Child error writing to pipe (%s)\n", strerror(errno));
+ while ((nbytes = fread(pbuf, 1, CONFIG_BUF_LEN, configFile)) > 0)
+ if (write(xcpipe[1], pbuf, nbytes) < 0)
+ FatalError("Child error writing to pipe (%s)\n", strerror(errno));
+ }
+ close(xcpipe[1]);
+ fclose(configFile);
+ exit(0);
+ break;
+ default: /* parent */
+ close(xcpipe[1]);
+ configFile = (FILE *)fdopen(xcpipe[0], "r");
+ if (fgets(configPath, PATH_MAX, configFile) == NULL)
+ FatalError("Error reading config file\n");
+ configPath[strlen(configPath) - 1] = '\0';
+ }
+ }
+ else {
+ HANDLE_RETURN(findConfigFile(configPath, &configFile));
+ }
+#else /* ! (SYSV || linux) */
+ {
+#ifndef __EMX__ /* in OS/2 we don't care about uids */
+ int real_uid = getuid();
+
+ if (real_uid) {
+#ifdef MINIX
+ setuid(getuid());
+#else
+#if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
+ setruid(0);
+#endif
+ seteuid(real_uid);
+#endif /* MINIX */
+ }
+#endif /* __EMX__ */
+
+ HANDLE_RETURN(findConfigFile(configPath, &configFile));
+#if defined(MINIX) || defined(__EMX__)
+ /* no need to restore the uid to root */
+#else
+ if (real_uid) {
+ seteuid(0);
+#if !defined(SVR4) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
+ setruid(real_uid);
+#endif
+ }
+#endif /* MINIX */
+ }
+#endif /* SYSV || linux */
+ xf86Info.sharedMonitor = FALSE;
+ xf86Info.kbdProc = NULL;
+ xf86Info.notrapSignals = FALSE;
+ xf86Info.caughtSignal = FALSE;
+
+ /* Allocate mouse device */
+#if defined(XINPUT) && !defined(XF86SETUP)
+ local = mouse_assoc.device_allocate();
+ xf86Info.mouseLocal = (pointer) local;
+ xf86Info.mouseDev = (MouseDevPtr) local->private;
+ xf86Info.mouseDev->mseProc = NULL;
+#else
+ xf86Info.mouseDev = (MouseDevPtr) Xcalloc(sizeof(MouseDevRec));
+#endif
+
+ while ((token = xf86GetToken(TopLevelTab)) != EOF) {
+ switch(token) {
+ case SECTION:
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("section name string expected");
+ if ( StrCaseCmp(val.str, "files") == 0 ) {
+ HANDLE_RETURN(configFilesSection());
+ } else if ( StrCaseCmp(val.str, "serverflags") == 0 ) {
+ HANDLE_RETURN(configServerFlagsSection());
+ } else if ( StrCaseCmp(val.str, "keyboard") == 0 ) {
+ HANDLE_RETURN(configKeyboardSection());
+ } else if ( StrCaseCmp(val.str, "pointer") == 0 ) {
+ HANDLE_RETURN(configPointerSection(xf86Info.mouseDev, ENDSECTION, NULL));
+ } else if ( StrCaseCmp(val.str, "device") == 0 ) {
+ HANDLE_RETURN(configDeviceSection());
+ } else if ( StrCaseCmp(val.str, "monitor") == 0 ) {
+ HANDLE_RETURN(configMonitorSection());
+ } else if ( StrCaseCmp(val.str, "screen") == 0 ) {
+ HANDLE_RETURN(configScreenSection());
+#ifdef XINPUT
+ } else if ( StrCaseCmp(val.str, "xinput") == 0 ) {
+ HANDLE_RETURN(xf86ConfigExtendedInputSection(&val));
+#endif
+ } else if ( StrCaseCmp(val.str, "module") == 0 ) {
+ HANDLE_RETURN(configDynamicModuleSection());
+ } else {
+ xf86ConfigError("not a recognized section name");
+ }
+ break;
+ }
+ }
+
+ fclose(configFile);
+ xfree(configBuf);
+ xfree(configRBuf);
+ xfree(configPath);
+
+ /* These aren't needed after the XF86Config file has been read */
+#ifndef XF86SETUP
+ if (monitor_list)
+ xfree(monitor_list);
+ if (device_list)
+ xfree(device_list);
+#endif
+ if (modulePath)
+ xfree(modulePath);
+
+#if defined(SYSV) || defined(linux)
+ if (getuid() != 0) {
+ /* Wait for the child */
+ wait(NULL);
+ }
+#endif
+
+ /* Try XF86Config FontPath first */
+ if (!xf86fpFlag)
+ if (fontPath) {
+ char *f = xf86ValidateFontPath(fontPath);
+ if (*f)
+ defaultFontPath = f;
+ else
+ ErrorF(
+ "Warning: FontPath is completely invalid. Using compiled-in default.\n"
+ );
+ xfree(fontPath);
+ fontPath = (char *)NULL;
+ }
+ else
+ ErrorF("Warning: No FontPath specified, using compiled-in default.\n");
+ else /* Use fontpath specified with '-fp' */
+ {
+ OFLG_CLR (XCONFIG_FONTPATH, &GenericXF86ConfigFlag);
+ if (fontPath)
+ {
+ xfree(fontPath);
+ fontPath = (char *)NULL;
+ }
+ }
+ if (!fontPath) {
+ /* xf86ValidateFontPath will write into it's arg, but defaultFontPath
+ could be static, so we make a copy. */
+ char *f = (char *)xalloc(strlen(defaultFontPath) + 1);
+ f[0] = '\0';
+ strcpy (f, defaultFontPath);
+ defaultFontPath = xf86ValidateFontPath(f);
+ xfree(f);
+ }
+ else
+ xfree(fontPath);
+
+ /* If defaultFontPath is still empty, exit here */
+
+ if (! *defaultFontPath)
+ FatalError("No valid FontPath could be found\n");
+ if (xf86Verbose)
+ ErrorF("%s FontPath set to \"%s\"\n",
+ OFLG_ISSET(XCONFIG_FONTPATH, &GenericXF86ConfigFlag) ? XCONFIG_GIVEN :
+ XCONFIG_PROBED, defaultFontPath);
+
+ if (!xf86Info.kbdProc)
+ FatalError("You must specify a keyboard in XF86Config");
+ if (!xf86Info.mouseDev->mseProc)
+ FatalError("You must specify a mouse in XF86Config");
+
+ if (!graphFound)
+ {
+ Bool needcomma = FALSE;
+
+ ErrorF("\nYou must provide a \"Screen\" section in XF86Config for at\n");
+ ErrorF("least one of the following graphics drivers: ");
+ for (i = 0; i < xf86MaxScreens; i++)
+ {
+ if (xf86Screens[i])
+ {
+ ErrorF("%s%s", needcomma ? ", " : "",
+ xf86TokenToString(DriverTab, xf86ScreenNames[i]));
+ needcomma = TRUE;
+ }
+ }
+ ErrorF("\n");
+ FatalError("No configured graphics devices");
+ }
+ }
+#ifndef XF86SETUP
+ else /* if (vtopen) */
+ {
+ /*
+ * Probe all configured screens for letting them resolve their modes
+ */
+ xf86ScreensOpen = TRUE;
+ for ( i=0; i < xf86MaxScreens; i++ )
+ if (xf86Screens[i] && xf86Screens[i]->configured &&
+ (xf86Screens[i]->configured = (xf86Screens[i]->Probe)())){
+ /* if driver doesn't report error do it here */
+ if(xf86DCGetToken(xf86Screens[i]->DCConfig,NULL,DeviceTab) != EOF){
+ xf86DCConfigError("Unknown device section keyword");
+ FatalError("\n");
+ }
+ if(xf86Screens[i]->DCOptions){
+ xf86DCGetOption(xf86Screens[i]->DCOptions,NULL);
+ FatalError("\n");
+ }
+ xf86InitViewport(xf86Screens[i]);
+ }
+
+ /*
+ * Now sort the drivers to match the order of the ScreenNumbers
+ * requested by the user. (sorry, slow bubble-sort here)
+ * Note, that after this sorting the first driver that is not configured
+ * can be used as last-mark for all configured ones.
+ */
+ for ( j = 0; j < xf86MaxScreens-1; j++)
+ for ( i=0; i < xf86MaxScreens-j-1; i++ )
+ if (!xf86Screens[i] || !xf86Screens[i]->configured ||
+ (xf86Screens[i+1] && xf86Screens[i+1]->configured &&
+ (xf86Screens[i+1]->tmpIndex < xf86Screens[i]->tmpIndex)))
+ {
+ ScrnInfoPtr temp = xf86Screens[i+1];
+ xf86Screens[i+1] = xf86Screens[i];
+ xf86Screens[i] = temp;
+ }
+
+ }
+#endif /* XF86SETUP */
+
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static char* prependRoot(char *pathname)
+{
+#ifndef __EMX__
+ return pathname;
+#else
+ /* XXXX caveat: multiple path components in line */
+ return (char*)__XOS2RedirRoot(pathname);
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configFilesSection()
+{
+ int token;
+ int i, j;
+ int k, l;
+ char *str;
+
+ while ((token = xf86GetToken(FilesTab)) != ENDSECTION) {
+ switch (token) {
+ case FONTPATH:
+ OFLG_SET(XCONFIG_FONTPATH,&GenericXF86ConfigFlag);
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("Font path component expected");
+ j = FALSE;
+ str = prependRoot(val.str);
+ if (fontPath == NULL)
+ {
+ fontPath = (char *)xalloc(1);
+ fontPath[0] = '\0';
+ i = strlen(str) + 1;
+ }
+ else
+ {
+ i = strlen(fontPath) + strlen(str) + 1;
+ if (fontPath[strlen(fontPath)-1] != ',')
+ {
+ i++;
+ j = TRUE;
+ }
+ }
+ fontPath = (char *)xrealloc(fontPath, i);
+ if (j)
+ strcat(fontPath, ",");
+
+ strcat(fontPath, str);
+ xfree(val.str);
+ break;
+
+ case RGBPATH:
+ OFLG_SET(XCONFIG_RGBPATH, &GenericXF86ConfigFlag);
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("RGB path expected");
+ if (!xf86coFlag)
+ rgbPath = val.str;
+ break;
+
+ case MODULEPATH:
+ OFLG_SET(XCONFIG_MODULEPATH, &GenericXF86ConfigFlag);
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("Module path expected");
+ l = FALSE;
+ str = prependRoot(val.str);
+ if (modulePath == NULL) {
+ modulePath = (char *)xalloc(1);
+ modulePath[0] = '\0';
+ k = strlen(str) + 1;
+ }
+ else
+ {
+ k = strlen(modulePath) + strlen(str) + 1;
+ if (modulePath[strlen(modulePath)-1] != ',')
+ {
+ k++;
+ l = TRUE;
+ }
+ }
+ modulePath = (char *)xrealloc(modulePath, k);
+ if (l)
+ strcat(modulePath, ",");
+
+ strcat(modulePath, str);
+ xfree(val.str);
+ break;
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+ default:
+ xf86ConfigError("File section keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configServerFlagsSection()
+{
+ int token;
+
+ xf86Info.dontZap = FALSE;
+ xf86Info.dontZoom = FALSE;
+
+ while ((token = xf86GetToken(ServerFlagsTab)) != ENDSECTION) {
+ switch (token) {
+ case NOTRAPSIGNALS:
+ xf86Info.notrapSignals=TRUE;
+ break;
+ case DONTZAP:
+ xf86Info.dontZap = TRUE;
+ break;
+ case DONTZOOM:
+ xf86Info.dontZoom = TRUE;
+ break;
+#ifdef XF86VIDMODE
+ case DISABLEVIDMODE:
+ xf86VidModeEnabled = FALSE;
+ break;
+ case ALLOWNONLOCAL:
+ xf86VidModeAllowNonLocal = TRUE;
+ break;
+#endif
+#ifdef XF86MISC
+ case DISABLEMODINDEV:
+ xf86MiscModInDevEnabled = FALSE;
+ break;
+ case MODINDEVALLOWNONLOCAL:
+ xf86MiscModInDevAllowNonLocal = TRUE;
+ break;
+#endif
+ case ALLOWMOUSEOPENFAIL:
+ xf86AllowMouseOpenFail = TRUE;
+ break;
+ case PCIPROBE1:
+ xf86PCIFlags = PCIProbe1;
+ break;
+ case PCIPROBE2:
+ xf86PCIFlags = PCIProbe2;
+ break;
+ case PCIFORCECONFIG1:
+ xf86PCIFlags = PCIForceConfig1;
+ break;
+ case PCIFORCECONFIG2:
+ xf86PCIFlags = PCIForceConfig2;
+ break;
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+ default:
+ xf86ConfigError("Server flags section keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configKeyboardSection()
+{
+ int token, ntoken;
+
+ /* Initialize defaults */
+ xf86Info.serverNumLock = FALSE;
+ xf86Info.xleds = 0L;
+ xf86Info.kbdDelay = 500;
+ xf86Info.kbdRate = 30;
+ xf86Info.kbdProc = (DeviceProc)0;
+ xf86Info.vtinit = NULL;
+ xf86Info.vtSysreq = VT_SYSREQ_DEFAULT;
+ xf86Info.specialKeyMap = (int *)xalloc((RIGHTCTL - LEFTALT + 1) *
+ sizeof(int));
+ xf86Info.specialKeyMap[LEFTALT - LEFTALT] = KM_META;
+ xf86Info.specialKeyMap[RIGHTALT - LEFTALT] = KM_META;
+ xf86Info.specialKeyMap[SCROLLLOCK - LEFTALT] = KM_COMPOSE;
+ xf86Info.specialKeyMap[RIGHTCTL - LEFTALT] = KM_CONTROL;
+#if defined(SVR4) && defined(i386) && !defined(PC98)
+ xf86Info.panix106 = FALSE;
+#endif
+#ifdef XKB
+ xf86Info.xkbkeymap = NULL;
+ xf86Info.xkbtypes = "default";
+#ifndef PC98
+ xf86Info.xkbcompat = "default";
+ xf86Info.xkbkeycodes = "xfree86";
+ xf86Info.xkbsymbols = "us(pc101)";
+ xf86Info.xkbgeometry = "pc";
+#else
+ xf86Info.xkbcompat = "pc98";
+ xf86Info.xkbkeycodes = "xfree98";
+ xf86Info.xkbsymbols = "nec/jp(pc98)";
+ xf86Info.xkbgeometry = "nec(pc98)";
+#endif
+ xf86Info.xkbcomponents_specified = False;
+ xf86Info.xkbrules = "xfree86";
+ xf86Info.xkbmodel = NULL;
+ xf86Info.xkblayout = NULL;
+ xf86Info.xkbvariant = NULL;
+ xf86Info.xkboptions = NULL;
+#endif
+
+ while ((token = xf86GetToken(KeyboardTab)) != ENDSECTION) {
+ switch (token) {
+ case KPROTOCOL:
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("Keyboard protocol name expected");
+ if ( StrCaseCmp(val.str,"standard") == 0 ) {
+ xf86Info.kbdProc = xf86KbdProc;
+#ifdef AMOEBA
+ xf86Info.kbdEvents = NULL;
+#else
+ xf86Info.kbdEvents = xf86KbdEvents;
+#endif
+ } else if ( StrCaseCmp(val.str,"xqueue") == 0 ) {
+#ifdef XQUEUE
+ xf86Info.kbdProc = xf86XqueKbdProc;
+ xf86Info.kbdEvents = xf86XqueEvents;
+ xf86Info.mouseDev->xqueSema = 0;
+ if (xf86Verbose)
+ ErrorF("%s Xqueue selected for keyboard input\n",
+ XCONFIG_GIVEN);
+#endif
+ } else {
+ xf86ConfigError("Not a valid keyboard protocol name");
+ }
+ break;
+ case AUTOREPEAT:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Autorepeat delay expected");
+ xf86Info.kbdDelay = val.num;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Autorepeat rate expected");
+ xf86Info.kbdRate = val.num;
+ break;
+ case SERVERNUM:
+ xf86Info.serverNumLock = TRUE;
+ break;
+
+ case XLEDS:
+ while ((token= xf86GetToken(NULL)) == NUMBER)
+ xf86Info.xleds |= 1L << (val.num-1);
+ pushToken = token;
+ break;
+ case LEFTALT:
+ case RIGHTALT:
+ case SCROLLLOCK:
+ case RIGHTCTL:
+ ntoken = xf86GetToken(KeyMapTab);
+ if ((ntoken == EOF) || (ntoken == STRING) || (ntoken == NUMBER))
+ xf86ConfigError("KeyMap type token expected");
+ else {
+ switch(ntoken) {
+ case KM_META:
+ case KM_COMPOSE:
+ case KM_MODESHIFT:
+ case KM_MODELOCK:
+ case KM_SCROLLLOCK:
+ case KM_CONTROL:
+ xf86Info.specialKeyMap[token - LEFTALT] = ntoken;
+ break;
+ default:
+ xf86ConfigError("Illegal KeyMap type");
+ break;
+ }
+ }
+ break;
+ case VTINIT:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("VTInit string expected");
+ xf86Info.vtinit = val.str;
+ if (xf86Verbose)
+ ErrorF("%s VTInit: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case VTSYSREQ:
+#ifdef USE_VT_SYSREQ
+ xf86Info.vtSysreq = TRUE;
+ if (xf86Verbose && !VT_SYSREQ_DEFAULT)
+ ErrorF("%s VTSysReq enabled\n", XCONFIG_GIVEN);
+#else
+ xf86ConfigError("VTSysReq not supported on this OS");
+#endif
+ break;
+
+#ifdef XKB
+ case XKBDISABLE:
+ noXkbExtension = TRUE;
+ if (xf86Verbose)
+ ErrorF("%s XKB: disabled\n", XCONFIG_GIVEN);
+ break;
+
+ case XKBKEYMAP:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBKeymap string expected");
+ xf86Info.xkbkeymap = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: keymap: \"%s\" (overrides other XKB settings)\n",
+ XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBCOMPAT:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBCompat string expected");
+ xf86Info.xkbcompat = val.str;
+ xf86Info.xkbcomponents_specified = True;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: compat: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBTYPES:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBTypes string expected");
+ xf86Info.xkbtypes = val.str;
+ xf86Info.xkbcomponents_specified = True;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: types: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBKEYCODES:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBKeycodes string expected");
+ xf86Info.xkbkeycodes = val.str;
+ xf86Info.xkbcomponents_specified = True;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: keycodes: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBGEOMETRY:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBGeometry string expected");
+ xf86Info.xkbgeometry = val.str;
+ xf86Info.xkbcomponents_specified = True;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: geometry: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBSYMBOLS:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBSymbols string expected");
+ xf86Info.xkbsymbols = val.str;
+ xf86Info.xkbcomponents_specified = True;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: symbols: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBRULES:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBRules string expected");
+ xf86Info.xkbrules = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: rules: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBMODEL:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBModel string expected");
+ xf86Info.xkbmodel = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: model: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBLAYOUT:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBLayout string expected");
+ xf86Info.xkblayout = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: layout: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBVARIANT:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBVariant string expected");
+ xf86Info.xkbvariant = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: variant: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+
+ case XKBOPTIONS:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("XKBOptions string expected");
+ xf86Info.xkboptions = val.str;
+ if (xf86Verbose && !XkbInitialMap)
+ ErrorF("%s XKB: options: \"%s\"\n", XCONFIG_GIVEN, val.str);
+ break;
+#endif
+#if defined(SVR4) && defined(i386) && !defined(PC98)
+ case PANIX106:
+ xf86Info.panix106 = TRUE;
+ if (xf86Verbose)
+ ErrorF("%s PANIX106: enabled\n", XCONFIG_GIVEN);
+ break;
+#endif
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+
+ default:
+ xf86ConfigError("Keyboard section keyword expected");
+ break;
+ }
+ }
+ if (xf86Info.kbdProc == (DeviceProc)0)
+ {
+ xf86ConfigError("No keyboard device given");
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+CONFIG_RETURN_TYPE
+configPointerSection(MouseDevPtr mouse_dev,
+ int end_tag,
+ char **devicename) /* used by extended device */
+{
+ int token;
+ int mtoken;
+ int i;
+ char *mouseType = "unknown";
+
+ /* Set defaults */
+ mouse_dev->baudRate = 1200;
+ mouse_dev->oldBaudRate = -1;
+ mouse_dev->sampleRate = 0;
+ mouse_dev->resolution = 0;
+ mouse_dev->buttons = MSE_DFLTBUTTONS;
+ mouse_dev->emulate3Buttons = FALSE;
+ mouse_dev->emulate3Timeout = 50;
+ mouse_dev->chordMiddle = FALSE;
+ mouse_dev->mouseFlags = 0;
+ mouse_dev->mseProc = (DeviceProc)0;
+ mouse_dev->mseDevice = NULL;
+ mouse_dev->mseType = -1;
+ mouse_dev->mseModel = 0;
+ mouse_dev->negativeZ = 0;
+ mouse_dev->positiveZ = 0;
+
+ while ((token = xf86GetToken(PointerTab)) != end_tag) {
+ switch (token) {
+
+ case PROTOCOL:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mouse name expected");
+#if defined(USE_OSMOUSE) || defined(OSMOUSE_ONLY)
+ if ( StrCaseCmp(val.str,"osmouse") == 0 ) {
+ if (xf86Verbose)
+ ErrorF("%s OsMouse selected for mouse input\n", XCONFIG_GIVEN);
+ /*
+ * allow an option to be passed to the OsMouse routines
+ */
+ if ((i = xf86GetToken(NULL)) != ERROR_TOKEN)
+ xf86OsMouseOption(i, (pointer) &val);
+ else
+ pushToken = i;
+ mouse_dev->mseProc = xf86OsMouseProc;
+ mouse_dev->mseEvents = (void(*)(MouseDevPtr))xf86OsMouseEvents;
+ break;
+ }
+#endif
+#ifdef XQUEUE
+ if ( StrCaseCmp(val.str,"xqueue") == 0 ) {
+ mouse_dev->mseProc = xf86XqueMseProc;
+ mouse_dev->mseEvents = (void(*)(MouseDevPtr))xf86XqueEvents;
+ mouse_dev->xqueSema = 0;
+ if (xf86Verbose)
+ ErrorF("%s Xqueue selected for mouse input\n",
+ XCONFIG_GIVEN);
+ break;
+ }
+#endif
+
+#ifndef OSMOUSE_ONLY
+#if defined(MACH) || defined(AMOEBA)
+ mouseType = (char *) xalloc (strlen (val.str) + 1);
+ strcpy (mouseType, val.str);
+#else
+ mouseType = (char *)strdup(val.str); /* GJA -- should we free this? */
+#endif
+ mtoken = getStringToken(MouseTab); /* Which mouse? */
+#ifdef AMOEBA
+ mouse_dev->mseProc = xf86MseProc;
+ mouse_dev->mseEvents = NULL;
+#else
+ mouse_dev->mseProc = xf86MseProc;
+ mouse_dev->mseEvents = xf86MseEvents;
+#endif
+ mouse_dev->mseType = mtoken - MICROSOFT;
+ if (!xf86MouseSupported(mouse_dev->mseType))
+ {
+ xf86ConfigError("Mouse type not supported by this OS");
+ }
+#else /* OSMOUSE_ONLY */
+ xf86ConfigError("Mouse type not supported by this OS");
+#endif /* OSMOUSE_ONLY */
+
+#ifdef MACH386
+ /* Don't need to specify the device for MACH -- should always be this */
+ mouse_dev->mseDevice = "/dev/mouse";
+#endif
+ break;
+#ifndef OSMOUSE_ONLY
+ case PDEVICE:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mouse device expected");
+ mouse_dev->mseDevice = val.str;
+ break;
+ case BAUDRATE:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Baudrate expected");
+ if (mouse_dev->mseType + MICROSOFT == LOGIMAN)
+ {
+ /*
+ * XXXX This should be extended to other mouse types -- most
+ * support only 1200. Should also disallow baudrate for bus mice
+ */
+ /* Moan if illegal baud rate! [CHRIS-211092] */
+ if ((val.num != 1200) && (val.num != 9600))
+ xf86ConfigError("Only 1200 or 9600 Baud are supported by MouseMan");
+ }
+ else if (val.num%1200 != 0 || val.num < 1200 || val.num > 9600)
+ xf86ConfigError("Baud rate must be one of 1200, 2400, 4800, or 9600");
+ mouse_dev->baudRate = val.num;
+ break;
+
+ case SAMPLERATE:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Sample rate expected");
+#if 0
+ if (mouse_dev->mseType + MICROSOFT == LOGIMAN)
+ {
+ /* XXXX Most mice don't allow this */
+ /* Moan about illegal sample rate! [CHRIS-211092] */
+ xf86ConfigError("Selection of sample rate is not supported by MouseMan");
+ }
+#endif
+ mouse_dev->sampleRate = val.num;
+ break;
+
+ case PRESOLUTION:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Resolution expected");
+ if (val.num <= 0)
+ xf86ConfigError("Resolution must be a positive value");
+ mouse_dev->resolution = val.num;
+ break;
+#endif /* OSMOUSE_ONLY */
+ case EMULATE3:
+ if (mouse_dev->chordMiddle)
+ xf86ConfigError("Can't use Emulate3Buttons with ChordMiddle");
+ mouse_dev->emulate3Buttons = TRUE;
+ break;
+
+ case EM3TIMEOUT:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("3 button emulation timeout expected");
+ mouse_dev->emulate3Timeout = val.num;
+ break;
+
+#ifndef OSMOUSE_ONLY
+ case CHORDMIDDLE:
+ if (mouse_dev->mseType + MICROSOFT == MICROSOFT ||
+ mouse_dev->mseType + MICROSOFT == LOGIMAN)
+ {
+ if (mouse_dev->emulate3Buttons)
+ xf86ConfigError("Can't use ChordMiddle with Emulate3Buttons");
+ mouse_dev->chordMiddle = TRUE;
+ }
+ else
+ xf86ConfigError("ChordMiddle is only supported for Microsoft and MouseMan");
+ break;
+
+ case CLEARDTR:
+#ifdef CLEARDTR_SUPPORT
+ if (mouse_dev->mseType + MICROSOFT == MOUSESYS)
+ mouse_dev->mouseFlags |= MF_CLEAR_DTR;
+ else
+ xf86ConfigError("ClearDTR only supported for MouseSystems mouse");
+#else
+ xf86ConfigError("ClearDTR not supported on this OS");
+#endif
+ break;
+ case CLEARRTS:
+#ifdef CLEARDTR_SUPPORT
+ if (mouse_dev->mseType + MICROSOFT == MOUSESYS)
+ mouse_dev->mouseFlags |= MF_CLEAR_RTS;
+ else
+ xf86ConfigError("ClearRTS only supported for MouseSystems mouse");
+#else
+ xf86ConfigError("ClearRTS not supported on this OS");
+#endif
+ break;
+#endif /* OSMOUSE_ONLY */
+
+ case DEVICE_NAME:
+ if (!devicename) /* not called for an extended device */
+ xf86ConfigError("Pointer section keyword expected");
+
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("Option string expected");
+ *devicename = strdup(val.str);
+ break;
+
+#ifndef XF86SETUP
+#ifdef XINPUT
+ case ALWAYSCORE:
+ xf86AlwaysCore(mouse_dev->local, TRUE);
+ break;
+#endif
+#endif
+
+ case ZAXISMAPPING:
+ switch (xf86GetToken(ZMapTab)) {
+ case NUMBER:
+ if (val.num <= 0 || val.num > MSE_MAXBUTTONS)
+ xf86ConfigError("Button number (1..12) expected");
+ mouse_dev->negativeZ = 1 << (val.num - 1);
+ if (xf86GetToken(NULL) != NUMBER ||
+ val.num <= 0 || val.num > MSE_MAXBUTTONS)
+ xf86ConfigError("Button number (1..12) expected");
+ mouse_dev->positiveZ = 1 << (val.num - 1);
+ break;
+ case XAXIS:
+ mouse_dev->negativeZ = mouse_dev->positiveZ = MSE_MAPTOX;
+ break;
+ case YAXIS:
+ mouse_dev->negativeZ = mouse_dev->positiveZ = MSE_MAPTOY;
+ break;
+ default:
+ xf86ConfigError("Button number (1..12), X or Y expected");
+ }
+ break;
+
+ case PBUTTONS:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Number of buttons (1..12) expected");
+ if (val.num <= 0 || val.num > MSE_MAXBUTTONS)
+ xf86ConfigError("Number of buttons must be a positive value (1..12)");
+ mouse_dev->buttons = val.num;
+ break;
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+
+ default:
+ xf86ConfigError("Pointer section keyword expected");
+ break;
+ }
+
+ }
+ /* Print log and make sanity checks */
+
+ if (mouse_dev->mseProc == (DeviceProc)0)
+ {
+ xf86ConfigError("No mouse protocol given");
+ }
+
+ /*
+ * if mseProc is set and mseType isn't, then using Xqueue or OSmouse.
+ * Otherwise, a mouse device is required.
+ */
+ if (mouse_dev->mseType >= 0 && !mouse_dev->mseDevice)
+ {
+ xf86ConfigError("No mouse device given");
+ }
+
+ switch (mouse_dev->negativeZ) {
+ case 0: /* none */
+ case MSE_MAPTOX:
+ case MSE_MAPTOY:
+ break;
+ default: /* buttons */
+ for (i = 0; mouse_dev->negativeZ != (1 << i); ++i)
+ ;
+ if (i + 1 > mouse_dev->buttons)
+ mouse_dev->buttons = i + 1;
+ for (i = 0; mouse_dev->positiveZ != (1 << i); ++i)
+ ;
+ if (i + 1 > mouse_dev->buttons)
+ mouse_dev->buttons = i + 1;
+ break;
+ }
+
+ if (xf86Verbose && mouse_dev->mseType >= 0)
+ {
+ Bool formatFlag = FALSE;
+ ErrorF("%s Mouse: type: %s, device: %s",
+ XCONFIG_GIVEN, mouseType, mouse_dev->mseDevice);
+ if (mouse_dev->mseType != P_BM
+ && mouse_dev->mseType != P_PS2
+ && mouse_dev->mseType != P_IMPS2
+ && mouse_dev->mseType != P_THINKINGPS2
+ && mouse_dev->mseType != P_MMANPLUSPS2
+ && mouse_dev->mseType != P_GLIDEPOINTPS2
+ && mouse_dev->mseType != P_NETPS2
+ && mouse_dev->mseType != P_NETSCROLLPS2
+ && mouse_dev->mseType != P_SYSMOUSE)
+ {
+ formatFlag = TRUE;
+ ErrorF(", baudrate: %d", mouse_dev->baudRate);
+ }
+ if (mouse_dev->sampleRate)
+ {
+ ErrorF(formatFlag ? "\n%s Mouse: samplerate: %d" : "%ssamplerate: %d",
+ formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->sampleRate);
+ formatFlag = !formatFlag;
+ }
+ if (mouse_dev->resolution)
+ {
+ ErrorF(formatFlag ? "\n%s Mouse: resolution: %d" : "%sresolution: %d",
+ formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->resolution);
+ formatFlag = !formatFlag;
+ }
+ ErrorF(formatFlag ? "\n%s Mouse: buttons: %d" : "%sbuttons: %d",
+ formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->buttons);
+ formatFlag = !formatFlag;
+ if (mouse_dev->emulate3Buttons)
+ {
+ ErrorF(formatFlag ? "\n%s Mouse: 3 button emulation (timeout: %dms)" :
+ "%s3 button emulation (timeout: %dms)",
+ formatFlag ? XCONFIG_GIVEN : ", ", mouse_dev->emulate3Timeout);
+ formatFlag = !formatFlag;
+ }
+ if (mouse_dev->chordMiddle)
+ ErrorF(formatFlag ? "\n%s Mouse: Chorded middle button" :
+ "%sChorded middle button",
+ formatFlag ? XCONFIG_GIVEN : ", ");
+ ErrorF("\n");
+
+ switch (mouse_dev->negativeZ) {
+ case 0: /* none */
+ break;
+ case MSE_MAPTOX:
+ ErrorF("%s Mouse: zaxismapping: X\n", XCONFIG_GIVEN);
+ break;
+ case MSE_MAPTOY:
+ ErrorF("%s Mouse: zaxismapping: Y\n", XCONFIG_GIVEN);
+ break;
+ default: /* buttons */
+ for (i = 0; mouse_dev->negativeZ != (1 << i); ++i)
+ ;
+ ErrorF("%s Mouse: zaxismapping: (-)%d", XCONFIG_GIVEN, i + 1);
+ for (i = 0; mouse_dev->positiveZ != (1 << i); ++i)
+ ;
+ ErrorF(" (+)%d\n", i + 1);
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configDeviceSection()
+{
+ int token;
+ int i;
+ GDevPtr devp;
+
+ /* Allocate one more device */
+ if ( device_list == NULL ) {
+ device_list = (GDevPtr) xalloc(sizeof(GDevRec));
+ } else {
+ device_list = (GDevPtr) xrealloc(device_list,
+ (n_devices+1) * sizeof(GDevRec));
+ }
+ devp = &(device_list[n_devices]); /* Point to the last device */
+ n_devices++;
+
+ /* Pre-init the newly created device */
+ devp->identifier = NULL;
+ devp->board = NULL;
+ devp->vendor = NULL;
+ devp->chipset = NULL;
+ devp->ramdac = NULL;
+ for (i=0; i<MAXDACSPEEDS; i++)
+ devp->dacSpeeds[i] = 0;
+ OFLG_ZERO(&(devp->options));
+ OFLG_ZERO(&(devp->xconfigFlag));
+ devp->videoRam = 0;
+ devp->speedup = SPEEDUP_DEFAULT;
+ OFLG_ZERO(&(devp->clockOptions));
+ devp->clocks = 0;
+ devp->clockprog = NULL;
+ devp->textClockValue = -1;
+ /* GJA -- We initialize the following fields to known values.
+ * If later on we find they contain different values,
+ * they might be interesting to print.
+ */
+ devp->IObase = 0;
+ devp->DACbase = 0;
+ devp->COPbase = 0;
+ devp->POSbase = 0;
+ devp->instance = 0;
+ devp->BIOSbase = 0;
+ devp->VGAbase = 0;
+ devp->MemBase = 0;
+ devp->s3Madjust = 0;
+ devp->s3Nadjust = 0;
+ devp->s3MClk = 0;
+ devp->chipID = 0;
+ devp->chipRev = 0;
+ devp->s3RefClk = 0;
+ devp->s3BlankDelay = -1;
+ devp->DCConfig = NULL;
+ devp->DCOptions = NULL;
+ devp->MemClk = 0;
+ devp->LCDClk = 0;
+
+ while ((token = xf86GetToken(DeviceTab)) != ENDSECTION) {
+ devp->DCConfig = xf86DCSaveLine(devp->DCConfig, token);
+ switch (token) {
+
+ case IDENTIFIER:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("identifier name expected");
+ devp->identifier = val.str;
+ break;
+
+ case VENDOR:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("vendor name expected");
+ devp->vendor = val.str;
+ break;
+
+ case BOARD:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("board name expected");
+ devp->board = val.str;
+ break;
+
+ case CHIPSET:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Chipset string expected");
+ devp->chipset = val.str;
+ OFLG_SET(XCONFIG_CHIPSET,&(devp->xconfigFlag));
+ break;
+
+ case RAMDAC:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("RAMDAC string expected");
+ devp->ramdac = val.str;
+ OFLG_SET(XCONFIG_RAMDAC,&(devp->xconfigFlag));
+ break;
+
+ case DACSPEED:
+ for (i=0; i<MAXDACSPEEDS; i++)
+ devp->dacSpeeds[i] = 0;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("DAC speed(s) expected");
+ else {
+ devp->dacSpeeds[0] = (int)(val.realnum * 1000.0 + 0.5);
+ for(i=1; i<MAXDACSPEEDS; i++) {
+ if (xf86GetToken(NULL) == NUMBER)
+ devp->dacSpeeds[i] = (int)(val.realnum * 1000.0 + 0.5);
+ else {
+ pushToken = token;
+ break;
+ }
+ }
+ }
+ OFLG_SET(XCONFIG_DACSPEED,&(devp->xconfigFlag));
+ break;
+
+ case CLOCKCHIP:
+ /* Only allow one Clock string */
+ if (OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions)))
+ {
+ xf86ConfigError("Only one Clock chip may be specified.");
+ break;
+ }
+ if (devp->clocks == 0)
+ {
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected");
+ i = 0;
+ while (xf86_ClockOptionTab[i].token != -1)
+ {
+ if (StrCaseCmp(val.str, xf86_ClockOptionTab[i].name) == 0)
+ {
+ OFLG_SET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions));
+ OFLG_SET(xf86_ClockOptionTab[i].token,
+ &(devp->clockOptions));
+ break;
+ }
+ i++;
+ }
+ if (xf86_ClockOptionTab[i].token == -1) {
+ xf86ConfigError("Unknown clock chip");
+ break;
+ }
+ }
+ else
+ {
+ xf86ConfigError("Clocks previously specified by value");
+ }
+ break;
+
+ case CLOCKS:
+ OFLG_SET(XCONFIG_CLOCKS,&(devp->xconfigFlag));
+ if ((token = xf86GetToken(NULL)) == STRING)
+ {
+ xf86ConfigError("Use ClockChip to specify a programmable clock");
+ break;
+ }
+ if (OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(devp->clockOptions)))
+ {
+ xf86ConfigError("Clock previously specified as programmable");
+ break;
+ }
+ for (i = devp->clocks; token == NUMBER && i < MAXCLOCKS; i++) {
+ devp->clock[i] = (int)(val.realnum * 1000.0 + 0.5);
+ token = xf86GetToken(NULL);
+ }
+
+ devp->clocks = i;
+ pushToken = token;
+ break;
+
+ case OPTION:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected");
+ i = 0;
+ while (xf86_OptionTab[i].token != -1)
+ {
+ if (StrCaseCmp(val.str, xf86_OptionTab[i].name) == 0)
+ {
+ OFLG_SET(xf86_OptionTab[i].token, &(devp->options));
+ break;
+ }
+ i++;
+ }
+ if (xf86_OptionTab[i].token == -1)
+ /*xf86ConfigError("Unknown option string");*/
+ devp->DCOptions = xf86DCOption(devp->DCOptions,val);
+ break;
+
+ case VIDEORAM:
+ OFLG_SET(XCONFIG_VIDEORAM,&(devp->xconfigFlag));
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Video RAM size expected");
+ devp->videoRam = val.num;
+ break;
+
+ case SPEEDUP:
+ OFLG_SET(XCONFIG_SPEEDUP,&(devp->xconfigFlag));
+ if ((token = xf86GetToken(NULL)) == STRING)
+ if (!strcmp(val.str,"all"))
+ devp->speedup = SPEEDUP_ALL;
+ else
+ if (!strcmp(val.str,"best"))
+ devp->speedup = SPEEDUP_BEST;
+ else
+ if (!strcmp(val.str,"none"))
+ devp->speedup = 0;
+ else
+ xf86ConfigError("Unrecognised SpeedUp option");
+ else
+ {
+ pushToken = token;
+ if ((token = xf86GetToken(NULL)) == NUMBER)
+ devp->speedup = val.num;
+ else
+ {
+ pushToken = token;
+ devp->speedup = SPEEDUP_ALL;
+ }
+ }
+ break;
+
+ case NOSPEEDUP:
+ OFLG_SET(XCONFIG_SPEEDUP,&(devp->xconfigFlag));
+ devp->speedup = 0;
+ break;
+
+ case CLOCKPROG:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("ClockProg string expected");
+ if (val.str[0] != '/')
+ FatalError("Full pathname must be given for ClockProg \"%s\"\n",
+ val.str);
+ if (access(val.str, X_OK) < 0)
+ {
+ if (access(val.str, F_OK) < 0)
+ FatalError("ClockProg \"%s\" does not exist\n", val.str);
+ else
+ FatalError("ClockProg \"%s\" is not executable\n", val.str);
+ }
+ {
+ struct stat stat_buf;
+ stat(val.str, &stat_buf);
+ if (!CHECK_TYPE(stat_buf.st_mode, S_IFREG))
+ FatalError("ClockProg \"%s\" is not a regular file\n", val.str);
+ }
+ devp->clockprog = val.str;
+ if (xf86GetToken(NULL) == NUMBER)
+ {
+ devp->textClockValue = (int)(val.realnum * 1000.0 + 0.5);
+ }
+ else
+ {
+ pushToken = token;
+ }
+ break;
+
+ case BIOSBASE:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("BIOS base address expected");
+ devp->BIOSbase = val.num;
+ OFLG_SET(XCONFIG_BIOSBASE, &(devp->xconfigFlag));
+ break;
+
+ case MEMBASE:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Memory base address expected");
+ devp->MemBase = val.num;
+ OFLG_SET(XCONFIG_MEMBASE, &(devp->xconfigFlag));
+ break;
+
+ case IOBASE:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Direct access register I/O base address expected");
+ devp->IObase = val.num;
+ OFLG_SET(XCONFIG_IOBASE, &(devp->xconfigFlag));
+ break;
+
+ case DACBASE:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("DAC base I/O address expected");
+ devp->DACbase = val.num;
+ OFLG_SET(XCONFIG_DACBASE, &(devp->xconfigFlag));
+ break;
+
+ case COPBASE:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Coprocessor base memory address expected");
+ devp->COPbase = val.num;
+ OFLG_SET(XCONFIG_COPBASE, &(devp->xconfigFlag));
+ break;
+
+ case POSBASE:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("POS base address expected");
+ devp->POSbase = val.num;
+ OFLG_SET(XCONFIG_POSBASE, &(devp->xconfigFlag));
+ break;
+
+ case INSTANCE:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Video adapter instance number expected");
+ devp->instance = val.num;
+ OFLG_SET(XCONFIG_INSTANCE, &(devp->xconfigFlag));
+ break;
+
+ case S3MNADJUST:
+ if ((token = xf86GetToken(NULL)) == DASH) { /* negative number */
+ token = xf86GetToken(NULL);
+ val.num = -val.num;
+ }
+ if (token != NUMBER || val.num<-31 || val.num>31)
+ xf86ConfigError("M adjust (max. 31) expected");
+ devp->s3Madjust = val.num;
+
+ if ((token = xf86GetToken(NULL)) == DASH) { /* negative number */
+ token = xf86GetToken(NULL);
+ val.num = -val.num;
+ }
+ if (token == NUMBER) {
+ if (val.num<-255 || val.num>255)
+ xf86ConfigError("N adjust (max. 255) expected");
+ else
+ devp->s3Nadjust = val.num;
+ }
+ else pushToken = token;
+ break;
+
+ case S3MCLK:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("MCLK value in MHz expected");
+ devp->s3MClk = (int)(val.realnum * 1000.0 + 0.5);
+ break;
+
+ case MEMCLOCK:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Memory Clock value in MHz expected");
+ devp->MemClk = (int)(val.realnum * 1000.0 + 0.5);
+ OFLG_SET(XCONFIG_MEMCLOCK,&(devp->xconfigFlag));
+ break;
+
+ case LCDCLOCK:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("LCD Clock value in MHz expected");
+ devp->LCDClk = (int)(val.realnum * 1000.0 + 0.5);
+ OFLG_SET(XCONFIG_LCDCLOCK,&(devp->xconfigFlag));
+ break;
+
+ case CHIPID:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("ChipID expected");
+ devp->chipID = val.num;
+ break;
+
+ case CHIPREV:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("ChipRev expected");
+ devp->chipRev = val.num;
+ break;
+
+ case VGABASEADDR:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("VGA aperature base address expected");
+ devp->VGAbase = val.num;
+ OFLG_SET(XCONFIG_VGABASE, &(devp->xconfigFlag));
+ break;
+
+ case S3REFCLK:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("RefCLK value in MHz expected");
+ devp->s3RefClk = (int)(val.realnum * 1000.0 + 0.5);
+ break;
+
+ case S3BLANKDELAY:
+ if (xf86GetToken(NULL) != NUMBER || val.num>7)
+ xf86ConfigError("number(s) 0..7 expected");
+ devp->s3BlankDelay = val.num;
+ if ((token=xf86GetToken(NULL)) == NUMBER) {
+ if (val.num>7) xf86ConfigError("number2 0..7 expected");
+ devp->s3BlankDelay |= val.num<<4;
+ }
+ else pushToken = token;
+ break;
+
+ case TEXTCLOCKFRQ:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Text clock expected");
+ devp->textClockValue = (int)(val.realnum * 1000.0 + 0.5);
+ break;
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+ default:
+ if(DCerr)
+ xf86ConfigError("Device section keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configMonitorSection()
+{
+ int token;
+ int i;
+ MonPtr monp;
+ float multiplier;
+
+ /* Allocate one more monitor */
+ if ( monitor_list == NULL ) {
+ monitor_list = (MonPtr) xalloc(sizeof(MonRec));
+ } else {
+ monitor_list = (MonPtr) xrealloc(monitor_list,
+ (n_monitors+1) * sizeof(MonRec));
+ }
+ monp = &(monitor_list[n_monitors]); /* Point to the new monitor */
+ monp->Modes = 0;
+ monp->Last = 0;
+ monp->n_hsync = 0;
+ monp->n_vrefresh = 0;
+ n_monitors++;
+
+ while ((token = xf86GetToken(MonitorTab)) != ENDSECTION) {
+ switch (token) {
+ case IDENTIFIER:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("identifier name expected");
+ monp->id = val.str;
+ break;
+ case VENDOR:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("vendor name expected");
+ monp->vendor = val.str;
+ break;
+ case MODEL:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("model name expected");
+ monp->model = val.str;
+ break;
+ case MODE:
+ readVerboseMode(monp);
+ break;
+ case MODELINE:
+ token = xf86GetToken(NULL);
+ pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec));
+
+ if (monp->Last)
+ monp->Last->next = pNew;
+ else
+ monp->Modes = pNew;
+
+ if (token == STRING)
+ {
+ pNew->name = val.str;
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ FatalError("Dotclock expected");
+ }
+ else if (monp->Last)
+ {
+#if defined(MACH) || defined(AMOEBA)
+ pNew->name = (char *) xalloc (strlen (monp->Last->name) + 1);
+ strcpy (pNew->name, monp->Last->name);
+#else
+ pNew->name = (char *)strdup(monp->Last->name);
+#endif
+ }
+ else
+ xf86ConfigError("Mode name expected");
+
+ pNew->next = NULL;
+ pNew->prev = NULL;
+ pNew->Flags = 0;
+ pNew->Clock = (int)(val.realnum * 1000.0 + 0.5);
+ pNew->CrtcHAdjusted = FALSE;
+ pNew->CrtcVAdjusted = FALSE;
+ pNew->CrtcHSkew = pNew->HSkew = 0;
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHDisplay = pNew->HDisplay = val.num;
+ else xf86ConfigError("Horizontal display expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHSyncStart = pNew->HSyncStart = val.num;
+ else xf86ConfigError("Horizontal sync start expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHSyncEnd = pNew->HSyncEnd = val.num;
+ else xf86ConfigError("Horizontal sync end expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHTotal = pNew->HTotal = val.num;
+ else xf86ConfigError("Horizontal total expected");
+
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVDisplay = pNew->VDisplay = val.num;
+ else xf86ConfigError("Vertical display expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVSyncStart = pNew->VSyncStart = val.num;
+ else xf86ConfigError("Vertical sync start expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVSyncEnd = pNew->VSyncEnd = val.num;
+ else xf86ConfigError("Vertical sync end expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVTotal = pNew->VTotal = val.num;
+ else xf86ConfigError("Vertical total expected");
+
+ token = xf86GetToken(TimingTab);
+ while ( (token == TT_INTERLACE) || (token == TT_PHSYNC) ||
+ (token == TT_NHSYNC) || (token == TT_PVSYNC) ||
+ (token == TT_NVSYNC) || (token == TT_CSYNC) ||
+ (token == TT_PCSYNC) || (token == TT_NCSYNC) ||
+ (token == TT_DBLSCAN) || (token == TT_HSKEW) )
+ {
+ switch(token) {
+
+ case TT_INTERLACE: pNew->Flags |= V_INTERLACE; break;
+ case TT_PHSYNC: pNew->Flags |= V_PHSYNC; break;
+ case TT_NHSYNC: pNew->Flags |= V_NHSYNC; break;
+ case TT_PVSYNC: pNew->Flags |= V_PVSYNC; break;
+ case TT_NVSYNC: pNew->Flags |= V_NVSYNC; break;
+ case TT_CSYNC: pNew->Flags |= V_CSYNC; break;
+ case TT_PCSYNC: pNew->Flags |= V_PCSYNC; break;
+ case TT_NCSYNC: pNew->Flags |= V_NCSYNC; break;
+ case TT_DBLSCAN: pNew->Flags |= V_DBLSCAN; break;
+ case TT_HSKEW:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Horizontal skew expected");
+ pNew->CrtcHSkew = pNew->HSkew = val.num;
+ pNew->Flags |= V_HSKEW;
+ break;
+ default:
+ xf86ConfigError("bug found in config reader"); break;
+ }
+ token = xf86GetToken(TimingTab);
+ }
+ pushToken = token;
+ monp->Last = pNew; /* GJA */
+ break;
+ case BANDWIDTH:
+ /* This should be completely removed at some point */
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Bandwidth number expected");
+#if 0
+ monp->bandwidth = val.realnum;
+ /* Handle optional scaler */
+ token = xf86GetToken(UnitTab);
+ switch ( token ) {
+ case HRZ: multiplier = 1.0e-6; break;
+ case KHZ: multiplier = 1.0e-3; break;
+ case MHZ: multiplier = 1.0; break;
+ default: multiplier = 1.0; pushToken = token;
+ }
+ monp->bandwidth *= multiplier;
+#endif
+ break;
+ case HORIZSYNC:
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Horizontal sync value expected");
+ monp->hsync[monp->n_hsync].lo = val.realnum;
+ if ((token = xf86GetToken(NULL)) == DASH) {
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Upperbound for horizontal sync value expected");
+ monp->hsync[monp->n_hsync].hi = val.realnum;
+ } else {
+ pushToken = token;
+ monp->hsync[monp->n_hsync].hi = monp->hsync[monp->n_hsync].lo;
+ }
+ monp->n_hsync++;
+ while ( (token = xf86GetToken(NULL)) == COMMA ) {
+ if ( monp->n_hsync == MAX_HSYNC )
+ xf86ConfigError("Sorry. Too many horizontal sync intervals.");
+
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Horizontal sync value expected");
+ monp->hsync[monp->n_hsync].lo = val.realnum;
+ if ((token = xf86GetToken(NULL)) == DASH) {
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Upperbound for horizontal sync value expected");
+ monp->hsync[monp->n_hsync].hi = val.realnum;
+ } else {
+ pushToken = token;
+ monp->hsync[monp->n_hsync].hi = monp->hsync[monp->n_hsync].lo;
+ }
+ monp->n_hsync++;
+ }
+ pushToken = token;
+ /* Handle optional scaler */
+ token = xf86GetToken(UnitTab);
+ switch ( token ) {
+ case HRZ: multiplier = 1.0e-3; break;
+ case KHZ: multiplier = 1.0; break;
+ case MHZ: multiplier = 1.0e3; break;
+ default: multiplier = 1.0; pushToken = token;
+ }
+ for ( i = 0 ; i < monp->n_hsync ; i++ ) {
+ monp->hsync[i].hi *= multiplier;
+ monp->hsync[i].lo *= multiplier;
+ }
+ break;
+ case VERTREFRESH:
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Vertical refresh value expected");
+ monp->vrefresh[monp->n_vrefresh].lo = val.realnum;
+ if ((token = xf86GetToken(NULL)) == DASH) {
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Upperbound for vertical refresh value expected");
+ monp->vrefresh[monp->n_vrefresh].hi = val.realnum;
+ } else {
+ monp->vrefresh[monp->n_vrefresh].hi =
+ monp->vrefresh[monp->n_vrefresh].lo;
+ pushToken = token;
+ }
+ monp->n_vrefresh++;
+ while ( (token = xf86GetToken(NULL)) == COMMA ) {
+ if ( monp->n_vrefresh == MAX_HSYNC )
+ xf86ConfigError("Sorry. Too many vertical refresh intervals.");
+
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Vertical refresh value expected");
+ monp->vrefresh[monp->n_vrefresh].lo = val.realnum;
+ if ((token = xf86GetToken(NULL)) == DASH) {
+ if ((token = xf86GetToken(NULL)) != NUMBER)
+ xf86ConfigError("Upperbound for vertical refresh value expected");
+ monp->vrefresh[monp->n_vrefresh].hi = val.realnum;
+ } else {
+ monp->vrefresh[monp->n_vrefresh].hi =
+ monp->vrefresh[monp->n_vrefresh].lo;
+ pushToken = token;
+ }
+ monp->n_vrefresh++;
+ }
+ pushToken = token;
+ /* Handle optional scaler */
+ token = xf86GetToken(UnitTab);
+ switch ( token ) {
+ case HRZ: multiplier = 1.0; break;
+ case KHZ: multiplier = 1.0e3; break;
+ case MHZ: multiplier = 1.0e6; break;
+ default: multiplier = 1.0; pushToken = token;
+ }
+ for ( i = 0 ; i < monp->n_vrefresh ; i++ ) {
+ monp->vrefresh[i].hi *= multiplier;
+ monp->vrefresh[i].lo *= multiplier;
+ }
+ break;
+ case GAMMA: {
+ char *msg = "gamma correction value(s) expected\n either one value or three r/g/b values with 0.1 <= gamma <= 10";
+ if ((token = xf86GetToken(NULL)) != NUMBER || val.realnum<0.1 || val.realnum>10)
+ xf86ConfigError(msg);
+ else {
+ xf86rGamma = xf86gGamma = xf86bGamma = 1.0 / val.realnum;
+ if ((token = xf86GetToken(NULL)) == NUMBER) {
+ if (val.realnum<0.1 || val.realnum>10) xf86ConfigError(msg);
+ else {
+ xf86gGamma = 1.0 / val.realnum;
+ if ((token = xf86GetToken(NULL)) != NUMBER || val.realnum<0.1 || val.realnum>10)
+ xf86ConfigError(msg);
+ else {
+ xf86bGamma = 1.0 / val.realnum;
+ }
+ }
+ }
+ else pushToken = token;
+ }
+ break;
+ }
+ case EOF:
+ FatalError("Unexpected EOF. Missing EndSection?");
+ break; /* :-) */
+
+ default:
+ xf86ConfigError("Monitor section keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configDynamicModuleSection()
+{
+ int token;
+
+ while ((token = xf86GetToken(ModuleTab)) != ENDSECTION) {
+ switch (token) {
+ case LOAD:
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("Dynamic module expected");
+ else {
+#ifdef DYNAMIC_MODULE
+ if (!modulePath) {
+ static Bool firstTime = TRUE;
+
+ modulePath = (char*)Xcalloc(strlen(DEFAULT_MODULE_PATH)+1);
+ strcpy(modulePath, DEFAULT_MODULE_PATH);
+
+ if (xf86Verbose && firstTime) {
+ ErrorF("%s no ModulePath specified using default: %s\n",
+ XCONFIG_PROBED, DEFAULT_MODULE_PATH);
+ firstTime = FALSE;
+ }
+ }
+ xf86LoadModule(val.str, modulePath);
+#else
+ ErrorF("Dynamic modules not supported. \"%s\" not loaded\n",
+ val.str);
+#endif
+ }
+ break;
+
+ case EOF:
+ FatalError("Unexpected EOF. Missing EndSection?");
+ break; /* :-) */
+
+ default:
+ xf86ConfigError("Module section keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+readVerboseMode(monp)
+MonPtr monp;
+{
+ int token, token2;
+ int had_dotclock = 0, had_htimings = 0, had_vtimings = 0;
+
+ pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec));
+ pNew->next = NULL;
+ pNew->prev = NULL;
+ pNew->Flags = 0;
+ pNew->HDisplay = pNew->VDisplay = 0; /* Uninitialized */
+ pNew->CrtcHAdjusted = pNew->CrtcVAdjusted = FALSE;
+ pNew->CrtcHSkew = pNew->HSkew = 0;
+
+ if (monp->Last)
+ monp->Last->next = pNew;
+ else
+ monp->Modes = pNew;
+ monp->Last = pNew;
+
+ if ( xf86GetToken(NULL) != STRING ) {
+ FatalError("Mode name expected");
+ }
+ pNew->name = val.str;
+ while ((token = xf86GetToken(ModeTab)) != ENDMODE) {
+ switch (token) {
+ case DOTCLOCK:
+ if ((token = xf86GetToken(NULL)) != NUMBER) {
+ FatalError("Dotclock expected");
+ }
+ pNew->Clock = (int)(val.realnum * 1000.0 + 0.5);
+ had_dotclock = 1;
+ break;
+ case HTIMINGS:
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHDisplay = pNew->HDisplay = val.num;
+ else xf86ConfigError("Horizontal display expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHSyncStart = pNew->HSyncStart = val.num;
+ else xf86ConfigError("Horizontal sync start expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHSyncEnd = pNew->HSyncEnd = val.num;
+ else xf86ConfigError("Horizontal sync end expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcHTotal = pNew->HTotal = val.num;
+ else xf86ConfigError("Horizontal total expected");
+ had_htimings = 1;
+ break;
+ case VTIMINGS:
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVDisplay = pNew->VDisplay = val.num;
+ else xf86ConfigError("Vertical display expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVSyncStart = pNew->VSyncStart = val.num;
+ else xf86ConfigError("Vertical sync start expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVSyncEnd = pNew->VSyncEnd = val.num;
+ else xf86ConfigError("Vertical sync end expected");
+
+ if (xf86GetToken(NULL) == NUMBER)
+ pNew->CrtcVTotal = pNew->VTotal = val.num;
+ else xf86ConfigError("Vertical total expected");
+ had_vtimings = 1;
+ break;
+ case FLAGS:
+ token = xf86GetToken(NULL);
+ if (token != STRING)
+ xf86ConfigError("Flag string expected. Note: flags must be in \"\"");
+ while ( token == STRING ) {
+ token2 = getStringToken(TimingTab);
+ switch(token2) {
+ case TT_INTERLACE: pNew->Flags |= V_INTERLACE; break;
+ case TT_PHSYNC: pNew->Flags |= V_PHSYNC; break;
+ case TT_NHSYNC: pNew->Flags |= V_NHSYNC; break;
+ case TT_PVSYNC: pNew->Flags |= V_PVSYNC; break;
+ case TT_NVSYNC: pNew->Flags |= V_NVSYNC; break;
+ case TT_CSYNC: pNew->Flags |= V_CSYNC; break;
+ case TT_PCSYNC: pNew->Flags |= V_PCSYNC; break;
+ case TT_NCSYNC: pNew->Flags |= V_NCSYNC; break;
+ case TT_DBLSCAN: pNew->Flags |= V_DBLSCAN; break;
+ default:
+ xf86ConfigError("Unknown flag string"); break;
+ }
+ token = xf86GetToken(NULL);
+ }
+ pushToken = token;
+ break;
+ case HSKEW:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Horizontal skew expected");
+ pNew->Flags |= V_HSKEW;
+ pNew->CrtcHSkew = pNew->HSkew = val.num;
+ break;
+ }
+ }
+ if ( !had_dotclock ) xf86ConfigError("the dotclock is missing");
+ if ( !had_htimings ) xf86ConfigError("the horizontal timings are missing");
+ if ( !had_vtimings ) xf86ConfigError("the vertical timings are missing");
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static Bool dummy;
+
+#ifdef XF86SETUP
+int xf86setup_scrn_ndisps[8];
+DispPtr xf86setup_scrn_displays[8];
+#endif
+
+static CONFIG_RETURN_TYPE
+configScreenSection()
+{
+ int i, j;
+ int driverno;
+ int had_monitor = 0, had_device = 0;
+ int dispIndex = 0;
+ int numDisps = 0;
+ DispPtr dispList = NULL;
+ DispPtr dispp;
+
+ int token;
+ ScrnInfoPtr screen = NULL;
+ int textClockValue = -1;
+
+ token = xf86GetToken(ScreenTab);
+ if ( token != DRIVER )
+ xf86ConfigError("The screen section must begin with the 'driver' line");
+
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Driver name expected");
+ driverno = getStringToken(DriverTab);
+ switch ( driverno ) {
+ case SVGA:
+ case VGA2:
+ case MONO:
+ case VGA16:
+ case ACCEL:
+ case FBDEV:
+ break;
+ default:
+ xf86ConfigError("Not a recognized driver name");
+ }
+ scr_index = getScreenIndex(driverno);
+
+ dummy = scr_index < 0 || !xf86Screens[scr_index];
+ if (dummy)
+ screen = (ScrnInfoPtr)xalloc(sizeof(ScrnInfoRec));
+ else
+ {
+ screen = xf86Screens[scr_index];
+ screen->configured = TRUE;
+ screen->tmpIndex = screenno++;
+ screen->scrnIndex = scr_index; /* scrnIndex must not be changed */
+ screen->frameX0 = -1;
+ screen->frameY0 = -1;
+ screen->virtualX = -1;
+ screen->virtualY = -1;
+ screen->defaultVisual = -1;
+ screen->modes = NULL;
+ screen->width = 240;
+ screen->height = 180;
+ screen->bankedMono = FALSE;
+ screen->textclock = -1;
+ screen->blackColour.red = 0;
+ screen->blackColour.green = 0;
+ screen->blackColour.blue = 0;
+ screen->whiteColour.red = 0x3F;
+ screen->whiteColour.green = 0x3F;
+ screen->whiteColour.blue = 0x3F;
+ }
+ screen->clocks = 0;
+
+ while ((token = xf86GetToken(ScreenTab)) != ENDSECTION) {
+ switch (token) {
+
+ case DEFBPP:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Default color depth expected");
+ screen->depth = val.num;
+ break;
+
+ case SCREENNO:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Screen number expected");
+ screen->tmpIndex = val.num;
+ break;
+
+ case SUBSECTION:
+ if ((xf86GetToken(NULL) != STRING) || (StrCaseCmp(val.str, "display") != 0)) {
+ xf86ConfigError("You must say \"Display\" here");
+ }
+ if (dispList == NULL) {
+ dispList = (DispPtr)xalloc(sizeof(DispRec));
+ } else {
+ dispList = (DispPtr)xrealloc(dispList,
+ (numDisps + 1) * sizeof(DispRec));
+ }
+ dispp = dispList + numDisps;
+ numDisps++;
+ dispp->depth = -1;
+ dispp->weight.red = dispp->weight.green = dispp->weight.blue = 0;
+ dispp->frameX0 = -1;
+ dispp->frameY0 = -1;
+ dispp->virtualX = -1;
+ dispp->virtualY = -1;
+ dispp->modes = NULL;
+ dispp->whiteColour.red = dispp->whiteColour.green =
+ dispp->whiteColour.blue = 0x3F;
+ dispp->blackColour.red = dispp->blackColour.green =
+ dispp->blackColour.blue = 0;
+ dispp->defaultVisual = -1;
+ OFLG_ZERO(&(dispp->options));
+ OFLG_ZERO(&(dispp->xconfigFlag));
+ dispp->DCOptions = NULL;
+
+ configDisplaySubsection(dispp);
+ break;
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSection?)");
+ break; /* :-) */
+
+ case MDEVICE:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Device name expected");
+ for ( i = 0 ; i < n_devices ; i++ ) {
+ if ( strcmp(device_list[i].identifier,val.str) == 0 ) {
+ /* Copy back */
+ if (!dummy && xf86Verbose) {
+ ErrorF("%s %s: Graphics device ID: \"%s\"\n",
+ XCONFIG_GIVEN, screen->name, device_list[i].identifier);
+ }
+ screen->clocks = device_list[i].clocks;
+ for ( j = 0 ; j < MAXCLOCKS ; j++ ) {
+ screen->clock[j] = device_list[i].clock[j];
+ }
+ screen->chipset = device_list[i].chipset;
+ screen->ramdac = device_list[i].ramdac;
+ for (j=0; j<MAXDACSPEEDS; j++)
+ screen->dacSpeeds[j] = device_list[i].dacSpeeds[j];
+ screen->dacSpeedBpp = 0;
+ screen->options = device_list[i].options;
+ screen->clockOptions = device_list[i].clockOptions;
+ screen->xconfigFlag = device_list[i].xconfigFlag;
+ screen->videoRam = device_list[i].videoRam;
+ screen->speedup = device_list[i].speedup;
+ screen->clockprog = device_list[i].clockprog;
+ textClockValue = device_list[i].textClockValue;
+ if (OFLG_ISSET(XCONFIG_BIOSBASE, &screen->xconfigFlag))
+ screen->BIOSbase = device_list[i].BIOSbase;
+ if (OFLG_ISSET(XCONFIG_MEMBASE, &screen->xconfigFlag))
+ screen->MemBase = device_list[i].MemBase;
+ if (OFLG_ISSET(XCONFIG_IOBASE, &screen->xconfigFlag))
+ screen->IObase = device_list[i].IObase;
+ if (OFLG_ISSET(XCONFIG_DACBASE, &screen->xconfigFlag))
+ screen->DACbase = device_list[i].DACbase;
+ if (OFLG_ISSET(XCONFIG_COPBASE, &screen->xconfigFlag))
+ screen->COPbase = device_list[i].COPbase;
+ if (OFLG_ISSET(XCONFIG_POSBASE, &screen->xconfigFlag))
+ screen->POSbase = device_list[i].POSbase;
+ if (OFLG_ISSET(XCONFIG_INSTANCE, &screen->xconfigFlag))
+ screen->instance = device_list[i].instance;
+ screen->s3Madjust = device_list[i].s3Madjust;
+ screen->s3Nadjust = device_list[i].s3Nadjust;
+ screen->s3MClk = device_list[i].s3MClk;
+ screen->MemClk = device_list[i].MemClk;
+ screen->LCDClk = device_list[i].LCDClk;
+ screen->chipID = device_list[i].chipID;
+ screen->chipRev = device_list[i].chipRev;
+ screen->s3RefClk = device_list[i].s3RefClk;
+ screen->s3BlankDelay = device_list[i].s3BlankDelay;
+ screen->textClockFreq = device_list[i].textClockValue;
+ if (OFLG_ISSET(XCONFIG_VGABASE, &screen->xconfigFlag))
+ screen->VGAbase = device_list[i].VGAbase;
+ screen->DCConfig = device_list[i].DCConfig;
+ screen->DCOptions = device_list[i].DCOptions;
+#ifdef XF86SETUP
+ screen->device = (void *) &device_list[i];
+#endif
+ break;
+ }
+ }
+ if ( i == n_devices ) { /* Exhausted the device list */
+ xf86ConfigError("Not a declared device");
+ }
+ had_device = 1;
+ break;
+
+ case MONITOR:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Monitor name expected");
+ for ( i = 0 ; i < n_monitors ; i++ ) {
+ if ( strcmp(monitor_list[i].id,val.str) == 0 ) {
+ if (!dummy && xf86Verbose) {
+ ErrorF("%s %s: Monitor ID: \"%s\"\n",
+ XCONFIG_GIVEN, screen->name, monitor_list[i].id);
+ }
+ if (!dummy) {
+ monitor_list[i].Modes = xf86PruneModes(&monitor_list[i],
+ monitor_list[i].Modes,
+ screen, FALSE);
+ screen->monitor = (MonPtr)xalloc(sizeof(MonRec));
+ memcpy(screen->monitor, &monitor_list[i], sizeof(MonRec));
+ }
+ break;
+ }
+ }
+ if ( i == n_monitors ) { /* Exhausted the monitor list */
+ xf86ConfigError("Not a declared monitor");
+ }
+ had_monitor = 1;
+ break;
+
+ case BLANKTIME:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Screensaver blank time expected");
+ if (!dummy && !xf86sFlag)
+ defaultScreenSaverTime = ScreenSaverTime = val.num * MILLI_PER_MIN;
+ break;
+
+ case STANDBYTIME:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Screensaver standby time expected");
+#ifdef DPMSExtension
+ if (!dummy)
+ DPMSStandbyTime = val.num * MILLI_PER_MIN;
+#endif
+ break;
+
+ case SUSPENDTIME:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Screensaver suspend time expected");
+#ifdef DPMSExtension
+ if (!dummy)
+ DPMSSuspendTime = val.num * MILLI_PER_MIN;
+#endif
+ break;
+
+ case OFFTIME:
+ if (xf86GetToken(NULL) != NUMBER)
+ xf86ConfigError("Screensaver off time expected");
+#ifdef DPMSExtension
+ if (!dummy)
+ DPMSOffTime = val.num * MILLI_PER_MIN;
+#endif
+ break;
+
+ default:
+ if (!dummy && !validateGraphicsToken(screen->validTokens, token))
+ {
+ xf86ConfigError("Screen section keyword expected");
+ }
+ break;
+ }
+ }
+
+ if (!dummy) {
+ if (dispList == NULL) {
+ FatalError(
+ "A \"Display\" subsection is required in each \"Screen\" section\n");
+ } else {
+ /* Work out which if any Display subsection to use based on depth */
+ if (xf86bpp < 0) {
+ /*
+ * no -bpp option given, so take depth if only one Display subsection
+ * Don't do this for VGA2 and VGA16 where it makes no sense, and only
+ * causes problems
+ */
+ if (numDisps == 1) {
+#ifndef XF86SETUP
+ if (dispList[0].depth > 0
+ && !(driverno >= VGA2 && driverno <= VGA16)) {
+ xf86bpp = dispList[0].depth;
+ }
+#endif
+ dispIndex = 0;
+ } else {
+ xf86bpp = screen->depth;
+ /* Look for a section which matches the driver's default depth */
+ for (dispIndex = 0; dispIndex < numDisps; dispIndex++) {
+ if (dispList[dispIndex].depth == screen->depth)
+ break;
+ }
+ if (dispIndex == numDisps) {
+ /* No match. This time, allow 15/16 and 24/32 to match */
+ for (dispIndex = 0; dispIndex < numDisps; dispIndex++) {
+ if ((screen->depth == 15 && dispList[dispIndex].depth == 16) ||
+ (screen->depth == 16 && dispList[dispIndex].depth == 15) ||
+ (screen->depth == 24 && dispList[dispIndex].depth == 32) ||
+ (screen->depth == 32 && dispList[dispIndex].depth == 24))
+ break;
+ }
+ }
+ if (dispIndex == numDisps) {
+ /* Still no match, so exit */
+ FatalError("No \"Display\" subsection for default depth %d\n",
+ screen->depth);
+ }
+ }
+ } else {
+ /* xf86bpp is set */
+ if (numDisps == 1 && dispList[0].depth < 0) {
+ /* one Display subsection, no depth set, so use it */
+ /* XXXX Maybe should only do this when xf86bpp == default depth?? */
+ dispIndex = 0;
+ } else {
+ /* find Display subsection matching xf86bpp */
+ for (dispIndex = 0; dispIndex < numDisps; dispIndex++) {
+ if (dispList[dispIndex].depth == xf86bpp)
+ break;
+ }
+ if (dispIndex == numDisps) {
+#if 0
+ /* No match. This time, allow 15/16 and 24/32 to match */
+ for (dispIndex = 0; dispIndex < numDisps; dispIndex++) {
+ if ((xf86bpp == 15 && dispList[dispIndex].depth == 16) ||
+ (xf86bpp == 16 && dispList[dispIndex].depth == 15) ||
+ (xf86bpp == 24 && dispList[dispIndex].depth == 32) ||
+ (xf86bpp == 32 && dispList[dispIndex].depth == 24))
+ break;
+#else
+ /* No match. This time, allow 15/16 to match */
+ for (dispIndex = 0; dispIndex < numDisps; dispIndex++) {
+ if ((xf86bpp == 15 && dispList[dispIndex].depth == 16) ||
+ (xf86bpp == 16 && dispList[dispIndex].depth == 15))
+ break;
+#endif
+ }
+ }
+ if (dispIndex == numDisps) {
+ if (!(driverno >= VGA2 && driverno <= VGA16)) {
+ /* Still no match, so exit */
+ FatalError("No \"Display\" subsection for -bpp depth %d\n",
+ xf86bpp);
+ }
+ else
+ dispIndex = 0;
+ }
+ }
+ }
+ /* Now copy the info across to the screen rec */
+ dispp = dispList + dispIndex;
+ if (xf86bpp > 0) screen->depth = xf86bpp;
+ else if (dispp->depth > 0) screen->depth = dispp->depth;
+ if (xf86weight.red || xf86weight.green || xf86weight.blue)
+ screen->weight = xf86weight;
+ else if (dispp->weight.red > 0) {
+ screen->weight = dispp->weight;
+ xf86weight = dispp->weight;
+ }
+ screen->frameX0 = dispp->frameX0;
+ screen->frameY0 = dispp->frameY0;
+ screen->virtualX = dispp->virtualX;
+ screen->virtualY = dispp->virtualY;
+ screen->modes = dispp->modes;
+ screen->whiteColour = dispp->whiteColour;
+ screen->blackColour = dispp->blackColour;
+ screen->defaultVisual = dispp->defaultVisual;
+ /* Add any new options that might be set */
+ for (i = 0; i < MAX_OFLAGS; i++) {
+ if (OFLG_ISSET(i, &(dispp->options)))
+ OFLG_SET(i, &(screen->options));
+ if (OFLG_ISSET(i, &(dispp->xconfigFlag)))
+ OFLG_SET(i, &(screen->xconfigFlag));
+ }
+ screen->DCOptions = xf86DCConcatOption(screen->DCOptions,dispp->DCOptions);
+#ifdef XF86SETUP
+ xf86setup_scrn_ndisps[driverno-SVGA] = numDisps;
+ xf86setup_scrn_displays[driverno-SVGA] = dispList;
+#else
+ /* Don't need them any more */
+ xfree(dispList);
+#endif
+ }
+
+ /* Maybe these should be FatalError() instead? */
+ if ( !had_monitor ) {
+ xf86ConfigError("A screen must specify a monitor");
+ }
+ if ( !had_device ) {
+ xf86ConfigError("A screen must specify a device");
+ }
+ }
+
+ /* Check for information that must be specified in XF86Config */
+ if (scr_index >= 0 && xf86Screens[scr_index])
+ {
+ ScrnInfoPtr driver = xf86Screens[scr_index];
+
+ graphFound = TRUE;
+
+ if (driver->clockprog && !driver->clocks)
+ {
+ if (!OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions))){
+ ErrorF("%s: No clock line specified: assuming programmable clocks\n");
+ OFLG_SET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions));}
+ driver->textclock = textClockValue;
+ }
+
+ /* Find the Index of the Text Clock for the ClockProg */
+ if (driver->clockprog && textClockValue > 0
+ && !OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(screen->clockOptions)))
+ {
+ driver->textclock = xf86GetNearestClock(driver, textClockValue);
+ if (abs(textClockValue - driver->clock[driver->textclock]) >
+ CLOCK_TOLERANCE)
+ FatalError(
+ "There is no defined dot-clock matching the text clock\n");
+ if (xf86Verbose)
+ ErrorF("%s %s: text clock = %7.3f, clock used = %7.3f\n",
+ XCONFIG_GIVEN,
+ driver->name, textClockValue / 1000.0,
+ driver->clock[driver->textclock] / 1000.0);
+ }
+ if (xf86Verbose && driver->defaultVisual > 0) {
+ char *visualname;
+ switch (driver->defaultVisual) {
+ case StaticGray:
+ case GrayScale:
+ case StaticColor:
+ case PseudoColor:
+ case TrueColor:
+ case DirectColor:
+ visualname = xf86VisualNames[driver->defaultVisual];
+ break;
+ default:
+ xf86ConfigError("unknown visual type");
+ }
+ ErrorF("%s %s: Default visual: %s\n", XCONFIG_GIVEN, driver->name,
+ visualname);
+ }
+ if (defaultColorVisualClass < 0)
+ defaultColorVisualClass = driver->defaultVisual;
+
+ /* GJA --Moved these from the device code. Had to reorganize it
+ * a bit.
+ */
+ if (xf86Verbose) {
+ if (OFLG_ISSET(XCONFIG_IOBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: Direct Access Register I/O Base Address: %x\n",
+ XCONFIG_GIVEN, driver->name, driver->IObase);
+
+ if (OFLG_ISSET(XCONFIG_DACBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: DAC Base I/O Address: %x\n",
+ XCONFIG_GIVEN, driver->name, driver->DACbase);
+
+ if (OFLG_ISSET(XCONFIG_COPBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: Coprocessor Base Memory Address: %x\n",
+ XCONFIG_GIVEN, driver->name, driver->COPbase);
+
+ if (OFLG_ISSET(XCONFIG_POSBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: POS Base Address: %x\n", XCONFIG_GIVEN, driver->name,
+ driver->POSbase);
+
+ if (OFLG_ISSET(XCONFIG_BIOSBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: BIOS Base Address: %x\n", XCONFIG_GIVEN, driver->name,
+ driver->BIOSbase);
+
+ if (OFLG_ISSET(XCONFIG_MEMBASE, &driver->xconfigFlag))
+ ErrorF("%s %s: Memory Base Address: %x\n", XCONFIG_GIVEN,
+ driver->name, driver->MemBase);
+
+ if (OFLG_ISSET(XCONFIG_VGABASE, &driver->xconfigFlag))
+ ErrorF("%s %s: VGA Aperture Base Address: %x\n", XCONFIG_GIVEN,
+ driver->name, driver->VGAbase);
+
+ /* Print clock program */
+ if ( driver->clockprog ) {
+ ErrorF("%s %s: ClockProg: \"%s\"", XCONFIG_GIVEN, driver->name,
+ driver->clockprog);
+ if ( textClockValue )
+ ErrorF(", Text Clock: %7.3f\n", textClockValue / 1000.0);
+ ErrorF("\n");
+ }
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+static CONFIG_RETURN_TYPE
+configDisplaySubsection(disp)
+DispPtr disp;
+{
+ int token;
+ int i;
+
+ while ((token = xf86GetToken(DisplayTab)) != ENDSUBSECTION) {
+ switch (token) {
+ case DEPTH:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display depth expected");
+ disp->depth = val.num;
+ break;
+
+ case WEIGHT:
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected");
+ if (val.num > 9) {
+ disp->weight.red = (val.num / 100) % 10;
+ disp->weight.green = (val.num / 10) % 10;
+ disp->weight.blue = val.num % 10;
+ } else {
+ disp->weight.red = val.num;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected");
+ disp->weight.green = val.num;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Display weight expected");
+ disp->weight.blue = val.num;
+ }
+ break;
+
+ case VIEWPORT:
+ OFLG_SET(XCONFIG_VIEWPORT,&(disp->xconfigFlag));
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Viewport X expected");
+ disp->frameX0 = val.num;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Viewport Y expected");
+ disp->frameY0 = val.num;
+ break;
+
+ case VIRTUAL:
+ OFLG_SET(XCONFIG_VIRTUAL,&(disp->xconfigFlag));
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Virtual X expected");
+ disp->virtualX = val.num;
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("Virtual Y expected");
+ disp->virtualY = val.num;
+ break;
+
+ case MODES:
+ for (pLast=NULL; (token = xf86GetToken(NULL)) == STRING; pLast = pNew)
+ {
+ pNew = (DisplayModePtr)xalloc(sizeof(DisplayModeRec));
+ pNew->name = val.str;
+ pNew->PrivSize = 0;
+ pNew->Private = NULL;
+
+ if (pLast)
+ {
+ pLast->next = pNew;
+ pNew->prev = pLast;
+ }
+ else
+ disp->modes = pNew;
+ }
+ /* Make sure at least one mode was present */
+ if (!pLast)
+ xf86ConfigError("Mode name expected");
+ pNew->next = disp->modes;
+ disp->modes->prev = pLast;
+ pushToken = token;
+ break;
+
+ case BLACK:
+ case WHITE:
+ {
+ unsigned char rgb[3];
+ int ii;
+
+ for (ii = 0; ii < 3; ii++)
+ {
+ if (xf86GetToken(NULL) != NUMBER) xf86ConfigError("RGB value expected");
+ rgb[ii] = val.num & 0x3F;
+ }
+ if (token == BLACK)
+ {
+ disp->blackColour.red = rgb[0];
+ disp->blackColour.green = rgb[1];
+ disp->blackColour.blue = rgb[2];
+ }
+ else
+ {
+ disp->whiteColour.red = rgb[0];
+ disp->whiteColour.green = rgb[1];
+ disp->whiteColour.blue = rgb[2];
+ }
+ }
+ break;
+
+ case VISUAL:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Visual name expected");
+ token = getStringToken(VisualTab);
+ if (!dummy && disp->defaultVisual >= 0)
+ xf86ConfigError("Only one default visual may be specified");
+ disp->defaultVisual = token - STATICGRAY;
+ break;
+
+ case OPTION:
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Option string expected");
+ i = 0;
+ while (xf86_OptionTab[i].token != -1)
+ {
+ if (StrCaseCmp(val.str, xf86_OptionTab[i].name) == 0)
+ {
+ OFLG_SET(xf86_OptionTab[i].token, &(disp->options));
+ break;
+ }
+ i++;
+ }
+ if (xf86_OptionTab[i].token == -1)
+ disp->DCOptions = xf86DCOption(disp->DCOptions,val);
+ break;
+
+ /* The following should really go in the S3 server */
+ case INVERTVCLK:
+ case BLANKDELAY:
+ case EARLYSC:
+ {
+ DisplayModePtr p = disp->modes;
+ if (xf86GetToken(NULL) != STRING) xf86ConfigError("Mode name expected");
+ if (disp->modes == NULL)
+ xf86ConfigError("This must be after the Modes line");
+ {
+ Bool found = FALSE;
+ int opt;
+ INT32 value;
+ char *mode_string = (char *)xalloc(strlen(val.str)+1);
+ strcpy(mode_string,val.str);
+
+ switch (token) {
+ default: /* pacify compiler (uninitialized opt, value) */
+ case INVERTVCLK:
+ if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 1)
+ xf86ConfigError("0 or 1 expected");
+ opt = S3_INVERT_VCLK;
+ value = val.num;
+ break;
+
+ case BLANKDELAY:
+ if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 7)
+ xf86ConfigError("number(s) 0..7 expected");
+ opt = S3_BLANK_DELAY;
+ value = val.num;
+ if ((token=xf86GetToken(NULL)) == NUMBER) {
+ if (val.num < 0 || val.num > 7)
+ xf86ConfigError("number2 0..7 expected");
+ value |= val.num << 4;
+ }
+ else pushToken = token;
+ break;
+
+ case EARLYSC:
+ if (xf86GetToken(NULL) != NUMBER || val.num < 0 || val.num > 1)
+ xf86ConfigError("0 or 1 expected");
+ opt = S3_EARLY_SC;
+ value = val.num;
+ break;
+ }
+
+ do {
+ if (strcmp(p->name, mode_string) == 0
+ || strcmp("*", mode_string) == 0) {
+ found = TRUE;
+ if (!p->PrivSize || !p->Private) {
+ p->PrivSize = S3_MODEPRIV_SIZE;
+ p->Private = (INT32 *)Xcalloc(sizeof(INT32) * S3_MODEPRIV_SIZE);
+ p->Private[0] = 0;
+ }
+ p->Private[0] |= (1 << opt);
+ p->Private[opt] = value;
+ }
+ p = p->next;
+ } while (p != disp->modes);
+ if (!found) xf86ConfigError("No mode of that name in the Modes line");
+ xfree(mode_string);
+ }
+ }
+ break;
+
+
+ case EOF:
+ FatalError("Unexpected EOF (missing EndSubSection)");
+ break; /* :-) */
+
+ default:
+ xf86ConfigError("Display subsection keyword expected");
+ break;
+ }
+ }
+#ifdef NEED_RETURN_VALUE
+ return RET_OKAY;
+#endif
+}
+
+Bool
+xf86LookupMode(target, driver, flags)
+ DisplayModePtr target;
+ ScrnInfoPtr driver;
+ int flags;
+{
+ DisplayModePtr p;
+ DisplayModePtr best_mode = NULL;
+ int i, j, k, Gap;
+ int Minimum_Gap = CLOCK_TOLERANCE + 1;
+ Bool found_mode = FALSE;
+ Bool clock_too_high = FALSE;
+ static Bool first_time = TRUE;
+ double refresh, bestRefresh = 0.0;
+
+ if (first_time)
+ {
+ ErrorF("%s %s: Maximum allowed dot-clock: %1.3f MHz\n", XCONFIG_PROBED,
+ driver->name, driver->maxClock / 1000.0);
+ first_time = FALSE;
+ /*
+ * First time through, cull modes which are not valid for the
+ * card/driver.
+ */
+ driver->monitor->Modes = xf86PruneModes(NULL, driver->monitor->Modes,
+ driver, TRUE);
+ }
+
+ if (xf86BestRefresh && !(flags & LOOKUP_FORCE_DEFAULT))
+ flags |= LOOKUP_BEST_REFRESH;
+
+ for (p = driver->monitor->Modes; p != NULL; p = p->next) /* scan list */
+ {
+ if (!strcmp(p->name, target->name)) /* names equal ? */
+ {
+ /* First check if the driver objects to the mode */
+ if ((driver->ValidMode)(p, xf86Verbose, MODE_USED) != MODE_OK)
+ {
+ ErrorF("%s %s: Mode \"%s\" rejected by driver. Deleted.\n",
+ XCONFIG_PROBED,driver->name, target->name );
+ break;
+ }
+
+ if ((flags & LOOKUP_NO_INTERLACED) && (p->Flags & V_INTERLACE))
+ {
+ continue;
+ }
+
+ if ((OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(driver->clockOptions))) &&
+ !OFLG_ISSET(OPTION_NO_PROGRAM_CLOCKS, &(driver->options)))
+ {
+ if (driver->clocks == 0)
+ {
+ /* this we know */
+ driver->clock[0] = 25175; /* 25.175Mhz */
+ driver->clock[1] = 28322; /* 28.322MHz */
+ driver->clocks = 2;
+ }
+
+ if ((p->Clock / 1000) > (driver->maxClock / 1000))
+ clock_too_high = TRUE;
+ else
+ {
+ /* We fill in the the programmable clocks as we go */
+ for (i=0; i < driver->clocks; i++)
+ if (driver->clock[i] == p->Clock)
+ break;
+
+ if (i >= MAXCLOCKS)
+ {
+ ErrorF("%s %s: Too many programmable clocks used (limit %d)!\n",
+ XCONFIG_PROBED, driver->name, MAXCLOCKS);
+ return FALSE;
+ }
+
+ if (i == driver->clocks)
+ {
+ driver->clock[i] = p->Clock;
+ driver->clocks++;
+ }
+
+
+ if (flags & LOOKUP_BEST_REFRESH)
+ {
+ refresh = p->Clock * 1000.0 / p->HTotal / p->VTotal;
+ if (p->Flags & V_INTERLACE)
+ {
+ refresh *= 2;
+ refresh /= INTERLACE_REFRESH_WEIGHT;
+ }
+ else if (p->Flags & V_DBLSCAN)
+ {
+ refresh /= 2;
+ }
+ if (refresh > bestRefresh)
+ {
+ best_mode = p;
+ bestRefresh = refresh;
+ target->Clock = i;
+ }
+ }
+ else
+ {
+ target->Clock = i;
+ best_mode = p;
+ }
+ }
+ }
+ else
+ {
+ /*
+ * go look if any of the clocks in the list matches the one in
+ * the mode (j=1), or if a better match exists when the clocks
+ * in the list are divided by 2 (j=2)
+ */
+ if (OFLG_ISSET(OPTION_CLKDIV2, &(driver->options)))
+ k=2;
+ else
+ k=1;
+ for (j=1 ; j<=k ; j++)
+ {
+ i = xf86GetNearestClock(driver, p->Clock*j);
+ if (flags & LOOKUP_BEST_REFRESH)
+ {
+ if ( ((driver->clock[i]/j) / 1000) > (driver->maxClock / 1000) )
+ clock_too_high = TRUE;
+ else
+ {
+ refresh = p->Clock * 1000.0 / p->HTotal / p->VTotal;
+ if (p->Flags & V_INTERLACE)
+ {
+ refresh *= 2;
+ refresh /= INTERLACE_REFRESH_WEIGHT;
+ }
+ else if (p->Flags & V_DBLSCAN)
+ {
+ refresh /= 2;
+ }
+ if (refresh > bestRefresh)
+ {
+ target->Clock = i;
+ if (j==2) p->Flags |= V_CLKDIV2;
+ best_mode = p;
+ bestRefresh = refresh;
+ }
+ }
+ }
+ else
+ {
+ Gap = abs( p->Clock - (driver->clock[i]/j) );
+ if (Gap < Minimum_Gap)
+ {
+ if ( ((driver->clock[i]/j) / 1000) > (driver->maxClock / 1000) )
+ clock_too_high = TRUE;
+ else
+ {
+ target->Clock = i;
+ if (j==2) p->Flags |= V_CLKDIV2;
+ best_mode = p;
+ Minimum_Gap = Gap;
+ }
+ }
+ }
+ }
+ }
+ found_mode = TRUE;
+ }
+ }
+
+ if (best_mode != NULL)
+ {
+ target->HDisplay = best_mode->HDisplay;
+ target->HSyncStart = best_mode->HSyncStart;
+ target->HSyncEnd = best_mode->HSyncEnd;
+ target->HTotal = best_mode->HTotal;
+ target->HSkew = best_mode->HSkew;
+ target->VDisplay = best_mode->VDisplay;
+ target->VSyncStart = best_mode->VSyncStart;
+ target->VSyncEnd = best_mode->VSyncEnd;
+ target->VTotal = best_mode->VTotal;
+ target->Flags = best_mode->Flags;
+ target->CrtcHDisplay = best_mode->CrtcHDisplay;
+ target->CrtcHSyncStart = best_mode->CrtcHSyncStart;
+ target->CrtcHSyncEnd = best_mode->CrtcHSyncEnd;
+ target->CrtcHTotal = best_mode->CrtcHTotal;
+ target->CrtcHSkew = best_mode->CrtcHSkew;
+ target->CrtcVDisplay = best_mode->CrtcVDisplay;
+ target->CrtcVSyncStart = best_mode->CrtcVSyncStart;
+ target->CrtcVSyncEnd = best_mode->CrtcVSyncEnd;
+ target->CrtcVTotal = best_mode->CrtcVTotal;
+ target->CrtcHAdjusted = best_mode->CrtcHAdjusted;
+ target->CrtcVAdjusted = best_mode->CrtcVAdjusted;
+ if (target->Flags & V_DBLSCAN)
+ {
+ target->CrtcVDisplay *= 2;
+ target->CrtcVSyncStart *= 2;
+ target->CrtcVSyncEnd *= 2;
+ target->CrtcVTotal *= 2;
+ target->CrtcVAdjusted = TRUE;
+ }
+
+#if 0
+ /* I'm not sure if this is the best place for this in the
+ * new XF86Config organization. - SRA
+ */
+ if (found_mode)
+ if ((driver->ValidMode)(target, xf86Verbose, MODE_USED) != MODE_OK)
+ {
+ ErrorF("%s %s: Unable to support mode \"%s\"\n",
+ XCONFIG_GIVEN,driver->name, target->name );
+ return(FALSE);
+ }
+#endif
+
+ if (xf86Verbose)
+ {
+ ErrorF("%s %s: Mode \"%s\": mode clock = %7.3f",
+ XCONFIG_GIVEN, driver->name, target->name,
+ best_mode->Clock / 1000.0);
+ if (!OFLG_ISSET(CLOCK_OPTION_PROGRAMABLE, &(driver->clockOptions)) ||
+ OFLG_ISSET(OPTION_NO_PROGRAM_CLOCKS, &(driver->options))) {
+ ErrorF(", clock used = %7.3f", driver->clock[target->Clock] / 1000.0);
+ if (target->Flags & V_CLKDIV2)
+ ErrorF("/2");
+ }
+ ErrorF("\n");
+ }
+ }
+ else if (!found_mode)
+ ErrorF("%s %s: There is no mode definition named \"%s\"\n",
+ XCONFIG_PROBED, driver->name, target->name);
+ else if (clock_too_high)
+ ErrorF("%s %s: Clock for mode \"%s\" %s\n\tLimit is %7.3f MHz\n",
+ XCONFIG_PROBED, driver->name, target->name,
+ "is too high for the configured hardware.",
+ driver->maxClock / 1000.0);
+ else
+ ErrorF("%s %s: There is no defined dot-clock matching mode \"%s\"\n",
+ XCONFIG_PROBED, driver->name, target->name);
+
+ return (best_mode != NULL);
+}
+
+void
+xf86VerifyOptions(allowedOptions, driver)
+ OFlagSet *allowedOptions;
+ ScrnInfoPtr driver;
+{
+ int j;
+
+ for (j=0; xf86_OptionTab[j].token >= 0; j++)
+ if ((OFLG_ISSET(xf86_OptionTab[j].token, &driver->options)))
+ if (OFLG_ISSET(xf86_OptionTab[j].token, allowedOptions))
+ {
+ if (xf86Verbose)
+ ErrorF("%s %s: Option \"%s\"\n", XCONFIG_GIVEN,
+ driver->name, xf86_OptionTab[j].name);
+ }
+ else
+ ErrorF("%s %s: Option flag \"%s\" is not defined for this driver\n",
+ XCONFIG_GIVEN, driver->name, xf86_OptionTab[j].name);
+}
+
+/* Note: (To keep me [GJA] from getting confused)
+ * We have two mode-related datastructures:
+ * 1. A doubly linked mode name list, with ends marked by self-pointers.
+ * 2. A doubly linked mode structure list.
+ * We are operating here on the second structure.
+ * Initially this is just singly linked.
+ */
+static DisplayModePtr
+xf86PruneModes(monp, allmodes, scrp, card)
+ MonPtr monp; /* Monitor specification */
+ DisplayModePtr allmodes; /* List to be pruned */
+ ScrnInfoPtr scrp;
+ Bool card; /* TRUE => do driver validity check */
+{
+ DisplayModePtr dispmp; /* To walk the list */
+ DisplayModePtr olddispmp; /* The one being freed. */
+ DisplayModePtr remainder; /* The first one retained. */
+
+ dispmp = allmodes;
+
+ /* The first modes to be deleted require that the pointer to the
+ * mode list is updated. Also, they have no predecessor in the list.
+ */
+ while (dispmp &&
+ (card ?
+ ((scrp->ValidMode)(dispmp, xf86Verbose, MODE_SUGGESTED)
+ != MODE_OK) :
+ (xf86CheckMode(scrp, dispmp, monp, xf86Verbose) != MODE_OK))) {
+ olddispmp = dispmp;
+ dispmp = dispmp->next;
+ xfree(olddispmp->name);
+ xfree(olddispmp);
+ }
+ /* Now we either have a mode that fits, or no mode at all */
+ if ( ! dispmp ) { /* No mode at all */
+ return NULL;
+ }
+ remainder = dispmp;
+ while ( dispmp->next ) {
+ if (card ?
+ ((scrp->ValidMode)(dispmp->next,xf86Verbose,MODE_SUGGESTED)
+ != MODE_OK) :
+ (xf86CheckMode(scrp, dispmp->next, monp, xf86Verbose) !=
+ MODE_OK)) {
+ olddispmp = dispmp->next;
+ dispmp->next = dispmp->next->next;
+ xfree(olddispmp->name);
+ xfree(olddispmp);
+ } else {
+ dispmp = dispmp->next;
+ }
+ }
+ return remainder; /* Return pointer to {the first / the list } */
+}
+
+/*
+ * Return MODE_OK if the mode pointed to by dispmp agrees with all constraints
+ * we can make up for the monitor pointed to by monp.
+ */
+int
+xf86CheckMode(scrp, dispmp, monp, verbose)
+ ScrnInfoPtr scrp;
+ DisplayModePtr dispmp;
+ MonPtr monp;
+ Bool verbose;
+{
+ int i;
+ float dotclock, hsyncfreq, vrefreshrate;
+ char *scrname = scrp->name;
+
+ /* Sanity checks */
+ if ((0 >= dispmp->HDisplay) ||
+ (dispmp->HDisplay > dispmp->HSyncStart) ||
+ (dispmp->HSyncStart >= dispmp->HSyncEnd) ||
+ (dispmp->HSyncEnd >= dispmp->HTotal))
+ {
+ ErrorF(
+ "%s %s: Invalid horizontal timing for mode \"%s\". Deleted.\n",
+ XCONFIG_PROBED, scrname, dispmp->name);
+ return MODE_HSYNC;
+ }
+
+ if ((0 >= dispmp->VDisplay) ||
+ (dispmp->VDisplay > dispmp->VSyncStart) ||
+ (dispmp->VSyncStart >= dispmp->VSyncEnd) ||
+ (dispmp->VSyncEnd >= dispmp->VTotal))
+ {
+ ErrorF(
+ "%s %s: Invalid vertical timing for mode \"%s\". Deleted.\n",
+ XCONFIG_PROBED, scrname, dispmp->name);
+ return MODE_VSYNC;
+ }
+
+ /* Deal with the dispmp->Clock being a frequency or index */
+ if (dispmp->Clock > MAXCLOCKS) {
+ dotclock = (float)dispmp->Clock;
+ } else {
+ dotclock = (float)scrp->clock[dispmp->Clock];
+ }
+ hsyncfreq = dotclock / (float)(dispmp->HTotal);
+ for ( i = 0 ; i < monp->n_hsync ; i++ )
+ if ( (hsyncfreq > 0.999 * monp->hsync[i].lo) &&
+ (hsyncfreq < 1.001 * monp->hsync[i].hi) )
+ break; /* In range. */
+
+ /* Now see whether we ran out of sync frequencies */
+ if ( i == monp->n_hsync ) {
+ if (verbose) {
+ ErrorF(
+ "%s %s: Mode \"%s\" needs hsync freq of %.2f kHz. Deleted.\n",
+ XCONFIG_PROBED, scrname, dispmp->name, hsyncfreq);
+ }
+ return MODE_HSYNC;
+ }
+
+ vrefreshrate = dotclock * 1000.0 /
+ ((float)(dispmp->HTotal) * (float)(dispmp->VTotal)) ;
+ if ( dispmp->Flags & V_INTERLACE ) vrefreshrate *= 2.0;
+ if ( dispmp->Flags & V_DBLSCAN ) vrefreshrate /= 2.0;
+ for ( i = 0 ; i < monp->n_vrefresh ; i++ )
+ if ( (vrefreshrate > 0.999 * monp->vrefresh[i].lo) &&
+ (vrefreshrate < 1.001 * monp->vrefresh[i].hi) )
+ break; /* In range. */
+
+ /* Now see whether we ran out of refresh rates */
+ if ( i == monp->n_vrefresh ) {
+ if (verbose) {
+ ErrorF(
+ "%s %s: Mode \"%s\" needs vert refresh rate of %.2f Hz. Deleted.\n",
+ XCONFIG_PROBED, scrname, dispmp->name, vrefreshrate);
+ }
+ return MODE_VSYNC;
+ }
+
+ /* Interlaced modes should have an odd VTotal */
+ if (dispmp->Flags & V_INTERLACE)
+ dispmp->CrtcVTotal = dispmp->VTotal |= 1;
+
+ /* Passed every test. */
+ return MODE_OK;
+}
+
+/*
+ * Save entire line from config file in memory area, if memory area
+ * does not exist allocate it. Set DCerr according to value of token.
+ * Return address of memory area.
+ */
+static char *xf86DCSaveLine(DCPointer,token)
+ char *DCPointer;
+ int token;
+{
+ static int len = 0; /* length of memory area where to store strings */
+ static int pos = 0; /* current position */
+ char *currpointer; /* pointer to current position in memory area */
+ static int currline; /* lineno of line currently interpreted */
+ int addlen; /* len to add to pos */
+
+ if(DCPointer == NULL){ /* initialize */
+ DCPointer = (char *)xalloc(4096); /* initial size 4kB */
+ len = 4096;
+ strcpy(DCPointer,configPath);
+ pos = strlen(DCPointer) + 1;
+ currline = -1; /* no line yet */
+ }
+
+ if(configLineNo != currline) /* new line */
+ {
+ currline = configLineNo;
+ addlen = strlen(configBuf) + 1 + sizeof(int); /* string + lineno */
+ while ( (pos + addlen) >= len ){ /* not enough space? */
+ DCPointer = (char *)xrealloc(DCPointer, (len + 4096));
+ len += 4096;
+ }
+ currpointer = DCPointer + pos; /* find current position */
+ memcpy(currpointer, &currline, sizeof(int)); /* Grrr unaligned ints.. */
+ strcpy((currpointer + sizeof(int)),configBuf); /* store complete line*/
+ pos += addlen; /* goto end */
+ currpointer += addlen;
+ *(currpointer) = EOF; /* mark end */
+ }
+ switch(token){
+ case STRING:
+ case DASH:
+ case NUMBER:
+ case COMMA:
+ break;
+ case ERROR_TOKEN: /* if unknown token unset DCerr to ignore it */
+ DCerr = 0; /* and subsequent STRING, DASH, NUMBER, COMMA */
+ break;
+ default: /* set to complain if a valid token is */
+ DCerr = 1; /* followed by an unwanted STRING etc. */
+ }
+ return(DCPointer);
+}
+
+/*
+ * Store any unknown Option strings (contained in val.str)
+ * in a memory are pointed to by pointer. If it doesn't
+ * exist allocate it and return a pointer pointing to it
+ */
+
+static char *
+xf86DCOption(DCPointer, val)
+ char *DCPointer;
+ LexRec val;
+{
+ static int len = 0;
+ static int pos = 0;
+ int addlen;
+ char *currpointer; /* current position */
+
+ if (DCPointer == NULL){ /* First time: initialize */
+ DCPointer = (char *)xalloc(4096); /* allocate enough space */
+ strcpy(DCPointer,configPath);
+ pos = strlen(DCPointer) + 1;
+ len = 4096; /* and total length */
+ }
+
+ addlen = sizeof(int) + strlen(val.str) + 1; /* token, lineno */
+ while( (pos + addlen) >= len ){ /* reallocate if not enough */
+ DCPointer = (char *)xrealloc(DCPointer, (len + 4096));
+ len += 4096;
+ }
+ currpointer = DCPointer + pos;
+ *(int *)currpointer=configLineNo;
+ strcpy(currpointer + sizeof(int),val.str); /* store string */
+ pos += addlen;
+ *(currpointer + addlen) = EOF; /* mark end */
+ return(DCPointer);
+}
+
+static char
+* xf86DCConcatOption(Pointer1, Pointer2)
+char *Pointer1;
+char *Pointer2;
+{
+ int s1 = 0;
+ int s2 = 0;
+ int s3;
+ char *ptmp;
+
+ if(Pointer1)
+ while(*(Pointer1 + s1) != EOF){s1++;}
+ else if (Pointer2)
+ return Pointer2;
+ else return NULL;
+ if(Pointer2)
+ while(*(Pointer2 + s2) != EOF){s2++;}
+ else if (Pointer1)
+ return Pointer1;
+ else return NULL;
+ s3 = strlen(Pointer2) + 1;
+ s2 -= s3;
+
+ Pointer1 = (char *)xrealloc(Pointer1,s1+s2+1);
+ ptmp = Pointer1 + s1;
+ Pointer2 += s3;
+ do{
+ *ptmp = *Pointer2;
+ *ptmp++;
+ *Pointer2++;
+ } while(s2--);
+ return Pointer1;
+}
+
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
new file mode 100644
index 000000000..6c0943b41
--- /dev/null
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -0,0 +1,326 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Cursor.c,v 3.13 1996/12/23 06:43:22 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86Cursor.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "cursor.h"
+#include "mipointer.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Procs.h"
+#ifdef XFreeXDGA
+#include "Xproto.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+
+#define _XF86DGA_SERVER_
+#include "extensions/xf86dgastr.h"
+#endif
+
+#ifdef XINPUT
+#include "xf86_Config.h"
+#include "XIproto.h"
+#include "xf86Xinput.h"
+#endif
+
+/* #include "atKeynames.h" -hv- dont need that include here */
+
+
+static Bool xf86CursorOffScreen(
+#if NeedFunctionPrototypes
+ ScreenPtr *pScreen,
+ int *x,
+ int *y
+#endif
+);
+static void xf86CrossScreen(
+#if NeedFunctionPrototypes
+ ScreenPtr pScreen,
+ Bool entering
+#endif
+);
+static void xf86WrapCursor(
+#if NeedFunctionPrototypes
+ ScreenPtr pScreen,
+ int x,
+ int y
+#endif
+);
+
+miPointerScreenFuncRec xf86PointerScreenFuncs = {
+ xf86CursorOffScreen,
+ xf86CrossScreen,
+ xf86WrapCursor,
+#ifdef XINPUT
+ xf86eqEnqueue,
+#endif
+};
+
+
+
+/*
+ * xf86InitViewport --
+ * Initialize paning & zooming parameters, so that a driver must only
+ * check what resolutions are possible and whether the virtual area
+ * is valid if specifyed.
+ */
+
+void
+xf86InitViewport(pScr)
+ ScrnInfoPtr pScr;
+{
+ /*
+ * Compute the initial Viewport if necessary
+ */
+ if (pScr->frameX0 < 0)
+ {
+ pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2;
+ pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2;
+ }
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+
+ /*
+ * Now adjust the initial Viewport, so it lies within the virtual area
+ */
+ if (pScr->frameX1 >= pScr->virtualX)
+ {
+ pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay;
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ }
+
+ if (pScr->frameY1 >= pScr->virtualY)
+ {
+ pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+ }
+}
+
+
+/*
+ * xf86SetViewport --
+ * Scroll the visual part of the screen so the pointer is visible.
+ */
+
+void
+xf86SetViewport(pScreen, x, y)
+ ScreenPtr pScreen;
+ int x, y;
+{
+ Bool frameChanged = FALSE;
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+
+ /*
+ * check wether (x,y) belongs to the visual part of the screen
+ * if not, change the base of the displayed frame accoring
+ */
+ if ( pScr->frameX0 > x) {
+ pScr->frameX0 = x;
+ pScr->frameX1 = x + pScr->modes->HDisplay - 1;
+ frameChanged = TRUE ;
+ }
+
+ if ( pScr->frameX1 < x) {
+ pScr->frameX1 = x + 1;
+ pScr->frameX0 = x - pScr->modes->HDisplay + 1;
+ frameChanged = TRUE ;
+ }
+
+ if ( pScr->frameY0 > y) {
+ pScr->frameY0 = y;
+ pScr->frameY1 = y + pScr->modes->VDisplay - 1;
+ frameChanged = TRUE;
+ }
+
+ if ( pScr->frameY1 < y) {
+ pScr->frameY1 = y;
+ pScr->frameY0 = y - pScr->modes->VDisplay + 1;
+ frameChanged = TRUE;
+ }
+
+ if (frameChanged) (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0);
+}
+
+
+static Bool xf86ZoomLocked = FALSE;
+
+/*
+ * xf86LockZoom --
+ * Enable/disable ZoomViewport
+ */
+
+void
+xf86LockZoom (pScreen, lock)
+ ScreenPtr pScreen;
+ Bool lock;
+{
+ /*
+ * pScreen is currently ignored, but may be used later to enable locking
+ * of individual screens.
+ */
+
+ xf86ZoomLocked = lock;
+}
+
+/*
+ * xf86ZoomViewport --
+ * Reinitialize the visual part of the screen for another modes->
+ */
+
+void
+xf86ZoomViewport (pScreen, zoom)
+ ScreenPtr pScreen;
+ int zoom;
+{
+ ScrnInfoPtr pScr = XF86SCRNINFO(pScreen);
+
+ if (xf86ZoomLocked)
+ return;
+
+#ifdef XFreeXDGA
+ /*
+ * We should really send the mode change request to the DGA client and let
+ * it decide what to do. For now just bin the request
+ */
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics)
+ return;
+#endif
+
+ if (pScr->modes != pScr->modes->next)
+ {
+ pScr->modes = zoom > 0 ? pScr->modes->next : pScr->modes->prev;
+
+ if ((pScr->SwitchMode)(pScr->modes))
+ {
+ /*
+ * adjust new frame for the displaysize
+ */
+ pScr->frameX0 = (pScr->frameX1 + pScr->frameX0 -pScr->modes->HDisplay)/2;
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+
+ if (pScr->frameX0 < 0)
+ {
+ pScr->frameX0 = 0;
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ }
+ else if (pScr->frameX1 >= pScr->virtualX)
+ {
+ pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay;
+ pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1;
+ }
+
+ pScr->frameY0 = (pScr->frameY1 + pScr->frameY0 - pScr->modes->VDisplay)/2;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+
+ if (pScr->frameY0 < 0)
+ {
+ pScr->frameY0 = 0;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+ }
+ else if (pScr->frameY1 >= pScr->virtualY)
+ {
+ pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay;
+ pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1;
+ }
+ }
+ else /* switch failed, so go back to old mode */
+ pScr->modes = zoom > 0 ? pScr->modes->prev : pScr->modes->next;
+ }
+
+ (pScr->AdjustFrame)(pScr->frameX0, pScr->frameY0);
+}
+
+
+
+/*
+ * xf86CursorOffScreen --
+ * Check whether it is necessary to switch to another screen
+ */
+
+/* ARGSUSED */
+static Bool
+xf86CursorOffScreen (pScreen, x, y)
+ ScreenPtr *pScreen;
+ int *x, *y;
+{
+ int i;
+
+ if ((screenInfo.numScreens > 1) && ((*x < 0) || ((*pScreen)->width <= *x))) {
+ i = (*pScreen)->myNum;
+ if (*x < 0) {
+ i = (i ? i : screenInfo.numScreens) -1;
+ *pScreen = screenInfo.screens[i];
+ *x += (*pScreen)->width;
+ }
+ else {
+ *x -= (*pScreen)->width;
+ i = (i+1) % screenInfo.numScreens;
+ *pScreen = screenInfo.screens[i];
+ }
+ return(TRUE);
+ }
+ return(FALSE);
+}
+
+
+
+/*
+ * xf86CrossScreen --
+ * Switch to another screen
+ */
+
+/* ARGSUSED */
+static void
+xf86CrossScreen (pScreen, entering)
+ ScreenPtr pScreen;
+ Bool entering;
+{
+ if (xf86Info.sharedMonitor)
+ (XF86SCRNINFO(pScreen)->EnterLeaveMonitor)(entering);
+ (XF86SCRNINFO(pScreen)->EnterLeaveCursor)(entering);
+}
+
+
+/*
+ * xf86WrapCursor --
+ * Wrap possible to another screen
+ */
+
+/* ARGSUSED */
+static void
+xf86WrapCursor (pScreen, x, y)
+ ScreenPtr pScreen;
+ int x,y;
+{
+ miPointerWarpCursor(pScreen,x,y);
+
+ xf86Info.currentScreen = pScreen;
+}
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
new file mode 100644
index 000000000..aa0983111
--- /dev/null
+++ b/hw/xfree86/common/xf86Events.c
@@ -0,0 +1,1575 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Events.c,v 3.42.2.4 1998/02/07 09:23:28 hohndel Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86Events.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */
+
+/* [JCH-96/01/21] Extended std reverse map to four buttons. */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "Xpoll.h"
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "xf86_Config.h"
+#include "atKeynames.h"
+
+
+#ifdef XFreeXDGA
+#include "XIproto.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+
+#include "exevents.h"
+
+#define _XF86DGA_SERVER_
+#include "extensions/xf86dgastr.h"
+#endif
+
+#ifdef XINPUT
+#include "XI.h"
+#include "XIproto.h"
+#include "xf86Xinput.h"
+#endif
+
+#include "mipointer.h"
+#include "opaque.h"
+#ifdef DPMSExtension
+#include "extensions/dpms.h"
+#endif
+
+#ifdef XKB
+extern Bool noXkbExtension;
+#endif
+
+#define XE_POINTER 1
+#define XE_KEYBOARD 2
+
+#ifdef XTESTEXT1
+
+#define XTestSERVER_SIDE
+#include "xtestext1.h"
+extern short xtest_mousex;
+extern short xtest_mousey;
+extern int on_steal_input;
+extern Bool XTestStealKeyData();
+extern void XTestStealMotionData();
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ if (!on_steal_input || \
+ XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, dev_type, \
+ xtest_mousex, xtest_mousey)) \
+ mieqEnqueue((ev))
+#endif
+
+#define MOVEPOINTER(dx, dy, time) \
+ if (on_steal_input) \
+ XTestStealMotionData(dx, dy, XE_POINTER, xtest_mousex, xtest_mousey); \
+ miPointerDeltaCursor (dx, dy, time)
+
+#else /* ! XTESTEXT1 */
+
+#ifdef XINPUT
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ xf86eqEnqueue((ev))
+#else
+#define ENQUEUE(ev, code, direction, dev_type) \
+ (ev)->u.u.detail = (code); \
+ (ev)->u.u.type = (direction); \
+ mieqEnqueue((ev))
+#endif
+#define MOVEPOINTER(dx, dy, time) \
+ miPointerDeltaCursor (dx, dy, time)
+
+#endif
+
+Bool xf86VTSema = TRUE;
+
+#ifdef XINPUT
+extern InputInfo inputInfo;
+#endif /* XINPUT */
+
+/*
+ * The first of many hack's to get VT switching to work under
+ * Solaris 2.1 for x86. The basic problem is that Solaris is supposed
+ * to be SVR4. It is for the most part, except where the video interface
+ * is concerned. These hacks work around those problems.
+ * See the comments for Linux, and SCO.
+ *
+ * This is a toggleling variable:
+ * FALSE = No VT switching keys have been pressed last time around
+ * TRUE = Possible VT switch Pending
+ * (DWH - 12/2/93)
+ *
+ * This has been generalised to work with Linux and *BSD+syscons (DHD)
+ */
+
+#ifdef USE_VT_SYSREQ
+static Bool VTSysreqToggle = FALSE;
+#endif /* !USE_VT_SYSREQ */
+static Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for *BSD */
+
+extern fd_set EnabledDevices;
+
+#if defined(CODRV_SUPPORT)
+extern unsigned char xf86CodrvMap[];
+#endif
+
+#if defined(XQUEUE) && !defined(XQUEUE_ASYNC)
+extern void xf86XqueRequest(
+#if NeedFunctionPrototypes
+ void
+#endif
+ );
+#endif
+
+#ifdef DPMSExtension
+extern BOOL DPMSEnabled;
+extern void DPMSSet(CARD16);
+#endif
+
+static void xf86VTSwitch(
+#if NeedFunctionPrototypes
+ void
+#endif
+ );
+#ifdef XFreeXDGA
+static void XF86DirectVideoMoveMouse(
+#if NeedFunctionPrototypes
+ int x,
+ int y,
+ CARD32 mtime
+#endif
+ );
+static void XF86DirectVideoKeyEvent(
+#if NeedFunctionPrototypes
+ xEvent *xE,
+ int keycode,
+ int etype
+#endif
+ );
+#endif
+static CARD32 buttonTimer(
+#if NeedFunctionPrototypes
+ OsTimerPtr timer,
+ CARD32 now,
+ pointer arg
+#endif
+ );
+
+/*
+ * Lets create a simple finite-state machine:
+ *
+ * state[?][0]: action1
+ * state[?][1]: action2
+ * state[?][2]: next state
+ *
+ * action > 0: ButtonPress
+ * action = 0: nothing
+ * action < 0: ButtonRelease
+ *
+ * Why this stuff ??? Normally you cannot press both mousebuttons together, so
+ * the mouse reports both pressed at the same time ...
+ */
+
+static char stateTab[48][3] = {
+
+/* nothing pressed */
+ { 0, 0, 0 },
+ { 0, 0, 8 }, /* 1 right -> delayed right */
+ { 0, 0, 0 }, /* 2 nothing */
+ { 0, 0, 8 }, /* 3 right -> delayed right */
+ { 0, 0, 16 }, /* 4 left -> delayed left */
+ { 2, 0, 24 }, /* 5 left & right (middle press) -> middle pressed */
+ { 0, 0, 16 }, /* 6 left -> delayed left */
+ { 2, 0, 24 }, /* 7 left & right (middle press) -> middle pressed */
+
+/* delayed right */
+ { 1, -1, 0 }, /* 8 nothing (right event) -> init */
+ { 1, 0, 32 }, /* 9 right (right press) -> right pressed */
+ { 1, -1, 0 }, /* 10 nothing (right event) -> init */
+ { 1, 0, 32 }, /* 11 right (right press) -> right pressed */
+ { 1, -1, 16 }, /* 12 left (right event) -> delayed left */
+ { 2, 0, 24 }, /* 13 left & right (middle press) -> middle pressed */
+ { 1, -1, 16 }, /* 14 left (right event) -> delayed left */
+ { 2, 0, 24 }, /* 15 left & right (middle press) -> middle pressed */
+
+/* delayed left */
+ { 3, -3, 0 }, /* 16 nothing (left event) -> init */
+ { 3, -3, 8 }, /* 17 right (left event) -> delayed right */
+ { 3, -3, 0 }, /* 18 nothing (left event) -> init */
+ { 3, -3, 8 }, /* 19 right (left event) -> delayed right */
+ { 3, 0, 40 }, /* 20 left (left press) -> pressed left */
+ { 2, 0, 24 }, /* 21 left & right (middle press) -> pressed middle */
+ { 3, 0, 40 }, /* 22 left (left press) -> pressed left */
+ { 2, 0, 24 }, /* 23 left & right (middle press) -> pressed middle */
+
+/* pressed middle */
+ { -2, 0, 0 }, /* 24 nothing (middle release) -> init */
+ { -2, 0, 0 }, /* 25 right (middle release) -> init */
+ { -2, 0, 0 }, /* 26 nothing (middle release) -> init */
+ { -2, 0, 0 }, /* 27 right (middle release) -> init */
+ { -2, 0, 0 }, /* 28 left (middle release) -> init */
+ { 0, 0, 24 }, /* 29 left & right -> pressed middle */
+ { -2, 0, 0 }, /* 30 left (middle release) -> init */
+ { 0, 0, 24 }, /* 31 left & right -> pressed middle */
+
+/* pressed right */
+ { -1, 0, 0 }, /* 32 nothing (right release) -> init */
+ { 0, 0, 32 }, /* 33 right -> pressed right */
+ { -1, 0, 0 }, /* 34 nothing (right release) -> init */
+ { 0, 0, 32 }, /* 35 right -> pressed right */
+ { -1, 0, 16 }, /* 36 left (right release) -> delayed left */
+ { -1, 2, 24 }, /* 37 left & right (r rel, m prs) -> middle pressed */
+ { -1, 0, 16 }, /* 38 left (right release) -> delayed left */
+ { -1, 2, 24 }, /* 39 left & right (r rel, m prs) -> middle pressed */
+
+/* pressed left */
+ { -3, 0, 0 }, /* 40 nothing (left release) -> init */
+ { -3, 0, 8 }, /* 41 right (left release) -> delayed right */
+ { -3, 0, 0 }, /* 42 nothing (left release) -> init */
+ { -3, 0, 8 }, /* 43 right (left release) -> delayed right */
+ { 0, 0, 40 }, /* 44 left -> left pressed */
+ { -3, 2, 24 }, /* 45 left & right (l rel, mprs) -> middle pressed */
+ { 0, 0, 40 }, /* 46 left -> left pressed */
+ { -3, 2, 24 }, /* 47 left & right (l rel, mprs) -> middle pressed */
+};
+
+
+/*
+ * Table to allow quick reversal of natural button mapping to correct mapping
+ */
+
+/*
+ * [JCH-96/01/21] The ALPS GlidePoint pad extends the MS protocol
+ * with a fourth button activated by tapping the PAD.
+ * The 2nd line corresponds to 4th button on; the drv sends
+ * the buttons in the following map (MSBit described first) :
+ * 0 | 4th | 1st | 2nd | 3rd
+ * And we remap them (MSBit described first) :
+ * 0 | 4th | 3rd | 2nd | 1st
+ */
+static char reverseMap[32] = { 0, 4, 2, 6, 1, 5, 3, 7,
+ 8, 12, 10, 14, 9, 13, 11, 15,
+ 16, 20, 18, 22, 17, 21, 19, 23,
+ 24, 28, 26, 30, 25, 29, 27, 31};
+
+
+static char hitachMap[16] = { 0, 2, 1, 3,
+ 8, 10, 9, 11,
+ 4, 6, 5, 7,
+ 12, 14, 13, 15 };
+
+#define reverseBits(map, b) (((b) & ~0x0f) | map[(b) & 0x0f])
+
+
+/*
+ * TimeSinceLastInputEvent --
+ * Function used for screensaver purposes by the os module. Retruns the
+ * time in milliseconds since there last was any input.
+ */
+
+int
+TimeSinceLastInputEvent()
+{
+ if (xf86Info.lastEventTime == 0) {
+ xf86Info.lastEventTime = GetTimeInMillis();
+ }
+ return GetTimeInMillis() - xf86Info.lastEventTime;
+}
+
+
+
+/*
+ * SetTimeSinceLastInputEvent --
+ * Set the lastEventTime to now.
+ */
+
+void
+SetTimeSinceLastInputEvent()
+{
+ xf86Info.lastEventTime = GetTimeInMillis();
+}
+
+
+
+/*
+ * ProcessInputEvents --
+ * Retrieve all waiting input events and pass them to DIX in their
+ * correct chronological order. Only reads from the system pointer
+ * and keyboard.
+ */
+
+void
+ProcessInputEvents ()
+{
+ int x, y;
+#ifdef INHERIT_LOCK_STATE
+ static int generation = 0;
+#endif
+
+#ifdef AMOEBA
+#define MAXEVENTS 32
+#define BUTTON_PRESS 0x1000
+#define MAP_BUTTON(ev,but) (((ev) == EV_ButtonPress) ? \
+ ((but) | BUTTON_PRESS) : ((but) & ~BUTTON_PRESS))
+#define KEY_RELEASE 0x80
+#define MAP_KEY(ev, key) (((ev) == EV_KeyReleaseEvent) ? \
+ ((key) | KEY_RELEASE) : ((key) & ~KEY_RELEASE))
+
+ register IOPEvent *e, *elast;
+ IOPEvent events[MAXEVENTS];
+ int dx, dy, nevents;
+#endif
+
+ /*
+ * With INHERIT_LOCK_STATE defined, the initial state of CapsLock, NumLock
+ * and ScrollLock will be set to match that of the VT the server is
+ * running on.
+ */
+#ifdef INHERIT_LOCK_STATE
+ if (generation != serverGeneration) {
+ xEvent kevent;
+ DevicePtr pKeyboard = xf86Info.pKeyboard;
+ extern unsigned int xf86InitialCaps, xf86InitialNum, xf86InitialScroll;
+
+ generation = serverGeneration;
+ kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ kevent.u.keyButtonPointer.rootX = 0;
+ kevent.u.keyButtonPointer.rootY = 0;
+ kevent.u.u.type = KeyPress;
+
+
+ if (xf86InitialCaps) {
+ kevent.u.u.detail = xf86InitialCaps;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialCaps = 0;
+ }
+ if (xf86InitialNum) {
+ kevent.u.u.detail = xf86InitialNum;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialNum = 0;
+ }
+ if (xf86InitialScroll) {
+ kevent.u.u.detail = xf86InitialScroll;
+ (* pKeyboard->processInputProc)(&kevent, (DeviceIntPtr)pKeyboard, 1);
+ xf86InitialScroll = 0;
+ }
+ }
+#endif
+
+#ifdef AMOEBA
+ /*
+ * Get all events from the IOP server
+ */
+ while ((nevents = AmoebaGetEvents(events, MAXEVENTS)) > 0) {
+ for (e = &events[0], elast = &events[nevents]; e < elast; e++) {
+ xf86Info.lastEventTime = e->time;
+ switch (e->type) {
+ case EV_PointerDelta:
+ if (e->x != 0 || e->y != 0) {
+ xf86PostMseEvent(&xf86Info.pMouse, 0, e->x, e->y);
+ }
+ break;
+ case EV_ButtonPress:
+ case EV_ButtonRelease:
+ xf86PostMseEvent(&xf86Info.pMouse, MAP_BUTTON(e->type, e->keyorbut), 0, 0);
+ break;
+ case EV_KeyPressEvent:
+ case EV_KeyReleaseEvent:
+ xf86PostKbdEvent(MAP_KEY(e->type, e->keyorbut));
+ break;
+ default:
+ /* this shouldn't happen */
+ ErrorF("stray event %d (%d,%d) %x\n",
+ e->type, e->x, e->y, e->keyorbut);
+ break;
+ }
+ }
+ }
+#endif
+
+ xf86Info.inputPending = FALSE;
+
+#ifdef XINPUT
+ xf86eqProcessInputEvents();
+#else
+ mieqProcessInputEvents();
+#endif
+ miPointerUpdate();
+
+ miPointerPosition(&x, &y);
+ xf86SetViewport(xf86Info.currentScreen, x, y);
+}
+
+
+
+/*
+ * xf86PostKbdEvent --
+ * Translate the raw hardware KbdEvent into an XEvent, and tell DIX
+ * about it. Scancode preprocessing and so on is done ...
+ *
+ * OS/2 specific xf86PostKbdEvent(key) has been moved to os-support/os2/os2_kbd.c
+ * as some things differ, and I did not want to scatter this routine with
+ * ifdefs further (hv).
+ */
+
+#ifdef ASSUME_CUSTOM_KEYCODES
+extern u_char SpecialServerMap[];
+#endif /* ASSUME_CUSTOM_KEYCODES */
+
+#if !defined(__EMX__)
+void
+xf86PostKbdEvent(key)
+ unsigned key;
+{
+ int scanCode = (key & 0x7f);
+ int specialkey;
+ Bool down = (key & 0x80 ? FALSE : TRUE);
+ KeyClassRec *keyc = ((DeviceIntPtr)xf86Info.pKeyboard)->key;
+ Bool updateLeds = FALSE;
+ Bool UsePrefix = FALSE;
+ Bool Direction = FALSE;
+ xEvent kevent;
+ KeySym *keysym;
+ int keycode;
+ static int lockkeys = 0;
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ static Bool first_time = TRUE;
+#endif
+
+#if defined(CODRV_SUPPORT)
+ if (xf86Info.consType == CODRV011 || xf86Info.consType == CODRV01X)
+ scanCode = xf86CodrvMap[scanCode];
+#endif
+
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ if (first_time)
+ {
+ first_time = FALSE;
+ VTSwitchEnabled = (xf86Info.consType == SYSCONS)
+ || (xf86Info.consType == PCVT);
+ }
+#endif
+
+#if defined (i386) && defined (SVR4) && !defined (PC98)
+ /*
+ * PANIX returns DICOP standards based keycodes in using 106jp
+ * keyboard. We need to remap some keys.
+ */
+#define KEY_P_UP 0x5A
+#define KEY_P_PGUP 0x5B
+#define KEY_P_LEFT 0x5C
+#define KEY_P_BKSL 0x73
+#define KEY_P_YEN 0x7D
+#define KEY_P_NFER 0x7B
+#define KEY_P_XFER 0x79
+
+ if(xf86Info.panix106 == TRUE){
+ switch (scanCode) {
+ /* case 0x78: scanCode = KEY_P_UP; break; not needed*/
+ case 0x56: scanCode = KEY_P_BKSL; break; /* Backslash */
+ case 0x5A: scanCode = KEY_P_NFER; break; /* No Kanji Transfer*/
+ case 0x5B: scanCode = KEY_P_XFER; break; /* Kanji Tranfer */
+ case 0x5C: scanCode = KEY_P_YEN; break; /* Yen curs pgup */
+ case 0x6B: scanCode = KEY_P_LEFT; break; /* Cur Left */
+ case 0x6F: scanCode = KEY_P_PGUP; break; /* Cur PageUp */
+ case 0x72: scanCode = KEY_AltLang; break; /* AltLang(right) */
+ case 0x73: scanCode = KEY_RCtrl; break; /* not needed */
+ }
+ }
+#endif /* i386 && SVR4 */
+
+#ifndef ASSUME_CUSTOM_KEYCODES
+ /*
+ * First do some special scancode remapping ...
+ */
+ if (xf86Info.scanPrefix == 0) {
+
+ switch (scanCode) {
+
+#ifndef PC98
+ case KEY_Prefix0:
+ case KEY_Prefix1:
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ if (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS
+ || xf86Info.consType == PCVT) {
+#endif
+ xf86Info.scanPrefix = scanCode; /* special prefixes */
+ return;
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ }
+ break;
+#endif
+#endif /* not PC98 */
+ }
+#ifndef PC98
+ if (xf86Info.serverNumLock) {
+ if ((!xf86Info.numLock && ModifierDown(ShiftMask)) ||
+ (xf86Info.numLock && !ModifierDown(ShiftMask))) {
+ /*
+ * Hardwired numlock handling ... (Some applications break if they have
+ * these keys double defined, like twm)
+ */
+ switch (scanCode) {
+ case KEY_KP_7: scanCode = KEY_SN_KP_7; break; /* curs 7 */
+ case KEY_KP_8: scanCode = KEY_SN_KP_8; break; /* curs 8 */
+ case KEY_KP_9: scanCode = KEY_SN_KP_9; break; /* curs 9 */
+ case KEY_KP_4: scanCode = KEY_SN_KP_4; break; /* curs 4 */
+ case KEY_KP_5: scanCode = KEY_SN_KP_5; break; /* curs 5 */
+ case KEY_KP_6: scanCode = KEY_SN_KP_6; break; /* curs 6 */
+ case KEY_KP_1: scanCode = KEY_SN_KP_1; break; /* curs 1 */
+ case KEY_KP_2: scanCode = KEY_SN_KP_2; break; /* curs 2 */
+ case KEY_KP_3: scanCode = KEY_SN_KP_3; break; /* curs 3 */
+ case KEY_KP_0: scanCode = KEY_SN_KP_0; break; /* curs 0 */
+ case KEY_KP_Decimal: scanCode = KEY_SN_KP_Dec; break; /* curs decimal */
+ }
+ } else {
+ switch (scanCode) {
+ case KEY_KP_7: scanCode = KEY_SN_KP_Home; break; /* curs home */
+ case KEY_KP_8: scanCode = KEY_SN_KP_Up ; break; /* curs up */
+ case KEY_KP_9: scanCode = KEY_SN_KP_Prior; break; /* curs pgup */
+ case KEY_KP_4: scanCode = KEY_SN_KP_Left; break; /* curs left */
+ case KEY_KP_5: scanCode = KEY_SN_KP_Begin; break; /* curs begin */
+ case KEY_KP_6: scanCode = KEY_SN_KP_Right; break; /* curs right */
+ case KEY_KP_1: scanCode = KEY_SN_KP_End; break; /* curs end */
+ case KEY_KP_2: scanCode = KEY_SN_KP_Down; break; /* curs down */
+ case KEY_KP_3: scanCode = KEY_SN_KP_Next; break; /* curs pgdn */
+ case KEY_KP_0: scanCode = KEY_SN_KP_Ins; break; /* curs ins */
+ case KEY_KP_Decimal: scanCode = KEY_SN_KP_Del; break; /* curs del */
+ }
+ }
+ }
+#endif /* not PC98 */
+ }
+
+#ifndef PC98
+ else if (
+#ifdef CSRG_BASED
+ (xf86Info.consType == PCCONS || xf86Info.consType == SYSCONS
+ || xf86Info.consType == PCVT) &&
+#endif
+ (xf86Info.scanPrefix == KEY_Prefix0)) {
+ xf86Info.scanPrefix = 0;
+
+ switch (scanCode) {
+ case KEY_KP_7: scanCode = KEY_Home; break; /* curs home */
+ case KEY_KP_8: scanCode = KEY_Up; break; /* curs up */
+ case KEY_KP_9: scanCode = KEY_PgUp; break; /* curs pgup */
+ case KEY_KP_4: scanCode = KEY_Left; break; /* curs left */
+ case KEY_KP_5: scanCode = KEY_Begin; break; /* curs begin */
+ case KEY_KP_6: scanCode = KEY_Right; break; /* curs right */
+ case KEY_KP_1: scanCode = KEY_End; break; /* curs end */
+ case KEY_KP_2: scanCode = KEY_Down; break; /* curs down */
+ case KEY_KP_3: scanCode = KEY_PgDown; break; /* curs pgdown */
+ case KEY_KP_0: scanCode = KEY_Insert; break; /* curs insert */
+ case KEY_KP_Decimal: scanCode = KEY_Delete; break; /* curs delete */
+ case KEY_Enter: scanCode = KEY_KP_Enter; break; /* keypad enter */
+ case KEY_LCtrl: scanCode = KEY_RCtrl; break; /* right ctrl */
+ case KEY_KP_Multiply: scanCode = KEY_Print; break; /* print */
+ case KEY_Slash: scanCode = KEY_KP_Divide; break; /* keyp divide */
+ case KEY_Alt: scanCode = KEY_AltLang; break; /* right alt */
+ case KEY_ScrollLock: scanCode = KEY_Break; break; /* curs break */
+ case 0x5b: scanCode = KEY_LMeta; break;
+ case 0x5c: scanCode = KEY_RMeta; break;
+ case 0x5d: scanCode = KEY_Menu; break;
+ case KEY_F3: scanCode = KEY_F13; break;
+ case KEY_F4: scanCode = KEY_F14; break;
+ case KEY_F5: scanCode = KEY_F15; break;
+ case KEY_F6: scanCode = KEY_F16; break;
+ case KEY_F7: scanCode = KEY_F17; break;
+ case KEY_KP_Plus: scanCode = KEY_KP_DEC; break;
+ /*
+ * Ignore virtual shifts (E0 2A, E0 AA, E0 36, E0 B6)
+ */
+ default:
+ return; /* skip illegal */
+ }
+ }
+
+ else if (xf86Info.scanPrefix == KEY_Prefix1)
+ {
+ xf86Info.scanPrefix = (scanCode == KEY_LCtrl) ? KEY_LCtrl : 0;
+ return;
+ }
+
+ else if (xf86Info.scanPrefix == KEY_LCtrl)
+ {
+ xf86Info.scanPrefix = 0;
+ if (scanCode != KEY_NumLock) return;
+ scanCode = KEY_Pause; /* pause */
+ }
+#endif /* not PC98 */
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+
+ /*
+ * and now get some special keysequences
+ */
+
+#ifdef ASSUME_CUSTOM_KEYCODES
+ specialkey = SpecialServerMap[scanCode];
+#else /* ASSUME_CUSTOM_KEYCODES */
+ specialkey = scanCode;
+#endif /* ASSUME_CUSTOM_KEYCODES */
+
+ if ((ModifierDown(ControlMask | AltMask)) ||
+ (ModifierDown(ControlMask | AltLangMask)))
+ {
+
+ switch (specialkey) {
+
+ case KEY_BackSpace:
+ if (!xf86Info.dontZap) {
+#ifdef XFreeXDGA
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics)
+ break;
+#endif
+ GiveUp(0);
+ }
+ break;
+
+ /*
+ * The idea here is to pass the scancode down to a list of
+ * registered routines. There should be some standard conventions
+ * for processing certain keys.
+ */
+ case KEY_KP_Minus: /* Keypad - */
+ if (!xf86Info.dontZoom) {
+ if (down) xf86ZoomViewport(xf86Info.currentScreen, -1);
+ return;
+ }
+ break;
+
+ case KEY_KP_Plus: /* Keypad + */
+ if (!xf86Info.dontZoom) {
+ if (down) xf86ZoomViewport(xf86Info.currentScreen, 1);
+ return;
+ }
+ break;
+
+#if defined(linux) || (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT))) || defined(SCO)
+ /*
+ * Under Linux, the raw keycodes are consumed before the kernel
+ * does any processing on them, so we must emulate the vt switching
+ * we want ourselves.
+ */
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSwitchEnabled && !xf86Info.vtSysreq
+#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)))
+ && (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)
+#endif
+ )
+ {
+ if (down)
+#ifdef SCO325
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F1);
+#else
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F1 + 1);
+#endif
+ return;
+ }
+ break;
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSwitchEnabled && !xf86Info.vtSysreq
+#if (defined(CSRG_BASED) && (defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)))
+ && (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)
+#endif
+ )
+ {
+ if (down)
+#ifdef SCO325
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F11 + 10);
+#else
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey - KEY_F11 + 11);
+#endif
+ return;
+ }
+ break;
+#endif /* linux || BSD with VTs */
+
+ /* just worth mentioning here: any 386bsd keyboard driver
+ * (pccons.c or co_kbd.c) catches CTRL-ALT-DEL and CTRL-ALT-ESC
+ * before any application (e.g. XF86) will see it
+ * OBS: syscons does not, nor does pcvt !
+ */
+ }
+ }
+
+ /*
+ * Start of actual Solaris VT switching code.
+ * This should pretty much emulate standard SVR4 switching keys.
+ *
+ * DWH 12/2/93
+ */
+
+#ifdef USE_VT_SYSREQ
+ if (VTSwitchEnabled && xf86Info.vtSysreq)
+ {
+ switch (specialkey)
+ {
+ /*
+ * syscons on *BSD doesn't have a VT #0 -- don't think Linux does
+ * either
+ */
+#if defined (sun) && defined (i386) && defined (SVR4)
+ case KEY_H:
+ if (VTSysreqToggle && down)
+ {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0);
+ VTSysreqToggle = 0;
+ return;
+ }
+ break;
+
+ /*
+ * Yah, I know the N, and P keys seem backwards, however that's
+ * how they work under Solaris
+ * XXXX N means go to next active VT not necessarily vtno+1 (or vtno-1)
+ */
+
+ case KEY_N:
+ if (VTSysreqToggle && down)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno - 1 ) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+
+ case KEY_P:
+ if (VTSysreqToggle && down)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1 ) < 0)
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+#endif
+
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ if (VTSysreqToggle && down)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey-KEY_F1 + 1) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+
+ case KEY_F11:
+ case KEY_F12:
+ if (VTSysreqToggle && down)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, specialkey-KEY_F11 + 11) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ VTSysreqToggle = FALSE;
+ return;
+ }
+ break;
+
+ /* Ignore these keys -- ie don't let them cancel an alt-sysreq */
+ case KEY_Alt:
+#ifndef PC98
+ case KEY_AltLang:
+#endif /* not PC98 */
+ break;
+
+#ifndef PC98
+ case KEY_SysReqest:
+ if (down && (ModifierDown(AltMask) || ModifierDown(AltLangMask)))
+ VTSysreqToggle = TRUE;
+ break;
+#endif /* not PC98 */
+
+ default:
+ if (VTSysreqToggle)
+ {
+ /*
+ * We only land here when Alt-SysReq is followed by a
+ * non-switching key.
+ */
+ VTSysreqToggle = FALSE;
+
+ }
+ }
+ }
+
+#endif /* USE_VT_SYSREQ */
+
+#ifdef SCO
+ /*
+ * With the console in raw mode, SCO will not switch consoles,
+ * you get around this by activating the next console along, if
+ * this fails then go back to console 0, if there is only one
+ * then it doesn't matter, switching to yourself is a nop as far
+ * as the console driver is concerned.
+ * We could do something similar to linux here but SCO ODT uses
+ * Ctrl-PrintScrn, so why change?
+ */
+ if (specialkey == KEY_Print && ModifierDown(ControlMask)) {
+ if (down)
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno + 1) < 0)
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 0) < 0)
+ ErrorF("Failed to switch consoles (%s)\n", strerror(errno));
+ return;
+ }
+#endif /* SCO */
+
+ /*
+ * Now map the scancodes to real X-keycodes ...
+ */
+ keycode = scanCode + MIN_KEYCODE;
+ keysym = (keyc->curKeySyms.map +
+ keyc->curKeySyms.mapWidth *
+ (keycode - keyc->curKeySyms.minKeyCode));
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ /*
+ * Filter autorepeated caps/num/scroll lock keycodes.
+ */
+#define CAPSFLAG 0x01
+#define NUMFLAG 0x02
+#define SCROLLFLAG 0x04
+#define MODEFLAG 0x08
+ if( down ) {
+ switch( keysym[0] ) {
+ case XK_Caps_Lock :
+ if (lockkeys & CAPSFLAG)
+ return;
+ else
+ lockkeys |= CAPSFLAG;
+ break;
+
+ case XK_Num_Lock :
+ if (lockkeys & NUMFLAG)
+ return;
+ else
+ lockkeys |= NUMFLAG;
+ break;
+
+ case XK_Scroll_Lock :
+ if (lockkeys & SCROLLFLAG)
+ return;
+ else
+ lockkeys |= SCROLLFLAG;
+ break;
+ }
+ if (keysym[1] == XF86XK_ModeLock)
+ {
+ if (lockkeys & MODEFLAG)
+ return;
+ else
+ lockkeys |= MODEFLAG;
+ }
+
+ }
+ else {
+ switch( keysym[0] ) {
+ case XK_Caps_Lock :
+ lockkeys &= ~CAPSFLAG;
+ break;
+
+ case XK_Num_Lock :
+ lockkeys &= ~NUMFLAG;
+ break;
+
+ case XK_Scroll_Lock :
+ lockkeys &= ~SCROLLFLAG;
+ break;
+ }
+ if (keysym[1] == XF86XK_ModeLock)
+ lockkeys &= ~MODEFLAG;
+ }
+
+ /*
+ * LockKey special handling:
+ * ignore releases, toggle on & off on presses.
+ * Don't deal with the Caps_Lock keysym directly, but check the lock modifier
+ */
+#ifndef PC98
+ if (keyc->modifierMap[keycode] & LockMask ||
+ keysym[0] == XK_Scroll_Lock ||
+ keysym[1] == XF86XK_ModeLock ||
+ keysym[0] == XK_Num_Lock)
+ {
+ Bool flag;
+
+ if (!down) return;
+ if (KeyPressed(keycode)) {
+ down = !down;
+ flag = FALSE;
+ }
+ else
+ flag = TRUE;
+
+ if (keyc->modifierMap[keycode] & LockMask) xf86Info.capsLock = flag;
+ if (keysym[0] == XK_Num_Lock) xf86Info.numLock = flag;
+ if (keysym[0] == XK_Scroll_Lock) xf86Info.scrollLock = flag;
+ if (keysym[1] == XF86XK_ModeLock) xf86Info.modeSwitchLock = flag;
+ updateLeds = TRUE;
+ }
+#endif /* not PC98 */
+
+#ifndef ASSUME_CUSTOM_KEYCODES
+ /*
+ * normal, non-keypad keys
+ */
+ if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) {
+#if !defined(CSRG_BASED) && !defined(MACH386) && !defined(MINIX) && !defined(__OSF__)
+ /*
+ * magic ALT_L key on AT84 keyboards for multilingual support
+ */
+ if (xf86Info.kbdType == KB_84 &&
+ ModifierDown(AltMask) &&
+ keysym[2] != NoSymbol)
+ {
+ UsePrefix = TRUE;
+ Direction = TRUE;
+ }
+#endif /* !CSRG_BASED && !MACH386 && !MINIX && !__OSF__ */
+ }
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+ if (updateLeds) xf86KbdLeds();
+#ifdef XKB
+ }
+#endif
+
+ /*
+ * check for an autorepeat-event
+ */
+ if ((down && KeyPressed(keycode)) &&
+ (xf86Info.autoRepeat != AutoRepeatModeOn || keyc->modifierMap[keycode]))
+ return;
+
+ xf86Info.lastEventTime = kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ /*
+ * And now send these prefixes ...
+ * NOTE: There cannot be multiple Mode_Switch keys !!!!
+ */
+ if (UsePrefix)
+ {
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ (Direction ? KeyPress : KeyRelease),
+ XE_KEYBOARD);
+ ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD);
+ ENQUEUE(&kevent,
+ keyc->modifierKeyMap[keyc->maxKeysPerModifier*7],
+ (Direction ? KeyRelease : KeyPress),
+ XE_KEYBOARD);
+ }
+ else
+ {
+#ifdef XFreeXDGA
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectKeyb) {
+ XF86DirectVideoKeyEvent(&kevent, keycode, (down ? KeyPress : KeyRelease));
+ } else
+#endif
+ {
+ ENQUEUE(&kevent, keycode, (down ? KeyPress : KeyRelease), XE_KEYBOARD);
+
+ }
+ }
+}
+#endif /* !__EMX__ */
+
+
+static CARD32
+buttonTimer(timer, now, arg)
+ OsTimerPtr timer;
+ CARD32 now;
+ pointer arg;
+{
+ MouseDevPtr priv = MOUSE_DEV((DeviceIntPtr) arg);
+
+ xf86PostMseEvent(((DeviceIntPtr) arg), priv->truebuttons, 0, 0);
+ return(0);
+}
+
+
+/*
+ * xf86PostMseEvent --
+ * Translate the raw hardware MseEvent into an XEvent(s), and tell DIX
+ * about it. Perform a 3Button emulation if required.
+ */
+
+void
+xf86PostMseEvent(device, buttons, dx, dy)
+ DeviceIntPtr device;
+ int buttons, dx, dy;
+{
+ static OsTimerPtr timer = NULL;
+ MouseDevPtr private = MOUSE_DEV(device);
+ int id, change;
+ int truebuttons;
+ xEvent mevent[2];
+#ifdef XINPUT
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer *) mevent;
+ deviceValuator *xv = (deviceValuator *) (xev+1);
+ int is_pointer; /* the mouse is the pointer ? */
+#endif
+
+#ifdef AMOEBA
+ int pressed;
+
+ pressed = ((buttons & BUTTON_PRESS) != 0);
+ buttons &= ~BUTTON_PRESS;
+#endif
+
+#ifdef XINPUT
+ is_pointer = xf86IsCorePointer(device);
+
+ if (!is_pointer) {
+ xev->time = xf86Info.lastEventTime = GetTimeInMillis();
+ }
+ else
+#endif
+ xf86Info.lastEventTime = mevent->u.keyButtonPointer.time = GetTimeInMillis();
+
+ truebuttons = buttons;
+ if (private->mseType == P_MMHIT)
+ buttons = reverseBits(hitachMap, buttons);
+ else
+ buttons = reverseBits(reverseMap, buttons);
+
+ if (dx || dy) {
+
+ /*
+ * accelerate the baby now if sqrt(dx*dx + dy*dy) > threshold !
+ * but do some simpler arithmetic here...
+ */
+ if ((abs(dx) + abs(dy)) >= private->threshold) {
+ dx = (dx * private->num) / private->den;
+ dy = (dy * private->num)/ private->den;
+ }
+
+#ifdef XINPUT
+ if (is_pointer) {
+#endif
+#ifdef XFreeXDGA
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectMouse) {
+ XF86DirectVideoMoveMouse(dx, dy, mevent->u.keyButtonPointer.time);
+ } else
+#endif
+ {
+ MOVEPOINTER(dx, dy, mevent->u.keyButtonPointer.time);
+ }
+#ifdef XINPUT
+ }
+ else {
+ xev->type = DeviceMotionNotify;
+ xev->deviceid = device->id | MORE_EVENTS;
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->num_valuators = 2;
+ xv->first_valuator = 0;
+ xv->device_state = 0;
+ xv->valuator0 = dx;
+ xv->valuator1 = dy;
+ xf86eqEnqueue(mevent);
+ }
+#endif
+ }
+
+ if (private->emulate3Buttons)
+ {
+
+ /*
+ * Hack to operate the middle button even with Emulate3Buttons set.
+ * Modifying the state table to keep track of the middle button state
+ * would nearly double its size, so I'll stick with this fix. - TJW
+ */
+ if (private->mseType == P_MMHIT)
+ change = buttons ^ reverseBits(hitachMap, private->lastButtons);
+ else
+ change = buttons ^ reverseBits(reverseMap, private->lastButtons);
+ if (change & 02)
+ {
+#ifdef XINPUT
+ if (xf86CheckButton(2, (buttons & 02))) {
+#endif
+ ENQUEUE(mevent,
+ 2, (buttons & 02) ? ButtonPress : ButtonRelease,
+ XE_POINTER);
+#ifdef XINPUT
+ }
+#endif
+ }
+
+ /*
+ * emulate the third button by the other two
+ */
+ if ((id = stateTab[buttons + private->emulateState][0]) != 0)
+ {
+#ifdef XINPUT
+ if (is_pointer) {
+ if (xf86CheckButton(abs(id), (id >= 0))) {
+#endif
+ ENQUEUE(mevent,
+ abs(id), (id < 0 ? ButtonRelease : ButtonPress),
+ XE_POINTER);
+#ifdef XINPUT
+ }
+ }
+ else {
+ xev->type = (id < 0 ? DeviceButtonRelease : DeviceButtonPress);
+ xev->deviceid = device->id | MORE_EVENTS;
+ xev->detail = abs(id);
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->num_valuators = 0;
+ xv->device_state = 0;
+ xf86eqEnqueue(mevent);
+ }
+#endif
+ }
+
+ if ((id = stateTab[buttons + private->emulateState][1]) != 0)
+ {
+#ifdef XINPUT
+ if (is_pointer) {
+ if (xf86CheckButton(abs(id), (id >= 0))) {
+#endif
+ ENQUEUE(mevent,
+ abs(id), (id < 0 ? ButtonRelease : ButtonPress),
+ XE_POINTER);
+#ifdef XINPUT
+ }
+ }
+ else {
+ xev->type = (id < 0 ? DeviceButtonRelease : DeviceButtonPress);
+ xev->deviceid = device->id | MORE_EVENTS;
+ xev->detail = abs(id);
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->num_valuators = 0;
+ xv->device_state = 0;
+ xf86eqEnqueue(mevent);
+ }
+#endif
+ }
+
+ private->emulateState = stateTab[buttons + private->emulateState][2];
+ if (stateTab[buttons + private->emulateState][0] ||
+ stateTab[buttons + private->emulateState][1])
+ {
+ private->truebuttons = truebuttons;
+ timer = TimerSet(timer, 0, private->emulate3Timeout, buttonTimer,
+ (pointer)device);
+ }
+ else
+ {
+ if (timer)
+ {
+ TimerFree(timer);
+ timer = NULL;
+ }
+ }
+ }
+ else
+ {
+#ifdef AMOEBA
+ if (truebuttons != 0) {
+#ifdef XINPUT
+ if (is_pointer) {
+ if (xf86CheckButton(truebuttons)) {
+#endif
+ ENQUEUE(mevent,
+ truebuttons, (pressed ? ButtonPress : ButtonRelease),
+ XE_POINTER);
+#ifdef XINPUT
+ }
+ }
+ else {
+ xev->type = pressed ? DeviceButtonPress : DeviceButtonRelease;
+ xev->deviceid = device->id | MORE_EVENTS;
+ xev->detail = truebuttons;
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->num_valuators = 0;
+ xv->device_state = 0;
+ xf86eqEnqueue(mevent);
+ }
+#endif
+ }
+#else
+ /*
+ * real three button event
+ * Note that xf86Info.lastButtons has the hardware button mapping which
+ * is the reverse of the button mapping reported to the server.
+ */
+ if (private->mseType == P_MMHIT)
+ change = buttons ^ reverseBits(hitachMap, private->lastButtons);
+ else
+ change = buttons ^ reverseBits(reverseMap, private->lastButtons);
+ while (change)
+ {
+ id = ffs(change);
+ change &= ~(1 << (id-1));
+#ifdef XINPUT
+ if (is_pointer) {
+ if (xf86CheckButton(id, (buttons&(1<<(id-1))))) {
+#endif
+ ENQUEUE(mevent,
+ id, (buttons&(1<<(id-1)))? ButtonPress : ButtonRelease,
+ XE_POINTER);
+#ifdef XINPUT
+ }
+ }
+ else {
+ xev->type = (buttons&(1<<(id-1)))? DeviceButtonPress : DeviceButtonRelease;
+ xev->deviceid = device->id | MORE_EVENTS;
+ xev->detail = id;
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->num_valuators = 0;
+ xv->device_state = 0;
+ xf86eqEnqueue(mevent);
+ }
+#endif
+ }
+#endif
+ }
+ private->lastButtons = truebuttons;
+}
+
+
+
+/*
+ * xf86Block --
+ * Os block handler.
+ */
+
+/* ARGSUSED */
+void
+xf86Block(blockData, pTimeout, pReadmask)
+ pointer blockData;
+ OSTimePtr pTimeout;
+ pointer pReadmask;
+{
+}
+
+
+#ifndef AMOEBA
+
+/*
+ * xf86Wakeup --
+ * Os wakeup handler.
+ */
+
+/* ARGSUSED */
+void
+xf86Wakeup(blockData, err, pReadmask)
+ pointer blockData;
+ int err;
+ pointer pReadmask;
+{
+
+#ifndef __EMX__
+#ifdef __OSF__
+ fd_set kbdDevices;
+ fd_set mseDevices;
+#endif /* __OSF__ */
+ fd_set* LastSelectMask = (fd_set*)pReadmask;
+ fd_set devicesWithInput;
+
+ if ((int)err >= 0) {
+ XFD_ANDSET(&devicesWithInput, LastSelectMask, &EnabledDevices);
+#ifdef __OSF__
+ /*
+ * Until the two devices are made nonblock on read, we have to do this.
+ */
+
+ MASKANDSETBITS(devicesWithInput, pReadmask, EnabledDevices);
+
+ CLEARBITS(kbdDevices);
+ BITSET(kbdDevices, xf86Info.consoleFd);
+ MASKANDSETBITS(kbdDevices, kbdDevices, devicesWithInput);
+
+ CLEARBITS(mseDevices);
+ BITSET(mseDevices, xf86Info.mouseDev->mseFd);
+ MASKANDSETBITS(mseDevices, mseDevices, devicesWithInput);
+
+ if (ANYSET(kbdDevices) || xf86Info.kbdRate)
+ (xf86Info.kbdEvents)(ANYSET(kbdDevices));
+ if (ANYSET(mseDevices))
+ (xf86Info.mouseDev->mseEvents)(1);
+
+#else
+ if (XFD_ANYSET(&devicesWithInput))
+ {
+ (xf86Info.kbdEvents)();
+ (xf86Info.mouseDev->mseEvents)(xf86Info.mouseDev);
+ }
+#endif /* __OSF__ */
+ }
+#else /* __EMX__ */
+
+ (xf86Info.kbdEvents)(); /* Under OS/2, always call */
+ (xf86Info.mouseDev->mseEvents)(xf86Info.mouseDev);
+
+#endif /* __EMX__ */
+
+#if defined(XQUEUE) && !defined(XQUEUE_ASYNC)
+ /* This could be done more cleanly */
+ if (xf86Info.mouseDev->xqueSema && xf86Info.mouseDev->xquePending)
+ xf86XqueRequest();
+#endif
+
+ if (xf86VTSwitchPending()) xf86VTSwitch();
+
+ if (xf86Info.inputPending) ProcessInputEvents();
+}
+
+#endif /* AMOEBA */
+
+
+/*
+ * xf86SigHandler --
+ * Catch unexpected signals and exit cleanly.
+ */
+void
+xf86SigHandler(signo)
+ int signo;
+{
+ signal(signo,SIG_IGN);
+ xf86Info.caughtSignal = TRUE;
+ FatalError("Caught signal %d. Server aborting\n", signo);
+}
+
+/*
+ * xf86VTSwitch --
+ * Handle requests for switching the vt.
+ */
+static void
+xf86VTSwitch()
+{
+ int j;
+
+#ifdef XFreeXDGA
+ /*
+ * Not ideal, but until someone adds DGA events to the DGA client we
+ * should protect the machine
+ */
+ if (((ScrnInfoPtr)(xf86Info.currentScreen->devPrivates[xf86ScreenIndex].ptr))->directMode&XF86DGADirectGraphics) {
+ xf86Info.vtRequestsPending = FALSE;
+ return;
+ }
+#endif
+ if (xf86VTSema) {
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(LEAVE, j);
+
+#ifndef __EMX__
+ DisableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ DisableDevice((DeviceIntPtr)xf86Info.pMouse);
+#endif
+
+ if (!xf86VTSwitchAway()) {
+ /*
+ * switch failed
+ */
+
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j);
+ SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
+#ifdef DPMSExtension
+ if (DPMSEnabled)
+ DPMSSet(DPMSModeOn);
+#endif
+
+#ifndef __EMX__
+ EnableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ EnableDevice((DeviceIntPtr)xf86Info.pMouse);
+#endif
+
+ } else {
+ xf86VTSema = FALSE;
+ }
+ } else {
+ if (!xf86VTSwitchTo()) return;
+
+ xf86VTSema = TRUE;
+ for (j = 0; j < screenInfo.numScreens; j++)
+ (XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j);
+
+ /* Turn screen saver off when switching back */
+ SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
+#ifdef DPMSExtension
+ if (DPMSEnabled)
+ DPMSSet(DPMSModeOn);
+#endif
+
+#ifndef __EMX__
+ EnableDevice((DeviceIntPtr)xf86Info.pKeyboard);
+ EnableDevice((DeviceIntPtr)xf86Info.pMouse);
+#endif
+
+ }
+}
+
+#ifdef XTESTEXT1
+
+void
+XTestGetPointerPos(fmousex, fmousey)
+ short *fmousex;
+ short *fmousey;
+{
+ int x,y;
+
+ miPointerPosition(&x, &y);
+ *fmousex = x;
+ *fmousey = y;
+}
+
+
+
+void
+XTestJumpPointer(jx, jy, dev_type)
+ int jx;
+ int jy;
+ int dev_type;
+{
+ miPointerAbsoluteCursor(jx, jy, GetTimeInMillis() );
+}
+
+
+
+void
+XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey)
+ int dev_type;
+ int keycode;
+ int keystate;
+ int mousex;
+ int mousey;
+{
+ xEvent tevent;
+
+ tevent.u.u.type = (dev_type == XE_POINTER) ?
+ (keystate == XTestKEY_UP) ? ButtonRelease : ButtonPress :
+ (keystate == XTestKEY_UP) ? KeyRelease : KeyPress;
+ tevent.u.u.detail = keycode;
+ tevent.u.keyButtonPointer.rootX = mousex;
+ tevent.u.keyButtonPointer.rootY = mousey;
+ tevent.u.keyButtonPointer.time = xf86Info.lastEventTime = GetTimeInMillis();
+#ifdef XINPUT
+ xf86eqEnqueue(&tevent);
+#else
+ mieqEnqueue(&tevent);
+#endif
+ xf86Info.inputPending = TRUE; /* virtual event */
+}
+
+#endif /* XTESTEXT1 */
+
+
+#ifdef XFreeXDGA
+static void
+XF86DirectVideoMoveMouse(x, y, mtime)
+ int x;
+ int y;
+ CARD32 mtime;
+{
+ xEvent xE;
+
+ xE.u.u.type = MotionNotify;
+ xE.u.keyButtonPointer.time = xf86Info.lastEventTime = mtime;
+ xf86Info.lastEventTime = mtime;
+
+
+ xE.u.keyButtonPointer.eventY = x;
+ xE.u.keyButtonPointer.eventY = y;
+ xE.u.keyButtonPointer.rootX = x;
+ xE.u.keyButtonPointer.rootY = y;
+
+ if (((DeviceIntPtr)(xf86Info.pMouse))->grab)
+ DeliverGrabbedEvent(&xE, (xf86Info.pMouse), FALSE, 1);
+ else
+ DeliverDeviceEvents(GetSpriteWindow(), &xE, NullGrab, NullWindow,
+ (xf86Info.pMouse), 1);
+}
+
+static void
+XF86DirectVideoKeyEvent(xE, keycode, etype)
+xEvent *xE;
+int keycode;
+int etype;
+{
+ DeviceIntPtr keybd = (DeviceIntPtr)xf86Info.pKeyboard;
+ KeyClassPtr keyc = keybd->key;
+ BYTE *kptr;
+
+ kptr = &keyc->down[keycode >> 3];
+ xE->u.u.type = etype;
+ xE->u.u.detail = keycode;
+
+ /* clear the keypress state */
+ if (etype == KeyPress) {
+ *kptr &= ~(1 << (keycode & 7));
+ }
+ keybd->public.processInputProc(xE, keybd, 1);
+}
+#endif
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
new file mode 100644
index 000000000..864933a84
--- /dev/null
+++ b/hw/xfree86/common/xf86Init.c
@@ -0,0 +1,834 @@
+/*
+ * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.66.2.2 1997/06/29 08:43:36 dawes Exp $
+ *
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $Xorg: xf86Init.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */
+
+#ifndef X_NOT_STDC_ENV
+#include <stdlib.h>
+#else
+extern int atoi();
+#endif
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xmd.h"
+#include "Xproto.h"
+#include "input.h"
+#include "servermd.h"
+#include "scrnintstr.h"
+#include "site.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "xf86Version.h"
+#include "mipointer.h"
+
+#ifdef XINPUT
+#include "XI.h"
+#include "XIproto.h"
+#include "xf86_Config.h"
+#include "xf86Xinput.h"
+#else
+#include "inputstr.h"
+#endif
+
+#include "opaque.h"
+
+#ifdef XTESTEXT1
+#include "atKeynames.h"
+extern int xtest_command_key;
+#endif /* XTESTEXT1 */
+
+#ifdef __EMX__
+#define seteuid(x) /*nothing*/
+#define setruid(x) /*nothing*/
+#endif
+
+/* xf86Exiting is set while the screen is shutting down (even on a reset) */
+Bool xf86Exiting = FALSE;
+Bool xf86Resetting = FALSE;
+Bool xf86ProbeFailed = TRUE;
+Bool xf86FlipPixels = FALSE;
+#ifdef XF86VIDMODE
+Bool xf86VidModeEnabled = TRUE;
+Bool xf86VidModeAllowNonLocal = FALSE;
+#endif
+#ifdef XF86MISC
+Bool xf86MiscModInDevEnabled = TRUE;
+Bool xf86MiscModInDevAllowNonLocal = FALSE;
+#endif
+Bool xf86AllowMouseOpenFail = FALSE;
+PciProbeType xf86PCIFlags = PCIProbe1;
+Bool xf86ScreensOpen = FALSE;
+int xf86Verbose = 1;
+Bool xf86fpFlag = FALSE;
+Bool xf86coFlag = FALSE;
+Bool xf86sFlag = FALSE;
+Bool xf86ProbeOnly = FALSE;
+char xf86ConfigFile[PATH_MAX] = "";
+int xf86bpp = -1;
+xrgb xf86weight = { 0, 0, 0 } ; /* RGB weighting at 16 bpp */
+double xf86rGamma=1.0, xf86gGamma=1.0, xf86bGamma=1.0;
+unsigned char xf86rGammaMap[256], xf86gGammaMap[256], xf86bGammaMap[256];
+char *xf86ServerName = NULL;
+Bool xf86BestRefresh = FALSE;
+
+int vgaIOBase = 0x3d0;
+int vgaCRIndex = 0x3d4;
+int vgaCRReg = 0x3d5;
+
+static void xf86PrintBanner(
+#if NeedFunctionPrototypes
+ void
+#endif
+ );
+static void xf86PrintConfig(
+#if NeedFunctionPrototypes
+ void
+#endif
+ );
+#ifdef DO_CHECK_BETA
+void xf86CheckBeta(
+#if NeedFunctionPrototypes
+ int,
+ char *
+#endif
+ );
+static int extraDays = 0;
+static char *expKey = NULL;
+#endif
+
+extern ScrnInfoPtr xf86Screens[];
+extern int xf86MaxScreens;
+extern double pow();
+#ifdef USE_XF86_SERVERLOCK
+extern void xf86UnlockServer();
+#endif
+#ifdef __EMX__
+extern void os2ServerVideoAccess();
+#endif
+
+xf86InfoRec xf86Info;
+int xf86ScreenIndex;
+
+/*
+ * InitOutput --
+ * Initialize screenInfo for all actually accessible framebuffers.
+ * That includes vt-manager setup, querying all possible devices and
+ * collecting the pixmap formats.
+ */
+
+void
+InitOutput(pScreenInfo, argc, argv)
+ ScreenInfo *pScreenInfo;
+ int argc;
+ char **argv;
+{
+ int i, j, scr_index;
+ static int numFormats = 0;
+ static PixmapFormatRec formats[MAXFORMATS];
+ static unsigned long generation = 0;
+ int any_screens = 0;
+
+#ifdef __EMX__
+ os2ServerVideoAccess(); /* See if we have access to the screen before doing anything */
+#endif
+
+ if (serverGeneration == 1) {
+
+ if ((xf86ServerName = strrchr(argv[0], '/')) != 0)
+ xf86ServerName++;
+ else
+ xf86ServerName = argv[0];
+
+#ifdef DO_CHECK_BETA
+ xf86CheckBeta(extraDays, expKey);
+#endif
+
+ xf86PrintBanner();
+
+ xf86PrintConfig();
+
+ xf86OpenConsole();
+
+#if !defined(AMOEBA) && !defined(MINIX)
+ /*
+ * If VTInit was set, run that program with consoleFd as stdin and stdout
+ */
+
+ if (xf86Info.vtinit) {
+ switch(fork()) {
+ case -1:
+ FatalError("Fork failed for VTInit (%s)\n", strerror(errno));
+ break;
+ case 0: /* child */
+ setuid(getuid());
+ /* set stdin, stdout to the consoleFd */
+ for (i = 0; i < 2; i++) {
+ if (xf86Info.consoleFd != i) {
+ close(i);
+ dup(xf86Info.consoleFd);
+ }
+ }
+ execl("/bin/sh", "sh", "-c", xf86Info.vtinit, NULL);
+ ErrorF("Warning: exec of /bin/sh failed for VTInit (%s)\n",
+ strerror(errno));
+ exit(255);
+ break;
+ default: /* parent */
+ wait(NULL);
+ }
+ }
+#endif /* !AMOEBA && !MINIX */
+
+ /* Do this after XF86Config is read (it's normally in OsInit()) */
+ OsInitColors();
+
+ for (i=0; i<256; i++) {
+ xf86rGammaMap[i] = (int)(pow(i/255.0,xf86rGamma)*255.0+0.5);
+ xf86gGammaMap[i] = (int)(pow(i/255.0,xf86gGamma)*255.0+0.5);
+ xf86bGammaMap[i] = (int)(pow(i/255.0,xf86bGamma)*255.0+0.5);
+ }
+
+ xf86Config(TRUE); /* Probe displays, and resolve modes */
+
+#ifdef XKB
+ xf86InitXkb();
+#endif
+
+ /*
+ * collect all possible formats
+ */
+ formats[0].depth = 1;
+ formats[0].bitsPerPixel = 1;
+ formats[0].scanlinePad = BITMAP_SCANLINE_PAD;
+ numFormats++;
+
+ for ( i=0;
+ i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured;
+ i++ )
+ {
+ /*
+ * At least one probe function succeeded.
+ */
+ any_screens = 1;
+
+ /*
+ * add new pixmap format
+ */
+ for ( j=0; j < numFormats; j++ ) {
+
+ if (formats[j].depth == xf86Screens[i]->depth &&
+ formats[j].bitsPerPixel == xf86Screens[i]->bitsPerPixel)
+ break; /* found */
+ }
+
+ if (j == numFormats) { /* not already there */
+ formats[j].depth = xf86Screens[i]->depth;
+ formats[j].bitsPerPixel = xf86Screens[i]->bitsPerPixel;
+ formats[j].scanlinePad = BITMAP_SCANLINE_PAD;
+ numFormats++;
+ if ( numFormats > MAXFORMATS )
+ FatalError( "Too many pixmap formats! Exiting\n" );
+ }
+ }
+ if (!any_screens)
+ if (xf86ProbeFailed)
+ ErrorF("\n *** None of the configured devices were detected.***\n\n");
+ else
+ ErrorF(
+ "\n *** A configured device found, but display modes could not be resolved.***\n\n");
+ if (xf86ProbeOnly)
+ {
+ xf86VTSema = FALSE;
+ AbortDDX();
+ fflush(stderr);
+ exit(0);
+ }
+ }
+ else {
+ /*
+ * serverGeneration != 1; some OSs have to do things here, too.
+ */
+ xf86OpenConsole();
+ }
+
+ /*
+ * Install signal handler for unexpected signals
+ */
+ if (!xf86Info.notrapSignals)
+ {
+ xf86Info.caughtSignal=FALSE;
+ signal(SIGSEGV,xf86SigHandler);
+ signal(SIGILL,xf86SigHandler);
+#ifdef SIGEMT
+ signal(SIGEMT,xf86SigHandler);
+#endif
+ signal(SIGFPE,xf86SigHandler);
+#ifdef SIGBUS
+ signal(SIGBUS,xf86SigHandler);
+#endif
+#ifdef SIGSYS
+ signal(SIGSYS,xf86SigHandler);
+#endif
+#ifdef SIGXCPU
+ signal(SIGXCPU,xf86SigHandler);
+#endif
+#ifdef SIGXFSZ
+ signal(SIGXFSZ,xf86SigHandler);
+#endif
+ }
+
+
+ /*
+ * Use the previous collected parts to setup pScreenInfo
+ */
+ pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+ pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+ pScreenInfo->numPixmapFormats = numFormats;
+ for ( i=0; i < numFormats; i++ ) pScreenInfo->formats[i] = formats[i];
+
+ if (generation != serverGeneration)
+ {
+ xf86ScreenIndex = AllocateScreenPrivateIndex();
+ generation = serverGeneration;
+ }
+
+
+ for ( i=0;
+ i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured;
+ i++ )
+ {
+ /*
+ * On a server-reset, we have explicitely to remap all stuff ...
+ * (At startuptime this is implicitely done by probing the device
+ */
+ if (serverGeneration != 1)
+ {
+ xf86Resetting = TRUE;
+ xf86Exiting = FALSE;
+#ifdef HAS_USL_VTS
+ if (!xf86VTSema)
+ ioctl(xf86Info.consoleFd,VT_RELDISP,VT_ACKACQ);
+#endif
+ xf86VTSema = TRUE;
+ (xf86Screens[i]->EnterLeaveVT)(ENTER, i);
+ xf86Resetting = FALSE;
+ }
+#ifdef SCO
+ else {
+ /*
+ * Under SCO we must ack that we got the console at startup,
+ * I think this is the safest way to assure it
+ */
+ static int once = 1;
+ if (once) {
+ once = 0;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
+ ErrorF("VT_ACKACQ failed");
+ }
+ }
+#endif /* SCO */
+ scr_index = AddScreen(xf86Screens[i]->Init, argc, argv);
+ if (scr_index > -1)
+ {
+ screenInfo.screens[scr_index]->devPrivates[xf86ScreenIndex].ptr
+ = (pointer)xf86Screens[i];
+ }
+
+ /*
+ * Here we have to let the driver getting access of the VT. Note that
+ * this doesn't mean that the graphics board may access automatically
+ * the monitor. If the monitor is shared this is done in xf86CrossScreen!
+ */
+ if (!xf86Info.sharedMonitor) (xf86Screens[i]->EnterLeaveMonitor)(ENTER);
+ }
+
+#ifndef AMOEBA
+ RegisterBlockAndWakeupHandlers(xf86Block, xf86Wakeup, (void *)0);
+#endif
+}
+
+
+/*
+ * InitInput --
+ * Initialize all supported input devices...what else is there
+ * besides pointer and keyboard? Two DeviceRec's are allocated and
+ * registered as the system pointer and keyboard devices.
+ */
+
+void
+InitInput(argc, argv)
+ int argc;
+ char **argv;
+{
+ xf86Info.vtRequestsPending = FALSE;
+ xf86Info.inputPending = FALSE;
+#ifdef XTESTEXT1
+ xtest_command_key = KEY_Begin + MIN_KEYCODE;
+#endif /* XTESTEXT1 */
+
+ xf86Info.pKeyboard = AddInputDevice(xf86Info.kbdProc, TRUE);
+ xf86Info.pMouse = AddInputDevice(xf86Info.mouseDev->mseProc, TRUE);
+ RegisterKeyboardDevice((DevicePtr)xf86Info.pKeyboard);
+ RegisterPointerDevice((DevicePtr)xf86Info.pMouse);
+
+#ifdef XINPUT
+ (xf86Info.pMouse)->public.devicePrivate = xf86Info.mouseLocal;
+#if 0 /* Is this needed?? */
+ ((LocalDevicePtr) xf86Info.mouseLocal)->dev = xf86Info.pMouse;
+#endif
+#else
+ (xf86Info.pMouse)->public.devicePrivate = (pointer) xf86Info.mouseDev;
+#endif
+
+#ifdef XINPUT
+ InitExtInput();
+#endif
+
+ miRegisterPointerDevice(screenInfo.screens[0], (DevicePtr) xf86Info.pMouse);
+#ifdef XINPUT
+ xf86XinputFinalizeInit(xf86Info.pMouse);
+ xf86eqInit ((DevicePtr)xf86Info.pKeyboard, (DevicePtr)xf86Info.pMouse);
+#else
+ mieqInit (xf86Info.pKeyboard, xf86Info.pMouse);
+#endif
+}
+
+/*
+ * OsVendorInit --
+ * OS/Vendor-specific initialisations. Called from OsInit(), which
+ * is called by dix before establishing the well known sockets.
+ */
+
+extern Bool OsDelayInitColors;
+
+void
+OsVendorInit()
+{
+#ifdef SIGCHLD
+ signal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */
+#endif
+#ifdef USE_XF86_SERVERLOCK
+ extern void xf86LockServer();
+ static Bool been_here = FALSE;
+
+ if (!been_here) {
+ xf86LockServer();
+ been_here = TRUE;
+ }
+#endif
+ OsDelayInitColors = TRUE;
+}
+
+#ifdef DPMSExtension
+extern CARD16 DPMSPowerLevel;
+
+/*
+ * DPMSSet --
+ * Device dependent DPMS mode setting hook. This is called whenever
+ * the DPMS mode is to be changed.
+ */
+void
+DPMSSet(CARD16 level)
+{
+ int i;
+
+ /* For each screen, set the power saver level */
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ (XF86SCRNINFO(screenInfo.screens[i])->DPMSSet)(level);
+ }
+
+ DPMSPowerLevel = level;
+}
+
+#if 0
+/*
+ * DPMSGet --
+ * Device dependent DPMS mode getting hook. This returns the current
+ * DPMS mode, or -1 if DPMS is not supported.
+ *
+ * This should hook in to the appropriate driver-level function, which
+ * will be added to the ScrnInfoRec.
+ *
+ * NOTES:
+ * 1. the calling interface should be changed to specify which
+ * screen to check.
+ * 2. It isn't clear that this function is ever used.
+ */
+CARD16
+DPMSGet(CARD16 *level)
+{
+ int i;
+
+ /* For each screen, set the power saver level */
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ ;
+ }
+}
+#endif
+
+/*
+ * DPMSSupported --
+ * Return TRUE if any screen supports DPMS.
+ */
+Bool
+DPMSSupported(void)
+{
+ int i;
+
+ /* For each screen, check if DPMS is supported */
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ if (XF86SCRNINFO(screenInfo.screens[i])->DPMSSet != (void (*)())NoopDDA)
+ return TRUE;
+ }
+ return FALSE;
+}
+#endif /* DPMSExtension */
+
+/*
+ * ddxGiveUp --
+ * Device dependent cleanup. Called by by dix before normal server death.
+ * For SYSV386 we must switch the terminal back to normal mode. No error-
+ * checking here, since there should be restored as much as possible.
+ */
+
+void
+ddxGiveUp()
+{
+#ifdef USE_XF86_SERVERLOCK
+ xf86UnlockServer();
+#endif
+
+ xf86CloseConsole();
+
+ /* If an unexpected signal was caught, dump a core for debugging */
+ if (xf86Info.caughtSignal)
+ abort();
+}
+
+
+
+/*
+ * AbortDDX --
+ * DDX - specific abort routine. Called by AbortServer(). The attempt is
+ * made to restore all original setting of the displays. Also all devices
+ * are closed.
+ */
+
+void
+AbortDDX()
+{
+ int i;
+
+#if 0
+ if (xf86Exiting)
+ return;
+#endif
+
+ xf86Exiting = TRUE;
+
+ /*
+ * try to deinitialize all input devices
+ */
+ if (xf86Info.pMouse) (xf86Info.mouseDev->mseProc)(xf86Info.pMouse, DEVICE_CLOSE);
+ if (xf86Info.pKeyboard) (xf86Info.kbdProc)(xf86Info.pKeyboard, DEVICE_CLOSE);
+
+ /*
+ * try to restore the original video state
+ */
+#ifdef HAS_USL_VTS
+ /* Need the sleep when starting X from within another X session */
+ sleep(1);
+#endif
+ if (xf86VTSema && xf86ScreensOpen)
+ for ( i=0;
+ i < xf86MaxScreens && xf86Screens[i] && xf86Screens[i]->configured;
+ i++ )
+ (xf86Screens[i]->EnterLeaveVT)(LEAVE, i);
+
+ /*
+ * This is needed for a abnormal server exit, since the normal exit stuff
+ * MUST also be performed (i.e. the vt must be left in a defined state)
+ */
+ ddxGiveUp();
+}
+
+void
+OsVendorFatalError()
+{
+ ErrorF("\nWhen reporting a problem related to a server crash, please send\n"
+ "the full server output, not just the last messages\n\n");
+}
+
+/*
+ * ddxProcessArgument --
+ * Process device-dependent command line args. Returns 0 if argument is
+ * not device dependent, otherwise Count of number of elements of argv
+ * that are part of a device dependent commandline option.
+ */
+
+/* ARGSUSED */
+int
+ddxProcessArgument (argc, argv, i)
+ int argc;
+ char *argv[];
+ int i;
+{
+ if (getuid() == 0 && !strcmp(argv[i], "-xf86config"))
+ {
+ if (!argv[i+1])
+ return 0;
+ if (strlen(argv[i+1]) >= PATH_MAX)
+ FatalError("XF86Config path name too long\n");
+ strcpy(xf86ConfigFile, argv[i+1]);
+ return 2;
+ }
+ if (!strcmp(argv[i],"-probeonly"))
+ {
+ xf86ProbeOnly = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-flipPixels"))
+ {
+ xf86FlipPixels = TRUE;
+ return 1;
+ }
+#ifdef XF86VIDMODE
+ if (!strcmp(argv[i],"-disableVidMode"))
+ {
+ xf86VidModeEnabled = FALSE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-allowNonLocalXvidtune"))
+ {
+ xf86VidModeAllowNonLocal = TRUE;
+ return 1;
+ }
+#endif
+#ifdef XF86MISC
+ if (!strcmp(argv[i],"-disableModInDev"))
+ {
+ xf86MiscModInDevEnabled = FALSE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-allowNonLocalModInDev"))
+ {
+ xf86MiscModInDevAllowNonLocal = TRUE;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-allowMouseOpenFail"))
+ {
+ xf86AllowMouseOpenFail = TRUE;
+ return 1;
+ }
+#endif
+ if (!strcmp(argv[i],"-bestRefresh"))
+ {
+ xf86BestRefresh = TRUE;
+ return 1;
+ }
+#ifdef DO_CHECK_BETA
+ if (!strcmp(argv[i],"-extendExpiry"))
+ {
+ extraDays = atoi(argv[i + 1]);
+ expKey = argv[i + 2];
+ return 3;
+ }
+#endif
+ if (!strcmp(argv[i],"-verbose"))
+ {
+ if (!xf86Verbose++)
+ xf86Verbose = 2;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-quiet"))
+ {
+ xf86Verbose = 0;
+ return 1;
+ }
+ if (!strcmp(argv[i],"-showconfig") || !strcmp(argv[i],"-version"))
+ {
+ xf86PrintBanner();
+ xf86PrintConfig();
+ exit(0);
+ }
+ /* Notice the -fp flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-fp"))
+ {
+ xf86fpFlag = TRUE;
+ return 0;
+ }
+ /* Notice the -co flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-co"))
+ {
+ xf86coFlag = TRUE;
+ return 0;
+ }
+ /* Notice the -s flag, but allow it to pass to the dix layer */
+ if (!strcmp(argv[i], "-s"))
+ {
+ xf86sFlag = TRUE;
+ return 0;
+ }
+#ifndef XF86MONOVGA
+ if (!strcmp(argv[i], "-bpp"))
+ {
+ int bpp;
+ if (++i >= argc)
+ return 0;
+ if (sscanf(argv[i], "%d", &bpp) == 1)
+ {
+ xf86bpp = bpp;
+ return 2;
+ }
+ else
+ {
+ ErrorF("Invalid bpp\n");
+ return 0;
+ }
+ }
+ if (!strcmp(argv[i], "-weight"))
+ {
+ int red, green, blue;
+ if (++i >= argc)
+ return 0;
+ if (sscanf(argv[i], "%1d%1d%1d", &red, &green, &blue) == 3)
+ {
+ xf86weight.red = red;
+ xf86weight.green = green;
+ xf86weight.blue = blue;
+ return 2;
+ }
+ else
+ {
+ ErrorF("Invalid weighting\n");
+ return 0;
+ }
+ }
+ if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") ||
+ !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma"))
+ {
+ double gamma;
+ if (++i >= argc)
+ return 0;
+ if (sscanf(argv[i], "%lf", &gamma) == 1) {
+ if (gamma < 0.1 || gamma > 10) {
+ ErrorF("gamma out of range, only 0.1 < gamma_value < 10 is valid\n");
+ return 0;
+ }
+ if (!strcmp(argv[i-1], "-gamma"))
+ xf86rGamma = xf86gGamma = xf86bGamma = 1.0 / gamma;
+ else if (!strcmp(argv[i-1], "-rgamma")) xf86rGamma = 1.0 / gamma;
+ else if (!strcmp(argv[i-1], "-ggamma")) xf86gGamma = 1.0 / gamma;
+ else if (!strcmp(argv[i-1], "-bgamma")) xf86bGamma = 1.0 / gamma;
+ return 2;
+ }
+ }
+#endif /* XF86MONOVGA */
+ return xf86ProcessArgument(argc, argv, i);
+}
+
+
+/*
+ * ddxUseMsg --
+ * Print out correct use of device dependent commandline options.
+ * Maybe the user now knows what really to do ...
+ */
+
+void
+ddxUseMsg()
+{
+ ErrorF("\n");
+ ErrorF("\n");
+ ErrorF("Device Dependent Usage\n");
+ if (getuid() == 0)
+ ErrorF("-xf86config file specify a configuration file\n");
+ ErrorF("-probeonly probe for devices, then exit\n");
+ ErrorF("-verbose verbose startup messages\n");
+ ErrorF("-quiet minimal startup messages\n");
+#ifndef XF86MONOVGA
+ ErrorF("-bpp n set number of bits per pixel. Default: 8\n");
+ ErrorF("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n");
+ ErrorF("-rgamma f set gamma value for red phase\n");
+ ErrorF("-ggamma f set gamma value for green phase\n");
+ ErrorF("-bgamma f set gamma value for blue phase\n");
+ ErrorF("-weight nnn set RGB weighting at 16 bpp. Default: 565\n");
+#endif /* XF86MONOVGA */
+ ErrorF("-flipPixels swap default black/white Pixel values\n");
+#ifdef XF86VIDMODE
+ ErrorF("-disableVidMode disable mode adjustments with xvidtune\n");
+ ErrorF("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n");
+#endif
+#ifdef XF86MISC
+ ErrorF("-disableModInDev disable dynamic modification of input device settings\n");
+ ErrorF("-allowNonLocalModInDev allow changes to keyboard and mouse settings\n");
+ ErrorF(" from non-local clients\n");
+ ErrorF("-allowMouseOpenFail start server even if the mouse can't be initialized\n");
+#endif
+ ErrorF("-bestRefresh Chose modes with the best refresh rate\n");
+ ErrorF(
+ "-showconfig show which drivers are included in the server\n");
+ xf86UseMsg();
+ ErrorF("\n");
+}
+
+
+#ifndef OSNAME
+#define OSNAME "unknown"
+#endif
+#ifndef OSVENDOR
+#define OSVENDOR ""
+#endif
+
+static void
+xf86PrintBanner()
+{
+ ErrorF("\nXFree86 Version%s/ X Window System\n",XF86_VERSION);
+ ErrorF("(protocol Version %d, revision %d, vendor release %d)\n",
+ X_PROTOCOL, X_PROTOCOL_REVISION, VENDOR_RELEASE );
+ ErrorF("Release Date: %s\n", XF86_DATE);
+ ErrorF("\tIf the server is older than 6-12 months, or if your card is "
+ "newer\n"
+ "\tthan the above date, look for a newer version before "
+ "reporting\n"
+ "\tproblems. (see http://www.XFree86.Org/FAQ)\n");
+ ErrorF("Operating System: %s %s\n", OSNAME, OSVENDOR);
+}
+
+static void
+xf86PrintConfig()
+{
+ int i;
+
+ ErrorF("Configured drivers:\n");
+ for (i = 0; i < xf86MaxScreens; i++)
+ if (xf86Screens[i])
+ (xf86Screens[i]->PrintIdent)();
+}
+
diff --git a/hw/xfree86/common/xf86Io.c b/hw/xfree86/common/xf86Io.c
new file mode 100644
index 000000000..6fddb5e89
--- /dev/null
+++ b/hw/xfree86/common/xf86Io.c
@@ -0,0 +1,542 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 3.28.2.5 1998/02/24 19:05:55 hohndel Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86Io.c,v 1.3 2000/08/17 19:50:29 cpqbld Exp $ */
+/* Patch for PS/2 Intellimouse - Tim Goodwin 1997-11-06. */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "xf86_Config.h"
+
+#ifdef XINPUT
+#include "xf86Xinput.h"
+#endif
+
+#ifdef XKB
+#include <X11/extensions/XKB.h>
+#include <X11/extensions/XKBstr.h>
+#include <X11/extensions/XKBsrv.h>
+#endif
+
+extern KeybdCtrl defaultKeyboardControl;
+
+unsigned int xf86InitialCaps = 0;
+unsigned int xf86InitialNum = 0;
+unsigned int xf86InitialScroll = 0;
+
+#include "atKeynames.h"
+
+extern int miPointerGetMotionEvents(DeviceIntPtr pPtr, xTimecoord *coords,
+ unsigned long start, unsigned long stop,
+ ScreenPtr pScreen);
+
+/*
+ * xf86KbdBell --
+ * Ring the terminal/keyboard bell for an amount of time proportional to
+ * "loudness".
+ */
+
+void
+xf86KbdBell(percent, pKeyboard, ctrl, unused)
+ int percent; /* Percentage of full volume */
+ DeviceIntPtr pKeyboard; /* Keyboard to ring */
+ pointer ctrl;
+ int unused;
+{
+ xf86SoundKbdBell(percent, xf86Info.bell_pitch, xf86Info.bell_duration);
+}
+
+#ifdef AMOEBA
+#define LED_CAP IOP_LED_CAP
+#define LED_NUM IOP_LED_NUM
+#define LED_SCR IOP_LED_SCROLL
+#endif
+
+#ifdef MINIX
+#define LED_CAP KBD_LEDS_CAPS
+#define LED_NUM KBD_LEDS_NUM
+#define LED_SCR KBD_LEDS_SCROLL
+#endif
+
+void
+xf86KbdLeds ()
+{
+ int leds = 0;
+#ifdef XKB
+ if (!noXkbExtension) {
+ XkbEventCauseRec cause;
+ XkbSetCauseUnknown(&cause);
+ XkbUpdateIndicators((DeviceIntPtr)xf86Info.pKeyboard,
+ XkbAllIndicatorsMask, False, NULL, &cause);
+ return;
+ }
+#endif
+#ifdef LED_CAP
+ if (xf86Info.capsLock && !(xf86Info.xleds & XLED1))
+ leds |= LED_CAP;
+
+ if (xf86Info.numLock && !(xf86Info.xleds & XLED2))
+ leds |= LED_NUM;
+
+ if ((xf86Info.scrollLock ||
+ xf86Info.modeSwitchLock ||
+ xf86Info.composeLock) &&
+ !(xf86Info.xleds & XLED3))
+ leds |= LED_SCR;
+
+ if ((xf86Info.leds & xf86Info.xleds) & XLED1) leds |= LED_CAP;
+ if ((xf86Info.leds & xf86Info.xleds) & XLED2) leds |= LED_NUM;
+ if ((xf86Info.leds & xf86Info.xleds) & XLED3) leds |= LED_SCR;
+
+ xf86SetKbdLeds(leds);
+#endif /* LED_CAP */
+}
+
+/*
+ * xf86KbdCtrl --
+ * Alter some of the keyboard control parameters. All special protocol
+ * values are handled by dix (ProgChangeKeyboardControl)
+ */
+
+void
+xf86KbdCtrl (pKeyboard, ctrl)
+ DevicePtr pKeyboard; /* Keyboard to alter */
+ KeybdCtrl *ctrl;
+{
+ xf86Info.bell_pitch = ctrl->bell_pitch;
+ xf86Info.bell_duration = ctrl->bell_duration;
+ xf86Info.autoRepeat = ctrl->autoRepeat;
+ xf86Info.leds = (ctrl->leds & ~(XCAPS | XNUM | XSCR));
+
+ xf86Info.composeLock = (ctrl->leds & XCOMP) ? TRUE : FALSE;
+
+ xf86KbdLeds();
+}
+
+/*
+ * xf86InitKBD --
+ * Reinitialize the keyboard. Only set Lockkeys accrding to ours leds.
+ * Depress all other keys.
+ */
+
+void
+xf86InitKBD(init)
+Bool init;
+{
+ char leds = 0, rad;
+ unsigned int i;
+ xEvent kevent;
+ DeviceIntPtr pKeyboard = xf86Info.pKeyboard;
+ KeyClassRec *keyc = xf86Info.pKeyboard->key;
+ KeySym *map = keyc->curKeySyms.map;
+
+#ifndef MACH386
+ kevent.u.keyButtonPointer.time = GetTimeInMillis();
+ kevent.u.keyButtonPointer.rootX = 0;
+ kevent.u.keyButtonPointer.rootY = 0;
+
+ /*
+ * Hmm... here is the biggest hack of every time !
+ * It may be possible that a switch-vt procedure has finished BEFORE
+ * you released all keys neccessary to do this. That peculiar behavior
+ * can fool the X-server pretty much, cause it assumes that some keys
+ * were not released. TWM may stuck alsmost completly....
+ * OK, what we are doing here is after returning from the vt-switch
+ * exeplicitely unrelease all keyboard keys before the input-devices
+ * are reenabled.
+ */
+ for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
+ i < keyc->curKeySyms.maxKeyCode;
+ i++, map += keyc->curKeySyms.mapWidth)
+ if (KeyPressed(i))
+ {
+ switch (*map) {
+ /* Don't release the lock keys */
+ case XK_Caps_Lock:
+ case XK_Shift_Lock:
+ case XK_Num_Lock:
+ case XK_Scroll_Lock:
+ case XK_Kana_Lock:
+ break;
+ default:
+ kevent.u.u.detail = i;
+ kevent.u.u.type = KeyRelease;
+ (* pKeyboard->public.processInputProc)(&kevent, pKeyboard, 1);
+ }
+ }
+#endif /* MACH386 */
+
+ xf86Info.scanPrefix = 0;
+
+ if (init)
+ {
+ /*
+ * we must deal here with the fact, that on some cases the numlock or
+ * capslock key are enabled BEFORE the server is started up. So look
+ * here at the state on the according LEDS to determine whether a
+ * lock-key is already set.
+ */
+
+ xf86Info.capsLock = FALSE;
+ xf86Info.numLock = FALSE;
+ xf86Info.scrollLock = FALSE;
+ xf86Info.modeSwitchLock = FALSE;
+ xf86Info.composeLock = FALSE;
+
+#ifdef LED_CAP
+#ifdef INHERIT_LOCK_STATE
+ leds = xf86Info.leds;
+
+ for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
+ i < keyc->curKeySyms.maxKeyCode;
+ i++, map += keyc->curKeySyms.mapWidth)
+
+ switch(*map) {
+
+ case XK_Caps_Lock:
+ case XK_Shift_Lock:
+ if (leds & LED_CAP)
+ {
+ xf86InitialCaps = i;
+ xf86Info.capsLock = TRUE;
+ }
+ break;
+
+ case XK_Num_Lock:
+ if (leds & LED_NUM)
+ {
+ xf86InitialNum = i;
+ xf86Info.numLock = TRUE;
+ }
+ break;
+
+ case XK_Scroll_Lock:
+ case XK_Kana_Lock:
+ if (leds & LED_SCR)
+ {
+ xf86InitialScroll = i;
+ xf86Info.scrollLock = TRUE;
+ }
+ break;
+ }
+#endif /* INHERIT_LOCK_STATE */
+ xf86SetKbdLeds(leds);
+#endif /* LED_CAP */
+
+ if (xf86Info.kbdDelay <= 375) rad = 0x00;
+ else if (xf86Info.kbdDelay <= 625) rad = 0x20;
+ else if (xf86Info.kbdDelay <= 875) rad = 0x40;
+ else rad = 0x60;
+
+ if (xf86Info.kbdRate <= 2) rad |= 0x1F;
+ else if (xf86Info.kbdRate >= 30) rad |= 0x00;
+ else rad |= ((58 / xf86Info.kbdRate) - 2);
+
+ xf86SetKbdRepeat(rad);
+ }
+}
+
+/*
+ * xf86KbdProc --
+ * Handle the initialization, etc. of a keyboard.
+ */
+
+int
+xf86KbdProc (pKeyboard, what)
+ DeviceIntPtr pKeyboard; /* Keyboard to manipulate */
+ int what; /* What to do to it */
+{
+ KeySymsRec keySyms;
+ CARD8 modMap[MAP_LENGTH];
+ int kbdFd;
+
+ switch (what) {
+
+ case DEVICE_INIT:
+ /*
+ * First open and find the current state of the keyboard.
+ */
+
+ xf86KbdInit();
+
+ xf86KbdGetMapping(&keySyms, modMap);
+
+
+#ifndef XKB
+ defaultKeyboardControl.leds = xf86GetKbdLeds();
+#else
+ defaultKeyboardControl.leds = 0;
+#endif
+
+ /*
+ * Perform final initialization of the system private keyboard
+ * structure and fill in various slots in the device record
+ * itself which couldn't be filled in before.
+ */
+
+ pKeyboard->public.on = FALSE;
+
+#ifdef XKB
+ if (noXkbExtension) {
+#endif
+ InitKeyboardDeviceStruct((DevicePtr)xf86Info.pKeyboard,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+#ifdef XKB
+ } else {
+ XkbComponentNamesRec names;
+ if (XkbInitialMap) {
+ if ((xf86Info.xkbkeymap = strchr(XkbInitialMap, '/')) != NULL)
+ xf86Info.xkbkeymap++;
+ else
+ xf86Info.xkbkeymap = XkbInitialMap;
+ }
+ if (xf86Info.xkbkeymap) {
+ names.keymap = xf86Info.xkbkeymap;
+ names.keycodes = NULL;
+ names.types = NULL;
+ names.compat = NULL;
+ names.symbols = NULL;
+ names.geometry = NULL;
+ } else {
+ names.keymap = NULL;
+ names.keycodes = xf86Info.xkbkeycodes;
+ names.types = xf86Info.xkbtypes;
+ names.compat = xf86Info.xkbcompat;
+ names.symbols = xf86Info.xkbsymbols;
+ names.geometry = xf86Info.xkbgeometry;
+ }
+ if ((xf86Info.xkbkeymap || xf86Info.xkbcomponents_specified)
+ && (xf86Info.xkbmodel == NULL || xf86Info.xkblayout == NULL)) {
+ xf86Info.xkbrules = NULL;
+ }
+ XkbSetRulesDflts(xf86Info.xkbrules, xf86Info.xkbmodel,
+ xf86Info.xkblayout, xf86Info.xkbvariant,
+ xf86Info.xkboptions);
+ XkbInitKeyboardDeviceStruct(pKeyboard,
+ &names,
+ &keySyms,
+ modMap,
+ xf86KbdBell,
+ (KbdCtrlProcPtr)xf86KbdCtrl);
+ }
+#endif
+
+ xf86InitKBD(TRUE);
+ break;
+
+ case DEVICE_ON:
+ /*
+ * Set the keyboard into "direct" mode and turn on
+ * event translation.
+ */
+
+ kbdFd = xf86KbdOn();
+ /*
+ * Discard any pending input after a VT switch to prevent the server
+ * passing on parts of the VT switch sequence.
+ */
+ sleep(1);
+ if (kbdFd != -1) {
+ char buf[16];
+ read(kbdFd, buf, 16);
+ }
+
+#ifndef __EMX__ /* Under EMX, keyboard cannot be select()'ed */
+ if (kbdFd != -1)
+ AddEnabledDevice(kbdFd);
+#endif /* __EMX__ */
+
+ pKeyboard->public.on = TRUE;
+ xf86InitKBD(FALSE);
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ /*
+ * Restore original keyboard directness and translation.
+ */
+
+ kbdFd = xf86KbdOff();
+
+ if (kbdFd != -1)
+ RemoveEnabledDevice(kbdFd);
+
+ pKeyboard->public.on = FALSE;
+ break;
+
+ }
+ return (Success);
+}
+
+/*
+ * xf86MseCtrl --
+ * Alter the control parameters for the mouse. Note that all special
+ * protocol values are handled by dix.
+ */
+
+void
+xf86MseCtrl(pPointer, ctrl)
+ DevicePtr pPointer;
+ PtrCtrl *ctrl;
+{
+ MouseDevPtr mouse = MOUSE_DEV((DeviceIntPtr) pPointer);
+
+ mouse->num = ctrl->num;
+ mouse->den = ctrl->den;
+ mouse->threshold = ctrl->threshold;
+}
+
+/*
+ * xf86MseProc --
+ * Handle the initialization, etc. of a mouse
+ */
+
+int
+xf86MseProc(pPointer, what)
+ DeviceIntPtr pPointer;
+ int what;
+{
+ MouseDevPtr mouse = MOUSE_DEV(pPointer);
+
+ mouse->device = pPointer;
+
+ return xf86MseProcAux(pPointer, what, mouse, NULL,
+ (PtrCtrlProcPtr)xf86MseCtrl);
+}
+
+int
+xf86MseProcAux(pPointer, what, mouse, fd, ctrl)
+ DeviceIntPtr pPointer;
+ int what;
+ MouseDevPtr mouse;
+ int *fd;
+ PtrCtrlProcPtr ctrl;
+{
+ unsigned char map[MSE_MAXBUTTONS + 1];
+ int nbuttons;
+ int mousefd;
+
+ switch (what)
+ {
+ case DEVICE_INIT:
+ pPointer->public.on = FALSE;
+
+ /*
+ * [KAZU-241097] We don't know exactly how many buttons the
+ * device has...
+ */
+ for (nbuttons = 0; nbuttons < MSE_MAXBUTTONS; ++nbuttons)
+ map[nbuttons + 1] = nbuttons + 1;
+
+ InitPointerDeviceStruct((DevicePtr)pPointer,
+ map,
+ min(mouse->buttons, MSE_MAXBUTTONS),
+ miPointerGetMotionEvents,
+ ctrl,
+ miPointerGetMotionBufferSize());
+
+ xf86MouseInit(mouse);
+
+ break;
+
+ case DEVICE_ON:
+
+ mousefd = xf86MouseOn(mouse);
+
+ if (fd)
+ *fd = mousefd;
+
+ if (mousefd != -1) {
+ if (mousefd == -2) {
+ if (fd)
+ *fd = -1;
+ } else {
+ if (mouse->mseType == P_PS2)
+ write(mousefd, "\364", 1);
+
+ AddEnabledDevice(mousefd);
+ }
+ mouse->lastButtons = 0;
+ mouse->emulateState = 0;
+ pPointer->public.on = TRUE;
+ } else {
+ return !Success;
+ }
+
+ break;
+
+ case DEVICE_OFF:
+ case DEVICE_CLOSE:
+
+ mousefd = xf86MouseOff(mouse, what == DEVICE_CLOSE);
+
+ if (mousefd != -1)
+ RemoveEnabledDevice(mousefd);
+
+ pPointer->public.on = FALSE;
+ usleep(300000);
+ break;
+ }
+ return Success;
+}
+
+/*
+ * xf86MseEvents --
+ * Read the new events from the device, and pass them to the eventhandler.
+ * This should is not used if there is only an OS_MOUSE driver.
+ */
+#ifndef OSMOUSE_ONLY
+void
+xf86MseEvents(mouse)
+ MouseDevPtr mouse;
+{
+ xf86MouseEvents(mouse);
+}
+#endif
+
+#if !defined(AMOEBA) && !(defined (sun) && defined(i386) && defined (SVR4)) && !defined(MINIX) && !defined(__mips__)
+/*
+ * These are getting tossed in here until I can think of where
+ * they really belong
+ */
+CARD32
+GetTimeInMillis()
+{
+ struct timeval tp;
+
+ gettimeofday(&tp, 0);
+ return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+}
+#endif /* !AMOEBA && !(sun || SVR4) && !MINIX */
+
diff --git a/hw/xfree86/common/xf86Kbd.c b/hw/xfree86/common/xf86Kbd.c
new file mode 100644
index 000000000..f263937a2
--- /dev/null
+++ b/hw/xfree86/common/xf86Kbd.c
@@ -0,0 +1,407 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Kbd.c,v 3.14 1997/01/05 11:58:08 dawes Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86Kbd.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86_Config.h"
+
+#include "xf86Keymap.h"
+
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]]
+
+/*
+ * NOTE: Not all possible remappable symbols are remapped. There are two main
+ * reasons:
+ * a) The mapping between scancode and SYSV/386 - symboltable
+ * is inconsistent between different versions and has some
+ * BIG mistakes.
+ * b) In X-Windows there is a difference between numpad-keys
+ * and normal keys. SYSV/386 uses for both kinds of keys
+ * the same symbol.
+ *
+ * Thus only the alpha keypad and the function keys are translated.
+ * Also CapsLock, NumLock, ScrollLock, Shift, Control & Alt.
+ */
+
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ };
+
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__)
+ keymap_t keymap;
+#endif /* !Lynx && !AMOEBA && !MINIX && !__OSF__ && !__EMX__ */
+ char type;
+ int i, j;
+ KeySym *pMap;
+
+#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__)
+ xf86Info.kbdType =
+ ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+ if (xf86Info.kbdType == KB_84)
+ pMap = map84;
+ else
+ pMap = map;
+#else
+ xf86Info.kbdType = 0;
+ pMap = map;
+#endif
+
+#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__)
+ /*
+ * use the keymap, which can be gotten from our oringinal vt??.
+ * ( ttymap(1) !!!! )
+ */
+ if (ioctl(xf86Info.consoleFd, GIO_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++)
+
+ if (remap[i]) {
+
+ k = pMap + (remap[i] << 2);
+
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
+ }
+ }
+#endif /* !Lynx && !AMOEBA && !MINIX && !__OSF__ && !__EMX__ */
+
+ /*
+ * Apply the special key mapping specified in XF86Config
+ */
+ for (k = pMap, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+ switch (k[0]) {
+ case XK_Alt_L:
+ j = K_INDEX_LEFTALT;
+ break;
+ case XK_Alt_R:
+ j = K_INDEX_RIGHTALT;
+ break;
+ case XK_Scroll_Lock:
+ j = K_INDEX_SCROLLLOCK;
+ break;
+ case XK_Control_R:
+ j = K_INDEX_RIGHTCTL;
+ break;
+ default:
+ j = -1;
+ }
+ if (j >= 0)
+ switch (xf86Info.specialKeyMap[j]) {
+ case KM_META:
+ if (k[0] == XK_Alt_R)
+ k[1] = XK_Meta_R;
+ else {
+ k[0] = XK_Alt_L;
+ k[1] = XK_Meta_L;
+ }
+ break;
+ case KM_COMPOSE:
+ k[0] = XK_Multi_key;
+ break;
+ case KM_MODESHIFT:
+ k[0] = XK_Mode_switch;
+ k[1] = NoSymbol;
+ break;
+ case KM_MODELOCK:
+ k[0] = XK_Mode_switch;
+ k[1] = XF86XK_ModeLock;
+ break;
+ case KM_SCROLLLOCK:
+ k[0] = XK_Scroll_Lock;
+ break;
+ case KM_CONTROL:
+ k[0] = XK_Control_R;
+ break;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = pMap, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+#if !defined(Lynx) && !defined(AMOEBA) && !defined(MINIX) && !defined(__OSF__) && !defined(__EMX__) && !defined(__mips__)
+ xf86Info.kbdType =
+ ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+#else
+/* OS/2 sets the keyboard type during xf86OpenKbd */
+#ifndef __EMX__
+ xf86Info.kbdType = 0;
+#endif
+#endif
+
+
+ pKeySyms->map = pMap;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ if (xf86Info.serverNumLock)
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+ else
+ pKeySyms->maxKeyCode = MAX_STD_KEYCODE;
+}
diff --git a/hw/xfree86/common/xf86KbdBSD.c b/hw/xfree86/common/xf86KbdBSD.c
new file mode 100644
index 000000000..bf880dd68
--- /dev/null
+++ b/hw/xfree86/common/xf86KbdBSD.c
@@ -0,0 +1,687 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdBSD.c,v 3.10 1996/12/23 06:43:30 dawes Exp $ */
+/*
+ * Derived from xf86Kbd.c by S_ren Schmidt (sos@login.dkuug.dk)
+ * which is Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * and from xf86KbdCODrv.c by Holger Veit
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $Xorg: xf86KbdBSD.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86_Config.h"
+#include "coKeynames.h"
+#include "xf86Keymap.h"
+
+#define KD_GET_ENTRY(i,n) \
+ eascii_to_x[((keymap.key[i].spcl << (n+1)) & 0x100) + keymap.key[i].map[n]]
+
+#ifndef __bsdi__
+static KeySym coGetKeysym();
+#endif
+
+#ifndef PC98
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0x69, 0x65, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+#else /* PC98 */
+static unsigned char remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0, 0, 0, /* 0x30 - 0x37 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x38 - 0x3f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0x52, 0x53, 0x54, 0x55, 0x56, 0, /* 0x50 - 0x57 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 - 0x67 */
+ 0x68, 0x69, 0x6a, 0x6b, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+#endif /* PC98 */
+
+
+/* This table assumes the ibm code page 437 coding for characters
+ * > 0x80. They are returned in this form by PCVT */
+static KeySym eascii_to_x[512] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+
+ /*
+ * special marked entries (256 + x)
+ */
+
+ NoSymbol, NoSymbol, XK_Shift_L, XK_Shift_R,
+ XK_Caps_Lock, XK_Num_Lock, XK_Scroll_Lock, XK_Alt_L,
+ NoSymbol, XK_Control_L, XK_Alt_L, XK_Alt_R,
+ XK_Control_L, XK_Control_R, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_F1,
+ XK_F2, XK_F3, XK_F4, XK_F5,
+ XK_F6, XK_F7, XK_F8, XK_F9,
+ XK_F10, XK_F11, XK_F12, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ };
+
+#ifdef __OpenBSD__
+/* don't mark AltR and CtrlR for remapping, since they
+ * cannot be remapped by pccons */
+static unsigned char pccons_remap[128] = {
+ 0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00 - 0x07 */
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08 - 0x0f */
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10 - 0x17 */
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18 - 0x1f */
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 - 0x27 */
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28 - 0x2f */
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, /* 0x30 - 0x37 */
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38 - 0x3f */
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0, /* 0x40 - 0x47 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x48 - 0x4f */
+ 0, 0, 0, 0, 0, 0, 0x56, 0x57, /* 0x50 - 0x57 */
+ 0x58, 0, 0, 0, 0, 0, 0, 0, /* 0x58 - 0x5f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x67 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x68 - 0x6f */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x77 */
+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0x78 - 0x7f */
+};
+
+/* This table assumes an iso8859_1 encoding for the characters
+ * > 80, as returned by pccons */
+static KeySym latin1_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+ };
+#endif
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+ char type;
+ int i, j;
+
+#ifndef __bsdi__
+ switch (xf86Info.consType) {
+
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+#if defined(__OpenBSD__)
+ /*
+ * on OpenBSD, the pccons keymap is programmable, too
+ */
+ {
+ pccons_keymap_t keymap[KB_NUM_KEYS];
+ if (ioctl(xf86Info.consoleFd, CONSOLE_GET_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < KB_NUM_KEYS; i++)
+ if (pccons_remap[i]) {
+ k = map + (pccons_remap[i] << 2);
+ switch (keymap[i].type) {
+ case KB_ASCII:
+ /* For ASCII keys, there is only one char in the keymap */
+ k[0] = latin1_to_x[(unsigned char)keymap[i].unshift[0]];
+ k[1] = latin1_to_x[(unsigned char)keymap[i].shift[0]];
+ k[2] = latin1_to_x[(unsigned char)keymap[i].altgr[0]];
+ k[3] = latin1_to_x[(unsigned char)keymap[i].shift_altgr[0]];
+ break;
+ case KB_SCROLL:
+ k[0] = XK_Scroll_Lock;
+ goto special;
+ case KB_NUM:
+ k[0] = XK_Num_Lock;
+ goto special;
+ case KB_CAPS:
+ k[0] = XK_Caps_Lock;
+ goto special;
+ case KB_SHIFT:
+ switch (keymap[i].unshift[0]) {
+ case 1:
+ /* left shift */
+ k[0] = XK_Shift_L;
+ break;
+ case 2:
+ /* right shift */
+ k[0] = XK_Shift_R;
+ break;
+ default:
+ k[0] = NoSymbol;
+ }
+ goto special;
+ case KB_CTL:
+ k[0] = XK_Control_L;
+ goto special;
+ case KB_ALT:
+ k[0] = XK_Alt_L;
+ goto special;
+ case KB_FUNC:
+ switch (keymap[i].unshift[2]) {
+ case 'M':
+ k[0] = XK_F1;
+ break;
+ case 'N':
+ k[0] = XK_F2;
+ break;
+ case 'O':
+ k[0] = XK_F3;
+ break;
+ case 'P':
+ k[0] = XK_F4;
+ break;
+ case 'Q':
+ k[0] = XK_F5;
+ break;
+ case 'R':
+ k[0] = XK_F6;
+ break;
+ case 'S':
+ k[0] = XK_F7;
+ break;
+ case 'T':
+ k[0] = XK_F8;
+ break;
+ case 'U':
+ k[0] = XK_F9;
+ break;
+ case 'V':
+ k[0] = XK_F10;
+ break;
+ case 'W':
+ k[0] = XK_F11;
+ break;
+ case 'X':
+ k[0] = XK_F12;
+ break;
+ default:
+ k[0] = NoSymbol;
+ break;
+ }
+ goto special;
+ default:
+ k[0] = NoSymbol;
+ special:
+ k[1] = k[2] = k[3] = NoSymbol;
+ }
+ }
+ } else {
+ ErrorF("Can't read pccons keymap\n");
+ }
+ }
+#endif /* __OpenBSD__ */
+ break;
+#endif
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ {
+ keymap_t keymap;
+
+ if (ioctl(xf86Info.consoleFd, GIO_KEYMAP, &keymap) != -1) {
+ for (i = 0; i < keymap.n_keys && i < NUM_KEYCODES; i++)
+#ifdef PC98
+ if (remap[i] || i == 0) {
+#else
+ if (remap[i]) {
+#endif
+ k = map + (remap[i] << 2);
+ k[0] = KD_GET_ENTRY(i,0); /* non-shifed */
+ k[1] = KD_GET_ENTRY(i,1); /* shifted */
+ k[2] = KD_GET_ENTRY(i,4); /* alt */
+ k[3] = KD_GET_ENTRY(i,5); /* alt - shifted */
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3])
+ k[2] = k[3] = NoSymbol;
+ }
+ }
+ }
+ break;
+#endif /* SYSCONS || PCVT */
+
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ for (i=1; i<= 128; i++) {
+ struct kbd_ovlkey cokeymap;
+ struct oldkbd_ovlkey ocokeymap;
+ KeySym coGetKeysym();
+
+ if (xf86Info.consType == CODRV011) {
+ ocokeymap.keynum = i;
+ if (ioctl(xf86Info.consoleFd, OLDKBDGCKEY, &ocokeymap) < 0)
+ break; /* Don't try again if it fails once */
+ if ((ocokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */
+ k = map + (xf86CodrvMap[i] << 2);
+ k[0] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.unshift,k[0]);
+ k[1] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.shift,k[1]);
+ k[2] = coGetKeysym(ocokeymap.type,(CARD8*)&ocokeymap.altgr,k[2]);
+ k[3] = NoSymbol;
+ }
+ } else {
+ cokeymap.keynum = i;
+ if (ioctl(xf86Info.consoleFd, KBDGCKEY, &cokeymap) < 0)
+ break; /* Don't try again if it fails once */
+ if ((cokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */
+ k = map + (xf86CodrvMap[i] << 2);
+ k[0] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.unshift,k[0]);
+ k[1] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.shift,k[1]);
+ k[2] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.altgr,k[2]);
+ k[3] = coGetKeysym(cokeymap.type,(CARD8*)&cokeymap.shiftaltgr,k[3]);
+ }
+ }
+ if ((cokeymap.type & KBD_OVERLOAD)) { /* changed from default setting */
+ if (k[3] == k[2]) k[3] = NoSymbol;
+ if (k[2] == k[1]) k[2] = NoSymbol;
+ if (k[1] == k[0]) k[1] = NoSymbol;
+ if (k[0] == k[2] && k[1] == k[3]) k[2] = k[3] = NoSymbol;
+ }
+ }
+ break;
+#endif /* CODRV */
+ }
+#endif /* !bsdi */
+
+ /*
+ * Apply the special key mapping specified in XF86Config
+ */
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+ switch (k[0]) {
+ case XK_Alt_L:
+ j = K_INDEX_LEFTALT;
+ break;
+ case XK_Alt_R:
+ j = K_INDEX_RIGHTALT;
+ break;
+ case XK_Scroll_Lock:
+ j = K_INDEX_SCROLLLOCK;
+ break;
+ case XK_Control_R:
+ j = K_INDEX_RIGHTCTL;
+ break;
+ default:
+ j = -1;
+ }
+ if (j >= 0)
+ switch (xf86Info.specialKeyMap[j]) {
+ case KM_META:
+ if (k[0] == XK_Alt_R)
+ k[1] = XK_Meta_R;
+ else {
+ k[0] = XK_Alt_L;
+ k[1] = XK_Meta_L;
+ }
+ break;
+ case KM_COMPOSE:
+ k[0] = XK_Multi_key;
+ break;
+ case KM_MODESHIFT:
+ k[0] = XK_Mode_switch;
+ k[1] = NoSymbol;
+ break;
+ case KM_MODELOCK:
+ k[0] = XK_Mode_switch;
+ k[1] = XF86XK_ModeLock;
+ break;
+ case KM_SCROLLLOCK:
+ k[0] = XK_Scroll_Lock;
+ break;
+ case KM_CONTROL:
+ k[0] = XK_Control_R;
+ break;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType = 0;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ if (xf86Info.serverNumLock)
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+ else
+ pKeySyms->maxKeyCode = MAX_STD_KEYCODE;
+
+}
+
+#ifdef CODRV_SUPPORT
+/* Converts a CoDriver ASCII+Special combination into a KeySym
+ */
+static KeySym
+coGetKeysym(typ,str,old)
+ int typ;
+ CARD8 *str;
+ KeySym old;
+{
+ if (strlen((char *)str) > 1) return old;
+ switch (typ & KBD_MASK) {
+ case KBD_NONE:
+ return NoSymbol;
+ case KBD_SHIFT:
+ if (old==XK_Shift_L || old==XK_Shift_R) return old;
+ else return XK_Shift_L;
+ case KBD_NUM:
+ return XK_Num_Lock;
+ case KBD_CTL:
+ if (old==XK_Control_L || old==XK_Control_R) return old;
+ else return XK_Control_L;
+ case KBD_ALTGR:
+ return XK_Mode_switch;
+ case KBD_META:
+ if (old==XK_Alt_L || old==XK_Alt_R) return old;
+ else return XK_Alt_L;
+ case KBD_SHFTLOCK:
+ case KBD_CAPS:
+ return XK_Caps_Lock;
+ case KBD_SCROLL:
+ return XK_Scroll_Lock;
+ case KBD_BREAK:
+ return XK_Break;
+ default:
+ case KBD_KP: /* there are few good reasons to overload
+ * F Keys and KP Keys, so we ignore any attempt
+ * at all
+ */
+ return old;
+ case KBD_ASCII:
+ return *str;
+ }
+}
+#endif
diff --git a/hw/xfree86/common/xf86KbdLnx.c b/hw/xfree86/common/xf86KbdLnx.c
new file mode 100644
index 000000000..094044b30
--- /dev/null
+++ b/hw/xfree86/common/xf86KbdLnx.c
@@ -0,0 +1,697 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdLnx.c,v 3.12 1996/12/23 06:43:31 dawes Exp $ */
+/*
+ * Linux version of keymapping setup. The kernel (since 0.99.14) has support
+ * for fully remapping the keyboard, but there are some differences between
+ * the Linux map and the SVR4 map (esp. in the extended keycodes). We also
+ * remove the restriction on what keycodes can be remapped.
+ * Orest Zborowski.
+ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86KbdLnx.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86_Config.h"
+
+#include "xf86Keymap.h"
+#include "DECkeysym.h"
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(unsigned int key, DevicePtr pDev)
+{
+ return (TRUE);
+}
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+static void readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap);
+
+void
+xf86KbdGetMapping (KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KeySym *k;
+ char type;
+ int i, j;
+
+ readKernelMapping(pKeySyms, pModMap);
+
+ /*
+ * Apply the special key mapping specified in XF86Config
+ */
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+ switch (k[0]) {
+ case XK_Alt_L:
+ j = K_INDEX_LEFTALT;
+ break;
+ case XK_Alt_R:
+ j = K_INDEX_RIGHTALT;
+ break;
+ case XK_Scroll_Lock:
+ j = K_INDEX_SCROLLLOCK;
+ break;
+ case XK_Control_R:
+ j = K_INDEX_RIGHTCTL;
+ break;
+ default:
+ j = -1;
+ }
+ if (j >= 0)
+ switch (xf86Info.specialKeyMap[j]) {
+ case KM_META:
+ if (k[0] == XK_Alt_R)
+ k[1] = XK_Meta_R;
+ else {
+ k[0] = XK_Alt_L;
+ k[1] = XK_Meta_L;
+ }
+ break;
+ case KM_COMPOSE:
+ k[0] = XK_Multi_key;
+ break;
+ case KM_MODESHIFT:
+ k[0] = XK_Mode_switch;
+ k[1] = NoSymbol;
+ break;
+ case KM_MODELOCK:
+ k[0] = XK_Mode_switch;
+ k[1] = XF86XK_ModeLock;
+ break;
+ case KM_SCROLLLOCK:
+ k[0] = XK_Scroll_Lock;
+ break;
+ case KM_CONTROL:
+ k[0] = XK_Control_R;
+ break;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType =
+ ioctl(xf86Info.consoleFd, KDGKBTYPE, &type) != -1 ? type : KB_101;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ if (xf86Info.serverNumLock)
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+ else
+ pKeySyms->maxKeyCode = MAX_STD_KEYCODE;
+
+}
+
+#include <linux/keyboard.h>
+
+static KeySym linux_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling,
+ XK_currency, XK_yen, XK_brokenbar, XK_section,
+ XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft,
+ XK_notsign, XK_hyphen, XK_registered, XK_macron,
+ XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior,
+ XK_acute, XK_mu, XK_paragraph, XK_periodcentered,
+ XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright,
+ XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown,
+ XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde,
+ XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla,
+ XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis,
+ XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis,
+ XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute,
+ XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply,
+ XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex,
+ XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp,
+ XK_agrave, XK_aacute, XK_acircumflex, XK_atilde,
+ XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla,
+ XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis,
+ XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis,
+ XK_eth, XK_ntilde, XK_ograve, XK_oacute,
+ XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division,
+ XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex,
+ XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis
+};
+
+#ifndef ASSUME_CUSTOM_KEYCODES
+
+/*
+ * Maps the AT keycodes to Linux keycodes
+ */
+static unsigned char at2lnx[] =
+{
+ 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */
+ 0x03, /* KEY_2 */ 0x04, /* KEY_3 */
+ 0x05, /* KEY_4 */ 0x06, /* KEY_5 */
+ 0x07, /* KEY_6 */ 0x08, /* KEY_7 */
+ 0x09, /* KEY_8 */ 0x0a, /* KEY_9 */
+ 0x0b, /* KEY_0 */ 0x0c, /* KEY_Minus */
+ 0x0d, /* KEY_Equal */ 0x0e, /* KEY_BackSpace */
+ 0x0f, /* KEY_Tab */ 0x10, /* KEY_Q */
+ 0x11, /* KEY_W */ 0x12, /* KEY_E */
+ 0x13, /* KEY_R */ 0x14, /* KEY_T */
+ 0x15, /* KEY_Y */ 0x16, /* KEY_U */
+ 0x17, /* KEY_I */ 0x18, /* KEY_O */
+ 0x19, /* KEY_P */ 0x1a, /* KEY_LBrace */
+ 0x1b, /* KEY_RBrace */ 0x1c, /* KEY_Enter */
+ 0x1d, /* KEY_LCtrl */ 0x1e, /* KEY_A */
+ 0x1f, /* KEY_S */ 0x20, /* KEY_D */
+ 0x21, /* KEY_F */ 0x22, /* KEY_G */
+ 0x23, /* KEY_H */ 0x24, /* KEY_J */
+ 0x25, /* KEY_K */ 0x26, /* KEY_L */
+ 0x27, /* KEY_SemiColon */ 0x28, /* KEY_Quote */
+ 0x29, /* KEY_Tilde */ 0x2a, /* KEY_ShiftL */
+ 0x2b, /* KEY_BSlash */ 0x2c, /* KEY_Z */
+ 0x2d, /* KEY_X */ 0x2e, /* KEY_C */
+ 0x2f, /* KEY_V */ 0x30, /* KEY_B */
+ 0x31, /* KEY_N */ 0x32, /* KEY_M */
+ 0x33, /* KEY_Comma */ 0x34, /* KEY_Period */
+ 0x35, /* KEY_Slash */ 0x36, /* KEY_ShiftR */
+ 0x37, /* KEY_KP_Multiply */ 0x38, /* KEY_Alt */
+ 0x39, /* KEY_Space */ 0x3a, /* KEY_CapsLock */
+ 0x3b, /* KEY_F1 */ 0x3c, /* KEY_F2 */
+ 0x3d, /* KEY_F3 */ 0x3e, /* KEY_F4 */
+ 0x3f, /* KEY_F5 */ 0x40, /* KEY_F6 */
+ 0x41, /* KEY_F7 */ 0x42, /* KEY_F8 */
+ 0x43, /* KEY_F9 */ 0x44, /* KEY_F10 */
+ 0x45, /* KEY_NumLock */ 0x46, /* KEY_ScrollLock */
+ 0x47, /* KEY_KP_7 */ 0x48, /* KEY_KP_8 */
+ 0x49, /* KEY_KP_9 */ 0x4a, /* KEY_KP_Minus */
+ 0x4b, /* KEY_KP_4 */ 0x4c, /* KEY_KP_5 */
+ 0x4d, /* KEY_KP_6 */ 0x4e, /* KEY_KP_Plus */
+ 0x4f, /* KEY_KP_1 */ 0x50, /* KEY_KP_2 */
+ 0x51, /* KEY_KP_3 */ 0x52, /* KEY_KP_0 */
+ 0x53, /* KEY_KP_Decimal */ 0x54, /* KEY_SysReqest */
+ 0x00, /* 0x55 */ 0x56, /* KEY_Less */
+ 0x57, /* KEY_F11 */ 0x58, /* KEY_F12 */
+ 0x66, /* KEY_Home */ 0x67, /* KEY_Up */
+ 0x68, /* KEY_PgUp */ 0x69, /* KEY_Left */
+ 0x5d, /* KEY_Begin */ 0x6a, /* KEY_Right */
+ 0x6b, /* KEY_End */ 0x6c, /* KEY_Down */
+ 0x6d, /* KEY_PgDown */ 0x6e, /* KEY_Insert */
+ 0x6f, /* KEY_Delete */ 0x60, /* KEY_KP_Enter */
+ 0x61, /* KEY_RCtrl */ 0x77, /* KEY_Pause */
+ 0x63, /* KEY_Print */ 0x62, /* KEY_KP_Divide */
+ 0x64, /* KEY_AltLang */ 0x65, /* KEY_Break */
+ 0x00, /* KEY_LMeta */ 0x00, /* KEY_RMeta */
+ 0x7A, /* KEY_Menu/FOCUS_PF11*/0x00, /* 0x6e */
+ 0x7B, /* FOCUS_PF12 */ 0x00, /* 0x70 */
+ 0x00, /* 0x71 */ 0x00, /* 0x72 */
+ 0x59, /* FOCUS_PF2 */ 0x78, /* FOCUS_PF9 */
+ 0x00, /* 0x75 */ 0x00, /* 0x76 */
+ 0x5A, /* FOCUS_PF3 */ 0x5B, /* FOCUS_PF4 */
+ 0x5C, /* FOCUS_PF5 */ 0x5D, /* FOCUS_PF6 */
+ 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */
+ 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */
+ 0x00, /* 0x7f */
+ /* the following are for ServerNumLock handling */
+ 0x47, /* KEY_SN_KP_7 */ 0x48, /* KEY_SN_KP_8 */
+ 0x49, /* KEY_SN_KP_9 */ 0x4b, /* KEY_SN_KP_4 */
+ 0x4c, /* KEY_SN_KP_5 */ 0x4d, /* KEY_SN_KP_6 */
+ 0x4f, /* KEY_SN_KP_1 */ 0x50, /* KEY_SN_KP_2 */
+ 0x51, /* KEY_SN_KP_3 */ 0x52, /* KEY_SN_KP_0 */
+ 0x53, /* KEY_SN_KP_Decimal */ 0x66, /* KEY_SN_Home */
+ 0x67, /* KEY_SN_Up */ 0x68, /* KEY_SN_Prior */
+ 0x69, /* KEY_SN_Left */ 0x5d, /* KEY_SN_Begin */
+ 0x6a, /* KEY_SN_Right */ 0x6b, /* KEY_SN_End */
+ 0x6c, /* KEY_SN_Down */ 0x6d, /* KEY_SN_Next */
+ 0x6e, /* KEY_SN_Ins */ 0x6f /* KEY_SN_Del */
+};
+#define NUM_AT2LNX (sizeof(at2lnx) / sizeof(at2lnx[0]))
+
+#else /* !ASSUME_CUSTOM_KEYCODES */
+
+#define NUM_AT2LNX NR_KEYS
+
+u_char SpecialServerMap[NR_KEYS];
+
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+
+static void
+readKernelMapping(KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ KeySym *k;
+ int i;
+ static unsigned char tbl[GLYPHS_PER_KEY] =
+ {
+ 0, /* unshifted */
+ 1, /* shifted */
+ 0, /* modeswitch unshifted */
+ 0 /* modeswitch shifted */
+ };
+
+ /*
+ * Read the mapping from the kernel.
+ * Since we're still using the XFree86 scancode->AT keycode mapping
+ * routines, we need to convert the AT keycodes to Linux keycodes,
+ * then translate the Linux keysyms into X keysyms.
+ *
+ * First, figure out which tables to use for the modeswitch columns
+ * above, from the XF86Config fields.
+ */
+ if (xf86Info.specialKeyMap[K_INDEX_RIGHTCTL] == KM_MODESHIFT ||
+ xf86Info.specialKeyMap[K_INDEX_RIGHTCTL] == KM_MODELOCK)
+ tbl[2] = 4; /* control */
+ else if (xf86Info.specialKeyMap[K_INDEX_RIGHTALT] == KM_MODESHIFT ||
+ xf86Info.specialKeyMap[K_INDEX_RIGHTALT] == KM_MODELOCK)
+ tbl[2] = 2; /* AltGr */
+ else
+ tbl[2] = 8; /* alt */
+ tbl[3] = tbl[2] | 1;
+
+#ifndef ASSUME_CUSTOM_KEYCODES
+ for (i = 0, k = map+GLYPHS_PER_KEY; i < NUM_AT2LNX; ++i)
+#else /* !ASSUME_CUSTOM_KEYCODES */
+ for (i = 0, k = map; i < NUM_AT2LNX; ++i)
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+ {
+ struct kbentry kbe;
+ int j;
+
+#ifndef ASSUME_CUSTOM_KEYCODES
+ kbe.kb_index = at2lnx[i];
+#else /* !ASSUME_CUSTOM_KEYCODES */
+ kbe.kb_index = i;
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+
+ for (j = 0; j < GLYPHS_PER_KEY; ++j, ++k)
+ {
+ unsigned short kval;
+
+ *k = NoSymbol;
+
+ kbe.kb_table = tbl[j];
+ if (
+#ifndef ASSUME_CUSTOM_KEYCODES
+ kbe.kb_index == 0 ||
+#endif /* !ASSUME_CUSTOM_KEYCODES */
+ ioctl(xf86Info.consoleFd, KDGKBENT, &kbe))
+ continue;
+
+ kval = KVAL(kbe.kb_value);
+ switch (KTYP(kbe.kb_value))
+ {
+ case KT_LATIN:
+ case KT_LETTER:
+ *k = linux_to_x[kval];
+ break;
+
+ case KT_FN:
+ if (kval <= 19)
+ *k = XK_F1 + kval;
+ else switch (kbe.kb_value)
+ {
+ case K_FIND:
+ *k = XK_Home; /* or XK_Find */
+ break;
+ case K_INSERT:
+ *k = XK_Insert;
+ break;
+ case K_REMOVE:
+ *k = XK_Delete;
+ break;
+ case K_SELECT:
+ *k = XK_End; /* or XK_Select */
+ break;
+ case K_PGUP:
+ *k = XK_Prior;
+ break;
+ case K_PGDN:
+ *k = XK_Next;
+ break;
+ case K_HELP:
+ *k = XK_Help;
+ break;
+ case K_DO:
+ *k = XK_Execute;
+ break;
+ case K_PAUSE:
+ *k = XK_Pause;
+ break;
+ case K_MACRO:
+ *k = XK_Menu;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_SPEC:
+ switch (kbe.kb_value)
+ {
+ case K_ENTER:
+ *k = XK_Return;
+ break;
+ case K_BREAK:
+ *k = XK_Break;
+ break;
+ case K_CAPS:
+ *k = XK_Caps_Lock;
+ break;
+ case K_NUM:
+ *k = XK_Num_Lock;
+ break;
+ case K_HOLD:
+ *k = XK_Scroll_Lock;
+ break;
+ case K_COMPOSE:
+ *k = XK_Multi_key;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case KT_PAD:
+ switch (kbe.kb_value)
+ {
+ case K_PPLUS:
+ *k = XK_KP_Add;
+ break;
+ case K_PMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ case K_PSTAR:
+ *k = XK_KP_Multiply;
+ break;
+ case K_PSLASH:
+ *k = XK_KP_Divide;
+ break;
+ case K_PENTER:
+ *k = XK_KP_Enter;
+ break;
+ case K_PCOMMA:
+ *k = XK_KP_Separator;
+ break;
+ case K_PDOT:
+ *k = XK_KP_Decimal;
+ break;
+ case K_PPLUSMINUS:
+ *k = XK_KP_Subtract;
+ break;
+ default:
+ if (kval <= 9)
+ *k = XK_KP_0 + kval;
+ break;
+ }
+ break;
+
+ /*
+ * KT_DEAD keys are for accelerated diacritical creation.
+ */
+ case KT_DEAD:
+ switch (kbe.kb_value)
+ {
+ case K_DGRAVE:
+ *k = XK_dead_grave;
+ break;
+ case K_DACUTE:
+ *k = XK_dead_acute;
+ break;
+ case K_DCIRCM:
+ *k = XK_dead_circumflex;
+ break;
+ case K_DTILDE:
+ *k = XK_dead_tilde;
+ break;
+ case K_DDIERE:
+ *k = XK_dead_diaeresis;
+ break;
+ }
+ break;
+
+ case KT_CUR:
+ switch (kbe.kb_value)
+ {
+ case K_DOWN:
+ *k = XK_Down;
+ break;
+ case K_LEFT:
+ *k = XK_Left;
+ break;
+ case K_RIGHT:
+ *k = XK_Right;
+ break;
+ case K_UP:
+ *k = XK_Up;
+ break;
+ }
+ break;
+
+ case KT_SHIFT:
+ switch (kbe.kb_value)
+ {
+ case K_ALTGR:
+ *k = XK_Alt_R;
+ break;
+ case K_ALT:
+ *k = (kbe.kb_index == 0x64 ?
+ XK_Alt_R : XK_Alt_L);
+ break;
+ case K_CTRL:
+ *k = (kbe.kb_index == 0x61 ?
+ XK_Control_R : XK_Control_L);
+ break;
+ case K_CTRLL:
+ *k = XK_Control_L;
+ break;
+ case K_CTRLR:
+ *k = XK_Control_R;
+ break;
+ case K_SHIFT:
+ *k = (kbe.kb_index == 0x36 ?
+ XK_Shift_R : XK_Shift_L);
+ break;
+ case K_SHIFTL:
+ *k = XK_Shift_L;
+ break;
+ case K_SHIFTR:
+ *k = XK_Shift_R;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /*
+ * KT_ASCII keys accumulate a 3 digit decimal number that gets
+ * emitted when the shift state changes. We can't emulate that.
+ */
+ case KT_ASCII:
+ break;
+
+ case KT_LOCK:
+ if (kbe.kb_value == K_SHIFTLOCK)
+ *k = XK_Shift_Lock;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (k[-1] == k[-2]) k[-1] = NoSymbol;
+ if (k[-2] == k[-3]) k[-2] = NoSymbol;
+ if (k[-3] == k[-4]) k[-3] = NoSymbol;
+ if (k[-4] == k[-2] && k[-3] == k[-1]) k[-2] = k[-1] = NoSymbol;
+ if (k[-1] == k[-4] && k[-2] == k[-3] && k[-2] == NoSymbol) k[-1] =NoSymbol;
+ }
+#ifdef ASSUME_CUSTOM_KEYCODES
+ /*
+ * Find the Mapping for the special server functions
+ */
+ for (i = 0; i < NR_KEYS; ++i) {
+ struct kbentry kbe;
+ int special = 0;
+
+ kbe.kb_index = i;
+ kbe.kb_table = 0; /* Plain map */
+ if (!ioctl(xf86Info.consoleFd, KDGKBENT, &kbe))
+ switch (kbe.kb_value) {
+ case K(KT_LATIN,0x7f): /* This catches DEL too... But who cares? */
+ special = KEY_BackSpace;
+ break;
+ case K_PMINUS:
+ special = KEY_KP_Minus;
+ break;
+ case K_PPLUS:
+ special = KEY_KP_Plus;
+ break;
+ case K_F1:
+ special = KEY_F1;
+ break;
+ case K_F2:
+ special = KEY_F2;
+ break;
+ case K_F3:
+ special = KEY_F3;
+ break;
+ case K_F4:
+ special = KEY_F4;
+ break;
+ case K_F5:
+ special = KEY_F5;
+ break;
+ case K_F6:
+ special = KEY_F6;
+ break;
+ case K_F7:
+ special = KEY_F7;
+ break;
+ case K_F8:
+ special = KEY_F8;
+ break;
+ case K_F9:
+ special = KEY_F9;
+ break;
+ case K_F10:
+ special = KEY_F10;
+ break;
+ case K_F11:
+ special = KEY_F11;
+ break;
+ case K_F12:
+ special = KEY_F12;
+ break;
+ case K_ALT:
+ special = KEY_Alt;
+ break;
+ case K_ALTGR:
+ special = KEY_AltLang;
+ break;
+ case K_CONS:
+ special = KEY_SysReqest;
+ break;
+ }
+ SpecialServerMap[i] = special;
+ }
+#endif /* ASSUME_CUSTOM_KEYCODES */
+}
diff --git a/hw/xfree86/common/xf86KbdMach.c b/hw/xfree86/common/xf86KbdMach.c
new file mode 100644
index 000000000..cc23ee8e0
--- /dev/null
+++ b/hw/xfree86/common/xf86KbdMach.c
@@ -0,0 +1,312 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86KbdMach.c,v 3.7 1996/12/23 06:43:32 dawes Exp $ */
+/*
+ *****************************************************************************
+ * HISTORY
+ * Log: xf86KbdMach.c,v
+ * Revision 2.1.2.1 92/06/25 10:32:08 moore
+ * Incorporate the Elliot Dresselhaus's, Ernest Hua's and local changes
+ * to run Thomas Roell's I386 color X11R5. Original code only worked
+ * with SCO Unix. New code works with 2.5 and 3.0 Mach
+ * [92/06/24 rvb]
+ *
+ * EndLog
+ *
+ *****************************************************************************
+ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86KbdMach.c,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "atKeynames.h"
+#include "xf86_Config.h"
+
+#include "xf86Keymap.h"
+
+static KeySym ascii_to_x[256] = {
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol,
+ NoSymbol, XK_Return, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, XK_Escape,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_space, XK_exclam, XK_quotedbl, XK_numbersign,
+ XK_dollar, XK_percent, XK_ampersand, XK_apostrophe,
+ XK_parenleft, XK_parenright, XK_asterisk, XK_plus,
+ XK_comma, XK_minus, XK_period, XK_slash,
+ XK_0, XK_1, XK_2, XK_3,
+ XK_4, XK_5, XK_6, XK_7,
+ XK_8, XK_9, XK_colon, XK_semicolon,
+ XK_less, XK_equal, XK_greater, XK_question,
+ XK_at, XK_A, XK_B, XK_C,
+ XK_D, XK_E, XK_F, XK_G,
+ XK_H, XK_I, XK_J, XK_K,
+ XK_L, XK_M, XK_N, XK_O,
+ XK_P, XK_Q, XK_R, XK_S,
+ XK_T, XK_U, XK_V, XK_W,
+ XK_X, XK_Y, XK_Z, XK_bracketleft,
+ XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore,
+ XK_grave, XK_a, XK_b, XK_c,
+ XK_d, XK_e, XK_f, XK_g,
+ XK_h, XK_i, XK_j, XK_k,
+ XK_l, XK_m, XK_n, XK_o,
+ XK_p, XK_q, XK_r, XK_s,
+ XK_t, XK_u, XK_v, XK_w,
+ XK_x, XK_y, XK_z, XK_braceleft,
+ XK_bar, XK_braceright, XK_asciitilde, XK_Delete,
+ XK_Ccedilla, XK_udiaeresis, XK_eacute, XK_acircumflex,
+ XK_adiaeresis, XK_agrave, XK_aring, XK_ccedilla,
+ XK_ecircumflex, XK_ediaeresis, XK_egrave, XK_idiaeresis,
+ XK_icircumflex, XK_igrave, XK_Adiaeresis, XK_Aring,
+ XK_Eacute, XK_ae, XK_AE, XK_ocircumflex,
+ XK_odiaeresis, XK_ograve, XK_ucircumflex, XK_ugrave,
+ XK_ydiaeresis, XK_Odiaeresis, XK_Udiaeresis, XK_cent,
+ XK_sterling, XK_yen, XK_paragraph, XK_section,
+ XK_aacute, XK_iacute, XK_oacute, XK_uacute,
+ XK_ntilde, XK_Ntilde, XK_ordfeminine, XK_masculine,
+ XK_questiondown,XK_hyphen, XK_notsign, XK_onehalf,
+ XK_onequarter, XK_exclamdown, XK_guillemotleft,XK_guillemotright,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ XK_Greek_alpha, XK_ssharp, XK_Greek_GAMMA, XK_Greek_pi,
+ XK_Greek_SIGMA, XK_Greek_sigma, XK_mu, XK_Greek_tau,
+ XK_Greek_PHI, XK_Greek_THETA, XK_Greek_OMEGA, XK_Greek_delta,
+ XK_infinity, XK_Ooblique, XK_Greek_epsilon, XK_intersection,
+ XK_identical, XK_plusminus, XK_greaterthanequal, XK_lessthanequal,
+ XK_topintegral, XK_botintegral, XK_division, XK_similarequal,
+ XK_degree, NoSymbol, NoSymbol, XK_radical,
+ XK_Greek_eta, XK_twosuperior, XK_periodcentered, NoSymbol,
+ };
+
+/*
+ * LegalModifier --
+ * determine whether a key is a legal modifier key, i.e send a
+ * press/release sequence.
+ */
+
+/*ARGSUSED*/
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return (TRUE);
+}
+
+
+
+/*
+ * xf86KbdGetMapping --
+ * Get the national keyboard mapping. The keyboard type is set, a new map
+ * and the modifiermap is computed.
+ */
+
+void
+xf86KbdGetMapping (pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+ KeySym *k;
+ struct kbentry kbe;
+ char type;
+ int i, j;
+
+ for (i = 0; i < NUMKEYS; i++)
+ {
+ static int states[] = { NORM_STATE, SHIFT_STATE, ALT_STATE, SHIFT_ALT };
+ int j;
+
+ k = &map[i*4];
+ kbe.kb_index = i;
+
+ for (j = 0; j < 4; j++)
+ {
+ kbe.kb_state = states[j];
+
+ if (ioctl (xf86Info.consoleFd, KDGKBENT, &kbe) != -1)
+ continue;
+
+ if (kbe.kb_value [0] == K_SCAN)
+ {
+ int keycode = -1;
+ switch (kbe.kb_value [1])
+ {
+ case K_CTLSC: keycode = XK_Control_L; break;
+ case K_LSHSC: keycode = XK_Shift_L; break;
+ case K_RSHSC: keycode = XK_Shift_R; break;
+ case K_ALTSC: keycode = XK_Alt_L; break;
+ case K_CLCKSC: keycode = XK_Caps_Lock; break;
+ case K_NLCKSC: keycode = XK_Num_Lock; break;
+ default: break;
+ }
+ if (keycode > 0)
+ k[j] = keycode;
+ }
+ else if (kbe.kb_value[1] != NC)
+ {
+ /* How to handle multiple characters?
+ Ignore them for now. */
+ }
+ else
+ {
+ k[j] = ascii_to_x[kbe.kb_value[0]];
+ }
+ }
+ }
+
+ /*
+ * Apply the special key mapping specified in XF86Config
+ */
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4) {
+ switch (k[0]) {
+ case XK_Alt_L:
+ j = K_INDEX_LEFTALT;
+ break;
+ case XK_Alt_R:
+ j = K_INDEX_RIGHTALT;
+ break;
+ case XK_Scroll_Lock:
+ j = K_INDEX_SCROLLLOCK;
+ break;
+ case XK_Control_R:
+ j = K_INDEX_RIGHTCTL;
+ break;
+ default:
+ j = -1;
+ }
+ if (j >= 0)
+ switch (xf86Info.specialKeyMap[j]) {
+ case KM_META:
+ if (k[0] == XK_Alt_R)
+ k[1] = XK_Meta_R;
+ else {
+ k[0] = XK_Alt_L;
+ k[1] = XK_Meta_L;
+ }
+ break;
+ case KM_COMPOSE:
+ k[0] = XK_Multi_key;
+ break;
+ case KM_MODESHIFT:
+ k[0] = XK_Mode_switch;
+ k[1] = NoSymbol;
+ break;
+ case KM_MODELOCK:
+ k[0] = XK_Mode_switch;
+ k[1] = XF86XK_ModeLock;
+ break;
+ case KM_SCROLLLOCK:
+ k[0] = XK_Scroll_Lock;
+ break;
+ case KM_CONTROL:
+ k[0] = XK_Control_R;
+ break;
+ }
+ }
+
+ /*
+ * compute the modifier map
+ */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ for (k = map, i = MIN_KEYCODE;
+ i < (NUM_KEYCODES + MIN_KEYCODE);
+ i++, k += 4)
+
+ switch(*k) {
+
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ if (!xf86Info.serverNumLock) pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+ /* kana support */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+
+ }
+
+ xf86Info.kbdType =
+ ioctl(xf86Info.kbdFd, KDGKBDTYPE, &type) != -1 ? type : KB_VANILLAKB;
+
+ pKeySyms->map = map;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ if (xf86Info.serverNumLock)
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+ else
+ pKeySyms->maxKeyCode = MAX_STD_KEYCODE;
+
+}
diff --git a/hw/xfree86/common/xf86Keymap.h b/hw/xfree86/common/xf86Keymap.h
new file mode 100644
index 000000000..2b9debff4
--- /dev/null
+++ b/hw/xfree86/common/xf86Keymap.h
@@ -0,0 +1,449 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h,v 3.9 1996/12/23 06:43:35 dawes Exp $ */
+/*
+ *
+ * For Scancodes see notes in atKeynames.h !!!!
+ *
+ */
+/* $Xorg: xf86Keymap.h,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = {
+#ifndef PC98
+ /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol,
+ /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol,
+ /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol,
+ /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol,
+ /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol,
+ /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol,
+ /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol,
+ /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol,
+ /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol,
+ /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol,
+ /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol,
+ /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol,
+ /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol,
+ /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol,
+ /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol,
+ /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol,
+ /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol,
+ /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol,
+ /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol,
+ /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol,
+ /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol,
+ /* 0x4c */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol,
+ /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol,
+ /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol,
+ /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol,
+ /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+
+ /* 0x59 */ XK_Home, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5c */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5d */ XK_Begin, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5e */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ XK_End, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x61 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x62 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x63 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_Break, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x73 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+#else /* PC98 */
+ /* 0x00 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_1, XK_exclam, XK_kana_NU, NoSymbol,
+ /* 0x02 */ XK_2, XK_quotedbl, XK_kana_FU, NoSymbol,
+ /* 0x03 */ XK_3, XK_numbersign, XK_kana_A, XK_kana_a,
+ /* 0x04 */ XK_4, XK_dollar, XK_kana_U, XK_kana_u,
+ /* 0x05 */ XK_5, XK_percent, XK_kana_E, XK_kana_e,
+ /* 0x06 */ XK_6, XK_ampersand, XK_kana_O, XK_kana_o,
+ /* 0x07 */ XK_7, XK_quoteright, XK_kana_YA, XK_kana_ya,
+ /* 0x08 */ XK_8, XK_parenleft, XK_kana_YU, XK_kana_yu,
+ /* 0x09 */ XK_9, XK_parenright, XK_kana_YO, XK_kana_yo,
+ /* 0x0a */ XK_0, NoSymbol, XK_kana_WA, XK_kana_WO,
+ /* 0x0b */ XK_minus, XK_equal, XK_kana_HO, NoSymbol,
+ /* 0x0c */ XK_asciicircum, XK_quoteleft, XK_kana_HE, NoSymbol,
+ /* 0x0d */ XK_backslash, XK_bar, XK_prolongedsound, NoSymbol,
+ /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Q, NoSymbol, XK_kana_TA, NoSymbol,
+ /* 0x11 */ XK_W, NoSymbol, XK_kana_TE, NoSymbol,
+ /* 0x12 */ XK_E, NoSymbol, XK_kana_I, XK_kana_i,
+ /* 0x13 */ XK_R, NoSymbol, XK_kana_SU, NoSymbol,
+ /* 0x14 */ XK_T, NoSymbol, XK_kana_KA, NoSymbol,
+ /* 0x15 */ XK_Y, NoSymbol, XK_kana_N, NoSymbol,
+ /* 0x16 */ XK_U, NoSymbol, XK_kana_NA, NoSymbol,
+ /* 0x17 */ XK_I, NoSymbol, XK_kana_NI, NoSymbol,
+ /* 0x18 */ XK_O, NoSymbol, XK_kana_RA, NoSymbol,
+ /* 0x19 */ XK_P, NoSymbol, XK_kana_SE, NoSymbol,
+ /* 0x1a */ XK_at, XK_asciitilde, XK_voicedsound, NoSymbol,
+ /* 0x1b */ XK_bracketleft, XK_braceleft, XK_semivoicedsound, XK_kana_openingbracket,
+ /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_A, NoSymbol, XK_kana_CHI, NoSymbol,
+ /* 0x1e */ XK_S, NoSymbol, XK_kana_TO, NoSymbol,
+ /* 0x1f */ XK_D, NoSymbol, XK_kana_SHI, NoSymbol,
+ /* 0x20 */ XK_F, NoSymbol, XK_kana_HA, NoSymbol,
+ /* 0x21 */ XK_G, NoSymbol, XK_kana_KI, NoSymbol,
+ /* 0x22 */ XK_H, NoSymbol, XK_kana_KU, NoSymbol,
+ /* 0x23 */ XK_J, NoSymbol, XK_kana_MA, NoSymbol,
+ /* 0x24 */ XK_K, NoSymbol, XK_kana_NO, NoSymbol,
+ /* 0x25 */ XK_L, NoSymbol, XK_kana_RI, NoSymbol,
+ /* 0x26 */ XK_semicolon, XK_plus, XK_kana_RE, NoSymbol,
+ /* 0x27 */ XK_colon, XK_asterisk, XK_kana_KE, NoSymbol,
+ /* 0x28 */ XK_bracketright,XK_braceright, XK_kana_MU, XK_kana_closingbracket,
+ /* 0x29 */ XK_Z, NoSymbol, XK_kana_TSU, NoSymbol,
+ /* 0x2a */ XK_X, NoSymbol, XK_kana_SA, NoSymbol,
+ /* 0x2b */ XK_C, NoSymbol, XK_kana_SO, NoSymbol,
+ /* 0x2c */ XK_V, NoSymbol, XK_kana_HI, NoSymbol,
+ /* 0x2d */ XK_B, NoSymbol, XK_kana_KO, NoSymbol,
+ /* 0x2e */ XK_N, NoSymbol, XK_kana_MI, NoSymbol,
+ /* 0x2f */ XK_M, NoSymbol, XK_kana_MO, NoSymbol,
+ /* 0x30 */ XK_comma, XK_less, XK_kana_NE, XK_kana_comma,
+ /* 0x31 */ XK_period, XK_greater, XK_kana_RU, XK_kana_fullstop,
+ /* 0x32 */ XK_slash, XK_question, XK_kana_ME, XK_kana_middledot,
+ /* 0x33 */ XK_underscore, XK_underscore, XK_kana_RO, NoSymbol,
+ /* 0x34 */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_Henkan, XK_Kanji, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x38 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_Clear, XK_Home, NoSymbol, NoSymbol,
+ /* 0x3f */ XK_Help, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x48 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x49 */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4a */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4c */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4d */ XK_KP_Equal, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4e */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_KP_Separator,NoSymbol, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_Muhenkan, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x52 */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_F13, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ XK_F14, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_F15, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x57 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ XK_Break, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x61 */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x62 */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x63 */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ XK_kana_switch, NoSymbol, XK_kana_switch, NoSymbol,
+ /* 0x73 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x74 */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+#endif /* PC98 */
+ /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+
+ /* These are for ServerNumLock handling */
+ /* 0x80 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x81 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x82 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x83 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x84 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x85 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x86 */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x87 */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x88 */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x89 */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8a */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8b */ XK_Home, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8c */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8d */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8e */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8f */ XK_Begin, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x90 */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x91 */ XK_End, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x92 */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x93 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x94 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x95 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+};
+
+static KeySym map84[NUM_KEYCODES * GLYPHS_PER_KEY] = {
+ /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol,
+ /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol,
+ /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol,
+ /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol,
+ /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol,
+ /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol,
+ /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol,
+ /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol,
+ /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol,
+ /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol,
+ /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol,
+ /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol,
+ /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x0f */ XK_Tab, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol,
+ /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol,
+ /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol,
+ /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol,
+ /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol,
+ /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol,
+ /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol,
+ /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol,
+ /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol,
+ /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol,
+ /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol,
+ /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol,
+ /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol,
+ /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol,
+ /* 0x4c */ NoSymbol, XK_KP_5, NoSymbol, NoSymbol,
+ /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol,
+ /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol,
+ /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol,
+ /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol,
+ /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol,
+ /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol,
+ /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol,
+ /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol,
+
+ /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x5f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x60 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x61 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x62 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x63 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x64 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x65 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x66 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x67 */ XK_Print, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x68 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x69 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol,
+ /* 0x6a */ XK_Break, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6b */ XK_Meta_L, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6c */ XK_Meta_R, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6d */ XK_Menu, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x6f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x70 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x71 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x72 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x73 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x77 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol,
+
+ /* These are for ServerNumLock handling */
+ /* 0x80 */ XK_KP_7, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x81 */ XK_KP_8, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x82 */ XK_KP_9, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x83 */ XK_KP_4, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x84 */ XK_KP_5, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x85 */ XK_KP_6, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x86 */ XK_KP_1, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x87 */ XK_KP_2, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x88 */ XK_KP_3, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x89 */ XK_KP_0, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8a */ XK_KP_Decimal, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8b */ XK_Home, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8c */ XK_Up, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8d */ XK_Prior, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8e */ XK_Left, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x8f */ XK_Begin, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x90 */ XK_Right, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x91 */ XK_End, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x92 */ XK_Down, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x93 */ XK_Next, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x94 */ XK_Insert, NoSymbol, NoSymbol, NoSymbol,
+ /* 0x95 */ XK_Delete, NoSymbol, NoSymbol, NoSymbol,
+};
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
new file mode 100644
index 000000000..3c73f6e56
--- /dev/null
+++ b/hw/xfree86/common/xf86Priv.h
@@ -0,0 +1,175 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Priv.h,v 3.24.2.1 1998/02/01 16:04:47 robin Exp $ */
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Thomas Roell not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Thomas Roell makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: xf86Priv.h,v 1.3 2000/08/17 19:50:30 cpqbld Exp $ */
+
+#ifndef _XF86PRIV_H
+#define _XF86PRIV_H
+
+#ifndef _XF86VIDMODE_SERVER_
+#include "Xproto.h"
+#include "xf86_OSproc.h"
+#endif
+
+typedef struct {
+
+ /* keyboard part */
+ DeviceIntPtr pKeyboard;
+ DeviceProc kbdProc; /* procedure for initializing */
+ void (* kbdEvents)( /* proc for processing events */
+#if NeedNestedPrototypes && !defined(__OSF__)
+ void
+#endif
+ );
+#ifndef MINIX
+ int consoleFd;
+#else
+ int kbdFd;
+#endif /* MINIX */
+#if defined(MACH386) || defined(__OSF__)
+ int kbdFd;
+#endif /* MACH386 || __OSF__ */
+ int vtno;
+ int kbdType; /* AT84 / AT101 */
+ int kbdRate;
+ int kbdDelay;
+ int bell_pitch;
+ int bell_duration;
+ Bool autoRepeat;
+ unsigned long leds;
+ unsigned long xleds;
+ char *vtinit;
+ int *specialKeyMap;
+ int scanPrefix; /* scancode-state */
+ Bool capsLock;
+ Bool numLock;
+ Bool scrollLock;
+ Bool modeSwitchLock;
+ Bool serverNumLock;
+ Bool composeLock;
+ Bool vtSysreq;
+#if defined(SVR4) && defined(i386)
+ Bool panix106;
+#endif /* SVR4 && i386 */
+
+ /* mouse part */
+ DeviceIntPtr pMouse;
+#ifdef XINPUT
+ pointer mouseLocal;
+#endif
+ MouseDevPtr mouseDev;
+
+ /* event handler part */
+ int lastEventTime;
+ Bool vtRequestsPending;
+ Bool inputPending;
+ Bool dontZap;
+ Bool dontZoom;
+ Bool notrapSignals; /* don't exit cleanly - die at fault */
+ Bool caughtSignal;
+
+ /* graphics part */
+ Bool sharedMonitor;
+ ScreenPtr currentScreen;
+#ifdef CSRG_BASED
+ int screenFd; /* fd for memory mapped access to vga card */
+ int consType; /* Which console driver? */
+#endif
+#if defined(AMOEBA)
+ void *screenPtr;
+#endif
+
+#ifdef XKB
+/*
+ * would like to use an XkbComponentNamesRec here but can't without
+ * pulling in a bunch of header files. :-(
+ */
+ char *xkbkeymap;
+ char *xkbkeycodes;
+ char *xkbtypes;
+ char *xkbcompat;
+ char *xkbsymbols;
+ char *xkbgeometry;
+ Bool xkbcomponents_specified;
+ char *xkbrules;
+ char *xkbmodel;
+ char *xkblayout;
+ char *xkbvariant;
+ char *xkboptions;
+#endif
+
+} xf86InfoRec, *xf86InfoPtr;
+
+extern xf86InfoRec xf86Info;
+
+/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */
+#define XLED1 ((unsigned long) 0x00000001)
+#define XLED2 ((unsigned long) 0x00000002)
+#define XLED3 ((unsigned long) 0x00000004)
+#define XCAPS ((unsigned long) 0x20000000)
+#define XNUM ((unsigned long) 0x40000000)
+#define XSCR ((unsigned long) 0x80000000)
+#define XCOMP ((unsigned long) 0x00008000)
+
+/* 386BSD console driver types (consType) */
+#ifdef CSRG_BASED
+#define PCCONS 0
+#define CODRV011 1
+#define CODRV01X 2
+#define SYSCONS 8
+#define PCVT 16
+#endif
+
+/* Values of xf86Info.mouseFlags */
+#define MF_CLEAR_DTR 1
+#define MF_CLEAR_RTS 2
+
+extern int xf86ScreenIndex;
+
+#define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr))
+
+extern int xf86MaxScreens;
+extern ScrnInfoPtr xf86Screens[];
+extern int xf86ScreenNames[];
+
+extern char xf86ConfigFile[];
+extern int xf86Verbose;
+extern Bool xf86ProbeOnly, xf86ProbeFailed;
+extern unsigned short xf86MouseCflags[];
+extern Bool xf86SupportedMouseTypes[];
+extern int xf86NumMouseTypes;
+extern int xf86bpp;
+extern xrgb xf86weight;
+extern Bool xf86AllowMouseOpenFail;
+extern Bool xf86BestRefresh;
+
+extern Bool xf86FlipPixels;
+#define XF86FLIP_PIXELS() \
+ if (xf86FlipPixels) { \
+ pScreen->whitePixel = (pScreen->whitePixel) ? 0 : 1; \
+ pScreen->blackPixel = (pScreen->blackPixel) ? 0 : 1; \
+ }
+
+#endif /* _XF86PRIV_H */
+
+
diff --git a/hw/xfree86/common/xf86Version.h b/hw/xfree86/common/xf86Version.h
new file mode 100644
index 000000000..f403c31f5
--- /dev/null
+++ b/hw/xfree86/common/xf86Version.h
@@ -0,0 +1,23 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/xf86Version.h,v 3.236.2.50 1998/03/02 09:58:21 dawes Exp $ */
+
+#define XF86_VERSION " 3.3.2 "
+
+/* The finer points in versions... */
+#define XF86_VERSION_MAJOR 3
+#define XF86_VERSION_MINOR 3
+#define XF86_VERSION_SUBMINOR 2
+#define XF86_VERSION_BETA 0 /* 0="", 1="A", 2="B", etc... */
+#define XF86_VERSION_ALPHA 0 /* 0="", 1="a", 2="b", etc... */
+
+#define XF86_VERSION_NUMERIC(major,minor,subminor,beta,alpha) \
+ ((((((((major << 7) | minor) << 7) | subminor) << 5) | beta) << 5) | alpha)
+#define XF86_VERSION_CURRENT \
+ XF86_VERSION_NUMERIC(XF86_VERSION_MAJOR, \
+ XF86_VERSION_MINOR, \
+ XF86_VERSION_SUBMINOR, \
+ XF86_VERSION_BETA, \
+ XF86_VERSION_ALPHA)
+
+#define XF86_DATE "March 2 1998"
+
+/* $Xorg: xf86Version.h,v 1.3 2000/08/17 19:48:48 cpqbld Exp $ */
diff --git a/hw/xfree86/common/xf86XKB.c b/hw/xfree86/common/xf86XKB.c
new file mode 100644
index 000000000..c5ac740fd
--- /dev/null
+++ b/hw/xfree86/common/xf86XKB.c
@@ -0,0 +1,118 @@
+/* $Xorg: xf86XKB.c,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */
+/************************************************************
+Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+********************************************************/
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86XKB.c,v 3.6 1996/12/28 11:14:43 dawes Exp $ */
+
+#include <stdio.h>
+#define NEED_EVENTS 1
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/keysym.h>
+#include "inputstr.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "XI.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+#include "xf86_Config.h"
+
+#include "XKBsrv.h"
+
+#ifdef AMOEBA
+#define LED_CAP IOP_LED_CAP
+#define LED_NUM IOP_LED_NUM
+#define LED_SCR IOP_LED_SCROLL
+#endif
+
+#ifdef MINIX
+#define LED_CAP KBD_LEDS_CAPS
+#define LED_NUM KBD_LEDS_NUM
+#define LED_SCR KBD_LEDS_SCROLL
+#endif
+
+void
+xf86InitXkb()
+{
+}
+
+void
+#if NeedFunctionPrototypes
+XkbDDXUpdateIndicators(DeviceIntPtr pXDev,CARD32 new)
+#else
+XkbDDXUpdateIndicators(pXDev,new)
+ DeviceIntPtr pXDev;
+ CARD32 new;
+#endif
+{
+ CARD32 old;
+#ifdef DEBUG
+/* if (xkbDebugFlags)*/
+ ErrorF("XkbDDXUpdateIndicators(...,0x%x) -- XFree86 version\n",new);
+#endif
+#ifdef LED_CAP
+ old= new;
+ new= 0;
+ if (old&XLED1) new|= LED_CAP;
+ if (old&XLED2) new|= LED_NUM;
+ if (old&XLED3) new|= LED_SCR;
+#endif
+ xf86SetKbdLeds(new);
+ return;
+}
+
+void
+#if NeedFunctionPrototypes
+XkbDDXUpdateDeviceIndicators( DeviceIntPtr dev,
+ XkbSrvLedInfoPtr sli,
+ CARD32 new)
+#else
+XkbDDXUpdateDeviceIndicators(dev,sli,new)
+ DeviceIntPtr dev;
+ XkbSrvLedInfoPtr sli;
+ CARD32 new;
+#endif
+{
+ if (sli->fb.kf==dev->kbdfeed)
+ XkbDDXUpdateIndicators(dev,new);
+ else if (sli->class==KbdFeedbackClass) {
+ KbdFeedbackPtr kf;
+ kf= sli->fb.kf;
+ if (kf && kf->CtrlProc) {
+ (*kf->CtrlProc)(dev,&kf->ctrl);
+ }
+ }
+ else if (sli->class==LedFeedbackClass) {
+ LedFeedbackPtr lf;
+ lf= sli->fb.lf;
+ if (lf && lf->CtrlProc) {
+ (*lf->CtrlProc)(dev,&lf->ctrl);
+ }
+ }
+ return;
+}
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
new file mode 100644
index 000000000..7659deb3f
--- /dev/null
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -0,0 +1,1264 @@
+/* $Xorg: xf86Xinput.c,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */
+/*
+ * Copyright 1995,1996 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.c,v 3.22.2.7 1998/02/07 10:05:22 hohndel Exp $ */
+
+#include "Xmd.h"
+#include "XI.h"
+#include "XIproto.h"
+#include "xf86.h"
+#include "Xpoll.h"
+#include "xf86Priv.h"
+#include "xf86_Config.h"
+#include "xf86Xinput.h"
+#include "xf86Procs.h"
+#include "mipointer.h"
+
+#ifdef DPMSExtension
+#include "extensions/dpms.h"
+#endif
+
+#include "exevents.h" /* AddInputDevice */
+
+#include "extnsionst.h"
+#include "extinit.h" /* LookupDeviceIntRec */
+
+#include "windowstr.h" /* screenIsSaved */
+
+#include <stdarg.h>
+
+extern InputInfo inputInfo;
+
+#ifndef DYNAMIC_MODULE
+#ifdef JOYSTICK_SUPPORT
+extern DeviceAssocRec joystick_assoc;
+#endif
+#ifdef WACOM_SUPPORT
+extern DeviceAssocRec wacom_stylus_assoc;
+extern DeviceAssocRec wacom_cursor_assoc;
+extern DeviceAssocRec wacom_eraser_assoc;
+#endif
+#ifdef ELOGRAPHICS_SUPPORT
+extern DeviceAssocRec elographics_assoc;
+#endif
+#ifdef SUMMASKETCH_SUPPORT
+extern DeviceAssocRec summasketch_assoc;
+#endif
+#endif
+
+extern DeviceAssocRec mouse_assoc;
+
+static int num_devices;
+static LocalDevicePtr *localDevices;
+static int max_devices;
+
+static DeviceAssocPtr *deviceAssoc = NULL;
+static int numAssoc = 0;
+static int maxAssoc = 0;
+
+static SymTabRec XinputTab[] = {
+ { ENDSECTION, "endsection"},
+ { SUBSECTION, "subsection" },
+ { -1, "" },
+};
+
+/***********************************************************************
+ *
+ * xf86AlwaysCoreControl --
+ *
+ * Control proc for the integer feedback that controls the always
+ * core feature.
+ *
+ ***********************************************************************
+ */
+static void
+xf86AlwaysCoreControl(DeviceIntPtr device,
+ IntegerCtrl *control)
+{
+}
+
+/***********************************************************************
+ *
+ * Core devices functions --
+ *
+ * Test if device is the core device by checking the
+ * value of always core feedback and the inputInfo struct.
+ *
+ ***********************************************************************
+ */
+int
+xf86IsCorePointer(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ return((local->always_core_feedback &&
+ local->always_core_feedback->ctrl.integer_displayed) ||
+ (device == inputInfo.pointer));
+}
+
+static int
+xf86IsAlwaysCore(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ return(local->always_core_feedback &&
+ local->always_core_feedback->ctrl.integer_displayed);
+}
+
+int
+xf86IsCoreKeyboard(DeviceIntPtr device)
+{
+ LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
+
+ return((local->flags & XI86_ALWAYS_CORE) ||
+ (device == inputInfo.keyboard));
+}
+
+void
+xf86AlwaysCore(LocalDevicePtr local,
+ Bool always)
+{
+ if (always) {
+ local->flags |= XI86_ALWAYS_CORE;
+ } else {
+ local->flags &= ~XI86_ALWAYS_CORE;
+ }
+}
+
+/***********************************************************************
+ *
+ * xf86CheckButton --
+ *
+ * Test if the core pointer button state is coherent with
+ * the button event to send.
+ *
+ ***********************************************************************
+ */
+Bool
+xf86CheckButton(int button,
+ int down)
+{
+ /* The device may have up to MSE_MAXBUTTONS (12) buttons. */
+ int state = (inputInfo.pointer->button->state & 0x0fff00) >> 8;
+ int check = (state & (1 << (button - 1)));
+
+ if ((check && down) && (!check && !down)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/***********************************************************************
+ *
+ * ReadInput --
+ * Wakeup handler to catch input and dispatch it to our
+ * input routines if necessary.
+ *
+ ***********************************************************************
+ */
+static void
+ReadInput(pointer block_data,
+ int select_status,
+ pointer read_mask)
+{
+ int i;
+ LocalDevicePtr local_dev;
+ fd_set* LastSelectMask = (fd_set*) read_mask;
+ fd_set devices_with_input;
+ extern fd_set EnabledDevices;
+
+ if (select_status < 1)
+ return;
+
+ XFD_ANDSET(&devices_with_input, LastSelectMask, &EnabledDevices);
+ if (!XFD_ANYSET(&devices_with_input))
+ return;
+
+ for (i = 0; i < num_devices; i++) {
+ local_dev = localDevices[i];
+ if (local_dev->read_input &&
+ (local_dev->fd >= 0) &&
+ (FD_ISSET(local_dev->fd, ((fd_set *) read_mask)) != 0)) {
+ (*local_dev->read_input)(local_dev);
+ break;
+ }
+ }
+}
+
+/***********************************************************************
+ *
+ * configExtendedInputSection --
+ *
+ ***********************************************************************
+ */
+
+void
+xf86ConfigExtendedInputSection(LexPtr val)
+{
+ int i;
+ int token;
+
+#ifndef DYNAMIC_MODULE
+# ifdef JOYSTICK_SUPPORT
+ xf86AddDeviceAssoc(&joystick_assoc);
+# endif
+# ifdef WACOM_SUPPORT
+ xf86AddDeviceAssoc(&wacom_stylus_assoc);
+ xf86AddDeviceAssoc(&wacom_cursor_assoc);
+ xf86AddDeviceAssoc(&wacom_eraser_assoc);
+# endif
+# ifdef ELOGRAPHICS_SUPPORT
+ xf86AddDeviceAssoc(&elographics_assoc);
+# endif
+# ifdef SUMMASKETCH_SUPPORT
+ xf86AddDeviceAssoc(&summasketch_assoc);
+# endif
+#endif
+
+ xf86AddDeviceAssoc(&mouse_assoc);
+
+ num_devices = 0;
+ max_devices = 3;
+ localDevices = (LocalDevicePtr*) xalloc(sizeof(LocalDevicePtr)*max_devices);
+
+ while ((token = xf86GetToken(XinputTab)) != ENDSECTION)
+ {
+ if (token == SUBSECTION)
+ {
+ int found = 0;
+
+ if (xf86GetToken(NULL) != STRING)
+ xf86ConfigError("SubSection name expected");
+
+ for(i=0; !found && i<numAssoc; i++)
+ {
+ if (StrCaseCmp(val->str, deviceAssoc[i]->config_section_name) == 0)
+ {
+ if (num_devices == max_devices) {
+ max_devices *= 2;
+ localDevices = (LocalDevicePtr*) xrealloc(localDevices,
+ sizeof(LocalDevicePtr)*max_devices);
+ }
+ localDevices[num_devices] = deviceAssoc[i]->device_allocate();
+
+ if (localDevices[num_devices] && localDevices[num_devices]->device_config)
+ {
+ (*localDevices[num_devices]->device_config)(localDevices,
+ num_devices,
+ num_devices+1,
+ val);
+ localDevices[num_devices]->flags |= XI86_CONFIGURED;
+ num_devices++;
+ }
+ found = 1;
+ }
+ }
+ if (!found)
+ xf86ConfigError("Invalid SubSection name");
+ }
+ else
+ xf86ConfigError("XInput keyword section expected");
+ }
+}
+
+/***********************************************************************
+ *
+ * xf86AddDeviceAssoc --
+ *
+ * Add an association to the array deviceAssoc. This is needed to
+ * allow dynamic loading of devices to register themself.
+ *
+ ***********************************************************************
+ */
+void
+xf86AddDeviceAssoc(DeviceAssocPtr assoc)
+{
+ if (!deviceAssoc) {
+ maxAssoc = 10;
+ deviceAssoc = (DeviceAssocPtr*) xalloc(sizeof(DeviceAssocPtr)*maxAssoc);
+ } else {
+ if (maxAssoc == numAssoc) {
+ maxAssoc *= 2;
+ deviceAssoc = (DeviceAssocPtr*) xrealloc(deviceAssoc, sizeof(DeviceAssocPtr)*maxAssoc);
+ }
+ }
+ deviceAssoc[numAssoc] = assoc;
+ numAssoc++;
+}
+
+/***********************************************************************
+ *
+ * xf86XinputFinalizeInit --
+ *
+ * Create and initialize an integer feedback to control the always
+ * core feature.
+ *
+ ***********************************************************************
+ */
+void
+xf86XinputFinalizeInit(DeviceIntPtr dev)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ if (InitIntegerFeedbackClassDeviceStruct(dev, xf86AlwaysCoreControl) == FALSE) {
+ ErrorF("Unable to init integer feedback for always core feature\n");
+ } else {
+ local->always_core_feedback = dev->intfeed;
+ dev->intfeed->ctrl.integer_displayed = (local->flags & XI86_ALWAYS_CORE) ? 1 : 0;
+ }
+}
+
+
+/***********************************************************************
+ *
+ * InitExtInput --
+ *
+ * Initialize any extended devices we might have. It is called from
+ * ddx InitInput.
+ *
+ ***********************************************************************
+ */
+
+void
+InitExtInput()
+{
+ DeviceIntPtr dev;
+ int i;
+
+ /* Register a Wakeup handler to handle input when generated */
+ RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr) NoopDDA, ReadInput,
+ NULL);
+
+ /* Add each device */
+ for (i = 0; i < num_devices; i++) {
+ if (localDevices[i]->flags & XI86_CONFIGURED) {
+ int open_on_init;
+
+ open_on_init = !(localDevices[i]->flags & XI86_NO_OPEN_ON_INIT) ||
+ (localDevices[i]->flags & XI86_ALWAYS_CORE);
+
+ dev = AddInputDevice(localDevices[i]->device_control,
+ open_on_init);
+ if (dev == NULL)
+ FatalError("Too many input devices");
+
+ localDevices[i]->atom = MakeAtom(localDevices[i]->name,
+ strlen(localDevices[i]->name),
+ TRUE);
+ dev->public.devicePrivate = (pointer) localDevices[i];
+ localDevices[i]->dev = dev;
+
+ xf86XinputFinalizeInit(dev);
+
+ RegisterOtherDevice(dev);
+ if (serverGeneration == 1)
+ ErrorF("%s Adding extended device \"%s\" (type: %s)\n", XCONFIG_GIVEN,
+ localDevices[i]->name, localDevices[i]->type_name);
+ }
+ }
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXOpenDevice
+ *
+ * This is the implementation-dependent routine to open an input device.
+ * Some implementations open all input devices when the server is first
+ * initialized, and never close them. Other implementations open only
+ * the X pointer and keyboard devices during server initialization,
+ * and only open other input devices when some client makes an
+ * XOpenDevice request. This entry point is for the latter type of
+ * implementation.
+ *
+ * If the physical device is not already open, do it here. In this case,
+ * you need to keep track of the fact that one or more clients has the
+ * device open, and physically close it when the last client that has
+ * it open does an XCloseDevice.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are opened during X server initialization and kept open).
+ *
+ ***********************************************************************
+ */
+
+void
+OpenInputDevice (dev, client, status)
+ DeviceIntPtr dev;
+ ClientPtr client;
+ int *status;
+{
+ extern int BadDevice;
+
+ if (!dev->inited) {
+ *status = BadDevice;
+ } else {
+ if (!dev->public.on) {
+ if (!EnableDevice(dev)) {
+ *status = BadDevice;
+ } else {
+ /* to prevent ProcXOpenDevice to call EnableDevice again */
+ dev->startup = FALSE;
+ }
+ }
+ }
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangeKeyboardDevice
+ *
+ * This procedure does the implementation-dependent portion of the work
+ * needed to change the keyboard device.
+ *
+ * The X keyboard device has a FocusRec. If the device that has been
+ * made into the new X keyboard did not have a FocusRec,
+ * ProcXChangeKeyboardDevice will allocate one for it.
+ *
+ * If you do not want clients to be able to focus the old X keyboard
+ * device, call DeleteFocusClassDeviceStruct to free the FocusRec.
+ *
+ * If you support input devices with keys that you do not want to be
+ * used as the X keyboard, you need to check for them here and return
+ * a BadDevice error.
+ *
+ * The default implementation is to do nothing (assume you do want
+ * clients to be able to focus the old X keyboard). The commented-out
+ * sample code shows what you might do if you don't want the default.
+ *
+ ***********************************************************************
+ */
+
+int
+ChangeKeyboardDevice (old_dev, new_dev)
+ DeviceIntPtr old_dev;
+ DeviceIntPtr new_dev;
+{
+ /**********************************************************************
+ * DeleteFocusClassDeviceStruct(old_dev); * defined in xchgptr.c *
+ **********************************************************************/
+ return !Success;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangePointerDevice
+ *
+ * This procedure does the implementation-dependent portion of the work
+ * needed to change the pointer device.
+ *
+ * The X pointer device does not have a FocusRec. If the device that
+ * has been made into the new X pointer had a FocusRec,
+ * ProcXChangePointerDevice will free it.
+ *
+ * If you want clients to be able to focus the old pointer device that
+ * has now become accessible through the input extension, you need to
+ * add a FocusRec to it here.
+ *
+ * The XChangePointerDevice protocol request also allows the client
+ * to choose which axes of the new pointer device are used to move
+ * the X cursor in the X- and Y- directions. If the axes are different
+ * than the default ones, you need to keep track of that here.
+ *
+ * If you support input devices with valuators that you do not want to be
+ * used as the X pointer, you need to check for them here and return a
+ * BadDevice error.
+ *
+ * The default implementation is to do nothing (assume you don't want
+ * clients to be able to focus the old X pointer). The commented-out
+ * sample code shows what you might do if you don't want the default.
+ *
+ ***********************************************************************
+ */
+
+int
+#ifdef NeedFunctionPrototypes
+ChangePointerDevice (
+ DeviceIntPtr old_dev,
+ DeviceIntPtr new_dev,
+ unsigned char x,
+ unsigned char y)
+#else
+ChangePointerDevice (old_dev, new_dev, x, y)
+ DeviceIntPtr old_dev, new_dev;
+ unsigned char x, y;
+#endif /* NeedFunctionPrototypes */
+{
+ /************************************************************************
+ InitFocusClassDeviceStruct(old_dev); * allow focusing old ptr*
+
+ x_axis = x; * keep track of new x-axis*
+ y_axis = y; * keep track of new y-axis*
+ if (x_axis != 0 || y_axis != 1)
+ axes_changed = TRUE; * remember axes have changed*
+ else
+ axes_changed = FALSE;
+ *************************************************************************/
+ /*
+ * We don't allow axis swap or other exotic features.
+ */
+ if (x == 0 && y == 1) {
+ LocalDevicePtr old_local = (LocalDevicePtr)old_dev->public.devicePrivate;
+ LocalDevicePtr new_local = (LocalDevicePtr)new_dev->public.devicePrivate;
+
+ InitFocusClassDeviceStruct(old_dev);
+
+ /* Restore Extended motion history information */
+ old_dev->valuator->GetMotionProc = old_local->motion_history_proc;
+ old_dev->valuator->numMotionEvents = old_local->history_size;
+
+ /* Save Extended motion history information */
+ new_local->motion_history_proc = new_dev->valuator->GetMotionProc;
+ new_local->history_size = new_dev->valuator->numMotionEvents;
+
+ /* Set Core motion history information */
+ new_dev->valuator->GetMotionProc = miPointerGetMotionEvents;
+ new_dev->valuator->numMotionEvents = miPointerGetMotionBufferSize();
+
+ return Success;
+ }
+ else
+ return !Success;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXCloseDevice
+ *
+ * Take care of implementation-dependent details of closing a device.
+ * Some implementations may actually close the device, others may just
+ * remove this clients interest in that device.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are initialized during X server initialization and kept open).
+ *
+ ***********************************************************************
+ */
+
+void
+CloseInputDevice (d, client)
+ DeviceIntPtr d;
+ ClientPtr client;
+{
+ ErrorF("ProcXCloseDevice to close or not ?\n");
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXListInputDevices
+ *
+ * This is the implementation-dependent routine to initialize an input
+ * device to the point that information about it can be listed.
+ * Some implementations open all input devices when the server is first
+ * initialized, and never close them. Other implementations open only
+ * the X pointer and keyboard devices during server initialization,
+ * and only open other input devices when some client makes an
+ * XOpenDevice request. If some other process has the device open, the
+ * server may not be able to get information about the device to list it.
+ *
+ * This procedure should be used by implementations that do not initialize
+ * all input devices at server startup. It should do device-dependent
+ * initialization for any devices not previously initialized, and call
+ * AddInputDevice for each of those devices so that a DeviceIntRec will be
+ * created for them.
+ *
+ * The default implementation is to do nothing (assume all input devices
+ * are initialized during X server initialization and kept open).
+ * The commented-out sample code shows what you might do if you don't want
+ * the default.
+ *
+ ***********************************************************************
+ */
+
+void
+AddOtherInputDevices ()
+{
+}
+
+
+/****************************************************************************
+ *
+ * Caller: ProcXSetDeviceMode
+ *
+ * Change the mode of an extension device.
+ * This function is used to change the mode of a device from reporting
+ * relative motion to reporting absolute positional information, and
+ * vice versa.
+ * The default implementation below is that no such devices are supported.
+ *
+ ***********************************************************************
+ */
+
+int
+SetDeviceMode (client, dev, mode)
+ register ClientPtr client;
+ DeviceIntPtr dev;
+ int mode;
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ if (local->switch_mode) {
+ return (*local->switch_mode)(client, dev, mode);
+ }
+ else
+ return BadMatch;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXSetDeviceValuators
+ *
+ * Set the value of valuators on an extension input device.
+ * This function is used to set the initial value of valuators on
+ * those input devices that are capable of reporting either relative
+ * motion or an absolute position, and allow an initial position to be set.
+ * The default implementation below is that no such devices are supported.
+ *
+ ***********************************************************************
+ */
+
+int
+SetDeviceValuators (client, dev, valuators, first_valuator, num_valuators)
+ register ClientPtr client;
+ DeviceIntPtr dev;
+ int *valuators;
+ int first_valuator;
+ int num_valuators;
+{
+ return BadMatch;
+}
+
+
+/***********************************************************************
+ *
+ * Caller: ProcXChangeDeviceControl
+ *
+ * Change the specified device controls on an extension input device.
+ *
+ ***********************************************************************
+ */
+
+int
+ChangeDeviceControl (client, dev, control)
+ register ClientPtr client;
+ DeviceIntPtr dev;
+ xDeviceCtl *control;
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+
+ if (!local->control_proc) {
+ return (BadMatch);
+ }
+ else {
+ return (*local->control_proc)(local, control);
+ }
+}
+
+/*
+ * adapted from mieq.c to support extended events
+ *
+ */
+extern InputInfo inputInfo;
+
+#define QUEUE_SIZE 256
+
+typedef struct _Event {
+ xEvent event;
+#ifdef XINPUT
+ deviceValuator val;
+#endif
+ ScreenPtr pScreen;
+} EventRec, *EventPtr;
+
+typedef struct _EventQueue {
+ HWEventQueueType head, tail;
+ CARD32 lastEventTime; /* to avoid time running backwards */
+ Bool lastMotion;
+ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
+ DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
+ ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
+ ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
+} EventQueueRec, *EventQueuePtr;
+
+static EventQueueRec xf86EventQueue;
+
+Bool
+xf86eqInit (pKbd, pPtr)
+ DevicePtr pKbd, pPtr;
+{
+ xf86EventQueue.head = xf86EventQueue.tail = 0;
+ xf86EventQueue.lastEventTime = GetTimeInMillis ();
+ xf86EventQueue.pKbd = pKbd;
+ xf86EventQueue.pPtr = pPtr;
+ xf86EventQueue.lastMotion = FALSE;
+ xf86EventQueue.pEnqueueScreen = screenInfo.screens[0];
+ xf86EventQueue.pDequeueScreen = xf86EventQueue.pEnqueueScreen;
+ SetInputCheck (&xf86EventQueue.head, &xf86EventQueue.tail);
+ return TRUE;
+}
+
+/*
+ * Must be reentrant with ProcessInputEvents. Assumption: xf86eqEnqueue
+ * will never be interrupted. If this is called from both signal
+ * handlers and regular code, make sure the signal is suspended when
+ * called from regular code.
+ */
+
+void
+xf86eqEnqueue (e)
+ xEvent *e;
+{
+ int oldtail, newtail;
+ Bool isMotion;
+#ifdef XINPUT
+ int count;
+
+ switch (e->u.u.type)
+ {
+ case KeyPress:
+ case KeyRelease:
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ count = 1;
+ break;
+ default:
+ if (!((deviceKeyButtonPointer *) e)->deviceid & MORE_EVENTS)
+ {
+ count = 1;
+ }
+ else
+ {
+ count = 2;
+ }
+ break;
+ }
+#endif
+
+ oldtail = xf86EventQueue.tail;
+ isMotion = e->u.u.type == MotionNotify;
+ if (isMotion && xf86EventQueue.lastMotion && oldtail != xf86EventQueue.head)
+ {
+ if (oldtail == 0)
+ oldtail = QUEUE_SIZE;
+ oldtail = oldtail - 1;
+ }
+ else
+ {
+ newtail = oldtail + 1;
+ if (newtail == QUEUE_SIZE)
+ newtail = 0;
+ /* Toss events which come in late */
+ if (newtail == xf86EventQueue.head)
+ return;
+ xf86EventQueue.tail = newtail;
+ }
+
+ xf86EventQueue.lastMotion = isMotion;
+ xf86EventQueue.events[oldtail].event = *e;
+#ifdef XINPUT
+ if (count == 2)
+ {
+ xf86EventQueue.events[oldtail].val = *((deviceValuator *) (((deviceKeyButtonPointer *) e)+1));
+ }
+#endif
+ /*
+ * Make sure that event times don't go backwards - this
+ * is "unnecessary", but very useful
+ */
+ if (e->u.keyButtonPointer.time < xf86EventQueue.lastEventTime &&
+ xf86EventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
+ {
+ xf86EventQueue.events[oldtail].event.u.keyButtonPointer.time =
+ xf86EventQueue.lastEventTime;
+ }
+ xf86EventQueue.events[oldtail].pScreen = xf86EventQueue.pEnqueueScreen;
+}
+
+/*
+ * Call this from ProcessInputEvents()
+ */
+void
+xf86eqProcessInputEvents ()
+{
+ EventRec *e;
+ int x, y;
+ xEvent xe;
+#ifdef XINPUT
+ DeviceIntPtr dev;
+ int id, count;
+ deviceKeyButtonPointer *dev_xe;
+#endif
+
+ while (xf86EventQueue.head != xf86EventQueue.tail)
+ {
+ if (screenIsSaved == SCREEN_SAVER_ON)
+ SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+#ifdef DPMSExtension
+ if (DPMSPowerLevel != DPMSModeOn)
+ DPMSSet(DPMSModeOn);
+#endif
+
+ e = &xf86EventQueue.events[xf86EventQueue.head];
+ /*
+ * Assumption - screen switching can only occur on motion events
+ */
+ if (e->pScreen != xf86EventQueue.pDequeueScreen)
+ {
+ xf86EventQueue.pDequeueScreen = e->pScreen;
+ x = e->event.u.keyButtonPointer.rootX;
+ y = e->event.u.keyButtonPointer.rootY;
+ if (xf86EventQueue.head == QUEUE_SIZE - 1)
+ xf86EventQueue.head = 0;
+ else
+ ++xf86EventQueue.head;
+ NewCurrentScreen (xf86EventQueue.pDequeueScreen, x, y);
+ }
+ else
+ {
+ xe = e->event;
+ if (xf86EventQueue.head == QUEUE_SIZE - 1)
+ xf86EventQueue.head = 0;
+ else
+ ++xf86EventQueue.head;
+ switch (xe.u.u.type)
+ {
+ case KeyPress:
+ case KeyRelease:
+ (*xf86EventQueue.pKbd->processInputProc)
+ (&xe, (DeviceIntPtr)xf86EventQueue.pKbd, 1);
+ break;
+#ifdef XINPUT
+ case ButtonPress:
+ case ButtonRelease:
+ case MotionNotify:
+ (*(inputInfo.pointer->public.processInputProc))
+ (&xe, (DeviceIntPtr)inputInfo.pointer, 1);
+ break;
+
+ default:
+ dev_xe = (deviceKeyButtonPointer *) e;
+ id = dev_xe->deviceid & DEVICE_BITS;
+ if (!(dev_xe->deviceid & MORE_EVENTS)) {
+ count = 1;
+ } else {
+ count = 2;
+ }
+ dev = LookupDeviceIntRec(id);
+ if (dev == NULL)
+ {
+ ErrorF("LookupDeviceIntRec id=0x%x not found\n", id);
+/* FatalError("xf86eqProcessInputEvents : device not found.\n");
+ */
+ break;
+ }
+ if (!dev->public.processInputProc)
+ {
+ FatalError("xf86eqProcessInputEvents : device has no input proc.\n");
+ break;
+ }
+ (*dev->public.processInputProc)(&e->event, dev, count);
+#else
+ default:
+ (*xf86EventQueue.pPtr->processInputProc)
+ (&xe, (DeviceIntPtr)xf86EventQueue.pPtr, 1);
+#endif
+ break;
+ }
+ }
+ }
+}
+
+/*
+ * convenient functions to post events
+ */
+
+void
+xf86PostMotionEvent(DeviceIntPtr device,
+ int is_absolute,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+ LocalDevicePtr local = (LocalDevicePtr)device->public.devicePrivate;
+ char *buff;
+ Time current = GetTimeInMillis();
+
+ if (HAS_MOTION_HISTORY(local)) {
+ buff = ((char *)local->motion_history +
+ (sizeof(INT32) * local->dev->valuator->numAxes + sizeof(Time)) * local->last);
+ } else
+ buff = 0;
+
+ va_start(var, num_valuators);
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = va_arg(var, int);
+ break;
+ case 1:
+ xv->valuator1 = va_arg(var, int);
+ break;
+ case 2:
+ xv->valuator2 = va_arg(var, int);
+ break;
+ case 3:
+ xv->valuator3 = va_arg(var, int);
+ break;
+ case 4:
+ xv->valuator4 = va_arg(var, int);
+ break;
+ case 5:
+ xv->valuator5 = va_arg(var, int);
+ break;
+ }
+ if ((loop % 6 == 5) || (loop == num_valuators - 1)) {
+ if (!xf86IsCorePointer(device)) {
+ xev->type = DeviceMotionNotify;
+ xev->detail = 0;
+ xf86Info.lastEventTime = xev->time = current;
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+
+ xv->num_valuators = (loop % 6) + 1;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+ xv->device_state = 0;
+
+ if (HAS_MOTION_HISTORY(local)) {
+ *(Time*)buff = current;
+ memcpy(buff+sizeof(Time)+sizeof(INT32)*xv->first_valuator, &xv->valuator0,
+ sizeof(INT32)*xv->num_valuators);
+ }
+
+ xf86eqEnqueue(xE);
+ } else {
+ xf86Info.lastEventTime = current;
+
+ if (num_valuators >= 2) {
+ if (is_absolute) {
+ miPointerAbsoluteCursor(xv->valuator0, xv->valuator1, xf86Info.lastEventTime);
+ } else {
+ if (device->ptrfeed) {
+ /* modeled from xf86Events.c */
+ if ((abs(xv->valuator0) + abs(xv->valuator1)) >= device->ptrfeed->ctrl.threshold) {
+ xv->valuator0 = (xv->valuator0 * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den;
+ xv->valuator1 = (xv->valuator1 * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den;
+ }
+ }
+ miPointerDeltaCursor(xv->valuator0, xv->valuator1, xf86Info.lastEventTime);
+ }
+ }
+ break;
+ }
+ }
+ va_end(var);
+ }
+ if (HAS_MOTION_HISTORY(local)) {
+ local->last = (local->last + 1) % device->valuator->numMotionEvents;
+ if (local->last == local->first)
+ local->first = (local->first + 1) % device->valuator->numMotionEvents;
+ }
+}
+
+void
+xf86PostProximityEvent(DeviceIntPtr device,
+ int is_in,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+
+ va_start(var, num_valuators);
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = va_arg(var, int);
+ break;
+ case 1:
+ xv->valuator1 = va_arg(var, int);
+ break;
+ case 2:
+ xv->valuator2 = va_arg(var, int);
+ break;
+ case 3:
+ xv->valuator3 = va_arg(var, int);
+ break;
+ case 4:
+ xv->valuator4 = va_arg(var, int);
+ break;
+ case 5:
+ xv->valuator5 = va_arg(var, int);
+ break;
+ }
+ if ((loop % 6 == 5) || (loop == num_valuators - 1)) {
+ xev->type = is_in ? ProximityIn : ProximityOut;
+ xev->detail = 0;
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+
+ xv->num_valuators = (loop % 6) + 1;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+ xv->device_state = 0;
+
+ xf86eqEnqueue(xE);
+ }
+ }
+ va_end(var);
+}
+
+void
+xf86PostButtonEvent(DeviceIntPtr device,
+ int is_absolute,
+ int button,
+ int is_down,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+ int is_core_pointer = xf86IsCorePointer(device);
+
+ /* Check the core pointer button state not to send an inconsistent
+ * event. This can happen with the AlwaysCore feature.
+ */
+ if (is_core_pointer && !xf86CheckButton(button, is_down)) {
+ return;
+ }
+
+ va_start(var, num_valuators);
+
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = va_arg(var, int);
+ break;
+ case 1:
+ xv->valuator1 = va_arg(var, int);
+ break;
+ case 2:
+ xv->valuator2 = va_arg(var, int);
+ break;
+ case 3:
+ xv->valuator3 = va_arg(var, int);
+ break;
+ case 4:
+ xv->valuator4 = va_arg(var, int);
+ break;
+ case 5:
+ xv->valuator5 = va_arg(var, int);
+ break;
+ }
+ if (((loop % 6 == 5) || (loop == num_valuators - 1)) &&
+ !is_core_pointer) {
+ xev->type = is_down ? DeviceButtonPress : DeviceButtonRelease;
+ xev->detail = button;
+
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->device_state = 0;
+ /* if the device is in the relative mode we don't have to send valuators */
+ xv->num_valuators = is_absolute ? (loop % 6) + 1 : 0;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+ xf86eqEnqueue(xE);
+ /* if the device is in the relative mode only one event is needed */
+ if (!is_absolute) break;
+ }
+ if (is_core_pointer && loop == 1) {
+ int cx, cy;
+
+ GetSpritePosition(&cx, &cy);
+
+ /* Try to find the index in the core buttons map
+ * which corresponds to the extended button for
+ * an AlwaysCore device.
+ */
+ if (xf86IsAlwaysCore(device)) {
+ int loop;
+
+ button = device->button->map[button];
+
+ for(loop=1; loop<=inputInfo.pointer->button->numButtons; loop++) {
+ if (inputInfo.pointer->button->map[loop] == button) {
+ button = loop;
+ break;
+ }
+ }
+ }
+
+ xE->u.u.type = is_down ? ButtonPress : ButtonRelease;
+ xE->u.u.detail = button;
+ xE->u.keyButtonPointer.rootY = cx;
+ xE->u.keyButtonPointer.rootX = cy;
+ xf86Info.lastEventTime = xE->u.keyButtonPointer.time = GetTimeInMillis();
+ xf86eqEnqueue(xE);
+ break;
+ }
+ }
+ va_end(var);
+}
+
+void
+xf86PostKeyEvent(DeviceIntPtr device,
+ unsigned int key_code,
+ int is_down,
+ int is_absolute,
+ int first_valuator,
+ int num_valuators,
+ ...)
+{
+ va_list var;
+ int loop;
+ xEvent xE[2];
+ deviceKeyButtonPointer *xev = (deviceKeyButtonPointer*) xE;
+ deviceValuator *xv = (deviceValuator*) xev+1;
+
+ va_start(var, num_valuators);
+
+
+ for(loop=0; loop<num_valuators; loop++) {
+ switch (loop % 6) {
+ case 0:
+ xv->valuator0 = va_arg(var, int);
+ break;
+ case 1:
+ xv->valuator1 = va_arg(var, int);
+ break;
+ case 2:
+ xv->valuator2 = va_arg(var, int);
+ break;
+ case 3:
+ xv->valuator3 = va_arg(var, int);
+ break;
+ case 4:
+ xv->valuator4 = va_arg(var, int);
+ break;
+ case 5:
+ xv->valuator5 = va_arg(var, int);
+ break;
+ }
+ if (((loop % 6 == 5) || (loop == num_valuators - 1))) {
+ xev->type = is_down ? DeviceKeyPress : DeviceKeyRelease;
+ xev->detail = key_code;
+
+ xf86Info.lastEventTime = xev->time = GetTimeInMillis();
+ xev->deviceid = device->id | MORE_EVENTS;
+
+ xv->type = DeviceValuator;
+ xv->deviceid = device->id;
+ xv->device_state = 0;
+ /* if the device is in the relative mode we don't have to send valuators */
+ xv->num_valuators = is_absolute ? (loop % 6) + 1 : 0;
+ xv->first_valuator = first_valuator + (loop / 6) * 6;
+
+ xf86eqEnqueue(xE);
+ /* if the device is in the relative mode only one event is needed */
+ if (!is_absolute) break;
+ }
+ }
+ va_end(var);
+}
+
+/*
+ * Motion history management.
+ */
+
+void
+xf86MotionHistoryAllocate(LocalDevicePtr local)
+{
+ ValuatorClassPtr valuator = local->dev->valuator;
+
+ if (!HAS_MOTION_HISTORY(local))
+ return;
+
+ local->motion_history = xalloc((sizeof(INT32) * valuator->numAxes + sizeof(Time))
+ * valuator->numMotionEvents);
+ local->first = 0;
+ local->last = 0;
+}
+
+int
+xf86GetMotionEvents(DeviceIntPtr dev,
+ xTimecoord *buff,
+ unsigned long start,
+ unsigned long stop,
+ ScreenPtr pScreen)
+{
+ LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
+ ValuatorClassPtr valuator = dev->valuator;
+ int num = 0;
+ int loop = local->first;
+ int size;
+ Time current;
+
+ if (!HAS_MOTION_HISTORY(local))
+ return 0;
+
+ size = (sizeof(INT32) * valuator->numAxes + sizeof(Time));
+
+ while (loop != local->last) {
+ current = *(Time*)(((char *)local->motion_history)+loop*size);
+ if (current > stop)
+ return num;
+ if (current >= start) {
+ memcpy(((char *)buff)+size*num,
+ ((char *)local->motion_history)+loop*size, size);
+ num++;
+ }
+ loop = (loop + 1) % valuator->numMotionEvents;
+ }
+ return num;
+}
+
+/* end of xf86Xinput.c */
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
new file mode 100644
index 000000000..b2bb8832f
--- /dev/null
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -0,0 +1,280 @@
+/* $Xorg: xf86Xinput.h,v 1.3 2000/08/17 19:50:31 cpqbld Exp $ */
+/*
+ * Copyright 1995,1996 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Xinput.h,v 3.14.2.1 1997/05/12 12:52:29 hohndel Exp $ */
+
+#ifndef _xf86Xinput_h
+#define _xf86Xinput_h
+
+#ifndef NEED_EVENTS
+#define NEED_EVENTS
+#endif
+#include "X.h"
+#include "Xproto.h"
+#include "inputstr.h"
+#include "XI.h"
+#include "XIproto.h"
+#include "XIstubs.h"
+
+#define XI86_NO_OPEN_ON_INIT 1 /* open the device only when needed */
+#define XI86_CONFIGURED 2 /* the device has been configured */
+#define XI86_ALWAYS_CORE 4 /* the device always controls the pointer */
+
+#ifdef PRIVATE
+#undef PRIVATE
+#endif
+#define PRIVATE(dev) (((LocalDevicePtr)((dev)->public.devicePrivate))->private)
+
+#ifdef HAS_MOTION_HISTORY
+#undef HAS_MOTION_HISTORY
+#endif
+#define HAS_MOTION_HISTORY(local) ((local)->dev->valuator && (local)->dev->valuator->numMotionEvents)
+
+typedef struct _LocalDeviceRec {
+ char *name;
+ int flags;
+ Bool (*device_config)(
+#if NeedNestedPrototypes
+ struct _LocalDeviceRec** /*array*/,
+ int /*index*/,
+ int /*max*/,
+ LexPtr /*val*/
+#endif
+ );
+ Bool (*device_control)(
+#if NeedNestedPrototypes
+ DeviceIntPtr /*device*/,
+ int /*what*/
+#endif
+ );
+ void (*read_input)(
+#if NeedNestedPrototypes
+ struct _LocalDeviceRec* /*local*/
+#endif
+ );
+ int (*control_proc)(
+#if NeedNestedPrototypes
+ struct _LocalDeviceRec* /*local*/,
+ xDeviceCtl* /* control */
+#endif
+ );
+ void (*close_proc)(
+#if NeedNestedPrototypes
+ struct _LocalDeviceRec* /*local*/
+#endif
+ );
+ int (*switch_mode)(
+#if NeedNestedPrototypes
+ ClientPtr /*client*/,
+ DeviceIntPtr /*dev*/,
+ int /*mode*/
+#endif
+ );
+ int fd;
+ Atom atom;
+ DeviceIntPtr dev;
+ pointer private;
+ int private_flags;
+ pointer motion_history;
+ ValuatorMotionProcPtr motion_history_proc;
+ unsigned int history_size; /* only for configuration purpose */
+ unsigned int first;
+ unsigned int last;
+ char *type_name;
+ IntegerFeedbackPtr always_core_feedback;
+} LocalDeviceRec, *LocalDevicePtr;
+
+typedef struct _DeviceAssocRec
+{
+ char *config_section_name;
+ LocalDevicePtr (*device_allocate)(
+#if NeedNestedPrototypes
+ void
+#endif
+);
+} DeviceAssocRec, *DeviceAssocPtr;
+
+extern int DeviceKeyPress;
+extern int DeviceKeyRelease;
+extern int DeviceButtonPress;
+extern int DeviceButtonRelease;
+extern int DeviceMotionNotify;
+extern int DeviceValuator;
+extern int ProximityIn;
+extern int ProximityOut;
+
+extern int
+xf86IsCorePointer(
+#if NeedFunctionPrototypes
+ DeviceIntPtr /*dev*/
+#endif
+);
+
+extern int
+xf86IsCoreKeyboard(
+#if NeedFunctionPrototypes
+ DeviceIntPtr /*dev*/
+#endif
+);
+
+extern void
+xf86AlwaysCore(
+#if NeedFunctionPrototypes
+ LocalDevicePtr /*local*/,
+ Bool /*always*/
+#endif
+);
+
+void
+xf86configExtendedInputSection(
+#ifdef NeedFunctionPrototypes
+ LexPtr /* val */
+#endif
+);
+
+void
+xf86AddDeviceAssoc(
+#ifdef NeedFunctionPrototypes
+ DeviceAssocPtr /* assoc */
+#endif
+);
+
+void
+InitExtInput(
+#ifdef NeedFunctionPrototypes
+ void
+#endif
+);
+
+Bool
+xf86eqInit (
+#ifdef NeedFunctionPrototypes
+ DevicePtr /* pKbd */,
+ DevicePtr /* pPtr */
+#endif
+);
+
+void
+xf86eqEnqueue (
+#ifdef NeedFunctionPrototypes
+ struct _xEvent * /*event */
+#endif
+);
+
+void
+xf86eqProcessInputEvents (
+#ifdef NeedFunctionPrototypes
+ void
+#endif
+);
+
+void
+xf86PostMotionEvent(
+#if NeedVarargsPrototypes
+ DeviceIntPtr /*device*/,
+ int /*is_absolute*/,
+ int /*first_valuator*/,
+ int /*num_valuators*/,
+ ...
+#endif
+);
+
+void
+xf86PostProximityEvent(
+#if NeedVarargsPrototypes
+ DeviceIntPtr /*device*/,
+ int /*is_in*/,
+ int /*first_valuator*/,
+ int /*num_valuators*/,
+ ...
+#endif
+);
+
+void
+xf86PostButtonEvent(
+#if NeedVarargsPrototypes
+ DeviceIntPtr /*device*/,
+ int /*is_absolute*/,
+ int /*button*/,
+ int /*is_down*/,
+ int /*first_valuator*/,
+ int /*num_valuators*/,
+ ...
+#endif
+);
+
+void
+xf86PostKeyEvent(
+#if NeedVarargsPrototypes
+ DeviceIntPtr device,
+ unsigned int key_code,
+ int is_down,
+ int is_absolute,
+ int first_valuator,
+ int num_valuators,
+ ...
+#endif
+);
+
+void
+xf86AddDeviceAssoc(
+#if NeedFunctionPrototypes
+ DeviceAssocPtr /*assoc*/
+#endif
+);
+
+void
+xf86MotionHistoryAllocate(
+#if NeedFunctionPrototypes
+ LocalDevicePtr local
+#endif
+);
+
+int
+xf86GetMotionEvents(
+#if NeedFunctionPrototypes
+ DeviceIntPtr dev,
+ xTimecoord *buff,
+ unsigned long start,
+ unsigned long stop,
+ ScreenPtr pScreen
+#endif
+);
+
+void
+xf86XinputFinalizeInit(
+#if NeedFunctionPrototypes
+ DeviceIntPtr dev
+#endif
+);
+
+Bool
+xf86CheckButton(
+#if NeedFunctionPrototypes
+ int button,
+ int down
+#endif
+);
+
+#endif /* _xf86Xinput_h */
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
new file mode 100644
index 000000000..8abab86a5
--- /dev/null
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -0,0 +1,1429 @@
+/* $XFree86: xc/programs/Xserver/Xext/xf86vmode.c,v 3.25 1996/10/16 14:37:58 dawes Exp $ */
+
+/*
+
+Copyright 1995 Kaleb S. KEITHLEY
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Kaleb S. KEITHLEY
+shall not be used in advertising or otherwise to promote the sale, use
+or other dealings in this Software without prior written authorization
+from Kaleb S. KEITHLEY
+
+*/
+/* $Xorg: xf86vmode.c,v 1.3 2000/08/17 19:47:59 cpqbld Exp $ */
+/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define _XF86VIDMODE_SERVER_
+#include "xf86vmstr.h"
+#include "Xfuncproto.h"
+#include "../hw/xfree86/common/xf86.h"
+#include "../hw/xfree86/common/xf86Priv.h"
+
+extern int xf86ScreenIndex;
+extern Bool xf86VidModeEnabled;
+extern Bool xf86VidModeAllowNonLocal;
+
+static int vidmodeErrorBase;
+
+static int ProcXF86VidModeDispatch(
+#if NeedFunctionPrototypes
+ ClientPtr /* client */
+#endif
+);
+
+static int SProcXF86VidModeDispatch(
+#if NeedFunctionPrototypes
+ ClientPtr /* client */
+#endif
+);
+
+static void XF86VidModeResetProc(
+#if NeedFunctionPrototypes
+ ExtensionEntry* /* extEntry */
+#endif
+);
+
+extern void Swap32Write(); /* XXX should be in header file */
+
+static unsigned char XF86VidModeReqCode = 0;
+
+/* The XF86VIDMODE_EVENTS code is far from complete */
+
+#ifdef XF86VIDMODE_EVENTS
+static int XF86VidModeEventBase = 0;
+
+static void SXF86VidModeNotifyEvent();
+#if NeedFunctionPrototypes
+ xXF86VidModeNotifyEvent * /* from */,
+ xXF86VidModeNotifyEvent * /* to */
+#endif
+);
+
+extern WindowPtr *WindowTable;
+
+static RESTYPE EventType; /* resource type for event masks */
+
+typedef struct _XF86VidModeEvent *XF86VidModeEventPtr;
+
+typedef struct _XF86VidModeEvent {
+ XF86VidModeEventPtr next;
+ ClientPtr client;
+ ScreenPtr screen;
+ XID resource;
+ CARD32 mask;
+} XF86VidModeEventRec;
+
+static int XF86VidModeFreeEvents();
+
+typedef struct _XF86VidModeScreenPrivate {
+ XF86VidModeEventPtr events;
+ Bool hasWindow;
+} XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
+
+static int ScreenPrivateIndex;
+
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr)(s)->devPrivates[ScreenPrivateIndex].ptr)
+#define SetScreenPrivate(s,v) ((s)->devPrivates[ScreenPrivateIndex].ptr = (pointer) v);
+#define SetupScreen(s) ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
+
+#define New(t) ((t *) xalloc (sizeof (t)))
+#endif
+
+void
+XFree86VidModeExtensionInit()
+{
+ ExtensionEntry* extEntry;
+#ifdef XF86VIDMODE_EVENTS
+ int i;
+ ScreenPtr pScreen;
+
+ EventType = CreateNewResourceType(XF86VidModeFreeEvents);
+ ScreenPrivateIndex = AllocateScreenPrivateIndex ();
+ for (i = 0; i < screenInfo.numScreens; i++)
+ {
+ pScreen = screenInfo.screens[i];
+ SetScreenPrivate (pScreen, NULL);
+ }
+#endif
+
+ if (
+#ifdef XF86VIDMODE_EVENTS
+ EventType && ScreenPrivateIndex != -1 &&
+#endif
+ (extEntry = AddExtension(XF86VIDMODENAME,
+ XF86VidModeNumberEvents,
+ XF86VidModeNumberErrors,
+ ProcXF86VidModeDispatch,
+ SProcXF86VidModeDispatch,
+ XF86VidModeResetProc,
+ StandardMinorOpcode))) {
+ XF86VidModeReqCode = (unsigned char)extEntry->base;
+ vidmodeErrorBase = extEntry->errorBase;
+#ifdef XF86VIDMODE_EVENTS
+ XF86VidModeEventBase = extEntry->eventBase;
+ EventSwapVector[XF86VidModeEventBase] = SXF86VidModeNotifyEvent;
+#endif
+ }
+}
+
+/*ARGSUSED*/
+static void
+XF86VidModeResetProc (extEntry)
+ ExtensionEntry* extEntry;
+{
+}
+
+#ifdef XF86VIDMODE_EVENTS
+static void
+CheckScreenPrivate (pScreen)
+ ScreenPtr pScreen;
+{
+ SetupScreen (pScreen);
+
+ if (!pPriv)
+ return;
+ if (!pPriv->events && !pPriv->hasWindow) {
+ xfree (pPriv);
+ SetScreenPrivate (pScreen, NULL);
+ }
+}
+
+static XF86VidModeScreenPrivatePtr
+MakeScreenPrivate (pScreen)
+ ScreenPtr pScreen;
+{
+ SetupScreen (pScreen);
+
+ if (pPriv)
+ return pPriv;
+ pPriv = New (XF86VidModeScreenPrivateRec);
+ if (!pPriv)
+ return 0;
+ pPriv->events = 0;
+ pPriv->hasWindow = FALSE;
+ SetScreenPrivate (pScreen, pPriv);
+ return pPriv;
+}
+
+static unsigned long
+getEventMask (pScreen, client)
+ ScreenPtr pScreen;
+ ClientPtr client;
+{
+ SetupScreen(pScreen);
+ XF86VidModeEventPtr pEv;
+
+ if (!pPriv)
+ return 0;
+ for (pEv = pPriv->events; pEv; pEv = pEv->next)
+ if (pEv->client == client)
+ return pEv->mask;
+ return 0;
+}
+
+static Bool
+setEventMask (pScreen, client, mask)
+ ScreenPtr pScreen;
+ ClientPtr client;
+ unsigned long mask;
+{
+ SetupScreen(pScreen);
+ XF86VidModeEventPtr pEv, *pPrev;
+
+ if (getEventMask (pScreen, client) == mask)
+ return TRUE;
+ if (!pPriv) {
+ pPriv = MakeScreenPrivate (pScreen);
+ if (!pPriv)
+ return FALSE;
+ }
+ for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+ if (pEv->client == client)
+ break;
+ if (mask == 0) {
+ *pPrev = pEv->next;
+ xfree (pEv);
+ CheckScreenPrivate (pScreen);
+ } else {
+ if (!pEv) {
+ pEv = New (ScreenSaverEventRec);
+ if (!pEv) {
+ CheckScreenPrivate (pScreen);
+ return FALSE;
+ }
+ *pPrev = pEv;
+ pEv->next = NULL;
+ pEv->client = client;
+ pEv->screen = pScreen;
+ pEv->resource = FakeClientID (client->index);
+ }
+ pEv->mask = mask;
+ }
+ return TRUE;
+}
+
+static int
+XF86VidModeFreeEvents (value, id)
+ pointer value;
+ XID id;
+{
+ XF86VidModeEventPtr pOld = (XF86VidModeEventPtr)value;
+ ScreenPtr pScreen = pOld->screen;
+ SetupScreen (pScreen);
+ XF86VidModeEventPtr pEv, *pPrev;
+
+ if (!pPriv)
+ return TRUE;
+ for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+ if (pEv == pOld)
+ break;
+ if (!pEv)
+ return TRUE;
+ *pPrev = pEv->next;
+ xfree (pEv);
+ CheckScreenPrivate (pScreen);
+ return TRUE;
+}
+
+static void
+SendXF86VidModeNotify (pScreen, state, forced)
+ ScreenPtr pScreen;
+ int state;
+ Bool forced;
+{
+ XF86VidModeScreenPrivatePtr pPriv;
+ XF86VidModeEventPtr pEv;
+ unsigned long mask;
+ xXF86VidModeNotifyEvent ev;
+ ClientPtr client;
+ int kind;
+
+ UpdateCurrentTimeIf ();
+ mask = XF86VidModeNotifyMask;
+ pScreen = screenInfo.screens[pScreen->myNum];
+ pPriv = GetScreenPrivate(pScreen);
+ if (!pPriv)
+ return;
+ kind = XF86VidModeModeChange;
+ for (pEv = pPriv->events; pEv; pEv = pEv->next)
+ {
+ client = pEv->client;
+ if (client->clientGone)
+ continue;
+ if (!(pEv->mask & mask))
+ continue;
+ ev.type = XF86VidModeNotify + XF86VidModeEventBase;
+ ev.state = state;
+ ev.sequenceNumber = client->sequence;
+ ev.timestamp = currentTime.milliseconds;
+ ev.root = WindowTable[pScreen->myNum]->drawable.id;
+ ev.kind = kind;
+ ev.forced = forced;
+ WriteEventsToClient (client, 1, (xEvent *) &ev);
+ }
+}
+
+static void
+SXF86VidModeNotifyEvent (from, to)
+ xXF86VidModeNotifyEvent *from, *to;
+{
+ to->type = from->type;
+ to->state = from->state;
+ cpswaps (from->sequenceNumber, to->sequenceNumber);
+ cpswapl (from->timestamp, to->timestamp);
+ cpswapl (from->root, to->root);
+ to->kind = from->kind;
+ to->forced = from->forced;
+}
+#endif
+
+static int
+ProcXF86VidModeQueryVersion(client)
+ register ClientPtr client;
+{
+ xXF86VidModeQueryVersionReply rep;
+ register int n;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
+ rep.type = X_Reply;
+ rep.length = 0;
+ rep.sequenceNumber = client->sequence;
+ rep.majorVersion = XF86VIDMODE_MAJOR_VERSION;
+ rep.minorVersion = XF86VIDMODE_MINOR_VERSION;
+ if (client->swapped) {
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ swaps(&rep.majorVersion, n);
+ swaps(&rep.minorVersion, n);
+ }
+ WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), (char *)&rep);
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetModeLine(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeGetModeLineReq);
+ xXF86VidModeGetModeLineReply rep;
+ register int n;
+ ScrnInfoPtr vptr;
+ DisplayModePtr mptr;
+ int privsize;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->modes;
+
+ if (!mptr->Private)
+ privsize = 0;
+ else
+ privsize = mptr->PrivSize;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+ rep.type = X_Reply;
+ rep.length = (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xGenericReply) +
+ privsize * sizeof(INT32)) >> 2;
+ rep.sequenceNumber = client->sequence;
+ rep.dotclock = vptr->clock[mptr->Clock];
+ rep.hdisplay = mptr->HDisplay;
+ rep.hsyncstart = mptr->HSyncStart;
+ rep.hsyncend = mptr->HSyncEnd;
+ rep.htotal = mptr->HTotal;
+ rep.vdisplay = mptr->VDisplay;
+ rep.vsyncstart = mptr->VSyncStart;
+ rep.vsyncend = mptr->VSyncEnd;
+ rep.vtotal = mptr->VTotal;
+ rep.flags = mptr->Flags;
+ rep.privsize = privsize;
+ if (client->swapped) {
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ swapl(&rep.dotclock, n);
+ swaps(&rep.hdisplay, n);
+ swaps(&rep.hsyncstart, n);
+ swaps(&rep.hsyncend, n);
+ swaps(&rep.htotal, n);
+ swaps(&rep.vdisplay, n);
+ swaps(&rep.vsyncstart, n);
+ swaps(&rep.vsyncend, n);
+ swaps(&rep.vtotal, n);
+ swapl(&rep.flags, n);
+ swapl(&rep.privsize, n);
+ }
+ WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), (char *)&rep);
+ if (privsize) {
+ client->pSwapReplyFunc = Swap32Write;
+ WriteSwappedDataToClient(client, privsize * sizeof(INT32),
+ mptr->Private);
+ }
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetAllModeLines(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeGetAllModeLinesReq);
+ xXF86VidModeGetAllModeLinesReply rep;
+ xXF86VidModeModeInfo mdinf;
+ register int n;
+ ScrnInfoPtr vptr;
+ DisplayModePtr mptr, curmptr;
+ int privsize, modecount=1;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ curmptr = mptr = vptr->modes;
+
+ while (mptr->next != curmptr) {
+ ++modecount;
+ mptr = mptr->next;
+ }
+
+ REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+ rep.type = X_Reply;
+ rep.length = (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xGenericReply) +
+ modecount * sizeof(xXF86VidModeModeInfo)) >> 2;
+ rep.sequenceNumber = client->sequence;
+ rep.modecount = modecount;
+ if (client->swapped) {
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ swapl(&rep.modecount, n);
+ }
+ WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), (char *)&rep);
+ mptr = curmptr;
+ do {
+ if (!mptr->Private)
+ privsize = 0;
+ else
+ privsize = mptr->PrivSize;
+
+ mdinf.dotclock = vptr->clock[mptr->Clock];
+ mdinf.hdisplay = mptr->HDisplay;
+ mdinf.hsyncstart = mptr->HSyncStart;
+ mdinf.hsyncend = mptr->HSyncEnd;
+ mdinf.htotal = mptr->HTotal;
+ mdinf.vdisplay = mptr->VDisplay;
+ mdinf.vsyncstart = mptr->VSyncStart;
+ mdinf.vsyncend = mptr->VSyncEnd;
+ mdinf.vtotal = mptr->VTotal;
+ mdinf.flags = mptr->Flags;
+ mdinf.privsize = privsize;
+ if (client->swapped) {
+ swapl(&mdinf.dotclock, n);
+ swaps(&mdinf.hdisplay, n);
+ swaps(&mdinf.hsyncstart, n);
+ swaps(&mdinf.hsyncend, n);
+ swaps(&mdinf.htotal, n);
+ swaps(&mdinf.vdisplay, n);
+ swaps(&mdinf.vsyncstart, n);
+ swaps(&mdinf.vsyncend, n);
+ swaps(&mdinf.vtotal, n);
+ swapl(&mdinf.flags, n);
+ swapl(&mdinf.privsize, n);
+ }
+ WriteToClient(client, sizeof(xXF86VidModeModeInfo), (char *)&mdinf);
+ mptr = mptr->next;
+ } while (mptr != curmptr);
+ return (client->noClientException);
+}
+
+#define CLOCKSPD(clk,scrp) ((clk>MAXCLOCKS)? clk: scrp->clock[clk])
+#define MODEMATCH(mptr,stuff,scrp) \
+ (CLOCKSPD(mptr->Clock,scrp) == CLOCKSPD(stuff->dotclock,scrp) \
+ && mptr->HDisplay == stuff->hdisplay \
+ && mptr->HSyncStart== stuff->hsyncstart \
+ && mptr->HSyncEnd == stuff->hsyncend \
+ && mptr->HTotal == stuff->htotal \
+ && mptr->VDisplay == stuff->vdisplay \
+ && mptr->VSyncStart== stuff->vsyncstart \
+ && mptr->VSyncEnd == stuff->vsyncend \
+ && mptr->VTotal == stuff->vtotal \
+ && mptr->Flags == stuff->flags )
+
+static int
+ProcXF86VidModeAddModeLine(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeAddModeLineReq);
+ ScrnInfoPtr vptr;
+ DisplayModePtr curmptr, mptr, newmptr;
+ DisplayModeRec modetmp;
+ int len;
+
+ if (xf86Verbose) {
+ ErrorF("AddModeLine - scrn: %d clock: %d\n",
+ stuff->screen, stuff->dotclock);
+ ErrorF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ stuff->hdisplay, stuff->hsyncstart,
+ stuff->hsyncend, stuff->htotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+ stuff->vtotal, stuff->flags);
+ ErrorF(" after - scrn: %d clock: %d\n",
+ stuff->screen, stuff->after_dotclock);
+ ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ stuff->after_hdisplay, stuff->after_hsyncstart,
+ stuff->after_hsyncend, stuff->after_htotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ stuff->after_vdisplay, stuff->after_vsyncstart,
+ stuff->after_vsyncend, stuff->after_vtotal, stuff->after_flags);
+ }
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ curmptr = mptr = vptr->modes;
+
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+ len = client->req_len - (sizeof(xXF86VidModeAddModeLineReq) >> 2);
+ if (len != stuff->privsize)
+ return BadLength;
+
+ if (stuff->hsyncstart < stuff->hdisplay ||
+ stuff->hsyncend < stuff->hsyncstart ||
+ stuff->htotal < stuff->hsyncend ||
+ stuff->vsyncstart < stuff->vdisplay ||
+ stuff->vsyncend < stuff->vsyncstart ||
+ stuff->vtotal < stuff->vsyncend)
+ return BadValue;
+
+ if (stuff->after_hsyncstart < stuff->after_hdisplay ||
+ stuff->after_hsyncend < stuff->after_hsyncstart ||
+ stuff->after_htotal < stuff->after_hsyncend ||
+ stuff->after_vsyncstart < stuff->after_vdisplay ||
+ stuff->after_vsyncend < stuff->after_vsyncstart ||
+ stuff->after_vtotal < stuff->after_vsyncend)
+ return BadValue;
+
+ if (stuff->after_htotal != 0 || stuff->after_vtotal != 0) {
+ Bool found = FALSE;
+ do {
+ if (MODEMATCH(mptr, stuff, vptr)) {
+ found = TRUE;
+ break;
+ }
+ } while ((mptr = mptr->next) != curmptr);
+ if (!found)
+ return BadValue;
+ }
+
+ newmptr = (DisplayModePtr) xalloc(sizeof(DisplayModeRec));
+
+ newmptr->Clock = stuff->dotclock;
+ newmptr->CrtcHDisplay = newmptr->HDisplay = stuff->hdisplay;
+ newmptr->CrtcHSyncStart= newmptr->HSyncStart = stuff->hsyncstart;
+ newmptr->CrtcHSyncEnd = newmptr->HSyncEnd = stuff->hsyncend;
+ newmptr->CrtcHTotal = newmptr->HTotal = stuff->htotal;
+ newmptr->CrtcVDisplay = newmptr->VDisplay = stuff->vdisplay;
+ newmptr->CrtcVSyncStart= newmptr->VSyncStart = stuff->vsyncstart;
+ newmptr->CrtcVSyncEnd = newmptr->VSyncEnd = stuff->vsyncend;
+ newmptr->CrtcVTotal = newmptr->VTotal = stuff->vtotal;
+ newmptr->Flags = stuff->flags;
+#if 0
+ newmptr->CrtcHSkew = newmptr->HSkew = stuff->hskew;
+#endif
+ newmptr->CrtcHAdjusted = FALSE;
+ newmptr->CrtcVAdjusted = FALSE;
+ newmptr->name = "";
+ newmptr->Private = NULL;
+ if (stuff->privsize) {
+ if (xf86Verbose)
+ ErrorF("AddModeLine - Request includes privates\n");
+ newmptr->Private =
+ (INT32 *) ALLOCATE_LOCAL(stuff->privsize * sizeof(INT32));
+ memcpy(newmptr->Private, &stuff[1], stuff->privsize*sizeof(INT32));
+ }
+
+ /* Check that the mode is consistent with the monitor specs */
+ switch (xf86CheckMode(vptr, newmptr, vptr->monitor, FALSE)) {
+ case MODE_HSYNC:
+ xfree(newmptr->Private);
+ xfree(newmptr);
+ return vidmodeErrorBase + XF86VidModeBadHTimings;
+ case MODE_VSYNC:
+ xfree(newmptr->Private);
+ xfree(newmptr);
+ return vidmodeErrorBase + XF86VidModeBadVTimings;
+ }
+
+ /* Check that the driver is happy with the mode */
+ if (vptr->ValidMode(newmptr, xf86Verbose, MODE_VID) != MODE_OK) {
+ xfree(newmptr->Private);
+ xfree(newmptr);
+ return vidmodeErrorBase + XF86VidModeModeUnsuitable;
+ }
+
+ if (newmptr->Flags & V_DBLSCAN)
+ {
+ newmptr->CrtcVDisplay *= 2;
+ newmptr->CrtcVSyncStart *= 2;
+ newmptr->CrtcVSyncEnd *= 2;
+ newmptr->CrtcVTotal *= 2;
+ newmptr->CrtcVAdjusted = TRUE;
+ }
+
+ newmptr->next = mptr->next;
+ newmptr->prev = mptr;
+ mptr->next = newmptr;
+ newmptr->next->prev = newmptr;
+
+#if 0 /* Do we want this? */
+ (vptr->SwitchMode)(newmptr);
+#endif
+
+ if (xf86Verbose)
+ ErrorF("AddModeLine - Succeeded\n");
+ return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeDeleteModeLine(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeDeleteModeLineReq);
+ ScrnInfoPtr vptr;
+ DisplayModePtr curmptr, mptr;
+ DisplayModeRec modetmp;
+ int len;
+
+ if (xf86Verbose) {
+ ErrorF("DeleteModeLine - scrn: %d clock: %d\n",
+ stuff->screen, stuff->dotclock, stuff->dotclock);
+ ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ stuff->hdisplay, stuff->hsyncstart,
+ stuff->hsyncend, stuff->htotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+ stuff->vtotal, stuff->flags);
+ }
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ curmptr = mptr = vptr->modes;
+
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+ len = client->req_len - (sizeof(xXF86VidModeDeleteModeLineReq) >> 2);
+ if (len != stuff->privsize) {
+ ErrorF("req_len = %d, sizeof(Req) = %d, privsize = %d, len = %d, length = %d\n",
+ client->req_len, sizeof(xXF86VidModeDeleteModeLineReq)>>2, stuff->privsize, len, stuff->length);
+ return BadLength;
+ }
+
+ ErrorF("Checking against clock: %d (%d)\n",
+ mptr->Clock, CLOCKSPD(mptr->Clock, vptr));
+ ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ mptr->HDisplay, mptr->HSyncStart,
+ mptr->HSyncEnd, mptr->HTotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ mptr->VDisplay, mptr->VSyncStart, mptr->VSyncEnd,
+ mptr->VTotal, mptr->Flags);
+ if (MODEMATCH(mptr, stuff, vptr))
+ return BadValue;
+
+ while ((mptr = mptr->next) != curmptr) {
+ ErrorF("Checking against clock: %d (%d)\n",
+ mptr->Clock, CLOCKSPD(mptr->Clock, vptr));
+ ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ mptr->HDisplay, mptr->HSyncStart,
+ mptr->HSyncEnd, mptr->HTotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ mptr->VDisplay, mptr->VSyncStart, mptr->VSyncEnd,
+ mptr->VTotal, mptr->Flags);
+ if (MODEMATCH(mptr, stuff, vptr)) {
+ mptr->prev->next = mptr->next;
+ mptr->next->prev = mptr->prev;
+ xfree(mptr->name);
+ xfree(mptr->Private);
+ xfree(mptr);
+ if (xf86Verbose)
+ ErrorF("DeleteModeLine - Succeeded\n");
+ return(client->noClientException);
+ }
+ }
+ return BadValue;
+}
+
+static int
+ProcXF86VidModeModModeLine(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeModModeLineReq);
+ ScrnInfoPtr vptr;
+ DisplayModePtr mptr;
+ DisplayModeRec modetmp;
+ int len;
+
+ if (xf86Verbose) {
+ ErrorF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ stuff->screen, stuff->hdisplay, stuff->hsyncstart,
+ stuff->hsyncend, stuff->htotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+ stuff->vtotal, stuff->flags);
+ }
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->modes;
+
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+ len = client->req_len - (sizeof(xXF86VidModeModModeLineReq) >> 2);
+ if (len != stuff->privsize)
+ return BadLength;
+
+ if (stuff->hsyncstart < stuff->hdisplay ||
+ stuff->hsyncend < stuff->hsyncstart ||
+ stuff->htotal < stuff->hsyncend ||
+ stuff->vsyncstart < stuff->vdisplay ||
+ stuff->vsyncend < stuff->vsyncstart ||
+ stuff->vtotal < stuff->vsyncend)
+ return BadValue;
+
+ memcpy(&modetmp, mptr, sizeof(DisplayModeRec));
+
+ modetmp.HDisplay = stuff->hdisplay;
+ modetmp.HSyncStart = stuff->hsyncstart;
+ modetmp.HSyncEnd = stuff->hsyncend;
+ modetmp.HTotal = stuff->htotal;
+ modetmp.VDisplay = stuff->vdisplay;
+ modetmp.VSyncStart = stuff->vsyncstart;
+ modetmp.VSyncEnd = stuff->vsyncend;
+ modetmp.VTotal = stuff->vtotal;
+ modetmp.Flags = stuff->flags;
+ if (mptr->PrivSize && stuff->privsize) {
+ if (mptr->PrivSize != stuff->privsize)
+ return BadValue;
+ }
+ if (mptr->PrivSize && mptr->Private) {
+ modetmp.Private =
+ (INT32 *)ALLOCATE_LOCAL(mptr->PrivSize * sizeof(INT32));
+ if (stuff->privsize) {
+ if (xf86Verbose)
+ ErrorF("ModModeLine - Request includes privates\n");
+ memcpy(modetmp.Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+ } else
+ memcpy(modetmp.Private, mptr->Private,
+ mptr->PrivSize * sizeof(INT32));
+ }
+
+ /* Check that the mode is consistent with the monitor specs */
+ switch (xf86CheckMode(vptr, &modetmp, vptr->monitor, FALSE)) {
+ case MODE_HSYNC:
+ DEALLOCATE_LOCAL(modetmp.Private);
+ return vidmodeErrorBase + XF86VidModeBadHTimings;
+ case MODE_VSYNC:
+ DEALLOCATE_LOCAL(modetmp.Private);
+ return vidmodeErrorBase + XF86VidModeBadVTimings;
+ }
+
+ /* Check that the driver is happy with the mode */
+ if (vptr->ValidMode(&modetmp, xf86Verbose, MODE_VID) != MODE_OK) {
+ DEALLOCATE_LOCAL(modetmp.Private);
+ return vidmodeErrorBase + XF86VidModeModeUnsuitable;
+ }
+
+ DEALLOCATE_LOCAL(modetmp.Private);
+
+ mptr->HDisplay = stuff->hdisplay;
+ mptr->HSyncStart = stuff->hsyncstart;
+ mptr->HSyncEnd = stuff->hsyncend;
+ mptr->HTotal = stuff->htotal;
+ mptr->VDisplay = stuff->vdisplay;
+ mptr->VSyncStart = stuff->vsyncstart;
+ mptr->VSyncEnd = stuff->vsyncend;
+ mptr->VTotal = stuff->vtotal;
+ mptr->Flags = stuff->flags;
+ mptr->CrtcHDisplay = stuff->hdisplay;
+ mptr->CrtcHSyncStart = stuff->hsyncstart;
+ mptr->CrtcHSyncEnd = stuff->hsyncend;
+ mptr->CrtcHTotal = stuff->htotal;
+ mptr->CrtcVDisplay = stuff->vdisplay;
+ mptr->CrtcVSyncStart = stuff->vsyncstart;
+ mptr->CrtcVSyncEnd = stuff->vsyncend;
+ mptr->CrtcVTotal = stuff->vtotal;
+ mptr->CrtcVAdjusted = FALSE;
+ mptr->CrtcHAdjusted = FALSE;
+ if (mptr->Flags & V_DBLSCAN)
+ {
+ mptr->CrtcVDisplay *= 2;
+ mptr->CrtcVSyncStart *= 2;
+ mptr->CrtcVSyncEnd *= 2;
+ mptr->CrtcVTotal *= 2;
+ mptr->CrtcVAdjusted = TRUE;
+ }
+ if (mptr->PrivSize && stuff->privsize) {
+ memcpy(mptr->Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+ }
+
+ (vptr->SwitchMode)(mptr);
+ (vptr->AdjustFrame)(vptr->frameX0, vptr->frameY0);
+
+ if (xf86Verbose)
+ ErrorF("ModModeLine - Succeeded\n");
+ return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeValidateModeLine(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeValidateModeLineReq);
+ xXF86VidModeValidateModeLineReply rep;
+ ScrnInfoPtr vptr;
+ DisplayModePtr mptr;
+ DisplayModeRec modetmp;
+ int len, status;
+
+ if (xf86Verbose) {
+ ErrorF("ValidateModeLine - scrn: %d clock: %d\n",
+ stuff->screen, stuff->dotclock, stuff->dotclock);
+ ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
+ stuff->hdisplay, stuff->hsyncstart,
+ stuff->hsyncend, stuff->htotal);
+ ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+ stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+ stuff->vtotal, stuff->flags);
+ }
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->modes;
+
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+ len = client->req_len - (sizeof(xXF86VidModeValidateModeLineReq) >> 2);
+ if (len != stuff->privsize)
+ return BadLength;
+
+ status = MODE_OK;
+ modetmp.Private = NULL;
+
+ if (stuff->hsyncstart < stuff->hdisplay ||
+ stuff->hsyncend < stuff->hsyncstart ||
+ stuff->htotal < stuff->hsyncend ||
+ stuff->vsyncstart < stuff->vdisplay ||
+ stuff->vsyncend < stuff->vsyncstart ||
+ stuff->vtotal < stuff->vsyncend)
+ {
+ status = MODE_BAD;
+ goto status_reply;
+ }
+
+ memcpy(&modetmp, mptr, sizeof(DisplayModeRec));
+
+ modetmp.HDisplay = stuff->hdisplay;
+ modetmp.HSyncStart = stuff->hsyncstart;
+ modetmp.HSyncEnd = stuff->hsyncend;
+ modetmp.HTotal = stuff->htotal;
+ modetmp.VDisplay = stuff->vdisplay;
+ modetmp.VSyncStart = stuff->vsyncstart;
+ modetmp.VSyncEnd = stuff->vsyncend;
+ modetmp.VTotal = stuff->vtotal;
+ modetmp.Flags = stuff->flags;
+ modetmp.Private = NULL;
+ if (mptr->PrivSize && stuff->privsize) {
+ if (mptr->PrivSize != stuff->privsize) {
+ status = MODE_BAD;
+ goto status_reply;
+ }
+ }
+ if (mptr->PrivSize && mptr->Private) {
+ modetmp.Private =
+ (INT32 *)ALLOCATE_LOCAL(mptr->PrivSize * sizeof(INT32));
+ if (stuff->privsize) {
+ if (xf86Verbose)
+ ErrorF("ValidateModeLine - Request includes privates\n");
+ memcpy(modetmp.Private, &stuff[1], mptr->PrivSize * sizeof(INT32));
+ } else
+ memcpy(modetmp.Private, mptr->Private,
+ mptr->PrivSize * sizeof(INT32));
+ }
+
+ /* Check that the mode is consistent with the monitor specs */
+ if ((status = xf86CheckMode(vptr, &modetmp, vptr->monitor, FALSE)) != MODE_OK)
+ goto status_reply;
+
+ /* Check that the driver is happy with the mode */
+ status = vptr->ValidMode(&modetmp, xf86Verbose, MODE_VID);
+
+status_reply:
+ if (modetmp.Private)
+ DEALLOCATE_LOCAL(modetmp.Private);
+ rep.type = X_Reply;
+ rep.length = (SIZEOF(xXF86VidModeValidateModeLineReply)
+ - SIZEOF(xGenericReply)) >> 2;
+ rep.sequenceNumber = client->sequence;
+ rep.status = status;
+ if (client->swapped) {
+ register int n;
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ swapl(&rep.status, n);
+ }
+ WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), (char *)&rep);
+ if (xf86Verbose)
+ ErrorF("ValidateModeLine - Succeeded\n");
+ return(client->noClientException);
+}
+
+static int
+ProcXF86VidModeSwitchMode(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeSwitchModeReq);
+ ScreenPtr vptr;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = screenInfo.screens[stuff->screen];
+ if (xf86Info.dontZoom)
+ return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+
+ xf86ZoomViewport(vptr, (short)stuff->zoom);
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeSwitchToMode(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeSwitchToModeReq);
+ ScrnInfoPtr vptr;
+ DisplayModePtr curmptr, mptr;
+ DisplayModeRec modetmp;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ if (xf86Info.dontZoom)
+ return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ curmptr = mptr = vptr->modes;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
+
+ if (MODEMATCH(mptr, stuff, vptr))
+ return (client->noClientException);
+
+ while ((mptr = mptr->next) != curmptr) {
+ if (MODEMATCH(mptr, stuff, vptr)) {
+ if ((vptr->SwitchMode)(mptr)) {
+ vptr->modes = mptr;
+ vptr->frameX0 = (vptr->frameX1 +vptr->frameX0 -mptr->HDisplay)/2;
+ vptr->frameX1 = vptr->frameX0 + mptr->HDisplay -1;
+ if (vptr->frameX0 < 0) {
+ vptr->frameX0 = 0;
+ vptr->frameX1 = mptr->HDisplay -1;
+ } else if (vptr->frameX1 >= vptr->virtualX) {
+ vptr->frameX0 = vptr->virtualX - mptr->HDisplay;
+ vptr->frameX1 = vptr->frameX0 + mptr->HDisplay -1;
+ }
+ vptr->frameY0 = (vptr->frameY1 +vptr->frameY0 -mptr->VDisplay)/2;
+ vptr->frameY1 = vptr->frameY0 + mptr->VDisplay -1;
+ if (vptr->frameY0 < 0) {
+ vptr->frameY0 = 0;
+ vptr->frameY1 = mptr->VDisplay -1;
+ } else if (vptr->frameY1 >= vptr->virtualY) {
+ vptr->frameY0 = vptr->virtualY - mptr->VDisplay;
+ vptr->frameY1 = vptr->frameY0 + mptr->VDisplay -1;
+ }
+ }
+ (vptr->AdjustFrame)(vptr->frameX0, vptr->frameY0);
+ return(client->noClientException);
+ }
+ }
+ return BadValue;
+}
+
+static int
+ProcXF86VidModeLockModeSwitch(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeLockModeSwitchReq);
+ ScreenPtr vptr;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = screenInfo.screens[stuff->screen];
+ if (xf86Info.dontZoom)
+ return vidmodeErrorBase + XF86VidModeZoomLocked;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+
+ xf86LockZoom(vptr, (short)stuff->lock);
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetMonitor(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeGetMonitorReq);
+ xXF86VidModeGetMonitorReply rep;
+ register int n;
+ ScrnInfoPtr vptr;
+ MonPtr mptr;
+ CARD32 *hsyncdata, *vsyncdata;
+ int i;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->monitor;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+ rep.type = X_Reply;
+ if (mptr->vendor)
+ rep.vendorLength = strlen(mptr->vendor);
+ else
+ rep.vendorLength = 0;
+ if (mptr->model)
+ rep.modelLength = strlen(mptr->model);
+ else
+ rep.modelLength = 0;
+ rep.length = (SIZEOF(xXF86VidModeGetMonitorReply) - SIZEOF(xGenericReply) +
+ (mptr->n_hsync + mptr->n_vrefresh) * sizeof(CARD32) +
+ ((rep.vendorLength + 3) & ~3) +
+ ((rep.modelLength + 3) & ~3)) >> 2;
+ rep.sequenceNumber = client->sequence;
+ rep.nhsync = mptr->n_hsync;
+ rep.nvsync = mptr->n_vrefresh;
+#if 0
+ rep.bandwidth = (unsigned long)(mptr->bandwidth * 1e6);
+#endif
+ hsyncdata = ALLOCATE_LOCAL(mptr->n_hsync * sizeof(CARD32));
+ if (!hsyncdata) {
+ return BadAlloc;
+ }
+ vsyncdata = ALLOCATE_LOCAL(mptr->n_vrefresh * sizeof(CARD32));
+ if (!vsyncdata) {
+ DEALLOCATE_LOCAL(hsyncdata);
+ return BadAlloc;
+ }
+ for (i = 0; i < mptr->n_hsync; i++) {
+ hsyncdata[i] = (unsigned short)(mptr->hsync[i].lo * 100.0) |
+ (unsigned short)(mptr->hsync[i].hi * 100.0) << 16;
+ }
+ for (i = 0; i < mptr->n_vrefresh; i++) {
+ vsyncdata[i] = (unsigned short)(mptr->vrefresh[i].lo * 100.0) |
+ (unsigned short)(mptr->vrefresh[i].hi * 100.0) << 16;
+ }
+
+ if (client->swapped) {
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ swapl(&rep.bandwidth, n);
+ }
+ WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), (char *)&rep);
+ client->pSwapReplyFunc = Swap32Write;
+ WriteSwappedDataToClient(client, mptr->n_hsync * sizeof(CARD32),
+ hsyncdata);
+ WriteSwappedDataToClient(client, mptr->n_vrefresh * sizeof(CARD32),
+ vsyncdata);
+ if (rep.vendorLength)
+ WriteToClient(client, rep.vendorLength, mptr->vendor);
+ if (rep.modelLength)
+ WriteToClient(client, rep.modelLength, mptr->model);
+ DEALLOCATE_LOCAL(hsyncdata);
+ DEALLOCATE_LOCAL(vsyncdata);
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeGetViewPort(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeGetViewPortReq);
+ xXF86VidModeGetViewPortReply rep;
+ register int n;
+ ScrnInfoPtr vptr;
+ MonPtr mptr;
+ CARD32 *hsyncdata, *vsyncdata;
+ int i;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->monitor;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+ rep.type = X_Reply;
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeSetViewPort(client)
+ register ClientPtr client;
+{
+ REQUEST(xXF86VidModeSetViewPortReq);
+ register int n;
+ ScrnInfoPtr vptr;
+ MonPtr mptr;
+ CARD32 *hsyncdata, *vsyncdata;
+ int i;
+
+ if (stuff->screen > screenInfo.numScreens)
+ return BadValue;
+
+ vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+ mptr = vptr->monitor;
+
+ REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+ return (client->noClientException);
+}
+
+static int
+ProcXF86VidModeDispatch (client)
+ register ClientPtr client;
+{
+ REQUEST(xReq);
+ switch (stuff->data)
+ {
+ case X_XF86VidModeQueryVersion:
+ return ProcXF86VidModeQueryVersion(client);
+ case X_XF86VidModeGetModeLine:
+ return ProcXF86VidModeGetModeLine(client);
+ case X_XF86VidModeGetAllModeLines:
+ return ProcXF86VidModeGetAllModeLines(client);
+ case X_XF86VidModeGetMonitor:
+ return ProcXF86VidModeGetMonitor(client);
+ case X_XF86VidModeValidateModeLine:
+ return ProcXF86VidModeValidateModeLine(client);
+ case X_XF86VidModeGetViewPort:
+ return ProcXF86VidModeGetViewPort(client);
+ default:
+ if (!xf86VidModeEnabled)
+ return vidmodeErrorBase + XF86VidModeExtensionDisabled;
+ if (xf86VidModeAllowNonLocal || LocalClient (client)) {
+ switch (stuff->data) {
+ case X_XF86VidModeAddModeLine:
+ return ProcXF86VidModeAddModeLine(client);
+ case X_XF86VidModeDeleteModeLine:
+ return ProcXF86VidModeDeleteModeLine(client);
+ case X_XF86VidModeModModeLine:
+ return ProcXF86VidModeModModeLine(client);
+ case X_XF86VidModeSwitchMode:
+ return ProcXF86VidModeSwitchMode(client);
+ case X_XF86VidModeSwitchToMode:
+ return ProcXF86VidModeSwitchToMode(client);
+ case X_XF86VidModeLockModeSwitch:
+ return ProcXF86VidModeLockModeSwitch(client);
+ case X_XF86VidModeSetViewPort:
+ return ProcXF86VidModeSetViewPort(client);
+ default:
+ return BadRequest;
+ }
+ } else
+ return vidmodeErrorBase + XF86VidModeClientNotLocal;
+ }
+}
+
+static int
+SProcXF86VidModeQueryVersion(client)
+ register ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeQueryVersionReq);
+ swaps(&stuff->length, n);
+ return ProcXF86VidModeQueryVersion(client);
+}
+
+static int
+SProcXF86VidModeGetModeLine(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeGetModeLineReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeGetModeLine(client);
+}
+
+static int
+SProcXF86VidModeGetAllModeLines(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeGetAllModeLinesReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeGetAllModeLines(client);
+}
+
+static int
+SProcXF86VidModeAddModeLine(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeAddModeLineReq);
+ swaps(&stuff->length, n);
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+ swapl(&stuff->screen, n);
+ swaps(&stuff->hdisplay, n);
+ swaps(&stuff->hsyncstart, n);
+ swaps(&stuff->hsyncend, n);
+ swaps(&stuff->htotal, n);
+ swaps(&stuff->vdisplay, n);
+ swaps(&stuff->vsyncstart, n);
+ swaps(&stuff->vsyncend, n);
+ swaps(&stuff->vtotal, n);
+ swapl(&stuff->flags, n);
+ swapl(&stuff->privsize, n);
+ SwapRestL(stuff);
+ return ProcXF86VidModeAddModeLine(client);
+}
+
+static int
+SProcXF86VidModeDeleteModeLine(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeDeleteModeLineReq);
+ swaps(&stuff->length, n);
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+ swapl(&stuff->screen, n);
+ swaps(&stuff->hdisplay, n);
+ swaps(&stuff->hsyncstart, n);
+ swaps(&stuff->hsyncend, n);
+ swaps(&stuff->htotal, n);
+ swaps(&stuff->vdisplay, n);
+ swaps(&stuff->vsyncstart, n);
+ swaps(&stuff->vsyncend, n);
+ swaps(&stuff->vtotal, n);
+ swapl(&stuff->flags, n);
+ swapl(&stuff->privsize, n);
+ SwapRestL(stuff);
+ return ProcXF86VidModeDeleteModeLine(client);
+}
+
+static int
+SProcXF86VidModeModModeLine(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeModModeLineReq);
+ swaps(&stuff->length, n);
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+ swapl(&stuff->screen, n);
+ swaps(&stuff->hdisplay, n);
+ swaps(&stuff->hsyncstart, n);
+ swaps(&stuff->hsyncend, n);
+ swaps(&stuff->htotal, n);
+ swaps(&stuff->vdisplay, n);
+ swaps(&stuff->vsyncstart, n);
+ swaps(&stuff->vsyncend, n);
+ swaps(&stuff->vtotal, n);
+ swapl(&stuff->flags, n);
+ swapl(&stuff->privsize, n);
+ SwapRestL(stuff);
+ return ProcXF86VidModeModModeLine(client);
+}
+
+static int
+SProcXF86VidModeValidateModeLine(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeValidateModeLineReq);
+ swaps(&stuff->length, n);
+ REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+ swapl(&stuff->screen, n);
+ swaps(&stuff->hdisplay, n);
+ swaps(&stuff->hsyncstart, n);
+ swaps(&stuff->hsyncend, n);
+ swaps(&stuff->htotal, n);
+ swaps(&stuff->vdisplay, n);
+ swaps(&stuff->vsyncstart, n);
+ swaps(&stuff->vsyncend, n);
+ swaps(&stuff->vtotal, n);
+ swapl(&stuff->flags, n);
+ swapl(&stuff->privsize, n);
+ SwapRestL(stuff);
+ return ProcXF86VidModeValidateModeLine(client);
+}
+
+static int
+SProcXF86VidModeSwitchMode(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeSwitchModeReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+ swaps(&stuff->screen, n);
+ swaps(&stuff->zoom, n);
+ return ProcXF86VidModeSwitchMode(client);
+}
+
+static int
+SProcXF86VidModeSwitchToMode(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeSwitchToModeReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeSwitchToMode(client);
+}
+
+static int
+SProcXF86VidModeLockModeSwitch(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeLockModeSwitchReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+ swaps(&stuff->screen, n);
+ swaps(&stuff->lock, n);
+ return ProcXF86VidModeLockModeSwitch(client);
+}
+
+static int
+SProcXF86VidModeGetMonitor(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeGetMonitorReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeGetMonitor(client);
+}
+
+static int
+SProcXF86VidModeGetViewPort(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeGetViewPortReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeGetViewPort(client);
+}
+
+static int
+SProcXF86VidModeSetViewPort(client)
+ ClientPtr client;
+{
+ register int n;
+ REQUEST(xXF86VidModeSetViewPortReq);
+ swaps(&stuff->length, n);
+ REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+ swaps(&stuff->screen, n);
+ return ProcXF86VidModeSetViewPort(client);
+}
+
+static int
+SProcXF86VidModeDispatch (client)
+ register ClientPtr client;
+{
+ REQUEST(xReq);
+ switch (stuff->data)
+ {
+ case X_XF86VidModeQueryVersion:
+ return SProcXF86VidModeQueryVersion(client);
+ case X_XF86VidModeGetModeLine:
+ return SProcXF86VidModeGetModeLine(client);
+ case X_XF86VidModeGetAllModeLines:
+ return SProcXF86VidModeGetAllModeLines(client);
+ case X_XF86VidModeGetMonitor:
+ return SProcXF86VidModeGetMonitor(client);
+ case X_XF86VidModeGetViewPort:
+ return SProcXF86VidModeGetViewPort(client);
+ case X_XF86VidModeValidateModeLine:
+ return SProcXF86VidModeValidateModeLine(client);
+ default:
+ if (!xf86VidModeEnabled)
+ return vidmodeErrorBase + XF86VidModeExtensionDisabled;
+ if (xf86VidModeAllowNonLocal || LocalClient(client)) {
+ switch (stuff->data) {
+ case X_XF86VidModeAddModeLine:
+ return SProcXF86VidModeAddModeLine(client);
+ case X_XF86VidModeDeleteModeLine:
+ return SProcXF86VidModeDeleteModeLine(client);
+ case X_XF86VidModeModModeLine:
+ return SProcXF86VidModeModModeLine(client);
+ case X_XF86VidModeSwitchMode:
+ return SProcXF86VidModeSwitchMode(client);
+ case X_XF86VidModeSwitchToMode:
+ return SProcXF86VidModeSwitchToMode(client);
+ case X_XF86VidModeLockModeSwitch:
+ return SProcXF86VidModeLockModeSwitch(client);
+ case X_XF86VidModeSetViewPort:
+ return SProcXF86VidModeSetViewPort(client);
+ default:
+ return BadRequest;
+ }
+ } else
+ return vidmodeErrorBase + XF86VidModeClientNotLocal;
+ }
+}
diff --git a/hw/xfree86/os-support/README.OS-lib b/hw/xfree86/os-support/README.OS-lib
new file mode 100644
index 000000000..cf3a0cc7e
--- /dev/null
+++ b/hw/xfree86/os-support/README.OS-lib
@@ -0,0 +1,437 @@
+
+ README for XFree86 OS-support Layer
+ -----------------------------------
+
+Contents
+--------
+ 1) Overview
+ 2) Directory Layout
+ 3) Adding a new OS
+ 4) OS Support API
+
+1 - Overview
+------------
+ This directory contains the OS support layer functions for the XFree86
+servers. In addition, some miscellaneous server support functions (not
+OS-dependent) are included here, to take advantage of the fact that this
+library comes last in the linking order.
+
+Most of the functionality required to support a new OS is encapsulated in
+this library. It is hoped that all OS-specific details can be encapsulated,
+but that is not likely ever to be completely possible. Hence some minor
+changes will wind up being made in other parts of the server. The major
+design principles for this library are maintainability, readability, and
+portability. Sometimes these goals conflict; some somewhat arbitrary choices
+have been made in implementation.
+
+2 - Directory Layout
+--------------------
+ os-support/ Contains headers and documentation; no code
+ misc/ Non-OS-specific miscellaneous functions that
+ fit best into the link architecture this way.
+ shared/ Contains files with functions used by more than one
+ OS. These are symlinked into the OS subdirectories
+ at build time via Imakefile rules. This is alway
+ preferable to reproducing functions in more than one
+ OS library.
+ amoeba/ OS support for the Amoeba operating system.
+ bsd/ OS support for the 386BSD/NetBSD/FreeBSD operating
+ systems.
+ bsdi/ OS support for the BSD/386 operating system.
+ linux/ OS support for the Linux operating system.
+ mach/ OS support for the Mach and OSF/1 operating systems.
+ minix/ OS support for the Minix operating system.
+ os2/ OS support for OS/2 2.11 and OS/2 Warp
+ sco/ OS support for the SCO SVR3.x operating system.
+ solx86/ OS support for the Solaris x86 operating system.
+ sysv/ OS support for all SVR4.0 and SVR4.2, and for
+ ISC and AT&T SVR3.2 operating systems.
+
+3 - Adding A New OS
+-------------------
+ Adding a support for a new operating system entails implementing all of
+the functions described in the API below. Many of these functions are no-ops
+for many operating systems, and appropriate files with dummy declarations are
+available in the 'shared' subdirectory.
+
+If your OS is sufficiently similar to an existing OS, you can make use of
+the existing subdirectory. One of the reasons for implementing this OS
+library was the unmaintainability of the spagetti-#ifdef code that existed
+before. You should try to avoid cluttering the code with #ifdef's. If
+you find that the subdirectory is getting cluttered, split off into a
+seperate subdirectory (e.g. as was done for SCO, rather than cluttering
+the 'sysv' subdirectory). You can split functions out of an existing
+subdirectory into the 'shared' subdirectory, if that is appropriate. Just
+remember to update the Imakefile for the old subdirectory.
+
+You will still likely have to make some small changes to other parts of
+the server. You should not put OS-specific #define's or #include's anywhere
+else in the server. These should all go in the "xf86_OSlib.h" header file
+in this directory.
+
+4 - OS Support API
+-----------------
+void xf86OpenConsole(void)
+{
+ /*
+ * Open console device, activate VTs, etc, etc. Fill in requisite
+ * pieces of x386Info. Most of this code comes from x386Init.c
+ */
+}
+
+void xf86CloseConsole(void)
+{
+ /*
+ * Close console at server exit.
+ */
+}
+
+Bool xf86VTSwitchPending(void)
+{
+ /*
+ * Returns TRUE iff there is a VT switch operation pending for
+ * the server. In the USL VT model, this is indicated via a
+ * signal handler. Should return FALSE always for OSs without
+ * VTs.
+ */
+}
+
+Bool xf86VTSwitchAway(void)
+{
+ /*
+ * Handles the OS-specific action for switching away from the active
+ * VT. Returns FALSE if the switch away fails. Should return
+ * FALSE always for OSs without VTs (then again, this function
+ * should never be called in that case).
+ */
+}
+
+Bool xf86VTSwitchTo(void)
+{
+ /*
+ * Handles the OS-specific action for switching to the active VT.
+ * Returns FALSE if the switch to fails. Should return TRUE
+ * always for OSs without VTs (then again, this function should
+ * never be called in that case).
+ */
+}
+
+Bool xf86LinearVidMem(void)
+{
+ /*
+ * Returns TRUE if the OS supports mapping linear frame buffers
+ * (ie memory at addresses above physical memory).
+ */
+}
+
+pointer xf86MapVidMem(int ScreenNum, int Region, pointer Base,
+ unsigned long Size)
+{
+ /*
+ * Handle mapping the video memory. Returns (pointer *)0 for
+ * failure; causes server exit. It is allowable to call FatalError()
+ * from inside this function and exit directly.
+ */
+}
+
+void xf86UnMapVidMem(int ScreenNum, int Region, pointer Base,
+ unsigned long Size)
+{
+ /*
+ * Handle unmapping the video memory. This should undo what
+ * xf86MapVidMem() does. Base is a pointer obtained from
+ * a previous call to xf86MapVidMem().
+ */
+}
+
+void xf86MapDisplay(int ScreenNum, int Region)
+{
+ /*
+ * For OSs that require the screen be mapped when entering a VT.
+ * A dummy function will be defined for OSs that don't require
+ * this (or don't have VTs at all).
+ */
+}
+
+void xf86UnMapDisplay(int ScreenNum, int Region)
+{
+ /*
+ * For Os that require that the screen be unmapped when leaving a
+ * VT. A dummy function will be defined for OSs that don't require
+ * this (or don't have VTs at all).
+ */
+}
+
+int xf86ReadBIOS(unsigned long Base, unsigned long Offset,
+ unsigned char *Buf, int Len)
+{
+ /*
+ * Read Len bytes from the BIOS at address Base, offset Offset,
+ * into buffer Buf. Returns -1 for failure or if the OS does
+ * not support reading the BIOS. This causes a driver probe
+ * to fail, but does not cause the server to abort.
+ */
+}
+
+void xf86ClearIOPortList(int ScreenNum)
+{
+ /*
+ * Clears any list of I/O ports that the OS-layer may be maintaining.
+ * Note: the value used for ScreenNum must be the scrnIndex field
+ * of the screenInfoRec, because this is the only index that is
+ * guaranteed to be valid and never change during the life of the
+ * server. It is not the same as the index of pScreen in ScreenInfo.
+ */
+}
+
+void xf86AddIOPorts(int ScreenNum, int NumPorts, unsigned *Ports)
+{
+ /*
+ * Adds NumPorts I/O ports listed in array Ports to a list that
+ * the OS-layer may be maintaining. Successive calls to this
+ * function are cumulative.
+ */
+}
+
+void xf86EnableIOPorts(int ScreenNum)
+{
+ /*
+ * Enables I/O permissions. The OS layer can either use a
+ * previously created list of I/O ports to be used, or can
+ * enable all I/O port access.
+ */
+}
+
+void xf86DisableIOPorts(int ScreenNum)
+{
+ /*
+ * Disables I/O permissions. Does not clear the list of I/O
+ * ports, if any exists.
+ */
+}
+
+void xf86DisableIOPrivs(void)
+{
+ /*
+ * Do whatever is necessary to disable I/O permissions after forking
+ * a child process.
+ */
+}
+
+Bool xf86DisableInterrupts(void)
+{
+ /*
+ * Disable interrupts if allowed for this OS. Returns FALSE if
+ * this is not allowed or if the attempt fails for some reason.
+ */
+}
+
+void xf86EnableInterrupts(void)
+{
+ /*
+ * Reenable interrupts
+ */
+}
+
+int xf86ProcessArgument(int argc, char *argv[], int i)
+{
+ /*
+ * Process OS-specific command-line arguments. See
+ * ddxProcessArgument() for more info.
+ */
+}
+
+void xf86UseMsg(void)
+{
+ /*
+ * Print list of OS-specific command-line arguments. See
+ * ddxUseMsg() for more info.
+ */
+}
+
+void xf86SoundKbdBell(int loudness, int pitch, int duration)
+{
+ /*
+ * Sound the keyboard bell. pitch is in Hz, duration in ms,
+ * loudness is in the range 0-100 (0 -> off). For systems
+ * where the loudness can't be controlled, scale the duration
+ * by loudness/50.
+ */
+}
+
+void xf86SetKbdLeds(int leds)
+{
+ /*
+ * Set the keyboard LEDs to the state indicated in leds
+ */
+}
+
+int xf86GetKbdLeds(void)
+{
+ /*
+ * Return the state of the keyboard LEDs. If the OS doesn't
+ * support this, return 0.
+ */
+}
+
+void xf86SetKbdRepeat(char rad)
+{
+ /*
+ * Set the keyboard repeat rate and delay according the
+ * the rad value. The lower 5 bits determine the repeat
+ * rate (lower value -> higher rate). The next 2 bits
+ * determine the delay.
+ * This should possibly be changed to take separate rate and
+ * delay parameters.
+ */
+}
+
+void xf86KbdInit(void)
+{
+ /*
+ * Save initial keyboard state. This is called at the start of
+ * each server generation.
+ */
+}
+
+int xf86KbdOn(void)
+{
+ /*
+ * Set the keyboard up for use with X. This is called whenever
+ * the server becomes active (ie at the start of each generation and
+ * whenever its VT becomes active). Return the file descriptor
+ * for keyboard input. Return -1 if there is no file descriptor
+ * to add as an input device. If there are errors encountered,
+ * call FatalError(). A return value of -1 is not considered an
+ * error condition.
+ */
+}
+
+int xf86KbdOff(void)
+{
+ /*
+ * Return the keyboard to the state saved by xf86KbdInit(). This is
+ * called at the end of a server generation, and also when the
+ * server's VT ceases being active. Returns the keyboard file
+ * descriptor. Returns -1 if there is no file descriptor to be
+ * removed as an input device. Errors should be handled the same
+ * way as in xf86KbdOn().
+ */
+}
+
+void xf86KbdEvents(void)
+{
+ /*
+ * Read characters from the keyboard device, and post the events
+ * by calling x386PostKbdEvent(). Read as much as is available
+ * without waiting.
+ */
+}
+
+void xf86SetMouseSpeed(int old, int new, unsigned cflag)
+{
+ /*
+ * Set the speed of the mouse port. old is the previous speed,
+ * new is the new speed, and cflag is the value of the termio[s]
+ * c_cflag field. For mice that have programmable speed operation,
+ * this should send the appropriate commands to the mouse.
+ */
+}
+
+void xf86MouseInit(void)
+{
+ /*
+ * This is called at the start of each server generation. In most
+ * cases this is a noop. If the mouse must not be opened/closed
+ * when VT switching, the open should be done here.
+ */
+}
+
+int xf86MousedOn(void)
+{
+ /*
+ * Set the mouse up for use with X. This is called whenever
+ * the server becomes active (ie at the start of each generation and
+ * whenever its VT becomes active). This function normally opens
+ * the mouse device, and may call xf86SetupMouse() to initialise
+ * the mouse parameters. Return the file descriptor for mouse input.
+ * Return -1 if there is no file descriptor to add as an input
+ * device. If there are errors encountered, call FatalError().
+ * A return value of -1 is not considered an error condition.
+ */
+}
+
+int xf86MouseOff(Bool doclose)
+{
+ /*
+ * Release the mouse from use with X. This is called at the end
+ * of a server generation (with doclose==TRUE), and also when the
+ * server's VT ceases being active (with doclose==FALSE). If the
+ * mouse should not be opened/closed when VT switching, the close
+ * should be done here when doclose==TRUE. For other systems, the
+ * mouse device should be closed regardless of the doclose value.
+ * Returns the mouse file descriptor. Returns -1 if there is no
+ * file descriptor to be removed as an input device. Errors
+ * should be handled the same way as in xf86MouseOn().
+ */
+}
+
+void xf86MouseEvents(void)
+{
+ /*
+ * Read characters from the mouse device, and post the events
+ * by calling x386PostMseEvent(). Read as much as is available
+ * without waiting. If the OS doesn't handle the mouse protocol
+ * translation, xf86MouseProtocol() may be called to do the
+ * translation and event posting. If the OS does handle the protocol
+ * translation, MOUSE_PROTOCOL_IN_KERNEL should be #define'd in
+ * xf86_OSlib.h.
+ */
+}
+
+int xf86OsMouseProc(DevicePtr pPointer, int what)
+{
+ /*
+ * Implements the device-proc for the pointer device when an
+ * OS-based mouse driver is being used (as opposed to the
+ * server's internal mouse driver). Implemented as any other
+ * device-proc in the server.
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+int xf86OsMouseEvents(void)
+{
+ /*
+ * When supporting an OS-based mouse driver (as opposed to the
+ * server's internal mouse driver), read some events from the device
+ * and post them to the DIX layer through x386PostMseEvent().
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+void xf86OsMouseOption(int token, pointer lex_ptr)
+{
+ /*
+ * Used in parsing an OsMouse keyword from the Xconfig file.
+ * Passed the token type and a pointer to the token value.
+ * The function should do whatever is appropriate for the OS's
+ * mouse driver.
+ *
+ * This function only needs to be implemented if USE_OSMOUSE is
+ * defined for the OS.
+ */
+}
+
+
+$XFree86: xc/programs/Xserver/hw/xfree86/os-support/README.OS-lib,v 3.2 1996/12/23 06:48:59 dawes Exp $
+
+
+
+
+
+$Xorg: README.OS-lib,v 1.3 2000/08/17 19:51:19 cpqbld Exp $
diff --git a/hw/xfree86/os-support/assyntax.h b/hw/xfree86/os-support/assyntax.h
new file mode 100644
index 000000000..ee2c23fa4
--- /dev/null
+++ b/hw/xfree86/os-support/assyntax.h
@@ -0,0 +1,725 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/assyntax.h,v 3.7.2.2 1997/05/11 02:56:22 dawes Exp $ */
+#ifndef __ASSYNTAX_H__
+#define __ASSYNTAX_H__
+
+/*
+ * Copyright 1992 Vrije Universiteit, The Netherlands
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the Vrije Universiteit not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. The Vrije Universiteit makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ *
+ * The Vrije Universiteit DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL The Vrije Universiteit BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+/* $Xorg: assyntax.h,v 1.3 2000/08/17 19:51:19 cpqbld Exp $ */
+
+ /*
+ * assyntax.h
+ *
+ * Select the syntax appropriate to the 386 assembler being used
+ * To add support for more assemblers add more columns to the CHOICE
+ * macro. Note that register names must also have uppercase names
+ * to avoid macro recursion. e.g., #define ah %ah recurses!
+ *
+ * NB 1. Some of the macros for certain assemblers imply that the code is to
+ * run in protected mode!! Caveat emptor.
+ *
+ * NB 2. 486 specific instructions are not included. This is to discourage
+ * their accidental use in code that is intended to run on 386 and 486
+ * systems.
+ *
+ * Supported assemblers:
+ *
+ * (a) AT&T SysVr4 as(1): default
+ * (b) GNU Assembler gas: define USE_GAS or GNU_ASSEMBLER
+ * (c) Amsterdam Compiler kit: define ACK_ASSEMBLER
+ *
+ * The following naming conventions have been used to identify the various
+ * data types:
+ * _SR = segment register version
+ * Integer:
+ * _Q = quadword = 64 bits
+ * _L = long = 32 bits
+ * _W = short = 16 bits
+ * _B = byte = 8 bits
+ * Floating-point:
+ * _X = m80real = 80 bits
+ * _D = double = 64 bits
+ * _S = single = 32 bits
+ *
+ * Author: Gregory J. Sharp, Sept 1992
+ * Vrije Universiteit, Amsterdam, The Netherlands
+ */
+
+#if defined(USE_GAS) && !defined(GNU_ASSEMBLER)
+#define GNU_ASSEMBLER
+#endif
+
+#if (defined(__STDC__) && !defined(UNIXCPP)) || (defined (sun) && defined (i386) && defined (SVR4) && defined (__STDC__) && !defined (__GNUC__))
+#define CONCAT(x, y) x ## y
+#else
+#define CONCAT(x, y) x/**/y
+#endif
+
+#ifdef ACK_ASSEMBLER
+
+/* Assume we write code for 32-bit protected mode! */
+
+/* Redefine register names for GAS & AT&T assemblers */
+#define AL al
+#define AH ah
+#define AX ax
+#define EAX ax
+#define BL bl
+#define BH bh
+#define BX bx
+#define EBX bx
+#define CL cl
+#define CH ch
+#define CX cx
+#define ECX cx
+#define DL dl
+#define DH dh
+#define DX dx
+#define EDX dx
+#define BP bp
+#define EBP bp
+#define SI si
+#define ESI si
+#define DI di
+#define EDI di
+#define SP sp
+#define ESP sp
+#define CS cs
+#define SS ss
+#define DS ds
+#define ES es
+#define FS fs
+#define GS gs
+/* Control Registers */
+#define CR0 cr0
+#define CR1 cr1
+#define CR2 cr2
+#define CR3 cr3
+/* Debug Registers */
+#define DR0 dr0
+#define DR1 dr1
+#define DR2 dr2
+#define DR3 dr3
+#define DR4 dr4
+#define DR5 dr5
+#define DR6 dr6
+#define DR7 dr7
+/* Floating-point Stack */
+#define ST st
+
+#define AS_BEGIN .sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text
+
+
+#define _WTOG o16 /* word toggle for _W instructions */
+#define _LTOG /* long toggle for _L instructions */
+#define ADDR_TOGGLE a16
+#define OPSZ_TOGGLE o16
+#define USE16 .use16
+#define USE32 .use32
+
+#define CHOICE(a,b,c) c
+
+#else /* AT&T or GAS */
+
+/* Redefine register names for GAS & AT&T assemblers */
+#define AL %al
+#define AH %ah
+#define AX %ax
+#define EAX %eax
+#define BL %bl
+#define BH %bh
+#define BX %bx
+#define EBX %ebx
+#define CL %cl
+#define CH %ch
+#define CX %cx
+#define ECX %ecx
+#define DL %dl
+#define DH %dh
+#define DX %dx
+#define EDX %edx
+#define BP %bp
+#define EBP %ebp
+#define SI %si
+#define ESI %esi
+#define DI %di
+#define EDI %edi
+#define SP %sp
+#define ESP %esp
+#define CS %cs
+#define SS %ss
+#define DS %ds
+#define ES %es
+#define FS %fs
+#define GS %gs
+/* Control Registers */
+#define CR0 %cr0
+#define CR1 %cr1
+#define CR2 %cr2
+#define CR3 %cr3
+/* Debug Registers */
+#define DR0 %db0
+#define DR1 %db1
+#define DR2 %db2
+#define DR3 %db3
+#define DR4 %db4
+#define DR5 %db5
+#define DR6 %db6
+#define DR7 %db7
+/* Floating-point Stack */
+#define ST %st
+
+#define AS_BEGIN
+#define USE16
+#define USE32
+
+#ifdef GNU_ASSEMBLER
+
+#define ADDR_TOGGLE aword
+#define OPSZ_TOGGLE word
+
+#define CHOICE(a,b,c) b
+
+#else
+/*
+ * AT&T ASSEMBLER SYNTAX
+ * *********************
+ */
+#define CHOICE(a,b,c) a
+
+#define ADDR_TOGGLE addr16
+#define OPSZ_TOGGLE data16
+
+#endif /* GNU_ASSEMBLER */
+#endif /* ACK_ASSEMBLER */
+
+
+#if defined(Lynx) || (defined(SYSV) || defined(SVR4)) && !defined(ACK_ASSEMBLER) || (defined(linux) || defined(__OS2ELF__)) && defined(__ELF__)
+#define GLNAME(a) a
+#else
+#define GLNAME(a) CONCAT(_,a)
+#endif
+
+
+ /****************************************/
+ /* */
+ /* Select the various choices */
+ /* */
+ /****************************************/
+
+
+/* Redefine assembler directives */
+/*********************************/
+#define GLOBL CHOICE(.globl, .globl, .extern)
+#define ALIGNTEXT4 CHOICE(.align 4, .align ARG2(2,0x90), .align 4)
+#define ALIGNTEXT2 CHOICE(.align 2, .align ARG2(1,0x90), .align 2)
+/* ALIGNTEXT4ifNOP is the same as ALIGNTEXT4, but only if the space is
+ * guaranteed to be filled with NOPs. Otherwise it does nothing.
+ */
+#define ALIGNTEXT4ifNOP CHOICE(.align 4, .align ARG2(2,0x90), /*can't do it*/)
+#define ALIGNDATA4 CHOICE(.align 4, .align ARG2(2,0x0), .align 4)
+#define ALIGNDATA2 CHOICE(.align 2, .align ARG2(1,0x0), .align 2)
+#define FILE(s) CHOICE(.file s, .file s, .file s)
+#define STRING(s) CHOICE(.string s, .asciz s, .asciz s)
+#define D_LONG CHOICE(.long, .long, .data4)
+#define D_WORD CHOICE(.value, .short, .data2)
+#define D_BYTE CHOICE(.byte, .byte, .data1)
+#define SPACE CHOICE(.comm, .space, .space)
+#define COMM CHOICE(.comm, .comm, .comm)
+#define SEG_DATA CHOICE(.data, .data, .sect .data)
+#define SEG_TEXT CHOICE(.text, .text, .sect .text)
+#define SEG_BSS CHOICE(.bss, .bss, .sect .bss)
+
+#ifdef GNU_ASSEMBLER
+#define D_SPACE(n) . = . + n
+#else
+#define D_SPACE(n) .space n
+#endif
+
+/* Addressing Modes */
+/* Immediate Mode */
+#define ADDR(a) CHOICE(CONCAT($,a), CONCAT($,a), a)
+#define CONST(a) CHOICE(CONCAT($,a), CONCAT($,a), a)
+
+/* Indirect Mode */
+#define CONTENT(a) CHOICE(a, a, (a)) /* take contents of variable */
+#define REGIND(a) CHOICE((a), (a), (a)) /* Register a indirect */
+/* Register b indirect plus displacement a */
+#define REGOFF(a, b) CHOICE(a(b), a(b), a(b))
+/* Reg indirect Base + Index + Displacement - this is mainly for 16-bit mode
+ * which has no scaling
+ */
+#define REGBID(b,i,d) CHOICE(d(b,i), d(b,i), d(b)(i))
+/* Reg indirect Base + (Index * Scale) + Displacement */
+#define REGBISD(b,i,s,d) CHOICE(d(b,i,s), d(b,i,s), d(b)(i*s))
+/* Displaced Scaled Index: */
+#define REGDIS(d,i,s) CHOICE(d(,i,s), d(,i,s), d(i * s))
+/* Indexed Base: */
+#define REGBI(b,i) CHOICE((b,i), (b,i), (b)(i))
+/* Displaced Base: */
+#define REGDB(d,b) CHOICE(d(b), d(b), d(b))
+/* Variable indirect: */
+#define VARINDIRECT(var) CHOICE(*var, *var, (var))
+/* Use register contents as jump/call target: */
+#define CODEPTR(reg) CHOICE(*reg, *reg, reg)
+
+/* For expressions requiring bracketing
+ * eg. (CRT0_PM | CRT_EM)
+ */
+
+#define EXPR(a) CHOICE([a], (a), [a])
+#define ENOT(a) CHOICE(0!a, ~a, ~a)
+#define EMUL(a,b) CHOICE(a\*b, a*b, a*b)
+#define EDIV(a,b) CHOICE(a\/b, a/b, a/b)
+
+/*
+ * We have to beat the problem of commas within arguments to choice.
+ * eg. choice (add a,b, add b,a) will get argument mismatch. Luckily ANSI
+ * and other known cpp definitions evaluate arguments before substitution
+ * so the following works.
+ */
+#define ARG2(a, b) a,b
+#define ARG3(a,b,c) a,b,c
+
+/* Redefine assembler commands */
+#define AAA CHOICE(aaa, aaa, aaa)
+#define AAD CHOICE(aad, aad, aad)
+#define AAM CHOICE(aam, aam, aam)
+#define AAS CHOICE(aas, aas, aas)
+#define ADC_L(a, b) CHOICE(adcl ARG2(a,b), adcl ARG2(a,b), _LTOG adc ARG2(b,a))
+#define ADC_W(a, b) CHOICE(adcw ARG2(a,b), adcw ARG2(a,b), _WTOG adc ARG2(b,a))
+#define ADC_B(a, b) CHOICE(adcb ARG2(a,b), adcb ARG2(a,b), adcb ARG2(b,a))
+#define ADD_L(a, b) CHOICE(addl ARG2(a,b), addl ARG2(a,b), _LTOG add ARG2(b,a))
+#define ADD_W(a, b) CHOICE(addw ARG2(a,b), addw ARG2(a,b), _WTOG add ARG2(b,a))
+#define ADD_B(a, b) CHOICE(addb ARG2(a,b), addb ARG2(a,b), addb ARG2(b,a))
+#define AND_L(a, b) CHOICE(andl ARG2(a,b), andl ARG2(a,b), _LTOG and ARG2(b,a))
+#define AND_W(a, b) CHOICE(andw ARG2(a,b), andw ARG2(a,b), _WTOG and ARG2(b,a))
+#define AND_B(a, b) CHOICE(andb ARG2(a,b), andb ARG2(a,b), andb ARG2(b,a))
+#define ARPL(a,b) CHOICE(arpl ARG2(a,b), arpl ARG2(a,b), arpl ARG2(b,a))
+#define BOUND_L(a, b) CHOICE(boundl ARG2(a,b), boundl ARG2(b,a), _LTOG bound ARG2(b,a))
+#define BOUND_W(a, b) CHOICE(boundw ARG2(a,b), boundw ARG2(b,a), _WTOG bound ARG2(b,a))
+#define BSF_L(a, b) CHOICE(bsfl ARG2(a,b), bsfl ARG2(a,b), _LTOG bsf ARG2(b,a))
+#define BSF_W(a, b) CHOICE(bsfw ARG2(a,b), bsfw ARG2(a,b), _WTOG bsf ARG2(b,a))
+#define BSR_L(a, b) CHOICE(bsrl ARG2(a,b), bsrl ARG2(a,b), _LTOG bsr ARG2(b,a))
+#define BSR_W(a, b) CHOICE(bsrw ARG2(a,b), bsrw ARG2(a,b), _WTOG bsr ARG2(b,a))
+#define BT_L(a, b) CHOICE(btl ARG2(a,b), btl ARG2(a,b), _LTOG bt ARG2(b,a))
+#define BT_W(a, b) CHOICE(btw ARG2(a,b), btw ARG2(a,b), _WTOG bt ARG2(b,a))
+#define BTC_L(a, b) CHOICE(btcl ARG2(a,b), btcl ARG2(a,b), _LTOG btc ARG2(b,a))
+#define BTC_W(a, b) CHOICE(btcw ARG2(a,b), btcw ARG2(a,b), _WTOG btc ARG2(b,a))
+#define BTR_L(a, b) CHOICE(btrl ARG2(a,b), btrl ARG2(a,b), _LTOG btr ARG2(b,a))
+#define BTR_W(a, b) CHOICE(btrw ARG2(a,b), btrw ARG2(a,b), _WTOG btr ARG2(b,a))
+#define BTS_L(a, b) CHOICE(btsl ARG2(a,b), btsl ARG2(a,b), _LTOG bts ARG2(b,a))
+#define BTS_W(a, b) CHOICE(btsw ARG2(a,b), btsw ARG2(a,b), _WTOG bts ARG2(b,a))
+#define CALL(a) CHOICE(call a, call a, call a)
+#define CALLF(s,a) CHOICE(lcall ARG2(s,a), lcall ARG2(s,a), callf s:a)
+#define CBW CHOICE(cbtw, cbw, cbw)
+#define CWDE CHOICE(cwtd, cwde, cwde)
+#define CLC CHOICE(clc, clc, clc)
+#define CLD CHOICE(cld, cld, cld)
+#define CLI CHOICE(cli, cli, cli)
+#define CLTS CHOICE(clts, clts, clts)
+#define CMC CHOICE(cmc, cmc, cmc)
+#define CMP_L(a, b) CHOICE(cmpl ARG2(a,b), cmpl ARG2(a,b), _LTOG cmp ARG2(b,a))
+#define CMP_W(a, b) CHOICE(cmpw ARG2(a,b), cmpw ARG2(a,b), _WTOG cmp ARG2(b,a))
+#define CMP_B(a, b) CHOICE(cmpb ARG2(a,b), cmpb ARG2(a,b), cmpb ARG2(b,a))
+#define CMPS_L CHOICE(cmpsl, cmpsl, _LTOG cmps)
+#define CMPS_W CHOICE(cmpsw, cmpsw, _WTOG cmps)
+#define CMPS_B CHOICE(cmpsb, cmpsb, cmpsb)
+#define CWD CHOICE(cwtl, cwd, cwd)
+#define CDQ CHOICE(cltd, cdq, cdq)
+#define DAA CHOICE(daa, daa, daa)
+#define DAS CHOICE(das, das, das)
+#define DEC_L(a) CHOICE(decl a, decl a, _LTOG dec a)
+#define DEC_W(a) CHOICE(decw a, decw a, _WTOG dec a)
+#define DEC_B(a) CHOICE(decb a, decb a, decb a)
+#define DIV_L(a) CHOICE(divl a, divl a, div a)
+#define DIV_W(a) CHOICE(divw a, divw a, div a)
+#define DIV_B(a) CHOICE(divb a, divb a, divb a)
+#define ENTER(a,b) CHOICE(enter ARG2(a,b), enter ARG2(a,b), enter ARG2(b,a))
+#define HLT CHOICE(hlt, hlt, hlt)
+#define IDIV_L(a) CHOICE(idivl a, idivl a, _LTOG idiv a)
+#define IDIV_W(a) CHOICE(idivw a, idivw a, _WTOG idiv a)
+#define IDIV_B(a) CHOICE(idivb a, idivb a, idivb a)
+/* More forms than this for imul!! */
+#define IMUL_L(a, b) CHOICE(imull ARG2(a,b), imull ARG2(a,b), _LTOG imul ARG2(b,a))
+#define IMUL_W(a, b) CHOICE(imulw ARG2(a,b), imulw ARG2(a,b), _WTOG imul ARG2(b,a))
+#define IMUL_B(a) CHOICE(imulb a, imulb a, imulb a)
+#define IN_L CHOICE(inl (DX), inl ARG2(DX,EAX), _LTOG in DX)
+#define IN_W CHOICE(inw (DX), inw ARG2(DX,AX), _WTOG in DX)
+#define IN_B CHOICE(inb (DX), inb ARG2(DX,AL), inb DX)
+/* Please AS code writer: use the following ONLY, if you refer to ports<256
+ * directly, but not in IN1_W(DX), for instance, even if IN1_ looks nicer
+ */
+#if defined (sun)
+#define IN1_L(a) CHOICE(inl (a), inl ARG2(a,EAX), _LTOG in a)
+#define IN1_W(a) CHOICE(inw (a), inw ARG2(a,AX), _WTOG in a)
+#define IN1_B(a) CHOICE(inb (a), inb ARG2(a,AL), inb a)
+#else
+#define IN1_L(a) CHOICE(inl a, inl ARG2(a,EAX), _LTOG in a)
+#define IN1_W(a) CHOICE(inw a, inw ARG2(a,AX), _WTOG in a)
+#define IN1_B(a) CHOICE(inb a, inb ARG2(a,AL), inb a)
+#endif
+#define INC_L(a) CHOICE(incl a, incl a, _LTOG inc a)
+#define INC_W(a) CHOICE(incw a, incw a, _WTOG inc a)
+#define INC_B(a) CHOICE(incb a, incb a, incb a)
+#define INS_L CHOICE(insl, insl, _LTOG ins)
+#define INS_W CHOICE(insw, insw, _WTOG ins)
+#define INS_B CHOICE(insb, insb, insb)
+#define INT(a) CHOICE(int a, int a, int a)
+#define INT3 CHOICE(int CONST(3), int3, int CONST(3))
+#define INTO CHOICE(into, into, into)
+#define IRET CHOICE(iret, iret, iret)
+#define IRETD CHOICE(iret, iret, iretd)
+#define JA(a) CHOICE(ja a, ja a, ja a)
+#define JAE(a) CHOICE(jae a, jae a, jae a)
+#define JB(a) CHOICE(jb a, jb a, jb a)
+#define JBE(a) CHOICE(jbe a, jbe a, jbe a)
+#define JC(a) CHOICE(jc a, jc a, jc a)
+#define JE(a) CHOICE(je a, je a, je a)
+#define JG(a) CHOICE(jg a, jg a, jg a)
+#define JGE(a) CHOICE(jge a, jge a, jge a)
+#define JL(a) CHOICE(jl a, jl a, jl a)
+#define JLE(a) CHOICE(jle a, jle a, jle a)
+#define JNA(a) CHOICE(jna a, jna a, jna a)
+#define JNAE(a) CHOICE(jnae a, jnae a, jnae a)
+#define JNB(a) CHOICE(jnb a, jnb a, jnb a)
+#define JNBE(a) CHOICE(jnbe a, jnbe a, jnbe a)
+#define JNC(a) CHOICE(jnc a, jnc a, jnc a)
+#define JNE(a) CHOICE(jne a, jne a, jne a)
+#define JNG(a) CHOICE(jng a, jng a, jng a)
+#define JNGE(a) CHOICE(jnge a, jnge a, jnge a)
+#define JNL(a) CHOICE(jnl a, jnl a, jnl a)
+#define JNLE(a) CHOICE(jnle a, jnle a, jnle a)
+#define JNO(a) CHOICE(jno a, jno a, jno a)
+#define JNP(a) CHOICE(jnp a, jnp a, jnp a)
+#define JNS(a) CHOICE(jns a, jns a, jns a)
+#define JNZ(a) CHOICE(jnz a, jnz a, jnz a)
+#define JO(a) CHOICE(jo a, jo a, jo a)
+#define JP(a) CHOICE(jp a, jp a, jp a)
+#define JPE(a) CHOICE(jpe a, jpe a, jpe a)
+#define JPO(a) CHOICE(jpo a, jpo a, jpo a)
+#define JS(a) CHOICE(js a, js a, js a)
+#define JZ(a) CHOICE(jz a, jz a, jz a)
+#define JMP(a) CHOICE(jmp a, jmp a, jmp a)
+#define JMPF(s,a) CHOICE(ljmp ARG2(s,a), ljmp ARG2(s,a), jmpf s:a)
+#define LAHF CHOICE(lahf, lahf, lahf)
+#if !defined(_REAL_MODE) && !defined(_V86_MODE)
+#define LAR(a, b) CHOICE(lar ARG2(a, b), lar ARG2(a, b), lar ARG2(b, a))
+#endif
+#define LEA_L(a, b) CHOICE(leal ARG2(a,b), leal ARG2(a,b), _LTOG lea ARG2(b,a))
+#define LEA_W(a, b) CHOICE(leaw ARG2(a,b), leaw ARG2(a,b), _WTOG lea ARG2(b,a))
+#define LEAVE CHOICE(leave, leave, leave)
+#define LGDT(a) CHOICE(lgdt a, lgdt a, lgdt a)
+#define LIDT(a) CHOICE(lidt a, lidt a, lidt a)
+#define LDS(a, b) CHOICE(ldsl ARG2(a,b), lds ARG2(a,b), lds ARG2(b,a))
+#define LES(a, b) CHOICE(lesl ARG2(a,b), les ARG2(a,b), les ARG2(b,a))
+#define LFS(a, b) CHOICE(lfsl ARG2(a,b), lfs ARG2(a,b), lfs ARG2(b,a))
+#define LGS(a, b) CHOICE(lgsl ARG2(a,b), lgs ARG2(a,b), lgs ARG2(b,a))
+#define LSS(a, b) CHOICE(lssl ARG2(a,b), lss ARG2(a,b), lss ARG2(b,a))
+#define LLDT(a) CHOICE(lldt a, lldt a, lldt a)
+#define LMSW(a) CHOICE(lmsw a, lmsw a, lmsw a)
+#define LOCK CHOICE(lock, lock, lock)
+#define LODS_L CHOICE(lodsl, lodsl, _LTOG lods)
+#define LODS_W CHOICE(lodsw, lodsw, _WTOG lods)
+#define LODS_B CHOICE(lodsb, lodsb, lodsb)
+#define LOOP(a) CHOICE(loop a, loop a, loop a)
+#define LOOPE(a) CHOICE(loope a, loope a, loope a)
+#define LOOPZ(a) CHOICE(loopz a, loopz a, loopz a)
+#define LOOPNE(a) CHOICE(loopne a, loopne a, loopne a)
+#define LOOPNZ(a) CHOICE(loopnz a, loopnz a, loopnz a)
+#if !defined(_REAL_MODE) && !defined(_V86_MODE)
+#define LSL(a, b) CHOICE(lsl ARG2(a,b), lsl ARG2(a,b), lsl ARG2(b,a))
+#endif
+#define LTR(a) CHOICE(ltr a, ltr a, ltr a)
+#define MOV_SR(a, b) CHOICE(movw ARG2(a,b), mov ARG2(a,b), mov ARG2(b,a))
+#define MOV_L(a, b) CHOICE(movl ARG2(a,b), movl ARG2(a,b), _LTOG mov ARG2(b,a))
+#define MOV_W(a, b) CHOICE(movw ARG2(a,b), movw ARG2(a,b), _WTOG mov ARG2(b,a))
+#define MOV_B(a, b) CHOICE(movb ARG2(a,b), movb ARG2(a,b), movb ARG2(b,a))
+#define MOVS_L CHOICE(movsl, movsl, _LTOG movs)
+#define MOVS_W CHOICE(movsw, movsw, _WTOG movs)
+#define MOVS_B CHOICE(movsb, movsb, movsb)
+#define MOVSX_BL(a, b) CHOICE(movsbl ARG2(a,b), movsbl ARG2(a,b), movsx ARG2(b,a))
+#define MOVSX_BW(a, b) CHOICE(movsbw ARG2(a,b), movsbw ARG2(a,b), movsx ARG2(b,a))
+#define MOVSX_WL(a, b) CHOICE(movswl ARG2(a,b), movswl ARG2(a,b), movsx ARG2(b,a))
+#define MOVZX_BL(a, b) CHOICE(movzbl ARG2(a,b), movzbl ARG2(a,b), movzx ARG2(b,a))
+#define MOVZX_BW(a, b) CHOICE(movzbw ARG2(a,b), movzbw ARG2(a,b), movzx ARG2(b,a))
+#define MOVZX_WL(a, b) CHOICE(movzwl ARG2(a,b), movzwl ARG2(a,b), movzx ARG2(b,a))
+#define MUL_L(a) CHOICE(mull a, mull a, _LTOG mul a)
+#define MUL_W(a) CHOICE(mulw a, mulw a, _WTOG mul a)
+#define MUL_B(a) CHOICE(mulb a, mulb a, mulb a)
+#define NEG_L(a) CHOICE(negl a, negl a, _LTOG neg a)
+#define NEG_W(a) CHOICE(negw a, negw a, _WTOG neg a)
+#define NEG_B(a) CHOICE(negb a, negb a, negb a)
+#define NOP CHOICE(nop, nop, nop)
+#define NOT_L(a) CHOICE(notl a, notl a, _LTOG not a)
+#define NOT_W(a) CHOICE(notw a, notw a, _WTOG not a)
+#define NOT_B(a) CHOICE(notb a, notb a, notb a)
+#define OR_L(a,b) CHOICE(orl ARG2(a,b), orl ARG2(a,b), _LTOG or ARG2(b,a))
+#define OR_W(a,b) CHOICE(orw ARG2(a,b), orw ARG2(a,b), _WTOG or ARG2(b,a))
+#define OR_B(a,b) CHOICE(orb ARG2(a,b), orb ARG2(a,b), orb ARG2(b,a))
+#define OUT_L CHOICE(outl (DX), outl ARG2(EAX,DX), _LTOG out DX)
+#define OUT_W CHOICE(outw (DX), outw ARG2(AX,DX), _WTOG out DX)
+#define OUT_B CHOICE(outb (DX), outb ARG2(AL,DX), outb DX)
+/* Please AS code writer: use the following ONLY, if you refer to ports<256
+ * directly, but not in OUT1_W(DX), for instance, even if OUT1_ looks nicer
+ */
+#define OUT1_L(a) CHOICE(outl (a), outl ARG2(EAX,a), _LTOG out a)
+#define OUT1_W(a) CHOICE(outw (a), outw ARG2(AX,a), _WTOG out a)
+#define OUT1_B(a) CHOICE(outb (a), outb ARG2(AL,a), outb a)
+#define OUTS_L CHOICE(outsl, outsl, _LTOG outs)
+#define OUTS_W CHOICE(outsw, outsw, _WTOG outs)
+#define OUTS_B CHOICE(outsb, outsb, outsb)
+#define POP_SR(a) CHOICE(pop a, pop a, pop a)
+#define POP_L(a) CHOICE(popl a, popl a, _LTOG pop a)
+#define POP_W(a) CHOICE(popw a, popw a, _WTOG pop a)
+#define POPA_L CHOICE(popal, popal, _LTOG popa)
+#define POPA_W CHOICE(popaw, popaw, _WTOG popa)
+#define POPF_L CHOICE(popfl, popfl, _LTOG popf)
+#define POPF_W CHOICE(popfw, popfw, _WTOG popf)
+#define PUSH_SR(a) CHOICE(push a, push a, push a)
+#define PUSH_L(a) CHOICE(pushl a, pushl a, _LTOG push a)
+#define PUSH_W(a) CHOICE(pushw a, pushw a, _WTOG push a)
+#define PUSH_B(a) CHOICE(push a, pushb a, push a)
+#define PUSHA_L CHOICE(pushal, pushal, _LTOG pusha)
+#define PUSHA_W CHOICE(pushaw, pushaw, _WTOG pusha)
+#define PUSHF_L CHOICE(pushfl, pushfl, _LTOG pushf)
+#define PUSHF_W CHOICE(pushfw, pushfw, _WTOG pushf)
+#define RCL_L(a, b) CHOICE(rcll ARG2(a,b), rcll ARG2(a,b), _LTOG rcl ARG2(b,a))
+#define RCL_W(a, b) CHOICE(rclw ARG2(a,b), rclw ARG2(a,b), _WTOG rcl ARG2(b,a))
+#define RCL_B(a, b) CHOICE(rclb ARG2(a,b), rclb ARG2(a,b), rclb ARG2(b,a))
+#define RCR_L(a, b) CHOICE(rcrl ARG2(a,b), rcrl ARG2(a,b), _LTOG rcr ARG2(b,a))
+#define RCR_W(a, b) CHOICE(rcrw ARG2(a,b), rcrw ARG2(a,b), _WTOG rcr ARG2(b,a))
+#define RCR_B(a, b) CHOICE(rcrb ARG2(a,b), rcrb ARG2(a,b), rcrb ARG2(b,a))
+#define ROL_L(a, b) CHOICE(roll ARG2(a,b), roll ARG2(a,b), _LTOG rol ARG2(b,a))
+#define ROL_W(a, b) CHOICE(rolw ARG2(a,b), rolw ARG2(a,b), _WTOG rol ARG2(b,a))
+#define ROL_B(a, b) CHOICE(rolb ARG2(a,b), rolb ARG2(a,b), rolb ARG2(b,a))
+#define ROR_L(a, b) CHOICE(rorl ARG2(a,b), rorl ARG2(a,b), _LTOG ror ARG2(b,a))
+#define ROR_W(a, b) CHOICE(rorw ARG2(a,b), rorw ARG2(a,b), _WTOG ror ARG2(b,a))
+#define ROR_B(a, b) CHOICE(rorb ARG2(a,b), rorb ARG2(a,b), rorb ARG2(b,a))
+#define REP CHOICE(rep ;, rep ;, repe)
+#define REPE CHOICE(repz ;, repe ;, repe)
+#define REPNE CHOICE(repnz ;, repne ;, repne)
+#define REPNZ REPNE
+#define REPZ REPE
+#define RET CHOICE(ret, ret, ret)
+#define SAHF CHOICE(sahf, sahf, sahf)
+#define SAL_L(a, b) CHOICE(sall ARG2(a,b), sall ARG2(a,b), _LTOG sal ARG2(b,a))
+#define SAL_W(a, b) CHOICE(salw ARG2(a,b), salw ARG2(a,b), _WTOG sal ARG2(b,a))
+#define SAL_B(a, b) CHOICE(salb ARG2(a,b), salb ARG2(a,b), salb ARG2(b,a))
+#define SAR_L(a, b) CHOICE(sarl ARG2(a,b), sarl ARG2(a,b), _LTOG sar ARG2(b,a))
+#define SAR_W(a, b) CHOICE(sarw ARG2(a,b), sarw ARG2(a,b), _WTOG sar ARG2(b,a))
+#define SAR_B(a, b) CHOICE(sarb ARG2(a,b), sarb ARG2(a,b), sarb ARG2(b,a))
+#define SBB_L(a, b) CHOICE(sbbl ARG2(a,b), sbbl ARG2(a,b), _LTOG sbb ARG2(b,a))
+#define SBB_W(a, b) CHOICE(sbbw ARG2(a,b), sbbw ARG2(a,b), _WTOG sbb ARG2(b,a))
+#define SBB_B(a, b) CHOICE(sbbb ARG2(a,b), sbbb ARG2(a,b), sbbb ARG2(b,a))
+#define SCAS_L CHOICE(scasl, scasl, _LTOG scas)
+#define SCAS_W CHOICE(scasw, scasw, _WTOG scas)
+#define SCAS_B CHOICE(scasb, scasb, scasb)
+#define SETA(a) CHOICE(seta a, seta a, seta a)
+#define SETAE(a) CHOICE(setae a, setae a, setae a)
+#define SETB(a) CHOICE(setb a, setb a, setb a)
+#define SETBE(a) CHOICE(setbe a, setbe a, setbe a)
+#define SETC(a) CHOICE(setc a, setb a, setb a)
+#define SETE(a) CHOICE(sete a, sete a, sete a)
+#define SETG(a) CHOICE(setg a, setg a, setg a)
+#define SETGE(a) CHOICE(setge a, setge a, setge a)
+#define SETL(a) CHOICE(setl a, setl a, setl a)
+#define SETLE(a) CHOICE(setle a, setle a, setle a)
+#define SETNA(a) CHOICE(setna a, setna a, setna a)
+#define SETNAE(a) CHOICE(setnae a, setnae a, setnae a)
+#define SETNB(a) CHOICE(setnb a, setnb a, setnb a)
+#define SETNBE(a) CHOICE(setnbe a, setnbe a, setnbe a)
+#define SETNC(a) CHOICE(setnc a, setnb a, setnb a)
+#define SETNE(a) CHOICE(setne a, setne a, setne a)
+#define SETNG(a) CHOICE(setng a, setng a, setng a)
+#define SETNGE(a) CHOICE(setnge a, setnge a, setnge a)
+#define SETNL(a) CHOICE(setnl a, setnl a, setnl a)
+#define SETNLE(a) CHOICE(setnle a, setnle a, setnle a)
+#define SETNO(a) CHOICE(setno a, setno a, setno a)
+#define SETNP(a) CHOICE(setnp a, setnp a, setnp a)
+#define SETNS(a) CHOICE(setns a, setns a, setna a)
+#define SETNZ(a) CHOICE(setnz a, setnz a, setnz a)
+#define SETO(a) CHOICE(seto a, seto a, seto a)
+#define SETP(a) CHOICE(setp a, setp a, setp a)
+#define SETPE(a) CHOICE(setpe a, setpe a, setpe a)
+#define SETPO(a) CHOICE(setpo a, setpo a, setpo a)
+#define SETS(a) CHOICE(sets a, sets a, seta a)
+#define SETZ(a) CHOICE(setz a, setz a, setz a)
+#define SGDT(a) CHOICE(sgdt a, sgdt a, sgdt a)
+#define SIDT(a) CHOICE(sidt a, sidt a, sidt a)
+#define SHL_L(a, b) CHOICE(shll ARG2(a,b), shll ARG2(a,b), _LTOG shl ARG2(b,a))
+#define SHL_W(a, b) CHOICE(shlw ARG2(a,b), shlw ARG2(a,b), _WTOG shl ARG2(b,a))
+#define SHL_B(a, b) CHOICE(shlb ARG2(a,b), shlb ARG2(a,b), shlb ARG2(b,a))
+#define SHLD_L(a,b,c) CHOICE(shldl ARG3(a,b,c), shldl ARG3(a,b,c), _LTOG shld ARG3(c,b,a))
+#define SHLD2_L(a,b) CHOICE(shldl ARG2(a,b), shldl ARG3(CL,a,b), _LTOG shld ARG3(b,a,CL))
+#define SHLD_W(a,b,c) CHOICE(shldw ARG3(a,b,c), shldw ARG3(a,b,c), _WTOG shld ARG3(c,b,a))
+#define SHLD2_W(a,b) CHOICE(shldw ARG2(a,b), shldw ARG3(CL,a,b), _WTOG shld ARG3(b,a,CL))
+#define SHR_L(a, b) CHOICE(shrl ARG2(a,b), shrl ARG2(a,b), _LTOG shr ARG2(b,a))
+#define SHR_W(a, b) CHOICE(shrw ARG2(a,b), shrw ARG2(a,b), _WTOG shr ARG2(b,a))
+#define SHR_B(a, b) CHOICE(shrb ARG2(a,b), shrb ARG2(a,b), shrb ARG2(b,a))
+#define SHRD_L(a,b,c) CHOICE(shrdl ARG3(a,b,c), shrdl ARG3(a,b,c), _LTOG shrd ARG3(c,b,a))
+#define SHRD2_L(a,b) CHOICE(shrdl ARG2(a,b), shrdl ARG3(CL,a,b), _LTOG shrd ARG3(b,a,CL))
+#define SHRD_W(a,b,c) CHOICE(shrdw ARG3(a,b,c), shrdw ARG3(a,b,c), _WTOG shrd ARG3(c,b,a))
+#define SHRD2_W(a,b) CHOICE(shrdw ARG2(a,b), shrdw ARG3(CL,a,b), _WTOG shrd ARG3(b,a,CL))
+#define SLDT(a) CHOICE(sldt a, sldt a, sldt a)
+#define SMSW(a) CHOICE(smsw a, smsw a, smsw a)
+#define STC CHOICE(stc, stc, stc)
+#define STD CHOICE(std, std, std)
+#define STI CHOICE(sti, sti, sti)
+#define STOS_L CHOICE(stosl, stosl, _LTOG stos)
+#define STOS_W CHOICE(stosw, stosw, _WTOG stos)
+#define STOS_B CHOICE(stosb, stosb, stosb)
+#define STR(a) CHOICE(str a, str a, str a)
+#define SUB_L(a, b) CHOICE(subl ARG2(a,b), subl ARG2(a,b), _LTOG sub ARG2(b,a))
+#define SUB_W(a, b) CHOICE(subw ARG2(a,b), subw ARG2(a,b), _WTOG sub ARG2(b,a))
+#define SUB_B(a, b) CHOICE(subb ARG2(a,b), subb ARG2(a,b), subb ARG2(b,a))
+#define TEST_L(a, b) CHOICE(testl ARG2(a,b), testl ARG2(a,b), _LTOG test ARG2(b,a))
+#define TEST_W(a, b) CHOICE(testw ARG2(a,b), testw ARG2(a,b), _WTOG test ARG2(b,a))
+#define TEST_B(a, b) CHOICE(testb ARG2(a,b), testb ARG2(a,b), testb ARG2(b,a))
+#define VERR(a) CHOICE(verr a, verr a, verr a)
+#define VERW(a) CHOICE(verw a, verw a, verw a)
+#define WAIT CHOICE(wait, wait, wait)
+#define XCHG_L(a, b) CHOICE(xchgl ARG2(a,b), xchgl ARG2(a,b), _LTOG xchg ARG2(b,a))
+#define XCHG_W(a, b) CHOICE(xchgw ARG2(a,b), xchgw ARG2(a,b), _WTOG xchg ARG2(b,a))
+#define XCHG_B(a, b) CHOICE(xchgb ARG2(a,b), xchgb ARG2(a,b), xchgb ARG2(b,a))
+#define XLAT CHOICE(xlat, xlat, xlat)
+#define XOR_L(a, b) CHOICE(xorl ARG2(a,b), xorl ARG2(a,b), _LTOG xor ARG2(b,a))
+#define XOR_W(a, b) CHOICE(xorw ARG2(a,b), xorw ARG2(a,b), _WTOG xor ARG2(b,a))
+#define XOR_B(a, b) CHOICE(xorb ARG2(a,b), xorb ARG2(a,b), xorb ARG2(b,a))
+
+
+/* Floating Point Instructions */
+#define F2XM1 CHOICE(f2xm1, f2xm1, f2xm1)
+#define FABS CHOICE(fabs, fabs, fabs)
+#define FADD_D(a) CHOICE(faddl a, faddl a, faddd a)
+#define FADD_S(a) CHOICE(fadds a, fadds a, fadds a)
+#define FADD2(a, b) CHOICE(fadd ARG2(a,b), fadd ARG2(a,b), fadd ARG2(b,a))
+#define FADDP(a, b) CHOICE(faddp ARG2(a,b), faddp ARG2(a,b), faddp ARG2(b,a))
+#define FIADD_L(a) CHOICE(fiaddl a, fiaddl a, fiaddl a)
+#define FIADD_W(a) CHOICE(fiadd a, fiadds a, fiadds a)
+#define FBLD(a) CHOICE(fbld a, fbld a, fbld a)
+#define FBSTP(a) CHOICE(fbstp a, fbstp a, fbstp a)
+#define FCHS CHOICE(fchs, fchs, fchs)
+#define FCLEX CHOICE(fclex, wait; fnclex, wait; fclex)
+#define FNCLEX CHOICE(fnclex, fnclex, fclex)
+#define FCOM(a) CHOICE(fcom a, fcom a, fcom a)
+#define FCOM_D(a) CHOICE(fcoml a, fcoml a, fcomd a)
+#define FCOM_S(a) CHOICE(fcoms a, fcoms a, fcoms a)
+#define FCOMP(a) CHOICE(fcomp a, fcomp a, fcomp a)
+#define FCOMP_D(a) CHOICE(fcompl a, fcompl a, fcompd a)
+#define FCOMP_S(a) CHOICE(fcomps a, fcomps a, fcomps a)
+#define FCOMPP CHOICE(fcompp, fcompp, fcompp)
+#define FCOS CHOICE(fcos, fcos, fcos)
+#define FDECSTP CHOICE(fdecstp, fdecstp, fdecstp)
+#define FDIV_D(a) CHOICE(fdivl a, fdivl a, fdivd a)
+#define FDIV_S(a) CHOICE(fdivs a, fdivs a, fdivs a)
+#define FDIV2(a, b) CHOICE(fdiv ARG2(a,b), fdiv ARG2(a,b), fdiv ARG2(b,a))
+#define FDIVP(a, b) CHOICE(fdivp ARG2(a,b), fdivp ARG2(a,b), fdivp ARG2(b,a))
+#define FIDIV_L(a) CHOICE(fidivl a, fidivl a, fidivl a)
+#define FIDIV_W(a) CHOICE(fidiv a, fidivs a, fidivs a)
+#define FDIVR_D(a) CHOICE(fdivrl a, fdivrl a, fdivrd a)
+#define FDIVR_S(a) CHOICE(fdivrs a, fdivrs a, fdivrs a)
+#define FDIVR2(a, b) CHOICE(fdivr ARG2(a,b), fdivr ARG2(a,b), fdivr ARG2(b,a))
+#define FDIVRP(a, b) CHOICE(fdivrp ARG2(a,b), fdivrp ARG2(a,b), fdivrp ARG2(b,a))
+#define FIDIVR_L(a) CHOICE(fidivrl a, fidivrl a, fidivrl a)
+#define FIDIVR_W(a) CHOICE(fidivr a, fidivrs a, fidivrs a)
+#define FFREE(a) CHOICE(ffree a, ffree a, ffree a)
+#define FICOM_L(a) CHOICE(ficoml a, ficoml a, ficoml a)
+#define FICOM_W(a) CHOICE(ficom a, ficoms a, ficoms a)
+#define FICOMP_L(a) CHOICE(ficompl a, ficompl a, ficompl a)
+#define FICOMP_W(a) CHOICE(ficomp a, ficomps a, ficomps a)
+#define FILD_Q(a) CHOICE(fildll a, fildq a, fildq a)
+#define FILD_L(a) CHOICE(fildl a, fildl a, fildl a)
+#define FILD_W(a) CHOICE(fild a, filds a, filds a)
+#define FINCSTP CHOICE(fincstp, fincstp, fincstp)
+#define FINIT CHOICE(finit, wait; fninit, wait; finit)
+#define FNINIT CHOICE(fninit, fninit, finit)
+#define FIST_L(a) CHOICE(fistl a, fistl a, fistl a)
+#define FIST_W(a) CHOICE(fist a, fists a, fists a)
+#define FISTP_Q(a) CHOICE(fistpll a, fistpq a, fistpq a)
+#define FISTP_L(a) CHOICE(fistpl a, fistpl a, fistpl a)
+#define FISTP_W(a) CHOICE(fistp a, fistps a, fistps a)
+#define FLD_X(a) CHOICE(fldt a, fldt a, fldx a) /* 80 bit data type! */
+#define FLD_D(a) CHOICE(fldl a, fldl a, fldd a)
+#define FLD_S(a) CHOICE(flds a, flds a, flds a)
+#define FLD1 CHOICE(fld1, fld1, fld1)
+#define FLDL2T CHOICE(fldl2t, fldl2t, fldl2t)
+#define FLDL2E CHOICE(fldl2e, fldl2e, fldl2e)
+#define FLDPI CHOICE(fldpi, fldpi, fldpi)
+#define FLDLG2 CHOICE(fldlg2, fldlg2, fldlg2)
+#define FLDLN2 CHOICE(fldln2, fldln2, fldln2)
+#define FLDZ CHOICE(fldz, fldz, fldz)
+#define FLDCW(a) CHOICE(fldcw a, fldcw a, fldcw a)
+#define FLDENV(a) CHOICE(fldenv a, fldenv a, fldenv a)
+#define FMUL_S(a) CHOICE(fmuls a, fmuls a, fmuls a)
+#define FMUL_D(a) CHOICE(fmull a, fmull a, fmuld a)
+#define FMUL2(a, b) CHOICE(fmul ARG2(a,b), fmul ARG2(a,b), fmul ARG2(b,a))
+#define FMULP(a, b) CHOICE(fmulp ARG2(a,b), fmulp ARG2(a,b), fmulp ARG2(b,a))
+#define FIMUL_L(a) CHOICE(fimull a, fimull a, fimull a)
+#define FIMUL_W(a) CHOICE(fimul a, fimuls a, fimuls a)
+#define FNOP CHOICE(fnop, fnop, fnop)
+#define FPATAN CHOICE(fpatan, fpatan, fpatan)
+#define FPREM CHOICE(fprem, fprem, fprem)
+#define FPREM1 CHOICE(fprem1, fprem1, fprem1)
+#define FPTAN CHOICE(fptan, fptan, fptan)
+#define FRNDINT CHOICE(frndint, frndint, frndint)
+#define FRSTOR(a) CHOICE(frstor a, frstor a, frstor a)
+#define FSAVE(a) CHOICE(fsave a, wait; fnsave a, wait; fsave a)
+#define FNSAVE(a) CHOICE(fnsave a, fnsave a, fsave a)
+#define FSCALE CHOICE(fscale, fscale, fscale)
+#define FSIN CHOICE(fsin, fsin, fsin)
+#define FSINCOS CHOICE(fsincos, fsincos, fsincos)
+#define FSQRT CHOICE(fsqrt, fsqrt, fsqrt)
+#define FST_D(a) CHOICE(fstl a, fstl a, fstd a)
+#define FST_S(a) CHOICE(fsts a, fsts a, fsts a)
+#define FSTP_X(a) CHOICE(fstpt a, fstpt a, fstpx a)
+#define FSTP_D(a) CHOICE(fstpl a, fstpl a, fstpd a)
+#define FSTP_S(a) CHOICE(fstps a, fstps a, fstps a)
+#define FSTCW(a) CHOICE(fstcw a, wait; fnstcw a, wait; fstcw a)
+#define FNSTCW(a) CHOICE(fnstcw a, fnstcw a, fstcw a)
+#define FSTENV(a) CHOICE(fstenv a, wait; fnstenv a, fstenv a)
+#define FNSTENV(a) CHOICE(fnstenv a, fnstenv a, fstenv a)
+#define FSTSW(a) CHOICE(fstsw a, wait; fnstsw a, wait; fstsw a)
+#define FNSTSW(a) CHOICE(fnstsw a, fnstsw a, fstsw a)
+#define FSUB_S(a) CHOICE(fsubs a, fsubs a, fsubs a)
+#define FSUB_D(a) CHOICE(fsubl a, fsubl a, fsubd a)
+#define FSUB2(a, b) CHOICE(fsub ARG2(a,b), fsub ARG2(a,b), fsub ARG2(b,a))
+#define FSUBP(a, b) CHOICE(fsubp ARG2(a,b), fsubp ARG2(a,b), fsubp ARG2(b,a))
+#define FISUB_L(a) CHOICE(fisubl a, fisubl a, fisubl a)
+#define FISUB_W(a) CHOICE(fisub a, fisubs a, fisubs a)
+#define FSUBR_S(a) CHOICE(fsubrs a, fsubrs a, fsubrs a)
+#define FSUBR_D(a) CHOICE(fsubrl a, fsubrl a, fsubrd a)
+#define FSUBR2(a, b) CHOICE(fsubr ARG2(a,b), fsubr ARG2(a,b), fsubr ARG2(b,a))
+#define FSUBRP(a, b) CHOICE(fsubrp ARG2(a,b), fsubrp ARG2(a,b), fsubrp ARG2(b,a))
+#define FISUBR_L(a) CHOICE(fisubrl a, fisubrl a, fisubrl a)
+#define FISUBR_W(a) CHOICE(fisubr a, fisubrs a, fisubrs a)
+#define FTST CHOICE(ftst, ftst, ftst)
+#define FUCOM(a) CHOICE(fucom a, fucom a, fucom a)
+#define FUCOMP(a) CHOICE(fucomp a, fucomp a, fucomp a)
+#define FUCOMPP CHOICE(fucompp, fucompp, fucompp)
+#define FWAIT CHOICE(wait, wait, wait)
+#define FXAM CHOICE(fxam, fxam, fxam)
+#define FXCH(a) CHOICE(fxch a, fxch a, fxch a)
+#define FXTRACT CHOICE(fxtract, fxtract, fxtract)
+#define FYL2X CHOICE(fyl2x, fyl2x, fyl2x)
+#define FYL2XP1 CHOICE(fyl2xp1, fyl2xp1, fyl2xp1)
+
+#endif /* __ASSYNTAX_H__ */
diff --git a/hw/xfree86/os-support/bsd/bsd_VTsw.c b/hw/xfree86/os-support/bsd/bsd_VTsw.c
new file mode 100644
index 000000000..13e78ad34
--- /dev/null
+++ b/hw/xfree86/os-support/bsd/bsd_VTsw.c
@@ -0,0 +1,92 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_VTsw.c,v 3.5 1996/12/23 06:49:35 dawes Exp $ */
+/*
+ * Derived from VTsw_usl.c which is
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ * by S_ren Schmidt (sos@login.dkuug.dk)
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of David Wexelblat not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. David Wexelblat makes no representations
+ * about the suitability of this software for any purpose. It is provided
+ * "as is" without express or implied warranty.
+ *
+ * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: bsd_VTsw.c,v 1.3 2000/08/17 19:51:21 cpqbld Exp $ */
+
+#include "X.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+/*
+ * Handle the VT-switching interface for OSs that use USL-style ioctl()s
+ * (the bsd, sysv, sco, and linux subdirs).
+ */
+
+/*
+ * This function is the signal handler for the VT-switching signal. It
+ * is only referenced inside the OS-support layer.
+ */
+void xf86VTRequest(sig)
+int sig;
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = TRUE;
+ }
+#endif
+ return;
+}
+
+Bool xf86VTSwitchPending()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ return(xf86Info.vtRequestsPending ? TRUE : FALSE);
+ }
+#endif
+ return FALSE;
+}
+
+Bool xf86VTSwitchAway()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0)
+ return(FALSE);
+ else
+ return(TRUE);
+ }
+#endif
+ return FALSE;
+}
+
+Bool xf86VTSwitchTo()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) {
+ xf86Info.vtRequestsPending = FALSE;
+ if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
+ return(FALSE);
+ else
+ return(TRUE);
+ }
+#endif
+ return(TRUE);
+}
diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c
new file mode 100644
index 000000000..961fd0eac
--- /dev/null
+++ b/hw/xfree86/os-support/bsd/bsd_init.c
@@ -0,0 +1,780 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c,v 3.8.2.1 1998/02/06 22:36:49 hohndel Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: bsd_init.c,v 1.3 2000/08/17 19:51:21 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+extern void xf86VTRequest(
+#if NeedFunctionPrototypes
+ int
+#endif
+);
+
+static Bool KeepTty = FALSE;
+static int devConsoleFd = -1;
+static int VTnum = -1;
+static int initialVT = -1;
+
+#ifdef PCCONS_SUPPORT
+/* Stock 0.1 386bsd pccons console driver interface */
+#ifndef __OpenBSD__
+# define PCCONS_CONSOLE_DEV1 "/dev/ttyv0"
+#else
+# define PCCONS_CONSOLE_DEV1 "/dev/ttyC0"
+#endif
+#define PCCONS_CONSOLE_DEV2 "/dev/vga"
+#define PCCONS_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#ifdef CODRV_SUPPORT
+/* Holger Veit's codrv console driver */
+#define CODRV_CONSOLE_DEV "/dev/kbd"
+#define CODRV_CONSOLE_MODE O_RDONLY|O_NDELAY
+#endif
+
+#ifdef SYSCONS_SUPPORT
+/* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */
+#define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0"
+#define SYSCONS_CONSOLE_DEV2 "/dev/vga"
+#define SYSCONS_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#ifdef PCVT_SUPPORT
+/* Hellmuth Michaelis' pcvt driver */
+#ifndef __OpenBSD__
+# define PCVT_CONSOLE_DEV "/dev/ttyv0"
+#else
+# define PCVT_CONSOLE_DEV "/dev/ttyC0"
+#endif
+#define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY
+#endif
+
+#define CHECK_DRIVER_MSG \
+ "Check your kernel's console driver configuration and /dev entries"
+
+static char *supported_drivers[] = {
+#ifdef PCCONS_SUPPORT
+ "pccons (with X support)",
+#endif
+#ifdef CODRV_SUPPORT
+ "codrv",
+#endif
+#ifdef SYSCONS_SUPPORT
+ "syscons",
+#endif
+#ifdef PCVT_SUPPORT
+ "pcvt",
+#endif
+};
+
+
+/*
+ * Functions to probe for the existance of a supported console driver.
+ * Any function returns either a valid file descriptor (driver probed
+ * succesfully), -1 (driver not found), or uses FatalError() if the
+ * driver was found but proved to not support the required mode to run
+ * an X server.
+ */
+
+typedef int (*xf86ConsOpen_t)(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+#ifdef PCCONS_SUPPORT
+static int xf86OpenPccons(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+#endif /* PCCONS_SUPPORT */
+
+#ifdef CODRV_SUPPORT
+static int xf86OpenCodrv(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+#endif /* CODRV_SUPPORT */
+
+#ifdef SYSCONS_SUPPORT
+static int xf86OpenSyscons(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+#endif /* SYSCONS_SUPPORT */
+
+#ifdef PCVT_SUPPORT
+static int xf86OpenPcvt(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+#endif /* PCVT_SUPPORT */
+
+/*
+ * The sequence of the driver probes is important; start with the
+ * driver that is best distinguishable, and end with the most generic
+ * driver. (Otherwise, pcvt would also probe as syscons, and either
+ * pcvt or syscons might succesfully probe as pccons. Only codrv is
+ * at its own.)
+ */
+static xf86ConsOpen_t xf86ConsTab[] = {
+#ifdef PCVT_SUPPORT
+ xf86OpenPcvt,
+#endif
+#ifdef CODRV_SUPPORT
+ xf86OpenCodrv,
+#endif
+#ifdef SYSCONS_SUPPORT
+ xf86OpenSyscons,
+#endif
+#ifdef PCCONS_SUPPORT
+ xf86OpenPccons,
+#endif
+ (xf86ConsOpen_t)NULL
+};
+
+
+void
+xf86OpenConsole()
+{
+ int i, fd;
+#ifdef CODRV_SUPPORT
+ int onoff;
+#endif
+ xf86ConsOpen_t *driver;
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ vtmode_t vtmode;
+#endif
+
+ if (serverGeneration == 1)
+ {
+ /* check if we are run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be running with root "
+ "permissions\n"
+ "You should be using Xwrapper to start the server or xdm.\n"
+ "We strongly advise against making the server SUID root!\n");
+ }
+
+ if (!KeepTty)
+ {
+ /*
+ * detaching the controlling tty solves problems of kbd character
+ * loss. This is not interesting for CO driver, because it is
+ * exclusive.
+ */
+ setpgrp(0, getpid());
+ if ((i = open("/dev/tty",O_RDWR)) >= 0)
+ {
+ ioctl(i,TIOCNOTTY,(char *)0);
+ close(i);
+ }
+ }
+
+ /* detect which driver we are running on */
+ for (driver = xf86ConsTab; *driver; driver++)
+ {
+ if((fd = (*driver)()) >= 0)
+ break;
+ }
+
+ /* Check that a supported console driver was found */
+ if (fd < 0)
+ {
+ char cons_drivers[80] = {0, };
+ for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++)
+ {
+ if (i)
+ {
+ strcat(cons_drivers, ", ");
+ }
+ strcat(cons_drivers, supported_drivers[i]);
+ }
+ FatalError(
+ "%s: No console driver found\n\tSupported drivers: %s\n\t%s\n",
+ "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG);
+ }
+ fclose(stdin);
+ xf86Info.consoleFd = fd;
+ xf86Info.screenFd = fd;
+
+ xf86Config(FALSE); /* Read XF86Config */
+
+ switch (xf86Info.consType)
+ {
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ onoff = X_MODE_ON;
+ if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE, &onoff) < 0)
+ {
+ FatalError("%s: CONSOLE_X_MODE ON failed (%s)\n%s\n",
+ "xf86OpenConsole", strerror(errno),
+ CHECK_DRIVER_MSG);
+ }
+ if (xf86Info.consType == CODRV01X)
+ ioctl(xf86Info.consoleFd, VGATAKECTRL, 0);
+ break;
+#endif
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0)
+ {
+ FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s\n",
+ "xf86OpenConsole", strerror(errno),
+ CHECK_DRIVER_MSG);
+ }
+ /*
+ * Hack to prevent keyboard hanging when syslogd closes
+ * /dev/console
+ */
+ if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0)
+ {
+ ErrorF("Warning: couldn't open /dev/console (%s)\n",
+ strerror(errno));
+ }
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ /*
+ * First activate the #1 VT. This is a hack to allow a server
+ * to be started while another one is active. There should be
+ * a better way.
+ */
+ if (initialVT != 1) {
+
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ sleep(1);
+ }
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ vtmode.mode = VT_PROCESS;
+ vtmode.relsig = SIGUSR1;
+ vtmode.acqsig = SIGUSR1;
+ vtmode.frsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0)
+ {
+ FatalError("xf86OpenConsole: KDENABIO failed (%s)\n",
+ strerror(errno));
+ }
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ {
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
+ }
+ break;
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ }
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)
+ {
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ }
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ }
+ return;
+}
+
+
+#ifdef PCCONS_SUPPORT
+
+static int
+xf86OpenPccons()
+{
+ int fd = -1;
+
+ if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0))
+ >= 0 ||
+ (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0))
+ >= 0)
+ {
+ if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0)
+ {
+ FatalError(
+ "%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s\n",
+ "xf86OpenPccons",
+ strerror(errno),
+ "Was expecting pccons driver with X support",
+ CHECK_DRIVER_MSG);
+ }
+ xf86Info.consType = PCCONS;
+ if (xf86Verbose)
+ {
+ ErrorF("Using pccons driver with X support\n");
+ }
+ }
+ return fd;
+}
+
+#endif /* PCCONS_SUPPORT */
+
+#ifdef SYSCONS_SUPPORT
+
+static int
+xf86OpenSyscons()
+{
+ int fd = -1;
+ vtmode_t vtmode;
+ char vtname[12];
+ struct stat status;
+ long syscons_version;
+
+ /* Check for syscons */
+ if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0
+ || (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0)
+ {
+ if (ioctl(fd, VT_GETMODE, &vtmode) >= 0)
+ {
+ /* Get syscons version */
+ if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0)
+ {
+ syscons_version = 0;
+ }
+
+ xf86Info.vtno = VTnum;
+
+#ifdef VT_GETACTIVE
+ if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
+ initialVT = -1;
+#endif
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * For old syscons versions (<0x100), VT_OPENQRY returns
+ * the current VT rather than the next free VT. In this
+ * case, the server gets started on the current VT instead
+ * of the next free VT.
+ */
+
+#if 0
+ /* check for the fixed VT_OPENQRY */
+ if (syscons_version >= 0x100)
+ {
+#endif
+ if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
+ {
+ /* No free VTs */
+ xf86Info.vtno = -1;
+ }
+#if 0
+ }
+#endif
+
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * All VTs are in use. If initialVT was found, use it.
+ * Otherwise, if stdin is a VT, use that one.
+ */
+ if (initialVT != -1)
+ {
+ xf86Info.vtno = initialVT;
+ }
+ else if ((fstat(0, &status) >= 0)
+ && S_ISCHR(status.st_mode)
+ && (ioctl(0, VT_GETMODE, &vtmode) >= 0))
+ {
+ /* stdin is a VT */
+ xf86Info.vtno = minor(status.st_rdev) + 1;
+ }
+ else
+ {
+ if (syscons_version >= 0x100)
+ {
+ FatalError("%s: Cannot find a free VT\n",
+ "xf86OpenSyscons");
+ }
+ /* Should no longer reach here */
+ FatalError("%s: %s %s\n\t%s %s\n",
+ "xf86OpenSyscons",
+ "syscons versions prior to 1.0 require",
+ "either the",
+ "server's stdin be a VT",
+ "or the use of the vtxx server option");
+ }
+ }
+ }
+
+ close(fd);
+#ifndef __OpenBSD__
+ sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1);
+#else
+ sprintf(vtname, "/dev/ttyC%01x", xf86Info.vtno - 1);
+#endif
+ if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0)
+ {
+ FatalError("xf86OpenSyscons: Cannot open %s (%s)\n",
+ vtname, strerror(errno));
+ }
+ if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenSyscons: VT_GETMODE failed\n");
+ }
+ xf86Info.consType = SYSCONS;
+ if (xf86Verbose)
+ {
+ ErrorF("Using syscons driver with X support");
+ if (syscons_version >= 0x100)
+ {
+ ErrorF(" (version %d.%d)\n", syscons_version >> 8,
+ syscons_version & 0xFF);
+ }
+ else
+ {
+ ErrorF(" (version 0.x)\n");
+ }
+ ErrorF("(using VT number %d)\n\n", xf86Info.vtno);
+ }
+ }
+ else
+ {
+ /* VT_GETMODE failed, probably not syscons */
+ close(fd);
+ fd = -1;
+ }
+ }
+ return fd;
+}
+
+#endif /* SYSCONS_SUPPORT */
+
+
+#ifdef CODRV_SUPPORT
+
+static int
+xf86OpenCodrv()
+{
+ int fd = -1, onoff = X_MODE_OFF;
+ struct oldconsinfo ci;
+
+ if ((fd = open(CODRV_CONSOLE_DEV, CODRV_CONSOLE_MODE, 0)) >= 0)
+ {
+ if (ioctl(fd, CONSOLE_X_MODE, &onoff) < 0)
+ {
+ FatalError("%s: CONSOLE_X_MODE on %s failed (%s)\n%s\n%s\n",
+ "xf86OpenCodrv",
+ CODRV_CONSOLE_DEV, strerror(errno),
+ "Was expecting codrv driver",
+ CHECK_DRIVER_MSG);
+ }
+ xf86Info.consType = CODRV011;
+ }
+ else
+ {
+ if (errno == EBUSY)
+ {
+ FatalError("xf86OpenCodrv: %s is already in use (codrv)\n",
+ CODRV_CONSOLE_DEV);
+ }
+ }
+ else
+ {
+ fd = -1;
+ }
+
+ if(fd >= 0)
+ {
+ /*
+ * analyse whether this kernel has sufficient capabilities for
+ * this xserver, if not don't proceed: it won't work. Also
+ * find out which codrv version.
+ */
+#define NECESSARY (CONS_HASKBD|CONS_HASKEYNUM|CONS_HASPX386)
+ if ((ioctl(fd, OLDCONSGINFO, &ci) < 0 ||
+ (ci.info1 & NECESSARY) != NECESSARY))
+ {
+ FatalError("xf86OpenCodrv: %s\n%s\n%s\n",
+ "This Xserver has detected the codrv driver, but your",
+ "kernel doesn't appear to have the required facilities",
+ CHECK_DRIVER_MSG);
+ }
+ /* Check for codrv 0.1.2 or later */
+ if (ci.info1 & CONS_CODRV2)
+ {
+ xf86Info.consType = CODRV01X;
+ if (xf86Verbose)
+ {
+ ErrorF("Using codrv 0.1.2 (or later)\n");
+ }
+ }
+ else
+ {
+ if (xf86Verbose)
+ {
+ ErrorF("Using codrv 0.1.1\n");
+ }
+ }
+#undef NECESSARY
+ }
+
+ return fd;
+}
+#endif /* CODRV_SUPPORT */
+
+#ifdef PCVT_SUPPORT
+
+static int
+xf86OpenPcvt()
+{
+ /* This looks much like syscons, since pcvt is API compatible */
+ int fd = -1;
+ vtmode_t vtmode;
+ char vtname[12];
+ struct stat status;
+ struct pcvtid pcvt_version;
+
+ if ((fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0)) >= 0)
+ {
+ if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0)
+ {
+ if(ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("%s: VT_GETMODE failed\n%s%s\n%s\n",
+ "xf86OpenPcvt",
+ "Found pcvt driver but X11 seems to be",
+ " not supported.", CHECK_DRIVER_MSG);
+ }
+
+ xf86Info.vtno = VTnum;
+
+ if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
+ initialVT = -1;
+
+ if (xf86Info.vtno == -1)
+ {
+ if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
+ {
+ /* No free VTs */
+ xf86Info.vtno = -1;
+ }
+
+ if (xf86Info.vtno == -1)
+ {
+ /*
+ * All VTs are in use. If initialVT was found, use it.
+ * Otherwise, if stdin is a VT, use that one.
+ */
+ if (initialVT != -1)
+ {
+ xf86Info.vtno = initialVT;
+ }
+ else if ((fstat(0, &status) >= 0)
+ && S_ISCHR(status.st_mode)
+ && (ioctl(0, VT_GETMODE, &vtmode) >= 0))
+ {
+ /* stdin is a VT */
+ xf86Info.vtno = minor(status.st_rdev) + 1;
+ }
+ else
+ {
+ FatalError("%s: Cannot find a free VT\n",
+ "xf86OpenPcvt");
+ }
+ }
+ }
+
+ close(fd);
+#ifndef __OpenBSD__
+ sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1);
+#else
+ sprintf(vtname, "/dev/ttyC%01x", xf86Info.vtno - 1);
+#endif
+ if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0)
+ {
+ FatalError("xf86OpenPcvt: Cannot open %s (%s)\n",
+ vtname, strerror(errno));
+ }
+ if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
+ {
+ FatalError("xf86OpenPcvt: VT_GETMODE failed\n");
+ }
+ xf86Info.consType = PCVT;
+ if (xf86Verbose)
+ {
+ ErrorF("Using pcvt driver (version %d.%d)\n",
+ pcvt_version.rmajor, pcvt_version.rminor);
+ }
+ }
+ else
+ {
+ /* Not pcvt */
+ close(fd);
+ fd = -1;
+ }
+ }
+ return fd;
+}
+
+#endif /* PCVT_SUPPORT */
+
+
+void
+xf86CloseConsole()
+{
+#if defined(CODRV_SUPPORT)
+ int onoff;
+#endif
+#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ struct vt_mode VT;
+#endif
+
+ switch (xf86Info.consType)
+ {
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ onoff = X_MODE_OFF;
+ if (xf86Info.consType == CODRV01X)
+ {
+ ioctl (xf86Info.consoleFd, VGAGIVECTRL, 0);
+ }
+ ioctl (xf86Info.consoleFd, CONSOLE_X_MODE, &onoff);
+ break;
+#endif /* CODRV_SUPPORT */
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0);
+ break;
+#endif /* PCCONS_SUPPORT */
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode */
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */
+ }
+ if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0)
+ {
+ xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)\n",
+ strerror(errno));
+ }
+ if (initialVT != -1)
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT);
+ break;
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ }
+
+ if (xf86Info.screenFd != xf86Info.consoleFd)
+ {
+ close(xf86Info.screenFd);
+ close(xf86Info.consoleFd);
+ if ((xf86Info.consoleFd = open("/dev/console",O_RDONLY,0)) <0)
+ {
+ xf86FatalError("xf86CloseConsole: Cannot open /dev/console (%s)\n",
+ strerror(errno));
+ }
+ }
+ close(xf86Info.consoleFd);
+ if (devConsoleFd >= 0)
+ close(devConsoleFd);
+ return;
+}
+
+int
+xf86ProcessArgument (argc, argv, i)
+int argc;
+char *argv[];
+int i;
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0 ||
+ VTnum < 1 || VTnum > 12)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ return(0);
+}
+
+void
+xf86UseMsg()
+{
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ ErrorF("vtXX use the specified VT number (1-12)\n");
+#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/hw/xfree86/os-support/bsd/bsd_io.c b/hw/xfree86/os-support/bsd/bsd_io.c
new file mode 100644
index 000000000..6741ba978
--- /dev/null
+++ b/hw/xfree86/os-support/bsd/bsd_io.c
@@ -0,0 +1,257 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_io.c,v 3.12 1996/12/23 06:49:37 dawes Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Dawes <dawes@physics.su.oz.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Rich Murphey and
+ * David Dawes make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID DAWES BE LIABLE FOR
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: bsd_io.c,v 1.3 2000/08/17 19:51:21 cpqbld Exp $ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+void xf86SoundKbdBell(loudness, pitch, duration)
+int loudness;
+int pitch;
+int duration;
+{
+ if (loudness && pitch)
+ {
+#ifdef CODRV_SUPPORT
+ struct kbd_sound s;
+#endif
+#ifdef PCCONS_SUPPORT
+ int data[2];
+#endif
+
+ switch (xf86Info.consType) {
+
+#ifdef PCCONS_SUPPORT
+ case PCCONS:
+ data[0] = pitch;
+ data[1] = (duration * loudness) / 50;
+ ioctl(xf86Info.consoleFd, CONSOLE_X_BELL, data);
+ break;
+#endif
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ s.pitch = pitch;
+ s.duration = (duration * loudness) / 50;
+ ioctl(xf86Info.consoleFd, KBDSETBELL, &s);
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration*loudness/50)<<16));
+ break;
+#endif
+ }
+ }
+}
+
+void xf86SetKbdLeds(leds)
+int leds;
+{
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ leds = (leds&0x01)<<2 | leds&0x02 | (leds&0x04)>>2;
+ ioctl(xf86Info.consoleFd, KBDSLEDS, &leds);
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+ break;
+#endif
+ }
+}
+
+int xf86GetKbdLeds()
+{
+ int leds = 0;
+
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ ioctl(xf86Info.consoleFd, KBDGLEDS, &leds);
+ leds = (leds&0x01)<<2 | leds&0x02 | (leds&0x04)>>2;
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ break;
+#endif
+ }
+ return(leds);
+}
+
+#if NeedFunctionPrototypes
+void xf86SetKbdRepeat(char rad)
+#else
+void xf86SetKbdRepeat(rad)
+char rad;
+#endif
+{
+ switch (xf86Info.consType) {
+
+ case PCCONS:
+ break;
+#ifdef CODRV_SUPPORT
+ case CODRV011:
+ case CODRV01X:
+ ioctl(xf86Info.consoleFd, KBDSTPMAT, &rad);
+ break;
+#endif
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSETRAD, rad);
+ break;
+#endif
+ }
+}
+
+static struct termio kbdtty;
+
+void xf86KbdInit()
+{
+ switch (xf86Info.consType) {
+
+ case CODRV011:
+ case CODRV01X:
+ break;
+#if defined(PCCONS_SUPPORT) || defined(SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case PCCONS:
+ case SYSCONS:
+ case PCVT:
+ tcgetattr(xf86Info.consoleFd, &kbdtty);
+ break;
+#endif
+ }
+}
+
+int xf86KbdOn()
+{
+ struct termios nTty;
+
+ switch (xf86Info.consType) {
+
+ case CODRV011:
+ case CODRV01X:
+ break;
+
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ case SYSCONS:
+ case PCCONS:
+ case PCVT:
+ nTty = kbdtty;
+ nTty.c_iflag = IGNPAR | IGNBRK;
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME] = 0;
+ nTty.c_cc[VMIN] = 1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW);
+#endif
+ break;
+#endif
+ }
+ return(xf86Info.consoleFd);
+}
+
+int xf86KbdOff()
+{
+ switch (xf86Info.consType) {
+
+ case CODRV011:
+ case CODRV01X:
+ break;
+
+#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
+ case SYSCONS:
+ case PCVT:
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_XLATE);
+ /* FALL THROUGH */
+#endif
+#if defined(SYSCONS_SUPPORT) || defined(PCCONS_SUPPORT) || defined(PCVT_SUPPORT)
+ case PCCONS:
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ break;
+#endif
+ }
+ return(xf86Info.consoleFd);
+}
+
+void xf86MouseInit(mouse)
+MouseDevPtr mouse;
+{
+ return;
+}
+
+int xf86MouseOn(mouse)
+MouseDevPtr mouse;
+{
+ if ((mouse->mseFd = open(mouse->mseDevice, O_RDWR | O_NDELAY)) < 0)
+ {
+ if (xf86AllowMouseOpenFail) {
+ ErrorF("Cannot open mouse (%s) - Continuing...\n",
+ strerror(errno));
+ return(-2);
+ }
+ FatalError("Cannot open mouse (%s)\n", strerror(errno));
+ }
+
+ xf86SetupMouse(mouse);
+
+ /* Flush any pending input */
+ tcflush(mouse->mseFd, TCIFLUSH);
+
+ return(mouse->mseFd);
+}
diff --git a/hw/xfree86/os-support/bsd/bsd_jstk.c b/hw/xfree86/os-support/bsd/bsd_jstk.c
new file mode 100644
index 000000000..ab4a31420
--- /dev/null
+++ b/hw/xfree86/os-support/bsd/bsd_jstk.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright 1995 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* Modified for FreeBSD by David Dawes <dawes@XFree86.org> */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_jstk.c,v 3.2 1996/01/12 14:34:41 dawes Exp $ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <machine/joystick.h>
+#include <fcntl.h>
+
+#define JS_RETURN sizeof(struct joystick)
+
+extern int errno;
+extern int xf86Verbose;
+
+/***********************************************************************
+ *
+ * xf86JoystickOn --
+ *
+ * open the device and init timeout according to the device value.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOn(char * name, int *timeout, int *centerX, int *centerY)
+{
+ int status;
+ int changed = 0;
+ int timeinmicros;
+ struct joystick js;
+
+#ifdef DEBUG
+ ErrorF("xf86JoystickOn: %s\n", name);
+#endif
+
+ if ((status = open(name, O_RDWR | O_NDELAY)) < 0)
+ {
+ ErrorF("xf86JoystickOn: Cannot open joystick '%s' (%s)\n", name,
+ strerror(errno));
+ return -1;
+ }
+
+ if (*timeout <= 0) {
+ /* Use the current setting */
+ ioctl(status, JOY_GETTIMEOUT, &timeinmicros);
+ *timeout = timeinmicros / 1000;
+ if (*timeout == 0)
+ *timeout = 1;
+ changed = 1;
+ }
+ /* Maximum allowed timeout in the FreeBSD driver is 10ms */
+ if (*timeout > 10) {
+ *timeout = 10;
+ changed = 1;
+ }
+
+ if (changed && xf86Verbose)
+ ErrorF("(--) Joystick: timeout value = %d\n", *timeout);
+
+ timeinmicros = *timeout * 1000;
+
+ /* Assume the joystick is centred when this is called */
+ read(status, &js, JS_RETURN);
+ if (*centerX < 0) {
+ *centerX = js.x;
+ if (xf86Verbose) {
+ ErrorF("(--) Joystick: CenterX set to %d\n", *centerX);
+ }
+ }
+ if (*centerY < 0) {
+ *centerY = js.y;
+ if (xf86Verbose) {
+ ErrorF("(--) Joystick: CenterY set to %d\n", *centerY);
+ }
+ }
+
+ return status;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickInit --
+ *
+ * called when X device is initialized.
+ *
+ ***********************************************************************
+ */
+
+void
+xf86JoystickInit()
+{
+ return;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickOff --
+ *
+ * close the handle.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOff(fd, doclose)
+int *fd;
+int doclose;
+{
+ int oldfd;
+
+ if (((oldfd = *fd) >= 0) && doclose) {
+ close(*fd);
+ *fd = -1;
+ }
+ return oldfd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickGetState --
+ *
+ * return the state of buttons and the position of the joystick.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickGetState(fd, x, y, buttons)
+int fd;
+int *x;
+int *y;
+int *buttons;
+{
+ struct joystick js;
+ int status;
+
+ status = read(fd, &js, JS_RETURN);
+
+ if (status != JS_RETURN)
+ {
+ Error("Joystick read");
+ return 0;
+ }
+
+ *x = js.x;
+ *y = js.y;
+ *buttons = js.b1 | (js.b2 << 1);
+#ifdef DEBUG
+ ErrorF("xf86JoystickGetState: x = %d, y = %d, buttons = %d\n", *x, *y,
+ *buttons);
+#endif
+
+ return 1;
+}
+
+/* end of bsd_jstk.c */
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
new file mode 100644
index 000000000..1c0791abb
--- /dev/null
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -0,0 +1,274 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 3.7.2.3 1998/02/06 22:36:51 hohndel Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: lnx_init.c,v 1.3 2000/08/17 19:51:23 cpqbld Exp $ */
+
+#include "X.h"
+#include "Xmd.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86.h"
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+#ifdef USE_DEV_FB
+extern char *getenv(const char *);
+#include <linux/fb.h>
+char *fb_dev_name;
+#endif
+
+static Bool KeepTty = FALSE;
+static int VTnum = -1;
+static int activeVT = -1;
+
+extern void xf86VTRequest(
+#if NeedFunctionPrototypes
+ int
+#endif
+);
+
+void xf86OpenConsole()
+{
+ int i, fd;
+ struct vt_mode VT;
+ char vtname[11];
+ struct vt_stat vts;
+#ifdef USE_DEV_FB
+ struct fb_var_screeninfo var;
+ int fbfd;
+#endif
+
+ if (serverGeneration == 1)
+ {
+ /* check if we're run with euid==0 */
+ if (geteuid() != 0)
+ {
+ FatalError("xf86OpenConsole: Server must be running with root "
+ "permissions\n"
+ "You should be using Xwrapper to start the server or xdm.\n"
+ "We strongly advise against making the server SUID root!\n");
+ }
+
+ /*
+ * setup the virtual terminal manager
+ */
+ if (VTnum != -1)
+ {
+ xf86Info.vtno = VTnum;
+ }
+ else
+ {
+ if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0)
+ {
+ FatalError(
+ "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n",
+ strerror(errno));
+ }
+ if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
+ (xf86Info.vtno == -1))
+ {
+ FatalError("xf86OpenConsole: Cannot find a free VT\n");
+ }
+ close(fd);
+ }
+
+#ifdef USE_DEV_FB
+ fb_dev_name=getenv("FRAMEBUFFER");
+ if (!fb_dev_name)
+ fb_dev_name="/dev/fb0current";
+ if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0)
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ fb_dev_name, strerror(errno));
+ if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var))
+ FatalError("xf86OpenConsole: Unable to get screen info\n");
+#endif
+ ErrorF("(using VT number %d)\n\n", xf86Info.vtno);
+
+ sprintf(vtname,"/dev/tty%d",xf86Info.vtno); /* /dev/tty1-64 */
+
+ xf86Config(FALSE); /* Read XF86Config */
+
+ if (!KeepTty)
+ {
+ setpgrp();
+ }
+
+ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0)
+ {
+ FatalError("xf86OpenConsole: Cannot open %s (%s)\n",
+ vtname, strerror(errno));
+ }
+
+ /* change ownership of the vt */
+ chown(vtname, getuid(), getgid());
+
+ /*
+ * the current VT device we're running on is not "console", we want
+ * to grab all consoles too
+ *
+ * Why is this needed?
+ */
+ chown("/dev/tty0", getuid(), getgid());
+
+ /*
+ * Linux doesn't switch to an active vt after the last close of a vt,
+ * so we do this ourselves by remembering which is active now.
+ */
+ if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0)
+ {
+ activeVT = vts.v_active;
+ }
+
+ if (!KeepTty)
+ {
+ /*
+ * Detach from the controlling tty to avoid char loss
+ */
+ if ((i = open("/dev/tty",O_RDWR)) >= 0)
+ {
+ ioctl(i, TIOCNOTTY, 0);
+ close(i);
+ }
+ }
+
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
+ {
+ FatalError ("xf86OpenConsole: VT_GETMODE failed\n");
+ }
+
+ signal(SIGUSR1, xf86VTRequest);
+
+ VT.mode = VT_PROCESS;
+ VT.relsig = SIGUSR1;
+ VT.acqsig = SIGUSR1;
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ {
+ FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
+ {
+ FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
+ }
+#ifdef USE_DEV_FB
+ /* copy info to new console */
+ var.yoffset=0;
+ var.xoffset=0;
+ if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var))
+ FatalError("Unable to set screen info\n");
+ close(fbfd);
+#endif
+ }
+ else
+ {
+ /* serverGeneration != 1 */
+ /*
+ * now get the VT
+ */
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_ACTIVATE failed\n");
+ }
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
+ {
+ ErrorF("xf86OpenConsole: VT_WAITACTIVE failed\n");
+ }
+ }
+ return;
+}
+
+void xf86CloseConsole()
+{
+ struct vt_mode VT;
+
+#if 0
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
+ ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
+#endif
+ ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
+ if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
+ {
+ VT.mode = VT_AUTO;
+ ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
+ }
+ /*
+ * Perform a switch back to the active VT when we were started
+ */
+ if (activeVT >= 0)
+ {
+ ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT);
+ activeVT = -1;
+ }
+ close(xf86Info.consoleFd); /* make the vt-manager happy */
+ return;
+}
+
+int xf86ProcessArgument (argc, argv, i)
+int argc;
+char *argv[];
+int i;
+{
+ /*
+ * Keep server from detaching from controlling tty. This is useful
+ * when debugging (so the server can receive keyboard signals.
+ */
+ if (!strcmp(argv[i], "-keeptty"))
+ {
+ KeepTty = TRUE;
+ return(1);
+ }
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ {
+ UseMsg();
+ VTnum = -1;
+ return(0);
+ }
+ return(1);
+ }
+ return(0);
+}
+
+void xf86UseMsg()
+{
+ ErrorF("vtXX use the specified VT number\n");
+ ErrorF("-keeptty ");
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ return;
+}
diff --git a/hw/xfree86/os-support/linux/lnx_io.c b/hw/xfree86/os-support/linux/lnx_io.c
new file mode 100644
index 000000000..57a2979c5
--- /dev/null
+++ b/hw/xfree86/os-support/linux/lnx_io.c
@@ -0,0 +1,136 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c,v 3.3 1996/12/23 06:50:01 dawes Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Dawes <dawes@physics.su.oz.au>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Dawes
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Dawes make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID DAWES BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: lnx_io.c,v 1.3 2000/08/17 19:51:23 cpqbld Exp $ */
+
+#define NEED_EVENTS
+#include "X.h"
+#include "Xproto.h"
+#include "inputstr.h"
+#include "scrnintstr.h"
+
+#include "compiler.h"
+
+#include "xf86Procs.h"
+#include "xf86_OSlib.h"
+
+void xf86SoundKbdBell(loudness, pitch, duration)
+int loudness;
+int pitch;
+int duration;
+{
+ if (loudness && pitch)
+ {
+ ioctl(xf86Info.consoleFd, KDMKTONE,
+ ((1193190 / pitch) & 0xffff) |
+ (((unsigned long)duration *
+ loudness / 50) << 16));
+ }
+}
+
+void xf86SetKbdLeds(leds)
+int leds;
+{
+ ioctl(xf86Info.consoleFd, KDSETLED, leds);
+}
+
+int xf86GetKbdLeds()
+{
+ int leds;
+
+ ioctl(xf86Info.consoleFd, KDGETLED, &leds);
+ return(leds);
+}
+
+#if NeedFunctionPrototypes
+void xf86SetKbdRepeat(char rad)
+#else
+void xf86SetKbdRepeat(rad)
+char rad;
+#endif
+{
+ return;
+}
+
+static int kbdtrans;
+static struct termios kbdtty;
+
+void xf86KbdInit()
+{
+ ioctl (xf86Info.consoleFd, KDGKBMODE, &kbdtrans);
+ tcgetattr (xf86Info.consoleFd, &kbdtty);
+}
+
+int xf86KbdOn()
+{
+ struct termios nTty;
+
+ ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW);
+ nTty = kbdtty;
+ nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
+ nTty.c_oflag = 0;
+ nTty.c_cflag = CREAD | CS8;
+ nTty.c_lflag = 0;
+ nTty.c_cc[VTIME]=0;
+ nTty.c_cc[VMIN]=1;
+ cfsetispeed(&nTty, 9600);
+ cfsetospeed(&nTty, 9600);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
+ return(xf86Info.consoleFd);
+}
+
+int xf86KbdOff()
+{
+ ioctl(xf86Info.consoleFd, KDSKBMODE, kbdtrans);
+ tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty);
+ return(xf86Info.consoleFd);
+}
+
+void xf86MouseInit(mouse)
+MouseDevPtr mouse;
+{
+ return;
+}
+
+int xf86MouseOn(mouse)
+MouseDevPtr mouse;
+{
+ if ((mouse->mseFd = open(mouse->mseDevice, O_RDWR | O_NDELAY)) < 0)
+ {
+ if (xf86AllowMouseOpenFail) {
+ ErrorF("Cannot open mouse (%s) - Continuing...\n",
+ strerror(errno));
+ return(-2);
+ }
+ FatalError("Cannot open mouse (%s)\n", strerror(errno));
+ }
+
+ xf86SetupMouse(mouse);
+
+ /* Flush any pending input */
+ tcflush(mouse->mseFd, TCIFLUSH);
+
+ return(mouse->mseFd);
+}
diff --git a/hw/xfree86/os-support/linux/lnx_jstk.c b/hw/xfree86/os-support/linux/lnx_jstk.c
new file mode 100644
index 000000000..ea308c159
--- /dev/null
+++ b/hw/xfree86/os-support/linux/lnx_jstk.c
@@ -0,0 +1,173 @@
+/* $Xorg: lnx_jstk.c,v 1.3 2000/08/17 19:51:23 cpqbld Exp $ */
+/* Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp */
+/*
+ * Copyright 1995 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Frederic Lepied not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Frederic Lepied makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c,v 3.6 1996/12/23 06:50:02 dawes Exp $ */
+
+static const char rcs_id[] = "$Xorg: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp";
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#define inline __inline__
+#include <linux/joystick.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+extern int errno;
+
+/***********************************************************************
+ *
+ * xf86JoystickOn --
+ *
+ * open the device and init timeout according to the device value.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY)
+{
+ int fd;
+ struct JS_DATA_TYPE js;
+ extern int xf86Verbose;
+
+#ifdef DEBUG
+ ErrorF("xf86JoystickOn %s\n", name);
+#endif
+
+ if ((fd = open(name, O_RDWR | O_NDELAY)) < 0)
+ {
+ ErrorF("Cannot open joystick '%s' (%s)\n", name,
+ strerror(errno));
+ return -1;
+ }
+
+ if (*timeout == 0) {
+ if (ioctl (fd, JS_GET_TIMELIMIT, timeout) == -1) {
+ Error("joystick JS_GET_TIMELIMIT ioctl");
+ }
+ else {
+ if (xf86Verbose) {
+ ErrorF("(--) Joystick: timeout value = %d\n", *timeout);
+ }
+ }
+ }
+ else {
+ if (ioctl(fd, JS_SET_TIMELIMIT, timeout) == -1) {
+ Error("joystick JS_SET_TIMELIMIT ioctl");
+ }
+ }
+
+ /* Assume the joystick is centred when this is called */
+ read(fd, &js, JS_RETURN);
+ if (*centerX < 0) {
+ *centerX = js.x;
+ if (xf86Verbose) {
+ ErrorF("(--) Joystick: CenterX set to %d\n", *centerX);
+ }
+ }
+ if (*centerY < 0) {
+ *centerY = js.y;
+ if (xf86Verbose) {
+ ErrorF("(--) Joystick: CenterY set to %d\n", *centerY);
+ }
+ }
+
+ return fd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickInit --
+ *
+ * called when X device is initialized.
+ *
+ ***********************************************************************
+ */
+
+void
+xf86JoystickInit()
+{
+ return;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickOff --
+ *
+ * close the handle.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickOff(fd, doclose)
+int *fd;
+int doclose;
+{
+ int oldfd;
+
+ if (((oldfd = *fd) >= 0) && doclose) {
+ close(*fd);
+ *fd = -1;
+ }
+ return oldfd;
+}
+
+/***********************************************************************
+ *
+ * xf86JoystickGetState --
+ *
+ * return the state of buttons and the position of the joystick.
+ *
+ ***********************************************************************
+ */
+
+int
+xf86JoystickGetState(fd, x, y, buttons)
+int fd;
+int *x;
+int *y;
+int *buttons;
+{
+ struct JS_DATA_TYPE js;
+ int status;
+
+ status = read(fd, &js, JS_RETURN);
+
+ if (status != JS_RETURN)
+ {
+ Error("Joystick read");
+ return 0;
+ }
+
+ *x = js.x;
+ *y = js.y;
+ *buttons = js.buttons;
+
+ return 1;
+}
+
+/* end of lnx_jstk.c */
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
new file mode 100644
index 000000000..a29db8251
--- /dev/null
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -0,0 +1,634 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 3.13.2.1 1997/05/11 05:04:25 dawes Exp $ */
+/*
+ * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission. Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* $Xorg: lnx_video.c,v 1.3 2000/08/17 19:51:23 cpqbld Exp $ */
+
+#include "X.h"
+#include "input.h"
+#include "scrnintstr.h"
+
+#include "xf86.h"
+#include "xf86Priv.h"
+#include "xf86_OSlib.h"
+
+#ifdef __alpha__
+
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme.
+ *
+ * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
+ */
+
+#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
+#define SPARSE (5)
+#define isJensen (1)
+#else
+#define isJensen (!_bus_base())
+#define SPARSE (7)
+#endif
+
+#define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base())
+#define JENSEN_SHIFT(x) (isJensen ? ((long)x<<SPARSE) : (long)x)
+#else
+#define BUS_BASE 0
+#define JENSEN_SHIFT(x) (x)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section */
+/***************************************************************************/
+
+/*
+ * Unfortunatly mmap without MAP_FIXED only works the first time :-(
+ * This is now fixed in pl13 ALPHA, but still seems to have problems.
+ */
+#undef ONLY_MMAP_FIXED_WORKS
+
+#ifdef ONLY_MMAP_FIXED_WORKS
+static pointer AllocAddress[MAXSCREENS][NUM_REGIONS];
+#endif
+
+#if 0
+static struct xf86memMap {
+ int offset;
+ int memSize;
+} xf86memMaps[MAXSCREENS];
+#endif
+
+pointer xf86MapVidMem(ScreenNum, Region, Base, Size)
+int ScreenNum;
+int Region;
+pointer Base;
+unsigned long Size;
+{
+ pointer base;
+ int fd;
+
+#ifdef ONLY_MMAP_FIXED_WORKS
+#ifdef __alpha__
+ FatalError("xf86MapVidMem: Unexpected code for Alpha (pagesize=8k!)\n");
+#endif
+ AllocAddress[ScreenNum][Region] = (pointer)xalloc(Size + 0x1000);
+ if (AllocAddress[ScreenNum][Region] == NULL)
+ {
+ FatalError("xf86MapVidMem: can't alloc framebuffer space\n");
+ }
+ base = (pointer)(((unsigned int)AllocAddress[ScreenNum][Region]
+ & ~0xFFF) + 0x1000);
+ if ((fd = open("/dev/mem", O_RDWR)) < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open /dev/mem (%s)\n",
+ strerror(errno));
+ }
+ base = (pointer)mmap((caddr_t)base, Size, PROT_READ|PROT_WRITE,
+ MAP_FIXED|MAP_SHARED, fd, (off_t)Base);
+#else
+ if ((fd = open("/dev/mem", O_RDWR)) < 0)
+ {
+ FatalError("xf86MapVidMem: failed to open /dev/mem (%s)\n",
+ strerror(errno));
+ }
+ /* This requirers linux-0.99.pl10 or above */
+ base = (pointer)mmap((caddr_t)0, JENSEN_SHIFT(Size),
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED, fd,
+ (off_t)(JENSEN_SHIFT((off_t)Base) + BUS_BASE));
+#endif
+ close(fd);
+ if ((long)base == -1)
+ {
+ FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n",
+ strerror(errno));
+ }
+#if 0
+ xf86memMaps[ScreenNum].offset = (int) Base;
+ xf86memMaps[ScreenNum].memSize = Size;
+#endif