#include "assym.h"
#include <sys/asm_linkage.h>
#include <sys/hypervisor_api.h>
#include <sys/machasi.h>
#include <sys/machpcb.h>
#include <sys/machlock.h>
#include <sys/mmu.h>
#include <sys/lpad.h>
ENTRY_NP(mach_cpu_startup)
rd %pc, %l0
add %l0, LPAD_TEXT_SIZE, %l1 ! %l1 has start of data
wrpr %g0, 0, %tl
wrpr %g0, 0, %gl
wrpr %g0, MAXWIN - 2, %cansave
wrpr %g0, MAXWIN - 2, %cleanwin
wrpr %g0, 0, %canrestore
wrpr %g0, 0, %otherwin
wrpr %g0, 0, %cwp
wrpr %g0, 0, %wstate
wr %g0, %y
wrpr %g0, PIL_MAX, %pil
set trap_table, %g1
wrpr %g1, %tba
! initialize cpuid into scratchpad register
mov SCRATCHPAD_CPUID, %g1
stxa %o0, [%g1]ASI_SCRATCHPAD
! sanity check the data section
setx LPAD_MAGIC_VAL, %g2, %g1
ldx [%l1 + LPAD_MAGIC], %g2
cmp %g1, %g2
bne startup_error
nop
ldx [%l1 + LPAD_NMAP], %l2 ! %l2 = number of mappings
add %l1, LPAD_MAP, %l3 ! %l3 = the current mapping
mulx %l2, LPAD_MAP_SIZE, %g1
add %l3, %g1, %g1 ! %g1 = end of the array
add %l1, LPAD_DATA_SIZE, %g2 ! %g2 = end of data section
sub %g2, %g1, %g2
brlz %g2, startup_error
nop
0:
cmp %l2, %g0
be 3f
nop
ldx [%l3 + LPAD_MAP_FLAGS], %l4 ! %l4 = flags
ldx [%l3 + LPAD_MAP_VA], %o0 ! %o0 = virtual address
mov KCONTEXT, %o1 ! %o1 = context
ldx [%l3 + LPAD_MAP_TTE], %o2 ! %o2 = TTE
and %l4, FLAG_MMUFLAGS_MASK, %o3 ! %o3 = MMU flags
! check if this is a locked TTE
and %l4, FLAG_LOCK_MASK, %l4
cmp %l4, %g0
bne 1f
nop
! install an unlocked entry
ta MMU_MAP_ADDR
ba 2f
nop
1:
! install a locked entry
mov MAP_PERM_ADDR, %o5
ta FAST_TRAP
2:
! check for errors from the hcall
cmp %o0, %g0
bne startup_error
nop
sub %l2, 1, %l2 ! decrement counter
add %l3, LPAD_MAP_SIZE, %l3 ! increment pointer
ba 0b
nop
3:
ldx [%l1 + LPAD_MMFSA_RA], %o0
mov MMU_SET_INFOPTR, %o5
ta FAST_TRAP
! check for errors from the hcall
cmp %o0, %g0
bne startup_error
nop
ldx [%l1 + LPAD_PC], %l3 ! %l3 = specified entry point
ldx [%l1 + LPAD_ARG], %l4 ! %l4 = specified argument
ldx [%l1 + LPAD_INUSE], %l5 ! %l5 = va of inuse mailbox
mov 1, %o0 ! %o0 = enable flag (1 = enable)
set startup_complete, %o1 ! VA of return address
mov MMU_ENABLE, %o5
ta FAST_TRAP
startup_error:
ba startup_error
nop
startup_complete:
mov %l4, %o0
jmpl %l3, %g0
stx %g0, [%l5] ! clear the inuse mailbox
SET_SIZE(mach_cpu_startup)
.global mach_cpu_startup_end
mach_cpu_startup_end: