# fr30 testcase for
# mach(): fr30
# ld $Rj,$Ri
# ld @($R13,$Rj),$Ri
# ld @($R14,$disp10),$Ri
# ld @($R15,$udisp6),$Ri
# ld @$R15+,$Ri
# ld @$R15+,$Rs

	.include "testutils.inc"

	START

	.text
	.global ld
ld:
	; Test ld $Rj,$Ri
	mvi_h_mem	#0x00000000,sp
	set_cc          0x0f		; condition codes should not change
	ld		@sp,r7
	test_cc		1 1 1 1
	test_h_gr  	0,r7

	mvi_h_mem	#0x00000001,sp
	set_cc          0x07		; condition codes should not change
	ld    		@sp,r7
	test_cc		0 1 1 1
	test_h_gr  	1,r7

	mvi_h_mem	#0x7fffffff,sp
	set_cc          0x0b		; condition codes should not change
	ld		@sp,r7
	test_cc		1 0 1 1
	test_h_gr  	0x7fffffff,r7

	mvi_h_mem	#0x80000000,sp
	set_cc          0x0d		; condition codes should not change
	ld      	@sp,r7
	test_cc		1 1 0 1
	test_h_gr  	0x80000000,r7

	mvi_h_mem	#0xffffffff,sp
	set_cc          0x0e		; condition codes should not change
	ld		@sp,r7
	test_cc		1 1 1 0
	test_h_gr  	-1,r7

	; Test ld @($R13,$Rj),$Ri
	mvr_h_gr	sp,r13
	inci_h_gr	-8,r13
	mvi_h_gr	8,r8

	mvi_h_mem	#0x00000000,sp
	set_cc          0x0f		; condition codes should not change
	ld		@(r13,r8),r7
	test_cc		1 1 1 1
	test_h_gr  	0,r7

	mvi_h_mem	#0x00000001,sp
	set_cc          0x07		; condition codes should not change
	ld    		@(r13,r8),r7
	test_cc		0 1 1 1
	test_h_gr  	1,r7

	mvi_h_mem	#0x7fffffff,sp
	set_cc          0x0b		; condition codes should not change
	ld		@(r13,r8),r7
	test_cc		1 0 1 1
	test_h_gr  	0x7fffffff,r7

	mvi_h_mem	#0x80000000,sp
	set_cc          0x0d		; condition codes should not change
	ld      	@(r13,r8),r7
	test_cc		1 1 0 1
	test_h_gr  	0x80000000,r7

	mvi_h_mem	#0xffffffff,sp
	set_cc          0x0e		; condition codes should not change
	ld		@(r13,r8),r7
	test_cc		1 1 1 0
	test_h_gr  	-1,r7

	; Test ld @($R14,$disp10),$Ri
	mvi_h_mem	#0xdeadbeef,sp
	mvr_h_gr	sp,r14
	mvi_h_gr	-0x1fc,r8
	add_h_gr	r8,r14

	set_cc          0x0f		; condition codes should not change
	ld		@(r14,0x1fc),r7
	test_cc		1 1 1 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0xfc,r14
	set_cc          0x07		; condition codes should not change
	ld    		@(r14,0x100),r7
	test_cc		0 1 1 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0x100,r14
	set_cc          0x0b		; condition codes should not change
	ld		@(r14,0x0),r7
	test_cc		1 0 1 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0x100,r14
	set_cc          0x0d		; condition codes should not change
	ld      	@(r14,-0x100),r7
	test_cc		1 1 0 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0x100,r14
	set_cc          0x0e		; condition codes should not change
	ld		@(r14,-0x200),r7
	test_cc		1 1 1 0
	test_h_gr  	0xdeadbeef,r7

	; Test ld @($R15,$udisp6),$Ri
	mvi_h_mem	#0xdeadbeef,sp
	mvr_h_gr	sp,r14
	mvi_h_gr	-0x3c,r8
	add_h_gr	r8,r14

	set_cc          0x0f		; condition codes should not change
	ld		@(r14,0x3c),r7
	test_cc		1 1 1 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0x1c,r14
	set_cc          0x07		; condition codes should not change
	ld    		@(r14,0x20),r7
	test_cc		0 1 1 1
	test_h_gr  	0xdeadbeef,r7

	inci_h_gr	0x20,r14
	set_cc          0x0b		; condition codes should not change
	ld		@(r14,0x0),r7
	test_cc		1 0 1 1
	test_h_gr  	0xdeadbeef,r7

	; Test ld @$R15+,$Ri
	mvr_h_gr	sp,r8		; save original stack pointer
	mvr_h_gr	r8,r9
	inci_h_gr	4,r9		; original stack pointer + 4
	mvi_h_mem	#0xdeadbeef,sp	; prime memory

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,r7
	test_cc		1 1 1 1
	test_h_gr  	0xdeadbeef,r7
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,sp
	test_cc		1 1 1 1
	test_h_gr  	0xdeadbeef,sp	; should not have been incremented

	; Test ld @$R15+,$Rs
	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,tbr
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,tbr
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,rp
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,rp
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,mdh
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,mdh
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,mdl
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,mdl
	testr_h_gr	sp,r9		; should have been incremented

	set_s_user
	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,ssp
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,ssp
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,usp
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,usp
	test_h_gr	0xdeadbeef,sp	; should not have been incremented

	set_s_system
	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,usp
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,usp
	testr_h_gr	sp,r9		; should have been incremented

	mvr_h_gr	r8,sp		; restore original stack pointer
	set_cc          0x0f		; condition codes should not change
	ld		@r15+,ssp
	test_cc		1 1 1 1
	test_h_dr  	0xdeadbeef,ssp
	test_h_gr	0xdeadbeef,sp	; should not have been incremented

	pass
