Subversion Repositories HelenOS

Rev

Rev 2131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2147
Line 49... Line 49...
49
#   define KA2PA(x) ((x) - 0x80000000)
49
#   define KA2PA(x) ((x) - 0x80000000)
50
#   define PA2KA(x) ((x) + 0x80000000)
50
#   define PA2KA(x) ((x) + 0x80000000)
51
#endif
51
#endif
52
 
52
 
53
#ifdef KERNEL
53
#ifdef KERNEL
54
 
-
 
-
 
54
// Using small pages <==> 4kb
55
#define PTL0_ENTRIES_ARCH   0   /* TODO */
55
#define PTL0_ENTRIES_ARCH   (2<<12) // 4096
56
#define PTL1_ENTRIES_ARCH   0   /* TODO */
56
#define PTL1_ENTRIES_ARCH   0   
57
#define PTL2_ENTRIES_ARCH   0   /* TODO */
57
#define PTL2_ENTRIES_ARCH   0   
58
#define PTL3_ENTRIES_ARCH   0   /* TODO */
58
#define PTL3_ENTRIES_ARCH   (2<<8)  // 256
59
 
59
 
60
#define PTL0_INDEX_ARCH(vaddr)  0   /* TODO */ 
60
#define PTL0_INDEX_ARCH(vaddr)  (((vaddr) >> 20) & 0xfff)
61
#define PTL1_INDEX_ARCH(vaddr)  0   /* TODO */
61
#define PTL1_INDEX_ARCH(vaddr)  0   
62
#define PTL2_INDEX_ARCH(vaddr)  0   /* TODO */
62
#define PTL2_INDEX_ARCH(vaddr)  0   
63
#define PTL3_INDEX_ARCH(vaddr)  0   /* TODO */
63
#define PTL3_INDEX_ARCH(vaddr)  (((vaddr) >> 12) & 0x0ff)
64
 
64
 
65
#define SET_PTL0_ADDRESS_ARCH(ptl0)
-
 
66
 
65
 
67
#define GET_PTL1_ADDRESS_ARCH(ptl0, i)      0   /* TODO */
66
#define GET_PTL1_ADDRESS_ARCH(ptl0, i)      ((pte_t *)(  (((pte_level0_t*)(ptl0))[(i)]) & 0xfffffc00 )
68
#define GET_PTL2_ADDRESS_ARCH(ptl1, i)      0   /* TODO */
67
#define GET_PTL2_ADDRESS_ARCH(ptl1, i)      (ptl1)
69
#define GET_PTL3_ADDRESS_ARCH(ptl2, i)      0   /* TODO */
68
#define GET_PTL3_ADDRESS_ARCH(ptl2, i)      (ptl2)
70
#define GET_FRAME_ADDRESS_ARCH(ptl3, i)     0   /* TODO */
69
#define GET_FRAME_ADDRESS_ARCH(ptl3, i)     ( (uintptr_t)(((pte_level1_t*)(ptl3))[(i)]) & 0xfffff000 )
71
 
70
 
72
#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)   /* TODO */
71
#define SET_PTL0_ADDRESS_ARCH(ptl0)  // TODO
-
 
72
#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)   (((pte_level0_t *)(ptl0))[(i)].coarse_table_addr = (a)>>10)
73
#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)   /* TODO */
73
#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
74
#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)   /* TODO */
74
#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
75
#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)  /* TODO */
75
#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) (((pte_level1_t *)(ptl3))[(i)].frame_base_addr = (a)>>12)
76
 
76
 
