From dc8801cc0b5ed911a775cfc2ea853048f7a00db1 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 12 Oct 2011 11:12:29 +0800 Subject: [PATCH] Major build system changes - Implemented ARMv7 userspace - Shifted build system about to do so > `make all` processes user apps first This is so they are compiled for the initrd > Syscalls header changed to use #define instead of enum Allows ARMv7 assembly file to use it - Moved most of my libgcc functions to ld-acess > ld-acess needed them, so remove code duplication NOTE: Broke dependencies for nasm in user code - I need to properly separate NASM and GAS objects, will do that in next commit. --- Kernel/GenSyscalls.php | 17 +-- Kernel/GenSyscalls.pl | 20 ++- Kernel/arch/armv7/start.S | 8 +- Kernel/include/syscalls.h | 116 +++++++++--------- Makefile | 12 +- Makefile.cfg | 1 + Modules/Filesystems/InitRD/.gitignore | 1 + Modules/Filesystems/InitRD/GenerateInitRD.php | 82 ++++++------- Modules/Filesystems/InitRD/Makefile | 10 +- Modules/Filesystems/InitRD/files.lst | 33 +++-- Modules/armv7/GIC/gic.c | 2 +- Usermode/Applications/axwin2_src/WM/helpers.c | 3 +- Usermode/Applications/axwin2_src/WM/input.c | 2 +- Usermode/Libraries/Makefile.tpl | 4 +- .../Libraries/acess.ld_src/acess_armv7.ld.h | 1 + Usermode/Libraries/crt0.o_src/crt0.armv7.S | 6 +- Usermode/Libraries/ld-acess.so_src/Makefile | 4 +- Usermode/Libraries/ld-acess.so_src/_stublib.c | 11 ++ .../Libraries/ld-acess.so_src/arch/armv7.S.h | 79 ++++++++++++ .../Libraries/ld-acess.so_src/arch/armv7.ld | 66 ++++++++++ Usermode/Libraries/ld-acess.so_src/lib.c | 78 +++++++++++- Usermode/Libraries/libc.so_src/arch/armv7.S | 24 ++++ Usermode/Libraries/libgcc.so_src/libgcc.c | 108 ---------------- 23 files changed, 411 insertions(+), 277 deletions(-) create mode 100644 Usermode/Libraries/ld-acess.so_src/arch/armv7.S.h create mode 100644 Usermode/Libraries/ld-acess.so_src/arch/armv7.ld create mode 100644 Usermode/Libraries/libc.so_src/arch/armv7.S diff --git a/Kernel/GenSyscalls.php b/Kernel/GenSyscalls.php index 1876046b..d451d1dd 100644 --- a/Kernel/GenSyscalls.php +++ b/Kernel/GenSyscalls.php @@ -27,7 +27,6 @@ $lHeader = "/* #ifndef _SYSCALLS_H #define _SYSCALLS_H -enum eSyscalls { "; $i = 0; foreach($lSyscalls as $num=>$call) @@ -37,9 +36,8 @@ foreach($lSyscalls as $num=>$call) $lAsmInc .= "\n"; } - $lHeader .= "\t{$call[0]}"; - if($i != $num) $lHeader .= " = {$num}"; - $lHeader .= ",\t// {$num} - {$call[1]}\n"; + $lHeader .= "#define {$call[0]}\t{$num}"; + $lHeader .= "\t// {$num} - {$call[1]}\n"; $lAsmInc .= "%define {$call[0]}\t{$num}\t; {$call[1]}\n"; @@ -49,9 +47,10 @@ foreach($lSyscalls as $num=>$call) else $i ++; } -$lHeader .= "\tNUM_SYSCALLS,\n"; -$lHeader .= "\tSYS_DEBUG = 0x100 // 0x100 - Print a debug string\n"; -$lHeader .= "};\n\n"; +$lHeader .= "#define NUM_SYSCALLS\t$i\n"; +$lHeader .= "#define SYS_DEBUG\t0x100 // 0x100 - Print a debug string\n"; +$lHeader .= "\n"; +$lHeader .= "#ifdef __GNUC__\n"; $lHeader .= "static const char *cSYSCALL_NAMES[] = {\n\t"; $j = 0; @@ -67,7 +66,9 @@ for($i=0;$i<$lMax;$i++) $j = 0; } } -$lHeader .= "\"\"\n};\n#endif\n"; +$lHeader .= "\"\"\n};\n" +$lHeader .= "#endif\n"; +$lHeader .= "#endif\n"; $fp = fopen("include/syscalls.h", "w"); fwrite($fp, $lHeader); fclose($fp); $fp = fopen("include/syscalls.inc.asm", "w"); fwrite($fp, $lAsmInc); fclose($fp); diff --git a/Kernel/GenSyscalls.pl b/Kernel/GenSyscalls.pl index 15270a6d..487ceca4 100755 --- a/Kernel/GenSyscalls.pl +++ b/Kernel/GenSyscalls.pl @@ -33,27 +33,20 @@ print HEADER "/* #ifndef _SYSCALLS_H #define _SYSCALLS_H -enum eSyscalls { "; $lastid = -1; +$i = 0; foreach my $call (@calls) { - if( $lastid + 1 != $call->[0] ) { - print HEADER "\n"; - } - print HEADER "\t", $call->[1]; - if( $lastid + 1 != $call->[0] ) { - print HEADER " = ", $call->[0]; - } - print HEADER ",\t// ", $call->[2], "\n"; - $lastid = $call->[0]; + print HEADER "#define ", $call->[1], "\t", $call->[0], "\t// ", $call->[2], "\n"; + $i = $call->[0] + 1; } print HEADER " -\tNUM_SYSCALLS, -\tSYS_DEBUG = 0x100 -}; +#define NUM_SYSCALLS ",$i," +#define SYS_DEBUG 0x100 +#ifndef __ASSEMBLER__ static const char *cSYSCALL_NAMES[] = { "; @@ -71,6 +64,7 @@ foreach $call (@calls) print HEADER " \t\"\" }; +#endif #endif "; diff --git a/Kernel/arch/armv7/start.S b/Kernel/arch/armv7/start.S index 0ba0c8c3..078b9986 100644 --- a/Kernel/arch/armv7/start.S +++ b/Kernel/arch/armv7/start.S @@ -65,10 +65,10 @@ IRQHandler: PUSH_GPRS - ldr r0, =csIRQ_Tag - ldr r1, =csIRQ_Fmt - ldr r4, =Log_Debug - blx r4 +@ ldr r0, =csIRQ_Tag +@ ldr r1, =csIRQ_Fmt +@ ldr r4, =Log_Debug +@ blx r4 @ Call the registered handler ldr r0, gpIRQHandler diff --git a/Kernel/include/syscalls.h b/Kernel/include/syscalls.h index bb80ffb1..98bb9796 100644 --- a/Kernel/include/syscalls.h +++ b/Kernel/include/syscalls.h @@ -8,67 +8,64 @@ #ifndef _SYSCALLS_H #define _SYSCALLS_H -enum eSyscalls { - SYS_EXIT, // Kill this thread - SYS_CLONE, // Create a new thread - SYS_KILL, // Send a signal - SYS_SETFAULTHANDLER, // Set signal Handler - SYS_YIELD, // Yield remainder of timestamp - SYS_SLEEP, // Sleep until messaged or signaled - SYS_WAIT, // Wait for a time or a message - SYS_WAITTID, // Wait for a thread to do something - SYS_SETNAME, // Set's the name of the current thread - SYS_GETNAME, // Get's the name of a thread - SYS_GETTID, // Get current thread ID - SYS_GETPID, // Get current thread group ID - SYS_SETPRI, // Set process priority - SYS_SENDMSG, // Send an IPC message - SYS_GETMSG, // Recieve an IPC message - SYS_GETTIME, // Get the current timestamp - SYS_SPAWN, // Spawn a new process - SYS_EXECVE, // Replace the current process - SYS_LOADBIN, // Load a binary into the current address space - SYS_UNLOADBIN, // Unload a loaded binary - SYS_LOADMOD, // Load a module into the kernel +#define SYS_EXIT 0 // Kill this thread +#define SYS_CLONE 1 // Create a new thread +#define SYS_KILL 2 // Send a signal +#define SYS_SETFAULTHANDLER 3 // Set signal Handler +#define SYS_YIELD 4 // Yield remainder of timestamp +#define SYS_SLEEP 5 // Sleep until messaged or signaled +#define SYS_WAIT 6 // Wait for a time or a message +#define SYS_WAITTID 7 // Wait for a thread to do something +#define SYS_SETNAME 8 // Set's the name of the current thread +#define SYS_GETNAME 9 // Get's the name of a thread +#define SYS_GETTID 10 // Get current thread ID +#define SYS_GETPID 11 // Get current thread group ID +#define SYS_SETPRI 12 // Set process priority +#define SYS_SENDMSG 13 // Send an IPC message +#define SYS_GETMSG 14 // Recieve an IPC message +#define SYS_GETTIME 15 // Get the current timestamp +#define SYS_SPAWN 16 // Spawn a new process +#define SYS_EXECVE 17 // Replace the current process +#define SYS_LOADBIN 18 // Load a binary into the current address space +#define SYS_UNLOADBIN 19 // Unload a loaded binary +#define SYS_LOADMOD 20 // Load a module into the kernel +#define SYS_GETPHYS 32 // Get the physical address of a page +#define SYS_MAP 33 // Map a physical address +#define SYS_ALLOCATE 34 // Allocate a page +#define SYS_UNMAP 35 // Unmap a page +#define SYS_PREALLOC 36 // Preallocate a page +#define SYS_SETFLAGS 37 // Set a page's flags +#define SYS_SHAREWITH 38 // Share a page with another thread +#define SYS_GETUID 39 // Get current User ID +#define SYS_GETGID 40 // Get current Group ID +#define SYS_SETUID 41 // Set current user ID +#define SYS_SETGID 42 // Set current Group ID +#define SYS_OPEN 64 // Open a file +#define SYS_REOPEN 65 // Close a file and reuse its handle +#define SYS_CLOSE 66 // Close a file +#define SYS_READ 67 // Read from an open file +#define SYS_WRITE 68 // Write to an open file +#define SYS_IOCTL 69 // Perform an IOCtl Call +#define SYS_SEEK 70 // Seek to a new position in the file +#define SYS_READDIR 71 // Read from an open directory +#define SYS_OPENCHILD 72 // Open a child entry in a directory +#define SYS_GETACL 73 // Get an ACL Value +#define SYS_SETACL 74 // Set an ACL Value +#define SYS_FINFO 75 // Get file information +#define SYS_MKDIR 76 // Create a new directory +#define SYS_LINK 77 // Create a new link to a file +#define SYS_SYMLINK 78 // Create a symbolic link +#define SYS_UNLINK 79 // Delete a file +#define SYS_TELL 80 // Return the current file position +#define SYS_CHDIR 81 // Change current directory +#define SYS_GETCWD 82 // Get current directory +#define SYS_MOUNT 83 // Mount a filesystem +#define SYS_SELECT 84 // Wait for file handles - SYS_GETPHYS = 32, // Get the physical address of a page - SYS_MAP, // Map a physical address - SYS_ALLOCATE, // Allocate a page - SYS_UNMAP, // Unmap a page - SYS_PREALLOC, // Preallocate a page - SYS_SETFLAGS, // Set a page's flags - SYS_SHAREWITH, // Share a page with another thread - SYS_GETUID, // Get current User ID - SYS_GETGID, // Get current Group ID - SYS_SETUID, // Set current user ID - SYS_SETGID, // Set current Group ID - - SYS_OPEN = 64, // Open a file - SYS_REOPEN, // Close a file and reuse its handle - SYS_CLOSE, // Close a file - SYS_READ, // Read from an open file - SYS_WRITE, // Write to an open file - SYS_IOCTL, // Perform an IOCtl Call - SYS_SEEK, // Seek to a new position in the file - SYS_READDIR, // Read from an open directory - SYS_OPENCHILD, // Open a child entry in a directory - SYS_GETACL, // Get an ACL Value - SYS_SETACL, // Set an ACL Value - SYS_FINFO, // Get file information - SYS_MKDIR, // Create a new directory - SYS_LINK, // Create a new link to a file - SYS_SYMLINK, // Create a symbolic link - SYS_UNLINK, // Delete a file - SYS_TELL, // Return the current file position - SYS_CHDIR, // Change current directory - SYS_GETCWD, // Get current directory - SYS_MOUNT, // Mount a filesystem - SYS_SELECT, // Wait for file handles - - NUM_SYSCALLS, - SYS_DEBUG = 0x100 -}; +#define NUM_SYSCALLS 85 +#define SYS_DEBUG 0x100 +#ifndef __ASSEMBLER__ static const char *cSYSCALL_NAMES[] = { "SYS_EXIT", "SYS_CLONE", @@ -158,5 +155,6 @@ static const char *cSYSCALL_NAMES[] = { "" }; +#endif #endif diff --git a/Makefile b/Makefile index 4fca6d54..3336e806 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ -include Makefile.cfg -.PHONY: all clean +.PHONY: all clean SyscallList all-user SUBMAKE = $(MAKE) --no-print-directory @@ -48,10 +48,14 @@ 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) +all: SyscallList $(ALL_USRLIBS) $(ALL_USRAPPS) $(ALL_MODULES) all-Kernel $(ALL_DYNMODS) +all-install: SyscallList $(AI_USRLIBS) $(AI_USRAPPS) $(AI_MODULES) allinstall-Kernel $(AI_DYNMODS) clean: $(CLEAN_DYNMODS) $(CLEAN_MODULES) clean-Kernel $(CLEAN_USRLIBS) $(CLEAN_USRAPPS) -install: install-Filesystem $(INSTALL_DYNMODS) $(INSTALL_MODULES) install-Kernel $(INSTALL_USRLIBS) $(INSTALL_USRAPPS) +install: install-Filesystem SyscallList $(INSTALL_USRLIBS) $(INSTALL_USRAPPS) $(INSTALL_DYNMODS) $(INSTALL_MODULES) install-Kernel + +SyscallList: include/syscalls.h +include/syscalls.h: Kernel/Makefile Kernel/syscalls.lst + @make -C Kernel/ include/syscalls.h # Compile Only $(ALL_DYNMODS): all-%: diff --git a/Makefile.cfg b/Makefile.cfg index 6986150a..b919d869 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -72,6 +72,7 @@ endif ifeq ($(ARCHDIR),armv7) MODULES += Input/PS2KbMouse MODULES += armv7/GIC +MODULES += Filesystems/InitRD endif MODULES += IPStack # So the other modules are loaded before it diff --git a/Modules/Filesystems/InitRD/.gitignore b/Modules/Filesystems/InitRD/.gitignore index a3115058..1a33cc27 100644 --- a/Modules/Filesystems/InitRD/.gitignore +++ b/Modules/Filesystems/InitRD/.gitignore @@ -1 +1,2 @@ files.c +files.*.c diff --git a/Modules/Filesystems/InitRD/GenerateInitRD.php b/Modules/Filesystems/InitRD/GenerateInitRD.php index ab6eb600..4632cc01 100644 --- a/Modules/Filesystems/InitRD/GenerateInitRD.php +++ b/Modules/Filesystems/InitRD/GenerateInitRD.php @@ -10,6 +10,9 @@ $gOutput = << 3 ? $argv[3] : false); @@ -24,6 +27,7 @@ $lStack = array( array("",array()) ); foreach($lines as $line) { $line = trim($line); + // Directory if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches)) { $new = array($matches[1], array()); @@ -31,12 +35,14 @@ foreach($lines as $line) $lDepth ++; continue; } + // End of a block if($line == "}") { $lDepth --; $lStack[$lDepth][1][] = array_pop($lStack); continue; } + // File if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches)) { $lStack[$lDepth][1][] = array($matches[1], $matches[2]); @@ -63,6 +69,7 @@ function hd8($fp) function ProcessFolder($prefix, $items) { global $gOutput; + global $ACESSDIR, $ARCH; foreach($items as $i=>$item) { if(is_array($item[1])) @@ -91,57 +98,40 @@ tVFS_Node {$prefix}_{$i} = { EOF; } - else { - if(!file_exists($item[1])) { - echo "ERROR: '{$item[1]}' does not exist\n", + else + { + $path = $item[1]; + + // Parse path components + $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path); + $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path); + echo $path,"\n"; + // --- + + if(!file_exists($path)) { + echo "ERROR: '{$path}' does not exist\n", exit(1); } - $size = filesize($item[1]); + $size = filesize($path); - $fp = fopen($item[1], "rb"); - if(0) - { - $gOutput .= "Uint32 {$prefix}_{$i}_data[] = {\n"; - for( $j = 0; $j + 16 < $size; $j += 16 ) - { - $gOutput .= "\t"; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).",\n"; - } + $fp = fopen($path, "rb"); + + $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n"; + for( $j = 0; $j + 16 < $size; $j += 16 ) { $gOutput .= "\t"; - for( ; $j+3 < $size; $j += 4 ) - { - if( $j & 15 ) $gOutput .= ","; - $gOutput .= hd($fp); - } - if($j < $size) { - $tmp = ""; - while($j ++ < $size) - $tmp .= fgetc($fp); - $tmp .= "\0\0\0"; - $tmp = unpack("I", $tmp); - $gOutput .= "0x".dechex($tmp[1]); - } + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).",\n"; } - else - { - $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n"; - for( $j = 0; $j + 16 < $size; $j += 16 ) { - $gOutput .= "\t"; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).","; - $gOutput .= hd8($fp).",".hd8($fp).",\n"; - } - $gOutput .= "\t"; - for( ; $j < $size; $j ++ ) { - if( $j & 15 ) $gOutput .= ","; - $gOutput .= hd8($fp); - } + $gOutput .= "\t"; + for( ; $j < $size; $j ++ ) { + if( $j & 15 ) $gOutput .= ","; + $gOutput .= hd8($fp); } fclose($fp); $gOutput .= "\n};\n"; diff --git a/Modules/Filesystems/InitRD/Makefile b/Modules/Filesystems/InitRD/Makefile index 7506f7e3..205ad7b1 100644 --- a/Modules/Filesystems/InitRD/Makefile +++ b/Modules/Filesystems/InitRD/Makefile @@ -1,13 +1,15 @@ # InitRD Filesystem Driver # -OBJ = main.o files.o +OBJ = main.o files.$(ARCH).o EXTRA = files.c NAME = InitRD +EXTRA = files.$(ARCH).c files.$(ARCH).c.dep -include ../Makefile.tpl -files.c: GenerateInitRD.php files.lst - php GenerateInitRD.php files.lst files.c files.c.d --include files.c.d +files.$(ARCH).c: GenerateInitRD.php files.lst + ARCH=$(ARCH) ACESSDIR=$(ACESSDIR) php GenerateInitRD.php files.lst $@ $@.dep + +-include files.$(ARCH).c.dep diff --git a/Modules/Filesystems/InitRD/files.lst b/Modules/Filesystems/InitRD/files.lst index 6d7c8424..e8033266 100644 --- a/Modules/Filesystems/InitRD/files.lst +++ b/Modules/Filesystems/InitRD/files.lst @@ -1,25 +1,24 @@ Dir "SBin" { - File "init" "../../../Usermode/Output/i386/SBin/init" - File "login" "../../../Usermode/Output/i386/SBin/login" + File "init" "__BIN__/SBin/init" + File "login" "__BIN__/SBin/login" } Dir "Bin" { - File "CLIShell" "../../../Usermode/Output/i386/Bin/CLIShell" - File "ls" "../../../Usermode/Output/i386/Bin/ls" - File "cat" "../../../Usermode/Output/i386/Bin/cat" - File "mount" "../../../Usermode/Output/i386/Bin/mount" - File "pcidump" "../../../Usermode/Output/i386/Bin/pcidump" - File "ifconfig" "../../../Usermode/Output/i386/Bin/ifconfig" - File "telnet" "../../../Usermode/Output/i386/Bin/telnet" - File "irc" "../../../Usermode/Output/i386/Bin/irc" + File "CLIShell" "__BIN__/Bin/CLIShell" + File "ls" "__BIN__/Bin/ls" + File "cat" "__BIN__/Bin/cat" + File "mount" "__BIN__/Bin/mount" + File "ifconfig" "__BIN__/Bin/ifconfig" + File "telnet" "__BIN__/Bin/telnet" + File "irc" "__BIN__/Bin/irc" } Dir "Libs" { - File "ld-acess.so" "../../../Usermode/Output/i386/Libs/ld-acess.so" - File "libld-acess.so" "../../../Usermode/Output/i386/Libs/libld-acess.so" - File "libc.so" "../../../Usermode/Output/i386/Libs/libc.so" - File "libgcc.so" "../../../Usermode/Output/i386/Libs/libgcc.so" - File "libreadline.so" "../../../Usermode/Output/i386/Libs/libreadline.so" - File "libnet.so" "../../../Usermode/Output/i386/Libs/libnet.so" + File "ld-acess.so" "__BIN__/Libs/ld-acess.so" + File "libld-acess.so" "__BIN__/Libs/libld-acess.so" + File "libc.so" "__BIN__/Libs/libc.so" + File "libgcc.so" "__BIN__/Libs/libgcc.so" + File "libreadline.so" "__BIN__/Libs/libreadline.so" + File "libnet.so" "__BIN__/Libs/libnet.so" } Dir "Conf" { - File "BootConf.cfg" "../../../Usermode/Filesystem/Conf/BootConf.cfg" + File "BootConf.cfg" "__FS__/Conf/BootConf.cfg" } diff --git a/Modules/armv7/GIC/gic.c b/Modules/armv7/GIC/gic.c index 4ace4005..21c3a30f 100644 --- a/Modules/armv7/GIC/gic.c +++ b/Modules/armv7/GIC/gic.c @@ -57,7 +57,7 @@ int GIC_Install(char **Arguments) void GIC_IRQHandler(void) { Uint32 num = gpGIC_InterfaceBase[GICC_IAR]; - Log_Debug("GIC", "IRQ 0x%x", num); +// Log_Debug("GIC", "IRQ 0x%x", num); gaIRQ_Handlers[num]( num, gaIRQ_HandlerData[num] ); gpGIC_InterfaceBase[GICC_EOIR] = num; } diff --git a/Usermode/Applications/axwin2_src/WM/helpers.c b/Usermode/Applications/axwin2_src/WM/helpers.c index d9238175..194c0249 100644 --- a/Usermode/Applications/axwin2_src/WM/helpers.c +++ b/Usermode/Applications/axwin2_src/WM/helpers.c @@ -7,5 +7,6 @@ // === CODE === void memset32(void *ptr, uint32_t val, size_t count) { - __asm__ __volatile__ ("rep stosl" : : "D"(ptr),"a"(val),"c"(count)); + uint32_t *dst = ptr; + while(count --) *dst++ = val; } diff --git a/Usermode/Applications/axwin2_src/WM/input.c b/Usermode/Applications/axwin2_src/WM/input.c index a9728f79..aa7f3b37 100644 --- a/Usermode/Applications/axwin2_src/WM/input.c +++ b/Usermode/Applications/axwin2_src/WM/input.c @@ -71,6 +71,6 @@ void Input_HandleSelect(fd_set *set) // Handle movement // Video_SetCursorPos( mouseinfo.Axies[0], mouseinfo.Axies[1] ); - _SysDebug("Cursor to %i,%i\n", mouseinfo.Axies[0], mouseinfo.Axies[1]); + _SysDebug("Cursor to %i,%i\n", mouseinfo.Axies[0].CursorPos, mouseinfo.Axies[1].CursorPos); } } diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index 5ca97a91..adf1c7ec 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -43,11 +43,11 @@ $(_OBJPREFIX)%.o: %.c @$(CC) $(CFLAGS) -o $@ -c $< @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $@.dep -$(_OBJPREFIX)%.ao: %.asm +$(_OBJPREFIX)%.ao: %.$(ASSUFFIX) @echo [AS] -o $@ @mkdir -p $(dir $@) @$(AS) $(ASFLAGS) -o $@ $< - @$(AS) $(ASFLAGS) -o $@ $< -M > $@.dep + @$(AS) $(ASFLAGS) -o $@.dep $< -M #$(OUTPUTDIR)Libs/libld-acess.so: # @make -C $(ACESSDIR)/Usermode/Libraries/ld-acess.so_src/ diff --git a/Usermode/Libraries/acess.ld_src/acess_armv7.ld.h b/Usermode/Libraries/acess.ld_src/acess_armv7.ld.h index c338f469..e652a5aa 100644 --- a/Usermode/Libraries/acess.ld_src/acess_armv7.ld.h +++ b/Usermode/Libraries/acess.ld_src/acess_armv7.ld.h @@ -4,6 +4,7 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", OUTPUT_ARCH(arm) ENTRY(_start) SEARCH_DIR(__LIBDIR) +INPUT(crt0.o) SECTIONS { /* Read-only sections, merged into text segment: */ diff --git a/Usermode/Libraries/crt0.o_src/crt0.armv7.S b/Usermode/Libraries/crt0.o_src/crt0.armv7.S index 77b9c2d6..157ba15d 100644 --- a/Usermode/Libraries/crt0.o_src/crt0.armv7.S +++ b/Usermode/Libraries/crt0.o_src/crt0.armv7.S @@ -3,12 +3,12 @@ @ C Runtime 0 @ - crt0.arm7.asm -.globl start -start: +.globl _start +_start: bl main push {r0} - ldr r0, = _crt0_exit_handler + ldr r0, =_crt0_exit_handler ldr r0, [r0] tst r0, r0 blxne r0 diff --git a/Usermode/Libraries/ld-acess.so_src/Makefile b/Usermode/Libraries/ld-acess.so_src/Makefile index a29dd4b6..2a7a1862 100644 --- a/Usermode/Libraries/ld-acess.so_src/Makefile +++ b/Usermode/Libraries/ld-acess.so_src/Makefile @@ -23,7 +23,7 @@ $(_XBIN): $(_OBJPREFIX)_stublib.o # Override .ao to look in the object prefix for the source -%.ao: %.asm +%.ao: %.$(ASSUFFIX) @echo [AS] -o $@ @mkdir -p $(dir $@) @$(AS) $(ASFLAGS) -o $@ $< @@ -34,5 +34,5 @@ $(_XBIN): $(_OBJPREFIX)_stublib.o $(_OBJPREFIX)%: %.h @echo [CPP] -o $@ @mkdir -p $(dir $@) - @$(CPP) $(CPPFLAGS) -P -D_ASM_ $< -o $@ + @$(CPP) $(CPPFLAGS) -P -D__ASM__ $< -o $@ diff --git a/Usermode/Libraries/ld-acess.so_src/_stublib.c b/Usermode/Libraries/ld-acess.so_src/_stublib.c index 6107c692..347b32ff 100644 --- a/Usermode/Libraries/ld-acess.so_src/_stublib.c +++ b/Usermode/Libraries/ld-acess.so_src/_stublib.c @@ -1,4 +1,6 @@ +#include + int _errno; #define SYSCALL0(name,num) void name(void){} @@ -11,3 +13,12 @@ int _errno; #include "arch/syscalls.s.h" +// libgcc functions +uint64_t __udivdi3(uint64_t Num, uint64_t Den){return 0;} +uint64_t __umoddi3(uint64_t Num, uint64_t Den){return 0;} + +int32_t __divsi3(int32_t Num, int32_t Den){return 0;} +int32_t __modsi3(int32_t Num, int32_t Den){return 0;} +uint32_t __udivsi3(uint32_t Num, uint32_t Den){return 0;} +uint32_t __umodsi3(uint32_t Num, uint32_t Den){return 0;} + diff --git a/Usermode/Libraries/ld-acess.so_src/arch/armv7.S.h b/Usermode/Libraries/ld-acess.so_src/arch/armv7.S.h new file mode 100644 index 00000000..75c56d8f --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/arch/armv7.S.h @@ -0,0 +1,79 @@ +// +// Acess2 ARMv7 - System Calls +// + +#include "../../../../Kernel/include/syscalls.h" + +.globl _start +.extern SoMain +_start: + push {r1,r2,r3} + bl SoMain + + mov r4, r0 + + pop {r0,r1,r2} + blx r4 + + b _exit + +@ Stupid GCC +.globl __ucmpdi2 +__ucmpdi2: + cmp r0, r2 + movmi r0, #0 + movmi pc, lr + movhi r0, #2 + movhi pc, lr + cmp r1, r2 + movmi r0, #0 + movmi pc, lr + movhi r0, #2 + movhi pc, lr + mov r0, #1 + mov pc, lr + +@ DEST +@ SRC +@_memcpy: +@ push rbp +@ mov rbp, rsp +@ +@ ; RDI - First Param +@ ; RSI - Second Param +@ mov rcx, rdx ; RDX - Third +@ rep movsb +@ +@ pop rbp +@ ret +@ +.globl _errno +_errno: .long 0 @ Placed in .text, to allow use of relative addressing + +.macro syscall0 _name, _num +.globl \_name +\_name: + svc #\_num + str r2, _errno + mov pc, lr +.endm + +#define SYSCALL0(_name,_num) syscall0 _name, _num +#define SYSCALL1(_name,_num) SYSCALL0(_name, _num) +#define SYSCALL2(_name,_num) SYSCALL0(_name, _num) +#define SYSCALL3(_name,_num) SYSCALL0(_name, _num) +#define SYSCALL4(_name,_num) SYSCALL0(_name, _num) +// TODO: 5/6 need special handling, because the args are on the stack +#define SYSCALL5(_name,_num) SYSCALL0(_name, _num) +#define SYSCALL6(_name,_num) SYSCALL0(_name, _num) + +// Override the clone syscall +#define _exit _exit_raw +#include "syscalls.s.h" +#undef _exit + +.globl _exit +_exit: + svc #0 + b . + diff --git a/Usermode/Libraries/ld-acess.so_src/arch/armv7.ld b/Usermode/Libraries/ld-acess.so_src/arch/armv7.ld new file mode 100644 index 00000000..efa4f19c --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/arch/armv7.ld @@ -0,0 +1,66 @@ +ENTRY(_start) +OUTPUT_FORMAT(elf32-littlearm) + +SECTIONS { + . = 0x00100000; + gLinkedBase = .; + . += SIZEOF_HEADERS; + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + } + + .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.so_src/lib.c b/Usermode/Libraries/ld-acess.so_src/lib.c index 150ae77c..d7a581e4 100644 --- a/Usermode/Libraries/ld-acess.so_src/lib.c +++ b/Usermode/Libraries/ld-acess.so_src/lib.c @@ -72,10 +72,47 @@ int file_exists(const char *filename) return 1; } -uint64_t __udivdi3(uint64_t Num, uint64_t Den) +uint64_t __divmod64(uint64_t Num, uint64_t Den, uint64_t *Rem) { uint64_t ret = 0, add = 1; + if( Den == 0 ) { + if(Rem) *Rem = 0; + return -1; + } + + // Find what power of two times Den is > Num + while( Num >= Den ) + { + Den <<= 1; + add <<= 1; + } + + // Search backwards + while( add > 1 ) + { + add >>= 1; + Den >>= 1; + // If the numerator is >= Den, subtract and add to return value + if( Num >= Den ) + { + ret += add; + Num -= Den; + } + } + if(Rem) *Rem = Num; + return ret; +} + +uint32_t __divmod32(uint32_t Num, uint32_t Den, uint32_t *Rem) +{ + uint32_t ret = 0, add = 1; + + if( Den == 0 ) { + if(Rem) *Rem = 0; + return -1; + } + // Find what power of two times Den is > Num while( Num >= Den ) { @@ -88,14 +125,47 @@ uint64_t __udivdi3(uint64_t Num, uint64_t Den) { add >>= 1; Den >>= 1; - // If the numerator is > Den, subtract and add to return value - if( Num > Den ) + // If the numerator is >= Den, subtract and add to return value + if( Num >= Den ) { ret += add; Num -= Den; } } -// if(Rem) *Rem = Num; + if(Rem) *Rem = Num; + return ret; +} + +uint64_t __udivdi3(uint64_t Num, uint64_t Den) +{ + return __divmod64(Num, Den, NULL); +} + +uint64_t __umoddi3(uint64_t Num, uint64_t Den) +{ + uint64_t ret; + __divmod64(Num, Den, &ret); + return ret; +} + +int32_t __divsi3(int32_t Num, int32_t Den) +{ + int32_t sign = 1; + if(Num < 0) { + Num = -Num; + sign = -sign; + } + if(Den < 0) { + Den = -Den; + sign = -sign; + } + return sign * __divmod32(Num, Den, NULL); +} + +uint32_t __umodsi3(uint32_t Num, uint32_t Den) +{ + uint32_t ret; + __divmod32(Num, Den, &ret); return ret; } diff --git a/Usermode/Libraries/libc.so_src/arch/armv7.S b/Usermode/Libraries/libc.so_src/arch/armv7.S new file mode 100644 index 00000000..23fd42e3 --- /dev/null +++ b/Usermode/Libraries/libc.so_src/arch/armv7.S @@ -0,0 +1,24 @@ +@ +@ Acess2 C Library +@ - By John Hodge (thePowersGang) +@ +@ arch/armv7.S +@ - ARMv7 specific code +.globl setjmp +setjmp: + @ RO: Buffer + stm r0, {r0-r14} + eor r0, r0 + mov pc, lr + +.globl longjmp +longjmp: + @ R0: Buffer + @ R1: Value + add r0, #8 + ldm r0, {r2-r14} + mov r0, r1 + tst r0, r0 + addeq r0, #1 + mov pc, lr @ Will return to after setjmp + diff --git a/Usermode/Libraries/libgcc.so_src/libgcc.c b/Usermode/Libraries/libgcc.so_src/libgcc.c index 8c5c13a0..df1832d1 100644 --- a/Usermode/Libraries/libgcc.so_src/libgcc.c +++ b/Usermode/Libraries/libgcc.so_src/libgcc.c @@ -18,111 +18,3 @@ void __stack_chk_fail() for(;;); } -// --- 64-Bit Math --- -/** - * \fn uint64_t __udivdi3(uint64_t Num, uint64_t Den) - * \brief Divide two 64-bit integers - */ -uint64_t __udivdi3(uint64_t Num, uint64_t Den) -{ - #if 0 - uint64_t ret = 0; - if(Den == 0) // Call Div by Zero Error - __asm__ __volatile__ ("int $0"); - - if(Den == 1) return Num; - if(Den == 2) return Num >> 1; - if(Den == 4) return Num >> 2; - if(Den == 8) return Num >> 3; - if(Den == 16) return Num >> 4; - if(Den == 32) return Num >> 5; - if(Den == 64) return Num >> 6; - if(Den == 128) return Num >> 7; - if(Den == 256) return Num >> 8; - - while(Num > Den) { - ret ++; - Num -= Den; - } - return ret; - #else - uint64_t P[2]; - uint64_t q; - int i; - - if(Den == 0) __asm__ __volatile__ ("int $0x0"); - // Common speedups - if(Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF) - return (uint32_t)Num / (uint32_t)Den; - if(Den == 1) return Num; - if(Den == 2) return Num >> 1; - if(Den == 16) return Num >> 4; - if(Num < Den) return 0; - if(Num < Den*2) return 1; - if(Num == Den*2) return 2; - - // Restoring division, from wikipedia - // http://en.wikipedia.org/wiki/Division_(digital) - P[0] = Num; P[1] = 0; - for( i = 64; i--; ) - { - // P <<= 1; - P[1] = (P[1] << 1) | (P[0] >> 63); - P[0] = P[0] << 1; - - // P -= Den << 64 - P[1] -= Den; - - // P >= 0 - if( !(P[1] & (1ULL<<63)) ) { - q |= (uint64_t)1 << (63-i); - } - else { - //q |= 0 << (63-i); - P[1] += Den; - } - } - - return q; - #endif -} - -/** - * \fn uint64_t __umoddi3(uint64_t Num, uint64_t Den) - * \brief Get the modulus of two 64-bit integers - */ -uint64_t __umoddi3(uint64_t Num, uint64_t Den) -{ - #if 0 - if(Den == 0) __asm__ __volatile__ ("int $0"); // Call Div by Zero Error - - if(Den == 1) return 0; - if(Den == 2) return Num & 0x01; - if(Den == 4) return Num & 0x03; - if(Den == 8) return Num & 0x07; - if(Den == 16) return Num & 0x0F; - if(Den == 32) return Num & 0x1F; - if(Den == 64) return Num & 0x3F; - if(Den == 128) return Num & 0x3F; - if(Den == 256) return Num & 0x7F; - - while(Num >= Den) Num -= Den; - - return Num; - #else - if(Den == 0) __asm__ __volatile__ ("int $0"); // Call Div by Zero Error - - // Speedups - if(Num < Den) return Num; - if(Num == Den) return 0; - if(Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF) - return (uint32_t)Num % (uint32_t)Den; - - // Speedups for common operations - if(Den == 1) return 0; - if(Den == 2) return Num & 0x01; - if(Den == 8) return Num & 0x07; - if(Den == 16) return Num & 0x0F; - return Num - __udivdi3(Num, Den) * Den; - #endif -} -- 2.20.1