tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / kernel / swap / writer / kernel_operations.h
1 /**
2  * @file writer/kernel_operations.h
3  * @author Alexander Aksenov <a.aksenov@samsung.com>
4  *
5  * @section LICENSE
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @section COPYRIGHT
22  *
23  * Copyright (C) Samsung Electronics, 2013
24  *
25  * @section DESCRIPTION
26  *
27  * Writer kernel operations.
28  */
29
30 /* Kernel functions wrap */
31
32 #ifndef __KERNEL_OPERATIONS_H__
33 #define __KERNEL_OPERATIONS_H__
34
35 #include <linux/kernel.h>
36 #include <linux/uaccess.h>
37 #include <asm/ptrace.h>
38
39 /* MESSAGES */
40
41 /** Prints debug message.*/
42 #define print_debug(msg, args...) \
43         printk(KERN_DEBUG "SWAP_WRITER DEBUG : " msg, ##args)
44 /** Prints info message.*/
45 #define print_msg(msg, args...)   \
46         printk(KERN_INFO "SWAP_WRITER : " msg, ##args)
47 /** Prints warning message.*/
48 #define print_warn(msg, args...)  \
49         printk(KERN_WARNING "SWAP_WRITER WARNING : " msg, ##args)
50 /** Prints error message.*/
51 #define print_err(msg, args...)   \
52         printk(KERN_ERR "SWAP_WRITER ERROR : " msg, ##args)
53 /** Prints critical error message.*/
54 #define print_crit(msg, args...)  \
55         printk(KERN_CRIT "SWAP_WRITER CRITICAL : " msg, ##args)
56
57 /* ARCH-DEPENDED OPERATIONS */
58
59
60 /* Regs manipulations */
61 #if defined(CONFIG_ARM)
62
63 #define get_regs_ip(regs)           (regs->ARM_pc)    /**< Get pc reg. */
64 #define get_regs_ret_func(regs)     (regs->ARM_lr)    /**< Get lr reg. */
65 #define get_regs_ret_val(regs)      (regs->ARM_r0)    /**< Get ret val. */
66 #define get_regs_stack_ptr(regs)    (regs->ARM_sp)    /**< Get stack pointer. */
67
68 #elif defined(CONFIG_X86_32)
69
70 #define get_regs_ip(regs)           (regs->ip - 1)    /**< Get ip. */
71 #define get_regs_ret_val(regs)      (regs->ax)        /**< Get ret val. */
72 #define get_regs_stack_ptr(regs)    (regs->sp)        /**< Get stack pointer. */
73
74 static inline u32 get_regs_ret_func(struct pt_regs *regs)
75 {
76         u32 *sp, addr = 0;
77
78         if (user_mode(regs)) {
79                 sp = (u32 *)regs->sp;
80                 if (get_user(addr, sp))
81                         printk(KERN_INFO "failed to dereference a pointer, sp=%p, "
82                                "pc=%lx\n", sp, get_regs_ip(regs));
83         } else {
84                 sp = (u32 *)kernel_stack_pointer(regs);
85                 addr = *sp;
86         }
87
88         return addr;
89 }
90
91 #endif /* CONFIG_arch */
92
93 #endif /* __KERNEL_OPERATIONS_H__ */