77
#define GET_PTL1_FLAGS_ARCH(ptl0, i)        0   /* TODO */
77
#define GET_PTL1_FLAGS_ARCH(ptl0, i)        get_pt_level0_flags((pte_level0_t *)(ptl0), (index_t)(i))
78
#define GET_PTL2_FLAGS_ARCH(ptl1, i)        0   /* TODO */
78
#define GET_PTL2_FLAGS_ARCH(ptl1, i)        PAGE_PRESENT
79
#define GET_PTL3_FLAGS_ARCH(ptl2, i)        0   /* TODO */
79
#define GET_PTL3_FLAGS_ARCH(ptl2, i)        PAGE_PRESENT
80
#define GET_FRAME_FLAGS_ARCH(ptl3, i)       0   /* TODO */
80
#define GET_FRAME_FLAGS_ARCH(ptl3, i)       get_pt_level1_flags((pte_level1_t *)(ptl3), (index_t)(i))
81
 
81
 
82
#define SET_PTL1_FLAGS_ARCH(ptl0, i, x)     /* TODO */
82
#define SET_PTL1_FLAGS_ARCH(ptl0, i, x)     set_pt_level0_flags((pte_level0_t *)(ptl0), (index_t)(i), (x))
83
#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)     /* TODO */
83
#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
84
#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)     /* TODO */
84
#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
85
#define SET_FRAME_FLAGS_ARCH(ptl3, i, x)    /* TODO */
85
#define SET_FRAME_FLAGS_ARCH(ptl3, i, x)    set_pt_level1_flags((pte_level1t *)(ptl3), (index_t)(i), (x))
86
 
86
 
87
#define PTE_VALID_ARCH(pte)         0   /* TODO */
87
#define PTE_VALID_ARCH(pte)                  (*((uint32_t *) (pte)) != 0)
88
#define PTE_PRESENT_ARCH(pte)           0   /* TODO */
88
#define PTE_PRESENT_ARCH(pte)                  ( ((pte_level0_t *)(pte))->descriptor_type )
89
#define PTE_GET_FRAME_ARCH(pte)         0   /* TODO */
89
#define PTE_GET_FRAME_ARCH(pte)              ( ((pte_level1_t *)(pte))->frame_base_addr << FRAME_WIDTH) // pte should point into ptl3 
90
#define PTE_WRITABLE_ARCH(pte)          0   /* TODO */
90
#define PTE_WRITABLE_ARCH(pte)               ( ((pte_level1_t *)(pte))->access_permission_0 == pte_ap_user_rw_kernel_rw )  // pte should point into ptl3
91
#define PTE_EXECUTABLE_ARCH(pte)        0   /* TODO */
91
#define PTE_EXECUTABLE_ARCH(pte)         1
92
 
92
 
93
#ifndef __ASM__
93
#ifndef __ASM__
94
 
94
 
95
#include <mm/mm.h>
95
#include <mm/mm.h>
96
#include <arch/exception.h>
96
#include <arch/exception.h>
97
 
97
 
-
 
98
//TODO Comment: Page table structure as in other architectures
-
 
99
 
-
 
100
static inline int get_pt_level0_flags(pte_level0_t *pt, index_t i)
-
 
101
{
-
 
102
  pte_level0_t *p = &pt[i];
-
 
103
 
-
 
104
    return (
-
 
105
        ( p->destriptor_type != pte_descriptor_not_preset ) << PAGE_PRESENT_SHIFT |
-
 
106
        ( 1 << PAGE_READ_SHIFT ) |
-
 
107
        ( 1 << PAGE_EXEC_SHIFT ) |
-
 
108
        ( 1 << PAGE_CACHEABLE  )
-
 
109
  // Alf Note: MayBe return WriteAble because level0 should use only kernel which can write
-
 
110
  // Alf Note: MayBe return global flag if index i > 2048 (horni 2GB because kernel is mapped globaly)
-
 
111
    );
-
 
112
 
-
 
113
}
98
static inline int get_pt_flags(pte_t *pt, index_t i)
114
static inline int get_pt_level1_flags(pte_t *pt, index_t i)
99
{
115
{
-
 
116
  pte_level1_t *p = &pt[i];
-
 
117
 
100
    return 0;   /* TODO */
118
    return (
-
 
119
        ( p->destriptor_type != pte_descriptor_not_preset )    << PAGE_PRESENT_SHIFT |
-
 
120
        ( (p->access_permission_0 == pte_ap_user_ro_kernel_rw) << PAGE_READ_SHIFT )  |
-
 
121
        ( (p->access_permission_0 == pte_ap_user_rw_kernel_rw) << PAGE_READ_SHIFT )  |
-
 
122
        ( (p->access_permission_0 == pte_ap_user_rw_kernel_rw) << PAGE_WRITE_SHIFT ) |
-
 
123
    ( (p->access_permission_0 != pte_ap_user_no_kernel_rw) << PAGE_USER_SHIFT )  |
-
 
124
        ( 1 << PAGE_EXEC_SHIFT ) |
-
 
125
        ( p->bufferable << PAGE_CACHEABLE  )
-
 
126
  // Alf Note: MayBe return global flag if index i > 2048 (horni 2GB because kernel is mapped globaly)
-
 
127
 
-
 
128
 
-
 
129
    );
-
 
130
 
101
}
131
}
102
 
