[syslinux:elflink] elflink: Remove MODULE_MAIN() from executable ELF modules

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Wed Apr 27 14:30:51 PDT 2011


Commit-ID:  990e7e1df3dc6fa456ff7cdaec7d239977557c8d
Gitweb:     http://syslinux.zytor.com/commit/990e7e1df3dc6fa456ff7cdaec7d239977557c8d
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Thu, 7 Apr 2011 21:02:02 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Tue, 26 Apr 2011 09:53:24 +0100

elflink: Remove MODULE_MAIN() from executable ELF modules

To make it easier to move existing COM32 modules over to ELF modules
without having to modify them we need to search for and run their
main() functions when they're loaded instead of requiring their
initial function to be labeled with MODULE_MAIN().

Currently, we require all executable ELF modules to specify their
initial function with the use of the MODULE_MAIN() macro and not via
the traditional method of naming it main(). However, there are weird
restrictions on what functions can be passed to MODULE_MAIN(), for
instance, they must be declared static.

This patch makes life much simpler and allows executable ELF modules
to be loaded without the MODULE_MAIN() wrapper, but rather by naming
their initial function main(). All the modules in com32/modules can
now be run as ELF modules without any modifications.

Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com>


---
 com32/elflink/ldlinux/ldlinux.c   |    3 +-
 com32/elflink/modules/Makefile    |   11 +--
 com32/elflink/modules/cpuid.c     |   61 -------------
 com32/elflink/modules/cpuidtest.c |  140 -----------------------------
 com32/elflink/modules/dir.c       |  178 -------------------------------------
 com32/elflink/modules/disk.c      |   60 -------------
 com32/elflink/modules/hello.c     |    7 +-
 com32/elflink/modules/meminfo.c   |    5 +-
 com32/elflink/modules/menu.c      |    4 +-
 com32/elflink/modules/mytest.c    |    5 +-
 com32/elflink/modules/pcitest.c   |  156 --------------------------------
 com32/elflink/modules/test.c      |    5 +-
 com32/elflink/modules/vesainfo.c  |    5 +-
 com32/include/sys/module.h        |    5 +-
 com32/lib/sys/module/elf_module.c |   16 +---
 com32/lib/sys/module/exec.c       |    8 +-
 16 files changed, 18 insertions(+), 651 deletions(-)

diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index 839a28a..5f4b058 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -97,7 +97,7 @@ static void enter_cmdline(void)
 	}
 }
 
-static int ldlinux_main(int argc, char **argv)
+int main(int argc, char **argv)
 {
 	openconsole(&dev_rawcon_r, &dev_ansiserial_w);
 
@@ -129,4 +129,3 @@ cmdline:
 
 	return 0;
 }
-MODULE_MAIN(ldlinux_main);
diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile
index eb2d052..8a274ae 100644
--- a/com32/elflink/modules/Makefile
+++ b/com32/elflink/modules/Makefile
@@ -18,7 +18,7 @@ CFLAGS += -I$(topdir)/core/elflink
 
 MODULES	  = hello.c32 sort.c32 mytest.c32 menumain.c32 printmsg.c32 background.c32 passwd.c32 sha1hash.c32 \
 	unbase64.c32 sha512crypt.c32 md5.c32 crypt-md5.c32 sha256crypt.c32 get_key.c32 ansiraw.c32 test.c32 \
-	meminfo.c32 menu.c32 drain.c32 dir.c32 pcitest.c32 vesainfo.c32 cpuid.c32 cpuidtest.c32
+	meminfo.c32 menu.c32 drain.c32 vesainfo.c32
 
 TESTFILES =
 
@@ -84,18 +84,9 @@ meminfo.c32 : meminfo.o
 pcitest.c32 : pcitest.o
 	$(LD) $(LDFLAGS) -o $@ $^
 
-dir.c32 : dir.o
-	$(LD) $(LDFLAGS) -o $@ $^
-
 vesainfo.c32 : vesainfo.o
 	$(LD) $(LDFLAGS) -o $@ $^
 
