[comp.os.minix] Patch 1 for 386 kernel

evans@ditsyda.oz (Bruce.Evans) (07/02/90)

Although my 386 Minix kernel has not been posted yet, this bug fix seems
important enough to post. Pages were being remapped from low memory to
extended memory beginning at 2M even when 2M was not the end of extended
memory. This causes the corresponding number of pages at the top of the
final memory memory map to be bad. With more than 1M of extended memory,
the top pages are rarely allocated so the bug would not bite often. The
bug only affects the most recent (June 1990) version of the kernel.

There are bugs in test8 that seem to be more dangerous with this kernel.
Test8 calls mknod with the wrong number of arguments. This creates
directories and files with "random" sizes, including possibly negative
sizes. Big sizes cause directory seaches to take "forever", and negative
sizes may cause panics. Test8 should not be run until these calls and
mknod are fixed.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  klib386.x.crc klib386.x.cdif
# Wrapped by evans@ditsyda on Mon Jul  2 22:36:27 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'klib386.x.crc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'klib386.x.crc'\"
else
echo shar: Extracting \"'klib386.x.crc'\" \(47 characters\)
sed "s/^X//" >'klib386.x.crc' <<'END_OF_FILE'
X54263  20437 klib386.x
X43247  19739 klib386.x~
END_OF_FILE
if test 47 -ne `wc -c <'klib386.x.crc'`; then
    echo shar: \"'klib386.x.crc'\" unpacked with wrong size!
