69 lines
2.5 KiB
C
69 lines
2.5 KiB
C
/*
|
|
Copyright 2025 Kamil Kowalczyk
|
|
|
|
Redistribution and use in source and binary forms, with or
|
|
without modification, are permitted provided that the following
|
|
conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its
|
|
contributors may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef _SYS_MM_H
|
|
#define _SYS_MM_H
|
|
|
|
#include <libk/util.h>
|
|
#include <libk/types.h>
|
|
#include <libk/compiler.h>
|
|
#include <sync/spinlock.h>
|
|
|
|
#define VIRT_BASE 0xC0000000
|
|
|
|
#define PAGE_SIZE 0x1000
|
|
|
|
#define PF_PRESENT (1<<0)
|
|
#define PF_WRITABLE (1<<1)
|
|
#define PF_USER (1<<2)
|
|
#define PF_LOCK (1<<31) /* Special flag for internal usage that doesn't exist in x86.
|
|
I use this here, because when (un)mapping an entire page range
|
|
it would be inefficient to constantly (un)lock. */
|
|
|
|
#define KERNEL_HEAP_START 0xF0000000
|
|
|
|
struct page_dir {
|
|
volatile uint32_t *pd;
|
|
uint16_t pt_refcount[1024];
|
|
struct spinlock sl;
|
|
};
|
|
|
|
void mm_init(void);
|
|
|
|
void mm_map_page(struct page_dir *pd, uptr_t vaddr, uptr_t paddr, uint32_t flags);
|
|
void mm_unmap_page(struct page_dir *pd, uptr_t vaddr, uint32_t flags);
|
|
uptr_t mm_translate_v2p(struct page_dir *pd, uptr_t vaddr, uint32_t flags);
|
|
uptr_t mm_translate_p2v(struct page_dir *pd, uptr_t paddr, uint32_t flags);
|
|
void mm_load_pd(struct page_dir *pd);
|
|
struct page_dir *mm_get_kernel_pd(void);
|
|
|
|
#endif // _SYS_MM_H
|