Skip to content

Commit 79725df

Browse files
committed
unicore32 core architecture: processor and system headers
This patch includes processor and system headers. System call interface is here. We used the syscall interface the same as asm-generic version. Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 87c1a3f commit 79725df

10 files changed

Lines changed: 810 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/byteorder.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*
12+
* UniCore ONLY support Little Endian mode, the data bus is connected such
13+
* that byte accesses appear as:
14+
* 0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31
15+
* and word accesses (data or instruction) appear as:
16+
* d0...d31
17+
*/
18+
#ifndef __UNICORE_BYTEORDER_H__
19+
#define __UNICORE_BYTEORDER_H__
20+
21+
#include <linux/byteorder/little_endian.h>
22+
23+
#endif
24+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/cpu-single.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#ifndef __UNICORE_CPU_SINGLE_H__
13+
#define __UNICORE_CPU_SINGLE_H__
14+
15+
#include <asm/page.h>
16+
#include <asm/memory.h>
17+
18+
#ifdef __KERNEL__
19+
#ifndef __ASSEMBLY__
20+
21+
#define cpu_switch_mm(pgd, mm) cpu_do_switch_mm(virt_to_phys(pgd), mm)
22+
23+
#define cpu_get_pgd() \
24+
({ \
25+
unsigned long pg; \
26+
__asm__("movc %0, p0.c2, #0" \
27+
: "=r" (pg) : : "cc"); \
28+
pg &= ~0x0fff; \
29+
(pgd_t *)phys_to_virt(pg); \
30+
})
31+
32+
struct mm_struct;
33+
34+
/* declare all the functions as extern */
35+
extern void cpu_proc_fin(void);
36+
extern int cpu_do_idle(void);
37+
extern void cpu_dcache_clean_area(void *, int);
38+
extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm);
39+
extern void cpu_set_pte(pte_t *ptep, pte_t pte);
40+
extern void cpu_reset(unsigned long addr) __attribute__((noreturn));
41+
42+
#endif /* __ASSEMBLY__ */
43+
#endif /* __KERNEL__ */
44+
45+
#endif /* __UNICORE_CPU_SINGLE_H__ */
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/cputype.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#ifndef __UNICORE_CPUTYPE_H__
13+
#define __UNICORE_CPUTYPE_H__
14+
15+
#include <linux/stringify.h>
16+
17+
#define CPUID_CPUID 0
18+
#define CPUID_CACHETYPE 1
19+
20+
#define read_cpuid(reg) \
21+
({ \
22+
unsigned int __val; \
23+
asm("movc %0, p0.c0, #" __stringify(reg) \
24+
: "=r" (__val) \
25+
: \
26+
: "cc"); \
27+
__val; \
28+
})
29+
30+
#define uc32_cpuid read_cpuid(CPUID_CPUID)
31+
#define uc32_cachetype read_cpuid(CPUID_CACHETYPE)
32+
33+
#endif

