From: augustss@cs.chalmers.se (Lennart Augustsson)
Newsgroups: comp.unix.bsd
Subject: Big kernel speedup
Date: 27 Jan 93 15:31:06 GMT
Organization: Dept. of CS, Chalmers, Sweden


Here are some patches that on my system (a noname 33Mhz 486) just
about *halves* the system time (at least for recompiling the kernel).
It also enables profiling of the assembly language routines in
locore.s and icu.s.

The patch does a few things:
 - if you put the NONOP option in your system configuration file
   the NOP and NOP1 macros will be empty.  These two macros
   are used to introduce delays for certain operations.
   On my machine these delays are not necessary.  I suggest that 
   you try with the NONOP option, but be careful.  Bad I/O timing
   can wreak havoc.  The best is to try this from a floppy first.
   If you can use the NONOP option this is a big save.
 - The old spl routines manipulated the ICU as soon as they
   were called.  The new ones check if what they are about to
   write to the ICU is the same as the old interrupt mask
   (quite common) and skips the out instruction if it is.
   This saves a bit since I/O can be very slow.
 - Unrelated to performance, but important for profiling the
   kernel, most assembly routines now call mcount if the system
   is compiled with profiling.  There are some new spl routines
   that do not call mcount (called nmsplXXX); they are needed
   in the profiling code itself.

I've been running with these fixes installed for several
months now without any problems.

The patch should be applied to a system where the patches in 
patchkit version 0.2 have already been applied.

	Good luck
	-- Lennart Augustsson


*** ./kern/subr_mcount.c.pre	Mon Jan 25 23:31:58 1993
--- ./kern/subr_mcount.c	Mon Jan 25 23:32:23 1993
***************
*** 185,191 ****
  	asm("movw	sr,%0" : "=g" (s));
  	asm("movw	#0x2700,sr");
  #else
! 	s = splhigh();
  #endif
  	/*
  	 * Check that frompcindex is a reasonable pc value.
--- 185,191 ----
  	asm("movw	sr,%0" : "=g" (s));
  	asm("movw	#0x2700,sr");
  #else
! 	s = nmsplhigh();
  #endif
  	/*
  	 * Check that frompcindex is a reasonable pc value.
***************
*** 267,273 ****
  #if defined(hp300)
  	asm("movw	%0,sr" : : "g" (s));
  #else
! 	splx(s);
  #endif
  	/* and fall through */
  out:
--- 267,273 ----
  #if defined(hp300)
  	asm("movw	%0,sr" : : "g" (s));
  #else
! 	nmsplx(s);
  #endif
  	/* and fall through */
  out:
*** ./i386/i386/locore.s.pre	Sun Jan 24 22:58:29 1993
--- ./i386/i386/locore.s	Wed Jan 27 02:13:42 1993
***************
*** 60,65 ****
--- 60,77 ----
  
  #include "machine/trap.h"
  
+ #ifdef GPROF
+ #define	CENTRY(x)	.globl _/**/x; \
+ 			.data; 1:; .long 0; .text; .align 2; _/**/x: \
+ 			movl $1b,%eax; call mcount 
+ #define	CENTRY2(x,y)	.globl _/**/x; .globl _/**/y; \
+ 			.data; 1:; .long 0; .text; .align 2; _/**/x: ; _/**/y: \
+ 			movl $1b,%eax; call mcount
+ #else /* GPROF */
+ #define	CENTRY(x)	.globl _/**/x; .text; .align 2; _/**/x:
+ #define	CENTRY2(x,y)	.globl _/**/x; .globl _/**/y; .text; .align 2; _/**/x: ; _/**/y:
+ #endif /* GPROF */
+ 
  /*
   * Note: This version greatly munged to avoid various assembler errors
   * that may be fixed in newer versions of gas. Perhaps newer versions
***************
*** 71,77 ****
--- 83,97 ----
  	/*note: gas copys sign bit (e.g. arithmetic >>), can't do SYSTEM>>22! */
  	.set	SYSPDROFF,0x3F8		# Page dir index of System Base
  
+ /* Some machines do not require nops.  A big speedup! */
+ #if defined(NONOP)
+ #define NOP	;
+ #define NOP1	;
+ #else
  #define	NOP	inb $0x84, %al ; inb $0x84, %al 
+ #define NOP1	inb $0x84,%al
+ #endif
+ 
  #define	ALIGN32	.align 2	/* 2^2  = 4 */
  
  /*
***************
*** 105,114 ****
--- 125,136 ----
  	.set	PPDROFF,0x3F6
  	.set	PPTEOFF,0x400-UPAGES	# 0x3FE
  
+ #if 0
  #define	ENTRY(name) \
  	.globl _/**/name; _/**/name:
  #define	ALTENTRY(name) \
  	.globl _/**/name; _/**/name:
+ #endif
  
  /*
   * Initialization
***************
*** 401,409 ****
  	/*
  	 * I/O bus instructions via C
  	 */
! 	.globl	_inb
! 	ALIGN32
! _inb:	movl	4(%esp),%edx
  	subl	%eax,%eax	# clr eax
  	NOP
  	inb	%dx,%al
--- 423,430 ----
  	/*
  	 * I/O bus instructions via C
  	 */
! CENTRY(inb)
! 	movl	4(%esp),%edx
  	subl	%eax,%eax	# clr eax
  	NOP
  	inb	%dx,%al
***************
*** 410,418 ****
  	ret
  
  
! 	.globl	_inw
! 	ALIGN32
! _inw:	movl	4(%esp),%edx
  	subl	%eax,%eax	# clr eax
  	NOP
  	inw	%dx,%ax
--- 431,438 ----
  	ret
  
  
! CENTRY(inw)
! 	movl	4(%esp),%edx
  	subl	%eax,%eax	# clr eax
  	NOP
  	inw	%dx,%ax
***************
*** 419,435 ****
  	ret
  
  
! 	.globl	_rtcin
! 	ALIGN32
! _rtcin:	movl	4(%esp),%eax
  	outb	%al,$0x70
  	subl	%eax,%eax	# clr eax
  	inb	$0x71,%al	# Compaq SystemPro 
  	ret
  
! 	.globl	_outb
! 	ALIGN32
! _outb:	movl	4(%esp),%edx
  	NOP
  	movl	8(%esp),%eax
  	outb	%al,%dx
--- 439,453 ----
  	ret
  
  
! CENTRY(rtcin)
! 	movl	4(%esp),%eax
  	outb	%al,$0x70
  	subl	%eax,%eax	# clr eax
  	inb	$0x71,%al	# Compaq SystemPro 
  	ret
  
! CENTRY(outb)
! 	movl	4(%esp),%edx
  	NOP
  	movl	8(%esp),%eax
  	outb	%al,%dx
***************
*** 436,444 ****
  	NOP
  	ret
  
! 	.globl	_outw
! 	ALIGN32
! _outw:	movl	4(%esp),%edx
  	NOP
  	movl	8(%esp),%eax
  	outw	%ax,%dx
--- 454,461 ----
  	NOP
  	ret
  
! CENTRY(outw)
! 	movl	4(%esp),%edx
  	NOP
  	movl	8(%esp),%eax
  	outw	%ax,%dx
***************
*** 449,457 ****
  	 * void bzero(void *base, u_int cnt)
  	 */
  
! 	.globl _bzero
! 	ALIGN32
! _bzero:
  	pushl	%edi
  	movl	8(%esp),%edi
  	movl	12(%esp),%ecx
--- 466,472 ----
  	 * void bzero(void *base, u_int cnt)
  	 */
  
! CENTRY(bzero)
  	pushl	%edi
  	movl	8(%esp),%edi
  	movl	12(%esp),%ecx
***************
*** 471,479 ****
  	 * fillw (pat,base,cnt)
  	 */
  
! 	.globl _fillw
! 	ALIGN32
! _fillw:
  	pushl	%edi
  	movl	8(%esp),%eax
  	movl	12(%esp),%edi
--- 486,492 ----
  	 * fillw (pat,base,cnt)
  	 */
  
! CENTRY(fillw)
  	pushl	%edi
  	movl	8(%esp),%eax
  	movl	12(%esp),%edi
***************
*** 484,492 ****
  	popl	%edi
  	ret
  
! 	.globl _bcopyb
! 	ALIGN32
! _bcopyb:
  	pushl	%esi
  	pushl	%edi
  	movl	12(%esp),%esi
--- 497,503 ----
  	popl	%edi
  	ret
  
! CENTRY(bcopyb)
  	pushl	%esi
  	pushl	%edi
  	movl	12(%esp),%esi
***************
*** 505,514 ****
  	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
  	 */
  
! 	.globl	_bcopy,_ovbcopy
! 	ALIGN32
! _ovbcopy:
! _bcopy:
  	pushl	%esi
  	pushl	%edi
  	movl	12(%esp),%esi
--- 516,523 ----
  	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
  	 */
  
! 
! CENTRY2(ovbcopy,bcopy)
  	pushl	%esi
  	pushl	%edi
  	movl	12(%esp),%esi
