From: John Hodge Date: Sat, 27 Nov 2010 05:29:36 +0000 (+0800) Subject: Usermode build system overhaul X-Git-Tag: rel0.07~48 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=cb8ee714fcb4fce504fd767462789093a9fecbb1;p=tpg%2Facess2.git Usermode build system overhaul - All usermode binaries now go to Usermode/Output//[Libs,Bin,SBin] - Moved almost all individual Makefiles over to using ../Makefile.tpl - Fixed compile warnings - Deleted un-needed libacess.so and old ld-acess.so sources (they're in git if I need them) --- diff --git a/Makefile b/Makefile index f67dd3cd..2a7f1a95 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,9 @@ AI_USRAPPS := $(addprefix allinstall-,$(USRAPPS)) kmode: $(AI_MODULES) $(AI_DYNMODS) allinstall-Kernel +all-user: $(ALL_USRLIBS) $(ALL_USRAPPS) +clean-user: $(CLEAN_USRLIBS) $(CLEAN_USRAPPS) + all: $(ALL_DYNMODS) $(ALL_MODULES) all-Kernel $(ALL_USRLIBS) $(ALL_USRAPPS) all-install: $(AI_DYNMODS) $(AI_MODULES) allinstall-Kernel $(AI_USRLIBS) $(AI_USRAPPS) clean: $(CLEAN_DYNMODS) $(CLEAN_MODULES) clean-Kernel $(CLEAN_USRLIBS) $(CLEAN_USRAPPS) diff --git a/Usermode/Applications/CLIShell_src/Makefile b/Usermode/Applications/CLIShell_src/Makefile index ef770485..e500edd2 100644 --- a/Usermode/Applications/CLIShell_src/Makefile +++ b/Usermode/Applications/CLIShell_src/Makefile @@ -3,9 +3,9 @@ -include ../Makefile.cfg CPPFLAGS += -I./include -LDFLAGS += -lreadline +LDFLAGS += -lreadline -BIN = ../CLIShell +BIN = CLIShell OBJ = main.o lib.o -include ../Makefile.tpl diff --git a/Usermode/Applications/Makefile.cfg b/Usermode/Applications/Makefile.cfg index bc33f905..6b946969 100644 --- a/Usermode/Applications/Makefile.cfg +++ b/Usermode/Applications/Makefile.cfg @@ -1,15 +1,18 @@ # Acess 2 Applications # General Makefile --include ../../../Makefile.cfg +#-include ../../../Makefile.cfg # satisfying 2 deep applications -ifeq ($(ACESSDIR),) - -include ../../../../Makefile.cfg -endif -ACESSUSERDIR := $(ACESSDIR)/Usermode +#ifeq ($(ACESSDIR),) +# -include ../../../../Makefile.cfg +#endif + +# Include Usermode Makefile.cfg +include $(dir $(lastword $(MAKEFILE_LIST)))../Makefile.cfg + ASFLAGS = -felf CPPFLAGS = -I$(ACESSUSERDIR)/include/ CFLAGS = -fno-stack-protector $(CPPFLAGS) -LDFLAGS = -T $(ACESSUSERDIR)/Libraries/acess.ld -L $(ACESSUSERDIR)/Libraries -I /Acess/Libs/ld-acess.so -lc +LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lc DIR = Bin diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index b82e7ac1..adbc80ad 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -1,5 +1,6 @@ -# Acess2 - Application Template Makefile # +# Acess2 +# - Application Template Makefile # CFLAGS += -Wall -Werror -fno-builtin -fno-stack-protector -g @@ -7,24 +8,27 @@ LDFLAGS += DEPFILES := $(OBJ:%.o=%.d) +_BIN := $(OUTPUTDIR)$(DIR)/$(BIN) + .PHONY : all clean install -all: $(BIN) +all: $(_BIN) clean: - @$(RM) $(OBJ) $(DEPFILES) $(BIN) $(BIN).dsm Map.txt + @$(RM) $(OBJ) $(DEPFILES) $(_BIN) $(BIN).dsm Map.txt install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/$(DIR)/ + $(xCP) $(_BIN) $(DISTROOT)/$(DIR)/ -$(BIN): $(OBJ) +$(_BIN): $(OBJ) + @mkdir -p $(dir $(_BIN)) @echo --- $(LD) -o $@ ifneq ($(_DBGMAKEFILE),) $(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map Map.txt else @$(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map Map.txt endif - @objdump -d -S $(BIN) > $(BIN).dsm + @objdump -d -S $(_BIN) > $(BIN).dsm $(OBJ): %.o: %.c @echo --- GCC -o $@ diff --git a/Usermode/Applications/MultibootCheck_src/Makefile b/Usermode/Applications/MultibootCheck_src/Makefile index ac0dc415..cad02733 100644 --- a/Usermode/Applications/MultibootCheck_src/Makefile +++ b/Usermode/Applications/MultibootCheck_src/Makefile @@ -1,8 +1,8 @@ -# Project: Multiboot Check - --include ../Makefile.cfg - +# Project: Multiboot Check + +-include ../Makefile.cfg + OBJ = MultibootCheck.o -BIN = ../MultibootCheck - --include ../Makefile.tpl +BIN = MultibootCheck + +-include ../Makefile.tpl diff --git a/Usermode/Applications/bomb_src/Makefile b/Usermode/Applications/bomb_src/Makefile index b4483c02..76635f2a 100644 --- a/Usermode/Applications/bomb_src/Makefile +++ b/Usermode/Applications/bomb_src/Makefile @@ -3,7 +3,7 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../bomb +BIN = bomb -include ../Makefile.tpl diff --git a/Usermode/Applications/cat_src/Makefile b/Usermode/Applications/cat_src/Makefile index 9c968f43..a384b008 100644 --- a/Usermode/Applications/cat_src/Makefile +++ b/Usermode/Applications/cat_src/Makefile @@ -3,7 +3,7 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../cat +BIN = cat -include ../Makefile.tpl diff --git a/Usermode/Applications/cpuid_src/Makefile b/Usermode/Applications/cpuid_src/Makefile index 66739a88..b60d6b17 100644 --- a/Usermode/Applications/cpuid_src/Makefile +++ b/Usermode/Applications/cpuid_src/Makefile @@ -1,8 +1,8 @@ -# Project: cpuid - --include ../Makefile.cfg - +# Project: cpuid + +-include ../Makefile.cfg + OBJ = main.o -BIN = ../cpuid - --include ../Makefile.tpl +BIN = cpuid + +-include ../Makefile.tpl diff --git a/Usermode/Applications/ifconfig_src/Makefile b/Usermode/Applications/ifconfig_src/Makefile index c742c250..e914e2b6 100644 --- a/Usermode/Applications/ifconfig_src/Makefile +++ b/Usermode/Applications/ifconfig_src/Makefile @@ -1,11 +1,11 @@ -# Project: ifconfig - --include ../Makefile.cfg - -LDFLAGS += -lnet - +# Project: ifconfig + +-include ../Makefile.cfg + +LDFLAGS += -lnet + OBJ = main.o -BIN = ../ifconfig - +BIN = ifconfig + -include ../Makefile.tpl - + diff --git a/Usermode/Applications/init_src/Makefile b/Usermode/Applications/init_src/Makefile index 94aebd11..c8a6ddb5 100644 --- a/Usermode/Applications/init_src/Makefile +++ b/Usermode/Applications/init_src/Makefile @@ -7,7 +7,7 @@ CFLAGS += -Wall -Werror -O3 LDFLAGS += # -lspiderscript -BIN = ../init +BIN = init OBJ = main.o DIR = SBin diff --git a/Usermode/Applications/irc_src/Makefile b/Usermode/Applications/irc_src/Makefile index b51ed6af..5103870f 100644 --- a/Usermode/Applications/irc_src/Makefile +++ b/Usermode/Applications/irc_src/Makefile @@ -5,6 +5,6 @@ LDFLAGS += -lnet OBJ = main.o -BIN = ../irc +BIN = irc -include ../Makefile.tpl diff --git a/Usermode/Applications/login_src/Makefile b/Usermode/Applications/login_src/Makefile index 63909f64..9261791f 100644 --- a/Usermode/Applications/login_src/Makefile +++ b/Usermode/Applications/login_src/Makefile @@ -5,7 +5,7 @@ DBTYPE = tpl OBJ = main.o database_$(DBTYPE).o -BIN = ../login +BIN = login DIR = SBin -include ../Makefile.tpl diff --git a/Usermode/Applications/ls_src/Makefile b/Usermode/Applications/ls_src/Makefile index 0ea66db4..070bcb33 100644 --- a/Usermode/Applications/ls_src/Makefile +++ b/Usermode/Applications/ls_src/Makefile @@ -3,6 +3,6 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../ls +BIN = ls -include ../Makefile.tpl diff --git a/Usermode/Applications/mount_src/Makefile b/Usermode/Applications/mount_src/Makefile index 842de666..0702e451 100644 --- a/Usermode/Applications/mount_src/Makefile +++ b/Usermode/Applications/mount_src/Makefile @@ -3,7 +3,7 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../mount +BIN = mount -include ../Makefile.tpl diff --git a/Usermode/Applications/pcidump_src/Makefile b/Usermode/Applications/pcidump_src/Makefile index 7f32b994..e872ddc8 100644 --- a/Usermode/Applications/pcidump_src/Makefile +++ b/Usermode/Applications/pcidump_src/Makefile @@ -3,6 +3,6 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../pcidump +BIN = pcidump -include ../Makefile.tpl diff --git a/Usermode/Applications/ping_src/Makefile b/Usermode/Applications/ping_src/Makefile index 4d44a338..64c4649e 100644 --- a/Usermode/Applications/ping_src/Makefile +++ b/Usermode/Applications/ping_src/Makefile @@ -5,7 +5,7 @@ LDFLAGS += -lnet OBJ = main.o -BIN = ../ping +BIN = ping -include ../Makefile.tpl diff --git a/Usermode/Applications/testclient_src/Makefile b/Usermode/Applications/testclient_src/Makefile index 33526835..ae6b8235 100644 --- a/Usermode/Applications/testclient_src/Makefile +++ b/Usermode/Applications/testclient_src/Makefile @@ -1,9 +1,9 @@ -# Project: testclient +# Project: Test TCP Client Application (testclient) -include ../Makefile.cfg OBJ = main.o -BIN = ../testclient +BIN = testclient -include ../Makefile.tpl diff --git a/Usermode/Applications/testserver_src/Makefile b/Usermode/Applications/testserver_src/Makefile index 5b6d2554..94aa7f06 100644 --- a/Usermode/Applications/testserver_src/Makefile +++ b/Usermode/Applications/testserver_src/Makefile @@ -3,7 +3,7 @@ -include ../Makefile.cfg OBJ = main.o -BIN = ../testsrv +BIN = testsrv -include ../Makefile.tpl diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index 159ab1ef..9b1dd91f 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -1,11 +1,11 @@ # Acess 2 Libraries # General Makefile --include ../../../Makefile.cfg +-include $(dir $(lastword $(MAKEFILE_LIST)))../Makefile.cfg MAKEDEP = $(CC) -M -ASFLAGS = -felf -CPPFLAGS = -I$(ACESSDIR)/Usermode/include/ -CFLAGS = -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS) -LDFLAGS = -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L.. +ASFLAGS := -felf +CPPFLAGS := -I$(ACESSDIR)/Usermode/include/ +CFLAGS := -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS) +LDFLAGS := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L$(OUTPUTDIR)Libs/ diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index eedd9d33..5f736327 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -1,26 +1,35 @@ -# Acess 2 SQLite 3 Library +# Acess2 +# - Library Common Makefile # -DEPFILES := $(OBJ:%.o=%.d) +DEPFILES := $(addsuffix .d,$(OBJ)) + +_BIN := $(OUTPUTDIR)Libs/$(BIN) .PHONY: all clean install -all: $(BIN) +all: $(_BIN) clean: - $(RM) $(BIN) $(OBJ) $(BIN).dsm + $(RM) $(_BIN) $(OBJ) $(_BIN).dsm $(DEPFILES) -install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Libs/ +install: $(_BIN) + $(xCP) $(_BIN) $(DISTROOT)/Libs/ -$(BIN): $(OBJ) +$(_BIN): $(OBJ) + @mkdir -p $(dir $(_BIN)) @echo [LD] -o $(BIN) $(OBJ) - @$(LD) $(LDFLAGS) -o $(BIN) $(OBJ) - @$(OBJDUMP) -d -S $(BIN) > $(BIN).dsm + @$(LD) $(LDFLAGS) -o $(_BIN) $(OBJ) + @$(OBJDUMP) -d -S $(_BIN) > $(_BIN).dsm %.o: %.c @echo [CC] -o $@ @$(CC) $(CFLAGS) -o $@ -c $< - @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $*.d + @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $@.d + +%.ao: %.asm + @echo [AS] -o $@ + @$(AS) $(ASFLAGS) -o $@ $< + @$(AS) $(ASFLAGS) -o $@ $< -M > $@.d -include $(DEPFILES) diff --git a/Usermode/Libraries/acess.ld_src/Makefile b/Usermode/Libraries/acess.ld_src/Makefile index fa819fa8..57a9cd9f 100644 --- a/Usermode/Libraries/acess.ld_src/Makefile +++ b/Usermode/Libraries/acess.ld_src/Makefile @@ -1,16 +1,22 @@ +# +# Acess2 +# - Common usermode linker script +# + -include ../Makefile.cfg -BIN = ../acess.ld +BIN = $(OUTPUTDIR)Libs/acess.ld .PHONY: all clean install -all: ../acess.ld +all: $(BIN) clean: - $(RM) ../acess.ld + $(RM) $(BIN) -install: ../acess.ld +install: $(BIN) -../acess.ld: acess.ld.h - cpp -nostdinc -U i386 -P -C $< -o $@ -D__LIBDIR=$(ACESSDIR)/Usermode/Libraries +$(BIN): acess.ld.h + @mkdir -p $(dir $(BIN)) + cpp -nostdinc -U i386 -P -C $< -o $@ -D__LIBDIR=$(OUTPUTDIR)Libs diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index d15f271f..62d04ed5 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -5,15 +5,16 @@ -include ../Makefile.cfg ASFLAGS = -felf +BIN = $(OUTPUTDIR)Libs/crt0.o .PHONY: all clean install -all: ../crt0.o +all: $(BIN) -install: ../crt0.o +install: $(BIN) clean: - $(RM) ../crt0.o + $(RM) $(BIN) -../crt0.o: crt0.asm +$(BIN): crt0.$(ARCHDIR).asm $(AS) $(ASFLAGS) $< -o $@ diff --git a/Usermode/Libraries/crt0.o_src/crt0.x86.asm b/Usermode/Libraries/crt0.o_src/crt0.x86.asm new file mode 120000 index 00000000..084206aa --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/crt0.x86.asm @@ -0,0 +1 @@ +crt0.asm \ No newline at end of file diff --git a/Usermode/Libraries/ld-acess.old.so_src/Makefile b/Usermode/Libraries/ld-acess.old.so_src/Makefile deleted file mode 100644 index 7c3a4b8c..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Acess Dynamic Linker (ELF) Version 1 -# LD-ACESS.SO -# Makefile - --include ../Makefile.cfg - -COBJ = main.o lib.o loadlib.o elf.o pe.o -AOBJ = helpers.ao -BIN = ../ld-acess.so - -CFLAGS = -Wall -fno-builtin -fleading-underscore -fno-stack-protector -ASFLAGS = -felf -LDFLAGS = -T link.ld -Map map.txt -Bstatic - - -.PHONY: all clean install - -all: $(BIN) - -clean: - $(RM) $(BIN) $(AOBJ) $(COBJ) ld-acess.dmp ld-acess.dsm link.txt map.txt - -install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Libs/ - -$(BIN): $(AOBJ) $(COBJ) - @echo --- $(LD) -shared -o $@ - @$(LD) $(LDFLAGS) -o $(BIN) $(AOBJ) $(COBJ) > link.txt - $(OBJDUMP) -x $(BIN) > ld-acess.dmp - $(OBJDUMP) -d $(BIN) > ld-acess.dsm - -$(COBJ): %.o: %.c - @echo $(CC) -o $@ - @$(CC) $(CFLAGS) -o $@ -c $< - -$(AOBJ): %.ao: %.asm - @echo $(AS) -o $@ - @$(AS) $(ASFLAGS) -o $@ $< - diff --git a/Usermode/Libraries/ld-acess.old.so_src/common.h b/Usermode/Libraries/ld-acess.old.so_src/common.h deleted file mode 100644 index 81913d50..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/common.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - AcessOS v1 - By thePowersGang - ld-acess.so - COMMON.H -*/ -#ifndef _COMMON_H -#define _COMMON_H - -#define NULL ((void*)0) - -#include - -// === CONSTANTS === -#define MAX_LOADED_LIBRARIES 64 -#define MAX_STRINGS_BYTES 4096 -#define SYSTEM_LIB_DIR "/Acess/Libs/" - -// === Types === -typedef unsigned int Uint; -typedef unsigned char Uint8; -typedef unsigned short Uint16; -typedef unsigned long Uint32; -typedef signed char Sint8; -typedef signed short Sint16; -typedef signed long Sint32; - -typedef struct { - Uint Base; - char *Name; -} tLoadedLib; - -// === GLOBALS === -extern tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES]; - -// === Main === -extern int DoRelocate( Uint base, char **envp, char *Filename ); - -// === Library/Symbol Manipulation == -extern Uint LoadLibrary(char *filename, char *SearchDir, char **envp); -extern void AddLoaded(char *File, Uint base); -extern Uint GetSymbol(char *name); -extern int GetSymbolFromBase(Uint base, char *name, Uint *ret); - -// === Library Functions === -extern char *strcpy(char *dest, const char *src); -extern char *strcat(char *dest, const char *src); -extern int strcmp(const char *s1, const char *s2); -extern int strlen(const char *str); -extern int file_exists(char *filename); - -// === System Calls === -extern void SysExit(); -extern void SysDebug(char *fmt, ...); //!< Now implemented in main.c -extern void SysDebugV(char *fmt, ...); -extern Uint SysLoadBin(char *path, Uint *entry); -extern Uint SysUnloadBin(Uint Base); -extern void SysSetFaultHandler(int (*Hanlder)(int)); -extern int open(char *filename, int flags); -extern void close(int fd); - -// === ELF Loader === -extern int ElfGetSymbol(Uint Base, char *name, Uint *ret); - -// === PE Loader === -extern int PE_GetSymbol(Uint Base, char *Name, Uint *ret); - -#endif diff --git a/Usermode/Libraries/ld-acess.old.so_src/elf.c b/Usermode/Libraries/ld-acess.old.so_src/elf.c deleted file mode 100644 index e1fcd2d4..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/elf.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * AcessOS 1 - Dynamic Loader - * By thePowersGang - */ -#include "common.h" -#include "elf32.h" - -#define DEBUG 0 - -#if DEBUG -# define DEBUGS(v...) SysDebug(v) -#else -# define DEBUGS(...) -#endif - -// === CONSTANTS === -#if DEBUG -//static const char *csaDT_NAMES[] = {"DT_NULL", "DT_NEEDED", "DT_PLTRELSZ", "DT_PLTGOT", "DT_HASH", "DT_STRTAB", "DT_SYMTAB", "DT_RELA", "DT_RELASZ", "DT_RELAENT", "DT_STRSZ", "DT_SYMENT", "DT_INIT", "DT_FINI", "DT_SONAME", "DT_RPATH", "DT_SYMBOLIC", "DT_REL", "DT_RELSZ", "DT_RELENT", "DT_PLTREL", "DT_DEBUG", "DT_TEXTREL", "DT_JMPREL"}; -static const char *csaR_NAMES[] = {"R_386_NONE", "R_386_32", "R_386_PC32", "R_386_GOT32", "R_386_PLT32", "R_386_COPY", "R_386_GLOB_DAT", "R_386_JMP_SLOT", "R_386_RELATIVE", "R_386_GOTOFF", "R_386_GOTPC", "R_386_LAST"}; -#endif - -// === PROTOTYPES === -void elf_doRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base); -Uint ElfHashString(char *name); - -// === CODE === -/** - \fn int ElfRelocate(void *Base, char **envp, char *Filename) - \brief Relocates a loaded ELF Executable -*/ -int ElfRelocate(void *Base, char **envp, char *Filename) -{ - Elf32_Ehdr *hdr = Base; - Elf32_Phdr *phtab; - int i, j; // Counters - char *libPath; - Uint iRealBase = -1; - Uint iBaseDiff; - int iSegmentCount; - int iSymCount; - Elf32_Rel *rel = NULL; - Elf32_Rela *rela = NULL; - Uint32 *pltgot = NULL; - void *plt = NULL; - int relSz=0, relEntSz=8; - int relaSz=0, relaEntSz=8; - int pltSz=0, pltType=0; - Elf32_Dyn *dynamicTab = NULL; // Dynamic Table Pointer - char *dynstrtab = NULL; // .dynamic String Table - Elf32_Sym *dynsymtab; - - DEBUGS("ElfRelocate: (Base=0x%x)\n", Base); - - // Check magic header - - - // Parse Program Header to get Dynamic Table - phtab = Base + hdr->phoff; - iSegmentCount = hdr->phentcount; - for(i=0;i phtab[i].VAddr) - iRealBase = phtab[i].VAddr; - - // Find Dynamic Section - if(phtab[i].Type == PT_DYNAMIC) { - if(dynamicTab) { - DEBUGS(" WARNING - elf_relocate: Multiple PT_DYNAMIC segments\n"); - continue; - } - dynamicTab = (void *) phtab[i].VAddr; - j = i; // Save Dynamic Table ID - } - } - - // Page Align real base - iRealBase &= ~0xFFF; - DEBUGS(" elf_relocate: True Base = 0x%x, Compiled Base = 0x%x\n", Base, iRealBase); - - // Adjust "Real" Base - iBaseDiff = (Uint)Base - iRealBase; - - hdr->entrypoint += iBaseDiff; // Adjust Entrypoint - - // Check if a PT_DYNAMIC segement was found - if(!dynamicTab) { - SysDebug(" elf_relocate: No PT_DYNAMIC segment in image, returning\n"); - return hdr->entrypoint; - } - - // Adjust Dynamic Table - dynamicTab = (void *) ((Uint)dynamicTab + iBaseDiff); - - // === Get Symbol table and String Table === - for( j = 0; dynamicTab[j].d_tag != DT_NULL; j++) - { - switch(dynamicTab[j].d_tag) - { - // --- Symbol Table --- - case DT_SYMTAB: - DEBUGS(" elf_relocate: DYNAMIC Symbol Table 0x%x (0x%x)\n", - dynamicTab[j].d_val, dynamicTab[j].d_val + iBaseDiff); - dynamicTab[j].d_val += iBaseDiff; - dynsymtab = (void*)(dynamicTab[j].d_val); - hdr->misc.SymTable = dynamicTab[j].d_val; // Saved in unused bytes of ident - break; - // --- String Table --- - case DT_STRTAB: - DEBUGS(" elf_relocate: DYNAMIC String Table 0x%x (0x%x)\n", - dynamicTab[j].d_val, dynamicTab[j].d_val + iBaseDiff); - dynamicTab[j].d_val += iBaseDiff; - dynstrtab = (void*)(dynamicTab[j].d_val); - break; - // --- Hash Table -- - case DT_HASH: - dynamicTab[j].d_val += iBaseDiff; - iSymCount = ((Uint*)(dynamicTab[j].d_val))[1]; - hdr->misc.HashTable = dynamicTab[j].d_val; // Saved in unused bytes of ident - break; - } - } - - if(dynsymtab == NULL) { - SysDebug("ld-acess.so - WARNING: No Dynamic Symbol table, returning\n"); - return hdr->entrypoint; - } - - // Alter Symbols to true base - for(i=0;i DT_JMPREL) continue; - //DEBUGS(" elf_relocate: %i-%i = %s,0x%x\n", - // i,j, csaDT_NAMES[dynamicTab[j].d_tag],dynamicTab[j].d_val); - break; - } - } - - DEBUGS(" elf_relocate: Beginning Relocation\n"); - - // Parse Relocation Entries - if(rel && relSz) - { - Uint32 *ptr; - DEBUGS(" elf_relocate: rel=0x%x, relSz=0x%x, relEntSz=0x%x\n", rel, relSz, relEntSz); - j = relSz / relEntSz; - for( i = 0; i < j; i++ ) - { - //DEBUGS(" Rel %i: 0x%x+0x%x\n", i, iBaseDiff, rel[i].r_offset); - ptr = (void*)(iBaseDiff + rel[i].r_offset); - elf_doRelocate(rel[i].r_info, ptr, *ptr, dynsymtab, iBaseDiff); - } - } - // Parse Relocation Entries - if(rela && relaSz) - { - Uint32 *ptr; - DEBUGS(" elf_relocate: rela=0x%x, relaSz=0x%x, relaEntSz=0x%x\n", rela, relaSz, relaEntSz); - j = relaSz / relaEntSz; - for( i = 0; i < j; i++ ) - { - ptr = (void*)(iBaseDiff + rela[i].r_offset); - elf_doRelocate(rel[i].r_info, ptr, rela[i].r_addend, dynsymtab, iBaseDiff); - } - } - - // === Process PLT (Procedure Linkage Table) === - if(plt && pltSz) - { - Uint32 *ptr; - DEBUGS(" elf_relocate: Relocate PLT, plt=0x%x\n", plt); - if(pltType == DT_REL) - { - Elf32_Rel *pltRel = plt; - j = pltSz / sizeof(Elf32_Rel); - DEBUGS(" elf_relocate: PLT Reloc Type = Rel, %i entries\n", j); - for(i=0;ientrypoint); - return hdr->entrypoint; -} - -void elf_doRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base) -{ - int type = ELF32_R_TYPE(r_info); - int sym = ELF32_R_SYM(r_info); - Uint32 val; - switch( type ) - { - // Standard 32 Bit Relocation (S+A) - case R_386_32: - val = GetSymbol( symtab[sym].name ); - DEBUGS(" elf_doRelocate: R_386_32 *0x%x += 0x%x('%s')\n", - ptr, val, symtab[sym].name); - *ptr = val + addend; - break; - - // 32 Bit Relocation wrt. Offset (S+A-P) - case R_386_PC32: - DEBUGS(" elf_doRelocate: #%i: '%s'\n", sym, symtab[sym].name); - val = GetSymbol( symtab[sym].name ); - DEBUGS(" elf_doRelocate: R_386_PC32 *0x%x = 0x%x + 0x%x - 0x%x\n", - ptr, *ptr, val, (Uint)ptr ); - *ptr = val + addend - (Uint)ptr; - //*ptr = val + addend - ((Uint)ptr - base); - break; - - // Absolute Value of a symbol (S) - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - DEBUGS(" elf_doRelocate: #%i: '%s'\n", sym, symtab[sym].name); - val = GetSymbol( symtab[sym].name ); - DEBUGS(" elf_doRelocate: %s *0x%x = 0x%x\n", csaR_NAMES[type], ptr, val); - *ptr = val; - break; - - // Base Address (B+A) - case R_386_RELATIVE: - DEBUGS(" elf_doRelocate: R_386_RELATIVE *0x%x = 0x%x + 0x%x\n", ptr, base, addend); - *ptr = base + addend; - break; - - default: - DEBUGS(" elf_doRelocate: Rel 0x%x: 0x%x,%s\n", ptr, sym, csaR_NAMES[type]); - break; - } - -} - -/** - * \fn int ElfGetSymbol(Uint Base, char *name, Uint *ret) - */ -int ElfGetSymbol(Uint Base, char *Name, Uint *ret) -{ - Elf32_Ehdr *hdr = (void*)Base; - Elf32_Sym *symtab; - int nbuckets = 0; - int iSymCount = 0; - int i; - Uint *pBuckets; - Uint *pChains; - Uint iNameHash; - - //DEBUGS("ElfGetSymbol: (Base=0x%x, Name='%s')\n", Base, Name); - - pBuckets = (void *) hdr->misc.HashTable; - symtab = (void *) hdr->misc.SymTable; - - nbuckets = pBuckets[0]; - iSymCount = pBuckets[1]; - pBuckets = &pBuckets[2]; - pChains = &pBuckets[ nbuckets ]; - - // Get hash - iNameHash = ElfHashString(Name); - iNameHash %= nbuckets; - //DEBUGS(" ElfGetSymbol: iNameHash = 0x%x\n", iNameHash); - - // Walk Chain - i = pBuckets[ iNameHash ]; - //DEBUGS(" ElfGetSymbol: strcmp(Name, \"%s\")\n", symtab[i].name); - if(symtab[i].shndx != SHN_UNDEF && strcmp(symtab[i].name, Name) == 0) { - *ret = symtab[ i ].value; - return 1; - } - - //DEBUGS(" ElfGetSymbol: Hash of first = 0x%x\n", ElfHashString( symtab[i].name ) % nbuckets); - while(pChains[i] != STN_UNDEF) - { - //DEBUGS(" pChains[%i] = %i\n", i, pChains[i]); - i = pChains[i]; - //DEBUGS(" ElfGetSymbol: strcmp(Name, \"%s\")\n", symtab[ i ].name); - if(symtab[i].shndx != SHN_UNDEF && strcmp(symtab[ i ].name, Name) == 0) { - //DEBUGS("ElfGetSymbol: RETURN 1, '%s' = 0x%x\n", symtab[ i ].name, symtab[ i ].value); - *ret = symtab[ i ].value; - return 1; - } - } - - //DEBUGS("ElfGetSymbol: RETURN 0, Symbol '%s' not found\n", Name); - return 0; -} - -Uint ElfHashString(char *name) -{ - Uint h = 0, g; - while(*name) - { - h = (h << 4) + *name++; - if( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - } - return h; -} - -#if 0 -unsigned long elf_hash(const unsigned char *name) -{ - unsigned long h = 0, g; - while (*name) - { - h = (h << 4) + *name++; - if (g = h & 0xf0000000) - h ^= g >> 24; - h &= ~g; - } - return h; -} -#endif diff --git a/Usermode/Libraries/ld-acess.old.so_src/elf32.h b/Usermode/Libraries/ld-acess.old.so_src/elf32.h deleted file mode 100644 index eededf4e..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/elf32.h +++ /dev/null @@ -1,215 +0,0 @@ -/** - Acess v1 - \file elf32.h - \brief ELF Exeutable Loader -*/ -#ifndef _ELF32_H -#define _ELF32_H - -/** - \struct elf_header_s - \brief ELF File Header -*/ -struct sElf32_Ehdr { - union { - char ident[16]; //!< Identifier Bytes - struct { - Uint Ident1; - Uint Ident2; - Uint HashTable; - Uint SymTable; - } misc; - }; - Uint16 filetype; //!< File Type - Uint16 machine; //!< Machine / Arch - Uint32 version; //!< Version (File?) - Uint32 entrypoint; //!< Entry Point - Uint32 phoff; //!< Program Header Offset - Uint32 shoff; //!< Section Header Offset - Uint32 flags; //!< Flags - Uint16 headersize; //!< Header Size - Uint16 phentsize; //!< Program Header Entry Size - Uint16 phentcount; //!< Program Header Entry Count - Uint16 shentsize; //!< Section Header Entry Size - Uint16 shentcount; //!< Section Header Entry Count - Uint16 shstrindex; //!< Section Header String Table Index -}; - -/** - \name Executable Types - \{ -*/ -#define ET_NONE 0 //!< NULL Type -#define ET_REL 1 //!< Relocatable (Object) -#define ET_EXEC 2 //!< Executable -#define ET_DYN 3 //!< Dynamic Library -#define ET_CORE 4 //!< Core? -#define ET_LOPROC 0xFF00 //!< Low Impl Defined -#define ET_HIPROC 0xFFFF //!< High Impl Defined -//! \} - -/** - \name Section IDs - \{ -*/ -#define SHN_UNDEF 0 //!< Undefined Section -#define SHN_LORESERVE 0xFF00 //!< Low Reserved -#define SHN_LOPROC 0xFF00 //!< Low Impl Defined -#define SHN_HIPROC 0xFF1F //!< High Impl Defined -#define SHN_ABS 0xFFF1 //!< Absolute Address (Base: 0, Size: -1) -#define SHN_COMMON 0xFFF2 //!< Common -#define SHN_HIRESERVE 0xFFFF //!< High Reserved -//! \} - -/** - \enum eElfSectionTypes - \brief ELF Section Types -*/ -enum eElfSectionTypes { - SHT_NULL, //0 - SHT_PROGBITS, //1 - SHT_SYMTAB, //2 - SHT_STRTAB, //3 - SHT_RELA, //4 - SHT_HASH, //5 - SHT_DYNAMIC, //6 - SHT_NOTE, //7 - SHT_NOBITS, //8 - SHT_REL, //9 - SHT_SHLIB, //A - SHT_DYNSYM, //B - SHT_LAST, //C - SHT_LOPROC = 0x70000000, - SHT_HIPROC = 0x7fffffff, - SHT_LOUSER = 0x80000000, - SHT_HIUSER = 0xffffffff -}; - -#define SHF_WRITE 0x1 -#define SHF_ALLOC 0x2 -#define SHF_EXECINSTR 0x4 -#define SHF_MASKPROC 0xf0000000 - -struct sElf32_Shent { - Uint32 name; - Uint32 type; - Uint32 flags; - Uint32 address; - Uint32 offset; - Uint32 size; - Uint32 link; - Uint32 info; - Uint32 addralign; - Uint32 entsize; -}; //sizeof = 40 - -struct elf_sym_s { - union { - Uint32 nameOfs; - char *name; - }; - Uint32 value; //Address - Uint32 size; - Uint8 info; - Uint8 other; - Uint16 shndx; -}; -#define STN_UNDEF 0 // Undefined Symbol - -enum { - PT_NULL, //0 - PT_LOAD, //1 - PT_DYNAMIC, //2 - PT_INTERP, //3 - PT_NOTE, //4 - PT_SHLIB, //5 - PT_PHDR, //6 - PT_LOPROC = 0x70000000, - PT_HIPROC = 0x7fffffff -}; - -struct sElf32_Phdr { - Uint32 Type; - Uint Offset; - Uint VAddr; - Uint PAddr; - Uint32 FileSize; - Uint32 MemSize; - Uint32 Flags; - Uint32 Align; -}; - -struct elf32_rel_s { - Uint32 r_offset; - Uint32 r_info; -}; - -struct elf32_rela_s { - Uint32 r_offset; - Uint32 r_info; - Sint32 r_addend; -}; - -enum { - R_386_NONE=0, // none - R_386_32, // S+A - R_386_PC32, // S+A-P - R_386_GOT32, // G+A-P - R_386_PLT32, // L+A-P - R_386_COPY, // none - R_386_GLOB_DAT, // S - R_386_JMP_SLOT, // S - R_386_RELATIVE, // B+A - R_386_GOTOFF, // S+A-GOT - R_386_GOTPC, // GOT+A-P - R_386_LAST // none -}; - -#define ELF32_R_SYM(i) ((i)>>8) // Takes an info value and returns a symbol index -#define ELF32_R_TYPE(i) ((i)&0xFF) // Takes an info value and returns a type -#define ELF32_R_INFO(s,t) (((s)<<8)+((t)&0xFF)) // Takes a type and symbol index and returns an info value - -struct elf32_dyn_s { - Uint16 d_tag; - Uint32 d_val; //Also d_ptr -}; - -enum { - DT_NULL, //!< Marks End of list - DT_NEEDED, //!< Offset in strtab to needed library - DT_PLTRELSZ, //!< Size in bytes of PLT - DT_PLTGOT, //!< Address of PLT/GOT - DT_HASH, //!< Address of symbol hash table - DT_STRTAB, //!< String Table address - DT_SYMTAB, //!< Symbol Table address - DT_RELA, //!< Relocation table address - DT_RELASZ, //!< Size of relocation table - DT_RELAENT, //!< Size of entry in relocation table - DT_STRSZ, //!< Size of string table - DT_SYMENT, //!< Size of symbol table entry - DT_INIT, //!< Address of initialisation function - DT_FINI, //!< Address of termination function - DT_SONAME, //!< String table offset of so name - DT_RPATH, //!< String table offset of library path - DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable - DT_REL, //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela) - DT_RELSZ, //!< Size of above table (bytes) - DT_RELENT, //!< Size of entry in above table - DT_PLTREL, //!< Relocation entry of PLT - DT_DEBUG, //!< Debugging Entry - Unknown contents - DT_TEXTREL, //!< Indicates that modifcations to a non-writeable segment may occur - DT_JMPREL, //!< Address of PLT only relocation entries - DT_LOPROC = 0x70000000, //!< Low Definable - DT_HIPROC = 0x7FFFFFFF //!< High Definable -}; - -typedef struct sElf32_Ehdr Elf32_Ehdr; -typedef struct sElf32_Phdr Elf32_Phdr; -typedef struct sElf32_Shent Elf32_Shent; -typedef struct elf_sym_s elf_symtab; -typedef struct elf_sym_s Elf32_Sym; -typedef struct elf32_rel_s Elf32_Rel; -typedef struct elf32_rela_s Elf32_Rela; -typedef struct elf32_dyn_s Elf32_Dyn; - -#endif // defined(_EXE_ELF_H) diff --git a/Usermode/Libraries/ld-acess.old.so_src/helpers.asm b/Usermode/Libraries/ld-acess.old.so_src/helpers.asm deleted file mode 100644 index 49b9bd8a..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/helpers.asm +++ /dev/null @@ -1,88 +0,0 @@ -; AcessOS 1 -; By thePowersGang -; LD-ACESS.SO -; - helpers.asm - -%include "../libacess.so_src/syscalls.inc.asm" - -[global _SysDebug] -[global _SysExit] -[global _SysLoadBin] -[global _SysUnloadBin] -[global _SysSetFaultHandler] -[global _open] -[global _close] - -; void SysDebugV(char *fmt, va_list Args) -_SysDebug: - ;xchg bx, bx - push ebp - mov ebp, esp - pusha - - mov eax, 0x100 ; User Debug - mov ebx, [ebp+8] ; Format - mov ecx, [ebp+12] ; Arguments - mov edx, [ebp+16] ; Arguments - mov edi, [ebp+20] ; Arguments - mov esi, [ebp+24] ; Arguments - int 0xAC - - popa - pop ebp - ret - -; void SysExit() -_SysExit: - push ebx - mov eax, SYS_EXIT ; Exit - mov ebx, [esp+0x8] ; Exit Code - int 0xAC - pop ebx - ret - -; Uint SysLoadBin(char *path, Uint *entry) -_SysLoadBin: - push ebx - mov eax, SYS_LOADBIN ; SYS_LDBIN - mov ebx, [esp+0x8] ; Path - mov ecx, [esp+0xC] ; Entry - int 0xAC - pop ebx - ret - -; Uint SysUnloadBin(Uint Base) -_SysUnloadBin: - push ebx - mov eax, SYS_UNLOADBIN ; SYS_ULDBIN - mov ebx, [esp+0x8] ; Base - int 0xAC - pop ebx - ret - -; int close(char *name, int flags) -_open: - push ebx - mov eax, SYS_OPEN - mov ebx, [esp+0x8] ; Filename - mov ecx, [esp+0xC] ; Flags - int 0xAC - pop ebx - ret - -; void close(int fd) -_close: - push ebx - mov eax, SYS_CLOSE - mov ebx, [esp+0x8] ; File Descriptor - int 0xAC - pop ebx - ret - -_SysSetFaultHandler: - push ebx - mov eax, SYS_SETFAULTHANDLER - mov ebx, [esp+0x8] ; File Descriptor - int 0xAC - pop ebx - ret diff --git a/Usermode/Libraries/ld-acess.old.so_src/lib.c b/Usermode/Libraries/ld-acess.old.so_src/lib.c deleted file mode 100644 index 3acc129d..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/lib.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - AcessOS 1 - Dynamic Loader - By thePowersGang -*/ -#include "common.h" - -// === CODE === -char *strcpy(char *dest, const char *src) -{ - char *ret = dest; - while(*src) { - *dest = *src; - src ++; dest ++; - } - *dest = '\0'; - return ret; -} - -char *strcat(char *dest, const char *src) -{ - char *ret = dest; - while(*dest) dest++; - while(*src) *dest++ = *src++; - *dest = '\0'; - return ret; -} - -/** - * \fn int strcmp(const char *s1, const char *s2) - * \brief Compare two strings - */ -int strcmp(const char *s1, const char *s2) -{ - while(*s1 && *s1 == *s2) s1++,s2++; - return *s1-*s2; -} - -/** - * \fn int strlen(const char *str) - * \brief - */ -int strlen(const char *str) -{ - int len = 0; - while(*str) len++,str++; - return len; -} - -/** - * \fn int file_exists(char *filename) - * \brief Checks if a file exists - */ -int file_exists(char *filename) -{ - int fd; - //fd = open(filename, OPENFLAG_READ); - fd = open(filename, 0); - if(fd == -1) return 0; - close(fd); - return 1; -} diff --git a/Usermode/Libraries/ld-acess.old.so_src/link.ld b/Usermode/Libraries/ld-acess.old.so_src/link.ld deleted file mode 100644 index 8ddc2346..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/link.ld +++ /dev/null @@ -1,27 +0,0 @@ -ENTRY(_SoMain) -OUTPUT_FORMAT(elf32-i386) - -SECTIONS { - . = 0xBBFF0000; - _gLinkedBase = .; - - .text : AT(ADDR(.text)) { - code = .; - *(.text) - *(.rodata*) - } - - .data ALIGN (0x1000) : AT(ADDR(.data)) { - data = .; - *(.data) - } - - .bss ALIGN (0x1000) : AT(ADDR(.bss)) { - _sbss = .; - *(COMMON) - *(.bss) - _ebss = .; - bss = .; - } - _end = .; -} diff --git a/Usermode/Libraries/ld-acess.old.so_src/loadlib.c b/Usermode/Libraries/ld-acess.old.so_src/loadlib.c deleted file mode 100644 index e5090ddd..00000000 --- a/Usermode/Libraries/ld-acess.old.so_src/loadlib.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - AcessOS 1 - Dynamic Loader - By thePowersGang -*/ -#include "common.h" - -#define DEBUG 0 - -#if DEBUG -# define DEBUGS(v...) SysDebug(v) -#else -# define DEBUGS(v...) -#endif - -// === PROTOTYPES === -Uint IsFileLoaded(char *file); - int GetSymbolFromBase(Uint base, char *name, Uint *ret); - -// === CONSTANTS === -const struct { - Uint Value; - char *Name; -} caLocalExports[] = { - {(Uint)gLoadedLibraries, "gLoadedLibraries"} -}; - -// === GLOABLS === -tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES]; -char gsLoadedStrings[MAX_STRINGS_BYTES]; -char *gsNextAvailString = gsLoadedStrings; -//tLoadLib *gpLoadedLibraries = NULL; - -// === CODE === -char *FindLibrary(char *DestBuf, char *SoName, char *ExtraSearchDir) -{ - // -- #1: Executable Specified - if(ExtraSearchDir) - { - strcpy(DestBuf, ExtraSearchDir); - strcat(DestBuf, "/"); - strcat(DestBuf, SoName); - if(file_exists(DestBuf)) return DestBuf; - } - - // -- #2: System - strcpy(DestBuf, SYSTEM_LIB_DIR); - strcat(DestBuf, SoName); - if(file_exists(DestBuf)) return DestBuf; - - // -- #3: Current Directory - if(file_exists(SoName)) return SoName; - - return NULL; -} - -/** - */ -Uint LoadLibrary(char *SoName, char *SearchDir, char **envp) -{ - char sTmpName[1024]; - char *filename; - Uint iArg; - void (*fEntry)(int, int, char *[], char**); - - DEBUGS("LoadLibrary: (filename='%s', envp=0x%x)\n", filename, envp); - - // Create Temp Name - filename = FindLibrary(sTmpName, SoName, SearchDir); - if(filename == NULL) { - DEBUGS("LoadLibrary: RETURN 0\n"); - return 0; - } - DEBUGS(" LoadLibrary: filename='%s'\n", filename); - - if( (iArg = IsFileLoaded(filename)) ) - return iArg; - - // Load Library - iArg = SysLoadBin(filename, (Uint*)&fEntry); - if(iArg == 0) { - DEBUGS("LoadLibrary: RETURN 0\n"); - return 0; - } - - DEBUGS(" LoadLibrary: iArg=0x%x, iEntry=0x%x\n", iArg, fEntry); - - // Load Symbols - fEntry = (void*)DoRelocate( iArg, envp, filename ); - - // Call Entrypoint - DEBUGS(" LoadLibrary: '%s' Entry 0x%x\n", SoName, fEntry); - fEntry(iArg, 0, NULL, envp); - - DEBUGS("LoadLibrary: RETURN 1\n"); - return iArg; -} - -/** - * \fn Uint IsFileLoaded(char *file) - * \brief Determine if a file is already loaded - */ -Uint IsFileLoaded(char *file) -{ - int i; - DEBUGS("IsFileLoaded: (file='%s')", file); - for( i = 0; i < MAX_LOADED_LIBRARIES; i++ ) - { - if(gLoadedLibraries[i].Base == 0) break; // Last entry has Base set to NULL - DEBUGS(" strcmp('%s', '%s')", gLoadedLibraries[i].Name, file); - if(strcmp(gLoadedLibraries[i].Name, file) == 0) { - DEBUGS("IsFileLoaded: Found %i (0x%x)", i, gLoadedLibraries[i].Base); - return gLoadedLibraries[i].Base; - } - } - DEBUGS("IsFileLoaded: Not Found"); - return 0; -} - -/** - * \fn void AddLoaded(char *File, Uint base) - * \brief Add a file to the loaded list - */ -void AddLoaded(char *File, Uint base) -{ - int i, length; - char *name = gsNextAvailString; - - DEBUGS("AddLoaded: (File='%s', base=0x%x)", File, base); - - // Find a free slot - for( i = 0; i < MAX_LOADED_LIBRARIES; i ++ ) - { - if(gLoadedLibraries[i].Base == 0) break; - } - if(i == MAX_LOADED_LIBRARIES) { - SysDebug("ERROR - ld-acess.so has run out of load slots!"); - return; - } - - // Check space in string buffer - length = strlen(File); - if(&name[length+1] >= &gsLoadedStrings[MAX_STRINGS_BYTES]) { - SysDebug("ERROR - ld-acess.so has run out of string buffer memory!"); - return; - } - - // Set information - gLoadedLibraries[i].Base = base; - strcpy(name, File); - gLoadedLibraries[i].Name = name; - gsNextAvailString = &name[length+1]; - DEBUGS("'%s' (0x%x) loaded as %i\n", name, base, i); - return; -} - -/** - * \fn void Unload(Uint Base) - */ -void Unload(Uint Base) -{ - int i, j; - int id; - char *str; - for( id = 0; id < MAX_LOADED_LIBRARIES; id++ ) - { - if(gLoadedLibraries[id].Base == Base) break; - } - if(id == MAX_LOADED_LIBRARIES) return; - - // Unload Binary - SysUnloadBin( Base ); - // Save String Pointer - str = gLoadedLibraries[id].Name; - - // Compact Loaded List - j = id; - for( i = j + 1; i < MAX_LOADED_LIBRARIES; i++, j++ ) - { - if(gLoadedLibraries[i].Base == 0) break; - // Compact String - strcpy(str, gLoadedLibraries[i].Name); - str += strlen(str)+1; - // Compact Entry - gLoadedLibraries[j].Base = gLoadedLibraries[i].Base; - gLoadedLibraries[j].Name = str; - } - - // NULL Last Entry - gLoadedLibraries[j].Base = 0; - gLoadedLibraries[j].Name = NULL; - // Save next string - gsNextAvailString = str; -} - -/** - \fn Uint GetSymbol(char *name) - \brief Gets a symbol value from a loaded library -*/ -Uint GetSymbol(char *name) -{ - int i; - Uint ret; - for(i=0;iPeHdrOffs; - - directory = peHeaders->OptHeader.Directory; - - // === Load Import Tables - impDir = Base + directory[PE_DIR_IMPORT].RVA; - for( i = 0; impDir[i].DLLName != NULL; i++ ) - { - impDir[i].DLLName += iBase; - impDir[i].ImportLookupTable += iBase/4; - impDir[i].ImportAddressTable += iBase/4; - DEBUGS(" PE_Relocate: DLL Required '%s'(0x%x)\n", impDir[i].DLLName, impDir[i].DLLName); - iLibBase = LoadLibrary(PE_int_GetTrueFile(impDir[i].DLLName), DLL_BASE_PATH, envp); - if(iLibBase == 0) { - SysDebug("Unable to load required library '%s'\n", impDir[i].DLLName); - return 0; - } - DEBUGS(" PE_Relocate: Loaded as 0x%x\n", iLibBase); - importTab = impDir[i].ImportLookupTable; - aIAT = impDir[i].ImportAddressTable; - for( j = 0; importTab[j] != 0; j++ ) - { - if( importTab[j] & 0x80000000 ) - DEBUGS(" PE_Relocate: Import Ordinal %i\n", importTab[j] & 0x7FFFFFFF); - else - { - name = (void*)( iBase + importTab[j] ); - DEBUGS(" PE_Relocate: Import Name '%s', Hint 0x%x\n", name->Name, name->Hint); - if( GetSymbolFromBase(iLibBase, name->Name, (Uint*)&aIAT[j]) == 0 ) { - SysDebug("Unable to find symbol '%s' in library '%s'\n", name->Name, impDir[i].DLLName); - return 0; - } - } - } - } - - #if DEBUG - for(i=0;iOptHeader.EntryPoint); - - return iBase + peHeaders->OptHeader.EntryPoint; -} - -/** - * \fn int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) - */ -int PE_GetSymbol(Uint Base, char *Name, Uint *Ret) -{ - tPE_DOS_HEADER *dosHdr = (void*)Base; - tPE_IMAGE_HEADERS *peHeaders; - tPE_DATA_DIR *directory; - tPE_EXPORT_DIR *expDir; - Uint32 *nameTable, *addrTable; - Uint16 *ordTable; - int i; - int symbolCount; - char *name; - Uint retVal; - Uint expLen; - - peHeaders = (void*)( Base + dosHdr->PeHdrOffs ); - directory = peHeaders->OptHeader.Directory; - - expDir = (void*)( Base + directory[PE_DIR_EXPORT].RVA ); - expLen = directory[PE_DIR_EXPORT].Size; - symbolCount = expDir->NumNamePointers; - nameTable = (void*)( Base + expDir->NamePointerRVA ); - ordTable = (void*)( Base + expDir->OrdinalTableRVA ); - addrTable = (void*)( Base + expDir->AddressRVA ); - //DEBUGS(" PE_GetSymbol: %i Symbols\n", symbolCount); - for(i=0;i link.txt - $(OBJDUMP) -x $(BIN) > ld-acess.dmp - $(OBJDUMP) -d $(BIN) > ld-acess.dsm - -$(COBJ): %.o: %.c - @echo $(CC) -o $@ - @$(CC) $(CFLAGS) -o $@ -c $< - -$(AOBJ): %.ao: %.asm - @echo $(AS) -o $@ - @$(AS) $(ASFLAGS) -o $@ $< - diff --git a/Usermode/Libraries/libacess.so_src/Makefile b/Usermode/Libraries/libacess.so_src/Makefile deleted file mode 100644 index a6267f2d..00000000 --- a/Usermode/Libraries/libacess.so_src/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# -# -# - --include ../../../Makefile.cfg - -ASFLAGS = -felf -LDFLAGS = -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain - -OBJ = core.ao vfs.ao mm.ao -BIN = ../libacess.so - -.PHONY: all clean install - -all: $(BIN) - -clean: - $(RM) $(BIN) $(OBJ) - -install: - $(xCP) $(BIN) $(DISTROOT)/Libs - -$(BIN): $(OBJ) - @echo --- $(LD) -shared -o $@ - @$(LD) $(LDFLAGS) -o $(BIN) $(OBJ) - @$(STRIP) $(BIN) - -%.ao: %.asm syscalls.inc.asm ../../../Kernel/include/syscalls.inc.asm - @echo $(AS) -o $@ - @$(AS) $(ASFLAGS) -o $@ $< diff --git a/Usermode/Libraries/libacess.so_src/core.asm b/Usermode/Libraries/libacess.so_src/core.asm deleted file mode 100644 index d79bfa1f..00000000 --- a/Usermode/Libraries/libacess.so_src/core.asm +++ /dev/null @@ -1,47 +0,0 @@ -; -; Acess2 System Interface -; -%include "syscalls.inc.asm" - -[BITS 32] -[section .data] -[global _errno:data (4)] -_errno: - dd 0 - -[section .text] -[global SoMain:func] -SoMain: - ret - -; --- Process Controll --- -SYSCALL1 _exit, SYS_EXIT -SYSCALL2 clone, SYS_CLONE -SYSCALL2 kill, SYS_KILL -SYSCALL0 yield, SYS_YIELD -SYSCALL0 sleep, SYS_SLEEP -SYSCALL2 waittid, SYS_WAITTID - -SYSCALL0 gettid, SYS_GETTID -SYSCALL0 getpid, SYS_GETPID -SYSCALL0 getuid, SYS_GETUID -SYSCALL0 getgid, SYS_GETGID - -SYSCALL1 setuid, SYS_SETUID -SYSCALL1 setgid, SYS_SETGID - -SYSCALL1 SysSetName, SYS_SETNAME -SYSCALL2 SysGetName, SYS_GETNAME - -SYSCALL1 SysSetPri, SYS_SETPRI - -SYSCALL3 SysSendMessage, SYS_SENDMSG -SYSCALL3 SysGetMessage, SYS_GETMSG - -SYSCALL3 SysSpawn, SYS_SPAWN -SYSCALL3 execve, SYS_EXECVE -SYSCALL2 SysLoadBin, SYS_LOADBIN - -SYSCALL1 _SysSetFaultHandler, SYS_SETFAULTHANDLER - -SYSCALL6 _SysDebug, 0x100 diff --git a/Usermode/Libraries/libacess.so_src/mm.asm b/Usermode/Libraries/libacess.so_src/mm.asm deleted file mode 100644 index bede9aef..00000000 --- a/Usermode/Libraries/libacess.so_src/mm.asm +++ /dev/null @@ -1,11 +0,0 @@ -; -; Acess2 System Interface -; -%include "syscalls.inc.asm" - -[BITS 32] -[extern _errno] - -[section .text] -SYSCALL1 _SysGetPhys, SYS_GETPHYS ; uint64_t _SysGetPhys(uint addr) -SYSCALL1 _SysAllocate, SYS_ALLOCATE ; uint64_t _SysAllocate(uint addr) diff --git a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm b/Usermode/Libraries/libacess.so_src/syscalls.inc.asm deleted file mode 100644 index eea5573a..00000000 --- a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm +++ /dev/null @@ -1,141 +0,0 @@ -; ======================== -; AcssMicro - System Calls -; ======================== - -%include "../../../Kernel/include/syscalls.inc.asm" - -;%define SYSCALL_OP jmp 0xCFFF0000 -%define SYSCALL_OP int 0xAC - -; System Call - No Arguments -%macro SYSCALL0 2 -[global %1:func] -%1: - push ebx - mov eax, %2 - SYSCALL_OP - mov [_errno], ebx - pop ebx - ret -%endmacro - -; System Call - 1 Argument -%macro SYSCALL1 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - mov eax, %2 - mov ebx, [ebp+8] - SYSCALL_OP - mov [_errno], ebx - pop ebx - pop ebp - ret -%endmacro - -; System Call - 2 Arguments -%macro SYSCALL2 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - mov eax, %2 - mov ebx, [ebp+8] - mov ecx, [ebp+12] - SYSCALL_OP - mov [_errno], ebx - pop ebx - pop ebp - ret -%endmacro - -; System Call - 3 Arguments -%macro SYSCALL3 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - mov eax, %2 - mov ebx, [ebp+8] - mov ecx, [ebp+12] - mov edx, [ebp+16] - SYSCALL_OP - mov [_errno], ebx - pop ebx - pop ebp - ret -%endmacro - -; System Call - 4 Arguments -%macro SYSCALL4 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - push edi - mov eax, %2 - mov ebx, [ebp+8] - mov ecx, [ebp+12] - mov edx, [ebp+16] - mov edi, [ebp+20] - SYSCALL_OP - mov [_errno], ebx - pop edi - pop ebx - pop ebp - ret -%endmacro - -; System Call - 5 Arguments -%macro SYSCALL5 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - push edi - push esi - mov eax, %2 - mov ebx, [ebp+8] - mov ecx, [ebp+12] - mov edx, [ebp+16] - mov edi, [ebp+20] - mov esi, [ebp+24] - SYSCALL_OP - mov [_errno], ebx - pop esi - pop edi - pop ebx - pop ebp - ret -%endmacro - -; System Call - 6 Arguments -%macro SYSCALL6 2 -[global %1:func] -%1: - push ebp - mov ebp, esp - push ebx - push edi - push esi - mov eax, %2 - mov ebx, [ebp+8] - mov ecx, [ebp+12] - mov edx, [ebp+16] - mov edi, [ebp+20] - mov esi, [ebp+24] - mov ebp, [ebp+28] - SYSCALL_OP - mov [_errno], ebx - pop esi - pop edi - pop ebx - pop ebp - ret -%endmacro diff --git a/Usermode/Libraries/libacess.so_src/vfs.asm b/Usermode/Libraries/libacess.so_src/vfs.asm deleted file mode 100644 index 44bce6b2..00000000 --- a/Usermode/Libraries/libacess.so_src/vfs.asm +++ /dev/null @@ -1,24 +0,0 @@ -; -; Acess2 System Interface -; -%include "syscalls.inc.asm" - -[BITS 32] -[extern _errno] - -[section .text] -SYSCALL2 open, SYS_OPEN ; char*, int -SYSCALL3 reopen, SYS_REOPEN ; int, char*, int -SYSCALL1 close, SYS_CLOSE ; int -SYSCALL3 read, SYS_READ ; int, uint, void* -SYSCALL3 write, SYS_WRITE ; int, uint, void* -SYSCALL4 seek, SYS_SEEK ; int, uint64_t, int -SYSCALL1 tell, SYS_TELL ; int -SYSCALL3 finfo, SYS_FINFO ; int, void*, int -SYSCALL2 readdir, SYS_READDIR ; int, char* -SYSCALL2 _SysGetACL, SYS_GETACL ; int, void* -SYSCALL1 chdir, SYS_CHDIR ; char* -SYSCALL3 ioctl, SYS_IOCTL ; int, int, void* -SYSCALL4 _SysMount, SYS_MOUNT ; char*, char*, char*, char* - -SYSCALL3 _SysOpenChild, SYS_OPENCHILD diff --git a/Usermode/Libraries/libaxwin2.so_src/Makefile b/Usermode/Libraries/libaxwin2.so_src/Makefile index 2ce02e44..240646b7 100644 --- a/Usermode/Libraries/libaxwin2.so_src/Makefile +++ b/Usermode/Libraries/libaxwin2.so_src/Makefile @@ -8,6 +8,6 @@ CFLAGS += -Wall LDFLAGS += -lc -soname libaxwin2.so OBJ = main.o messages.o -BIN = ../libaxwin2.so +BIN = libaxwin2.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index a12ff45b..2d6801d6 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -11,35 +11,13 @@ LDFLAGS += -soname libc.so -Map map.txt -lgcc OBJ = stub.o heap.o stdlib.o env.o fileIO.o string.o DEPFILES := $(OBJ:%.o=%.d) # signals.o -BIN = ../libc.so +BIN = libc.so -.PHONY: all clean install +include ../Makefile.tpl -all: $(BIN) - -clean: - $(RM) $(BIN) $(OBJ) $(DEPFILES) libc.so.dsm libc.so.dmp map.txt - -install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Libs/ - -# Core C Library -$(BIN): $(OBJ) - @echo --- ld -shared -o $@ - @$(LD) $(LDFLAGS) $(OBJ) -o $@ - @$(OBJDUMP) -d $@ > libc.so.1.dsm - @$(OBJDUMP) -x -r -R $@ > libc.so.1.dmp +#all: $(OUTPUTDIR)Libs/crt0.o # C Runtime 0 -../crt0.o: crt0.asm - @echo --- $(AS) -o $@ - @$(AS) $(ASFLAGS) -o $@ $< - -$(filter %.o, $(OBJ)): %.o: %.c - @echo --- $(CC) -o $@ - @$(CC) $(CFLAGS) -DBUILD_SO -o $@ -c $< - @$(MAKEDEP) $(CPPFLAGS) -MT $@ -o $*.d $< - -$(filter %.ao, $(OBJ)): %.ao: %.asm - @echo --- $(AS) -o $@ - @$(AS) $(ASFLAGS) -o $@ $< +#$(OUTPUTDIR)Libs/crt0.o: crt0.asm +# @echo --- $(AS) -o $@ +# @$(AS) $(ASFLAGS) -o $@ $< diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index d1ee56ea..fbdf30d0 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -22,6 +22,7 @@ static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uin // === IMPORTS === extern tLoadedLib gLoadedLibraries[64]; +extern int _SysSetFaultHandler(int (*Handler)(int)); // === GLOBALS === extern char **_envp; diff --git a/Usermode/Libraries/libgcc.so_src/Makefile b/Usermode/Libraries/libgcc.so_src/Makefile index b6f5b70d..235810ac 100644 --- a/Usermode/Libraries/libgcc.so_src/Makefile +++ b/Usermode/Libraries/libgcc.so_src/Makefile @@ -4,27 +4,11 @@ -include ../Makefile.cfg -OBJS = libgcc.o -BIN = ../libgcc.so +OBJ = libgcc.o +BIN = libgcc.so CFLAGS += -Wall -Werror LDFLAGS += -soname libgcc.so -.PHONY: all clean install +include ../Makefile.tpl -all: $(BIN) - -clean: - $(RM) $(BIN) $(OBJS) libgcc.so.dsm - -install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Libs - -$(BIN): $(OBJS) - @echo -- ld -o $@ - @$(LD) $(LDFLAGS) -o $(BIN) $(OBJS) - @$(OBJDUMP) -d $(BIN) > libgcc.so.dsm - -$(OBJS): %.o: %.c - @echo -- gcc -o $@ - @$(CC) $(CFLAGS) -o $@ -c $< diff --git a/Usermode/Libraries/libimage_sif.so_src/Makefile b/Usermode/Libraries/libimage_sif.so_src/Makefile index b4b94e20..44a9d4ec 100644 --- a/Usermode/Libraries/libimage_sif.so_src/Makefile +++ b/Usermode/Libraries/libimage_sif.so_src/Makefile @@ -8,6 +8,6 @@ CFLAGS += -Wall LDFLAGS += -lc -soname libimage_sif.so OBJ = main.o -BIN = ../libimage_sif.so +BIN = libimage_sif.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libnet.so_src/Makefile b/Usermode/Libraries/libnet.so_src/Makefile index fa775eff..aa2f2f9a 100644 --- a/Usermode/Libraries/libnet.so_src/Makefile +++ b/Usermode/Libraries/libnet.so_src/Makefile @@ -7,6 +7,6 @@ CFLAGS += -Wall LDFLAGS += -lc -soname libnet.so OBJ = main.o address.o -BIN = ../libnet.so +BIN = libnet.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libreadline.so_src/Makefile b/Usermode/Libraries/libreadline.so_src/Makefile index fefbf0c1..538ec260 100644 --- a/Usermode/Libraries/libreadline.so_src/Makefile +++ b/Usermode/Libraries/libreadline.so_src/Makefile @@ -8,6 +8,6 @@ CFLAGS += -Wall LDFLAGS += -lc -soname libreadline.so OBJ = main.o -BIN = ../libreadline.so +BIN = libreadline.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libspiderscript.so_src/Makefile b/Usermode/Libraries/libspiderscript.so_src/Makefile index 954b2a70..28382cad 100644 --- a/Usermode/Libraries/libspiderscript.so_src/Makefile +++ b/Usermode/Libraries/libspiderscript.so_src/Makefile @@ -8,6 +8,6 @@ CFLAGS += -Wall LDFLAGS += -lc -lgcc -soname libspiderscript.so --no-allow-shlib-undefined OBJ = main.o lex.o parse.o ast.o exec_ast.o exports.o -BIN = ../libspiderscript.so +BIN = libspiderscript.so include ../Makefile.tpl diff --git a/Usermode/Libraries/liburi.so_src/Makefile b/Usermode/Libraries/liburi.so_src/Makefile index 047a7047..006c1886 100644 --- a/Usermode/Libraries/liburi.so_src/Makefile +++ b/Usermode/Libraries/liburi.so_src/Makefile @@ -8,6 +8,6 @@ CFLAGS += -Wall LDFLAGS += -lc -soname liburi.so OBJ = main.o -BIN = ../liburi.so +BIN = liburi.so include ../Makefile.tpl diff --git a/Usermode/Makefile.cfg b/Usermode/Makefile.cfg new file mode 100644 index 00000000..13fa0a6c --- /dev/null +++ b/Usermode/Makefile.cfg @@ -0,0 +1,14 @@ +# +# Usermode Makefile.cfg +# + +# Include Root Makefile.cfg +-include $(dir $(lastword $(MAKEFILE_LIST)))../Makefile.cfg + + +# Set variables +# > Usermode directory +ACESSUSERDIR := $(ACESSDIR)/Usermode/ +# > Output directory for build binaries +OUTPUTDIR := $(ACESSUSERDIR)Output/$(ARCH)/ +