132
 
-
 
133
 
103
static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
134
static inline void set_pt_level0_flags(pte_level0_t *pt, index_t i, int flags)
104
{
135
{
-
 
136
    pte_level0_t *p = &pt[i];
-
 
137
   
-
 
138
    if ( flags & PAGE_NOT_PRESENT ) {
-
 
139
      p->destriptor_type = pte_descriptor_not_preset;
-
 
140
      p->should_be_zero  = 1;
105
    /* TODO */
141
    } else
-
 
142
    {
-
 
143
      p->destriptor_type = pte_descriptor_coarse_table;
-
 
144
      p->should_be_zero  = 0;
-
 
145
    }
106
    return;
146
    return;
107
}
147
}
108
 
148
 
-
 
149
/* We use same acess rights for whole page, so if page is set as not preset then
-
 
150
 * in acess_rigts_3 set value 1
-
 
151
 */  
-
 
152
static inline void set_pt_level1_flags(pte_level1_t *pt, index_t i, int flags)
-
 
153
{
-
 
154
    pte_level1_t *p = &pt[i];
-
 
155
   
-
 
156
    if ( flags & PAGE_NOT_PRESENT ) {
-
 
157
      p->destriptor_type      = pte_descriptor_not_preset;
-
 
158
      p->access_permission_3  = 1; // Ensure not all bits set to zero ... correct acess rights are stored in other 0-2 access permission entries
-
 
159
    } else
-
 
160
    {
-
 
161
      p->destriptor_type      = pte_descriptor_coarse_table;
-
 
162
      p->access_permission_3  = p->access_permission_0;
-
 
163
    }
-
 
164
 
-
 
165
  p->cacheable = p->bufferable = (flags & PAGE_CACHEABLE) != 0;
-
 
166
  // default kernel rw, user none
-
 
167
  p->access_permission_0 = p->access_permission_1 = p->access_permission_2 = p->access_permission_3 = pte_ap_user_no_kernel_rw;
-
 
168
  if ( flags & PAGE_USER )  {
-
 
169
      if ( flags & PAGE_READ )
-
 
170
          p->access_permission_0 = p->access_permission_1 = p->access_permission_2 = p->access_permission_3 = pte_ap_user_ro_kernel_rw;
-
 
171
      if ( flags & PAGE_WRITE )
-
 
172
          p->access_permission_0 = p->access_permission_1 = p->access_permission_2 = p->access_permission_3 = pte_ap_user_rw_kernel_rw;
-
 
173
  }
-
 
174
    return; return;
-
 
175
}
-
 
176
 
109
extern void page_arch_init(void);
177
extern void page_arch_init(void);
110
 
178
 
111
#endif /* __ASM__ */
179
#endif /* __ASM__ */
112
 
180
 
113
#endif /* KERNEL */
181
#endif /* KERNEL */
114
 
182
 
115
#endif
183
#endif
116
 
184
 
117
/** @}
185
/** @}
118
 */
186
 */
-
 
187