Browse Source

* direct asm removing

Tomas Hajny 24 years ago
parent
commit
f22b036c55
2 changed files with 128 additions and 126 deletions
  1. 67 66
      rtl/os2/dos.pas
  2. 61 60
      rtl/os2/system.pas

+ 67 - 66
rtl/os2/dos.pas

@@ -81,7 +81,7 @@ type    {Some string types:}
 {$i textrec.inc}
 
         {Data structure for the registers needed by msdos and intr:}
-       registers=record
+       registers=packed record
             case i:integer of
                 0:(ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,
                    f8,flags,fs,gs:word);
@@ -181,6 +181,7 @@ implementation
 uses    DosCalls;
 
 var     LastSR: SearchRec;
+        envc: longint; external name '_envc';
 
 type    TBA = array [1..SizeOf (SearchRec)] of byte;
         PBA = ^TBA;
@@ -314,68 +315,69 @@ begin
     intr($21,regs);
 end;
 
-{$ASMMODE DIRECT}
-
-procedure intr(intno:byte;var regs:registers);
+procedure intr(intno:byte;var regs:registers); assembler;
 
 {Not recommended for EMX. Only works in DOS mode, not in OS/2 mode.}
 
-begin
-    asm
-        .data
-    int86:
-        .byte        0xcd
-    int86_vec:
-        .byte        0x03
-        jmp        int86_retjmp
-
-        .text
-        movl        8(%ebp),%eax
-        movb        %al,int86_vec
-
-        movl        10(%ebp),%eax
-        {Do not use first int}
-        incl        %eax
-        incl        %eax
-
-        movl        4(%eax),%ebx
-        movl        8(%eax),%ecx
-        movl        12(%eax),%edx
-        movl        16(%eax),%ebp
-        movl        20(%eax),%esi
-        movl        24(%eax),%edi
-        movl        (%eax),%eax
-
-        jmp        int86
-    int86_retjmp:
-        pushf
-        pushl   %ebp
-        pushl       %eax
-        movl        %esp,%ebp
-        {Calc EBP new}
-        addl        $12,%ebp
-        movl        10(%ebp),%eax
-        {Do not use first int}
-        incl        %eax
-        incl        %eax
-
-        popl        (%eax)
-        movl        %ebx,4(%eax)
-        movl        %ecx,8(%eax)
-        movl        %edx,12(%eax)
-        {Restore EBP}
-        popl    %edx
-        movl    %edx,16(%eax)
-        movl        %esi,20(%eax)
-        movl        %edi,24(%eax)
-        {Ignore ES and DS}
-        popl        %ebx            {Flags.}
-        movl        %ebx,32(%eax)
-        {FS and GS too}
-    end;
-end;
+asm
+    jmp .Lstart
+{    .data}
+.Lint86:
+    .byte   0xcd
+.Lint86_vec:
+    .byte   0x03
+    jmp     .Lint86_retjmp
+
+{    .text}
+.Lstart:
+    movl    intno,%eax
+    movb    %al,.Lint86_vec
 
-{$ASMMODE ATT}
+{
+    movl    10(%ebp),%eax
+    incl    %eax
+    incl    %eax
+}
+    movl    regs,%eax
+    {Do not use first int}
+    movl    4(%eax),%ebx
+    movl    8(%eax),%ecx
+    movl    12(%eax),%edx
+    movl    16(%eax),%ebp
+    movl    20(%eax),%esi
+    movl    24(%eax),%edi
+    movl    (%eax),%eax
+
+    jmp     .Lint86
+.Lint86_retjmp:
+    pushf
+    pushl   %ebp
+    pushl   %eax
+    movl    %esp,%ebp
+    {Calc EBP new}
+    addl    $12,%ebp
+{
+    movl    10(%ebp),%eax
+    incl    %eax
+    incl    %eax
+}
+    {Do not use first int}
+    movl    regs,%eax
+
+    popl    (%eax)
+    movl    %ebx,4(%eax)
+    movl    %ecx,8(%eax)
+    movl    %edx,12(%eax)
+    {Restore EBP}
+    popl    %edx
+    movl    %edx,16(%eax)
+    movl    %esi,20(%eax)
+    movl    %edi,24(%eax)
+    {Ignore ES and DS}
+    popl    %ebx            {Flags.}
+    movl    %ebx,32(%eax)
+    {FS and GS too}
+end;
 
 procedure exec(const path:pathstr;const comline:comstr);
 
