shithub: powernv

ref: a691c9111a69257e206ce895d35396d0f6225929
dir: /l.s/

View raw version
#include "mem.h"

TEXT _main(SB), $-8
	MOVD	$0, R0
	MOVD	$setSB-KZERO(SB),R2

	MOVD	$0x1234567800000000, R11
	MOVD	$0x1, R12
	MOVD	$0x2, R13

	MOVD	R8,R13	/* opal BASE */
	MOVD	R9,R14	/* opal entry point */
	MOVD	R3,R15	/* device tree pointer */
	MOVD	R4,R8	/* where _main is now */

	/* Relocate our binary from here to where we want to be */
	MOVD	$_main-KZERO(SB), R9
	MOVD	$etext-KZERO(SB), R10
	MOVD	$0x0, R11
copy:
	MOVD	(R8), R5
	MOVD	R5, (R9)
	ADD	$8, R8
	ADD	$8, R9
	CMP	R9, R10
	BNE	copy

	ADD	$1,R11,R11
	CMP	R11,$0x2
	BEQ	bss

	/* Next part goes to DATA */
	MOVD	$bdata-KZERO(SB), R9
	MOVD	$edata-KZERO(SB), R10
	BR	copy

bss:
	/* Zero BSS */
	MOVD	R10, R9
	MOVD	$end-KZERO(SB), R10
bsscopy:
	CMP	R9, R10
	BEQ	done
	MOVD	R0, (R9)
	ADD	$8, R9
	BR	bsscopy

done:
	MOVD	R13, opalsb(SB)
	MOVD	R14, opalep(SB)
	MOVD	R15, devtree(SB)

	/* leap to new location */
	MOVD	$main-KZERO(SB),R11
	MOVD	R11,CTR
	BL	(CTR)
	MOVD	$setSB(SB), R2
park:
	BR	park


/* caller must have arguments in correct registers */
TEXT opalcall(SB), $0
	MOVD	$opalsb-KZERO(SB), R12
	MOVD	(R12), R12
	MOVD	$opalep-KZERO(SB), R13
	MOVD	(R13), R13

	/* load the shotgun */
	MOVD	R11,R0
	MOVD	R12,R2
	MOVD	R13,CTR
	BL	(CTR)

	/* unload the shotgun */
	MOVD	$0,R0
	MOVD	$setSB(SB),R2
	RETURN

TEXT opalshutdown(SB), $0
	MOVD	$0,R3
	MOVD	$5,R11
	BL	opalcall(SB)
	RETURN

TEXT opalconswr(SB), $0
	MOVD	R3,R5
	MOVD	$8(FP),R4
	MOVD	$0,R3
	MOVD	$1,R11
	BL	opalcall(SB)
	RETURN

TEXT opalconsrd(SB), $0
	MOVD	R3,R5
	MOVD	$8(FP),R4
	MOVD	$0,R3
	MOVD	$2,R11
	BL	opalcall(SB)
	RETURN

TEXT islo(SB), $0
	MOVD	MSR, R3
	RLWNM	$0, R3, $(MSR_EE>>32), R3
	RETURN

TEXT splhi(SB), $0
	MOVD	MSR, R3
	RLWNM	$0, R3, $((~MSR_EE)>>32), R4
	SYNC
	MOVD	R4, MSR
	SYNC
	RETURN

TEXT splx(SB), $0
	MOVD	MSR, R4
	RLWMI	$0, R3, $(MSR_EE>>32), R4
	SYNC
	MOVD	R4, MSR
	SYNC
	RETURN

TEXT spllo(SB), $0
	MOVD	MSR, R3
	MOVD	$MSR_EE, R5
	OR	R5, R3, R4
	SYNC
	MOVD	R4, MSR
	SYNC
	RETURN

TEXT coherence(SB), $0
	EIEIO
	RETURN

TEXT setlabel(SB), $-8
	MOVD	LR, R31
	MOVD	R1, 0(R3)
	MOVD	R31, 8(R3)
	MOVD	$0, R3
	RETURN

TEXT gotolabel(SB), $-8
	MOVD	8(R3), R31
	MOVD	R31, LR
	MOVD	0(R3), R1
	MOVD	$1, R3
	RETURN

TEXT returnto(SB), $-8
	MOVD	R3, 0(R1)
	RETURN

TEXT	_tas(SB), $0
TEXT	tas(SB), $0
	SYNC
	MOVD	R3, R4
	MOVWZ	$0xdeaddead,R5
tas1:	
	SYNC
	LWAR	(R4), R3
	CMP	R3, $0
	BNE	tas0
	STWCCC	R5, (R4)
	BNE	tas1
tas0:
	SYNC
	ISYNC
	RETURN

TEXT	cas(SB), $0
TEXT	cmpswap(SB), $0
	SYNC
	MOVD	ov+8(FP), R4
	MOVD	nv+8(FP), R5
cas1:
	SYNC
	LWAR	(R3), R4
	CMP	R4, R6
	BNE	cas0
	STWCCC	R5, (R3)
	BNE	cas1
	SYNC
	ISYNC
	MOVD	$1, R3
	RETURN
cas0:
	SYNC
	ISYNC
	MOVD	$0, R3
	RETURN

TEXT fpsaveregs(SB), $0
TEXT fpoff(SB), $0
TEXT fpon(SB), $0
TEXT fploadregs(SB), $0
TEXT idlehands(SB), $0
TEXT vcycles(SB), $0
TEXT noteret(SB), $0
	RETURN

DATA	opalsb(SB)/8, $0x00
GLOBL	opalsb(SB), $0x8
DATA	opalep(SB)/8, $0x00
GLOBL	opalep(SB), $0x8
DATA	devtree(SB)/8, $0x00
GLOBL	devtree(SB), $0x8