ソースを参照

* translated prt0.as from the OpenBSD x86_64 startup code to pascal inline asm; the code compiles, but is not used yet

git-svn-id: trunk@41695 -
nickysn 6 年 前
コミット
f1a7e2cdc5
5 ファイル変更169 行追加0 行削除
  1. 1 0
      .gitattributes
  2. 15 0
      rtl/openbsd/si_impl.inc
  3. 4 0
      rtl/openbsd/si_intf.inc
  4. 1 0
      rtl/openbsd/si_prc.pp
  5. 148 0
      rtl/openbsd/x86_64/si_prc.inc

+ 1 - 0
.gitattributes

@@ -10261,6 +10261,7 @@ rtl/openbsd/rtldefs.inc svneol=native#text/plain
 rtl/openbsd/setsysnr.inc svneol=native#text/plain
 rtl/openbsd/setsysnr.inc svneol=native#text/plain
 rtl/openbsd/si_c.pp svneol=native#text/plain
 rtl/openbsd/si_c.pp svneol=native#text/plain
 rtl/openbsd/si_dll.pp svneol=native#text/plain
 rtl/openbsd/si_dll.pp svneol=native#text/plain
+rtl/openbsd/si_impl.inc svneol=native#text/plain
 rtl/openbsd/si_intf.inc svneol=native#text/plain
 rtl/openbsd/si_intf.inc svneol=native#text/plain
 rtl/openbsd/si_prc.pp svneol=native#text/plain
 rtl/openbsd/si_prc.pp svneol=native#text/plain
 rtl/openbsd/signal.inc svneol=native#text/plain
 rtl/openbsd/signal.inc svneol=native#text/plain

+ 15 - 0
rtl/openbsd/si_impl.inc

@@ -0,0 +1,15 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2015 by Sven Barth, member of the Free Pascal development
+    team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+procedure PascalMain; external name 'PASCALMAIN';

+ 4 - 0
rtl/openbsd/si_intf.inc

@@ -20,3 +20,7 @@ var
   operatingsystem_parameter_envp: ppchar; public name 'operatingsystem_parameter_envp';
   operatingsystem_parameter_envp: ppchar; public name 'operatingsystem_parameter_envp';
   operatingsystem_parameter_argc: longint; public name 'operatingsystem_parameter_argc';
   operatingsystem_parameter_argc: longint; public name 'operatingsystem_parameter_argc';
   operatingsystem_parameter_argv: ppchar; public name 'operatingsystem_parameter_argv';
   operatingsystem_parameter_argv: ppchar; public name 'operatingsystem_parameter_argv';
+  operatingsystem_result: word; public name 'operatingsystem_result';
+  environ: ppchar; public name 'environ';
+  __progname: pchar = ''; public name '__progname';
+  __progname_storage: array [0..255] of char; public name '__progname_storage';

+ 1 - 0
rtl/openbsd/si_prc.pp

@@ -23,6 +23,7 @@ interface
 
 
 implementation
 implementation
 
 
+{$i si_impl.inc}
 {$i si_prc.inc}
 {$i si_prc.inc}
 
 
 end.
 end.

+ 148 - 0
rtl/openbsd/x86_64/si_prc.inc

