Fork me on GitHub

root/include/fiwix/mm.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/mm.h
   3  *
   4  * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #ifndef _FIWIX_MEMORY_H
   9 #define _FIWIX_MEMORY_H
  10 
  11 #include <fiwix/types.h>
  12 #include <fiwix/segments.h>
  13 #include <fiwix/process.h>
  14 
  15 /*
  16  * Convert only from physical to virtual the addresses below KERNEL_BASE_ADDR
  17  * (formerly 0xC0000000).
  18  */
  19 #define P2V(addr)               (addr < KERNEL_BASE_ADDR ? addr + KERNEL_BASE_ADDR : addr)
  20 
  21 #define V2P(addr)               (addr - KERNEL_BASE_ADDR)
  22 
  23 #define PAGE_SIZE               4096
  24 #define PAGE_SHIFT              0x0C
  25 #define PAGE_MASK               ~(PAGE_SIZE - 1)        /* 0xFFFFF000 */
  26 #define PAGE_ALIGN(addr)        (((addr) + (PAGE_SIZE - 1)) & PAGE_MASK)
  27 #define PT_ENTRIES              (PAGE_SIZE / sizeof(unsigned int))
  28 #define PD_ENTRIES              (PAGE_SIZE / sizeof(unsigned int))
  29 
  30 #define PAGE_PRESENT            0x001   /* Present */
  31 #define PAGE_RW                 0x002   /* Read/Write */
  32 #define PAGE_USER               0x004   /* User */
  33 
  34 #define PAGE_LOCKED             0x001
  35 #define PAGE_RESERVED           0x100   /* kernel, BIOS address, ... */
  36 #define PAGE_COW                0x200   /* marked for Copy-On-Write */
  37 
  38 #define PFAULT_V                0x01    /* protection violation */
  39 #define PFAULT_W                0x02    /* during write */
  40 #define PFAULT_U                0x04    /* in user mode */
  41 
  42 #define GET_PGDIR(address)      ((unsigned int)((address) >> 22) & 0x3FF)
  43 #define GET_PGTBL(address)      ((unsigned int)((address) >> 12) & 0x3FF)
  44 
  45 #define P_TEXT  1       /* text section */
  46 #define P_DATA  2       /* data section */
  47 #define P_BSS   3       /* BSS section */
  48 #define P_HEAP  4       /* heap section (sys_brk()) */
  49 #define P_STACK 5       /* stack section */
  50 #define P_MMAP  6       /* mmap() section */
  51 
  52 struct page {
  53         int page;               /* page number */
  54         int count;              /* usage counter */
  55         int flags;
  56         __ino_t inode;          /* inode of the file */
  57         __off_t offset;         /* file offset */
  58         __dev_t dev;            /* device where file resides */
  59         char *data;             /* page contents */
  60         struct page *prev_hash;
  61         struct page *next_hash;
  62         struct page *prev_free;
  63         struct page *next_free;
  64 };
  65 
  66 extern struct page *page_table;
  67 extern struct page **page_hash_table;
  68 
  69 /* values to be determined during system startup */
  70 extern unsigned int page_table_size;            /* size in bytes */
  71 extern unsigned int page_hash_table_size;       /* size in bytes */
  72 
  73 extern unsigned int *kpage_dir;
  74 extern unsigned int *kpage_table;
  75 
  76 /* alloc.c */
  77 unsigned int kmalloc(void);
  78 void kfree(unsigned int);
  79 
  80 /* page.c */
  81 void page_lock(struct page *);
  82 void page_unlock(struct page *);
  83 struct page * get_free_page(void);
  84 struct page * search_page_hash(struct inode *, __off_t);
  85 void release_page(int);
  86 int is_valid_page(int);
  87 void update_page_cache(struct inode *, __off_t, const char *, int);
  88 int write_page(struct page *, struct inode *, __off_t, unsigned int);
  89 int bread_page(struct page *, struct inode *, __off_t, char, char);
  90 int file_read(struct inode *, struct fd *, char *, __size_t);
  91 void page_init(int);
  92 
  93 /* memory.c */
  94 void bss_init(void);
  95 unsigned int setup_minmem(void);
  96 unsigned int get_mapped_addr(struct proc *, unsigned int);
  97 int clone_pages(struct proc *);
  98 int free_page_tables(struct proc *);
  99 unsigned int map_page(struct proc *, unsigned int, unsigned int, unsigned int);
 100 int unmap_page(unsigned int);
 101 void mem_init(void);
 102 void mem_stats(void);
 103 
 104 /* swapper.c */
 105 int kswapd(void);
 106 
 107 #endif /* _FIWIX_MEMORY_H */

/* [previous][next][first][last][top][bottom][index][help] */