-cpuid.c32 : cpuid.o
-	$(LD) $(LDFLAGS) -o $@ $^
-
-cpuidtest.c32 : cpuidtest.o
-	$(LD) $(LDFLAGS) -o $@ $^
-
 tidy dist:
 	rm -f *.o *.lo *.a *.lst .*.d 
 
diff --git a/com32/elflink/modules/cpuid.c b/com32/elflink/modules/cpuid.c
deleted file mode 100644
index 1b5d188..0000000
--- a/com32/elflink/modules/cpuid.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 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., 51 Franklin St, Fifth Floor,
- *   Boston MA 02110-1301, USA; either version 2 of the License, or
- *   (at your option) any later version; incorporated herein by reference.
- *
- * ----------------------------------------------------------------------- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/cpu.h>
-#include <console.h>
-#include <com32.h>
-
-#include <sys/module.h>
-
-static void dump_reg(const char *name, uint32_t val)
-{
-	int i;
-
-	printf("%-3s : %10u 0x%08x ", name, val, val);
-
-	for (i = 3; i >= 0; i--) {
-		uint8_t c = val >> (i*8);
-		putchar((c >= ' ' && c <= '~') ? c : '.');
-	}
-	putchar('\n');
-}
-
-static int cpuid_main(int argc, char *argv[])
-{
-	uint32_t leaf, counter;
-	uint32_t eax, ebx, ecx, edx;
-
-	if (argc < 2 || argc > 4) {
-		printf("Usage: %s leaf [counter]\n", argv[0]);
-		exit(1);
-	}
-
-	leaf = strtoul(argv[1], NULL, 0);
-	counter = (argc > 2) ? strtoul(argv[2], NULL, 0) : 0;
-
-	if (!cpu_has_eflag(EFLAGS_ID)) {
-		printf("The CPUID instruction is not supported\n");
-		exit(1);
-	}
-
-	cpuid_count(leaf, counter, &eax, &ebx, &ecx, &edx);
-
-	dump_reg("eax", eax);
-	dump_reg("ebx", ebx);
-	dump_reg("ecx", ecx);
-	dump_reg("edx", edx);
-
-	return 0;
-}
-MODULE_MAIN(cpuid_main);
diff --git a/com32/elflink/modules/cpuidtest.c b/com32/elflink/modules/cpuidtest.c
deleted file mode 100644
index 942955f..0000000
--- a/com32/elflink/modules/cpuidtest.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2006 Erwan Velu - All Rights Reserved
- *
- *   Permission is hereby granted, free of charge, to any person
- *   obtaining a copy of this software and associated documentation
- *   files (the "Software"), to deal in the Software without
- *   restriction, including without limitation the rights to use,
- *   copy, modify, merge, publish, distribute, sublicense, and/or
- *   sell copies of the Software, and to permit persons to whom
- *   the Software is furnished to do so, subject to the following
- *   conditions:
- *
- *   The above copyright notice and this permission notice shall
- *   be included in all copies or substantial portions of the Software.
- *
- *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- *   OTHER DEALINGS IN THE SOFTWARE.
- *
- * -----------------------------------------------------------------------
-*/
-
-/*
- * cpuidtest.c
- *
- * A CPUID demo program using libcom32
- */
-
-#include <string.h>
-#include <stdio.h>
-#include <console.h>
-#include "cpuid.h"
-
-#include <sys/module.h>
-
-char display_line;
-
-static int cpuidtest_main(void)
-{
-    s_cpu cpu;
-
-    for (;;) {
-	detect_cpu(&cpu);
-	printf("Vendor      = %s\n", cpu.vendor);
-	printf("Model       = %s\n", cpu.model);
-	printf("Vendor ID   = %d\n", cpu.vendor_id);
-	printf("Family      = %d\n", cpu.family);
-	printf("Model ID    = %d\n", cpu.model_id);
-	printf("Stepping    = %d\n", cpu.stepping);
-	printf("Flags       = ");
-	if (cpu.flags.fpu)
-	    printf("fpu ");
-	if (cpu.flags.vme)
-	    printf("vme ");
-	if (cpu.flags.de)
-	    printf("de ");
-	if (cpu.flags.pse)
-	    printf("pse ");
-	if (cpu.flags.tsc)
-	    printf("tsc ");
-	if (cpu.flags.msr)
-	    printf("msr ");
-	if (cpu.flags.pae)
-	    printf("pae ");
-	if (cpu.flags.mce)
-	    printf("mce ");
-	if (cpu.flags.cx8)
-	    printf("cx8 ");
-	if (cpu.flags.apic)
-	    printf("apic ");
-	if (cpu.flags.sep)
-	    printf("sep ");
-	if (cpu.flags.mtrr)
-	    printf("mtrr ");
-	if (cpu.flags.pge)
-	    printf("pge ");
-	if (cpu.flags.mca)
-	    printf("mca ");
-	if (cpu.flags.cmov)
-	    printf("cmov ");
-	if (cpu.flags.pat)
-	    printf("pat ");
-	if (cpu.flags.pse_36)
-	    printf("pse_36 ");
-	if (cpu.flags.psn)
-	    printf("psn ");
-	if (cpu.flags.clflsh)
-	    printf("clflsh ");
-	if (cpu.flags.dts)
-	    printf("dts ");
-	if (cpu.flags.acpi)
-	    printf("acpi ");
-	if (cpu.flags.mmx)
-	    printf("mmx ");
-	if (cpu.flags.sse)
-	    printf("sse ");
-	if (cpu.flags.sse2)
-	    printf("sse2 ");
-	if (cpu.flags.ss)
-	    printf("ss ");
-	if (cpu.flags.htt)
-	    printf("ht ");
-	if (cpu.flags.acc)
-	    printf("acc ");
-	if (cpu.flags.syscall)
-	    printf("syscall ");
-	if (cpu.flags.mp)
-	    printf("mp ");
-	if (cpu.flags.nx)
-	    printf("nx ");
-	if (cpu.flags.mmxext)
-	    printf("mmxext ");
-	if (cpu.flags.lm)
-	    printf("lm ");
-	if (cpu.flags.nowext)
-	    printf("3dnowext ");
-	if (cpu.flags.now)
-	    printf("3dnow! ");
-	if (cpu.flags.vmx)
-	    printf("vmx ");
-	if (cpu.flags.svm)
-	    printf("svm ");
-	printf("\n");
-	printf("SMP         = ");
-	if (cpu.flags.smp)
-	    printf("yes\n");
-	else
-	    printf("no\n");
-	break;
-    }
-
-    return 0;
-}
-MODULE_MAIN(cpuidtest_main);
diff --git a/com32/elflink/modules/dir.c b/com32/elflink/modules/dir.c
deleted file mode 100644
index 17e7880..0000000
--- a/com32/elflink/modules/dir.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Display directory contents
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <console.h>
-#include <string.h>
-#include <com32.h>
-#include <dirent.h>
-#include <minmax.h>
-#include <unistd.h>
-#include <getkey.h>
-
-#include <sys/module.h>
-
-static int rows, cols;		/* Screen parameters */
-
-#define DIR_CHUNK	1024
-
-static const char *type_str(int type)
-{
-    switch (type) {
-    case DT_FIFO:
-	return "[fif]";
-    case DT_CHR:
-	return "[chr]";
-    case DT_DIR:
-	return "[dir]";
-    case DT_BLK:
-	return "[blk]";
-    case DT_UNKNOWN:
-    case DT_REG:
-	return "";
-    case DT_LNK:
-	return "[lnk]";
-    case DT_SOCK:
-	return "[sck]";
-    case DT_WHT:
-	return "[wht]";
-    default:
-	return "[???]";
-    }
-}
-
-static void free_dirents(struct dirent **dex, size_t n_de)
-{
-    size_t i;
-
-    for (i = 0; i < n_de; i++)
-	free(dex[i]);
-
-    free(dex);
-}
-
-static int compare_dirent(const void *p_de1, const void *p_de2)
-{
-    const struct dirent *de1 = *(const struct dirent **)p_de1;
-    const struct dirent *de2 = *(const struct dirent **)p_de2;
-    int ndir1, ndir2;
-
-    ndir1 = de1->d_type != DT_DIR;
-    ndir2 = de2->d_type != DT_DIR;
-
-    if (ndir1 != ndir2)
-	return ndir1 - ndir2;
-
-    return strcmp(de1->d_name, de2->d_name);
-}
-
-static int display_directory(const char *dirname)
-{
-    DIR *dir;
-    struct dirent *de;
-    struct dirent **dex = NULL;
-    size_t n_dex = 0, n_de = 0;
-    size_t i, j, k;
-    size_t nrows, ncols, perpage;
-    size_t endpage;
-    int maxlen = 0;
-    int pos, tpos, colwidth;
-
-    dir = opendir(dirname);
-    if (!dir) {
-	printf("Unable to read directory: %s\n", dirname);
-	return -1;
-    }
-
-    while ((de = readdir(dir)) != NULL) {
-	struct dirent *nde;
-
-	if (n_de >= n_dex) {
-	    struct dirent **ndex;
-
-	    ndex = realloc(dex, (n_dex + DIR_CHUNK) * sizeof *dex);
-	    if (!ndex)
-		goto nomem;
-
-	    dex = ndex;
-	    n_dex += DIR_CHUNK;
-	}
-
-	nde = malloc(de->d_reclen);
-	if (!nde)
-	    goto nomem;
-
-	memcpy(nde, de, de->d_reclen);
-	dex[n_de++] = nde;
-
-	maxlen = max(maxlen, de->d_reclen);
-    }
-
-    closedir(dir);
-
-    qsort(dex, n_de, sizeof *dex, compare_dirent);
-
-    maxlen -= offsetof(struct dirent, d_name) + 1;
-    ncols = (cols + 2)/(maxlen + 8);
-    ncols = min(ncols, n_de);
-    ncols = max(ncols, 1U);
-    colwidth = (cols + 2)/ncols;
-    perpage = ncols * (rows - 1);
-
-    for (i = 0; i < n_de; i += perpage) {
-	/* Rows on this page */
-	endpage = min(i+perpage, n_de);
-	nrows = ((endpage-i) + ncols - 1)/ncols;
-
-	for (j = 0; j < nrows; j++) {
-	    pos = tpos = 0;
-	    for (k = i+j; k < endpage; k += nrows) {
-		pos += printf("%*s%-5s %s",
-			      (tpos - pos), "",
-			      type_str(dex[k]->d_type),
-			      dex[k]->d_name);
-		tpos += colwidth;
-	    }
-	    printf("\n");
-	}
-
-	if (endpage >= n_de)
-	    break;
-
-	get_key(stdin, 0);
-    }
-
-    free_dirents(dex, n_de);
-    return 0;
-
-nomem:
-    closedir(dir);
-    printf("Out of memory error!\n");
-    free_dirents(dex, n_de);
-    return -1;
-}
-
-static int dir_main(int argc, char *argv[])
-{
-    int rv;
-    
-    if (getscreensize(1, &rows, &cols)) {
-	/* Unknown screen size? */
-	rows = 24;
-	cols = 80;
-    }
-
-    if (argc < 2)
-	rv = display_directory(".");
-    else if (argc == 2)
-	rv = display_directory(argv[1]);
-    else {
-	printf("Usage: dir directory\n");
-	rv = 1;
-    }
-
-    return rv ? 1 : 0;
-}
-MODULE_MAIN(dir_main);
-  
diff --git a/com32/elflink/modules/disk.c b/com32/elflink/modules/disk.c
deleted file mode 100644
index 3c864bd..0000000
--- a/com32/elflink/modules/disk.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
- *
- *   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., 51 Franklin St, Fifth Floor,
- *   Boston MA 02110-1301, USA; either version 2 of the License, or
- *   (at your option) any later version; incorporated herein by reference.
- *
- * ----------------------------------------------------------------------- */
-
-#include <stdio.h>
-#include <console.h>
-#include <stdlib.h>
-#include <string.h>
-#include <disk/geom.h>
-#include <disk/util.h>
-#include <disk/errno_disk.h>
-#include <disk/error.h>
-
-#include <sys/module.h>
-
-int disk_main(int argc, char *argv[])
-{
-	struct driveinfo drive;
-	struct driveinfo *d = &drive;
-
-	for (int disk = 0x80; disk < 0xff; disk++) {
-		memset(d, 0, sizeof(struct driveinfo));
-		d->disk = disk;
-		get_drive_parameters(d);
-
-		/* Do not print output when drive does not exists */
-		if (errno_disk == -1 || !d->cbios)
-			continue;
-
-		if (errno_disk) {
-			printf("reading disk");
-			continue;
-		}
-
-		printf("DISK 0x%X:\n", d->disk);
-		printf("  C/H/S: %d heads, %d cylinders\n",
-			d->legacy_max_head + 1, d->legacy_max_cylinder + 1);
-		printf("         %d sectors/track, %d drives\n",
-			d->legacy_sectors_per_track, d->legacy_max_drive);
-		printf("  EDD:   ebios=%d, EDD version: %X\n",
-			d->ebios, d->edd_version);
-		printf("         %d heads, %d cylinders\n",
-			(int) d->edd_params.heads, (int) d->edd_params.cylinders);
-		printf("         %d sectors, %d bytes/sector, %d sectors/track\n",
-			(int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector,
-			(int) d->edd_params.sectors_per_track);
-		printf("         Host bus: %s, Interface type: %s\n\n",
-			d->edd_params.host_bus_type, d->edd_params.interface_type);
-	}
-	return 0;
-}
-MODULE_MAIN(disk_main);
diff --git a/com32/elflink/modules/hello.c b/com32/elflink/modules/hello.c
index b38f05c..f28d38d 100644
--- a/com32/elflink/modules/hello.c
+++ b/com32/elflink/modules/hello.c
@@ -7,23 +7,20 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/module.h>
 
 #include "sort.h"
 
 #define NUM_COUNT		10
 #define MAX_NUM			100
 
-static int hello_main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     int *nums = NULL;
 
     nums = malloc(NUM_COUNT * sizeof(int));
-    printf("Hello, world, from 0x%08X! malloc return %p\n", (unsigned int)&hello_main, nums);
+    printf("Hello, world, from 0x%08X! malloc return %p\n", (unsigned int)&main, nums);
 
     free(nums);
 
     return 0;
 }
