mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-26 14:45:03 +00:00
Add memory, PCI, and timer modules to kernel
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
29
kernel/include/kernel/memory.h
Normal file
29
kernel/include/kernel/memory.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef METALOS_KERNEL_MEMORY_H
|
||||
#define METALOS_KERNEL_MEMORY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "kernel/kernel.h"
|
||||
|
||||
// Memory constants
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
// Physical memory manager
|
||||
void pmm_init(BootInfo* boot_info);
|
||||
void* pmm_alloc_page(void);
|
||||
void pmm_free_page(void* page);
|
||||
uint64_t pmm_get_total_memory(void);
|
||||
uint64_t pmm_get_free_memory(void);
|
||||
|
||||
// Simple kernel heap allocator (bump allocator for now)
|
||||
void heap_init(void* start, size_t size);
|
||||
void* kmalloc(size_t size);
|
||||
void* kcalloc(size_t num, size_t size);
|
||||
void kfree(void* ptr);
|
||||
|
||||
// Memory utility functions
|
||||
void* memset(void* dest, int val, size_t count);
|
||||
void* memcpy(void* dest, const void* src, size_t count);
|
||||
int memcmp(const void* s1, const void* s2, size_t count);
|
||||
|
||||
#endif // METALOS_KERNEL_MEMORY_H
|
||||
31
kernel/include/kernel/pci.h
Normal file
31
kernel/include/kernel/pci.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef METALOS_KERNEL_PCI_H
|
||||
#define METALOS_KERNEL_PCI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// PCI Configuration Space Registers
|
||||
#define PCI_CONFIG_ADDRESS 0xCF8
|
||||
#define PCI_CONFIG_DATA 0xCFC
|
||||
|
||||
// PCI Device Structure
|
||||
typedef struct {
|
||||
uint8_t bus;
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint8_t class_code;
|
||||
uint8_t subclass;
|
||||
uint8_t prog_if;
|
||||
uint8_t revision_id;
|
||||
uint32_t bar[6]; // Base Address Registers
|
||||
} pci_device_t;
|
||||
|
||||
// PCI Functions
|
||||
void pci_init(void);
|
||||
uint32_t pci_read_config(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
|
||||
void pci_write_config(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t value);
|
||||
pci_device_t* pci_find_device(uint16_t vendor_id, uint16_t device_id);
|
||||
void pci_enable_bus_mastering(pci_device_t* dev);
|
||||
|
||||
#endif // METALOS_KERNEL_PCI_H
|
||||
17
kernel/include/kernel/timer.h
Normal file
17
kernel/include/kernel/timer.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef METALOS_KERNEL_TIMER_H
|
||||
#define METALOS_KERNEL_TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Timer frequency (Hz)
|
||||
#define TIMER_FREQUENCY 1000 // 1ms per tick
|
||||
|
||||
// Timer functions
|
||||
void timer_init(uint32_t frequency);
|
||||
uint64_t timer_get_ticks(void);
|
||||
void timer_wait(uint32_t ticks);
|
||||
|
||||
// Timer interrupt handler (called from ISR)
|
||||
void timer_handler(void);
|
||||
|
||||
#endif // METALOS_KERNEL_TIMER_H
|
||||
Reference in New Issue
Block a user