#define _LOCORE
#include <machine/param.h>
#include <machine/asm.h>
#include <machine/psl.h>
#define CCFSZ 96
.file "str0.s"
.comm _C_LABEL(romp), 4
.comm _C_LABEL(cputyp), 4
.comm _C_LABEL(nbpg), 4
.comm _C_LABEL(pgofset), 4
.comm _C_LABEL(pgshift), 4
.text
.globl start
start:
set start, %o1
save %o1, -CCFSZ, %sp
1: call 2f
sethi %hi(1b), %l0
2: or %l0, %lo(1b), %l0
cmp %l0, %o7 ! %o7 contains actual address of 1b
beq 4f ! already there, no need to relocate
nop
add %o7, (start-1b), %l0
set start, %l1
set _edata, %o0
sub %o0, %l1, %l2 ! length
3: ld [%l0], %o0
add %l0, 4, %l0
st %o0, [%l1]
subcc %l2, 4, %l2
bg 3b
add %l1, 4, %l1
set 4f, %g1
jmp %g1
nop
4:
#ifdef notyet
wr %g0, 0, %wim ! make sure we can set psr
nop; nop; nop
wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
nop; nop; nop
wr %g0, 2, %wim ! set initial %wim (w1 invalid)
rd %psr, %l0
wr %l0, PSR_ET, %psr
nop; nop; nop
#endif
set _edata, %o0 ! bzero(edata, end - edata)
1: ! check if %o0 is well aligned
andcc %o0, 3, %o2
bz 2f
nop
stb %g0, [%o0]
b 1b
add %o0, 1, %o0
2: ! now we have %o0 4 byte aligned
set _end, %o1
subcc %o1, %o0, %o1
bz 2f ! in case there is no BSS
srl %o1, 2, %o1 ! we do 4 byte writes now
1:
st %g0, [%o0] ! while (n--)
subcc %o1, 1, %o1 ! *p = 0; etc..
bnz 1b
add %o0, 4, %o0
2:
rd %psr, %o0
andn %o0, PSR_PIL, %o0
wr %o0, 0xb00, %psr ! (11 << 8)
nop; nop; nop
sethi %hi(_C_LABEL(cputyp)), %o0
set 0x4000, %g7
cmp %i0, %g7
beq is_sun4
nop
mov CPU_SUN4C, %g4
mov SUN4CM_PGSHIFT, %g5
cmp %i0, 0
be is_openfirm
nop
! save address of PROM vector
sethi %hi(_C_LABEL(romp)), %o1
st %i0, [%o1 + %lo(_C_LABEL(romp))]
b,a is_sun4cm
is_openfirm:
! only javastations have OFW, so we know it is a sun4m
mov CPU_SUN4M, %g4
! save address of OpenFirmware client interface handler
sethi %hi(_C_LABEL(romp)), %o1
st %i3, [%o1 + %lo(_C_LABEL(romp))]
b,a is_sun4cm
is_sun4:
mov CPU_SUN4, %g4
mov SUN4_PGSHIFT, %g5
is_sun4cm:
st %g4, [%o0 + %lo(_C_LABEL(cputyp))]
sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg)
st %g5, [%o0 + %lo(_C_LABEL(pgshift))]
mov 1, %o0 ! nbpg = 1 << pgshift
sll %o0, %g5, %g5
sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page
st %g5, [%o0 + %lo(_C_LABEL(nbpg))]
sub %g5, 1, %g5
sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = nbpg - 1
st %g5, [%o0 + %lo(_C_LABEL(pgofset))]
call _C_LABEL(main)
mov %i0, %o0
ret
restore
ENTRY(sparc_noop)
retl
nop
ENTRY(openfirmware)
sethi %hi(_C_LABEL(romp)), %o1
ld [%o1 + %lo(_C_LABEL(romp))], %o2
jmp %o2
nop
#ifdef TIGHT
.align 4
.global .div, .udiv
! int n = 0; while (a >= b) { a -= b; n++; }; return n;
.div:
.udiv:
cmp %o0, %o1
bl 2f
mov 0, %o5
1:
sub %o0, %o1, %o0
cmp %o0, %o1
bge 1b
add %o5, 1, %o5
2:
retl
mov %o5, %o0
.align 4
.global .rem, .urem
! while (a>=b) a -= b; return a;
.rem:
.urem:
cmp %o0, %o1
bl 2f
nop
sub %o0, %o1, %o0
1:
cmp %o0, %o1
bge,a 1b
sub %o0, %o1, %o0
2:
retl
nop
#endif