1/*- 2 * Copyright (c) 2005 Rink Springer 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29#include <machine/asmacros.h> 30 31.text 32 33/* 34 * send a command to the PIC16L 35 * 36 * void pic16l_setbyte (int addr, int reg, int data) 37 * 38 */ 39ENTRY(pic16l_setbyte) 40 push %ebp 41 mov %esp,%ebp 42 43 push %ebx 44 45 movw $0xc000,%dx 46 471: xor %eax,%eax 48 inw %dx,%ax 49 shr $0x0b,%eax 50 and $0x01,%eax 51 test %eax,%eax 52 jne 1b 53 54 mov $50,%ecx 552: movw $0xc004,%dx 56 movl 0x8(%ebp),%eax 57 outb %al,%dx 58 movw $0xc008,%dx 59 movl 0xc(%ebp),%eax 60 outb %al,%dx 61 movw $0xc006,%dx 62 movl 0x10(%ebp),%eax 63 outw %ax,%dx 64 65 movw $0xc000,%dx 66 inw %dx,%ax 67 outw %ax,%dx 68 69 movw $0xc002,%dx 70 movb $0x1a,%al 71 outb %al,%dx 72 73 movw $0xc000,%dx 743: 75 inb %dx,%al 76 movb %al,%bl 77 orb $0x36,%al 78 jz 3b 79 80 orb $0x10,%bl 81 jnz 5f 82 834: 84 push %ecx 85 xor %ecx,%ecx 86l: loop l 87 pop %ecx 88 89 dec %ecx 90 jz 5f 91 jmp 2b 925: 93 94 pop %ebx 95 96 leave 97 ret 98 99/* 100 * instructs the pic16l to reboot the xbox 101 * 102 * void pic16l_reboot(); 103 * 104 */ 105ENTRY(pic16l_reboot) 106 pushl $0x01 107 pushl $0x02 108 pushl $0x20 109 call pic16l_setbyte 110 addl $12,%esp 111 ret 112 113/* 114 * instructs the pic16l to power-off the xbox 115 * 116 * void pic16l_poweroff(); 117 * 118 */ 119ENTRY(pic16l_poweroff) 120 pushl $0x80 121 pushl $0x02 122 pushl $0x20 123 call pic16l_setbyte 124 addl $12,%esp 125 ret 126 127pic16l_ledhlp: 128 movw $0xc000,%dx 1291: xor %eax,%eax 130 inw %dx,%ax 131 shr $0x0b,%eax 132 and $0x01,%eax 133 test %eax,%eax 134 jne 1b 135 136 mov $400,%ecx 137 1382: 139 movw $0xc004,%dx 140 movb $0x20,%al 141 outb %al,%dx 142 143 movw $0xc008,%dx 144 movb %bh,%al 145 outb %al,%dx 146 147 movw $0xc006,%dx 148 movb %bl,%al 149 outb %al,%dx 150 151 movw $0xc000,%dx 152 inw %dx,%ax 153 outw %ax,%dx 154 155 movw $0xc002,%dx 156 movb $0x1a,%al 157 outb %al,%dx 158 159 movw $0xc000,%dx 1603: 161 inb %dx,%al 162 movb %al,%bl 163 orb $0x36,%al 164 jz 3b 165 166 orb $0x10,%bl 167 jz 4f 168 169 ret 170 1714: 172 push %ecx 173 xor %ecx,%ecx 174l2: loop l2 175 pop %ecx 176 dec %ecx 177 jz 5f 178 jmp 2b 1795: 180 ret 181 182/* 183 * changes the front led 184 * 185 * void pic16l_setled (int val); 186 */ 187ENTRY(pic16l_setled) 188 push %ebp 189 mov %esp,%ebp 190 191 push %ebx 192 193 movl 0x8(%ebp),%ebx 194 orl $0x800,%ebx 195 call pic16l_ledhlp 196 movl $0x701,%ebx 197 call pic16l_ledhlp 198 199 pop %ebx 200 201 leave 202 ret 203