Browse Source

* let the compiler generate the stack segment in i8086 near data memory models
as well. Even though, in these models, the stack is dynamically allocated
(because it goes on top of the heap, but the heap is variable size), there are
still benefits:
1) the program will run on a larger stack during initialization, before the
actual stack (and heap) are ready
2) in cases, when the system is extremely low on memory, DOS will reject to
load the program if there's not enough memory for the stack the program
requires. This way the startup code can be further simplified by omitting
the 'not enough memory' check in the future (when we add the minimum heap
size to the executable reserved space as well).

git-svn-id: trunk@27903 -

nickysn 11 years ago
parent
commit
73d7f2aa18
3 changed files with 8 additions and 10 deletions
  1. 2 2
      compiler/i8086/n8086util.pas
  2. 2 5
      compiler/x86/agx86nsm.pas
  3. 4 3
      rtl/msdos/prt0comn.asm

+ 2 - 2
compiler/i8086/n8086util.pas

@@ -47,8 +47,7 @@ implementation
   class procedure ti8086nodeutils.InsertMemorySizes;
   class procedure ti8086nodeutils.InsertMemorySizes;
     begin
     begin
       inherited;
       inherited;
-      if current_settings.x86memorymodel in x86_far_data_models then
-        InsertStackSegment;
+      InsertStackSegment;
     end;
     end;
 
 
 
 
@@ -73,6 +72,7 @@ implementation
           dec(stacksizeleft,stackblock);
           dec(stacksizeleft,stackblock);
           inc(i);
           inc(i);
         end;
         end;
+      current_asmdata.asmlists[al_globals].concat(tai_symbol.Createname_global('___stacktop',AT_DATA,0));
     end;
     end;
 
 
 
 

+ 2 - 5
compiler/x86/agx86nsm.pas

@@ -1226,16 +1226,13 @@ interface
       AsmWriteLn('SECTION .fpc');
       AsmWriteLn('SECTION .fpc');
       { WLINK requires class=bss in order to leave the BSS section out of the executable }
       { WLINK requires class=bss in order to leave the BSS section out of the executable }
       AsmWriteLn('SECTION .bss class=bss');
       AsmWriteLn('SECTION .bss class=bss');
-      if current_settings.x86memorymodel in x86_far_data_models then
+      if current_settings.x86memorymodel<>mm_tiny then
         AsmWriteLn('SECTION stack stack class=stack align=16');
         AsmWriteLn('SECTION stack stack class=stack align=16');
       { group these sections in the same segment }
       { group these sections in the same segment }
       if current_settings.x86memorymodel=mm_tiny then
       if current_settings.x86memorymodel=mm_tiny then
         AsmWriteLn('GROUP dgroup text rodata data fpc bss')
         AsmWriteLn('GROUP dgroup text rodata data fpc bss')
       else
       else
-        if current_settings.x86memorymodel in x86_far_data_models then
-          AsmWriteLn('GROUP dgroup rodata data fpc bss stack')
-        else
-          AsmWriteLn('GROUP dgroup rodata data fpc bss');
+        AsmWriteLn('GROUP dgroup rodata data fpc bss stack');
       if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
       if paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4] then
         begin
         begin
           AsmWriteLn('SECTION .debug_frame  use32 class=DWARF');
           AsmWriteLn('SECTION .debug_frame  use32 class=DWARF');

+ 4 - 3
rtl/msdos/prt0comn.asm

@@ -56,6 +56,9 @@
 %ifdef __FAR_DATA__
 %ifdef __FAR_DATA__
         extern ___stack
         extern ___stack
 %endif
 %endif
+%ifdef __NEAR_DATA__
+        extern ___stacktop
+%endif
 
 
         extern __SaveInt00
         extern __SaveInt00
 
 
@@ -72,7 +75,7 @@
     %ifdef __NEAR_DATA__
     %ifdef __NEAR_DATA__
         ; init the stack
         ; init the stack
         mov ss, bx
         mov ss, bx
-        mov sp, stacktop
+        mov sp, ___stacktop wrt dgroup
     %endif
     %endif
 %endif
 %endif
 
 
@@ -475,8 +478,6 @@ __nullarea:
 
 
     %ifdef __NEAR_DATA__
     %ifdef __NEAR_DATA__
         segment stack stack class=stack
         segment stack stack class=stack
-        resb 256
-        stacktop:
     %else
     %else
         segment data
         segment data
         ; add reference to the beginning of stack, so the object module,
         ; add reference to the beginning of stack, so the object module,