Skip to content

Commit 510c72a

Browse files
committed
sh: Fixup various PAGE_SIZE == 4096 assumptions.
There were a number of places that made evil PAGE_SIZE == 4k assumptions that ended up breaking when trying to play with 8k and 64k page sizes, this fixes those up. The most significant change is the way we load THREAD_SIZE, previously this was done via: mov #(THREAD_SIZE >> 8), reg shll8 reg to avoid a memory access and allow the immediate load. With a 64k PAGE_SIZE, we're out of range for the immediate load size without resorting to special instructions available in later ISAs (movi20s and so on). The "workaround" for this is to bump up the shift to 10 and insert a shll2, which gives a bit more flexibility while still being much cheaper than a memory access. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 1dc41e5 commit 510c72a

11 files changed

Lines changed: 37 additions & 45 deletions

File tree

‎arch/sh/kernel/cpu/sh3/entry.S‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ general_exception:
335335
/* This code makes some assumptions to improve performance.
336336
* Make sure they are stil true. */
337337
#if PTRS_PER_PGD != PTRS_PER_PTE
338-
#error PDG and PTE sizes don't match
338+
#error PGD and PTE sizes don't match
339339
#endif
340340

341341
/* gas doesn't flag impossible values for mov #immediate as an error */
@@ -547,8 +547,9 @@ ENTRY(handle_exception)
547547
bt/s 1f ! It's a kernel to kernel transition.
548548
mov r15, k0 ! save original stack to k0
549549
/* User space to kernel */
550-
mov #(THREAD_SIZE >> 8), k1
550+
mov #(THREAD_SIZE >> 10), k1
551551
shll8 k1 ! k1 := THREAD_SIZE
552+
shll2 k1
552553
add current, k1
553554
mov k1, r15 ! change to kernel stack
554555
!

‎arch/sh/kernel/head.S‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ENTRY(empty_zero_page)
3333
.long 0x00360000 /* INITRD_START */
3434
.long 0x000a0000 /* INITRD_SIZE */
3535
.long 0
36-
.balign 4096,0,4096
36+
.balign PAGE_SIZE,0,PAGE_SIZE
3737

3838
.text
3939
/*
@@ -70,8 +70,9 @@ ENTRY(_stext)
7070
!
7171
mov.l 2f, r0
7272
mov r0, r15 ! Set initial r15 (stack pointer)
73-
mov #(THREAD_SIZE >> 8), r1
73+
mov #(THREAD_SIZE >> 10), r1
7474
shll8 r1 ! r1 = THREAD_SIZE
75+
shll2 r1
7576
sub r1, r0 !
7677
#ifdef CONFIG_CPU_HAS_SR_RB
7778
ldc r0, r7_bank ! ... and initial thread_info

‎arch/sh/kernel/relocate_kernel.S‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
* This source code is licensed under the GNU General Public License,
88
* Version 2. See the file COPYING for more details.
99
*/
10-
1110
#include <linux/linkage.h>
12-
13-
#define PAGE_SIZE 4096 /* must be same value as in <asm/page.h> */
14-
11+
#include <asm/addrspace.h>
12+
#include <asm/page.h>
1513

1614
.globl relocate_new_kernel
1715
relocate_new_kernel:
@@ -20,8 +18,8 @@ relocate_new_kernel:
2018
/* r6 = start_address */
2119
/* r7 = vbr_reg */
2220

23-
mov.l 10f,r8 /* 4096 */
24-
mov.l 11f,r9 /* 0xa0000000 */
21+
mov.l 10f,r8 /* PAGE_SIZE */
22+
mov.l 11f,r9 /* P2SEG */
2523

2624
/* stack setting */
2725
add r8,r5
@@ -32,7 +30,7 @@ relocate_new_kernel:
3230
0:
3331
mov.l @r4+,r0 /* cmd = *ind++ */
3432

