فهرست منبع

* converted the i386 OpenBSD startup code to Pascal

git-svn-id: trunk@41764 -
nickysn 6 سال پیش
والد
کامیت
516438fd19
5فایلهای تغییر یافته به همراه266 افزوده شده و 1 حذف شده
  1. 1 1
      compiler/systems.pas
  2. 68 0
      rtl/openbsd/i386/si_c.inc
  3. 38 0
      rtl/openbsd/i386/si_dll.inc
  4. 81 0
      rtl/openbsd/i386/si_g.inc
  5. 78 0
      rtl/openbsd/i386/si_prc.inc

+ 1 - 1
compiler/systems.pas

@@ -352,7 +352,7 @@ interface
                                    system_i386_linux,system_powerpc64_linux,system_sparc64_linux,system_x86_64_linux,
                                    system_m68k_atari,system_m68k_palmos,
                                    system_i386_haiku,system_x86_64_haiku,
-                                   system_x86_64_openbsd
+                                   system_i386_openbsd,system_x86_64_openbsd
                                   ]+systems_darwin+systems_amigalike;
 
        { all systems that use garbage collection for reference-counted types }

+ 68 - 0
rtl/openbsd/i386/si_c.inc

@@ -14,4 +14,72 @@
 
  **********************************************************************}
 
+{$asmmode att}
+
+procedure __init; cdecl; external name '__init';
+procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
+  asm
+    pushl   %ebx                    { ps_strings }
+    pushl   %ecx                    { obj }
+    pushl   %edx                    { cleanup }
+    movl    12(%esp),%eax
+    leal    20(%esp,%eax,4),%ecx
+    leal    16(%esp),%edx
+    pushl   %ecx
+    pushl   %edx
+    pushl   %eax
+    call    _FPC_proc___start
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
+function _strrchr(str: PChar; character: LongInt): PChar; forward;
+
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+  var
+    I: SizeUInt;
+  begin
+    environ:=envp;
+    operatingsystem_parameter_envp:=envp;
+    operatingsystem_parameter_argc:=argc;
+    operatingsystem_parameter_argv:=argv;
+    if argv[0]<>nil then
+      begin
+        __progname:=_strrchr(argv[0], Ord('/'));
+        if __progname<>nil then
+          Inc(__progname)
+        else
+          __progname:=argv[0];
+        I:=Low(__progname_storage);
+        while (I<High(__progname_storage)) and (__progname[I]<>#0) do
+          begin
+            __progname_storage[I]:=__progname[I-Low(__progname_storage)];
+            Inc(I);
+          end;
+        __progname_storage[I]:=#0;
+        __progname:=@__progname_storage;
+      end;
+    __init;
+    PascalMain;
+    c_exit(operatingsystem_result);
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
+  begin
+    c_exit(operatingsystem_result);
+  end;
+
+function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
+  begin
+    _strrchr:=nil;
+    repeat
+      if str^=Chr(character) then
+        _strrchr:=str;
+      if str^<>#0 then
+        Inc(str);
+    until str^=#0;
+  end;
 

+ 38 - 0
rtl/openbsd/i386/si_dll.inc

@@ -14,4 +14,42 @@
 
  **********************************************************************}
 
+{$asmmode att}
 
+{$ifdef VER3_0}
+procedure _init; external name '_init';
+{$else VER3_0}
+procedure _init; weakexternal name '_init';
+{$endif VER3_0}
+
+procedure _FPC_shared_lib_start; cdecl; public name 'FPC_LIB_START';
+  begin
+    { todo: figure out if there's any way to obtain these in OpenBSD shared libraries }
+    environ:=nil;
+    operatingsystem_parameter_envp:=nil;
+    operatingsystem_parameter_argc:=0;
+    operatingsystem_parameter_argv:=nil;
+    if Assigned(@_init) then
+      _init;
+    PascalMain;
+  end;
+
+{ this routine is only called when the halt() routine of the RTL embedded in
+  the shared library is called }
+procedure _FPC_shared_lib_haltproc; cdecl; public name '_haltproc';
+  var
+    ExitCode: LongInt;
+  begin
+    ExitCode:=operatingsystem_result;
+    asm
+.Lendless:
+      pushl   ExitCode
+      mov     $1,%eax
+      call    .Lactualsyscall
+      jmp     .Lendless
+
+.Lactualsyscall:
+      int     $0x80
+      ret
+    end;
+  end;

+ 81 - 0
rtl/openbsd/i386/si_g.inc

@@ -14,3 +14,84 @@
 
  **********************************************************************}
 