-
-MODULE_MAIN(hello_main);
diff --git a/com32/elflink/modules/meminfo.c b/com32/elflink/modules/meminfo.c
index db9718a..00d0e14 100644
--- a/com32/elflink/modules/meminfo.c
+++ b/com32/elflink/modules/meminfo.c
@@ -22,8 +22,6 @@
 #include <console.h>
 #include <com32.h>
 
-#include <sys/module.h>
-
 struct e820_data {
     uint64_t base;
     uint64_t len;
@@ -124,10 +122,9 @@ static void dump_legacy(void)
 	   oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
 }
 
-static int meminfo_main(void)
+int main(int argc, char **argv)
 {
     dump_legacy();
     dump_e820();
     return 0;
 }
-MODULE_MAIN(meminfo_main);
diff --git a/com32/elflink/modules/menu.c b/com32/elflink/modules/menu.c
index c0813a8..d0134b3 100644
--- a/com32/elflink/modules/menu.c
+++ b/com32/elflink/modules/menu.c
@@ -5,16 +5,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <core-elf.h>
-#include <sys/module.h>
 
 #include "menu.h"
 
 /*
  * useage: menu.c32 [config file]
  */
-static int menu(int argc, char **argv)
+int menu(int argc, char **argv)
 {
 	menu_main(argc, argv);
 	return 0;
 }
