~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/i740/i740_cursor.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/**************************************************************************
 
3
 
 
4
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 
5
All Rights Reserved.
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a
 
8
copy of this software and associated documentation files (the
 
9
"Software"), to deal in the Software without restriction, including
 
10
without limitation the rights to use, copy, modify, merge, publish,
 
11
distribute, sub license, and/or sell copies of the Software, and to
 
12
permit persons to whom the Software is furnished to do so, subject to
 
13
the following conditions:
 
14
 
 
15
The above copyright notice and this permission notice (including the
 
16
next paragraph) shall be included in all copies or substantial portions
 
17
of the Software.
 
18
 
 
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 
22
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 
23
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 
24
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 
25
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
26
 
 
27
**************************************************************************/
 
28
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/i740/i740_cursor.c,v 1.5 2002/10/21 13:32:58 alanh Exp $ */
 
29
 
 
30
/*
 
31
 * Authors:
 
32
 *   Daryll Strauss <daryll@precisioninsight.com>
 
33
 *
 
34
 */
 
35
 
 
36
#include "xf86.h"
 
37
#include "xf86_OSproc.h"
 
38
#include "xf86_ansic.h"
 
39
#include "compiler.h"
 
40
 
 
41
#include "xf86fbman.h"
 
42
 
 
43
#include "vgaHW.h"
 
44
#include "xf86xv.h"
 
45
#include "i740.h"
 
46
 
 
47
static void I740LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
 
48
static void I740ShowCursor(ScrnInfoPtr pScrn);
 
49
static void I740HideCursor(ScrnInfoPtr pScrn);
 
50
static void I740SetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
 
51
static void I740SetCursorColors(ScrnInfoPtr pScrn, int bg, int fb);
 
52
static Bool I740UseHWCursor(ScreenPtr pScrn, CursorPtr pCurs);
 
53
 
 
54
Bool
 
55
I740CursorInit(ScreenPtr pScreen)
 
56
{
 
57
  ScrnInfoPtr pScrn;
 
58
  I740Ptr pI740;
 
59
  xf86CursorInfoPtr infoPtr;
 
60
  FBAreaPtr fbarea;
 
61
 
 
62
  pScrn = xf86Screens[pScreen->myNum];
 
63
  pI740 = I740PTR(pScrn);
 
64
  pI740->CursorInfoRec = infoPtr = xf86CreateCursorInfoRec();
 
65
  if (!infoPtr) return FALSE;
 
66
 
 
67
  infoPtr->MaxWidth = 64;
 
68
  infoPtr->MaxHeight = 64;
 
69
  infoPtr->Flags =  HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
 
70
    HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
 
71
    HARDWARE_CURSOR_INVERT_MASK |
 
72
    HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK |
 
73
    HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
 
74
    HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64;
 
75
 
 
76
  infoPtr->SetCursorColors = I740SetCursorColors;
 
77
  infoPtr->SetCursorPosition = I740SetCursorPosition;
 
78
  infoPtr->LoadCursorImage = I740LoadCursorImage;
 
79
  infoPtr->HideCursor = I740HideCursor;
 
80
  infoPtr->ShowCursor = I740ShowCursor;
 
81
  infoPtr->UseHWCursor = I740UseHWCursor;
 
82
 
 
83
/*
 
84
 * Allocate a region the full width and tall enough
 
85
 * that at least 6K of video memory is consumed.
 
86
 * Then use a 1 kilobyte piece that is 4K byte aligned
 
87
 * within that region. KAO.
 
88
 */
 
89
  fbarea = xf86AllocateOffscreenArea(pScreen, 
 
90
                                pScrn->displayWidth,
 
91
                                ((6*1024)/(pScrn->displayWidth*pI740->cpp))+1,
 
92
                                0,0,0,0);
 
93
  if (fbarea == NULL) {
 
94
    pI740->CursorStart=0;
 
95
    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 
 
96
               "Hardware cursor disabled due to failure allocating offscreen memory.\n");
 
97
  }
 
98
  else {
 
99
    pI740->CursorStart = ((((fbarea->box.x1 + pScrn->displayWidth * fbarea->box.y1) * pI740->cpp)+4096)&0xfff000);
 
100
  }
 
101
  /*
 
102
   * Perhaps move the cursor to the beginning of the frame buffer
 
103
   * so that it never fails?
 
104
   */
 
105
  if (pI740->CursorStart>4*1024*1024) {
 
106
    pI740->CursorStart=0;
 
107
    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, 
 
108
               "Disabling hardware cursor due to large framebuffer\n");
 
109
  }
 
110
  return xf86InitCursor(pScreen, infoPtr);
 
111
}
 
112
 
 
113
static Bool
 
