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

Last change on this file since 143 was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: memory.cpp 142 2000-04-23 14:55:46Z ktk $ */
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 return 0;
53 }
54 return pagelist.addr;
55#else
56 LINEAR addr = (LINEAR)address;
57 PAGELIST pagelist;
58
59 if(DevLinToPageList(addr, PAGE_SIZE, (PAGELIST near *)__StackToFlat((ULONG)&pagelist))) {
60 return 0;
61 }
62 return pagelist.physaddr;
63#endif
64}
65//******************************************************************************
66//******************************************************************************
67void * phys_to_virt(unsigned long address)
68{
69 DebugInt3();
70 return 0;
71}
72//******************************************************************************
73//******************************************************************************
74void *__get_free_pages(int gfp_mask, unsigned long order)
75{
76 ULONG addr;
77
78 order = (1 << order); //TODO: Is this correct???
79#ifdef KEE
80 SHORT sel;
81
82 if(KernVMAlloc(order*PAGE_SIZE, VMDHA_FIXED|VMDHA_CONTIG,
83 (PVOID*)&addr, (PVOID*)-1, &sel)) {
84#else
85 if(DevVMAlloc(VMDHA_FIXED|VMDHA_CONTIG, order*PAGE_SIZE, (LINEAR)-1, __StackToFlat((ULONG)&addr))) {
86#endif
87 return 0;
88 }
89 return (void *)addr;
90}
91//******************************************************************************
92//******************************************************************************
93int free_pages(unsigned long addr, unsigned long order)
94{
95#ifdef KEE
96 KernVMFree((PVOID)addr);
97#else
98 DevVMFree((LINEAR)addr);
99#endif
100 return 0;
101}
102//******************************************************************************
103//******************************************************************************
104struct page * alloc_pages(int gfp_mask, unsigned long order)
105{
106 DebugInt3();
107 return 0;
108}
109//******************************************************************************
110//******************************************************************************
111int remap_page_range(unsigned long from, unsigned long to, unsigned long size, unsigned long prot)
112{
113 DebugInt3();
114 return 0;
115}
116//******************************************************************************
117//******************************************************************************
118int is_access_ok(int type, void *addr, unsigned long size)
119{
120 return 1;
121}
122//******************************************************************************
123//******************************************************************************
124void __copy_user(void *to, const void *from, unsigned long n)
125{
126#ifdef KEE
127 memcpy(to, from, n);
128#else
129 _fmemcpy(to, from, n);
130#endif
131}
132//******************************************************************************
133//******************************************************************************
134unsigned long copy_to_user(void *to, const void *from, unsigned long n)
135{
136#ifdef KEE
137 memcpy(to, from, n);
138#else
139 _fmemcpy(to, from, n);
140#endif
141 return 0;
142}
143//******************************************************************************
144//******************************************************************************
145void __copy_user_zeroing(void *to, const void *from, unsigned long n)
146{
147 copy_to_user(to, from, n);
148}
149//******************************************************************************
150//******************************************************************************
151unsigned long copy_from_user(void *to, const void *from, unsigned long n)
152{
153#ifdef KEE
154 memcpy(to, from, n);
155#else
156 _fmemcpy(to, from, n);
157#endif
158 return 0;
159}
160//******************************************************************************
161//******************************************************************************
162int get_user(int size, void *dest, void *src)
163{
164#ifdef KEE
165 memcpy(dest, src, size);
166#else
167 _fmemcpy(dest, src, size);
168#endif
169 return 0;
170}
171//******************************************************************************
172//******************************************************************************
173int put_user(int x, void *ptr)
174{
175 *(int *)ptr = x;
176 return 0;
177}
178//******************************************************************************
179//******************************************************************************
180#if 0
181int __put_user(int size, int x, void *ptr)
182{
183#ifdef KEE
184 memcpy(ptr,
185#else
186 _fmemcpy(ptr,
187#endif
188 return 0;
189}
190#endif
191//******************************************************************************
192//******************************************************************************
193void *kmalloc(int size, int flags)
194{
195 char near *addr;
196
197 if(size > 1024) {
198#ifdef KEE
199 SHORT sel;
200
201 if(KernVMAlloc(size+4, VMDHA_FIXED,
202 (PVOID*)&addr, (PVOID*)-1, &sel)) {
203#else
204 if(DevVMAlloc(VMDHA_FIXED, size+4, (LINEAR)-1, __StackToFlat((ULONG)&addr))) {
205#endif
206 return 0;
207 }
208 *(ULONG *)addr = 0; //flat address
209 return addr+4;
210 }
211 addr = (char near *)CallOSS16(IDC16_MALLOC, size, 0);
212 if(addr == NULL) {
213 DebugInt3();
214 return 0;
215 }
216 return addr+4; //first 4 bytes contain original 16:16 address
217}
218//******************************************************************************
219//******************************************************************************
220void kfree(const void *ptr)
221{
222 ULONG addr;
223
224 addr = (ULONG)ptr;
225 if(addr == NULL) {
226 DebugInt3();
227 return;
228 }
229 addr -= 4; //first 4 bytes contain original 16:16 address or 0 if allocated by VMAlloc
230 if(*(ULONG near *)addr) {
231 CallOSS16(IDC16_FREE, *(ULONG near *)addr, 0);
232 }
233#ifdef KEE
234 else KernVMFree((PVOID)addr);
235#else
236 else DevVMFree((LINEAR)addr);
237#endif
238}
239//******************************************************************************
240//******************************************************************************
241void kfree_s(const void *ptr, unsigned int size)
242{
243 kfree(ptr);
244}
245//******************************************************************************
246//******************************************************************************
247
248}
Note: See TracBrowser for help on using the repository browser.