From: John Hodge Date: Thu, 24 Mar 2011 08:02:58 +0000 (+0800) Subject: Usermode/ld-acess - x86_64 support X-Git-Tag: rel0.10~141 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5ce8b1a0af07fdba89c8d72c8d6c086e91076a3c;p=tpg%2Facess2.git Usermode/ld-acess - x86_64 support --- diff --git a/Usermode/Libraries/ld-acess.so_src/Makefile b/Usermode/Libraries/ld-acess.so_src/Makefile index 64a120c2..87b82130 100644 --- a/Usermode/Libraries/ld-acess.so_src/Makefile +++ b/Usermode/Libraries/ld-acess.so_src/Makefile @@ -9,10 +9,9 @@ OBJ += arch/$(ARCHDIR).ao BIN = ld-acess.so EXTRABIN := libld-acess.so -CFLAGS = -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector +CFLAGS = -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC CFLAGS += $(CPPFLAGS) -ASFLAGS = -felf -LDFLAGS = -T link.ld -Map map.txt --export-dynamic +LDFLAGS = -T arch/$(ARCHDIR).ld -Map map.txt --export-dynamic include ../Makefile.tpl @@ -27,6 +26,8 @@ $(_XBIN): $(_BIN) @mkdir -p $(dir $@) @$(AS) $(ASFLAGS) -o $@ $< +.PRECIOUS: $(OBJ:%.ao=%.asm) + # Preprocessing objects if needed $(_OBJPREFIX)%: %.h @echo [CPP] -o $@ diff --git a/Usermode/Libraries/ld-acess.so_src/arch/x86.ld b/Usermode/Libraries/ld-acess.so_src/arch/x86.ld new file mode 100644 index 00000000..3ab4f1a9 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/arch/x86.ld @@ -0,0 +1,66 @@ +ENTRY(SoMain) +OUTPUT_FORMAT(elf32-i386) + +SECTIONS { + . = 0xBBFF0000; + 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/arch/x86_64.asm.h b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h new file mode 100644 index 00000000..a21bf180 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.asm.h @@ -0,0 +1,173 @@ +; ======================== +; AcssMicro - System Calls +; ======================== + +%include "../../../Kernel/include/syscalls.inc.asm" + +[bits 64] + +[section .text] +; DEST +; SRC +_memcpy: + push rbp + mov rbp, rsp + push rdi + push rsi ; // DI and SI must be maintained, CX doesn't + + mov rcx, [rbp+4*8] + mov rsi, [rbp+3*8] + mov rdi, [rbp+2*8] + rep movsb + + pop rsi + pop rdi + pop rbp + ret + +[global _errno] +_errno: dw 0 ; Placed in .text, to allow use of relative addressing + +#define SYSCALL0(_name,_num) SYSCALL0 _name, _num +#define SYSCALL1(_name,_num) SYSCALL1 _name, _num +#define SYSCALL2(_name,_num) SYSCALL2 _name, _num +#define SYSCALL3(_name,_num) SYSCALL3 _name, _num +#define SYSCALL4(_name,_num) SYSCALL4 _name, _num +#define SYSCALL5(_name,_num) SYSCALL5 _name, _num +#define SYSCALL6(_name,_num) SYSCALL6 _name, _num + +;%define SYSCALL_OP jmp 0xCFFF0000 +%define SYSCALL_OP int 0xAC + +; System Call - No Arguments +%macro SYSCALL0 2 +[global %1:func] +%1: + push rbx + mov eax, %2 + SYSCALL_OP + mov [DWORD rel _errno], ebx + pop rbx + ret +%endmacro + +%macro _SYSCALL_HEAD 2 +[global %1:func] +%1: + push rbp + mov rbp, rsp + push rbx + mov eax, %2 +%endmacro +%macro _SYSCALL_TAIL 0 + mov [DWORD rel _errno], ebx + pop rbx + pop rbp + ret +%endmacro + +; System Call - 1 Argument +%macro SYSCALL1 2 +_SYSCALL_HEAD %1, %2 + mov rbx, [rbp+2*8] + SYSCALL_OP +_SYSCALL_TAIL +%endmacro + +; System Call - 2 Arguments +%macro SYSCALL2 2 +_SYSCALL_HEAD %1, %2 + mov rbx, [rbp+2*8] + mov rcx, [rbp+3*8] + SYSCALL_OP +_SYSCALL_TAIL +%endmacro + +; System Call - 3 Arguments +%macro SYSCALL3 2 +_SYSCALL_HEAD %1, %2 + mov rbx, [rbp+2*8] + mov rcx, [rbp+3*8] + mov rdx, [rbp+4*8] + SYSCALL_OP +_SYSCALL_TAIL +%endmacro + +; System Call - 4 Arguments +%macro SYSCALL4 2 +_SYSCALL_HEAD %1, %2 + push rdi + mov rbx, [rbp+2*8] + mov rcx, [rbp+3*8] + mov rdx, [rbp+4*8] + mov rdi, [rbp+5*8] + SYSCALL_OP + pop rdi +_SYSCALL_TAIL +%endmacro + +; System Call - 5 Arguments +%macro SYSCALL5 2 +_SYSCALL_HEAD %1, %2 + push rdi + push rsi + mov rbx, [rbp+2*8] + mov rcx, [rbp+3*8] + mov rdx, [rbp+4*8] + mov rdi, [rbp+5*8] + mov rsi, [rbp+6*8] + SYSCALL_OP + pop rsi + pop rdi +_SYSCALL_TAIL +%endmacro + +; System Call - 6 Arguments +%macro SYSCALL6 2 +_SYSCALL_HEAD %1, %2 + push rdi + push rsi + mov rbx, [rbp+2*8] + mov rcx, [rbp+3*8] + mov rdx, [rbp+4*8] + mov rdi, [rbp+5*8] + mov rsi, [rbp+6*8] + mov rbp, [rbp+7*8] + SYSCALL_OP + pop rsi + pop rdi +_SYSCALL_TAIL +%endmacro + +; // Override the clone syscall +#define clone _clone_raw +#include "syscalls.s.h" +#undef clone + +[global clone:func] +clone: + push rbp + mov rbp, rsp + push rbx + + mov rbx, [rbp+3*8] ; Get new stack pointer + + ; Check if the new stack is being used + test rbx, rbx + jz .doCall + ; Quick hack, just this stack frame + mov rax, [rbp+1*8] + mov [rbx-1*8], rax ; Return + mov [rbx-2*8], rbx ; EBP + and QWORD [rbx-3*8], BYTE 0 ; EBX + sub rbx, 3*8 +.doCall: + mov eax, SYS_CLONE + mov rcx, rbx ; Stack + mov rbx, [rbp+2*8] ; Flags + SYSCALL_OP + mov [rel _errno], ebx + pop rbx + pop rbp + ret + diff --git a/Usermode/Libraries/ld-acess.so_src/arch/x86_64.ld b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.ld new file mode 100644 index 00000000..5dd69023 --- /dev/null +++ b/Usermode/Libraries/ld-acess.so_src/arch/x86_64.ld @@ -0,0 +1,66 @@ +ENTRY(SoMain) +OUTPUT_FORMAT(elf64-x86-64) + +SECTIONS { + . = 0x00200000; + 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/link.ld b/Usermode/Libraries/ld-acess.so_src/link.ld deleted file mode 100644 index 3ab4f1a9..00000000 --- a/Usermode/Libraries/ld-acess.so_src/link.ld +++ /dev/null @@ -1,66 +0,0 @@ -ENTRY(SoMain) -OUTPUT_FORMAT(elf32-i386) - -SECTIONS { - . = 0xBBFF0000; - 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 = .; -}