Capitalize namespacing structs

This helps to avoid name clashes when breaking up modules into packages.
This commit is contained in:
Josh Holtrop 2023-01-01 17:34:41 -05:00
parent a423cdf1b1
commit 25ee1775f0
16 changed files with 86 additions and 86 deletions

View File

@ -103,7 +103,7 @@ static void generate(const char * d_file_name)
fprintf(fh, " int baseline_offset;\n");
fprintf(fh, " const CharInfo[] chars;\n");
fprintf(fh, "};\n");
fprintf(fh, "__gshared const FontInfo kfont = {\n");
fprintf(fh, "__gshared const FontInfo Kfont = {\n");
fprintf(fh, " %du,\n", line_height);
fprintf(fh, " %du,\n", max_advance);
fprintf(fh, " %d,\n", baseline_offset);

View File

@ -7,7 +7,7 @@ import hulk.hurl;
import hulk.klog;
import hulk.memory;
struct acpi
struct Acpi
{
enum uint APIC_SIGNATURE = 0x43495041u;
enum uint XSDT_SIGNATURE = 0x54445358u;
@ -58,20 +58,20 @@ struct acpi
public static void initialize(ulong acpi_xsdt_phys)
{
/* Map the XSDT header. */
hurl.identity_map_range(acpi_xsdt_phys, Xsdt.sizeof, 0u);
Hurl.identity_map_range(acpi_xsdt_phys, Xsdt.sizeof, 0u);
const(Xsdt) * xsdt = cast(const(Xsdt) *)acpi_xsdt_phys;
if (xsdt.header.signature != XSDT_SIGNATURE)
{
klog.writef("XSDT signature invalid\n");
Klog.writef("XSDT signature invalid\n");
return;
}
/* Map the entire XSDT. */
hurl.identity_map_range(acpi_xsdt_phys, xsdt.header.length, 0u);
Hurl.identity_map_range(acpi_xsdt_phys, xsdt.header.length, 0u);
size_t n_entries = (xsdt.header.length - xsdt.header.sizeof) / xsdt.tables[0].sizeof;
for (size_t i = 0u; i < n_entries; i++)
{
ulong address = xsdt.tables[i];
hurl.identity_map_range(address, 4u, 0u);
Hurl.identity_map_range(address, 4u, 0u);
uint signature = *cast(const(uint) *)address;
if (signature == APIC_SIGNATURE)
{
@ -83,9 +83,9 @@ struct acpi
private static parse_apic_table(ulong address)
{
const(MadtHeader) * madt_header = cast(const(MadtHeader) *)address;
hurl.identity_map_range(address, madt_header.length, 0u);
Hurl.identity_map_range(address, madt_header.length, 0u);
apic_address = madt_header.local_apic_address;
klog.writefln("Found 32-bit APIC address: 0x%x", apic_address);
Klog.writefln("Found 32-bit APIC address: 0x%x", apic_address);
const(void) * madt_end = cast(const(void) *)(address + madt_header.length);
const(MadtEntry) * madt_entry = cast(const(MadtEntry) *)(address + 0x2Cu);
while (madt_entry < madt_end)
@ -95,7 +95,7 @@ struct acpi
{
/* Found a 64-bit Local APIC Address Override entry. */
memcpy(cast(void *)&apic_address, cast(const(void) *)madt_entry + 4u, 8u);
klog.writefln("Found 64-bit APIC address: 0x%x", apic_address);
Klog.writefln("Found 64-bit APIC address: 0x%x", apic_address);
}
}
}

View File

@ -9,7 +9,7 @@ import hulk.acpi;
import hulk.idt;
import hulk.rtc;
struct apic
struct Apic
{
private enum uint PERIODIC_MODE = 0x2_0000u;
@ -66,22 +66,22 @@ struct apic
public static void initialize()
{
apic_registers = cast(ApicRegisters *)acpi.apic_address;
apic_registers = cast(ApicRegisters *)Acpi.apic_address;
io_apic_registers = cast(IoApicRegisters *)0xFEC0_0000u;
hurl.map(cast(ulong)apic_registers, cast(ulong)apic_registers,
Hurl.map(cast(ulong)apic_registers, cast(ulong)apic_registers,
PT_WRITABLE | PT_WRITE_THROUGH | PT_DISABLE_CACHE | PT_NO_EXECUTE);
hurl.map(cast(ulong)io_apic_registers, cast(ulong)io_apic_registers,
Hurl.map(cast(ulong)io_apic_registers, cast(ulong)io_apic_registers,
PT_WRITABLE | PT_WRITE_THROUGH | PT_DISABLE_CACHE | PT_NO_EXECUTE);
klog.writefln("LAPIC ID: 0x%08x", apic_registers.lapic_id.value);
klog.writefln("LAPIC version: 0x%08x", apic_registers.lapic_version.value);
Klog.writefln("LAPIC ID: 0x%08x", apic_registers.lapic_id.value);
Klog.writefln("LAPIC version: 0x%08x", apic_registers.lapic_version.value);
/* Enable local APIC to receive interrupts and set spurious interrupt
* vector to 0xFF. */
apic_registers.spurious_interrupt_vector.value = 0x100u | idt.INT_APIC_SPURIOUS;
apic_registers.lvt_timer.value = idt.INT_APIC_TIMER;
apic_registers.lvt_lint[0].value = idt.INT_APIC_LINT0;
apic_registers.lvt_lint[1].value = idt.INT_APIC_LINT1;
apic_registers.spurious_interrupt_vector.value = 0x100u | Idt.INT_APIC_SPURIOUS;
apic_registers.lvt_timer.value = Idt.INT_APIC_TIMER;
apic_registers.lvt_lint[0].value = Idt.INT_APIC_LINT0;
apic_registers.lvt_lint[1].value = Idt.INT_APIC_LINT1;
/* Enable RTC interrupt. */
configure_io_apic_irq(IRQ_RTC, idt.INT_APIC_BASE + IRQ_RTC);
configure_io_apic_irq(IRQ_RTC, Idt.INT_APIC_BASE + IRQ_RTC);
}
private static void configure_io_apic_irq(size_t io_apic_irq, size_t interrupt_id)
@ -102,8 +102,8 @@ struct apic
{
switch (vector)
{
case idt.INT_APIC_BASE + IRQ_RTC:
rtc.isr();
case Idt.INT_APIC_BASE + IRQ_RTC:
Rtc.isr();
break;
default:

View File

@ -6,7 +6,7 @@ module hulk.console;
import hulk.fb;
import hulk.kfont;
struct console
struct Console
{
/** Console width in text columns. */
private static __gshared size_t m_width;
@ -25,8 +25,8 @@ struct console
*/
public static void initialize()
{
m_width = fb.width / kfont.advance;
m_height = fb.height / kfont.line_height;
m_width = Fb.width / Kfont.advance;
m_height = Fb.height / Kfont.line_height;
}
/**
@ -34,7 +34,7 @@ struct console
*/
public static void clear()
{
fb.clear();
Fb.clear();
m_x = 0u;
m_y = 0u;
}
@ -64,10 +64,10 @@ struct console
if (m_y == m_height)
{
m_y--;
fb.copy_rows_up(fb_y(m_height - 1u),
(m_height - 1u) * kfont.line_height,
kfont.line_height);
fb.rect(0u, fb_y(m_height - 1u), fb_x(m_width), kfont.line_height, 0u);
Fb.copy_rows_up(fb_y(m_height - 1u),
(m_height - 1u) * Kfont.line_height,
Kfont.line_height);
Fb.rect(0u, fb_y(m_height - 1u), fb_x(m_width), Kfont.line_height, 0u);
}
}
@ -80,8 +80,8 @@ struct console
*/
private static void render_char(size_t x, size_t y, char ch)
{
const(CharInfo) * ci = &kfont.chars[ch];
fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
const(CharInfo) * ci = &Kfont.chars[ch];
Fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
}
/**
@ -89,7 +89,7 @@ struct console
*/
private static size_t fb_x(size_t x)
{
return x * kfont.advance;
return x * Kfont.advance;
}
/**
@ -97,6 +97,6 @@ struct console
*/
private static size_t fb_y(size_t y)
{
return fb.height - ((y + 1u) * kfont.line_height);
return Fb.height - ((y + 1u) * Kfont.line_height);
}
}

View File

@ -11,7 +11,7 @@ import hulk.kfont;
*
* TODO: Handle other pixel formats. Currently only BGRx is supported.
*/
struct fb
struct Fb
{
/** Device frame buffer base address. */
private __gshared static uint * m_device_buffer;
@ -141,8 +141,8 @@ struct fb
*/
static void character(int x, int y, char ch, uint color)
{
const(CharInfo) * ci = &kfont.chars[ch];
blend_alpha_bitmap(x + ci.left, y + kfont.baseline_offset + ci.top - ci.height, ci.bitmap, ci.width, ci.height, color);
const(CharInfo) * ci = &Kfont.chars[ch];
blend_alpha_bitmap(x + ci.left, y + Kfont.baseline_offset + ci.top - ci.height, ci.bitmap, ci.width, ci.height, color);
}
/**

View File

@ -5,7 +5,7 @@ module hulk.gdt;
import ldc.llvmasm;
struct gdt
struct Gdt
{
struct gdtr_t
{

View File

@ -7,7 +7,7 @@
*/
module hulk.hippo;
struct hippo
struct Hippo
{
/**
* Linked list node entry for a physical page.

View File

@ -56,25 +56,25 @@ void hulk_start()
{
cli();
initialize_cpu();
gdt.initialize();
idt.initialize();
fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS,
Gdt.initialize();
Idt.initialize();
Fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS,
cast(uint *)hulk_header.bootinfo.fb_buffer1_phys,
hulk_header.bootinfo.fb.width,
hulk_header.bootinfo.fb.height,
hulk_header.bootinfo.fb.stride);
console.initialize();
console.clear();
klog.initialize();
Console.initialize();
Console.clear();
Klog.initialize();
klog.writefln("Welcome to HULK, the HOS UltraLight Kernel!");
Klog.writefln("Welcome to HULK, the HOS UltraLight Kernel!");
hurl.initialize(&hulk_header);
pci.initialize();
pic.initialize();
acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys);
apic.initialize();
rtc.initialize();
Hurl.initialize(&hulk_header);
Pci.initialize();
Pic.initialize();
Acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys);
Apic.initialize();
Rtc.initialize();
sti();
for (;;)

View File

@ -23,7 +23,7 @@ enum ulong HULK_VIRTUAL_STACK_TOP_ADDRESS = 0xFFFF_A000_0000_0000u;
/** HULK virtual framebuffer address. */
enum ulong HULK_VIRTUAL_FRAMEBUFFER_ADDRESS = 0xFFFF_A000_0000_0000u;
struct hurl
struct Hurl
{
/**
* Pointer to the base page table.
@ -121,7 +121,7 @@ struct hurl
reclaimed_pages += reclaim_bootloader_page_table_pages(pte.follow(), level + 1u);
}
}
hippo.free_page(pt);
Hippo.free_page(pt);
reclaimed_pages++;
return reclaimed_pages;
}
@ -186,7 +186,7 @@ struct hurl
}
if (!is_reserved)
{
hippo.free_page(phys);
Hippo.free_page(phys);
}
phys += PAGE_SIZE;
}
@ -213,8 +213,8 @@ struct hurl
usable_memory += LinkerAddresses.hulk_bss_size;
usable_memory += header.stack_size;
usable_memory += fb_size;
klog.writefln("Usable memory: %uKB", usable_memory >> 10u);
klog.writefln("Kernel size: %uKB", (LinkerAddresses.hulk_binary_size + LinkerAddresses.hulk_bss_size + header.stack_size) >> 10u);
Klog.writefln("Usable memory: %uKB", usable_memory >> 10u);
Klog.writefln("Kernel size: %uKB", (LinkerAddresses.hulk_binary_size + LinkerAddresses.hulk_bss_size + header.stack_size) >> 10u);
}
public static void map(T, U)(T virtual, U physical, ulong flags)
@ -266,12 +266,12 @@ struct hurl
public static void debug_lookup(void * address)
{
klog.writefln("Debugging page table lookup of 0x%x", address);
Klog.writefln("Debugging page table lookup of 0x%x", address);
PageTable * pt = m_pt_base;
for (size_t level = 0; level < 4u; level++)
{
PageTableEntry pte = *pt.entry(address, level);
klog.writefln("Level %u, index %u, entry = 0x%x", level, pt.index(address, level), pte);
Klog.writefln("Level %u, index %u, entry = 0x%x", level, pt.index(address, level), pte);
if (pte.present)
{
pt = pte.follow();
@ -289,7 +289,7 @@ struct hurl
private static PageTable * allocate_pt()
{
PageTable * pt = cast(PageTable *)hippo.allocate_page();
PageTable * pt = cast(PageTable *)Hippo.allocate_page();
memset64(pt, 0u, PAGE_SIZE / 8u);
return pt;
}

View File

@ -10,7 +10,7 @@ import hulk.console;
import hulk.klog;
import hulk.apic;
struct idt
struct Idt
{
/* The I/O APIC is configured to map IRQ 0 to interrupt 64 (0x40). */
public static enum ulong INT_APIC_BASE = 0x40u; /* IRQ 0 */
@ -96,7 +96,7 @@ struct idt
((offset & 0xFFFF_0000u) << 32u) |
(dpl << 45u) |
((trap ? 1uL : 0uL) << 40u) |
(gdt.SELECTOR_KERNEL_CODE << 16u) |
(Gdt.SELECTOR_KERNEL_CODE << 16u) |
(offset & 0xFFFFu);
idt[index][1] = offset >> 32u;
}
@ -104,25 +104,25 @@ struct idt
public extern(C) void isr(ulong vector, ulong arg)
{
if ((vector >= idt.INT_APIC_BASE) && (vector < (idt.INT_APIC_BASE + idt.INT_APIC_COUNT)))
if ((vector >= Idt.INT_APIC_BASE) && (vector < (Idt.INT_APIC_BASE + Idt.INT_APIC_COUNT)))
{
apic.isr(vector);
Apic.isr(vector);
}
else
{
switch (vector)
{
case idt.INT_APIC_TIMER:
case idt.INT_APIC_LINT0:
case idt.INT_APIC_LINT1:
case idt.INT_APIC_SPURIOUS:
apic.isr(vector);
case Idt.INT_APIC_TIMER:
case Idt.INT_APIC_LINT0:
case Idt.INT_APIC_LINT1:
case Idt.INT_APIC_SPURIOUS:
Apic.isr(vector);
break;
default:
console.clear();
fb.clear(0xFF8000u);
klog.writefln("ISR %u, 0x%x", vector, arg);
Console.clear();
Fb.clear(0xFF8000u);
Klog.writefln("ISR %u, 0x%x", vector, arg);
__asm("cli", "");
for (;;)
{

View File

@ -7,7 +7,7 @@ import core.stdc.stdarg;
import hulk.console;
static import hulk.writef;
struct klog
struct Klog
{
/**
* Kernel buffer size log.
@ -40,7 +40,7 @@ struct klog
public static void writef(string s, va_list args)
{
hulk.writef.writef(s, args, function void(ubyte ch) {
console.write(ch);
Console.write(ch);
});
}

View File

@ -31,7 +31,7 @@ enum ulong MTRRPHYSBASE_TYPE_MASK = 0xFFu;
enum ulong MTRRPHYSMASK_PHYSMASK_MASK = 0x000F_FFFF_FFFF_F000u;
enum ulong MTRRPHYSMASK_VALID = 0x800u;
struct mtrr
struct Mtrr
{
public static void initialize()
{
@ -41,7 +41,7 @@ struct mtrr
cpuid1(&ebx, &ecx, &edx);
if ((edx & CPUID_1_EDX_MTRR) == 0u)
{
klog.writefln("CPU does not support MTRR");
Klog.writefln("CPU does not support MTRR");
return;
}
const(ulong) mtrrcap = rdmsr(MSR_MTRRCAP);

View File

@ -3,7 +3,7 @@ module hulk.pci;
import hulk.cpu;
import hulk.klog;
struct pci
struct Pci
{
/* IO address for PCI configuration address. */
enum IO_ADDR_CONFIG_ADDRESS = 0xCF8u;
@ -24,7 +24,7 @@ struct pci
if (reg0 != 0xFFFFFFFFu)
{
ulong reg2 = read_config_register(bus_id, device_id, 2u);
klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u",
Klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u",
(reg0 & 0xFFFFu), (reg0 >> 16u),
(reg2 >> 24u) & 0xFFu,
(reg2 >> 16u) & 0xFFu,
@ -35,7 +35,7 @@ struct pci
public static void initialize()
{
klog.writefln("Scanning PCI devices...");
Klog.writefln("Scanning PCI devices...");
for (ulong bus_id = 0u; bus_id < 256u; bus_id++)
{
for (ulong device_id = 0u; device_id < 32u; device_id++)
@ -43,6 +43,6 @@ struct pci
scan(bus_id, device_id);
}
}
klog.writefln("PCI scan complete.");
Klog.writefln("PCI scan complete.");
}
}

View File

@ -5,7 +5,7 @@ module hulk.pic;
import hulk.cpu;
struct pic
struct Pic
{
public static void initialize()
{

View File

@ -6,7 +6,7 @@ module hulk.pit;
import hulk.cpu;
import hulk.klog;
struct pit
struct Pit
{
/** PIT input frequency in 1/1000 Hz. */
private enum ulong PIT_FREQUENCY_1000HZ = 1_193_181_667u;
@ -37,6 +37,6 @@ struct pit
public static void isr()
{
klog.writefln("PIT ISR");
Klog.writefln("PIT ISR");
}
}

View File

@ -6,7 +6,7 @@ module hulk.rtc;
import hulk.cpu;
import hulk.klog;
struct rtc
struct Rtc
{
private enum ubyte PORT_SELECT = 0x70u;
private enum ubyte PORT_DATA = 0x71u;
@ -53,7 +53,7 @@ struct rtc
/* Read the current system time. */
time t = read_rtc_time();
klog.writefln("System time is 20%02u-%02u-%02u %02u:%02u:%02u",
Klog.writefln("System time is 20%02u-%02u-%02u %02u:%02u:%02u",
t.year, t.month, t.day, t.hour, t.minute, t.second);
/* Send EOI to enable more RTC interrupts and re-enable NMIs. */
@ -86,7 +86,7 @@ struct rtc
if ((count % 1024) == 0u)
{
seconds++;
klog.writefln("Seconds: %u", seconds);
Klog.writefln("Seconds: %u", seconds);
}
eoi();
}