repo_id
stringlengths
5
115
size
int64
590
5.01M
file_path
stringlengths
4
212
content
stringlengths
590
5.01M
a1ive/grub
1,816
grub-core/lib/libgcrypt/mpi/hppa/mpih-rshift.S
/* hppa rshift * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, (gr26) * mpi_ptr_t up, (gr25) * mpi_size_t usize, (gr24) * unsigned cnt) (gr23) */ .code .export _gcry_mpih_rshift .label _gcry_mpih_rshift .proc .callinfo frame=64,no_calls .entry ldws,ma 4(0,%r25),%r22 mtsar %r23 addib,= -1,%r24,L$r004 vshd %r22,%r0,%r28 ; compute carry out limb ldws,ma 4(0,%r25),%r29 addib,= -1,%r24,L$r002 vshd %r29,%r22,%r20 .label L$roop ldws,ma 4(0,%r25),%r22 stws,ma %r20,4(0,%r26) addib,= -1,%r24,L$r003 vshd %r22,%r29,%r20 ldws,ma 4(0,%r25),%r29 stws,ma %r20,4(0,%r26) addib,<> -1,%r24,L$roop vshd %r29,%r22,%r20 .label L$r002 stws,ma %r20,4(0,%r26) vshd %r0,%r29,%r20 bv 0(%r2) stw %r20,0(0,%r26) .label L$r003 stws,ma %r20,4(0,%r26) .label L$r004 vshd %r0,%r22,%r20 bv 0(%r2) stw %r20,0(0,%r26) .exit .procend
a1ive/grub
2,166
grub-core/lib/libgcrypt/mpi/hppa/mpih-add1.S
/* hppa add_n -- Add two limb vectors of the same length > 0 and store * sum in a third limb vector. * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Fee Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, (gr26) * mpi_ptr_t s1_ptr, (gr25) * mpi_ptr_t s2_ptr, (gr24) * mpi_size_t size) (gr23) * * One might want to unroll this as for other processors, but it turns * out that the data cache contention after a store makes such * unrolling useless. We can't come under 5 cycles/limb anyway. */ .code .export _gcry_mpih_add_n .label _gcry_mpih_add_n .proc .callinfo frame=0,no_calls .entry ldws,ma 4(0,%r25),%r20 ldws,ma 4(0,%r24),%r19 addib,= -1,%r23,L$end ; check for (SIZE == 1) add %r20,%r19,%r28 ; add first limbs ignoring cy .label L$loop ldws,ma 4(0,%r25),%r20 ldws,ma 4(0,%r24),%r19 stws,ma %r28,4(0,%r26) addib,<> -1,%r23,L$loop addc %r20,%r19,%r28 .label L$end stws %r28,0(0,%r26) bv 0(%r2) addc %r0,%r0,%r28 .exit .procend
a1ive/grub
7,052
grub-core/lib/libgcrypt/mpi/hppa/udiv-qrnnd.S
/* HP-PA __udiv_qrnnd division support, used from longlong.h. * This version runs fast on pre-PA7000 CPUs. * * Copyright (C) 1993, 1994, 1998, 2001, * 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ /* INPUT PARAMETERS * rem_ptr gr26 * n1 gr25 * n0 gr24 * d gr23 * * The code size is a bit excessive. We could merge the last two ds;addc * sequences by simply moving the "bb,< Odd" instruction down. The only * trouble is the FFFFFFFF code that would need some hacking. */ .code .export __udiv_qrnnd .label __udiv_qrnnd .proc .callinfo frame=0,no_calls .entry comb,< %r23,0,L$largedivisor sub %r0,%r23,%r1 ; clear cy as side-effect ds %r0,%r1,%r0 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r24 ds %r25,%r23,%r25 addc %r24,%r24,%r28 ds %r25,%r23,%r25 comclr,>= %r25,%r0,%r0 addl %r25,%r23,%r25 stws %r25,0(0,%r26) bv 0(%r2) addc %r28,%r28,%r28 .label L$largedivisor extru %r24,31,1,%r19 ; r19 = n0 & 1 bb,< %r23,31,L$odd extru %r23,30,31,%r22 ; r22 = d >> 1 shd %r25,%r24,1,%r24 ; r24 = new n0 extru %r25,30,31,%r25 ; r25 = new n1 sub %r0,%r22,%r21 ds %r0,%r21,%r0 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 comclr,>= %r25,%r0,%r0 addl %r25,%r22,%r25 sh1addl %r25,%r19,%r25 stws %r25,0(0,%r26) bv 0(%r2) addc %r24,%r24,%r28 .label L$odd addib,sv,n 1,%r22,L$FF.. ; r22 = (d / 2 + 1) shd %r25,%r24,1,%r24 ; r24 = new n0 extru %r25,30,31,%r25 ; r25 = new n1 sub %r0,%r22,%r21 ds %r0,%r21,%r0 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r24 ds %r25,%r22,%r25 addc %r24,%r24,%r28 comclr,>= %r25,%r0,%r0 addl %r25,%r22,%r25 sh1addl %r25,%r19,%r25 ; We have computed (n1,,n0) / (d + 1), q' = r28, r' = r25 add,nuv %r28,%r25,%r25 addl %r25,%r1,%r25 addc %r0,%r28,%r28 sub,<< %r25,%r23,%r0 addl %r25,%r1,%r25 stws %r25,0(0,%r26) bv 0(%r2) addc %r0,%r28,%r28 ; This is just a special case of the code above. ; We come here when d == 0xFFFFFFFF .label L$FF.. add,uv %r25,%r24,%r24 sub,<< %r24,%r23,%r0 ldo 1(%r24),%r24 stws %r24,0(0,%r26) bv 0(%r2) addc %r0,%r25,%r28 .exit .procend
a1ive/grub
2,245
grub-core/lib/libgcrypt/mpi/hppa/mpih-sub1.S
/* hppa sub_n -- Sub two limb vectors of the same length > 0 and store * sum in a third limb vector. * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (gr26) * mpi_ptr_t s1_ptr, (gr25) * mpi_ptr_t s2_ptr, (gr24) * mpi_size_t size) (gr23) * * One might want to unroll this as for other processors, but it turns * out that the data cache contention after a store makes such * unrolling useless. We can't come under 5 cycles/limb anyway. */ .code .export _gcry_mpih_sub_n .label _gcry_mpih_sub_n .proc .callinfo frame=0,no_calls .entry ldws,ma 4(0,%r25),%r20 ldws,ma 4(0,%r24),%r19 addib,= -1,%r23,L$end ; check for (SIZE == 1) sub %r20,%r19,%r28 ; subtract first limbs ignoring cy .label L$loop ldws,ma 4(0,%r25),%r20 ldws,ma 4(0,%r24),%r19 stws,ma %r28,4(0,%r26) addib,<> -1,%r23,L$loop subb %r20,%r19,%r28 .label L$end stws %r28,0(0,%r26) addc %r0,%r0,%r28 bv 0(%r2) subi 1,%r28,%r28 .exit .procend
a1ive/grub
2,323
grub-core/lib/libgcrypt/mpi/pa7100/mpih-lshift.S
/* hppa lshift * optimized for the PA7100, where it runs at 3.25 cycles/limb * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, (gr26) * mpi_ptr_t up, (gr25) * mpi_size_t usize, (gr24) * unsigned cnt) (gr23) */ .code .export _gcry_mpih_lshift .label _gcry_mpih_lshift .proc .callinfo frame=64,no_calls .entry sh2add %r24,%r25,%r25 sh2add %r24,%r26,%r26 ldws,mb -4(0,%r25),%r22 subi 32,%r23,%r1 mtsar %r1 addib,= -1,%r24,L$0004 vshd %r0,%r22,%r28 ; compute carry out limb ldws,mb -4(0,%r25),%r29 addib,<= -5,%r24,L$rest vshd %r22,%r29,%r20 .label L$loop ldws,mb -4(0,%r25),%r22 stws,mb %r20,-4(0,%r26) vshd %r29,%r22,%r20 ldws,mb -4(0,%r25),%r29 stws,mb %r20,-4(0,%r26) vshd %r22,%r29,%r20 ldws,mb -4(0,%r25),%r22 stws,mb %r20,-4(0,%r26) vshd %r29,%r22,%r20 ldws,mb -4(0,%r25),%r29 stws,mb %r20,-4(0,%r26) addib,> -4,%r24,L$loop vshd %r22,%r29,%r20 .label L$rest addib,= 4,%r24,L$end1 nop .label L$eloop ldws,mb -4(0,%r25),%r22 stws,mb %r20,-4(0,%r26) addib,<= -1,%r24,L$end2 vshd %r29,%r22,%r20 ldws,mb -4(0,%r25),%r29 stws,mb %r20,-4(0,%r26) addib,> -1,%r24,L$eloop vshd %r22,%r29,%r20 .label L$end1 stws,mb %r20,-4(0,%r26) vshd %r29,%r0,%r20 bv 0(%r2) stw %r20,-4(0,%r26) .label L$end2 stws,mb %r20,-4(0,%r26) .label L$0004 vshd %r22,%r0,%r20 bv 0(%r2) stw %r20,-4(0,%r26) .exit .procend
a1ive/grub
2,262
grub-core/lib/libgcrypt/mpi/pa7100/mpih-rshift.S
/* hppa rshift * optimized for the PA7100, where it runs at 3.25 cycles/limb * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, (gr26) * mpi_ptr_t up, (gr25) * mpi_size_t usize, (gr24) * unsigned cnt) (gr23) */ .code .export _gcry_mpih_rshift .label _gcry_mpih_rshift .proc .callinfo frame=64,no_calls .entry ldws,ma 4(0,%r25),%r22 mtsar %r23 addib,= -1,%r24,L$r004 vshd %r22,%r0,%r28 ; compute carry out limb ldws,ma 4(0,%r25),%r29 addib,<= -5,%r24,L$rrest vshd %r29,%r22,%r20 .label L$roop ldws,ma 4(0,%r25),%r22 stws,ma %r20,4(0,%r26) vshd %r22,%r29,%r20 ldws,ma 4(0,%r25),%r29 stws,ma %r20,4(0,%r26) vshd %r29,%r22,%r20 ldws,ma 4(0,%r25),%r22 stws,ma %r20,4(0,%r26) vshd %r22,%r29,%r20 ldws,ma 4(0,%r25),%r29 stws,ma %r20,4(0,%r26) addib,> -4,%r24,L$roop vshd %r29,%r22,%r20 .label L$rrest addib,= 4,%r24,L$rend1 nop .label L$eroop ldws,ma 4(0,%r25),%r22 stws,ma %r20,4(0,%r26) addib,<= -1,%r24,L$rend2 vshd %r22,%r29,%r20 ldws,ma 4(0,%r25),%r29 stws,ma %r20,4(0,%r26) addib,> -1,%r24,L$eroop vshd %r29,%r22,%r20 .label L$rend1 stws,ma %r20,4(0,%r26) vshd %r0,%r29,%r20 bv 0(%r2) stw %r20,0(0,%r26) .label L$rend2 stws,ma %r20,4(0,%r26) .label L$r004 vshd %r0,%r22,%r20 bv 0(%r2) stw %r20,0(0,%r26) .exit .procend
a1ive/grub
2,721
grub-core/lib/libgcrypt/mpi/sparc32v8/mpih-mul1.S
/* SPARC v8 __mpn_mul_1 -- Multiply a limb vector with a single limb and * store the product in a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ ! INPUT PARAMETERS ! res_ptr o0 ! s1_ptr o1 ! size o2 ! s2_limb o3 #include "sysdep.h" .text .align 8 .global C_SYMBOL_NAME(_gcry_mpih_mul_1) C_SYMBOL_NAME(_gcry_mpih_mul_1): sll %o2,4,%g1 and %g1,(4-1)<<4,%g1 #if PIC mov %o7,%g4 ! Save return address register call 1f add %o7,LL-1f,%g3 1: mov %g4,%o7 ! Restore return address register #else sethi %hi(LL),%g3 or %g3,%lo(LL),%g3 #endif jmp %g3+%g1 ld [%o1+0],%o4 ! 1 LL: LL00: add %o0,-4,%o0 add %o1,-4,%o1 b Loop00 /* 4, 8, 12, ... */ orcc %g0,%g0,%g2 LL01: b Loop01 /* 1, 5, 9, ... */ orcc %g0,%g0,%g2 nop nop LL10: add %o0,-12,%o0 /* 2, 6, 10, ... */ add %o1,4,%o1 b Loop10 orcc %g0,%g0,%g2 nop LL11: add %o0,-8,%o0 /* 3, 7, 11, ... */ add %o1,-8,%o1 b Loop11 orcc %g0,%g0,%g2 Loop: addcc %g3,%g2,%g3 ! 1 ld [%o1+4],%o4 ! 2 st %g3,[%o0+0] ! 1 rd %y,%g2 ! 1 Loop00: umul %o4,%o3,%g3 ! 2 addxcc %g3,%g2,%g3 ! 2 ld [%o1+8],%o4 ! 3 st %g3,[%o0+4] ! 2 rd %y,%g2 ! 2 Loop11: umul %o4,%o3,%g3 ! 3 addxcc %g3,%g2,%g3 ! 3 ld [%o1+12],%o4 ! 4 add %o1,16,%o1 st %g3,[%o0+8] ! 3 rd %y,%g2 ! 3 Loop10: umul %o4,%o3,%g3 ! 4 addxcc %g3,%g2,%g3 ! 4 ld [%o1+0],%o4 ! 1 st %g3,[%o0+12] ! 4 add %o0,16,%o0 rd %y,%g2 ! 4 addx %g0,%g2,%g2 Loop01: addcc %o2,-4,%o2 bg Loop umul %o4,%o3,%g3 ! 1 addcc %g3,%g2,%g3 ! 4 st %g3,[%o0+0] ! 4 rd %y,%g2 ! 4 retl addx %g0,%g2,%o0
a1ive/grub
3,062
grub-core/lib/libgcrypt/mpi/sparc32v8/mpih-mul2.S
/* SPARC v8 __mpn_addmul_1 -- Multiply a limb vector with a limb and * add the result to a second limb vector. * * Copyright (C) 1992, 1993, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ ! INPUT PARAMETERS ! res_ptr o0 ! s1_ptr o1 ! size o2 ! s2_limb o3 #include "sysdep.h" .text .align 4 .global C_SYMBOL_NAME(_gcry_mpih_addmul_1) C_SYMBOL_NAME(_gcry_mpih_addmul_1): orcc %g0,%g0,%g2 ld [%o1+0],%o4 ! 1 sll %o2,4,%g1 and %g1,(4-1)<<4,%g1 #if PIC mov %o7,%g4 ! Save return address register call 1f add %o7,LL-1f,%g3 1: mov %g4,%o7 ! Restore return address register #else sethi %hi(LL),%g3 or %g3,%lo(LL),%g3 #endif jmp %g3+%g1 nop LL: LL00: add %o0,-4,%o0 b Loop00 /* 4, 8, 12, ... */ add %o1,-4,%o1 nop LL01: b Loop01 /* 1, 5, 9, ... */ nop nop nop LL10: add %o0,-12,%o0 /* 2, 6, 10, ... */ b Loop10 add %o1,4,%o1 nop LL11: add %o0,-8,%o0 /* 3, 7, 11, ... */ b Loop11 add %o1,-8,%o1 nop 1: addcc %g3,%g2,%g3 ! 1 ld [%o1+4],%o4 ! 2 rd %y,%g2 ! 1 addx %g0,%g2,%g2 ld [%o0+0],%g1 ! 2 addcc %g1,%g3,%g3 st %g3,[%o0+0] ! 1 Loop00: umul %o4,%o3,%g3 ! 2 ld [%o0+4],%g1 ! 2 addxcc %g3,%g2,%g3 ! 2 ld [%o1+8],%o4 ! 3 rd %y,%g2 ! 2 addx %g0,%g2,%g2 nop addcc %g1,%g3,%g3 st %g3,[%o0+4] ! 2 Loop11: umul %o4,%o3,%g3 ! 3 addxcc %g3,%g2,%g3 ! 3 ld [%o1+12],%o4 ! 4 rd %y,%g2 ! 3 add %o1,16,%o1 addx %g0,%g2,%g2 ld [%o0+8],%g1 ! 2 addcc %g1,%g3,%g3 st %g3,[%o0+8] ! 3 Loop10: umul %o4,%o3,%g3 ! 4 addxcc %g3,%g2,%g3 ! 4 ld [%o1+0],%o4 ! 1 rd %y,%g2 ! 4 addx %g0,%g2,%g2 ld [%o0+12],%g1 ! 2 addcc %g1,%g3,%g3 st %g3,[%o0+12] ! 4 add %o0,16,%o0 addx %g0,%g2,%g2 Loop01: addcc %o2,-4,%o2 bg 1b umul %o4,%o3,%g3 ! 1 addcc %g3,%g2,%g3 ! 4 rd %y,%g2 ! 4 addx %g0,%g2,%g2 ld [%o0+0],%g1 ! 2 addcc %g1,%g3,%g3 st %g3,[%o0+0] ! 4 addx %g0,%g2,%o0 retl nop ! umul, ld, addxcc, rd, st ! umul, ld, addxcc, rd, ld, addcc, st, addx
a1ive/grub
1,935
grub-core/lib/libgcrypt/mpi/sparc32v8/mpih-mul3.S
/* SPARC v8 __mpn_submul_1 -- Multiply a limb vector with a limb and * subtract the result from a second limb vector. * * Copyright (C) 1992, 1993, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ ! INPUT PARAMETERS ! res_ptr o0 ! s1_ptr o1 ! size o2 ! s2_limb o3 #include "sysdep.h" .text .align 4 .global C_SYMBOL_NAME(_gcry_mpih_submul_1) C_SYMBOL_NAME(_gcry_mpih_submul_1): sub %g0,%o2,%o2 ! negate ... sll %o2,2,%o2 ! ... and scale size sub %o1,%o2,%o1 ! o1 is offset s1_ptr sub %o0,%o2,%g1 ! g1 is offset res_ptr mov 0,%o0 ! clear cy_limb Loop: ld [%o1+%o2],%o4 ld [%g1+%o2],%g2 umul %o4,%o3,%o5 rd %y,%g3 addcc %o5,%o0,%o5 addx %g3,0,%o0 subcc %g2,%o5,%g2 addx %o0,0,%o0 st %g2,[%g1+%o2] addcc %o2,4,%o2 bne Loop nop retl nop
a1ive/grub
3,604
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-mul1.S
/* PowerPC-32 mul_1 -- Multiply a limb vector with a limb and store * the result in a second limb vector. * * Copyright (C) 1992, 1993, 1994, 1995, * 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (r3) * mpi_ptr_t s1_ptr, (r4) * mpi_size_t s1_size, (r5) * mpi_limb_t s2_limb) (r6) * * This is a fairly straightforward implementation. The timing of the PC601 * is hard to understand, so I will wait to optimize this until I have some * hardware to play with. * * The code trivially generalizes to 64 bit limbs for the PC620. */ .toc .csect ._gcry_mpih_mul_1[PR] .align 2 .globl _gcry_mpih_mul_1 .globl ._gcry_mpih_mul_1 .csect _gcry_mpih_mul_1[DS] _gcry_mpih_mul_1: .long ._gcry_mpih_mul_1[PR], TOC[tc0], 0 .csect ._gcry_mpih_mul_1[PR] ._gcry_mpih_mul_1: mtctr 5 lwz 0,0(4) mullw 7,0,6 mulhwu 10,0,6 addi 3,3,-4 # adjust res_ptr addic 5,5,0 # clear cy with dummy insn bdz Lend Loop: lwzu 0,4(4) stwu 7,4(3) mullw 8,0,6 adde 7,8,10 mulhwu 10,0,6 bdnz Loop Lend: stw 7,4(3) addze 3,10 blr #else /* Multiply a limb vector by a limb, for PowerPC. Copyright (C) 1993, 1994, 1995, 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mp_limb_t mpn_mul_1 (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_size_t s1_size, mp_limb_t s2_limb) Calculate s1*s2 and put result in res_ptr; return carry. */ ENTRY(_gcry_mpih_mul_1) mtctr %r5 lwz %r0,0(%r4) mullw %r7,%r0,%r6 mulhwu %r10,%r0,%r6 addi %r3,%r3,-4 # adjust res_ptr addic %r5,%r5,0 # clear cy with dummy insn bdz 1f 0: lwzu %r0,4(%r4) stwu %r7,4(%r3) mullw %r8,%r0,%r6 adde %r7,%r8,%r10 mulhwu %r10,%r0,%r6 bdnz 0b 1: stw %r7,4(%r3) addze %r3,%r10 blr END(_gcry_mpih_mul_1) #endif
a1ive/grub
3,717
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-mul2.S
/* PowerPC-32 addmul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1995, 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (r3) * mpi_ptr_t s1_ptr, (r4) * mpi_size_t s1_size, (r5) * mpi_limb_t s2_limb) (r6) * * This is a fairly straightforward implementation. The timing of the PC601 * is hard to understand, so I will wait to optimize this until I have some * hardware to play with. * * The code trivially generalizes to 64 bit limbs for the PC620. */ .toc .csect ._gcry_mpih_addmul_1[PR] .align 2 .globl _gcry_mpih_addmul_1 .globl ._gcry_mpih_addmul_1 .csect _gcry_mpih_addmul_1[DS] _gcry_mpih_addmul_1: .long ._gcry_mpih_addmul_1[PR], TOC[tc0], 0 .csect ._gcry_mpih_addmul_1[PR] ._gcry_mpih_addmul_1: mtctr 5 lwz 0,0(4) mullw 7,0,6 mulhwu 10,0,6 lwz 9,0(3) addc 8,7,9 addi 3,3,-4 bdz Lend Loop: lwzu 0,4(4) stwu 8,4(3) mullw 8,0,6 adde 7,8,10 mulhwu 10,0,6 lwz 9,4(3) addze 10,10 addc 8,7,9 bdnz Loop Lend: stw 8,4(3) addze 3,10 blr #else /* Multiply a limb vector by a single limb, for PowerPC. Copyright (C) 1993, 1994, 1995, 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mp_limb_t mpn_addmul_1 (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_size_t s1_size, mp_limb_t s2_limb) Calculate res+s1*s2 and put result back in res; return carry. */ ENTRY(_gcry_mpih_addmul_1) mtctr %r5 lwz %r0,0(%r4) mullw %r7,%r0,%r6 mulhwu %r10,%r0,%r6 lwz %r9,0(%r3) addc %r8,%r7,%r9 addi %r3,%r3,-4 /* adjust res_ptr */ bdz 1f 0: lwzu %r0,4(%r4) stwu %r8,4(%r3) mullw %r8,%r0,%r6 adde %r7,%r8,%r10 mulhwu %r10,%r0,%r6 lwz %r9,4(%r3) addze %r10,%r10 addc %r8,%r7,%r9 bdnz 0b 1: stw %r8,4(%r3) addze %r3,%r10 blr END(_gcry_mpih_addmul_1) #endif
a1ive/grub
5,431
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-lshift.S
/* PowerPC-32 lshift * * Copyright (C) 1995, 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, (r3) * mpi_ptr_t up, (r4) * mpi_size_t usize, (r5) * unsigned cnt) (r6) */ .toc .csect .text[PR] .align 2 .globl _gcry_mpih_lshift .globl ._gcry_mpih_lshift .csect _gcry_mpih_lshift[DS] _gcry_mpih_lshift: .long ._gcry_mpih_lshift, TOC[tc0], 0 .csect .text[PR] ._gcry_mpih_lshift: mtctr 5 # copy size into CTR slwi 0,5,2 add 7,3,0 # make r7 point at end of res add 4,4,0 # make r4 point at end of s1 subfic 8,6,32 lwzu 11,-4(4) # load first s1 limb srw 3,11,8 # compute function return value bdz Lend1 Loop: lwzu 10,-4(4) slw 9,11,6 srw 12,10,8 or 9,9,12 stwu 9,-4(7) bdz Lend2 lwzu 11,-4(4) slw 9,10,6 srw 12,11,8 or 9,9,12 stwu 9,-4(7) bdnz Loop Lend1: slw 0,11,6 stw 0,-4(7) blr Lend2: slw 0,10,6 stw 0,-4(7) blr #else /* Shift a limb left, low level routine. Copyright (C) 1996, 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mp_limb_t mpn_lshift (mp_ptr wp, mp_srcptr up, mp_size_t usize, unsigned int cnt) */ EALIGN(_gcry_mpih_lshift,3,0) mtctr %r5 # copy size into CTR cmplwi %cr0,%r5,16 # is size < 16 slwi %r0,%r5,2 add %r7,%r3,%r0 # make r7 point at end of res add %r4,%r4,%r0 # make r4 point at end of s1 lwzu %r11,-4(%r4) # load first s1 limb subfic %r8,%r6,32 srw %r3,%r11,%r8 # compute function return value bge %cr0,L(big) # branch if size >= 16 bdz L(end1) 0: lwzu %r10,-4(%r4) slw %r9,%r11,%r6 srw %r12,%r10,%r8 or %r9,%r9,%r12 stwu %r9,-4(%r7) bdz L(end2) lwzu %r11,-4(%r4) slw %r9,%r10,%r6 srw %r12,%r11,%r8 or %r9,%r9,%r12 stwu %r9,-4(%r7) bdnz 0b L(end1):slw %r0,%r11,%r6 stw %r0,-4(%r7) blr /* Guaranteed not to succeed. */ L(boom): tweq %r0,%r0 /* We imitate a case statement, by using (yuk!) fixed-length code chunks, of size 4*12 bytes. We have to do this (or something) to make this PIC. */ L(big): mflr %r9 bltl- %cr0,L(boom) # Never taken, only used to set LR. slwi %r10,%r6,4 mflr %r12 add %r10,%r12,%r10 slwi %r8,%r6,5 add %r10,%r8,%r10 mtctr %r10 addi %r5,%r5,-1 mtlr %r9 bctr L(end2):slw %r0,%r10,%r6 stw %r0,-4(%r7) blr #define DO_LSHIFT(n) \ mtctr %r5; \ 0: lwzu %r10,-4(%r4); \ slwi %r9,%r11,n; \ inslwi %r9,%r10,n,32-n; \ stwu %r9,-4(%r7); \ bdz- L(end2); \ lwzu %r11,-4(%r4); \ slwi %r9,%r10,n; \ inslwi %r9,%r11,n,32-n; \ stwu %r9,-4(%r7); \ bdnz 0b; \ b L(end1) DO_LSHIFT(1) DO_LSHIFT(2) DO_LSHIFT(3) DO_LSHIFT(4) DO_LSHIFT(5) DO_LSHIFT(6) DO_LSHIFT(7) DO_LSHIFT(8) DO_LSHIFT(9) DO_LSHIFT(10) DO_LSHIFT(11) DO_LSHIFT(12) DO_LSHIFT(13) DO_LSHIFT(14) DO_LSHIFT(15) DO_LSHIFT(16) DO_LSHIFT(17) DO_LSHIFT(18) DO_LSHIFT(19) DO_LSHIFT(20) DO_LSHIFT(21) DO_LSHIFT(22) DO_LSHIFT(23) DO_LSHIFT(24) DO_LSHIFT(25) DO_LSHIFT(26) DO_LSHIFT(27) DO_LSHIFT(28) DO_LSHIFT(29) DO_LSHIFT(30) DO_LSHIFT(31) END(_gcry_mpih_lshift) #endif
a1ive/grub
3,470
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-rshift.S
/* PowerPC-32 rshift * * Copyright (C) 1995, 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, (r3) * mpi_ptr_t up, (r4) * mpi_size_t usize, (r5) * unsigned cnt) (r6) */ .toc .csect .text[PR] .align 2 .globl _gcry_mpih_rshift .globl ._gcry_mpih_rshift .csect _gcry_mpih_rshift[DS] _gcry_mpih_rshift: .long ._gcry_mpih_rshift, TOC[tc0], 0 .csect .text[PR] ._gcry_mpih_rshift: mtctr 5 # copy size into CTR addi 7,3,-4 # move adjusted res_ptr to free return reg subfic 8,6,32 lwz 11,0(4) # load first s1 limb slw 3,11,8 # compute function return value bdz Lend1 Loop: lwzu 10,4(4) srw 9,11,6 slw 12,10,8 or 9,9,12 stwu 9,4(7) bdz Lend2 lwzu 11,4(4) srw 9,10,6 slw 12,11,8 or 9,9,12 stwu 9,4(7) bdnz Loop Lend1: srw 0,11,6 stw 0,4(7) blr Lend2: srw 0,10,6 stw 0,4(7) blr #else /* Shift a limb right, low level routine. Copyright (C) 1995, 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* INPUT PARAMETERS res_ptr r3 s1_ptr r4 size r5 cnt r6 */ ENTRY(_gcry_mpih_rshift) mtctr 5 # copy size into CTR addi 7,3,-4 # move adjusted res_ptr to free return reg subfic 8,6,32 lwz 11,0(4) # load first s1 limb slw 3,11,8 # compute function return value bdz 1f 0: lwzu 10,4(4) srw 9,11,6 slw 12,10,8 or 9,9,12 stwu 9,4(7) bdz 2f lwzu 11,4(4) srw 9,10,6 slw 12,11,8 or 9,9,12 stwu 9,4(7) bdnz 0b 1: srw 0,11,6 stw 0,4(7) blr 2: srw 0,10,6 stw 0,4(7) blr END(_gcry_mpih_rshift) #endif
a1ive/grub
3,915
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-mul3.S
/* PowerPC-32 submul_1 -- Multiply a limb vector with a limb and subtract * the result from a second limb vector. * * Copyright (C) 1995, 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (r3) * mpi_ptr_t s1_ptr, (r4) * mpi_size_t s1_size, (r5) * mpi_limb_t s2_limb) (r6) * * This is a fairly straightforward implementation. The timing of the PC601 * is hard to understand, so I will wait to optimize this until I have some * hardware to play with. * * The code trivially generalizes to 64 bit limbs for the PC620. */ .toc .csect ._gcry_mpih_submul_1[PR] .align 2 .globl _gcry_mpih_submul_1 .globl ._gcry_mpih_submul_1 .csect _gcry_mpih_submul_1[DS] _gcry_mpih_submul_1: .long ._gcry_mpih_submul_1[PR], TOC[tc0], 0 .csect ._gcry_mpih_submul_1[PR] ._gcry_mpih_submul_1: mtctr 5 lwz 0,0(4) mullw 7,0,6 mulhwu 10,0,6 lwz 9,0(3) subfc 8,7,9 addc 7,7,8 # invert cy (r7 is junk) addi 3,3,-4 bdz Lend Loop: lwzu 0,4(4) stwu 8,4(3) mullw 8,0,6 adde 7,8,10 mulhwu 10,0,6 lwz 9,4(3) addze 10,10 subfc 8,7,9 addc 7,7,8 # invert cy (r7 is junk) bdnz Loop Lend: stw 8,4(3) addze 3,10 blr #else /* Multiply a limb vector by a single limb, for PowerPC. Copyright (C) 1993, 1994, 1995, 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mp_limb_t mpn_submul_1 (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_size_t s1_size, mp_limb_t s2_limb) Calculate res-s1*s2 and put result back in res; return carry. */ ENTRY(_gcry_mpih_submul_1) mtctr %r5 lwz %r0,0(%r4) mullw %r7,%r0,%r6 mulhwu %r10,%r0,%r6 lwz %r9,0(%r3) subf %r8,%r7,%r9 addc %r7,%r7,%r8 # invert cy (r7 is junk) addi %r3,%r3,-4 # adjust res_ptr bdz 1f 0: lwzu %r0,4(%r4) stwu %r8,4(%r3) mullw %r8,%r0,%r6 adde %r7,%r8,%r10 mulhwu %r10,%r0,%r6 lwz %r9,4(%r3) addze %r10,%r10 subf %r8,%r7,%r9 addc %r7,%r7,%r8 # invert cy (r7 is junk) bdnz 0b 1: stw %r8,4(%r3) addze %r3,%r10 blr END(_gcry_mpih_submul_1) #endif
a1ive/grub
4,260
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-add1.S
/* PowerPC-32 add_n -- Add two limb vectors of equal, non-zero length. * * Copyright (C) 1992, 1994, 1995, 1998, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, (r3) * mpi_ptr_t s1_ptr, (r4) * mpi_ptr_t s2_ptr, (r5) * mpi_size_t size) (r6) */ .toc .extern _gcry_mpih_add_n[DS] .extern ._gcry_mpih_add_n .csect [PR] .align 2 .globl _gcry_mpih_add_n .globl ._gcry_mpih_add_n .csect _gcry_mpih_add_n[DS] _gcry_mpih_add_n: .long ._gcry_mpih_add_n, TOC[tc0], 0 .csect [PR] ._gcry_mpih_add_n: mtctr 6 # copy size into CTR lwz 8,0(4) # load least significant s1 limb lwz 0,0(5) # load least significant s2 limb addi 3,3,-4 # offset res_ptr, it is updated before used addc 7,0,8 # add least significant limbs, set cy bdz Lend # If done, skip loop Loop: lwzu 8,4(4) # load s1 limb and update s1_ptr lwzu 0,4(5) # load s2 limb and update s2_ptr stwu 7,4(3) # store previous limb in load latency slot adde 7,0,8 # add new limbs with cy, set cy bdnz Loop # decrement CTR and loop back Lend: stw 7,4(3) # store ultimate result limb li 3,0 # load cy into ... addze 3,3 # ... return value register blr #else /* Add two limb vectors of equal, non-zero length for PowerPC. Copyright (C) 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "sysdep.h" #include "asm-syntax.h" /* mp_limb_t mpn_add_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) Calculate s1+s2 and put result in res_ptr; return carry, 0 or 1. */ /* Note on optimisation: This code is optimal for the 601. Almost every other possible 2-unrolled inner loop will not be. Also, watch out for the alignment... */ EALIGN(_gcry_mpih_add_n,3,0) /* Set up for loop below. */ mtcrf 0x01,%r6 srwi. %r7,%r6,1 li %r10,0 mtctr %r7 bt 31,2f /* Clear the carry. */ addic %r0,%r0,0 /* Adjust pointers for loop. */ addi %r3,%r3,-4 addi %r4,%r4,-4 addi %r5,%r5,-4 b 0f 2: lwz %r7,0(%r5) lwz %r6,0(%r4) addc %r6,%r6,%r7 stw %r6,0(%r3) beq 1f /* The loop. */ /* Align start of loop to an odd word boundary to guarantee that the last two words can be fetched in one access (for 601). */ 0: lwz %r9,4(%r4) lwz %r8,4(%r5) lwzu %r6,8(%r4) lwzu %r7,8(%r5) adde %r8,%r9,%r8 stw %r8,4(%r3) adde %r6,%r6,%r7 stwu %r6,8(%r3) bdnz 0b /* Return the carry. */ 1: addze %r3,%r10 blr END(_gcry_mpih_add_n) #endif
a1ive/grub
4,367
grub-core/lib/libgcrypt/mpi/powerpc32/mpih-sub1.S
/* PowerPC-32 sub_n -- Subtract two limb vectors of the same length > 0 * and store difference in a third limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "sysdep.h" #include "asm-syntax.h" #ifndef USE_PPC_PATCHES /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (r3) * mpi_ptr_t s1_ptr, (r4) * mpi_ptr_t s2_ptr, (r5) * mpi_size_t size) (r6) */ .toc .extern _gcry_mpih_sub_n[DS] .extern ._gcry_mpih_sub_n .csect [PR] .align 2 .globl _gcry_mpih_sub_n .globl ._gcry_mpih_sub_n .csect _gcry_mpih_sub_n[DS] _gcry_mpih_sub_n: .long ._gcry_mpih_sub_n, TOC[tc0], 0 .csect [PR] ._gcry_mpih_sub_n: mtctr 6 # copy size into CTR lwz 8,0(4) # load least significant s1 limb lwz 0,0(5) # load least significant s2 limb addi 3,3,-4 # offset res_ptr, it is updated before used subfc 7,0,8 # add least significant limbs, set cy bdz Lend # If done, skip loop Loop: lwzu 8,4(4) # load s1 limb and update s1_ptr lwzu 0,4(5) # load s2 limb and update s2_ptr stwu 7,4(3) # store previous limb in load latency slot subfe 7,0,8 # add new limbs with cy, set cy bdnz Loop # decrement CTR and loop back Lend: stw 7,4(3) # store ultimate result limb subfe 3,0,0 # load !cy into ... subfic 3,3,0 # ... return value register blr #else /* Subtract two limb vectors of equal, non-zero length for PowerPC. Copyright (C) 1997 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 Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* mp_limb_t mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size) Calculate s1-s2 and put result in res_ptr; return borrow, 0 or 1. */ /* Note on optimisation: This code is optimal for the 601. Almost every other possible 2-unrolled inner loop will not be. Also, watch out for the alignment... */ EALIGN(_gcry_mpih_sub_n,3,1) /* Set up for loop below. */ mtcrf 0x01,%r6 srwi. %r7,%r6,1 mtctr %r7 bt 31,2f /* Set the carry (clear the borrow). */ subfc %r0,%r0,%r0 /* Adjust pointers for loop. */ addi %r3,%r3,-4 addi %r4,%r4,-4 addi %r5,%r5,-4 b 0f 2: lwz %r7,0(%r5) lwz %r6,0(%r4) subfc %r6,%r7,%r6 stw %r6,0(%r3) beq 1f /* Align start of loop to an odd word boundary to guarantee that the last two words can be fetched in one access (for 601). This turns out to be important. */ 0: lwz %r9,4(%r4) lwz %r8,4(%r5) lwzu %r6,8(%r4) lwzu %r7,8(%r5) subfe %r8,%r8,%r9 stw %r8,4(%r3) subfe %r6,%r7,%r6 stwu %r6,8(%r3) bdnz 0b /* Return the borrow. */ 1: subfe %r3,%r3,%r3 neg %r3,%r3 blr END(_gcry_mpih_sub_n) #endif
a1ive/grub
2,294
grub-core/lib/libgcrypt/mpi/mips3/mpih-mul1.S
/* mips3 mpih-mul1.S -- Multiply a limb vector with a limb and store * the result in a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, 2000 * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (r4) * mpi_ptr_t s1_ptr, (r5) * mpi_size_t s1_size, (r6) * mpi_limb_t s2_limb) (r7) */ .text .align 4 .globl _gcry_mpih_mul_1 .ent _gcry_mpih_mul_1 _gcry_mpih_mul_1: .set noreorder .set nomacro /* # warm up phase 0 */ ld $8,0($5) /* # warm up phase 1 */ daddiu $5,$5,8 dmultu $8,$7 daddiu $6,$6,-1 beq $6,$0,$LC0 move $2,$0 # zero cy2 daddiu $6,$6,-1 beq $6,$0,$LC1 ld $8,0($5) # load new s1 limb as early as possible Loop: mflo $10 mfhi $9 daddiu $5,$5,8 daddu $10,$10,$2 # add old carry limb to low product limb dmultu $8,$7 ld $8,0($5) # load new s1 limb as early as possible daddiu $6,$6,-1 # decrement loop counter sltu $2,$10,$2 # carry from previous addition -> $2 sd $10,0($4) daddiu $4,$4,8 bne $6,$0,Loop daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 1 */ $LC1: mflo $10 mfhi $9 daddu $10,$10,$2 sltu $2,$10,$2 dmultu $8,$7 sd $10,0($4) daddiu $4,$4,8 daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 0 */ $LC0: mflo $10 mfhi $9 daddu $10,$10,$2 sltu $2,$10,$2 sd $10,0($4) j $31 daddu $2,$9,$2 # add high product limb and carry from addition .end _gcry_mpih_mul_1
a1ive/grub
2,527
grub-core/lib/libgcrypt/mpi/mips3/mpih-mul2.S
/* MIPS3 addmul_1 -- Multiply a limb vector with a single limb and * add the product to a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, 2000 * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (r4) * mpi_ptr_t s1_ptr, (r5) * mpi_size_t s1_size, (r6) * mpi_limb_t s2_limb) (r7) */ .text .align 4 .globl _gcry_mpih_addmul_1 .ent _gcry_mpih_addmul_1 _gcry_mpih_addmul_1: .set noreorder .set nomacro /* # warm up phase 0 */ ld $8,0($5) /* # warm up phase 1 */ daddiu $5,$5,8 dmultu $8,$7 daddiu $6,$6,-1 beq $6,$0,$LC0 move $2,$0 # zero cy2 daddiu $6,$6,-1 beq $6,$0,$LC1 ld $8,0($5) # load new s1 limb as early as possible Loop: ld $10,0($4) mflo $3 mfhi $9 daddiu $5,$5,8 daddu $3,$3,$2 # add old carry limb to low product limb dmultu $8,$7 ld $8,0($5) # load new s1 limb as early as possible daddiu $6,$6,-1 # decrement loop counter sltu $2,$3,$2 # carry from previous addition -> $2 daddu $3,$10,$3 sltu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) daddiu $4,$4,8 bne $6,$0,Loop daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 1 */ $LC1: ld $10,0($4) mflo $3 mfhi $9 daddu $3,$3,$2 sltu $2,$3,$2 dmultu $8,$7 daddu $3,$10,$3 sltu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) daddiu $4,$4,8 daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 0 */ $LC0: ld $10,0($4) mflo $3 mfhi $9 daddu $3,$3,$2 sltu $2,$3,$2 daddu $3,$10,$3 sltu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) j $31 daddu $2,$9,$2 # add high product limb and carry from addition .end _gcry_mpih_addmul_1
a1ive/grub
2,172
grub-core/lib/libgcrypt/mpi/mips3/mpih-lshift.S
/* mips3 lshift * * Copyright (C) 1995, 1998, 2000, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, ($4) * mpi_ptr_t up, ($5) * mpi_size_t usize, ($6) * unsigned cnt) ($7) */ .text .align 2 .globl _gcry_mpih_lshift .ent _gcry_mpih_lshift _gcry_mpih_lshift: .set noreorder .set nomacro dsll $2,$6,3 daddu $5,$5,$2 # make r5 point at end of src ld $10,-8($5) # load first limb dsubu $13,$0,$7 daddu $4,$4,$2 # make r4 point at end of res daddiu $6,$6,-1 and $9,$6,4-1 # number of limbs in first loop beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop dsrl $2,$10,$13 # compute function result dsubu $6,$6,$9 .Loop0: ld $3,-16($5) daddiu $4,$4,-8 daddiu $5,$5,-8 daddiu $9,$9,-1 dsll $11,$10,$7 dsrl $12,$3,$13 move $10,$3 or $8,$11,$12 bne $9,$0,.Loop0 sd $8,0($4) .L0: beq $6,$0,.Lend nop .Loop: ld $3,-16($5) daddiu $4,$4,-32 daddiu $6,$6,-4 dsll $11,$10,$7 dsrl $12,$3,$13 ld $10,-24($5) dsll $14,$3,$7 or $8,$11,$12 sd $8,24($4) dsrl $9,$10,$13 ld $3,-32($5) dsll $11,$10,$7 or $8,$14,$9 sd $8,16($4) dsrl $12,$3,$13 ld $10,-40($5) dsll $14,$3,$7 or $8,$11,$12 sd $8,8($4) dsrl $9,$10,$13 daddiu $5,$5,-32 or $8,$14,$9 bgtz $6,.Loop sd $8,0($4) .Lend: dsll $8,$10,$7 j $31 sd $8,-8($4) .end _gcry_mpih_lshift
a1ive/grub
2,059
grub-core/lib/libgcrypt/mpi/mips3/mpih-rshift.S
/* mips3 rshift * * Copyright (C) 1995, 1998, 2000 * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, ($4) * mpi_ptr_t up, ($5) * mpi_size_t usize, ($6) * unsigned cnt) ($7) */ .text .align 2 .globl _gcry_mpih_rshift .ent _gcry_mpih_rshift _gcry_mpih_rshift: .set noreorder .set nomacro ld $10,0($5) # load first limb dsubu $13,$0,$7 daddiu $6,$6,-1 and $9,$6,4-1 # number of limbs in first loop beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop dsll $2,$10,$13 # compute function result dsubu $6,$6,$9 .Loop0: ld $3,8($5) daddiu $4,$4,8 daddiu $5,$5,8 daddiu $9,$9,-1 dsrl $11,$10,$7 dsll $12,$3,$13 move $10,$3 or $8,$11,$12 bne $9,$0,.Loop0 sd $8,-8($4) .L0: beq $6,$0,.Lend nop .Loop: ld $3,8($5) daddiu $4,$4,32 daddiu $6,$6,-4 dsrl $11,$10,$7 dsll $12,$3,$13 ld $10,16($5) dsrl $14,$3,$7 or $8,$11,$12 sd $8,-32($4) dsll $9,$10,$13 ld $3,24($5) dsrl $11,$10,$7 or $8,$14,$9 sd $8,-24($4) dsll $12,$3,$13 ld $10,32($5) dsrl $14,$3,$7 or $8,$11,$12 sd $8,-16($4) dsll $9,$10,$13 daddiu $5,$5,32 or $8,$14,$9 bgtz $6,.Loop sd $8,-8($4) .Lend: dsrl $8,$10,$7 j $31 sd $8,0($4) .end _gcry_mpih_rshift
a1ive/grub
2,530
grub-core/lib/libgcrypt/mpi/mips3/mpih-mul3.S
/* MIPS3 submul_1 -- Multiply a limb vector with a single limb and * subtract the product from a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, 2000 * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (r4) * mpi_ptr_t s1_ptr, (r5) * mpi_size_t s1_size, (r6) * mpi_limb_t s2_limb) (r7) */ .text .align 4 .globl _gcry_mpih_submul_1 .ent _gcry_mpih_submul_1 _gcry_mpih_submul_1: .set noreorder .set nomacro /* # warm up phase 0 */ ld $8,0($5) /* # warm up phase 1 */ daddiu $5,$5,8 dmultu $8,$7 daddiu $6,$6,-1 beq $6,$0,$LC0 move $2,$0 # zero cy2 daddiu $6,$6,-1 beq $6,$0,$LC1 ld $8,0($5) # load new s1 limb as early as possible Loop: ld $10,0($4) mflo $3 mfhi $9 daddiu $5,$5,8 daddu $3,$3,$2 # add old carry limb to low product limb dmultu $8,$7 ld $8,0($5) # load new s1 limb as early as possible daddiu $6,$6,-1 # decrement loop counter sltu $2,$3,$2 # carry from previous addition -> $2 dsubu $3,$10,$3 sgtu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) daddiu $4,$4,8 bne $6,$0,Loop daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 1 */ $LC1: ld $10,0($4) mflo $3 mfhi $9 daddu $3,$3,$2 sltu $2,$3,$2 dmultu $8,$7 dsubu $3,$10,$3 sgtu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) daddiu $4,$4,8 daddu $2,$9,$2 # add high product limb and carry from addition /* # cool down phase 0 */ $LC0: ld $10,0($4) mflo $3 mfhi $9 daddu $3,$3,$2 sltu $2,$3,$2 dsubu $3,$10,$3 sgtu $10,$3,$10 daddu $2,$2,$10 sd $3,0($4) j $31 daddu $2,$9,$2 # add high product limb and carry from addition .end _gcry_mpih_submul_1
a1ive/grub
2,478
grub-core/lib/libgcrypt/mpi/mips3/mpih-add1.S
/* mips3 add_n -- Add two limb vectors of the same length > 0 and store * sum in a third limb vector. * * Copyright (C) 1995, 1998, 2000 * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, ($4) * mpi_ptr_t s1_ptr, ($5) * mpi_ptr_t s2_ptr, ($6) * mpi_size_t size) ($7) */ .text .align 2 .globl _gcry_mpih_add_n .ent _gcry_mpih_add_n _gcry_mpih_add_n: .set noreorder .set nomacro ld $10,0($5) ld $11,0($6) daddiu $7,$7,-1 and $9,$7,4-1 # number of limbs in first loop beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop move $2,$0 dsubu $7,$7,$9 .Loop0: daddiu $9,$9,-1 ld $12,8($5) daddu $11,$11,$2 ld $13,8($6) sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,0($4) or $2,$2,$8 daddiu $5,$5,8 daddiu $6,$6,8 move $10,$12 move $11,$13 bne $9,$0,.Loop0 daddiu $4,$4,8 .L0: beq $7,$0,.Lend nop .Loop: daddiu $7,$7,-4 ld $12,8($5) daddu $11,$11,$2 ld $13,8($6) sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,0($4) or $2,$2,$8 ld $10,16($5) daddu $13,$13,$2 ld $11,16($6) sltu $8,$13,$2 daddu $13,$12,$13 sltu $2,$13,$12 sd $13,8($4) or $2,$2,$8 ld $12,24($5) daddu $11,$11,$2 ld $13,24($6) sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,16($4) or $2,$2,$8 ld $10,32($5) daddu $13,$13,$2 ld $11,32($6) sltu $8,$13,$2 daddu $13,$12,$13 sltu $2,$13,$12 sd $13,24($4) or $2,$2,$8 daddiu $5,$5,32 daddiu $6,$6,32 bne $7,$0,.Loop daddiu $4,$4,32 .Lend: daddu $11,$11,$2 sltu $8,$11,$2 daddu $11,$10,$11 sltu $2,$11,$10 sd $11,0($4) j $31 or $2,$2,$8 .end _gcry_mpih_add_n
a1ive/grub
2,499
grub-core/lib/libgcrypt/mpi/mips3/mpih-sub1.S
/* mips3 sub_n -- Subtract two limb vectors of the same length > 0 and * store difference in a third limb vector. * * Copyright (C) 1995, 1998, 1999, 2000, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (r4) * mpi_ptr_t s1_ptr, (r5) * mpi_ptr_t s2_ptr, (r6) * mpi_size_t size) (r7) */ .text .align 2 .globl _gcry_mpih_sub_n .ent _gcry_mpih_sub_n _gcry_mpih_sub_n: .set noreorder .set nomacro ld $10,0($5) ld $11,0($6) daddiu $7,$7,-1 and $9,$7,4-1 # number of limbs in first loop beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop move $2,$0 dsubu $7,$7,$9 .Loop0: daddiu $9,$9,-1 ld $12,8($5) daddu $11,$11,$2 ld $13,8($6) sltu $8,$11,$2 dsubu $11,$10,$11 sltu $2,$10,$11 sd $11,0($4) or $2,$2,$8 daddiu $5,$5,8 daddiu $6,$6,8 move $10,$12 move $11,$13 bne $9,$0,.Loop0 daddiu $4,$4,8 .L0: beq $7,$0,.Lend nop .Loop: daddiu $7,$7,-4 ld $12,8($5) daddu $11,$11,$2 ld $13,8($6) sltu $8,$11,$2 dsubu $11,$10,$11 sltu $2,$10,$11 sd $11,0($4) or $2,$2,$8 ld $10,16($5) daddu $13,$13,$2 ld $11,16($6) sltu $8,$13,$2 dsubu $13,$12,$13 sltu $2,$12,$13 sd $13,8($4) or $2,$2,$8 ld $12,24($5) daddu $11,$11,$2 ld $13,24($6) sltu $8,$11,$2 dsubu $11,$10,$11 sltu $2,$10,$11 sd $11,16($4) or $2,$2,$8 ld $10,32($5) daddu $13,$13,$2 ld $11,32($6) sltu $8,$13,$2 dsubu $13,$12,$13 sltu $2,$12,$13 sd $13,24($4) or $2,$2,$8 daddiu $5,$5,32 daddiu $6,$6,32 bne $7,$0,.Loop daddiu $4,$4,32 .Lend: daddu $11,$11,$2 sltu $8,$11,$2 dsubu $11,$10,$11 sltu $2,$10,$11 sd $11,0($4) j $31 or $2,$2,$8 .end _gcry_mpih_sub_n
a1ive/grub
1,914
grub-core/lib/libgcrypt/mpi/amd64/mpih-mul1.S
/* AMD64 mul_1 -- Multiply a limb vector with a limb and store * the result in a second limb vector. * Copyright (C) 1992, 1994, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (rdi) * mpi_ptr_t s1_ptr, (rsi) * mpi_size_t s1_size, (rdx) * mpi_limb_t s2_limb) (rcx) */ TEXT ALIGN(5) .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 GLOBL C_SYMBOL_NAME(_gcry_mpih_mul_1) C_SYMBOL_NAME(_gcry_mpih_mul_1:) movq %rdx, %r11 leaq (%rsi,%rdx,8), %rsi leaq (%rdi,%rdx,8), %rdi negq %r11 xorl %r8d, %r8d .Loop: movq (%rsi,%r11,8), %rax mulq %rcx addq %r8, %rax movl $0, %r8d adcq %rdx, %r8 movq %rax, (%rdi,%r11,8) incq %r11 jne .Loop movq %r8, %rax ret
a1ive/grub
3,596
grub-core/lib/libgcrypt/mpi/amd64/mpih-mul2.S
/* AMD64 addmul2 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1992, 1994, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_addmul_2( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) */ /* i80386 addmul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1992, 1994, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (rdi) * mpi_ptr_t s1_ptr, (rsi) * mpi_size_t s1_size, (rdx) * mpi_limb_t s2_limb) (rcx) */ TEXT GLOBL C_SYMBOL_NAME(_gcry_mpih_addmul_1) C_SYMBOL_NAME(_gcry_mpih_addmul_1:) movq %rdx, %r11 leaq (%rsi,%rdx,8), %rsi leaq (%rdi,%rdx,8), %rdi negq %r11 xorl %r8d, %r8d xorl %r10d, %r10d ALIGN(3) /* minimal alignment for claimed speed */ .Loop: movq (%rsi,%r11,8), %rax mulq %rcx addq (%rdi,%r11,8), %rax adcq %r10, %rdx addq %r8, %rax movq %r10, %r8 movq %rax, (%rdi,%r11,8) adcq %rdx, %r8 incq %r11 jne .Loop movq %r8, %rax ret
a1ive/grub
2,189
grub-core/lib/libgcrypt/mpi/amd64/mpih-lshift.S
/* AMD64 (x86_64) lshift -- Left shift a limb vector and store * result in a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, rdi * mpi_ptr_t up, rsi * mpi_size_t usize, rdx * unsigned cnt) rcx */ .text .globl C_SYMBOL_NAME(_gcry_mpih_lshift) C_SYMBOL_NAME(_gcry_mpih_lshift:) movq -8(%rsi,%rdx,8), %mm7 movd %ecx, %mm1 movl $64, %eax subl %ecx, %eax movd %eax, %mm0 movq %mm7, %mm3 psrlq %mm0, %mm7 movd %mm7, %rax subq $2, %rdx jl .Lendo ALIGN(4) /* minimal alignment for claimed speed */ .Loop: movq (%rsi,%rdx,8), %mm6 movq %mm6, %mm2 psrlq %mm0, %mm6 psllq %mm1, %mm3 por %mm6, %mm3 movq %mm3, 8(%rdi,%rdx,8) je .Lende movq -8(%rsi,%rdx,8), %mm7 movq %mm7, %mm3 psrlq %mm0, %mm7 psllq %mm1, %mm2 por %mm7, %mm2 movq %mm2, (%rdi,%rdx,8) subq $2, %rdx jge .Loop .Lendo: movq %mm3, %mm2 .Lende: psllq %mm1, %mm2 movq %mm2, (%rdi) emms ret
a1ive/grub
2,250
grub-core/lib/libgcrypt/mpi/amd64/mpih-rshift.S
/* AMD64 (x86_64) rshift -- Right shift a limb vector and store * result in a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, rdi * mpi_ptr_t up, rsi * mpi_size_t usize, rdx * unsigned cnt) rcx */ .text .globl C_SYMBOL_NAME(_gcry_mpih_rshift) C_SYMBOL_NAME(_gcry_mpih_rshift:) movq (%rsi), %mm7 movd %ecx, %mm1 movl $64, %eax subl %ecx, %eax movd %eax, %mm0 movq %mm7, %mm3 psllq %mm0, %mm7 movd %mm7, %rax leaq (%rsi,%rdx,8), %rsi leaq (%rdi,%rdx,8), %rdi negq %rdx addq $2, %rdx jg .Lendo ALIGN(8) /* minimal alignment for claimed speed */ .Loop: movq -8(%rsi,%rdx,8), %mm6 movq %mm6, %mm2 psllq %mm0, %mm6 psrlq %mm1, %mm3 por %mm6, %mm3 movq %mm3, -16(%rdi,%rdx,8) je .Lende movq (%rsi,%rdx,8), %mm7 movq %mm7, %mm3 psllq %mm0, %mm7 psrlq %mm1, %mm2 por %mm7, %mm2 movq %mm2, -8(%rdi,%rdx,8) addq $2, %rdx jle .Loop .Lendo: movq %mm3, %mm2 .Lende: psrlq %mm1, %mm2 movq %mm2, -8(%rdi) emms ret
a1ive/grub
2,020
grub-core/lib/libgcrypt/mpi/amd64/mpih-mul3.S
/* AMD64 submul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1992, 1994, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (rdi) * mpi_ptr_t s1_ptr, (rsi) * mpi_size_t s1_size, (rdx) * mpi_limb_t s2_limb) (rcx) */ TEXT GLOBL C_SYMBOL_NAME(_gcry_mpih_submul_1) C_SYMBOL_NAME(_gcry_mpih_submul_1:) movq %rdx, %r11 leaq (%rsi,%r11,8), %rsi leaq (%rdi,%r11,8), %rdi negq %r11 xorl %r8d, %r8d ALIGN(3) /* minimal alignment for claimed speed */ .Loop: movq (%rsi,%r11,8), %rax movq (%rdi,%r11,8), %r10 mulq %rcx subq %r8, %r10 movl $0, %r8d adcl %r8d, %r8d subq %rax, %r10 adcq %rdx, %r8 movq %r10, (%rdi,%r11,8) incq %r11 jne .Loop movq %r8, %rax ret
a1ive/grub
1,981
grub-core/lib/libgcrypt/mpi/amd64/mpih-add1.S
/* AMD64 (x86_64) add_n -- Add two limb vectors of the same length > 0 and store * sum in a third limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, rdi * mpi_ptr_t s1_ptr, rsi * mpi_ptr_t s2_ptr, rdx * mpi_size_t size) rcx */ .text .globl C_SYMBOL_NAME(_gcry_mpih_add_n) C_SYMBOL_NAME(_gcry_mpih_add_n:) leaq (%rsi,%rcx,8), %rsi leaq (%rdi,%rcx,8), %rdi leaq (%rdx,%rcx,8), %rdx negq %rcx xorl %eax, %eax /* clear cy */ ALIGN(4) /* minimal alignment for claimed speed */ .Loop: movq (%rsi,%rcx,8), %rax movq (%rdx,%rcx,8), %r10 adcq %r10, %rax movq %rax, (%rdi,%rcx,8) incq %rcx jne .Loop movq %rcx, %rax /* zero %rax */ adcq %rax, %rax ret
a1ive/grub
1,984
grub-core/lib/libgcrypt/mpi/amd64/mpih-sub1.S
/* AMD64 (x86_64) sub_n -- Subtract two limb vectors of the same length > 0 and store * sum in a third limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002, 2006 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, rdi * mpi_ptr_t s1_ptr, rsi * mpi_ptr_t s2_ptr, rdx * mpi_size_t size) rcx */ .text .globl C_SYMBOL_NAME(_gcry_mpih_sub_n) C_SYMBOL_NAME(_gcry_mpih_sub_n:) leaq (%rsi,%rcx,8), %rsi leaq (%rdi,%rcx,8), %rdi leaq (%rdx,%rcx,8), %rdx negq %rcx xorl %eax, %eax /* clear cy */ ALIGN(4) /* minimal alignment for claimed speed */ .Loop: movq (%rsi,%rcx,8), %rax movq (%rdx,%rcx,8), %r10 sbbq %r10, %rax movq %rax, (%rdi,%rcx,8) incq %rcx jne .Loop movq %rcx, %rax /* zero %rax */ adcq %rax, %rax ret
a1ive/grub
2,919
grub-core/lib/libgcrypt/mpi/alpha/mpih-mul1.S
/* Alpha 21064 mpih-mul1.S -- Multiply a limb vector with a limb and store * the result in a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (r16) * mpi_ptr_t s1_ptr, (r17) * mpi_size_t s1_size, (r18) * mpi_limb_t s2_limb) (r19) * * This code runs at 42 cycles/limb on the EV4 and 18 cycles/limb on the EV5. * * To improve performance for long multiplications, we would use * 'fetch' for S1 and 'fetch_m' for RES. It's not obvious how to use * these instructions without slowing down the general code: 1. We can * only have two prefetches in operation at any time in the Alpha * architecture. 2. There will seldom be any special alignment * between RES_PTR and S1_PTR. Maybe we can simply divide the current * loop into an inner and outer loop, having the inner loop handle * exactly one prefetch block? */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_mul_1 .ent _gcry_mpih_mul_1 2 _gcry_mpih_mul_1: .frame $30,0,$26 ldq $2,0($17) # $2 = s1_limb subq $18,1,$18 # size-- mulq $2,$19,$3 # $3 = prod_low bic $31,$31,$4 # clear cy_limb umulh $2,$19,$0 # $0 = prod_high beq $18,Lend1 # jump if size was == 1 ldq $2,8($17) # $2 = s1_limb subq $18,1,$18 # size-- stq $3,0($16) beq $18,Lend2 # jump if size was == 2 .align 3 Loop: mulq $2,$19,$3 # $3 = prod_low addq $4,$0,$0 # cy_limb = cy_limb + 'cy' subq $18,1,$18 # size-- umulh $2,$19,$4 # $4 = cy_limb ldq $2,16($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ addq $3,$0,$3 # $3 = cy_limb + prod_low stq $3,8($16) cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) addq $16,8,$16 # res_ptr++ bne $18,Loop Lend2: mulq $2,$19,$3 # $3 = prod_low addq $4,$0,$0 # cy_limb = cy_limb + 'cy' umulh $2,$19,$4 # $4 = cy_limb addq $3,$0,$3 # $3 = cy_limb + prod_low cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) stq $3,8($16) addq $4,$0,$0 # cy_limb = prod_high + cy ret $31,($26),1 Lend1: stq $3,0($16) ret $31,($26),1 .end _gcry_mpih_mul_1
a1ive/grub
2,794
grub-core/lib/libgcrypt/mpi/alpha/mpih-mul2.S
/* Alpha 21064 addmul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (r16) * mpi_ptr_t s1_ptr, (r17) * mpi_size_t s1_size, (r18) * mpi_limb_t s2_limb) (r19) * * This code runs at 42 cycles/limb on EV4 and 18 cycles/limb on EV5. */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_addmul_1 .ent _gcry_mpih_addmul_1 2 _gcry_mpih_addmul_1: .frame $30,0,$26 ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ subq $18,1,$18 # size-- mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr umulh $2,$19,$0 # $0 = prod_high beq $18,.Lend1 # jump if size was == 1 ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ subq $18,1,$18 # size-- addq $5,$3,$3 cmpult $3,$5,$4 stq $3,0($16) addq $16,8,$16 # res_ptr++ beq $18,.Lend2 # jump if size was == 2 .align 3 .Loop: mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr addq $4,$0,$0 # cy_limb = cy_limb + 'cy' subq $18,1,$18 # size-- umulh $2,$19,$4 # $4 = cy_limb ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ addq $3,$0,$3 # $3 = cy_limb + prod_low cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) addq $5,$3,$3 cmpult $3,$5,$5 stq $3,0($16) addq $16,8,$16 # res_ptr++ addq $5,$0,$0 # combine carries bne $18,.Loop .Lend2: mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr addq $4,$0,$0 # cy_limb = cy_limb + 'cy' umulh $2,$19,$4 # $4 = cy_limb addq $3,$0,$3 # $3 = cy_limb + prod_low cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) addq $5,$3,$3 cmpult $3,$5,$5 stq $3,0($16) addq $5,$0,$0 # combine carries addq $4,$0,$0 # cy_limb = prod_high + cy ret $31,($26),1 .Lend1: addq $5,$3,$3 cmpult $3,$5,$5 stq $3,0($16) addq $0,$5,$0 ret $31,($26),1 .end _gcry_mpih_addmul_1
a1ive/grub
3,051
grub-core/lib/libgcrypt/mpi/alpha/mpih-lshift.S
/* alpha - left shift * * Copyright (C) 1994, 1995, 1998, 2001, * 2002 Free Software Foundation, Inc. * * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, (r16) * mpi_ptr_t up, (r17) * mpi_size_t usize, (r18) * unsigned cnt) (r19) * * This code runs at 4.8 cycles/limb on the 21064. With infinite unrolling, * it would take 4 cycles/limb. It should be possible to get down to 3 * cycles/limb since both ldq and stq can be paired with the other used * instructions. But there are many restrictions in the 21064 pipeline that * makes it hard, if not impossible, to get down to 3 cycles/limb: * * 1. ldq has a 3 cycle delay, srl and sll have a 2 cycle delay. * 2. Only aligned instruction pairs can be paired. * 3. The store buffer or silo might not be able to deal with the bandwidth. */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_lshift .ent _gcry_mpih_lshift _gcry_mpih_lshift: .frame $30,0,$26,0 s8addq $18,$17,$17 # make r17 point at end of s1 ldq $4,-8($17) # load first limb subq $17,8,$17 subq $31,$19,$7 s8addq $18,$16,$16 # make r16 point at end of RES subq $18,1,$18 and $18,4-1,$20 # number of limbs in first loop srl $4,$7,$0 # compute function result beq $20,.L0 subq $18,$20,$18 .align 3 .Loop0: ldq $3,-8($17) subq $16,8,$16 subq $17,8,$17 subq $20,1,$20 sll $4,$19,$5 srl $3,$7,$6 bis $3,$3,$4 bis $5,$6,$8 stq $8,0($16) bne $20,.Loop0 .L0: beq $18,.Lend .align 3 .Loop: ldq $3,-8($17) subq $16,32,$16 subq $18,4,$18 sll $4,$19,$5 srl $3,$7,$6 ldq $4,-16($17) sll $3,$19,$1 bis $5,$6,$8 stq $8,24($16) srl $4,$7,$2 ldq $3,-24($17) sll $4,$19,$5 bis $1,$2,$8 stq $8,16($16) srl $3,$7,$6 ldq $4,-32($17) sll $3,$19,$1 bis $5,$6,$8 stq $8,8($16) srl $4,$7,$2 subq $17,32,$17 bis $1,$2,$8 stq $8,0($16) bgt $18,.Loop .Lend: sll $4,$19,$8 stq $8,-8($16) ret $31,($26),1 .end _gcry_mpih_lshift
a1ive/grub
2,950
grub-core/lib/libgcrypt/mpi/alpha/mpih-rshift.S
/* alpha rshift * Copyright (C) 1994, 1995, 1998, 1999, * 2000, 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, (r16) * mpi_ptr_t up, (r17) * mpi_size_t usize, (r18) * unsigned cnt) (r19) * * This code runs at 4.8 cycles/limb on the 21064. With infinite unrolling, * it would take 4 cycles/limb. It should be possible to get down to 3 * cycles/limb since both ldq and stq can be paired with the other used * instructions. But there are many restrictions in the 21064 pipeline that * makes it hard, if not impossible, to get down to 3 cycles/limb: * * 1. ldq has a 3 cycle delay, srl and sll have a 2 cycle delay. * 2. Only aligned instruction pairs can be paired. * 3. The store buffer or silo might not be able to deal with the bandwidth. */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_rshift .ent _gcry_mpih_rshift _gcry_mpih_rshift: .frame $30,0,$26,0 ldq $4,0($17) # load first limb addq $17,8,$17 subq $31,$19,$7 subq $18,1,$18 and $18,4-1,$20 # number of limbs in first loop sll $4,$7,$0 # compute function result beq $20,.R0 subq $18,$20,$18 .align 3 .Roop0: ldq $3,0($17) addq $16,8,$16 addq $17,8,$17 subq $20,1,$20 srl $4,$19,$5 sll $3,$7,$6 bis $3,$3,$4 bis $5,$6,$8 stq $8,-8($16) bne $20,.Roop0 .R0: beq $18,.Rend .align 3 .Roop: ldq $3,0($17) addq $16,32,$16 subq $18,4,$18 srl $4,$19,$5 sll $3,$7,$6 ldq $4,8($17) srl $3,$19,$1 bis $5,$6,$8 stq $8,-32($16) sll $4,$7,$2 ldq $3,16($17) srl $4,$19,$5 bis $1,$2,$8 stq $8,-24($16) sll $3,$7,$6 ldq $4,24($17) srl $3,$19,$1 bis $5,$6,$8 stq $8,-16($16) sll $4,$7,$2 addq $17,32,$17 bis $1,$2,$8 stq $8,-8($16) bgt $18,.Roop .Rend: srl $4,$19,$8 stq $8,0($16) ret $31,($26),1 .end _gcry_mpih_rshift
a1ive/grub
2,811
grub-core/lib/libgcrypt/mpi/alpha/mpih-mul3.S
/* Alpha 21064 submul_1 -- Multiply a limb vector with a limb and * subtract the result from a second limb vector. * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (r16 ) * mpi_ptr_t s1_ptr, (r17 ) * mpi_size_t s1_size, (r18 ) * mpi_limb_t s2_limb) (r19 ) * * This code runs at 42 cycles/limb on EV4 and 18 cycles/limb on EV5. */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_submul_1 .ent _gcry_mpih_submul_1 2 _gcry_mpih_submul_1: .frame $30,0,$26 ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ subq $18,1,$18 # size-- mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr umulh $2,$19,$0 # $0 = prod_high beq $18,.Lend1 # jump if size was == 1 ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ subq $18,1,$18 # size-- subq $5,$3,$3 cmpult $5,$3,$4 stq $3,0($16) addq $16,8,$16 # res_ptr++ beq $18,.Lend2 # jump if size was == 2 .align 3 .Loop: mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr addq $4,$0,$0 # cy_limb = cy_limb + 'cy' subq $18,1,$18 # size-- umulh $2,$19,$4 # $4 = cy_limb ldq $2,0($17) # $2 = s1_limb addq $17,8,$17 # s1_ptr++ addq $3,$0,$3 # $3 = cy_limb + prod_low cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) subq $5,$3,$3 cmpult $5,$3,$5 stq $3,0($16) addq $16,8,$16 # res_ptr++ addq $5,$0,$0 # combine carries bne $18,.Loop .Lend2: mulq $2,$19,$3 # $3 = prod_low ldq $5,0($16) # $5 = *res_ptr addq $4,$0,$0 # cy_limb = cy_limb + 'cy' umulh $2,$19,$4 # $4 = cy_limb addq $3,$0,$3 # $3 = cy_limb + prod_low cmpult $3,$0,$0 # $0 = carry from (cy_limb + prod_low) subq $5,$3,$3 cmpult $5,$3,$5 stq $3,0($16) addq $5,$0,$0 # combine carries addq $4,$0,$0 # cy_limb = prod_high + cy ret $31,($26),1 .Lend1: subq $5,$3,$3 cmpult $5,$3,$5 stq $3,0($16) addq $0,$5,$0 ret $31,($26),1 .end _gcry_mpih_submul_1
a1ive/grub
2,449
grub-core/lib/libgcrypt/mpi/alpha/mpih-add1.S
/* alpha add_n -- Add two limb vectors of the same length > 0 and store * sum in a third limb vector. * Copyright (C) 1995, 1998, 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, ($16) * mpi_ptr_t s1_ptr, ($17) * mpi_ptr_t s2_ptr, ($18) * mpi_size_t size) ($19) */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_add_n .ent _gcry_mpih_add_n _gcry_mpih_add_n: .frame $30,0,$26,0 ldq $3,0($17) ldq $4,0($18) subq $19,1,$19 and $19,4-1,$2 # number of limbs in first loop bis $31,$31,$0 beq $2,.L0 # if multiple of 4 limbs, skip first loop subq $19,$2,$19 .Loop0: subq $2,1,$2 ldq $5,8($17) addq $4,$0,$4 ldq $6,8($18) cmpult $4,$0,$1 addq $3,$4,$4 cmpult $4,$3,$0 stq $4,0($16) or $0,$1,$0 addq $17,8,$17 addq $18,8,$18 bis $5,$5,$3 bis $6,$6,$4 addq $16,8,$16 bne $2,.Loop0 .L0: beq $19,.Lend .align 3 .Loop: subq $19,4,$19 ldq $5,8($17) addq $4,$0,$4 ldq $6,8($18) cmpult $4,$0,$1 addq $3,$4,$4 cmpult $4,$3,$0 stq $4,0($16) or $0,$1,$0 ldq $3,16($17) addq $6,$0,$6 ldq $4,16($18) cmpult $6,$0,$1 addq $5,$6,$6 cmpult $6,$5,$0 stq $6,8($16) or $0,$1,$0 ldq $5,24($17) addq $4,$0,$4 ldq $6,24($18) cmpult $4,$0,$1 addq $3,$4,$4 cmpult $4,$3,$0 stq $4,16($16) or $0,$1,$0 ldq $3,32($17) addq $6,$0,$6 ldq $4,32($18) cmpult $6,$0,$1 addq $5,$6,$6 cmpult $6,$5,$0 stq $6,24($16) or $0,$1,$0 addq $17,32,$17 addq $18,32,$18 addq $16,32,$16 bne $19,.Loop .Lend: addq $4,$0,$4 cmpult $4,$0,$1 addq $3,$4,$4 cmpult $4,$3,$0 stq $4,0($16) or $0,$1,$0 ret $31,($26),1 .end _gcry_mpih_add_n
a1ive/grub
3,134
grub-core/lib/libgcrypt/mpi/alpha/udiv-qrnnd.S
/* Alpha 21064 __udiv_qrnnd * * Copyright (C) 1992, 1994, 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ .set noreorder .set noat .text .align 3 .globl __udiv_qrnnd .ent __udiv_qrnnd __udiv_qrnnd: .frame $30,0,$26,0 .prologue 0 #define cnt $2 #define tmp $3 #define rem_ptr $16 #define n1 $17 #define n0 $18 #define d $19 #define qb $20 ldiq cnt,16 blt d,.Largedivisor .Loop1: cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule d,n1,qb subq n1,d,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule d,n1,qb subq n1,d,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule d,n1,qb subq n1,d,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule d,n1,qb subq n1,d,tmp cmovne qb,tmp,n1 bis n0,qb,n0 subq cnt,1,cnt bgt cnt,.Loop1 stq n1,0(rem_ptr) bis $31,n0,$0 ret $31,($26),1 .Largedivisor: and n0,1,$4 srl n0,1,n0 sll n1,63,tmp or tmp,n0,n0 srl n1,1,n1 and d,1,$6 srl d,1,$5 addq $5,$6,$5 .Loop2: cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule $5,n1,qb subq n1,$5,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule $5,n1,qb subq n1,$5,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule $5,n1,qb subq n1,$5,tmp cmovne qb,tmp,n1 bis n0,qb,n0 cmplt n0,0,tmp addq n1,n1,n1 bis n1,tmp,n1 addq n0,n0,n0 cmpule $5,n1,qb subq n1,$5,tmp cmovne qb,tmp,n1 bis n0,qb,n0 subq cnt,1,cnt bgt cnt,.Loop2 addq n1,n1,n1 addq $4,n1,n1 bne $6,.LOdd stq n1,0(rem_ptr) bis $31,n0,$0 ret $31,($26),1 .LOdd: /* q' in n0. r' in n1 */ addq n1,n0,n1 cmpult n1,n0,tmp # tmp := carry from addq beq tmp,.LLp6 addq n0,1,n0 subq n1,d,n1 .LLp6: cmpult n1,d,tmp bne tmp,.LLp7 addq n0,1,n0 subq n1,d,n1 .LLp7: stq n1,0(rem_ptr) bis $31,n0,$0 ret $31,($26),1 .end __udiv_qrnnd
a1ive/grub
2,487
grub-core/lib/libgcrypt/mpi/alpha/mpih-sub1.S
/* Alpha sub_n -- Subtract two limb vectors of the same length > 0 and * store difference in a third limb vector. * Copyright (C) 1995, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (r16) * mpi_ptr_t s1_ptr, (r17) * mpi_ptr_t s2_ptr, (r18) * mpi_size_t size) (r19) */ .set noreorder .set noat .text .align 3 .globl _gcry_mpih_sub_n .ent _gcry_mpih_sub_n _gcry_mpih_sub_n: .frame $30,0,$26,0 ldq $3,0($17) ldq $4,0($18) subq $19,1,$19 and $19,4-1,$2 # number of limbs in first loop bis $31,$31,$0 beq $2,.L0 # if multiple of 4 limbs, skip first loop subq $19,$2,$19 .Loop0: subq $2,1,$2 ldq $5,8($17) addq $4,$0,$4 ldq $6,8($18) cmpult $4,$0,$1 subq $3,$4,$4 cmpult $3,$4,$0 stq $4,0($16) or $0,$1,$0 addq $17,8,$17 addq $18,8,$18 bis $5,$5,$3 bis $6,$6,$4 addq $16,8,$16 bne $2,.Loop0 .L0: beq $19,.Lend .align 3 .Loop: subq $19,4,$19 ldq $5,8($17) addq $4,$0,$4 ldq $6,8($18) cmpult $4,$0,$1 subq $3,$4,$4 cmpult $3,$4,$0 stq $4,0($16) or $0,$1,$0 ldq $3,16($17) addq $6,$0,$6 ldq $4,16($18) cmpult $6,$0,$1 subq $5,$6,$6 cmpult $5,$6,$0 stq $6,8($16) or $0,$1,$0 ldq $5,24($17) addq $4,$0,$4 ldq $6,24($18) cmpult $4,$0,$1 subq $3,$4,$4 cmpult $3,$4,$0 stq $4,16($16) or $0,$1,$0 ldq $3,32($17) addq $6,$0,$6 ldq $4,32($18) cmpult $6,$0,$1 subq $5,$6,$6 cmpult $5,$6,$0 stq $6,24($16) or $0,$1,$0 addq $17,32,$17 addq $18,32,$18 addq $16,32,$16 bne $19,.Loop .Lend: addq $4,$0,$4 cmpult $4,$0,$1 subq $3,$4,$4 cmpult $3,$4,$0 stq $4,0($16) or $0,$1,$0 ret $31,($26),1 .end _gcry_mpih_sub_n
a1ive/grub
4,503
grub-core/lib/libgcrypt/mpi/pentium4/mmx/mpih-lshift.S
/* Intel Pentium-4 mpn_lshift -- left shift. * * Copyright 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_lshift( mpi_ptr_t wp, (sp + 4) * mpi_ptr_t up, (sp + 8) * mpi_size_t usize, (sp + 12) * unsigned cnt) (sp + 16) * * P4 Willamette, Northwood: 1.75 cycles/limb * P4 Prescott: 2.0 cycles/limb */ .text ALIGN (3) .globl C_SYMBOL_NAME(_gcry_mpih_lshift) C_SYMBOL_NAME(_gcry_mpih_lshift:) pushl %ebx pushl %edi movl 20(%esp), %eax movl 12(%esp), %edx movl 16(%esp), %ebx movl 24(%esp), %ecx cmp $5, %eax jae .Lunroll movl -4(%ebx,%eax,4), %edi decl %eax jnz .Lsimple shldl %cl, %edi, %eax shll %cl, %edi movl %edi, (%edx) popl %edi popl %ebx ret .Lsimple: movd (%ebx,%eax,4), %mm5 movd %ecx, %mm6 negl %ecx psllq %mm6, %mm5 addl $32, %ecx movd %ecx, %mm7 psrlq $32, %mm5 .Lsimple_top: movq -4(%ebx,%eax,4), %mm0 decl %eax psrlq %mm7, %mm0 movd %mm0, 4(%edx,%eax,4) jnz .Lsimple_top movd (%ebx), %mm0 movd %mm5, %eax psllq %mm6, %mm0 popl %edi popl %ebx movd %mm0, (%edx) emms ret .align 8, 0x90 .Lunroll: movd -4(%ebx,%eax,4), %mm5 leal (%ebx,%eax,4), %edi movd %ecx, %mm6 andl $4, %edi psllq %mm6, %mm5 jz .Lstart_src_aligned movq -8(%ebx,%eax,4), %mm0 psllq %mm6, %mm0 decl %eax psrlq $32, %mm0 movd %mm0, (%edx,%eax,4) .Lstart_src_aligned: movq -8(%ebx,%eax,4), %mm1 leal (%edx,%eax,4), %edi andl $4, %edi psrlq $32, %mm5 movq -16(%ebx,%eax,4), %mm3 jz .Lstart_dst_aligned movq %mm1, %mm0 addl $32, %ecx psllq %mm6, %mm0 movd %ecx, %mm6 psrlq $32, %mm0 movd %mm0, -4(%edx,%eax,4) subl $4, %edx .Lstart_dst_aligned: psllq %mm6, %mm1 negl %ecx addl $64, %ecx movq %mm3, %mm2 movd %ecx, %mm7 subl $8, %eax psrlq %mm7, %mm3 por %mm1, %mm3 jc .Lfinish .align 8, 0x90 .Lunroll_loop: movq 8(%ebx,%eax,4), %mm0 psllq %mm6, %mm2 movq %mm0, %mm1 psrlq %mm7, %mm0 movq %mm3, 24(%edx,%eax,4) por %mm2, %mm0 movq (%ebx,%eax,4), %mm3 psllq %mm6, %mm1 movq %mm0, 16(%edx,%eax,4) movq %mm3, %mm2 psrlq %mm7, %mm3 subl $4, %eax por %mm1, %mm3 jnc .Lunroll_loop .Lfinish: testb $2, %al jz .Lfinish_no_two movq 8(%ebx,%eax,4), %mm0 psllq %mm6, %mm2 movq %mm0, %mm1 psrlq %mm7, %mm0 movq %mm3, 24(%edx,%eax,4) por %mm2, %mm0 movq %mm1, %mm2 movq %mm0, %mm3 subl $2, %eax .Lfinish_no_two: testb $1, %al movd %mm5, %eax popl %edi jz .Lfinish_zero movd (%ebx), %mm0 psllq %mm6, %mm2 movq %mm3, 12(%edx) psllq $32, %mm0 movq %mm0, %mm1 psrlq %mm7, %mm0 por %mm2, %mm0 psllq %mm6, %mm1 movq %mm0, 4(%edx) psrlq $32, %mm1 andl $32, %ecx popl %ebx jz .Lfinish_one_unaligned movd %mm1, (%edx) .Lfinish_one_unaligned: emms ret .Lfinish_zero: movq %mm3, 8(%edx) andl $32, %ecx psllq %mm6, %mm2 jz .Lfinish_zero_unaligned movq %mm2, (%edx) .Lfinish_zero_unaligned: psrlq $32, %mm2 popl %ebx movd %mm5, %eax movd %mm2, 4(%edx) emms ret
a1ive/grub
4,439
grub-core/lib/libgcrypt/mpi/pentium4/mmx/mpih-rshift.S
/* Intel Pentium-4 mpn_rshift -- right shift. * * Copyright 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_rshift( mpi_ptr_t wp, (sp + 4) * mpi_ptr_t up, (sp + 8) * mpi_size_t usize, (sp + 12) * unsigned cnt) (sp + 16) * * P4 Willamette, Northwood: 1.75 cycles/limb * P4 Prescott: 2.0 cycles/limb */ .text ALIGN (3) .globl C_SYMBOL_NAME(_gcry_mpih_rshift) C_SYMBOL_NAME(_gcry_mpih_rshift:) pushl %ebx pushl %edi movl 20(%esp), %eax movl 12(%esp), %edx movl 16(%esp), %ebx movl 24(%esp), %ecx cmp $5, %eax jae .Lunroll decl %eax movl (%ebx), %edi jnz .Lsimple shrdl %cl, %edi, %eax shrl %cl, %edi movl %edi, (%edx) popl %edi popl %ebx ret .align 8, 0x90 .Lsimple: movd (%ebx), %mm5 leal (%ebx,%eax,4), %ebx movd %ecx, %mm6 leal -4(%edx,%eax,4), %edx psllq $32, %mm5 negl %eax .Lsimple_top: movq (%ebx,%eax,4), %mm0 incl %eax psrlq %mm6, %mm0 movd %mm0, (%edx,%eax,4) jnz .Lsimple_top movd (%ebx), %mm0 psrlq %mm6, %mm5 psrlq %mm6, %mm0 popl %edi movd %mm5, %eax popl %ebx movd %mm0, 4(%edx) emms ret .align 8, 0x90 .Lunroll: movd (%ebx), %mm5 movl $4, %edi movd %ecx, %mm6 testl %edi, %ebx psllq $32, %mm5 jz .Lstart_src_aligned movq (%ebx), %mm0 psrlq %mm6, %mm0 addl $4, %ebx decl %eax movd %mm0, (%edx) addl $4, %edx .Lstart_src_aligned: movq (%ebx), %mm1 testl %edi, %edx psrlq %mm6, %mm5 jz .Lstart_dst_aligned movq %mm1, %mm0 addl $32, %ecx psrlq %mm6, %mm0 movd %ecx, %mm6 movd %mm0, (%edx) addl $4, %edx .Lstart_dst_aligned: movq 8(%ebx), %mm3 negl %ecx movq %mm3, %mm2 addl $64, %ecx movd %ecx, %mm7 psrlq %mm6, %mm1 leal -12(%ebx,%eax,4), %ebx leal -20(%edx,%eax,4), %edx psllq %mm7, %mm3 subl $7, %eax por %mm1, %mm3 negl %eax jns .Lfinish .align 8, 0x90 .Lunroll_loop: movq (%ebx,%eax,4), %mm0 psrlq %mm6, %mm2 movq %mm0, %mm1 psllq %mm7, %mm0 movq %mm3, -8(%edx,%eax,4) por %mm2, %mm0 movq 8(%ebx,%eax,4), %mm3 psrlq %mm6, %mm1 movq %mm0, (%edx,%eax,4) movq %mm3, %mm2 psllq %mm7, %mm3 addl $4, %eax por %mm1, %mm3 js .Lunroll_loop .Lfinish: testb $2, %al jnz .Lfinish_no_two movq (%ebx,%eax,4), %mm0 psrlq %mm6, %mm2 movq %mm0, %mm1 psllq %mm7, %mm0 movq %mm3, -8(%edx,%eax,4) por %mm2, %mm0 movq %mm1, %mm2 movq %mm0, %mm3 addl $2, %eax .Lfinish_no_two: testb $1, %al popl %edi movd %mm5, %eax jnz .Lfinish_zero movd 8(%ebx), %mm0 psrlq %mm6, %mm2 movq %mm0, %mm1 psllq %mm7, %mm0 movq %mm3, (%edx) por %mm2, %mm0 psrlq %mm6, %mm1 andl $32, %ecx popl %ebx jz .Lfinish_one_unaligned movd %mm1, 16(%edx) .Lfinish_one_unaligned: movq %mm0, 8(%edx) emms ret .Lfinish_zero: movq %mm3, 4(%edx) psrlq %mm6, %mm2 movd %mm2, 12(%edx) andl $32, %ecx popl %ebx jz .Lfinish_zero_unaligned movq %mm2, 12(%edx) .Lfinish_zero_unaligned: emms ret
a1ive/grub
2,568
grub-core/lib/libgcrypt/mpi/pentium4/sse2/mpih-mul1.S
/* Intel Pentium-4 mpn_mul_1 -- Multiply a limb vector with a limb and store * the result in a second limb vector. * * Copyright 2001, 2002, 2003, 2005 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) * * src != dst src == dst * P6 model 9 (Banias) ?.? * P6 model 13 (Dothan) 4.75 4.75 * P4 model 0 (Willamette) 4.0 6.0 * P4 model 1 (?) 4.0 6.0 * P4 model 2 (Northwood) 4.0 6.0 * P4 model 3 (Prescott) ?.? ?.? * P4 model 4 (Nocona) ?.? ?.? * Unfortunately when src==dst the write-combining described in * pentium4/README takes us up to 6 c/l. * */ TEXT ALIGN (3) GLOBL C_SYMBOL_NAME(_gcry_mpih_mul_1) C_SYMBOL_NAME(_gcry_mpih_mul_1:); pxor %mm0, %mm0 .Lstart_1c: movl 8(%esp), %eax movd 16(%esp), %mm7 movl 4(%esp), %edx movl 12(%esp), %ecx .Ltop: /* C eax src, incrementing C ebx C ecx counter, size iterations C edx dst, incrementing C C mm0 carry limb C mm7 multiplier */ movd (%eax), %mm1 addl $4, %eax pmuludq %mm7, %mm1 paddq %mm1, %mm0 movd %mm0, (%edx) addl $4, %edx psrlq $32, %mm0 subl $1, %ecx jnz .Ltop movd %mm0, %eax emms ret
a1ive/grub
3,284
grub-core/lib/libgcrypt/mpi/pentium4/sse2/mpih-mul2.S
/* Intel Pentium-4 mpn_addmul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright 2001, 2002, 2004, 2005 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) * * P3 model 9 (Banias) ?.? * P3 model 13 (Dothan) 5.8 * P4 model 0 (Willamette) 5.5 * P4 model 1 (?) 5.5 * P4 model 2 (Northwood) 5.5 * P4 model 3 (Prescott) 6.0 * P4 model 4 (Nocona) * * Only the carry limb propagation is on the dependent chain, but some other * Pentium4 pipeline magic brings down performance to 6 cycles/l from the * ideal 4 cycles/l. */ TEXT ALIGN (4) GLOBL C_SYMBOL_NAME(_gcry_mpih_addmul_1) C_SYMBOL_NAME(_gcry_mpih_addmul_1:) pxor %mm4, %mm4 .Lstart_1c: movl 8(%esp), %eax movl 12(%esp), %ecx movl 4(%esp), %edx movd 16(%esp), %mm7 /* C eax src, incrementing ; 5B C ecx loop counter, decrementing C edx dst, incrementing C C mm4 carry, low 32-bits C mm7 multiplier */ movd (%eax), %mm2 pmuludq %mm7, %mm2 shrl $1, %ecx jnc .Leven leal 4(%eax), %eax movd (%edx), %mm1 paddq %mm2, %mm1 paddq %mm1, %mm4 movd %mm4, (%edx) psrlq $32, %mm4 testl %ecx, %ecx jz .Lrtn leal 4(%edx), %edx movd (%eax), %mm2 pmuludq %mm7, %mm2 .Leven: movd 4(%eax), %mm0 movd (%edx), %mm1 pmuludq %mm7, %mm0 subl $1, %ecx jz .Lend .Lloop: paddq %mm2, %mm1 movd 8(%eax), %mm2 paddq %mm1, %mm4 movd 4(%edx), %mm3 pmuludq %mm7, %mm2 movd %mm4, (%edx) psrlq $32, %mm4 paddq %mm0, %mm3 movd 12(%eax), %mm0 paddq %mm3, %mm4 movd 8(%edx), %mm1 pmuludq %mm7, %mm0 movd %mm4, 4(%edx) psrlq $32, %mm4 leal 8(%eax), %eax leal 8(%edx), %edx subl $1, %ecx jnz .Lloop .Lend: paddq %mm2, %mm1 paddq %mm1, %mm4 movd 4(%edx), %mm3 movd %mm4, (%edx) psrlq $32, %mm4 paddq %mm0, %mm3 paddq %mm3, %mm4 movd %mm4, 4(%edx) psrlq $32, %mm4 .Lrtn: movd %mm4, %eax emms ret
a1ive/grub
4,093
grub-core/lib/libgcrypt/mpi/pentium4/sse2/mpih-mul3.S
/* Intel Pentium-4 mpn_submul_1 -- Multiply a limb vector with a limb and * subtract the result from a second limb vector. * * Copyright 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) * * P4: 7 cycles/limb, unstable timing, at least on early Pentium4 silicon * (stepping 10). * * This code is not particularly good at 7 c/l. The dependent chain is only * 4 c/l and there's only 4 MMX unit instructions, so it's not clear why that * speed isn't achieved. * * The arrangements made here to get a two instruction dependent chain are * slightly subtle. In the loop the carry (or borrow rather) is a negative * so that a paddq can be used to give a low limb ready to store, and a high * limb ready to become the new carry after a psrlq. * * If the carry was a simple twos complement negative then the psrlq shift * would need to bring in 0 bits or 1 bits according to whether the high was * zero or non-zero, since a non-zero value would represent a negative * needing sign extension. That wouldn't be particularly easy to arrange and * certainly would add an instruction to the dependent chain, so instead an * offset is applied so that the high limb will be 0xFFFFFFFF+c. With c in * the range -0xFFFFFFFF to 0, the value 0xFFFFFFFF+c is in the range 0 to * 0xFFFFFFFF and is therefore always positive and can always have 0 bits * shifted in, which is what psrlq does. * * The extra 0xFFFFFFFF must be subtracted before c is used, but that can be * done off the dependent chain. The total adjustment then is to add * 0xFFFFFFFF00000000 to offset the new carry, and subtract * 0x00000000FFFFFFFF to remove the offset from the current carry, for a net * add of 0xFFFFFFFE00000001. In the code this is applied to the destination * limb when fetched. * * It's also possible to view the 0xFFFFFFFF adjustment as a ones-complement * negative, which is how it's undone for the return value, but that doesn't * seem as clear. */ TEXT ALIGN (4) GLOBL C_SYMBOL_NAME(_gcry_mpih_submul_1) C_SYMBOL_NAME(_gcry_mpih_submul_1:) pxor %mm1, %mm1 .Lstart_1c: movl 8(%esp), %eax pcmpeqd %mm0, %mm0 movd 16(%esp), %mm7 pcmpeqd %mm6, %mm6 movl 4(%esp), %edx psrlq $32, %mm0 movl 12(%esp), %ecx psllq $32, %mm6 psubq %mm0, %mm6 psubq %mm1, %mm0 /* C eax src, incrementing C ebx C ecx loop counter, decrementing C edx dst, incrementing C C mm0 0xFFFFFFFF - borrow C mm6 0xFFFFFFFE00000001 C mm7 multiplier */ .Lloop: movd (%eax), %mm1 leal 4(%eax), %eax movd (%edx), %mm2 paddq %mm6, %mm2 pmuludq %mm7, %mm1 psubq %mm1, %mm2 paddq %mm2, %mm0 subl $1, %ecx movd %mm0, (%edx) psrlq $32, %mm0 leal 4(%edx), %edx jnz .Lloop movd %mm0, %eax notl %eax emms ret
a1ive/grub
2,488
grub-core/lib/libgcrypt/mpi/pentium4/sse2/mpih-add1.S
/* Intel Pentium-4 mpn_add_n -- mpn addition. * * Copyright 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_add_n( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_ptr_t s2_ptr, (sp + 12) * mpi_size_t size) (sp + 16) * * P4 Willamette, Northwood: 4.0 cycles/limb if dst!=src1 and dst!=src2 * 6.0 cycles/limb if dst==src1 or dst==src2 * P4 Prescott: >= 5 cycles/limb * * The 4 c/l achieved here isn't particularly good, but is better than 9 c/l * for a basic adc loop. */ TEXT ALIGN (3) GLOBL C_SYMBOL_NAME(_gcry_mpih_add_n) C_SYMBOL_NAME(_gcry_mpih_add_n:) pxor %mm0, %mm0 movl 8(%esp), %eax /* s1_ptr */ movl %ebx, 8(%esp) /* re-use parameter space */ movl 12(%esp), %ebx /* res_ptr */ movl 4(%esp), %edx /* s2_ptr */ movl 16(%esp), %ecx /* size */ leal (%eax,%ecx,4), %eax /* src1 end */ leal (%ebx,%ecx,4), %ebx /* src2 end */ leal (%edx,%ecx,4), %edx /* dst end */ negl %ecx /* -size */ Ltop: /* C eax src1 end C ebx src2 end C ecx counter, limbs, negative C edx dst end C mm0 carry bit */ movd (%eax,%ecx,4), %mm1 movd (%ebx,%ecx,4), %mm2 paddq %mm2, %mm1 paddq %mm1, %mm0 movd %mm0, (%edx,%ecx,4) psrlq $32, %mm0 addl $1, %ecx jnz Ltop movd %mm0, %eax movl 8(%esp), %ebx /* restore saved EBX */ emms ret
a1ive/grub
2,568
grub-core/lib/libgcrypt/mpi/pentium4/sse2/mpih-sub1.S
/* Intel Pentium-4 mpn_sub_n -- mpn subtraction. * * Copyright 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_ptr_t s2_ptr, (sp + 12) * mpi_size_t size) (sp + 16) * * P4 Willamette, Northwood: 4.0 cycles/limb if dst!=src1 and dst!=src2 * 6.0 cycles/limb if dst==src1 or dst==src2 * P4 Prescott: >= 5 cycles/limb * * The main loop code is 2x unrolled so that the carry bit can alternate * between mm0 and mm1. */ .text ALIGN (3) .globl C_SYMBOL_NAME(_gcry_mpih_sub_n) C_SYMBOL_NAME(_gcry_mpih_sub_n:) pxor %mm0, %mm0 .Lstart_nc: movl 8(%esp), %eax movl %ebx, 8(%esp) movl 12(%esp), %ebx movl 4(%esp), %edx movl 16(%esp), %ecx leal (%eax,%ecx,4), %eax leal (%ebx,%ecx,4), %ebx leal (%edx,%ecx,4), %edx negl %ecx .Ltop: /* C eax src1 end C ebx src2 end C ecx counter, limbs, negative C edx dst end C mm0 carry bit */ movd (%eax,%ecx,4), %mm1 movd (%ebx,%ecx,4), %mm2 psubq %mm2, %mm1 psubq %mm0, %mm1 movd %mm1, (%edx,%ecx,4) psrlq $63, %mm1 addl $1, %ecx jz .Ldone_mm1 movd (%eax,%ecx,4), %mm0 movd (%ebx,%ecx,4), %mm2 psubq %mm2, %mm0 psubq %mm1, %mm0 movd %mm0, (%edx,%ecx,4) psrlq $63, %mm0 addl $1, %ecx jnz .Ltop movd %mm0, %eax movl 8(%esp), %ebx emms ret .Ldone_mm1: movd %mm1, %eax movl 8(%esp), %ebx emms ret
a1ive/grub
2,823
grub-core/lib/libgcrypt/mpi/m68k/mc68020/mpih-mul1.S
/* mc68020 __mpn_mul_1 -- Multiply a limb vector with a limb and store * the result in a second limb vector. * * Copyright (C) 1992, 1994, 1996, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) */ TEXT ALIGN GLOBL C_SYMBOL_NAME(_gcry_mpih_mul_1) C_SYMBOL_NAME(_gcry_mpih_mul_1:) PROLOG(_gcry_mpih_mul_1) #define res_ptr a0 #define s1_ptr a1 #define s1_size d2 #define s2_limb d4 /* Save used registers on the stack. */ moveml R(d2)-R(d4),MEM_PREDEC(sp) #if 0 movel R(d2),MEM_PREDEC(sp) movel R(d3),MEM_PREDEC(sp) movel R(d4),MEM_PREDEC(sp) #endif /* Copy the arguments to registers. Better use movem? */ movel MEM_DISP(sp,16),R(res_ptr) movel MEM_DISP(sp,20),R(s1_ptr) movel MEM_DISP(sp,24),R(s1_size) movel MEM_DISP(sp,28),R(s2_limb) eorw #1,R(s1_size) clrl R(d1) lsrl #1,R(s1_size) bcc L(L1) subql #1,R(s1_size) subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ L(Loop:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d1):R(d3) addxl R(d0),R(d3) movel R(d3),MEM_POSTINC(res_ptr) L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d0):R(d3) addxl R(d1),R(d3) movel R(d3),MEM_POSTINC(res_ptr) dbf R(s1_size),L(Loop) clrl R(d3) addxl R(d3),R(d0) subl #0x10000,R(s1_size) bcc L(Loop) /* Restore used registers from stack frame. */ moveml MEM_POSTINC(sp),R(d2)-R(d4) #if 0 movel MEM_POSTINC(sp),R(d4) movel MEM_POSTINC(sp),R(d3) movel MEM_POSTINC(sp),R(d2) #endif rts EPILOG(_gcry_mpih_mul_1)
a1ive/grub
2,708
grub-core/lib/libgcrypt/mpi/m68k/mc68020/mpih-mul2.S
/* mc68020 __mpn_addmul_1 -- Multiply a limb vector with a limb and add * the result to a second limb vector. * * Copyright (C) 1992, 1994, 1996, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) */ TEXT ALIGN GLOBL C_SYMBOL_NAME(_gcry_mpih_addmul_1) C_SYMBOL_NAME(_gcry_mpih_addmul_1:) PROLOG(_gcry_mpih_addmul_1) #define res_ptr a0 #define s1_ptr a1 #define s1_size d2 #define s2_limb d4 /* Save used registers on the stack. */ moveml R(d2)-R(d5),MEM_PREDEC(sp) /* Copy the arguments to registers. Better use movem? */ movel MEM_DISP(sp,20),R(res_ptr) movel MEM_DISP(sp,24),R(s1_ptr) movel MEM_DISP(sp,28),R(s1_size) movel MEM_DISP(sp,32),R(s2_limb) eorw #1,R(s1_size) clrl R(d1) clrl R(d5) lsrl #1,R(s1_size) bcc L(L1) subql #1,R(s1_size) subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ L(Loop:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d1):R(d3) addxl R(d0),R(d3) addxl R(d5),R(d1) addl R(d3),MEM_POSTINC(res_ptr) L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d0):R(d3) addxl R(d1),R(d3) addxl R(d5),R(d0) addl R(d3),MEM_POSTINC(res_ptr) dbf R(s1_size),L(Loop) addxl R(d5),R(d0) subl #0x10000,R(s1_size) bcc L(Loop) /* Restore used registers from stack frame. */ moveml MEM_POSTINC(sp),R(d2)-R(d5) rts EPILOG(_gcry_mpih_addmul_1)
a1ive/grub
2,717
grub-core/lib/libgcrypt/mpi/m68k/mc68020/mpih-mul3.S
/* mc68020 __mpn_submul_1 -- Multiply a limb vector with a limb and subtract * the result from a second limb vector. * * Copyright (C) 1992, 1994, 1996, 1998, * 2001, 2002 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * * Libgcrypt 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. * * Libgcrypt 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Note: This code is heavily based on the GNU MP Library. * Actually it's the same code with only minor changes in the * way the data is stored; this is to support the abstraction * of an optional secure memory allocation which may be used * to avoid revealing of sensitive data due to paging etc. */ #include "sysdep.h" #include "asm-syntax.h" /******************* * mpi_limb_t * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (sp + 4) * mpi_ptr_t s1_ptr, (sp + 8) * mpi_size_t s1_size, (sp + 12) * mpi_limb_t s2_limb) (sp + 16) */ TEXT ALIGN GLOBL C_SYMBOL_NAME(_gcry_mpih_submul_1) C_SYMBOL_NAME(_gcry_mpih_submul_1:) PROLOG(_gcry_mpih_submul_1) #define res_ptr a0 #define s1_ptr a1 #define s1_size d2 #define s2_limb d4 /* Save used registers on the stack. */ moveml R(d2)-R(d5),MEM_PREDEC(sp) /* Copy the arguments to registers. Better use movem? */ movel MEM_DISP(sp,20),R(res_ptr) movel MEM_DISP(sp,24),R(s1_ptr) movel MEM_DISP(sp,28),R(s1_size) movel MEM_DISP(sp,32),R(s2_limb) eorw #1,R(s1_size) clrl R(d1) clrl R(d5) lsrl #1,R(s1_size) bcc L(L1) subql #1,R(s1_size) subl R(d0),R(d0) /* (d0,cy) <= (0,0) */ L(Loop:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d1):R(d3) addxl R(d0),R(d3) addxl R(d5),R(d1) subl R(d3),MEM_POSTINC(res_ptr) L(L1:) movel MEM_POSTINC(s1_ptr),R(d3) mulul R(s2_limb),R(d0):R(d3) addxl R(d1),R(d3) addxl R(d5),R(d0) subl R(d3),MEM_POSTINC(res_ptr) dbf R(s1_size),L(Loop) addxl R(d5),R(d0) subl #0x10000,R(s1_size) bcc L(Loop) /* Restore used registers from stack frame. */ moveml MEM_POSTINC(sp),R(d2)-R(d5) rts EPILOG(_gcry_mpih_submul_1)
a1ive/grub
4,145
grub-core/lib/i386/xen/relocator.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/i386/memory.h> #include <grub/i386/types.h> #include <grub/symbol.h> #include <grub/xen.h> .p2align 4 /* force 16-byte alignment */ VARIABLE(grub_relocator_xen_remap_start) LOCAL(base): /* Remap the remapper to it's new address. */ /* mov imm32, %ebx - %ebx: new virtual address of remapper */ .byte 0xbb VARIABLE(grub_relocator_xen_remapper_virt) .long 0 /* mov imm32, %ecx - %ecx: low part of page table entry */ .byte 0xb9 VARIABLE(grub_relocator_xen_remapper_map) .long 0 /* mov imm32, %edx - %edx: high part of page table entry */ .byte 0xba VARIABLE(grub_relocator_xen_remapper_map_high) .long 0 movl %ebx, %ebp /* %ebx is clobbered by hypercall */ movl $UVMF_INVLPG, %esi /* esi: flags (inv. single entry) */ movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 movl %ebp, %ebx addl $(LOCAL(cont) - LOCAL(base)), %ebx jmp *%ebx /* Continue with new virtual address */ LOCAL(cont): /* Modify mappings of new page tables to be read-only. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_paging_areas_addr) .long 0 movl %eax, %ebx 1: movl 0(%ebx), %ebp /* Get start pfn of the current area */ movl GRUB_TARGET_SIZEOF_LONG(%ebx), %ecx /* Get # of pg tables */ testl %ecx, %ecx /* 0 -> last area reached */ jz 3f addl $(2 * GRUB_TARGET_SIZEOF_LONG), %ebx movl %ebx, %esp /* Save current area pointer */ 2: movl %ecx, %edi /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_mfn_list) .long 0 movl 0(%eax, %ebp, 4), %ecx /* mfn */ movl %ebp, %ebx shll $PAGE_SHIFT, %ebx /* virtual address (1:1 mapping) */ movl %ecx, %edx shll $PAGE_SHIFT, %ecx /* prepare pte low part */ shrl $(32 - PAGE_SHIFT), %edx /* pte high part */ orl $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %ecx /* pte low */ movl $UVMF_INVLPG, %esi movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 /* parameters: eax, ebx, ecx, edx, esi */ incl %ebp /* next pfn */ movl %edi, %ecx loop 2b mov %esp, %ebx /* restore area poniter */ jmp 1b 3: /* Switch page tables: pin new L3 pt, load cr3, unpin old L3. */ /* mov imm32, %ebx */ .byte 0xbb VARIABLE(grub_relocator_xen_mmu_op_addr) .long 0 movl $3, %ecx /* 3 mmu ops */ movl $0, %edx /* pdone (not used) */ movl $DOMID_SELF, %esi movl $__HYPERVISOR_mmuext_op, %eax int $0x82 /* Continue in virtual kernel mapping. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remap_continue) .long 0 jmp *%eax VARIABLE(grub_relocator_xen_paging_areas) .long 0, 0, 0, 0, 0, 0, 0, 0 VARIABLE(grub_relocator_xen_mmu_op) .space 256 VARIABLE(grub_relocator_xen_remap_end) VARIABLE(grub_relocator_xen_start) /* Unmap old remapper area. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_remapper_virt2) .long 0 movl %eax, %ebx xorl %ecx, %ecx /* Invalid pte */ xorl %edx, %edx movl $UVMF_INVLPG, %esi movl $__HYPERVISOR_update_va_mapping, %eax int $0x82 /* Prepare registers for starting kernel. */ /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_stack) .long 0 movl %eax, %esp /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_start_info) .long 0 movl %eax, %esi cld /* mov imm32, %eax */ .byte 0xb8 VARIABLE(grub_relocator_xen_entry_point) .long 0 /* Now start the new kernel. */ jmp *%eax VARIABLE(grub_relocator_xen_end)
a1ive/grub
3,733
grub-core/lib/x86_64/xen/relocator.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/x86_64/memory.h> #include <grub/x86_64/types.h> #include <grub/symbol.h> #include <grub/xen.h> /* Macro to load an imm64 value stored by the C-part into %rax: */ #define MOV_IMM64_RAX(var) .byte 0x48, 0xb8; VARIABLE(var); .quad 0 .p2align 4 /* force 16-byte alignment */ VARIABLE(grub_relocator_xen_remap_start) LOCAL(base): /* Remap the remapper to it's new address. */ MOV_IMM64_RAX(grub_relocator_xen_remapper_virt) movq %rax, %rdi /* %rdi: new virtual address of remapper */ movq %rax, %rbx /* Remember new virtual address */ MOV_IMM64_RAX(grub_relocator_xen_remapper_map) movq %rax, %rsi /* %rsi: page table entry */ movq $UVMF_INVLPG, %rdx /* %rdx: flags (inv. single entry) */ movq $__HYPERVISOR_update_va_mapping, %rax syscall /* Do the remap operation */ addq $(LOCAL(cont) - LOCAL(base)), %rbx jmp *%rbx /* Continue with new virtual address */ LOCAL(cont): /* Modify mappings of new page tables to be read-only. */ MOV_IMM64_RAX(grub_relocator_xen_mfn_list) movq %rax, %rbx /* %rbx is the base of the p2m list */ leaq EXT_C(grub_relocator_xen_paging_areas) (%rip), %r8 1: movq 0(%r8), %r12 /* Get start pfn of the current area */ movq GRUB_TARGET_SIZEOF_LONG(%r8), %rcx /* Get # of pg tables */ testq %rcx, %rcx /* 0 -> last area reached */ jz 3f 2: movq %r12, %rdi shlq $PAGE_SHIFT, %rdi /* virtual address (1:1 mapping) */ movq (%rbx, %r12, 8), %rsi /* mfn */ shlq $PAGE_SHIFT, %rsi orq $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %rsi /* Build pte */ movq $UVMF_INVLPG, %rdx movq %rcx, %r9 /* %rcx clobbered by hypercall */ movq $__HYPERVISOR_update_va_mapping, %rax syscall movq %r9, %rcx incq %r12 /* next pfn */ loop 2b addq $(2 * GRUB_TARGET_SIZEOF_LONG), %r8 /* next pg table area */ jmp 1b 3: /* Switch page tables: pin new L4 pt, load cr3, unpin old L4. */ leaq EXT_C(grub_relocator_xen_mmu_op) (%rip), %rdi movq $3, %rsi /* 3 mmu ops */ movq $0, %rdx /* pdone (not used) */ movq $DOMID_SELF, %r10 movq $__HYPERVISOR_mmuext_op, %rax syscall /* Continue in virtual kernel mapping. */ MOV_IMM64_RAX(grub_relocator_xen_remap_continue) jmp *%rax VARIABLE(grub_relocator_xen_paging_areas) /* array of start, size pairs, size 0 is end marker */ .quad 0, 0, 0, 0, 0, 0, 0, 0 VARIABLE(grub_relocator_xen_mmu_op) .space 256 VARIABLE(grub_relocator_xen_remap_end) VARIABLE(grub_relocator_xen_start) /* Unmap old remapper area. */ MOV_IMM64_RAX(grub_relocator_xen_remapper_virt2) movq %rax, %rdi xorq %rax, %rax /* Invalid pte */ movq %rax, %rsi movq $UVMF_INVLPG, %rdx movq $__HYPERVISOR_update_va_mapping, %rax syscall /* Prepare registers for starting kernel. */ MOV_IMM64_RAX(grub_relocator_xen_stack) movq %rax, %rsp MOV_IMM64_RAX(grub_relocator_xen_start_info) movq %rax, %rsi cld MOV_IMM64_RAX(grub_relocator_xen_entry_point) /* Now start the new kernel. */ jmp *%rax VARIABLE(grub_relocator_xen_end)
a1ive/grub
6,967
grub-core/boot/mips/startup_raw.S
/* startup.S - Startup code for the MIPS. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/offsets.h> #include <grub/machine/memory.h> #include <grub/machine/kernel.h> #include <grub/offsets.h> #include <grub/mips/asm.h> #define BASE_ADDR 8 .extern __bss_start .extern _end .extern _edata .globl __start, _start, start .set noreorder .set nomacro __start: _start: start: bal codestart nop base: .org GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE compressed_size: .long 0 .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE uncompressed_size: .long 0 .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR uncompressed_addr: .long 0 codestart: /* Save our base. */ move $s0, $ra /* Parse arguments. Has to be done before relocation. So need to do it in asm. */ #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS lui $t0, %hi (((16 << 20) - 264 + 4) | 0x80000000) lw $t1, %lo (((16 << 20) - 264 + 4) | 0x80000000) ($t0) lui $t2, 0x1234 ori $t2, 0x5678 bne $t1, $t2, 1f nop lui $t0, %hi (((16 << 20) - 264) | 0x80000000) b 2f lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0) 1: li $s4, 0 2: #endif #ifdef GRUB_MACHINE_MIPS_LOONGSON move $s2, $zero move $s3, $zero move $s4, $zero move $s5, $zero move $s7, $zero /* $a2 has the environment. */ addiu $t0, $zero, -0x10 and $t1, $a2, $t0 beq $t0, $t1, argfw nop move $t0, $a2 argcont: lw $t1, 0($t0) beq $t1, $zero, argdone nop #define DO_PARSE(str, reg) \ addiu $t2, $s0, (str-base);\ bal parsestr;\ nop ;\ beq $v0, $zero, 1f;\ nop ;\ b 2f;\ move reg, $v0; \ 1: #define DO_CHECKT1(str, val) \ move $t6, $t1 ;\ addiu $t7, $s0, (str - base);\ bal do_check ;\ li $t2, val DO_PARSE (busclockstr, $s2) DO_PARSE (cpuclockstr, $s3) DO_PARSE (memsizestr, $s4) DO_PARSE (highmemsizestr, $s5) DO_CHECKT1 (pmon_yeeloong_verstr, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKT1 (pmon_fuloong2f_verstr, GRUB_ARCH_MACHINE_FULOONG2F) 2: b argcont addiu $t0, $t0, 4 parsestr: move $v0, $zero move $t3, $t1 3: lb GRUB_ASM_T4, 0($t2) lb GRUB_ASM_T5, 0($t3) addiu $t2, $t2, 1 addiu $t3, $t3, 1 beq GRUB_ASM_T5, $zero, 1f nop beq GRUB_ASM_T5, GRUB_ASM_T4, 3b nop bne GRUB_ASM_T4, $zero, 1f nop addiu $t3, $t3, 0xffff digcont: lb GRUB_ASM_T5, 0($t3) /* Substract '0' from digit. */ addiu GRUB_ASM_T5, GRUB_ASM_T5, 0xffd0 bltz GRUB_ASM_T5, 1f nop addiu GRUB_ASM_T4, GRUB_ASM_T5, 0xfff7 bgtz GRUB_ASM_T4, 1f nop /* Multiply $v0 by 10 with bitshifts. */ sll $v0, $v0, 1 sll GRUB_ASM_T4, $v0, 2 addu $v0, $v0, GRUB_ASM_T4 addu $v0, $v0, GRUB_ASM_T5 addiu $t3, $t3, 1 b digcont nop 1: jr $ra nop busclockstr: .asciz "busclock=" cpuclockstr: .asciz "cpuclock=" memsizestr: .asciz "memsize=" highmemsizestr: .asciz "highmemsize=" machtype_yeeloong_str1: .asciz "machtype=8.9" machtype_yeeloong_str2: .asciz "machtype=lemote-yeeloong-" machtype_fuloong2f_str: .asciz "machtype=lemote-fuloong-2f" machtype_fuloong2e_str: .asciz "machtype=lemote-fuloong-2e" pmon_yeeloong_str: .asciz "PMON_VER=LM8" pmon_fuloong2f_str: .asciz "PMON_VER=LM6" pmon_yeeloong_verstr: .asciz "Version=LM8" pmon_fuloong2f_verstr: .asciz "Version=LM6" .p2align 2 argdone: beq $a0, $zero, cmdlinedone nop #define DO_CHECKA1(str, val) \ lw $t6, 0($a1) ;\ addiu $t7, $s0, (str - base);\ bal do_check ;\ li $t2, val DO_CHECKA1 (machtype_yeeloong_str1, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKA1 (machtype_yeeloong_str2, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKA1 (pmon_yeeloong_str, GRUB_ARCH_MACHINE_YEELOONG) DO_CHECKA1 (machtype_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F) DO_CHECKA1 (machtype_fuloong2e_str, GRUB_ARCH_MACHINE_FULOONG2E) DO_CHECKA1 (pmon_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F) addiu $a0, $a0, -1 b argdone addiu $a1, $a1, 4 do_check: lb GRUB_ASM_T4, 0($t7) beq GRUB_ASM_T4, $zero, 1f lb $t3, 0($t6) bne $t3, GRUB_ASM_T4, 2f addiu $t6, $t6, 1 b do_check addiu $t7, $t7, 1 1: move $s7, $t2 2: jr $ra nop argfw: not $s7, $a2 cmdlinedone: #endif #ifdef GRUB_MACHINE_ARC lui $t0, %hi(_start - 256) addiu $t0, $t0, %lo(_start - 256) addiu $t3, $t0, 255 lw $t1, 0($a1) 1: bne $t0, $t3, 2f lb $t2, 0($t1) move $t2, $zero 2: sb $t2, 0($t0) addiu $t0, $t0, 1 bnez $t2, 1b addiu $t1, $t1, 1 #endif /* Copy the decompressor. */ lui $t1, %hi(base) addiu $t1, $t1, %lo(base) lui $t3, %hi(__bss_start) addiu $t3, $t3, %lo(__bss_start) move $t2, $s0 1: beq $t1, $t3, 2f lb GRUB_ASM_T4, 0($t2) sb GRUB_ASM_T4, 0($t1) addiu $t1, $t1, 1 b 1b addiu $t2, $t2, 1 2: /* Clean out its BSS. */ lui $t1, %hi(__bss_start) addiu $t1, $t1, %lo(__bss_start) lui $t2, %hi(_end) addiu $t2, $t2, %lo(_end) 1: beq $t1, $t2, 2f nop sb $zero, 0($t1) b 1b addiu $t1, $t1, 1 2: lui $a0, %hi(base) addiu $a0, $a0, %lo(base) lui $a1, %hi(_end) addiu $a1, %lo(_end) subu $a1,$a1,$a0 #include "../../kern/mips/cache_flush.S" /* Decompress the payload. */ lui $a0, %hi(_edata) addiu $a0, $a0, %lo(_edata) lui $t0, %hi(base) addiu $t0, $t0, %lo(base) subu $a0, $a0, $t0 addu $a0, $a0, $s0 lw $a1, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR - BASE_ADDR)($s0) lw $a2, (GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0) lw $a3, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0) move $s1, $a1 /* $a0 contains source compressed address, $a1 is destination, $a2 is compressed size, $a3 is uncompressed size. */ move $s6, $a3 lui $t9, %hi(EXT_C(grub_decompress_core)) addiu $t9, $t9, %lo(EXT_C(grub_decompress_core)) #ifdef GRUB_MACHINE_ARC lui $sp, %hi(_start - 512) jalr $t9 addiu $sp, $sp, %lo(_start - 512) #else lui $sp, %hi(_start - 256) jalr $t9 addiu $sp, $sp, %lo(_start - 256) #endif move $a0, $s1 move $a1, $s6 #include "../../kern/mips/cache_flush.S" lui $t1, %hi(GRUB_MACHINE_LINK_ADDR) addiu $t1, %lo(GRUB_MACHINE_LINK_ADDR) jr $t1 nop /* Ensure that .data section is created. In code we suppose that _edata is first location not in decompressor image. Strictly speaking it's _edata only when .data is present and _etext otherwise. But checking for .data presence would cost more in code than it is to ensure that .data is created. */ .data .long 0
a1ive/grub
1,950
grub-core/boot/i386/qemu/boot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/machine/memory.h> #include <grub/machine/boot.h> #include <grub/machine/kernel.h> .text .code16 .globl _start _start: /* Disable interrupts. */ cli jmp 1f .org GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR VARIABLE(grub_core_entry_addr) .long 0 1: /* Set up %ds, %ss, and %es. */ xorw %ax, %ax movw %ax, %ds movw %ax, %ss movw %ax, %es /* Set up the real mode stack. */ movl $GRUB_MEMORY_MACHINE_REAL_STACK, %esp /* Transition to protected mode. We use pushl to force generation of a flat return address. */ pushl $1f jmp real_to_prot .code32 1: /* Ensure A20 is enabled. We're in qemu, so control port A works and there is no need to wait since there is no real logic, it's all emulated. */ inb $0x92 andb $(~0x03), %al orb $0x02, %al outb $0x92 movl EXT_C(grub_core_entry_addr), %edx jmp *%edx #include "../../../kern/i386/realmode.S" /* Intel, in its infinite wisdom, decided to put the i8086 entry point *right here* and this is why we need this kludge. */ .org GRUB_BOOT_MACHINE_SIZE - 16 .code16 jmp _start .org GRUB_BOOT_MACHINE_SIZE
a1ive/grub
9,639
grub-core/boot/i386/pc/lzma_decode.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #define FIXED_PROPS #define LZMA_BASE_SIZE 1846 #define LZMA_LIT_SIZE 768 #define LZMA_PROPERTIES_SIZE 5 #define kNumTopBits 24 #define kTopValue (1 << kNumTopBits) #define kNumBitModelTotalBits 11 #define kBitModelTotal (1 << kNumBitModelTotalBits) #define kNumMoveBits 5 #define kNumPosBitsMax 4 #define kNumPosStatesMax (1 << kNumPosBitsMax) #define kLenNumLowBits 3 #define kLenNumLowSymbols (1 << kLenNumLowBits) #define kLenNumMidBits 3 #define kLenNumMidSymbols (1 << kLenNumMidBits) #define kLenNumHighBits 8 #define kLenNumHighSymbols (1 << kLenNumHighBits) #define LenChoice 0 #define LenChoice2 (LenChoice + 1) #define LenLow (LenChoice2 + 1) #define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) #define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) #define kNumLenProbs (LenHigh + kLenNumHighSymbols) #define kNumStates 12 #define kNumLitStates 7 #define kStartPosModelIndex 4 #define kEndPosModelIndex 14 #define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) #define kNumPosSlotBits 6 #define kNumLenToPosStates 4 #define kNumAlignBits 4 #define kAlignTableSize (1 << kNumAlignBits) #define kMatchMinLen 2 #define IsMatch 0 #define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) #define IsRepG0 (IsRep + kNumStates) #define IsRepG1 (IsRepG0 + kNumStates) #define IsRepG2 (IsRepG1 + kNumStates) #define IsRep0Long (IsRepG2 + kNumStates) #define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) #define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) #define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) #define LenCoder (Align + kAlignTableSize) #define RepLenCoder (LenCoder + kNumLenProbs) #define Literal (RepLenCoder + kNumLenProbs) #define out_size 8(%ebp) #define now_pos -4(%ebp) #define prev_byte -8(%ebp) #define range -12(%ebp) #define code -16(%ebp) #define state -20(%ebp) #define rep0 -24(%ebp) #define rep1 -28(%ebp) #define rep2 -32(%ebp) #define rep3 -36(%ebp) #ifdef FIXED_PROPS #define FIXED_LC 3 #define FIXED_LP 0 #define FIXED_PB 2 #define POS_STATE_MASK ((1 << (FIXED_PB)) - 1) #define LIT_POS_MASK ((1 << (FIXED_LP)) - 1) #define LOCAL_SIZE 36 #else #define lc (%ebx) #define lp 4(%ebx) #define pb 8(%ebx) #define probs 12(%ebx) #define pos_state_mask -40(%ebp) #define lit_pos_mask -44(%ebp) #define LOCAL_SIZE 44 #endif RangeDecoderBitDecode: #ifdef FIXED_PROPS leal (%ebx, %eax, 4), %eax #else shll $2, %eax addl probs, %eax #endif movl %eax, %ecx movl (%ecx), %eax movl range, %edx shrl $kNumBitModelTotalBits, %edx mull %edx cmpl code, %eax jbe 1f movl %eax, range movl $kBitModelTotal, %edx subl (%ecx), %edx shrl $kNumMoveBits, %edx addl %edx, (%ecx) clc 3: pushf cmpl $kTopValue, range jnc 2f shll $8, code lodsb movb %al, code shll $8, range 2: popf ret 1: subl %eax, range subl %eax, code movl (%ecx), %edx shrl $kNumMoveBits, %edx subl %edx, (%ecx) stc jmp 3b RangeDecoderBitTreeDecode: RangeDecoderReverseBitTreeDecode: movzbl %cl, %ecx xorl %edx, %edx pushl %edx incl %edx pushl %edx 1: pushl %eax pushl %ecx pushl %edx addl %edx, %eax call RangeDecoderBitDecode popl %edx popl %ecx jnc 2f movl 4(%esp), %eax orl %eax, 8(%esp) stc 2: adcl %edx, %edx popl %eax shll $1, (%esp) loop 1b popl %ecx subl %ecx, %edx /* RangeDecoderBitTreeDecode */ popl %ecx /* RangeDecoderReverseBitTreeDecode */ ret LzmaLenDecode: pushl %eax addl $LenChoice, %eax call RangeDecoderBitDecode popl %eax jc 1f pushl $0 movb $kLenNumLowBits, %cl addl $LenLow, %eax 2: movl 12(%esp), %edx shll %cl, %edx addl %edx, %eax 3: call RangeDecoderBitTreeDecode popl %eax addl %eax, %edx ret 1: pushl %eax addl $LenChoice2, %eax call RangeDecoderBitDecode popl %eax jc 1f pushl $kLenNumLowSymbols movb $kLenNumMidBits, %cl addl $LenMid, %eax jmp 2b 1: pushl $(kLenNumLowSymbols + kLenNumMidSymbols) addl $LenHigh, %eax movb $kLenNumHighBits, %cl jmp 3b WriteByte: movb %al, prev_byte stosb incl now_pos ret /* * int LzmaDecode(CLzmaDecoderState *vs, * const unsigned char *inStream, * unsigned char *outStream, * SizeT outSize); */ _LzmaDecodeA: pushl %ebp movl %esp, %ebp subl $LOCAL_SIZE, %esp #ifndef ASM_FILE pushl %esi pushl %edi pushl %ebx movl %eax, %ebx movl %edx, %esi pushl %ecx #else pushl %edi #endif cld #ifdef FIXED_PROPS movl %ebx, %edi movl $(Literal + (LZMA_LIT_SIZE << (FIXED_LC + FIXED_LP))), %ecx #else movl $LZMA_LIT_SIZE, %eax movb lc, %cl addb lp, %cl shll %cl, %eax addl $Literal, %eax movl %eax, %ecx movl probs, %edi #endif movl $(kBitModelTotal >> 1), %eax rep stosl popl %edi xorl %eax, %eax movl %eax, now_pos movl %eax, prev_byte movl %eax, state incl %eax movl %eax, rep0 movl %eax, rep1 movl %eax, rep2 movl %eax, rep3 #ifndef FIXED_PROPS movl %eax, %edx movb pb, %cl shll %cl, %edx decl %edx movl %edx, pos_state_mask movl %eax, %edx movb lp, %cl shll %cl, %edx decl %edx movl %edx, lit_pos_mask; #endif /* RangeDecoderInit */ negl %eax movl %eax, range incl %eax movb $5, %cl 1: shll $8, %eax lodsb loop 1b movl %eax, code lzma_decode_loop: movl now_pos, %eax cmpl out_size, %eax jb 1f #ifndef ASM_FILE xorl %eax, %eax popl %ebx popl %edi popl %esi #endif movl %ebp, %esp popl %ebp ret 1: #ifdef FIXED_PROPS andl $POS_STATE_MASK, %eax #else andl pos_state_mask, %eax #endif pushl %eax /* posState */ movl state, %edx shll $kNumPosBitsMax, %edx addl %edx, %eax pushl %eax /* (state << kNumPosBitsMax) + posState */ call RangeDecoderBitDecode jc 1f movl now_pos, %eax #ifdef FIXED_PROPS andl $LIT_POS_MASK, %eax shll $FIXED_LC, %eax movl prev_byte, %edx shrl $(8 - FIXED_LC), %edx #else andl lit_pos_mask, %eax movb lc, %cl shll %cl, %eax negb %cl addb $8, %cl movl prev_byte, %edx shrl %cl, %edx #endif addl %edx, %eax movl $LZMA_LIT_SIZE, %edx mull %edx addl $Literal, %eax pushl %eax incl %edx /* edx = 1 */ movl rep0, %eax negl %eax pushl (%edi, %eax) /* matchByte */ cmpb $kNumLitStates, state jb 5f /* LzmaLiteralDecodeMatch */ 3: cmpl $0x100, %edx jae 4f xorl %eax, %eax shlb $1, (%esp) adcl %eax, %eax pushl %eax pushl %edx shll $8, %eax leal 0x100(%edx, %eax), %eax addl 12(%esp), %eax call RangeDecoderBitDecode setc %al popl %edx adcl %edx, %edx popl %ecx cmpb %cl, %al jz 3b 5: /* LzmaLiteralDecode */ cmpl $0x100, %edx jae 4f pushl %edx movl %edx, %eax addl 8(%esp), %eax call RangeDecoderBitDecode popl %edx adcl %edx, %edx jmp 5b 4: addl $16, %esp movb %dl, %al call WriteByte movb state, %al cmpb $4, %al jae 2f xorb %al, %al jmp 3f 2: subb $3, %al cmpb $7, %al jb 3f subb $3, %al 3: movb %al, state jmp lzma_decode_loop 1: movl state, %eax addl $IsRep, %eax call RangeDecoderBitDecode jnc 1f movl state, %eax addl $IsRepG0, %eax call RangeDecoderBitDecode jc 10f movl (%esp), %eax addl $IsRep0Long, %eax call RangeDecoderBitDecode jc 20f cmpb $7, state movb $9, state jb 100f addb $2, state 100: movl $1, %ecx 3: movl rep0, %edx negl %edx 4: movb (%edi, %edx), %al call WriteByte loop 4b popl %eax popl %eax jmp lzma_decode_loop 10: movl state, %eax addl $IsRepG1, %eax call RangeDecoderBitDecode movl rep1, %edx jnc 100f movl state, %eax addl $IsRepG2, %eax call RangeDecoderBitDecode movl rep2, %edx jnc 1000f movl rep2, %edx xchgl rep3, %edx 1000: pushl rep1 popl rep2 100: xchg rep0, %edx movl %edx, rep1 20: movl $RepLenCoder, %eax call LzmaLenDecode cmpb $7, state movb $8, state jb 100f addb $3, state 100: jmp 2f 1: movl rep0, %eax xchgl rep1, %eax xchgl rep2, %eax movl %eax, rep3 cmpb $7, state movb $7, state jb 10f addb $3, state 10: movl $LenCoder, %eax call LzmaLenDecode pushl %edx movl $(kNumLenToPosStates - 1), %eax cmpl %eax, %edx jbe 100f movl %eax, %edx 100: movb $kNumPosSlotBits, %cl shll %cl, %edx leal PosSlot(%edx), %eax call RangeDecoderBitTreeDecode movl %edx, rep0 cmpl $kStartPosModelIndex, %edx jb 100f movl %edx, %ecx shrl $1, %ecx decl %ecx movzbl %dl, %eax andb $1, %al orb $2, %al shll %cl, %eax movl %eax, rep0 cmpl $kEndPosModelIndex, %edx jae 200f movl rep0, %eax addl $(SpecPos - 1), %eax subl %edx, %eax jmp 300f 200: subb $kNumAlignBits, %cl /* RangeDecoderDecodeDirectBits */ xorl %edx, %edx 1000: shrl $1, range shll $1, %edx movl range, %eax cmpl %eax, code jb 2000f subl %eax, code orb $1, %dl 2000: cmpl $kTopValue, %eax jae 3000f shll $8, range shll $8, code lodsb movb %al, code 3000: loop 1000b movb $kNumAlignBits, %cl shll %cl, %edx addl %edx, rep0 movl $Align, %eax 300: call RangeDecoderReverseBitTreeDecode addl %ecx, rep0 100: incl rep0 popl %edx 2: addl $kMatchMinLen, %edx movl %edx, %ecx jmp 3b
a1ive/grub
2,922
grub-core/boot/i386/pc/cdboot.S
/* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/boot.h> #include <grub/machine/kernel.h> #include <multiboot.h> .file "cdboot.S" #define CODE_ADDR 0x6000 #define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200) #define CDSEC_SHIFT 11 #define CDBLK_LENG 16 .text .code16 .globl start, _start start: _start: call LOCAL(next) LOCAL(next): jmp 1f .org 8 bi_pvd: .long 0 /* LBA of primary volume descriptor. */ bi_file: .long 0 /* LBA of boot file. */ bi_length: .long 0 /* Length of boot file. */ bi_csum: .long 0 /* Checksum of boot file */ bi_reserved: .space (10*4) /* Reserved */ 1: popw %bx /* Boot from CDROM. */ xorw %ax, %ax movw %ax, %ss movw $(CODE_ADDR), %sp movw %ax, %ds movw %ax, %es movw $(0x7C00 + err_noboot_msg - start), %si movl %cs: bi_length - LOCAL(next)(%bx), %ecx orl %ecx, %ecx jz LOCAL(fail) addl $((1 << CDSEC_SHIFT) - 1), %ecx shrl $CDSEC_SHIFT, %ecx movl %cs: bi_file - LOCAL(next)(%bx), %esi call LOCAL(read_cdrom) ljmp $(DATA_ADDR >> 4), $0 /* * Parameters: * esi: start sector * ecx: number of sectors */ LOCAL(read_cdrom): xorl %eax, %eax /* Number of blocks to read. */ pushw $CDBLK_LENG /* Block number. */ incl %esi pushl %eax pushl %esi /* Buffer address. */ pushw $((DATA_ADDR - 0x200)>> 4) pushl %eax pushw $0x10 xorl %edi, %edi movw %sp, %si 1: movw 0x10(%si), %di cmpl %ecx, %edi jbe 2f movl %ecx, %edi 2: mov %di, 2(%si) pushl %ecx movb $0x42, %ah int $0x13 jnc 3f movb $0x42, %ah /* Try again. */ int $0x13 jnc 3f 2: shrw $1, %di /* Reduce transfer size. */ jz LOCAL(cdrom_fail) movw %di, 0x10(%si) movw %di, 2(%si) movb $0x42, %ah int $0x13 jc 2b 3: movw %di, %ax shlw $(CDSEC_SHIFT - 4), %ax addw %ax, 6(%si) addl %edi, 8(%si) popl %ecx subl %edi, %ecx jnz 1b addw $0x12, %sp ret LOCAL(cdrom_fail): movw $(0x7C00 + err_cdfail_msg - start), %si LOCAL(fail): movb $0x0e, %ah xorw %bx, %bx 1: lodsb (%si), %al int $0x10 cmpb $0, %al jne 1b 1: jmp 1b err_noboot_msg: .ascii "no boot info\0" err_cdfail_msg: .ascii "cdrom read fails\0" .org 0x7FF .byte 0
a1ive/grub
7,868
grub-core/boot/i386/pc/startup_raw.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/offsets.h> #include <grub/machine/boot.h> #include <grub/machine/memory.h> #include <grub/machine/kernel.h> #define ABS(x) ((x) - LOCAL (base) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200) .file "startup_raw.S" .text /* Tell GAS to generate 16-bit instructions so that this code works in real mode. */ .code16 .globl start, _start start: _start: LOCAL (base): /* * Guarantee that "main" is loaded at 0x0:0x8200. */ #ifdef __APPLE__ ljmp $0, $(ABS(LOCAL (codestart)) - 0x10000) #else ljmp $0, $ABS(LOCAL (codestart)) #endif /* * This is a special data area. */ .org GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE LOCAL(compressed_size): .long 0 .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE LOCAL(uncompressed_size): .long 0 .org GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY reed_solomon_redundancy: .long 0 .org GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH .short (LOCAL(reed_solomon_part) - _start) /* * This is the area for all of the special variables. */ .org GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE LOCAL(boot_dev): .byte 0xFF, 0xFF, 0xFF LOCAL(boot_drive): .byte 0x00 /* the real mode code continues... */ LOCAL (codestart): cli /* we're not safe here! */ /* set up %ds, %ss, and %es */ xorw %ax, %ax movw %ax, %ds movw %ax, %ss movw %ax, %es /* set up the real mode/BIOS stack */ movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp movl %ebp, %esp sti /* we're safe again */ /* save the boot drive */ movb %dl, LOCAL(boot_drive) /* reset disk system (%ah = 0) */ int $0x13 /* transition to protected mode */ calll real_to_prot /* The ".code32" directive takes GAS out of 16-bit mode. */ .code32 cld call grub_gate_a20 movl LOCAL(compressed_size), %edx #ifdef __APPLE__ addl $decompressor_end, %edx subl $(LOCAL(reed_solomon_part)), %edx #else addl $(LOCAL(decompressor_end) - LOCAL(reed_solomon_part)), %edx #endif movl reed_solomon_redundancy, %ecx leal LOCAL(reed_solomon_part), %eax cld call EXT_C (grub_reed_solomon_recover) jmp post_reed_solomon #include "../../../kern/i386/realmode.S" /* * * This is a workaround for clang adding a section containing only .addrsig * Since clang itself is unable to assemble this pseudo-opcode, just replace * it with .text * */ #define addrsig text #include <rs_decoder.h> #undef addrsig .text /* * grub_gate_a20(void) * * Gate address-line 20 for high memory. * * This routine is probably overconservative in what it does, but so what? * * It also eats any keystrokes in the keyboard buffer. :-( */ grub_gate_a20: gate_a20_test_current_state: /* first of all, test if already in a good state */ call gate_a20_check_state testb %al, %al jnz gate_a20_try_bios ret gate_a20_try_bios: /* second, try a BIOS call */ pushl %ebp call prot_to_real .code16 movw $0x2401, %ax int $0x15 calll real_to_prot .code32 popl %ebp call gate_a20_check_state testb %al, %al jnz gate_a20_try_system_control_port_a ret gate_a20_try_system_control_port_a: /* * In macbook, the keyboard test would hang the machine, so we move * this forward. */ /* fourth, try the system control port A */ inb $0x92 andb $(~0x03), %al orb $0x02, %al outb $0x92 call gate_a20_check_state testb %al, %al jnz gate_a20_try_keyboard_controller ret gate_a20_flush_keyboard_buffer: inb $0x64 andb $0x02, %al jnz gate_a20_flush_keyboard_buffer 2: inb $0x64 andb $0x01, %al jz 3f inb $0x60 jmp 2b 3: ret gate_a20_try_keyboard_controller: /* third, try the keyboard controller */ call gate_a20_flush_keyboard_buffer movb $0xd1, %al outb $0x64 4: inb $0x64 andb $0x02, %al jnz 4b movb $0xdf, %al outb $0x60 call gate_a20_flush_keyboard_buffer /* output a dummy command (USB keyboard hack) */ movb $0xff, %al outb $0x64 call gate_a20_flush_keyboard_buffer call gate_a20_check_state testb %al, %al /* everything failed, so restart from the beginning */ jnz gate_a20_try_bios ret gate_a20_check_state: /* iterate the checking for a while */ movl $100, %ecx 1: call 3f testb %al, %al jz 2f loop 1b 2: ret 3: pushl %ebx pushl %ecx xorl %eax, %eax /* compare the byte at 0x8000 with that at 0x108000 */ movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx pushl %ebx /* save the original byte in CL */ movb (%ebx), %cl /* store the value at 0x108000 in AL */ addl $0x100000, %ebx movb (%ebx), %al /* try to set one less value at 0x8000 */ popl %ebx movb %al, %ch decb %ch movb %ch, (%ebx) /* serialize */ outb %al, $0x80 outb %al, $0x80 /* obtain the value at 0x108000 in CH */ pushl %ebx addl $0x100000, %ebx movb (%ebx), %ch /* this result is 0 if A20 is on or 1 if it is off */ subb %ch, %al /* restore the original */ popl %ebx movb %cl, (%ebx) popl %ecx popl %ebx ret LOCAL(reed_solomon_part): /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). * This uses the a.out kludge to load raw binary to the area starting at 1MB, * and relocates itself after loaded. */ .p2align 2 /* force 4-byte alignment */ multiboot_header: /* magic */ .long 0x1BADB002 /* flags */ .long (1 << 16) /* checksum */ .long -0x1BADB002 - (1 << 16) /* header addr */ .long multiboot_header - _start + 0x100000 + 0x200 /* load addr */ .long 0x100000 /* load end addr */ .long 0 /* bss end addr */ .long 0 /* entry addr */ .long multiboot_entry - _start + 0x100000 + 0x200 multiboot_entry: .code32 /* obtain the boot device */ movl 12(%ebx), %edx movl $GRUB_MEMORY_MACHINE_PROT_STACK, %ebp movl %ebp, %esp /* relocate the code */ #ifdef __APPLE__ LOCAL(compressed_size_offset) = LOCAL(compressed_size) - LOCAL(base) movl $0x200, %ecx addl $decompressor_end, %ecx subl $LOCAL(base), %ecx addl LOCAL(compressed_size_offset) + 0x100000 + 0x200, %ecx #else movl $(LOCAL(decompressor_end) - _start + 0x200), %ecx addl LOCAL(compressed_size) - _start + 0x100000 + 0x200, %ecx #endif movl $0x100000, %esi movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi cld rep movsb /* jump to the real address */ movl $multiboot_trampoline, %eax jmp *%eax multiboot_trampoline: /* fill the boot information */ movl %edx, LOCAL(boot_dev) shrl $24, %edx /* enter the usual booting */ call prot_to_real .code16 jmp LOCAL (codestart) .code32 post_reed_solomon: #ifdef ENABLE_LZMA movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi #ifdef __APPLE__ movl $decompressor_end, %esi #else movl $LOCAL(decompressor_end), %esi #endif pushl %edi movl LOCAL (uncompressed_size), %ecx leal (%edi, %ecx), %ebx /* Don't remove this push: it's an argument. */ push %ecx call _LzmaDecodeA pop %ecx /* _LzmaDecodeA clears DF, so no need to run cld */ popl %esi #endif movl LOCAL(boot_dev), %edx movl $prot_to_real, %edi movl $real_to_prot, %ecx movl $LOCAL(realidt), %eax jmp *%esi #ifdef ENABLE_LZMA #include "lzma_decode.S" #endif .p2align 4 #ifdef __APPLE__ .zerofill __DATA, __aa_before_bss, decompressor_end, 10, 0 #else .bss LOCAL(decompressor_end): #endif
a1ive/grub
8,626
grub-core/boot/i386/pc/diskboot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2006,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/boot.h> /* * defines for the code go here */ #define MSG(x) movw $x, %si; call LOCAL(message) .file "diskboot.S" .text /* Tell GAS to generate 16-bit instructions so that this code works in real mode. */ .code16 .globl start, _start start: _start: /* * _start is loaded at 0x8000 and is jumped to with * CS:IP 0:0x8000 in kernel. */ /* * we continue to use the stack for boot.img and assume that * some registers are set to correct values. See boot.S * for more information. */ /* save drive reference first thing! */ pushw %dx /* this sets up for the first run through "bootloop" */ movw $LOCAL(firstlist), %di /* save the sector number of the second sector in %ebp */ movl (%di), %ebp /* this is the loop for reading the rest of the kernel in */ LOCAL(bootloop): /* check the number of sectors to read */ cmpw $0, 8(%di) /* if zero, go to the start function */ je LOCAL(bootit) LOCAL(setup_sectors): /* check if we use LBA or CHS */ cmpb $0, -1(%si) /* use CHS if zero, LBA otherwise */ je LOCAL(chs_mode) /* load logical sector start */ movl (%di), %ebx movl 4(%di), %ecx /* the maximum is limited to 0x7f because of Phoenix EDD */ xorl %eax, %eax movb $0x7f, %al /* how many do we really want to read? */ cmpw %ax, 8(%di) /* compare against total number of sectors */ /* which is greater? */ jg 1f /* if less than, set to total */ movw 8(%di), %ax 1: /* subtract from total */ subw %ax, 8(%di) /* add into logical sector start */ addl %eax, (%di) adcl $0, 4(%di) /* set up disk address packet */ /* the size and the reserved byte */ movw $0x0010, (%si) /* the number of sectors */ movw %ax, 2(%si) /* the absolute address */ movl %ebx, 8(%si) movl %ecx, 12(%si) /* the segment of buffer address */ movw $GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si) /* save %ax from destruction! */ pushw %ax /* the offset of buffer address */ movw $0, 4(%si) /* * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory * Call with %ah = 0x42 * %dl = drive number * %ds:%si = segment:offset of disk address packet * Return: * %al = 0x0 on success; err code on failure */ movb $0x42, %ah int $0x13 jc LOCAL(read_error) movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx jmp LOCAL(copy_buffer) LOCAL(chs_mode): /* load logical sector start (top half) */ movl 4(%di), %eax orl %eax, %eax jnz LOCAL(geometry_error) /* load logical sector start (bottom half) */ movl (%di), %eax /* zero %edx */ xorl %edx, %edx /* divide by number of sectors */ divl (%si) /* save sector start */ movb %dl, 10(%si) xorl %edx, %edx /* zero %edx */ divl 4(%si) /* divide by number of heads */ /* save head start */ movb %dl, 11(%si) /* save cylinder start */ movw %ax, 12(%si) /* do we need too many cylinders? */ cmpw 8(%si), %ax jge LOCAL(geometry_error) /* determine the maximum sector length of this read */ movw (%si), %ax /* get number of sectors per track/head */ /* subtract sector start */ subb 10(%si), %al /* how many do we really want to read? */ cmpw %ax, 8(%di) /* compare against total number of sectors */ /* which is greater? */ jg 2f /* if less than, set to total */ movw 8(%di), %ax 2: /* subtract from total */ subw %ax, 8(%di) /* add into logical sector start */ addl %eax, (%di) adcl $0, 4(%di) /* * This is the loop for taking care of BIOS geometry translation (ugh!) */ /* get high bits of cylinder */ movb 13(%si), %dl shlb $6, %dl /* shift left by 6 bits */ movb 10(%si), %cl /* get sector */ incb %cl /* normalize sector (sectors go from 1-N, not 0-(N-1) ) */ orb %dl, %cl /* composite together */ movb 12(%si), %ch /* sector+hcyl in cl, cylinder in ch */ /* restore %dx */ popw %dx pushw %dx /* head number */ movb 11(%si), %dh pushw %ax /* save %ax from destruction! */ /* * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory * Call with %ah = 0x2 * %al = number of sectors * %ch = cylinder * %cl = sector (bits 6-7 are high bits of "cylinder") * %dh = head * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) * %es:%bx = segment:offset of buffer * Return: * %al = 0x0 on success; err code on failure */ movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw %bx, %es /* load %es segment with disk buffer */ xorw %bx, %bx /* %bx = 0, put it at 0 in the segment */ movb $0x2, %ah /* function 2 */ int $0x13 jc LOCAL(read_error) /* save source segment */ movw %es, %bx LOCAL(copy_buffer): /* load addresses for copy from disk buffer to destination */ movw 10(%di), %es /* load destination segment */ /* restore %ax */ popw %ax /* determine the next possible destination address (presuming 512 byte sectors!) */ shlw $5, %ax /* shift %ax five bits to the left */ addw %ax, 10(%di) /* add the corrected value to the destination address for next time */ /* save addressing regs */ pusha pushw %ds /* get the copy length */ shlw $3, %ax movw %ax, %cx xorw %di, %di /* zero offset of destination addresses */ xorw %si, %si /* zero offset of source addresses */ movw %bx, %ds /* restore the source segment */ cld /* sets the copy direction to forward */ /* perform copy */ rep /* sets a repeat */ movsw /* this runs the actual copy */ /* restore addressing regs and print a dot with correct DS (MSG modifies SI, which is saved, and unused AX and BX) */ popw %ds MSG(notification_step) popa /* check if finished with this dataset */ cmpw $0, 8(%di) jne LOCAL(setup_sectors) /* update position to load from */ subw $GRUB_BOOT_MACHINE_LIST_SIZE, %di /* jump to bootloop */ jmp LOCAL(bootloop) /* END OF MAIN LOOP */ LOCAL(bootit): /* print a newline */ MSG(notification_done) popw %dx /* this makes sure %dl is our "boot" drive */ ljmp $0, $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200) /* * BIOS Geometry translation error (past the end of the disk geometry!). */ LOCAL(geometry_error): MSG(geometry_error_string) jmp LOCAL(general_error) /* * Read error on the disk. */ LOCAL(read_error): MSG(read_error_string) LOCAL(general_error): MSG(general_error_string) /* go here when you need to stop the machine hard after an error condition */ LOCAL(stop): jmp LOCAL(stop) notification_string: .asciz "loading" notification_step: .asciz "." notification_done: .asciz "\r\n" geometry_error_string: .asciz "Geom" read_error_string: .asciz "Read" general_error_string: .asciz " Error" /* * message: write the string pointed to by %si * * WARNING: trashes %si, %ax, and %bx */ /* * Use BIOS "int 10H Function 0Eh" to write character in teletype mode * %ah = 0xe %al = character * %bh = page %bl = foreground color (graphics modes) */ 1: movw $0x0001, %bx movb $0xe, %ah int $0x10 /* display a byte */ incw %si LOCAL(message): movb (%si), %al cmpb $0, %al jne 1b /* if not end of string, jmp to display */ ret /* * This area is an empty space between the main body of code below which * grows up (fixed after compilation, but between releases it may change * in size easily), and the lists of sectors to read, which grows down * from a fixed top location. */ .word 0 .word 0 .org 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE LOCAL(firstlist): /* this label has to be before the first list entry!!! */ /* fill the first data listing with the default */ blocklist_default_start: /* this is the sector start parameter, in logical sectors from the start of the disk, sector 0 */ .long 2, 0 blocklist_default_len: /* this is the number of sectors to read. grub-mkimage will fill this up */ .word 0 blocklist_default_seg: /* this is the segment of the starting address to load the data into */ .word (GRUB_BOOT_MACHINE_KERNEL_SEG + 0x20)
a1ive/grub
5,452
grub-core/boot/i386/pc/lnxboot.S
/* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/machine/boot.h> #include <grub/machine/kernel.h> #include <multiboot.h> .file "lnxboot.S" #define CODE_ADDR 0x6000 #define CODE_SECTORS 1 #define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200) #define BLCK_LENG 0x4000 .text .code16 .globl start, _start data_start: xorl %ebp, %ebp jmp LOCAL(linux_next) .org 0x1F1 setup_sects: .byte CODE_SECTORS root_flags: .word 0 syssize: .word 0 swap_dev: .word 0 ram_size: .word 0 vid_mode: .word 0 root_dev: .word 0 boot_flag: .word 0xAA55 start: _start: jmp LOCAL(linux_init) .ascii "HdrS" /* Header signature. */ .word 0x0203 /* Header version number. */ realmode_swtch: .word 0, 0 /* default_switch, SETUPSEG. */ start_sys_seg: .word 0x1000 /* Obsolete. */ version_ptr: .word 0 /* Version string ptr. */ type_of_loader: .byte 0 /* Filled in by boot loader. */ loadflags: .byte 1 /* Please load high. */ setup_move_size: .word 0 /* Unused. */ code32_start: .long 0x100000 /* 32-bit start address. */ ramdisk_image: .long 0 /* Loaded ramdisk image address. */ ramdisk_size: .long 0 /* Size of loaded ramdisk. */ bootsect_kludge: .word 0, 0 heap_end_ptr: .word 0 pad1: .word 0 cmd_line_ptr: .long 0 /* Command line. */ ramdisk_max: .long 0xffffffff /* Highest allowed ramdisk address. */ gdt: .long 0, 0, 0, 0 /* Must be zero. */ .word 0xffff /* 64 K segment size. */ gdt_src1: .byte 0, 0 ,0 /* Low 24 bits of source address. */ .byte 0x93 /* Access rights. */ .byte 0 /* Extended access rights. */ gdt_src2: .byte 0 /* High 8 bits of source address. */ .word 0xffff /* 64 K segment size. */ gdt_dst1: .byte 0, 0, 0 /* Low 24 bits of target address. */ .byte 0x93 /* Access rights. */ .byte 0 /* Extended access rights. */ gdt_dst2: .byte 0 /* High 8 bits of source address. */ .long 0, 0, 0, 0 /* More space for the BIOS. */ reg_edx: .byte 0x80, 0, 0xFF, 0xFF data_leng: .long 0 LOCAL(linux_init): movw %cs:(reg_edx - start), %dx movl %cs:(code32_start - start), %ebp LOCAL(linux_next): call LOCAL(normalize) LOCAL(normalize): popw %bx subw $(LOCAL(normalize) - start), %bx shrw $4, %bx movw %cs, %ax addw %bx, %ax pushw %ax pushw $(real_code - start) lret /* Jump to real_code. */ real_code: subw $0x20, %ax movw %ax, %ds movw (setup_sects - data_start), %cx shlw $7, %cx /* Setup stack. */ xorw %si, %si movw %si, %ss movw $(CODE_ADDR), %sp /* Move itself to 0:CODE_ADDR. */ cld movw %cs, %ax movw %ax, %ds movw $(CODE_ADDR >> 4), %ax movw %ax, %es movw %si, %di rep movsl ljmp $(CODE_ADDR >> 4), $(real_code_2 - start) real_code_2: xchgl %ebp, %esi orl %esi, %esi jnz 1f movw %ds, %si shll $4, %esi addl %ebp, %esi 1: pushw %es popw %ds movl $0x1000, %ecx addl $0x200, %esi movl $DATA_ADDR, %edi call LOCAL(move_memory) /* Check for multiboot signature. */ movl $DATA_ADDR, %edi 3: movl %ss:(%edi), %eax cmpl $MULTIBOOT_HEADER_MAGIC, %eax jz 1f addl $4, %edi cmpl $(DATA_ADDR + 0x1000), %edi jne 3b movl (ramdisk_image - start), %esi movl (ramdisk_size - start), %ecx movl $(DATA_ADDR - 0x200), %edi jmp 2f 1: movl $(DATA_ADDR + 0x1000), %edi movl %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE), %ecx addl $GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE, %ecx 2: call LOCAL(move_memory) movb %dh, %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE + 2) movb (reg_edx + 2 - start), %dh movb %dh, %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE + 1) movb $0xFF, %dh ljmp $(DATA_ADDR >> 4), $0 /* * Parameters: * esi: source address * edi: target address * ecx: number of bytes */ LOCAL(move_memory): incl %ecx andb $0xFE, %cl pushw %dx 1: pushl %esi pushl %edi pushl %ecx cmpl $BLCK_LENG, %ecx jbe 2f movl $BLCK_LENG, %ecx 2: pushl %ecx movl %esi, %eax movw %si, (gdt_src1 - start) shrl $16, %eax movb %al, (gdt_src1 + 2 - start) movb %ah, (gdt_src2 - start) movl %edi, %eax movw %di, (gdt_dst1 - start) shrl $16, %eax movb %al, (gdt_dst1 + 2 - start) movb %ah, (gdt_dst2 - start) movw $(gdt - start), %si movb $0x87, %ah shrw $1, %cx int $0x15 popl %eax popl %ecx popl %edi popl %esi jnc 2f movw $(err_int15_msg - start), %si jmp LOCAL(fail) 2: addl %eax, %esi addl %eax, %edi subl %eax, %ecx jnz 1b popw %dx ret /* * Parameters: * si: message */ LOCAL(fail): movb $0x0e, %ah xorw %bx, %bx 1: lodsb (%si), %al int $0x10 cmpb $0, %al jne 1b 1: jmp 1b err_int15_msg: .ascii "move memory fails\0" .org (CODE_SECTORS * 512 + 512)
a1ive/grub
10,421
grub-core/boot/i386/pc/boot.S
/* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/boot.h> /* * defines for the code go here */ /* Print message string */ #define MSG(x) movw $x, %si; call LOCAL(message) #define ERR(x) movw $x, %si; jmp LOCAL(error_message) .macro floppy part_start: LOCAL(probe_values): .byte 36, 18, 15, 9, 0 LOCAL(floppy_probe): pushw %dx /* * Perform floppy probe. */ #ifdef __APPLE__ LOCAL(probe_values_minus_one) = LOCAL(probe_values) - 1 movw MACRO_DOLLAR(LOCAL(probe_values_minus_one)), %si #else movw MACRO_DOLLAR(LOCAL(probe_values)) - 1, %si #endif LOCAL(probe_loop): /* reset floppy controller INT 13h AH=0 */ xorw %ax, %ax int MACRO_DOLLAR(0x13) incw %si movb (%si), %cl /* if number of sectors is 0, display error and die */ testb %cl, %cl jnz 1f /* * Floppy disk probe failure. */ MSG(fd_probe_error_string) jmp LOCAL(general_error) /* "Floppy" */ fd_probe_error_string: .asciz "Floppy" 1: /* perform read */ movw MACRO_DOLLAR(GRUB_BOOT_MACHINE_BUFFER_SEG), %bx movw %bx, %es xorw %bx, %bx movw MACRO_DOLLAR(0x201), %ax movb MACRO_DOLLAR(0), %ch movb MACRO_DOLLAR(0), %dh int MACRO_DOLLAR(0x13) /* if error, jump to "LOCAL(probe_loop)" */ jc LOCAL(probe_loop) /* %cl is already the correct value! */ movb MACRO_DOLLAR(1), %dh movb MACRO_DOLLAR(79), %ch jmp LOCAL(final_init) .endm .macro scratch /* scratch space */ mode: .byte 0 disk_address_packet: sectors: .long 0 heads: .long 0 cylinders: .word 0 sector_start: .byte 0 head_start: .byte 0 cylinder_start: .word 0 /* more space... */ .endm .file "boot.S" .text /* Tell GAS to generate 16-bit instructions so that this code works in real mode. */ .code16 .globl _start, start; _start: start: /* * _start is loaded at 0x7c00 and is jumped to with CS:IP 0:0x7c00 */ /* * Beginning of the sector is compatible with the FAT/HPFS BIOS * parameter block. */ jmp LOCAL(after_BPB) nop /* do I care about this ??? */ #ifdef HYBRID_BOOT nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop jmp LOCAL(after_BPB) #else /* * This space is for the BIOS parameter block!!!! Don't change * the first jump, nor start the code anywhere but right after * this area. */ .org GRUB_BOOT_MACHINE_BPB_START .org 4 #endif #ifdef HYBRID_BOOT floppy #else scratch #endif .org GRUB_BOOT_MACHINE_BPB_END /* * End of BIOS parameter block. */ LOCAL(kernel_address): .word GRUB_BOOT_MACHINE_KERNEL_ADDR #ifndef HYBRID_BOOT .org GRUB_BOOT_MACHINE_KERNEL_SECTOR LOCAL(kernel_sector): .long 1 LOCAL(kernel_sector_high): .long 0 #endif .org GRUB_BOOT_MACHINE_BOOT_DRIVE boot_drive: .byte 0xff /* the disk to load kernel from */ /* 0xff means use the boot drive */ LOCAL(after_BPB): /* general setup */ cli /* we're not safe here! */ /* * This is a workaround for buggy BIOSes which don't pass boot * drive correctly. If GRUB is installed into a HDD, check if * DL is masked correctly. If not, assume that the BIOS passed * a bogus value and set DL to 0x80, since this is the only * possible boot drive. If GRUB is installed into a floppy, * this does nothing (only jump). */ .org GRUB_BOOT_MACHINE_DRIVE_CHECK boot_drive_check: jmp 3f /* grub-setup may overwrite this jump */ testb $0x80, %dl jz 2f 3: /* Ignore %dl different from 0-0x0f and 0x80-0x8f. */ testb $0x70, %dl jz 1f 2: movb $0x80, %dl 1: /* * ljmp to the next instruction because some bogus BIOSes * jump to 07C0:0000 instead of 0000:7C00. */ ljmp $0, $real_start real_start: /* set up %ds and %ss as offset from 0 */ xorw %ax, %ax movw %ax, %ds movw %ax, %ss /* set up the REAL stack */ movw $GRUB_BOOT_MACHINE_STACK_SEG, %sp sti /* we're safe again */ /* * Check if we have a forced disk reference here */ movb boot_drive, %al cmpb $0xff, %al je 1f movb %al, %dl 1: /* save drive reference first thing! */ pushw %dx /* set %si to the disk address packet */ movw $disk_address_packet, %si /* check if LBA is supported */ movb $0x41, %ah movw $0x55aa, %bx int $0x13 /* * %dl may have been clobbered by INT 13, AH=41H. * This happens, for example, with AST BIOS 1.04. */ popw %dx pushw %dx /* use CHS if fails */ jc LOCAL(chs_mode) cmpw $0xaa55, %bx jne LOCAL(chs_mode) andw $1, %cx jz LOCAL(chs_mode) LOCAL(lba_mode): xorw %ax, %ax movw %ax, 4(%si) incw %ax /* set the mode to non-zero */ movb %al, -1(%si) /* the blocks */ movw %ax, 2(%si) /* the size and the reserved byte */ movw $0x0010, (%si) /* the absolute address */ movl LOCAL(kernel_sector), %ebx movl %ebx, 8(%si) movl LOCAL(kernel_sector_high), %ebx movl %ebx, 12(%si) /* the segment of buffer address */ movw $GRUB_BOOT_MACHINE_BUFFER_SEG, 6(%si) /* * BIOS call "INT 0x13 Function 0x42" to read sectors from disk into memory * Call with %ah = 0x42 * %dl = drive number * %ds:%si = segment:offset of disk address packet * Return: * %al = 0x0 on success; err code on failure */ movb $0x42, %ah int $0x13 /* LBA read is not supported, so fallback to CHS. */ jc LOCAL(chs_mode) movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx jmp LOCAL(copy_buffer) LOCAL(chs_mode): /* * Determine the hard disk geometry from the BIOS! * We do this first, so that LS-120 IDE floppies work correctly. */ movb $8, %ah int $0x13 jnc LOCAL(final_init) popw %dx /* * The call failed, so maybe use the floppy probe instead. */ testb %dl, %dl jnb LOCAL(floppy_probe) /* Nope, we definitely have a hard disk, and we're screwed. */ ERR(hd_probe_error_string) LOCAL(final_init): /* set the mode to zero */ movzbl %dh, %eax movb %ah, -1(%si) /* save number of heads */ incw %ax movl %eax, 4(%si) movzbw %cl, %dx shlw $2, %dx movb %ch, %al movb %dh, %ah /* save number of cylinders */ incw %ax movw %ax, 8(%si) movzbw %dl, %ax shrb $2, %al /* save number of sectors */ movl %eax, (%si) setup_sectors: /* load logical sector start (top half) */ movl LOCAL(kernel_sector_high), %eax orl %eax, %eax jnz LOCAL(geometry_error) /* load logical sector start (bottom half) */ movl LOCAL(kernel_sector), %eax /* zero %edx */ xorl %edx, %edx /* divide by number of sectors */ divl (%si) /* save sector start */ movb %dl, %cl xorw %dx, %dx /* zero %edx */ divl 4(%si) /* divide by number of heads */ /* do we need too many cylinders? */ cmpw 8(%si), %ax jge LOCAL(geometry_error) /* normalize sector start (1-based) */ incb %cl /* low bits of cylinder start */ movb %al, %ch /* high bits of cylinder start */ xorb %al, %al shrw $2, %ax orb %al, %cl /* save head start */ movb %dl, %al /* restore %dl */ popw %dx /* head start */ movb %al, %dh /* * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory * Call with %ah = 0x2 * %al = number of sectors * %ch = cylinder * %cl = sector (bits 6-7 are high bits of "cylinder") * %dh = head * %dl = drive (0x80 for hard disk, 0x0 for floppy disk) * %es:%bx = segment:offset of buffer * Return: * %al = 0x0 on success; err code on failure */ movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw %bx, %es /* load %es segment with disk buffer */ xorw %bx, %bx /* %bx = 0, put it at 0 in the segment */ movw $0x0201, %ax /* function 2 */ int $0x13 jc LOCAL(read_error) movw %es, %bx LOCAL(copy_buffer): /* * We need to save %cx and %si because the startup code in * kernel uses them without initializing them. */ pusha pushw %ds movw $0x100, %cx movw %bx, %ds xorw %si, %si movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di movw %si, %es cld rep movsw popw %ds popa /* boot kernel */ jmp *(LOCAL(kernel_address)) /* END OF MAIN LOOP */ /* * BIOS Geometry translation error (past the end of the disk geometry!). */ LOCAL(geometry_error): ERR(geometry_error_string) /* * Read error on the disk. */ LOCAL(read_error): movw $read_error_string, %si LOCAL(error_message): call LOCAL(message) LOCAL(general_error): MSG(general_error_string) /* go here when you need to stop the machine hard after an error condition */ /* tell the BIOS a boot failure, which may result in no effect */ int $0x18 LOCAL(stop): jmp LOCAL(stop) notification_string: .asciz "GRUB " geometry_error_string: .asciz "Geom" hd_probe_error_string: .asciz "Hard Disk" read_error_string: .asciz "Read" general_error_string: .asciz " Error\r\n" /* * message: write the string pointed to by %si * * WARNING: trashes %si, %ax, and %bx */ /* * Use BIOS "int 10H Function 0Eh" to write character in teletype mode * %ah = 0xe %al = character * %bh = page %bl = foreground color (graphics modes) */ 1: movw $0x0001, %bx movb $0xe, %ah int $0x10 /* display a byte */ LOCAL(message): lodsb cmpb $0, %al jne 1b /* if not end of string, jmp to display */ ret /* * Windows NT breaks compatibility by embedding a magic * number here. */ #ifdef HYBRID_BOOT .org 0x1b0 LOCAL(kernel_sector): .long 1 LOCAL(kernel_sector_high): .long 0 #endif .org GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC nt_magic: .long 0 .word 0 /* * This is where an MBR would go if on a hard disk. The code * here isn't even referenced unless we're on a floppy. Kinda * sneaky, huh? */ .org GRUB_BOOT_MACHINE_PART_START #ifndef HYBRID_BOOT floppy #else scratch #endif .org GRUB_BOOT_MACHINE_PART_END /* the last 2 bytes in the sector 0 contain the signature */ .word GRUB_BOOT_MACHINE_SIGNATURE
a1ive/grub
1,303
grub-core/boot/i386/pc/pxeboot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2000,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/machine/boot.h> .file "pxeboot.S" .text /* Start with the prehistoric environment... */ .code16 /* Let's go */ .globl start, _start; _start: start: /* Use drive number 0x7F for PXE */ movb $GRUB_BOOT_MACHINE_PXE_DL, %dl /* Jump to the real world */ ljmp $0, $0x8200 /* This region is a junk. Do you say that this is wasteful? But I like that the memory layout of the body is consistent among different kernels rather than scamping just for 1.5KB. */ .org 0x8200 - 0x7C00 - 0x200 - 1 .byte 0
a1ive/grub
3,229
grub-core/boot/sparc64/ieee1275/diskboot.S
/* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/machine/boot.h> #include <grub/offsets.h> .text .align 4 .globl _start _start: /* First stage boot block jumps to us here. */ pic_base: call after_info_block mov %o7, PIC_REG prom_write_name: .asciz "write" prom_seek_name: .asciz "seek" prom_read_name: .asciz "read" prom_close_name: .asciz "close" notification_string: .asciz "Loading kernel" #define NOTIFICATION_STRING_LEN 14 notification_step: .asciz "." #define NOTIFICATION_STEP_LEN 1 notification_done: .asciz "\r\n" #define NOTIFICATION_DONE_LEN 2 .align 4 /* %o2: message string * %o3: message length */ console_write: GET_ABS(prom_write_name, %o0) mov STDOUT_NODE_REG, %o1 /* fallthru */ /* %o0: OF call name * %o1: input arg 1 * %o2: input arg 2 * %o3: input arg 3 */ prom_call_3_1: mov 3, %g1 mov 1, %o5 /* fallthru */ /* %o0: OF call name * %g1: num inputs * %o5: num outputs * %o1-%o4: inputs */ prom_call: stx %o0, [%l1 + 0x00] stx %g1, [%l1 + 0x08] stx %o5, [%l1 + 0x10] stx %o1, [%l1 + 0x18] stx %o2, [%l1 + 0x20] stx %o3, [%l1 + 0x28] stx %o4, [%l1 + 0x30] jmpl CIF_REG, %g0 mov %l1, %o0 after_info_block: sethi %hi(SCRATCH_PAD_DISKBOOT), %l1 /* OF argument slots */ GET_ABS(notification_string, %o2) call console_write mov NOTIFICATION_STRING_LEN, %o3 GET_ABS(firstlist - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE, %l2) set GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS, %l3 bootloop: lduw [%l2 + 0x08], %o0 brz %o0, bootit lduw [%l2 + 0x00], %o3 sllx %o3, 32, %o3 lduw [%l2 + 0x04], %o4 or %o3, %o4, %o3 GET_ABS(prom_seek_name, %o0) mov BOOTDEV_REG, %o1 clr %o2 call prom_call_3_1 sllx %o3, 9, %o3 GET_ABS(prom_read_name, %o0) mov BOOTDEV_REG, %o1 lduw [%l2 + 0x08], %o3 sllx %o3, 9, %o3 mov %l3, %o2 call prom_call_3_1 add %l3, %o3, %l3 GET_ABS(notification_step, %o2) call console_write mov NOTIFICATION_STEP_LEN, %o3 ba bootloop sub %l2, GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE, %l2 bootit: GET_ABS(prom_close_name, %o0) mov 1, %g1 mov 0, %o5 call prom_call mov BOOTDEV_REG, %o1 GET_ABS(notification_done, %o2) call console_write mov NOTIFICATION_DONE_LEN, %o3 sethi %hi(GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS), %o2 jmpl %o2 + %lo(GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS), %o7 mov CIF_REG, %o4 1: ba,a 1b lastlist: .word 0 .word 0 .org (0x200 - GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE) blocklist_default_start: .word 0 .word 2 blocklist_default_len: .word 0 firstlist:
a1ive/grub
6,956
grub-core/boot/sparc64/ieee1275/boot.S
/* -*-Asm-*- */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/machine/boot.h> .text .align 4 /* * We're writing the a.out header ourselves as newer * upstream versions of binutils no longer support * the a.out format on sparc64. * * The boot loader fits into 512 bytes with 32 bytes * used for the a.out header, hence the text segment * size is 512 - 32. There is no data segment and no * code relocation, thus those fields remain zero. */ .word 0x1030107 /* Magic number. */ .word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* Size of text segment. */ .word 0 /* Size of initialized data. */ .word 0 /* Size of uninitialized data. */ .word 0 /* Size of symbol table || checksum. */ .word _start /* Entry point. */ .word 0 /* Size of text relocation. */ .word 0 /* Size of data relocation. */ .globl _start _start: /* OF CIF entry point arrives in %o4 */ pic_base: call boot_continue mov %o4, CIF_REG #ifndef CDBOOT /* The offsets to these locations are defined by the * GRUB_BOOT_MACHINE_foo macros in include/grub/sparc64/ieee1275/boot.h, * and grub-setup uses this to patch these next three values as needed. * * The boot_path will be the OF device path of the partition where the * rest of the GRUB kernel image resides. kernel_sector will be set to * the location of the first block of the GRUB kernel, and * kernel_address is the location where we should load that first block. * * After loading in that block we will execute it by jumping to the * load address plus the size of the prepended A.OUT header (32 bytes). * * Since this assembly code includes the 32 bytes long a.out header, * we need to move the actual code entry point forward by the size * of the a.out header, i.e. += GRUB_BOOT_AOUT_HEADER_SIZE. */ .org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE boot_path: .org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE boot_path_end: kernel_byte: .xword (2 << 9) kernel_address: .word GRUB_BOOT_MACHINE_KERNEL_ADDR #else #define boot_path (_start + 512 + SCRATCH_PAD_BOOT_SIZE) #define boot_path_end (_start + 1024) #include <grub/offsets.h> .org 8 + GRUB_BOOT_AOUT_HEADER_SIZE kernel_byte: .xword (2 << 9) kernel_size: .word 512 kernel_address: .word GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS #endif prom_finddev_name: .asciz "finddevice" prom_chosen_path: .asciz "/chosen" prom_getprop_name: .asciz "getprop" prom_stdout_name: .asciz "stdout" prom_write_name: .asciz "write" prom_bootpath_name: .asciz "bootpath" prom_open_name: .asciz "open" prom_seek_name: .asciz "seek" prom_read_name: .asciz "read" prom_exit_name: .asciz "exit" grub_name: .asciz "GRUB " #ifdef CDBOOT prom_close_name: .asciz "close" #endif #define GRUB_NAME_LEN 5 .align 4 prom_open_error: GET_ABS(prom_open_name, %o2) call console_write mov 4, %o3 /* fallthru */ prom_error: GET_ABS(prom_exit_name, %o0) /* fallthru */ /* %o0: OF call name * %o1: input arg 1 */ prom_call_1_1_o2: clr %o2 ba prom_call_x_1 mov 1, %g1 prom_call_getprop: mov 4, %g1 stx %g1, [%l1 + 256] mov CHOSEN_NODE_REG, %o1 ba prom_call_x_1 GET_ABS(prom_getprop_name, %o0) prom_call_3_1_o1: ba prom_call_3_1 mov BOOTDEV_REG, %o1 /* %o2: message string * %o3: message length */ console_write: GET_ABS(prom_write_name, %o0) mov STDOUT_NODE_REG, %o1 /* fallthru */ /* %o0: OF call name * %o1: input arg 1 * %o2: input arg 2 * %o3: input arg 3 */ prom_call_3_1: mov 3, %g1 prom_call_x_1: mov 1, %o5 /* fallthru */ /* %o0: OF call name * %g1: num inputs * %o5: num outputs * %o1-%o4: inputs */ prom_call: stx %o0, [%l1 + 0x00] stx %g1, [%l1 + 0x08] stx %o5, [%l1 + 0x10] stx %o1, [%l1 + 0x18] stx %o2, [%l1 + 0x20] stx %o3, [%l1 + 0x28] stx %o4, [%l1 + 0x30] jmpl CIF_REG, %g0 mov %l1, %o0 boot_continue: mov %o7, PIC_REG /* PIC base */ #ifndef CDBOOT sethi %hi(SCRATCH_PAD_BOOT), %l1 /* OF argument slots */ #else GET_ABS(_start + 512, %l1) /* OF argument slots */ #endif /* Find the /chosen node so we can fetch the stdout handle, * and thus perform console output. * * chosen_node = prom_finddevice("/chosen") */ GET_ABS(prom_finddev_name, %o0) call prom_call_1_1_o2 GET_ABS(prom_chosen_path, %o1) ldx [%l1 + 0x20], CHOSEN_NODE_REG brz CHOSEN_NODE_REG, prom_error /* getprop(chosen_node, "stdout", &buffer, buffer_size) */ GET_ABS(prom_stdout_name, %o2) add %l1, 256, %o3 call prom_call_getprop mov 1024, %o4 lduw [%l1 + 256], STDOUT_NODE_REG brz,pn STDOUT_NODE_REG, prom_error /* write(stdout_node, "GRUB ", strlen("GRUB ")) */ GET_ABS(grub_name, %o2) call console_write mov GRUB_NAME_LEN, %o3 GET_ABS(boot_path, %o3) #ifndef CDBOOT ldub [%o3], %o1 brnz,pn %o1, bootpath_known #endif /* getprop(chosen_node, "bootpath", &buffer, buffer_size) */ GET_ABS(prom_bootpath_name, %o2) call prom_call_getprop mov (boot_path_end - boot_path), %o4 bootpath_known: /* Open up the boot_path, and use that handle to read the * first block of the GRUB kernel image. * * bootdev_handle = open(boot_path) */ GET_ABS(prom_open_name, %o0) call prom_call_1_1_o2 GET_ABS(boot_path, %o1) ldx [%l1 + 0x20], BOOTDEV_REG brz,pn BOOTDEV_REG, prom_open_error /* Since we have 64-bit cells, the high cell of the seek offset * is zero and the low cell is the entire value. * * seek(bootdev, 0, *kernel_byte) */ GET_ABS(prom_seek_name, %o0) clr %o2 call prom_call_3_1_o1 LDX_ABS(kernel_byte, 0x00, %o3) /* read(bootdev, *kernel_address, 512) */ GET_ABS(prom_read_name, %o0) LDUW_ABS(kernel_address, 0x00, %o2) call prom_call_3_1_o1 #ifdef CDBOOT LDUW_ABS(kernel_size, 0x00, %o3) GET_ABS(prom_close_name, %o0) mov 1, %g1 mov 0, %o5 call prom_call mov BOOTDEV_REG, %o1 #else mov 512, %o3 #endif LDUW_ABS(kernel_address, 0x00, %o2) jmpl %o2, %o7 #ifdef CDBOOT mov CIF_REG, %o4 #else nop #endif .org GRUB_BOOT_MACHINE_CODE_END /* the last 4 bytes in the sector 0 contain the signature */ .word GRUB_BOOT_MACHINE_SIGNATURE
a1ive/grub
23,509
grub-core/boot/mips/loongson/fwstart.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/mips/loongson/serial.h> #include <grub/mips/loongson/pci.h> #include <grub/mips/loongson.h> #include <grub/pci.h> #include <grub/machine/serial.h> #include <grub/machine/kernel.h> #include <grub/ns8250.h> #include <grub/cs5536.h> #include <grub/smbus.h> #ifndef FULOONG2F #include <grub/vgaregs.h> #define GRUB_SM712_REG_BASE 0x700000 #define GRUB_SM712_PCIID 0x0712126f #endif #ifdef FULOONG2F #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT2 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 #else #define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT0 #define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 #endif .set noreorder .set noat .set nomacro .set mips3 .global start,_start,__start start: _start: __start: /* Put serial init as soon as possible. But on Fuloong2f serial is past Geode, so on Fuloong2f we need Geode first. */ #ifndef FULOONG2F bal serial_hw_init nop #endif /* Find CS5536 controller. */ /* $t4 chooses device in priority encoding. */ /* Resulting value is kept in GRUB_MACHINE_PCI_CONF_CTRL_REG. This way we don't need to sacrifice a register for it. */ retry_cs5536: /* We have only one bus (0). Function is 0. */ lui $t0, %hi(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR_2F) lui $t1, %hi(GRUB_MACHINE_PCI_CONFSPACE_2F) lui $t3, %hi(GRUB_CS5536_PCIID) addiu $t3, $t3, %lo(GRUB_CS5536_PCIID) ori $t4, $zero, 1 1: andi $t4, $t4, ((1 << GRUB_PCI_NUM_DEVICES_2F) - 1) /* In case of failure try again. CS5536 may be slow to come up. */ beql $t4, $zero, retry_cs5536 nop sw $t4, %lo(GRUB_MACHINE_PCI_CONF_CTRL_REG_ADDR_2F) ($t0) lw $t2, (%lo(GRUB_MACHINE_PCI_CONFSPACE_2F) + GRUB_PCI_REG_PCI_ID) ($t1) bnel $t2, $t3, 1b sll $t4, $t4, 1 #ifndef FULOONG2F lui $a0, %hi(cs5536_found) bal message addiu $a0, $a0, %lo(cs5536_found) bal printhex move $a0, $t4 #endif lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE_2F) li $t1, GRUB_CS5536_MSR_MAILBOX_CONFIG_ENABLED sw $t1, (%lo(GRUB_MACHINE_PCI_CONFSPACE_2F) + GRUB_CS5536_MSR_MAILBOX_CONFIG) ($t0) /* Set GPIO LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_GPIO_BAR) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_GPIO_BAR) ori $a1, $zero, GRUB_CS5536_LBAR_GPIO /* Set mask to 0xf and enabled bit to 1. */ bal wrmsr ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \ | GRUB_CS5536_LBAR_ENABLE) >> 32) bal gpio_init nop #ifdef FULOONG2F bal serial_hw_init nop #endif /* Initialise SMBus controller. */ /* Set SMBUS LBAR. */ lui $a0, %hi(GRUB_CS5536_MSR_SMB_BAR) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_SMB_BAR) ori $a1, $zero, GRUB_CS5536_LBAR_SMBUS /* Set mask to 0xf and enabled bit to 1. */ bal wrmsr ori $a2, $zero, ((GRUB_CS5536_LBAR_MASK_MASK \ | GRUB_CS5536_LBAR_ENABLE) >> 32) lui $a0, %hi(smbus_enabled) bal message addiu $a0, $a0, %lo(smbus_enabled) lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS) /* Disable SMB. */ sb $zero, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL2) ($t0) /* Disable interrupts. */ sb $zero, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1) ($t0) /* Set as master. */ sb $zero, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_ADDR) ($t0) /* Launch SMBus controller at slowest speed possible. */ ori $t1, $zero, 0xff sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL3) ($t0) sb $t1, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL2) ($t0) /* Yeeloong and Fuloong2f have only one memory slot. */ /* Output first byte on serial for debugging. */ ori $a1, $zero, GRUB_SMB_RAM_START_ADDR bal read_spd move $a0, $zero bal printhex move $a0, $v0 bal read_spd ori $a0, $zero, GRUB_SMBUS_SPD_MEMORY_TYPE_ADDR ori $t0, $zero, GRUB_SMBUS_SPD_MEMORY_TYPE_DDR2 lui $a0, %hi(unimplemented_memory_type) bne $t0, $v0, fatal addiu $a0, $a0, %lo(unimplemented_memory_type) /* And here is our goal: DDR2 controller initialisation. */ lui $t0, %hi(GRUB_CPU_LOONGSON_CORECFG) ld $t1, %lo(GRUB_CPU_LOONGSON_CORECFG) ($t0) /* Use addiu for sign-extension. */ addiu $t2, $zero, ~(GRUB_CPU_LOONGSON_CORECFG_DISABLE_DDR2_SPACE|GRUB_CPU_LOONGSON_CORECFG_BUFFER_CPU) and $t1, $t1, $t2 sd $t1, %lo (GRUB_CPU_LOONGSON_CORECFG) ($t0) b continue .org GRUB_CPU_LOONGSON_FLASH_TLB_REFILL - GRUB_CPU_LOONGSON_FLASH_START tlb_refill: mfc0 $s1, GRUB_CPU_LOONGSON_COP0_EPC mfc0 $s2, GRUB_CPU_LOONGSON_COP0_BADVADDR move $s3, $ra lui $a0, %hi(epc) bal message addiu $a0, $a0, %lo(epc) bal printhex move $a0, $s1 lui $a0, %hi(badvaddr) bal message addiu $a0, $a0, %lo(badvaddr) bal printhex move $a0, $s2 lui $a0, %hi(return_msg) bal message addiu $a0, $a0, %lo(return_msg) bal printhex move $a0, $s3 lui $a0, %hi(newline) bal message addiu $a0, $a0, %lo(newline) lui $a0, %hi(unhandled_tlb_refill) b fatal addiu $a0, $a0, %lo(unhandled_tlb_refill) .org GRUB_CPU_LOONGSON_FLASH_CACHE_ERROR - GRUB_CPU_LOONGSON_FLASH_START cache_error: lui $a0, %hi(unhandled_cache_error) b fatal addiu $a0, $a0, %lo(unhandled_cache_error) .org GRUB_CPU_LOONGSON_FLASH_OTHER_EXCEPTION - GRUB_CPU_LOONGSON_FLASH_START other_exception: mfc0 $s0, GRUB_CPU_LOONGSON_COP0_CAUSE mfc0 $s1, GRUB_CPU_LOONGSON_COP0_EPC mfc0 $s2, GRUB_CPU_LOONGSON_COP0_BADVADDR lui $a0, %hi(cause) bal message addiu $a0, $a0, %lo(cause) bal printhex move $a0, $s0 lui $a0, %hi(epc) bal message addiu $a0, $a0, %lo(epc) bal printhex move $a0, $s1 lui $a0, %hi(badvaddr) bal message addiu $a0, $a0, %lo(badvaddr) bal printhex move $a0, $s2 lui $a0, %hi(newline) bal message addiu $a0, $a0, %lo(newline) lui $a0, %hi(unhandled_exception) b fatal addiu $a0, $a0, %lo(unhandled_exception) gpio_init: lui $t0, %hi(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_GPIO) addiu $t0, $t0, %lo(GRUB_MACHINE_PCI_IO_BASE_2F + GRUB_CS5536_LBAR_GPIO) lui $t1, %hi (gpio_dump) addiu $t1, $t1, %lo (gpio_dump) 1: lw $t2, 0($t1) sw $t2, 0($t0) addiu $t0, $t0, 4 addiu $t1, $t1, 4 lui $t2, %hi (gpio_dump_end) addiu $t2, $t2, %lo (gpio_dump_end) bne $t1, $t2, 1b nop jr $ra nop /* Same as similarly named C function but in asm since we need it early. */ /* In: none. Out: none. Clobbered: $t0, $t1, $t2, $a0, $a1, $a2. */ serial_hw_init: move $t2, $ra #ifdef FULOONG2F lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_LEG_IO) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_LEG_IO) lui $a1, %hi (GRUB_CS5536_MSR_DIVIL_LEG_IO_UART2_COM3 \ | GRUB_CS5536_MSR_DIVIL_LEG_IO_F_REMAP \ | GRUB_CS5536_MSR_DIVIL_LEG_IO_MODE_X86 \ | GRUB_CS5536_MSR_DIVIL_LEG_IO_UART1_COM1) ori $a1, $a1, (GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE0 \ | GRUB_CS5536_MSR_DIVIL_LEG_IO_RTC_ENABLE1) bal wrmsr move $a2, $zero lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART1_CONF) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART1_CONF) li $a1, 2 bal wrmsr move $a2, $zero lui $a0, %hi(GRUB_CS5536_MSR_DIVIL_UART2_CONF) addiu $a0, $a0, %lo(GRUB_CS5536_MSR_DIVIL_UART2_CONF) li $a1, 2 bal wrmsr move $a2, $zero #endif lui $t0, %hi (GRUB_MACHINE_SERIAL_PORT) /* Turn off the interrupt. */ sb $zero, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_IER)($t0) /* Set DLAB. */ ori $t1, $zero, UART_DLAB sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_LCR)($t0) /* Set the baud rate 115200. */ ori $t1, $zero, GRUB_MACHINE_SERIAL_DIVISOR_115200 sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_DLL)($t0) sb $zero, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_DLH)($t0) /* Set the line status. */ ori $t1, $zero, (UART_NO_PARITY | UART_8BITS_WORD | UART_1_STOP_BIT) sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_LCR)($t0) /* Enable the FIFO. */ ori $t1, $zero, UART_ENABLE_FIFO_TRIGGER1 sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_FCR)($t0) /* Turn on DTR and RTS. */ ori $t1, $zero, UART_ENABLE_DTRRTS sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_MCR)($t0) /* Let message return to original caller. */ lui $a0, %hi(notification_string) addiu $a0, $a0, %lo(notification_string) move $ra, $t2 /* Print message on serial console. */ /* In: $a0 = asciiz message. Out: none. Clobbered: $t0, $t1, $a0. */ message: lui $t0, %hi (GRUB_MACHINE_SERIAL_PORT) 1: lb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_LSR)($t0) andi $t1, $t1, UART_EMPTY_TRANSMITTER beq $t1, $zero, 1b nop lb $t1, 0($a0) sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_TX)($t0) bne $t1, $zero, 1b addiu $a0, $a0, 1 jr $ra nop /* Print 32-bit hexadecimal on serial. In: $a0. Out: None. Clobbered: $a0, $t0, $t1, $t2 */ printhex: lui $t0, %hi (GRUB_MACHINE_SERIAL_PORT) ori $t2, $zero, 8 1: lb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_LSR)($t0) andi $t1, $t1, UART_EMPTY_TRANSMITTER beq $t1, $zero, 1b nop srl $t1, $a0, 28 addiu $t1, $t1, -10 bltz $t1, 2f sll $a0, $a0, 4 addiu $t1, $t1, 'A'-10-'0' 2: addiu $t1, $t1, '0'+10 sb $t1, (%lo (GRUB_MACHINE_SERIAL_PORT) + UART_TX)($t0) addiu $t2, $t2, -1 bne $t2, $zero, 1b nop jr $ra nop fatal: bal message nop self: b self nop /* Write CS5536 MSR. In: $a0 address, $a1 lower word, $a2 upper word. Out: None Clobbered: $t0 */ wrmsr: lui $t0, %hi(GRUB_MACHINE_PCI_CONFSPACE_2F) sw $a0, (%lo(GRUB_MACHINE_PCI_CONFSPACE_2F) + GRUB_CS5536_MSR_MAILBOX_ADDR) ($t0) sw $a1, (%lo(GRUB_MACHINE_PCI_CONFSPACE_2F) + GRUB_CS5536_MSR_MAILBOX_DATA0) ($t0) jr $ra sw $a2, (%lo(GRUB_MACHINE_PCI_CONFSPACE_2F) + GRUB_CS5536_MSR_MAILBOX_DATA1) ($t0) /* Wait for SMBus data or empty transmitter. */ /* In: $a0 = exception handler. Out: none. Clobbered: $t0, $t1 */ smbus_wait: 1: lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_STATUS + GRUB_MACHINE_PCI_IO_BASE_2F) lb $t0, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_STATUS + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) andi $t1, $t0, GRUB_CS5536_SMB_REG_STATUS_SDAST bne $t1, $zero, return nop andi $t1, $t0, (GRUB_CS5536_SMB_REG_STATUS_BER | GRUB_CS5536_SMB_REG_STATUS_NACK) beq $t1, $zero, 1b nop jr $a0 nop return: jr $ra nop /* Read SPD byte. In: $a0 byte, $a1 device. Out: $v0 read byte (0x100 on failure). Clobbered: $t0, $t1, $t2, $t3, $a0. */ read_spd: move $t2, $a0 move $t3, $ra lui $a0, %hi(read_spd_fail) addiu $a0, $a0, %lo(read_spd_fail) /* Send START. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) lb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) ori $t1, $t1, GRUB_CS5536_SMB_REG_CTRL1_START bal smbus_wait sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send device address. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) sll $t1, $a1, 1 bal smbus_wait sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send ACK. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) lb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) ori $t1, $t1, GRUB_CS5536_SMB_REG_CTRL1_ACK sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send byte address. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) bal smbus_wait sb $t2, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send START. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) lb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) ori $t1, $t1, GRUB_CS5536_SMB_REG_CTRL1_START bal smbus_wait sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send device address. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) sll $t1, $a1, 1 ori $t1, $t1, 1 bal smbus_wait sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) /* Send STOP. */ lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) lb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) ori $t1, $t1, GRUB_CS5536_SMB_REG_CTRL1_STOP bal smbus_wait sb $t1, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_CTRL1 + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) lui $t0, %hi(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) lb $v0, %lo(GRUB_CS5536_LBAR_SMBUS + GRUB_CS5536_SMB_REG_DATA + GRUB_MACHINE_PCI_IO_BASE_2F) ($t0) jr $t3 andi $v0, $v0, 0xff read_spd_fail: jr $t3 ori $v0, $v0, 0x100 notification_string: .asciz "GRUB " cs5536_found: .asciz "CS5536 at " sm_failed: .asciz "SM transaction failed.\n\r" unhandled_tlb_refill: .asciz "Unhandled TLB refill.\n\r" unhandled_cache_error: .asciz "Unhandled cache error.\n\r" unhandled_exception: .asciz "Unhandled exception.\n\r" smbus_enabled: .asciz "SMBus controller enabled.\n\r" unimplemented_memory_type: .asciz "non-DDR2 memory isn't supported.\n\r" no_cas_latency: .asciz "Couldn't determine CAS latency.\n\r" cause: .asciz "Cause: " epc: .asciz "\n\rEPC: " badvaddr: .asciz "\n\rBadVaddr: " newline: .asciz "\n\r" return_msg: .asciz "\n\rReturn address: " caches_enabled: .asciz "Caches enabled\n\r" .p2align 3 regdump: .quad 0x0100010000000101 /* 0 */ .quad 0x0100010100000000 /* 2 */ .quad 0x0101000001000000 /* 3 */ .quad 0x0100020200010101 /* 4 */ .quad 0x0a04030603050203 /* 6 */ .quad 0x0f0e040000010a0b /* 7 */ #ifdef FULOONG2F .quad 0x0000000100000001 /* 8 */ #else .quad 0x0000010200000102 /* 8 */ #endif .quad 0x0000060c00000000 /* 9 */ .quad 0x2323233f3f1f0200 /* a */ .quad 0x5f7f232323232323 /* b */ .quad 0x002a3c0615000000 /* c */ .quad 0x002a002a002a002a /* d */ .quad 0x002a002a002a002a /* e */ #ifdef FULOONG2F .quad 0x00b40020005b0004 /* f */ #else .quad 0x00b40020006d0004 /* f */ #endif .quad 0x070007ff00000087 /* 10 */ .quad 0x000000000016101f /* 11 */ .quad 0x001c000000000000 /* 12 */ .quad 0x28e1000200c8006b /* 13 */ .quad 0x0000204200c8002f /* 14 */ .quad 0x0000000000030d40 /* 15 */ .quad 0 /* 16 */ .quad 0 /* 17 */ .quad 0 /* 18 */ .quad 0 /* 19 */ .quad 0 /* 1a */ .quad 0 /* 1b */ .quad 0 /* 1c */ /* Dump of GPIO connections. FIXME: Remove useless and macroify. */ gpio_dump: #ifdef FULOONG2F .long 0xffff0000, 0x2eefd110, 0xffff0000, 0xffff0000 .long 0x2eefd110, 0xffff0000, 0x1000efff, 0xefff1000 .long 0x3df3c20c, 0xffff0000, 0xffff0000, 0xffff0000 .long 0x7df3820c, 0x3df3c20c, 0xffff0000, 0x00000000 .long 0xffff0000, 0xffff0000, 0x3de3c21c, 0x3d83c27c .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000 .long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000 .long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000 .long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000 .long 0xffff0000, 0xffff0000, 0xefff1000, 0xefff1000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 #else .long 0xffff0000, 0x2ffdd002, 0xffff0000, 0xffff0000 .long 0x2fffd000, 0xffff0000, 0x1000efff, 0xefff1000 .long 0x3ffbc004, 0xffff0000, 0xffff0000, 0xffff0000 .long 0x3ffbc004, 0x3ffbc004, 0xffff0000, 0x00000000 .long 0xffff0000, 0xffff0000, 0x3ffbc004, 0x3f9bc064 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000 .long 0xffff0000, 0xffff0000, 0x0000ffff, 0xffff0000 .long 0xefff1000, 0xffff0000, 0xffff0000, 0xffff0000 .long 0xefff1000, 0xefff1000, 0xffff0000, 0x00000000 .long 0xffff0000, 0xffff0000, 0xefff1000, 0xffff0000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x00000000, 0x00000000, 0x00000000 .long 0x00000000, 0x50000000, 0x00000000, 0x00000000 #endif gpio_dump_end: .p2align 3 write_dumpreg: ld $t2, 0($t6) sd $t2, 0($t4) addiu $t4, $t4, GRUB_CPU_LOONGSON_DDR2_REG_STEP jr $ra addiu $t6, $t6, GRUB_CPU_LOONGSON_DDR2_REG_SIZE continue: lui $t4, %hi(GRUB_CPU_LOONGSON_DDR2_BASE) addiu $t4, $t4, %lo(GRUB_CPU_LOONGSON_DDR2_BASE) lui $t6, %hi(regdump) /* 0 */ bal write_dumpreg addiu $t6, $t6, %lo(regdump) /* 1 */ ori $a1, $a1, GRUB_SMB_RAM_START_ADDR move $t8, $zero lui $t5, 0x0001 bal read_spd ori $a0, $zero, GRUB_SMBUS_SPD_MEMORY_NUM_BANKS_ADDR ori $t7, $zero, 8 bne $v0, $t7, 1f ori $t5, $t5, 0x0001 ori $t8, $t8, GRUB_CPU_LOONGSON_DDR2_REG1_HI_8BANKS 1: dsll $t8, $t8, 32 or $t5, $t5, $t8 sd $t5, 0 ($t4) addiu $t4, $t4, GRUB_CPU_LOONGSON_DDR2_REG_STEP /* 2 */ bal write_dumpreg nop /* 3 */ bal write_dumpreg nop /* 4 */ bal write_dumpreg nop /* 5 */ /* FIXME: figure termination resistance. */ ori $t5, $zero, 0x2 bal read_spd ori $a0, $zero, GRUB_SMBUS_SPD_MEMORY_NUM_ROWS_ADDR /* $v0 = 15 - $v0. */ xori $v0, $v0, 0xf andi $v0, $v0, 0x7 sll $v0, $v0, 8 or $t5, $t5, $v0 /* Find the fastest supported CAS latency. */ bal read_spd ori $a0, $zero, GRUB_SMBUS_SPD_MEMORY_CAS_LATENCY_ADDR ori $t0, $zero, GRUB_SMBUS_SPD_MEMORY_CAS_LATENCY_MIN_VALUE ori $t1, $zero, (1 << GRUB_SMBUS_SPD_MEMORY_CAS_LATENCY_MIN_VALUE) 2: and $t2, $t1, $v0 bne $t2, $zero, 1f ori $t3, $zero, 8 lui $a0, %hi(no_cas_latency) beq $t0, $t3, fatal addiu $a0, $a0, %lo(no_cas_latency) addiu $t0, $t0, 1 b 2b sll $t1, $t1, 1 1: sll $t0, $t0, 16 or $t5, $t5, $t0 bal read_spd ori $a0, $zero, GRUB_SMBUS_SPD_MEMORY_NUM_COLUMNS_ADDR /* $v0 = 15 - ($v0 + 1) = 14 - $v0. */ addiu $v0, $v0, 1 xori $v0, $v0, 0xf andi $v0, $v0, 0x7 sll $v0, 24 or $t5, $t5, $v0 sd $t5, 0 ($t4) addiu $t4, $t4, GRUB_CPU_LOONGSON_DDR2_REG_STEP ori $t7, $zero, 0x16 1: ld $t2, 0($t6) sd $t2, 0($t4) addiu $t4, $t4, GRUB_CPU_LOONGSON_DDR2_REG_STEP addiu $t7, $t7, -1 bne $t7, $zero, 1b addiu $t6, $t6, GRUB_CPU_LOONGSON_DDR2_REG_SIZE lui $t4, %hi(GRUB_CPU_LOONGSON_DDR2_BASE) ld $t5, (%lo(GRUB_CPU_LOONGSON_DDR2_BASE) + 0x30) ($t4) ori $t0, $zero, 1 dsll $t0, $t0, 40 or $t5, $t5, $t0 sd $t5, (%lo(GRUB_CPU_LOONGSON_DDR2_BASE) + 0x30) ($t4) /* Desactivate DDR2 registers. */ lui $t0, %hi (GRUB_CPU_LOONGSON_CORECFG) ld $t1, %lo (GRUB_CPU_LOONGSON_CORECFG) ($t0) ori $t1, $t1, GRUB_CPU_LOONGSON_CORECFG_DISABLE_DDR2_SPACE sd $t1, %lo (GRUB_CPU_LOONGSON_CORECFG) ($t0) /* Enable cache. */ mfc0 $t0, GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG addiu $t1, $zero, ~GRUB_CPU_LOONGSON_CACHE_TYPE_MASK and $t0, $t1, $t1 /* Set line size to 32 bytes and disabled cache. */ ori $t0, $t0, (GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG_ILINESIZE \ | GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG_DLINESIZE \ | GRUB_CPU_LOONGSON_CACHE_ACCELERATED) mtc0 $t0, GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG /* Invalidate all I-cache entries. */ srl $t1, $t0, GRUB_CPU_LOONGSON_COP0_CACHE_ISIZE_SHIFT andi $t1, $t1, GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_MASK ori $t2, $zero, (1 << (GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_OFFSET \ - GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_LOG_BIG \ - GRUB_CPU_LOONGSON_I_CACHE_LOG_WAYS)) sll $t1, $t2, $t1 lui $t2, 0x8000 1: cache GRUB_CPU_LOONGSON_COP0_I_INDEX_INVALIDATE, 0($t2) addiu $t1, $t1, -1 bne $t1, $zero, 1b addiu $t2, $t2, (1 << GRUB_CPU_LOONGSON_COP0_I_INDEX_BIT_OFFSET) /* Invalidate all D-cache entries. */ srl $t1, $t0, GRUB_CPU_LOONGSON_COP0_CACHE_DSIZE_SHIFT andi $t1, $t1, GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_MASK ori $t2, $zero, (1 << (GRUB_CPU_LOONGSON_COP0_CACHE_SIZE_OFFSET \ - GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_LOG_BIG \ - GRUB_CPU_LOONGSON_D_CACHE_LOG_WAYS)) sll $t1, $t2, $t1 lui $t2, 0x8000 mtc0 $zero, GRUB_CPU_LOONGSON_COP0_CACHE_TAGLO mtc0 $zero, GRUB_CPU_LOONGSON_COP0_CACHE_TAGHI 1: /* All four ways. */ cache GRUB_CPU_LOONGSON_COP0_D_INDEX_TAG_STORE, 0($t2) cache GRUB_CPU_LOONGSON_COP0_D_INDEX_TAG_STORE, 1($t2) cache GRUB_CPU_LOONGSON_COP0_D_INDEX_TAG_STORE, 2($t2) cache GRUB_CPU_LOONGSON_COP0_D_INDEX_TAG_STORE, 3($t2) addiu $t1, $t1, -1 bne $t1, $zero, 1b addiu $t2, $t2, (1 << GRUB_CPU_LOONGSON_COP0_D_INDEX_BIT_OFFSET) /* Invalidate all S-cache entries. */ ori $t1, $zero, (1 << (GRUB_CPU_LOONGSON_SECONDARY_CACHE_LOG_SIZE \ - GRUB_CPU_LOONGSON_CACHE_LINE_SIZE_LOG_BIG \ - GRUB_CPU_LOONGSON_S_CACHE_LOG_WAYS)) lui $t2, 0x8000 mtc0 $zero, GRUB_CPU_LOONGSON_COP0_CACHE_TAGLO mtc0 $zero, GRUB_CPU_LOONGSON_COP0_CACHE_TAGHI 1: /* All four ways. */ cache GRUB_CPU_LOONGSON_COP0_S_INDEX_TAG_STORE, 0($t2) cache GRUB_CPU_LOONGSON_COP0_S_INDEX_TAG_STORE, 1($t2) cache GRUB_CPU_LOONGSON_COP0_S_INDEX_TAG_STORE, 2($t2) cache GRUB_CPU_LOONGSON_COP0_S_INDEX_TAG_STORE, 3($t2) addiu $t1, $t1, -1 bne $t1, $zero, 1b addiu $t2, $t2, (1 << GRUB_CPU_LOONGSON_COP0_D_INDEX_BIT_OFFSET) /* Finally enable cache. */ mfc0 $t0, GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG addiu $t1, $zero, ~GRUB_CPU_LOONGSON_CACHE_TYPE_MASK and $t0, $t1, $t1 ori $t0, $t0, GRUB_CPU_LOONGSON_CACHE_CACHED mtc0 $t0, GRUB_CPU_LOONGSON_COP0_CACHE_CONFIG lui $a0, %hi(caches_enabled) bal message addiu $a0, $a0, %lo(caches_enabled) /* Set ROM delay cycles to 1. */ lui $t0, %hi(GRUB_CPU_LOONGSON_LIOCFG) lw $t1, %lo(GRUB_CPU_LOONGSON_LIOCFG) ($t0) addiu $t2, $zero, ~(GRUB_CPU_LOONGSON_ROM_DELAY_MASK \ << GRUB_CPU_LOONGSON_ROM_DELAY_OFFSET) and $t1, $t1, $t2 ori $t1, $t1, (1 << GRUB_CPU_LOONGSON_ROM_DELAY_OFFSET) sw $t1, %lo(GRUB_CPU_LOONGSON_LIOCFG) ($t0) addiu $a0, $zero, -1 addiu $a1, $zero, -1 /* Take advantage of cache. */ lui $t0, %hi(cached_continue - 0x20000000) addiu $t0, $t0, %lo(cached_continue - 0x20000000) jr $t0 #ifdef FULOONG2F addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_FULOONG2F) #else addiu $a2, $zero, -(1 + GRUB_ARCH_MACHINE_YEELOONG) #endif cached_continue:
a1ive/grub
2,709
grub-core/kern/i386/int.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2010,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ FUNCTION(grub_bios_interrupt) pushf cli popf pushl %ebp pushl %ecx pushl %eax pushl %ebx pushl %esi pushl %edi pushl %edx movb %al, intno movl (%edx), %eax movl %eax, LOCAL(bios_register_eax) movw 4(%edx), %ax movw %ax, LOCAL(bios_register_es) movw 6(%edx), %ax movw %ax, LOCAL(bios_register_ds) movw 8(%edx), %ax movw %ax, LOCAL(bios_register_flags) movl 12(%edx), %ebx movl 16(%edx), %ecx movl 20(%edx), %edi movl 24(%edx), %esi movl 28(%edx), %edx /* Via C3 CPUs have cache coherence problems, so we need to call wbinvd at these 2 points. As wbinvd slows down boot, don't do it on non-VIA. 9090 is nop nop. */ VARIABLE(grub_bios_via_workaround1) .byte 0x90, 0x90 PROT_TO_REAL .code16 pushf cli mov %ds, %ax push %ax /* movw imm16, %ax*/ .byte 0xb8 LOCAL(bios_register_es): .short 0 movw %ax, %es /* movw imm16, %ax*/ .byte 0xb8 LOCAL(bios_register_ds): .short 0 movw %ax, %ds /* movw imm16, %ax*/ .byte 0xb8 LOCAL(bios_register_flags): .short 0 push %ax popf /* movl imm32, %eax*/ .byte 0x66, 0xb8 LOCAL(bios_register_eax): .long 0 /* int imm8. */ .byte 0xcd intno: .byte 0 movl %eax, %cs:LOCAL(bios_register_eax) movw %ds, %ax movw %ax, %cs:LOCAL(bios_register_ds) pop %ax mov %ax, %ds pushf pop %ax movw %ax, LOCAL(bios_register_flags) mov %es, %ax movw %ax, LOCAL(bios_register_es) popf VARIABLE(grub_bios_via_workaround2) .byte 0x90, 0x90 REAL_TO_PROT .code32 popl %eax movl %ebx, 12(%eax) movl %ecx, 16(%eax) movl %edi, 20(%eax) movl %esi, 24(%eax) movl %edx, 28(%eax) movl %eax, %edx movl LOCAL(bios_register_eax), %eax movl %eax, (%edx) movw LOCAL(bios_register_es), %ax movw %ax, 4(%edx) movw LOCAL(bios_register_ds), %ax movw %ax, 6(%edx) movw LOCAL(bios_register_flags), %ax movw %ax, 8(%edx) popl %edi popl %esi popl %ebx popl %eax popl %ecx popl %ebp ret
a1ive/grub
1,131
grub-core/kern/i386/reboot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2020 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ .p2align 4 FUNCTION(grub_bios_cold_reset) .code32 PROT_TO_REAL .code16 movw $0x0472, %di xorw %ax, %ax movw %ax, (%di) ljmp $0xf000, $0xfff0 .code32 .p2align 4 FUNCTION(grub_bios_warm_reset) .code32 PROT_TO_REAL .code16 movw $0x1234, %di xorw %ax, %ax movw %ax, (%di) ljmp $0xf000, $0xfff0 .code32
a1ive/grub
7,562
grub-core/kern/i386/realmode.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/machine/memory.h> /* * Note: These functions defined in this file may be called from C. * Be careful of that you must not modify some registers. Quote * from gcc-2.95.2/gcc/config/i386/i386.h: 1 for registers not available across function calls. These must include the FIXED_REGISTERS and also any registers that can be used without being saved. The latter must include the registers where values are returned and the register where structure-value addresses are passed. Aside from that, you can include as many other registers as you like. ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } */ /* * Note: GRUB is compiled with the options -mrtd and -mregparm=3. * So the first three arguments are passed in %eax, %edx, and %ecx, * respectively, and if a function has a fixed number of arguments * and the number if greater than three, the function must return * with "ret $N" where N is ((the number of arguments) - 3) * 4. */ /* * This is the area for all of the special variables. */ protstack: .long GRUB_MEMORY_MACHINE_PROT_STACK .macro PROT_TO_REAL call prot_to_real .endm .macro REAL_TO_PROT calll real_to_prot .endm /* * This is the Global Descriptor Table * * An entry, a "Segment Descriptor", looks like this: * * 31 24 19 16 7 0 * ------------------------------------------------------------ * | | |B| |A| | | |1|0|E|W|A| | * | BASE 31..24 |G|/|L|V| LIMIT |P|DPL| TYPE | BASE 23:16 | 4 * | | |D| |L| 19..16| | |1|1|C|R|A| | * ------------------------------------------------------------ * | | | * | BASE 15..0 | LIMIT 15..0 | 0 * | | | * ------------------------------------------------------------ * * Note the ordering of the data items is reversed from the above * description. */ .p2align 5 /* force 32-byte alignment */ gdt: .word 0, 0 .byte 0, 0, 0, 0 /* -- code segment -- * base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present * type = 32bit code execute/read, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x9A, 0xCF, 0 /* -- data segment -- * base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present * type = 32 bit data read/write, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x92, 0xCF, 0 /* -- 16 bit real mode CS -- * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present * type = 16 bit code execute/read only/conforming, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x9E, 0, 0 /* -- 16 bit real mode DS -- * base = 0x00000000, limit 0x0FFFF (1 B Granularity), present * type = 16 bit data read/write, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x92, 0, 0 .p2align 5 /* this is the GDT descriptor */ gdtdesc: .word 0x27 /* limit */ .long gdt /* addr */ LOCAL(realidt): .word 0x400 .long 0 protidt: .word 0 .long 0 /* * These next two routines, "real_to_prot" and "prot_to_real" are structured * in a very specific way. Be very careful when changing them. * * NOTE: Use of either one messes up %eax and %ebp. */ real_to_prot: .code16 cli /* load the GDT register */ xorw %ax, %ax movw %ax, %ds #ifdef GRUB_MACHINE_QEMU /* qemu is special: gdtdesc is in ROM. %cs = 0xf000 _start + GRUB_BOOT_MACHINE_SIZE = 0x100000 So _start + GRUB_BOOT_MACHINE_SIZE - 0x10000 points to the same point as %cs. gdtdesc - (_start + GRUB_BOOT_MACHINE_SIZE - 0x10000) = gdtdesc - _start - GRUB_BOOT_MACHINE_SIZE + 0x10000 but the later can be computed by assembly. */ lgdtl %cs:(gdtdesc - _start - GRUB_BOOT_MACHINE_SIZE + 0x10000) #else lgdtl gdtdesc #endif /* turn on protected mode */ movl %cr0, %eax orl $GRUB_MEMORY_CPU_CR0_PE_ON, %eax movl %eax, %cr0 /* jump to relocation, flush prefetch queue, and reload %cs */ ljmpl $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg .code32 protcseg: /* reload other segment registers */ movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax movw %ax, %ds movw %ax, %es movw %ax, %fs movw %ax, %gs movw %ax, %ss /* put the return address in a known safe location */ movl (%esp), %eax movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK /* get protected mode stack */ movl protstack, %eax movl %eax, %esp movl %eax, %ebp /* get return address onto the right stack */ movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax movl %eax, (%esp) /* zero %eax */ xorl %eax, %eax sidt LOCAL(realidt) lidt protidt /* return on the old (or initialized) stack! */ ret /* prot_to_real assumes that this code is under 64K which is not true for qemu. */ #ifndef GRUB_MACHINE_QEMU /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ prot_to_real: /* just in case, set GDT */ lgdt gdtdesc sidt protidt lidt LOCAL(realidt) /* save the protected mode stack */ movl %esp, %eax movl %eax, protstack /* get the return address */ movl (%esp), %eax movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK /* set up new stack */ movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax movl %eax, %esp movl %eax, %ebp /* set up segment limits */ movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax movw %ax, %ds movw %ax, %es movw %ax, %fs movw %ax, %gs movw %ax, %ss /* this might be an extra step */ /* jump to a 16 bit segment */ ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg tmpcseg: .code16 /* clear the PE bit of CR0 */ movl %cr0, %eax andl $(~GRUB_MEMORY_CPU_CR0_PE_ON), %eax movl %eax, %cr0 /* flush prefetch queue, reload %cs */ ljmpl $0, $realcseg realcseg: /* we are in real mode now * set up the real mode segment registers : DS, SS, ES */ /* zero %eax */ xorl %eax, %eax movw %ax, %ds movw %ax, %es movw %ax, %fs movw %ax, %gs movw %ax, %ss #ifdef GRUB_MACHINE_PCBIOS /* restore interrupts */ sti #endif /* return on new stack! */ retl #endif .code32
a1ive/grub
1,104
grub-core/kern/riscv/cache_flush.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2018 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache_flush.S" .text /* * Simple cache maintenance functions */ /* * a0 - *beg (inclusive) * a1 - *end (exclusive) * a2 - line size */ FUNCTION(grub_arch_clean_dcache_range) /* TODO */ ret /* * a0 - *beg (inclusive) * a1 - *end (exclusive) * a2 - line size */ FUNCTION(grub_arch_invalidate_icache_range) fence.i ret
a1ive/grub
1,171
grub-core/kern/sparc64/cache.S
/* cache.S - Flush the processor cache for a specific region. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache.S" .text /* * void grub_arch_sync_caches (void *address, grub_size_t len) */ FUNCTION(grub_arch_sync_caches) brz,pn %o1, 2f add %o0, %o1, %o1 add %o1, 7, %o1 andn %o1, 7, %o1 andn %o0, 7, %o0 sub %o1, %o0, %o1 1: subcc %o1, 8, %o1 bne,pt %icc, 1b flush %o0 + %o1 2: retl nop
a1ive/grub
2,690
grub-core/kern/arm/cache.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache.S" .text .syntax unified #if !defined (__thumb2__) || !defined (ARMV7) .arm #else .thumb #endif #if !defined (ARMV6) && !defined (ARMV7) # error Unsupported architecture version! #endif .align 2 /* * Simple cache maintenance functions */ @ r0 - *beg (inclusive) @ r1 - *end (exclusive) @void grub_arm_clean_dcache_range (grub_addr_t start, grub_addr_t end, grub_addr_t dlinesz) #ifdef ARMV6 FUNCTION(grub_arm_clean_dcache_range_armv6) #else FUNCTION(grub_arm_clean_dcache_range_armv7) #endif DSB @ Clean data cache for range to point-of-unification 1: cmp r0, r1 bge 2f #ifdef ARMV6 mcr p15, 0, r0, c7, c10, 1 @ Clean data cache line by MVA #else mcr p15, 0, r0, c7, c11, 1 @ DCCMVAU #endif add r0, r0, r2 @ Next line b 1b 2: DSB bx lr @ r0 - *beg (inclusive) @ r1 - *end (exclusive) #ifdef ARMV6 FUNCTION(grub_arm_invalidate_icache_range_armv6) #else FUNCTION(grub_arm_invalidate_icache_range_armv7) #endif @ Invalidate instruction cache for range to point-of-unification 1: cmp r0, r1 bge 2f mcr p15, 0, r0, c7, c5, 1 @ ICIMVAU add r0, r0, r2 @ Next line b 1b @ Branch predictor invalidate all 2: mcr p15, 0, r0, c7, c5, 6 @ BPIALL DSB ISB bx lr #ifdef ARMV6 FUNCTION(grub_arm_disable_caches_mmu_armv6) #else FUNCTION(grub_arm_disable_caches_mmu_armv7) #endif push {r4, lr} @ disable D-cache mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #(1 << 2) mcr p15, 0, r0, c1, c0, 0 DSB ISB @ clean/invalidate D-cache bl clean_invalidate_dcache @ disable I-cache mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #(1 << 12) mcr p15, 0, r0, c1, c0, 0 DSB ISB @ invalidate I-cache (also invalidates branch predictors) mcr p15, 0, r0, c7, c5, 0 DSB ISB @ clear SCTLR M bit mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #(1 << 0) mcr p15, 0, r0, c1, c0, 0 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLB mcr p15, 0, r0, c7, c5, 6 @ invalidate branch predictor DSB ISB pop {r4, lr} bx lr
a1ive/grub
1,688
grub-core/kern/arm/cache_armv6.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache_armv6.S" .text .syntax unified .arm # define DMB mcr p15, 0, r0, c7, c10, 5 # define DSB mcr p15, 0, r0, c7, c10, 4 # define ISB mcr p15, 0, r0, c7, c5, 4 #define ARMV6 1 clean_invalidate_dcache: mcr p15, 0, r0, c7, c14, 0 @ Clean/Invalidate D-cache bx lr #include "cache.S" FUNCTION(grub_arm_main_id) mrc p15, 0, r0, c0, c0, 0 bx lr FUNCTION(grub_arm_cache_type) mrc p15, 0, r0, c0, c0, 1 bx lr FUNCTION(grub_arm_clear_mmu_v6) mov r0, #0 mcr p15, 0, r0, c2, c0, 2 bx lr FUNCTION(grub_arm_enable_mmu) mcr p15, 0, r0, c2, c0, 0 mvn r0, #0 mcr p15, 0, r0, c3, c0, 0 mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #(1 << 23) mcr p15, 0, r0, c1, c0, 0 mrc p15, 0, r0, c1, c0, 0 orr r0, r0, #(1 << 0) mcr p15, 0, r0, c1, c0, 0 mrc p15, 0, r0, c1, c0, 0 orr r0, r0, #(1 << 2) mcr p15, 0, r0, c1, c0, 0 mrc p15, 0, r0, c1, c0, 0 orr r0, r0, #(1 << 12) mcr p15, 0, r0, c1, c0, 0 bx lr
a1ive/grub
2,282
grub-core/kern/arm/compiler-rt.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/dl.h> .file "misc.S" .text .syntax unified #if !defined (__thumb2__) .arm #else .thumb #endif .align 2 FUNCTION(__muldi3) FUNCTION(__aeabi_lmul) stmfd sp!, {r4, fp} add fp, sp, #4 sub sp, sp, #16 str r0, [fp, #-12] str r1, [fp, #-8] str r2, [fp, #-20] str r3, [fp, #-16] ldr r3, [fp, #-8] ldr r2, [fp, #-20] mul r2, r3, r2 ldr r3, [fp, #-16] ldr r1, [fp, #-12] mul r3, r1, r3 add r2, r2, r3 ldr r0, [fp, #-12] ldr r1, [fp, #-20] umull r3, r4, r0, r1 add r2, r2, r4 mov r4, r2 mov r0, r3 mov r1, r4 mov sp, fp sub sp, sp, #4 ldmfd sp!, {r4, fp} bx lr .macro division32 parent sub sp, sp, #8 @ Allocate naturally aligned 64-bit space stmfd sp!, {r3,lr} @ Dummy r3 to maintain stack alignment add r2, sp, #8 @ Set r2 to address of 64-bit space bl \parent ldr r1, [sp, #8] @ Extract remainder ldmfd sp!, {r3,lr} @ Pop into an unused arg/scratch register add sp, sp, #8 bx lr .endm FUNCTION(__aeabi_uidivmod) division32 grub_divmod32 FUNCTION(__aeabi_idivmod) division32 grub_divmod32s /* * Null divide-by-zero handler */ FUNCTION(__aeabi_unwind_cpp_pr0) FUNCTION(raise) mov r0, #0 bx lr END
a1ive/grub
3,064
grub-core/kern/arm/cache_armv7.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache_armv7.S" .text .syntax unified #if !defined (__thumb2__) .arch armv7a .arm #else .arch armv7 .thumb #endif # define DMB dmb # define DSB dsb # define ISB isb #define ARMV7 1 FUNCTION(grub_arm_clean_dcache_range_poc_armv7) DSB @ Clean data cache for range to point-of-coherence 1: cmp r0, r1 bge 2f mcr p15, 0, r0, c7, c14, 1 @ DCCMVAC add r0, r0, r2 @ Next line b 1b 2: DSB bx lr @ r0 - CLIDR @ r1 - LoC @ r2 - current level @ r3 - num sets @ r4 - num ways @ r5 - current set @ r6 - current way @ r7 - line size @ r8 - scratch @ r9 - scratch @ r10 - scratch @ r11 - scratch clean_invalidate_dcache: push {r4-r12, lr} mrc p15, 1, r0, c0, c0, 1 @ Read CLIDR lsr r1, r0, #24 @ Extract LoC and r1, r1, #0x7 mov r2, #0 @ First level, L1 2: and r8, r0, #7 @ cache type at current level cmp r8, #2 blt 5f @ instruction only, or none, skip level @ set current cache level/type (for CCSIDR read) lsl r8, r2, #1 mcr p15, 2, r8, c0, c0, 0 @ Write CSSELR (level, type: data/uni) @ read current cache information mrc p15, 1, r8, c0, c0, 0 @ Read CCSIDR lsr r3, r8, #13 @ Number of sets -1 @ Keep only 14 bits of r3 lsl r3, r3, #18 lsr r3, r3, #18 lsr r4, r8, #3 @ Number of ways -1 @ Keep only 9 bits of r4 lsl r4, r4, #23 lsr r4, r4, #23 and r7, r8, #7 @ log2(line size in words) - 2 add r7, r7, #2 @ adjust mov r8, #1 lsl r7, r8, r7 @ -> line size in words lsl r7, r7, #2 @ -> bytes @ set loop mov r5, #0 @ current set = 0 3: lsl r8, r2, #1 @ insert level clz r9, r7 @ calculate set field offset mov r10, #31 sub r9, r10, r9 lsl r10, r5, r9 orr r8, r8, r10 @ insert set field @ way loop @ calculate way field offset mov r6, #0 @ current way = 0 add r10, r4, #1 clz r9, r10 @ r9 = way field offset add r9, r9, #1 4: lsl r10, r6, r9 orr r11, r8, r10 @ insert way field @ clean and invalidate line by set/way mcr p15, 0, r11, c7, c14, 2 @ DCCISW @ next way add r6, r6, #1 cmp r6, r4 ble 4b @ next set add r5, r5, #1 cmp r5, r3 ble 3b @ next level 5: lsr r0, r0, #3 @ align next level CLIDR 'type' field add r2, r2, #1 @ increment cache level counter cmp r2, r1 blt 2b @ outer loop @ return 6: DSB ISB pop {r4-r12, lr} bx lr #include "cache.S"
a1ive/grub
4,728
grub-core/kern/arm/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/offsets.h> #include <grub/symbol.h> #include <grub/machine/kernel.h> /* * GRUB is called from U-Boot as a Linux Kernel type image, which * means among other things that it always enters in ARM state. * * coreboot starts in ARM mode as well. * * Overview of GRUB image layout: * * _start: * Entry point (1 ARM branch instruction, to "codestart") * grub_total_module_size: * Data field: Size of included module blob * (when generated by grub-mkimage) * codestart: * Remainder of statically-linked executable code and data. * __bss_start: * Start of included module blob. * Also where global/static variables are located. * _end: * End of bss region (but not necessarily module blob). * <stack>: * <modules>: * Loadable modules, post relocation. * <heap>: */ .text .arm FUNCTION(_start) b codestart @ Size of final image integrated module blob - set by grub-mkimage .org _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE VARIABLE(grub_total_module_size) .long 0 VARIABLE(grub_modbase) .long 0 bss_start_ptr: .long EXT_C(__bss_start) end_ptr: .long EXT_C(_end) @ Memory map at start: @ * text+data @ * list relocations @ * modules @ Before we enter C, we need to apply the relocations @ and get following map: @ * text+data @ * BSS (cleared) @ * stack @ * modules @ @ To make things easier we ensure @ that BSS+stack is larger than list of relocations @ by increasing stack if necessarry. @ This allows us to always unconditionally copy backwards @ Currently list of relocations is ~5K and stack is set @ to be at least 256K FUNCTION(codestart) @ Store context: Machine ID, atags/dtb, ... @ U-Boot API signature is stored on the U-Boot heap @ Stack pointer used as start address for signature probing mov r12, sp adr sp, entry_state push {r0-r12,lr} @ store U-Boot context (sp in r12) adr r1, _start ldr r0, bss_start_ptr @ src add r0, r0, r1 add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) mvn r2, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) and r0, r0, r2 1: ldr r3, [r0], #4 @load next offset @ both -2 and -1 are treated the same as we have only one type of relocs @ -2 means "end of this type of relocs" and -1 means "end of all relocs" add r2, r3, #2 cmp r2, #1 bls reloc_done @ Adjust next offset ldr r2, [r3, r1] add r2, r2, r1 str r2, [r3, r1] b 1b reloc_done: @ Modules have been stored as a blob @ they need to be manually relocated to _end add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) mvn r1, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) and r0, r0, r1 @ src = aligned end of relocations ldr r1, end_ptr @ dst = End of BSS ldr r2, grub_total_module_size @ blob size add r1, r1, #GRUB_KERNEL_MACHINE_STACK_SIZE and r1, r1, #~0x7 @ Ensure 8-byte alignment sub sp, r1, #8 add r1, r1, #1024 str r1, EXT_C(grub_modbase) /* Coreboot already places modules at right place. */ #ifndef GRUB_MACHINE_COREBOOT add r1, r1, r2 add r0, r0, r2 sub r1, r1, #4 sub r0, r0, #4 1: ldr r3, [r0], #-4 @ r3 = *src-- str r3, [r1], #-4 @ *dst-- = r3 subs r2, #4 @ remaining -= 4 bne 1b @ while remaining != 0 #endif @ Since we _are_ the C run-time, we need to manually zero the BSS @ region before continuing ldr r0, bss_start_ptr @ zero from here @ If unaligned, bytewise zero until base address aligned. mov r2, #0 1: tst r0, #3 beq 2f strb r2, [r0], #1 b 1b 2: ldr r1, end_ptr @ to here 1: str r2, [r0], #4 cmp r0, r1 bne 1b b EXT_C(grub_main) .align 3 @ U-boot/coreboot context stack space VARIABLE(grub_arm_saved_registers) .long 0 @ r0 .long 0 @ r1 .long 0 @ r2 .long 0 @ r3 .long 0 @ r4 .long 0 @ r5 .long 0 @ r6 .long 0 @ r7 .long 0 @ r8 .long 0 @ r9 .long 0 @ r10 .long 0 @ r11 .long 0 @ sp .long 0 @ lr entry_state:
a1ive/grub
1,495
grub-core/kern/arm64/cache_flush.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "cache_flush.S" .text /* * Simple cache maintenance functions */ // x0 - *beg (inclusive) // x1 - *end (exclusive) // x2 - line size FUNCTION(grub_arch_clean_dcache_range) // Clean data cache for range to point-of-unification 1: cmp x0, x1 b.ge 2f dc cvau, x0 // Clean Virtual Address to PoU add x0, x0, x2 // Next line b 1b 2: dsb ish isb ret // x0 - *beg (inclusive) // x1 - *end (exclusive) // x2 - line size FUNCTION(grub_arch_invalidate_icache_range) // Invalidate instruction cache for range to point-of-unification 1: cmp x0, x1 b.ge 2f ic ivau, x0 // Invalidate Virtual Address to PoU add x0, x0, x2 // Next line b 1b // Branch predictor invalidation not needed on AArch64 2: dsb ish isb ret
a1ive/grub
1,137
grub-core/kern/mips/cache.S
#include <grub/symbol.h> .set noreorder .set nomacro FUNCTION (grub_arch_sync_caches) #include "cache_flush.S" j $ra nop FUNCTION (grub_arch_sync_dma_caches) move $t2, $a0 addu $t3, $a0, $a1 srl $t2, $t2, 5 sll $t2, $t2, 5 addu $t3, $t3, 0x1f srl $t3, $t3, 5 sll $t3, $t3, 5 move $t0, $t2 subu $t1, $t3, $t2 1: cache_op 1, 0($t0) #ifdef GRUB_MACHINE_MIPS_LOONGSON cache_op 1, 1($t0) cache_op 1, 2($t0) cache_op 1, 3($t0) addiu $t1, $t1, -0x20 bne $t1, $zero, 1b addiu $t0, $t0, 0x20 #else addiu $t1, $t1, -4 bne $t1, $zero, 1b addiu $t0, $t0, 0x4 #endif sync_op move $t0, $t2 subu $t1, $t3, $t2 2: #ifdef GRUB_MACHINE_MIPS_LOONGSON cache_op 0, 0($t0) addiu $t1, $t1, -0x20 bne $t1, $zero, 2b addiu $t0, $t0, 0x20 #else cache_op 0, 0($t0) addiu $t1, $t1, -4 bne $t1, $zero, 2b addiu $t0, $t0, 0x4 #endif sync_op move $t0, $t2 subu $t1, $t3, $t2 2: #ifdef GRUB_MACHINE_MIPS_LOONGSON cache_op 23, 0($t0) addiu $t1, $t1, -0x20 bne $t1, $zero, 2b addiu $t0, $t0, 0x20 #else cache_op 23, 0($t0) addiu $t1, $t1, -0x4 bne $t1, $zero, 2b addiu $t0, $t0, 0x4 #endif sync_op jr $ra nop
a1ive/grub
2,917
grub-core/kern/mips/startup.S
/* startup.S - Startup code for the MIPS. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/offsets.h> #include <grub/machine/memory.h> #include <grub/machine/kernel.h> #include <grub/offsets.h> #include <grub/mips/asm.h> #define BASE_ADDR 8 .globl __start, _start, start .set noreorder .set nomacro __start: _start: start: .extern __bss_start .extern _end bal cont nop .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE VARIABLE(grub_total_modules_size) .long 0 VARIABLE (grub_arch_busclock) .long 0 VARIABLE (grub_arch_cpuclock) .long 0 VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 #ifdef GRUB_MACHINE_MIPS_LOONGSON VARIABLE (grub_arch_machine) .long GRUB_ARCH_MACHINE_FULOONG2F #endif cont: /* Save our base. */ move $s0, $ra #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS lui $t1, %hi(grub_arch_busclock) addiu $t1, %lo(grub_arch_busclock) sw $s4, 8($t1) #endif #ifdef GRUB_MACHINE_MIPS_LOONGSON lui $t1, %hi(grub_arch_busclock) addiu $t1, %lo(grub_arch_busclock) sw $s2, 0($t1) sw $s3, 4($t1) sw $s4, 8($t1) sw $s5, 12($t1) sw $s7, 16($t1) #endif /* Move the modules out of BSS. */ lui $t2, %hi(__bss_start) addiu $t2, %lo(__bss_start) lui $t1, %hi(_end) addiu $t1, %lo(_end) addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) nor $t3, $t3, $0 and $t1, $t1, $t3 lw $t3, (GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE - BASE_ADDR)($s0) /* Backward copy. */ add $t1, $t1, $t3 add $t2, $t2, $t3 addiu $t1, $t1, -1 addiu $t2, $t2, -1 /* $t2 is source. $t1 is destination. $t3 is size. */ modulesmovcont: beq $t3, $0, modulesmovdone nop lb GRUB_ASM_T4, 0($t2) sb GRUB_ASM_T4, 0($t1) addiu $t2, $t2, -1 addiu $t1, $t1, -1 b modulesmovcont addiu $t3, $t3, -1 modulesmovdone: /* Clean BSS. */ lui $t1, %hi(__bss_start) addiu $t1, $t1, %lo(__bss_start) lui $t2, %hi(_end) addiu $t2, $t2, %lo(_end) bsscont: sb $0,0($t1) addiu $t1, $t1, 1 sltu $t3, $t1, $t2 bne $t3, $0, bsscont nop lui $t9, %hi(grub_main) addiu $t9, %lo(grub_main) lui $sp, %hi(GRUB_MACHINE_MEMORY_STACK_HIGH) jr $t9 addiu $sp, $sp, %lo(GRUB_MACHINE_MEMORY_STACK_HIGH)
a1ive/grub
1,482
grub-core/kern/powerpc/cache_flush.S
/* cache.S - Flush the processor cache for a specific region. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2004,2007,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #undef CACHE_LINE_BYTES #define CACHE_LINE_BYTES 32 /* `address' may not be CACHE_LINE_BYTES-aligned. */ andi. 6, 3, CACHE_LINE_BYTES - 1 /* Find the misalignment. */ add 4, 4, 6 /* Adjust `size' to compensate. */ /* Force the dcache lines to memory. */ li 5, 0 1: dcbst 5, 3 addi 5, 5, CACHE_LINE_BYTES cmpw 5, 4 blt 1b sync /* Force all dcbsts to complete. */ /* Invalidate the icache lines. */ li 5, 0 1: icbi 5, 3 addi 5, 5, CACHE_LINE_BYTES cmpw 5, 4 blt 1b sync /* Force all icbis to complete. */ isync /* Discard partially executed instructions that were loaded from the invalid icache. */
a1ive/grub
3,987
grub-core/kern/powerpc/compiler-rt.S
/* * Special support for eabi and SVR4 * * Copyright (C) 1995-2014 Free Software Foundation, Inc. * Written By Michael Meissner * 64-bit support written by David Edelsohn * * This file is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 3, or (at your option) any * later version. * * This file 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 * General Public License for more details. * * Under Section 7 of GPL version 3, you are granted additional * permissions described in the GCC Runtime Library Exception, version * 3.1, as published by the Free Software Foundation. * * You should have received a copy of the GNU General Public License and * a copy of the GCC Runtime Library Exception along with this program; * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see * <http://www.gnu.org/licenses/>. */ /* Do any initializations needed for the eabi environment */ #include <grub/symbol.h> #include <grub/dl.h> .section ".text" #define CFI_RESTORE(reg) .cfi_restore reg #define CFI_OFFSET(reg, off) .cfi_offset reg, off #define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg #define CFI_STARTPROC .cfi_startproc #define CFI_ENDPROC .cfi_endproc /* Routines for restoring integer registers, called by the compiler. */ /* Called with r11 pointing to the stack header word of the caller of the */ /* function, just beyond the end of the integer restore area. */ CFI_STARTPROC CFI_DEF_CFA_REGISTER (11) CFI_OFFSET (65, 4) CFI_OFFSET (14, -72) CFI_OFFSET (15, -68) CFI_OFFSET (16, -64) CFI_OFFSET (17, -60) CFI_OFFSET (18, -56) CFI_OFFSET (19, -52) CFI_OFFSET (20, -48) CFI_OFFSET (21, -44) CFI_OFFSET (22, -40) CFI_OFFSET (23, -36) CFI_OFFSET (24, -32) CFI_OFFSET (25, -28) CFI_OFFSET (26, -24) CFI_OFFSET (27, -20) CFI_OFFSET (28, -16) CFI_OFFSET (29, -12) CFI_OFFSET (30, -8) CFI_OFFSET (31, -4) FUNCTION(_restgpr_14_x) lwz 14,-72(11) /* restore gp registers */ CFI_RESTORE (14) FUNCTION(_restgpr_15_x) lwz 15,-68(11) CFI_RESTORE (15) FUNCTION(_restgpr_16_x) lwz 16,-64(11) CFI_RESTORE (16) FUNCTION(_restgpr_17_x) lwz 17,-60(11) CFI_RESTORE (17) FUNCTION(_restgpr_18_x) lwz 18,-56(11) CFI_RESTORE (18) FUNCTION(_restgpr_19_x) lwz 19,-52(11) CFI_RESTORE (19) FUNCTION(_restgpr_20_x) lwz 20,-48(11) CFI_RESTORE (20) FUNCTION(_restgpr_21_x) lwz 21,-44(11) CFI_RESTORE (21) FUNCTION(_restgpr_22_x) lwz 22,-40(11) CFI_RESTORE (22) FUNCTION(_restgpr_23_x) lwz 23,-36(11) CFI_RESTORE (23) FUNCTION(_restgpr_24_x) lwz 24,-32(11) CFI_RESTORE (24) FUNCTION(_restgpr_25_x) lwz 25,-28(11) CFI_RESTORE (25) FUNCTION(_restgpr_26_x) lwz 26,-24(11) CFI_RESTORE (26) FUNCTION(_restgpr_27_x) lwz 27,-20(11) CFI_RESTORE (27) FUNCTION(_restgpr_28_x) lwz 28,-16(11) CFI_RESTORE (28) FUNCTION(_restgpr_29_x) lwz 29,-12(11) CFI_RESTORE (29) FUNCTION(_restgpr_30_x) lwz 30,-8(11) CFI_RESTORE (30) FUNCTION(_restgpr_31_x) lwz 0,4(11) lwz 31,-4(11) CFI_RESTORE (31) mtlr 0 CFI_RESTORE (65) mr 1,11 CFI_DEF_CFA_REGISTER (1) blr CFI_ENDPROC CFI_STARTPROC FUNCTION(_savegpr_14) stw 14,-72(11) /* save gp registers */ FUNCTION(_savegpr_15) stw 15,-68(11) FUNCTION(_savegpr_16) stw 16,-64(11) FUNCTION(_savegpr_17) stw 17,-60(11) FUNCTION(_savegpr_18) stw 18,-56(11) FUNCTION(_savegpr_19) stw 19,-52(11) FUNCTION(_savegpr_20) stw 20,-48(11) FUNCTION(_savegpr_21) stw 21,-44(11) FUNCTION(_savegpr_22) stw 22,-40(11) FUNCTION(_savegpr_23) stw 23,-36(11) FUNCTION(_savegpr_24) stw 24,-32(11) FUNCTION(_savegpr_25) stw 25,-28(11) FUNCTION(_savegpr_26) stw 26,-24(11) FUNCTION(_savegpr_27) stw 27,-20(11) FUNCTION(_savegpr_28) stw 28,-16(11) FUNCTION(_savegpr_29) stw 29,-12(11) FUNCTION(_savegpr_30) stw 30,-8(11) FUNCTION(_savegpr_31) stw 31,-4(11) blr CFI_ENDPROC
a1ive/grub
3,770
grub-core/kern/i386/multiboot/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/memory.h> #include <grub/offsets.h> #include <multiboot.h> #include <multiboot2.h> /* * Note: GRUB is compiled with the options -mrtd and -mregparm=3. * So the first three arguments are passed in %eax, %edx, and %ecx, * respectively, and if a function has a fixed number of arguments * and the number if greater than three, the function must return * with "ret $N" where N is ((the number of arguments) - 3) * 4. */ .file "startup.S" .text .globl start, _start start: _start: movl %eax, EXT_C(kern_multiboot_magic) movl %ebx, EXT_C(kern_multiboot_info) /* initialize the stack */ movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp /* jump to the main body of C code */ jmp EXT_C(grub_main) /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). */ #define MULTIBOOT_FLAGS (MULTIBOOT_MEMORY_INFO | \ MULTIBOOT_VIDEO_MODE) .p2align 2 /* force 4-byte alignment */ multiboot_header: /* magic */ .long MULTIBOOT_HEADER_MAGIC /* flags */ .long MULTIBOOT_FLAGS /* checksum */ .long -(MULTIBOOT_HEADER_MAGIC+MULTIBOOT_FLAGS) /* checksum */ .long 0 .long 0 .long 0 .long 0 .long 0 .long 1 /* mode_type */ .long 1024 /* cols */ .long 768 /* rows */ .long 32 /* color depth */ /* * Support for booting GRUB from a Multiboot2 boot loader (e.g. GRUB itself). */ #define MULTIBOOT2_ARCH MULTIBOOT2_ARCHITECTURE_I386 .align 8 mb2_hdr: /* magic */ .long MULTIBOOT2_HEADER_MAGIC /* architecture */ .long MULTIBOOT2_ARCH /* header length */ .long mb2_hdr_end - mb2_hdr /* checksum */ .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCH + (mb2_hdr_end - mb2_hdr)) .align 8 inf_tag_start: .short MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST .short MULTIBOOT2_HEADER_TAG_REQUIRED .long inf_tag_end - inf_tag_start .long MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO .long MULTIBOOT2_TAG_TYPE_MMAP inf_tag_end: .align 8 align_tag_start: .short MULTIBOOT2_HEADER_TAG_MODULE_ALIGN .short MULTIBOOT2_HEADER_TAG_REQUIRED .long align_tag_end - align_tag_start align_tag_end: .align 8 console_tag_start: .short MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS .short MULTIBOOT2_HEADER_TAG_REQUIRED .long console_tag_end - console_tag_start .long MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED console_tag_end: .align 8 fb_tag_start: .short MULTIBOOT2_HEADER_TAG_FRAMEBUFFER .short MULTIBOOT2_HEADER_TAG_OPTIONAL .long fb_tag_end - fb_tag_start .long 1024 .long 768 .long 32 fb_tag_end: .align 8 tag_end: .short MULTIBOOT2_HEADER_TAG_END .short MULTIBOOT2_HEADER_TAG_REQUIRED .long tag_end_end - tag_end tag_end_end: mb2_hdr_end: #include "../realmode.S" #include "../int.S" #include "../reboot.S"
a1ive/grub
1,876
grub-core/kern/i386/coreboot/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/memory.h> #include <grub/offsets.h> #include <multiboot.h> #include <multiboot2.h> /* * Note: GRUB is compiled with the options -mrtd and -mregparm=3. * So the first three arguments are passed in %eax, %edx, and %ecx, * respectively, and if a function has a fixed number of arguments * and the number if greater than three, the function must return * with "ret $N" where N is ((the number of arguments) - 3) * 4. */ .file "startup.S" .text .globl start, _start start: _start: /* initialize the stack */ movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp /* jump to the main body of C code */ jmp EXT_C(grub_main) /* * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself). */ #define MULTIBOOT_FLAGS MULTIBOOT_MEMORY_INFO .p2align 2 /* force 4-byte alignment */ multiboot_header: /* magic */ .long MULTIBOOT_HEADER_MAGIC /* flags */ .long MULTIBOOT_FLAGS /* checksum */ .long -(MULTIBOOT_HEADER_MAGIC+MULTIBOOT_FLAGS) /* checksum */
a1ive/grub
1,959
grub-core/kern/i386/xen/startup_pvh.S
/* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2018 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/machine/memory.h> .file "startup_pvh.S" .text .globl start, _start .code32 start: _start: cld lgdt gdtdesc ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f 1: movl $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %eax mov %eax, %ds mov %eax, %es mov %eax, %fs mov %eax, %gs mov %eax, %ss leal LOCAL(stack_end), %esp /* Save address of start info structure. */ mov %ebx, pvh_start_info call EXT_C(grub_main) /* Doesn't return. */ .p2align 3 gdt: .word 0, 0 .byte 0, 0, 0, 0 /* -- code segment -- * base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present * type = 32bit code execute/read, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x9A, 0xCF, 0 /* -- data segment -- * base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present * type = 32 bit data read/write, DPL = 0 */ .word 0xFFFF, 0 .byte 0, 0x92, 0xCF, 0 .p2align 3 /* this is the GDT descriptor */ gdtdesc: .word 0x17 /* limit */ .long gdt /* addr */ .p2align 2 /* Saved pointer to start info structure. */ .globl pvh_start_info pvh_start_info: .long 0 .bss .space GRUB_MEMORY_MACHINE_PROT_STACK_SIZE LOCAL(stack_end):
a1ive/grub
1,092
grub-core/kern/i386/xen/startup.S
/* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> .file "startup.S" .text .globl start, _start .code32 start: _start: leal LOCAL(stack_end), %esp movl %esi, EXT_C(grub_xen_start_page_addr) call EXT_C(grub_main) /* Doesn't return. */ .bss .space (1 << 22) LOCAL(stack_end):
a1ive/grub
1,200
grub-core/kern/i386/xen/hypercall.S
/* hypercall.S - wrappers for Xen hypercalls */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/xen.h> FUNCTION(grub_xen_hypercall) pushl %ebp movl %esp, %ebp pushl %esi pushl %edi pushl %ebx /* call number already in %eax. */ /* %edx -> %ebx*/ /* %ecx -> %ecx*/ movl %edx, %ebx movl 8(%ebp), %edx movl 12(%ebp), %esi movl 16(%ebp), %edi movl 20(%ebp), %ebp int $0x82 popl %ebx popl %edi popl %esi popl %ebp ret
a1ive/grub
1,143
grub-core/kern/i386/efi/startup.S
/* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2006,2007,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> .file "startup.S" .text .globl start, _start start: _start: /* * EFI_SYSTEM_TABLE * and EFI_HANDLE are passed on the stack. */ movl 4(%esp), %eax movl %eax, EXT_C(grub_efi_image_handle) movl 8(%esp), %eax movl %eax, EXT_C(grub_efi_system_table) call EXT_C(grub_main) ret
a1ive/grub
1,368
grub-core/kern/i386/ieee1275/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/offsets.h> #include <multiboot.h> #include <multiboot2.h> /* * Note: GRUB is compiled with the options -mrtd and -mregparm=3. * So the first three arguments are passed in %eax, %edx, and %ecx, * respectively, and if a function has a fixed number of arguments * and the number if greater than three, the function must return * with "ret $N" where N is ((the number of arguments) - 3) * 4. */ .file "startup.S" .text .globl start, _start start: _start: movl %eax, EXT_C(grub_ieee1275_entry_fn) jmp EXT_C(grub_main)
a1ive/grub
1,747
grub-core/kern/i386/qemu/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/machine/memory.h> #include <grub/machine/kernel.h> .text .code32 .globl _start _start: jmp codestart .org GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR VARIABLE(grub_core_entry_addr) .long 0 codestart: /* Relocate to low memory. First we figure out our location. We will derive the rom start address from it. */ call 1f 1: popl %esi /* Rom size is a multiple of 64 kiB. With this we get the value of `grub_core_entry_addr' in %esi. */ xorw %si, %si movl $(_edata - _start), %ecx movl $_start, %edi cld rep movsb ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $1f 1: /* clean out the bss */ movl $BSS_START_SYMBOL, %edi /* compute the bss length */ movl $END_SYMBOL, %ecx subl %edi, %ecx /* clean out */ xorl %eax, %eax cld rep stosb /* * Call the start of main body of C code. */ call EXT_C(grub_main) /* This should never happen. */ cli 1: hlt jmp 1b
a1ive/grub
4,762
grub-core/kern/i386/pc/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008,2009,2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ /* * Note: These functions defined in this file may be called from C. * Be careful of that you must not modify some registers. Quote * from gcc-2.95.2/gcc/config/i386/i386.h: 1 for registers not available across function calls. These must include the FIXED_REGISTERS and also any registers that can be used without being saved. The latter must include the registers where values are returned and the register where structure-value addresses are passed. Aside from that, you can include as many other registers as you like. ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } */ /* * Note: GRUB is compiled with the options -mrtd and -mregparm=3. * So the first three arguments are passed in %eax, %edx, and %ecx, * respectively, and if a function has a fixed number of arguments * and the number is greater than three, the function must return * with "ret $N" where N is ((the number of arguments) - 3) * 4. */ #include <config.h> #include <grub/symbol.h> #include <multiboot.h> #ifdef __APPLE__ #include <grub/i386/pc/memory.h> #endif .file "startup.S" .text .globl start, _start, __start start: _start: __start: #ifdef __APPLE__ LOCAL(start): #endif .code32 movl %ecx, (LOCAL(real_to_prot_addr) - _start) (%esi) movl %edi, (LOCAL(prot_to_real_addr) - _start) (%esi) movl %eax, (EXT_C(grub_realidt) - _start) (%esi) /* copy back the decompressed part (except the modules) */ #ifdef __APPLE__ movl $EXT_C(_edata), %ecx subl $LOCAL(start), %ecx #else movl $(_edata - _start), %ecx #endif movl $(_start), %edi rep movsb movl $LOCAL (cont), %esi jmp *%esi LOCAL(cont): #if 0 /* copy modules before cleaning out the bss */ movl EXT_C(grub_total_module_size), %ecx movl EXT_C(grub_kernel_image_size), %esi addl %ecx, %esi addl $_start, %esi decl %esi movl $END_SYMBOL, %edi addl %ecx, %edi decl %edi std rep movsb #endif #ifdef __APPLE__ /* clean out the bss */ movl $EXT_C(_edata), %edi /* compute the bss length */ movl $GRUB_MEMORY_MACHINE_SCRATCH_ADDR, %ecx #else /* clean out the bss */ movl $BSS_START_SYMBOL, %edi /* compute the bss length */ movl $END_SYMBOL, %ecx #endif subl %edi, %ecx /* clean out */ xorl %eax, %eax cld rep stosb movl %edx, EXT_C(grub_boot_device) /* * Call the start of main body of C code. */ call EXT_C(grub_main) LOCAL(real_to_prot_addr): .long 0 LOCAL(prot_to_real_addr): .long 0 .macro PROT_TO_REAL movl LOCAL(prot_to_real_addr), %eax call *%eax .endm .macro REAL_TO_PROT movl LOCAL(real_to_prot_addr), %eax calll *%eax .endm /* * grub_exit() * * Exit the system. */ FUNCTION(grub_exit) PROT_TO_REAL .code16 /* Tell the BIOS a boot failure. If this does not work, reboot. */ int $0x18 /* set 0x472 to 0x0000 for cold boot (0x1234 for warm boot) */ xorw %ax, %ax movw $0x0472, %di movw %ax, (%di) ljmp $0xf000, $0xfff0 .code32 /* * int grub_pxe_call (int func, void* data, grub_uint32_t pxe_rm_entry); */ FUNCTION(grub_pxe_call) pushl %ebp movl %esp, %ebp pushl %esi pushl %edi pushl %ebx movl %ecx, %ebx movl %eax, %ecx movl %edx, %eax andl $0xF, %eax shrl $4, %edx shll $16, %edx addl %eax, %edx PROT_TO_REAL .code16 pushl %ebx pushl %edx pushw %cx movw %sp, %bx lcall *%ss:6(%bx) cld addw $10, %sp movw %ax, %cx REAL_TO_PROT .code32 movzwl %cx, %eax popl %ebx popl %edi popl %esi popl %ebp ret #include "../int.S" VARIABLE(grub_realidt) .long 0 #include "../reboot.S" #ifdef __APPLE__ /* Older versions of objconv assume that there is the same number of text and data sections. Hence this dummy. */ .section __TEXT, __zz_dummy .byte 0 .globl EXT_C(_edata) .globl EXT_C(grub_boot_device) .zerofill __DATA, __aa_before_bss, EXT_C(_edata), 1, 0 .zerofill __DATA, __bss, EXT_C(grub_boot_device), 4, 2 #else .bss VARIABLE(grub_boot_device) .long 0 #endif
a1ive/grub
1,150
grub-core/kern/ia64/efi/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> #include <grub/offsets.h> .text .psr abi64 .psr lsb .lsb .global _start .proc _start _start: alloc loc0=ar.pfs,2,4,0,0 mov loc1=rp addl loc2=@gprel(grub_efi_image_handle),gp addl loc3=@gprel(grub_efi_system_table),gp ;; st8 [loc2]=in0 st8 [loc3]=in1 br.call.sptk.few rp=grub_main ;; mov ar.pfs=loc0 mov rp=loc1 ;; br.ret.sptk.few rp .endp _start
a1ive/grub
1,243
grub-core/kern/riscv/efi/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2018 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #if __riscv_xlen == 64 #define sl sd #define ll ld #else #define sl sw #define ll lw #endif .file "startup.S" .text FUNCTION(_start) /* * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0. */ ll a2, efi_image_handle_val sl a0, 0(a2) ll a2, efi_system_table_val sl a1, 0(a2) ll a2, grub_main_val jr a2 grub_main_val: .quad EXT_C(grub_main) efi_system_table_val: .quad EXT_C(grub_efi_system_table) efi_image_handle_val: .quad EXT_C(grub_efi_image_handle)
a1ive/grub
2,879
grub-core/kern/sparc64/ieee1275/crt0.S
/* crt0.S - Startup code for the Sparc64. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/machine/kernel.h> #include <grub/offsets.h> .text .align 4 .globl _start _start: ba codestart mov %o4, %o0 .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE VARIABLE(grub_total_module_size) .word 0 codestart: /* Copy the modules past the end of the kernel image. * They are currently sitting in the BSS. */ sethi %hi(__bss_start + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o2 or %o2, %lo(__bss_start + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o2 srl %o2, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o2 sll %o2, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o2 sethi %hi(_end + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o3 or %o3, %lo(_end + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o3 srl %o3, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o3 sll %o3, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o3 sethi %hi(grub_total_module_size), %o4 lduw [%o4 + %lo(grub_total_module_size)], %o4 add %o2, %o4, %o2 add %o3, %o4, %o3 /* Save ieee1275 stack for future use by booter. */ mov %o6, %o1 /* Our future stack. */ sethi %hi(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5 or %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5 add %o3, %o5, %o6 and %o6, ~0xff, %o6 sub %o6, 2047, %o6 sub %o2, 4, %o2 sub %o3, 4, %o3 1: lduw [%o2], %o5 stw %o5, [%o3] subcc %o4, 4, %o4 sub %o2, 4, %o2 bne,pt %icc, 1b sub %o3, 4, %o3 /* Now it's safe to clear out the BSS. */ sethi %hi(__bss_start), %o2 or %o2, %lo(__bss_start), %o2 1: stb %g0, [%o2] add %o2, 1, %o2 and %o2, 7, %o3 brnz %o3, 1b nop sethi %hi(_end - 1), %o3 or %o3, %lo(_end - 1), %o3 srl %o3, 3, %o3 sll %o3, 3, %o3 1: stx %g0, [%o2] add %o2, 8, %o2 cmp %o2, %o3 blt,pt %xcc, 1b nop sethi %hi(_end), %o3 or %o3, %lo(_end), %o3 1: stb %g0, [%o2] add %o2, 1, %o2 cmp %o2, %o3 blt,pt %xcc, 1b nop sethi %hi(grub_ieee1275_original_stack), %o2 stx %o1, [%o2 + %lo(grub_ieee1275_original_stack)] sethi %hi(grub_ieee1275_entry_fn), %o2 call grub_main stx %o0, [%o2 + %lo(grub_ieee1275_entry_fn)] 1: ba,a 1b nop
a1ive/grub
1,100
grub-core/kern/arm/coreboot/coreboot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2016 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "coreboot.S" .text .syntax unified #if !defined (__thumb2__) .arch armv7a .arm #else .arch armv7 .thumb #endif FUNCTION(grub_arm_pfr1) mrc p15, 0, r0, c0, c1, 1 bx lr FUNCTION(grub_armv7_get_timer_value) isb mrrc p15, 1, r0, r1, c14 bx lr FUNCTION(grub_armv7_get_timer_frequency) mrc p15, 0, r0, c14, c0, 0 bx lr
a1ive/grub
1,794
grub-core/kern/arm/uboot/uboot.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/offsets.h> #include <grub/symbol.h> #include <grub/machine/kernel.h> /* * uboot_syscall(): * This function is effectively a veneer, so it cannot * modify the stack or corrupt any registers other than * r12 (ip). Furthermore it needs to restore r8 for * U-Boot (Global Data Pointer) and preserve it for Grub. */ FUNCTION(grub_uboot_syscall) str r8, transition_space str lr, transition_space + 4 str r9, transition_space + 8 ldr ip, saved_registers_ptr ldr r8, [ip, #4 * 8] ldr r9, [ip, #4 * 9] bl do_syscall ldr r8, transition_space ldr lr, transition_space + 4 ldr r9, transition_space + 8 bx lr do_syscall: ldr ip, grub_uboot_syscall_ptr bx ip FUNCTION(grub_uboot_return) ldr ip, saved_registers_ptr ldr sp, [ip, #4 * 4] pop {r4-r12, lr} mov sp, r12 bx lr .align 3 @ GRUB context stack space transition_space: .long 0 @ r8 .long 0 @ lr .long 0 @ r9 saved_registers_ptr: .long EXT_C(grub_arm_saved_registers) VARIABLE(grub_uboot_syscall_ptr) .long 0 @ END
a1ive/grub
1,063
grub-core/kern/arm/efi/startup.S
/* * (C) Copyright 2013 Free Software Foundation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * 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. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * */ #include <grub/symbol.h> .file "startup.S" .text .arm FUNCTION(_start) /* * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in r1/r0. */ ldr ip, =EXT_C(grub_efi_image_handle) str r0, [ip] ldr ip, =EXT_C(grub_efi_system_table) str r1, [ip] ldr ip, =EXT_C(grub_main) bx ip END
a1ive/grub
1,148
grub-core/kern/arm64/efi/startup.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> .file "startup.S" .text FUNCTION(_start) /* * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in x1/x0. */ ldr x2, efi_image_handle_val str x0, [x2] ldr x2, efi_system_table_val str x1, [x2] ldr x2, grub_main_val br x2 grub_main_val: .quad EXT_C(grub_main) efi_system_table_val: .quad EXT_C(grub_efi_system_table) efi_image_handle_val: .quad EXT_C(grub_efi_image_handle)
a1ive/grub
1,116
grub-core/kern/x86_64/xen/startup.S
/* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2013 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> .file "startup.S" .text .globl start, _start .code64 start: _start: leaq LOCAL(stack_end), %rsp movq %rsi, EXT_C(grub_xen_start_page_addr)(%rip) andq $~0xf, %rsp call EXT_C(grub_main) /* Doesn't return. */ .bss .space (1 << 22) LOCAL(stack_end):
a1ive/grub
1,386
grub-core/kern/x86_64/xen/hypercall.S
/* hypercall.S - wrappers for Xen hypercalls */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2011 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/xen.h> FUNCTION(grub_xen_sched_op) movq $__HYPERVISOR_sched_op, %rax syscall ret FUNCTION(grub_xen_event_channel_op) movq $__HYPERVISOR_event_channel_op, %rax syscall ret FUNCTION(grub_xen_update_va_mapping) movq $__HYPERVISOR_update_va_mapping, %rax syscall ret FUNCTION(grub_xen_mmuext_op) movq %rcx, %r10 movq $__HYPERVISOR_mmuext_op, %rax syscall ret FUNCTION(grub_xen_grant_table_op) movq $__HYPERVISOR_grant_table_op, %rax syscall ret FUNCTION(grub_xen_mmu_update) movq %rcx, %r10 movq $__HYPERVISOR_mmu_update, %rax syscall ret
a1ive/grub
1,097
grub-core/kern/x86_64/efi/startup.S
/* startup.S - bootstrap GRUB itself */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> .file "startup.S" .text .globl start, _start .code64 start: _start: movq %rcx, EXT_C(grub_efi_image_handle)(%rip) movq %rdx, EXT_C(grub_efi_system_table)(%rip) andq $~0xf, %rsp call EXT_C(grub_main) /* Doesn't return. */
a1ive/grub
2,535
grub-core/kern/x86_64/efi/callwrap.S
/* callwrap.S - wrapper for x86_64 efi calls */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2006,2007,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <grub/symbol.h> /* * x86_64 uses registry to pass parameters. Unfortunately, gcc and efi use * different call conversion, so we need to do some conversion. * * gcc: * %rdi, %rsi, %rdx, %rcx, %r8, %r9, 8(%rsp), 16(%rsp), ... * * efi: * %rcx, %rdx, %r8, %r9, 32(%rsp), 40(%rsp), 48(%rsp), ... * */ .file "callwrap.S" .text FUNCTION(efi_wrap_0) subq $40, %rsp call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_1) subq $40, %rsp mov %rsi, %rcx call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_2) subq $40, %rsp mov %rsi, %rcx call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_3) subq $40, %rsp mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_4) subq $40, %rsp mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_5) subq $40, %rsp mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $40, %rsp ret FUNCTION(efi_wrap_6) subq $56, %rsp mov 56+8(%rsp), %rax mov %rax, 40(%rsp) mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $56, %rsp ret FUNCTION(efi_wrap_7) subq $88, %rsp mov 88+16(%rsp), %rax mov %rax, 48(%rsp) mov 88+8(%rsp), %rax mov %rax, 40(%rsp) mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $88, %rsp ret FUNCTION(efi_wrap_10) subq $88, %rsp mov 88+40(%rsp), %rax mov %rax, 72(%rsp) mov 88+32(%rsp), %rax mov %rax, 64(%rsp) mov 88+24(%rsp), %rax mov %rax, 56(%rsp) mov 88+16(%rsp), %rax mov %rax, 48(%rsp) mov 88+8(%rsp), %rax mov %rax, 40(%rsp) mov %r9, 32(%rsp) mov %r8, %r9 mov %rcx, %r8 mov %rsi, %rcx call *%rdi addq $88, %rsp ret
a1ive/grub
1,678
grub-core/kern/powerpc/ieee1275/startup.S
/* startup.S - Startup code for the PowerPC. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #include <grub/symbol.h> #include <grub/offsets.h> .extern __bss_start .extern _end .text .align 2 .globl start, _start start: _start: li 2, 0 li 13, 0 /* Stage1 won't zero BSS for us. In other cases, why not do it again? */ lis 6, (__bss_start - 4)@h ori 6, 6, (__bss_start - 4)@l 2: stb 2, 4(6) addi 6, 6, 1 andi. 7, 6, 3 cmpi 0, 1, 7, 0 bne 2b lis 7, (_end - 4)@h ori 7, 7, (_end - 4)@l subf 7, 6, 7 subi 8, 7, 1 andi. 8, 8, 3 addi 8, 8, 1 sub 7, 7, 8 srwi 7, 7, 2 /* We store 4 bytes at a time. */ mtctr 7 2: stwu 2, 4(6) /* We know r2 is already 0 from above. */ bdnz 2b mtctr 8 2: stb 2, 4(6) /* We know r2 is already 0 from above. */ addi 6, 6, 1 bdnz 2b /* Store r5 in grub_ieee1275_entry_fn. */ lis 9, grub_ieee1275_entry_fn@ha stw 5, grub_ieee1275_entry_fn@l(9) bl grub_main 1: b 1b
a1ive/grub
2,041
grub-core/tests/boot/kfreebsd.init-x86_64.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #define MODE_RDRW 2 #define FLAGS_NONE 0 #define SYSCALL_ARCH 165 #define SYSCALL_OPEN 5 #define SYSCALL_WRITE 4 #define SYSCALL_RESET 55 #define SYSCALL_EXIT 1 #define SYSCALL_ARCH_IOPERM 4 #define SYSCALL_FSYNC 95 #define RESET_NOSYNC 0x4 #define RESET_HALT 0x8 #define RESET_POWEROFF 0x4000 .section ".init", "ax" .global start,_start start: _start: /* open. */ movq $SYSCALL_OPEN, %rax leaq device, %rdi movq $MODE_RDRW, %rsi movq $FLAGS_NONE, %rdx syscall movq %rax, %rdi /* write. */ leaq message, %rsi movq $SYSCALL_WRITE, %rax movq $(messageend - message), %rdx syscall /* fsync. */ movq $SYSCALL_FSYNC, %rax syscall /* IOPERM. */ movq $SYSCALL_ARCH, %rax movq $SYSCALL_ARCH_IOPERM, %rdi leaq ioperm_arg1, %rsi syscall movq $SYSCALL_ARCH, %rax movq $SYSCALL_ARCH_IOPERM, %rdi leaq ioperm_arg2, %rsi syscall #include "qemu-shutdown-x86.S" /* shutdown. */ movq $SYSCALL_RESET, %rax movq $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC), %rdi syscall /* exit (1). Shouldn't be reached. */ movq $SYSCALL_EXIT, %rax movq $1, %rdi syscall device: .ascii "/dev/console" .byte 0 message: .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n" messageend: ioperm_arg1: .long 0xcf8 .long 8 .long 1 ioperm_arg2: .long 0x7000 .long 8 .long 1
a1ive/grub
2,333
grub-core/tests/boot/kbsd.init-i386.S
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ #ifdef TARGET_NETBSD #define SYSCALL_RESET 208 #elif defined (TARGET_OPENBSD) #define SYSCALL_RESET 55 #else #error unknown target #endif #define MODE_RDRW 2 #define FLAGS_NONE 0 #define SYSCALL_OPEN 5 #define SYSCALL_WRITE 4 #define SYSCALL_EXIT 1 #define SYSCALL_ARCH 165 #define SYSCALL_INT 0x80 #define SYSCALL_ARCH_IOPL 2 #define RESET_NOSYNC 0x4 #define RESET_HALT 0x8 #define RESET_POWEROFF 0x800 .section ".init", "ax" .global start,_start start: _start: /* open. */ movl $SYSCALL_OPEN, %eax pushl $FLAGS_NONE pushl $MODE_RDRW leal device, %ebx pushl %ebx pushl $0 int $SYSCALL_INT addl $16, %esp movl %eax, %ecx /* write. */ movl $SYSCALL_WRITE, %eax pushl $(messageend-message) leal message, %ebx pushl %ebx pushl %ecx pushl $0 int $SYSCALL_INT addl $16, %esp /* IOPL. */ movl $SYSCALL_ARCH, %eax pushl $iopl_arg pushl $SYSCALL_ARCH_IOPL pushl $0 int $SYSCALL_INT addl $12, %esp #include "qemu-shutdown-x86.S" /* shutdown. */ movl $SYSCALL_RESET, %eax pushl $0 pushl $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC) pushl $0 int $SYSCALL_INT addl $8, %esp /* exit (1). Shouldn't be reached. */ movl $SYSCALL_EXIT, %eax pushl $1 pushl $0 int $SYSCALL_INT .section ".fini", "ax" 1: jmp 1b .section ".text", "ax" 1: jmp 1b /* This section is needed for NetBSD to identify the binary. */ .section ".note.netbsd.ident", "a" .long 0x7 .long 0x4 .long 0x1 .ascii "NetBSD" .byte 0 .data device: .ascii "/dev/console" .byte 0 message: .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n" messageend: iopl_arg: .long 3