delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/08/12/13:58:45

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10108121754.AA12952@clio.rice.edu>
Subject: Latest crt0 patches (+block sizing for core)
To: djgpp-workers AT delorie DOT com (DJGPP developers)
Date: Sun, 12 Aug 2001 12:54:59 -0500 (CDT)
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

Here are the latest crt0 diffs.  They include memory handle sizing for dumps,
fixes for address space wraps, and fixes for too many memory handles.
Documentation updates included.  4 patched files.  If there are no new
comments I'd like to get these into cvs.


*** crt0.S_203	Wed Aug  1 20:28:48 2001
--- crt0.S	Sat Aug 11 19:42:50 2001
***************
*** 46,49 ****
--- 46,50 ----
  	.long	___djgpp_memory_handle_list+8		/* Next free, first for stub */
  	.comm	___djgpp_memory_handle_list, 2048	/* Enough for 256 handles */
+ 	.comm	___djgpp_memory_handle_size, 1024	/* Enough for 256 handles */
  #endif
  
***************
*** 145,155 ****
  	int	$0x31		/* set access rights for alias */
  
! /* Maybe set our DS limit to 4Gb in size if flag set */
! 	testb	$0x80, __crt0_startup_flags		/* include/crt0.h */
! 	jz	2f
  	movw	$0xffff, %cx
  	movl	%ecx, %edx
  	movw	$0x0008, %ax				/* reset alias limit to -1 */
  	int	$0x31
  	movw	%cs, %bx
  	movw	$0x0008, %ax				/* reset CS limit to -1 */
--- 146,163 ----
  	int	$0x31		/* set access rights for alias */
  
! /* Test set the limit on the alias to 4Gb (it may be reset on stack malloc) */
  	movw	$0xffff, %cx
  	movl	%ecx, %edx
  	movw	$0x0008, %ax				/* reset alias limit to -1 */
  	int	$0x31
+ 	lsl	%ebx, %ebx				/* Should be -1 */
+ 	incl	%ebx
+ 	jz	16f
+ 	andb	$0x7f, __crt0_startup_flags		/* clear it if failure */
+ 	orb	$0x80, __crt0_startup_flags+1		/* Wrap is *BAD* */
+ 	jmp	2f
+ /* Maybe set our DS limit to 4Gb in size if flag set */
+ 16:	testb	$0x80, __crt0_startup_flags		/* include/crt0.h */
+ 	jz	2f
  	movw	%cs, %bx
  	movw	$0x0008, %ax				/* reset CS limit to -1 */
***************
*** 158,165 ****
  	movw	$0x0008, %ax				/* reset DS limit to -1 */
  	int	$0x31
- 	lsl	%ebx, %ebx				/* Should be -1 */
- 	incl	%ebx
- 	jz	2f
- 	andb	$0x7f, __crt0_startup_flags		/* clear it if failure */
  2:
  #ifdef MULTIBLOCK
--- 166,169 ----
***************
*** 234,237 ****
--- 238,242 ----
  	movl	STUBINFO_INITIAL_SIZE, %eax
  	movl	%eax, __what_size_dpmi_thinks_we_are
+ 	movl	%eax, ___djgpp_memory_handle_size
  
  /* Maybe lock the initial block, expects BX:CX */
***************
*** 482,485 ****
--- 487,491 ----
  	movl	%edi, ___djgpp_memory_handle_list		/* store new handle */
  	movw	%si, ___djgpp_memory_handle_list+2
+ 	movl	%edx, ___djgpp_memory_handle_size
  	movl	%ecx, ___djgpp_base_address			/* store new base address */
  	movw	%bx, ___djgpp_base_address+2
***************
*** 500,506 ****
  /* Current allocation not large enough, get another block */
  10:	movl	%ecx, %eax					/* Add amt */
! 	pushl	%eax						/* Save orig */
! 	addl	$0x0000ffff, %eax				/* round up to 64K block */
! 	andl	$0xffff0000, %eax
  	movl	%eax, %edx					/* Save size */
  	movl	%eax, %ecx
--- 506,527 ----
  /* Current allocation not large enough, get another block */
  10:	movl	%ecx, %eax					/* Add amt */
! 14:	pushl	%eax						/* Save orig */
! 
! /* Prevent handle exhaustion:  Block size of later allocated handles is larger.
!    Block Size = 2^(16+handle#/32) which allows 512Mb on default 256 handles. */
! 
! 	movl	___djgpp_memory_handle_pointer, %ecx
! 	xorl	%edx, %edx
! 	subl	$___djgpp_memory_handle_list, %ecx		/* 8*hand# */
! 	shrl	$8, %ecx	/* hand#/32, tuneable, big shifts = old way */
! 	incl	%edx						/* EDX = 1 */
! 	addb	$16, %cl					/* 2^16=64K */
! 	shll	%cl, %edx
! 	decl	%edx
! 	movl	%edx, %ecx
! 	notl	%edx
! 	addl	%ecx, %eax				/* Round up to block */
! 	andl	%edx, %eax
! 
  	movl	%eax, %edx					/* Save size */
  	movl	%eax, %ecx
***************
*** 512,521 ****
  	jc	brk_error
  
- 	pushl	%edx						/* Size */
- 	call	lock_memory
- 
  	pushw	%bx
  	pushw	%cx
  	popl	%ecx						/* Linear address */
  	subl	___djgpp_base_address, %ecx			/* New dpmi size */
  	cmpl	%ecx, __what_size_dpmi_thinks_we_are		/* Back to back ? */