-MODULE_MAIN(menu);
diff --git a/com32/elflink/modules/mytest.c b/com32/elflink/modules/mytest.c
index 04c59ac..e8b5c1c 100644
--- a/com32/elflink/modules/mytest.c
+++ b/com32/elflink/modules/mytest.c
@@ -15,16 +15,13 @@
 #include <core-elf.h>
 #include <syslinux/adv.h>
 #include <syslinux/config.h>
-#include <sys/module.h>
 
 #include "menu.h"
 
-static int mytest_main(int argc, char **argv)
+int main(int argc, char **argv)
 {
     console_ansi_raw();
     //edit_cmdline("",1);
     menu_main(argc, argv);
     return 0;
 }
-
-MODULE_MAIN(mytest_main);
diff --git a/com32/elflink/modules/pcitest.c b/com32/elflink/modules/pcitest.c
deleted file mode 100644
index dcb8098..0000000
--- a/com32/elflink/modules/pcitest.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2006 Erwan Velu - All Rights Reserved
- *
- *   Permission is hereby granted, free of charge, to any person
- *   obtaining a copy of this software and associated documentation
- *   files (the "Software"), to deal in the Software without
- *   restriction, including without limitation the rights to use,
- *   copy, modify, merge, publish, distribute, sublicense, and/or
- *   sell copies of the Software, and to permit persons to whom
- *   the Software is furnished to do so, subject to the following
- *   conditions:
- *
- *   The above copyright notice and this permission notice shall
- *   be included in all copies or substantial portions of the Software.
- *
- *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- *   OTHER DEALINGS IN THE SOFTWARE.
- *
- * -----------------------------------------------------------------------
-*/
-
-/*
- * pcitest.c
- *
- */
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <console.h>
-#include <com32.h>
-#include <sys/pci.h>
-#include <stdbool.h>
-
-#include <sys/module.h>
-
-#ifdef DEBUG
-# define dprintf printf
-#else
-# define dprintf(...) ((void)0)
-#endif
-
-char display_line = 0;
-#define moreprintf(...)				\
-  do {						\
-    display_line++;				\
-    if (display_line == 24) {			\
-      char tempbuf[10];				\
-      display_line=0;				\
-      printf("Press Enter to continue\n");	\
-      fgets(tempbuf, sizeof tempbuf, stdin);	\
-    }						\
-    printf ( __VA_ARGS__);			\
-  } while (0);
-
-void display_pci_devices(struct pci_domain *pci_domain)
-{
-    struct pci_device *pci_device;
-    char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
-			MAX_KERNEL_MODULES_PER_PCI_DEVICE];
-
-    for_each_pci_func(pci_device, pci_domain) {
-
-	memset(kernel_modules, 0, sizeof kernel_modules);
-
-/*	printf("PCI: found %d kernel modules for  %04x:%04x[%04x:%04x]\n",
-		  pci_device->dev_info->linux_kernel_module_count,
-		  pci_device->vendor, pci_device->product,
-		  pci_device->sub_vendor, pci_device->sub_product);
-*/
-	for (int i = 0; i < pci_device->dev_info->linux_kernel_module_count;
-	     i++) {
-	    if (i > 0) {
-		strncat(kernel_modules, " | ", 3);
-	    }
-	    strncat(kernel_modules,
-		    pci_device->dev_info->linux_kernel_module[i],
-		    LINUX_KERNEL_MODULE_SIZE - 1);
-	}
-
-	moreprintf("%04x:%04x[%04x:%04x]: %s\n",
-		   pci_device->vendor, pci_device->product,
-		   pci_device->sub_vendor, pci_device->sub_product,
-		   pci_device->dev_info->class_name);
-
-	moreprintf(" Vendor Name      : %s\n",
-		   pci_device->dev_info->vendor_name);
-	moreprintf(" Product Name     : %s\n",
-		   pci_device->dev_info->product_name);
-	moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus,
-		   __pci_slot, __pci_func);
-	moreprintf(" Kernel modules   : %s\n\n", kernel_modules);
-    }
-}
-
-static int pcitest_main(int argc, char *argv[])
-{
-    struct pci_domain *pci_domain;
-    int return_code = 0;
-    int nb_pci_devices = 0;
-
-    /* Scanning to detect pci buses and devices */
-    printf("PCI: Scanning PCI BUS\n");
-    pci_domain = pci_scan();
-    if (!pci_domain) {
-	printf("PCI: no devices found!\n");
-	return 1;
-    }
-
-    struct pci_device *pci_device;
-    for_each_pci_func(pci_device, pci_domain) {
-	nb_pci_devices++;
-    }
-
-    printf("PCI: %d PCI devices found\n", nb_pci_devices);
-
-    printf("PCI: Looking for device name\n");
-    /* Assigning product & vendor name for each device */
-    return_code = get_name_from_pci_ids(pci_domain, "pci.ids");
-    if (return_code == -ENOPCIIDS) {
-	printf("PCI: ERROR !\n");
-	printf("PCI: Unable to open pci.ids file in current directory.\n");
-	printf("PCI: PCI Device names can't be computed.\n");
-    }
-
-    printf("PCI: Resolving class names\n");
-    /* Assigning class name for each device */
-    return_code = get_class_name_from_pci_ids(pci_domain, "pci.ids");
-    if (return_code == -ENOPCIIDS) {
-	printf("PCI: ERROR !\n");
-	printf("PCI: Unable to open pci.ids file in current directory.\n");
-	printf("PCI: PCI class names can't be computed.\n");
-    }
-
-    printf("PCI: Looking for Kernel modules\n");
-    /* Detecting which kernel module should match each device */
-    return_code = get_module_name_from_pcimap(pci_domain, "modules.pcimap");
-    if (return_code == -ENOMODULESPCIMAP) {
-	printf("PCI: ERROR !\n");
-	printf("PCI: Unable to open modules.pcimap file in current directory.\n");
-	printf("PCI: Kernel Module names can't be computed.\n");
-    }
-
-    /* display the pci devices we found */
-    display_pci_devices(pci_domain);
-    return 0;
-}
-MODULE_MAIN(pcitest_main);
diff --git a/com32/elflink/modules/test.c b/com32/elflink/modules/test.c
index dd9e520..13892fb 100644
--- a/com32/elflink/modules/test.c
+++ b/com32/elflink/modules/test.c
@@ -45,12 +45,11 @@
 #include <console.h>
 #include <syslinux/loadfile.h>
 #include <syslinux/linux.h>
