Browse Source

* ppc64/linux: fixed and enabled some more assembly routines in the RTL
* ppc64/linux: cleaned up several files (mainly proper comments)

git-svn-id: trunk@1757 -

tom_at_work 20 years ago
parent
commit
3bf1152a9c
4 changed files with 329 additions and 332 deletions
  1. 147 106
      rtl/linux/powerpc64/cprt0.as
  2. 96 145
      rtl/linux/powerpc64/prt0.as
  3. 46 36
      rtl/linux/powerpc64/stat.inc
  4. 40 45
      rtl/powerpc64/powerpc64.inc

+ 147 - 106
rtl/linux/powerpc64/cprt0.as

@@ -1,106 +1,147 @@
-.macro LOAD_64BIT_VAL ra, value 
-    lis             \ra,\value@highest
-    ori             \ra,\ra,\value@higher
-    sldi            \ra,\ra,32
-    oris            \ra,\ra,\value@h
-    ori             \ra,\ra,\value@l    
-.endm
-
-    .section ".rodata"
-    .align  3
-start_addresses:
-    .quad   0 /* was _SDA_BASE_  but not in 64-bit ABI*/
-  /*     function descriptors so don't need JUMPTARGET */
-    .quad   main_stub
-    .quad   __libc_csu_init
-    .quad   __libc_csu_fini
-    .size   start_adresses, .-start_addresses
-
-    .section ".text"
-    .align 2
-    .global _start
-    .section ".opd","aw"
-    .align 3
-_start:
-    .quad ._start,.TOC.@tocbase,0
-    .previous
-
-    .global ._start
-._start:
-    mr  9,1
-    /* Set up an initial stack frame, and clear the LR.  */
-    clrrdi  1,1,4
-    li  0,0
-    stdu    1,-128(1)
-    mtlr    0
-    std 0,0(1)
-
- /* put the address of start_addresses in r8...  *
-  * PPC64 ABI uses R13 for thread local, so we leave it alone */
-        LOAD_64BIT_VAL 8, start_addresses
-    
-    b   .__libc_start_main
-    nop
-
-    .section ".opd","aw"
-    .align 3
-main_stub:
-    .quad .main_stub,.TOC.@tocbase,0
-    .previous
-    .globl  .main_stub
-    .type   .main_stub,@function
-.main_stub:
-    mflr    0
-    std     0,16(1)
-    stdu    1,-128(1)
-
-    LOAD_64BIT_VAL 8, operatingsystem_parameter_argc
-    stw     3,0(8)
-
-    LOAD_64BIT_VAL 8, operatingsystem_parameter_argv
-    std     4,0(8)
-
-    LOAD_64BIT_VAL 8, operatingsystem_parameter_envp
-    std     5,0(8)
-
-    LOAD_64BIT_VAL 8, ___fpc_ret
-    std 1,0(8)
-
-    bl  .PASCALMAIN
-    nop
-
-    b   ._haltproc
-
-    .section ".opd","aw"
-    .align 3
-_haltproc:
-    .quad ._haltproc,.TOC.@tocbase,0
-    .previous
-    
-    .globl  ._haltproc
-    .type   ._haltproc,@function
-._haltproc:
-    LOAD_64BIT_VAL 8, ___fpc_ret
-    ld  1,0(8)
-    addi    1,1,128
-    ld      0,16(1)
-    mtlr    0
-    blr
-
-#        li      0,1          /* exit call */
-#        sc
-#        b  ._haltproc
-
-    /* Define a symbol for the first piece of initialized data.  */
-    .section ".data"
-    .globl  __data_start
-__data_start:
-data_start:
-
-___fpc_ret:                             /* return address to libc */
-        .quad   0
-
-.text
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,8
-        .comm operatingsystem_parameter_envp,8
+/*
+ * Startup code for programs linked with GNU libc, PowerPC64
+ * version.
+ *
+ * Adapted from the glibc-sources (2.3.5) in the file
+ * 
+ *     sysdeps/powerpc/powerpc64/elf/start.S
+ *
+ * Original header follows.
+ */
+
+/* Startup code for programs linked with GNU libc.  PowerPC64 version.
+   Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* some macros which simplify the startup code */
+
+/* load the 64 bit value "value" into register ra */
+.macro LOAD_64BIT_VAL ra, value 
+    lis       \ra,\value@highest
+    ori       \ra,\ra,\value@higher
+    sldi      \ra,\ra,32
+    oris      \ra,\ra,\value@h
+    ori       \ra,\ra,\value@l    
+.endm
+
+/* create function prolog for symbol "fn" */
+.macro FUNCTION_PROLOG fn
+    .section  ".text"
+    .align    2
+    .globl    \fn
+    .section  ".opd", "aw"
+    .align    3
+\fn:
+    .quad     .\fn, .TOC.@tocbase, 0
+    .previous
+    .size     \fn, 24
+    .type     \fn, @function	
+    .globl    .\fn
+.\fn:
+.endm
+
+/* 
+ * start_addresses is a structure containing the real 
+ * entry point (next to other things not interesting to
+ * us here).
+ *
+ * All references in the struct are function descriptors
+ *
+ */
+    .section ".rodata"
+    .align  3
+start_addresses:
+    .quad   0 /* was _SDA_BASE_  but not in 64-bit ABI*/
+    .quad   main_stub
+    .quad   __libc_csu_init
+    .quad   __libc_csu_fini
+    .size   start_adresses, .-start_addresses
+
+/*
+ * the real entry point for the program
+ */
+FUNCTION_PROLOG _start
+    mr  9,1                   /* save the stack pointer */
+
+    /* Set up an initial stack frame, and clear the LR.  */
+
+    clrrdi  1,1,4
+    li      0,0
+    stdu    1,-128(1)
+    mtlr    0
+    std     0,0(1)
+
+    /* put the address of start_addresses in r8...  */
+    /* PPC64 ABI uses R13 for thread local, so we leave it alone */
+    LOAD_64BIT_VAL 8, start_addresses
+    
+    b   .__libc_start_main
+    nop                      /* a NOP for the linker */ 
+
+/*
+ * This is our FreePascal main procedure which is called by
+ * libc after initializing.
+ */
+
+FUNCTION_PROLOG main_stub
+    mflr    0
+    std     0,16(1)
+    stdu    1,-128(1)
+
+    LOAD_64BIT_VAL 8, operatingsystem_parameter_argc
+    stw     3,0(8)
+
+    LOAD_64BIT_VAL 8, operatingsystem_parameter_argv
+    std     4,0(8)
+
+    LOAD_64BIT_VAL 8, operatingsystem_parameter_envp
+    std     5,0(8)
+
+    LOAD_64BIT_VAL 8, ___fpc_ret
+    std     1,0(8)
+
+    bl  .PASCALMAIN
+    nop
+
+    b   ._haltproc
+
+FUNCTION_PROLOG _haltproc
+    LOAD_64BIT_VAL 8, ___fpc_ret
+    ld      1, 0(8)
+    addi    1, 1, 128
+    ld      0, 16(1)
+    mtlr    0
+    blr
+
+#    li      0,1          /* exit call */
+#    sc
+#    b  ._haltproc
+
+    /* Define a symbol for the first piece of initialized data.  */
+    .section ".data"
+    .globl  __data_start
+__data_start:
+data_start:
+
+___fpc_ret:                            /* return address to libc */
+    .quad   0
+
+.text
+    .comm operatingsystem_parameter_argc, 4
+    .comm operatingsystem_parameter_argv, 8
+    .comm operatingsystem_parameter_envp, 8

