/*
 * Copyright 2015, Cyril Bur, IBM Corp.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include "basic_asm.h"
#include "vsx_asm.h"

#long check_vsx(vector int *r3);
#This function wraps storeing VSX regs to the end of an array and a
#call to a comparison function in C which boils down to a memcmp()
FUNC_START(check_vsx)
	PUSH_BASIC_STACK(32)
	std	r3,STACK_FRAME_PARAM(0)(sp)
	addi r3, r3, 16 * 12 #Second half of array
	bl store_vsx
	ld r3,STACK_FRAME_PARAM(0)(sp)
	bl vsx_memcmp
	POP_BASIC_STACK(32)
	blr
FUNC_END(check_vsx)

# int preempt_vmx(vector int *varray, int *threads_starting,
#                 int *running);
# On starting will (atomically) decrement threads_starting as a signal
# that the VMX have been loaded with varray. Will proceed to check the
# validity of the VMX registers while running is not zero.
FUNC_START(preempt_vsx)
	PUSH_BASIC_STACK(512)
	std r3,STACK_FRAME_PARAM(0)(sp) # vector int *varray
	std r4,STACK_FRAME_PARAM(1)(sp) # int *threads_starting
	std r5,STACK_FRAME_PARAM(2)(sp) # int *running

	bl load_vsx
	nop

	sync
	# Atomic DEC
	ld r3,STACK_FRAME_PARAM(1)(sp)
1:	lwarx r4,0,r3
	addi r4,r4,-1
	stwcx. r4,0,r3
	bne- 1b

2:	ld r3,STACK_FRAME_PARAM(0)(sp)
	bl check_vsx
	nop
	cmpdi r3,0
	bne 3f
	ld r4,STACK_FRAME_PARAM(2)(sp)
	ld r5,0(r4)
	cmpwi r5,0
	bne 2b

3:	POP_BASIC_STACK(512)
	blr
FUNC_END(preempt_vsx)
'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>refs</a><a class='active' href='/cgit.cgi/linux/net-next.git/log/sound/usb/6fire/firmware.h?h=nds-private-remove'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/sound/usb/6fire/firmware.h?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/sound/usb/6fire/firmware.h?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/sound/usb/6fire/firmware.h?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/sound/usb/6fire/firmware.h'>
<input type='hidden' name='h' value='nds-private-remove'/><input type='hidden' name='id' value='a79a5276aa2f844bd368c1d3d5a625e1fbefd989'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>sound</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/usb?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>usb</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/usb/6fire?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>6fire</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/usb/6fire/firmware.h?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989'>firmware.h</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/sound/usb/6fire/firmware.h?h=nds-private-remove&amp;id=a79a5276aa2f844bd368c1d3d5a625e1fbefd989&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>