***************
*** 551,559 ****
  	ret
  
  #ifdef notdef
! 	.globl	_copyout
! 	ALIGN32
! _copyout:
  	movl	_curpcb, %eax
  	movl	$cpyflt, PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
--- 560,566 ----
  	ret
  
  #ifdef notdef
! CENTRY(copyout)
  	movl	_curpcb, %eax
  	movl	$cpyflt, PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
***************
*** 655,663 ****
  	movl	$ EFAULT,%eax
  	ret
  #else
! 	.globl	_copyout
! 	ALIGN32
! _copyout:
  	movl	_curpcb,%eax
  	movl	$cpyflt,PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
--- 662,668 ----
  	movl	$ EFAULT,%eax
  	ret
  #else
! CENTRY(copyout)
  	movl	_curpcb,%eax
  	movl	$cpyflt,PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
***************
*** 680,688 ****
  	movl	%eax,PCB_ONFAULT(%edx)
  	ret
  
! 	.globl	_copyin
! 	ALIGN32
! _copyin:
  	movl	_curpcb,%eax
  	movl	$cpyflt,PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
--- 685,691 ----
  	movl	%eax,PCB_ONFAULT(%edx)
  	ret
  
! CENTRY(copyin)
  	movl	_curpcb,%eax
  	movl	$cpyflt,PCB_ONFAULT(%eax) # in case we page/protection violate
  	pushl	%esi
***************
*** 716,724 ****
  #endif
  
  	# insb(port,addr,cnt)
! 	.globl	_insb
! 	ALIGN32
! _insb:
  	pushl	%edi
  	movw	8(%esp),%dx
  	movl	12(%esp),%edi
--- 719,725 ----
  #endif
  
  	# insb(port,addr,cnt)
! CENTRY(insb)
  	pushl	%edi
  	movw	8(%esp),%dx
  	movl	12(%esp),%edi
***************
*** 733,741 ****
  	ret
  
  	# insw(port,addr,cnt)
! 	.globl	_insw
! 	ALIGN32
! _insw:
  	pushl	%edi
  	movw	8(%esp),%dx
  	movl	12(%esp),%edi
--- 734,740 ----
  	ret
  
  	# insw(port,addr,cnt)
! CENTRY(insw)
  	pushl	%edi
  	movw	8(%esp),%dx
  	movl	12(%esp),%edi
***************
*** 749,757 ****
  	ret
  
  	# outsw(port,addr,cnt)
! 	.globl	_outsw
! 	ALIGN32
! _outsw:
  	pushl	%esi
  	movw	8(%esp),%dx
  	movl	12(%esp),%esi
--- 748,754 ----
  	ret
  
  	# outsw(port,addr,cnt)
! CENTRY(outsw)
  	pushl	%esi
  	movw	8(%esp),%dx
  	movl	12(%esp),%esi
***************
*** 765,773 ****
  	ret
  
  	# outsb(port,addr,cnt)
! 	.globl	_outsb
! 	ALIGN32
! _outsb:
  	pushl	%esi
  	movw	8(%esp),%dx
  	movl	12(%esp),%esi
--- 762,768 ----
  	ret
  
  	# outsb(port,addr,cnt)
! CENTRY(outsb)
  	pushl	%esi
  	movw	8(%esp),%dx
  	movl	12(%esp),%esi
***************
*** 784,792 ****
  	/*
  	 * void lgdt(struct region_descriptor *rdp);
  	 */
! 	.globl	_lgdt
! 	ALIGN32
! _lgdt:
  	/* reload the descriptor table */
  	movl	4(%esp),%eax
  	lgdt	(%eax)
--- 779,785 ----
  	/*
  	 * void lgdt(struct region_descriptor *rdp);
  	 */
! CENTRY(lgdt)
  	/* reload the descriptor table */
  	movl	4(%esp),%eax
  	lgdt	(%eax)
***************
*** 811,819 ****
  	/*
  	 * void lidt(struct region_descriptor *rdp);
  	 */
! 	.globl	_lidt
! 	ALIGN32
! _lidt:
  	movl	4(%esp),%eax
  	lidt	(%eax)
  	ret
--- 804,810 ----
  	/*
  	 * void lidt(struct region_descriptor *rdp);
  	 */
! CENTRY(lidt)
  	movl	4(%esp),%eax
  	lidt	(%eax)
  	ret
***************
*** 821,829 ****
  	/*
  	 * void lldt(u_short sel)
  	 */
! 	.globl	_lldt
! 	ALIGN32
! _lldt:
  	lldt	4(%esp)
  	ret
  
