| 1 |
/* Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
This file is free software; you can redistribute it and/or modify it |
| 4 |
under the terms of the GNU General Public License as published by the |
| 5 |
Free Software Foundation; either version 3, or (at your option) any |
| 6 |
later version. |
| 7 |
|
| 8 |
This file is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
General Public License for more details. |
| 12 |
|
| 13 |
Under Section 7 of GPL version 3, you are granted additional |
| 14 |
permissions described in the GCC Runtime Library Exception, version |
| 15 |
3.1, as published by the Free Software Foundation. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License and |
| 18 |
a copy of the GCC Runtime Library Exception along with this program; |
| 19 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 20 |
<http://www.gnu.org/licenses/>. */ |
| 21 |
|
| 22 |
#include "mips16.S" |
| 23 |
|
| 24 |
#ifdef L_speculation_barrier |
| 25 |
|
| 26 |
/* MIPS16e1 has no sync/jr.hb instructions, and MIPS16e2 lacks of jr.hb. |
| 27 |
So, we use normal MIPS code here, just like what we do for __sync_*. */ |
| 28 |
.set nomips16 |
| 29 |
|
| 30 |
.set noreorder |
| 31 |
.globl __speculation_barrier |
| 32 |
.ent __speculation_barrier |
| 33 |
|
| 34 |
__speculation_barrier: |
| 35 |
.set push |
| 36 |
#if __mips >= 2 |
| 37 |
sync /* complementation barrier for memory. */ |
| 38 |
#elif defined (__linux) |
| 39 |
/* MIPS1 has no sync, while Linux can trap&emu sync. */ |
| 40 |
/* FIXME: Will somebody use linux/gcc for MIPS1/baremetal? */ |
| 41 |
.word 0x0000000f |
| 42 |
#endif |
| 43 |
|
| 44 |
|
| 45 |
#if __mips_isa_rev >= 1 |
| 46 |
/* Binutils claims that JR in R1 can do same as jr.hb. |
| 47 |
R6 changes the encoding of jr.hb. */ |
| 48 |
jr.hb $ra /* Jump with instruction hazard barrier. */ |
| 49 |
#else |
| 50 |
/* ssnop is actually available since R5500, |
| 51 |
and it will be decoded as nop on earlier processors. |
| 52 |
gas can only recognize it with -march=mips1 since 2.21. |
| 53 |
MIPS1 to MIPSr1: R10000 have 7 stage pipeline, |
| 54 |
so 8 ssnop is sufficient to block all speculation on all CPUs. */ |
| 55 |
.rept 8 |
| 56 |
.word 0x00000040 /* The encoding of ssnop. */ |
| 57 |
.endr |
| 58 |
/* jr.hb will be decoded as jr on earlier processors. */ |
| 59 |
.word 0x03e00408 /* The encoding of jr.hb $ra. */ |
| 60 |
#endif |
| 61 |
.set pop |
| 62 |
.end __speculation_barrier |
| 63 |
|
| 64 |
.set reorder |
| 65 |
#endif |