diff options
author | H. Peter Anvin <hpa@zytor.com> | 2019-03-01 00:31:40 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2019-03-01 00:31:40 -0800 |
commit | a89d436eda9c260745dd3a772d8bcc193566c809 (patch) | |
tree | 8cafb230d51d72754803f9565974074acc0fc16f | |
parent | 0731d3d3947d6a47cf2d837b81bc72de26160ca3 (diff) | |
download | syslinux-a89d436eda9c260745dd3a772d8bcc193566c809.tar.gz syslinux-a89d436eda9c260745dd3a772d8bcc193566c809.tar.xz syslinux-a89d436eda9c260745dd3a772d8bcc193566c809.zip |
WIP: another snapshot; now fails building the efi32 ldlinux.e32
-rw-r--r-- | com32/include/com32.h | 15 | ||||
-rw-r--r-- | core/Makefile | 6 | ||||
-rw-r--r-- | core/Makefile.bios | 2 | ||||
-rw-r--r-- | core/Makefile.efi | 24 | ||||
-rw-r--r-- | core/bios/bios.c | 13 | ||||
-rw-r--r-- | core/bios/mem/free.c (renamed from core/mem/free.c) | 45 | ||||
-rw-r--r-- | core/bios/mem/init.c (renamed from core/mem/init.c) | 0 | ||||
-rw-r--r-- | core/bios/mem/malloc.c (renamed from core/mem/malloc.c) | 53 | ||||
-rw-r--r-- | core/bios/mem/malloc.h (renamed from core/mem/malloc.h) | 0 | ||||
-rw-r--r-- | core/bios/mem/tests/Makefile (renamed from core/mem/tests/Makefile) | 0 | ||||
-rw-r--r-- | core/bios/mem/tests/meminit.c (renamed from core/mem/tests/meminit.c) | 0 | ||||
-rw-r--r-- | core/common/pmapi.c | 46 | ||||
-rw-r--r-- | core/common/zalloc.c | 18 | ||||
-rw-r--r-- | core/efi/arch/i386/linux.S (renamed from core/efi/i386/linux.S) | 0 | ||||
-rw-r--r-- | core/efi/arch/i386/syslinux.ld (renamed from core/efi/i386/syslinux.ld) | 0 | ||||
-rw-r--r-- | core/efi/arch/x86_64/linux.S (renamed from core/efi/x86_64/linux.S) | 0 | ||||
-rw-r--r-- | core/efi/arch/x86_64/syslinux.ld (renamed from core/efi/x86_64/syslinux.ld) | 0 | ||||
-rw-r--r-- | core/efi/main.c | 9 | ||||
-rw-r--r-- | core/efi/mem.c | 26 |
19 files changed, 61 insertions, 196 deletions
diff --git a/com32/include/com32.h b/com32/include/com32.h index a46284bb..0a1e75a2 100644 --- a/com32/include/com32.h +++ b/com32/include/com32.h @@ -74,21 +74,6 @@ typedef struct { reg32_t eflags; /* Offset 40 */ } com32sys_t; -struct com32_pmapi; - -extern struct com32_sys_args { - uint32_t cs_sysargs; - char *cs_cmdline; - void __cdecl (*cs_intcall)(uint8_t, const com32sys_t *, com32sys_t *); - void *cs_bounce; - uint32_t cs_bounce_size; - void __cdecl (*cs_farcall)(uint32_t, const com32sys_t *, com32sys_t *); - int __cdecl (*cs_cfarcall)(uint32_t, const void *, uint32_t); - uint32_t cs_memsize; - const char *cs_name; - const struct com32_pmapi *cs_pm; -} __com32; - extern const com32sys_t __com32_zero_regs; /* diff --git a/core/Makefile b/core/Makefile index b6d74166..2f5cac5f 100644 --- a/core/Makefile +++ b/core/Makefile @@ -39,7 +39,10 @@ PREPCORE = $(objdir)/prepcore/$(fwclass)/prepcore # All primary source files for the main syslinux files SRCFILES := $(sort $(shell find $(SRCDIRS:%=$(SRC)/%) \ - -name tests -prune -o -type f -print)) + -name tests -type d -prune -o \ + -name $(ARCH) -type d -true -o \ + -regex '.*/arch/[^/]+' -type d -prune -o \ + -type f -print)) NASMSRC := $(filter %.asm,$(SRCFILES)) NASMHDR := $(filter %.inc,$(SRCFILES)) CSRC := $(filter %.c ,$(SRCFILES)) @@ -81,6 +84,7 @@ DATE := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE)) endif CORELDSCRIPT ?= $(SRC)/$(fwclass)/syslinux.ld +CORE_LIBOBJS := $(filter-out $(FILTER_DIRS:%=%/%.o),$(ALLOBJ)) CORELDFLAGS += $(MAIN_LDFLAGS) -pie --no-dynamic-linker \ --unresolved-symbols=report-all \ diff --git a/core/Makefile.bios b/core/Makefile.bios index ea33f9cc..f3ade9aa 100644 --- a/core/Makefile.bios +++ b/core/Makefile.bios @@ -38,8 +38,6 @@ LPXELINUX_OBJS := $(filter $(LPXELINUX_DIRS:%=%/%.o),$(ALLOBJ)) PXELINUX_OBJS := $(filter $(PXELINUX_DIRS:%=%/%.o),$(ALLOBJ)) MAIN_OBJS := $(filter $(MAIN_DIRS:%=%/%.o),$(ALLOBJ)) -CORE_LIBOBJS := $(filter-out $(FILTER_DIRS:%=%/%.o),$(ALLOBJ)) - AUXLIBS := bios/pxelinux.a bios/lpxelinux.a CORELDSCRIPT := $(SRC)/bios/syslinux.ld diff --git a/core/Makefile.efi b/core/Makefile.efi index dce513ed..7b1db7a4 100644 --- a/core/Makefile.efi +++ b/core/Makefile.efi @@ -21,14 +21,12 @@ BTARGET = syslinux.efi # The corresponding ELF files ETARGET = efi/syslinux.elf -# Export library files -LIBCORE_FILES = libcore.so libcore.weak - -CORE_LIBOBJS = $(ALLOBJ) - CORELDFLAGS = CORE_LIB = efi/libsyslinux.a +CORE_LIBS += $(objdir)/com32/efi/lib/libgnuefi.a \ + $(objdir)/com32/efi/lib/libefi.a + INCLUDE += -I$(SRC)/efi CFLAGS += $(DATE_DEFS) @@ -36,15 +34,9 @@ CFLAGS += $(DATE_DEFS) syslinux.efi: efi/syslinux.elf $(PREPCORE) $(PREPCORE) $< $@ -wrapper: wrapper.c wrapper.h - $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $< $(LIBS_FOR_BUILD) - -CORELDSCRIPT = $(LDSCRIPT) - -# Assembly file to force certain symbols to be exported even if -# they are not used by the core. -EXPORT = export.o +CORELDSCRIPT = $(SRC)/efi/arch/$(ARCH)/syslinux.ld -$(ETARGET): $(CORE_LIB) - $(LD) $(CORELDFLAGS) --strip-debug -o $@ $^ \ - -L$(objdir)/com32/efi/lib -lgnuefi -lefi +$(ETARGET): $(CORE_LIB) $(CORE_LIBS) $(CORELDSCRIPT) + $(LD) $(CORELDFLAGS) --strip-debug -o $@ \ + --whole-archive $(CORE_LIB) --no-whole-archive \ + --start-group $(CORE_LIBS) --end-group > $*.map diff --git a/core/bios/bios.c b/core/bios/bios.c index 7fb37fec..ed2e52f8 100644 --- a/core/bios/bios.c +++ b/core/bios/bios.c @@ -690,16 +690,6 @@ static void bios_cleanup_hardware(void) sirq_cleanup(); } -extern void *bios_malloc(size_t, enum heap, size_t); -extern void *bios_realloc(void *, size_t); -extern void bios_free(void *); - -struct mem_ops bios_mem_ops = { - .malloc = bios_malloc, - .realloc = bios_realloc, - .free = bios_free, -}; - struct firmware bios_fw = { .init = bios_init, .adjust_screen = bios_adjust_screen, @@ -709,8 +699,7 @@ struct firmware bios_fw = { .i_ops = &bios_input_ops, .get_serial_console_info = bios_get_serial_console_info, .adv_ops = &bios_adv_ops, - .vesa = &bios_vesa_ops, - .mem = &bios_mem_ops, + .vesa = &bios_vesa_ops }; void syslinux_register_bios(void) diff --git a/core/mem/free.c b/core/bios/mem/free.c index 21f9b59f..b9b554b7 100644 --- a/core/mem/free.c +++ b/core/bios/mem/free.c @@ -6,7 +6,6 @@ #include <syslinux/firmware.h> #include <stdlib.h> -#include <dprintf.h> #include "malloc.h" #include <stdio.h> @@ -67,40 +66,16 @@ __free_block(struct free_arena_header *ah) return ah; } -void bios_free(void *ptr) +__export void free(void *ptr) { struct free_arena_header *ah; ah = (struct free_arena_header *) ((struct arena_header *)ptr - 1); -#ifdef DEBUG_MALLOC - if (ah->a.magic != ARENA_MAGIC) - dprintf("failed free() magic check: %p\n", ptr); - - if (ARENA_TYPE_GET(ah->a.attrs) != ARENA_TYPE_USED) - dprintf("invalid arena type: %d\n", ARENA_TYPE_GET(ah->a.attrs)); -#endif - __free_block(ah); } -__export void free(void *ptr) -{ -#ifdef DEBUG_MALLOC - dprintf("free(%p) @ %p\n", ptr, __builtin_return_address(0)); -#endif - - if ( !ptr ) - return; - - sem_down(&__malloc_semaphore, 0); - firmware->mem->free(ptr); - sem_up(&__malloc_semaphore); - - /* Here we could insert code to return memory to the system. */ -} - /* * This is used to insert a block which is not previously on the * free list. Only the a.size field of the arena header is assumed @@ -114,10 +89,6 @@ void __inject_free_block(struct free_arena_header *ah) size_t a_end = (size_t) ah + ARENA_SIZE_GET(ah->a.attrs); size_t n_end; - dprintf("inject: %#zx bytes @ %p, heap %u (%p)\n", - ARENA_SIZE_GET(ah->a.attrs), ah, - ARENA_HEAP_GET(ah->a.attrs), head); - sem_down(&__malloc_semaphore, 0); for (nah = head->a.next ; nah != head ; nah = nah->a.next) { @@ -131,8 +102,6 @@ void __inject_free_block(struct free_arena_header *ah) if ((size_t) ah >= n_end) continue; - printf("conflict:ah: %p, a_end: %p, nah: %p, n_end: %p\n", ah, a_end, nah, n_end); - /* Otherwise we have some sort of overlap - reject this block */ sem_up(&__malloc_semaphore); return; @@ -152,14 +121,14 @@ void __inject_free_block(struct free_arena_header *ah) /* * Free all memory which is tagged with a specific tag. */ -static void __free_tagged(malloc_tag_t tag) { +__export void __free_tagged(malloc_tag_t tag) +{ struct free_arena_header *fp, *head; int i; sem_down(&__malloc_semaphore, 0); for (i = 0; i < NHEAP; i++) { - dprintf("__free_tagged(%u) heap %d\n", tag, i); head = &__core_malloc_head[i]; for (fp = head->a.next ; fp != head ; fp = fp->a.next) { if (ARENA_TYPE_GET(fp->a.attrs) == ARENA_TYPE_USED && @@ -169,12 +138,4 @@ static void __free_tagged(malloc_tag_t tag) { } sem_up(&__malloc_semaphore); - dprintf("__free_tagged(%u) done\n", tag); -} - -void comboot_cleanup_lowmem(com32sys_t *regs) -{ - (void)regs; - - __free_tagged(MALLOC_MODULE); } diff --git a/core/mem/init.c b/core/bios/mem/init.c index 4f2ae70c..4f2ae70c 100644 --- a/core/mem/init.c +++ b/core/bios/mem/init.c diff --git a/core/mem/malloc.c b/core/bios/mem/malloc.c index 836c2fe3..807557d3 100644 --- a/core/mem/malloc.c +++ b/core/bios/mem/malloc.c @@ -67,12 +67,14 @@ static void *__malloc_from_block(struct free_arena_header *fp, return (void *)(&fp->a + 1); } -void *bios_malloc(size_t size, enum heap heap, malloc_tag_t tag) +static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag) { struct free_arena_header *fp; struct free_arena_header *head = &__core_malloc_head[heap]; void *p = NULL; + sem_down(&__malloc_semaphore, 0); + if (size) { /* Add the obligatory arena header, and round up */ size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK; @@ -84,27 +86,10 @@ void *bios_malloc(size_t size, enum heap heap, malloc_tag_t tag) break; } } + errno = ENOMEM; } - - return p; -} - -static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag) -{ - void *p; - -#ifdef DEBUG_MALLOC - dprintf("_malloc(%zu, %u, %u) @ %p = ", - size, heap, tag, __builtin_return_address(0)); -#endif - - sem_down(&__malloc_semaphore, 0); - p = firmware->mem->malloc(size, heap, tag); sem_up(&__malloc_semaphore); -#ifdef DEBUG_MALLOC - dprintf("%p\n", p); -#endif return p; } @@ -117,18 +102,10 @@ __export void *lmalloc(size_t size) { void *p; - p = _malloc(size, HEAP_LOWMEM, MALLOC_CORE); - if (!p) - errno = ENOMEM; - return p; + return _malloc(size, HEAP_LOWMEM, MALLOC_CORE); } -void *pmapi_lmalloc(size_t size) -{ - return _malloc(size, HEAP_LOWMEM, MALLOC_MODULE); -} - -void *bios_realloc(void *ptr, size_t size) +__export void *realloc(void *ptr, size_t size) { struct free_arena_header *ah, *nah; struct free_arena_header *head; @@ -224,7 +201,7 @@ void *bios_realloc(void *ptr, size_t size) head->next_free = nah; nah->next_free->prev_free = nah; } - } + } /* otherwise, use up the whole block */ return ptr; } else { @@ -239,19 +216,3 @@ void *bios_realloc(void *ptr, size_t size) } } } - -__export void *realloc(void *ptr, size_t size) -{ - return firmware->mem->realloc(ptr, size); -} - -__export void *zalloc(size_t size) -{ - void *ptr; - - ptr = malloc(size); - if (ptr) - memset(ptr, 0, size); - - return ptr; -} diff --git a/core/mem/malloc.h b/core/bios/mem/malloc.h index 4611a306..4611a306 100644 --- a/core/mem/malloc.h +++ b/core/bios/mem/malloc.h diff --git a/core/mem/tests/Makefile b/core/bios/mem/tests/Makefile index d1fb7867..d1fb7867 100644 --- a/core/mem/tests/Makefile +++ b/core/bios/mem/tests/Makefile diff --git a/core/mem/tests/meminit.c b/core/bios/mem/tests/meminit.c index e6c25c71..e6c25c71 100644 --- a/core/mem/tests/meminit.c +++ b/core/bios/mem/tests/meminit.c diff --git a/core/common/pmapi.c b/core/common/pmapi.c deleted file mode 100644 index cfdffa69..00000000 --- a/core/common/pmapi.c +++ /dev/null @@ -1,46 +0,0 @@ -/* ----------------------------------------------------------------------- - * - * Copyright 1994-2009 H. Peter Anvin - All Rights Reserved - * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -#include <inttypes.h> -#include <com32.h> -#include <syslinux/pmapi.h> -#include "core.h" -#include "fs.h" - -const struct com32_pmapi pm_api_vector = -{ - .__pmapi_size = sizeof(struct com32_pmapi), - - .lmalloc = pmapi_lmalloc, /* Allocate low memory */ - .lfree = free, /* Free low memory */ - - .open_file = open_file, - .read_file = pmapi_read_file, - .close_file = close_file, - - .opendir = opendir, - .readdir = readdir, - .closedir = closedir, - - .idle = __idle, - .reset_idle = reset_idle, - - .chdir = chdir, - .getcwd = core_getcwd, - - .jiffies = &__jiffies, - .ms_timer = &__ms_timer, - - .sysappend_count = SYSAPPEND_MAX, - .sysappend_strings = sysappend_strings, -}; diff --git a/core/common/zalloc.c b/core/common/zalloc.c new file mode 100644 index 00000000..b3f11448 --- /dev/null +++ b/core/common/zalloc.c @@ -0,0 +1,18 @@ +/* + * Allocate and zero + */ + +#include <core.h> +#include <stdlib.h> +#include <string.h> + +__export void *zalloc(size_t size) +{ + void *ptr; + + ptr = malloc(size); + if (ptr) + memset(ptr, 0, size); + + return ptr; +} diff --git a/core/efi/i386/linux.S b/core/efi/arch/i386/linux.S index 4049ad4d..4049ad4d 100644 --- a/core/efi/i386/linux.S +++ b/core/efi/arch/i386/linux.S diff --git a/core/efi/i386/syslinux.ld b/core/efi/arch/i386/syslinux.ld index bab3fc74..bab3fc74 100644 --- a/core/efi/i386/syslinux.ld +++ b/core/efi/arch/i386/syslinux.ld diff --git a/core/efi/x86_64/linux.S b/core/efi/arch/x86_64/linux.S index 29dde94a..29dde94a 100644 --- a/core/efi/x86_64/linux.S +++ b/core/efi/arch/x86_64/linux.S diff --git a/core/efi/x86_64/syslinux.ld b/core/efi/arch/x86_64/syslinux.ld index 450641c6..450641c6 100644 --- a/core/efi/x86_64/syslinux.ld +++ b/core/efi/arch/x86_64/syslinux.ld diff --git a/core/efi/main.c b/core/efi/main.c index 74e692c2..8b50a407 100644 --- a/core/efi/main.c +++ b/core/efi/main.c @@ -393,9 +393,7 @@ extern uint16_t *bios_free_mem; void efi_init(void) { /* XXX timer */ - *bios_free_mem = 0; syslinux_memscan_add(&efi_memscan); - mem_init(); } char efi_getchar(char *hi) @@ -1245,12 +1243,6 @@ static void serialcfg(uint16_t *iobase, uint16_t *divisor, uint16_t *flowctl) extern struct vesa_ops efi_vesa_ops; -struct mem_ops efi_mem_ops = { - .malloc = efi_malloc, - .realloc = efi_realloc, - .free = efi_free, -}; - struct firmware efi_fw = { .init = efi_init, .disk_init = efi_disk_init, @@ -1260,7 +1252,6 @@ struct firmware efi_fw = { .adv_ops = &efi_adv_ops, .boot_linux = efi_boot_linux, .vesa = &efi_vesa_ops, - .mem = &efi_mem_ops, }; static inline void syslinux_register_efi(void) diff --git a/core/efi/mem.c b/core/efi/mem.c index 67e8221d..6296b856 100644 --- a/core/efi/mem.c +++ b/core/efi/mem.c @@ -2,26 +2,38 @@ * Copyright 2012-2014 Intel Corporation - All Rights Reserved */ -#include <mem/malloc.h> +#include <stdlib.h> +#include <errno.h> #include <string.h> #include "efi.h" -void *efi_malloc(size_t size, enum heap heap, malloc_tag_t tag) +__export void *malloc(size_t size) { - return AllocatePool(size); + void *p = AllocatePool(size); + if (!p) + errno = ENOMEM; + return p; } -void *efi_realloc(void *ptr, size_t size) +__export void *lmalloc(size_t) __attribute__((alias("malloc"))); + +__export void *realloc(void *ptr, size_t size) { void *newptr; newptr = AllocatePool(size); - memcpy(newptr, ptr, size); - FreePool(ptr); + if (!newptr) { + errno = ENOMEM; + return NULL; + } + if (ptr) { + memcpy(newptr, ptr, size); + FreePool(ptr); + } return newptr; } -void efi_free(void *ptr) +__export void free(void *ptr) { FreePool(ptr); } |