source: rtems/c/src/lib/libbsp/powerpc/shared/startup/pgtbl_setup.c @ fb252a68

4.11
Last change on this file since fb252a68 was fb252a68, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 13, 2014 at 3:29:44 PM

libbsp/powerpc/shared: Fix warnings

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#include <rtems.h>
2#include <libcpu/mmu.h>
3#include <libcpu/page.h>
4#include <rtems/bspIo.h>
5#include <libcpu/pte121.h>
6
7/* Default setup of the page tables. This is a weak
8 * alias, so applications may easily override this
9 * default setup.
10 *
11 * NOTE: while it is possible to change the individual
12 *       mappings, the page table itself MUST be
13 *       allocated at the top of the physical memory!
14 *       bspstart.c RELIES on this.
15 *       Also, the 'setup' routine must reduce
16 *       *pmemsize by the size of the page table.
17 */
18
19/*
20 * Authorship
21 * ----------
22 * This software was created by
23 *     Till Straumann <strauman@slac.stanford.edu>, 4/2002,
24 *         Stanford Linear Accelerator Center, Stanford University.
25 *
26 * Acknowledgement of sponsorship
27 * ------------------------------
28 * This software was produced by
29 *     the Stanford Linear Accelerator Center, Stanford University,
30 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
31 *
32 * Government disclaimer of liability
33 * ----------------------------------
34 * Neither the United States nor the United States Department of Energy,
35 * nor any of their employees, makes any warranty, express or implied, or
36 * assumes any legal liability or responsibility for the accuracy,
37 * completeness, or usefulness of any data, apparatus, product, or process
38 * disclosed, or represents that its use would not infringe privately owned
39 * rights.
40 *
41 * Stanford disclaimer of liability
42 * --------------------------------
43 * Stanford University makes no representations or warranties, express or
44 * implied, nor assumes any liability for the use of this software.
45 *
46 * Stanford disclaimer of copyright
47 * --------------------------------
48 * Stanford University, owner of the copyright, hereby disclaims its
49 * copyright and all other rights in this software.  Hence, anyone may
50 * freely use it for any purpose without restriction.
51 *
52 * Maintenance of notices
53 * ----------------------
54 * In the interest of clarity regarding the origin and status of this
55 * SLAC software, this and all the preceding Stanford University notices
56 * are to remain affixed to any copy or derivative of this software made
57 * or distributed by the recipient and are to be affixed to any copy of
58 * software made or distributed by the recipient that contains a copy or
59 * derivative of this software.
60 *
61 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
62 */
63
64Triv121PgTbl __BSP_default_pgtbl_setup(unsigned int *pmemsize);
65Triv121PgTbl BSP_pgtbl_setup(unsigned int *)
66  __attribute__ (( weak, alias("__BSP_default_pgtbl_setup") ));
67
68/* get those from the linker script.
69 * NOTE THAT THE CORRECTNESS OF THE LINKER SCRIPT IS CRUCIAL
70 */
71extern unsigned long __DATA_START__[], _etext[];
72
73Triv121PgTbl
74__BSP_default_pgtbl_setup(unsigned int *pmemsize)
75{
76Triv121PgTbl    pt;
77unsigned                ldPtSize,tmp;
78
79  /* Allocate a page table large enough to map
80   * the entire physical memory. We put the page
81   * table at the top of the physical memory.
82   */
83
84  /* get minimal size (log base 2) of PT for
85   * this board's memory
86   */
87  ldPtSize = triv121PgTblLdMinSize(*pmemsize);
88  ldPtSize++; /* double this amount -- then why? */
89
90  /* allocate the page table at the top of the physical
91   * memory - THIS IS NOT AN OPTION - bspstart.c RELIES
92   * ON THIS LAYOUT! (the size, however may be changed)
93   */
94  if ( (pt = triv121PgTblInit(*pmemsize - (1<<ldPtSize), ldPtSize)) ) {
95        /* map text and RO data read-only */
96        tmp = triv121PgTblMap(
97                                                pt,
98                                                TRIV121_121_VSID,
99                                                0,
100                                                (PAGE_ALIGN((unsigned long)_etext) - 0) >> PG_SHIFT,
101                                                0, /* WIMG */
102                                                TRIV121_PP_RO_PAGE);
103        if (TRIV121_MAP_SUCCESS != tmp) {
104                printk("Unable to map page index %i; reverting to BAT0\n",
105                                tmp);
106                pt = 0;
107        } else {
108                /* map the rest (without the page table itself) RW */
109                tmp = triv121PgTblMap(
110                                                pt,
111                                                TRIV121_121_VSID,
112                                                (unsigned long)__DATA_START__,
113                                                (*pmemsize - (1<<ldPtSize) -  (unsigned long)__DATA_START__ )>> PG_SHIFT,
114                                                0, /* WIMG */
115                                                TRIV121_PP_RW_PAGE);
116                if (TRIV121_MAP_SUCCESS != tmp) {
117                        printk("Unable to map page index %i; reverting to BAT0\n",
118                                        tmp);
119                        pt = 0;
120                }
121        }
122  } else {
123        printk("WARNING: unable to allocate page table, keeping DBAT0\n");
124  }
125  if (pt) {
126#ifdef SHOW_MORE_INIT_SETTINGS
127        printk("Setting up page table mappings; protecting text/read-only data from write access\n");
128#endif
129        /* SUCCESS; reduce available memory by size of the page table */
130        *pmemsize -= (1<<ldPtSize);
131  }
132  return pt;
133}
Note: See TracBrowser for help on using the repository browser.