#ifndef _SYSCALLS_H
#define _SYSCALLS_H
-enum eSyscalls {
";
$i = 0;
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";
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;
$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);
#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[] = {
";
print HEADER "
\t\"\"
};
+#endif
#endif
";
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
#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",
""
};
+#endif
#endif
-include Makefile.cfg
-.PHONY: all clean
+.PHONY: all clean SyscallList all-user
SUBMAKE = $(MAKE) --no-print-directory
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-%:
ifeq ($(ARCHDIR),armv7)
MODULES += Input/PS2KbMouse
MODULES += armv7/GIC
+MODULES += Filesystems/InitRD
endif
MODULES += IPStack # So the other modules are loaded before it
EOF;
+$ACESSDIR = getenv("ACESSDIR");
+$ARCH = getenv("ARCH");
+
$gInputFile = $argv[1];
$gOutputFile = $argv[2];
$gDepFile = ($argc > 3 ? $argv[3] : false);
foreach($lines as $line)
{
$line = trim($line);
+ // Directory
if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
{
$new = array($matches[1], array());
$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]);
function ProcessFolder($prefix, $items)
{
global $gOutput;
+ global $ACESSDIR, $ARCH;
foreach($items as $i=>$item)
{
if(is_array($item[1]))
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";
# 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 $@
[email protected]
+
+-include files.$(ARCH).c.dep
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"
}
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;
}
// === 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;
}
// 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);
}
}
@$(CC) $(CFLAGS) -o $@ -c $<
-$(_OBJPREFIX)%.ao: %.asm
+$(_OBJPREFIX)%.ao: %.$(ASSUFFIX)
@echo [AS] -o $@
@mkdir -p $(dir $@)
@$(AS) $(ASFLAGS) -o $@ $<
+ @$(AS) $(ASFLAGS) -o $@.dep $< -M
#$(OUTPUTDIR)Libs/libld-acess.so:
# @make -C $(ACESSDIR)/Usermode/Libraries/ld-acess.so_src/
OUTPUT_ARCH(arm)
ENTRY(_start)
SEARCH_DIR(__LIBDIR)
+INPUT(crt0.o)
SECTIONS
{
/* Read-only sections, merged into text segment: */
@ 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
# Override .ao to look in the object prefix for the source
-%.ao: %.asm
+%.ao: %.$(ASSUFFIX)
@echo [AS] -o $@
@mkdir -p $(dir $@)
@$(AS) $(ASFLAGS) -o $@ $<
$(_OBJPREFIX)%: %.h
@echo [CPP] -o $@
@mkdir -p $(dir $@)
- @$(CPP) $(CPPFLAGS) -P -D_ASM_ $< -o $@
+ @$(CPP) $(CPPFLAGS) -P -D__ASM__ $< -o $@
+#include <stdint.h>
+
int _errno;
#define SYSCALL0(name,num) void name(void){}
#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;}
+
--- /dev/null
+//
+// 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 .
+
--- /dev/null
+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 = .;
+}
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 )
{
{
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;
}
--- /dev/null
+@
+@ 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
+
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
-}