--- 812,818 ----
  	/*
  	 * void lldt(u_short sel)
  	 */
! CENTRY(lldt)
  	lldt	4(%esp)
  	ret
  
***************
*** 830,838 ****
  	/*
  	 * void ltr(u_short sel)
  	 */
! 	.globl	_ltr
! 	ALIGN32
! _ltr:
  	ltr	4(%esp)
  	ret
  
--- 819,825 ----
  	/*
  	 * void ltr(u_short sel)
  	 */
! CENTRY(ltr)
  	ltr	4(%esp)
  	ret
  
***************
*** 839,872 ****
  	/*
  	 * void lcr3(caddr_t cr3)
  	 */
! 	.globl	_lcr3
! 	.globl	_load_cr3
! 	ALIGN32
! _load_cr3:
! _lcr3:
! 	inb	$0x84,%al	# check wristwatch
  	movl	4(%esp),%eax
   	orl	$ I386_CR3PAT,%eax
  	movl	%eax,%cr3
! 	inb	$0x84,%al	# check wristwatch
  	ret
  
  	# tlbflush()
! 	.globl	_tlbflush
! 	ALIGN32
! _tlbflush:
! 	inb	$0x84,%al	# check wristwatch
  	movl	%cr3,%eax
   	orl	$ I386_CR3PAT,%eax
  	movl	%eax,%cr3
! 	inb	$0x84,%al	# check wristwatch
  	ret
  
  	# lcr0(cr0)
! 	.globl	_lcr0,_load_cr0
! 	ALIGN32
! _lcr0:
! _load_cr0:
  	movl	4(%esp),%eax
  	movl	%eax,%cr0
  	ret
--- 826,850 ----
  	/*
  	 * void lcr3(caddr_t cr3)
  	 */
! CENTRY2(lcr3,load_cr3)
! 	NOP1
  	movl	4(%esp),%eax
   	orl	$ I386_CR3PAT,%eax
  	movl	%eax,%cr3
! 	NOP1
  	ret
  
  	# tlbflush()
! CENTRY(tlbflush)
! 	NOP1
  	movl	%cr3,%eax
   	orl	$ I386_CR3PAT,%eax
  	movl	%eax,%cr3
! 	NOP1
  	ret
  
  	# lcr0(cr0)
! CENTRY2(lcr0,load_cr0)
  	movl	4(%esp),%eax
  	movl	%eax,%cr0
  	ret
***************
*** 895,903 ****
  	ret
  
  	# ssdtosd(*ssdp,*sdp)
! 	.globl	_ssdtosd
! 	ALIGN32
! _ssdtosd:
  	pushl	%ebx
  	movl	8(%esp),%ecx
  	movl	8(%ecx),%ebx
--- 873,879 ----
  	ret
  
  	# ssdtosd(*ssdp,*sdp)
! CENTRY(ssdtosd)
  	pushl	%ebx
  	movl	8(%esp),%ecx
  	movl	8(%ecx),%ebx
***************
*** 920,928 ****
  /*
   * {fu,su},{byte,word}
   */
! 	ALIGN32
! ALTENTRY(fuiword)
! ENTRY(fuword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx)
  	movl	4(%esp),%edx
--- 896,902 ----
  /*
   * {fu,su},{byte,word}
   */
! CENTRY2(fuword,fuiword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx)
  	movl	4(%esp),%edx
***************
*** 931,938 ****
  	movl	$0,PCB_ONFAULT(%ecx)
  	ret
  	
