-#PREFIX := x86_64-pc-elf
-PREFIX := x86_64-none-elf
-
-CC := $(PREFIX)-gcc
-LD := $(PREFIX)-ld
-DISASM = $(PREFIX)-objdump -d -M x86-64 -S
+TRIPLET = x86_64-pc-acess2
KERNEL_CFLAGS := -mcmodel=kernel -nostdlib -mno-red-zone -Wall -mno-sse
DYNMOD_CFLAGS := -mcmodel=small -fPIC -mno-red-zone -mno-sse
BFD := i686
else ifeq ($(ARCH),x86_64)
BFD := x86_64
+else ifeq ($(ARCH),armv7)
+ BFD := arm
else
$(error No BFD translation for $(ARCH) in Externals/config.mk)
endif
@@ -167,1 +167,3 @@
i[3-7]86-*-nto-qnx*) targ_emul=i386nto ;;
+i[3-7]86-*-acess2*) targ_emul=acess2_i386 ;;
-+x86_64-*-acess2*) targ_emul=acess2_amd64 ;;
++x86_64-*-acess2*) targ_emul=acess2_amd64 ;;
SCRIPT_NAME=elf
-OUTPUT_FORMAT=elf64-x86_64
+OUTPUT_FORMAT=elf64-x86-64
TEXT_START_ADDR=0x00400000
MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
-TEMPLATE_NAME=elf64
+ELFSIZE=64
+TEMPLATE_NAME=elf32
-ARCH=x86_64
+ARCH="i386:x86-64"
MACHINE=
NOP=0x90909090
GENERATE_SHLIB_SCRIPT=yes
+ ;;
*-*-darwin*)
-@@ -1192,2 +1196,7 @@
+@@ -1192,2 +1196,12 @@
;;
+i[3-7]86-*-acess2*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h newlib-stdint.h acess2.h"
+ tmake_file="i386/t-i386elf i386/t-crtstuff t-svr4"
+ use_fixproto=yes
++ ;;
++x86_64-*-acess2*)
++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h acess2.h"
++ tmake_file="i386/t-i386elf i386/t-crtstuff t-svr4"
++ use_fixproto=yes
+ ;;
i[34567]86-*-elf*)
extern void Debug_PutCharDebug(char ch);
extern void Debug_PutStringDebug(const char *Str);
+extern void __AtomicTestSetLoop(Uint *Ptr, Uint Value);
+
#endif
#define MM_USER_MIN 0x00000000##00010000
#define USER_LIB_MAX 0x00007000##00000000
+#define MM_USER_MAX USER_LIB_MAX
#define USER_STACK_PREALLOC 0x00000000##00002000 // 8 KiB
#define USER_STACK_SZ 0x00000000##00020000 // 64 KiB
#define USER_STACK_TOP 0x00008000##00000000
#endif
}
+void __AtomicTestSetLoop(Uint *Ptr, Uint Value)
+{
+ __ASM__(
+ "1:\n\t"
+ "xor %%eax, %%eax;\n\t"
+ "lock cmpxchg %0, (%1);\n\t" // if( Ptr==0 ) { ZF=1; Ptr=Value } else { ZF=0; _=Ptr }
+ "jnz 1b;\n\t"
+ :: "r"(Value), "r"(Ptr)
+ : "eax" // EAX clobbered
+ );
+}
+
// === DEBUG IO ===
#if USE_GDB_STUB
void initGdbSerial(void)
#define INVLPG_ALL() __asm__ __volatile__ ("mov %cr3,%rax;\n\tmov %rax,%cr3;")
#define INVLPG_GLOBAL() __asm__ __volatile__ ("mov %cr4,%rax;\n\txorl $0x80, %eax;\n\tmov %rax,%cr4;\n\txorl $0x80, %eax;\n\tmov %rax,%cr4")
+// TODO: INVLPG_ALL is expensive
+#define GET_TEMP_MAPPING(cr3) do { \
+ __ASM__("cli"); \
+ __AtomicTestSetLoop( (Uint *)TMPCR3(), (cr3) | 3 ); \
+ INVLPG_ALL(); \
+} while(0)
+#define REL_TEMP_MAPPING() do { \
+ TMPCR3() = 0; \
+ __ASM__("sti"); \
+} while(0)
+
// === CONSTS ===
//tPAddr * const gaPageTable = MM_FRACTAL_BASE;
void MM_int_DumpTablesEnt(tVAddr RangeStart, size_t Length, tPAddr Expected);
//void MM_DumpTables(tVAddr Start, tVAddr End);
int MM_GetPageEntryPtr(tVAddr Addr, BOOL bTemp, BOOL bAllocate, BOOL bLargePage, tPAddr **Pointer);
+tPAddr MM_GetPageFromAS(tProcess *Process, volatile const void *Addr);
int MM_MapEx(volatile void *VAddr, tPAddr PAddr, BOOL bTemp, BOOL bLarge);
// int MM_Map(tVAddr VAddr, tPAddr PAddr);
void MM_Unmap(tVAddr VAddr);
int MM_GetPageEntry(tVAddr Addr, tPAddr *Phys, Uint *Flags);
// === GLOBALS ===
-tMutex glMM_TempFractalLock;
tShortSpinlock glMM_ZeroPage;
tPAddr gMM_ZeroPage;
return (*ptr & PADDR_MASK) | (Addr & 0xFFF);
}
+/**
+ * \brief Get the address of a page from another addres space
+ * \return Refenced physical address (or 0 on error)
+ */
+tPAddr MM_GetPageFromAS(tProcess *Process, volatile const void *Addr)
+{
+ GET_TEMP_MAPPING(Process->MemState.CR3);
+ tPAddr ret = 0;
+ tPAddr *ptr;
+ if(MM_GetPageEntryPtr((tVAddr)Addr, 1,0,0, &ptr) == 0) // Temp, NoAlloc, NotLarge
+ {
+ if( *ptr & 1 )
+ {
+ ret = (*ptr & ~0xFFF) | ((tVAddr)Addr & 0xFFF);
+ MM_RefPhys( ret );
+ }
+ }
+ REL_TEMP_MAPPING();
+ return ret;
+}
+
/**
* \brief Sets the flags on a page
*/
return 0;
}
+void *MM_MapTempFromProc(tProcess *Process, const void *VAddr)
+{
+ // Get paddr
+ tPAddr paddr = MM_GetPageFromAS(Process, VAddr);
+ if( paddr == 0 )
+ return NULL;
+ return MM_MapTemp(paddr);
+}
+
void MM_FreeTemp(void *Ptr)
{
MM_Deallocate(Ptr);
if(!ret) return 0;
// #2 Alter the fractal pointer
- Mutex_Acquire(&glMM_TempFractalLock);
- TMPCR3() = ret | 3;
- INVLPG_ALL();
+ GET_TEMP_MAPPING(ret);
// #3 Set Copy-On-Write to all user pages
if( Threads_GetPID() != 0 && !bNoUserCopy )
// MAGIC_BREAK();
// #7 Return
- TMPCR3() = 0;
- INVLPG_ALL();
- Mutex_Release(&glMM_TempFractalLock);
+ REL_TEMP_MAPPING();
// Log("MM_Clone: RETURN %P", ret);
return ret;
}
int i;
// #1 Set temp fractal to PID0
- Mutex_Acquire(&glMM_TempFractalLock);
- TMPCR3() = ((tPAddr)gInitialPML4 - KERNEL_BASE) | 3;
- INVLPG_ALL();
+ GET_TEMP_MAPPING( ((tPAddr)gInitialPML4 - KERNEL_BASE) );
// #2 Scan for a free stack addresss < 2^47
for(ret = 0x100000; ret < (1ULL << 47); ret += KERNEL_STACK_SIZE)
if( !(*ptr & 1) ) break;
}
if( ret >= (1ULL << 47) ) {
- Mutex_Release(&glMM_TempFractalLock);
+ REL_TEMP_MAPPING();
return 0;
}
MM_FreeTemp(tmp_addr);
}
- TMPCR3() = 0;
- Mutex_Release(&glMM_TempFractalLock);
+ REL_TEMP_MAPPING();
return ret + i*0x1000;
}
#include <string.h>
#include "common.h"
#include <ctype.h>
+#include <inttypes.h>
// === CONSTANTS ===
#define DEFAULT_SHELL "/Acess/SBin/login"
// Log spawn header
{
char buffer[101];
- size_t len = snprintf(buffer, 100, "[%lli] init spawning ", _SysTimestamp());
+ size_t len = snprintf(buffer, 100, "[%"PRIi64"] init spawning ", _SysTimestamp());
_SysWrite(out, buffer, len);
for( int i = 0; Program->Command[i]; i ++ )
{
utest generate_exp utest-build utest-run:
@echo > /dev/null
-$(OUTPUTDIR)Libs/%.o: %.c Makefile
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS) -c $< -o $@
$(OUTPUTDIR)Libs/%S.o: %S.c Makefile
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@ -fPIC
+$(OUTPUTDIR)Libs/%.o: %.c Makefile
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -c $< -o $@
$(OUTPUTDIR)Libs/%.o: $(ARCHDIR)-%.S
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
--- /dev/null
+.section .init
+.global _init
+.type _init, @function
+_init:
+ push %rbp
+ mov %rsp, %rbp
+ /* gcc will nicely put the contents of crtbegin.o's .init section here. */
+
+.section .fini
+.global _fini
+.type _fini, @function
+_fini:
+ push %rbp
+ mov %rsp, %rbp
+ /* gcc will nicely put the contents of crtbegin.o's .fini section here. */
--- /dev/null
+.section .init
+ /* gcc will nicely put the contents of crtend.o's .init section here. */
+ pop %rbp
+ ret
+
+.section .fini
+ /* gcc will nicely put the contents of crtend.o's .fini section here. */
+ pop %rbp
+ ret
int elf_doRelocate_386(tElfRelocInfo *Info, uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int bRela)
{
const Elf32_Sym *sym = &Info->symtab[ ELF32_R_SYM(r_info) ];
- void *symval = (void*)sym->st_value;
+ void *symval = (void*)(intptr_t)sym->st_value;
size_t size = sym->st_size;
TRACE("%i '%s'", ELF32_R_TYPE(r_info), Info->strtab + sym->st_name);
switch( ELF32_R_TYPE(r_info) )
int elf_doRelocate_arm(tElfRelocInfo *Info, uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int bRela)
{
const Elf32_Sym *sym = &Info->symtab[ ELF32_R_SYM(r_info) ];
- void *symval = (void*)sym->st_value;
+ void *symval = (void*)(intptr_t)sym->st_value;
size_t size = sym->st_size;
TRACE("%i '%s'", ELF32_R_TYPE(r_info), Info->strtab + sym->st_name);
uintptr_t val = (uintptr_t)symval;
TRACE("*sym = {value:0x%x,size:0x%x,info:0x%x,other:0x%x,shndx:%i}",
sym->st_value, sym->st_size, sym->st_info,
sym->st_other, sym->st_shndx);
- if(Addr) *Addr = (void*)( sym->st_value );
+ if(Addr) *Addr = (void*)(intptr_t)( sym->st_value );
if(Size) *Size = sym->st_size;
if(Binding) *Binding = ELF32_ST_BIND(sym->st_info);
if(Type) *Type = ELF32_ST_TYPE(sym->st_info);
#include <stdint.h>
-#define PRId64 "lld"
-#define PRIdLEAST64 "lld"
-#define PRIdFAST64 "lld"
+#if INT64MAX == LONG_MAX
+# define _PRI64 "l"
+#else
+# define _PRI64 "ll"
+#endif
+
+#define PRId64 _PRI64"ld"
+#define PRIdLEAST64 _PRI64"ld"
+#define PRIdFAST64 _PRI64"ld"
#define PRIdMAX
#define PRIdPTR
-#define PRIi64 "lli"
+#define PRIi64 _PRI64"i"
#define PRIiLEAST64
#define PRIiFAST64
#define PRIiMAX
#define PRIiPTR
-#define PRIx64 "llx"
+#define PRIx64 _PRI64"i"
#endif
CRTI := $(OUTPUTDIR)Libs/crti.o
CRTBEGIN := $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o 2>/dev/null)
+CRTBEGINS := $(shell $(CC) $(CFLAGS) -print-file-name=crtbeginS.o 2>/dev/null)
CRT0 := $(OUTPUTDIR)Libs/crt0.o
CRT0S := $(OUTPUTDIR)Libs/crt0S.o
CRTEND := $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o 2>/dev/null)
+CRTENDS := $(shell $(CC) $(CFLAGS) -print-file-name=crtendS.o 2>/dev/null)
CRTN := $(OUTPUTDIR)Libs/crtn.o
LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name 2>/dev/null)