3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
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
30 #define PAGE_MEM_FB 0x500000 // 4-5MB for framebuffer
31 #define PAGE_MEM_HIGH 0x800000 // 5-8MB for storage (binaries, additional data)
33 #define PAGING_BIT 0x80000000
35 #define PAGE_ATTR_MAPPED 3
36 #define PAGE_ATTR_UNMAPPED 2
38 #define PAGE_TABLE_FLAG_FREE 0x1
39 #define PAGE_TABLE_FLAG_KERNEL 0x2
40 #define PAGE_TABLE_FLAG_USER 0x4
42 #define PAGE_TABLE_BLOCK_SIZE 4096 // 4kB
43 #define PAGE_DIR_BLOCK_SIZE 1024 // 4kB * 1024 = 4MB
45 // Macros used in the bitset algorithms.
46 #define index_from_bit(a) (a/(8*4))
47 #define offset_from_bit(a) (a%(8*4))
51 #define __PACKED__ __attribute__ ((__packed__))
54 typedef struct page_context
59 unsigned accessed
: 1;
65 typedef struct page_table_context
70 typedef struct page_dir_context
72 page_table_t
*tables
[1024];
73 unsigned tables_phys
[1024];
77 typedef struct page_entity_context
84 extern unsigned int init_paging ();
85 extern unsigned paging_enable ();
86 extern unsigned paging_disable ();
87 extern page_ent_t
*page_cover_create ();
88 extern unsigned page_cover_delete (page_ent_t
*page_cover
);
89 extern unsigned page_mmap (page_ent_t
*page_cover
, void *from
, void *to
, unsigned kernel
, unsigned writeable
);
90 extern unsigned page_unmmap (page_ent_t
*page_cover
, void *from
, void *to
);
91 extern void page_dir_switch (page_dir_t
*page_dir
);