Subversion Repositories Kolibri OS

Rev

Rev 892 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. typedef struct
  3. {
  4.   link_t   link;
  5.   addr_t   base;
  6.   size_t   size;
  7.   addr_t   pte[0];
  8.  
  9. }mmap_t;
  10.  
  11.  
  12. typedef struct
  13. {
  14.   link_t buddy_link;        /**< link to the next free block inside one  order */
  15.   u16_t   refcount;           /**< tracking of shared frames  */
  16.   u16_t   buddy_order;        /**< buddy system block order */
  17.   void *parent;             /**< If allocated by slab, this points there */
  18. } frame_t;
  19.  
  20. typedef struct
  21. {
  22.   SPINLOCK_DECLARE(lock);   /**< this lock protects everything below */
  23.   pfn_t base;               /**< frame_no of the first frame in the frames array */
  24.   count_t count;            /**< Size of zone */
  25.  
  26.   frame_t *frames;          /**< array of frame_t structures in this zone */
  27.   count_t free_count;       /**< number of free frame_t structures */
  28.   count_t busy_count;       /**< number of busy frame_t structures */
  29.  
  30.   u32_t max_order;
  31.   link_t order[21];
  32.  
  33.         int flags;
  34. } zone_t;
  35.  
  36.  
  37. typedef struct
  38. {
  39.     link_t  link;
  40.     link_t  adj;
  41.     addr_t  base;
  42.     size_t  size;
  43.     void   *parent;
  44.     u32_t   state;
  45. }md_t;
  46.  
  47.  
  48. #define PG_MAP        1
  49. #define PG_WRITE      2
  50. #define PG_USER       4
  51.  
  52. #define PG_SW         3
  53. #define PG_UW         7
  54.  
  55.  
  56.  
  57. #define PAGE_SIZE    4096
  58. #define PAGE_WIDTH     12
  59.  
  60.  
  61. # define PA2KA(x) (((addr_t) (x)) + OS_BASE)
  62. # define KA2PA(x) (((addr_t) (x)) - OS_BASE)
  63.  
  64. static inline count_t SIZE2FRAMES(size_t size)
  65. {
  66.         if (!size)
  67.                 return 0;
  68.   return (count_t) ((size - 1) >> PAGE_WIDTH) + 1;
  69. }
  70.  
  71. static inline addr_t PFN2ADDR(pfn_t frame)
  72. {
  73.   return (addr_t) (frame << PAGE_WIDTH);
  74. }
  75.  
  76. static inline pfn_t ADDR2PFN(addr_t addr)
  77. {
  78.     return (pfn_t) (addr >> PAGE_WIDTH);
  79. };
  80.  
  81. void init_mm();
  82. void init_pg_slab();
  83.  
  84. void* __fastcall frame_get_parent(pfn_t pfn);
  85. void  __fastcall frame_set_parent(pfn_t pfn, void *data);
  86.  
  87.  
  88. addr_t __fastcall core_alloc(u32_t order);
  89. void   __fastcall core_free(addr_t frame);
  90.  
  91.  
  92. addr_t alloc_page(void);
  93.  
  94.  
  95. md_t* __fastcall md_alloc(size_t size, u32_t flags) ;
  96. void  __fastcall md_free(md_t *md);
  97.  
  98. addr_t __fastcall __export mem_alloc(size_t size, u32_t flags) asm ("MemAlloc");
  99. void   __fastcall __export mem_free(addr_t mem) asm ("MemFree");
  100.  
  101. addr_t __fastcall frame_alloc(size_t size);
  102. size_t __fastcall frame_free(addr_t addr);
  103.  
  104.