@@ -899,12 +901,10 @@ end;
 
 type    PPchar=^Pchar;
 
-{$ASMMODE DIRECT}
-
 function envs:PPchar;assembler;
 
 asm
-    movl _environ,%eax
+    movl envp,%eax
 end ['EAX'];
 
 function envcount:longint;assembler;
@@ -912,11 +912,9 @@ function envcount:longint;assembler;
 var hp : ppchar;
 
 asm
-    movl _envc,%eax
+    movl envc,%eax
 end ['EAX'];
 
-{$ASMMODE ATT}
-
 function envstr(index : longint) : string;
 
 var hp:PPchar;
@@ -1068,7 +1066,10 @@ end;
 end.
 {
   $Log$
-  Revision 1.6  2000-11-06 20:35:05  hajny
+  Revision 1.7  2001-02-04 01:57:52  hajny
+    * direct asm removing
+
+  Revision 1.6  2000/11/06 20:35:05  hajny
     * common FExpand introduced
 
   Revision 1.5  2000/11/05 22:21:47  hajny

+ 61 - 60
rtl/os2/system.pas

@@ -140,6 +140,10 @@ implementation
 
 {$I SYSTEM.INC}
 
+var
+    heap_base: pointer; external name '__heap_base';
+    heap_brk: pointer; external name '__heap_brk';
+
 procedure DosGetInfoBlocks (PATIB: PPThreadInfoBlock;
                             PAPIB: PPProcessInfoBlock); cdecl;
                             external 'DOSCALLS' index 312;
@@ -163,42 +167,32 @@ procedure syscall; external name '___SYSCALL';
 ***************************************************************************}
 
 {$S-}
-procedure st1(stack_size:longint);[public,alias: 'FPC_STACKCHECK'];
+procedure st1(stack_size:longint); assembler; [public,alias: 'FPC_STACKCHECK'];
 
-begin
-    { called when trying to get local stack }
-    { if the compiler directive $S is set   }
-    {$ASMMODE DIRECT}
-    asm
-        movl stack_size,%ebx
-        movl %esp,%eax
-        subl %ebx,%eax
+asm
+    movl stack_size,%ebx
+    movl %esp,%eax
+    subl %ebx,%eax
 {$ifdef SYSTEMDEBUG}
-        movl U_SYSOS2_LOWESTSTACK,%ebx
-        cmpl %eax,%ebx
-        jb   Lis_not_lowest
-        movl %eax,U_SYSOS2_LOWESTSTACK
-    Lis_not_lowest:
+    movl loweststack,%ebx
+    cmpl %eax,%ebx
+    jb   .Lis_not_lowest
+    movl %eax,loweststack
+.Lis_not_lowest:
 {$endif SYSTEMDEBUG}