+ 96 - 145
rtl/linux/powerpc64/prt0.as

@@ -1,145 +1,96 @@
-/*
-*/
-/* Startup code for programs linked with GNU libc.
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library 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.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-   
-.macro LOAD_64BIT_VAL ra, value 
-	lis             \ra,\value@highest
-	ori             \ra,\ra,\value@higher
-	sldi            \ra,\ra,32
-	oris            \ra,\ra,\value@h
-	ori             \ra,\ra,\value@l	
-.endm
-
-.macro FUNCTION_PROLOG fn
-	.section	".text"
-	.align	2
-	.globl	\fn
-	.section	".opd", "aw"
-	.align	3
-	\fn:
-	.quad	.\fn, .TOC.@tocbase, 0
-	.previous
-	.size	\fn, 24
-	.type	\fn, @function	
-	.globl	.\fn
-.\fn:
-.endm
-
-.macro FUNCTION_EPILOG fn
-	.long	0
-	.byte	0, 12, 0, 0, 0, 0, 0, 0
-	.type	.\fn, @function
-	.size	.\fn,.-.\fn
-.endm
-
-.macro PRINTMSG msg len
-	lis	4, \msg@highest
-	ori	4, 4, \msg@higher
-	sldi	4, 4, 32
-	oris	4, 4, \msg@h
-	ori	4, 4, \msg@l	
-	li	5, \len	
-	li	0,4
-	li	3,1
-	sc
-.endm
-
-.section ".text"
-.align 3
-.globl .ptrgl
-.ptrgl:
-    ld	0, 0(11)
-    std	2, 40(1)
-    mtctr	0
-    ld	2, 8(11)
-    ld	11, 8(11)
-    bctr
-    .long 0
-    .byte	0, 12, 0, 0, 0, 0, 0, 0
-    .type .ptrgl, @function
-    .size .ptrgl, . - .ptrgl
-
-	/*
-        Main Pascal entry point label (function)
-	*/
-FUNCTION_PROLOG _start
-
-	mr 	26, 1
-	/* Set up an initial stack frame, and clear the LR */
-	clrrdi  1, 1, 5       /* align r1 */
-	li      0, 0          
-	stdu    1,-128(1)      
-	mtlr    0             
-	std     0, 0(1)       /* r1 = pointer to NULL value */
-
-	/* store argument count (= 0(r1) )*/
-	ld      3, 0(26)
-	LOAD_64BIT_VAL 10, operatingsystem_parameter_argc
-	stw     3, 0(10)
-	/* calculate argument vector address and store (= 8(r1) + 8 ) */
-	addi    4, 26, 8
-	LOAD_64BIT_VAL 10, operatingsystem_parameter_argv
-	std     4, 0(10)
-	/* store environment pointer (= argv + (argc+1)* 8 ) */
-	addi    5, 3, 1
-	sldi    5, 5, 3
-	add     5, 4, 5
-	LOAD_64BIT_VAL 10, operatingsystem_parameter_envp
-	std     5, 0(10)
-
-	bl      .PASCALMAIN
-	ori     0, 0, 0
-
-	/* directly jump to exit procedure, not via the function pointer */
-	b       ._haltproc
-	
-	.align  3
-
-	.global _haltproc
-	.section        ".opd", "aw"
-	.align 3
-_haltproc:
-	.quad   ._haltproc, .TOC.@tocbase, 0
-	.previous
-	.size _haltproc, 24
-	.global ._haltproc
-
-._haltproc:
-	/* exit call */
-	li      0, 1
-	sc
-	b       ._haltproc
-
-	/* Define a symbol for the first piece of initialized data.  */
-	.section ".data"
-	.globl  __data_start
-__data_start:
-data_start:
-	.globl  ___fpc_brk_addr	/* heap management */
-	.type   ___fpc_brk_addr, @object
-	.size   ___fpc_brk_addr, 4
-___fpc_brk_addr:
-	.long   0
-
-.text
-	.comm operatingsystem_parameter_argc, 4
-	.comm operatingsystem_parameter_argv, 8
-	.comm operatingsystem_parameter_envp, 8
-
+/*
+ * Startup code for normal programs, PowerPC64 version.
+ *
+ */
+   
+.macro LOAD_64BIT_VAL ra, value 
+    lis       \ra,\value@highest
+    ori       \ra,\ra,\value@higher
+    sldi      \ra,\ra,32
+    oris      \ra,\ra,\value@h
+    ori       \ra,\ra,\value@l    
+.endm
+
+/* create function prolog for symbol "fn" */
+.macro FUNCTION_PROLOG fn
+    .section  ".text"
+    .align    2
+    .globl    \fn
+    .section  ".opd", "aw"
+    .align    3
+\fn:
+    .quad     .\fn, .TOC.@tocbase, 0
+    .previous
+    .size     \fn, 24
+    .type     \fn, @function	
+    .globl    .\fn
+.\fn:
+.endm
+
+/* "ptrgl" glue code */
+.section ".text"
+.align 3
+.globl .ptrgl
+.ptrgl:
+    ld	    0, 0(11)
+    std     2, 40(1)
+    mtctr   0
+    ld      2, 8(11)
+    ld      11, 8(11)
+    bctr
+.long 0
+.byte 0, 12, 0, 0, 0, 0, 0, 0
+.type .ptrgl, @function
+.size .ptrgl, . - .ptrgl
+
+/*
+ * Main Pascal entry point label (function)
+ */
+FUNCTION_PROLOG _start
+
+    mr   26, 1            /* save stack pointer */
+    /* Set up an initial stack frame, and clear the LR */
+    clrrdi  1, 1, 5       /* align r1 */
+    li      0, 0          
+    stdu    1,-128(1)      
+    mtlr    0             
+    std     0, 0(1)       /* r1 = pointer to NULL value */
+
+    /* store argument count (= 0(r1) )*/
+    ld      3, 0(26)
+    LOAD_64BIT_VAL 10, operatingsystem_parameter_argc
+    stw     3, 0(10)
+    /* calculate argument vector address and store (= 8(r1) + 8 ) */
+    addi    4, 26, 8
+    LOAD_64BIT_VAL 10, operatingsystem_parameter_argv
+    std     4, 0(10)
+    /* store environment pointer (= argv + (argc+1)* 8 ) */
+    addi    5, 3, 1
+    sldi    5, 5, 3
+    add     5, 4, 5
+    LOAD_64BIT_VAL 10, operatingsystem_parameter_envp
+    std     5, 0(10)
+
+    bl      .PASCALMAIN
+    nop
+
+    /* directly jump to exit procedure, not via the function pointer */
+    b       ._haltproc
+	
+FUNCTION_PROLOG _haltproc
+    /* exit call */
+    li      0, 1
+    sc
+    b       ._haltproc
+
+    /* Define a symbol for the first piece of initialized data.  */
+    .section ".data"
+    .globl  __data_start
+__data_start:
+data_start:
+
+.text
+    .comm operatingsystem_parameter_argc, 4
+    .comm operatingsystem_parameter_argv, 8
+    .comm operatingsystem_parameter_envp, 8
+

