Skip to content

Commit fe54616

Browse files
author
Yoshinori Sato
committed
h8300: process helpers
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
1 parent 06706c9 commit fe54616

4 files changed

Lines changed: 674 additions & 0 deletions

File tree

‎arch/h8300/kernel/process.c‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* linux/arch/h8300/kernel/process.c
3+
*
4+
* Yoshinori Sato <ysato@users.sourceforge.jp>
5+
*
6+
* Based on:
7+
*
8+
* linux/arch/m68knommu/kernel/process.c
9+
*
10+
* Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
11+
* Kenneth Albanowski <kjahds@kjahds.com>,
12+
* The Silver Hammer Group, Ltd.
13+
*
14+
* linux/arch/m68k/kernel/process.c
15+
*
16+
* Copyright (C) 1995 Hamish Macdonald
17+
*
18+
* 68060 fixes by Jesper Skov
19+
*/
20+
21+
/*
22+
* This file handles the architecture-dependent parts of process handling..
23+
*/
24+
25+
#include <linux/errno.h>
26+
#include <linux/module.h>
27+
#include <linux/sched.h>
28+
#include <linux/kernel.h>
29+
#include <linux/mm.h>
30+
#include <linux/smp.h>
31+
#include <linux/stddef.h>
32+
#include <linux/unistd.h>
33+
#include <linux/ptrace.h>
34+
#include <linux/user.h>
35+
#include <linux/interrupt.h>
36+
#include <linux/reboot.h>
37+
#include <linux/fs.h>
38+
#include <linux/slab.h>
39+
#include <linux/rcupdate.h>
40+
41+
#include <asm/uaccess.h>
42+
#include <asm/traps.h>
43+
#include <asm/setup.h>
44+
#include <asm/pgtable.h>
45+
46+
void (*pm_power_off)(void) = NULL;
47+
EXPORT_SYMBOL(pm_power_off);
48+
49+
asmlinkage void ret_from_fork(void);
50+
asmlinkage void ret_from_kernel_thread(void);
51+
52+
/*
53+
* The idle loop on an H8/300..
54+
*/
55+
void arch_cpu_idle(void)
56+
{
57+
local_irq_enable();
58+
__asm__("sleep");
59+
}
60+
61+
void machine_restart(char *__unused)
62+
{
63+
local_irq_disable();
64+
__asm__("jmp @@0");
65+
}
66+
67+
void machine_halt(void)
68+
{
69+
local_irq_disable();
70+
__asm__("sleep");
71+
for (;;)
72+
;
73+
}
74+
75+
void machine_power_off(void)
76+
{
77+
local_irq_disable();
78+
__asm__("sleep");
79+
for (;;)
80+
;
81+
}
82+
83+
void show_regs(struct pt_regs *regs)
84+
{
85+
show_regs_print_info(KERN_DEFAULT);
86+
87+
pr_notice("\n");
88+
pr_notice("PC: %08lx Status: %02x\n",
89+
regs->pc, regs->ccr);
90+
pr_notice("ORIG_ER0: %08lx ER0: %08lx ER1: %08lx\n",
91+
regs->orig_er0, regs->er0, regs->er1);
92+
pr_notice("ER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx\n",
93+
regs->er2, regs->er3, regs->er4, regs->er5);
94+
pr_notice("ER6' %08lx ", regs->er6);
95+
if (user_mode(regs))
96+
printk("USP: %08lx\n", rdusp());
97+
else
98+
printk("\n");
99+
}
100+
101+
void flush_thread(void)
102+
{
103+
}
104+
105+
int copy_thread(unsigned long clone_flags,
106+
unsigned long usp, unsigned long topstk,
107+
struct task_struct *p)
108+
{
109+
struct pt_regs *childregs;
110+
111+
childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
112+
113+
if (unlikely(p->flags & PF_KTHREAD)) {
114+
memset(childregs, 0, sizeof(struct pt_regs));
115+
childregs->retpc = (unsigned long) ret_from_kernel_thread;
116+
childregs->er4 = topstk; /* arg */
117+
childregs->er5 = usp; /* fn */
118+
} else {
119+
*childregs = *current_pt_regs();
120+
childregs->er0 = 0;
121+
childregs->retpc = (unsigned long) ret_from_fork;
122+
p->thread.usp = usp ?: rdusp();
123+
}
124+
p->thread.ksp = (unsigned long)childregs;
125+
126+
return 0;
127+
}
128+
129+
unsigned long thread_saved_pc(struct task_struct *tsk)
130+
{
131+
return ((struct pt_regs *)tsk->thread.esp0)->pc;
132+
}
133+
134+
unsigned long get_wchan(struct task_struct *p)
135+
{
136+
unsigned long fp, pc;
137+
unsigned long stack_page;
138+
int count = 0;
139+
140+
if (!p || p == current || p->state == TASK_RUNNING)
141+
return 0;
142+
143+
stack_page = (unsigned long)p;
144+
fp = ((struct pt_regs *)p->thread.ksp)->er6;
145+
do {
146+
if (fp < stack_page+sizeof(struct thread_info) ||
147+
fp >= 8184+stack_page)
148+
return 0;
149+
pc = ((unsigned long *)fp)[1];
150+
if (!in_sched_functions(pc))
151+
return pc;
152+
fp = *(unsigned long *) fp;
153+
} while (count++ < 16);
154+
return 0;
155+
}
156+
157+
/* generic sys_clone is not enough registers */
158+
asmlinkage int sys_clone(unsigned long __user *args)
159+
{
160+
unsigned long clone_flags;
161+
unsigned long newsp;
162+
uintptr_t parent_tidptr;
163+
uintptr_t child_tidptr;
164+
165+
get_user(clone_flags, &args[0]);
166+
get_user(newsp, &args[1]);
167+
get_user(parent_tidptr, &args[2]);
168+
get_user(child_tidptr, &args[3]);
169+
return do_fork(clone_flags, newsp, 0,
170+
(int __user *)parent_tidptr, (int __user *)child_tidptr);
171+
}

