home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Server / gdz.tbl.ms < prev    next >
Encoding:
Text File  |  1991-07-27  |  33.8 KB  |  882 lines

  1. .de Ip
  2. .IP \(bu 3
  3. ..
  4. .\"    These macros should select a typewriter font if you have one.
  5. .de LS
  6. .KS
  7. .DS
  8. .ft C
  9. ..
  10. .de LE
  11. .ft P
  12. .DE
  13. .KE
  14. ..
  15. .TL
  16. Godzilla's Guide to Porting the X V11 Sample Server
  17. .sp
  18. March 1, 1988
  19. .sp
  20. Updated for R4: April 12, 1990
  21. .AU
  22. David S. H. Rosenthal
  23. .AI
  24. Sun Microsystems
  25. .AU
  26. Adam R. de Boor
  27. .AI
  28. University of California at Berkeley
  29. .AU
  30. edits by Bob Scheifler
  31. .AI
  32. Massachusetts Institute of Technology
  33. .AU
  34. Updated for R4 by Keith Packard
  35. .AI
  36. MIT X Consortium
  37. .AB
  38. .LP
  39. For hackers in a hurry,  here's how to do a quick-and-dirty port of the
  40. X V11 sample server to memory-mapped monochrome & color frame buffers.
  41. The authors disclaim responsibility for damage to the environment during
  42. this process.
  43. .AE
  44. .QP
  45. ``Did I \- ?''
  46. .QP
  47. ``I told you you could,''  [Obi-Wan] Kenobi informed him with pleasure.
  48. ``Once you start to trust your inner self,  there'll be no stopping you.''
  49. .DS C
  50. Star Wars,  \fIGeorge Lucas\fP
  51. .DE
  52. .sp 2
  53. .DS C
  54. Copyright \(co 1987 by Sun Microsystems, Inc.\s-2\u1\d\s0
  55. .DE
  56. .DS C
  57. Copyright \(co 1990 by the Massachusetts Institute of Technology\s-2\u1\d\s0
  58. .DE
  59. .FS
  60. 1.  Permission to use, copy, modify, distribute and sell this document for
  61. any purpose and without fee is hereby granted, provided that the above
  62. copyright notice and this permission notice appear in all copies, and that
  63. the names of Sun Microsystems, Inc.  and M.I.T. not be used in advertising
  64. or publicity pertaining to distribution of the software without specific,
  65. written prior permission.  Sun Microsystems, Inc. and M.I.T. make no
  66. representations about the suitability of the software described herein for
  67. any purpose.  It is provided "as is" without express or implied warranty.
  68. .FE
  69. .sp 2
  70. .NH
  71. Introduction
  72. .LP
  73. In two independent efforts,  we ported the first alpha release of X V11
  74. to monochrome Sun hardware.  The results of these efforts were merged together,
  75. incorporated into the second alpha release,  and delivered to MIT for
  76. distribution.
  77. We went on to port the second alpha release to a number of Sun 8-bit
  78. memory-mapped color displays,  and we contributed this code to the beta
  79. releases.
  80. .LP
  81. With future releases, the internal structure of the server changed, and
  82. porting efforts have to be modified as well.  No attempt has been made to
  83. isolate the porting efforts from the changes between various versions of the
  84. server.  This document focuses on Release 4 of the MIT Sample Server.
  85. .LP
  86. Based on this experience, we present a guide for others attempting to port X
  87. V11.  Our goal is to enable them to get the server up and functional as
  88. expeditiously as possible.  We address only ``initial'' ports, using the
  89. \fIserver/ddx/mfb\fP, \fIserver/ddx/cfb\fP and \fIserver/ddx/mi\fP code to
  90. drive a dumb memory frame buffer.
  91. .LP
  92. It is possible to port X V11 to dumb frame buffers very quickly,
  93. even without a detailed understanding of the internals of the server.  We
  94. give instructions on how to do this,  and then go on to cover some of the
  95. internals that will be important in doing a more complex port,  and in
  96. performance tuning.
  97. We do \fInot\fP cover the following areas in detail:
  98. .Ip
  99. Porting to operating systems other than 4.2 or 4.3 BSD.
  100. .Ip
  101. Driving ``intelligent'' display hardware.
  102. .Ip
  103. Supporting input devices other than the mouse and keyboard.
  104. .Ip
  105. Performance tuning the system.
  106. .LP
  107. This document refers to the fourth full X V11 distribution from the MIT X
  108. Consortium.
  109. .NH
  110. Raw Materials
  111. .LP
  112. The server source code is organised into a number of directories:
  113. .IP ddx 8
  114. The code for driving displays,  keyboards,  mice,  and other peripherals.
  115. .IP dix 8
  116. The machine independent code implementing the protocol interpreter and
  117. resource managers.
  118. .IP include 8
  119. The \fI.h\fP files defining the machine independent data structures for the
  120. server.
  121. .IP os 8
  122. The code implementing the server's file and inter-process I/O,  which
  123. depends on the operating system.
  124. .LP
  125. In the \fBddx\fP directory,  there are the following directories:
  126. .IP mfb 8
  127. The ``monochrome frame buffer'' driver.  This is intended to be a machine independent
  128. driver for 1-bit deep memory mapped displays.
  129. .IP mi 8
  130. The ``machine independent'' driver.  This is intended to be a machine
  131. independent (but slightly incomplete) driver for \fIany\fP frame buffer.
  132. .IP cfb 8
  133. The ``color frame buffer'' driver.  This is intended to be a machine
  134. independent driver for \fIn\fP-bit deep (\fIn\fP <= 32) Z-Format memory
  135. mapped displays.  While much of this code is portable to arbitrary depth
  136. displays, release 4 provides a fast implementation only for the 8-bit case.
  137. .IP ...
  138. There are several directories which are specific to a particular vendor and
  139. contain minimal code for talking to that hardware.
  140. In the \fBos\fP directory,  there is at present only the following directory:
  141. .LP
  142. The only subdirectory in the \fBos\fP directory is:
  143. .IP 4.2bsd 8
  144. An implementation of the file and interprocess primitives for the server
  145. using the facilities of 4.2 and 4.3 BSD.  This code also works on various
  146. SYSV-BSD blends (A/UX, HPUX etc) but no attempt has been made to get it
  147. working in a generic SYSV environment.
  148. .LP
  149. The intent is that one should port the sample server to new hardware by
  150. using the \fImi\fP code,  implementing at first only the lowest level routines
  151. such as \fBFillSpans(\|)\fP.
  152. We did not do so for our initial monochrome ports (the \fImi\fP code was too
  153. incomplete), instead we used the \fImfb\fP code.  Our subsequent color
  154. ports were based on \fImi\fP and we describe both.  The current release
  155. relies on \fIcfb\fP heavily as much of \fImi\fP is only interesting from an
  156. academic viewpoint.
  157. .LP
  158. The details of server internals you need to know to do this, and more
  159. advanced ports,  are described in a document (the \fIPorting
  160. Layer\fP) written by the DEC team that developed it.\s-2\u2\d\s0
  161. .FS
  162. 2.  \fIThe Porting Layer for the X V11 Sample Server\fP,  by Susan Angebranndt,
  163. Raymond Drewry,  Phil Karlton and Todd Newman.  See the file
  164. \fIdoc/Server/ddx.doc.tbl.ms\fP.
  165. .FE
  166. You should read this document even for a simple monochrome or color port, a
  167. complete understanding isn't important, but a better understanding of the
  168. basic porting process will result from even a cursory perusal.  We refer to
  169. it frequently when more details are needed.
  170. .NH
  171. Road Map
  172. .LP
  173. In order to get the sample server running on your hardware,  you will need
  174. to deal with four distinct areas:
  175. .IP a)
  176. Painting the Bits \- you need to make the code work for the mapping
  177. between pixel coordinates and byte/bit addresses defined by your hardware.
  178. .IP b)
  179. Pounding the Keys \- you need to map between the keystrokes and mouse
  180. movements your hardware provides,  and the canonical forms required by the
  181. server.
  182. .IP c)
  183. Dragging the Cursor \- you need to move a cursor image around the screen,
  184. and change the image on demand.
  185. .IP d)
  186. Starting Up & Shutting Down \- you need to initialize and close down the
  187. connections between the server and your hardware.
  188. .NH
  189. Doing the Port (Monochrome and 8-bit color)
  190. .LP
  191. Lets suppose you want to port X V11 to the Generic Workstation Company's
  192. (GWC) hardware.  You can do most of the work in one fell swoop:
  193. .LS
  194. #!/bin/sh
  195. cd server/ddx/sun
  196. mkdir ../gwc
  197. sed -e 's/sun/gwc/g' Makefile >../gwc/Makefile
  198. for A in *.[hc]
  199. do
  200.     sed -e 's/sun/gwc/g' $A >../gwc/gwc`expr $A : 'sun\e(.*\e)'`
  201. done
  202. .LE
  203. .LP
  204. You now have a directory in the right place with a first approximation to the
  205. source files in it.
  206. It will avoid confusion if you remove all code in this directory between
  207. .LS
  208. #ifdef    SUN_WINDOWS
  209. #endif    SUN_WINDOWS
  210. .LE 
  211. This deals with running X V11 ``on top of'' the SunWindows window system,
  212. and is of no interest here.
  213. .LP
  214. The next steps tackle the four major areas in which
  215. GWC's workstations are different from Sun's.
  216. .NH 2
  217. Painting the Bits
  218. .LP
  219. Assuming that you have a machine  which has a simple memory bitmap,
  220. all you have to do to ensure that the pixels are painted correctly is to
  221. deal with the potential differences between simple memory bitmaps.  The files
  222. \fIserver/include/servermd.h\fP and \fIfonts/bdftosnf/bdftosnf.h\fP contain
  223. the definitions for the various CPUs which already support the sample
  224. server.  You will need to add #ifdef sections after the others
  225. in each file which contains the following definitions.
  226. .Ip
  227. Byte order.  Both the \fImfb\fP and \fIcfb\fP code can handle either byte
  228. order.  If you have a 68000 CPU (Big Endian), the file
  229. \fIserver/include/servermd.h\fP should contain:
  230. .LS
  231. #define IMAGE_BYTE_ORDER    MSBFirst
  232. .LE
  233. If you have a 80386 GWC,  \fIserver/include/servermd.h\fP should contain:
  234. .LS
  235. #define IMAGE_BYTE_ORDER    LSBFirst
  236. .LE
  237. .Ip
  238. Pixel order.  Again, both the \fImfb\fP and \fIcfb\fP code can handle either
  239. the 68000 style, where the most significant bit is to the left on the scan
  240. line, or the 80386 style, where the least significant bit is to the left on
  241. the scan line.  For the 68000 GWC, the file \fIserver/include/servermd.h\fP
  242. should contain:
  243. .LS
  244. #define BITMAP_BIT_ORDER    MSBFirst
  245. .LE
  246. .IP
  247. And the file \fIfonts/bdftosnf/bdftosnf.h\fP should contain:
  248. .LS
  249. #define    DEFAULTBITORDER    MSBFirst
  250. .LE
  251. For the 80386 GWC,  the file \fIserver/include/servermd.h\fP should contain:
  252. .LS
  253. #define BITMAP_BIT_ORDER    LSBFirst
  254. .LE
  255. .IP
  256. And the file \fIfonts/bdftosnf/bdftosnf.h\fP should contain:
  257. .LS
  258. #define    DEFAULTBITORDER    LSBFirst
  259. .LE
  260. .Ip
  261. Pixel meaning.
  262. Some machines have monochrome displays where a 1 bit means black, while
  263. others ones have displays where a 1 means white.  Check the manual, and set
  264. the appropriate values in the file \fIserver/ddx/gwc/gwcBW2.c\fP:
  265. .LS
  266. pScreen->whitePixel = 0 or 1;
  267. pScreen->blackPixel = 1 or 0;
  268. .LE
  269. .Ip
  270. Alignment restrictions.
  271. CPUs vary in the alignment restrictions they place on memory accesses.  For
  272. example, some can do 4-byte accesses at every byte address, and some only at
  273. 4-byte boundaries.  In general, the \fImfb\fP and \fIcfb\fP code take the
  274. conservative viewpoint that the framebuffer and memory bitmaps are accessed
  275. only 4 bytes wide at 4-byte boundaries.
  276. .IP
  277. However, this isn't true of the font code.  For Sun hardware, we decided to
  278. extend the same restriction to the font code, and changed the padding rules
  279. used for the fonts to avoid those cases in which the \fImfb\fP and \fIcfb\fP
  280. code would use addresses that weren't 4-byte aligned.  We will cover the
  281. padding rules in some detail later; for the moment all you need to do is to
  282. include in the file \fIfonts/bdftosnf/bdftosnf.h\fP:
  283. .LS
  284. #define    DEFAULTGLPAD    4
  285. .LE
  286. while \fIserver/include/servermd.h\fP should have
  287. .LS
  288. #define GLYPHPADBYTES    4
  289. .LE
  290. .IP
  291. .LP
  292. The \fImfb\fP, \fIcfb\fP and \fImi\fP directories are now set up for your
  293. machine.  The next steps are more work.
  294. .NH 2
  295. Pounding the Keys
  296. .LP
  297. More frequently than you would believe possible,  the DIX layer will call
  298. the function \fBProcessInputEvents(\|)\fP.
  299. This function lives in \fIgwcIo.c\fP,  and you will be able to use it
  300. almost unchanged.  It has to:
  301. .Ip
  302. Obtain the device-specific events from the keyboard and the mouse,  by
  303. calling through their private descriptor structures to a device-specific
  304. \fBGetEvents\fP routine.
  305. .Ip
  306. In time-stamp order, hand each event to the appropriate \fBProcessEvents\fP
  307. routine, again calling through the private descriptor structure for each
  308. device.
  309. .Ip
  310. Maintain the time of the last event.
  311. .Ip
  312. Restore the screen if it is currently saved.
  313. .LP
  314. Only the first of these requires modifications to the code you now have,
  315. and these take place in the files \fIgwcKbd.c\fP and \fIgwcMouse.c\fP
  316. .LP
  317. Each device has a \fBGetEvents\fP routine;  it needs to return an array
  318. containing the device-specific events that are immediately available.  The
  319. precise structure of the events is not important,  but they need to be
  320. time-stamped by the kernel.  The declarations in \fIgwcIo.c\fP,
  321. \fIgwcKbd.c\fP and \fIgwcMouse.c\fP of things as pointers to
  322. \fBFirm_events\fP should be changed to \fBgwc_events\fP,  the name of the
  323. structures the GWC kernel returns.
  324. .LP
  325. To obtain the events,  you can either do a non-blocking \fBread(\|)\fP or use
  326. a shared-memory circular queue of events, if your kernel
  327. supports it.  The \fIserver/ddx/sun\fP
  328. code supports only non-blocking reads,  since current
  329. Sun kernels do not have a shared-memory event queue.  You are strongly urged
  330. to add support for a shared-memory event queue to the GWC kernel,  since doing
  331. the non-blocking \fBread(\|)\fPs is a serious performance problem.
  332. .LP
  333. For the present,  we assume that the GWC kernel has separate
  334. \fI/dev/mouse\fP and \fI/dev/kbd\fP files,  which:
  335. .Ip
  336. Support the \fBfcntl(FNDELAY)\fP call.
  337. .Ip
  338. Provide a stream of \fBgwc_event\fP structures containing position, keycode,
  339. and timestamp information.
  340. .LP
  341. In \fIgwcMouse.c\fP,  you will need to change only the names of the fields
  342. in the device-specific event structures,  from those of the \fIFirm_event\fP
  343. to those of the \fIgwc_event\fP,  and the values of the ID codes (such as
  344. MS_LEFT) used for the button and motion events.  If you have one of the GWC
  345. mice that reports absolute positions rather than X and Y deltas,  you will
  346. need to add another case to the following statement.
  347. .LS
  348. switch (fe->id) {
  349.     case MS_LEFT:
  350.     case MS_MIDDLE:
  351.     case MS_RIGHT:
  352.     case LOC_X_DELTA:
  353.     case LOC_Y_DELTA:
  354.     default:
  355. }
  356. .LE
  357. Beware of the Sun convention that motion up gives a positive Y
  358. delta.
  359. .LP
  360. In \fIgwcKbd.c\fP,  you will need to make similar changes to the names of
  361. the event fields.  Then,
  362. replace the various \fBioctl(KIOC<foo>)\fP calls with their GWC equivalents
  363. Their meanings are:
  364. .TS
  365. center, box;
  366. c c
  367. l l.
  368. Name    Operation
  369. _
  370. KIOCTYPE    T{
  371. Get int indicating keyboard type
  372. T}
  373. KIOCGTRANS    T{
  374. Get/set keycode translation.  We want ASCII events.
  375. T}
  376. KIOCSDIRECT    T{
  377. Switch keystrokes between \fI/dev/kbd\fP and \fI/dev/console\fP.  We want
  378. \fI/dev/kbd\fP.
  379. T}
  380. .TE
  381. .LP
  382. Now,  you have to establish a mapping between the codes your keyboard
  383. sends and the names X V11 uses for keys (the so-called \fIkeysyms\fP).
  384. Read the files \fIserver/ddx/gwc/gwcKeyMap.c\fP and \fIX11/keysym.h\fP.
  385. Look at your keyboard manual,  and find the lowest keycode it sends (\fIkcmin\fP)
  386. and the highest keycode it sends (\fIkcmax\fP).
  387. Look at the keyboard itself,  and find the key with the largest number of
  388. symbols on it,  counting strings like ``Return'' or ``F9'' as one
  389. symbol.
  390. The number of symbols on this key is the \fIwidth\fP of the keyboard.
  391. Now,  for each of your keyboard types,  you will need two things in
  392. \fIgwcKeyMap.c\fP:
  393. .Ip
  394. A \fIkeymap\fP,  which is an array with (\fIkcmax\fP-\fIkcmin\fP+1)
  395. rows and \fIwidth\fP
  396. columns.
  397. Each row in the array should contain the keysyms corresponding to the
  398. symbols on the keycap,  with the first column containing the symbol
  399. generated when the key is un-shifted,  the second the symbol generated when
  400. the key is shifted,  and the other columns the other symbols in no
  401. special order.
  402. So,  for example,  a key with the symbols ``1'' and ``!'' on it would
  403. have the keysyms \fIXK_1\fP and \fIXK_exclam\fP in the table.
  404. .Ip
  405. A \fImodifier map\fP,  which is an array with one entry per keycode.
  406. Each entry should contain the modifier bits that are set when that key
  407. is down.  So,  for example,  a ``Shift'' key would have an entry
  408. \fIShiftMask\fP.
  409. .NH 2
  410. Dragging the (Software) Cursor
  411. .LP
  412. Suns use a software cursor,  as there is no cursor hardware.
  413. The problem with
  414. is that it must be removed from the display before painting operations that
  415. might affect the pixels it is using.  And,  of course,  put back again at
  416. some time later.
  417. .LP
  418. Fortunately, a machine-independent software cursor layer is included in
  419. \fIserver/ddx/mi\fP which is easily connected to the mouse device.  It will
  420. work on any display, but it is a little slow, and you will want to use the
  421. hardware cursor on machines that have it.  The changes needed to do so are
  422. fairly extensive, so we cover them later also.
  423. .NH 2
  424. Starting Up & Shutting Down
  425. .LP
  426. When the server is started,  it initializes its output and input devices by
  427. calling their initialization procedures.
  428. This is where things get really device-specific,  and the code for the GWC
  429. will differ significantly from the Sun code.  The overall structure will be
  430. preserved,  however.
  431. .LP
  432. It is important to observe that,  once the last client has closed its
  433. connection and everything has been shut down,
  434. the server will re-initialize everything by repeating the process.
  435. Although there is a close-down procedure,  it is generally better to avoid
  436. closing the device,  instead simply reset it to its initial state.
  437. So if,  for
  438. example,  initializing a display or a mouse involves opening a file,  the
  439. descriptor should be remembered in a static structure and not re-opened if
  440. it is already open.\s-2\u4\d\s0
  441. .FS
  442. 4.  See section 2.4.3 of the \fIPorting Layer\fP.
  443. .FE
  444. .NH 3
  445. Output
  446. .LP
  447. Output devices are initialized in a two-step process:
  448. .Ip
  449. The server calls \fBInitOutput(\|)\fP,  a routine in \fIgwcInit.c\fP which you
  450. can re-use untouched.  It calls each potentially available display's probe
  451. routine,  finding the probe routine and the probable file name for it in the
  452. \fBgwcFbData[\|]\fP array.
  453. .IP
  454. The dumb monochrome device,  whose driver is in \fIgwcBW2.c\fP,  has a probe
  455. routine called \fBgwcBW2Probe(\|)\fP.  This has to attempt to initialize the
  456. monochrome display and,  if it succeeds,  fill out the \fBfbFd\fP
  457. structure describing it.  In the Sun case,  most of the work is done in a
  458. routine \fBsunOpenFrameBuffer(\|)\fP in \fIsunInit.c\fP,  because it is common
  459. among all Sun framebuffers.  This routine scans the command-line arguments,
  460. the environment,  and the \fI/dev\fP directory to find a frame-buffer of
  461. the required type,  opens it,  and returns the file descriptor.
  462. .IP
  463. The dumb color device, whose driver is in \fIgwcCG3.c\fP, is similarly
  464. structured, the probe is called \fIgwcCG3Probe(\|)\fP.
  465. .IP
  466. The probe routines then have to map this descriptor into the server's address
  467. space, and install a pointer to the pixels in the \fBfbFd\fP structure.
  468. Note that the Sun monochrome code has to deal with two different sizes of
  469. monchrome framebuffers.  The \fBfbFd\fP structure is the static structure we
  470. mentioned earlier, needed to preserve internal driver information across
  471. server re-initializations.  Finally, it calls \fBAddScreen(\|)\fP, giving it
  472. the address of the BW2/CG3 initialization routine.
  473. .Ip
  474. \fBAddScreen(\|)\fP fills out the screen information, and calls the
  475. initialization routine.  In the monochrome case, \fBmfbScreenInit(\|)\fP is
  476. called to initialize the \fImfb\fP part of the code.  This fills in the
  477. \fBScreen\fP's operations vector with the routines the
  478. \fImfb\fP code supports.  The remaining entries are filled out by the
  479. initialization routine itself.  This code can be reused unchanged.  The
  480. color case simply uses \fBcfbScreenInit(\|)\fP.  Note that in the color case
  481. the values for whitePixel and blackPixel are left unspecified.  \fIcfb\fP
  482. will fill in the values 0 for white and 1 for black.  If this is not
  483. satisfactory, replace them with your own values after calling
  484. \fBcfbScreenInit\fP and before calling \fBcfbCreateDefColormap\fP.
  485. .LP
  486. When the server is shutting down prior to re-initialization,  it will call
  487. the \fBCloseScreen\fP function in the \fBScreen\fP structure.
  488. You can also use this routine unchanged.
  489. .LP
  490. One other area which needs attention are the \fBgwcBW2SaveScreen(\|)\fP and
  491. \fBgwcCG3SaveScreen(\|\)\fP routines.  These need to enable and disable the
  492. video for the GWC framebuffer.
  493. .NH 3
  494. Input
  495. .LP
  496. A similar two-step process is used to initialize the input devices.  First,
  497. the server calls \fBInitInput(\|)\fP, in \fIgwcInit.c\fP.  It registers the
  498. keyboard and mouse devices by calling \fBAddInputDevice(\|)\fP,  among the
  499. arguments to which are the appropriate initialization/closedown routines
  500. \fBgwcMouseProc\fP and \fBgwcKbdProc\fP.
  501. .LP
  502. Then,  the server calls each of the device initialization/closedown routines
  503. twice,  once with command \fBDEVICE_INIT\fP and once with command \fBDEVICE_ON\fP.
  504. These must:
  505. .Ip
  506. Open the necessary devices.
  507. .Ip
  508. Set up the appropriate keymaps.
  509. .LP
  510. When the server is shutting down prior to re-initialization,  it will call
  511. the device's initialization/closedown routine with command \fBDEVICE_OFF\fP.
  512. .LP
  513. Except for the details of how the devices are opened and coerced to supply
  514. ASCII events,  and the changes made earlier to the \fBioctl(\|)\fPs,  the rest
  515. of this code can be used unchanged.
  516. .NH 2
  517. Tidying Up
  518. .LP
  519. You have now made all the major changes needed.  All that remains is to make
  520. suitable changes to the makefiles:
  521. .Ip
  522. In \fIserver/Imakefile\fP,  make the following changes:
  523. .KF
  524. .LS
  525.      ALLDDXDIRS = \fIwhatever is already there\fP ddx/gwc
  526.         GWC = ddx/gwc/libgwc.a
  527.     ALLPOSSIBLE = \fIwhatever is already there\fP Xgwc
  528.  
  529. #ifndef    XgwcServer
  530. #define    XgwcServer /* as nothing */
  531. #endif
  532.             ALL = \fIwhatever is already there\fP XgwcServer
  533.  
  534. #
  535. # GWC server
  536. #
  537. GWCDIRS = dix ddx/snf ddx/mi ddx/mfb ddx/cfb ddx/gwc os/4.2bsd
  538. GWCOBJS = ddx/gwc/gwcInit.o
  539. GWCLIBS = $(GWC) $(CFB) $(DIX) $(SNF) $(UNIX) $(MFB) $(MI) $(EXTENSIONS)
  540. GWCSYSLIBS = $(SYSLIBS)
  541. XgwcDIRS = $(GWCDIRS)
  542.  
  543. ServerTarget(Xgwc,$(EXTDIR) $(GWCDIRS),$(GWCOBJS),$(GWCLIBS),$(GWCSYSLIBS))
  544. .LE
  545. .DS C
  546. .I
  547. Figure 1: Top-level Imakefile Changes
  548. .R
  549. .DE
  550. .KE
  551. .Ip
  552. Now go ahead,  make everything,  and enjoy!
  553. .LP
  554. There are probably some details we've omitted \- we no longer have our GWCs
  555. so we're writing this from memory.  If you find either the details or the
  556. hardware,  please let us know.
  557. .NH
  558. Additional work needed for doing a Color Port on non 8-bit displays.
  559. .LP
  560. After the \fImfb\fP-based monochrome drivers were shipped to MIT,  we went
  561. on to develop drivers for Sun's color hardware.
  562. Our initial attempt was based on the
  563. \fImi\fP code.  Our goals were:
  564. .Ip
  565. To get the server functional on color hardware as expeditiously as possible.
  566. .Ip
  567. To test the color code in \fIserver/dix\fP,  and as much as possible of the
  568. code in \fIserver/ddx/mi\fP.
  569. .Ip
  570. To test the recommended porting strategy,  using \fImi\fP and implementing
  571. only \fBGetSpans(\|)\fP,  \fBSetSpans(\|)\fP and \fBFillSpans(\|)\fP.
  572. .Ip
  573. To provide a highly portable implementation of the DDX layer for color hardware
  574. to enable others to get the server running as effortlessly as possible.
  575. .LP
  576. Performance was explicitly not a goal.
  577. Just as \fImfb\fP assumes that the display it is driving has a 1-bit deep memory
  578. framebuffer accessed 32 bits wide at 32-bit boundaries,  \fIcfb\fP assumes a
  579. \fIn\fP-bit deep (\fIn\fP\ <=\ 32) memory framebuffer accessed 32 bits wide
  580. at 32-bit boundaries.  While these restrictions are fairly onerous,  they
  581. make the code highly portable in both cases.  In the monochrome case, 
  582. the DEC team managed to provide relatively good performance.  In the color
  583. case,  there is \fIn\fP times more work to do,  and we have not attempted
  584. all of the optimizations that \fImfb\fP uses.
  585. .NH 2
  586. Porting cfb to non-8 bit framebuffers
  587. .LP
  588. By default,  \fIcfb\fP is set up to drive a framebuffer that is 8 bits deep
  589. with the pixel order defined by \fBBITMAP_BIT_ORDER\fP.  If your framebuffer
  590. is different,  you will need to change some parameters in
  591. \fIserver/ddx/cfb/cfbmskbits.h\fP:
  592. .TS
  593. center, box;
  594. c s s s
  595. c c c c
  596. l n n l.
  597. Parameters in cfb
  598. _
  599. Parameter    mfb    cfb    Comment
  600. _
  601. PPW    32    4    pixels per word
  602. PLST    31    3    last pixel in a word (should be PPW-1)
  603. PIM    0x1f    0x03    pixel index mask (index within a word)
  604. PWSH    5    2    pixel-to-word shift
  605. PSZ    1    8    pixel size (bits)
  606. PMSK    0x01    0xFF    single-pixel mask
  607. .TE
  608. .LP
  609. Read the comments in \fIcfbmskbits.[hc]\fP carefully before changing these
  610. parameters.  You will also need to change the mask values in
  611. \fIserver/ddx/cfb/cfbmskbits.c\fP.
  612. .LP
  613. Changing these parameters and masks is all you should need,  but we cannot
  614. be sure.
  615. The code has been used on several types of color hardware,  but in each case
  616. there are four pixels to the word (and,  therefore,  the masks don't need
  617. changing).
  618. .NH 2
  619. Using cfb
  620. .LP
  621. The code in \fIserver/ddx/sun/sunCG4C.c\fP illustrates how to use \fIcfb\fP
  622. to drive an 8-bit deep memory frambuffer (the usage on non 8-bit deep frame
  623. buffers is identcal but no example code exists).  You call
  624. \fBcfbscrinit(\|)\fP to fill out the screen operation vector, and
  625. \fBcfbCreateGC(\|)\fP to create a GC.  In both cases, reading the code will
  626. show that most of the procedures to be used are from \fImi\fP.
  627. .LP
  628. Unlike \fImfb\fP, which effectively supports only a StaticGray visual, the
  629. \fIcfb\fP code supports all 6 possible visual types if your hardware has
  630. writeable color maps.  Otherwise, (or for testing purposes) you can define
  631. \fBSTATIC_COLOR\fP and support a StaticColor visual (which also limits the
  632. supported visual types to StaticColor and TrueColor).
  633. .NH
  634. Details
  635. .LP
  636. This section is not intended to be a complete survey of the details of the
  637. server.  We wouldn't claim enough knowledge to write that (yet).   It is
  638. rather a collection of comments on the areas we have had to deal with in
  639. detail,  in the hope that we can save others from wasting their time on
  640. problems that are either already solved or insoluble.
  641. .NH 2
  642. Software & Hardware Cursors
  643. .LP
  644. The details of the DIX interface to the cursor support are described in
  645. section 2.5 of the \fIPorting Layer\fP.
  646. .NH 3
  647. Software Cursors
  648. .LP
  649. The Machine Independent software cursor code is very easy to use and it
  650. provides reasonable performance.  It works by "wrapping" every potential
  651. drawing operation to the screen and checking for overlap with the cursor
  652. during these operations.  The \fIPorting Layer\fP describes this
  653. "wrapping" notion in greater detail.
  654. .NH 3
  655. Hardware Cursors
  656. .LP
  657. To switch to using a hardware cursor,  you will need to study the QVSS code,\s-2\u12\d\s0
  658. .FS
  659. 12.  See the files
  660. \fIserver/ddx/sun/sunCursor.c\fP
  661. and
  662. \fIserver/ddx/dec/qvss/qvss_io.c\fP,
  663. and section 2.5 of the \fIPorting Layer\fP.
  664. .FE
  665. and to remove the following code from the \fIserver/ddx/sun\fP files:
  666. .Ip
  667. \fIsunInit.c\fP:  the code that calls miDCInitialize
  668. .Ip
  669. \fIsunMouse.c\fP:  the code in \fBsunMouseProcessEvent(\|)\fP that positions
  670. the software cursor.
  671. .NH 2
  672. Fonts & Padding
  673. .LP
  674. The \fIPorting Layer\fP describes the layout of the glyph information in
  675. memory as follows:\s-2\u13\d\s0
  676. .FS
  677. 13.  See section 5.3.
  678. .FE
  679. .QP
  680. ``Each scanline of each glyph is padded  to  a  byte  boundary
  681. with  zero  bits.  Bit and byte order is whatever is natural
  682. for the server.  (Note: the current BDF to SNF font compiler
  683. handles  either  bit  order  within a byte as a compile time
  684. option. It does not deal with byte order.) The glyph  for  a
  685. character whose XCHARINFO is ci begins at cg[ci.byteOffset].
  686. Glyphs may begin at arbitrary offsets within the array.''
  687. .LP
  688. The section on ``Alignment'' describes the problem:\s-2\u14\d\s0
  689. .FS
  690. 14.  See section 4.5.2.
  691. .FE
  692. .QP
  693. ``The mfb text code might access mis-aligned longwords;  this is not a problem
  694. on VAXes,  680x0 (x != 0),  or Intel architectures,  but might be on some as
  695. yet unknown processors,  and is definitely bad on a 68000.  An easy fix is
  696. to have the font compiler generate longword padded glyphs instead of
  697. byte-padded ones.''
  698. .LP
  699. We followed this advice,  and the results are incorporated in the Sun
  700. code in the release.
  701. The trade-offs to consider when deciding what to do are:
  702. .Ip
  703. Many processors cannot access mis-aligned longwords.\s-2\u15\d\s0  In these
  704. cases,  there is no real choice.
  705. .FS
  706. 15.  Try it on a 68010 sometime,  or on a PC/RT,  or on a SPARC,  or ....
  707. .FE
  708. .Ip
  709. Even processors which can access longwords at byte boundaries do so more
  710. slowly than aligned accesses,  and these accesses are made in a
  711. performance-critical area (painting characters).
  712. Check your hardware manual, or write a small benchmark.  Furthermore, the
  713. font code for big-endian machines is always slower when using non-longword
  714. padded fonts as it must shift things around.
  715. .Ip
  716. On the other hand,  padding the glyphs to longwords wastes a significant
  717. amount of space.
  718. .LP
  719. If you'd like to pack fonts even on machines which can't access longwords on
  720. non-longword boundaries, then, in the file \fIserver/include/servermd.h\fP,
  721. choose the alignment restriction (in bytes) for those accesses:
  722. .LS
  723. #define GETLEFTBITS_ALIGNMENT    1    /* arbitrary byte alignment */
  724. #define GETLEFTBITS_ALIGNMENT    2    /* halfword alignment */
  725. #define GETLEFTBITS_ALIGNMENT    4    /* longword alignment */
  726. .LE
  727. .LP
  728. If you are using GLYPHPADBYTES 4, make sure you set GETLEFTBITS_ALIGNMENT to
  729. 1 even if your CPU can't access longwords on non-longword boundaries.  This
  730. is because the text code would use extra instructions to check the alignment
  731. of the accesses even though the fonts are guaranteed to be longword aligned.
  732. .NH 2
  733. Shared Event Queue
  734. .LP
  735. By default,  the DIX layer calls \fBProcessInputEvents(\|)\fP before it it
  736. waits for something to happen,  and also before performing each client
  737. request.
  738. When using non-blocking \fBread(\|)\fP calls this is a substantial overhead,
  739. and a facility for reducing this has been provided.  \fBSetInputCheck(\|)\fP
  740. can be called with the addresses of two locations,  and
  741. \fBProcessInputEvents(\|)\fP will only be called when they differ.  There are
  742. two ways of using this:
  743. .Ip
  744. If your mouse and keyboard drivers support \fBSIGIO\fP,  enable this mode
  745. when you open them,  and register a handler that increments a location.
  746. Give \fBSetInputCheck(\|)\fP the address of this and a zero location,  and add
  747. code to re-zero the location to \fBProcessInputEvents(\|)\fP.
  748. The Sun code does this.
  749. .Ip
  750. If you have a kernel event queue that can be mapped into a user process,
  751. give \fBSetInputCheck(\|)\fP the addresses of the head and tail pointers.\s-2\u17\d\s0
  752. .FS
  753. 17.  See the file \fIserver/ddx/dec/qvss/qvss_io.c\fP.
  754. .FE
  755. This is the best alternative,  because it eliminates
  756. the \fBread(\|)\fP system calls as well.
  757. .LP
  758. In both cases,  there is an interaction with the software cursor code.  When
  759. the cursor is out of the bitmap,  this mechanism must be disabled.  We need
  760. to ensure that \fBProcessInputEvents(\|)\fP will be called at some time soon
  761. after the cursor is removed in order to put it back.
  762. .Ip
  763. If you are using \fBSIGIO\fP,  you can simply call the SIGIO handler from
  764. the cursor removal code.
  765. .Ip
  766. If you are using a shared event queue,  you have to call
  767. \fBSetEventCheck(\|)\fP in the cursor removal code,  giving it the addresses
  768. of two locations that are always different,  and again in the code that
  769. paints the cursor,  giving it the head and tail pointers.
  770. .NH 2
  771. Multiple Screens
  772. .LP
  773. The \fIsun\fP code supports multiple screens (``Zaphod'' mode).\s-2\u18\d\s0
  774. .FS
  775. 18.  See \fIThe Hitch-Hiker's Guide to the Galaxy\fP by Douglas Adams.
  776. .FE
  777. There are two possible versions of Zaphod mode:
  778. .Ip
  779. ``Passive'',  in which the cursor stays on one screen until some client
  780. actively warps it to another screen.
  781. .IP
  782. ``Active'',  in which the server warps the cursor between screens itself.
  783. .LP
  784. The \fIwm\fP window manager implements passize Zaphod mode,  clicking on the
  785. background warps the pointer to the next screen in sequence.
  786. .LP
  787. The \fIsun\fP code implements active Zaphod mode by using the mi Cursor
  788. code.  In \fBsunCursorOffScreen(\|)\fP, when the pointer gets to the right
  789. (left) edge of the current screen, it is warped to the next (previous)
  790. screen in sequence.  This is done by simply modifying the input paramenters
  791. and returning the appropriate value.  If you aren't using the mi software
  792. cursor code, examine it for the details on how to get the cursor to the new
  793. screen.
  794. .if 0 \{
  795.     how do you deal with deciding what pixmap formats are supported,
  796. and which ones not, in the following three cases:
  797.  
  798.     1 head, chosen from among several
  799.  
  800.     1 < n < m heads chosen from m
  801.  
  802.     n heads chosen from n
  803.  
  804. do you do table lookup here too?  this sounds like it could be
  805. strange, especially if you have two screens with different bit or byte
  806. order.  right now, i do it in init, by looking at some gloabls set by
  807. each screen, which seems quite wrong.
  808.     --raymond
  809. There does not seem to be a problem here.
  810.  
  811. The protocol defines that there is a single format per server per
  812. depth.  (I thought this was strange,  too,  but I got flamed at by RWS
  813. for mentioning it,  so I guess that really is what the protocol says)
  814.  
  815. We simply use a static table that defines this format for all
  816. depths it is possible to configure the server to support.  This table
  817. is used irrespective of whether a screen supporting that depth was
  818. found during auto-configuration.  Thus,  if you start the server on a
  819. monochrome Sun,  the screenInfo struct contains:
  820.  
  821.     numPixmapFormats = 2
  822.     formats[] = {
  823.         1, 1, BITMAP_SCANLINE_PAD,
  824.         8, 8, BITMAP_SCANLINE_PAD,
  825.         }
  826.  
  827. Since the formats array is always searched with a particular depth
  828. (derived from elsewhere and presumably valid) in mind,  these extra
  829. entries do no harm.
  830. \}
  831. .if 0 \{
  832. GCperDepth[] - entry 0 is always for depth 1.
  833. \}
  834. .NH
  835. Conclusions
  836. .LP
  837. During the alpha & beta testing periods of X V11,  many interpid porters
  838. attempted to adapt the sample server to their hardware.
  839. It is to their credit,  and especially to the spirit of cooperation in
  840. which the implementors received the enormous volume of comments and
  841. suggestions that resulted,  that the X V11 sample server is now
  842. remarkably easy to get running on new hardware.
  843. A few bold strokes of the keyboard,  and the task is done.  Well,
  844. almost,  but
  845. not quite.  What remains is to tune the server to give of its best
  846. on your particular hardware.  We leave this as an exercise for the reader.
  847. .NH
  848. Acknowledgements
  849. .LP
  850. Thanks to John Ousterhout and Andrew Cherenson for various suggestions
  851. in the initial UCB port.
  852. .LP
  853. The Sun port of the alpha server was done by David Rosenthal,  Mike
  854. Schwartz,  Stuart Marks, Robin Schaufler, and Alok Singhania.  It was made
  855. much easier by the extent to which we could steal from the Sun X.10 server,
  856. now the result of too many people's work to acknowledge individually.
  857. However,  Paul Borman of Cray Research did particularly useful work on
  858. keyboard support.
  859. .LP
  860. The \fIcfb\fP driver was originally the work of Stuart Marks (from a vague
  861. idea by David Rosenthal), with help from Jack Palevitch (now at Apple) and
  862. Bob Leichner of H-P Labs.  The current \fIcfb\fP release was written at the
  863. MIT X Consortium for release 4 and shares a few file names in common with
  864. the original code.
  865. .LP
  866. The version of the Sun code in the MIT release is the work of 
  867. Adam de Boor,
  868. David Rosenthal,
  869. Stuart Marks,
  870. Robin Schaufler,
  871. Frances Ho,
  872. Mark Opperman
  873. and Geoff Lee.
  874. Integration of the Sun code into the MIT release would have been impossible
  875. without
  876. the generous help of the Statistics Center at MIT,  who allowed us to
  877. monopolise their Suns at all hours of the day and night,  and Todd Brunhoff
  878. of Tektronix.
  879. .LP
  880. Special thanks to the Generic Workstation Company for the loan of their
  881. hardware.
  882.