.globl dcache_flush
dcache_flush:
	cmplwi 4, 0   # zero or negative size?
	blelr
	clrlwi. 5, 3, 27  # check for lower bits set in address
	beq 1f
	addi 4, 4, 0x20 
1:
	addi 4, 4, 0x1f
	srwi 4, 4, 5
	mtctr 4
2:
	dcbst 0, 3
	addi 3, 3, 0x20
	bdnz 2b
	blr

.globl dcache_inv
dcache_inv:
	cmplwi 4, 0   # zero or negative size?
	blelr
	clrlwi. 5, 3, 27  # check for lower bits set in address
	beq 1f
	addi 4, 4, 0x20 
1:
	addi 4, 4, 0x1f
	srwi 4, 4, 5
	mtctr 4
2:
	dcbi 0, 3
	addi 3, 3, 0x20
	bdnz 2b
	blr

.globl flush_code
flush_code:
	lis 5, 0xFFFF
	ori 5, 5, 0xFFF1
	and 5, 5, 3
	subf 3, 5, 3
	add 4, 4, 3
1:
	dcbst 0, 5
	sync
	icbi 0, 5
	addic 5, 5, 8
	subic. 4, 4, 8
	bge 1b
	isync
	blr

.globl GetMSR
GetMSR:
    mfmsr 3
    blr

.globl SetMSR
SetMSR:
    mtmsr 3
    blr

.globl GetLinkRegister
GetLinkRegister:
    mflr 3
    blr

.globl GetStackPointer
GetStackPointer:
    mr 3,1
    blr

.globl GetTime
GetTime:
__Time_GetTime_Loop:
    mftbu 	3
    mftb 	4
    mftbu 	5
    cmpw	3,5
    bne    __Time_GetTime_Loop
    blr

.globl LGetTime
LGetTime:
_L_Time_GetTime_Loop:
    mftbu 	3
    mftb 	4
    mftbu 	5
    cmpw	3,5
    bne    _L_Time_GetTime_Loop
    blr
