Browse Source

Plan 9 from Bell Labs 2005-11-02

David du Colombier 18 years ago
parent
commit
55c6a163d1

+ 11 - 10
dist/replica/_plan9.db

@@ -7966,7 +7966,7 @@ sys/src/9/pc/i8259.c - 664 sys sys 1015014519 4423
 sys/src/9/pc/init9.c - 664 sys sys 1040002518 94
 sys/src/9/pc/initcode.s - 664 sys sys 1015014519 282
 sys/src/9/pc/io.h - 664 sys sys 1099761152 8095
-sys/src/9/pc/kbd.c - 664 sys sys 1130788367 12382
+sys/src/9/pc/kbd.c - 664 sys sys 1130848300 12362
 sys/src/9/pc/l.s - 664 sys sys 1115566067 23833
 sys/src/9/pc/main.c - 664 sys sys 1126586232 14691
 sys/src/9/pc/mem.h - 664 sys sys 1018553448 4573
@@ -8059,7 +8059,7 @@ sys/src/9/port/devkprof.c - 664 sys sys 1014931173 3111
 sys/src/9/port/devloopback.c - 664 sys sys 1076612248 14573
 sys/src/9/port/devmnt.c - 664 sys sys 1126586197 21545
 sys/src/9/port/devmntstats.c - 664 sys sys 1014931173 4039
-sys/src/9/port/devmouse.c - 664 sys sys 1130780334 13327
+sys/src/9/port/devmouse.c - 664 sys sys 1130848303 13517
 sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
 sys/src/9/port/devproc.c - 664 sys sys 1126586197 28465
@@ -8967,7 +8967,7 @@ sys/src/boot/pc/8250.c - 664 sys sys 1015007947 5727
 sys/src/boot/pc/alarm.c - 664 sys sys 1015007947 1668
 sys/src/boot/pc/apm.c - 664 sys sys 1015007947 289
 sys/src/boot/pc/bcom.c - 664 sys sys 1032215919 6421
-sys/src/boot/pc/boot.c - 664 sys sys 1109364490 8418
+sys/src/boot/pc/boot.c - 664 sys sys 1130887226 8421
 sys/src/boot/pc/bootld.c - 664 sys sys 1015007948 1801
 sys/src/boot/pc/bootp.c - 664 sys sys 1114464742 12374
 sys/src/boot/pc/cga.c - 664 sys sys 1015007948 1362
@@ -9005,7 +9005,7 @@ sys/src/boot/pc/etherigbe.c - 664 sys sys 1123445062 40477
 sys/src/boot/pc/ethermii.c - 664 sys sys 1103641771 4413
 sys/src/boot/pc/ethermii.h - 664 sys sys 1071175087 3259
 sys/src/boot/pc/etherrhine.c - 664 sys sys 1071175087 12403
-sys/src/boot/pc/fns.h - 664 sys sys 1109364490 4221
+sys/src/boot/pc/fns.h - 664 sys sys 1130887225 4273
 sys/src/boot/pc/fs.c - 664 sys sys 1094674483 1509
 sys/src/boot/pc/fs.h - 664 sys sys 1094674488 653
 sys/src/boot/pc/ilock.c - 664 sys sys 1015007952 303
@@ -9015,11 +9015,11 @@ sys/src/boot/pc/ip.h - 664 sys sys 1094674489 2461
 sys/src/boot/pc/kbd.c - 664 sys sys 1015007952 10188
 sys/src/boot/pc/kfs.h - 664 sys sys 1032215924 861
 sys/src/boot/pc/kfsboot.c - 664 sys sys 1032215914 4788
-sys/src/boot/pc/l.s - 664 sys sys 1103641771 13843
+sys/src/boot/pc/l.s - 664 sys sys 1130887225 18115
 sys/src/boot/pc/lib.h - 664 sys sys 1094674487 2794
-sys/src/boot/pc/load.c - 664 sys sys 1109364491 8903
+sys/src/boot/pc/load.c - 664 sys sys 1130887225 8932
 sys/src/boot/pc/mbr.s - 664 sys sys 1015007953 6234
-sys/src/boot/pc/mem.h - 664 sys sys 1103641771 3371
+sys/src/boot/pc/mem.h - 664 sys sys 1130887225 3371
 sys/src/boot/pc/memory.c - 664 sys sys 1019533021 10272
 sys/src/boot/pc/mkfile - 664 sys sys 1103641863 3105
 sys/src/boot/pc/noether.c - 664 sys sys 1094674488 358
