source: sbliveos2/trunk/lib32/memory.cpp@ 149

Last change on this file since 149 was 148, checked in by sandervl, 25 years ago

beta 0.25 update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: memory.cpp 148 2000-04-26 18:01:02Z sandervl $ */
2
3//******************************************************************************
4// OS/2 implementation of Linux memory kernel services
5//
6// Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License as
10// published by the Free Software Foundation; either version 2 of
11// the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public
19// License along with this program; if not, write to the Free
20// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21// USA.
22//
23//******************************************************************************
24extern "C" {
25#define INCL_NOPMAPI
26#define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
27#include <os2.h>
28}
29#include <devhelp.h>
30#include <ossidc.h>
31#include <string.h>
32#ifdef KEE
33#include <kee.h>
34#endif
35
36#pragma off (unreferenced)
37
38#define PAGE_SIZE 4096
39
40extern "C" {
41
42//******************************************************************************
43//NOTE: Assumes memory is continuous!!
44//******************************************************************************
45unsigned long virt_to_phys(void * address)
46{
47#ifdef KEE
48 KEEVMPageList pagelist;
49 ULONG nrpages;
50
51 if(KernLinToPageList(address, PAGE_SIZE, &pagelist, &nrpages)) {
52 DebugInt3();
53 return 0;
54 }
55 return pagelist.addr;
56#else
57 LINEAR addr = (LINEAR)address;
58 PAGELIST pagelist;
59
60 if(DevLinToPageList(addr, PAGE_SIZE, (PAGELIST near *)__StackToFlat((ULONG)&pagelist))) {
61 DebugInt3();
62 return 0;
63 }
64 return pagelist.physaddr;
65#endif
66}
67//******************************************************************************
68//******************************************************************************
69void * phys_to_virt(unsigned long address)
70{
71 DebugInt3();
72 return 0;
73}
74//******************************************************************************
75//******************************************************************************
76void *__get_free_pages(int gfp_mask, unsigned long order)
77{
78 ULONG addr;
79
80 order = (1 << order); //TODO: Is this correct???
81#ifdef KEE
82 SHORT sel;
83
84 if(KernVMAlloc(order*PAGE_SIZE, VMDHA_FIXED|VMDHA_CONTIG,
85 (PVOID*)&addr, (PVOID*)-1, &sel)) {
86#else
87 if(DevVMAlloc(VMDHA_FIXED|VMDHA_CONTIG, order*PAGE_SIZE, (LINEAR)-1, __StackToFlat((ULONG)&addr))) {
88#endif
89 DebugInt3();
90 return 0;
91 }
92//// dprintf(("__get_free_pages %d returned %x", order*PAGE_SIZE, addr));
93 return (void *)addr;
94}
95//******************************************************************************
96//******************************************************************************
97int free_pages(unsigned long addr, unsigned long order)
98{
99#ifdef KEE
100 KernVMFree((PVOID)addr);
101#else
102 DevVMFree((LINEAR)addr);
103#endif
104//// dprintf(("free_pages %x", addr));
105 return 0;
106}
107//******************************************************************************
108//******************************************************************************
109struct page * alloc_pages(int gfp_mask, unsigned long order)
110{
111 DebugInt3();
112 return 0;
113}
114//******************************************************************************
115//******************************************************************************
116int remap_page_range(unsigned long from, unsigned long to, unsigned long size, unsigned long prot)
117{
118 DebugInt3();
119 return 0;
120}
121//******************************************************************************
122//******************************************************************************
123int is_access_ok(int type, void *addr, unsigned long size)
124{
125 return 1;
126}
127//******************************************************************************
128//******************************************************************************
129void __copy_user(void *to, const void *from, unsigned long n)
130{
131#ifdef KEE
132 memcpy(to, from, n);
133#else
134 _fmemcpy(to, from, n);
135#endif
136}
137//******************************************************************************
138//******************************************************************************
139unsigned long copy_to_user(void *to, const void *from, unsigned long n)
140{
141#ifdef KEE
142 memcpy(to, from, n);
143#else
144 _fmemcpy(to, from, n);
145#endif
146 return 0;
147}
148//******************************************************************************
149//******************************************************************************
150void __copy_user_zeroing(void *to, const void *from, unsigned long n)
151{
152 copy_to_user(to, from, n);
153}
154//******************************************************************************
155//******************************************************************************
156unsigned long copy_from_user(void *to, const void *from, unsigned long n)
157{
158#ifdef KEE
159 memcpy(to, from, n);
160#else
161 _fmemcpy(to, from, n);
162#endif
163 return 0;
164}
165//******************************************************************************
166//******************************************************************************
167int get_user(int size, void *dest, void *src)
168{
169#ifdef KEE
170 memcpy(dest, src, size);
171#else
172 _fmemcpy(dest, src, size);
173#endif
174 return 0;
175}
176//******************************************************************************
177//******************************************************************************
178int put_user(int x, void *ptr)
179{
180 *(int *)ptr = x;
181 return 0;
182}
183//******************************************************************************
184//******************************************************************************
185#if 0
186int __put_user(int size, int x, void *ptr)
187{
188#ifdef KEE
189 memcpy(ptr,
190#else
191 _fmemcpy(ptr,
192#endif
193 return 0;
194}
195#endif
196//******************************************************************************
197//******************************************************************************
198void *kmalloc(int size, int flags)
199{
200 char near *addr;
201
202 if(size > 1024) {
203#ifdef KEE
204 SHORT sel;
205
206 if(KernVMAlloc(size+4, VMDHA_FIXED,
207 (PVOID*)&addr, (PVOID*)-1, &sel)) {
208#else
209 if(DevVMAlloc(VMDHA_FIXED, size+4, (LINEAR)-1, __StackToFlat((ULONG)&addr))) {
210#endif
211 DebugInt3();
212 return 0;
213 }
214 *(ULONG *)addr = 0; //flat address
215//// dprintf(("kmalloc %d returned %x", size, addr));
216 return addr+4;
217 }
218 addr = (char near *)CallOSS16(IDC16_MALLOC, size, 0);
219 if(addr == NULL) {
220 DebugInt3();
221 return 0;
222 }
223//// dprintf(("kmalloc %d returned %x", size, addr));
224 return addr+4; //first 4 bytes contain original 16:16 address
225}
226//******************************************************************************
227//******************************************************************************
228void kfree(const void *ptr)
229{
230 ULONG addr;
231
232 addr = (ULONG)ptr;
233 if(addr == NULL) {
234 DebugInt3();
235 return;
236 }
237 addr -= 4; //first 4 bytes contain original 16:16 address or 0 if allocated by VMAlloc
238//// dprintf(("kfree %x", addr));
239 if(*(ULONG near *)addr) {
240 CallOSS16(IDC16_FREE, *(ULONG near *)addr, 0);
241 }
242#ifdef KEE
243 else KernVMFree((PVOID)addr);
244#else
245 else DevVMFree((LINEAR)addr);
246#endif
247}
248//******************************************************************************
249//******************************************************************************
250void kfree_s(const void *ptr, unsigned int size)
251{
252 kfree(ptr);
253}
254//******************************************************************************
255//******************************************************************************
256
257}
Note: See TracBrowser for help on using the repository browser.