-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch contains code that is in some way visible to the user: including via system calls, the VDSO, module loading and signal handling. It also contains some generic code that is ABI visible. Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
- Loading branch information
Palmer Dabbelt
committed
Sep 26, 2017
1 parent
07037db
commit e2c0cdf
Showing
27 changed files
with
1,687 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2012 Regents of the University of California | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
|
||
#ifndef _ASM_RISCV_MMU_H | ||
#define _ASM_RISCV_MMU_H | ||
|
||
#ifndef __ASSEMBLY__ | ||
|
||
typedef struct { | ||
void *vdso; | ||
} mm_context_t; | ||
|
||
#endif /* __ASSEMBLY__ */ | ||
|
||
#endif /* _ASM_RISCV_MMU_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2012 Regents of the University of California | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#ifndef _ASM_RISCV_PTRACE_H | ||
#define _ASM_RISCV_PTRACE_H | ||
|
||
#include <uapi/asm/ptrace.h> | ||
#include <asm/csr.h> | ||
|
||
#ifndef __ASSEMBLY__ | ||
|
||
struct pt_regs { | ||
unsigned long sepc; | ||
unsigned long ra; | ||
unsigned long sp; | ||
unsigned long gp; | ||
unsigned long tp; | ||
unsigned long t0; | ||
unsigned long t1; | ||
unsigned long t2; | ||
unsigned long s0; | ||
unsigned long s1; | ||
unsigned long a0; | ||
unsigned long a1; | ||
unsigned long a2; | ||
unsigned long a3; | ||
unsigned long a4; | ||
unsigned long a5; | ||
unsigned long a6; | ||
unsigned long a7; | ||
unsigned long s2; | ||
unsigned long s3; | ||
unsigned long s4; | ||
unsigned long s5; | ||
unsigned long s6; | ||
unsigned long s7; | ||
unsigned long s8; | ||
unsigned long s9; | ||
unsigned long s10; | ||
unsigned long s11; | ||
unsigned long t3; | ||
unsigned long t4; | ||
unsigned long t5; | ||
unsigned long t6; | ||
/* Supervisor CSRs */ | ||
unsigned long sstatus; | ||
unsigned long sbadaddr; | ||
unsigned long scause; | ||
/* a0 value before the syscall */ | ||
unsigned long orig_a0; | ||
}; | ||
|
||
#ifdef CONFIG_64BIT | ||
#define REG_FMT "%016lx" | ||
#else | ||
#define REG_FMT "%08lx" | ||
#endif | ||
|
||
#define user_mode(regs) (((regs)->sstatus & SR_PS) == 0) | ||
|
||
|
||
/* Helpers for working with the instruction pointer */ | ||
#define GET_IP(regs) ((regs)->sepc) | ||
#define SET_IP(regs, val) (GET_IP(regs) = (val)) | ||
|
||
static inline unsigned long instruction_pointer(struct pt_regs *regs) | ||
{ | ||
return GET_IP(regs); | ||
} | ||
static inline void instruction_pointer_set(struct pt_regs *regs, | ||
unsigned long val) | ||
{ | ||
SET_IP(regs, val); | ||
} | ||
|
||
#define profile_pc(regs) instruction_pointer(regs) | ||
|
||
/* Helpers for working with the user stack pointer */ | ||
#define GET_USP(regs) ((regs)->sp) | ||
#define SET_USP(regs, val) (GET_USP(regs) = (val)) | ||
|
||
static inline unsigned long user_stack_pointer(struct pt_regs *regs) | ||
{ | ||
return GET_USP(regs); | ||
} | ||
static inline void user_stack_pointer_set(struct pt_regs *regs, | ||
unsigned long val) | ||
{ | ||
SET_USP(regs, val); | ||
} | ||
|
||
/* Helpers for working with the frame pointer */ | ||
#define GET_FP(regs) ((regs)->s0) | ||
#define SET_FP(regs, val) (GET_FP(regs) = (val)) | ||
|
||
static inline unsigned long frame_pointer(struct pt_regs *regs) | ||
{ | ||
return GET_FP(regs); | ||
} | ||
static inline void frame_pointer_set(struct pt_regs *regs, | ||
unsigned long val) | ||
{ | ||
SET_FP(regs, val); | ||
} | ||
|
||
#endif /* __ASSEMBLY__ */ | ||
|
||
#endif /* _ASM_RISCV_PTRACE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved. | ||
* Copyright 2010 Tilera Corporation. All Rights Reserved. | ||
* Copyright 2015 Regents of the University of California, Berkeley | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* See asm-generic/syscall.h for descriptions of what we must do here. | ||
*/ | ||
|
||
#ifndef _ASM_RISCV_SYSCALL_H | ||
#define _ASM_RISCV_SYSCALL_H | ||
|
||
#include <linux/sched.h> | ||
#include <linux/err.h> | ||
|
||
/* The array of function pointers for syscalls. */ | ||
extern void *sys_call_table[]; | ||
|
||
/* | ||
* Only the low 32 bits of orig_r0 are meaningful, so we return int. | ||
* This importantly ignores the high bits on 64-bit, so comparisons | ||
* sign-extend the low 32 bits. | ||
*/ | ||
static inline int syscall_get_nr(struct task_struct *task, | ||
struct pt_regs *regs) | ||
{ | ||
return regs->a7; | ||
} | ||
|
||
static inline void syscall_set_nr(struct task_struct *task, | ||
struct pt_regs *regs, | ||
int sysno) | ||
{ | ||
regs->a7 = sysno; | ||
} | ||
|
||
static inline void syscall_rollback(struct task_struct *task, | ||
struct pt_regs *regs) | ||
{ | ||
regs->a0 = regs->orig_a0; | ||
} | ||
|
||
static inline long syscall_get_error(struct task_struct *task, | ||
struct pt_regs *regs) | ||
{ | ||
unsigned long error = regs->a0; | ||
|
||
return IS_ERR_VALUE(error) ? error : 0; | ||
} | ||
|
||
static inline long syscall_get_return_value(struct task_struct *task, | ||
struct pt_regs *regs) | ||
{ | ||
return regs->a0; | ||
} | ||
|
||
static inline void syscall_set_return_value(struct task_struct *task, | ||
struct pt_regs *regs, | ||
int error, long val) | ||
{ | ||
regs->a0 = (long) error ?: val; | ||
} | ||
|
||
static inline void syscall_get_arguments(struct task_struct *task, | ||
struct pt_regs *regs, | ||
unsigned int i, unsigned int n, | ||
unsigned long *args) | ||
{ | ||
BUG_ON(i + n > 6); | ||
if (i == 0) { | ||
args[0] = regs->orig_a0; | ||
args++; | ||
i++; | ||
n--; | ||
} | ||
memcpy(args, ®s->a1 + i * sizeof(regs->a1), n * sizeof(args[0])); | ||
} | ||
|
||
static inline void syscall_set_arguments(struct task_struct *task, | ||
struct pt_regs *regs, | ||
unsigned int i, unsigned int n, | ||
const unsigned long *args) | ||
{ | ||
BUG_ON(i + n > 6); | ||
if (i == 0) { | ||
regs->orig_a0 = args[0]; | ||
args++; | ||
i++; | ||
n--; | ||
} | ||
memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0)); | ||
} | ||
|
||
#endif /* _ASM_RISCV_SYSCALL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (C) 2012 Regents of the University of California | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#define __ARCH_HAVE_MMU | ||
#define __ARCH_WANT_SYS_CLONE | ||
#include <uapi/asm/unistd.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2012 ARM Limited | ||
* Copyright (C) 2014 Regents of the University of California | ||
* Copyright (C) 2017 SiFive | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _ASM_RISCV_VDSO_H | ||
#define _ASM_RISCV_VDSO_H | ||
|
||
#include <linux/types.h> | ||
|
||
struct vdso_data { | ||
}; | ||
|
||
/* | ||
* The VDSO symbols are mapped into Linux so we can just use regular symbol | ||
* addressing to get their offsets in userspace. The symbols are mapped at an | ||
* offset of 0, but since the linker must support setting weak undefined | ||
* symbols to the absolute address 0 it also happens to support other low | ||
* addresses even when the code model suggests those low addresses would not | ||
* otherwise be availiable. | ||
*/ | ||
#define VDSO_SYMBOL(base, name) \ | ||
({ \ | ||
extern const char __vdso_##name[]; \ | ||
(void __user *)((unsigned long)(base) + __vdso_##name); \ | ||
}) | ||
|
||
#endif /* _ASM_RISCV_VDSO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# UAPI Header export list | ||
include include/uapi/asm-generic/Kbuild.asm | ||
|
||
generic-y += setup.h | ||
generic-y += unistd.h | ||
generic-y += errno.h | ||
generic-y += fcntl.h | ||
generic-y += ioctl.h | ||
generic-y += ioctls.h | ||
generic-y += ipcbuf.h | ||
generic-y += mman.h | ||
generic-y += msgbuf.h | ||
generic-y += param.h | ||
generic-y += poll.h | ||
generic-y += posix_types.h | ||
generic-y += resource.h | ||
generic-y += sembuf.h | ||
generic-y += shmbuf.h | ||
generic-y += signal.h | ||
generic-y += socket.h | ||
generic-y += sockios.h | ||
generic-y += stat.h | ||
generic-y += statfs.h | ||
generic-y += swab.h | ||
generic-y += termbits.h | ||
generic-y += termios.h | ||
generic-y += types.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2012 ARM Ltd. | ||
* Copyright (C) 2015 Regents of the University of California | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _UAPI_ASM_RISCV_AUXVEC_H | ||
#define _UAPI_ASM_RISCV_AUXVEC_H | ||
|
||
/* vDSO location */ | ||
#define AT_SYSINFO_EHDR 33 | ||
|
||
#endif /* _UAPI_ASM_RISCV_AUXVEC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2012 ARM Ltd. | ||
* Copyright (C) 2015 Regents of the University of California | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _UAPI_ASM_RISCV_BITSPERLONG_H | ||
#define _UAPI_ASM_RISCV_BITSPERLONG_H | ||
|
||
#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8) | ||
|
||
#include <asm-generic/bitsperlong.h> | ||
|
||
#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */ |
Oops, something went wrong.