aboutsummaryrefslogtreecommitdiffstats
path: root/memdisk
diff options
context:
space:
mode:
Diffstat (limited to 'memdisk')
-rw-r--r--memdisk/Makefile34
-rw-r--r--memdisk/memdisk.h15
-rw-r--r--memdisk/setup.c8
3 files changed, 32 insertions, 25 deletions
diff --git a/memdisk/Makefile b/memdisk/Makefile
index 529d4a6d..66a6e51a 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -11,26 +11,22 @@
## -----------------------------------------------------------------------
topdir = ..
+include $(topdir)/MCONFIG
-include $(topdir)/version.mk
-TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
-
-CC = gcc
-
-gcc_ok = $(shell tmpf=$(TMPFILE); if $(CC) $(1) -c -x c /dev/null -o $$tmpf 2>/dev/null; \
- then echo $(1); else echo $(2); fi; rm -f $$tmpf)
-
-M32 := $(call gcc_ok,-m32,)
-ALIGN := $(call gcc_ok,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-malign-functions=0 -malign-jumps=0 -malign-loops=0)
-FREE := $(call gcc_ok,-ffreestanding,) $(call gcc_ok,-fno-stack-protector,)
-
-CFLAGS = $(M32) $(FREE) -g -W -Wall -Wno-sign-compare \
- -Os -fomit-frame-pointer -march=i386 -mregparm=3 $(ALIGN) \
- -DDATE='"$(DATE)"'
-SFLAGS = $(M32) -march=i386 -D__ASSEMBLY__
-LDFLAGS = $(M32) -g
-INCLUDE = -I../com32/include
-LD = ld -m elf_i386
+GCCOPT := $(call gcc_ok,-m32,) \
+ $(call gcc_ok,-ffreestanding,) \
+ $(call gcc_ok,-fno-stack-protector) \
+ $(call gcc_ok,-falign-functions=0,-malign-functions=0) \
+ $(call gcc_ok,-falign-jumps=0,-malign-jumps=0) \
+ $(call gcc_ok,-falign-loops=0,-malign-loops=0) \
+ -march=i386 -Os -fomit-frame-pointer -mregparm=3 -DREGPARM=3
+
+CFLAGS = $(GCCOPT) -g -W -Wall -Wno-sign-compare -DDATE='"$(DATE)"'
+SFLAGS = $(GCCOPT) -D__ASSEMBLY__
+LDFLAGS = $(GCCOPT) -g
+INCLUDE = -I$(topdir)/com32/include
+LD += -m elf_i386
NASM = nasm
NASMOPT = -O9999
NFLAGS = -dDATE='"$(DATE)"' -dWITH_EDD
@@ -63,7 +59,7 @@ all: memdisk # e820test
# tidy, clean removes everything except the final binary
tidy dist:
- rm -f *.o *.s *.o16 *.s16 *.bin *.lst *.elf e820test
+ rm -f *.o *.s *.tmp *.o16 *.s16 *.bin *.lst *.elf e820test
clean: tidy
diff --git a/memdisk/memdisk.h b/memdisk/memdisk.h
index 615e3d1e..9d4a4297 100644
--- a/memdisk/memdisk.h
+++ b/memdisk/memdisk.h
@@ -40,11 +40,22 @@ extern void __attribute__((noreturn)) die(void);
#define memcpy(a,b,c) __builtin_memcpy(a,b,c)
#define memset(a,b,c) __builtin_memset(a,b,c)
#define strcpy(a,b) __builtin_strcpy(a,b)
-#define strlen(a) __builtin_strlen(a)
+
+static inline size_t strlen(const char *__a)
+{
+ const char *__D;
+ size_t __c;
+
+ asm("repne;scasb"
+ : "=D" (__D), "=c" (__c)
+ : "D" (__a), "c" (-1), "a" (0), "m" (*__a));
+
+ return __D - __a - 1;
+}
/* memcpy() but returns a pointer to end of buffer */
static inline void *
-memcpy_endptr(void *__d, const void *__s, unsigned int __n)
+mempcpy(void *__d, const void *__s, unsigned int __n)
{
memcpy(__d, __s, __n);
return (void *)((char *)__d + __n);
diff --git a/memdisk/setup.c b/memdisk/setup.c
index b9466335..583570ea 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -751,7 +751,7 @@ __cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce)
map -- 12 bytes per range; we may need as many as 2 additional
ranges (each insertrange() can worst-case turn 1 area into 3)
plus the terminating range, over what nranges currently show. */
- cmdlinelen = strlen(shdr->cmdline)+1;
+ cmdlinelen = strlen(shdr->cmdline)+1;
total_size = hptr->total_size; /* Actual memdisk code */
total_size += (nranges+3)*sizeof(ranges[0]); /* E820 memory ranges */
total_size += cmdlinelen; /* Command line */
@@ -873,9 +873,9 @@ __cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce)
hptr = (struct memdisk_header *)dpp;
/* Actually copy to low memory */
- dpp = memcpy_endptr(dpp, &_binary_memdisk_bin_start, bin_size);
- dpp = memcpy_endptr(dpp, ranges, (nranges+1)*sizeof(ranges[0]));
- dpp = memcpy_endptr(dpp, shdr->cmdline, cmdlinelen+1);
+ dpp = mempcpy(dpp, &_binary_memdisk_bin_start, bin_size);
+ dpp = mempcpy(dpp, ranges, (nranges+1)*sizeof(ranges[0]));
+ dpp = mempcpy(dpp, shdr->cmdline, cmdlinelen+1);
}
/* Update various BIOS magic data areas (gotta love this shit) */