Warning, cross-references for /kernel/include/mem/virtual.h need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef _VIRTUAL_H_
0019 #define _VIRTUAL_H_
0020 #include "types.h"
0021 #include "util/cassert.h"
0022
0023 #define PGTBL_NUM_ENTRIES 0x400
0024 #define PGDIR_NUM_ENTRIES 0x400
0025 #define PGDIR_KERNEL_BEGIN 0x300
0026 #define PGDIR_KERNEL_STACK 0x3FE
0027 #define BIGPAGE_SIZE_BITS 22
0028 #define BIGPAGE_SIZE (1<<BIGPAGE_SIZE_BITS)
0029 #define PAGE_SIZE_BITS 12
0030 #define PAGE_SIZE (1<<PAGE_SIZE_BITS)
0031 #define FRAMENUM_TO_FRAME(x) ((frame_t) ((x) << PAGE_SIZE_BITS))
0032 #define FRAME_TO_FRAMENUM(x) ((framenum_t) ((x) >> PAGE_SIZE_BITS))
0033 #define BIGFRAMENUM_TO_FRAME(x) ((frame_t) ((x) << BIGPAGE_SIZE_BITS))
0034 #define FRAME_TO_BIGFRAMENUM(x) ((framenum_t) ((x) >> BIGPAGE_SIZE_BITS))
0035
0036 extern void *map_virtual_page (uint32 phys_frame);
0037 extern void unmap_virtual_page (void *virt_addr);
0038 extern void *map_virtual_pages (uint32 * phys_frames, uint32 count);
0039 extern void *map_contiguous_virtual_pages (uint32 phys_frame, uint32 count);
0040 extern void unmap_virtual_pages (void *virt_addr, uint32 count);
0041 extern void *get_phys_addr (void *virt_addr);
0042
0043 typedef union {
0044 u32 raw;
0045 struct {
0046 uint offset:PAGE_SIZE_BITS;
0047 uint pgtbl_i:(BIGPAGE_SIZE_BITS - PAGE_SIZE_BITS);
0048 uint pgdir_i:(8*sizeof (u32) - BIGPAGE_SIZE_BITS);
0049 };
0050 } linear_address_t PACKED;
0051 CASSERT (sizeof (linear_address_t) == sizeof (u32), linear_address_t);
0052
0053 typedef union {
0054 uint32 raw;
0055
0056 union {
0057 uint raw:12;
0058 struct {
0059 uint present:1;
0060 uint writeable:1;
0061 uint supervisor:1;
0062 uint write_through:1;
0063 uint cache_disabled:1;
0064 uint accessed:1;
0065 uint dirty:1;
0066 uint attribute_index:1;
0067 uint global_page:1;
0068 uint avail:3;
0069 };
0070 } flags;
0071 struct {
0072 uint __align:12;
0073 framenum_t framenum:20;
0074 };
0075 } pgtbl_entry_t PACKED;
0076 CASSERT (sizeof (pgtbl_entry_t) == sizeof (u32), pgtbl_entry_t);
0077
0078 typedef struct {
0079 frame_t table_pa;
0080 pgtbl_entry_t *table_va;
0081 uint8 *starting_va;
0082 } pgtbl_t;
0083
0084 typedef union {
0085 uint32 raw;
0086
0087
0088 union {
0089 union {
0090 uint32 raw:12;
0091 struct {
0092 uint present:1;
0093 uint writeable:1;
0094 uint supervisor:1;
0095 uint write_through:1;
0096 uint cache_disabled:1;
0097 uint accessed:1;
0098 uint avail1:1;
0099 uint page_size:1;
0100 uint global_page:1;
0101 uint avail3:3;
0102 };
0103 } flags;
0104 struct {
0105 uint __align:12;
0106 framenum_t table_framenum:20;
0107 };
0108 };
0109
0110
0111 union {
0112 union {
0113 uint32 raw:22;
0114 struct {
0115 uint present:1;
0116 uint writeable:1;
0117 uint supervisor:1;
0118 uint write_through:1;
0119 uint cache_disabled:1;
0120 uint accessed:1;
0121 uint dirty:1;
0122 uint page_size:1;
0123 uint global_page:1;
0124 uint avail3:3;
0125 uint attribute_index:1;
0126 uint reserved:9;
0127 };
0128 } flags_4k;
0129 struct {
0130 uint __align_4k:22;
0131 framenum_t framenum:10;
0132 };
0133 };
0134 } pgdir_entry_t PACKED;
0135 CASSERT (sizeof (pgdir_entry_t) == sizeof (u32), pgdir_entry_t);
0136
0137 typedef struct {
0138 frame_t dir_pa;
0139 pgdir_entry_t *dir_va;
0140 } pgdir_t;
0141
0142
0143
0144
0145
0146 pgdir_t clone_page_directory (pgdir_t dir);
0147
0148
0149
0150 frame_t pgdir_get_frame (pgdir_t dir, void *va);
0151
0152
0153
0154
0155 phys_addr_t pgdir_get_phys_addr (pgdir_t dir, void *va);
0156
0157 #endif
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168