@@ -9039,7 +9039,7 @@ sys/src/boot/pc/sd53c8xx.i - 664 sys sys 1015007955 27245
 sys/src/boot/pc/sdata.c - 664 sys sys 1126906010 38224
 sys/src/boot/pc/sdmylex.c - 664 sys sys 1015007955 28743
 sys/src/boot/pc/sdscsi.c - 664 sys sys 1077033682 7022
-sys/src/boot/pc/trap.c - 664 sys sys 1018462833 7098
+sys/src/boot/pc/trap.c - 664 sys sys 1130887225 7501
 sys/src/boot/pc/ureg.h - 664 sys sys 1015007955 550
 sys/src/boot/pc/x16.h - 664 sys sys 1015007955 5265
 sys/src/cmd - 20000000775 sys sys 1018897673 0
@@ -13047,7 +13047,7 @@ sys/src/cmd/troff/suftab.c - 664 sys sys 944961294 19337
 sys/src/cmd/troff/t10.c - 664 sys sys 1116769866 9493
 sys/src/cmd/troff/t11.c - 664 sys sys 944961294 7081
 sys/src/cmd/troff/t6.c - 664 sys sys 944961294 15408
-sys/src/cmd/troff/tdef.h - 664 sys sys 984718894 18334
+sys/src/cmd/troff/tdef.h - 664 sys sys 1130848601 18335
 sys/src/cmd/troff/unansi - 664 sys sys 944961294 1221
 sys/src/cmd/troff2html - 20000000775 sys sys 961257241 0
 sys/src/cmd/troff2html/chars.h - 664 sys sys 1105584129 3957
@@ -13789,7 +13789,7 @@ sys/src/games/mahjongg/level.c - 664 sys sys 1095792293 2522
 sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1095792293 3452
 sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1095792293 1606
 sys/src/games/mahjongg/mkfile - 664 sys sys 1095792293 230
-sys/src/games/memo.c - 664 sys sys 1125514848 6321
+sys/src/games/memo.c - 664 sys sys 1130853201 6471
 sys/src/games/mkfile - 664 sys sys 1128271766 586
 sys/src/games/music - 20000000775 sys sys 1103793915 0
 sys/src/games/music/Readme - 664 sys sys 1103793914 488
@@ -14969,3 +14969,4 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+386/bin/games/memo - 775 sys sys 1130904586 157331

+ 11 - 11
dist/replica/plan9.db

@@ -252,7 +252,7 @@
 386/bin/games/jukebox - 775 sys sys 1105589128 264821
 386/bin/games/jukefs - 775 sys sys 1105589129 165320
 386/bin/games/mahjongg - 775 sys sys 1130594741 164320
-386/bin/games/memo - 775 sys sys 1130594742 156924
+386/bin/games/memo - 775 sys sys 1130904586 157331
 386/bin/games/playlistfs - 775 sys sys 1105589129 148484
 386/bin/games/sokoban - 775 sys sys 1130594742 164745
 386/bin/games/sudoku - 775 sys sys 1117249746 171666
@@ -7966,7 +7966,7 @@ sys/src/9/pc/i8259.c - 664 sys sys 1015014519 4423
 sys/src/9/pc/init9.c - 664 sys sys 1040002518 94
 sys/src/9/pc/initcode.s - 664 sys sys 1015014519 282
 sys/src/9/pc/io.h - 664 sys sys 1099761152 8095
-sys/src/9/pc/kbd.c - 664 sys sys 1130788367 12382
+sys/src/9/pc/kbd.c - 664 sys sys 1130848300 12362
 sys/src/9/pc/l.s - 664 sys sys 1115566067 23833
 sys/src/9/pc/main.c - 664 sys sys 1126586232 14691
 sys/src/9/pc/mem.h - 664 sys sys 1018553448 4573
@@ -8059,7 +8059,7 @@ sys/src/9/port/devkprof.c - 664 sys sys 1014931173 3111
 sys/src/9/port/devloopback.c - 664 sys sys 1076612248 14573
 sys/src/9/port/devmnt.c - 664 sys sys 1126586197 21545
 sys/src/9/port/devmntstats.c - 664 sys sys 1014931173 4039