‎arch/unicore32/include/asm/hwcap.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/hwcap.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#ifndef __UNICORE_HWCAP_H__
13+
#define __UNICORE_HWCAP_H__
14+
15+
/*
16+
* HWCAP flags
17+
*/
18+
#define HWCAP_MSP 1
19+
#define HWCAP_UNICORE16 2
20+
#define HWCAP_CMOV 4
21+
#define HWCAP_UNICORE_F64 8
22+
#define HWCAP_TLS 0x80
23+
24+
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
25+
/*
26+
* This yields a mask that user programs can use to figure out what
27+
* instruction set this cpu supports.
28+
*/
29+
#define ELF_HWCAP (HWCAP_CMOV | HWCAP_UNICORE_F64)
30+
#endif
31+
32+
#endif
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/processor.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
13+
#ifndef __UNICORE_PROCESSOR_H__
14+
#define __UNICORE_PROCESSOR_H__
15+
16+
/*
17+
* Default implementation of macro that returns current
18+
* instruction pointer ("program counter").
19+
*/
20+
#define current_text_addr() ({ __label__ _l; _l: &&_l; })
21+
22+
#ifdef __KERNEL__
23+
24+
#include <asm/ptrace.h>
25+
#include <asm/types.h>
26+
27+
#ifdef __KERNEL__
28+
#define STACK_TOP TASK_SIZE
29+
#define STACK_TOP_MAX TASK_SIZE
30+
#endif
31+
32+
struct debug_entry {
33+
u32 address;
34+
u32 insn;
35+
};
36+
37+
struct debug_info {
38+
int nsaved;
39+
struct debug_entry bp[2];
40+
};
41+
42+
struct thread_struct {
43+
/* fault info */
44+
unsigned long address;
45+
unsigned long trap_no;
46+
unsigned long error_code;
47+
/* debugging */
48+
struct debug_info debug;
49+
};
50+
51+
#define INIT_THREAD { }
52+
53+
#define start_thread(regs, pc, sp) \
54+
({ \
55+
unsigned long *stack = (unsigned long *)sp; \
56+
set_fs(USER_DS); \
57+
memset(regs->uregs, 0, sizeof(regs->uregs)); \
58+
regs->UCreg_asr = USER_MODE; \
59+
regs->UCreg_pc = pc & ~1; /* pc */ \
60+
regs->UCreg_sp = sp; /* sp */ \
61+
regs->UCreg_02 = stack[2]; /* r2 (envp) */ \
62+
regs->UCreg_01 = stack[1]; /* r1 (argv) */ \
63+
regs->UCreg_00 = stack[0]; /* r0 (argc) */ \
64+
})
65+
66+
/* Forward declaration, a strange C thing */
67+
struct task_struct;
68+
69+
/* Free all resources held by a thread. */
70+
extern void release_thread(struct task_struct *);
71+
72+
/* Prepare to copy thread state - unlazy all lazy status */
73+
#define prepare_to_copy(tsk) do { } while (0)
74+
75+
unsigned long get_wchan(struct task_struct *p);
76+
77+
#define cpu_relax() barrier()
78+
79+
/*
80+
* Create a new kernel thread
81+
*/
82+
extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
83+
84+
#define task_pt_regs(p) \
85+
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
86+
87+
#define KSTK_EIP(tsk) (task_pt_regs(tsk)->UCreg_pc)
88+
#define KSTK_ESP(tsk) (task_pt_regs(tsk)->UCreg_sp)
89+
90+
#endif
91+
92+
#endif /* __UNICORE_PROCESSOR_H__ */
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/system.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#ifndef __UNICORE_SYSTEM_H__
13+
#define __UNICORE_SYSTEM_H__
14+
15+
#ifdef __KERNEL__
16+
17+
/*
18+
* CR1 bits (CP#0 CR1)
19+
*/
20+
#define CR_M (1 << 0) /* MMU enable */
21+
#define CR_A (1 << 1) /* Alignment abort enable */
22+
#define CR_D (1 << 2) /* Dcache enable */
23+
#define CR_I (1 << 3) /* Icache enable */
24+
#define CR_B (1 << 4) /* Dcache write mechanism: write back */
25+
#define CR_T (1 << 5) /* Burst enable */
26+
#define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
27+
28+
#ifndef __ASSEMBLY__
29+
30+
#include <linux/linkage.h>
31+
#include <linux/irqflags.h>
32+
33+
struct thread_info;
34+
struct task_struct;
35+
36+
struct pt_regs;
37+
38+
void die(const char *msg, struct pt_regs *regs, int err);
39+
40+
struct siginfo;
41+
void uc32_notify_die(const char *str, struct pt_regs *regs,
42+
struct siginfo *info, unsigned long err, unsigned long trap);
43+
44+
void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
45+
struct pt_regs *),
46+
int sig, int code, const char *name);
47+
48+
#define xchg(ptr, x) \
49+
((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
50+
51+
extern asmlinkage void __backtrace(void);
52+
extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
53+
54+
struct mm_struct;
55+
extern void show_pte(struct mm_struct *mm, unsigned long addr);
56+
extern void __show_regs(struct pt_regs *);
57+
58+
extern int cpu_architecture(void);
59+
extern void cpu_init(void);
60+
61+
#define vectors_high() (cr_alignment & CR_V)
62+
63+
#define isb() __asm__ __volatile__ ("" : : : "memory")
64+
#define dsb() __asm__ __volatile__ ("" : : : "memory")
65+
#define dmb() __asm__ __volatile__ ("" : : : "memory")
66+
67+
#define mb() barrier()
68+
#define rmb() barrier()
69+
#define wmb() barrier()
70+
#define smp_mb() barrier()
71+
#define smp_rmb() barrier()
72+
#define smp_wmb() barrier()
73+
#define read_barrier_depends() do { } while (0)
74+
#define smp_read_barrier_depends() do { } while (0)
75+
76+
#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
77+
#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
78+
79+
extern unsigned long cr_no_alignment; /* defined in entry-unicore.S */
80+
extern unsigned long cr_alignment; /* defined in entry-unicore.S */
81+
82+
static inline unsigned int get_cr(void)
83+
{
84+
unsigned int val;
85+
asm("movc %0, p0.c1, #0" : "=r" (val) : : "cc");
86+
return val;
87+
}
88+
89+
static inline void set_cr(unsigned int val)
90+
{
91+
asm volatile("movc p0.c1, %0, #0 @set CR"
92+
: : "r" (val) : "cc");
93+
isb();
94+
}
95+
96+
extern void adjust_cr(unsigned long mask, unsigned long set);
97+
98+
/*
99+
* switch_to(prev, next) should switch from task `prev' to `next'
100+
* `prev' will never be the same as `next'. schedule() itself
101+
* contains the memory barrier to tell GCC not to cache `current'.
102+
*/
103+
extern struct task_struct *__switch_to(struct task_struct *,
104+
struct thread_info *, struct thread_info *);
105+
extern void panic(const char *fmt, ...);
106+
107+
#define switch_to(prev, next, last) \
108+
do { \
109+
last = __switch_to(prev, \
110+
task_thread_info(prev), task_thread_info(next)); \
111+
} while (0)
112+
113+
static inline unsigned long
114+
__xchg(unsigned long x, volatile void *ptr, int size)
115+
{
116+
unsigned long ret;
117+
118+
switch (size) {
119+
case 1:
120+
asm volatile("@ __xchg1\n"
121+
" swapb %0, %1, [%2]"
122+
: "=&r" (ret)
123+
: "r" (x), "r" (ptr)
124+
: "memory", "cc");
125+
break;
126+
case 4:
127+
asm volatile("@ __xchg4\n"
128+
" swapw %0, %1, [%2]"
129+
: "=&r" (ret)
130+
: "r" (x), "r" (ptr)
131+
: "memory", "cc");
132+
break;
133+
default:
134+
panic("xchg: bad data size: ptr 0x%p, size %d\n",
135+
ptr, size);
136+
}
137+
138+
return ret;
139+
}
140+
141+
#include <asm-generic/cmpxchg-local.h>
142+
143+
/*
144+
* cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
145+
* them available.
146+
*/
147+
#define cmpxchg_local(ptr, o, n) \
148+
((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
149+
(unsigned long)(o), (unsigned long)(n), sizeof(*(ptr))))
150+
#define cmpxchg64_local(ptr, o, n) \
151+
__cmpxchg64_local_generic((ptr), (o), (n))
152+
153+
#include <asm-generic/cmpxchg.h>
154+
155+
#endif /* __ASSEMBLY__ */
156+
157+
#define arch_align_stack(x) (x)
158+
159+
#endif /* __KERNEL__ */
160+
161+
#endif

0 commit comments

Comments
 (0)