114
I740UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) {
 
115
  ScrnInfoPtr pScrn;
 
116
  I740Ptr pI740;
 
117
 
 
118
  pScrn = xf86Screens[pScreen->myNum];
 
119
  pI740 = I740PTR(pScrn);
 
120
  if (pScrn->currentMode->Flags&V_DBLSCAN)
 
121
    return FALSE;
 
122
  if (!pI740->CursorStart) return FALSE;
 
123
  return TRUE;
 
124
}
 
125
 
 
126
static void
 
127
I740LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) {
 
128
  I740Ptr pI740;
 
129
  int x, y;
 
130
  CARD8 *pcurs;
 
131
 
 
132
  pI740 = I740PTR(pScrn);
 
133
  pcurs = (CARD8 *)(pI740->FbBase + pI740->CursorStart);
 
134
  for (y = 0; y < 64; y++) {
 
135
    for (x = 0; x < 64 / 4; x++) {
 
136
      *pcurs++ = *src++;
 
137
    }
 
138
  }
 
139
}
 
140
 
 
141
static void
 
142
I740SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) {
 
143
  I740Ptr pI740;
 
144
  int flag;
 
145
 
 
146
  pI740 = I740PTR(pScrn);
 
147
  if (x >= 0) flag = CURSOR_X_POS;
 
148
  else {
 
149
    flag = CURSOR_X_NEG;
 
150
    x=-x;
 
151
  }
 
152
  pI740->writeControl(pI740, XRX, CURSOR_X_LO, x&0xFF);
 
153
  pI740->writeControl(pI740, XRX, CURSOR_X_HI, (((x >> 8) & 0x07) | flag));
 
154
 
 
155
  if (y >= 0) flag = CURSOR_Y_POS;
 
156
  else {
 
157
    flag = CURSOR_Y_NEG;
 
158
    y=-y;
 
159
  }
 
160
  pI740->writeControl(pI740, XRX, CURSOR_Y_LO, y&0xFF);
 
161
  pI740->writeControl(pI740, XRX, CURSOR_Y_HI, (((y >> 8) & 0x07) | flag));
 
162
}
 
163
 
 
164
static void
 
165
I740ShowCursor(ScrnInfoPtr pScrn) {
 
166
  I740Ptr pI740;
 
167
  unsigned char tmp;
 
168
 
 
169
  pI740 = I740PTR(pScrn);
 
170
  pI740->writeControl(pI740, XRX, CURSOR_BASEADDR_LO, 
 
171
                      (pI740->CursorStart & 0x0000F000) >> 8);
 
172
  pI740->writeControl(pI740, XRX, CURSOR_BASEADDR_HI,
 
173
                      (pI740->CursorStart & 0x003F0000) >> 16);
 
174
  pI740->writeControl(pI740, XRX, CURSOR_CONTROL,
 
175
                      CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C);
 
176
 
 
177
  tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
 
178
  tmp |= HW_CURSOR_ENABLE;
 
179
  pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
 
180
}
 
181
 
 
182
static void
 
183
I740HideCursor(ScrnInfoPtr pScrn) {
 
184
  unsigned char tmp;
 
185
  I740Ptr pI740;
 
186
 
 
187
  pI740 = I740PTR(pScrn);
 
188
  tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
 
189
  tmp &= ~HW_CURSOR_ENABLE;
 
190
  pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
 
191
}
 
192
 
 
193
static void
 
194
I740SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) {
 
195
  int tmp;
 
196
  I740Ptr pI740;
 
197
 
 
198
  pI740 = I740PTR(pScrn);
 
199
  tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
 
200
  tmp |= EXTENDED_PALETTE;
 
201
  pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
 
202
 
 
203
  pI740->writeStandard(pI740, DACMASK, 0xFF);
 
204
  pI740->writeStandard(pI740, DACWX, 0x04);
 
205
 
 
206
  pI740->writeStandard(pI740, DACDATA, (bg & 0x00FF0000) >> 16);
 
207
  pI740->writeStandard(pI740, DACDATA, (bg & 0x0000FF00) >> 8);
 
208
  pI740->writeStandard(pI740, DACDATA, (bg & 0x000000FF));
 
209
 
 
210
  pI740->writeStandard(pI740, DACDATA, (fg & 0x00FF0000) >> 16);
 
211
  pI740->writeStandard(pI740, DACDATA, (fg & 0x0000FF00) >> 8);
 
212
  pI740->writeStandard(pI740, DACDATA, (fg & 0x000000FF));
 
213
 
 
214
  tmp=pI740->readControl(pI740, XRX, PIXPIPE_CONFIG_0);
 
215
  tmp &= ~EXTENDED_PALETTE;
 
216
  pI740->writeControl(pI740, XRX, PIXPIPE_CONFIG_0, tmp);
 
217
}
 
218
 
 
219
 
 
220