3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #define PAGE_MEM_LOW 0x400000 // 0-4MB for kernel stuff
31 #define PAGING_BIT 0x80000000
33 #define PAGE_ATTR_MAPPED 3
34 #define PAGE_ATTR_UNMAPPED 2
36 #define PAGE_TABLE_FLAG_FREE 0x1
37 #define PAGE_TABLE_FLAG_KERNEL 0x2
38 #define PAGE_TABLE_FLAG_USER 0x4
40 #define PAGE_TABLE_BLOCK_SIZE 4096 // 4kB
41 #define PAGE_DIR_BLOCK_SIZE 1024 // 4kB * 1024 = 4MB
43 // Macros used in the bitset algorithms.
44 #define index_from_bit(a) (a/(8*4))
45 #define offset_from_bit(a) (a%(8*4))
50 typedef struct page_context
55 unsigned accessed
: 1;
61 typedef struct page_table_context
66 typedef struct page_dir_context
68 page_table_t
*tables
[1024];
69 unsigned tables_phys
[1024];
73 typedef struct page_entity_context
80 extern unsigned int init_paging ();
81 extern unsigned paging_enable ();
82 extern unsigned paging_disable ();
83 extern page_ent_t
*page_cover_create ();
84 extern unsigned page_cover_delete (page_ent_t
*page_cover
);
85 extern unsigned page_mmap (page_ent_t
*page_cover
, void *from
, void *to
, unsigned kernel
, unsigned writeable
);
86 extern unsigned page_unmmap (page_ent_t
*page_cover
, void *from
, void *to
);
87 extern void page_dir_switch (page_dir_t
*page_dir
);