Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:00

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