-sys/src/9/port/devmouse.c - 664 sys sys 1130780334 13327
+sys/src/9/port/devmouse.c - 664 sys sys 1130848303 13517
 sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
 sys/src/9/port/devproc.c - 664 sys sys 1126586197 28465
@@ -8967,7 +8967,7 @@ sys/src/boot/pc/8250.c - 664 sys sys 1015007947 5727
 sys/src/boot/pc/alarm.c - 664 sys sys 1015007947 1668
 sys/src/boot/pc/apm.c - 664 sys sys 1015007947 289
 sys/src/boot/pc/bcom.c - 664 sys sys 1032215919 6421
-sys/src/boot/pc/boot.c - 664 sys sys 1109364490 8418
+sys/src/boot/pc/boot.c - 664 sys sys 1130887226 8421
 sys/src/boot/pc/bootld.c - 664 sys sys 1015007948 1801
 sys/src/boot/pc/bootp.c - 664 sys sys 1114464742 12374
 sys/src/boot/pc/cga.c - 664 sys sys 1015007948 1362
@@ -9005,7 +9005,7 @@ sys/src/boot/pc/etherigbe.c - 664 sys sys 1123445062 40477
 sys/src/boot/pc/ethermii.c - 664 sys sys 1103641771 4413
 sys/src/boot/pc/ethermii.h - 664 sys sys 1071175087 3259
 sys/src/boot/pc/etherrhine.c - 664 sys sys 1071175087 12403
-sys/src/boot/pc/fns.h - 664 sys sys 1109364490 4221
+sys/src/boot/pc/fns.h - 664 sys sys 1130887225 4273
 sys/src/boot/pc/fs.c - 664 sys sys 1094674483 1509
 sys/src/boot/pc/fs.h - 664 sys sys 1094674488 653
 sys/src/boot/pc/ilock.c - 664 sys sys 1015007952 303
@@ -9015,11 +9015,11 @@ sys/src/boot/pc/ip.h - 664 sys sys 1094674489 2461
 sys/src/boot/pc/kbd.c - 664 sys sys 1015007952 10188
 sys/src/boot/pc/kfs.h - 664 sys sys 1032215924 861
 sys/src/boot/pc/kfsboot.c - 664 sys sys 1032215914 4788
-sys/src/boot/pc/l.s - 664 sys sys 1103641771 13843
+sys/src/boot/pc/l.s - 664 sys sys 1130887225 18115
 sys/src/boot/pc/lib.h - 664 sys sys 1094674487 2794
-sys/src/boot/pc/load.c - 664 sys sys 1109364491 8903
+sys/src/boot/pc/load.c - 664 sys sys 1130887225 8932
 sys/src/boot/pc/mbr.s - 664 sys sys 1015007953 6234
-sys/src/boot/pc/mem.h - 664 sys sys 1103641771 3371
+sys/src/boot/pc/mem.h - 664 sys sys 1130887225 3371
 sys/src/boot/pc/memory.c - 664 sys sys 1019533021 10272
 sys/src/boot/pc/mkfile - 664 sys sys 1103641863 3105
 sys/src/boot/pc/noether.c - 664 sys sys 1094674488 358
@@ -9039,7 +9039,7 @@ sys/src/boot/pc/sd53c8xx.i - 664 sys sys 1015007955 27245
 sys/src/boot/pc/sdata.c - 664 sys sys 1126906010 38224
 sys/src/boot/pc/sdmylex.c - 664 sys sys 1015007955 28743
 sys/src/boot/pc/sdscsi.c - 664 sys sys 1077033682 7022
-sys/src/boot/pc/trap.c - 664 sys sys 1018462833 7098
+sys/src/boot/pc/trap.c - 664 sys sys 1130887225 7501
 sys/src/boot/pc/ureg.h - 664 sys sys 1015007955 550
 sys/src/boot/pc/x16.h - 664 sys sys 1015007955 5265
 sys/src/cmd - 20000000775 sys sys 1018897673 0
@@ -13047,7 +13047,7 @@ sys/src/cmd/troff/suftab.c - 664 sys sys 944961294 19337
 sys/src/cmd/troff/t10.c - 664 sys sys 1116769866 9493
 sys/src/cmd/troff/t11.c - 664 sys sys 944961294 7081
 sys/src/cmd/troff/t6.c - 664 sys sys 944961294 15408