+ 46 - 36
rtl/linux/powerpc64/stat.inc

@@ -1,7 +1,9 @@
 {
     This file is part of the Free Pascal run time library.
-    Copyright (c) 1999-2000 by Jonas Maebe,
-    member of the Free Pascal development team.
+    Copyright (c) 1999-2000 by Jonas Maebe, (c) 2005 Thomas Schatzl,
+    members of the Free Pascal development team.
+
+    Contains the definition of the stat type for the PowerPC64 platform.
 
     See the file COPYING.FPC, included in this distribution,
     for details about the copyright.
@@ -12,48 +14,56 @@
 
  **********************************************************************}
 
-  Stat = packed record  // No unix typing because of differences
+{ This structure was ported from 
+
+    /usr/include/asm-ppc64/stat.h
+
+  on a 2.6.11 kernel. Note that the stat record is the same for direct
+  syscalls as for when linking to libc.
+}
+
+{$PACKRECORDS C}
+  stat = record 
     case integer of
     0 : (
-      st_dev : qword;
-      st_ino : qword;
-      st_nlink : qword;
-
-      st_mode : dword;
-      st_uid : dword;
-      st_gid : dword;
-      __pad0 : dword;
-      st_rdev : qword;
-      st_size : int64;
-      st_blksize : int64;
-      st_blocks : int64;      { Number 512-byte blocks allocated. }
-
-      st_atime : qword;
-      __reserved0 : qword;    { reserved for atime.nanoseconds }
-      st_mtime : qword;
-      __reserved1 : qword;    { reserved for atime.nanoseconds }
-      st_ctime : qword;
-      __reserved2 : qword;    { reserved for atime.nanoseconds }
-      __unused : array[0..2] of int64
+      st_dev     : cULong;
+      st_ino     : cULong;     { wrongly defined in RTL? }
+      st_nlink   : cULong;     { wrongly defined in RTL? }
+
+      st_mode    : mode_t;
+      st_uid     : uid_t;
+      st_gid     : gid_t;
+
+      st_rdev    : cULong;
+      st_size    : int64;
+      st_blksize : cULong;
+      st_blocks  : cULong;     { Number 512-byte blocks allocated. }
+
+      st_atime : cULong;
+      st_atime_nsec : cULong;
+      st_mtime : cULong;
+      st_mtime_nsec : cULong;
+      st_ctime : cULong;
+      st_ctime_nsec : cULong;
+      __unused : array[0..2] of cULong
       );
     1 : (
-      dev    : qword;
-      ino,
-      mode   : qword;
-      nlink_dummy     : dword;
-      uid_dummy,
-      gid_dummy,
-      rdev      : dword;
-      size   : qword;
+      dev        : cULong;
+      ino        : cULong;
+      nlink      : cULong;
+      mode       : mode_t;
+      uid        : uid_t;
+      gid        : gid_t;
+      rdev       : cULong;
+      size       : off_t;
       blksize,
       blocks,
       atime,
-      __unused1_dummy,
+      atime_nsec,
       mtime,
-      __unused2_dummy,
+      mtime_nsec,
       ctime,
-      __unused3_dummy,
-      __unused4_dummy,
-      __unused5_dummy  : qword;
+      ctime_nsec : cULong;
+      __unused_dummy : array[0..2] of cULong;
       );
   end;

