18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OpenRISC Linux
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Linux architectural port borrowing liberally from similar works of
68c2ecf20Sopenharmony_ci * others.  All original copyrights apply as per the original source
78c2ecf20Sopenharmony_ci * declaration.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * OpenRISC implementation:
108c2ecf20Sopenharmony_ci * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
118c2ecf20Sopenharmony_ci * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
128c2ecf20Sopenharmony_ci * et al.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef __ASM_OPENRISC_PROCESSOR_H
168c2ecf20Sopenharmony_ci#define __ASM_OPENRISC_PROCESSOR_H
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <asm/spr_defs.h>
198c2ecf20Sopenharmony_ci#include <asm/page.h>
208c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define STACK_TOP       TASK_SIZE
238c2ecf20Sopenharmony_ci#define STACK_TOP_MAX	STACK_TOP
248c2ecf20Sopenharmony_ci/* Kernel and user SR register setting */
258c2ecf20Sopenharmony_ci#define KERNEL_SR (SPR_SR_DME | SPR_SR_IME | SPR_SR_ICE \
268c2ecf20Sopenharmony_ci		   | SPR_SR_DCE | SPR_SR_SM)
278c2ecf20Sopenharmony_ci#define USER_SR   (SPR_SR_DME | SPR_SR_IME | SPR_SR_ICE \
288c2ecf20Sopenharmony_ci		   | SPR_SR_DCE | SPR_SR_IEE | SPR_SR_TEE)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * User space process size. This is hardcoded into a few places,
328c2ecf20Sopenharmony_ci * so don't change it unless you know what you are doing.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define TASK_SIZE       (0x80000000UL)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* This decides where the kernel will search for a free chunk of vm
388c2ecf20Sopenharmony_ci * space during mmap's.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE      (TASK_SIZE / 8 * 3)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct task_struct;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct thread_struct {
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/*
508c2ecf20Sopenharmony_ci * At user->kernel entry, the pt_regs struct is stacked on the top of the
518c2ecf20Sopenharmony_ci * kernel-stack.  This macro allows us to find those regs for a task.
528c2ecf20Sopenharmony_ci * Notice that subsequent pt_regs stackings, like recursive interrupts
538c2ecf20Sopenharmony_ci * occurring while we're in the kernel, won't affect this - only the first
548c2ecf20Sopenharmony_ci * user->kernel transition registers are reached by this (i.e. not regs
558c2ecf20Sopenharmony_ci * for running signal handler)
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_ci#define user_regs(thread_info)  (((struct pt_regs *)((unsigned long)(thread_info) + THREAD_SIZE - STACK_FRAME_OVERHEAD)) - 1)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * Dito but for the currently running task
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define task_pt_regs(task) user_regs(task_thread_info(task))
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define INIT_SP         (sizeof(init_stack) + (unsigned long) &init_stack)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define INIT_THREAD  { }
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define KSTK_EIP(tsk)   (task_pt_regs(tsk)->pc)
718c2ecf20Sopenharmony_ci#define KSTK_ESP(tsk)   (task_pt_regs(tsk)->sp)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_civoid start_thread(struct pt_regs *regs, unsigned long nip, unsigned long sp);
758c2ecf20Sopenharmony_civoid release_thread(struct task_struct *);
768c2ecf20Sopenharmony_ciunsigned long get_wchan(struct task_struct *p);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define cpu_relax()     barrier()
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
818c2ecf20Sopenharmony_ci#endif /* __ASM_OPENRISC_PROCESSOR_H */
82