-sys/src/cmd/troff/tdef.h - 664 sys sys 984718894 18334
+sys/src/cmd/troff/tdef.h - 664 sys sys 1130848601 18335
 sys/src/cmd/troff/unansi - 664 sys sys 944961294 1221
 sys/src/cmd/troff2html - 20000000775 sys sys 961257241 0
 sys/src/cmd/troff2html/chars.h - 664 sys sys 1105584129 3957
@@ -13789,7 +13789,7 @@ sys/src/games/mahjongg/level.c - 664 sys sys 1095792293 2522
 sys/src/games/mahjongg/mahjongg.c - 664 sys sys 1095792293 3452
 sys/src/games/mahjongg/mahjongg.h - 664 sys sys 1095792293 1606
 sys/src/games/mahjongg/mkfile - 664 sys sys 1095792293 230
-sys/src/games/memo.c - 664 sys sys 1125514848 6321
+sys/src/games/memo.c - 664 sys sys 1130853201 6471
 sys/src/games/mkfile - 664 sys sys 1128271766 586
 sys/src/games/music - 20000000775 sys sys 1103793915 0
 sys/src/games/music/Readme - 664 sys sys 1103793914 488

+ 11 - 0
dist/replica/plan9.log

@@ -22493,3 +22493,14 @@
 1130781693 0 c sys/src/9/port/devmouse.c - 664 sys sys 1130780334 13327
 1130788894 0 c sys/man/3/kbmap - 664 sys sys 1130788502 1666
 1130788894 1 c sys/src/9/pc/kbd.c - 664 sys sys 1130788367 12382
+1130848311 0 c sys/src/9/pc/kbd.c - 664 sys sys 1130848300 12362
+1130848311 1 c sys/src/9/port/devmouse.c - 664 sys sys 1130848303 13517
+1130850113 0 c sys/src/cmd/troff/tdef.h - 664 sys sys 1130848601 18335
+1130853713 0 c sys/src/games/memo.c - 664 sys sys 1130853201 6471
+1130887922 0 c sys/src/boot/pc/boot.c - 664 sys sys 1130887226 8421
+1130887922 1 c sys/src/boot/pc/fns.h - 664 sys sys 1130887225 4273
+1130887922 2 c sys/src/boot/pc/l.s - 664 sys sys 1130887225 18115
+1130887922 3 c sys/src/boot/pc/load.c - 664 sys sys 1130887225 8932
+1130887922 4 c sys/src/boot/pc/mem.h - 664 sys sys 1130887225 3371
+1130887922 5 c sys/src/boot/pc/trap.c - 664 sys sys 1130887225 7501
+1130905809 0 c 386/bin/games/memo - 775 sys sys 1130904586 157331

+ 8 - 7
sys/src/9/pc/kbd.c

@@ -6,8 +6,6 @@
 #include	"io.h"
 #include	"../port/error.h"
 
-extern void mousetrack(int, int, int, int);
-
 enum {
 	Data=		0x60,		/* data port */
 
@@ -170,7 +168,7 @@ enum
 };
 
 int mouseshifted;
-int kbdbuttons;
+void (*kbdmouse)(int);
 
 static Lock i8042lock;
 static uchar ccc;
