Ticket #216: libbsp_powerpc_shared.diff

File libbsp_powerpc_shared.diff, 90.0 KB (added by strauman, on Dec 3, 2006 at 1:31:12 PM)

libbsp_powerpc_shared.diff

Line 
1This patch (against rtems-ss-20020301) addresses the following
2issues:
3
4The "libbsp/powerpc/shared" BSP has been modified considerably
5with the goal to make it more flexible and reusable by other
6BSPs. The main strategies were:
7
8 - eliminate hardcoded base addresses; devices use offsets
9   and a BSP defined base address.
10 - separate functionality into different files (e.g. reboot
11   from inch.c to reboot.c) which can be overridden
12   by a 'derived' BSP.
13 - separate initialization code into separate files (e.g.
14   PCI bridge detection/initialization was separated from
15   the more generic PCI access routines), also to make
16   it easier for 'derived' BSPs to substitute their own
17   initialization code.
18
19There are also a couple of enhancements and fixes:
20
21 - IRQ handling code now has a hook for attaching
22   a VME bridge.
23 - OpenPIC is now explicitely initialized (polarities, senses).
24   Eliminated the implicit assumption on the presence of an ISA PIC.
25 - UART and console driver now supports more than 1 port. The current
26   maximum of 2 can easily be extended by enlarging a table (it
27   would even be easier if the ISR API was not broken by design).
28 - fixed polled_io.c so it correctly supports console on COM2
29 - fixed TLB invalidation code (start.S).
30 - exception handler prints a stack backtrace.
31 - added BSP_pciFindDevice() to scan the pci bus for a particular
32   vendor/device/instance a la vxWorks.
33
34Author: Till Straumann <strauman@slac.stanford.edu>, 2002/2002
35
36NOTE: This patch requires the "libcpu_powerpc_io" patch.
37
38Index: c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/Makefile.am
39===================================================================
40RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/Makefile.am,v
41retrieving revision 1.1.1.2
42retrieving revision 1.4
43diff -c -r1.1.1.2 -r1.4
44*** c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/Makefile.am    2001/12/15 00:13:11     1.1.1.2
45--- c/src/lib/libbsp/powerpc/motorola_powerpc/bootloader/Makefile.am    2001/12/18 04:21:46     1.4
46***************
47*** 11,19 ****
48 
49  noinst_PROGRAMS = bootloader.o
50 
51! bootloader_o_SOURCES = misc.c pci.c zlib.c mm.c em86.c polled_io.c lib.c
52  bootloader_o_SOURCES += bootldr.h zlib.h pci.h keyboard.h
53- bootloader_o_SOURCES += head.S exception.S em86real.S
54 
55  include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
56 
57--- 11,20 ----
58 
59  noinst_PROGRAMS = bootloader.o
60 
61! ## IMPORTANT: head.S must be first, T. Straumann 12/17/2001
62! bootloader_o_SOURCES = head.S exception.S em86real.S
63! bootloader_o_SOURCES += misc.c pci.c zlib.c mm.c em86.c polled_io.c lib.c
64  bootloader_o_SOURCES += bootldr.h zlib.h pci.h keyboard.h
65 
66  include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
67 
68Index: c/src/lib/libbsp/powerpc/motorola_powerpc/console/Makefile.am
69===================================================================
70RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/motorola_powerpc/console/Makefile.am,v
71retrieving revision 1.1.1.1
72retrieving revision 1.2
73diff -c -r1.1.1.1 -r1.2
74*** c/src/lib/libbsp/powerpc/motorola_powerpc/console/Makefile.am       2001/12/14 22:51:42     1.1.1.1
75--- c/src/lib/libbsp/powerpc/motorola_powerpc/console/Makefile.am       2002/03/07 01:23:41     1.2
76***************
77*** 6,12 ****
78 
79  VPATH = @srcdir@:@srcdir@/../../shared/console:@srcdir@/../../../shared
80 
81! C_FILES = polled_io.c uart.c console.c inch.c
82  C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
83 
84  H_FILES = ../../shared/console/consoleIo.h ../../shared/console/keyboard.h \
85--- 6,12 ----
86 
87  VPATH = @srcdir@:@srcdir@/../../shared/console:@srcdir@/../../../shared
88 
89! C_FILES = polled_io.c uart.c console.c inch.c reboot.c
90  C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
91 
92  H_FILES = ../../shared/console/consoleIo.h ../../shared/console/keyboard.h \
93Index: c/src/lib/libbsp/powerpc/motorola_powerpc/pci/Makefile.am
94===================================================================
95RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/motorola_powerpc/pci/Makefile.am,v
96retrieving revision 1.1.1.2
97retrieving revision 1.4
98diff -c -r1.1.1.2 -r1.4
99*** c/src/lib/libbsp/powerpc/motorola_powerpc/pci/Makefile.am   2001/12/15 00:13:12     1.1.1.2
100--- c/src/lib/libbsp/powerpc/motorola_powerpc/pci/Makefile.am   2002/05/04 04:48:01     1.4
101***************
102*** 6,12 ****
103 
104  VPATH = @srcdir@:@srcdir@/../../shared/pci
105 
106! C_FILES = pci.c
107  C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
108 
109  H_FILES = ../../shared/pci/pci.h
110--- 6,12 ----
111 
112  VPATH = @srcdir@:@srcdir@/../../shared/pci
113 
114! C_FILES = pci.c detect_raven_bridge.c pcifinddevice.c
115  C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
116 
117  H_FILES = ../../shared/pci/pci.h
118Index: c/src/lib/libbsp/powerpc/shared/bootloader/misc.c
119===================================================================
120RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/bootloader/misc.c,v
121retrieving revision 1.1.1.1
122retrieving revision 1.2
123diff -c -r1.1.1.1 -r1.2
124*** c/src/lib/libbsp/powerpc/shared/bootloader/misc.c   2001/12/14 22:52:01     1.1.1.1
125--- c/src/lib/libbsp/powerpc/shared/bootloader/misc.c   2002/03/07 00:56:09     1.2
126***************
127*** 232,237 ****
128--- 232,252 ----
129        codemove(bd->load_address, initrd_start, initrd_len, bd->cache_lsize);
130  }
131 
132+ static int ticks_per_ms=0;
133+
134+ /* this is from rtems_bsp_delay from libcpu */
135+ void
136+ boot_udelay(unsigned32 _microseconds)
137+ {
138+    unsigned32 start, ticks, now;
139+
140+    ticks = _microseconds * ticks_per_ms / 1000;
141+    CPU_Get_timebase_low( start );
142+    do {
143+      CPU_Get_timebase_low( now );
144+    } while (now - start < ticks);
145+ }
146+
147  void
148  setup_hw(void)
149  {
150***************
151*** 401,407 ****
152                        }
153                        break;  /* Exit 'timer' loop */
154                }
155!               udelay(1000);  /* 1 msec */
156        }
157        *cp = 0;
158  }
159--- 416,422 ----
160                        }
161                        break;  /* Exit 'timer' loop */
162                }
163!               boot_udelay(1000);  /* 1 msec */
164        }
165        *cp = 0;
166  }
167Index: c/src/lib/libbsp/powerpc/shared/console/Makefile.am
168===================================================================
169RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/Makefile.am,v
170retrieving revision 1.1.1.1
171retrieving revision 1.3
172diff -c -r1.1.1.1 -r1.3
173*** c/src/lib/libbsp/powerpc/shared/console/Makefile.am 2001/12/14 22:52:03     1.1.1.1
174--- c/src/lib/libbsp/powerpc/shared/console/Makefile.am 2002/04/21 00:43:32     1.3
175***************
176*** 4,10 ****
177 
178  AUTOMAKE_OPTIONS = foreign 1.4
179 
180! C_FILES = console.c inch.c polled_io.c uart.c
181 
182  H_FILES = consoleIo.h keyboard.h uart.h
183 
184--- 4,10 ----
185 
186  AUTOMAKE_OPTIONS = foreign 1.4
187 
188! C_FILES = console.c inch.c polled_io.c uart.c reboot.c
189 
190  H_FILES = consoleIo.h keyboard.h uart.h
191 
192***************
193*** 19,25 ****
194 
195  all-local: $(PREINSTALL_FILES)
196 
197! EXTRA_DIST = console.c consoleIo.h inch.c keyboard.h polled_io.c uart.c \
198!     uart.h
199 
200  include $(top_srcdir)/../../../../../automake/local.am
201--- 19,25 ----
202 
203  all-local: $(PREINSTALL_FILES)
204 
205! EXTRA_DIST = console.c inch.c polled_io.c uart.c \
206!     reboot.c console.inl
207 
208  include $(top_srcdir)/../../../../../automake/local.am
209Index: c/src/lib/libbsp/powerpc/shared/console/console.c
210===================================================================
211RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/console.c,v
212retrieving revision 1.1.1.1
213retrieving revision 1.5
214diff -c -r1.1.1.1 -r1.5
215*** c/src/lib/libbsp/powerpc/shared/console/console.c   2001/12/14 22:52:03     1.1.1.1
216--- c/src/lib/libbsp/powerpc/shared/console/console.c   2002/04/13 04:12:12     1.5
217***************
218*** 9,14 ****
219--- 9,17 ----
220   * (C) Copyright 1997 -
221   * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
222   *
223+  * Till Straumann, <strauman@slac.stanford.edu>, 12/20/2001
224+  * separate BSP specific stuff from generics...
225+  *
226   * http://pandora.ist.utl.pt
227   *
228   * Instituto Superior Tecnico * Lisboa * PORTUGAL
229***************
230*** 33,89 ****
231  #include <termios.h>
232  #include <bsp/uart.h>
233  #include <bsp/consoleIo.h>
234 
235  /* Definitions for BSPConsolePort */
236- #define BSP_CONSOLE_PORT_CONSOLE (-1)
237- #define BSP_CONSOLE_PORT_COM1    (BSP_UART_COM1)
238- #define BSP_CONSOLE_PORT_COM2    (BSP_UART_COM2)
239  /*
240   * Possible value for console input/output :
241   *    BSP_CONSOLE_PORT_CONSOLE
242   *    BSP_UART_COM1
243   *    BSP_UART_COM2
244   */
245!
246! int BSPConsolePort = BSP_UART_COM1;
247 
248! /* int BSPConsolePort = BSP_UART_COM2;  */
249! int BSPBaseBaud    = 115200;
250 
251  /*-------------------------------------------------------------------------+
252  | External Prototypes
253  +--------------------------------------------------------------------------*/
254 
255  static int  conSetAttr(int minor, const struct termios *);
256- static void isr_on(const rtems_irq_connect_data *);
257- static void isr_off(const rtems_irq_connect_data *);
258- static int  isr_is_on(const rtems_irq_connect_data *);
259-
260-
261- static rtems_irq_connect_data console_isr_data = {BSP_ISA_UART_COM1_IRQ,
262-                                                  BSP_uart_termios_isr_com1,
263-                                                  isr_on,
264-                                                  isr_off,
265-                                                  isr_is_on};
266-
267- static void
268- isr_on(const rtems_irq_connect_data *unused)
269- {
270-   return;
271- }
272-                                                 
273- static void
274- isr_off(const rtems_irq_connect_data *unused)
275- {
276-   return;
277- }
278 
279- static int
280- isr_is_on(const rtems_irq_connect_data *irq)
281- {
282-   return BSP_irq_enabled_at_i8259s(irq->name);
283- }
284-
285  void __assert (const char *file, int line, const char *msg)
286  {
287      static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
288--- 36,60 ----
289  #include <termios.h>
290  #include <bsp/uart.h>
291  #include <bsp/consoleIo.h>
292+ #include <rtems/bspIo.h>      /* printk */
293 
294  /* Definitions for BSPConsolePort */
295  /*
296   * Possible value for console input/output :
297   *    BSP_CONSOLE_PORT_CONSOLE
298   *    BSP_UART_COM1
299   *    BSP_UART_COM2
300   */
301! int BSPConsolePort = BSP_CONSOLE_PORT;
302 
303! int BSPBaseBaud    = BSP_UART_BAUD_BASE;
304 
305  /*-------------------------------------------------------------------------+
306  | External Prototypes
307  +--------------------------------------------------------------------------*/
308 
309  static int  conSetAttr(int minor, const struct termios *);
310 
311  void __assert (const char *file, int line, const char *msg)
312  {
313      static   char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot...";
314***************
315*** 111,116 ****
316--- 82,109 ----
317 
318  }
319 
320+ typedef struct TtySTblRec_ {
321+               char    *name;
322+               void    (*isr)(void); /* STUPID API doesn't pass a parameter :-( */
323+ } TtySTblRec, *TtySTbl;
324+
325+ static TtySTblRec ttyS[]={
326+               { "/dev/ttyS0",
327+ #ifdef BSP_UART_IOBASE_COM1
328+                 BSP_uart_termios_isr_com1
329+ #else
330+                 0
331+ #endif
332+               },
333+               { "/dev/ttyS1",
334+ #ifdef BSP_UART_IOBASE_COM2
335+                 BSP_uart_termios_isr_com2
336+ #else
337+                 0
338+ #endif
339+               },
340+ };
341+
342 
343  /*-------------------------------------------------------------------------+
344  | Console device driver INITIALIZE entry point.
345***************
346*** 129,135 ****
347     *  to be reinitialized.
348     */
349 
350-
351    /*
352     * Set up TERMIOS
353     */
354--- 122,127 ----
355***************
356*** 138,194 ****
357    /*
358     * Do device-specific initialization
359     */
360-       
361-   /* 9600-8-N-1 */
362-   BSP_uart_init(BSPConsolePort, 9600, 0);
363-       
364-       
365-   /* Set interrupt handler */
366-   if(BSPConsolePort == BSP_UART_COM1)
367-     {
368-       console_isr_data.name = BSP_ISA_UART_COM1_IRQ;
369-       console_isr_data.hdl  = BSP_uart_termios_isr_com1;
370-         
371-     }
372-   else
373-     {
374-       assert(BSPConsolePort == BSP_UART_COM2);
375-       console_isr_data.name = BSP_ISA_UART_COM2_IRQ;
376-       console_isr_data.hdl  = BSP_uart_termios_isr_com2;
377-     }
378-
379-   status = BSP_install_rtems_irq_handler(&console_isr_data);
380 
381!   if (!status){
382!     printk("Error installing serial console interrupt handler!\n");
383!     rtems_fatal_error_occurred(status);
384!   }
385!   /*
386!    * Register the device
387     */
388!   status = rtems_io_register_name ("/dev/console", major, 0);
389!   if (status != RTEMS_SUCCESSFUL)
390!     {
391!       printk("Error registering console device!\n");
392!       rtems_fatal_error_occurred (status);
393!     }
394 
395!   if(BSPConsolePort == BSP_UART_COM1)
396!     {
397!       printk("Initialized console on port COM1 9600-8-N-1\n\n");
398!     }
399!   else
400!     {
401!       printk("Initialized console on port COM2 9600-8-N-1\n\n");
402!     }
403    return RTEMS_SUCCESSFUL;
404  } /* console_initialize */
405 
406 
407  static int console_last_close(int major, int minor, void *arg)
408  {
409!   BSP_remove_rtems_irq_handler (&console_isr_data);
410!
411    return 0;
412  }
413 
414--- 130,195 ----
415    /*
416     * Do device-specific initialization
417     */
418 
419!   /* RTEMS calls this routine once with 'minor'==0; loop through
420!    * all known instances...
421     */
422!     
423!   for (minor=0; minor < sizeof(ttyS)/sizeof(ttyS[0]); minor++) {
424!       char *nm;
425!         /*
426!          * Skip ports (possibly not supported by BSP...) we have no ISR for
427!          */
428!         if ( ! ttyS[minor].isr )
429!               continue;
430!         /*
431!          * Register the device
432!          */
433!         status = rtems_io_register_name ((nm=ttyS[minor].name), major, minor);
434!         if ( RTEMS_SUCCESSFUL==status && BSPConsolePort == minor)
435!               {
436!                 printk("Registering /dev/console as minor %i (==%s)\n",
437!                                                       minor,
438!                                                       ttyS[minor].name);
439!                 /* also register an alias */
440!                 status = rtems_io_register_name (
441!                                                       (nm="/dev/console"),
442!                                                       major,
443!                                                       minor);
444!               }
445!         if (status != RTEMS_SUCCESSFUL)
446!               {
447!                 printk("Error registering %s!\n",nm);
448!                 rtems_fatal_error_occurred (status);
449!               }
450 
451!   }
452    return RTEMS_SUCCESSFUL;
453  } /* console_initialize */
454 
455+ static int console_first_open(int major, int minor, void *arg)
456+ {
457+   rtems_status_code status;
458+
459+         /* must not open a minor device we have no ISR for */
460+         assert( minor>=0 && minor < sizeof(ttyS)/sizeof(ttyS[0]) && ttyS[minor].isr );
461+
462+         /* 9600-8-N-1 */
463+         BSP_uart_init(minor, 9600, 0);
464+         status = BSP_uart_install_isr(minor, ttyS[minor].isr);
465+         if (!status)
466+               {
467+                 printk("Error installing serial console interrupt handler for '%s'!\n",
468+                               ttyS[minor].name);
469+                 rtems_fatal_error_occurred(status);
470+               }
471+         return 0;
472+ }
473+
474 
475  static int console_last_close(int major, int minor, void *arg)
476  {
477!   BSP_uart_remove_isr(minor, ttyS[minor].isr);
478    return 0;
479  }
480 
481***************
482*** 203,223 ****
483    rtems_status_code              status;
484    static rtems_termios_callbacks cb =
485    {
486!     NULL,                   /* firstOpen */
487!     console_last_close,       /* lastClose */
488!     NULL,                   /* pollRead */
489!     BSP_uart_termios_write_com1, /* write */
490!     conSetAttr,                     /* setAttributes */
491!     NULL,                   /* stopRemoteTx */
492!     NULL,                   /* startRemoteTx */
493!     1                       /* outputUsesInterrupts */
494    };
495 
496-   if(BSPConsolePort == BSP_UART_COM2)
497-     {
498-       cb.write = BSP_uart_termios_write_com2;
499-     }
500-
501    status = rtems_termios_open (major, minor, arg, &cb);
502 
503    if(status != RTEMS_SUCCESSFUL)
504--- 204,219 ----
505    rtems_status_code              status;
506    static rtems_termios_callbacks cb =
507    {
508!     console_first_open,                       /* firstOpen */
509!     console_last_close,                       /* lastClose */
510!     NULL,                                             /* pollRead */
511!     BSP_uart_termios_write_com,       /* write */
512!     conSetAttr,                                       /* setAttributes */
513!     NULL,                                             /* stopRemoteTx */
514!     NULL,                                             /* startRemoteTx */
515!     1                                                 /* outputUsesInterrupts */
516    };
517 
518    status = rtems_termios_open (major, minor, arg, &cb);
519 
520    if(status != RTEMS_SUCCESSFUL)
521***************
522*** 229,238 ****
523    /*
524     * Pass data area info down to driver
525     */
526!   BSP_uart_termios_set(BSPConsolePort,
527                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
528    /* Enable interrupts  on channel */
529!   BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS);
530 
531    return RTEMS_SUCCESSFUL;
532  }
533--- 225,234 ----
534    /*
535     * Pass data area info down to driver
536     */
537!   BSP_uart_termios_set(minor,
538                         ((rtems_libio_open_close_args_t *)arg)->iop->data1);
539    /* Enable interrupts  on channel */
540!   BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS);
541 
542    return RTEMS_SUCCESSFUL;
543  }
544***************
545*** 361,370 ****
546        return 0;
547      }
548 
549!   BSP_uart_set_baud(BSPConsolePort, baud);
550 
551    return 0;
552  }
553-
554-
555-
556--- 357,363 ----
557        return 0;
558      }
559 
560!   BSP_uart_set_baud(minor, baud);
561 
562    return 0;
563  }
564Index: c/src/lib/libbsp/powerpc/shared/console/console.inl
565===================================================================
566RCS file: console.inl
567diff -N console.inl
568*** /dev/null   Thu Aug 24 02:00:32 2000
569--- /tmp/cvsTeA1xp      Sun May  5 11:22:10 2002
570***************
571*** 0 ****
572--- 1,51 ----
573+ /* $Id: console.inl,v 1.2 2002/03/28 19:18:37 strauman Exp $ */
574+
575+ /* inline routines for console i/o
576+  *
577+  * The purpose of this file is to provide
578+  * generic inline functions, i.e. not using
579+  * hardcoded base addresses. These are
580+  * provided by the BSP header.
581+  */
582+
583+ #include <bsp.h>
584+
585+ #define INL_IN_DECL(name,base) \
586+ static inline unsigned char name(int off) \
587+ { \
588+       return in_8((unsigned char*)(((unsigned long)base) + off)); \
589+ }
590+
591+ #define INL_OUT_DECL(name,base) \
592+ static inline void name(int off, unsigned int val) \
593+ { \
594+       out_8((unsigned char*)(((unsigned long)base) + off), val); \
595+ }
596+
597+ #ifdef BSP_UART_IOBASE_COM1
598+ INL_IN_DECL(com1_inb, BSP_UART_IOBASE_COM1)
599+ INL_OUT_DECL(com1_outb,       BSP_UART_IOBASE_COM1)
600+ #endif
601+ #ifdef BSP_UART_IOBASE_COM2
602+ INL_IN_DECL(com2_inb, BSP_UART_IOBASE_COM2)
603+ INL_OUT_DECL(com2_outb,       BSP_UART_IOBASE_COM2)
604+ #endif
605+
606+ #if defined(BSP_CONSOLE_PORT)
607+ #if   (BSP_CONSOLE_PORT == BSP_UART_COM1) && defined(BSP_UART_IOBASE_COM1)
608+ #define INL_CONSOLE_INB               com1_inb
609+ #define INL_CONSOLE_OUTB      com1_outb
610+ #elif (BSP_CONSOLE_PORT == BSP_UART_COM2) && defined(BSP_UART_IOBASE_COM2)
611+ #define INL_CONSOLE_INB               com2_inb
612+ #define INL_CONSOLE_OUTB      com2_outb
613+ #endif
614+ #endif
615+
616+ #ifdef BSP_KBD_IOBASE
617+ INL_IN_DECL(kbd_inb,  BSP_KBD_IOBASE)
618+ INL_OUT_DECL(kbd_outb,        BSP_KBD_IOBASE)
619+ #endif
620+
621+ #ifdef BSP_VGA_IOBASE
622+ INL_OUT_DECL(vga_outb,  BSP_VGA_IOBASE)
623+ #endif
624Index: c/src/lib/libbsp/powerpc/shared/console/consoleIo.h
625===================================================================
626RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/consoleIo.h,v
627retrieving revision 1.1.1.1
628retrieving revision 1.2
629diff -c -r1.1.1.1 -r1.2
630*** c/src/lib/libbsp/powerpc/shared/console/consoleIo.h 2001/12/14 22:52:03     1.1.1.1
631--- c/src/lib/libbsp/powerpc/shared/console/consoleIo.h 2002/03/07 01:09:27     1.2
632***************
633*** 26,41 ****
634  typedef struct {
635    __io_ptr io_base;
636    __io_ptr isa_mem_base;
637-   __io_ptr pci_mmio_base;
638-   __io_ptr pci_dma_offset;
639  } board_memory_map;
640 
641  extern board_memory_map *ptr_mem_map;
642- extern unsigned long ticks_per_ms;
643 
644  extern int select_console(ioType t);
645  /* extern int printk(const char *, ...) __attribute__((format(printf, 1, 2))); */
646- extern void udelay(int);
647  extern void debug_putc(const unsigned char c);
648  extern int debug_getc(void);
649  extern int debug_tstc(void);
650--- 26,37 ----
651Index: c/src/lib/libbsp/powerpc/shared/console/inch.c
652===================================================================
653RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/inch.c,v
654retrieving revision 1.1.1.1
655retrieving revision 1.2
656diff -c -r1.1.1.1 -r1.2
657*** c/src/lib/libbsp/powerpc/shared/console/inch.c      2001/12/14 22:52:03     1.1.1.1
658--- c/src/lib/libbsp/powerpc/shared/console/inch.c      2002/03/07 01:09:28     1.2
659***************
660*** 22,33 ****
661  #include <bsp.h>
662  #include <bsp/irq.h>
663 
664  /*-------------------------------------------------------------------------+
665  | Constants
666  +--------------------------------------------------------------------------*/
667! #define KBD_CTL      0x61  /* -------------------------------- */
668! #define KBD_DATA     0x60  /* Ports for PC keyboard controller */
669! #define KBD_STATUS   0x64  /* -------------------------------- */
670 
671  #define KBD_BUF_SIZE 256
672 
673--- 22,35 ----
674  #include <bsp.h>
675  #include <bsp/irq.h>
676 
677+ #include "console.inl"
678+
679  /*-------------------------------------------------------------------------+
680  | Constants
681  +--------------------------------------------------------------------------*/
682! #define KBD_CTL      0x1  /* -------------------------------- */
683! #define KBD_DATA     0x0  /* Port offsets for PC keyboard controller */
684! #define KBD_STATUS   0x4  /* -------------------------------- */
685 
686  #define KBD_BUF_SIZE 256
687 
688***************
689*** 62,80 ****
690  static rtems_unsigned16 kbd_end   = KBD_BUF_SIZE - 1;
691 
692  /*-------------------------------------------------------------------------+
693- |         Function: rtemsReboot
694- |      Description: Reboot the PC.
695- | Global Variables: None.
696- |        Arguments: None.
697- |          Returns: Nothing.
698- +--------------------------------------------------------------------------*/
699- void rtemsReboot(void)
700- {
701-   /* shutdown and reboot */
702-   outport_byte(0x64, 0xFE);      /* use keyboard controler to do the job... */
703- } /* rtemsReboot */
704-
705- /*-------------------------------------------------------------------------+
706  |         Function: _IBMPC_scankey
707  |      Description: This function can be called during a poll for input, or by
708  |                   an ISR. Basically any time you want to process a keypress.
709--- 64,69 ----
710***************
711*** 97,114 ****
712    *outChar = NULL; /* default value if we return FALSE */
713 
714    /* Read keyboard controller, toggle enable */
715!   inport_byte(KBD_CTL, inChar);
716!   outport_byte(KBD_CTL, inChar & ~0x80);
717!   outport_byte(KBD_CTL, inChar | 0x80);
718!   outport_byte(KBD_CTL, inChar & ~0x80);
719 
720    /* See if it has data */
721!   inport_byte(KBD_STATUS, inChar);
722    if ((inChar & 0x01) == 0)
723      return FALSE;
724 
725    /* Read the data.  Handle nonsense with shift, control, etc. */
726!   inport_byte(KBD_DATA, inChar);
727 
728    if (extended)
729      extended--;
730--- 86,103 ----
731    *outChar = NULL; /* default value if we return FALSE */
732 
733    /* Read keyboard controller, toggle enable */
734!   inChar=kbd_inb(KBD_CTL);
735!   kbd_outb(KBD_CTL, inChar & ~0x80);
736!   kbd_outb(KBD_CTL, inChar | 0x80);
737!   kbd_outb(KBD_CTL, inChar & ~0x80);
738 
739    /* See if it has data */
740!   inChar=kbd_inb(KBD_STATUS);
741    if ((inChar & 0x01) == 0)
742      return FALSE;
743 
744    /* Read the data.  Handle nonsense with shift, control, etc. */
745!   inChar=kbd_inb(KBD_DATA);
746 
747    if (extended)
748      extended--;
749Index: c/src/lib/libbsp/powerpc/shared/console/polled_io.c
750===================================================================
751RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/polled_io.c,v
752retrieving revision 1.1.1.1
753retrieving revision 1.3
754diff -c -r1.1.1.1 -r1.3
755*** c/src/lib/libbsp/powerpc/shared/console/polled_io.c 2001/12/14 22:52:04     1.1.1.1
756--- c/src/lib/libbsp/powerpc/shared/console/polled_io.c 2002/04/13 04:12:13     1.3
757***************
758*** 20,36 ****
759  #include <libcpu/page.h>
760  #include <libcpu/cpu.h>
761  #include <libcpu/mmu.h>
762- #include "keyboard.h"
763  #include <libcpu/io.h>
764  #include <string.h>
765  #include <stdarg.h>
766  #include <bsp/consoleIo.h>
767  #include <libcpu/spr.h>
768 
769  typedef unsigned long long u64;
770  typedef long long s64;
771  typedef unsigned int u32;
772 
773  unsigned short plain_map[NR_KEYS] = {
774        0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
775        0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
776--- 20,53 ----
777  #include <libcpu/page.h>
778  #include <libcpu/cpu.h>
779  #include <libcpu/mmu.h>
780  #include <libcpu/io.h>
781  #include <string.h>
782  #include <stdarg.h>
783  #include <bsp/consoleIo.h>
784+ #include <bsp.h>
785  #include <libcpu/spr.h>
786 
787+ #ifdef BSP_KBD_IOBASE
788+ #define USE_KBD_SUPPORT
789+ #endif
790+ #ifdef BSP_VGA_IOBASE
791+ #define USE_VGA_SUPPORT
792+ #endif
793+
794+ #ifdef USE_KBD_SUPPORT
795+ #include "keyboard.h"
796+ #endif
797+ #include "console.inl"
798+
799+ #ifdef __BOOT__
800+ extern void boot_udelay();
801+ #endif
802+
803  typedef unsigned long long u64;
804  typedef long long s64;
805  typedef unsigned int u32;
806 
807+ #ifdef USE_KBD_SUPPORT
808  unsigned short plain_map[NR_KEYS] = {
809        0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
810        0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
811***************
812*** 296,305 ****
813 
814  /* These #defines have been copied from drivers/char/pc_keyb.h, by
815   * Martin Mares (mj@ucw.cz). 
816   */
817! #define KBD_STATUS_REG                0x64    /* Status register (R) */
818! #define KBD_CNTL_REG          0x64    /* Controller command register (W) */
819! #define KBD_DATA_REG          0x60    /* Keyboard data register (R/W) */
820 
821  /*
822   *    Keyboard Controller Commands
823--- 313,323 ----
824 
825  /* These #defines have been copied from drivers/char/pc_keyb.h, by
826   * Martin Mares (mj@ucw.cz). 
827+  * converted to offsets by Till Straumann <strauman@slac.stanford.edu>
828   */
829! #define KBD_STATUS_REG                0x4     /* Status register (R) */
830! #define KBD_CNTL_REG          0x4     /* Controller command register (W) */
831! #define KBD_DATA_REG          0x0     /* Keyboard data register (R/W) */
832 
833  /*
834   *    Keyboard Controller Commands
835***************
836*** 356,361 ****
837--- 374,381 ----
838  SPR_RW(DEC)
839  SPR_RO(PVR)
840 
841+ #endif /* USE_KBD_SUPPORT */
842+
843 
844  /* Early messages after mm init but before console init are kept in log
845   * buffers.
846***************
847*** 377,386 ****
848  #endif
849 
850  static board_memory_map mem_map = {
851!   (__io_ptr) 0x80000000,
852!   (__io_ptr) 0xc0000000,
853!   (__io_ptr) 0xc0000000,
854!   (__io_ptr) 0x80000000
855  };
856 
857  board_memory_map *ptr_mem_map = &mem_map;
858--- 397,404 ----
859  #endif
860 
861  static board_memory_map mem_map = {
862!   (__io_ptr) _IO_BASE,                /* from libcpu/io.h */
863!   (__io_ptr) _ISA_MEM_BASE,
864  };
865 
866  board_memory_map *ptr_mem_map = &mem_map;
867***************
868*** 404,421 ****
869 
870  extern console_io* curIo;
871 
872- unsigned long ticks_per_ms = 1000000; /* Decrementer ticks per ms (true for 601) */
873-
874- /* The decrementer is present on all processors and the RTC on the 601
875-  * has the annoying characteristic of jumping from 1e9 to 0, so we
876-  * use the decrementer.
877-  */
878- void udelay(int us) {
879-       us = us*ticks_per_ms/1000;
880-       _write_DEC(us);
881-       while((int)_read_DEC() >= 0);
882- }
883-
884  void debug_putc(const u_char c)
885  {
886    curIo->putc(c);
887--- 422,427 ----
888***************
889*** 473,479 ****
890  #define LSR_TEMT 0x40  /* Xmitter empty */
891  #define LSR_ERR  0x80  /* Error */
892 
893- #define COM1  0x3F8
894 
895  #ifdef STATIC_LOG_ALLOC
896  static int global_index = 0;
897--- 479,484 ----
898***************
899*** 543,565 ****
900        }
901  }
902 
903  void serial_putc(const u_char c)
904  {
905!       while ((inb(COM1+lsr) & LSR_THRE) == 0) ;
906!       outb(c, COM1+thr);
907  }
908   
909  int serial_getc(void)
910  {
911!       while ((inb(COM1+lsr) & LSR_DR) == 0) ;
912!       return (inb(COM1+rbr));
913  }
914 
915  int serial_tstc(void)
916  {
917!       return ((inb(COM1+lsr) & LSR_DR) != 0);
918  }
919 
920  static void scroll(void)
921  {
922        int i;
923--- 548,575 ----
924        }
925  }
926 
927+ #ifndef INL_CONSOLE_INB
928+ #error "BSP probably didn't define a console port"
929+ #endif
930+
931  void serial_putc(const u_char c)
932  {
933!       while ((INL_CONSOLE_INB(lsr) & LSR_THRE) == 0) ;
934!       INL_CONSOLE_OUTB(thr, c);
935  }
936   
937  int serial_getc(void)
938  {
939!       while ((INL_CONSOLE_INB(lsr) & LSR_DR) == 0) ;
940!       return (INL_CONSOLE_INB(rbr));
941  }
942 
943  int serial_tstc(void)
944  {
945!       return ((INL_CONSOLE_INB(lsr) & LSR_DR) != 0);
946  }
947 
948+ #ifdef USE_VGA_SUPPORT
949  static void scroll(void)
950  {
951        int i;
952***************
953*** 579,588 ****
954  cursor(int x, int y)
955  {
956        int pos = console_global_data.cols*y + x;
957!       outb(14, 0x3D4);
958!       outb(pos>>8, 0x3D5);
959!       outb(15, 0x3D4);
960!       outb(pos, 0x3D5);
961  }
962 
963  void
964--- 589,598 ----
965  cursor(int x, int y)
966  {
967        int pos = console_global_data.cols*y + x;
968!       vga_outb(14, 0x14);
969!       vga_outb(0x15, pos>>8);
970!       vga_outb(0x14, 15);
971!       vga_outb(0x15, pos);
972  }
973 
974  void
975***************
976*** 620,635 ****
977        console_global_data.orig_x = x;
978        console_global_data.orig_y = y;
979  }
980 
981  /* Keyboard support */
982  static int kbd_getc(void)
983  {
984        unsigned char dt, brk, val;
985        unsigned code;
986  loop:
987!       while((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) ;
988 
989!       dt = inb(KBD_DATA_REG);
990 
991        brk = dt & 0x80;        /* brk == 1 on key release */
992        dt = dt & 0x7f;         /* keycode */
993--- 630,647 ----
994        console_global_data.orig_x = x;
995        console_global_data.orig_y = y;
996  }
997+ #endif /* USE_VGA_SUPPORT */
998 
999+ #ifdef USE_KBD_SUPPORT
1000  /* Keyboard support */
1001  static int kbd_getc(void)
1002  {
1003        unsigned char dt, brk, val;
1004        unsigned code;
1005  loop:
1006!       while((kbd_inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) ;
1007 
1008!       dt = kbd_inb(KBD_DATA_REG);
1009 
1010        brk = dt & 0x80;        /* brk == 1 on key release */
1011        dt = dt & 0x7f;         /* keycode */
1012***************
1013*** 667,674 ****
1014                else if (val == KVAL(K_ENTER)) {
1015  enter:                    /* Wait for key up */
1016                    while (1) {
1017!                       while((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) ;
1018!                       dt = inb(KBD_DATA_REG);
1019                        if (dt & 0x80) /* key up */ break;
1020                    }
1021                    return 10;
1022--- 679,686 ----
1023                else if (val == KVAL(K_ENTER)) {
1024  enter:                    /* Wait for key up */
1025                    while (1) {
1026!                       while((kbd_inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) ;
1027!                       dt = kbd_inb(KBD_DATA_REG);
1028                        if (dt & 0x80) /* key up */ break;
1029                    }
1030                    return 10;
1031***************
1032*** 732,756 ****
1033  static int kbd_get(int ms) {
1034        int status, data;
1035        while(1) {
1036!               status = inb(KBD_STATUS_REG);
1037                if (status & KBD_STAT_OBF) {
1038!                       data = inb(KBD_DATA_REG);
1039                        if (status & (KBD_STAT_GTO | KBD_STAT_PERR))
1040                                return -1;
1041                        else
1042                                return data;
1043                }
1044                if (--ms < 0) return -1;
1045!               udelay(1000);
1046        }
1047  }
1048 
1049  static void kbd_put(u_char c, int ms, int port) {
1050!       while (inb(KBD_STATUS_REG) & KBD_STAT_IBF) {
1051                if (--ms < 0) return;
1052!               udelay(1000);
1053        }
1054!       outb(c, port);
1055  }
1056 
1057  int kbdreset(void)
1058--- 744,776 ----
1059  static int kbd_get(int ms) {
1060        int status, data;
1061        while(1) {
1062!               status = kbd_inb(KBD_STATUS_REG);
1063                if (status & KBD_STAT_OBF) {
1064!                       data = kbd_inb(KBD_DATA_REG);
1065                        if (status & (KBD_STAT_GTO | KBD_STAT_PERR))
1066                                return -1;
1067                        else
1068                                return data;
1069                }
1070                if (--ms < 0) return -1;
1071! #ifdef __BOOT__
1072!               boot_udelay(1000);
1073! #else
1074!               rtems_bsp_delay(1000);
1075! #endif
1076        }
1077  }
1078 
1079  static void kbd_put(u_char c, int ms, int port) {
1080!       while (kbd_inb(KBD_STATUS_REG) & KBD_STAT_IBF) {
1081                if (--ms < 0) return;
1082! #ifdef __BOOT__
1083!               boot_udelay(1000);
1084! #else
1085!               rtems_bsp_delay(1000);
1086! #endif
1087        }
1088!       kbd_outb(port, c);
1089  }
1090 
1091  int kbdreset(void)
1092***************
1093*** 796,803 ****
1094 
1095  int kbd_tstc(void)
1096  {
1097!       return ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) != 0);
1098  }
1099 
1100  const struct console_io
1101  vacuum_console_functions = {
1102--- 816,824 ----
1103 
1104  int kbd_tstc(void)
1105  {
1106!       return ((kbd_inb(KBD_STATUS_REG) & KBD_STAT_OBF) != 0);
1107  }
1108+ #endif /* USE_KBD_SUPPORT */
1109 
1110  const struct console_io
1111  vacuum_console_functions = {
1112***************
1113*** 811,829 ****
1114        log_putc,
1115        vacuum_getc,
1116        vacuum_tstc
1117! },
1118!
1119  serial_console_functions = {
1120        serial_putc,
1121        serial_getc,
1122        serial_tstc
1123! },
1124!
1125  vga_console_functions = {
1126        vga_putc,
1127        kbd_getc,
1128        kbd_tstc
1129! };
1130 
1131  console_io* curIo = (console_io*) &vacuum_console_functions;
1132 
1133--- 832,853 ----
1134        log_putc,
1135        vacuum_getc,
1136        vacuum_tstc
1137! }
1138! ,
1139  serial_console_functions = {
1140        serial_putc,
1141        serial_getc,
1142        serial_tstc
1143! }
1144! #if defined(USE_KBD_SUPPORT) && defined(USE_VGA_SUPPORT)
1145! ,
1146  vga_console_functions = {
1147        vga_putc,
1148        kbd_getc,
1149        kbd_tstc
1150! }
1151! #endif
1152! ;
1153 
1154  console_io* curIo = (console_io*) &vacuum_console_functions;
1155 
1156***************
1157*** 834,840 ****
1158--- 858,866 ----
1159    case CONSOLE_VACUUM         : curIo = (console_io*)&vacuum_console_functions; break;
1160    case CONSOLE_LOG    : curIo = (console_io*)&log_console_functions; break;
1161    case CONSOLE_SERIAL         : curIo = (console_io*)&serial_console_functions; break;
1162+ #if defined(USE_KBD_SUPPORT) && defined(USE_VGA_SUPPORT)
1163    case CONSOLE_VGA    : curIo = (console_io*)&vga_console_functions; break;
1164+ #endif
1165    default             : curIo = (console_io*)&vacuum_console_functions;break;
1166    }
1167    if (curType == CONSOLE_LOG) flush_log();
1168Index: c/src/lib/libbsp/powerpc/shared/console/reboot.c
1169===================================================================
1170RCS file: reboot.c
1171diff -N reboot.c
1172*** /dev/null   Thu Aug 24 02:00:32 2000
1173--- /tmp/cvsP1ssR6      Sun May  5 11:22:11 2002
1174***************
1175*** 0 ****
1176--- 1,16 ----
1177+ /* $Id$ */
1178+
1179+ #include "console.inl"
1180+
1181+ /*-------------------------------------------------------------------------+
1182+ |         Function: rtemsReboot
1183+ |      Description: Reboot the PC.
1184+ | Global Variables: None.
1185+ |        Arguments: None.
1186+ |          Returns: Nothing.
1187+ +--------------------------------------------------------------------------*/
1188+ void rtemsReboot(void)
1189+ {
1190+   /* shutdown and reboot */
1191+   kbd_outb(0x4, 0xFE);      /* use keyboard controler to do the job... */
1192+ } /* rtemsReboot */
1193Index: c/src/lib/libbsp/powerpc/shared/console/uart.c
1194===================================================================
1195RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/uart.c,v
1196retrieving revision 1.1.1.1
1197retrieving revision 1.3
1198diff -c -r1.1.1.1 -r1.3
1199*** c/src/lib/libbsp/powerpc/shared/console/uart.c      2001/12/14 22:52:04     1.1.1.1
1200--- c/src/lib/libbsp/powerpc/shared/console/uart.c      2002/03/28 19:18:37     1.3
1201***************
1202*** 19,30 ****
1203 
1204  struct uart_data
1205  {
1206    int hwFlow;
1207    int baud;
1208  };
1209 
1210! static struct uart_data uart_data[2];
1211 
1212  /*
1213   * Macros to read/wirte register of uart, if configuration is
1214   * different just rewrite these macros
1215--- 19,60 ----
1216 
1217  struct uart_data
1218  {
1219+   unsigned long ioBase;
1220    int hwFlow;
1221    int baud;
1222  };
1223 
1224! /*
1225!  * Initialization of BSP specific data.
1226!  * The constants are pulled in from a BSP
1227!  * specific file, whereas all of the code
1228!  * in this file is generic and makes no
1229!  * assumptions about addresses, irq vectors
1230!  * etc...
1231!  */
1232!
1233! #define UART_UNSUPP ((unsigned long)(-1))
1234!
1235! static struct uart_data uart_data[2] = {
1236!       {
1237! #ifdef        BSP_UART_IOBASE_COM1
1238!               BSP_UART_IOBASE_COM1,
1239! #else
1240!               UART_UNSUPP,
1241! #endif
1242!       },
1243!       {
1244! #ifdef        BSP_UART_IOBASE_COM2
1245!               BSP_UART_IOBASE_COM2,
1246! #else
1247!               UART_UNSUPP,
1248! #endif
1249!       },
1250! };
1251 
1252+ #define MAX_UARTS (sizeof(uart_data)/sizeof(uart_data[0]))
1253+ #define SANITY_CHECK(uart) \
1254+   assert( MAX_UARTS > (unsigned)(uart) && uart_data[(uart)].ioBase != UART_UNSUPP )
1255  /*
1256   * Macros to read/wirte register of uart, if configuration is
1257   * different just rewrite these macros
1258***************
1259*** 33,63 ****
1260  static inline unsigned char
1261  uread(int uart, unsigned int reg)
1262  {
1263-   register unsigned char val;
1264 
1265!   if(uart == 0)
1266!     {
1267!       inport_byte(COM1_BASE_IO+reg, val);
1268!     }
1269!   else
1270!     {
1271!       inport_byte(COM2_BASE_IO+reg, val);
1272!     }
1273 
1274-   return val;
1275  }
1276 
1277  static inline void     
1278  uwrite(int uart, int reg, unsigned int val)
1279  {
1280!   if(uart == 0)
1281!     {
1282!       outport_byte(COM1_BASE_IO+reg, val);
1283!     }
1284!   else
1285!     {
1286!       outport_byte(COM2_BASE_IO+reg, val);
1287!     }
1288  }
1289 
1290  #ifdef UARTDEBUG
1291--- 63,77 ----
1292  static inline unsigned char
1293  uread(int uart, unsigned int reg)
1294  {
1295 
1296!   return in_8((unsigned char*)(uart_data[uart].ioBase + reg));
1297 
1298  }
1299 
1300  static inline void     
1301  uwrite(int uart, int reg, unsigned int val)
1302  {
1303!   out_8((unsigned char*)(uart_data[uart].ioBase + reg), val);
1304  }
1305 
1306  #ifdef UARTDEBUG
1307***************
1308*** 103,109 ****
1309    unsigned char tmp;
1310   
1311    /* Sanity check */
1312!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1313   
1314    switch(baud)
1315      {
1316--- 117,123 ----
1317    unsigned char tmp;
1318   
1319    /* Sanity check */
1320!   SANITY_CHECK(uart);
1321   
1322    switch(baud)
1323      {
1324***************
1325*** 166,172 ****
1326    unsigned char mcr, ier;
1327 
1328    /* Sanity check */
1329!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1330   
1331    /*
1332     * This function may be called whenever TERMIOS parameters
1333--- 180,186 ----
1334    unsigned char mcr, ier;
1335 
1336    /* Sanity check */
1337!   SANITY_CHECK(uart);
1338   
1339    /*
1340     * This function may be called whenever TERMIOS parameters
1341***************
1342*** 197,203 ****
1343  BSP_uart_intr_ctrl(int uart, int cmd)
1344  {
1345 
1346!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1347 
1348    switch(cmd)
1349      {
1350--- 211,217 ----
1351  BSP_uart_intr_ctrl(int uart, int cmd)
1352  {
1353 
1354!   SANITY_CHECK(uart);
1355 
1356    switch(cmd)
1357      {
1358***************
1359*** 260,266 ****
1360  {
1361    unsigned int mcr;
1362   
1363!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1364 
1365    if(!uart_data[uart].hwFlow)
1366      {
1367--- 274,280 ----
1368  {
1369    unsigned int mcr;
1370   
1371!   SANITY_CHECK(uart);
1372 
1373    if(!uart_data[uart].hwFlow)
1374      {
1375***************
1376*** 281,287 ****
1377  {
1378    unsigned int mcr;
1379 
1380!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1381 
1382    if(!uart_data[uart].hwFlow)
1383      {
1384--- 295,301 ----
1385  {
1386    unsigned int mcr;
1387 
1388!   SANITY_CHECK(uart);
1389 
1390    if(!uart_data[uart].hwFlow)
1391      {
1392***************
1393*** 311,317 ****
1394  {
1395    unsigned char val;
1396 
1397!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1398 
1399    val = uread(uart, LSR);
1400 
1401--- 325,331 ----
1402  {
1403    unsigned char val;
1404 
1405!   SANITY_CHECK(uart);
1406 
1407    val = uread(uart, LSR);
1408 
1409***************
1410*** 353,359 ****
1411    unsigned char val1;
1412   
1413    /* Sanity check */
1414!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1415   
1416    for(;;)
1417      {
1418--- 367,373 ----
1419    unsigned char val1;
1420   
1421    /* Sanity check */
1422!   SANITY_CHECK(uart);
1423   
1424    for(;;)
1425      {
1426***************
1427*** 394,400 ****
1428  {
1429    unsigned char val;
1430 
1431!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1432   
1433    for(;;)
1434      {
1435--- 408,414 ----
1436  {
1437    unsigned char val;
1438 
1439!   SANITY_CHECK(uart);
1440   
1441    for(;;)
1442      {
1443***************
1444*** 415,434 ****
1445        return BSP_uart_polled_read(BSPConsolePort);
1446  }
1447 
1448 
1449  /* ================ Termios support  =================*/
1450 
1451! static volatile int  termios_stopped_com1        = 0;
1452! static volatile int  termios_tx_active_com1      = 0;
1453! static void*       termios_ttyp_com1           = NULL;
1454! static char          termios_tx_hold_com1        = 0;
1455! static volatile char termios_tx_hold_valid_com1  = 0;
1456!
1457! static volatile int  termios_stopped_com2        = 0;
1458! static volatile int  termios_tx_active_com2      = 0;
1459! static void*       termios_ttyp_com2           = NULL;
1460! static char          termios_tx_hold_com2        = 0;
1461! static volatile char termios_tx_hold_valid_com2  = 0;
1462 
1463  /*
1464   * Set channel parameters
1465--- 429,485 ----
1466        return BSP_uart_polled_read(BSPConsolePort);
1467  }
1468 
1469+ static void
1470+ uart_noop(const rtems_irq_connect_data *unused)
1471+ {
1472+   return;
1473+ }
1474 
1475+ /* note that the IRQ names contain _ISA_ for legacy
1476+  * reasons. They can be any interrupt, depending
1477+  * on the particular BSP...
1478+  */
1479+
1480+ static int
1481+ uart_isr_is_on(const rtems_irq_connect_data *irq)
1482+ {
1483+ int uart = (irq->name == BSP_ISA_UART_COM1_IRQ) ?
1484+                       BSP_UART_COM1 : BSP_UART_COM2;
1485+   return uread(uart,IER);
1486+ }
1487+
1488+ static int
1489+ doit(int uart, rtems_irq_hdl handler, int (*p)(const rtems_irq_connect_data*))
1490+ {
1491+       rtems_irq_connect_data d={0};
1492+       d.name = (uart == BSP_UART_COM1) ?
1493+                       BSP_ISA_UART_COM1_IRQ : BSP_ISA_UART_COM2_IRQ;
1494+       d.off  = d.on = uart_noop;
1495+       d.isOn = uart_isr_is_on;
1496+       d.hdl  = handler;
1497+       return p(&d);
1498+ }
1499+
1500+ int
1501+ BSP_uart_install_isr(int uart, rtems_irq_hdl handler)
1502+ {
1503+       return doit(uart, handler, BSP_install_rtems_irq_handler);
1504+ }
1505+       
1506+ int
1507+ BSP_uart_remove_isr(int uart, rtems_irq_hdl handler)
1508+ {
1509+       return doit(uart, handler, BSP_remove_rtems_irq_handler);
1510+ }
1511+
1512+
1513  /* ================ Termios support  =================*/
1514 
1515! static volatile int  termios_stopped_com[2]        = {0,0};
1516! static volatile int  termios_tx_active_com[2]      = {0,0};
1517! static void*       termios_ttyp_com[2]           = {NULL,NULL};
1518! static char          termios_tx_hold_com[2]        = {0,0};
1519! static volatile char termios_tx_hold_valid_com[2]  = {0,0};
1520 
1521  /*
1522   * Set channel parameters
1523***************
1524*** 437,485 ****
1525  BSP_uart_termios_set(int uart, void *ttyp)
1526  {
1527    unsigned char val;
1528!   assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2);
1529   
1530!   if(uart == BSP_UART_COM1)
1531      {
1532!       if(uart_data[uart].hwFlow)
1533!       {
1534!         val = uread(uart, MSR);
1535 
1536!         termios_stopped_com1   = (val & CTS) ? 0 : 1;
1537!       }
1538!       else
1539!       {
1540!         termios_stopped_com1 = 0;
1541!       }
1542!       termios_tx_active_com1      = 0;
1543!       termios_ttyp_com1           = ttyp;
1544!       termios_tx_hold_com1        = 0;
1545!       termios_tx_hold_valid_com1  = 0;
1546      }
1547    else
1548!     {
1549!       if(uart_data[uart].hwFlow)
1550!       {
1551!         val = uread(uart, MSR);
1552!
1553!         termios_stopped_com2   = (val & CTS) ? 0 : 1;
1554!       }
1555!       else
1556!       {
1557!         termios_stopped_com2 = 0;
1558!       }
1559!       termios_tx_active_com2      = 0;
1560!       termios_ttyp_com2           = ttyp;
1561!       termios_tx_hold_com2        = 0;
1562!       termios_tx_hold_valid_com2  = 0;
1563!     }
1564 
1565    return;
1566  }
1567 
1568  int
1569! BSP_uart_termios_write_com1(int minor, const char *buf, int len)
1570  {
1571    assert(buf != NULL);
1572 
1573    if(len <= 0)
1574--- 488,517 ----
1575  BSP_uart_termios_set(int uart, void *ttyp)
1576  {
1577    unsigned char val;
1578!   SANITY_CHECK(uart);
1579   
1580!   if(uart_data[uart].hwFlow)
1581      {
1582!       val = uread(uart, MSR);
1583 
1584!       termios_stopped_com[uart]    = (val & CTS) ? 0 : 1;
1585      }
1586    else
1587!   {
1588!       termios_stopped_com[uart] = 0;
1589!   }
1590!   termios_tx_active_com[uart]      = 0;
1591!   termios_ttyp_com[uart]           = ttyp;
1592!   termios_tx_hold_com[uart]        = 0;
1593!   termios_tx_hold_valid_com[uart]  = 0;
1594 
1595    return;
1596  }
1597 
1598  int
1599! BSP_uart_termios_write_com(int minor, const char *buf, int len)
1600  {
1601+   int uart=minor;     /* could differ, theoretically */
1602    assert(buf != NULL);
1603 
1604    if(len <= 0)
1605***************
1606*** 491,512 ****
1607    /*   assert((uread(BSP_UART_COM1, LSR) & THRE) != 0); */
1608         
1609 
1610!   if(termios_stopped_com1)
1611      {
1612        /* CTS low */
1613!       termios_tx_hold_com1       = *buf;
1614!       termios_tx_hold_valid_com1 = 1;
1615        return 0;
1616      }
1617 
1618    /* Write character */
1619!   uwrite(BSP_UART_COM1, THR, *buf & 0xff);
1620 
1621    /* Enable interrupts if necessary */
1622!   if(!termios_tx_active_com1 && uart_data[BSP_UART_COM1].hwFlow)
1623      {
1624!       termios_tx_active_com1 = 1;
1625!       uwrite(BSP_UART_COM1, IER,
1626             (RECEIVE_ENABLE  |
1627              TRANSMIT_ENABLE |
1628              RECEIVER_LINE_ST_ENABLE |
1629--- 523,544 ----
1630    /*   assert((uread(BSP_UART_COM1, LSR) & THRE) != 0); */
1631         
1632 
1633!   if(termios_stopped_com[uart])
1634      {
1635        /* CTS low */
1636!       termios_tx_hold_com[uart]       = *buf;
1637!       termios_tx_hold_valid_com[uart] = 1;
1638        return 0;
1639      }
1640 
1641    /* Write character */
1642!   uwrite(uart, THR, *buf & 0xff);
1643 
1644    /* Enable interrupts if necessary */
1645!   if(!termios_tx_active_com[uart] && uart_data[uart].hwFlow)
1646      {
1647!       termios_tx_active_com[uart] = 1;
1648!       uwrite(uart, IER,
1649             (RECEIVE_ENABLE  |
1650              TRANSMIT_ENABLE |
1651              RECEIVER_LINE_ST_ENABLE |
1652***************
1653*** 514,523 ****
1654             )
1655            );
1656      }
1657!   else if(!termios_tx_active_com1)
1658      {
1659!       termios_tx_active_com1 = 1;
1660!       uwrite(BSP_UART_COM1, IER,
1661             (RECEIVE_ENABLE  |
1662              TRANSMIT_ENABLE |
1663              RECEIVER_LINE_ST_ENABLE
1664--- 546,555 ----
1665             )
1666            );
1667      }
1668!   else if(!termios_tx_active_com[uart])
1669      {
1670!       termios_tx_active_com[uart] = 1;
1671!       uwrite(uart, IER,
1672             (RECEIVE_ENABLE  |
1673              TRANSMIT_ENABLE |
1674              RECEIVER_LINE_ST_ENABLE
1675***************
1676*** 528,589 ****
1677    return 0;
1678  }
1679 
1680! int
1681! BSP_uart_termios_write_com2(int minor, const char *buf, int len)
1682  {
1683-   assert(buf != NULL);
1684-
1685-   if(len <= 0)
1686-     {
1687-       return 0;
1688-     }
1689-
1690-
1691-   /* If there TX buffer is busy - something is royally screwed up */
1692-   assert((uread(BSP_UART_COM2, LSR) & THRE) != 0);
1693-
1694-   if(termios_stopped_com2)
1695-     {
1696-       /* CTS low */
1697-       termios_tx_hold_com2       = *buf;
1698-       termios_tx_hold_valid_com2 = 1;
1699-       return 0;
1700-     }
1701-
1702-   /* Write character */
1703-
1704-   uwrite(BSP_UART_COM2, THR, *buf & 0xff);
1705-
1706-   /* Enable interrupts if necessary */
1707-   if(!termios_tx_active_com2 && uart_data[BSP_UART_COM2].hwFlow)
1708-     {
1709-       termios_tx_active_com2 = 1;
1710-       uwrite(BSP_UART_COM2, IER,
1711-            (RECEIVE_ENABLE  |
1712-             TRANSMIT_ENABLE |
1713-             RECEIVER_LINE_ST_ENABLE |
1714-             MODEM_ENABLE
1715-            )
1716-           );
1717-     }
1718-   else if(!termios_tx_active_com2)
1719-     {
1720-       termios_tx_active_com2 = 1;
1721-       uwrite(BSP_UART_COM2, IER,
1722-            (RECEIVE_ENABLE  |
1723-             TRANSMIT_ENABLE |
1724-             RECEIVER_LINE_ST_ENABLE
1725-            )
1726-           );
1727-     }
1728-
1729-   return 0;
1730- }
1731-
1732-
1733- void
1734- BSP_uart_termios_isr_com1(void)
1735- {
1736    unsigned char buf[40];
1737    unsigned char val;
1738    int      off, ret, vect;
1739--- 560,568 ----
1740    return 0;
1741  }
1742 
1743! static void
1744! BSP_uart_termios_isr_com(int uart)
1745  {
1746    unsigned char buf[40];
1747    unsigned char val;
1748    int      off, ret, vect;
1749***************
1750*** 592,620 ****
1751 
1752    for(;;)
1753      {
1754!       vect = uread(BSP_UART_COM1, IIR) & 0xf;
1755       
1756        switch(vect)
1757        {
1758        case MODEM_STATUS :
1759!         val = uread(BSP_UART_COM1, MSR);
1760!         if(uart_data[BSP_UART_COM1].hwFlow)
1761            {
1762              if(val & CTS)
1763                {
1764                  /* CTS high */
1765!                 termios_stopped_com1 = 0;
1766!                 if(termios_tx_hold_valid_com1)
1767                    {
1768!                     termios_tx_hold_valid_com1 = 0;
1769!                     BSP_uart_termios_write_com1(0, &termios_tx_hold_com1,
1770                                                    1);
1771                    }
1772                }
1773              else
1774                {
1775                  /* CTS low */
1776!                 termios_stopped_com1 = 1;
1777                }
1778            }
1779          break;
1780--- 571,599 ----
1781 
1782    for(;;)
1783      {
1784!       vect = uread(uart, IIR) & 0xf;
1785       
1786        switch(vect)
1787        {
1788        case MODEM_STATUS :
1789!         val = uread(uart, MSR);
1790!         if(uart_data[uart].hwFlow)
1791            {
1792              if(val & CTS)
1793                {
1794                  /* CTS high */
1795!                 termios_stopped_com[uart] = 0;
1796!                 if(termios_tx_hold_valid_com[uart])
1797                    {
1798!                     termios_tx_hold_valid_com[uart] = 0;
1799!                     BSP_uart_termios_write_com(uart, &termios_tx_hold_com[uart],
1800                                                    1);
1801                    }
1802                }
1803              else
1804                {
1805                  /* CTS low */
1806!                 termios_stopped_com[uart] = 1;
1807                }
1808            }
1809          break;
1810***************
1811*** 623,629 ****
1812          if(off != 0)
1813            {
1814              /* Update rx buffer */
1815!             rtems_termios_enqueue_raw_characters(termios_ttyp_com1,
1816                                                   (char *)buf,
1817                                                   off);
1818            }
1819--- 602,608 ----
1820          if(off != 0)
1821            {
1822              /* Update rx buffer */
1823!             rtems_termios_enqueue_raw_characters(termios_ttyp_com[uart],
1824                                                   (char *)buf,
1825                                                   off);
1826            }
1827***************
1828*** 634,671 ****
1829           * if there is nothing more to send.
1830           */
1831 
1832!         ret = rtems_termios_dequeue_characters(termios_ttyp_com1, 1);
1833 
1834          /* If nothing else to send disable interrupts */
1835!         if(ret == 0 && uart_data[BSP_UART_COM1].hwFlow)
1836            {
1837!             uwrite(BSP_UART_COM1, IER,
1838                     (RECEIVE_ENABLE  |
1839                      RECEIVER_LINE_ST_ENABLE |
1840                      MODEM_ENABLE
1841                     )
1842                    );
1843!               termios_tx_active_com1 = 0;
1844            }
1845          else if(ret == 0)
1846            {
1847!             uwrite(BSP_UART_COM1, IER,
1848                     (RECEIVE_ENABLE  |
1849                      RECEIVER_LINE_ST_ENABLE
1850                     )
1851                    );
1852!               termios_tx_active_com1 = 0;
1853            }
1854          break;
1855        case RECEIVER_DATA_AVAIL :
1856        case CHARACTER_TIMEOUT_INDICATION:
1857          /* RX data ready */
1858          assert(off < sizeof(buf));
1859!         buf[off++] = uread(BSP_UART_COM1, RBR);
1860          break;
1861        case RECEIVER_ERROR:
1862          /* RX error: eat character */
1863!          uartError(BSP_UART_COM1);
1864          break;
1865        default:
1866          /* Should not happen */
1867--- 613,650 ----
1868           * if there is nothing more to send.
1869           */
1870 
1871!         ret = rtems_termios_dequeue_characters(termios_ttyp_com[uart], 1);
1872 
1873          /* If nothing else to send disable interrupts */
1874!         if(ret == 0 && uart_data[uart].hwFlow)
1875            {
1876!             uwrite(uart, IER,
1877                     (RECEIVE_ENABLE  |
1878                      RECEIVER_LINE_ST_ENABLE |
1879                      MODEM_ENABLE
1880                     )
1881                    );
1882!               termios_tx_active_com[uart] = 0;
1883            }
1884          else if(ret == 0)
1885            {
1886!             uwrite(uart, IER,
1887                     (RECEIVE_ENABLE  |
1888                      RECEIVER_LINE_ST_ENABLE
1889                     )
1890                    );
1891!               termios_tx_active_com[uart] = 0;
1892            }
1893          break;
1894        case RECEIVER_DATA_AVAIL :
1895        case CHARACTER_TIMEOUT_INDICATION:
1896          /* RX data ready */
1897          assert(off < sizeof(buf));
1898!         buf[off++] = uread(uart, RBR);
1899          break;
1900        case RECEIVER_ERROR:
1901          /* RX error: eat character */
1902!          uartError(uart);
1903          break;
1904        default:
1905          /* Should not happen */
1906***************
1907*** 676,778 ****
1908  }
1909         
1910  void
1911! BSP_uart_termios_isr_com2()
1912  {
1913!   unsigned char buf[40];
1914!   unsigned char val;
1915!   int      off, ret, vect;
1916!
1917!   off = 0;
1918!
1919!   for(;;)
1920!     {
1921!       vect = uread(BSP_UART_COM2, IIR) & 0xf;
1922!       
1923!       switch(vect)
1924!       {
1925!       case MODEM_STATUS :
1926!         val = uread(BSP_UART_COM2, MSR);
1927!         if(uart_data[BSP_UART_COM2].hwFlow)
1928!           {
1929!             if(val & CTS)
1930!               {
1931!                 /* CTS high */
1932!                 termios_stopped_com2 = 0;
1933!                 if(termios_tx_hold_valid_com2)
1934!                   {
1935!                     termios_tx_hold_valid_com2 = 0;
1936!                     BSP_uart_termios_write_com2(0, &termios_tx_hold_com2,
1937!                                                   1);
1938!                   }
1939!               }
1940!             else
1941!               {
1942!                 /* CTS low */
1943!                 termios_stopped_com2 = 1;
1944!               }
1945!           }
1946!         break;
1947!       case NO_MORE_INTR :
1948!         /* No more interrupts */
1949!         if(off != 0)
1950!           {
1951!             /* Update rx buffer */
1952!             rtems_termios_enqueue_raw_characters(termios_ttyp_com2,
1953!                                                  (char *)buf,
1954!                                                  off);
1955!           }
1956!         return;
1957!       case TRANSMITTER_HODING_REGISTER_EMPTY :
1958!         /*
1959!          * TX holding empty: we have to disable these interrupts
1960!          * if there is nothing more to send.
1961!          */
1962!
1963!         ret = rtems_termios_dequeue_characters(termios_ttyp_com2, 1);
1964!
1965!         /* If nothing else to send disable interrupts */
1966!         if(ret == 0 && uart_data[BSP_UART_COM2].hwFlow)
1967!           {
1968!             uwrite(BSP_UART_COM2, IER,
1969!                    (RECEIVE_ENABLE  |
1970!                     RECEIVER_LINE_ST_ENABLE |
1971!                     MODEM_ENABLE
1972!                    )
1973!                   );
1974!               termios_tx_active_com2 = 0;
1975!           }
1976!         else if(ret == 0)
1977!           {
1978!             uwrite(BSP_UART_COM2, IER,
1979!                    (RECEIVE_ENABLE  |
1980!                     RECEIVER_LINE_ST_ENABLE
1981!                    )
1982!                   );
1983!               termios_tx_active_com2 = 0;
1984!           }
1985!         break;
1986!       case RECEIVER_DATA_AVAIL :
1987!       case CHARACTER_TIMEOUT_INDICATION:
1988!         /* RX data ready */
1989!         assert(off < sizeof(buf));
1990!         buf[off++] = uread(BSP_UART_COM2, RBR);
1991!         break;
1992!       case RECEIVER_ERROR:
1993!         /* RX error: eat character */
1994!          uartError(BSP_UART_COM2);
1995!         break;
1996!       default:
1997!         /* Should not happen */
1998!         assert(0);
1999!         return;
2000!       }
2001!     }
2002  }
2003-         
2004-   
2005-
2006-
2007 
2008!
2009!
2010 
2011--- 655,668 ----
2012  }
2013         
2014  void
2015! BSP_uart_termios_isr_com1(void)
2016  {
2017!       BSP_uart_termios_isr_com(BSP_UART_COM1);
2018  }
2019 
2020! void
2021! BSP_uart_termios_isr_com2(void)
2022! {
2023!       BSP_uart_termios_isr_com(BSP_UART_COM2);
2024! }
2025 
2026Index: c/src/lib/libbsp/powerpc/shared/console/uart.h
2027===================================================================
2028RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/console/uart.h,v
2029retrieving revision 1.1.1.1
2030retrieving revision 1.2
2031diff -c -r1.1.1.1 -r1.2
2032*** c/src/lib/libbsp/powerpc/shared/console/uart.h      2001/12/14 22:52:04     1.1.1.1
2033--- c/src/lib/libbsp/powerpc/shared/console/uart.h      2002/03/07 01:07:10     1.2
2034***************
2035*** 10,15 ****
2036--- 10,17 ----
2037  #ifndef _BSPUART_H
2038  #define _BSPUART_H
2039 
2040+ #include <bsp/irq.h>
2041+
2042  void BSP_uart_init(int uart, int baud, int hwFlow);
2043  void BSP_uart_set_baud(int aurt, int baud);
2044  void BSP_uart_intr_ctrl(int uart, int cmd);
2045***************
2046*** 19,30 ****
2047  void BSP_uart_polled_write(int uart, int val);
2048  int  BSP_uart_polled_read(int uart);
2049  void BSP_uart_termios_set(int uart, void *ttyp);
2050! int  BSP_uart_termios_write_com1(int minor, const char *buf, int len);
2051! int  BSP_uart_termios_write_com2(int minor, const char *buf, int len);
2052  void BSP_uart_termios_isr_com1();
2053  void BSP_uart_termios_isr_com2();
2054  void BSP_uart_dbgisr_com1(void);
2055  void BSP_uart_dbgisr_com2(void);
2056  extern unsigned BSP_poll_char_via_serial(void);
2057  extern void BSP_output_char_via_serial(int val);
2058  extern int BSPConsolePort;
2059--- 21,34 ----
2060  void BSP_uart_polled_write(int uart, int val);
2061  int  BSP_uart_polled_read(int uart);
2062  void BSP_uart_termios_set(int uart, void *ttyp);
2063! int  BSP_uart_termios_write_com(int minor, const char *buf, int len);
2064  void BSP_uart_termios_isr_com1();
2065  void BSP_uart_termios_isr_com2();
2066  void BSP_uart_dbgisr_com1(void);
2067  void BSP_uart_dbgisr_com2(void);
2068+ int  BSP_uart_install_isr(int uart, rtems_irq_hdl handler);
2069+ int  BSP_uart_remove_isr(int uart, rtems_irq_hdl handler);
2070+
2071  extern unsigned BSP_poll_char_via_serial(void);
2072  extern void BSP_output_char_via_serial(int val);
2073  extern int BSPConsolePort;
2074***************
2075*** 48,60 ****
2076  /* PC UART definitions */
2077  #define BSP_UART_COM1            (0)
2078  #define BSP_UART_COM2            (1)
2079-
2080- /*
2081-  * Base IO for UART
2082-  */
2083-
2084- #define COM1_BASE_IO  0x3F8
2085- #define COM2_BASE_IO  0x2F8
2086 
2087  /*
2088   * Offsets from base
2089--- 52,57 ----
2090Index: c/src/lib/libbsp/powerpc/shared/include/bsp.h
2091===================================================================
2092RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/include/bsp.h,v
2093retrieving revision 1.1.1.2
2094retrieving revision 1.5
2095diff -c -r1.1.1.2 -r1.5
2096*** c/src/lib/libbsp/powerpc/shared/include/bsp.h       2001/12/15 00:14:04     1.1.1.2
2097--- c/src/lib/libbsp/powerpc/shared/include/bsp.h       2002/04/21 00:23:05     1.5
2098***************
2099*** 26,34 ****
2100   *   - Interrupt stack space is not minimum if defined.
2101   */
2102 
2103! /* #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2 */
2104  #define CONFIGURE_INTERRUPT_STACK_MEMORY  (16 * 1024)
2105   
2106  #ifndef ASM
2107  #define outport_byte(port,value) outb(value,port)
2108  #define outport_word(port,value) outw(value,port)
2109--- 26,58 ----
2110   *   - Interrupt stack space is not minimum if defined.
2111   */
2112 
2113! #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2
2114  #define CONFIGURE_INTERRUPT_STACK_MEMORY  (16 * 1024)
2115+
2116+ /* fundamental addresses for this BSP (PREPxxx are from libcpu/io.h) */
2117+ #define       _IO_BASE                        PREP_ISA_IO_BASE
2118+ #define       _ISA_MEM_BASE           PREP_ISA_MEM_BASE
2119+ /* address of our ram on the PCI bus   */
2120+ #define       PCI_DRAM_OFFSET         PREP_PCI_DRAM_OFFSET
2121+ /* offset of pci memory as seen from the CPU */
2122+ #define PCI_MEM_BASE          PREP_ISA_MEM_BASE
2123+
2124+ /*
2125+  *  base address definitions for several devices
2126+  *
2127+  */
2128+ #define BSP_UART_IOBASE_COM1 ((_IO_BASE)+0x3f8)
2129+ #define BSP_UART_IOBASE_COM2 ((_IO_BASE)+0x2f8)
2130+ #define BSP_KBD_IOBASE       ((_IO_BASE)+0x60)
2131+ #define BSP_VGA_IOBASE       ((_IO_BASE)+0x3c0)
2132+
2133+ #define BSP_CONSOLE_PORT      BSP_UART_COM1
2134+ #define BSP_UART_BAUD_BASE    115200
2135   
2136+ #include <bsp/openpic.h>
2137+ #define BSP_PIC_DO_EOI openpic_eoi(0)
2138+
2139+
2140  #ifndef ASM
2141  #define outport_byte(port,value) outb(value,port)
2142  #define outport_word(port,value) outw(value,port)
2143Index: c/src/lib/libbsp/powerpc/shared/irq/Makefile.am
2144===================================================================
2145RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/irq/Makefile.am,v
2146retrieving revision 1.1.1.2
2147retrieving revision 1.2
2148diff -c -r1.1.1.2 -r1.2
2149*** c/src/lib/libbsp/powerpc/shared/irq/Makefile.am     2001/12/15 00:14:04     1.1.1.2
2150--- c/src/lib/libbsp/powerpc/shared/irq/Makefile.am     2002/04/21 00:43:32     1.2
2151***************
2152*** 22,27 ****
2153 
2154  all-local: $(PREINSTALL_FILES)
2155 
2156! EXTRA_DIST = i8259.c irq.c irq.h irq_asm.S irq_init.c
2157 
2158  include $(top_srcdir)/../../../../../automake/local.am
2159--- 22,27 ----
2160 
2161  all-local: $(PREINSTALL_FILES)
2162 
2163! EXTRA_DIST = i8259.c irq.c irq_asm.S irq_init.c
2164 
2165  include $(top_srcdir)/../../../../../automake/local.am
2166Index: c/src/lib/libbsp/powerpc/shared/irq/irq.c
2167===================================================================
2168RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/irq/irq.c,v
2169retrieving revision 1.1.1.1
2170retrieving revision 1.4
2171diff -c -r1.1.1.1 -r1.4
2172*** c/src/lib/libbsp/powerpc/shared/irq/irq.c   2001/12/14 22:52:05     1.1.1.1
2173--- c/src/lib/libbsp/powerpc/shared/irq/irq.c   2002/03/19 00:32:02     1.4
2174***************
2175*** 20,25 ****
2176--- 20,26 ----
2177  #include <bsp/vectors.h>
2178  #include <libcpu/cpu.h>
2179 
2180+ #include <rtems/bspIo.h> /* for printk */
2181  #define RAVEN_INTR_ACK_REG 0xfeff0030
2182 
2183  /*
2184***************
2185*** 124,129 ****
2186--- 125,131 ----
2187      unsigned int level;
2188   
2189      if (!isValidInterrupt(irq->name)) {
2190+       printk("Invalid interrupt vector %i\n",irq->name);
2191        return 0;
2192      }
2193      /*
2194***************
2195*** 134,139 ****
2196--- 136,142 ----
2197       * to get the previous handler before accepting to disconnect.
2198       */
2199      if (rtems_hdl_tbl[irq->name].hdl != default_rtems_entry.hdl) {
2200+       printk("IRQ vector %i already connected\n",irq->name);
2201        return 0;
2202      }
2203      _CPU_ISR_Disable(level);
2204***************
2205*** 372,378 ****
2206      outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
2207    }
2208    else {
2209!     openpic_eoi(0);
2210    }
2211  }
2212     
2213--- 375,388 ----
2214      outport_byte(PIC_SLAVE_IMR_IO_PORT, ((i8259s_cache & 0xff00) >> 8));
2215    }
2216    else {
2217! #ifdef BSP_PCI_VME_BRIDGE_DOES_EOI
2218!       /* leave it to the VME bridge to do EOI, so
2219!          * it can re-enable the openpic while handling
2220!          * VME interrupts (-> VME priorities in software)
2221!        */
2222!       if (BSP_PCI_VME_BRIDGE_IRQ!=irq)
2223! #endif
2224!               openpic_eoi(0);
2225    }
2226  }
2227     
2228Index: c/src/lib/libbsp/powerpc/shared/irq/irq.h
2229===================================================================
2230RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/irq/irq.h,v
2231retrieving revision 1.1.1.1
2232retrieving revision 1.2
2233diff -c -r1.1.1.1 -r1.2
2234*** c/src/lib/libbsp/powerpc/shared/irq/irq.h   2001/12/14 22:52:05     1.1.1.1
2235--- c/src/lib/libbsp/powerpc/shared/irq/irq.h   2001/12/14 23:36:56     1.2
2236***************
2237*** 87,98 ****
2238    BSP_PROCESSOR_IRQ_NUMBER    =       1,
2239    BSP_PROCESSOR_IRQ_LOWEST_OFFSET =   BSP_PCI_IRQ_MAX_OFFSET + 1,
2240    BSP_PROCESSOR_IRQ_MAX_OFFSET        =       BSP_PROCESSOR_IRQ_LOWEST_OFFSET + BSP_PROCESSOR_IRQ_NUMBER - 1,
2241    /*
2242     * Summary
2243     */
2244!   BSP_IRQ_NUMBER              =       BSP_PROCESSOR_IRQ_MAX_OFFSET + 1,
2245    BSP_LOWEST_OFFSET           =       BSP_ISA_IRQ_LOWEST_OFFSET,
2246!   BSP_MAX_OFFSET              =       BSP_PROCESSOR_IRQ_MAX_OFFSET,
2247      /*
2248       * Some ISA IRQ symbolic name definition
2249       */             
2250--- 87,103 ----
2251    BSP_PROCESSOR_IRQ_NUMBER    =       1,
2252    BSP_PROCESSOR_IRQ_LOWEST_OFFSET =   BSP_PCI_IRQ_MAX_OFFSET + 1,
2253    BSP_PROCESSOR_IRQ_MAX_OFFSET        =       BSP_PROCESSOR_IRQ_LOWEST_OFFSET + BSP_PROCESSOR_IRQ_NUMBER - 1,
2254+   /* Misc vectors for OPENPIC irqs (IPI, timers)
2255+    */
2256+   BSP_MISC_IRQ_NUMBER         =       8,
2257+   BSP_MISC_IRQ_LOWEST_OFFSET  =       BSP_PROCESSOR_IRQ_MAX_OFFSET + 1,
2258+   BSP_MISC_IRQ_MAX_OFFSET     =       BSP_MISC_IRQ_LOWEST_OFFSET + BSP_MISC_IRQ_NUMBER - 1,
2259    /*
2260     * Summary
2261     */
2262!   BSP_IRQ_NUMBER              =       BSP_MISC_IRQ_MAX_OFFSET + 1,
2263    BSP_LOWEST_OFFSET           =       BSP_ISA_IRQ_LOWEST_OFFSET,
2264!   BSP_MAX_OFFSET              =       BSP_MISC_IRQ_MAX_OFFSET,
2265      /*
2266       * Some ISA IRQ symbolic name definition
2267       */             
2268Index: c/src/lib/libbsp/powerpc/shared/irq/irq_init.c
2269===================================================================
2270RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/irq/irq_init.c,v
2271retrieving revision 1.1.1.1
2272retrieving revision 1.2
2273diff -c -r1.1.1.1 -r1.2
2274*** c/src/lib/libbsp/powerpc/shared/irq/irq_init.c      2001/12/14 22:52:05     1.1.1.1
2275--- c/src/lib/libbsp/powerpc/shared/irq/irq_init.c      2002/03/07 01:00:06     1.2
2276***************
2277*** 8,13 ****
2278--- 8,16 ----
2279   * Enhanced by Jay Kulpinski <jskulpin@eng01.gdds.com>
2280   * to make it valid for MVME2300 Motorola boards.
2281   *
2282+  * Till Straumann <strauman@slac.stanford.edu>, 12/20/2001:
2283+  * Use the new interface to openpic_init
2284+  *
2285   *  The license and distribution terms for this file may be
2286   *  found in the file LICENSE in this distribution or at
2287   *  http://www.OARcorp.com/rtems/license.html.
2288***************
2289*** 87,92 ****
2290--- 90,100 ----
2291    0
2292  };
2293 
2294+ static unsigned char mcp750_openpic_initpolarities[16] = {
2295+     1,  /* 8259 cascade */
2296+     0,        /* all the rest of them */
2297+ };
2298+
2299  static unsigned char mcp750_openpic_initsenses[] = {
2300      1,        /* MCP750_INT_PCB(8259) */
2301      0,        /* MCP750_INT_FALCON_ECC_ERR */
2302***************
2303*** 224,235 ****
2304    /*
2305     * First initialize the Interrupt management hardware
2306     */
2307-   OpenPIC_InitSenses = mcp750_openpic_initsenses;
2308-   OpenPIC_NumInitSenses = sizeof(mcp750_openpic_initsenses) / sizeof(char);
2309  #ifdef TRACE_IRQ_INIT 
2310    printk("Going to initialize raven interrupt controller (openpic compliant)\n");
2311  #endif       
2312!   openpic_init(1);
2313  #ifdef TRACE_IRQ_INIT 
2314    printk("Going to initialize the PCI/ISA bridge IRQ related setting (VIA 82C586)\n");
2315  #endif
2316--- 232,241 ----
2317    /*
2318     * First initialize the Interrupt management hardware
2319     */
2320  #ifdef TRACE_IRQ_INIT 
2321    printk("Going to initialize raven interrupt controller (openpic compliant)\n");
2322  #endif       
2323!   openpic_init(1, mcp750_openpic_initsenses, mcp750_openpic_initpolarities);
2324  #ifdef TRACE_IRQ_INIT 
2325    printk("Going to initialize the PCI/ISA bridge IRQ related setting (VIA 82C586)\n");
2326  #endif
2327Index: c/src/lib/libbsp/powerpc/shared/openpic/openpic.c
2328===================================================================
2329RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/openpic/openpic.c,v
2330retrieving revision 1.1.1.1
2331retrieving revision 1.3
2332diff -c -r1.1.1.1 -r1.3
2333*** c/src/lib/libbsp/powerpc/shared/openpic/openpic.c   2001/12/14 22:52:06     1.1.1.1
2334--- c/src/lib/libbsp/powerpc/shared/openpic/openpic.c   2002/03/19 00:32:05     1.3
2335***************
2336*** 26,40 ****
2337  #include <libcpu/io.h>
2338  #include <libcpu/byteorder.h>
2339  #include <bsp.h>
2340 
2341  #define NULL 0
2342  #define REGISTER_DEBUG
2343  #undef REGISTER_DEBUG
2344 
2345 
2346  volatile struct OpenPIC *OpenPIC = NULL;
2347- unsigned int OpenPIC_NumInitSenses  = 0;
2348- unsigned char *OpenPIC_InitSenses  = NULL;
2349 
2350  static unsigned int NumProcessors;
2351  static unsigned int NumSources;
2352--- 26,41 ----
2353  #include <libcpu/io.h>
2354  #include <libcpu/byteorder.h>
2355  #include <bsp.h>
2356+ #include <rtems/bspIo.h>
2357 
2358+ #ifndef NULL
2359  #define NULL 0
2360+ #endif
2361  #define REGISTER_DEBUG
2362  #undef REGISTER_DEBUG
2363 
2364 
2365  volatile struct OpenPIC *OpenPIC = NULL;
2366 
2367  static unsigned int NumProcessors;
2368  static unsigned int NumSources;
2369***************
2370*** 157,165 ****
2371       * Add some kludge to use the Motorola Raven OpenPIC which does not
2372       * report vendor and device id, and gets the wrong number of interrupts.
2373       * (Motorola did a great job on that one!)
2374       */
2375 
2376! void openpic_init(int main_pic)
2377  {
2378      unsigned int t, i;
2379      unsigned int vendorid, devid, stepping, timerfreq;
2380--- 158,170 ----
2381       * Add some kludge to use the Motorola Raven OpenPIC which does not
2382       * report vendor and device id, and gets the wrong number of interrupts.
2383       * (Motorola did a great job on that one!)
2384+      *
2385+      * T. Straumann, 12/20/2001: polarities and senses are now passed as
2386+      *                           parameters, eliminated global vars.
2387+      *                           IRQ0 is no longer treated specially.
2388       */
2389 
2390! void openpic_init(int main_pic, unsigned char *polarities, unsigned char *senses)
2391  {
2392      unsigned int t, i;
2393      unsigned int vendorid, devid, stepping, timerfreq;
2394***************
2395*** 250,259 ****
2396            openpic_initirq(0, 8, OPENPIC_VEC_SOURCE, 1, 1);
2397            /* Processor 0 */
2398            openpic_mapirq(0, 1<<0);
2399!           for (i = 1; i < NumSources; i++) {
2400                    /* Enabled, Priority 8 */
2401!                   openpic_initirq(i, 8, OPENPIC_VEC_SOURCE+i, 0,
2402!                                   i < OpenPIC_NumInitSenses ? OpenPIC_InitSenses[i] : 1);
2403                    /* Processor 0 */
2404                    openpic_mapirq(i, 1<<0);
2405            }
2406--- 255,265 ----
2407            openpic_initirq(0, 8, OPENPIC_VEC_SOURCE, 1, 1);
2408            /* Processor 0 */
2409            openpic_mapirq(0, 1<<0);
2410!           for (i = 0; i < NumSources; i++) {
2411                    /* Enabled, Priority 8 */
2412!                   openpic_initirq(i, 8, OPENPIC_VEC_SOURCE+i,
2413!                                       polarities ? polarities[i] : 0,
2414!                                       senses     ? senses[i]     : 1);
2415                    /* Processor 0 */
2416                    openpic_mapirq(i, 1<<0);
2417            }
2418Index: c/src/lib/libbsp/powerpc/shared/openpic/openpic.h
2419===================================================================
2420RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/openpic/openpic.h,v
2421retrieving revision 1.1.1.1
2422retrieving revision 1.2
2423diff -c -r1.1.1.1 -r1.2
2424*** c/src/lib/libbsp/powerpc/shared/openpic/openpic.h   2001/12/14 22:52:06     1.1.1.1
2425--- c/src/lib/libbsp/powerpc/shared/openpic/openpic.h   2002/03/07 01:00:59     1.2
2426***************
2427*** 191,198 ****
2428  };
2429 
2430  extern volatile struct OpenPIC *OpenPIC;
2431- extern unsigned int OpenPIC_NumInitSenses;
2432- extern unsigned char *OpenPIC_InitSenses;
2433 
2434 
2435      /*
2436--- 191,196 ----
2437***************
2438*** 309,315 ****
2439       */
2440 
2441  /* Global Operations */
2442! extern void openpic_init(int);
2443  extern void openpic_reset(void);
2444  extern void openpic_enable_8259_pass_through(void);
2445  extern void openpic_disable_8259_pass_through(void);
2446--- 307,313 ----
2447       */
2448 
2449  /* Global Operations */
2450! extern void openpic_init(int,unsigned char *, unsigned char *);
2451  extern void openpic_reset(void);
2452  extern void openpic_enable_8259_pass_through(void);
2453  extern void openpic_disable_8259_pass_through(void);
2454Index: c/src/lib/libbsp/powerpc/shared/pci/Makefile.am
2455===================================================================
2456RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/pci/Makefile.am,v
2457retrieving revision 1.1.1.1
2458retrieving revision 1.5
2459diff -c -r1.1.1.1 -r1.5
2460*** c/src/lib/libbsp/powerpc/shared/pci/Makefile.am     2001/12/14 22:52:06     1.1.1.1
2461--- c/src/lib/libbsp/powerpc/shared/pci/Makefile.am     2002/05/04 04:48:23     1.5
2462***************
2463*** 4,10 ****
2464 
2465  AUTOMAKE_OPTIONS = foreign 1.4
2466 
2467! C_FILES = pci.c
2468 
2469  H_FILES = pci.h
2470 
2471--- 4,10 ----
2472 
2473  AUTOMAKE_OPTIONS = foreign 1.4
2474 
2475! C_FILES = pci.c detect_raven_bridge.c pcifinddevice.c
2476 
2477  H_FILES = pci.h
2478 
2479***************
2480*** 19,24 ****
2481 
2482  all-local: $(PREINSTALL_FILES)
2483 
2484! EXTRA_DIST = pci.c pci.h
2485 
2486  include $(top_srcdir)/../../../../../automake/local.am
2487--- 19,24 ----
2488 
2489  all-local: $(PREINSTALL_FILES)
2490 
2491! EXTRA_DIST = pci.c pci.h detect_raven_bridge.c pcifinddevice.c
2492 
2493  include $(top_srcdir)/../../../../../automake/local.am
2494Index: c/src/lib/libbsp/powerpc/shared/pci/detect_raven_bridge.c
2495===================================================================
2496RCS file: detect_raven_bridge.c
2497diff -N detect_raven_bridge.c
2498*** /dev/null   Thu Aug 24 02:00:32 2000
2499--- /tmp/cvsOAnrxa      Sun May  5 11:22:14 2002
2500***************
2501*** 0 ****
2502--- 1,107 ----
2503+ #include <libcpu/io.h>
2504+
2505+ #include <bsp.h>
2506+ #include <bsp/pci.h>
2507+ #include <bsp/consoleIo.h>
2508+ #include <bsp/residual.h>
2509+ #include <bsp/openpic.h>
2510+
2511+ #define RAVEN_MPIC_IOSPACE_ENABLE     0x1
2512+ #define RAVEN_MPIC_MEMSPACE_ENABLE    0x2
2513+ #define RAVEN_MASTER_ENABLE           0x4
2514+ #define RAVEN_PARITY_CHECK_ENABLE     0x40
2515+ #define RAVEN_SYSTEM_ERROR_ENABLE     0x100
2516+ #define RAVEN_CLEAR_EVENTS_MASK               0xf9000000
2517+
2518+ #define pci BSP_pci_configuration
2519+
2520+ extern const pci_config_access_functions pci_direct_functions;
2521+ extern const pci_config_access_functions pci_indirect_functions;
2522+
2523+ void detect_host_bridge()
2524+ {
2525+   PPC_DEVICE *hostbridge;
2526+   unsigned int id0;
2527+   unsigned int tmp;
2528+   
2529+   /*
2530+    * This code assumes that the host bridge is located at
2531+    * bus 0, dev 0, func 0 AND that the old pre PCI 2.1
2532+    * standart devices detection mecahnism that was used on PC
2533+    * (still used in BSD source code) works.
2534+    */
2535+   hostbridge=residual_find_device(&residualCopy, PROCESSORDEVICE, NULL,
2536+                                 BridgeController,
2537+                                 PCIBridge, -1, 0);
2538+   if (hostbridge) {
2539+     if (hostbridge->DeviceId.Interface==PCIBridgeIndirect) {
2540+       pci.pci_functions=&pci_indirect_functions;
2541+       /* Should be extracted from residual data,
2542+        * indeed MPC106 in CHRP mode is different,
2543+        * but we should not use residual data in
2544+        * this case anyway.
2545+        */
2546+       pci.pci_config_addr = ((volatile unsigned char *)
2547+                             (ptr_mem_map->io_base+0xcf8));
2548+       pci.pci_config_data = ptr_mem_map->io_base+0xcfc;
2549+     } else if(hostbridge->DeviceId.Interface==PCIBridgeDirect) {
2550+       pci.pci_functions=&pci_direct_functions;
2551+       pci.pci_config_data=(unsigned char *) 0x80800000;
2552+     } else {
2553+     }
2554+   } else {
2555+     /* Let us try by experimentation at our own risk! */
2556+     pci.pci_functions = &pci_direct_functions;
2557+     /* On all direct bridges I know the host bridge itself
2558+      * appears as device 0 function 0.
2559+                */
2560+     pci_read_config_dword(0, 0, 0, PCI_VENDOR_ID, &id0);
2561+     if (id0==~0U) {
2562+       pci.pci_functions = &pci_indirect_functions;
2563+       pci.pci_config_addr = ((volatile unsigned char*)
2564+                             (ptr_mem_map->io_base+0xcf8));
2565+       pci.pci_config_data = ((volatile unsigned char*)ptr_mem_map->io_base+0xcfc);
2566+     }
2567+     /* Here we should check that the host bridge is actually
2568+      * present, but if it not, we are in such a desperate
2569+      * situation, that we probably can't even tell it.
2570+      */
2571+   }
2572+   pci_read_config_dword(0, 0, 0, 0, &id0);
2573+   if(id0 == PCI_VENDOR_ID_MOTOROLA +
2574+      (PCI_DEVICE_ID_MOTOROLA_RAVEN<<16)) {
2575+     /*
2576+      * We have a Raven bridge. We will get information about its settings
2577+      */
2578+     pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
2579+ #ifdef SHOW_RAVEN_SETTING   
2580+     printk("RAVEN PCI command register = %x\n",id0);
2581+ #endif   
2582+     id0 |= RAVEN_CLEAR_EVENTS_MASK;
2583+     pci_write_config_dword(0, 0, 0, PCI_COMMAND, id0);
2584+     pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
2585+ #ifdef SHOW_RAVEN_SETTING   
2586+     printk("After error clearing RAVEN PCI command register = %x\n",id0);
2587+ #endif   
2588+     
2589+     if (id0 & RAVEN_MPIC_IOSPACE_ENABLE) {
2590+       pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_0, &tmp);
2591+ #ifdef SHOW_RAVEN_SETTING   
2592+       printk("Raven MPIC is accessed via IO Space Access at address : %x\n",(tmp & ~0x1));
2593+ #endif   
2594+     }
2595+     if (id0 & RAVEN_MPIC_MEMSPACE_ENABLE) {
2596+       pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_1, &tmp);
2597+ #ifdef SHOW_RAVEN_SETTING   
2598+       printk("Raven MPIC is accessed via memory Space Access at address : %x\n", tmp);
2599+ #endif   
2600+       OpenPIC=(volatile struct OpenPIC *) (tmp + PREP_ISA_MEM_BASE);
2601+       printk("OpenPIC found at %p.\n",
2602+            OpenPIC);
2603+     }
2604+   }
2605+   if (OpenPIC == (volatile struct OpenPIC *)0) {
2606+     BSP_panic("OpenPic Not found\n");
2607+   }
2608+
2609+ }
2610Index: c/src/lib/libbsp/powerpc/shared/pci/pci.c
2611===================================================================
2612RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/pci/pci.c,v
2613retrieving revision 1.1.1.1
2614retrieving revision 1.3
2615diff -c -r1.1.1.1 -r1.3
2616*** c/src/lib/libbsp/powerpc/shared/pci/pci.c   2001/12/14 22:52:06     1.1.1.1
2617--- c/src/lib/libbsp/powerpc/shared/pci/pci.c   2002/05/03 19:34:55     1.3
2618***************
2619*** 14,39 ****
2620   *  http://www.OARcorp.com/rtems/license.html.
2621   *
2622   *  $Id: pci.c,v 1.1 1999/12/02 14:31:18 joel Exp $
2623   */
2624 
2625- #include <bsp/consoleIo.h>
2626  #include <libcpu/io.h>
2627  #include <bsp/pci.h>
2628- #include <bsp/residual.h>
2629- #include <bsp/openpic.h>
2630- #include <bsp.h>
2631 
2632  #define PCI_CONFIG_ADDR                       0xcf8
2633  #define PCI_CONFIG_DATA                       0xcfc
2634  #define PCI_INVALID_VENDORDEVICEID    0xffffffff
2635  #define PCI_MULTI_FUNCTION            0x80
2636- #define RAVEN_MPIC_IOSPACE_ENABLE     0x1
2637- #define RAVEN_MPIC_MEMSPACE_ENABLE    0x2
2638- #define RAVEN_MASTER_ENABLE           0x4
2639- #define RAVEN_PARITY_CHECK_ENABLE     0x40
2640- #define RAVEN_SYSTEM_ERROR_ENABLE     0x100
2641- #define RAVEN_CLEAR_EVENTS_MASK               0xf9000000
2642 
2643 
2644  /*
2645   * Bit encode for PCI_CONFIG_HEADER_TYPE register
2646--- 14,40 ----
2647   *  http://www.OARcorp.com/rtems/license.html.
2648   *
2649   *  $Id: pci.c,v 1.1 1999/12/02 14:31:18 joel Exp $
2650+  *
2651+  *  Till Straumann, <strauman@slac.stanford.edu>, 1/2002
2652+  *   - separated bridge detection code out of this file
2653   */
2654 
2655  #include <libcpu/io.h>
2656  #include <bsp/pci.h>
2657 
2658+ /* allow for overriding these definitions */
2659+ #ifndef PCI_CONFIG_ADDR
2660  #define PCI_CONFIG_ADDR                       0xcf8
2661+ #endif
2662+ #ifndef PCI_CONFIG_DATA
2663  #define PCI_CONFIG_DATA                       0xcfc
2664+ #endif
2665+
2666  #define PCI_INVALID_VENDORDEVICEID    0xffffffff
2667  #define PCI_MULTI_FUNCTION            0x80
2668 
2669+ /* define a shortcut */
2670+ #define pci   BSP_pci_configuration
2671 
2672  /*
2673   * Bit encode for PCI_CONFIG_HEADER_TYPE register
2674***************
2675*** 106,112 ****
2676        return PCIBIOS_SUCCESSFUL;
2677  }
2678 
2679! static const pci_config_access_functions indirect_functions = {
2680        indirect_pci_read_config_byte,
2681        indirect_pci_read_config_word,
2682        indirect_pci_read_config_dword,
2683--- 107,113 ----
2684        return PCIBIOS_SUCCESSFUL;
2685  }
2686 
2687! const pci_config_access_functions pci_indirect_functions = {
2688        indirect_pci_read_config_byte,
2689        indirect_pci_read_config_word,
2690        indirect_pci_read_config_dword,
2691***************
2692*** 115,123 ****
2693        indirect_pci_write_config_dword
2694  };
2695 
2696! pci_config pci = {(volatile unsigned char*)PCI_CONFIG_ADDR,
2697                         (volatile unsigned char*)PCI_CONFIG_DATA,
2698!                        &indirect_functions};
2699 
2700  static int
2701  direct_pci_read_config_byte(unsigned char bus, unsigned char slot,
2702--- 116,124 ----
2703        indirect_pci_write_config_dword
2704  };
2705 
2706! pci_config BSP_pci_configuration = {(volatile unsigned char*)PCI_CONFIG_ADDR,
2707                         (volatile unsigned char*)PCI_CONFIG_DATA,
2708!                        &pci_indirect_functions};
2709 
2710  static int
2711  direct_pci_read_config_byte(unsigned char bus, unsigned char slot,
2712***************
2713*** 205,211 ****
2714        return PCIBIOS_SUCCESSFUL;
2715  }
2716 
2717! static const pci_config_access_functions direct_functions = {
2718        direct_pci_read_config_byte,
2719        direct_pci_read_config_word,
2720        direct_pci_read_config_dword,
2721--- 206,212 ----
2722        return PCIBIOS_SUCCESSFUL;
2723  }
2724 
2725! const pci_config_access_functions pci_direct_functions = {
2726        direct_pci_read_config_byte,
2727        direct_pci_read_config_word,
2728        direct_pci_read_config_dword,
2729***************
2730*** 215,313 ****
2731  };
2732 
2733 
2734- void detect_host_bridge()
2735- {
2736-   PPC_DEVICE *hostbridge;
2737-   unsigned int id0;
2738-   unsigned int tmp;
2739-   
2740-   /*
2741-    * This code assumes that the host bridge is located at
2742-    * bus 0, dev 0, func 0 AND that the old pre PCI 2.1
2743-    * standart devices detection mecahnism that was used on PC
2744-    * (still used in BSD source code) works.
2745-    */
2746-   hostbridge=residual_find_device(&residualCopy, PROCESSORDEVICE, NULL,
2747-                                 BridgeController,
2748-                                 PCIBridge, -1, 0);
2749-   if (hostbridge) {
2750-     if (hostbridge->DeviceId.Interface==PCIBridgeIndirect) {
2751-       pci.pci_functions=&indirect_functions;
2752-       /* Should be extracted from residual data,
2753-        * indeed MPC106 in CHRP mode is different,
2754-        * but we should not use residual data in
2755-        * this case anyway.
2756-        */
2757-       pci.pci_config_addr = ((volatile unsigned char *)
2758-                             (ptr_mem_map->io_base+0xcf8));
2759-       pci.pci_config_data = ptr_mem_map->io_base+0xcfc;
2760-     } else if(hostbridge->DeviceId.Interface==PCIBridgeDirect) {
2761-       pci.pci_functions=&direct_functions;
2762-       pci.pci_config_data=(unsigned char *) 0x80800000;
2763-     } else {
2764-     }
2765-   } else {
2766-     /* Let us try by experimentation at our own risk! */
2767-     pci.pci_functions = &direct_functions;
2768-     /* On all direct bridges I know the host bridge itself
2769-      * appears as device 0 function 0.
2770-                */
2771-     pci_read_config_dword(0, 0, 0, PCI_VENDOR_ID, &id0);
2772-     if (id0==~0U) {
2773-       pci.pci_functions = &indirect_functions;
2774-       pci.pci_config_addr = ((volatile unsigned char*)
2775-                             (ptr_mem_map->io_base+0xcf8));
2776-       pci.pci_config_data = ((volatile unsigned char*)ptr_mem_map->io_base+0xcfc);
2777-     }
2778-     /* Here we should check that the host bridge is actually
2779-      * present, but if it not, we are in such a desperate
2780-      * situation, that we probably can't even tell it.
2781-      */
2782-   }
2783-   pci_read_config_dword(0, 0, 0, 0, &id0);
2784-   if(id0 == PCI_VENDOR_ID_MOTOROLA +
2785-      (PCI_DEVICE_ID_MOTOROLA_RAVEN<<16)) {
2786-     /*
2787-      * We have a Raven bridge. We will get information about its settings
2788-      */
2789-     pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
2790- #ifdef SHOW_RAVEN_SETTING   
2791-     printk("RAVEN PCI command register = %x\n",id0);
2792- #endif   
2793-     id0 |= RAVEN_CLEAR_EVENTS_MASK;
2794-     pci_write_config_dword(0, 0, 0, PCI_COMMAND, id0);
2795-     pci_read_config_dword(0, 0, 0, PCI_COMMAND, &id0);
2796- #ifdef SHOW_RAVEN_SETTING   
2797-     printk("After error clearing RAVEN PCI command register = %x\n",id0);
2798- #endif   
2799-     
2800-     if (id0 & RAVEN_MPIC_IOSPACE_ENABLE) {
2801-       pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_0, &tmp);
2802- #ifdef SHOW_RAVEN_SETTING   
2803-       printk("Raven MPIC is accessed via IO Space Access at address : %x\n",(tmp & ~0x1));
2804- #endif   
2805-     }
2806-     if (id0 & RAVEN_MPIC_MEMSPACE_ENABLE) {
2807-       pci_read_config_dword(0, 0, 0,PCI_BASE_ADDRESS_1, &tmp);
2808- #ifdef SHOW_RAVEN_SETTING   
2809-       printk("Raven MPIC is accessed via memory Space Access at address : %x\n", tmp);
2810- #endif   
2811-       OpenPIC=(volatile struct OpenPIC *) (tmp + PREP_ISA_MEM_BASE);
2812-       printk("OpenPIC found at %p.\n",
2813-            OpenPIC);
2814-     }
2815-   }
2816-   if (OpenPIC == (volatile struct OpenPIC *)0) {
2817-     BSP_panic("OpenPic Not found\n");
2818-   }
2819-
2820- }
2821-
2822  /*
2823   * This routine determines the maximum bus number in the system
2824   */
2825  void InitializePCI()
2826  {
2827    unsigned char ucSlotNumber, ucFnNumber, ucNumFuncs;
2828    unsigned char ucHeader;
2829    unsigned char ucMaxSubordinate;
2830--- 216,227 ----
2831  };
2832 
2833 
2834  /*
2835   * This routine determines the maximum bus number in the system
2836   */
2837  void InitializePCI()
2838  {
2839+   extern void detect_host_bridge();
2840    unsigned char ucSlotNumber, ucFnNumber, ucNumFuncs;
2841    unsigned char ucHeader;
2842    unsigned char ucMaxSubordinate;
2843Index: c/src/lib/libbsp/powerpc/shared/pci/pci.h
2844===================================================================
2845RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/pci/pci.h,v
2846retrieving revision 1.1.1.1
2847retrieving revision 1.5
2848diff -c -r1.1.1.1 -r1.5
2849*** c/src/lib/libbsp/powerpc/shared/pci/pci.h   2001/12/14 22:52:06     1.1.1.1
2850--- c/src/lib/libbsp/powerpc/shared/pci/pci.h   2002/05/03 20:54:24     1.5
2851***************
2852*** 1082,1088 ****
2853  #define PCIBIOS_SET_FAILED            0x88
2854  #define PCIBIOS_BUFFER_TOO_SMALL      0x89
2855 
2856! #define PCI_MAX_DEVICES                       16
2857  #define PCI_MAX_FUNCTIONS             8
2858 
2859  typedef struct  {
2860--- 1082,1091 ----
2861  #define PCIBIOS_SET_FAILED            0x88
2862  #define PCIBIOS_BUFFER_TOO_SMALL      0x89
2863 
2864! /* T. Straumann, 7/31/2001: increased to 32 - PMC slots are not
2865!  * scanned on mvme2306 otherwise
2866!  */
2867! #define PCI_MAX_DEVICES                       32
2868  #define PCI_MAX_FUNCTIONS             8
2869 
2870  typedef struct  {
2871***************
2872*** 1103,1147 ****
2873  typedef struct {
2874    volatile unsigned char*     pci_config_addr;
2875    volatile unsigned char*     pci_config_data;
2876!   pci_config_access_functions*        pci_functions;
2877  } pci_config;
2878 
2879! extern pci_config pci;
2880 
2881  extern inline int
2882  pci_read_config_byte(unsigned char bus, unsigned char slot, unsigned char function,
2883                         unsigned char where, unsigned char * val) {
2884!       return pci.pci_functions->read_config_byte(bus, slot, function, where, val);
2885  }
2886 
2887  extern inline int
2888  pci_read_config_word(unsigned char bus, unsigned char slot, unsigned char function,
2889                         unsigned char where, unsigned short * val) {
2890!       return pci.pci_functions->read_config_word(bus, slot, function, where, val);
2891  }
2892 
2893  extern inline int
2894  pci_read_config_dword(unsigned char bus, unsigned char slot, unsigned char function,
2895                         unsigned char where, unsigned int * val) {
2896!       return pci.pci_functions->read_config_dword(bus, slot, function, where, val);
2897  }
2898 
2899  extern inline int
2900  pci_write_config_byte(unsigned char bus, unsigned char slot, unsigned char function,
2901                         unsigned char where, unsigned char val) {
2902!       return pci.pci_functions->write_config_byte(bus, slot, function, where, val);
2903  }
2904 
2905  extern inline int
2906  pci_write_config_word(unsigned char bus, unsigned char slot, unsigned char function,
2907                         unsigned char where, unsigned short val) {
2908!       return pci.pci_functions->write_config_word(bus, slot, function, where, val);
2909  }
2910 
2911  extern inline int
2912  pci_write_config_dword(unsigned char bus, unsigned char slot, unsigned char function,
2913                         unsigned char where, unsigned int val) {
2914!       return pci.pci_functions->write_config_dword(bus, slot, function, where, val);
2915  }
2916 
2917  /*
2918--- 1106,1150 ----
2919  typedef struct {
2920    volatile unsigned char*     pci_config_addr;
2921    volatile unsigned char*     pci_config_data;
2922!   const pci_config_access_functions*  pci_functions;
2923  } pci_config;
2924 
2925! extern pci_config BSP_pci_configuration;
2926 
2927  extern inline int
2928  pci_read_config_byte(unsigned char bus, unsigned char slot, unsigned char function,
2929                         unsigned char where, unsigned char * val) {
2930!       return BSP_pci_configuration.pci_functions->read_config_byte(bus, slot, function, where, val);
2931  }
2932 
2933  extern inline int
2934  pci_read_config_word(unsigned char bus, unsigned char slot, unsigned char function,
2935                         unsigned char where, unsigned short * val) {
2936!       return BSP_pci_configuration.pci_functions->read_config_word(bus, slot, function, where, val);
2937  }
2938 
2939  extern inline int
2940  pci_read_config_dword(unsigned char bus, unsigned char slot, unsigned char function,
2941                         unsigned char where, unsigned int * val) {
2942!       return BSP_pci_configuration.pci_functions->read_config_dword(bus, slot, function, where, val);
2943  }
2944 
2945  extern inline int
2946  pci_write_config_byte(unsigned char bus, unsigned char slot, unsigned char function,
2947                         unsigned char where, unsigned char val) {
2948!       return BSP_pci_configuration.pci_functions->write_config_byte(bus, slot, function, where, val);
2949  }
2950 
2951  extern inline int
2952  pci_write_config_word(unsigned char bus, unsigned char slot, unsigned char function,
2953                         unsigned char where, unsigned short val) {
2954!       return BSP_pci_configuration.pci_functions->write_config_word(bus, slot, function, where, val);
2955  }
2956 
2957  extern inline int
2958  pci_write_config_dword(unsigned char bus, unsigned char slot, unsigned char function,
2959                         unsigned char where, unsigned int val) {
2960!       return BSP_pci_configuration.pci_functions->write_config_dword(bus, slot, function, where, val);
2961  }
2962 
2963  /*
2964***************
2965*** 1149,1153 ****
2966--- 1152,1166 ----
2967   */
2968  extern unsigned char BusCountPCI();
2969  extern void InitializePCI();
2970+
2971+ /* scan for a specific device */
2972+ /* find a particular PCI device
2973+  * (currently, only bus0 is scanned for device/fun0)
2974+  *
2975+  * RETURNS: zero on success, bus/dev/fun in *pbus / *pdev / *pfun
2976+  */
2977+ int
2978+ BSP_pciFindDevice(unsigned short vendorid, unsigned short deviceid,
2979+                 int instance, int *pbus, int *pdev, int *pfun);
2980 
2981  #endif /* RTEMS_PCI_H */
2982Index: c/src/lib/libbsp/powerpc/shared/pci/pcifinddevice.c
2983===================================================================
2984RCS file: pcifinddevice.c
2985diff -N pcifinddevice.c
2986*** /dev/null   Thu Aug 24 02:00:32 2000
2987--- /tmp/cvszu5q7k      Sun May  5 11:22:14 2002
2988***************
2989*** 0 ****
2990--- 1,54 ----
2991+ /* $Id: pcifinddevice.c,v 1.5 2002/05/05 18:16:57 till Exp $ */
2992+
2993+ /* Author: Till Straumann <strauman@slac.stanford.edu>, 2001 */
2994+
2995+ /* find a particular PCI device
2996+  * (we assume, the firmware configured the PCI bus[es] for us)
2997+  */
2998+
2999+ #define PCI_INVALID_VENDORDEVICEID    0xffffffff
3000+ #define PCI_MULTI_FUNCTION                    0x80
3001+
3002+ #include <bsp/pci.h>
3003+ #include <rtems/bspIo.h>
3004+
3005+ int
3006+ BSP_pciFindDevice(unsigned short vendorid, unsigned short deviceid,
3007+                 int instance, int *pbus, int *pdev, int *pfun)
3008+ {
3009+ unsigned int d;
3010+ unsigned short s;
3011+ unsigned char bus,dev,fun,hd;
3012+
3013+       for (bus=0; bus<BusCountPCI(); bus++) {
3014+       for (dev=0; dev<PCI_MAX_DEVICES; dev++) {
3015+
3016+               pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd);
3017+               hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
3018+
3019+               for (fun=0; fun<hd; fun++) {
3020+                       /*
3021+                        * The last devfn id/slot is special; must skip it
3022+                        */
3023+                       if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun)
3024+                               break;
3025+                       (void)pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d);
3026+                       if (PCI_INVALID_VENDORDEVICEID == d)
3027+                               continue;
3028+ #ifdef PCI_DEBUG
3029+                       printk("BSP_pciFindDevice: found 0x%08x at %i/%i/%i\n",d,bus,dev,fun);
3030+ #endif
3031+                       (void) pci_read_config_word(bus,dev,fun,PCI_VENDOR_ID,&s);
3032+                       if (vendorid != s)
3033+                               continue;
3034+                       (void) pci_read_config_word(bus,dev,fun,PCI_DEVICE_ID,&s);
3035+                       if (deviceid == s) {
3036+                               if (instance--) continue;
3037+                               *pbus=bus; *pdev=dev; *pfun=fun;
3038+                               return 0;
3039+                       }
3040+               }
3041+       }
3042+       }
3043+     return -1;
3044+ }
3045Index: c/src/lib/libbsp/powerpc/shared/residual/Makefile.am
3046===================================================================
3047RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/residual/Makefile.am,v
3048retrieving revision 1.1.1.1
3049retrieving revision 1.2
3050diff -c -r1.1.1.1 -r1.2
3051*** c/src/lib/libbsp/powerpc/shared/residual/Makefile.am        2001/12/14 22:52:07     1.1.1.1
3052--- c/src/lib/libbsp/powerpc/shared/residual/Makefile.am        2002/04/21 00:43:32     1.2
3053***************
3054*** 19,24 ****
3055 
3056  all-local: $(PREINSTALL_FILES)
3057 
3058! EXTRA_DIST = pnp.h residual.c residual.h
3059 
3060  include $(top_srcdir)/../../../../../automake/local.am
3061--- 19,24 ----
3062 
3063  all-local: $(PREINSTALL_FILES)
3064 
3065! EXTRA_DIST = residual.c
3066 
3067  include $(top_srcdir)/../../../../../automake/local.am
3068Index: c/src/lib/libbsp/powerpc/shared/start/start.S
3069===================================================================
3070RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/start/start.S,v
3071retrieving revision 1.1.1.1
3072retrieving revision 1.2
3073diff -c -r1.1.1.1 -r1.2
3074*** c/src/lib/libbsp/powerpc/shared/start/start.S       2001/12/14 22:52:08     1.1.1.1
3075--- c/src/lib/libbsp/powerpc/shared/start/start.S       2002/04/09 04:13:53     1.2
3076***************
3077*** 193,199 ****
3078        lis     r20, 0x1000
3079  1:    addic.  r20, r20, -0x1000
3080        tlbie   r20
3081!       blt     1b
3082        sync
3083        blr
3084       
3085--- 193,199 ----
3086        lis     r20, 0x1000
3087  1:    addic.  r20, r20, -0x1000
3088        tlbie   r20
3089!       bgt     1b
3090        sync
3091        blr
3092       
3093Index: c/src/lib/libbsp/powerpc/shared/startup/bspstart.c
3094===================================================================
3095RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/startup/bspstart.c,v
3096retrieving revision 1.1.1.1
3097retrieving revision 1.2
3098diff -c -r1.1.1.1 -r1.2
3099*** c/src/lib/libbsp/powerpc/shared/startup/bspstart.c  2001/12/14 22:52:08     1.1.1.1
3100--- c/src/lib/libbsp/powerpc/shared/startup/bspstart.c  2001/12/14 23:39:15     1.2
3101***************
3102*** 199,204 ****
3103--- 199,208 ----
3104     * so that It can be printed without accessing R1.
3105     */
3106    stack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
3107+
3108+  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
3109+   *((unsigned32 *)stack) = 0;
3110+
3111    /*
3112     * Initialize the interrupt related settings
3113     * SPRG0 = interrupt nesting level count
3114***************
3115*** 208,213 ****
3116--- 212,221 ----
3117     * some settings below...
3118     */
3119    intrStack = ((unsigned char*) &__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE - CPU_MINIMUM_STACK_FRAME_SIZE;
3120+
3121+  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
3122+   *((unsigned32 *)intrStack) = 0;
3123+
3124    asm volatile ("mtspr        273, %0" : "=r" (intrStack) : "0" (intrStack));
3125    asm volatile ("mtspr        272, %0" : "=r" (intrNestingLevel) : "0" (intrNestingLevel));
3126    /*
3127***************
3128*** 227,233 ****
3129     * PCI devices memory area. Needed to access OPENPIC features
3130     * provided by the RAVEN
3131     */
3132!   setdbat(2, 0xc0000000, 0xc0000000, 0x08000000, IO_PAGE);
3133    /*
3134     * Must have acces to open pic PCI ACK registers
3135     * provided by the RAVEN
3136--- 235,242 ----
3137     * PCI devices memory area. Needed to access OPENPIC features
3138     * provided by the RAVEN
3139     */
3140!   /* T. Straumann: give more PCI address space */
3141!   setdbat(2, 0xc0000000, 0xc0000000, 0x10000000, IO_PAGE);
3142    /*
3143     * Must have acces to open pic PCI ACK registers
3144     * provided by the RAVEN
3145Index: c/src/lib/libbsp/powerpc/shared/vectors/vectors.S
3146===================================================================
3147RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/vectors/vectors.S,v
3148retrieving revision 1.1.1.1
3149retrieving revision 1.2
3150diff -c -r1.1.1.1 -r1.2
3151*** c/src/lib/libbsp/powerpc/shared/vectors/vectors.S   2001/12/14 22:52:08     1.1.1.1
3152--- c/src/lib/libbsp/powerpc/shared/vectors/vectors.S   2001/12/14 23:40:52     1.2
3153***************
3154*** 86,91 ****
3155--- 86,95 ----
3156        stw     r30,  EXC_CTR_OFFSET(r1)
3157        mfxer   r28
3158        stw     r28,  EXC_XER_OFFSET(r1)
3159+       mfmsr   r28
3160+       stw     r28,  EXC_MSR_OFFSET(r1)
3161+       mfdar   r28
3162+       stw     r28,  EXC_DAR_OFFSET(r1)
3163          /*
3164           * compute SP at exception entry
3165           */
3166Index: c/src/lib/libbsp/powerpc/shared/vectors/vectors.h
3167===================================================================
3168RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/vectors/vectors.h,v
3169retrieving revision 1.1.1.1
3170retrieving revision 1.2
3171diff -c -r1.1.1.1 -r1.2
3172*** c/src/lib/libbsp/powerpc/shared/vectors/vectors.h   2001/12/14 22:52:08     1.1.1.1
3173--- c/src/lib/libbsp/powerpc/shared/vectors/vectors.h   2001/12/14 23:40:52     1.2
3174***************
3175*** 60,66 ****
3176  #define EXC_CTR_OFFSET 152
3177  #define EXC_XER_OFFSET 156
3178  #define EXC_LR_OFFSET 160
3179! #define EXC_DAR_OFFSET 164
3180  /*
3181   * maintain the EABI requested 8 bytes aligment
3182   * As SVR4 ABI requires 16, make it 16 (as some
3183--- 60,67 ----
3184  #define EXC_CTR_OFFSET 152
3185  #define EXC_XER_OFFSET 156
3186  #define EXC_LR_OFFSET 160
3187! #define EXC_MSR_OFFSET 164
3188! #define EXC_DAR_OFFSET 168
3189  /*
3190   * maintain the EABI requested 8 bytes aligment
3191   * As SVR4 ABI requires 16, make it 16 (as some
3192Index: c/src/lib/libbsp/powerpc/shared/vectors/vectors_init.c
3193===================================================================
3194RCS file: /afs/slac/g/spear/cvsrep/rtems/src/c/src/lib/libbsp/powerpc/shared/vectors/vectors_init.c,v
3195retrieving revision 1.1.1.1
3196retrieving revision 1.6
3197diff -c -r1.1.1.1 -r1.6
3198*** c/src/lib/libbsp/powerpc/shared/vectors/vectors_init.c      2001/12/14 22:52:08     1.1.1.1
3199--- c/src/lib/libbsp/powerpc/shared/vectors/vectors_init.c      2002/05/04 22:09:18     1.6
3200***************
3201*** 21,26 ****
3202--- 21,58 ----
3203 
3204  exception_handler_t globalExceptHdl;
3205 
3206+ /* T. Straumann: provide a stack trace
3207+  * <strauman@slac.stanford.edu>, 6/26/2001
3208+  */
3209+ typedef struct LRFrameRec_ {
3210+       struct LRFrameRec_ *frameLink;
3211+       unsigned long *lr;
3212+ } LRFrameRec, *LRFrame;
3213+
3214+ #define STACK_CLAMP 50        /* in case we have a corrupted bottom */
3215+
3216+ void
3217+ BSP_printStackTrace(BSP_Exception_frame* excPtr)
3218+ {
3219+ LRFrame f;
3220+ int   i;
3221+
3222+       printk("Stack Trace: ");
3223+       printk("  IP: 0x%08x, LR: 0x%08x\n",
3224+                       excPtr->EXC_SRR0, excPtr->EXC_LR);
3225+       for (f=(LRFrame)excPtr->GPR1, i=0; f->frameLink && i<STACK_CLAMP; f=f->frameLink) {
3226+               printk("--^ 0x%08x", (long)(f->frameLink->lr));
3227+               if (!(++i%5))
3228+                       printk("\n");
3229+       }
3230+       if (i>=STACK_CLAMP) {
3231+               printk("Too many stack frames (stack possibly corrupted), giving up...\n");
3232+       } else {
3233+               if (i%5)
3234+                       printk("\n");
3235+       }
3236+ }
3237+
3238  void C_exception_handler(BSP_Exception_frame* excPtr)
3239  {
3240    int recoverable = 0;
3241***************
3242*** 64,70 ****
3243    printk("\t CTR = %x\n", excPtr->EXC_CTR);
3244    printk("\t XER = %x\n", excPtr->EXC_XER);
3245    printk("\t LR = %x\n", excPtr->EXC_LR);
3246!   printk("\t MSR = %x\n", excPtr->EXC_MSR);
3247    if (excPtr->_EXC_number == ASM_DEC_VECTOR)
3248         recoverable = 1;
3249    if (excPtr->_EXC_number == ASM_SYS_VECTOR)
3250--- 96,105 ----
3251    printk("\t CTR = %x\n", excPtr->EXC_CTR);
3252    printk("\t XER = %x\n", excPtr->EXC_XER);
3253    printk("\t LR = %x\n", excPtr->EXC_LR);
3254!   printk("\t DAR = %x\n", excPtr->EXC_DAR);
3255!
3256!   BSP_printStackTrace(excPtr);
3257!
3258    if (excPtr->_EXC_number == ASM_DEC_VECTOR)
3259         recoverable = 1;
3260    if (excPtr->_EXC_number == ASM_SYS_VECTOR)