Fixed ZDE build - missing header file
[ZeXOS.git] / kernel / include / paging.h
blob453f1b683723348452bcb158197653de14fe69c2
1 /*
2 * ZeX/OS
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/>.
21 #ifndef _PAGING_H
22 #define _PAGING_H
24 #include <build.h>
26 /* x86 dependent */
27 #ifdef ARCH_i386
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))
49 #endif
51 #define __PACKED__ __attribute__ ((__packed__))
53 /* Page structure */
54 typedef struct page_context
56 unsigned present : 1;
57 unsigned rw : 1;
58 unsigned user : 1;
59 unsigned accessed : 1;
60 unsigned dirty : 1;
61 unsigned unused : 7;
62 unsigned frame : 20;
63 } __PACKED__ page_t ;
65 typedef struct page_table_context
67 page_t pages[1024];
68 } page_table_t;
70 typedef struct page_dir_context
72 page_table_t *tables[1024];
73 unsigned tables_phys[1024];
74 unsigned addr_phys;
75 } page_dir_t;
77 typedef struct page_entity_context
79 page_dir_t *page_dir;
80 unsigned *frames;
81 } page_ent_t;
83 /* externs */
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);
93 #endif