Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / libc / stdlib / memory.c
blob28906d226ed472a47834277268414b1325643d5a
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <string.h>
23 void *malloc (size_t size)
25 void *p = 0;
27 asm volatile (
28 "movl $14, %%eax;"
29 "movl %1, %%ebx;"
30 "int $0x80;"
31 "movl %%eax, %0;": "=g" (p) : "g" ((unsigned) size) : "%eax", "%ebx");
33 return (void *) p;
36 void *calloc (size_t nmemb, size_t size)
38 void *p = malloc (nmemb * size);
40 if (p)
41 memset (p, 0, nmemb * size);
43 return p;
46 void free (void *blk)
48 asm volatile (
49 "movl $43, %%eax;"
50 "movl %0, %%ebx;"
51 "int $0x80;" :: "b" (blk) : "%eax", "memory");
54 void *realloc (void *blk, size_t size)
56 void *p = 0;
58 asm volatile (
59 "movl $44, %%eax;"
60 "movl %1, %%ebx;"
61 "movl %2, %%ecx;"
62 "int $0x80;"
63 "movl %%eax, %0;": "=g" (p) : "b" (blk), "g" ((unsigned) size) : "%eax", "memory", "%ecx");
65 return (void *) p;