mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-04 02:23:10 +00:00
Moved header files into their lib directory
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#ifndef MEMORY_ADDRESSES_H
|
||||
#define MEMORY_ADDRESSES_H
|
||||
|
||||
/*
|
||||
* Memory layout of addresses 0x0000 - 0x12000
|
||||
* 0x0000-0x0fff - Probably shouldn't mess with this? idk it feels wrong
|
||||
* 0x1000-0x17ff - Free
|
||||
* 0x1800-0x1fff - Global Variables
|
||||
* 0x2000-0x2fff - Larger structs
|
||||
* 0x3000-0x3fff - Filesystem Info
|
||||
* 0x4000-0x4fff - Font area
|
||||
* 0x6000-0x6fff - VBE info area
|
||||
* 0x7000-0x7bff - SMAP Area
|
||||
* 0x7c00-0x8bff - Bootblock
|
||||
* 0x8c00-0x9bff - Superblock
|
||||
* 0x9c00-0xafff - Free
|
||||
* 0xb000-0xbfff - Bootloader first INode
|
||||
* 0xc000-0xcfff - Scratch INode block
|
||||
*/
|
||||
|
||||
// Global Variables 0x1800-0x1fff
|
||||
#define SLEEP_TIMER 0x1800
|
||||
#define CURRENT_PAGE_DIR_ADDR 0x1804
|
||||
#define PHYS_MEM_MAX_BLOCKS 0x1808
|
||||
#define PHYS_MEM_USED_BLOCKS 0x180C
|
||||
|
||||
// Some structs 0x2000-0x2fff
|
||||
#define TERMINAL_INFO_LOC 0x2000
|
||||
#define KEYBOARD_STATE_LOC 0x2100
|
||||
#define DATETIME_LOC 0x2200
|
||||
|
||||
// Filesystem Area 0x3000 - 0x3fff
|
||||
#define FS_INFO_LOC 0x3000
|
||||
|
||||
// Font area 0x4000 - 0x4fff
|
||||
#define FONT_LOC 0x4000
|
||||
|
||||
// VBE Info Area 0x6000 - 0x6fff
|
||||
#define MODE_INFO_BLOCK_LOC 0x6000 // 512 Bytes
|
||||
|
||||
// Smap Area 0x7000 - 0x7bff
|
||||
#define SMAP_ENTRY_COUNT 0x7000
|
||||
#define SMAP_ENTRIES 0x7004
|
||||
|
||||
// Bootblock 0x7c00-0x9bff
|
||||
#define BOOTBLOCK_LOC 0x7c00
|
||||
|
||||
// Superblock 0x9c00-0xabff
|
||||
#define SUPERBLOCK_LOC 0x8c00
|
||||
|
||||
// First INode from bootloader
|
||||
#define BOOT_FIRST_INODE_LOC 0xb000
|
||||
#define SCRATCH_BLOCK_LOC 0xc000
|
||||
|
||||
// Other addresses
|
||||
#define KERNEL_LOC 0x100000
|
||||
#define KERNEL_MALLOC_AREA 0x300000
|
||||
#define MEMMAP_AREA 0x30000
|
||||
#define OPEN_FILE_LOC 0xd000
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MEMORY_MALLOC_H
|
||||
#define MEMORY_MALLOC_H
|
||||
|
||||
#include <memory/virtual.h>
|
||||
#include <memory/physical.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Singly linked list!
|
||||
typedef struct mallocNode_s {
|
||||
uint32_t size;
|
||||
bool free;
|
||||
struct mallocNode_s* next;
|
||||
} mallocNode_t;
|
||||
|
||||
extern mallocNode_t* mallocListHead;
|
||||
extern uint32_t mallocVirtualAddr;
|
||||
extern uint32_t mallocPhysicalAddr;
|
||||
extern uint32_t mallocPages;
|
||||
|
||||
void mallocInit(uint32_t size);
|
||||
void mallocSplit(mallocNode_t* node, uint32_t size);
|
||||
void* mallocNextNode(uint32_t size);
|
||||
void mallocMergeFree();
|
||||
void mallocFree(void* ptr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef MEMORY_PHYSICAL_H
|
||||
#define MEMORY_PHYSICAL_H
|
||||
|
||||
#include <memory/addresses.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BLOCK_SIZE 4096 // 4kB
|
||||
#define BLOCKS_PER_BYTE 8
|
||||
|
||||
typedef struct smapEntry_s {
|
||||
uint64_t baseAddress;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
uint32_t acpiAttr;
|
||||
} __attribute__ ((packed)) smapEntry_t;
|
||||
|
||||
extern uint32_t* memoryMap;
|
||||
extern uint32_t maxBlocks;
|
||||
extern uint32_t usedBlocks;
|
||||
|
||||
void setBlock(uint32_t block);
|
||||
void unsetBlock(uint32_t block);
|
||||
uint8_t testBlock(uint32_t block);
|
||||
|
||||
int32_t findFreeBlocks(uint32_t blockCount);
|
||||
void setupPhysicalMemoryManager(uint32_t startAddress, uint32_t size);
|
||||
void initMemoryRegion(uint32_t baseAddress, uint32_t size);
|
||||
void deinitMemoryRegion(uint32_t baseAddress, uint32_t size);
|
||||
void* allocBlocks(uint32_t blockCount);
|
||||
void freeBlocks(void* address, uint32_t blockCount);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
#ifndef MEMORY_VIRTUAL_H
|
||||
#define MEMORY_VIRTUAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory/physical.h>
|
||||
|
||||
#define PAGES_PER_TABLE 1024
|
||||
#define TABLES_PER_DIRECTORY 1024
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#define PD_INDEX(_vAddress) ((_vAddress) >> 22)
|
||||
#define PT_INDEX(_vAddress) (((_vAddress) >> 12) & 0x3ff)
|
||||
#define PAGE_PHYS_ADDRESS(_dirEntry) (*(_dirEntry) & ~ 0xfff)
|
||||
#define SET_ATTR(_entry, _attr) (*(_entry) |= (_attr))
|
||||
#define CLEAR_ATTR(_entry, _attr) (*(_entry) &= ~(_attr))
|
||||
#define TEST_ATTR(_entry, _attr) (*(_entry) & (_attr))
|
||||
#define SET_FRAME(_entry, _address) (*(_entry) = (*(_entry) & ~0xfffff000) | (_address))
|
||||
|
||||
typedef uint32_t ptEntry_t;
|
||||
typedef uint32_t pdEntry_t;
|
||||
|
||||
typedef enum {
|
||||
PTE_PRESENT = 0x01,
|
||||
PTE_READ_WRITE = 0x02,
|
||||
PTE_USER = 0x04,
|
||||
PTE_WRITE_THROUGH = 0x08,
|
||||
PTE_CACHE_DISABLE = 0x10,
|
||||
PTE_ACCESSED = 0x20,
|
||||
PTE_DIRTY = 0x40,
|
||||
PTE_PAT = 0x80,
|
||||
PTE_GLOBAL = 0x100,
|
||||
PTE_FRAME = 0x7ffff000,
|
||||
} PAGE_TABLE_FLAGS;
|
||||
|
||||
typedef enum {
|
||||
PDE_PRESENT = 0x01,
|
||||
PDE_READ_WRITE = 0x02,
|
||||
PDE_USER = 0x04,
|
||||
PDE_WRITE_THROUGH = 0x08,
|
||||
PDE_CACHE_DISABLE = 0x10,
|
||||
PDE_ACCESSED = 0x20,
|
||||
PDE_DIRTY = 0x40, // Only with 4MB pages
|
||||
PDE_PAGE_SIZE = 0x80, // Is page 4MB
|
||||
PDE_GLOBAL = 0x100,
|
||||
PDE_PAT = 0x2000,
|
||||
PDE_FRAME = 0x7ffff000,
|
||||
} PAGE_DIR_FLAGS;
|
||||
|
||||
typedef struct {
|
||||
ptEntry_t entries[PAGES_PER_TABLE];
|
||||
} pageTable_t;
|
||||
|
||||
typedef struct {
|
||||
pdEntry_t entries[TABLES_PER_DIRECTORY];
|
||||
} pageDirectory_t;
|
||||
|
||||
extern pageDirectory_t* currentPd;
|
||||
|
||||
ptEntry_t* getPtEntry(pageTable_t* pt, uint32_t virtualAddress);
|
||||
pdEntry_t* getPdEntry(pageDirectory_t* pd, uint32_t virtualAddress);
|
||||
ptEntry_t* getPage(uint32_t virtualAddress);
|
||||
void* allocPage(ptEntry_t* page);
|
||||
void freePage(ptEntry_t* page);
|
||||
uint8_t setPageDirectory(pageDirectory_t* pd);
|
||||
void flushTlbEntry(uint32_t virtualAddress);
|
||||
uint8_t mapPage(void* physicalAddr, void* virtualAddr);
|
||||
void unmapPage(void* virtualAddress);
|
||||
uint8_t setupVirtualMemoryManager();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user