doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
macosx_utils.mm
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 // -*- mode: objc -*-
30 #import "../../idlib/precompiled.h"
31 
32 #import <Foundation/Foundation.h>
33 #import <mach/mach.h>
34 #import <mach/vm_map.h>
35 
36 
37 #define CD_MOUNT_NAME "DOOM"
38 
39 #include "macosx_local.h"
40 #include "macosx_sys.h"
41 
42 //extern "C" void *vm_allocate(unsigned, unsigned*, unsigned, int);
43 //extern "C" void vm_deallocate(unsigned, unsigned*, unsigned);
44 
46 {
47  return "/Library/DOOM";
48 }
49 
50 // EEEK!
51 static long size_save;
52 
53 void *osxAllocateMemoryNV(long size, float readFrequency, float writeFrequency, float priority)
54 {
55  kern_return_t kr;
56  vm_address_t buffer;
57 
58  kr = vm_allocate(mach_task_self(),
59  (vm_address_t *)&buffer,
60  size,
61  VM_FLAGS_ANYWHERE);
62  if(kr == 0) {
63  size_save = size;
64  return buffer;
65  }
66  else
67  {
68  size_save = 0;
69  return NULL;
70  }
71 
72 }
73 
75 {
76  if(size_save) {
77  vm_deallocate(mach_task_self(),
78  (vm_address_t)pointer,
79  size_save);
80  size_save = 0;
81  }
82 }
83 
85 {
86  kern_return_t kr;
87  vm_address_t buffer;
88 
89  size += sizeof( int );
90  kr = vm_allocate(mach_task_self(),
91  (vm_address_t *)&buffer,
92  size,
93  VM_FLAGS_ANYWHERE);
94  if(kr == 0) {
95  int *ptr = buffer;
96  *ptr = size;
97  ptr = ptr + 1;
98  return ptr;
99  }
100  else
101  {
102  return NULL;
103  }
104 
105 }
106 
108 {
109  int size;
110  int *ptr = pointer;
111  ptr = ptr - 1;
112  size = *ptr;
113  vm_deallocate(mach_task_self(), (vm_address_t)ptr, size);
114 }
115 
116 static inline void __eieio(void)
117 {
118  __asm__ ("eieio");
119 }
120 
121 static inline void __sync(void)
122 {
123  __asm__ ("sync");
124 }
125 
126 static inline void __isync(void)
127 {
128  __asm__ ("isync");
129 }
130 
131 static inline void __dcbf(void *base, unsigned long offset)
132 {
133  __asm__ ("dcbf %0, %1"
134  :
135  : "r" (base), "r" (offset)
136  : "r0");
137 }
138 
139 static inline void __dcbst(void *base, unsigned long offset)
140 {
141  __asm__ ("dcbst %0, %1"
142  :
143  : "r" (base), "r" (offset)
144  : "r0");
145 }
146 
147 static inline void __dcbz(void *base, unsigned long offset)
148 {
149  __asm__ ("dcbz %0, %1"
150  :
151  : "r" (base), "r" (offset)
152  : "r0");
153 }
154 
155 void Sys_FlushCacheMemory( void *base, int bytes ) {
156  unsigned long i;
157 
158  for(i = 0; i < bytes; i+= 32) {
159  __dcbf(base,i);
160  }
161  __sync();
162  __isync();
163  __dcbf(base, i);
164  __sync();
165  __isync();
166  *(volatile unsigned long *)(base + i);
167  __isync();
168 }
case const int
Definition: Callbacks.cpp:52
int i
Definition: process.py:33
GLintptr offset
Definition: glext.h:3113
GLsizei const GLvoid * pointer
Definition: glext.h:3035
#define NULL
Definition: Lib.h:88
GLuint buffer
Definition: glext.h:3108
void * osxAllocateMemoryNV(long size, float readFrequency, float writeFrequency, float priority)
Definition: macosx_utils.mm:53
void osxFreeMemoryNV(void *pointer)
Definition: macosx_utils.mm:74
void osxFreeMemory(void *pointer)
GLsizeiptr size
Definition: glext.h:3112
const char * macosx_scanForLibraryDirectory(void)
Definition: macosx_utils.mm:45
void Sys_FlushCacheMemory(void *base, int bytes)
void * osxAllocateMemory(long size)
Definition: macosx_utils.mm:84