35-
1: /* addr = (cmd | 0xa0000000) & 0xfffffff0 */
33+
1: /* addr = (cmd | P2SEG) & 0xfffffff0 */
3634
mov r0,r2
3735
or r9,r2
3836
mov #-16,r1
@@ -92,7 +90,7 @@ relocate_new_kernel:
9290
10:
9391
.long PAGE_SIZE
9492
11:
95-
.long 0xa0000000
93+
.long P2SEG
9694

9795
relocate_new_kernel_end:
9896

‎arch/sh/mm/cache-sh4.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static inline void flush_cache_4096(unsigned long start,
225225
*/
226226
if ((cpu_data->flags & CPU_HAS_P2_FLUSH_BUG) ||
227227
(start < CACHE_OC_ADDRESS_ARRAY))
228-
exec_offset = 0x20000000;
228+
exec_offset = 0x20000000;
229229

230230
local_irq_save(flags);
231231
__flush_cache_4096(start | SH_CACHE_ASSOC,
@@ -246,7 +246,7 @@ void flush_dcache_page(struct page *page)
246246

247247
/* Loop all the D-cache */
248248
n = cpu_data->dcache.n_aliases;
249-
for (i = 0; i < n; i++, addr += PAGE_SIZE)
249+
for (i = 0; i < n; i++, addr += 4096)
250250
flush_cache_4096(addr, phys);
251251
}
252252

‎arch/sh/mm/clear_page.S‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/* $Id: clear_page.S,v 1.13 2003/08/25 17:03:10 lethal Exp $
2-
*
1+
/*
32
* __clear_user_page, __clear_user, clear_page implementation of SuperH
43
*
54
* Copyright (C) 2001 Kaz Kojima
65
* Copyright (C) 2001, 2002 Niibe Yutaka
7-
*
6+
* Copyright (C) 2006 Paul Mundt
87
*/
98
#include <linux/linkage.h>
9+
#include <asm/page.h>
1010

1111
/*
1212
* clear_page_slow
@@ -18,11 +18,11 @@
1818
/*
1919
* r0 --- scratch
2020
* r4 --- to
21-
* r5 --- to + 4096
21+
* r5 --- to + PAGE_SIZE
2222
*/
2323
ENTRY(clear_page_slow)
2424
mov r4,r5
25-
mov.w .Llimit,r0
25+
mov.l .Llimit,r0
2626
add r0,r5
2727
mov #0,r0
2828
!
@@ -50,7 +50,7 @@ ENTRY(clear_page_slow)
5050
!
5151
rts
5252
nop
53-
.Llimit: .word (4096-28)
53+
.Llimit: .long (PAGE_SIZE-28)
5454

5555
ENTRY(__clear_user)
5656
!
@@ -164,10 +164,10 @@ ENTRY(__clear_user)
164164
* r0 --- scratch
165165
* r4 --- to
166166
* r5 --- orig_to
167-
* r6 --- to + 4096
167+
* r6 --- to + PAGE_SIZE
168168
*/
169169
ENTRY(__clear_user_page)
170-
mov.w .L4096,r0
170+
mov.l .Lpsz,r0
171171
mov r4,r6
172172
add r0,r6
173173
mov #0,r0
@@ -191,7 +191,7 @@ ENTRY(__clear_user_page)
191191
!
192192
rts
193193
nop
194-
.L4096: .word 4096
194+
.Lpsz: .long PAGE_SIZE
195195

196196
#endif
197197

‎arch/sh/mm/copy_page.S‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/* $Id: copy_page.S,v 1.8 2003/08/25 17:03:10 lethal Exp $
2-
*
1+
/*
32
* copy_page, __copy_user_page, __copy_user implementation of SuperH
43
*
54
* Copyright (C) 2001 Niibe Yutaka & Kaz Kojima
65
* Copyright (C) 2002 Toshinobu Sugioka
7-
*
6+
* Copyright (C) 2006 Paul Mundt
87
*/
98
#include <linux/linkage.h>
9+
#include <asm/page.h>
1010

1111
/*
1212
* copy_page_slow
@@ -18,7 +18,7 @@
1818

1919
/*
2020
* r0, r1, r2, r3, r4, r5, r6, r7 --- scratch
21-
* r8 --- from + 4096
21+
* r8 --- from + PAGE_SIZE
2222
* r9 --- not used
2323
* r10 --- to
2424
* r11 --- from
@@ -30,7 +30,7 @@ ENTRY(copy_page_slow)
3030
mov r4,r10
3131
mov r5,r11
3232
mov r5,r8
33-
mov.w .L4096,r0
33+
mov.l .Lpsz,r0
3434
add r0,r8
3535
!
3636
1: mov.l @r11+,r0
@@ -80,7 +80,7 @@ ENTRY(copy_page_slow)
8080

8181
/*
8282
* r0, r1, r2, r3, r4, r5, r6, r7 --- scratch
83-
* r8 --- from + 4096
83+
* r8 --- from + PAGE_SIZE
8484
* r9 --- orig_to
8585
* r10 --- to
8686
* r11 --- from
@@ -94,7 +94,7 @@ ENTRY(__copy_user_page)
9494
mov r5,r11
9595
mov r6,r9
9696
mov r5,r8
97-
mov.w .L4096,r0
97+
mov.l .Lpsz,r0
9898
add r0,r8
9999
!
100100
1: ocbi @r9
@@ -129,7 +129,7 @@ ENTRY(__copy_user_page)
129129
rts
130130
nop
131131
#endif
132-
.L4096: .word 4096
132+
.Lpsz: .long PAGE_SIZE
133133
/*
134134
* __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
135135
* Return the number of bytes NOT copied

‎arch/sh/mm/init.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ static struct kcore_list kcore_mem, kcore_vmalloc;
217217

218218
void __init mem_init(void)
219219
{
220-
extern unsigned long empty_zero_page[1024];
221220
int codesize, reservedpages, datasize, initsize;
222221
int tmp;
223222
extern unsigned long memory_start;

‎arch/sh/mm/pg-dma.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ static void copy_page_dma(void *to, void *from)
3939

4040
static void clear_page_dma(void *to)
4141
{
42-
extern unsigned long empty_zero_page[1024];
43-
4442
/*
4543
* We get invoked quite early on, if the DMAC hasn't been initialized
4644
* yet, fall back on the slow manual implementation.

‎include/asm-sh/entry-macros.S‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#ifdef CONFIG_HAS_SR_RB
2424
stc r7_bank, \ti
2525
#else
26-
mov #((THREAD_SIZE - 1)>> 8) ^ 0xff, \tmp
26+
mov #((THREAD_SIZE - 1) >> 10) ^ 0xff, \tmp
2727
shll8 \tmp
28+
shll2 \tmp
2829
mov r15, \ti
2930
and \tmp, \ti
3031
#endif

‎include/asm-sh/pgtable.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
4747
#define PGDIR_MASK (~(PGDIR_SIZE-1))
4848

4949
/* Entries per level */
50-
#define PTRS_PER_PTE (1 << PTE_BITS)
51-
#define PTRS_PER_PGD (1 << PGDIR_BITS)
50+
#define PTRS_PER_PTE (PAGE_SIZE / 4)
51+
#define PTRS_PER_PGD (PAGE_SIZE / 4)
5252

5353
#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
5454
#define FIRST_USER_ADDRESS 0
@@ -57,7 +57,7 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
5757

5858
/*
5959
* First 1MB map is used by fixed purpose.
60-
* Currently only 4-enty (16kB) is used (see arch/sh/mm/cache.c)
60+
* Currently only 4-entry (16kB) is used (see arch/sh/mm/cache.c)
6161
*/
6262
#define VMALLOC_START (P3SEG+0x00100000)
6363
#define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)

0 commit comments

Comments
 (0)