Fix definition of PAGESIZE and B_PAGE_SIZE

On sparc, the minimal page size we can use is 8K. Since B_PAGE_SIZE and
PAGESIZE defines were hardcoded to 4K, this resulted in a lot of
confusion in all code trying to manipulate pages.

- Remove cpu.h from headers/private/kernel/arch/*. It dates back from
  NewOS and was not used anymore since our kernel uses B_PAGE_SIZE
  (PAGE_SIZE was the only thing defined in this header).
- Add posix/arch/*/limits.h with the arch specific page size and include
  it from the main limits.h.
- Adjust bios_ia32/debug.cpp which was the only place using the
  PAGE_SIZE constant from the deleted headers.
- Change OS.h to define B_PAGE_SIZE to be the same as POSIX PAGESIZE.
- Define PAGESIZE in the build header if the host OS doesn't.

Change-Id: I8c3732cf952ea3c2f088aa16d216678fbf198b96
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3558
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Adrien Destugues 2020-12-30 14:42:48 +01:00 committed by Adrien Destugues
parent c46f51fb45
commit 68d37cfb3a
25 changed files with 115 additions and 253 deletions

View File

@ -1 +1,9 @@
// Some platforms (Linux) don't define PAGESIZE, set a default value in that
// case.
#include <limits.h>
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
#include <../os/kernel/OS.h>

View File