-        cmpb $2,U_SYSOS2_OS_MODE
-        jne Lrunning_in_dos
-        movl U_SYSOS2_STACKBOTTOM,%ebx
-        jmp Lrunning_in_os2
-    Lrunning_in_dos:
-        movl __heap_brk,%ebx
-    Lrunning_in_os2:
-        cmpl %eax,%ebx
-        jae  Lshort_on_stack
-        leave
-        ret  $4
-    Lshort_on_stack:
-    end ['EAX','EBX'];
-    {$ASMMODE ATT}
-    { this needs a local variable }
-    { so the function called itself !! }
-    { Writeln('low in stack ');}
-    HandleError(202);
-end;
+    cmpb osOS2,os_mode
+    jne .Lrunning_in_dos
+    movl stackbottom,%ebx
+    jmp .Lrunning_in_os2
+.Lrunning_in_dos:
+    movl heap_brk,%ebx
+.Lrunning_in_os2:
+    cmpl %eax,%ebx
+    jae  .Lshort_on_stack
+.Lshort_on_stack:
+    pushl $202
+    call HandleError
+end ['EAX','EBX'];
 {no stack check in system }
 
 {****************************************************************************
@@ -213,15 +207,14 @@ asm
     mov  ah, 04ch
     mov  al, byte ptr exitcode
     call syscall
-end;
+end ['EAX'];
 
-{$asmmode att}
+{$ASMMODE ATT}
 
-{$asmmode direct}
 function paramcount:longint;assembler;
 
 asm
-    movl _argc,%eax
+    movl argc,%eax
     decl %eax
 end ['EAX'];
 
@@ -230,7 +223,7 @@ function paramstr(l:longint):string;
     function args:pointer;assembler;
 
     asm
-        movl _argv,%eax
+        movl argv,%eax
     end ['EAX'];
 
 var p:^Pchar;
@@ -246,7 +239,6 @@ begin
                 mov eax, 7F33h
                 call syscall
             end;
-{$ASMMODE ATT}
             ParamStr := StrPas (PChar (P));
             FreeMem (P, 260);
         end
@@ -259,8 +251,7 @@ begin
         else paramstr:='';
 end;
 
-{$asmmode att}
-
+{
 procedure randomize;
 
 var hl:longint;
@@ -274,6 +265,17 @@ begin
     end;
     randseed:=hl;
 end;
+}
+
+procedure randomize; assembler;
+asm
+    mov ah, 2Ch
+    call syscall
+    mov word ptr [randseed], cx
+    mov word ptr [randseed + 2], dx
+end;
+
+{$ASMMODE ATT}
 
 {****************************************************************************
 
@@ -292,18 +294,16 @@ asm
     call syscall
 end;
 
-{$ASMMODE direct}
 function getheapstart:pointer;assembler;
 
 asm
-    movl __heap_base,%eax
+    movl heap_base,%eax
 end ['EAX'];
 
 function getheapsize:longint;assembler;
 asm
-    movl    HEAPSIZE,%eax
+    movl HeapSize,%eax
 end ['EAX'];
-{$ASMMODE ATT}
 
 {$i heap.inc}
 
@@ -443,12 +443,12 @@ procedure do_truncate(handle,pos:longint); assembler;
 asm
 (* DOS function 40h isn't safe for this according to EMX documentation
         movl $0x4200,%eax
-        movl 8(%ebp),%ebx
-        movl 12(%ebp),%edx
+        movl handle,%ebx
+        movl pos,%edx
         call syscall
         jc .LTruncate1
-        movl 8(%ebp),%ebx
-        movl 12(%ebp),%edx
+        movl handle,%ebx
+        movl pos,%edx
         movl %ebp,%edx
         xorl %ecx,%ecx
         movb $0x40,%ah
@@ -870,22 +870,20 @@ begin
         jz .LnoRSX
         movl $2,os_mode
     .LnoRSX:
-    end;
+{    end;}
 
-    {$ASMMODE DIRECT}
     {Enable the brk area by initializing it with the initial heap size.}
-    asm
+{    asm}
         movw $0x7f01,%ax
-        movl HEAPSIZE,%edx
-        addl __heap_base,%edx
-        call ___SYSCALL
+        movl HeapSize,%edx
+        addl heap_base,%edx
+        call syscall
         cmpl $-1,%eax
-        jnz Lheapok
+        jnz .Lheapok
         pushl $204
-        {call RUNERROR$$WORD}
-    Lheapok:
+        call HandleError
+    .Lheapok:
     end;
-    {$ASMMODE ATT}
 
     {Now request, if we are running under DOS,
      read-access to the first meg. of memory.}
@@ -950,7 +948,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.6  2001-02-01 21:30:01  hajny
+  Revision 1.7  2001-02-04 01:57:52  hajny
+    * direct asm removing
+
+  Revision 1.6  2001/02/01 21:30:01  hajny
     * MT support completion
 
   Revision 1.5  2001/01/23 20:38:59  hajny