| 1 |
/* do not edit automatically generated by mc from MemUtils. */ |
| 2 |
/* MemUtils.mod provides some basic memory utilities. |
| 3 |
|
| 4 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 5 |
Contributed by Gaius Mulley <[email protected]>. |
| 6 |
|
| 7 |
This file is part of GNU Modula-2. |
| 8 |
|
| 9 |
GNU Modula-2 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, or (at your option) |
| 12 |
any later version. |
| 13 |
|
| 14 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 15 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
General Public License for more details. |
| 18 |
|
| 19 |
Under Section 7 of GPL version 3, you are granted additional |
| 20 |
permissions described in the GCC Runtime Library Exception, version |
| 21 |
3.1, as published by the Free Software Foundation. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License and |
| 24 |
a copy of the GCC Runtime Library Exception along with this program; |
| 25 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 26 |
<http://www.gnu.org/licenses/>. */ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
#include "system.h" |
| 30 |
#include <stdbool.h> |
| 31 |
# if !defined (PROC_D) |
| 32 |
# define PROC_D |
| 33 |
typedef void (*PROC_t) (void); |
| 34 |
typedef struct { PROC_t proc; } PROC; |
| 35 |
# endif |
| 36 |
|
| 37 |
#define _MemUtils_C |
| 38 |
|
| 39 |
#include "GMemUtils.h" |
| 40 |
# include "GSYSTEM.h" |
| 41 |
|
| 42 |
|
| 43 |
/* |
| 44 |
MemCopy - copys a region of memory to the required destination. |
| 45 |
*/ |
| 46 |
|
| 47 |
extern "C" void MemUtils_MemCopy (void * from, unsigned int length, void * to); |
| 48 |
|
| 49 |
/* |
| 50 |
MemZero - sets a region of memory: a..a+length to zero. |
| 51 |
*/ |
| 52 |
|
| 53 |
extern "C" void MemUtils_MemZero (void * a, unsigned int length); |
| 54 |
|
| 55 |
|
| 56 |
/* |
| 57 |
MemCopy - copys a region of memory to the required destination. |
| 58 |
*/ |
| 59 |
|
| 60 |
extern "C" void MemUtils_MemCopy (void * from, unsigned int length, void * to) |
| 61 |
{ |
| 62 |
typedef unsigned int *MemCopy__T1; |
| 63 |
|
| 64 |
typedef unsigned char *MemCopy__T2; |
| 65 |
|
| 66 |
MemCopy__T1 pwb; |
| 67 |
MemCopy__T1 pwa; |
| 68 |
MemCopy__T2 pbb; |
| 69 |
MemCopy__T2 pba; |
| 70 |
|
| 71 |
while (length >= sizeof (unsigned int )) |
| 72 |
{ |
| 73 |
pwa = static_cast<MemCopy__T1> (from); |
| 74 |
pwb = static_cast<MemCopy__T1> (to); |
| 75 |
(*pwb) = (*pwa); |
| 76 |
from = reinterpret_cast<void *> (reinterpret_cast<char *> (from)+sizeof (unsigned int )); |
| 77 |
to = reinterpret_cast<void *> (reinterpret_cast<char *> (to)+sizeof (unsigned int )); |
| 78 |
length -= sizeof (unsigned int ); |
| 79 |
} |
| 80 |
while (length > 0) |
| 81 |
{ |
| 82 |
pba = static_cast<MemCopy__T2> (from); |
| 83 |
pbb = static_cast<MemCopy__T2> (to); |
| 84 |
(*pbb) = (*pba); |
| 85 |
from = reinterpret_cast<void *> (reinterpret_cast<char *> (from)+sizeof (unsigned char )); |
| 86 |
to = reinterpret_cast<void *> (reinterpret_cast<char *> (to)+sizeof (unsigned char )); |
| 87 |
length -= sizeof (unsigned char ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/* |
| 93 |
MemZero - sets a region of memory: a..a+length to zero. |
| 94 |
*/ |
| 95 |
|
| 96 |
extern "C" void MemUtils_MemZero (void * a, unsigned int length) |
| 97 |
{ |
| 98 |
typedef unsigned int *MemZero__T3; |
| 99 |
|
| 100 |
typedef unsigned char *MemZero__T4; |
| 101 |
|
| 102 |
MemZero__T3 pwa; |
| 103 |
MemZero__T4 pba; |
| 104 |
|
| 105 |
pwa = static_cast<MemZero__T3> (a); |
| 106 |
while (length >= sizeof (unsigned int )) |
| 107 |
{ |
| 108 |
(*pwa) = (unsigned int ) (0); |
| 109 |
pwa += sizeof (unsigned int ); |
| 110 |
length -= sizeof (unsigned int ); |
| 111 |
} |
| 112 |
pba = static_cast<MemZero__T4> ((void *) (pwa)); |
| 113 |
while (length >= sizeof (unsigned char )) |
| 114 |
{ |
| 115 |
(*pba) = (unsigned char ) (0); |
| 116 |
pba += sizeof (unsigned char ); |
| 117 |
length -= sizeof (unsigned char ); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
extern "C" void _M2_MemUtils_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 122 |
{ |
| 123 |
} |
| 124 |
|
| 125 |
extern "C" void _M2_MemUtils_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 126 |
{ |
| 127 |
} |