Subversion Repositories shark

Rev

Rev 2 | Rev 326 | Go to most recent revision | 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
 ------------
21
 CVS :        $Id: mem.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-03-29 14:12:52 $
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,
75
                                   MEMORY_UNDER_16M,      0);
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
//  kern_printf("highsize:%d\n", highsize);
82
  /* blocks of free memory */
83
  if (lowsize)
84
    lmm_add_free(&lmm, (void *)lowp, lowsize-1);
85
  if (highsize)
86
    lmm_add_free(&lmm, (void *)highp, highsize);
87
}
88
 
89
void *kern_alloc(DWORD s)
90
{
91
  if (s==0) return NULL;
92
  return lmm_alloc(&lmm, s, 0);
93
}
94
 
95
void *kern_alloc_aligned(size_t size, lmm_flags_t flags,
96
                        int align_bits, DWORD align_ofs)
97
{
98
  return lmm_alloc_aligned(&lmm, size, flags, align_bits, align_ofs);
99
}
100
 
101
void *kern_alloc_page(lmm_flags_t flags)
102
{
103
  return lmm_alloc_page(&lmm, flags);
104
}
105
 
106
void *kern_alloc_gen(size_t size, lmm_flags_t flags,
107
                    int align_bits, DWORD align_ofs,
108
                    DWORD bounds_min, DWORD bounds_max)
109
{
110
  return lmm_alloc_gen(&lmm, size, flags, align_bits, align_ofs,
111
                       bounds_min, bounds_max);
112
}
113
 
114
void kern_free(void *block, size_t size)
115
{
116
  lmm_free(&lmm, block, size);
117
}
118
 
119
void kern_free_page(void *block)
120
{
121
  lmm_free_page(&lmm, block);
122
}
123
 
124
void *DOS_alloc(DWORD size)
125
{
126
  return lmm_alloc(&lmm, size, MEMORY_UNDER_1M);
127
}
128
 
129
void DOS_free(void *ptr,DWORD size)
130
{
131
  lmm_free(&lmm, ptr, size);
132
}
133
 
134
 
135
void kern_mem_dump(void)
136
{
137
  lmm_dump(&lmm);
138
  lmm_stats(&lmm);
139
}