add loongarch64 port

Author: Xiaojuan Zhai <[email protected]>
Author: Meidan Li <[email protected]>
Author: Guoqi Chen <[email protected]>
Author: Xiaolin Zhao <[email protected]>
Author: Fan peng <[email protected]>
Author: Jiantao Shan <[email protected]>
Author: Xuhui Qiang <[email protected]>
Author: Jingyun Hua <[email protected]>
Author: Liu xue <[email protected]>
Author: Hongliang Wang <[email protected]>
This commit is contained in:
Hongliang Wang
2024-02-16 09:33:10 -05:00
committed by Rich Felker
parent 4a16ddf53e
commit 522bd54eda
29 changed files with 1116 additions and 1 deletions
+78
View File
@@ -0,0 +1,78 @@
#ifndef __loongarch_soft_float
#ifdef BROKEN_LOONGARCH_FCSR_ASM
#define FCSR $r0
#else
#define FCSR $fcsr0
#endif
.global feclearexcept
.type feclearexcept,@function
feclearexcept:
li.w $t0, 0x1f0000
and $a0, $a0, $t0
movfcsr2gr $t1, FCSR
andn $t1, $t1, $a0
movgr2fcsr FCSR, $t1
li.w $a0, 0
jr $ra
.global feraiseexcept
.type feraiseexcept,@function
feraiseexcept:
li.w $t0, 0x1f0000
and $a0, $a0, $t0
movfcsr2gr $t1, FCSR
or $t1, $t1, $a0
movgr2fcsr FCSR, $t1
li.w $a0, 0
jr $ra
.global fetestexcept
.type fetestexcept,@function
fetestexcept:
li.w $t0, 0x1f0000
and $a0, $a0, $t0
movfcsr2gr $t1, FCSR
and $a0, $t1, $a0
jr $ra
.global fegetround
.type fegetround,@function
fegetround:
movfcsr2gr $t0, FCSR
andi $a0, $t0, 0x300
jr $ra
.global __fesetround
.hidden __fesetround
.type __fesetround,@function
__fesetround:
li.w $t0, 0x300
and $a0, $a0, $t0
movfcsr2gr $t1, FCSR
andn $t1, $t1, $t0
or $t1, $t1, $a0
movgr2fcsr FCSR, $t1
li.w $a0, 0
jr $ra
.global fegetenv
.type fegetenv,@function
fegetenv:
movfcsr2gr $t0, FCSR
st.w $t0, $a0, 0
li.w $a0, 0
jr $ra
.global fesetenv
.type fesetenv,@function
fesetenv:
addi.d $t0, $a0, 1
beq $t0, $r0, 1f
ld.w $t0, $a0, 0
1: movgr2fcsr FCSR, $t0
li.w $a0, 0
jr $ra
#endif
+7
View File
@@ -0,0 +1,7 @@
.global dlsym
.hidden __dlsym
.type dlsym,@function
dlsym:
move $a2, $ra
la.global $t0, __dlsym
jr $t0
+32
View File
@@ -0,0 +1,32 @@
.global _longjmp
.global longjmp
.type _longjmp,@function
.type longjmp,@function
_longjmp:
longjmp:
ld.d $ra, $a0, 0
ld.d $sp, $a0, 8
ld.d $r21,$a0, 16
ld.d $fp, $a0, 24
ld.d $s0, $a0, 32
ld.d $s1, $a0, 40
ld.d $s2, $a0, 48
ld.d $s3, $a0, 56
ld.d $s4, $a0, 64
ld.d $s5, $a0, 72
ld.d $s6, $a0, 80
ld.d $s7, $a0, 88
ld.d $s8, $a0, 96
#ifndef __loongarch_soft_float
fld.d $fs0, $a0, 104
fld.d $fs1, $a0, 112
fld.d $fs2, $a0, 120
fld.d $fs3, $a0, 128
fld.d $fs4, $a0, 136
fld.d $fs5, $a0, 144
fld.d $fs6, $a0, 152
fld.d $fs7, $a0, 160
#endif
sltui $a0, $a1, 1
add.d $a0, $a0, $a1
jr $ra
+34
View File
@@ -0,0 +1,34 @@
.global __setjmp
.global _setjmp
.global setjmp
.type __setjmp,@function
.type _setjmp,@function
.type setjmp,@function
__setjmp:
_setjmp:
setjmp:
st.d $ra, $a0, 0
st.d $sp, $a0, 8
st.d $r21,$a0, 16
st.d $fp, $a0, 24
st.d $s0, $a0, 32
st.d $s1, $a0, 40
st.d $s2, $a0, 48
st.d $s3, $a0, 56
st.d $s4, $a0, 64
st.d $s5, $a0, 72
st.d $s6, $a0, 80
st.d $s7, $a0, 88
st.d $s8, $a0, 96
#ifndef __loongarch_soft_float
fst.d $fs0, $a0, 104
fst.d $fs1, $a0, 112
fst.d $fs2, $a0, 120
fst.d $fs3, $a0, 128
fst.d $fs4, $a0, 136
fst.d $fs5, $a0, 144
fst.d $fs6, $a0, 152
fst.d $fs7, $a0, 160
#endif
move $a0, $zero
jr $ra
+10
View File
@@ -0,0 +1,10 @@
.global __restore_rt
.global __restore
.hidden __restore_rt
.hidden __restore
.type __restore_rt,@function
.type __restore,@function
__restore_rt:
__restore:
li.w $a7, 139
syscall 0
+25
View File
@@ -0,0 +1,25 @@
.global sigsetjmp
.global __sigsetjmp
.type sigsetjmp,@function
.type __sigsetjmp,@function
sigsetjmp:
__sigsetjmp:
beq $a1, $zero, 1f
st.d $ra, $a0, 184
st.d $s0, $a0, 200 #184+8+8
move $s0, $a0
la.global $t0, setjmp
jirl $ra, $t0, 0
move $a1, $a0 # Return from 'setjmp' or 'longjmp'
move $a0, $s0
ld.d $ra, $a0, 184
ld.d $s0, $a0, 200 #184+8+8
.hidden __sigsetjmp_tail
la.global $t0, __sigsetjmp_tail
jr $t0
1:
la.global $t0, setjmp
jr $t0
@@ -0,0 +1,7 @@
.global __set_thread_area
.hidden __set_thread_area
.type __set_thread_area,@function
__set_thread_area:
move $tp, $a0
move $a0, $zero
jr $ra
+7
View File
@@ -0,0 +1,7 @@
.global __unmapself
.type __unmapself, @function
__unmapself:
li.d $a7, 215 # call munmap
syscall 0
li.d $a7, 93 # call exit
syscall 0
+28
View File
@@ -0,0 +1,28 @@
#__clone(func, stack, flags, arg, ptid, tls, ctid)
# a0, a1, a2, a3, a4, a5, a6
# sys_clone(flags, stack, ptid, ctid, tls)
# a0, a1, a2, a3, a4
.global __clone
.hidden __clone
.type __clone,@function
__clone:
# Save function pointer and argument pointer on new thread stack
addi.d $a1, $a1, -16
st.d $a0, $a1, 0 # save function pointer
st.d $a3, $a1, 8 # save argument pointer
or $a0, $a2, $zero
or $a2, $a4, $zero
or $a3, $a6, $zero
or $a4, $a5, $zero
ori $a7, $zero, 220
syscall 0 # call clone
beqz $a0, 1f # whether child process
jirl $zero, $ra, 0 # parent process return
1:
ld.d $t8, $sp, 0 # function pointer
ld.d $a0, $sp, 8 # argument pointer
jirl $ra, $t8, 0 # call the user's function
ori $a7, $zero, 93
syscall 0 # child process exit
+29
View File
@@ -0,0 +1,29 @@
.global __cp_begin
.hidden __cp_begin
.global __cp_end
.hidden __cp_end
.global __cp_cancel
.hidden __cp_cancel
.hidden __cancel
.global __syscall_cp_asm
.hidden __syscall_cp_asm
.type __syscall_cp_asm,@function
__syscall_cp_asm:
__cp_begin:
ld.w $a0, $a0, 0
bnez $a0, __cp_cancel
move $t8, $a1 # reserve system call number
move $a0, $a2
move $a1, $a3
move $a2, $a4
move $a3, $a5
move $a4, $a6
move $a5, $a7
move $a7, $t8
syscall 0
__cp_end:
jr $ra
__cp_cancel:
la.local $t8, __cancel
jr $t8