Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / include / paging.h
blob2213c5b37fd726a2ee1f7eed57cbe4228ea48053
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 /* Page structure */
52 typedef struct page_context
54 unsigned present : 1;
55 unsigned rw : 1;
56 unsigned user : 1;
57 unsigned accessed : 1;
58 unsigned dirty : 1;
59 unsigned unused : 7;
60 unsigned frame : 20;
61 } page_t;
63 typedef struct page_table_context
65 page_t pages[1024];
66 } page_table_t;
68 typedef struct page_dir_context
70 page_table_t *tables[1024];
71 unsigned tables_phys[1024];
72 unsigned addr_phys;
73 } page_dir_t;
75 typedef struct page_entity_context
77 page_dir_t *page_dir;
78 unsigned *frames;
79 } page_ent_t;
81 /* externs */
82 extern unsigned int init_paging ();
83 extern unsigned paging_enable ();
84 extern unsigned paging_disable ();
85 extern page_ent_t *page_cover_create ();
86 extern unsigned page_cover_delete (page_ent_t *page_cover);
87 extern unsigned page_mmap (page_ent_t *page_cover, void *from, void *to, unsigned kernel, unsigned writeable);
88 extern unsigned page_unmmap (page_ent_t *page_cover, void *from, void *to);
89 extern void page_dir_switch (page_dir_t *page_dir);
91 #endif