+{$asmmode att}
+
+var
+  _etext: Byte; external name '_etext';
+  _eprol: Byte; external name '_eprol';
+
+procedure _mcleanup; cdecl; external name '_mcleanup';
+function atexit(proc: TCdeclProcedure): cint; cdecl; external name 'atexit';
+procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
+procedure __init; cdecl; external name '__init';
+procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
+
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
+  asm
+    pushl   %ebx                    { ps_strings }
+    pushl   %ecx                    { obj }
+    pushl   %edx                    { cleanup }
+    movl    12(%esp),%eax
+    leal    20(%esp,%eax,4),%ecx
+    leal    16(%esp),%edx
+    pushl   %ecx
+    pushl   %edx
+    pushl   %eax
+    call    _FPC_proc___start
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
+function _strrchr(str: PChar; character: LongInt): PChar; forward;
+
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+  var
+    I: SizeUInt;
+  begin
+    environ:=envp;
+    operatingsystem_parameter_envp:=envp;
+    operatingsystem_parameter_argc:=argc;
+    operatingsystem_parameter_argv:=argv;
+    if argv[0]<>nil then
+      begin
+        __progname:=_strrchr(argv[0], Ord('/'));
+        if __progname<>nil then
+          Inc(__progname)
+        else
+          __progname:=argv[0];
+        I:=Low(__progname_storage);
+        while (I<High(__progname_storage)) and (__progname[I]<>#0) do
+          begin
+            __progname_storage[I]:=__progname[I-Low(__progname_storage)];
+            Inc(I);
+          end;
+        __progname_storage[I]:=#0;
+        __progname:=@__progname_storage;
+      end;
+    atexit(@_mcleanup);
+    _monstartup(u_long(@_eprol),u_long(@_etext));
+    __init;
+    PascalMain;
+    c_exit(operatingsystem_result);
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
+  begin
+    c_exit(operatingsystem_result);
+  end;
+
+function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
+  begin
+    _strrchr:=nil;
+    repeat
+      if str^=Chr(character) then
+        _strrchr:=str;
+      if str^<>#0 then
+        Inc(str);
+    until str^=#0;
+  end;
+
+procedure MD_EPROL_LABEL; assembler; nostackframe; public name '_eprol';
+  asm
+  end;

+ 78 - 0
rtl/openbsd/i386/si_prc.inc

@@ -14,4 +14,82 @@
 
  **********************************************************************}
 
+{$asmmode att}
 
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
+  asm
+    pushl   %ebx                    { ps_strings }
+    pushl   %ecx                    { obj }
+    pushl   %edx                    { cleanup }
+    movl    12(%esp),%eax
+    leal    20(%esp,%eax,4),%ecx
+    leal    16(%esp),%edx
+    pushl   %ecx
+    pushl   %edx
+    pushl   %eax
+    call    _FPC_proc___start
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
+function _strrchr(str: PChar; character: LongInt): PChar; forward;
+
+procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
+  var
+    I: SizeUInt;
+  begin
+    environ:=envp;
+    operatingsystem_parameter_envp:=envp;
+    operatingsystem_parameter_argc:=argc;
+    operatingsystem_parameter_argv:=argv;
+    if argv[0]<>nil then
+      begin
+        __progname:=_strrchr(argv[0], Ord('/'));
+        if __progname<>nil then
+          Inc(__progname)
+        else
+          __progname:=argv[0];
+        I:=Low(__progname_storage);
+        while (I<High(__progname_storage)) and (__progname[I]<>#0) do
+          begin
+            __progname_storage[I]:=__progname[I-Low(__progname_storage)];
+            Inc(I);
+          end;
+        __progname_storage[I]:=#0;
+        __progname:=@__progname_storage;
+      end;
+    PascalMain;
+    asm
+      jmp     _FPC_proc_haltproc
+    end;
+  end;
+
+procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
+  var
+    ExitCode: LongInt;
+  begin
+    ExitCode:=operatingsystem_result;
+    asm
+.Lendless:
+      pushl   ExitCode
+      mov     $1,%eax
+      call    .Lactualsyscall
+      jmp     .Lendless
+
+.Lactualsyscall:
+      int     $0x80
+      ret
+    end;
+  end;
+
+function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
+  begin
+    _strrchr:=nil;
+    repeat
+      if str^=Chr(character) then
+        _strrchr:=str;
+      if str^<>#0 then
+        Inc(str);
+    until str^=#0;
+  end;