Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:59

0001 /*
0002  *  This routine starts the application.  It includes application,
0003  *  board, and monitor specific initialization and configuration.
0004  *  The generic CPU dependent initialization has been performed
0005  *  before this routine is invoked.
0006  */
0007 
0008 /*
0009  *  Author: Thomas Doerfler <td@imd.m.isar.de>
0010  *              IMD Ingenieurbuero fuer Microcomputertechnik
0011  *
0012  *  Copyright (c) 1998 IMD Ingenieurbuero fuer Microcomputertechnik
0013  *
0014  *  Changes from IMD are covered by the original distributions terms.
0015  *  This file has been derived from the papyrus BSP:
0016  *
0017  *  Author: Andrew Bray <andy@i-cubed.co.uk>
0018  *
0019  *  COPYRIGHT (c) 1995 by i-cubed ltd.
0020  *
0021  *  To anyone who acknowledges that this file is provided "AS IS"
0022  *  without any express or implied warranty:
0023  *      permission to use, copy, modify, and distribute this file
0024  *      for any purpose is hereby granted without fee, provided that
0025  *      the above copyright notice and this notice appears in all
0026  *      copies, and that the name of i-cubed limited not be used in
0027  *      advertising or publicity pertaining to distribution of the
0028  *      software without specific, written prior permission.
0029  *      i-cubed limited makes no representations about the suitability
0030  *      of this software for any purpose.
0031  *
0032  *  Modifications for spooling console driver and control of memory layout
0033  *  with linker command file by
0034  *              Thomas Doerfler <td@imd.m.isar.de>
0035  *  for these modifications:
0036  *  Copyright (c) 1997 IMD Ingenieurbuero fuer Microcomputertechnik
0037  *
0038  *  To anyone who acknowledges that this file is provided "AS IS"
0039  *  without any express or implied warranty:
0040  *      permission to use, copy, modify, and distribute this file
0041  *      for any purpose is hereby granted without fee, provided that
0042  *      the above copyright notice and this notice appears in all
0043  *      copies. IMD makes no representations about the suitability
0044  *      of this software for any purpose.
0045  *
0046  *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/startup/bspstart.c:
0047  *
0048  *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
0049  *  On-Line Applications Research Corporation (OAR).
0050  *
0051  *  Modifications for PPC405GP by Dennis Ehlin
0052  *  Modifications for Virtex4 by Richard Claus <claus@slac.stanford.edu>
0053  */
0054 #include <rtems.h>
0055 #include <rtems/config.h>
0056 #include <rtems/bspIo.h>
0057 #include <rtems/counter.h>
0058 #include <rtems/libio.h>
0059 #include <rtems/libcsupport.h>
0060 #include <rtems/sysinit.h>
0061 
0062 #include <libcpu/cpuIdent.h>
0063 #include <libcpu/spr.h>
0064 
0065 #include <bsp.h>
0066 #include <bsp/vectors.h>
0067 #include <bsp/bootcard.h>
0068 #include <bsp/irq.h>
0069 
0070 #include <string.h>
0071 #include <fcntl.h>
0072 #include <inttypes.h>
0073 
0074 #define DO_DOWN_ALIGN(x,a) ((x) & ~((a)-1))
0075 
0076 #define DO_UP_ALIGN(x,a)   DO_DOWN_ALIGN(((x) + (a) - 1 ),a)
0077 
0078 #define CPU_DOWN_ALIGN(x)  DO_DOWN_ALIGN(x, CPU_ALIGNMENT)
0079 #define CPU_UP_ALIGN(x)    DO_UP_ALIGN(x, CPU_ALIGNMENT)
0080 
0081 
0082 /* Defined in linkcmds linker script */
0083 LINKER_SYMBOL(RamBase);
0084 LINKER_SYMBOL(RamSize);
0085 LINKER_SYMBOL(__bsp_ram_start);
0086 LINKER_SYMBOL(__bsp_ram_end);
0087 LINKER_SYMBOL(__rtems_end);
0088 LINKER_SYMBOL(WorkAreaBase);
0089 LINKER_SYMBOL(MsgAreaBase);
0090 LINKER_SYMBOL(MsgAreaSize);
0091 LINKER_SYMBOL(__phy_ram_end);
0092 LINKER_SYMBOL(bsp_exc_vector_base);
0093 
0094 
0095 /* Expected by clock.c */
0096 uint32_t    bsp_clicks_per_usec;
0097 
0098 
0099 /*
0100  * Provide weak aliases so that RTEMS distribution builds
0101  */
0102 static void _noopfun(void) {}
0103 
0104 
0105 void app_bsp_start(void)
0106 __attribute__(( weak, alias("_noopfun") ));
0107 
0108 void app_bsp_predriver_hook(void)
0109 __attribute__(( weak, alias("_noopfun") ));
0110 
0111 
0112 static char* bspMsgBuffer = (char*)MsgAreaBase;
0113 
0114 static void __bsp_outchar_to_memory(char c)
0115 {
0116   static char* msgBuffer = (char*)MsgAreaBase;
0117   *msgBuffer++ = c;
0118   if (msgBuffer >= &bspMsgBuffer[(int)MsgAreaSize])  msgBuffer = bspMsgBuffer;
0119   *msgBuffer   = 0x00;                /* Overwrite next location to show EOM */
0120 }
0121 
0122 uint32_t _CPU_Counter_frequency(void)
0123 {
0124   return bsp_clicks_per_usec * 1000000;
0125 }
0126 
0127 /*===================================================================*/
0128 
0129 /*
0130  *  BSP start routine.  Called by boot_card().
0131  *
0132  *  This routine does the bulk of the system initialization.
0133  */
0134 void bsp_start(void)
0135 {
0136   ppc_cpu_id_t       myCpu;
0137   ppc_cpu_revision_t myCpuRevision;
0138 
0139   /* Set the character output function;  The application may override this */
0140   BSP_output_char = __bsp_outchar_to_memory;
0141 
0142   printk("RTEMS %s\n", rtems_get_version_string());
0143 
0144   /*
0145    * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
0146    * function stores the result in global variables so that it can be used later...
0147    */
0148   myCpu         = get_ppc_cpu_type();
0149   myCpuRevision = get_ppc_cpu_revision();
0150   printk("CPU: 0x%04x,  Revision: 0x%04x = %d,  Name: %s\n",
0151          myCpu, myCpuRevision, myCpuRevision, get_ppc_cpu_type_name(myCpu));
0152 
0153   /*
0154    *  Initialize the device driver parameters
0155    */
0156 
0157   /* Timebase register ticks/microsecond;  The application may override these */
0158   bsp_clicks_per_usec        = 350;
0159 
0160   ppc_exc_initialize();
0161 
0162   /* Let the user know what parameters we were compiled with */
0163   printk("                  Base/Start     End         Size\n"
0164          "RAM:              %p                    %p\n"
0165          "RTEMS:                           %p\n"
0166          "Workspace:        %p             %p\n"
0167          "MsgArea:          %p             %p\n"
0168          "Physical RAM                     %p\n",
0169          RamBase,        RamSize,
0170          __rtems_end,
0171          WorkAreaBase,   __bsp_ram_end,
0172          MsgAreaBase,    MsgAreaSize,
0173          __phy_ram_end);
0174 
0175   /*
0176    * Initialize RTEMS IRQ system
0177    */
0178   BSP_rtems_irq_mngt_init(0);
0179 
0180   /* Continue with application-specific initialization */
0181   app_bsp_start();
0182 }
0183 
0184 
0185 /*
0186  *  BSP predriver hook.  Called by boot_card() just before drivers are
0187  *  initialized.  Clear out any stale interrupts here.
0188  */
0189 static void virtex4_pre_driver_hook(void)
0190 {
0191   app_bsp_predriver_hook();
0192 }
0193 
0194 RTEMS_SYSINIT_ITEM(
0195   virtex4_pre_driver_hook,
0196   RTEMS_SYSINIT_BSP_PRE_DRIVERS,
0197   RTEMS_SYSINIT_ORDER_MIDDLE
0198 );