fi
# end of 'klib386.x.crc'
fi
if test -f 'klib386.x.cdif' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'klib386.x.cdif'\"
else
echo shar: Extracting \"'klib386.x.cdif'\" \(3717 characters\)
sed "s/^X//" >'klib386.x.cdif' <<'END_OF_FILE'
X*** dist/klib386.x	Thu Apr 26 20:23:07 1990
X--- klib386.x	Mon Jul  2 22:23:53 1990
X***************
X*** 44,55 ****
X  /* Paging constants. */
X! #define CR0_PG		0x80000000
X! #define LOG2_MEM_UNIT	10
X! #define LOG2_PAGE_SIZE	12
X! #define MEM_UNIT	1024
X! #define NR_PAGE_DIRS	1
X! #define NR_PAGE_TABLES	4
X! #define PAGE_DATA_SIZE	4
X! #define PAGE_SIZE	0x1000
X! #define PAGE_DIR_SIZE	0x1000
X! #define PAGE_TABLE_SIZE	0x1000
X  
X--- 44,57 ----
X  /* Paging constants. */
X! #define CR0_PG			0x80000000
X! #define EXTENDED_MEM_BASE	0x100000
X! #define LOG2_MEM_UNIT		10
X! #define LOG2_PAGE_DATA_SIZE	2
X! #define LOG2_PAGE_SIZE		12
X! #define MEM_UNIT		1024
X! #define NR_PAGE_DIRS		1
X! #define NR_PAGE_TABLES		4
X! #define PAGE_DATA_SIZE		4
X! #define PAGE_SIZE		0x1000
X! #define PAGE_DIR_SIZE		0x1000
X! #define PAGE_TABLE_SIZE		0x1000
X  
X***************
X*** 328,330 ****
X  	mov	cr3,edi			| use for page directory base
X! 	
X  	push	es
X--- 328,330 ----
X  	mov	cr3,edi			| use for page directory base
X! 
X  	push	es
X***************
X*** 332,334 ****
X  	mov	es,ax
X! 	
X  	mov	eax,_low_memsize
X--- 332,334 ----
X  	mov	es,ax
X! 
X  	mov	eax,_low_memsize
X***************
X*** 335,337 ****
X  	mov	ecx,edi
X! 	shr	ecx,#LOG2_MEM_UNIT	| assume MEM_UNIT <= PAGE_SIZE
X  	mov	_low_memsize,ecx	| now it ends at the page directory
X--- 335,340 ----
X  	mov	ecx,edi
X! #if MEM_UNIT > PAGE_SIZE
X! #error /* several calculations depend on MEM_UNIT <= PAGE_SIZE */
X! #endif
X! 	shr	ecx,#LOG2_MEM_UNIT
X  	mov	_low_memsize,ecx	| now it ends at the page directory
X***************
X*** 342,345 ****
X  	shl	eax,#LOG2_PAGE_SIZE-LOG2_MEM_UNIT
X! 	add	_ext_memsize,eax
X! 	
X  	lea	eax,PAGE_DIR_SIZE+0x07(edi)	| 0x07 is some access bits
X--- 345,353 ----
X  	shl	eax,#LOG2_PAGE_SIZE-LOG2_MEM_UNIT
X! 	mov	ecx,_ext_memsize
X! 	and	ecx,#!(PAGE_SIZE/MEM_UNIT-1)	| round down so top of extended
X! 					| memory is at a page boundary
X! 	push	ecx
X! 	add	ecx,eax
X! 	mov	_ext_memsize,ecx
X! 
X  	lea	eax,PAGE_DIR_SIZE+0x07(edi)	| 0x07 is some access bits
X***************
X*** 350,352 ****
X  	loop	init_page_dir
X! 	
X  	sub	eax,eax
X--- 358,360 ----
X  	loop	init_page_dir
X! 
X  	sub	eax,eax
X***************
X*** 355,357 ****
X  	stosd
X! 	
X  	mov	eax,#0x07
X--- 363,365 ----
X  	stosd
X! 
X  	mov	eax,#0x07
X***************
X*** 365,369 ****
X  	or	eax,#0x07
X! 	add	edi,#-NR_PAGE_TABLES*PAGE_TABLE_SIZE+0x200000/PAGE_SIZE*PAGE_DATA_SIZE
X! 					| 2M is end of extended mem
X  	pop	ecx			| number of pages stolen from low mem
X  init_stolen_page_table:
X--- 373,386 ----
X  	or	eax,#0x07
X! 	add	edi,#-NR_PAGE_TABLES*PAGE_TABLE_SIZE+EXTENDED_MEM_BASE/PAGE_SIZE*PAGE_DATA_SIZE
X! 					| page table for beginning of ext mem
X! 	pop	ecx			| size of extended memory
X! #if LOG2_MEM_UNIT-LOG2_PAGE_SIZE+LOG2_PAGE_DATA_SIZE > 0
X! 	shl	ecx,#LOG2_MEM_UNIT-LOG2_PAGE_SIZE+LOG2_PAGE_DATA_SIZE
X! #endif
X! #if LOG2_MEM_UNIT-LOG2_PAGE_SIZE+LOG2_PAGE_DATA_SIZE < 0
X! 	shr	ecx,#LOG2_PAGE_SIZE-LOG2_PAGE_DATA_SIZE-LOG2_MEM_UNIT
X! #endif
X! 	add	edi,ecx			| page table for orig end of ext mem
X  	pop	ecx			| number of pages stolen from low mem
X+ 	jcxz	over_init_stolen_page_table
X  init_stolen_page_table:
X***************
X*** 372,374 ****
X  	loop	init_stolen_page_table
X! 	
X  #if UNPORTABLE_PAGING
X--- 389,392 ----
X  	loop	init_stolen_page_table
X! over_init_stolen_page_table:
X! 
X  #if UNPORTABLE_PAGING
X***************
X*** 382,384 ****
X  	add	_ext_memsize,#0x60000/MEM_UNIT
X! 	
X  	mov	eax,#0xB0007		| Hercules memory at 0xB0000
X--- 400,402 ----
X  	add	_ext_memsize,#0x60000/MEM_UNIT
X! 
X  	mov	eax,#0xB0007		| Hercules memory at 0xB0000
X***************
X*** 390,392 ****
X  	add	_ext_memsize,#0x8000/MEM_UNIT
X! 	
X  #endif /* UNPORTABLE_PAGING */
X--- 408,410 ----
X  	add	_ext_memsize,#0x8000/MEM_UNIT
X! 
X  #endif /* UNPORTABLE_PAGING */
END_OF_FILE
if test 3717 -ne `wc -c <'klib386.x.cdif'`; then
    echo shar: \"'klib386.x.cdif'\" unpacked with wrong size!
fi
# end of 'klib386.x.cdif'
fi
echo shar: End of shell archive.
exit 0
-- 
Bruce Evans		evans@ditsyda.syd.dit.csiro.au