mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Use uintptr_t instead of addr_t
They're never actually going to change independently, and it's also brining in kutil headers more places than they should be.
This commit is contained in:
@@ -253,7 +253,7 @@ port::make_command(size_t length, fis_register_h2d **fis)
|
||||
void *mem = pm->map_offset_pages(page_count(prd_len));
|
||||
kutil::memset(mem, 0xaf, prd_len);
|
||||
|
||||
addr_t phys = pm->offset_phys(mem);
|
||||
uintptr_t phys = pm->offset_phys(mem);
|
||||
cmdt.entries[i].data_base_low = phys & 0xffffffff;
|
||||
cmdt.entries[i].data_base_high = phys >> 32;
|
||||
cmdt.entries[i].byte_count = prd_len - 1;
|
||||
@@ -442,9 +442,9 @@ port::finish_read(int slot)
|
||||
for (int i = 0; i < ent.prd_table_length; ++i) {
|
||||
size_t prd_len = (cmdt.entries[i].byte_count & 0x7fffffff) + 1;
|
||||
|
||||
addr_t phys =
|
||||
static_cast<addr_t>(cmdt.entries[i].data_base_low) |
|
||||
static_cast<addr_t>(cmdt.entries[i].data_base_high) << 32;
|
||||
uintptr_t phys =
|
||||
static_cast<uintptr_t>(cmdt.entries[i].data_base_low) |
|
||||
static_cast<uintptr_t>(cmdt.entries[i].data_base_high) << 32;
|
||||
|
||||
void *mem = kutil::offset_pointer(pm->offset_virt(phys), offset);
|
||||
|
||||
@@ -485,9 +485,9 @@ port::finish_identify(int slot)
|
||||
|
||||
size_t prd_len = (cmdt.entries[0].byte_count & 0x7fffffff) + 1;
|
||||
|
||||
addr_t phys =
|
||||
static_cast<addr_t>(cmdt.entries[0].data_base_low) |
|
||||
static_cast<addr_t>(cmdt.entries[0].data_base_high) << 32;
|
||||
uintptr_t phys =
|
||||
static_cast<uintptr_t>(cmdt.entries[0].data_base_low) |
|
||||
static_cast<uintptr_t>(cmdt.entries[0].data_base_high) << 32;
|
||||
|
||||
log::debug(logs::driver, "Reading ident PRD:");
|
||||
|
||||
@@ -535,9 +535,9 @@ port::free_command(int slot)
|
||||
for (int i = 0; i < ent.prd_table_length; ++i) {
|
||||
size_t prd_len = (cmdt.entries[i].byte_count & 0x7fffffff) + 1;
|
||||
|
||||
addr_t phys =
|
||||
static_cast<addr_t>(cmdt.entries[i].data_base_low) |
|
||||
static_cast<addr_t>(cmdt.entries[i].data_base_high) << 32;
|
||||
uintptr_t phys =
|
||||
static_cast<uintptr_t>(cmdt.entries[i].data_base_low) |
|
||||
static_cast<uintptr_t>(cmdt.entries[i].data_base_high) << 32;
|
||||
void *mem = pm->offset_virt(phys);
|
||||
pm->unmap_pages(mem, page_count(prd_len));
|
||||
}
|
||||
@@ -557,7 +557,7 @@ port::rebase()
|
||||
size_t pages = 1 + page_count(prd_size * 32);
|
||||
|
||||
void *mem = pm->map_offset_pages(pages);
|
||||
addr_t phys = pm->offset_phys(mem);
|
||||
uintptr_t phys = pm->offset_phys(mem);
|
||||
|
||||
log::debug(logs::driver, "Rebasing address for AHCI port %d to %lx [%d]", m_index, mem, pages);
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
/// \file debug.h
|
||||
/// Debugging utilities
|
||||
|
||||
#include "kutil/memory.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
addr_t get_rsp();
|
||||
addr_t get_rip();
|
||||
addr_t get_frame(int frame);
|
||||
uintptr_t get_rsp();
|
||||
uintptr_t get_rip();
|
||||
uintptr_t get_frame(int frame);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -136,13 +136,13 @@ idt_set_entry(uint8_t i, uint64_t addr, uint16_t selector, uint8_t flags)
|
||||
}
|
||||
|
||||
void
|
||||
tss_set_stack(int ring, addr_t rsp)
|
||||
tss_set_stack(int ring, uintptr_t rsp)
|
||||
{
|
||||
kassert(ring < 3, "Bad ring passed to tss_set_stack.");
|
||||
g_tss.rsp[ring] = rsp;
|
||||
}
|
||||
|
||||
addr_t
|
||||
uintptr_t
|
||||
tss_get_stack(int ring)
|
||||
{
|
||||
kassert(ring < 3, "Bad ring passed to tss_get_stack.");
|
||||
@@ -170,7 +170,7 @@ gdt_init()
|
||||
kutil::memset(&g_tss, 0, sizeof(tss_entry));
|
||||
g_tss.iomap_offset = sizeof(tss_entry);
|
||||
|
||||
addr_t tss_base = reinterpret_cast<addr_t>(&g_tss);
|
||||
uintptr_t tss_base = reinterpret_cast<uintptr_t>(&g_tss);
|
||||
|
||||
// Note that this takes TWO GDT entries
|
||||
tss_set_entry(6, tss_base, sizeof(tss_entry));
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/// \file gdt.h
|
||||
/// Definitions relating to system descriptor tables: GDT, IDT, TSS
|
||||
#include <stdint.h>
|
||||
#include "kutil/memory.h"
|
||||
|
||||
/// Set up the GDT and TSS, and switch segment registers to point
|
||||
/// to them.
|
||||
@@ -18,12 +17,12 @@ void idt_set_entry(uint8_t i, uint64_t addr, uint16_t selector, uint8_t flags);
|
||||
/// Set the stack pointer for a given ring in the TSS
|
||||
/// \arg ring Ring to set for (0-2)
|
||||
/// \arg rsp Stack pointer to set
|
||||
void tss_set_stack(int ring, addr_t rsp);
|
||||
void tss_set_stack(int ring, uintptr_t rsp);
|
||||
|
||||
/// Get the stack pointer for a given ring in the TSS
|
||||
/// \arg ring Ring to get (0-2)
|
||||
/// \returns Stack pointers for that ring
|
||||
addr_t tss_get_stack(int ring);
|
||||
uintptr_t tss_get_stack(int ring);
|
||||
|
||||
/// Dump information about the current GDT to the screen
|
||||
void gdt_dump();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kutil/memory.h"
|
||||
#include "apic.h"
|
||||
#include "console.h"
|
||||
#include "cpu.h"
|
||||
@@ -19,9 +18,9 @@ static const uint16_t PIC2 = 0xa0;
|
||||
extern "C" {
|
||||
void _halt();
|
||||
|
||||
addr_t isr_handler(addr_t, cpu_state);
|
||||
addr_t irq_handler(addr_t, cpu_state);
|
||||
addr_t syscall_handler(addr_t, cpu_state);
|
||||
uintptr_t isr_handler(uintptr_t, cpu_state);
|
||||
uintptr_t irq_handler(uintptr_t, cpu_state);
|
||||
uintptr_t syscall_handler(uintptr_t, cpu_state);
|
||||
|
||||
#define ISR(i, name) extern void name ();
|
||||
#define EISR(i, name) extern void name ();
|
||||
@@ -105,8 +104,8 @@ interrupts_init()
|
||||
log::info(logs::boot, "Interrupts enabled.");
|
||||
}
|
||||
|
||||
addr_t
|
||||
isr_handler(addr_t return_rsp, cpu_state regs)
|
||||
uintptr_t
|
||||
isr_handler(uintptr_t return_rsp, cpu_state regs)
|
||||
{
|
||||
console *cons = console::get();
|
||||
|
||||
@@ -251,8 +250,8 @@ isr_handler(addr_t return_rsp, cpu_state regs)
|
||||
return return_rsp;
|
||||
}
|
||||
|
||||
addr_t
|
||||
irq_handler(addr_t return_rsp, cpu_state regs)
|
||||
uintptr_t
|
||||
irq_handler(uintptr_t return_rsp, cpu_state regs)
|
||||
{
|
||||
console *cons = console::get();
|
||||
uint8_t irq = get_irq(regs.interrupt);
|
||||
@@ -269,8 +268,8 @@ irq_handler(addr_t return_rsp, cpu_state regs)
|
||||
return return_rsp;
|
||||
}
|
||||
|
||||
addr_t
|
||||
syscall_handler(addr_t return_rsp, cpu_state regs)
|
||||
uintptr_t
|
||||
syscall_handler(uintptr_t return_rsp, cpu_state regs)
|
||||
{
|
||||
return syscall_dispatch(return_rsp, regs);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "initrd/initrd.h"
|
||||
#include "kutil/assert.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "apic.h"
|
||||
#include "block_device.h"
|
||||
#include "console.h"
|
||||
@@ -110,7 +109,7 @@ kernel_main(popcorn_data *header)
|
||||
auto r = cpu.get(0x15);
|
||||
log::info(logs::boot, "CPU Crystal: %dHz", r.ecx);
|
||||
|
||||
addr_t cr4 = 0;
|
||||
uintptr_t cr4 = 0;
|
||||
__asm__ __volatile__ ( "mov %%cr4, %0" : "=r" (cr4) );
|
||||
log::info(logs::boot, "cr4: %016x", cr4);
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <utility>
|
||||
#include "kutil/assert.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "kutil/linked_list.h"
|
||||
#include "kutil/slab_allocator.h"
|
||||
#include "memory.h"
|
||||
@@ -13,7 +12,7 @@ namespace {
|
||||
// Page-by-page initial allocator for the initial page_block allocator
|
||||
struct page_consumer
|
||||
{
|
||||
page_consumer(addr_t start) : current(start) {}
|
||||
page_consumer(uintptr_t start) : current(start) {}
|
||||
|
||||
void * operator()(size_t size) {
|
||||
kassert(size == page_manager::page_size, "page_consumer used with non-page size!");
|
||||
@@ -22,7 +21,7 @@ namespace {
|
||||
return retval;
|
||||
}
|
||||
|
||||
addr_t current;
|
||||
uintptr_t current;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -128,7 +127,7 @@ desc_incr(const efi_memory_descriptor *d, size_t desc_length)
|
||||
}
|
||||
|
||||
page_block_list::item_type *
|
||||
remove_block_for(page_block_list &list, addr_t phys_start, size_t pages, page_block_list &cache)
|
||||
remove_block_for(page_block_list &list, uintptr_t phys_start, size_t pages, page_block_list &cache)
|
||||
{
|
||||
// This is basically just the removal portion of page_manager::unmap_pages,
|
||||
// but with physical addresses, and only ever removing a single block.
|
||||
|
||||
@@ -10,15 +10,15 @@ page_manager g_page_manager;
|
||||
kutil::memory_manager g_kernel_memory_manager;
|
||||
|
||||
|
||||
static addr_t
|
||||
static uintptr_t
|
||||
pt_to_phys(page_table *pt)
|
||||
{
|
||||
return reinterpret_cast<addr_t>(pt) - page_manager::page_offset;
|
||||
return reinterpret_cast<uintptr_t>(pt) - page_manager::page_offset;
|
||||
}
|
||||
|
||||
|
||||
static page_table *
|
||||
pt_from_phys(addr_t p)
|
||||
pt_from_phys(uintptr_t p)
|
||||
{
|
||||
return reinterpret_cast<page_table *>((p + page_manager::page_offset) & ~0xfffull);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void mm_grow_callback(void *next, size_t length)
|
||||
|
||||
size_t pages = length / page_manager::page_size;
|
||||
log::info(logs::memory, "Heap manager growing heap by %d pages.", pages);
|
||||
g_page_manager.map_pages(reinterpret_cast<addr_t>(next), pages);
|
||||
g_page_manager.map_pages(reinterpret_cast<uintptr_t>(next), pages);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ page_manager::init(
|
||||
consolidate_blocks();
|
||||
|
||||
// Initialize the kernel memory manager
|
||||
addr_t end = 0;
|
||||
uintptr_t end = 0;
|
||||
for (auto *block : m_used) {
|
||||
if (block->virtual_address &&
|
||||
block->virtual_address < page_offset) {
|
||||
@@ -198,9 +198,9 @@ page_manager::delete_process_map(page_table *table)
|
||||
void
|
||||
page_manager::map_offset_pointer(void **pointer, size_t length)
|
||||
{
|
||||
addr_t *p = reinterpret_cast<addr_t *>(pointer);
|
||||
addr_t v = *p + page_offset;
|
||||
addr_t c = ((length - 1) / page_size) + 1;
|
||||
uintptr_t *p = reinterpret_cast<uintptr_t *>(pointer);
|
||||
uintptr_t v = *p + page_offset;
|
||||
uintptr_t c = ((length - 1) / page_size) + 1;
|
||||
|
||||
// TODO: cleanly search/split this as a block out of used/free if possible
|
||||
auto *block = m_block_slab.pop();
|
||||
@@ -241,9 +241,9 @@ page_table *
|
||||
page_manager::get_table_page()
|
||||
{
|
||||
if (!m_page_cache) {
|
||||
addr_t phys = 0;
|
||||
uintptr_t phys = 0;
|
||||
size_t n = pop_pages(32, &phys);
|
||||
addr_t virt = phys + page_offset;
|
||||
uintptr_t virt = phys + page_offset;
|
||||
|
||||
auto *block = m_block_slab.pop();
|
||||
|
||||
@@ -258,7 +258,7 @@ page_manager::get_table_page()
|
||||
m_page_cache = reinterpret_cast<free_page_header *>(virt);
|
||||
|
||||
// The last one needs to be null, so do n-1
|
||||
addr_t end = virt + (n-1) * page_size;
|
||||
uintptr_t end = virt + (n-1) * page_size;
|
||||
while (virt < end) {
|
||||
reinterpret_cast<free_page_header *>(virt)->next =
|
||||
reinterpret_cast<free_page_header *>(virt + page_size);
|
||||
@@ -277,9 +277,9 @@ page_manager::get_table_page()
|
||||
void
|
||||
page_manager::free_table_pages(void *pages, size_t count)
|
||||
{
|
||||
addr_t start = reinterpret_cast<addr_t>(pages);
|
||||
uintptr_t start = reinterpret_cast<uintptr_t>(pages);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
addr_t addr = start + (i * page_size);
|
||||
uintptr_t addr = start + (i * page_size);
|
||||
free_page_header *header = reinterpret_cast<free_page_header *>(addr);
|
||||
header->count = 1;
|
||||
header->next = m_page_cache;
|
||||
@@ -295,7 +295,7 @@ page_manager::consolidate_blocks()
|
||||
}
|
||||
|
||||
void *
|
||||
page_manager::map_pages(addr_t address, size_t count, bool user, page_table *pml4)
|
||||
page_manager::map_pages(uintptr_t address, size_t count, bool user, page_table *pml4)
|
||||
{
|
||||
void *ret = reinterpret_cast<void *>(address);
|
||||
if (!pml4) pml4 = get_pml4();
|
||||
@@ -303,7 +303,7 @@ page_manager::map_pages(addr_t address, size_t count, bool user, page_table *pml
|
||||
while (count) {
|
||||
kassert(!m_free.empty(), "page_manager::map_pages ran out of free pages!");
|
||||
|
||||
addr_t phys = 0;
|
||||
uintptr_t phys = 0;
|
||||
size_t n = pop_pages(count, &phys);
|
||||
|
||||
auto *block = m_block_slab.pop();
|
||||
@@ -368,14 +368,14 @@ page_manager::map_offset_pages(size_t count)
|
||||
void
|
||||
page_manager::unmap_pages(void* address, size_t count)
|
||||
{
|
||||
addr_t addr = reinterpret_cast<addr_t>(address);
|
||||
uintptr_t addr = reinterpret_cast<uintptr_t>(address);
|
||||
size_t block_count = 0;
|
||||
|
||||
for (auto *block : m_used) {
|
||||
if (!block->contains(addr)) continue;
|
||||
|
||||
size_t size = page_size * count;
|
||||
addr_t end = addr + size;
|
||||
uintptr_t end = addr + size;
|
||||
|
||||
size_t leading = addr - block->virtual_address;
|
||||
size_t trailing =
|
||||
@@ -437,7 +437,7 @@ page_manager::check_needs_page(page_table *table, unsigned index, bool user)
|
||||
}
|
||||
|
||||
void
|
||||
page_manager::page_in(page_table *pml4, addr_t phys_addr, addr_t virt_addr, size_t count, bool user)
|
||||
page_manager::page_in(page_table *pml4, uintptr_t phys_addr, uintptr_t virt_addr, size_t count, bool user)
|
||||
{
|
||||
page_table_indices idx{virt_addr};
|
||||
page_table *tables[4] = {pml4, nullptr, nullptr, nullptr};
|
||||
@@ -482,7 +482,7 @@ page_manager::page_in(page_table *pml4, addr_t phys_addr, addr_t virt_addr, size
|
||||
}
|
||||
|
||||
void
|
||||
page_manager::page_out(page_table *pml4, addr_t virt_addr, size_t count)
|
||||
page_manager::page_out(page_table *pml4, uintptr_t virt_addr, size_t count)
|
||||
{
|
||||
page_table_indices idx{virt_addr};
|
||||
page_table *tables[4] = {pml4, nullptr, nullptr, nullptr};
|
||||
@@ -511,7 +511,7 @@ page_manager::page_out(page_table *pml4, addr_t virt_addr, size_t count)
|
||||
}
|
||||
|
||||
size_t
|
||||
page_manager::pop_pages(size_t count, addr_t *address)
|
||||
page_manager::pop_pages(size_t count, uintptr_t *address)
|
||||
{
|
||||
kassert(!m_free.empty(), "page_manager::pop_pages ran out of free pages!");
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kutil/memory.h"
|
||||
#include "kutil/enum_bitfields.h"
|
||||
#include "kutil/linked_list.h"
|
||||
#include "kutil/slab_allocator.h"
|
||||
@@ -25,13 +24,13 @@ public:
|
||||
static const size_t page_size = 0x1000;
|
||||
|
||||
/// Start of the higher half.
|
||||
static const addr_t high_offset = 0xffffff0000000000;
|
||||
static const uintptr_t high_offset = 0xffffff0000000000;
|
||||
|
||||
/// Offset from physical where page tables are mapped.
|
||||
static const addr_t page_offset = 0xffffff8000000000;
|
||||
static const uintptr_t page_offset = 0xffffff8000000000;
|
||||
|
||||
/// Initial process thread's stack address
|
||||
static const addr_t initial_stack = 0x0000800000000000;
|
||||
static const uintptr_t initial_stack = 0x0000800000000000;
|
||||
|
||||
/// Initial process thread's stack size, in pages
|
||||
static const unsigned initial_stack_pages = 1;
|
||||
@@ -50,7 +49,7 @@ public:
|
||||
/// \returns A pointer to the current PML4 table.
|
||||
static inline page_table * get_pml4()
|
||||
{
|
||||
addr_t pml4 = 0;
|
||||
uintptr_t pml4 = 0;
|
||||
__asm__ __volatile__ ( "mov %%cr3, %0" : "=r" (pml4) );
|
||||
return reinterpret_cast<page_table *>((pml4 & ~0xfffull) + page_offset);
|
||||
}
|
||||
@@ -59,7 +58,7 @@ public:
|
||||
/// \arg pml4 A pointer to the PML4 table to install.
|
||||
static inline void set_pml4(page_table *pml4)
|
||||
{
|
||||
addr_t p = reinterpret_cast<addr_t>(pml4) - page_offset;
|
||||
uintptr_t p = reinterpret_cast<uintptr_t>(pml4) - page_offset;
|
||||
__asm__ __volatile__ ( "mov %0, %%cr3" :: "r" (p & ~0xfffull) );
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ public:
|
||||
/// \arg user True is this memory is user-accessible
|
||||
/// \arg pml4 The pml4 to map into - null for the current one
|
||||
/// \returns A pointer to the start of the mapped region
|
||||
void * map_pages(addr_t address, size_t count, bool user = false, page_table *pml4 = nullptr);
|
||||
void * map_pages(uintptr_t address, size_t count, bool user = false, page_table *pml4 = nullptr);
|
||||
|
||||
/// Allocate and map contiguous pages into virtual memory, with
|
||||
/// a constant offset from their physical address.
|
||||
@@ -99,15 +98,15 @@ public:
|
||||
/// Get the physical address of an offset-mapped pointer
|
||||
/// \arg p Virtual address of memory that has been offset-mapped
|
||||
/// \returns Physical address of the memory pointed to by p
|
||||
inline addr_t offset_phys(void *p) const
|
||||
inline uintptr_t offset_phys(void *p) const
|
||||
{
|
||||
return reinterpret_cast<addr_t>(kutil::offset_pointer(p, -page_offset));
|
||||
return reinterpret_cast<uintptr_t>(kutil::offset_pointer(p, -page_offset));
|
||||
}
|
||||
|
||||
/// Get the virtual address of an offset-mapped physical address
|
||||
/// \arg a Physical address of memory that has been offset-mapped
|
||||
/// \returns Virtual address of the memory at address a
|
||||
inline void * offset_virt(addr_t a) const
|
||||
inline void * offset_virt(uintptr_t a) const
|
||||
{
|
||||
return kutil::offset_pointer(reinterpret_cast<void *>(a), page_offset);
|
||||
}
|
||||
@@ -172,8 +171,8 @@ private:
|
||||
/// \art user True if this is a userspace mapping
|
||||
void page_in(
|
||||
page_table *pml4,
|
||||
addr_t phys_addr,
|
||||
addr_t virt_addr,
|
||||
uintptr_t phys_addr,
|
||||
uintptr_t virt_addr,
|
||||
size_t count,
|
||||
bool user = false);
|
||||
|
||||
@@ -183,7 +182,7 @@ private:
|
||||
/// \arg count The number of pages to unmap
|
||||
void page_out(
|
||||
page_table *pml4,
|
||||
addr_t virt_addr,
|
||||
uintptr_t virt_addr,
|
||||
size_t count);
|
||||
|
||||
/// Get free pages from the free list. Only pages from the first free block
|
||||
@@ -192,7 +191,7 @@ private:
|
||||
/// \arg count The maximum number of pages to get
|
||||
/// \arg address [out] The address of the first page
|
||||
/// \returns The number of pages retrieved
|
||||
size_t pop_pages(size_t count, addr_t *address);
|
||||
size_t pop_pages(size_t count, uintptr_t *address);
|
||||
|
||||
page_table *m_kernel_pml4; ///< The PML4 of just kernel pages
|
||||
|
||||
@@ -235,17 +234,17 @@ IS_BITFIELD(page_block_flags);
|
||||
/// linked list of such structures.
|
||||
struct page_block
|
||||
{
|
||||
addr_t physical_address;
|
||||
addr_t virtual_address;
|
||||
uintptr_t physical_address;
|
||||
uintptr_t virtual_address;
|
||||
uint32_t count;
|
||||
page_block_flags flags;
|
||||
|
||||
inline bool has_flag(page_block_flags f) const { return bitfield_has(flags, f); }
|
||||
inline addr_t physical_end() const { return physical_address + (count * page_manager::page_size); }
|
||||
inline addr_t virtual_end() const { return virtual_address + (count * page_manager::page_size); }
|
||||
inline uintptr_t physical_end() const { return physical_address + (count * page_manager::page_size); }
|
||||
inline uintptr_t virtual_end() const { return virtual_address + (count * page_manager::page_size); }
|
||||
|
||||
inline bool contains(addr_t vaddr) const { return vaddr >= virtual_address && vaddr < virtual_end(); }
|
||||
inline bool contains_physical(addr_t addr) const { return addr >= physical_address && addr < physical_end(); }
|
||||
inline bool contains(uintptr_t vaddr) const { return vaddr >= virtual_address && vaddr < virtual_end(); }
|
||||
inline bool contains_physical(uintptr_t addr) const { return addr >= physical_address && addr < physical_end(); }
|
||||
|
||||
/// Helper to zero out a block and optionally set the next pointer.
|
||||
void zero();
|
||||
@@ -318,7 +317,7 @@ template <typename T> inline T
|
||||
page_align(T p)
|
||||
{
|
||||
return reinterpret_cast<T>(
|
||||
((reinterpret_cast<addr_t>(p) - 1) & ~(page_manager::page_size - 1))
|
||||
((reinterpret_cast<uintptr_t>(p) - 1) & ~(page_manager::page_size - 1))
|
||||
+ page_manager::page_size);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ pci_device::set_bar(unsigned i, uint32_t val)
|
||||
}
|
||||
|
||||
void
|
||||
pci_device::write_msi_regs(addr_t address, uint16_t data)
|
||||
pci_device::write_msi_regs(uintptr_t address, uint16_t data)
|
||||
{
|
||||
kassert(m_msi, "Tried to write MSI for a device without that cap");
|
||||
if (m_msi->id == pci_cap::type::msi) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
/// \file pci.h
|
||||
/// PCI devices and groups
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/memory.h"
|
||||
|
||||
@@ -75,7 +76,7 @@ public:
|
||||
/// Write to the MSI registers
|
||||
/// \arg addr The address to write to the MSI address registers
|
||||
/// \arg data The value to write to the MSI data register
|
||||
void write_msi_regs(addr_t addr, uint16_t data);
|
||||
void write_msi_regs(uintptr_t addr, uint16_t data);
|
||||
|
||||
/// Get a bus address, given the bus/device/function numbers.
|
||||
/// \arg bus Number of the bus
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
/// \file process.h
|
||||
/// The processes and related definitions
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/enum_bitfields.h"
|
||||
#include "kutil/linked_list.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "page_manager.h"
|
||||
|
||||
|
||||
@@ -46,7 +47,7 @@ struct process
|
||||
|
||||
uint32_t reserved1;
|
||||
|
||||
addr_t rsp;
|
||||
uintptr_t rsp;
|
||||
page_table *pml4;
|
||||
|
||||
/// Unready this process until it gets a signal
|
||||
|
||||
@@ -67,7 +67,7 @@ load_process(const void *image_start, size_t bytes, process *proc, cpu_state sta
|
||||
if (header->type != elf::segment_type::load)
|
||||
continue;
|
||||
|
||||
addr_t aligned = header->vaddr & ~(page_manager::page_size - 1);
|
||||
uintptr_t aligned = header->vaddr & ~(page_manager::page_size - 1);
|
||||
size_t size = (header->vaddr + header->mem_size) - aligned;
|
||||
size_t pages = page_manager::page_count(size);
|
||||
|
||||
@@ -153,7 +153,7 @@ scheduler::create_process(const char *name, const void *data, size_t size)
|
||||
proc->pid = pid;
|
||||
proc->ppid = 0; // TODO
|
||||
proc->priority = default_priority;
|
||||
proc->rsp = reinterpret_cast<addr_t>(loader_state);
|
||||
proc->rsp = reinterpret_cast<uintptr_t>(loader_state);
|
||||
proc->pml4 = pml4;
|
||||
proc->quanta = process_quanta;
|
||||
proc->flags =
|
||||
@@ -228,8 +228,8 @@ void scheduler::prune(uint64_t now)
|
||||
}
|
||||
}
|
||||
|
||||
addr_t
|
||||
scheduler::schedule(addr_t rsp0)
|
||||
uintptr_t
|
||||
scheduler::schedule(uintptr_t rsp0)
|
||||
{
|
||||
|
||||
// TODO: lol a real clock
|
||||
@@ -268,8 +268,8 @@ scheduler::schedule(addr_t rsp0)
|
||||
return rsp0;
|
||||
}
|
||||
|
||||
addr_t
|
||||
scheduler::tick(addr_t rsp0)
|
||||
uintptr_t
|
||||
scheduler::tick(uintptr_t rsp0)
|
||||
{
|
||||
if (--m_current->quanta == 0) {
|
||||
m_current->quanta = process_quanta;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
/// \file scheduler.h
|
||||
/// The task scheduler and related definitions
|
||||
#include "kutil/memory.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/slab_allocator.h"
|
||||
#include "process.h"
|
||||
|
||||
@@ -9,7 +10,7 @@ class lapic;
|
||||
struct page_table;
|
||||
struct cpu_state;
|
||||
|
||||
extern "C" addr_t isr_handler(addr_t, cpu_state);
|
||||
extern "C" uintptr_t isr_handler(uintptr_t, cpu_state);
|
||||
|
||||
|
||||
/// The task scheduler
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
/// Run the scheduler, possibly switching to a new task
|
||||
/// \arg rsp0 The stack pointer of the current interrupt handler
|
||||
/// \returns The stack pointer to switch to
|
||||
addr_t schedule(addr_t rsp0);
|
||||
uintptr_t schedule(uintptr_t rsp0);
|
||||
|
||||
/// Get the current process.
|
||||
/// \returns A pointer to the current process' process struct
|
||||
@@ -58,13 +59,13 @@ public:
|
||||
static scheduler & get() { return s_instance; }
|
||||
|
||||
private:
|
||||
friend addr_t syscall_dispatch(addr_t, const cpu_state &);
|
||||
friend addr_t isr_handler(addr_t, cpu_state);
|
||||
friend uintptr_t syscall_dispatch(uintptr_t, const cpu_state &);
|
||||
friend uintptr_t isr_handler(uintptr_t, cpu_state);
|
||||
|
||||
/// Handle a timer tick
|
||||
/// \arg rsp0 The stack pointer of the current interrupt handler
|
||||
/// \returns The stack pointer to switch to
|
||||
addr_t tick(addr_t rsp0);
|
||||
uintptr_t tick(uintptr_t rsp0);
|
||||
|
||||
void prune(uint64_t now);
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ syscall_enable()
|
||||
|
||||
// IA32_LSTAR - RIP for syscall
|
||||
wrmsr(msr::ia32_lstar,
|
||||
reinterpret_cast<addr_t>(&syscall_handler_prelude));
|
||||
reinterpret_cast<uintptr_t>(&syscall_handler_prelude));
|
||||
|
||||
// IA32_FMASK - FLAGS mask inside syscall
|
||||
wrmsr(msr::ia32_fmask, 0x200);
|
||||
}
|
||||
|
||||
addr_t
|
||||
syscall_dispatch(addr_t return_rsp, const cpu_state ®s)
|
||||
uintptr_t
|
||||
syscall_dispatch(uintptr_t return_rsp, const cpu_state ®s)
|
||||
{
|
||||
console *cons = console::get();
|
||||
syscall call = static_cast<syscall>(regs.rax);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "kutil/memory.h"
|
||||
|
||||
struct cpu_state;
|
||||
|
||||
@@ -17,5 +16,5 @@ enum class syscall : uint64_t
|
||||
};
|
||||
|
||||
void syscall_enable();
|
||||
addr_t syscall_dispatch(addr_t, const cpu_state &);
|
||||
uintptr_t syscall_dispatch(uintptr_t, const cpu_state &);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "elf/elf.h"
|
||||
#include "elf/headers.h"
|
||||
#include "kutil/memory.h"
|
||||
|
||||
static const uint32_t expected_magic = 0x464c457f; // "\x7f" "ELF"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "elf/headers.h"
|
||||
#include "kutil/memory.h"
|
||||
|
||||
namespace elf {
|
||||
|
||||
@@ -19,9 +19,9 @@ public:
|
||||
|
||||
/// Get the entrypoint address of the program image
|
||||
/// \returns A pointer to the entrypoint of the program
|
||||
inline addr_t entrypoint() const
|
||||
inline uintptr_t entrypoint() const
|
||||
{
|
||||
return static_cast<addr_t>(header()->entrypoint);
|
||||
return static_cast<uintptr_t>(header()->entrypoint);
|
||||
}
|
||||
|
||||
/// Get the number of program sections in the image
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
using addr_t = uint64_t;
|
||||
|
||||
void * operator new (size_t, void *p) noexcept;
|
||||
|
||||
|
||||
@@ -50,7 +48,7 @@ inline T read_from(const void *p)
|
||||
template <typename T>
|
||||
inline T * offset_pointer(T *p, ptrdiff_t n)
|
||||
{
|
||||
return reinterpret_cast<T *>(reinterpret_cast<addr_t>(p) + n);
|
||||
return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(p) + n);
|
||||
}
|
||||
|
||||
/// Return a pointer with the given bits masked out
|
||||
@@ -58,9 +56,9 @@ inline T * offset_pointer(T *p, ptrdiff_t n)
|
||||
/// \arg mask A bitmask of bits to clear from p
|
||||
/// \returns The masked pointer
|
||||
template <typename T>
|
||||
inline T* mask_pointer(T *p, addr_t mask)
|
||||
inline T* mask_pointer(T *p, uintptr_t mask)
|
||||
{
|
||||
return reinterpret_cast<T *>(reinterpret_cast<addr_t>(p) & ~mask);
|
||||
return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(p) & ~mask);
|
||||
}
|
||||
|
||||
/// Do a simple byte-wise checksum of an area of memory.
|
||||
|
||||
@@ -17,13 +17,13 @@ struct memory_manager::mem_header
|
||||
inline void set_size(uint8_t size)
|
||||
{
|
||||
m_prev = reinterpret_cast<mem_header *>(
|
||||
reinterpret_cast<addr_t>(prev()) | (size & 0x3f));
|
||||
reinterpret_cast<uintptr_t>(prev()) | (size & 0x3f));
|
||||
}
|
||||
|
||||
inline void set_used(bool used)
|
||||
{
|
||||
m_next = reinterpret_cast<mem_header *>(
|
||||
reinterpret_cast<addr_t>(next()) | (used ? 1 : 0));
|
||||
reinterpret_cast<uintptr_t>(next()) | (used ? 1 : 0));
|
||||
}
|
||||
|
||||
inline void set_next(mem_header *next)
|
||||
@@ -53,13 +53,13 @@ struct memory_manager::mem_header
|
||||
|
||||
inline mem_header * buddy() const {
|
||||
return reinterpret_cast<mem_header *>(
|
||||
reinterpret_cast<addr_t>(this) ^ (1 << size()));
|
||||
reinterpret_cast<uintptr_t>(this) ^ (1 << size()));
|
||||
}
|
||||
|
||||
inline bool eldest() const { return this < buddy(); }
|
||||
|
||||
inline uint8_t size() const { return reinterpret_cast<addr_t>(m_prev) & 0x3f; }
|
||||
inline bool used() const { return reinterpret_cast<addr_t>(m_next) & 0x1; }
|
||||
inline uint8_t size() const { return reinterpret_cast<uintptr_t>(m_prev) & 0x3f; }
|
||||
inline bool used() const { return reinterpret_cast<uintptr_t>(m_next) & 0x1; }
|
||||
|
||||
private:
|
||||
mem_header *m_prev;
|
||||
|
||||
Reference in New Issue
Block a user