‎arch/h8300/kernel/ptrace.c‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* linux/arch/h8300/kernel/ptrace.c
3+
*
4+
* Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp>
5+
*
6+
* This file is subject to the terms and conditions of the GNU General
7+
* Public License. See the file COPYING in the main directory of
8+
* this archive for more details.
9+
*/
10+
11+
#include <linux/kernel.h>
12+
#include <linux/errno.h>
13+
#include <linux/ptrace.h>
14+
#include <linux/audit.h>
15+
#include <linux/tracehook.h>
16+
#include <linux/regset.h>
17+
#include <linux/elf.h>
18+
19+
#define CCR_MASK 0x6f /* mode/imask not set */
20+
#define EXR_MASK 0x80 /* modify only T */
21+
22+
#define PT_REG(r) offsetof(struct pt_regs, r)
23+
24+
extern void user_disable_single_step(struct task_struct *child);
25+
26+
/* Mapping from PT_xxx to the stack offset at which the register is
27+
saved. Notice that usp has no stack-slot and needs to be treated
28+
specially (see get_reg/put_reg below). */
29+
static const int register_offset[] = {
30+
PT_REG(er1), PT_REG(er2), PT_REG(er3), PT_REG(er4),
31+
PT_REG(er5), PT_REG(er6), PT_REG(er0), -1,
32+
PT_REG(orig_er0), PT_REG(ccr), PT_REG(pc),
33+
#if defined(CONFIG_CPU_H8S)
34+
PT_REG(exr),
35+
#endif
36+
};
37+
38+
/* read register */
39+
long h8300_get_reg(struct task_struct *task, int regno)
40+
{
41+
switch (regno) {
42+
case PT_USP:
43+
return task->thread.usp + sizeof(long)*2;
44+
case PT_CCR:
45+
case PT_EXR:
46+
return *(unsigned short *)(task->thread.esp0 +
47+
register_offset[regno]);
48+
default:
49+
return *(unsigned long *)(task->thread.esp0 +
50+
register_offset[regno]);
51+
}
52+
}
53+
54+
int h8300_put_reg(struct task_struct *task, int regno, unsigned long data)
55+
{
56+
unsigned short oldccr;
57+
unsigned short oldexr;
58+
59+
switch (regno) {
60+
case PT_USP:
61+
task->thread.usp = data - sizeof(long)*2;
62+
case PT_CCR:
63+
oldccr = *(unsigned short *)(task->thread.esp0 +
64+
register_offset[regno]);
65+
oldccr &= ~CCR_MASK;
66+
data &= CCR_MASK;
67+
data |= oldccr;
68+
*(unsigned short *)(task->thread.esp0 +
69+
register_offset[regno]) = data;
70+
break;
71+
case PT_EXR:
72+
oldexr = *(unsigned short *)(task->thread.esp0 +
73+
register_offset[regno]);
74+
oldccr &= ~EXR_MASK;
75+
data &= EXR_MASK;
76+
data |= oldexr;
77+
*(unsigned short *)(task->thread.esp0 +
78+
register_offset[regno]) = data;
79+
break;
80+
default:
81+
*(unsigned long *)(task->thread.esp0 +
82+
register_offset[regno]) = data;
83+
break;
84+
}
85+
return 0;
86+
}
87+
88+
static int regs_get(struct task_struct *target,
89+
const struct user_regset *regset,
90+
unsigned int pos, unsigned int count,
91+
void *kbuf, void __user *ubuf)
92+
{
93+
int r;
94+
struct user_regs_struct regs;
95+
long *reg = (long *)&regs;
96+
97+
/* build user regs in buffer */
98+
for (r = 0; r < ARRAY_SIZE(register_offset); r++)
99+
*reg++ = h8300_get_reg(target, r);
100+
101+
return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
102+
&regs, 0, sizeof(regs));
103+
}
104+
105+
static int regs_set(struct task_struct *target,
106+
const struct user_regset *regset,
107+
unsigned int pos, unsigned int count,
108+
const void *kbuf, const void __user *ubuf)
109+
{
110+
int r;
111+
int ret;
112+
struct user_regs_struct regs;
113+
long *reg;
114+
115+
/* build user regs in buffer */
116+
for (reg = (long *)&regs, r = 0; r < ARRAY_SIZE(register_offset); r++)
117+
*reg++ = h8300_get_reg(target, r);
118+
119+
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
120+
&regs, 0, sizeof(regs));
121+
if (ret)
122+
return ret;
123+
124+
/* write back to pt_regs */
125+
for (reg = (long *)&regs, r = 0; r < ARRAY_SIZE(register_offset); r++)
126+
h8300_put_reg(target, r, *reg++);
127+
return 0;
128+
}
129+
130+
enum h8300_regset {
131+
REGSET_GENERAL,
132+
};
133+
134+
static const struct user_regset h8300_regsets[] = {
135+
[REGSET_GENERAL] = {
136+
.core_note_type = NT_PRSTATUS,
137+
.n = ELF_NGREG,
138+
.size = sizeof(long),
139+
.align = sizeof(long),
140+
.get = regs_get,
141+
.set = regs_set,
142+
},
143+
};
144+
145+
static const struct user_regset_view user_h8300_native_view = {
146+
.name = "h8300",
147+
.e_machine = EM_H8_300,
148+
.regsets = h8300_regsets,
149+
.n = ARRAY_SIZE(h8300_regsets),
150+
};
151+
152+
const struct user_regset_view *task_user_regset_view(struct task_struct *task)
153+
{
154+
return &user_h8300_native_view;
155+
}
156+
157+
void ptrace_disable(struct task_struct *child)
158+
{
159+
user_disable_single_step(child);
160+
}
161+
162+
long arch_ptrace(struct task_struct *child, long request,
163+
unsigned long addr, unsigned long data)
164+
{
165+
int ret;
166+
167+
switch (request) {
168+
default:
169+
ret = ptrace_request(child, request, addr, data);
170+
break;
171+
}
172+
return ret;
173+
}
174+
175+
asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
176+
{
177+
long ret = 0;
178+
179+
if (test_thread_flag(TIF_SYSCALL_TRACE) &&
180+
tracehook_report_syscall_entry(regs))
181+
/*
182+
* Tracing decided this syscall should not happen.
183+
* We'll return a bogus call number to get an ENOSYS
184+
* error, but leave the original number in regs->regs[0].
185+
*/
186+
ret = -1L;
187+
188+
audit_syscall_entry(regs->er1, regs->er2, regs->er3,
189+
regs->er4, regs->er5);
190+
191+
return ret ?: regs->er0;
192+
}
193+
194+
asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
195+
{
196+
int step;
197+
198+
audit_syscall_exit(regs);
199+
200+
step = test_thread_flag(TIF_SINGLESTEP);
201+
if (step || test_thread_flag(TIF_SYSCALL_TRACE))
202+
tracehook_report_syscall_exit(regs, step);
203+
}

0 commit comments

Comments
 (0)