+ 40 - 45
rtl/powerpc64/powerpc64.inc

@@ -693,69 +693,64 @@ end;
 {****************************************************************************
                                  String
 ****************************************************************************}
-(*
+
 {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
 function fpc_shortstr_to_shortstr(len:longint; const sstr: shortstring): shortstring; [public,alias: 'FPC_SHORTSTR_TO_SHORTSTR']; compilerproc;
 assembler; nostackframe;
 { input: r3: pointer to result, r4: len, r5: sstr }
 asm
-        { load length source }
-        lbz     r10,0(r5)
-        {  load the begin of the dest buffer in the data cache }
-        dcbtst  0,r3
-
-        { put min(length(sstr),len) in r4 }
-        subfc   r7,r10,r4     { r0 := r4 - r10                               }
-        subfe   r4,r4,r4      { if r3 >= r4 then r3' := 0 else r3' := -1     }
-        and     r7,r7,r4      { if r3 >= r4 then r3' := 0 else r3' := r3-r10 }
-        add     r4,r10,r7     { if r3 >= r4 then r3' := r10 else r3' := r3   }
-
-        cmplwi  r4,0
-        { put length in ctr }
-        mtctr   r4
-        stb     r4,0(r3)
-        beq     .LShortStrCopyDone
+  { load length source }
+  lbz     r10,0(r5)
+  {  load the begin of the dest buffer in the data cache }
+  dcbtst  0,r3
+
+  { put min(length(sstr),len) in r4 }
+  subfc   r7,r10,r4     { r0 := r4 - r10                               }
+  subfe   r4,r4,r4      { if r3 >= r4 then r3' := 0 else r3' := -1     }
+  and     r7,r7,r4      { if r3 >= r4 then r3' := 0 else r3' := r3-r10 }
+  add     r4,r10,r7     { if r3 >= r4 then r3' := r10 else r3' := r3   }
+
+  cmpldi  r4,0
+  { put length in ctr }
+  mtctr   r4
+  stb     r4,0(r3)
+  beq     .LShortStrCopyDone
 .LShortStrCopyLoop:
-        lbzu    r0,1(r5)
-        stbu    r0,1(r3)
-        bdnz    .LShortStrCopyLoop
+  lbzu    r0,1(r5)
+  stbu    r0,1(r3)
+  bdnz    .LShortStrCopyLoop
 .LShortStrCopyDone:
 end;
 
-
-{$ifdef interncopy}
 procedure fpc_shortstr_assign(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_ASSIGN'];
-{$else}
-procedure fpc_shortstr_copy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY'];
-{$endif}
 assembler; nostackframe;
 { input: r3: len, r4: sstr, r5: dstr }
 asm
-        { load length source }
-        lbz     r10,0(r4)
-        {  load the begin of the dest buffer in the data cache }
-        dcbtst  0,r5
-
-        { put min(length(sstr),len) in r3 }
-        subc    r0,r3,r10    { r0 := r3 - r10                               }
-        subfe   r3,r3,r3     { if r3 >= r4 then r3' := 0 else r3' := -1     }
-        and     r3,r0,r3     { if r3 >= r4 then r3' := 0 else r3' := r3-r10 }
-        add     r3,r3,r10    { if r3 >= r4 then r3' := r10 else r3' := r3   }
-
-        cmplwi  r3,0
-        { put length in ctr }
-        mtctr   r3
-        stb     r3,0(r5)
-        beq     .LShortStrCopyDone2
+  { load length source }
+  lbz     r10,0(r4)
+  {  load the begin of the dest buffer in the data cache }
+  dcbtst  0,r5
+
+  { put min(length(sstr),len) in r3 }
+  subc    r0,r3,r10    { r0 := r3 - r10                               }
+  subfe   r3,r3,r3     { if r3 >= r4 then r3' := 0 else r3' := -1     }
+  and     r3,r0,r3     { if r3 >= r4 then r3' := 0 else r3' := r3-r10 }
+  add     r3,r3,r10    { if r3 >= r4 then r3' := r10 else r3' := r3   }
+
+  cmpldi  r3,0
+  { put length in ctr }
+  mtctr   r3
+  stb     r3,0(r5)
+  beq     .LShortStrCopyDone2
 .LShortStrCopyLoop2:
-        lbzu    r0,1(r4)
-        stbu    r0,1(r5)
-        bdnz    .LShortStrCopyLoop2
+  lbzu    r0,1(r4)
+  stbu    r0,1(r5)
+  bdnz    .LShortStrCopyLoop2
 .LShortStrCopyDone2:
 end;
 {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_ASSIGN}
-*)
+
 (*
 {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
 {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}