1 | /* $Id$ */ |
---|
2 | |
---|
3 | #include <rtems.h> |
---|
4 | #include <libcpu/mmu.h> |
---|
5 | #include <libcpu/page.h> |
---|
6 | #include <rtems/bspIo.h> |
---|
7 | #include <libcpu/pte121.h> |
---|
8 | |
---|
9 | |
---|
10 | /* Default setup of the page tables. This is a weak |
---|
11 | * alias, so applications may easily override this |
---|
12 | * default setup. |
---|
13 | * |
---|
14 | * NOTE: while it is possible to change the individual |
---|
15 | * mappings, the page table itself MUST be |
---|
16 | * allocated at the top of the physical memory! |
---|
17 | * bspstart.c RELIES on this. |
---|
18 | * Also, the 'setup' routine must reduce |
---|
19 | * *pmemsize by the size of the page table. |
---|
20 | */ |
---|
21 | |
---|
22 | /* Author: Till Straumann, <strauman@slac.stanford.edu>, 4/2002 */ |
---|
23 | |
---|
24 | Triv121PgTbl |
---|
25 | BSP_pgtbl_setup(unsigned long) __attribute__ (( weak, alias("__BSP_default_pgtbl_setup") )); |
---|
26 | |
---|
27 | |
---|
28 | Triv121PgTbl |
---|
29 | __BSP_default_pgtbl_setup(unsigned int *pmemsize) |
---|
30 | { |
---|
31 | Triv121PgTbl pt; |
---|
32 | unsigned ldPtSize,tmp; |
---|
33 | |
---|
34 | /* Allocate a page table large enough to map |
---|
35 | * the entire physical memory. We put the page |
---|
36 | * table at the top of the physical memory. |
---|
37 | */ |
---|
38 | |
---|
39 | /* get minimal size (log base 2) of PT for |
---|
40 | * this board's memory |
---|
41 | */ |
---|
42 | ldPtSize = triv121PgTblLdMinSize(*pmemsize); |
---|
43 | ldPtSize++; /* double this amount -- then why? */ |
---|
44 | |
---|
45 | /* allocate the page table at the top of the physical |
---|
46 | * memory - THIS IS NOT AN OPTION - bspstart.c RELIES |
---|
47 | * ON THIS LAYOUT! (the size, however may be changed) |
---|
48 | */ |
---|
49 | if ( (pt = triv121PgTblInit(*pmemsize - (1<<ldPtSize), ldPtSize)) ) { |
---|
50 | /* get those from the linker script. |
---|
51 | * NOTE THAT THE CORRECTNESS OF THE LINKER SCRIPT IS CRUCIAL |
---|
52 | */ |
---|
53 | extern unsigned long __DATA_START__[], _etext[]; |
---|
54 | |
---|
55 | /* map text and RO data read-only */ |
---|
56 | tmp = triv121PgTblMap( |
---|
57 | pt, |
---|
58 | TRIV121_121_VSID, |
---|
59 | 0, |
---|
60 | (PAGE_ALIGN((unsigned long)_etext) - 0) >> PG_SHIFT, |
---|
61 | 0, /* WIMG */ |
---|
62 | TRIV121_PP_RO_PAGE); |
---|
63 | if (TRIV121_MAP_SUCCESS != tmp) { |
---|
64 | printk("Unable to map page index %i; reverting to BAT0\n", |
---|
65 | tmp); |
---|
66 | pt = 0; |
---|
67 | } else { |
---|
68 | /* map the rest (without the page table itself) RW */ |
---|
69 | tmp = triv121PgTblMap( |
---|
70 | pt, |
---|
71 | TRIV121_121_VSID, |
---|
72 | (unsigned long)__DATA_START__, |
---|
73 | (*pmemsize - (1<<ldPtSize) - (unsigned long)__DATA_START__ )>> PG_SHIFT, |
---|
74 | 0, /* WIMG */ |
---|
75 | TRIV121_PP_RW_PAGE); |
---|
76 | if (TRIV121_MAP_SUCCESS != tmp) { |
---|
77 | printk("Unable to map page index %i; reverting to BAT0\n", |
---|
78 | tmp); |
---|
79 | pt = 0; |
---|
80 | } |
---|
81 | } |
---|
82 | } else { |
---|
83 | printk("WARNING: unable to allocate page table, keeping DBAT0\n"); |
---|
84 | } |
---|
85 | if (pt) { |
---|
86 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
87 | printk("Setting up page table mappings; protecting text/read-only data from write access\n"); |
---|
88 | #endif |
---|
89 | /* SUCCESS; reduce available memory by size of the page table */ |
---|
90 | *pmemsize -= (1<<ldPtSize); |
---|
91 | } |
---|
92 | return pt; |
---|
93 | } |
---|