@@ -304,6 +302,7 @@ struct {
 	int collecting;
 	int nk;
 	Rune kc[5];
+	int buttons;
 } kbscan;
 
 /*
@@ -402,8 +401,9 @@ i8042intr(Ureg*, void*)
 		case Kmouse|3:
 		case Kmouse|4:
 		case Kmouse|5:
-			kbdbuttons &= ~(1<<(c-Kmouse-1));
-			mousetrack(0, 0, 0, TK2MS(MACHP(0)->ticks));
+			kbscan.buttons &= ~(1<<(c-Kmouse-1));
+			if(kbdmouse)
+				kbdmouse(kbscan.buttons);
 			break;
 		}
 		return;
@@ -473,8 +473,9 @@ i8042intr(Ureg*, void*)
 		case Kmouse|3:
 		case Kmouse|4:
 		case Kmouse|5:
-			kbdbuttons |= 1<<(c-Kmouse-1);
-			mousetrack(0, 0, 0, TK2MS(MACHP(0)->ticks));
+			kbscan.buttons |= 1<<(c-Kmouse-1);
+			if(kbdmouse)
+				kbdmouse(kbscan.buttons);
 			return;
 		}
 	}

+ 10 - 0
sys/src/9/port/devmouse.c

@@ -73,11 +73,13 @@ Mouseinfo	mouse;
 Cursorinfo	cursor;
 int		mouseshifted;
 int		kbdbuttons;
+void		(*kbdmouse)(int);
 Cursor		curs;
 
 void	Cursortocursor(Cursor*);
 int	mousechanged(void*);
 static void mouseclock(void);
+static void xkbdmouse(int);
 
 enum{
 	Qdir,
@@ -114,6 +116,13 @@ mousereset(void)
 	addclock0link(mouseclock, 33);
 }
 
+static void
+mousefromkbd(int buttons)
+{
+	kbdbuttons = buttons;
+	mousetrack(0, 0, 0, TK2MS(MACHP(0)->ticks));
+}
+
 static void
 mouseinit(void)
 {
@@ -123,6 +132,7 @@ mouseinit(void)
 	curs = arrow;
 	Cursortocursor(&arrow);
 	cursoron(1);
+	kbdmouse = mousefromkbd;
 }
 
 static Chan*

+ 4 - 4
sys/src/boot/pc/boot.c

@@ -149,7 +149,7 @@ nextphdr(Boot *b)
 		if(php->type != LOAD)
 			continue;
 		offset = php->offset;
-		paddr = (char*)(php->paddr & ~0xF0000000);
+		paddr = (char*)PADDR(php->paddr);
 		if(offset < curoff){
 			/*
 			 * Can't (be bothered to) rewind the
@@ -215,7 +215,7 @@ readedata(Boot *b)
 	if(php->filesz < php->memsz){
 		print("%lud",  php->memsz-php->filesz);
 		elftotal += php->memsz-php->filesz;
-		memset((char*)((php->paddr & ~0xF0000000)+php->filesz), 0, php->memsz-php->filesz);
+		memset((char*)(PADDR(php->paddr)+php->filesz), 0, php->memsz-php->filesz);
 	}
 	curoff = php->offset+php->filesz;
 	curphdr++;
@@ -326,7 +326,7 @@ bootpass(Boot *b, void *vbuf, int nbuf)
 		case READ9TEXT:
 			ep = &b->exec;
 			b->state = READ9DATA;
-			b->bp = (char*)PGROUND(GLLONG(ep->entry)+GLLONG(ep->text));
+			b->bp = (char*)PGROUND(PADDR(GLLONG(ep->entry))+GLLONG(ep->text));
 			b->wp = b->bp;
 			b->ep = b->wp + GLLONG(ep->data);
 			print("+%ld", GLLONG(ep->data));
@@ -432,7 +432,7 @@ Endofinput:
 		}
 
 		/* relocate data to start at page boundary */
-		memmove((void*)PGROUND(entry+text), (void*)(entry+text), data);
+		memmove((void*)PGROUND(PADDR(entry+text)), (void*)(PADDR(entry+text)), data);
 
 		print("entry: %lux\n", entry);
 		warp9(PADDR(entry));

+ 3 - 1
sys/src/boot/pc/fns.h

@@ -106,6 +106,8 @@ int	splhi(void);
 int	spllo(void);
 void	splx(int);
 void	trapinit(void);
+void	trapdisable(void);
+void	trapenable(void);
 void	uartdrain(void);
 void	uartspecial(int, void (*)(int), int (*)(void), int);
 void	uartputs(IOQ*, char*, int);
@@ -130,7 +132,7 @@ void*	xspanalloc(ulong, int, ulong);
 #define	PLLONG(p,v)	(p)[3]=(v);(p)[2]=(v)>>8;(p)[1]=(v)>>16;(p)[0]=(v)>>24
 
 #define KADDR(a)	((void*)((ulong)(a)|KZERO))
-#define PADDR(a)	((ulong)(a)&~KZERO)
+#define PADDR(a)	((ulong)(a)&~0xF0000000)
 
 #define	HOWMANY(x, y)	(((x)+((y)-1))/(y))
 #define ROUNDUP(x, y)	(HOWMANY((x), (y))*(y))

+ 232 - 2
sys/src/boot/pc/l.s

