This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [MIPS PATCH RFA] allow hardware hooks for exit, hazardavoidance.


cgd@broadcom.com wrote:
> 
> In porting MIPS libgloss to a new firmware environment (our "CFE"
> firmware, patches for that port to be submitted tomorrow, if I find
> the time) on our SB-1 MIPS CPU core, I encountered the need for a
> couple more hardware-related hooks in libgloss.
> 
> The exit hook allows code to call back into the firmware to exit
> gracefully.
> 
> The hazard hook allows machine-specific or hardware specific code to
> be used for CP0 hazard avoidance.  MIPS64 specifically makes CP0
> hazard handling implementation specific, and some MIPS64
> implementations have ... interesting hazard avoidance procedures after
> certain operations.  Specifically, on the SB-1, after changing CU1 the
> instruction fetch queue has to be flushed.  (Instruction fetch and
> decode occur asychronously w.r.t. execution, and instructions may have
> been fetched and decoded w/ the previous CU1 value if the hazard has
> not been properly cleared.  If those instructions are executed they
> will cause CP1 unusable exceptions.)  The hazard hook is meant to
> provide a conservative, not-necessarily-best-performance mechanism to
> clear all sorts of execution hazards.
> 
> Tested by cross-compiling targets mips-elf, mipsel-elf, mips64-elf,
> mipsisa32-elf, mipsisa64-elf from host x86-linux, and verifying no new
> regressions attributable to this patch for check-gcc, etc.  (There
> were a couple of regressions, since I updated my gcc code base and it
> looks like some of the MIPS unordered handling changed...  But, that
> was like one or two per target, out of ... Many tests run.  8-)
> 

Patch checked in.

-- Jeff J.

