1152219Simp/*-
2152219Simp * Copyright (c) 2005 Rink Springer
3152219Simp * All rights reserved.
4152219Simp *
5152219Simp * Redistribution and use in source and binary forms, with or without
6152219Simp * modification, are permitted provided that the following conditions
7152219Simp * are met:
8152219Simp * 1. Redistributions of source code must retain the above copyright
9152219Simp *    notice, this list of conditions and the following disclaimer.
10152219Simp * 2. Redistributions in binary form must reproduce the above copyright
11152219Simp *    notice, this list of conditions and the following disclaimer in the
12152219Simp *    documentation and/or other materials provided with the distribution.
13152219Simp * 3. The name of the author may not be used to endorse or promote products
14152219Simp *    derived from this software without specific prior written permission
15152219Simp *
16152219Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17152219Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18152219Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19152219Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20152219Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21152219Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22152219Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23152219Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24152219Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25152219Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26152219Simp *
27152219Simp * $FreeBSD: releng/10.2/sys/i386/xbox/pic16l.s 152219 2005-11-09 03:55:40Z imp $
28152219Simp */
29152219Simp#include <machine/asmacros.h>
30152219Simp
31152219Simp.text
32152219Simp
33152219Simp/*
34152219Simp * send a command to the PIC16L
35152219Simp *
36152219Simp * void pic16l_setbyte (int addr, int reg, int data)
37152219Simp *
38152219Simp */
39152219SimpENTRY(pic16l_setbyte)
40152219Simp	push	%ebp
41152219Simp	mov	%esp,%ebp
42152219Simp
43152219Simp	push	%ebx
44152219Simp
45152219Simp	movw	$0xc000,%dx
46152219Simp
47152219Simp1:	xor	%eax,%eax
48152219Simp	inw	%dx,%ax
49152219Simp	shr	$0x0b,%eax
50152219Simp	and	$0x01,%eax
51152219Simp	test	%eax,%eax
52152219Simp	jne	1b
53152219Simp
54152219Simp	mov	$50,%ecx
55152219Simp2:	movw	$0xc004,%dx
56152219Simp	movl	0x8(%ebp),%eax
57152219Simp	outb	%al,%dx
58152219Simp	movw	$0xc008,%dx
59152219Simp	movl	0xc(%ebp),%eax
60152219Simp	outb	%al,%dx
61152219Simp	movw	$0xc006,%dx
62152219Simp	movl	0x10(%ebp),%eax
63152219Simp	outw	%ax,%dx
64152219Simp
65152219Simp	movw	$0xc000,%dx
66152219Simp	inw 	%dx,%ax
67152219Simp	outw	%ax,%dx
68152219Simp
69152219Simp	movw	$0xc002,%dx
70152219Simp	movb	$0x1a,%al
71152219Simp	outb	%al,%dx
72152219Simp
73152219Simp	movw	$0xc000,%dx
74152219Simp3:
75152219Simp	inb 	%dx,%al
76152219Simp	movb	%al,%bl
77152219Simp	orb 	$0x36,%al
78152219Simp	jz  	3b
79152219Simp
80152219Simp	orb 	$0x10,%bl
81152219Simp	jnz  	5f
82152219Simp
83152219Simp4:
84152219Simp	push	%ecx
85152219Simp	xor	%ecx,%ecx
86152219Simpl:	loop	l
87152219Simp	pop	%ecx
88152219Simp
89152219Simp	dec	%ecx
90152219Simp	jz	5f
91152219Simp	jmp	2b
92152219Simp5:
93152219Simp
94152219Simp	pop	%ebx
95152219Simp
96152219Simp	leave
97152219Simp	ret
98152219Simp
99152219Simp/*
100152219Simp * instructs the pic16l to reboot the xbox
101152219Simp *
102152219Simp * void pic16l_reboot();
103152219Simp *
104152219Simp */
105152219SimpENTRY(pic16l_reboot)
106152219Simp	pushl	$0x01
107152219Simp	pushl	$0x02
108152219Simp	pushl	$0x20
109152219Simp	call	pic16l_setbyte
110152219Simp	addl	$12,%esp
111152219Simp	ret
112152219Simp
113152219Simp/*
114152219Simp * instructs the pic16l to power-off the xbox
115152219Simp *
116152219Simp * void pic16l_poweroff();
117152219Simp *
118152219Simp */
119152219SimpENTRY(pic16l_poweroff)
120152219Simp	pushl	$0x80
121152219Simp	pushl	$0x02
122152219Simp	pushl	$0x20
123152219Simp	call	pic16l_setbyte
124152219Simp	addl	$12,%esp
125152219Simp	ret
126152219Simp
127152219Simppic16l_ledhlp:
128152219Simp	movw	$0xc000,%dx
129152219Simp1:	xor	%eax,%eax
130152219Simp	inw	%dx,%ax
131152219Simp	shr	$0x0b,%eax
132152219Simp	and	$0x01,%eax
133152219Simp	test	%eax,%eax
134152219Simp	jne	1b
135152219Simp
136152219Simp	mov	$400,%ecx
137152219Simp
138152219Simp2:
139152219Simp	movw	$0xc004,%dx
140152219Simp	movb	$0x20,%al
141152219Simp	outb	%al,%dx
142152219Simp
143152219Simp	movw	$0xc008,%dx
144152219Simp	movb	%bh,%al
145152219Simp	outb	%al,%dx
146152219Simp
147152219Simp	movw	$0xc006,%dx
148152219Simp	movb	%bl,%al
149152219Simp	outb	%al,%dx
150152219Simp
151152219Simp	movw	$0xc000,%dx
152152219Simp	inw 	%dx,%ax
153152219Simp	outw	%ax,%dx
154152219Simp
155152219Simp	movw	$0xc002,%dx
156152219Simp	movb	$0x1a,%al
157152219Simp	outb	%al,%dx
158152219Simp
159152219Simp	movw	$0xc000,%dx
160152219Simp3:
161152219Simp	inb 	%dx,%al
162152219Simp	movb	%al,%bl
163152219Simp	orb 	$0x36,%al
164152219Simp	jz  	3b
165152219Simp
166152219Simp	orb 	$0x10,%bl
167152219Simp	jz  	4f
168152219Simp
169152219Simp	ret
170152219Simp
171152219Simp4:
172152219Simp	push	%ecx
173152219Simp	xor	%ecx,%ecx
174152219Simpl2:	loop	l2
175152219Simp	pop	%ecx
176152219Simp	dec	%ecx
177152219Simp	jz	5f
178152219Simp	jmp	2b
179152219Simp5:
180152219Simp	ret
181152219Simp
182152219Simp/*
183152219Simp * changes the front led
184152219Simp *
185152219Simp * void pic16l_setled (int val);
186152219Simp */
187152219SimpENTRY(pic16l_setled)
188152219Simp	push	%ebp
189152219Simp	mov	%esp,%ebp
190152219Simp
191152219Simp	push	%ebx
192152219Simp
193152219Simp	movl	0x8(%ebp),%ebx
194152219Simp	orl	$0x800,%ebx
195152219Simp	call	pic16l_ledhlp
196152219Simp	movl	$0x701,%ebx
197152219Simp	call	pic16l_ledhlp
198152219Simp
199152219Simp	pop	%ebx
200152219Simp
201152219Simp	leave
202152219Simp	ret
203