revert between 56095 -> 55830 in arch
[AROS.git] / arch / m68k-amiga / cia / cia_init.c
blobf562b311f7bdaff3994aed0feecf88d669d7084f
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * This is a skeleton of cia.resource implementation.
9 * Note that it uses custom initcode because cia.resource does not
10 * act in standard way. This module in fact contains two resources:
11 * ciaa.resource and ciab.resource.
12 * genmodule does not support such thing, so everything is written
13 * by hands here.
15 * Since we don't use genmodule, we have to use some other way for
16 * generating include files. A standard SFD file is used to keep all
17 * the definitions, it's processed using sfdc (note that it had to
18 * be fixed in order to support explicit base specification correctly)
20 * Note that fd2inline (which also supports generating AROS macros) will
21 * generate a BROKEN inline file for this resource. It handles missing
22 * base specification incorrectly.
24 * sonic <pavel_fedin@mail.ru>
27 #include <exec/types.h>
28 #include <exec/libraries.h>
29 #include <exec/resident.h>
30 #include <aros/libcall.h>
31 #include <aros/asmcall.h>
32 #include <dos/dos.h>
34 #include <proto/exec.h>
35 #include <proto/alib.h>
37 #include <hardware/cia.h>
38 #include <hardware/custom.h>
39 #include <hardware/intbits.h>
41 #define DEBUG 0
42 #include <aros/debug.h>
44 #include "cia_intern.h"
46 #define _STR(A) #A
47 #define STR(A) _STR(A)
49 AROS_LD2(struct Interrupt *, AddICRVector,
50 AROS_LDA(WORD, iCRBit, D0),
51 AROS_LDA(struct Interrupt *, interrupt, A1),
52 struct Library *, resource, 1, Cia
54 AROS_LD2(void, RemICRVector,
55 AROS_LDA(WORD, iCRBit, A0),
56 AROS_LDA(struct Interrupt *, interrupt, A1),
57 struct Library *, resource, 2, Cia
59 AROS_LD1(WORD, AbleICR,
60 AROS_LDA(WORD, mask, D0),
61 struct Library *, resource, 3, Cia
63 AROS_LD1(WORD, SetICR,
64 AROS_LDA(WORD, mask, D0),
65 struct Library *, resource, 4, Cia
68 #define RESIDENT_FLAGS RTF_COLDSTART
69 #define RESIDENT_PRIORITY 80
70 #define RESIDENT_NAME "cia.resource"
71 #define RESIDENT_VERSION 0
72 #define RESIDENT_REVISION 1
74 static const char resident_name[] = RESIDENT_NAME;
75 static const char resident_id[] = "\0$VER:" RESIDENT_NAME " " STR(RESIDENT_VERSION) "." STR(RESIDENT_REVISION) " (" ADATE ")";
77 AROS_INTP(Cia_Handler);
79 static AROS_UFP3 (APTR, Cia_Init,
80 AROS_UFPA(struct Library *, lh, D0),
81 AROS_UFPA(BPTR, segList, A0),
82 AROS_UFPA(struct ExecBase *, sysBase, A6));
84 extern void Cia_End(void);
86 struct Resident const Cia_ROMTag =
88 RTC_MATCHWORD,
89 &Cia_ROMTag,
90 (APTR)&Cia_End,
91 RESIDENT_FLAGS,
92 RESIDENT_VERSION,
93 NT_RESOURCE,
94 RESIDENT_PRIORITY,
95 resident_name,
96 &resident_id[6],
97 (APTR)Cia_Init
100 static const APTR Cia_FuncTable[]=
102 &AROS_SLIB_ENTRY(AddICRVector,Cia,1),
103 &AROS_SLIB_ENTRY(RemICRVector,Cia,2),
104 &AROS_SLIB_ENTRY(AbleICR,Cia,3),
105 &AROS_SLIB_ENTRY(SetICR,Cia,4),
106 (void *)-1
109 static struct CIABase *InitResource(char *Name, struct ExecBase *SysBase)
111 struct CIABase *base;
113 base = (struct CIABase *)MakeLibrary((APTR)Cia_FuncTable, NULL, NULL, sizeof(struct CIABase), 0);
115 if (base) {
116 base->lib.lib_Node.ln_Type = NT_RESOURCE;
117 base->lib.lib_Node.ln_Name = Name;
118 base->lib.lib_Version = RESIDENT_VERSION;
119 base->lib.lib_IdString = (STRPTR)&resident_id[6];
120 base->lib.lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
121 base->lib.lib_Revision = RESIDENT_REVISION;
123 AddResource(base);
125 return base;
128 static AROS_UFH3 (APTR, Cia_Init,
129 AROS_UFHA(struct Library *, lh, D0),
130 AROS_UFHA(BPTR, segList, A0),
131 AROS_UFHA(struct ExecBase *, sysBase, A6)
134 AROS_USERFUNC_INIT
136 struct CIABase *base;
138 /* Initialize ciaa.resource */
139 base = InitResource("ciaa.resource", SysBase);
140 if (!base)
141 return NULL;
143 base->hw = (struct CIA*)0xbfe001;
144 base->hw->ciaicr = 0x7f;
145 base->hw->ciacra = 0x00;
146 base->hw->ciacrb = 0x80;
147 base->hw->ciatodhi = 0x00;
148 base->hw->ciatodmid = 0x0f;
149 base->hw->ciatodlow = 0x00;
150 base->hw->ciacrb = 0x00;
151 base->hw->ciapra = 0x00;
152 base->hw->ciaddra = 0x03;
153 base->hw->ciaddrb = 0xff;
154 base->inten_mask = INTF_PORTS;
156 base->ciaint.is_Node.ln_Pri = 120;
157 base->ciaint.is_Node.ln_Type = NT_INTERRUPT;
158 base->ciaint.is_Node.ln_Name = "CIA-A";
159 base->ciaint.is_Code = (APTR)Cia_Handler;
160 base->ciaint.is_Data = base;
161 AddIntServer(INTB_PORTS, &base->ciaint);
163 D(bug("CIA-A %p\n", base));
165 /* Initialize ciab.resource */
166 base = InitResource("ciab.resource", SysBase);
167 if (!base)
168 return NULL;
170 base->hw = (struct CIA*)0xbfd000;
171 base->hw->ciaicr = 0x7f;
172 base->hw->ciacra = 0x00;
173 base->hw->ciacrb = 0x80;
174 base->hw->ciatodhi = 0x00;
175 base->hw->ciatodmid = 0x0f;
176 base->hw->ciatodlow = 0x00;
177 base->hw->ciacrb = 0x00;
178 base->hw->ciapra = 0xff;
179 base->hw->ciaprb = 0xff;
180 base->hw->ciaddra = 0xff;
181 base->hw->ciaddrb = 0xff;
182 base->inten_mask = INTF_EXTER;
184 base->ciaint.is_Node.ln_Pri = 120;
185 base->ciaint.is_Node.ln_Type = NT_INTERRUPT;
186 base->ciaint.is_Node.ln_Name = "CIA-B";
187 base->ciaint.is_Code = (APTR)Cia_Handler;
188 base->ciaint.is_Data = base;
189 AddIntServer(INTB_EXTER, &base->ciaint);
191 D(bug("CIA-B %p\n", base));
193 return base;
195 AROS_USERFUNC_EXIT