#include "assym.h"
#include <sys/errno.h>
#include <machine/param.h>
#include <machine/asm.h>
#include <machine/psl.h>
#include <machine/trap.h>
#ifdef M88100
ENTRY(do_load_word)
bcnd ne0,%r3,1f
#ifdef ERRATA__XXX_USR
NOP
ld.usr %r2,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
ld.usr %r2,%r2,%r0
#endif
1: jmp.n %r1
ld %r2,%r2,%r0
ENTRY(do_load_half)
bcnd ne0,%r3,1f
#ifdef ERRATA__XXX_USR
NOP
ld.h.usr %r2,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
ld.h.usr %r2,%r2,%r0
#endif
1: jmp.n %r1
ld.h %r2,%r2,%r0
ENTRY(do_load_byte)
bcnd ne0,%r3,1f
#ifdef ERRATA__XXX_USR
NOP
ld.b.usr %r2,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
ld.b.usr %r2,%r2,%r0
#endif
1: jmp.n %r1
ld.b %r2,%r2,%r0
ENTRY(do_store_word)
bcnd ne0,%r4,1f
#ifdef ERRATA__XXX_USR
NOP
st.usr %r3,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
st.usr %r3,%r2,%r0
#endif
1: jmp.n %r1
st %r3,%r2,%r0
ENTRY(do_store_half)
bcnd ne0,%r4,1f
#ifdef ERRATA__XXX_USR
NOP
st.h.usr %r3,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
st.h.usr %r3,%r2,%r0
#endif
1: jmp.n %r1
st.h %r3,%r2,%r0
ENTRY(do_store_byte)
bcnd ne0,%r4,1f
#ifdef ERRATA__XXX_USR
NOP
st.b.usr %r3,%r2,%r0
NOP
NOP
NOP
jmp %r1
#else
jmp.n %r1
st.b.usr %r3,%r2,%r0
#endif
1: jmp.n %r1
st.b %r3,%r2,%r0
ENTRY(do_xmem_word)
bcnd ne0,%r4,1f
#ifdef ERRATA__XXX_USR
NOP
#endif
xmem.usr %r3,%r2,%r0
#ifdef ERRATA__XXX_USR
NOP
NOP
NOP
#endif
jmp.n %r1
or %r2, %r3, %r0
1: xmem %r3,%r2,%r0
jmp.n %r1
or %r2, %r3, %r0
ENTRY(do_xmem_byte)
bcnd ne0,%r4,1f
#ifdef ERRATA__XXX_USR
NOP
#endif
xmem.bu.usr %r3,%r2,%r0
#ifdef ERRATA__XXX_USR
NOP
NOP
NOP
#endif
jmp.n %r1
or %r2,%r3,%r0
1: xmem.bu %r3,%r2,%r0
jmp.n %r1
or %r2,%r3,%r0
#endif
#define SRC %r2
#define DEST %r3
#define LEN %r4
ENTRY(_copyin)
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
or.u %r5, %r0, %hi16(Lciflt)
or %r5, %r5, %lo16(Lciflt)
st %r5, %r6, PCB_ONFAULT
cmp %r9, LEN, 8
bb1 lt, %r9, copyin_byte_only
xor %r9, SRC, DEST
mask %r8, %r9, 0x3
bcnd ne0, %r8, copyin_byte_only
bb1 0, SRC, copyin_left_align_to_halfword
ASLOCAL(copyin_left_aligned_to_halfword)
bb1 1, SRC, copyin_left_align_to_word
ASLOCAL(copyin_left_aligned_to_word)
bb1 0, LEN, copyin_right_align_to_halfword
ASLOCAL(copyin_right_aligned_to_halfword)
bb1 1, LEN, copyin_right_align_to_word
ASLOCAL(copyin_right_aligned_to_word)
bb1.n 2, LEN, copyin_right_align_to_doubleword
or %r7, %r0, 4
ASLOCAL(copyin_right_aligned_to_doubleword)
#ifdef ERRATA__XXX_USR
NOP
ld.usr %r5, SRC, %r0
NOP
NOP
NOP
ld.usr %r6, SRC, %r7
NOP
NOP
NOP
#else
ld.usr %r5, SRC, %r0
ld.usr %r6, SRC, %r7
#endif
subu LEN, LEN, 8
st %r5, DEST, %r0
addu SRC, SRC, 8
st %r6, DEST, %r7
bcnd.n ne0, LEN, copyin_right_aligned_to_doubleword
addu DEST, DEST, 8
br.n Lcidone
or %r2, %r0, %r0
ASLOCAL(copyin_left_align_to_halfword)
#ifdef ERRATA__XXX_USR
NOP
ld.b.usr %r5, SRC, %r0
NOP
NOP
NOP
#else
ld.b.usr %r5, SRC, %r0
#endif
subu LEN, LEN, 1
st.b %r5, DEST, %r0
addu SRC, SRC, 1
br.n copyin_left_aligned_to_halfword
addu DEST, DEST, 1
ASLOCAL(copyin_left_align_to_word)
#ifdef ERRATA__XXX_USR
NOP
ld.h.usr %r5, SRC, %r0
NOP
NOP
NOP
#else
ld.h.usr %r5, SRC, %r0
#endif
subu LEN, LEN, 2
st.h %r5, DEST, %r0
addu SRC, SRC, 2
br.n copyin_left_aligned_to_word
addu DEST, DEST, 2
ASLOCAL(copyin_right_align_to_halfword)
subu LEN, LEN, 1
#ifdef ERRATA__XXX_USR
NOP
ld.b.usr %r5, SRC, LEN
NOP
NOP
NOP
#else
ld.b.usr %r5, SRC, LEN
#endif
br.n copyin_right_aligned_to_halfword
st.b %r5, DEST, LEN
ASLOCAL(copyin_right_align_to_word)
subu LEN, LEN, 2
#ifdef ERRATA__XXX_USR
NOP
ld.h.usr %r5, SRC, LEN
NOP
NOP
NOP
#else
ld.h.usr %r5, SRC, LEN
#endif
br.n copyin_right_aligned_to_word
st.h %r5, DEST, LEN
ASLOCAL(copyin_right_align_to_doubleword)
subu LEN, LEN, 4
#ifdef ERRATA__XXX_USR
NOP
ld.usr %r5, SRC, LEN
NOP
NOP
NOP
#else
ld.usr %r5, SRC, LEN
#endif
bcnd.n ne0, LEN, copyin_right_aligned_to_doubleword
st %r5, DEST, LEN
br.n Lcidone
or %r2, %r0, %r0
ASLOCAL(copyin_byte_only)
bcnd eq0, LEN, 2f
1:
subu LEN, LEN, 1
#ifdef ERRATA__XXX_USR
NOP
ld.b.usr %r5, SRC, LEN
NOP
NOP
NOP
#else
ld.b.usr %r5, SRC, LEN
#endif
bcnd.n ne0, LEN, 1b
st.b %r5, DEST, LEN
2:
or %r2, %r0, %r0
ASLOCAL(Lcidone)
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
jmp.n %r1
st %r0, %r6, PCB_ONFAULT
ASLOCAL(Lciflt)
br.n Lcidone
or %r2, %r0, EFAULT
#undef SRC
#undef DEST
#undef LEN
#define SRC %r2
#define DEST %r3
ENTRY(copyin32)
mask %r8, SRC, 0x3
bcnd ne0, %r8, copyin32_misaligned
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
or.u %r5, %r0, %hi16(Lciflt)
or %r5, %r5, %lo16(Lciflt)
st %r5, %r6, PCB_ONFAULT
#ifdef ERRATA__XXX_USR
NOP
ld.usr %r5, SRC, %r0
NOP
NOP
NOP
#else
ld.usr %r5, SRC, %r0
#endif
st %r5, DEST, %r0
br.n Lcidone
or %r2, %r0, %r0
ASLOCAL(copyin32_misaligned)
jmp.n %r1
or %r2, %r0, EFAULT
#undef SRC
#undef DEST
#define SRC %r2
#define DEST %r3
#define CNT %r4
#define LEN %r5
ENTRY(_copyinstr)
ldcr %r6, CPU
ld %r7, %r6, CI_CURPCB
or.u %r6, %r0, %hi16(Lcisflt)
or %r6, %r6, %lo16(Lcisflt)
st %r6, %r7, PCB_ONFAULT
or %r6, %r0, 0
bcnd lt0, CNT, Lcisflt
bcnd eq0, CNT, Lcistoolong
1:
#ifdef ERRATA__XXX_USR
NOP
ld.bu.usr %r7, SRC, %r6
NOP
NOP
NOP
#else
ld.bu.usr %r7, SRC, %r6
#endif
st.b %r7, DEST, %r6
bcnd.n eq0, %r7, 2f
addu %r6, %r6, 1
cmp %r7, %r6, CNT
bb1 lt, %r7, 1b
ASLOCAL(Lcistoolong)
or %r2, %r0, ENAMETOOLONG
ASLOCAL(Lcisnull)
bcnd eq0,%r6, Lcisdone
subu %r6, %r6, 1
st.b %r0, DEST, %r6
br.n Lcisdone
addu %r6, %r6, 1
2:
or %r2, %r0, 0
ASLOCAL(Lcisdone)
bcnd eq0, LEN, 3f
st %r6, %r0, LEN
3:
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
jmp.n %r1
st %r0, %r6, PCB_ONFAULT
ASLOCAL(Lcisflt)
br.n Lcisnull
or %r2, %r0, EFAULT
#undef SRC
#undef DEST
#undef CNT
#undef LEN
#define SRC %r2
#define DEST %r3
#define LEN %r4
ENTRY(copyout)
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
or.u %r5, %r0, %hi16(Lcoflt)
or %r5, %r5, %lo16(Lcoflt)
st %r5, %r6, PCB_ONFAULT
cmp %r9, LEN, 8
bb1 lt, %r9, copyout_byte_only
xor %r9, SRC, DEST
mask %r8, %r9, 0x3
bcnd ne0, %r8, copyout_byte_only
bb1 0, SRC, copyout_left_align_to_halfword
ASLOCAL(copyout_left_aligned_to_halfword)
bb1 1, SRC, copyout_left_align_to_word
ASLOCAL(copyout_left_aligned_to_word)
bb1 0, LEN, copyout_right_align_to_halfword
ASLOCAL(copyout_right_aligned_to_halfword)
bb1 1, LEN, copyout_right_align_to_word
ASLOCAL(copyout_right_aligned_to_word)
bb1.n 2, LEN, copyout_right_align_to_doubleword
or %r7, %r0, 4
ASLOCAL(copyout_right_aligned_to_doubleword)
ld %r5, SRC, %r0
ld %r6, SRC, %r7
subu LEN, LEN, 8
#ifdef ERRATA__XXX_USR
NOP
st.usr %r5, DEST, %r0
NOP
NOP
NOP
#else
st.usr %r5, DEST, %r0
#endif
addu SRC, SRC, 8
#ifdef ERRATA__XXX_USR
NOP
st.usr %r6, DEST, %r7
NOP
NOP
NOP
#else
st.usr %r6, DEST, %r7
#endif
bcnd.n ne0, LEN, copyout_right_aligned_to_doubleword
addu DEST, DEST, 8
or %r2, %r0, %r0
br Lcodone
ASLOCAL(copyout_left_align_to_halfword)
ld.b %r5, SRC, %r0
subu LEN, LEN, 1
#ifdef ERRATA__XXX_USR
NOP
st.b.usr %r5, DEST, %r0
NOP
NOP
NOP
#else
st.b.usr %r5, DEST, %r0
#endif
addu SRC, SRC, 1
br.n copyout_left_aligned_to_halfword
addu DEST, DEST, 1
ASLOCAL(copyout_left_align_to_word)
ld.h %r5, SRC, %r0
subu LEN, LEN, 2
#ifdef ERRATA__XXX_USR
NOP
st.h.usr %r5, DEST, %r0
NOP
NOP
NOP
#else
st.h.usr %r5, DEST, %r0
#endif
addu SRC, SRC, 2
br.n copyout_left_aligned_to_word
addu DEST, DEST, 2
ASLOCAL(copyout_right_align_to_halfword)
subu LEN, LEN, 1
ld.b %r5, SRC, LEN
#ifdef ERRATA__XXX_USR
NOP
st.b.usr %r5, DEST, LEN
NOP
NOP
NOP
br copyout_right_aligned_to_halfword
#else
br.n copyout_right_aligned_to_halfword
st.b.usr %r5, DEST, LEN
#endif
ASLOCAL(copyout_right_align_to_word)
subu LEN, LEN, 2
ld.h %r5, SRC, LEN
#ifdef ERRATA__XXX_USR
NOP
st.h.usr %r5, DEST, LEN
NOP
NOP
NOP
br copyout_right_aligned_to_word
#else
br.n copyout_right_aligned_to_word
st.h.usr %r5, DEST, LEN
#endif
ASLOCAL(copyout_right_align_to_doubleword)
subu LEN, LEN, 4
ld %r5, SRC, LEN
#ifdef ERRATA__XXX_USR
NOP
st.usr %r5, DEST, LEN
NOP
NOP
NOP
bcnd ne0, LEN, copyout_right_aligned_to_doubleword
#else
bcnd.n ne0, LEN, copyout_right_aligned_to_doubleword
st.usr %r5, DEST, LEN
#endif
br.n Lcodone
or %r2, %r0, %r0
ASLOCAL(copyout_byte_only)
bcnd eq0, LEN, 2f
1:
subu LEN, LEN, 1
ld.b %r5, SRC, LEN
#ifdef ERRATA__XXX_USR
NOP
st.b.usr %r5, DEST, LEN
NOP
NOP
NOP
bcnd ne0, LEN, 1b
#else
bcnd.n ne0, LEN, 1b
st.b.usr %r5, DEST, LEN
#endif
2:
or %r2, %r0, %r0
ASLOCAL(Lcodone)
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
jmp.n %r1
st %r0, %r6, PCB_ONFAULT
ASLOCAL(Lcoflt)
br.n Lcodone
or %r2, %r0, EFAULT
#undef SRC
#undef DEST
#undef LEN
#define SRC %r2
#define DEST %r3
#define CNT %r4
#define LEN %r5
ENTRY(copyoutstr)
ldcr %r6, CPU
ld %r7, %r6, CI_CURPCB
or.u %r6, %r0, %hi16(Lcosflt)
or %r6, %r6, %lo16(Lcosflt)
st %r6, %r7, PCB_ONFAULT
bcnd lt0, CNT, Lcosflt
bcnd eq0, CNT, 2f
or %r6, %r0, 0
1:
ld.bu %r7, SRC, %r6
#ifdef ERRATA__XXX_USR
NOP
st.b.usr %r7, DEST, %r6
NOP
NOP
NOP
#else
st.b.usr %r7, DEST, %r6
#endif
bcnd.n eq0, %r7, 3f
addu %r6, %r6, 1
cmp %r7, %r6, CNT
bb1 lt, %r7, 1b
2:
br.n Lcosdone
or %r2, %r0, ENAMETOOLONG
3:
br.n Lcosdone
or %r2, %r0, 0
ASLOCAL(Lcosflt)
br.n Lcosdone
or %r2, %r0, EFAULT
ASLOCAL(Lcosdone)
bcnd eq0, LEN, 3f
st %r6, %r0, LEN
3:
ldcr %r5, CPU
ld %r6, %r5, CI_CURPCB
jmp.n %r1
st %r0, %r6, PCB_ONFAULT
#undef SRC
#undef DEST
#undef CNT
#undef LEN
ENTRY(kcopy)
subu %r31, %r31, 16
ldcr %r5, CPU
st %r1, %r31, 4
ld %r6, %r5, CI_CURPCB
or.u %r8, %r0, %hi16(kcopy_fault)
ld %r7, %r6, PCB_ONFAULT
or %r8, %r8, %lo16(kcopy_fault)
st %r7, %r31, 0
st %r8, %r6, PCB_ONFAULT
bsr.n bcopy
addu %r1, %r1, 1f - . - 4
1:
or %r2, %r0, 0
ASLOCAL(kcopy_out_fault)
ld %r1, %r31, 4
ldcr %r5, CPU
ld %r7, %r31, 0
ld %r6, %r5, CI_CURPCB
addu %r31, %r31, 16
jmp.n %r1
st %r7, %r6, PCB_ONFAULT
ASLOCAL(kcopy_fault)
br.n kcopy_out_fault
or %r2, %r0, EFAULT
#ifdef DDB
ENTRY(setjmp)
st %r1, %r2, 0
st %r14, %r2, 4
st %r15, %r2, 2*4
st %r16, %r2, 3*4
st %r17, %r2, 4*4
st %r18, %r2, 5*4
st %r19, %r2, 6*4
st %r20, %r2, 7*4
st %r21, %r2, 8*4
st %r22, %r2, 9*4
st %r23, %r2, 10*4
st %r24, %r2, 11*4
st %r25, %r2, 12*4
st %r26, %r2, 13*4
st %r27, %r2, 14*4
st %r28, %r2, 15*4
st %r29, %r2, 16*4
st %r30, %r2, 17*4
st %r31, %r2, 18*4
jmp.n %r1
or %r2, %r0, %r0
ENTRY(longjmp)
ld %r1, %r2, 0
ld %r14, %r2, 4
ld %r15, %r2, 2*4
ld %r16, %r2, 3*4
ld %r17, %r2, 4*4
ld %r18, %r2, 5*4
ld %r19, %r2, 6*4
ld %r20, %r2, 7*4
ld %r21, %r2, 8*4
ld %r22, %r2, 9*4
ld %r23, %r2, 10*4
ld %r24, %r2, 11*4
ld %r25, %r2, 12*4
ld %r26, %r2, 13*4
ld %r27, %r2, 14*4
ld %r28, %r2, 15*4
ld %r29, %r2, 16*4
ld %r30, %r2, 17*4
ld %r31, %r2, 18*4
jmp.n %r1
or %r2, %r0, 1
#endif
.section .rodata
.align 3
.type sigcode,@function
GLOBAL(sigcode)
ld %r2, %r31, 0
or %r13, %r0, SYS_sigreturn
GLOBAL(sigcodecall)
GLOBAL(sigcoderet)
tb0 0, %r0, 450
NOP | failure return
#ifdef dontbother
NOP | success return
#endif
GLOBAL(esigcode)
GLOBAL(sigfill)
tb0 0, %r0, 130
GLOBAL(sigfillsiz)
.word sigfillsiz - sigfill
#ifdef M88100
ENTRY(m8820x_copypage)
addu %r12, %r2, PAGE_SIZE
1:
ld.d %r4, %r2, 0x00
ld.d %r6, %r2, 0x08
st.d %r4, %r3, 0x00
ld.d %r8, %r2, 0x10
st.d %r6, %r3, 0x08
ld.d %r10, %r2, 0x18
st.d %r8, %r3, 0x10
addu %r2, %r2, 0x20
st.d %r10, %r3, 0x18
cmp %r4, %r2, %r12
bb1.n ne, %r4, 1b
addu %r3, %r3, 0x20
jmp %r1
ENTRY(m8820x_zeropage)
addu %r12, %r2, PAGE_SIZE
or %r3, %r1, %r0
or %r1, %r0, %r0
1:
st.d %r0, %r2, 0x00
st.d %r0, %r2, 0x08
st.d %r0, %r2, 0x10
st.d %r0, %r2, 0x18
st.d %r0, %r2, 0x20
st.d %r0, %r2, 0x28
st.d %r0, %r2, 0x30
st.d %r0, %r2, 0x38
addu %r2, %r2, 0x40
cmp %r4, %r2, %r12
bb1 ne, %r4, 1b
jmp %r3
#endif
#ifdef M88110
ENTRY(m88110_copypage)
addu %r12, %r2, PAGE_SIZE
1:
ld.h %r0, %r3, 0x00 | load allocate
ld.d %r4, %r2, 0x00
ld.d %r6, %r2, 0x08
st.d %r4, %r3, 0x00
ld.d %r8, %r2, 0x10
st.d %r6, %r3, 0x08
ld.d %r10, %r2, 0x18
st.d %r8, %r3, 0x10
addu %r2, %r2, 0x20
st.d %r10, %r3, 0x18
cmp %r4, %r2, %r12
addu %r3, %r3, 0x20
bb1 ne, %r4, 1b
jmp %r1
ENTRY(m88110_zeropage)
addu %r12, %r2, PAGE_SIZE
or %r3, %r1, %r0
or %r1, %r0, %r0
1:
ld.h %r0, %r2, 0x00 | load allocate
st.d %r0, %r2, 0x00
st.d %r0, %r2, 0x08
st.d %r0, %r2, 0x10
st.d %r0, %r2, 0x18
addu %r2, %r2, 0x20
cmp %r4, %r2, %r12
bb1 ne, %r4, 1b
jmp %r3
#endif
ASENTRY(setup_psr)
#if defined(M88100)
#if defined(M88110)
ldcr %r2, PID
bb1 8, %r2, 1f
#endif
stcr %r0, SSBR
1:
#endif
stcr %r0, SR1
or.u %r2, %r0, %hi16(KERNEL_PSR)
or %r2, %r2, %lo16(KERNEL_PSR)
stcr %r2, PSR
FLUSH_PIPELINE
jmp %r1
GLOBAL(set_vbr)
ldcr %r3, PSR
set %r4, %r3, 1<PSR_INTERRUPT_DISABLE_BIT>
set %r4, %r4, 1<PSR_SHADOW_FREEZE_BIT>
stcr %r4, PSR
FLUSH_PIPELINE
stcr %r2, VBR
FLUSH_PIPELINE
#if defined(M88100) && defined(M88110)
ldcr %r2, PID
bb1 8, %r2, 1f
#endif
#ifdef M88100
stcr %r3, PSR
FLUSH_PIPELINE
jmp %r1
#endif
#ifdef M88110
1:
stcr %r1, EXIP
stcr %r3, EPSR
RTE
#endif