-#include <sys/module.h>
 #include <dprintf.h>
 
 //const char *progname = "test.c32";
 
-static int test_main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
     const char *kernel_name;
     struct initramfs *initramfs;
@@ -108,5 +107,3 @@ bail:
     fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
     return 1;
 }
-
-MODULE_MAIN(test_main);
diff --git a/com32/elflink/modules/vesainfo.c b/com32/elflink/modules/vesainfo.c
index 05e4f2c..86a4365 100644
--- a/com32/elflink/modules/vesainfo.c
+++ b/com32/elflink/modules/vesainfo.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include "../lib/sys/vesa/vesa.h"
 
-#include <sys/module.h>
-
 /* Wait for a keypress */
 static void wait_key(void)
 {
@@ -85,9 +83,8 @@ exit:
 	return;
 }
 
-static int vesainfo_main(void)
+int main(int argc, char **argv)
 {
     print_modes();
     return 0;
 }
-MODULE_MAIN(vesainfo_main);
diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h
index dbeab4a..fb72c4b 100644
--- a/com32/include/sys/module.h
+++ b/com32/include/sys/module.h
@@ -97,7 +97,7 @@ struct elf_module {
 
 	module_init_t		*init_func;	// The initialization entry point
 	module_exit_t		*exit_func;	// The module finalization code
-	module_main_t		*main_func; // The main function (for executable modules)
+	module_main_t		main_func; // The main function (for executable modules)
 
 
 	void				*module_addr; // The module location in the memory
@@ -175,9 +175,6 @@ struct module_dep {
 #define MODULE_EXIT(fn) static module_exit_t __module_exit \
 	__used __attribute__((section(".dtors_modexit")))  = fn
 
-#define MODULE_MAIN(fn) static module_main_t __module_main \
-	__used __attribute__((section(".ctors_modmain")))  = fn
-
 #else
 
 /*
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 4bc5d94..afb5b64 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -388,7 +388,7 @@ static int resolve_symbols(struct elf_module *module) {
 static int extract_operations(struct elf_module *module) {
 	Elf32_Sym *init_sym = module_find_symbol(MODULE_ELF_INIT_PTR, module);
 	Elf32_Sym *exit_sym = module_find_symbol(MODULE_ELF_EXIT_PTR, module);
-	Elf32_Sym *main_sym = module_find_symbol(MODULE_ELF_MAIN_PTR, module);
+	Elf32_Sym *main_sym = module_find_symbol("main", module);
 
 	if (init_sym == NULL) {
 		DBG_PRINT("Cannot find initialization routine pointer.\n");
@@ -400,11 +400,6 @@ static int extract_operations(struct elf_module *module) {
 		printf("Cannot find exit routine pointer.\n");
 		return -1;
 	}
-	if (main_sym == NULL) {
-		DBG_PRINT("Cannot find main routine pointer.\n");
-		printf("Cannot find main routine pointer.\n");
-		return -1;
-	}
 
 	module->init_func = (module_init_t*)module_get_absolute(
 								init_sym->st_value, module);
@@ -418,12 +413,9 @@ static int extract_operations(struct elf_module *module) {
 		module->exit_func = NULL;
 	}
 
-	module->main_func = (module_main_t*)module_get_absolute(
-								main_sym->st_value, module);
-	if (*(module->main_func) == NULL) {
-		module->main_func = NULL;
-	}
-
+	if (main_sym)
+		module->main_func =
+			module_get_absolute(main_sym->st_value, module);
 
 	return 0;
 }
diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index fbe165d..78df72e 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -188,7 +188,7 @@ int spawnv(const char *name, const char **argv)
 	else if (!module->main_func)
 		ret_val = -1;
 	else
-		exit((*module->main_func)(argc, args)); /* Actually run! */
+		exit((module->main_func)(argc, args)); /* Actually run! */
 
 	// Clean up the allocation context
 	__free_tagged(module);
@@ -246,8 +246,8 @@ int spawn_load(const char *name,const char **argv)
 		 * type EXEC_MODULE, then just return. We don't reload
 		 * the module because that might cause us to re-run
 		 * the init functions, which will cause us to run the
-		 * MODULE_MAIN function, which will take control of
-		 * this process.
+		 * main function, which will take control of this
+		 * process.
 		 *
 		 * This can happen if some other EXEC_MODULE is
 		 * resolving a symbol that is exported by the current
@@ -318,7 +318,7 @@ int spawn_load(const char *name,const char **argv)
 		else if (!module->main_func)
 			ret_val = -1;
 		else
-			exit((*module->main_func)(argc, args)); /* Actually run! */
+			exit((module->main_func)(argc, args)); /* Actually run! */
 
 
 		// Clean up the allocation context



More information about the Syslinux-commits mailing list