> ===================================================================
> 2002-07-10  Chris Demetriou  <cgd@broadcom.com>
> 
>         * mips/array.ld (hardware_exit_hook, hardware_hazard_hook): New
>         symbols for optionally-provided functions.
>         * mips/ddb-kseg0.ld: Likewise.
>         * mips/ddb.ld: Likewise.
>         * mips/dve.ld: Likewise.
>         * mips/idt.ld: Likewise.
>         * mips/idt32.ld: Likewise.
>         * mips/idt64.ld: Likewise.
>         * mips/idtecoff.ld: Likewise.
>         * mips/jmr3904app-java.ld: Likewise.
>         * mips/jmr3904app.ld: Likewise.
>         * mips/jmr3904dram-java.ld: Likewise.
>         * mips/jmr3904dram.ld: Likewise.
>         * mips/lsi.ld: Likewise.
>         * mips/nullmon.ld: Likewise.
>         * mips/pmon.ld: Likewise.
>         * mips/crt0.S: Invoke hardware_exit_hook and hardware_hazard_hook
>         functions if they are provided.
>         (_exit): Handle __embedded_pic properly.
> 
> Index: array.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/array.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 array.ld
> --- array.ld    17 Mar 2000 22:48:51 -0000      1.1
> +++ array.ld    11 Jul 2002 06:23:08 -0000
> @@ -74,6 +74,8 @@ PROVIDE (__stack = 1M - 8);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: crt0.S
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/crt0.S,v
> retrieving revision 1.3
> diff -u -p -r1.3 crt0.S
> --- crt0.S      11 Sep 2001 14:24:35 -0000      1.3
> +++ crt0.S      11 Jul 2002 06:23:08 -0000
> @@ -54,11 +54,13 @@
>   */
>         nop
> 
> +       .globl  hardware_hazard_hook .text
>         .globl  _start
>         .ent    _start
>  _start:
>         .set    noreorder
>  #ifdef __mips_embedded_pic
> +#define PICBASE start_PICBASE
>         PICBASE = .+8
>          bal    PICBASE
>         nop
> @@ -75,6 +77,14 @@ _start:
>         mtc0    zero, C0_CAUSE
>         nop
> 
> +       /* Avoid hazard from FPU enable and other SR changes.  */
> +       LA (t0, hardware_hazard_hook)
> +       beq     t0,zero,1f
> +       nop
> +       jal     t0
> +       nop
> +1:
> +
>  /* Check for FPU presence.  Don't check if we know that soft_float is
>     being used.  (This also avoids illegal instruction exceptions.)  */
> 
> @@ -97,6 +107,12 @@ _start:
>         li      v0, (STATUS_MASK-(STATUS_MASK & SR_CU1))
>         mtc0    v0, C0_SR
>         nop
> +       /* Avoid hazard from FPU disable.  */
> +       LA (t0, hardware_hazard_hook)
> +       beq     t0,zero,2f
> +       nop
> +       jal     t0
> +       nop
>  2:
> 
> 
> @@ -205,6 +221,11 @@ init:
>                                                 # destructors
>         move    a0,v0                           # pass through the exit code
>         .end    init
> +
> +/* Assume the PICBASE set up above is no longer valid below here.  */
> +#ifdef __mips_embedded_pic
> +#undef PICBASE
> +#endif
> 
>  /*
>   * _exit -- Exit from the application. Normally we cause a user trap
> @@ -214,19 +235,42 @@ init:
>   *          executables that contain a complete world to be linked with
>   *          just the crt0.o object.
>   */
> +       .globl  hardware_exit_hook .text
>         .globl  _exit
>         .ent _exit
>  _exit:
>  7:
> +#ifdef __mips_embedded_pic
> +       /* Need to reinit PICBASE, since we might be called via exit()
> +          rather than via a return path which would restore old s0.  */
> +#define PICBASE exit_PICBASE
> +       PICBASE = .+8
> +       bal     PICBASE
> +       nop
> +       move    s0,$31
> +#endif
>  #ifdef GCRT0
> -       jal     _mcleanup
> +       LA (t0, _mcleanup)
> +       jal     t0
>         nop
>  #endif
> +       LA (t0, hardware_exit_hook)
> +       beq     t0,zero,1f
> +       nop
> +       jal     t0
> +       nop
> +1:
> +
>         # break instruction can cope with 0xfffff, but GAS limits the range:
>         break   1023
>         nop
>         b       7b                              # but loop back just in-case
>         nop
>         .end _exit
> +
> +/* Assume the PICBASE set up above is no longer valid below here.  */
> +#ifdef __mips_embedded_pic
> +#undef PICBASE
> +#endif
> 
>  /* EOF crt0.S */
> Index: ddb-kseg0.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/ddb-kseg0.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 ddb-kseg0.ld
> --- ddb-kseg0.ld        18 Oct 2001 02:24:30 -0000      1.1
> +++ ddb-kseg0.ld        11 Jul 2002 06:23:08 -0000
> @@ -22,6 +22,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: ddb.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/ddb.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 ddb.ld
> --- ddb.ld      17 Mar 2000 22:48:51 -0000      1.1
> +++ ddb.ld      11 Jul 2002 06:23:08 -0000
> @@ -22,6 +22,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: dve.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/dve.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 dve.ld
> --- dve.ld      17 Mar 2000 22:48:51 -0000      1.1
> +++ dve.ld      11 Jul 2002 06:23:08 -0000
> @@ -22,6 +22,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: idt.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/idt.ld,v
> retrieving revision 1.2
> diff -u -p -r1.2 idt.ld
> --- idt.ld      31 Aug 2001 19:22:51 -0000      1.2
> +++ idt.ld      11 Jul 2002 06:23:08 -0000
> @@ -23,6 +23,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: idt32.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/idt32.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 idt32.ld
> --- idt32.ld    14 Sep 2001 18:40:47 -0000      1.1
> +++ idt32.ld    11 Jul 2002 06:23:08 -0000
> @@ -25,6 +25,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: idt64.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/idt64.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 idt64.ld
> --- idt64.ld    14 Sep 2001 18:40:47 -0000      1.1
> +++ idt64.ld    11 Jul 2002 06:23:08 -0000
> @@ -25,6 +25,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: idtecoff.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/idtecoff.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 idtecoff.ld
> --- idtecoff.ld 17 Mar 2000 22:48:51 -0000      1.1
> +++ idtecoff.ld 11 Jul 2002 06:23:08 -0000
> @@ -25,6 +25,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: jmr3904app-java.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/jmr3904app-java.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 jmr3904app-java.ld
> --- jmr3904app-java.ld  17 Mar 2000 22:48:51 -0000      1.1
> +++ jmr3904app-java.ld  11 Jul 2002 06:23:08 -0000
> @@ -22,6 +22,8 @@ PROVIDE (_Jv_QthreadsStackSize = 0x10000
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: jmr3904app.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/jmr3904app.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 jmr3904app.ld
> --- jmr3904app.ld       17 Mar 2000 22:48:51 -0000      1.1
> +++ jmr3904app.ld       11 Jul 2002 06:23:08 -0000
> @@ -19,6 +19,8 @@ PROVIDE (_mem_size = 0x100000); /* JMR39
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: jmr3904dram-java.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/jmr3904dram-java.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 jmr3904dram-java.ld
> --- jmr3904dram-java.ld 17 Mar 2000 22:48:51 -0000      1.1
> +++ jmr3904dram-java.ld 11 Jul 2002 06:23:08 -0000
> @@ -23,6 +23,8 @@ PROVIDE (_Jv_QthreadsStackSize = 0x10000
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: jmr3904dram.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/jmr3904dram.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 jmr3904dram.ld
> --- jmr3904dram.ld      17 Mar 2000 22:48:51 -0000      1.1
> +++ jmr3904dram.ld      11 Jul 2002 06:23:08 -0000
> @@ -20,6 +20,8 @@ PROVIDE (_mem_size = 0x100000); /* JMR39
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: lsi.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/lsi.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 lsi.ld
> --- lsi.ld      17 Mar 2000 22:48:51 -0000      1.1
> +++ lsi.ld      11 Jul 2002 06:23:08 -0000
> @@ -23,6 +23,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: nullmon.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/nullmon.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 nullmon.ld
> --- nullmon.ld  17 Mar 2000 22:48:51 -0000      1.1
> +++ nullmon.ld  11 Jul 2002 06:23:08 -0000
> @@ -23,6 +23,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
> 
> Index: pmon.ld
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/pmon.ld,v
> retrieving revision 1.1
> diff -u -p -r1.1 pmon.ld
> --- pmon.ld     17 Mar 2000 22:48:51 -0000      1.1
> +++ pmon.ld     11 Jul 2002 06:23:08 -0000
> @@ -23,6 +23,8 @@ PROVIDE (__stack = 0);
>   * We have to initalize them twice, so we multiple object file
>   * formats, as some prepend an underscore.
>   */
> +PROVIDE (hardware_exit_hook = 0);
> +PROVIDE (hardware_hazard_hook = 0);
>  PROVIDE (hardware_init_hook = 0);
>  PROVIDE (software_init_hook = 0);
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]