1/* sections */ 2 3 4#include <minix/config.h> 5#include <minix/const.h> 6#include <machine/asm.h> 7#include <machine/interrupt.h> 8#include <machine/vm.h> 9#include "archconst.h" 10#include "kernel/const.h" 11#include "sconst.h" 12#include <machine/multiboot.h> 13 14 15/*===========================================================================*/ 16/* copy_msg_from_user */ 17/*===========================================================================*/ 18/* 19 * int copy_msg_from_user(message * user_mbuf, message * dst); 20 * 21 * Copies a message of 64 bytes from user process space to a kernel buffer. This 22 * function assumes that the process address space is installed (ttbr loaded). 23 * 24 * This function from the callers point of view either succeeds or returns an 25 * error which gives the caller a chance to respond accordingly. In fact it 26 * either succeeds or if it generates a pagefault, general protection or other 27 * exception, the trap handler has to redirect the execution to 28 * __user_copy_msg_pointer_failure where the error is reported to the caller 29 * without resolving the pagefault. It is not kernel's problem to deal with 30 * wrong pointers from userspace and the caller should return an error to 31 * userspace as if wrong values or request were passed to the kernel 32 */ 33ENTRY(copy_msg_from_user) 34 push {r4-r10, lr} 35 /* load the source pointer */ 36 mov r9, r0 37 /* load the destination pointer */ 38 mov r10, r1 39 /* do the copy, first 32 bytes */ 40 ldm r9, {r0-r7} 41 stm r10, {r0-r7} 42 43 /* next 32 bytes */ 44 add r9, r9, #32 45 add r10, r10, #32 46 ldm r9, {r0-r7} 47 stm r10, {r0-r7} 48 49LABEL(__copy_msg_from_user_end) 50 pop {r4-r10, lr} 51 mov r0, #0 52 bx lr 53 54/*===========================================================================*/ 55/* copy_msg_to_user */ 56/*===========================================================================*/ 57/* 58 * void copy_msg_to_user(message * src, message * user_mbuf); 59 * 60 * Copies a message of 64 bytes to user process space from a kernel buffer. 61 * 62 * All the other copy_msg_from_user() comments apply here as well! 63 */ 64ENTRY(copy_msg_to_user) 65 push {r4-r10, lr} 66 /* load the source pointer */ 67 mov r9, r0 68 /* load the destination pointer */ 69 mov r10, r1 70 /* do the copy, first 32 bytes */ 71 ldm r9, {r0-r7} 72 stm r10, {r0-r7} 73 74 /* next 32 bytes */ 75 add r9, r9, #32 76 add r10, r10, #32 77 ldm r9, {r0-r7} 78 stm r10, {r0-r7} 79 80LABEL(__copy_msg_to_user_end) 81 pop {r4-r10, lr} 82 mov r0, #0 83 bx lr 84 85/* 86 * if a function from a selected set of copies from or to userspace fails, it is 87 * because of a wrong pointer supplied by the userspace. We have to clean up and 88 * and return -1 to indicated that something wrong has happend. The place it was 89 * called from has to handle this situation. The exception handler redirect us 90 * here to continue, clean up and report the error 91 */ 92ENTRY(__user_copy_msg_pointer_failure) 93 pop {r4-r10, lr} 94 mov r0, #-1 95 bx lr 96 97ENTRY(intr_enable) 98ENTRY(interrupts_enable) 99 dsb 100 cpsie if 101 bx lr 102 103ENTRY(intr_disable) 104ENTRY(interrupts_disable) 105 dsb 106 cpsid if 107 bx lr 108