Subversion Repositories shark

Rev

Rev 326 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
445 giacomo 21
 CVS :        $Id: mem.c,v 1.3 2004-02-10 17:50:04 giacomo Exp $
2 pj 22
 
23
 File:        $File$
445 giacomo 24
 Revision:    $Revision: 1.3 $
25
 Last update: $Date: 2004-02-10 17:50:04 $
2 pj 26
 ------------
27
 
28
 Basic Memory Manager Functions:
29
 
30
**/
31
 
32
/*
33
 * Copyright (C) 2000 Paolo Gai
34
 *
35
 * This program is free software; you can redistribute it and/or modify
36
 * it under the terms of the GNU General Public License as published by
37
 * the Free Software Foundation; either version 2 of the License, or
38
 * (at your option) any later version.
39
 *
40
 * This program is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43
 * GNU General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU General Public License
46
 * along with this program; if not, write to the Free Software
47
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
48
 *
49
 */
50
 
51
 
52
#include <kernel/func.h>
53
#include <kernel/lmm.h>
54
 
55
static lmm_t lmm;
56
static lmm_region_t region1M;
57
static lmm_region_t region16M;
58
static lmm_region_t region;
59
 
60
void kern_mem_init(struct multiboot_info *multiboot)
61
{
62
  DWORD lowsize, highsize;
63
  LIN_ADDR lowp, highp;
64
 
65
  X_meminfo(&highp, &highsize, &lowp, &lowsize);
66
 
67
  lmm_init(&lmm);
68
 
69
  /* Three memory regions:
70
     - under 1Mb
71
     - from 1Mb to 16Mb
72
     - all the other memory...
73
  */
74
  lmm_add_region(&lmm, &region1M , (void*)0x00000000, 0x000FFFFF,
326 giacomo 75
                                   MEMORY_UNDER_1M,       0);
2 pj 76
  lmm_add_region(&lmm, &region16M, (void*)0x00100000, 0x00FFFFFF,
77
                                   MEMORY_FROM_1M_TO_16M, 1);
78
  lmm_add_region(&lmm, &region   , (void*)0x01000000, 0xFEFFFFFF,
79
 
80
 
81
  if (lowsize)
82
    lmm_add_free(&lmm, (void *)lowp, lowsize-1);
83
  if (highsize)
326 giacomo 84
    lmm_add_free(&lmm, (void *)highp+0x100000, highsize-0x100000);
2 pj 85
}
86
 
87
void *kern_alloc(DWORD s)
88
{
89
  if (s==0) return NULL;
90
  return lmm_alloc(&lmm, s, 0);
91
}
92
 
93
void *kern_alloc_aligned(size_t size, lmm_flags_t flags,
94
                        int align_bits, DWORD align_ofs)
95
{
96
  return lmm_alloc_aligned(&lmm, size, flags, align_bits, align_ofs);
97
}
98
 
99
void *kern_alloc_page(lmm_flags_t flags)
100
{
101
  return lmm_alloc_page(&lmm, flags);
102
}
103
 
104
void *kern_alloc_gen(size_t size, lmm_flags_t flags,
105
                    int align_bits, DWORD align_ofs,
106
                    DWORD bounds_min, DWORD bounds_max)
107
{
108
  return lmm_alloc_gen(&lmm, size, flags, align_bits, align_ofs,
109
                       bounds_min, bounds_max);
110
}
111
 
112
void kern_free(void *block, size_t size)
113
{
114
  lmm_free(&lmm, block, size);
115
}
116
 
117
void kern_free_page(void *block)
118
{
119
  lmm_free_page(&lmm, block);
120
}
121
 
122
void *DOS_alloc(DWORD size)
123
{
124
  return lmm_alloc(&lmm, size, MEMORY_UNDER_1M);
125
}
126
 
127
void DOS_free(void *ptr,DWORD size)
128
{
129
  lmm_free(&lmm, ptr, size);
130
}
131
 
132
 
133
void kern_mem_dump(void)
134
{
135
  lmm_dump(&lmm);
136
  lmm_stats(&lmm);
137
}