Parcourir la source

+ added heapmax support to the $M directive on i8086-msdos. It is currently
only implemented in the near data memory models. The far data models support
is still a TODO.

git-svn-id: trunk@28039 -

nickysn il y a 11 ans
Parent
commit
1910177cf0
5 fichiers modifiés avec 59 ajouts et 9 suppressions
  1. 1 0
      compiler/globals.pas
  2. 18 0
      compiler/i8086/n8086util.pas
  3. 16 7
      compiler/parser.pas
  4. 8 0
      compiler/scandir.pas
  5. 16 2
      rtl/msdos/prt0comn.asm

+ 1 - 0
compiler/globals.pas

@@ -322,6 +322,7 @@ interface
        pendingstate       : tpendingstate;
        pendingstate       : tpendingstate;
      { Memory sizes }
      { Memory sizes }
        heapsize,
        heapsize,
+       maxheapsize,
        stacksize,
        stacksize,
        jmp_buf_size,
        jmp_buf_size,
        jmp_buf_align : longint;
        jmp_buf_align : longint;

+ 18 - 0
compiler/i8086/n8086util.pas

@@ -34,6 +34,7 @@ interface
       class procedure InsertMemorySizes; override;
       class procedure InsertMemorySizes; override;
       class procedure InsertStackSegment;
       class procedure InsertStackSegment;
       class procedure InsertHeapSegment;
       class procedure InsertHeapSegment;
+      class procedure InsertStackPlusHeapSize;
     end;
     end;
 
 
 
 
@@ -51,6 +52,8 @@ implementation
       if current_settings.x86memorymodel<>mm_tiny then
       if current_settings.x86memorymodel<>mm_tiny then
         InsertStackSegment;
         InsertStackSegment;
       InsertHeapSegment;
       InsertHeapSegment;
+      if current_settings.x86memorymodel in x86_near_data_models then
+        InsertStackPlusHeapSize;
     end;
     end;
 
 
 
 
@@ -104,6 +107,21 @@ implementation
     end;
     end;
 
 
 
 
+  class procedure ti8086nodeutils.InsertStackPlusHeapSize;
+    var
+      maxheapsize_para: Word;
+      stacksize_para: Word;
+    begin
+      maxheapsize_para:=(maxheapsize+15) div 16;
+      stacksize_para:=(stacksize+15) div 16;
+
+      maybe_new_object_file(current_asmdata.asmlists[al_globals]);
+      new_section(current_asmdata.asmlists[al_globals],sec_data,'__fpc_stackplusmaxheap_in_para',sizeof(pint));
+      current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__fpc_stackplusmaxheap_in_para',AT_DATA,4));
+      current_asmdata.asmlists[al_globals].concat(Tai_const.Create_16bit(min($1000,stacksize_para+maxheapsize_para)));
+    end;
+
+
 begin
 begin
   cnodeutils:=ti8086nodeutils;
   cnodeutils:=ti8086nodeutils;
 end.
 end.

+ 16 - 7
compiler/parser.pas

@@ -124,13 +124,22 @@ implementation
              include(supported_calling_conventions,pocall_syscall);
              include(supported_calling_conventions,pocall_syscall);
 {$ifdef i8086}
 {$ifdef i8086}
            system_i8086_msdos:
            system_i8086_msdos:
-             if stacksize=0 then
-               begin
-                 if init_settings.x86memorymodel in x86_far_data_models then
-                   stacksize:=16384
-                 else
-                   stacksize:=4096;
-               end;
+             begin
+               if stacksize=0 then
+                 begin
+                   if init_settings.x86memorymodel in x86_far_data_models then
+                     stacksize:=16384
+                   else
+                     stacksize:=4096;
+                 end;
+               if maxheapsize=0 then
+                 begin
+                   if init_settings.x86memorymodel in x86_far_data_models then
+                     maxheapsize:=655360
+                   else
+                     maxheapsize:=65520;
+                 end;
+             end;
 {$endif i8086}
 {$endif i8086}
          end;
          end;
       end;
       end;

+ 8 - 0
compiler/scandir.pas

@@ -724,6 +724,14 @@ unit scandir;
             l:=current_scanner.readval;
             l:=current_scanner.readval;
             if l>=1024 then
             if l>=1024 then
               heapsize:=l;
               heapsize:=l;
+            if c=',' then
+              begin
+                current_scanner.readchar;
+                current_scanner.skipspace;
+                l:=current_scanner.readval;
+                if l>=heapsize then
+                  maxheapsize:=l;
+              end;
           end;
           end;
       end;
       end;
 
 

+ 16 - 2
rtl/msdos/prt0comn.asm

@@ -55,6 +55,10 @@
 
 
         extern ___heap
         extern ___heap
 
 
+%ifdef __NEAR_DATA__
+        extern __fpc_stackplusmaxheap_in_para
+%endif
+
 %ifndef __TINY__
 %ifndef __TINY__
     %ifdef __FAR_DATA__
     %ifdef __FAR_DATA__
         extern ___stack
         extern ___stack
@@ -145,8 +149,18 @@ cpu_detect_done:
 ; ****************************************************************************
 ; ****************************************************************************
 
 
         ; allocate max heap
         ; allocate max heap
-        ; TODO: also support user specified heap size
-        ; try to resize our main DOS memory block until the end of the data segment
+        ; first we determine in paragraphs ax:=min(64kb, data+bss+stack+maxheap)
+        mov ax, _end wrt dgroup
+        add ax, 15
+        mov cl, 4
+        shr ax, cl
+        add ax, word [__fpc_stackplusmaxheap_in_para]
+        cmp ax, 1000h  ; 1000h = 64k in paragraphs
+        jbe data_with_maxheap_less_than_64k
+        mov ax, 1000h
+data_with_maxheap_less_than_64k:
+
+        ; try to resize our main DOS memory block until the end of the data segment (or even smaller, if maxheap is small)
         mov cx, word [dos_psp]
         mov cx, word [dos_psp]
 %ifdef __TINY__
 %ifdef __TINY__
         mov dx, cs
         mov dx, cs