Subversion Repositories Kolibri OS

Rev

Rev 1066 | 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.  
  21. typedef struct
  22. {
  23.   SPINLOCK_DECLARE(lock);     /**< this lock protects everything below */
  24.   pfn_t    base;              /**< frame_no of the first frame in the frames array */
  25.   count_t  count;             /**< Size of zone */
  26.  
  27.   frame_t *frames;            /**< array of frame_t structures in this zone */
  28.   count_t  free_count;        /**< number of free frame_t structures */
  29.   count_t  busy_count;        /**< number of busy frame_t structures */
  30.  
  31.   u32_t    max_order;
  32.   link_t   order[21];
  33.  
  34.   int      flags;
  35. } zone_t;
  36.  
  37.  
  38. typedef struct
  39. {
  40.     link_t  link;
  41.     link_t  adj;
  42.     addr_t  base;
  43.     size_t  size;
  44.     void   *parent;
  45.     u32_t   state;
  46. }md_t;
  47.  
  48.  
  49. #define PG_MAP          1
  50. #define PG_WRITE        2
  51. #define PG_USER         4
  52.  
  53. #define PG_SW           3
  54. #define PG_UW           7
  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.