@@ -14,4 +14,152 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
+{$asmmode gas}
 
 
+procedure _FPC_proc___start; forward;
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
+  asm
+    movq    %rbx,%r9
+    movq    %rcx,%r8
+    movq    %rdx,%rcx
+    movq    (%rsp),%rdi
+    leaq    16(%rsp,%rdi,8),%rdx
+    leaq    8(%rsp),%rsi
+    subq    $8,%rsp
+    andq    $0xFFFFFFFFFFFFFFF0,%rsp
+    addq    $8,%rsp
+    jmp     _FPC_proc___start
+  end;
+
+procedure _FPC_proc_haltproc; forward;
+function _strrchr(str: PChar; character: LongInt): PChar; forward;
+
+procedure _FPC_proc___start; assembler; nostackframe; public name '___start';
+  asm
+    pushq   %rbp
+    movq    %rsp, %rbp
+    subq    $64, %rsp
+    movl    %edi, -20(%rbp)
+    movq    %rsi, -32(%rbp)
+    movq    %rdx, -40(%rbp)
+    movq    %rcx, -48(%rbp)
+    movq    %r8, -56(%rbp)
+    movq    %r9, -64(%rbp)
+    movq    -40(%rbp), %rax
+    movq    %rax, environ(%rip)
+    movq    %rax,operatingsystem_parameter_envp(%rip)
+    movq    -32(%rbp), %rax
+    movq    (%rax), %rax
+    movq    %rax, -8(%rbp)
+    cmpq    $0, -8(%rbp)
+    je      .L2
+    movq    -8(%rbp), %rdi
+    movl    $47, %esi
+    call    _strrchr
+    movq    %rax, __progname(%rip)
+    movq    __progname(%rip), %rax
+    testq   %rax, %rax
+    jne     .L4
+    movq    -8(%rbp), %rax
+    movq    %rax, __progname(%rip)
+    jmp     .L6
+.L4:
+    movq    __progname(%rip), %rax
+    addq    $1, %rax
+    movq    %rax, __progname(%rip)
+.L6:
+    leaq    __progname_storage(%rip), %rax
+    movq    %rax, -16(%rbp)
+    jmp     .L7
+.L8:
+    movq    __progname(%rip), %rcx
+    movzbl  (%rcx), %edx
+    movq    -16(%rbp), %rax
+    movb    %dl, (%rax)
+    addq    $1, -16(%rbp)
+    leaq    1(%rcx), %rax
+    movq    %rax, __progname(%rip)
+.L7:
+    movq    __progname(%rip), %rax
+    movzbl  (%rax), %eax
+    testb   %al, %al
+    je      .L9
+    leaq    __progname_storage+255(%rip), %rax
+    cmpq    %rax, -16(%rbp)
+    jb      .L8
+.L9:
+    leaq    __progname_storage(%rip), %rax
+    movq    %rax, __progname(%rip)
+    movq    -16(%rbp), %rax
+    movb    $0, (%rax)
+.L2:
+    // movl    $_mcleanup, %edi
+    // call    atexit
+    // movl    $_etext, %eax
+    // movq    %rax, %rsi
+    // movl    $_eprol, %eax
+    // movq    %rax, %rdi
+    // call    monstartup
+    // movl    $0, %eax
+    // call    __init
+    movq    environ(%rip), %rdx
+    movq    -32(%rbp), %rsi
+    movl    -20(%rbp), %edi
+    movq    %rdi,operatingsystem_parameter_argc(%rip)
+    movq    %rsi,operatingsystem_parameter_argv(%rip)
+    movl    $0, %eax
+    call    PASCALMAIN
+    // movl    %eax, %edi
+    // call    exit
+    jmp     _FPC_proc_haltproc
+  end;
+
+procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
+  asm
+    movq    $1,%rax
+    movzwq  operatingsystem_result(%rip),%rbx
+    pushq   %rbx
+    call    .Lactualsyscall
+    addq    $8,%rsp
+    jmp     _FPC_proc_haltproc
+
+.Lactualsyscall:
+    int     $0x80
+    jb      .LErrorcode
+    xor     %rbx,%rbx
+    ret
+.LErrorcode:
+    movq    %rax,%rbx
+    movq    $-1,%rax
+  end;
+
+function _strrchr(str: PChar; character: LongInt): PChar; assembler; nostackframe; public name '_strrchr';
+  asm
+    pushq   %rbp
+    movq    %rsp, %rbp
+    movq    %rdi, -24(%rbp)
+    movb    %sil, -25(%rbp)
+    movq    $0, -8(%rbp)
+.L13:
+    movq    -24(%rbp), %rdx
+    movzbl  (%rdx), %eax
+    cmpb    -25(%rbp), %al
+    jne     .L14
+    movq    -24(%rbp), %rax
+    movq    %rax, -8(%rbp)
+.L14:
+    movq    -24(%rbp), %rdx
+    movzbl  (%rdx), %eax
+    testb   %al, %al
+    jne     .L16
+    movq    -8(%rbp), %rax
+    movq    %rax, -16(%rbp)
+    jmp     .L12
+.L16:
+    addq    $1, -24(%rbp)
+    jmp     .L13
+.L12:
+    movq    -16(%rbp), %rax
+    leave
+  end;