@@ -356,12 +356,15 @@ TEXT	tgdt(SB),$0
 	LONG	$(0xFFFF)
 	LONG	$(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
 
+	/* exec segment descriptor for 4 gigabytes (PL 0) 16-bit */
+	LONG	$(0xFFFF)
+	LONG	$(SEGG|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
+
 /*
  *  pointer to initial gdt
  */
 TEXT	tgdtptr(SB),$0
-
-	WORD	$(3*8)
+	WORD	$(4*8)
 	LONG	$tgdt-KZERO(SB)
 
 /*
@@ -847,3 +850,230 @@ DATA	pxe+0(SB)/4, $1
 #else
 DATA	pxe+0(SB)/4, $0
 #endif /* PXE */
+
+/*
+ * Save registers.
+ */
+TEXT saveregs(SB), $0
+	/* appease 8l */
+	SUBL $32, SP
+	POPL AX
+	POPL AX
+	POPL AX
+	POPL AX
+	POPL AX
+	POPL AX
+	POPL AX
+	POPL AX
+	
+	PUSHL	AX
+	PUSHL	BX
+	PUSHL	CX
+	PUSHL	DX
+	PUSHL	BP
+	PUSHL	DI
+	PUSHL	SI
+	PUSHFL
+
+	XCHGL	32(SP), AX	/* swap return PC and saved flags */
+	XCHGL	0(SP), AX
+	XCHGL	32(SP), AX
+	RET
+
+TEXT restoreregs(SB), $0
+	/* appease 8l */
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	PUSHL	AX
+	ADDL	$32, SP
+	
+	XCHGL	32(SP), AX	/* swap return PC and saved flags */
+	XCHGL	0(SP), AX
+	XCHGL	32(SP), AX
+
+	POPFL
+	POPL	SI
+	POPL	DI
+	POPL	BP
+	POPL	DX
+	POPL	CX
+	POPL	BX
+	POPL	AX
+	RET
+
+/*
+ * Assumed to be in protected mode at time of call.
+ * Switch to real mode, execute an interrupt, and
+ * then switch back to protected mode.  
+ *
+ * Assumes:
+ *
+ *	- no device interrupts are going to come in
+ *	- 0-16MB is identity mapped in page tables
+ *	- can use code segment 0x1000 in real mode
+ *		to get at l.s code
+ */
+TEXT realmodeidtptr(SB), $0
+	WORD	$(4*256-1)
+	LONG	$0
+
+TEXT realmode0(SB), $0
+	CALL	saveregs(SB)
+
+	/* switch to low code address */
+	LEAL	physcode-KZERO(SB), AX
+	JMP *AX
+
+TEXT physcode(SB), $0
+
+	/* switch to low stack */
+	MOVL	SP, AX
+	MOVL	$0x7C00, SP
+	PUSHL	AX
+
+	/* load IDT with real-mode version; GDT already fine */
+	MOVL	realmodeidtptr(SB), IDTR
+
+	/* edit INT $0x00 instruction below */
+	MOVL	realmodeintr(SB), AX
+	MOVB	AX, realmodeintrinst+1(SB)
+
+	/* disable paging */
+	MOVL	CR0, AX
+	ANDL	$0x7FFFFFFF, AX
+	MOVL	AX, CR0
+	/* JMP .+2 to clear prefetch queue*/
+	BYTE $0xEB; BYTE $0x00
+
+	/* jump to 16-bit code segment */
+/*	JMPFAR	SELECTOR(3, SELGDT, 0):$again16bit(SB) /**/
+	 BYTE	$0xEA
+	 LONG	$again16bit-KZERO(SB)
+	 WORD	$SELECTOR(3, SELGDT, 0)
+
+TEXT again16bit(SB), $0
+	/*
+	 * Now in 16-bit compatibility mode.
+	 * These are 32-bit instructions being interpreted
+	 * as 16-bit instructions.  I'm being lazy and
+	 * not using the macros because I know when
+	 * the 16- and 32-bit instructions look the same
+	 * or close enough.
+	 */
+
+	/* disable protected mode and jump to real mode cs */
+	OPSIZE; MOVL CR0, AX
+	OPSIZE; XORL BX, BX
+	OPSIZE; INCL BX
+	OPSIZE; XORL BX, AX
+	OPSIZE; MOVL AX, CR0
+
+	/* JMPFAR 0x1000:now16real */
+	 BYTE $0xEA
+	 WORD	$now16real-KZERO(SB)
+	 WORD	$0x1000
+
+TEXT now16real(SB), $0
+	/* copy the registers for the bios call */
+	LWI(0x1000, rAX)
+	MOVW	AX,SS
+	LWI(realmoderegs(SB), rBP)
+	
+	/* offsets are in Ureg */
+	LXW(44, xBP, rAX)
+	MOVW	AX, DS
+	LXW(40, xBP, rAX)
+	MOVW	AX, ES
+
+	OPSIZE; LXW(0, xBP, rDI)
+	OPSIZE; LXW(4, xBP, rSI)
+	OPSIZE; LXW(16, xBP, rBX)
+	OPSIZE; LXW(20, xBP, rDX)
+	OPSIZE; LXW(24, xBP, rCX)
+	OPSIZE; LXW(28, xBP, rAX)
+
+	CLC
+
+TEXT realmodeintrinst(SB), $0
+	INT $0x00
+
+	/* save the registers after the call */
+
+	LWI(0x7bfc, rSP)
+	OPSIZE; PUSHFL
+	OPSIZE; PUSHL AX
+
+	LWI(0x1000, rAX)
+	MOVW	AX,SS
+	LWI(realmoderegs(SB), rBP)
+	
+	OPSIZE; SXW(rDI, 0, xBP)
+	OPSIZE; SXW(rSI, 4, xBP)
+	OPSIZE; SXW(rBX, 16, xBP)
+	OPSIZE; SXW(rDX, 20, xBP)
+	OPSIZE; SXW(rCX, 24, xBP)
+	OPSIZE; POPL AX
+	OPSIZE; SXW(rAX, 28, xBP)
+
+	MOVW	DS, AX
+	OPSIZE; SXW(rAX, 44, xBP)
+	MOVW	ES, AX
+	OPSIZE; SXW(rAX, 40, xBP)
+
+	OPSIZE; POPL AX
+	OPSIZE; SXW(rAX, 64, xBP)	/* flags */
+
+	/* re-enter protected mode and jump to 32-bit code */
+	OPSIZE; MOVL $1, AX
+	OPSIZE; MOVL AX, CR0
+	
+/*	JMPFAR	SELECTOR(2, SELGDT, 0):$again32bit(SB) /**/
+	 OPSIZE
+	 BYTE $0xEA
+	 LONG	$again32bit-KZERO(SB)
+	 WORD	$SELECTOR(2, SELGDT, 0)
+
+TEXT again32bit(SB), $0
+	MOVW	$SELECTOR(1, SELGDT, 0),AX
+	MOVW	AX,DS
+	MOVW	AX,SS
+	MOVW	AX,ES
+	MOVW	AX,FS
+	MOVW	AX,GS
+
+	/* enable paging and jump to kzero-address code */
+	MOVL	CR0, AX
+	ORL	$0x80000000, AX
+	MOVL	AX, CR0
+	LEAL	again32kzero(SB), AX
+	JMP*	AX
+
+TEXT again32kzero(SB), $0
+	/* breathe a sigh of relief - back in 32-bit protected mode */
+
+	/* switch to old stack */	
+	PUSHL	AX	/* match popl below for 8l */
+	MOVL	$0x7BFC, SP
+	POPL	SP
+
+	/* restore idt */
+	MOVL	idtptr(SB),IDTR
+
+	CALL	restoreregs(SB)
+	RET
+
+TEXT realmoderegs(SB), $0
+	LONG $0; LONG $0; LONG $0; LONG $0
+	LONG $0; LONG $0; LONG $0; LONG $0
+	LONG $0; LONG $0; LONG $0; LONG $0
+	LONG $0; LONG $0; LONG $0; LONG $0
+	LONG $0; LONG $0; LONG $0; LONG $0
+
+TEXT realmodeintr(SB), $0
+	LONG $0
+

+ 4 - 0
sys/src/boot/pc/load.c

@@ -548,6 +548,10 @@ warp9(ulong entry)
 		sddetach();
 
 	consdrain();
+	
+	splhi();
+	trapdisable();
+
 	/*
 	 * This is where to push things on the stack to
 	 * boot *BSD systems, e.g.

+ 4 - 4
sys/src/boot/pc/mem.h

@@ -6,12 +6,12 @@
  * Sizes
  */
 #define	BI2BY		8			/* bits per byte */
-#define BI2WD		32			/* bits per word */
+#define	BI2WD		32			/* bits per word */
 #define	BY2WD		4			/* bytes per word */
 #define	BY2PG		4096			/* bytes per page */
 #define	WD2PG		(BY2PG/BY2WD)		/* words per page */
 #define	PGSHIFT		12			/* log(BY2PG) */
-#define PGROUND(s)	(((s)+(BY2PG-1))&~(BY2PG-1))
+#define	PGROUND(s)	(((s)+(BY2PG-1))&~(BY2PG-1))
 
 #define	MAXMACH		1			/* max # cpus system can run */
 
@@ -102,11 +102,11 @@
  */
 #define	PTEVALID	(1<<0)
 #define	PTEUNCACHED	0		/* everything is uncached */
-#define PTEWRITE	(1<<1)
+#define	PTEWRITE	(1<<1)
 #define	PTERONLY	(0<<1)
 #define	PTEKERNEL	(0<<2)
 #define	PTEUSER		(1<<2)
-#define PTESIZE		(1<<7)
+#define	PTESIZE		(1<<7)
 
 /*
  *  flag register bits that we care about

+ 30 - 0
sys/src/boot/pc/trap.c

@@ -99,6 +99,21 @@ setvec(int v, void (*r)(Ureg*, void*), void *arg)
 	}
 }
 
+void
+trapdisable(void)
+{
+	outb(Int0aux, 0xFF);
+	outb(Int1aux, 0xFF);
+}
+
+void
+trapenable(void)
+{
+	outb(Int0aux, int0mask);
+	outb(Int1aux, int1mask);
+}
+
+
 /*
  *  set up the interrupt/trap gates
  */
@@ -299,3 +314,18 @@ trap(Ureg *ur)
 		h = h->next;
 	} while(h);
 }
