[comp.windows.x] BW2 HiRed [sic] monitor on SparcStation running X11R3 - fatal bug!

david@sun.com (Stop stretching my slack...) (11/25/89)

In article <891122-104357-3733@Xerox> "Steven_S._Kang.ESM8"@XEROX.COM writes:
>All,
>	Does anyone know how to either enable or get the hi-res monitor driver for
>X11 running on a SparcStation with SunOs 4.0.3c?  I am desperate...

It's easy... let's take a look at server/ddx/sun/sunBW2.c:

   333		isHiRes = (fbType.fb_width > 1152);
   334	#ifdef	_MAP_NEW
   335		if (isHiRes) {
   336		    BW2HRfb = (BW2HRPtr) mmap((caddr_t) 0, sizeof(BW2HRRec),
   337				   PROT_READ | PROT_WRITE,
   338				   MAP_SHARED | _MAP_NEW,
   339				   fd, (off_t) 0);
   340		    if ((int)BW2HRfb == -1) {
   341			Error("mapping BW2 (hires)");
   342			sunFbData[fbNum].probeStatus = probedAndFailed;
   343			(void) close(fd);
   344			return FALSE;
   345		    }
   346		}
   347		else {
   348		    BW2fb = (BW2Ptr) mmap((caddr_t) 0, sizeof(BW2Rec),
   349				 PROT_READ | PROT_WRITE,
   350				 MAP_SHARED | _MAP_NEW,
   351				 fd, (off_t) 0);
   352		    if ((int)BW2fb == -1) {
   353			Error("mapping BW2");
   354			sunFbData[fbNum].probeStatus = probedAndFailed;
   355			(void) close(fd);
   356			return FALSE;
   357		    }
   358		}
   359	#else
   360		if (isHiRes) {
   361		    BW2HRfb = (BW2HRPtr) valloc(sizeof(BW2HRRec));
   362		}
   363		else {
   364		    BW2fb = (BW2Ptr) valloc(sizeof(BW2Rec));
   365		}
   366		if ((BW2fb == (BW2Ptr) NULL) && (BW2HRfb == (BW2HRPtr) NULL)) {
   367		    ErrorF("Could not allocate room for frame buffer.\n");
   368		    sunFbData[fbNum].probeStatus = probedAndFailed;
   369		    (void) close(fd);
   370		    return FALSE;
   371		}
   372		if (mmap((isHiRes ? (pointer) BW2HRfb : (pointer) BW2fb),
   373			 (isHiRes ? sizeof(BW2HRRec) : sizeof(BW2Rec)),
   374			 PROT_READ | PROT_WRITE, MAP_SHARED,
   375			 fd, (off_t) 0) < 0) {
   376		    ErrorF("Mapping bw2");
   377		    sunFbData[fbNum].probeStatus = probedAndFailed;
   378		    (void) close(fd);
   379		    return FALSE;
   380		}
   381	#endif	_MAP_NEW


Well, I can't claim to understand what the author intended, but try
replacing this section with the following (untested) code:

	{
		int pagemask, mapsize;
		caddr_t addr, mapaddr;

		pagemask = getpagesize() - 1;
		mapsize = (fbType.fb_size + pagemask) & ~pagemask;

		addr = 0;
#ifndef _MAP_NEW
		if ((addr = (caddr_t) valloc(mapsize)) == 0) {
			ErrorF("Could not allocate room for frame buffer.\n");
	    		sunFbData[fbNum].probeStatus = probedAndFailed;
			(void) close(fd);
			return FALSE;
		}
#endif _MAP_NEW

		if ((mapaddr = (caddr_t) mmap(addr, mapsize,
			PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
			(caddr_t) -1) {
			Error("mapping BW2");
			sunFbData[fbNum].probeStatus = probedAndFailed;
			if (addr)
				free((char *) addr);
			(void) close(fd);
			return FALSE;
		}

		if (mapaddr == 0)
			mapaddr = addr;

		if (isHiRes = (fbType.fb_width > 1152))
			BW2HRfb = (BW2HRPtr) mapaddr;
		else
			BW2fb = (BW2Ptr) mapaddr;
	}

-- 
David DiGiacomo, Sun Microsystems, Mt. View, CA  sun!david david@eng.sun.com