You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.8 KiB
C

/* See the end of this file for copyright and license terms. */
#pragma once
#ifndef _ARCH_PAGE_H_
#error "This file is not meant to be included directly, use <arch/page.h>"
#endif
/** @brief Binary logarithm of `HUGEPAGE_SIZE`. */
#define HUGEPAGE_SHIFT 22
#ifndef _ASM_SOURCE
#include <gay/cdefs.h>
#include <gay/types.h>
struct x86_page_table_entry {
unsigned present:1; /**< Page Fault on access if 0 */
unsigned rw:1; /**< Page Fault on write if 0 */
unsigned user:1; /**< Page Fault on user mode access if 0 */
unsigned write_through:1; /**< Enable write-through caching */
unsigned cache_disabled:1; /**< Disable caching in TLB */
unsigned accessed:1; /**< 1 if page has been accessed */
unsigned dirty:1; /**< 1 if page has been written to */
unsigned _reserved0:1;
unsigned global:1; /**< Don't update the TLB on table swap if 1 */
unsigned _reserved1:3;
uintptr_t shifted_address:20; /**< Aligned pointer to the physical page */
} __packed;
#define __PFLAG_PRESENT (1 << 0)
#define __PFLAG_RW (1 << 1)
#define __PFLAG_USER (1 << 2)
#define __PFLAG_WRITE_THROUGH (1 << 3)
#define __PFLAG_NOCACHE (1 << 4)
#define __PFLAG_ACCESSED (1 << 5)
#define __PFLAG_DIRTY (1 << 6)
#define __PFLAG_GLOBAL (1 << 8)
struct x86_page_table {
struct x86_page_table_entry entries[1024];
} __aligned(PAGE_SIZE);
/**
* @brief Currently active page table at position `index` in the page directory.
* The last entry in the page directory is mapped to itself, therefore being
* interpreted by the MMU as a page table. This has the effect that the last
* page table, i.e. the page directory again, maps the entire page directory
* structure so it can be manipulated while paging is active. See the comment
* at the beginning of `arch/x86/mm/page.c` for a more detailed explanation.
*
* @param index Table index in the page directory
*/
#define X86_CURRENT_PT(index) ( &((struct x86_page_table *)X86_PD_OFFSET)[index] )
struct x86_page_directory_entry {
unsigned present:1; /**< Page Fault on access if 0 */
unsigned rw:1; /**< Page Fault on write if 0 */
unsigned user:1; /**< Page Fault on user mode access if 0 */
unsigned write_through:1; /**< Enable write-through caching */
unsigned cache_disabled:1; /**< Disable caching in TLB */
unsigned accessed:1; /**< 1 if page has been accessed */
unsigned _reserved0:1;
unsigned huge:1; /**< 0 = 4K, 1 = 4M */
unsigned _reserved1:1;
unsigned _ignored2:3;
uintptr_t shifted_address:20; /**< Aligned pointer to `struct x86_page_table` */
} __packed;
#define __PFLAG_HUGE (1 << 7)
struct x86_page_directory {
struct x86_page_directory_entry entries[1024];
} __aligned(PAGE_SIZE);
/**
* @brief Currently active page directory.
* The last entry in the page directory is mapped to itself, therefore being
* interpreted by the MMU as a page table. See the comment at the start of
* `arch/x86/mm/page.c` for a more detailed explanation.
*/
#define X86_CURRENT_PD ((struct x86_page_directory *)X86_CURRENT_PT(1023))
/**
* @brief Arch dependent virtual memory information data structure (x86 version).
* Outside of `/arch/x86`, this is treated as a completely obfuscated type,
* and only pointers to it are stored and passed around.
*/
typedef struct x86_page_directory vm_info_t;
#endif /* not _ASM_SOURCE */
/*
* This file is part of GayBSD.
* Copyright (c) 2021 fef <owo@fef.moe>.
*
* GayBSD is nonviolent software: you may only use, redistribute, and/or
* modify it under the terms of the Cooperative Nonviolent Public License
* (CNPL) as found in the LICENSE file in the source code root directory
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
* of the license, or (at your option) any later version.
*
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPL for details.
*/