ARM build fixed, paging structures was missing in include file and x86 function was...
[ZeXOS.git] / kernel / include / paging.h
blob2436d4265fda2f8df0d9e41ade9e201c097784b9
1 /*
2 * ZeX/OS
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/>.
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
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))
47 #endif
49 /* Page structure */
50 typedef struct page_context
52 unsigned present : 1;
53 unsigned rw : 1;
54 unsigned user : 1;
55 unsigned accessed : 1;
56 unsigned dirty : 1;
57 unsigned unused : 7;
58 unsigned frame : 20;
59 } page_t;
61 typedef struct page_table_context
63 page_t pages[1024];
64 } page_table_t;
66 typedef struct page_dir_context
68 page_table_t *tables[1024];
69 unsigned tables_phys[1024];
70 unsigned addr_phys;
71 } page_dir_t;
73 typedef struct page_entity_context
75 page_dir_t *page_dir;
76 unsigned *frames;
77 } page_ent_t;
79 /* externs */
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);
89 #endif