@ -7,6 +7,7 @@
/** Kernel specific structures and functions */
#include <limits.h>
#include <stdarg.h>
#include <sys/types.h>
@ -21,9 +22,10 @@ extern "C" {
/* System constants */
#define B_OS_NAME_LENGTH 32
#define B_PAGE_SIZE 4096
#define B_INFINITE_TIMEOUT (9223372036854775807LL)
#define B_PAGE_SIZE PAGESIZE
enum {
B_TIMEOUT = 0x8, /* relative timeout */
B_RELATIVE_TIMEOUT = 0x8, /* fails after a relative timeout

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ARM_LIMITS_H
#define _ARM_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ARM64_LIMITS_H
#define _ARM64_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _M68K_LIMITS_H
#define _M68K_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _MIPS_LIMITS_H
#define _MIPS_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PPC_LIMITS_H
#define _PPC_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _RISCV64_LIMITS_H
#define _RISCV64_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SPARC_LIMITS_H
#define _SPARC_LIMITS_H
#define PAGESIZE 8192
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _X86_LIMITS_H
#define _X86_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -0,0 +1,11 @@
/*
* Copyright 2020, Haiku, inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _X86_64_LIMITS_H
#define _X86_64_LIMITS_H
#define PAGESIZE 4096
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2012 Haiku, Inc. All rights reserved.
* Copyright 2001-2020 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _LIBC_LIMITS_H_
@ -11,6 +11,9 @@
#include <float.h> /* for DBL_DIG, FLT_DIG, etc */
#include __HAIKU_ARCH_HEADER(limits.h)
#define LONGLONG_MIN (-9223372036854775807LL - 1) /* these are Be specific */
#define LONGLONG_MAX (9223372036854775807LL)
#define ULONGLONG_MAX (0xffffffffffffffffULL)
@ -38,7 +41,6 @@
#define NAME_MAX (256)
#define NGROUPS_MAX (32)
#define OPEN_MAX (128)
#define PAGESIZE (4096)
#define PATH_MAX (1024)
#define PIPE_BUF (4 * 1024)
#define PIPE_MAX (512)

View File

@ -1,11 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _ALPHA_CPU_H
#define _ALPHA_CPU_H
#define PAGE_SIZE 8192
#endif

View File

@ -1,11 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _M68K_CPU_H
#define _M68K_CPU_H
#define PAGE_SIZE 4096
#endif

View File

@ -1,11 +0,0 @@
/*
* Copyright 2009 Haiku Inc.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_ARCH_MIPSEL_CPU_H
#define _KERNEL_ARCH_MIPSEL_CPU_H
#define PAGE_SIZE 4096
#endif /* _KERNEL_ARCH_MIPSEL_CPU_H */

View File

@ -7,7 +7,6 @@
#include <arch/ppc/arch_thread_types.h>
#include <arch/ppc/cpu.h>
#include <kernel.h>

View File

@ -1,11 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _PPC_CPU_H
#define _PPC_CPU_H
#define PAGE_SIZE 4096
#endif

View File

@ -8,7 +8,6 @@
#include <arch/riscv64/arch_thread_types.h>
//#include <arch/riscv64/cpu.h>
#include <kernel.h>

View File

@ -1,24 +0,0 @@
/*
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _NEWOS_KERNEL_ARCH_SH4_CPU_H
#define _NEWOS_KERNEL_ARCH_SH4_CPU_H
#include <arch/cpu.h>
#include <arch/sh4/sh4.h>
unsigned int get_fpscr();
unsigned int get_sr();
void sh4_context_switch(unsigned int **old_sp, unsigned int *new_sp);
void sh4_function_caller();
void sh4_set_kstack(addr kstack);
void sh4_enter_uspace(addr entry, void *args, addr ustack_top);
void sh4_set_user_pgdir(addr pgdir);
void sh4_invl_page(addr va);
#define PAGE_SIZE 4096
#define _BIG_ENDIAN 0
#define _LITTLE_ENDIAN 1
#endif

View File

@ -1,152 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _SH4_H
#define _SH4_H
#define P4_AREA 0xe0000000
#define P4_AREA_LEN 0x20000000
#define P3_AREA 0xc0000000
#define P3_AREA_LEN (P4_AREA - P3_AREA)
#define P2_AREA 0xa0000000
#define P2_AREA_LEN (P3_AREA - P2_AREA)
#define P1_AREA 0x80000000
#define P1_AREA_LEN (P2_AREA - P1_AREA)
#define P0_AREA 0
#define P0_AREA_LEN (P1_AREA - P0_AREA)
#define U0_AREA P0_AREA
#define U0_AREA_LEN P0_AREA_LEN
#define PHYS_MEM_START 0x0c000000
#define PHYS_MEM_LEN 0x01000000
#define PHYS_MEM_END (PHYS_MEM_START + PHYS_MEM_LEN)
#define P1_PHYS_MEM_START (P1_AREA + PHYS_MEM_START)
#define P1_PHYS_MEM_LEN PHYS_MEM_LEN
#define P1_PHYS_MEM_END (P1_PHYS_MEM_START + P1_PHYS_MEM_LEN)
#define PHYS_ADDR_TO_P1(x) (((unsigned int)(x)) + P1_AREA)
#define PHYS_ADDR_TO_P2(x) (((unsigned int)(x)) + P2_AREA)
#define P1_TO_PHYS_ADDR(x) (((unsigned int)(x)) - P1_AREA)
#define PHYS_ADDR_SIZE (0x1fffffff+1)
//#define PAGE_SIZE 4096
#define PAGE_SIZE_1K 0
#define PAGE_SIZE_4K 1
#define PAGE_SIZE_64K 2
#define PAGE_SIZE_1M 3
#define PTEH 0xff000000
#define PTEL 0xff000004
#define PTEA 0xff000034
#define TTB 0xff000008
#define TEA 0xff00000c
#define MMUCR 0xff000010
#define UTLB 0xf6000000
#define UTLB1 0xf7000000
#define UTLB2 0xf3800000
#define UTLB_ADDR_SHIFT 0x8
#define UTLB_COUNT 64
struct utlb_addr_array {
unsigned int asid: 8;
unsigned int valid: 1;
unsigned int dirty: 1;
unsigned int vpn: 22;
};
struct utlb_data_array_1 {
unsigned int wt: 1;
unsigned int sh: 1;
unsigned int dirty: 1;
unsigned int cacheability: 1;
unsigned int psize0: 1;
unsigned int prot_key: 2;
unsigned int psize1: 1;
unsigned int valid: 1;
unsigned int unused: 1;
unsigned int ppn: 19;
unsigned int unused2: 3;
};
struct utlb_data_array_2 {
unsigned int sa: 2;
unsigned int tc: 1;
unsigned int unused: 29;
};
struct utlb_data {
struct utlb_addr_array a;
struct utlb_data_array_1 da1;
struct utlb_data_array_2 da2;
};
#define ITLB 0xf2000000
#define ITLB1 0xf3000000
#define ITLB2 0xf3800000
#define ITLB_ADDR_SHIFT 0x8
#define ITLB_COUNT 4
struct itlb_addr_array {
unsigned int asid: 8;
unsigned int valid: 1;
unsigned int unused: 1;
unsigned int vpn: 22;
};
struct itlb_data_array_1 {
unsigned int unused1: 1;
unsigned int sh: 1;
unsigned int unused2: 1;
unsigned int cacheability: 1;
unsigned int psize0: 1;
unsigned int unused3: 1;
unsigned int prot_key: 1;
unsigned int psize1: 1;
unsigned int valid: 1;
unsigned int unused4: 1;
unsigned int ppn: 19;
unsigned int unused5: 3;
};
struct itlb_data_array_2 {
unsigned int sa: 2;
unsigned int tc: 1;
unsigned int unused: 29;
};
struct itlb_data {
struct itlb_addr_array a;
struct itlb_data_array_1 da1;
struct itlb_data_array_2 da2;
};
// timer stuff
#define TOCR 0xffd80000
#define TSTR 0xffd80004
#define TCOR0 0xffd80008
#define TCNT0 0xffd8000c
#define TCR0 0xffd80010
#define TCOR1 0xffd80014
#define TCNT1 0xffd80018
#define TCR1 0xffd8001c
#define TCOR2 0xffd80020
#define TCNT2 0xffd80024
#define TCR2 0xffd80028
#define TCPR2 0xffd8002c
// interrupt controller stuff
#define ICR 0xffd00000
#define IPRA 0xffd00004
#define IPRB 0xffd00008
#define IPRC 0xffd0000c
// cache stuff
#define CCR 0xff00001c
#define QACR0 0xff000038
#define QACR1 0xff00003c
#endif

View File

@ -8,7 +8,6 @@
#include <arch/sparc/arch_thread_types.h>
#include <arch/sparc/cpu.h>
#include <kernel.h>

View File

@ -1,11 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _SPARC64_CPU_H
#define _SPARC64_CPU_H
#define PAGE_SIZE 8192
#endif

View File

@ -1,12 +0,0 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#ifndef _SPARC_H
#define _SPARC_H
#define PAGE_SIZE 4096
#define PAGE_ALIGN(x) (((x) + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1))
#endif

View File

@ -21,10 +21,6 @@
#include <arch/x86/arch_cpuasm.h>
#include <arch/x86/descriptors.h>
#ifdef __x86_64__
# include <arch/x86/64/cpu.h>
#endif
#endif // !_ASSEMBLER

View File

@ -6,6 +6,7 @@
#include "debug.h"
#include <limits.h>
#include <string.h>
#include <boot/platform.h>