mm.h
来自「一个微型操作系统源码」· C头文件 代码 · 共 133 行
H
133 行
/* * OSV * Copyright (C) 2002 Ciprian DOSOFTEI <rocksoul@mail.com> * All rights reserved. * * http://backster.free.fr/osv * * This file is part of the OSV project. OSV is free software, also known as * "open source"; you can redistribute it and/or modify it under the terms * of the GNU General Public License (GPL), version 2, as published by the Free * Software Foundation (FSF). To explore alternate licensing terms, contact * the author at rocksoul@mail.com or +40740649907. * * OSV is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have * received a copy of the GPL along with OSV; see the file COPYING. If * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. */#ifndef INCMM#define INCMM#include <sys/params.h>#include <asm/system.h> /* set_CR0(), set_CR3() etc. */#include <types.h>/* support 4GB of RAM (you can change this to reduce size) #define MAX_MEMORY 1024*1024*1024 */#define OWNER_NOBODY 0 #define OWNER_KERNEL 1/* Paging constants */#define PAGE_SIZE 4096#define PAGE_SHIFT 12#define PAGE_MASK 0x03FF#define PDE_SHIFT 22#define PTE_SHIFT 12#define TABLE_ENTRIES 1024#define PAGE_ROUND(x) ((x) & 0xFFFFF000)#define PAGE_ROUND_UP(x) (((ulong)(((x)+PAGE_SIZE-1)>>PAGE_SHIFT))<<PAGE_SHIFT)#define ROUND_4(x) (( x + 3) & ~ 3)// structure that defines an entry in the pagedirtypedef struct{ uint present:1; uint readWrite:1; uint user:1; uint reserved1:2; uint accessed:1; uint dirty:1; uint reserved2:2; uint os_use:3; /* for system programmer's use */ uint address:20;} pde;// structure that defines an entry in the pagetabletypedef struct{ uint present:1; uint readWrite:1; uint user:1; uint reserved1:2; uint accessed:1; uint dirty:1; uint reserved2:2; uint os_use:3; /* for system programmer's use */ uint address:20;} pte;/* values for attrib entry in the structure above */#define VMM_FREE 0x000#define VMM_BUSY 0x001#define VMM_LOCK 0x002// define a pagedir as an array containig 1024 entriestypedef struct{ pde entry[TABLE_ENTRIES];} pagedir;extern pagedir *PD;// define a pagetable as an array containig 1024 entriestypedef struct{ pte entry[TABLE_ENTRIES];} pagetable;/* Paging and VM functions */int setupPaging(ulong availableMemory);void enablePaging(void);void __inline__ make_pde(pagedir *dir, uint nr, ulong addr , uchar attr);void __inline__ make_pte(pagetable *tab, uint nr, ulong addr , uchar attr);/* Physical MM */void setupMemory(ulong availableMemory, ulong usedMemory);/* pointers */typedef struct __memlink{ struct __memlink *pNext; struct __memlink *pPrev; ulong size; ulong owner;} memlink;void *physAlloc(size_t allocsize,ulong client);void physFree(void *pointer);void showFreeMemory(void);void showUsedMemory(void);void *kmalloc(size_t allocsize);void kfree(void *pointer);/* Virtual Memory */void vmMapInit(pagedir *pd, ulong pages);int vmKernelMap(pagedir *pd);int vmMap(pagedir *pd, void *page, ulong attr);int vmUnmap(pagedir *pd, void *page);int vmMapRange(pagedir *pd, void *start, size_t len, ulong attr);int vmUnmapRange(pagedir *pd, void *start, size_t len);void dumpPageDir(pagedir *pd, ulong pdes);#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?