+
+void
+realmode(int intr, Ureg *ureg)
+{
+	extern void realmode0(void);	/* in l.s */
+	extern int realmodeintr;
+	extern Ureg realmoderegs;
+
+	realmoderegs = *ureg;
+	realmodeintr = intr;
+	trapdisable();
+	realmode0();
+	trapenable();
+	*ureg = realmoderegs;
+}

+ 1 - 1
sys/src/cmd/troff/tdef.h

@@ -169,7 +169,7 @@ extern	char	errbuf[];
 #define	NEV	3	/* environments */
 #define	EVLSZ	10	/* size of ev stack */
 
-#define	STACKSIZE (6*1024)	/* stack for macros and strings in progress */
+#define	STACKSIZE (12*1024)	/* stack for macros and strings in progress */
 #define	NHYP	10	/* max hyphens per word */
 #define	NHEX	512	/* byte size of exception word list */
 #define	NTAB	100	/* tab stops */

+ 15 - 5
sys/src/games/memo.c

@@ -4,6 +4,11 @@
 #include <draw.h>
 #include <event.h>
 
+enum { 
+	Facesize = 48 
+};
+
+
 void memoinit(void);
 void redraw(void);
 void eresized(int);
@@ -180,10 +185,19 @@ memoinit(void)
 void
 eresized(int new)
 {
+	double sq;
+	Point p;
+
 	if(new && getwindow(display, Refnone) < 0){
 		fprint(2, "can't reattach to window");
 		exits("resized");
 	}
+
+	sq = sqrt(level);
+	p = Pt(Dx(screen->r)+8, Dy(screen->r)+8);
+	if(!new || !eqpt(p, Pt(Facesize*sq+sq*4+17, Facesize*sq+sq*4+17)))
+		resize(Facesize*sq+sq*4+17);
+
 	allocblocks();
 	draw(screen, screen->r, back, nil, ZP);
 	redraw();
@@ -192,7 +206,7 @@ eresized(int new)
 void
 redraw(void)
 {
-	int i, nx, ny;
+	int i;
 	Rectangle r;
 	Point p;
 
@@ -290,9 +304,6 @@ openimage(char *path)
 	return i;
 }
 
-enum { 
-	Facesize = 48 };
-
 void
 allocblocks(void)
 {
@@ -300,7 +311,6 @@ allocblocks(void)
 	ushort i, x, y, sq;
 
 	sq = sqrt(level);
-	resize(Facesize*sq+sq*4+17);
 	r = insetrect(screen->r, 5);
 	r.max.x = r.min.x+Facesize*sq+sq*4-1;
 	r.max.y = r.min.y+Facesize*sq+sq*4-1;