! 	ALIGN32
! ENTRY(fusword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
--- 905,911 ----
  	movl	$0,PCB_ONFAULT(%ecx)
  	ret
  	
! CENTRY(fusword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
***************
*** 941,949 ****
  	movl	$0,PCB_ONFAULT(%ecx)
  	ret
  	
! 	ALIGN32
! ALTENTRY(fuibyte)
! ENTRY(fubyte)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
--- 914,920 ----
  	movl	$0,PCB_ONFAULT(%ecx)
  	ret
  	
! CENTRY2(fubyte,fuibyte)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
***************
*** 960,968 ****
  	decl	%eax
  	ret
  
! 	ALIGN32
! ALTENTRY(suiword)
! ENTRY(suword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
--- 931,937 ----
  	decl	%eax
  	ret
  
! CENTRY2(suword,suiword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
***************
*** 992,999 ****
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  	
! 	ALIGN32
! ENTRY(susword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
--- 961,967 ----
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  	
! CENTRY(susword)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
***************
*** 1021,1029 ****
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  
! 	ALIGN32
! ALTENTRY(suibyte)
! ENTRY(subyte)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
--- 989,995 ----
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  
! CENTRY2(subyte,suibyte)
  	movl	_curpcb,%ecx
  	movl	$fusufault,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	movl	4(%esp),%edx
***************
*** 1051,1058 ****
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  
! 	ALIGN32
! 	ENTRY(setjmp)
  	movl	4(%esp),%eax
  	movl	%ebx, 0(%eax)		# save ebx
  	movl	%esp, 4(%eax)		# save esp
--- 1017,1023 ----
  	movl	%eax,PCB_ONFAULT(%ecx) #in case we page/protection violate
  	ret
  
! CENTRY(setjmp)
  	movl	4(%esp),%eax
  	movl	%ebx, 0(%eax)		# save ebx
  	movl	%esp, 4(%eax)		# save esp
***************
*** 1064,1071 ****
  	xorl	%eax,%eax		# return (0);
  	ret
  
! 	ALIGN32
! 	ENTRY(longjmp)
  	movl	4(%esp),%eax
  	movl	 0(%eax),%ebx		# restore ebx
  	movl	 4(%eax),%esp		# restore esp
--- 1029,1035 ----
  	xorl	%eax,%eax		# return (0);
  	ret
  
! CENTRY(longjmp)
  	movl	4(%esp),%eax
  	movl	 0(%eax),%ebx		# restore ebx
  	movl	 4(%eax),%esp		# restore esp
***************
*** 1096,1103 ****
   *
   * Call should be made at spl6(), and p->p_stat should be SRUN
   */
! 	ALIGN32
! ENTRY(setrq)
  	movl	4(%esp),%eax
  	cmpl	$0,P_RLINK(%eax)	# should not be on q already
  	je	set1
--- 1060,1066 ----
   *
   * Call should be made at spl6(), and p->p_stat should be SRUN
   */
! CENTRY(setrq)
  	movl	4(%esp),%eax
  	cmpl	$0,P_RLINK(%eax)	# should not be on q already
  	je	set1
***************
*** 1123,1130 ****
   *
   * Call should be made at spl6().
   */
! 	ALIGN32
! ENTRY(remrq)
  	movl	4(%esp),%eax
  	movzbl	P_PRI(%eax),%edx
  	shrl	$2,%edx
--- 1086,1092 ----
   *
   * Call should be made at spl6().
   */
! CENTRY(remrq)
  	movl	4(%esp),%eax
  	movzbl	P_PRI(%eax),%edx
  	shrl	$2,%edx
***************
*** 1163,1169 ****
  	ALIGN32
  Idle:
  idle:
! 	call	_spl0
  	cmpl	$0,_whichqs
  	jne	sw1
  	hlt		# wait for interrupt
--- 1125,1131 ----
  	ALIGN32
  Idle:
  idle:
! 	call	_nmspl0
  	cmpl	$0,_whichqs
  	jne	sw1
  	hlt		# wait for interrupt
***************
*** 1178,1185 ****
  /*
   * Swtch()
   */
! 	ALIGN32
! ENTRY(swtch)
  
  	incl	_cnt+V_SWTCH
  
--- 1140,1146 ----
  /*
   * Swtch()
   */
! CENTRY(swtch)
  
  	incl	_cnt+V_SWTCH
  
***************
*** 1303,1316 ****
  	movl	%edx,_curpcb
  
  	/* pushl	PCB_IML(%edx)
! 	call	_splx
  	popl	%eax*/
  
  	movl	%edx,%eax		# return (1);
  	ret
  
- 	.globl	_mvesp
  	ALIGN32
  _mvesp:	movl	%esp,%eax
  	ret
  /*
--- 1264,1277 ----
  	movl	%edx,_curpcb
  
  	/* pushl	PCB_IML(%edx)
! 	call	_nmsplx
  	popl	%eax*/
  
  	movl	%edx,%eax		# return (1);
  	ret
  
  	ALIGN32
+ 	.globl	_mvesp
  _mvesp:	movl	%esp,%eax
  	ret
  /*
***************
*** 1322,1329 ****
   * Since this code requires a parameter from the "old" stack,
   * pass it back as a return value.
   */
! 	ALIGN32
! ENTRY(swtch_to_inactive)
  	popl	%edx			# old pc
  	popl	%eax			# arg, our return value
  	movl	_IdlePTD,%ecx
--- 1283,1289 ----
   * Since this code requires a parameter from the "old" stack,
   * pass it back as a return value.
   */
! CENTRY(swtch_to_inactive)
  	popl	%edx			# old pc
  	popl	%eax			# arg, our return value
  	movl	_IdlePTD,%ecx
***************
*** 1337,1344 ****
   * Update pcb, saving current processor state and arranging
   * for alternate return ala longjmp in swtch if altreturn is true.
   */
! 	ALIGN32
! ENTRY(savectx)
  	movl	4(%esp), %ecx
  	movw	_cpl, %ax
  	movw	%ax,  PCB_IML(%ecx)
--- 1297,1303 ----
   * Update pcb, saving current processor state and arranging
   * for alternate return ala longjmp in swtch if altreturn is true.
   */
! CENTRY(savectx)
  	movl	4(%esp), %ecx
  	movw	_cpl, %ax
  	movw	%ax,  PCB_IML(%ecx)
***************
*** 1388,1395 ****
   * update profiling information for the user process.
   */
  
! 	ALIGN32
! ENTRY(addupc)
  	pushl %ebp
  	movl %esp,%ebp
  	movl 12(%ebp),%edx		/* up */
--- 1347,1353 ----
   * update profiling information for the user process.
   */
  
! CENTRY(addupc)
  	pushl %ebp
  	movl %esp,%ebp
  	movl 12(%ebp),%edx		/* up */
***************
*** 1541,1547 ****
  calltrap:
  	incl	_cnt+V_TRAP
  	call	_trap
! 	call	_spl0
  	pop %es
  	pop %ds
  	popal
--- 1499,1505 ----
  calltrap:
  	incl	_cnt+V_TRAP
  	call	_trap
! 	call	_nmspl0
  	pop %es
  	pop %ds
  	popal
***************
*** 1585,1591 ****
  	movw	%ax,%ds
  	movw	%ax,%es
  	call	_syscall
! 	call	_spl0
  	movw	__udatasel,%ax	# switch back to user segments
  	movw	%ax,%ds
  	movw	%ax,%es
--- 1543,1549 ----
  	movw	%ax,%ds
  	movw	%ax,%es
  	call	_syscall
! 	call	_nmspl0
  	movw	__udatasel,%ax	# switch back to user segments
  	movw	%ax,%ds
  	movw	%ax,%es
***************
*** 1594,1602 ****
  	popfl
  	lret
  
! 	ALIGN32
! ENTRY(htonl)
! ENTRY(ntohl)
  	movl	4(%esp),%eax
  	xchgb	%al,%ah
  	roll	$16,%eax
--- 1552,1558 ----
  	popfl
  	lret
  
! CENTRY2(ntohl,htonl)
  	movl	4(%esp),%eax
  	xchgb	%al,%ah
  	roll	$16,%eax
***************
*** 1603,1611 ****
  	xchgb	%al,%ah
  	ret
  
! 	ALIGN32
! ENTRY(htons)
! ENTRY(ntohs)
  	movzwl	4(%esp),%eax
  	xchgb	%al,%ah
  	ret
--- 1559,1565 ----
  	xchgb	%al,%ah
  	ret
  
! CENTRY2(ntohs,htons)
  	movzwl	4(%esp),%eax
  	xchgb	%al,%ah
  	ret
*** ./i386/isa/icu.s.pre	Sun Jan 24 22:58:30 1993
--- ./i386/isa/icu.s	Wed Jan 27 02:14:37 1993
***************
*** 123,129 ****
  	call	c ; \
  1:
  
! 	call	_splnet
  
  	DONET(NETISR_RAW,_rawintr)
  #ifdef INET
--- 123,129 ----
  	call	c ; \
  1:
  
! 	call	_nmsplnet
  
  	DONET(NETISR_RAW,_rawintr)
  #ifdef INET
***************
*** 147,163 ****
  	outb	%al,$ IO_ICU2+1
  	NOP
  #else
! 	call	_spl0
  #endif
  
  	btrl	$ NETISR_SCLK,_netisr
  	jnb	1f
  	# back to an interrupt frame for a moment
! 	call	_splsoftclock
  	pushl	$0xff	# dummy intr
  	call	_softclock
  	popl	%eax
! 	call	_spl0
  
  	# jmp	2f
  
--- 147,163 ----
  	outb	%al,$ IO_ICU2+1
  	NOP
  #else
! 	call	_nmspl0
  #endif
  
  	btrl	$ NETISR_SCLK,_netisr
  	jnb	1f
  	# back to an interrupt frame for a moment
! 	call	_nmsplsoftclock
  	pushl	$0xff	# dummy intr
  	call	_softclock
  	popl	%eax
! 	call	_nmspl0
  
  	# jmp	2f
  
***************
*** 177,296 ****
  /*
   * Interrupt priority mechanism
   *
-  * Two flavors	-- imlXX masks relative to ISA noemenclature (for PC compat sw)
   *		-- splXX masks with group mechanism for BSD purposes
   */
  
! 	.globl	_splhigh
! 	.globl	_splclock
! 	ALIGN32
! _splhigh:
! _splclock:
! 	cli				# disable interrupts
! 	NOP
! 	movw	$0xffff,%ax		# set new priority level
! 	movw	%ax,%dx
! 	# orw	_imen,%ax		# mask off those not enabled yet
! 	movw	%ax,%cx
! 	outb	%al,$ IO_ICU1+1		/* update icu's */
! 	NOP
! 	movb	%ah,%al
! 	outb	%al,$ IO_ICU2+1
! 	NOP
! 	movzwl	_cpl,%eax		# return old priority
! 	movw	%dx,_cpl		# set new priority level
! 	sti				# enable interrupts
! 	ret
! 
! 	.globl	_spltty			# block clists
! 	ALIGN32
! _spltty:
! 	cli				# disable interrupts
! 	NOP
! 	movw	_cpl,%ax
! 	orw	_ttymask,%ax
! 	movw	%ax,%dx
! 	orw	_imen,%ax		# mask off those not enabled yet
! 	movw	%ax,%cx
! 	outb	%al,$ IO_ICU1+1		/* update icu's */
! 	NOP
! 	movb	%ah,%al
! 	outb	%al,$ IO_ICU2+1
! 	NOP
! 	movzwl	_cpl,%eax		# return old priority
! 	movw	%dx,_cpl		# set new priority level
! 	sti				# enable interrupts
! 	ret
  
! 	.globl	_splimp
! 	.globl	_splnet
! 	ALIGN32
! _splimp:
! _splnet:
! 	cli				# disable interrupts
! 	NOP
! 	movw	_cpl,%ax
! 	orw	_netmask,%ax
! 	movw	%ax,%dx
! 	orw	_imen,%ax		# mask off those not enabled yet
! 	movw	%ax,%cx
! 	outb	%al,$ IO_ICU1+1		/* update icu's */
! 	NOP
! 	movb	%ah,%al
! 	outb	%al,$ IO_ICU2+1
! 	NOP
! 	movzwl	_cpl,%eax		# return old priority
! 	movw	%dx,_cpl		# set new priority level
! 	sti				# enable interrupts
  	ret
  
- 	.globl	_splbio	
- 	ALIGN32
- _splbio:
- 	cli				# disable interrupts
- 	NOP
- 	movw	_cpl,%ax
- 	orw	_biomask,%ax
- 	movw	%ax,%dx
- 	orw	_imen,%ax		# mask off those not enabled yet
- 	movw	%ax,%cx
- 	outb	%al,$ IO_ICU1+1		/* update icu's */
- 	NOP
- 	movb	%ah,%al
- 	outb	%al,$ IO_ICU2+1
- 	NOP
- 	movzwl	_cpl,%eax		# return old priority
- 	movw	%dx,_cpl		# set new priority level
- 	sti				# enable interrupts
- 	ret
  
! 	.globl	_splsoftclock
! 	ALIGN32
! _splsoftclock:
  	cli				# disable interrupts
  	NOP
! 	movw	_cpl,%ax
! 	orw	$0x8000,%ax		# set new priority level
! 	movw	%ax,%dx
! 	orw	_imen,%ax		# mask off those not enabled yet
! 	movw	%ax,%cx
! 	outb	%al,$ IO_ICU1+1		/* update icu's */
! 	NOP
! 	movb	%ah,%al
! 	outb	%al,$ IO_ICU2+1
! 	NOP
! 	movzwl	_cpl,%eax		# return old priority
! 	movw	%dx,_cpl		# set new priority level
! 	sti				# enable interrupts
! 	ret
  
- 	.globl _splnone
- 	.globl _spl0
- 	ALIGN32
- _splnone:
- _spl0:
- 	cli				# disable interrupts
- 	NOP
  	pushl	_cpl			# save old priority
  	movw	_cpl,%ax
  	orw	_netmask,%ax		# mask off those network devices
--- 177,235 ----
  /*
   * Interrupt priority mechanism
   *
   *		-- splXX masks with group mechanism for BSD purposes
   */
  
! #define NMENTRY(x) 	.globl _nm/**/x; _nm/**/x:
  
! #define SPL(mask) \
! 	cli			; /* turn off interrupts */ \
! 	NOP 			; /* wait a little */ \
! 	movzwl	_cpl,%eax 	; /* get cpl */ \
! 	movl	%eax,%ecx	; /* ... and save it */ \
! 	orw	mask,%ax	; /* compute new cpl */ \
! 	cmpw	%ax,%cx		; /* same as old? */ \
! 	je	1f		; /* yes, skip ICU manipulation */ \
! 	movw	%ax,_cpl	; /* save new cpl */ \
! 	orw	_imen,%ax	; /* mask off disabled interrupts */ \
! 	outb	%al,$ IO_ICU1+1	; /* juggle the ICU */ \
! 	NOP 			; \
! 	movb	%ah,%al		; \
! 	outb	%al,$ IO_ICU2+1	; \
! 	NOP			; \
! 	movl	%ecx,%eax	; /* use old cpl as return value */ \
! 1:				; \
! 	sti			; /* enable interrupts again */ \
  	ret
  
  
! CENTRY2(splhigh,splclock)
! NMENTRY(splhigh)
! NMENTRY(splclock)
! 	SPL($0xffff)
! 
! CENTRY(spltty)				# block clists
! 	SPL(_ttymask)
! 
! CENTRY2(splimp,splnet)
! NMENTRY(splnet)
! 	SPL(_netmask)
! 
! CENTRY(splbio)
! 	SPL(_biomask)
! 
! CENTRY(splsoftclock)
! NMENTRY(splsoftclock)
! 	SPL($0x8000)
! 
! CENTRY2(splnone,spl0)
! NMENTRY(spl0)
! Lspl0jmp:
  	cli				# disable interrupts
  	NOP
! 	cmpl	$0,_netisr
! 	je	Lspl0
  
  	pushl	_cpl			# save old priority
  	movw	_cpl,%ax
  	orw	_netmask,%ax		# mask off those network devices
***************
*** 310,319 ****
  	cli				# disable interrupts
  	popl	_cpl			# save old priority
  	NOP
! 	movw	$0,%ax			# set new priority level
! 	movw	%ax,%dx
! 	orw	_imen,%ax		# mask off those not enabled yet
! 	movw	%ax,%cx
  	outb	%al,$ IO_ICU1+1		/* update icu's */
  	NOP
  	movb	%ah,%al
--- 249,256 ----
  	cli				# disable interrupts
  	popl	_cpl			# save old priority
  	NOP
! Lspl0:
! 	movw	_imen,%ax		# mask off those not enabled yet
  	outb	%al,$ IO_ICU1+1		/* update icu's */
  	NOP
  	movb	%ah,%al
***************
*** 320,339 ****
  	outb	%al,$ IO_ICU2+1
  	NOP
  	movzwl	_cpl,%eax		# return old priority
! 	movw	%dx,_cpl		# set new priority level
  	sti				# enable interrupts
  	ret
  
! 	.globl _splx
! 	ALIGN32
! _splx:
  	cli				# disable interrupts
  	NOP
  	movw	4(%esp),%ax		# new priority level
  	movw	%ax,%dx
  	cmpw	$0,%dx
! 	je	_spl0			# going to "zero level" is special
  
  	orw	_imen,%ax		# mask off those not enabled yet
  	movw	%ax,%cx
  	outb	%al,$ IO_ICU1+1		/* update icu's */
--- 257,278 ----
  	outb	%al,$ IO_ICU2+1
  	NOP
  	movzwl	_cpl,%eax		# return old priority
! 	movw	$0,_cpl			# set new priority level
  	sti				# enable interrupts
  	ret
  
! CENTRY(splx)
! NMENTRY(splx)
  	cli				# disable interrupts
  	NOP
  	movw	4(%esp),%ax		# new priority level
  	movw	%ax,%dx
  	cmpw	$0,%dx
! 	je	Lspl0jmp		# going to "zero level" is special
  
+ 	cmpw	%dx,_cpl		# same as we have now ?
+ 	je	1f			# yes, skip ICU handling
+ 
  	orw	_imen,%ax		# mask off those not enabled yet
  	movw	%ax,%cx
  	outb	%al,$ IO_ICU1+1		/* update icu's */
***************
*** 341,346 ****
--- 280,286 ----
  	movb	%ah,%al
  	outb	%al,$ IO_ICU2+1
  	NOP
+ 1:
  	movzwl	_cpl,%eax		# return old priority
  	movw	%dx,_cpl		# set new priority level
  	sti				# enable interrupts

-- 

	-- Lennart Augustsson
[This signature is intentionally left blank.]
Newsgroups: comp.unix.bsd