--- 533,547 ----
  	jc	brk_error
  
  	pushw	%bx
  	pushw	%cx
  	popl	%ecx						/* Linear address */
+ 	cmpl	___djgpp_base_address, %ecx			/* New dpmi size */
+ 	jns	15f						/* Ignore this block */
+ 	testb	$0x80, __crt0_startup_flags+1		/* include/crt0.h */
+ 	jnz	14b
+ 15:
+ 	pushl	%edx						/* Size */
+ 	call	lock_memory
+ 
  	subl	___djgpp_base_address, %ecx			/* New dpmi size */
  	cmpl	%ecx, __what_size_dpmi_thinks_we_are		/* Back to back ? */
***************
*** 532,535 ****
--- 558,567 ----
  	movw	%si, 2(%ebx)
  	movl	%ecx, 4(%ebx)
+ /* Handle Offset / 2 = Offset into Size Array */
+ 	movl	%ebx, %edi
+ 	subl	$___djgpp_memory_handle_list, %edi
+ 	shrl	$1, %edi
+ 	addl	$___djgpp_memory_handle_size, %edi
+ 	movl	%edx, (%edi)
  	addl	$8, %ebx
  	cmpl	$___djgpp_memory_handle_list+2040, %ebx		/* At end? */



*** crt0.h_203	Sun Jul 26 08:33:36 1998
--- crt0.h	Sat Aug 11 19:46:34 2001
***************
*** 164,167 ****
--- 164,177 ----
  #define _CRT0_FLAG_KEEP_QUOTES			0x4000
  
+ /* If set, non-move sbrk() should discard (ignore) memory blocks which are
+ ** returned by DPMI which would require address wrap to access (at addresses
+ ** below the CS/DS base address).  This bit is automatically set on Win NT 
+ ** systems which require it.  It may be manually set on other systems which 
+ ** don't require it to retain a more normal memory space layout and better
+ ** memory protection.  This bit can be set but should never be cleared.
+ */
+ 
+ #define _CRT0_DISABLE_SBRK_ADDRESS_WRAP		0x8000
+ 
  /*****************************************************************************\
   *  Access to the memory handles used by the non-move sbrk algorithm.  
***************
*** 177,180 ****
--- 187,191 ----
  extern __djgpp_sbrk_handle __djgpp_memory_handle_list[256];
  __djgpp_sbrk_handle *__djgpp_memory_handle(unsigned address);
+ extern unsigned __djgpp_memory_handle_size[256];
  
  #endif /* !_POSIX_SOURCE */



*** crt0.txh_203	Sat Mar 20 16:15:24 1999
--- crt0.txh	Sat Aug 11 21:43:06 2001
***************
*** 100,104 ****
  #include <crt0.h>
  
! extern __djgpp_sbrk_handle __djgpp_memory_handle_list[256];
  @end example
  
--- 100,111 ----
  #include <crt0.h>
  
!   for(i=0; i<256; i++) {
!     int h, a, s;
!     h = __djgpp_memory_handle_list[i].handle;
!     a = __djgpp_memory_handle_list[i].address;
!     s = __djgpp_memory_handle_size[i];    
!     if(a == 0 && i != 0) break;
!     printf("handle[%d]=0x%x base=0x%x size=0x%x\n",i,h,a,s);
!   }
  @end example
  
***************
*** 111,114 ****
--- 118,148 ----
  
  @subheading Portability
+ 
+ @portability !ansi, !posix
+ 
+ @c ----------------------------------------------------------------------
+ @node __djgpp_memory_handle_size, memory
+ @subheading Syntax
+ 
+ @example
+ #include <crt0.h>
+ 
+   for(i=0; i<256; i++) {
+     int h, a, s;
+     h = __djgpp_memory_handle_list[i].handle;
+     a = __djgpp_memory_handle_list[i].address;
+     s = __djgpp_memory_handle_size[i];    
+     if(a == 0 && i != 0) break;
+     printf("handle[%d]=0x%x base=0x%x size=0x%x\n",i,h,a,s);
+   }
+ @end example
+ 
+ @subheading Description
+ 
+ This array contains a list of the sizes of the memory handles allocated 
+ by sbrk() in addition to the handle allocated by the stub.  These 
+ values are normally not needed unless you are dumping the memory blocks.
+ 
+ @subheading Portability
  
  @portability !ansi, !posix



*** crt1.txh_203	Sat Mar 20 16:48:18 1999
--- crt1.txh	Sat Aug 11 21:50:06 2001
***************
*** 187,191 ****
  @code{sbrk} expectations.  This mode should not be used with hardware
  interrupts, near pointers, and may cause problems with QDPMI virtual
! memory.  On NT, this is the recommended algorithm.
  
  If your program requires a specific @code{sbrk} behavior, you
--- 187,191 ----
  @code{sbrk} expectations.  This mode should not be used with hardware
  interrupts, near pointers, and may cause problems with QDPMI virtual
! memory.
  
  If your program requires a specific @code{sbrk} behavior, you
***************
*** 193,196 ****
--- 193,205 ----
  change in different libc releases.
  
+ @item _CRT0_DISABLE_SBRK_ADDRESS_WRAP
+ 
+ If set, non-move @code{sbrk} should discard (ignore) memory blocks which are
+ returned by DPMI which would require address wrap to access (at addresses
+ below the CS/DS base address).  This bit is automatically set on Windows NT
+ systems which require it.  It may be manually set on other systems which 
+ don't require it to retain a more normal memory space layout and better
+ memory protection.  This bit can be set but should never be cleared.
+ 
  @item _CRT0_FLAG_LOCK_MEMORY
  

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019