added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / ppc-all / prep / kernel / io.c
blob2f050543c4a354b332e235ad93d04eddca685580
2 #include <aros/libcall.h>
3 #include <aros/asmcall.h>
5 #include <proto/exec.h>
6 #include <proto/kernel.h>
8 #include "kernel.h"
10 /*****************************************************************************
12 NAME */
14 AROS_LH1(APTR, BusToPhys,
16 /* SYNOPSIS */
17 AROS_LHA(APTR, busAddress, A0),
19 /* LOCATION */
20 APTR, KernelBase, 1, Kernel)
22 /* FUNCTION
23 This function translates Bus address (address that device sees) to
24 Physical address (address seen by CPU).
26 INPUTS
27 busAddress - Bus address as seen by device
29 RESULT
30 Physical address seen by CPU
32 *****************************************************************************/
34 AROS_LIBFUNC_INIT
36 return((APTR)((ULONG)busAddress+_BUS_BASE));
38 AROS_LIBFUNC_EXIT
44 /*****************************************************************************
46 NAME */
48 AROS_LH1(APTR, PhysToBus,
50 /* SYNOPSIS */
51 AROS_LHA(APTR, physAddress, A0),
53 /* LOCATION */
54 APTR, KernelBase, 2, Kernel)
56 /* FUNCTION
57 This function translates Physical address address (address seen by CPU)
58 to Bus address (address seen by device).
60 INPUTS
61 physAddress - Physical address as seen by CPU
63 RESULT
64 Bus address seen by device
66 *****************************************************************************/
68 AROS_LIBFUNC_INIT
70 return((APTR)((ULONG)physAddress+_BUS_BASE));
72 AROS_LIBFUNC_EXIT
76 /*****************************************************************************
78 IO access functions
80 These functions are the only allowable things used to communicate with IO
81 address space. Please note that theirs implementation is platform specific.
83 Also note, that allthough it might be possible to talk to hardware without
84 them, it doesn't have to be possible any time. It may happen, that
85 self-made IO access will end with program killed.
87 There is no description available for this functions, but there is no need
88 for any. Function names and parameters are self-explaining.
90 *****************************************************************************/
92 AROS_LH2(void, OutB,
93 AROS_LHA(UWORD, port, D0),
94 AROS_LHA(UBYTE, val, D1),
95 APTR, KernelBase, 3, Kernel)
97 AROS_LIBFUNC_INIT
99 asm volatile (
100 "stbx %0,0,%1 \n\t"
101 "sync \n\t"
103 : "r"(val), "r"(port + _IO_BASE));
105 AROS_LIBFUNC_EXIT
108 AROS_LH2(void, OutW,
109 AROS_LHA(UWORD, port, D0),
110 AROS_LHA(UWORD, val, D1),
111 APTR, KernelBase, 4, Kernel)
113 AROS_LIBFUNC_INIT
115 asm volatile (
116 "sthbrx %0,0,%1 \n\t"
117 "sync \n\t"
119 : "r"(val), "r"(port + _IO_BASE));
121 AROS_LIBFUNC_EXIT
124 AROS_LH2(void, OutL,
125 AROS_LHA(UWORD, port, D0),
126 AROS_LHA(ULONG, val, D1),
127 APTR, KernelBase, 5, Kernel)
129 AROS_LIBFUNC_INIT
131 asm volatile (
132 "stwbrx %0,0,%1 \n\t"
133 "sync \n\t"
135 : "r"(val), "r"(port + _IO_BASE));
137 AROS_LIBFUNC_EXIT
140 AROS_LH1(UBYTE, InB,
141 AROS_LHA(UWORD, port, D0),
142 APTR, KernelBase, 6, Kernel)
144 AROS_LIBFUNC_INIT
146 UBYTE ret;
148 asm volatile ("lbzx %0,0,%1\n\tisync\n\tnop"
149 :"=r"(ret)
150 :"r"(port + _IO_BASE));
152 return(ret);
154 AROS_LIBFUNC_EXIT
157 AROS_LH1(UWORD, InW,
158 AROS_LHA(UWORD, port, D0),
159 APTR, KernelBase, 7, Kernel)
161 AROS_LIBFUNC_INIT
163 UWORD ret;
165 asm volatile ("lhbrx %0,0,%1\n\tisync\n\tnop"
166 :"=r"(ret)
167 :"r"(port + _IO_BASE));
169 return(ret);
171 AROS_LIBFUNC_EXIT
174 AROS_LH1(ULONG, InL,
175 AROS_LHA(UWORD, port, D0),
176 APTR, KernelBase, 8, Kernel)
178 AROS_LIBFUNC_INIT
180 ULONG ret;
182 asm volatile ("lwbrx %0,0,%1\n\tisync\n\tnop"
183 :"=r"(ret)
184 :"r"(port + _IO_BASE));
186 return(ret);
188 AROS_LIBFUNC_EXIT