source: rtems/bsps/powerpc/shared/start/pgtbl_setup.c @ 9964895

5
Last change on this file since 9964895 was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

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