From c15925a24efe14f437d8a2699500241a58fdc8f9 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 17 Aug 2018 21:41:21 +0200 Subject: cleanup and working on fifo pipes --- asm/syscall.h | 11 +++++++++++ asm/syscall.s | 5 ----- asm/usermode.h | 7 +++++++ asm/usermode.s | 15 +++++++++------ 4 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 asm/syscall.h create mode 100644 asm/usermode.h (limited to 'asm') diff --git a/asm/syscall.h b/asm/syscall.h new file mode 100644 index 0000000..2cadce4 --- /dev/null +++ b/asm/syscall.h @@ -0,0 +1,11 @@ +/* + * Issue a System Call from Ring 3 / User Space + * + * Accepts up to 3 parameters. + * Check syscalls.h for details. + */ + +uint32_t syscall(uint32_t code, + uint32_t param_1, + uint32_t param_2, + uint32_t param_3); diff --git a/asm/syscall.s b/asm/syscall.s index 8860d89..388b6fa 100644 --- a/asm/syscall.s +++ b/asm/syscall.s @@ -1,10 +1,5 @@ .global syscall -// call from c with 4 x 32bit params -// syscall number, p1,p2,p3,p4 - -// TODO: push stack frame? - syscall: push %ebx // preserve (sysV abi convnetion) diff --git a/asm/usermode.h b/asm/usermode.h new file mode 100644 index 0000000..9b76db3 --- /dev/null +++ b/asm/usermode.h @@ -0,0 +1,7 @@ +/* + * Switch to User Mode and returin to function given by pointer + * provide the address of a void func() that will be called without + * any params. + */ + +void usermode(uint32_t func); diff --git a/asm/usermode.s b/asm/usermode.s index acf4b04..67eca04 100644 --- a/asm/usermode.s +++ b/asm/usermode.s @@ -1,8 +1,9 @@ -.global asm_usermode -.extern userfunc +.global usermode -# pass address to func to exec (TODO) -asm_usermode: +usermode: + + mov 0x4(%esp),%edx //get adress of passed : void func() + //to be called in ring 3 // 0x23 is user data segment (|2 low bits) // 0x1b is user code segment (|2 low bits) @@ -13,6 +14,7 @@ asm_usermode: mov %ax, %es mov %ax, %fs mov %ax, %gs + // ss is handled by iret mov %esp, %eax @@ -25,10 +27,11 @@ asm_usermode: //mov $0x200, %eax //push %eax // eflags image pushl $0x1B // return code segment selector - push $userfunc // return instruction pointer + push %edx // return instruction pointer + iret - jmp . // will never be reached? + jmp . // never to be reached -- cgit v1.2.3