source: rtems/c/src/lib/libbsp/m68k/gen68360/startup/init68360.c @ 69405459

4.104.114.84.95
Last change on this file since 69405459 was 676b504, checked in by Joel Sherrill <joel.sherrill@…>, on 04/06/99 at 20:27:45

Patch from Eric Norum <eric@…>:

I'd like to make the following change which adds the m360 structure
information to the debugging symbols in the final executable. This
makes it much easier to use the debugger to look at the elements of
the m360 structure.

  • Property mode set to 100644
File size: 14.3 KB
Line 
1/*
2 * MC68360 support routines
3 *
4 * W. Eric Norum
5 * Saskatchewan Accelerator Laboratory
6 * University of Saskatchewan
7 * Saskatoon, Saskatchewan, CANADA
8 * eric@skatter.usask.ca
9 *
10 *  $Id$
11 */
12
13#include <rtems.h>
14#include <bsp.h>
15#include <m68360.h>
16
17/*
18 * Declare the m360 structure here for the benefit of the debugger
19 */
20
21m360_t m360;
22
23/*
24 * Send a command to the CPM RISC processer
25 */
26
27void M360ExecuteRISC(rtems_unsigned16 command)
28{
29        rtems_unsigned16 sr;
30
31        m68k_disable_interrupts (sr);
32        while (m360.cr & M360_CR_FLG)
33                continue;
34        m360.cr = command | M360_CR_FLG;
35        m68k_enable_interrupts (sr);
36}
37
38/*
39 * Initialize MC68360
40 */
41void _Init68360 (void)
42{
43        int i;
44        m68k_isr_entry *vbr;
45        extern void _CopyDataClearBSSAndStart (void);
46
47#if (defined (__mc68040__))
48        /*
49         *******************************************
50         * Motorola 68040 and companion-mode 68360 *
51         *******************************************
52         */
53
54        /*
55         * Step 6: Is this a power-up reset?
56         * For now we just ignore this and do *all* the steps
57         * Someday we might want to:
58         *      if (Hard, Loss of Clock, Power-up)
59         *              Do all steps
60         *      else if (Double bus fault, watchdog or soft reset)
61         *              Skip to step 12
62         *      else (must be a reset command)
63         *              Skip to step 14
64         */
65
66        /*
67         * Step 7: Deal with clock synthesizer
68         * HARDWARE:
69         *      Change if you're not using an external 25 MHz oscillator.
70         */
71        m360.clkocr = 0x83;     /* No more writes, full-power CLKO2 */
72        m360.pllcr = 0xD000;    /* PLL, no writes, no prescale,
73                                   no LPSTOP slowdown, PLL X1 */
74        m360.cdvcr = 0x8000;    /* No more writes, no clock division */
75
76        /*
77         * Step 8: Initialize system protection
78         *      Enable watchdog
79         *      Watchdog causes system reset
80         *      Next-to-slowest watchdog timeout (21 seconds with 25 MHz oscillator)
81         *      Enable double bus fault monitor
82         *      Enable bus monitor for external cycles
83         *      1024 clocks for external timeout
84         */
85        m360.sypcr = 0xEC;
86
87        /*
88         * Step 9: Clear parameter RAM and reset communication processor module
89         */
90        for (i = 0 ; i < 192  ; i += sizeof (long)) {
91                *((long *)((char *)&m360 + 0xC00 + i)) = 0;
92                *((long *)((char *)&m360 + 0xD00 + i)) = 0;
93                *((long *)((char *)&m360 + 0xE00 + i)) = 0;
94                *((long *)((char *)&m360 + 0xF00 + i)) = 0;
95        }
96        M360ExecuteRISC (M360_CR_RST);
97
98        /*
99         * Step 10: Write PEPAR
100         *      SINTOUT standard M68000 family interrupt level encoding
101         *      CF1MODE=10 (BCLRO* output)
102         *      No RAS1* double drive
103         *      A31 - A28
104         *      AMUX output
105         *      CAS2* - CAS3*
106         *      CAS0* - CAS1*
107         *      CS7*
108         *      AVEC*
109         */
110        m360.pepar = 0x3440;
111
112        /*
113         * Step 11: Remap Chip Select 0 (CS0*), set up GMR
114         */
115        /*
116         * 512 addresses per DRAM page (256K DRAM chips)
117         * 70 nsec DRAM
118         * 180 nsec ROM (3 wait states)
119         */
120        m360.gmr = M360_GMR_RCNT(23) | M360_GMR_RFEN |
121                                M360_GMR_RCYC(0) | M360_GMR_PGS(1) |
122                                M360_GMR_DPS_32BIT | M360_GMR_NCS |
123                                M360_GMR_TSS40;
124        m360.memc[0].br = (unsigned long)&_RomBase | M360_MEMC_BR_WP |
125                                                        M360_MEMC_BR_V;
126        m360.memc[0].or = M360_MEMC_OR_WAITS(3) | M360_MEMC_OR_1MB |
127                                                M360_MEMC_OR_32BIT;
128
129        /*
130         * Step 12: Initialize the system RAM
131         */
132        /*
133         *      Set up option/base registers
134         *              1M DRAM
135         *              70 nsec DRAM
136         *      Enable burst mode
137         *      No parity checking
138         *      Wait for chips to power up
139         *      Perform 8 read cycles
140         */
141        m360.memc[1].or = M360_MEMC_OR_TCYC(0) |
142                                        M360_MEMC_OR_1MB |
143                                        M360_MEMC_OR_DRAM;
144        m360.memc[1].br = (unsigned long)&_RamBase |
145                                        M360_MEMC_BR_BACK40 |
146                                        M360_MEMC_BR_V;
147        for (i = 0; i < 50000; i++)
148                continue;
149        for (i = 0; i < 8; ++i)
150                *((volatile unsigned long *)(unsigned long)&_RamBase);
151
152        /*
153         * Step 13: Copy  the exception vector table to system RAM
154         */
155        m68k_get_vbr (vbr);
156        for (i = 0; i < 256; ++i)
157                M68Kvec[i] = vbr[i];
158        m68k_set_vbr (M68Kvec);
159       
160        /*
161         * Step 14: More system initialization
162         * SDCR (Serial DMA configuration register)
163         *      Enable SDMA during FREEZE
164         *      Give SDMA priority over all interrupt handlers
165         *      Set DMA arbiration level to 4
166         * CICR (CPM interrupt configuration register):
167         *      SCC1 requests at SCCa position
168         *      SCC2 requests at SCCb position
169         *      SCC3 requests at SCCc position
170         *      SCC4 requests at SCCd position
171         *      Interrupt request level 4
172         *      Maintain original priority order
173         *      Vector base 128
174         *      SCCs priority grouped at top of table
175         */
176        m360.sdcr = M360_SDMA_SISM_7 | M360_SDMA_SAID_4;
177        m360.cicr = (3 << 22) | (2 << 20) | (1 << 18) | (0 << 16) |
178                                                (4 << 13) | (0x1F << 8) | (128);
179
180        /*
181         * Step 15: Set module configuration register
182         *      Bus request MC68040 Arbitration ID 3
183         *      Bus asynchronous timing mode (work around bug in Rev. B)
184         *      Arbitration asynchronous timing mode
185         *      Disable timers during FREEZE
186         *      Disable bus monitor during FREEZE
187         *      BCLRO* arbitration level 3
188         *      No show cycles
189         *      User/supervisor access
190         *      Bus clear in arbitration ID level  3
191         *      SIM60 interrupt sources higher priority than CPM
192         */
193        m360.mcr = 0x6000EC3F;
194
195#elif (defined (M68360_ATLAS_HSB))
196        /*
197         ******************************************
198         * Standalone Motorola 68360 -- ATLAS HSB *
199         ******************************************
200         */
201
202        /*
203         * Step 6: Is this a power-up reset?
204         * For now we just ignore this and do *all* the steps
205         * Someday we might want to:
206         *      if (Hard, Loss of Clock, Power-up)
207         *              Do all steps
208         *      else if (Double bus fault, watchdog or soft reset)
209         *              Skip to step 12
210         *      else (must be a CPU32+ reset command)
211         *              Skip to step 14
212         */
213
214        /*
215         * Step 7: Deal with clock synthesizer
216         * HARDWARE:
217         *      Change if you're not using an external 25 MHz oscillator.
218         */
219        m360.clkocr = 0x8F;     /* No more writes, no clock outputs */
220        m360.pllcr = 0xD000;    /* PLL, no writes, no prescale,
221                                   no LPSTOP slowdown, PLL X1 */
222        m360.cdvcr = 0x8000;    /* No more writes, no clock division */
223
224        /*
225         * Step 8: Initialize system protection
226         *      Enable watchdog
227         *      Watchdog causes system reset
228         *      Next-to-slowest watchdog timeout (21 seconds with 25 MHz oscillator)
229         *      Enable double bus fault monitor
230         *      Enable bus monitor for external cycles
231         *      1024 clocks for external timeout
232         */
233        m360.sypcr = 0xEC;
234
235        /*
236         * Step 9: Clear parameter RAM and reset communication processor module
237         */
238        for (i = 0 ; i < 192  ; i += sizeof (long)) {
239                *((long *)((char *)&m360 + 0xC00 + i)) = 0;
240                *((long *)((char *)&m360 + 0xD00 + i)) = 0;
241                *((long *)((char *)&m360 + 0xE00 + i)) = 0;
242                *((long *)((char *)&m360 + 0xF00 + i)) = 0;
243        }
244        M360ExecuteRISC (M360_CR_RST);
245
246        /*
247         * Step 10: Write PEPAR
248         *      SINTOUT not used (CPU32+ mode)
249         *      CF1MODE=00 (CONFIG1 input)
250         *      RAS1* double drive
251         *      WE0* - WE3*
252         *      OE* output
253         *      CAS2* - CAS3*
254         *      CAS0* - CAS1*
255         *      CS7*
256         *      AVEC*
257         * HARDWARE:
258         *      Change if you are using a different memory configuration
259         *      (static RAM, external address multiplexing, etc).
260         */
261        m360.pepar = 0x0180;
262
263        /*
264         * Step 11: Remap Chip Select 0 (CS0*), set up GMR
265         */
266        m360.gmr = M360_GMR_RCNT(12) | M360_GMR_RFEN |
267                                M360_GMR_RCYC(0) | M360_GMR_PGS(1) |
268                                M360_GMR_DPS_32BIT | M360_GMR_DWQ |
269                                M360_GMR_GAMX;
270        m360.memc[0].br = (unsigned long)&_RomBase | M360_MEMC_BR_WP |
271                                                                M360_MEMC_BR_V;
272        m360.memc[0].or = M360_MEMC_OR_WAITS(3) | M360_MEMC_OR_1MB |
273                                                        M360_MEMC_OR_8BIT;
274
275        /*
276         * Step 12: Initialize the system RAM
277         */
278        /* first bank 1MByte DRAM */
279        m360.memc[1].or = M360_MEMC_OR_TCYC(2) | M360_MEMC_OR_1MB |
280                                        M360_MEMC_OR_PGME | M360_MEMC_OR_DRAM;
281        m360.memc[1].br = (unsigned long)&_RamBase | M360_MEMC_BR_V;
282
283        /* second bank 1MByte DRAM */
284        m360.memc[2].or = M360_MEMC_OR_TCYC(2) | M360_MEMC_OR_1MB |
285                                        M360_MEMC_OR_PGME | M360_MEMC_OR_DRAM;
286        m360.memc[2].br = ((unsigned long)&_RamBase + 0x100000) |
287                                        M360_MEMC_BR_V;
288
289        /* flash rom socket U6 on CS5 */
290        m360.memc[5].br = (unsigned long)ATLASHSB_ROM_U6 | M360_MEMC_BR_WP |
291                                                                M360_MEMC_BR_V;
292        m360.memc[5].or = M360_MEMC_OR_WAITS(2) | M360_MEMC_OR_512KB |
293                                                                M360_MEMC_OR_8BIT;
294
295        /* CSRs on CS7 */
296        m360.memc[7].or = M360_MEMC_OR_TCYC(4) | M360_MEMC_OR_64KB |
297                                        M360_MEMC_OR_8BIT;
298        m360.memc[7].br = ATLASHSB_ESR | 0x01;
299        for (i = 0; i < 50000; i++)
300                continue;
301        for (i = 0; i < 8; ++i)
302                *((volatile unsigned long *)(unsigned long)&_RamBase);
303
304        /*
305         * Step 13: Copy  the exception vector table to system RAM
306         */
307        m68k_get_vbr (vbr);
308        for (i = 0; i < 256; ++i)
309                M68Kvec[i] = vbr[i];
310        m68k_set_vbr (M68Kvec);
311       
312        /*
313         * Step 14: More system initialization
314         * SDCR (Serial DMA configuration register)
315         *      Enable SDMA during FREEZE
316         *      Give SDMA priority over all interrupt handlers
317         *      Set DMA arbiration level to 4
318         * CICR (CPM interrupt configuration register):
319         *      SCC1 requests at SCCa position
320         *      SCC2 requests at SCCb position
321         *      SCC3 requests at SCCc position
322         *      SCC4 requests at SCCd position
323         *      Interrupt request level 4
324         *      Maintain original priority order
325         *      Vector base 128
326         *      SCCs priority grouped at top of table
327         */
328        m360.sdcr = M360_SDMA_SISM_7 | M360_SDMA_SAID_4;
329        m360.cicr = (3 << 22) | (2 << 20) | (1 << 18) | (0 << 16) |
330                                                (4 << 13) | (0x1F << 8) | (128);
331
332        /*
333         * Step 15: Set module configuration register
334         *      Disable timers during FREEZE
335         *      Enable bus monitor during FREEZE
336         *      BCLRO* arbitration level 3
337         *      No show cycles
338         *      User/supervisor access
339         *      Bus clear interrupt service level 7
340         *      SIM60 interrupt sources higher priority than CPM
341         */
342        m360.mcr = 0x4C7F;
343
344#else
345        /*
346         ***************************************************
347         * Generic Standalone Motorola 68360               *
348         *           As described in MC68360 User's Manual *
349         *           Atlas ACE360                          *
350         ***************************************************
351         */
352
353        /*
354         * Step 6: Is this a power-up reset?
355         * For now we just ignore this and do *all* the steps
356         * Someday we might want to:
357         *      if (Hard, Loss of Clock, Power-up)
358         *              Do all steps
359         *      else if (Double bus fault, watchdog or soft reset)
360         *              Skip to step 12
361         *      else (must be a CPU32+ reset command)
362         *              Skip to step 14
363         */
364
365        /*
366         * Step 7: Deal with clock synthesizer
367         * HARDWARE:
368         *      Change if you're not using an external 25 MHz oscillator.
369         */
370        m360.clkocr = 0x8F;     /* No more writes, no clock outputs */
371        m360.pllcr = 0xD000;    /* PLL, no writes, no prescale,
372                                   no LPSTOP slowdown, PLL X1 */
373        m360.cdvcr = 0x8000;    /* No more writes, no clock division */
374
375        /*
376         * Step 8: Initialize system protection
377         *      Enable watchdog
378         *      Watchdog causes system reset
379         *      Next-to-slowest watchdog timeout (21 seconds with 25 MHz oscillator)
380         *      Enable double bus fault monitor
381         *      Enable bus monitor for external cycles
382         *      1024 clocks for external timeout
383         */
384        m360.sypcr = 0xEC;
385
386        /*
387         * Step 9: Clear parameter RAM and reset communication processor module
388         */
389        for (i = 0 ; i < 192  ; i += sizeof (long)) {
390                *((long *)((char *)&m360 + 0xC00 + i)) = 0;
391                *((long *)((char *)&m360 + 0xD00 + i)) = 0;
392                *((long *)((char *)&m360 + 0xE00 + i)) = 0;
393                *((long *)((char *)&m360 + 0xF00 + i)) = 0;
394        }
395        M360ExecuteRISC (M360_CR_RST);
396
397        /*
398         * Step 10: Write PEPAR
399         *      SINTOUT not used (CPU32+ mode)
400         *      CF1MODE=00 (CONFIG1 input)
401         *      RAS1* double drive
402         *      WE0* - WE3*
403         *      OE* output
404         *      CAS2* - CAS3*
405         *      CAS0* - CAS1*
406         *      CS7*
407         *      AVEC*
408         * HARDWARE:
409         *      Change if you are using a different memory configuration
410         *      (static RAM, external address multiplexing, etc).
411         */
412        m360.pepar = 0x0180;
413
414        /*
415         * Step 11: Remap Chip Select 0 (CS0*), set up GMR
416         *      32-bit DRAM
417         *      Internal DRAM address multiplexing
418         *      60 nsec DRAM
419         *      180 nsec ROM (3 wait states)
420         *      15.36 usec DRAM refresh interval
421         *      The DRAM page size selection is not modified since this
422         *      startup code may be running in a bootstrap PROM or in
423         *      a program downloaded by the bootstrap PROM.
424         */
425        m360.gmr = (m360.gmr & 0x001C0000) | M360_GMR_RCNT(23) |
426                                        M360_GMR_RFEN | M360_GMR_RCYC(0) |
427                                        M360_GMR_DPS_32BIT | M360_GMR_NCS |
428                                        M360_GMR_GAMX;
429        m360.memc[0].br = (unsigned long)&_RomBase | M360_MEMC_BR_WP |
430                                                                M360_MEMC_BR_V;
431        m360.memc[0].or = M360_MEMC_OR_WAITS(3) | M360_MEMC_OR_1MB |
432                                                        M360_MEMC_OR_8BIT;
433
434        /*
435         * Step 12: Initialize the system RAM
436         * Do this only if the DRAM has not already been set up
437         */
438        if ((m360.memc[1].br & M360_MEMC_BR_V) == 0) {
439                /*
440                 * Set up GMR DRAM page size, option and  base registers
441                 *      Assume 16Mbytes of DRAM
442                 *      60 nsec DRAM
443                 */
444                m360.gmr = (m360.gmr & ~0x001C0000) | M360_GMR_PGS(5);
445                m360.memc[1].or = M360_MEMC_OR_TCYC(0) |
446                                                M360_MEMC_OR_16MB |
447                                                M360_MEMC_OR_DRAM;
448                m360.memc[1].br = (unsigned long)&_RamBase | M360_MEMC_BR_V;
449
450                /*
451                 * Wait for chips to power up
452                 *      Perform 8 read cycles
453                 */
454                for (i = 0; i < 50000; i++)
455                        continue;
456                for (i = 0; i < 8; ++i)
457                        *((volatile unsigned long *)(unsigned long)&_RamBase);
458
459                /*
460                 * Determine memory size (1, 4, or 16 Mbytes)
461                 * Set GMR DRAM page size appropriately.
462                 * The OR is left at 16 Mbytes.  The bootstrap PROM places its
463                 * .data and .bss segments at the top of the 16 Mbyte space.
464                 * A 1 Mbyte or 4 Mbyte DRAM will show up several times in
465                 * the memory map, but will work with the same bootstrap PROM.
466                 */
467                *(volatile char *)&_RamBase = 0;
468                *((volatile char *)&_RamBase+0x00C01800) = 1;
469                if (*(volatile char *)&_RamBase) {
470                        m360.gmr = (m360.gmr & ~0x001C0000) | M360_GMR_PGS(1);
471                }
472                else {
473                        *((volatile char *)&_RamBase+0x00801000) = 1;
474                        if (*(volatile char *)&_RamBase) {
475                                m360.gmr = (m360.gmr & ~0x001C0000) | M360_GMR_PGS(3);
476                        }
477                }
478
479                /*
480                 * Enable parity checking
481                 */
482                m360.memc[1].br |= M360_MEMC_BR_PAREN;
483        }
484
485        /*
486         * Step 13: Copy  the exception vector table to system RAM
487         */
488        m68k_get_vbr (vbr);
489        for (i = 0; i < 256; ++i)
490                M68Kvec[i] = vbr[i];
491        m68k_set_vbr (M68Kvec);
492       
493        /*
494         * Step 14: More system initialization
495         * SDCR (Serial DMA configuration register)
496         *      Enable SDMA during FREEZE
497         *      Give SDMA priority over all interrupt handlers
498         *      Set DMA arbiration level to 4
499         * CICR (CPM interrupt configuration register):
500         *      SCC1 requests at SCCa position
501         *      SCC2 requests at SCCb position
502         *      SCC3 requests at SCCc position
503         *      SCC4 requests at SCCd position
504         *      Interrupt request level 4
505         *      Maintain original priority order
506         *      Vector base 128
507         *      SCCs priority grouped at top of table
508         */
509        m360.sdcr = M360_SDMA_SISM_7 | M360_SDMA_SAID_4;
510        m360.cicr = (3 << 22) | (2 << 20) | (1 << 18) | (0 << 16) |
511                                                (4 << 13) | (0x1F << 8) | (128);
512
513        /*
514         * Step 15: Set module configuration register
515         *      Disable timers during FREEZE
516         *      Enable bus monitor during FREEZE
517         *      BCLRO* arbitration level 3
518         *      No show cycles
519         *      User/supervisor access
520         *      Bus clear interrupt service level 7
521         *      SIM60 interrupt sources higher priority than CPM
522         */
523        m360.mcr = 0x4C7F;
524#endif
525
526        /*
527         * Copy data, clear BSS, switch stacks and call main()
528         */
529        _CopyDataClearBSSAndStart ();
530}
Note: See TracBrowser for help on using the repository browser.