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-2022, 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 PAGE_OFFSET
  17  * (formerly 0xC0000000).
  18  */
  19 #define P2V(addr)               (addr < PAGE_OFFSET ? addr + PAGE_OFFSET : addr)
  20 
  21 #define V2P(addr)               (addr - PAGE_OFFSET)
  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 struct page {
  46         int page;               /* page number */
  47         int count;              /* usage counter */
  48         int flags;
  49         __ino_t inode;          /* inode of the file */
  50         __off_t offset;         /* file offset */
  51         __dev_t dev;            /* device where file resides */
  52         char *data;             /* page contents */
  53         struct page *prev_hash;
  54         struct page *next_hash;
  55         struct page *prev_free;
  56         struct page *next_free;
  57 };
  58 
  59 extern struct page *page_table;
  60 extern struct page **page_hash_table;
  61 
  62 /* values to be determined during system startup */
  63 extern unsigned int page_table_size;            /* size in bytes */
  64 extern unsigned int page_hash_table_size;       /* size in bytes */
  65 
  66 extern unsigned int *kpage_dir;
  67 extern unsigned int *kpage_table;
  68 
  69 /* alloc.c */
  70 unsigned int kmalloc(void);
  71 void kfree(unsigned int);
  72 
  73 /* page.c */
  74 void page_lock(struct page *);
  75 void page_unlock(struct page *);
  76 struct page *get_free_page(void);
  77 struct page *search_page_hash(struct inode *, __off_t);
  78 void release_page(int);
  79 int is_valid_page(int);
  80 void update_page_cache(struct inode *, __off_t, const char *, int);
  81 int write_page(struct page *, struct inode *, __off_t, unsigned int);
  82 int bread_page(struct page *, struct inode *, __off_t, char, char);
  83 int file_read(struct inode *, struct fd *, char *, __size_t);
  84 void page_init(int);
  85 
  86 /* memory.c */
  87 void bss_init(void);
  88 unsigned int setup_minmem(void);
  89 unsigned int get_mapped_addr(struct proc *, unsigned int);
  90 int clone_pages(struct proc *);
  91 int free_page_tables(struct proc *);
  92 unsigned int map_page(struct proc *, unsigned int, unsigned int, unsigned int);
  93 int unmap_page(unsigned int);
  94 void mem_init(void);
  95 void mem_stats(void);
  96 
  97 /* swapper.c */
  98 int kswapd(void);
  99 
 100 #endif /* _FIWIX_MEMORY_H */

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