compiler problems...

This commit is contained in:
Jack Halford 2019-05-17 21:09:57 +02:00
parent f479edf1a3
commit ce879e11b2
8 changed files with 91 additions and 68 deletions

View file

@ -7,8 +7,9 @@ pub fn build(b: *Builder) void {
kernel.addPackagePath("arch", "src/arch/x86/lib/index.zig"); kernel.addPackagePath("arch", "src/arch/x86/lib/index.zig");
kernel.setOutputDir("build"); kernel.setOutputDir("build");
// kernel.addAssemblyFile("src/arch/x86/_start.s");
kernel.addAssemblyFile("src/arch/x86/gdt.s"); kernel.addAssemblyFile("src/arch/x86/gdt.s");
kernel.addAssemblyFile("src/arch/x86/isr.s"); // kernel.addAssemblyFile("src/arch/x86/isr.s");
kernel.setBuildMode(b.standardReleaseOptions()); kernel.setBuildMode(b.standardReleaseOptions());
kernel.setTarget(builtin.Arch.i386, builtin.Os.freestanding, builtin.Abi.none); kernel.setTarget(builtin.Arch.i386, builtin.Os.freestanding, builtin.Abi.none);

15
src/arch/x86/_start.s Normal file
View file

@ -0,0 +1,15 @@
.global _start
.type _start, @function
// Entry point. It puts the machine into a consistent state,
// starts the kernel and then waits forever.
_start:
mov $0x80000, %esp // Setup the stack.
push %ebx // Pass multiboot info structure.
push %eax // Pass multiboot magic code.
call x86_main // Call the kernel.
// Halt the CPU.
cli
hlt

View file

@ -1,23 +1,23 @@
.type loadGDT, @function .type loadGDT, @function
// ////
// Load the GDT into the system registers. // Load the GDT into the system registers.
// //
// Arguments: // Arguments:
// gdtr: Pointer to the GDTR. // gdtr: Pointer to the GDTR.
// //
loadGDT: loadGDT:
mov +4(%esp), %eax // Fetch the gdtr parameter. mov +4(%esp), %eax // Fetch the gdtr parameter.
lgdt (%eax) // Load the new GDT. lgdt (%eax) // Load the new GDT.
// Reload data segments (GDT entry 2: kernel data). // Reload data segments (GDT entry 2: kernel data).
mov $0x10, %ax mov $0x10, %ax
mov %ax, %ds mov %ax, %ds
mov %ax, %es mov %ax, %es
mov %ax, %fs mov %ax, %fs
mov %ax, %gs mov %ax, %gs
mov %ax, %ss mov %ax, %ss
// Reload code segment (GDT entry 1: kernel code). // Reload code segment (GDT entry 1: kernel code).
ljmp $0x08, $1f ljmp $0x08, $1f
1: ret 1: ret

View file

@ -103,56 +103,56 @@ pub export var context: *volatile Context = undefined;
pub fn install() void { pub fn install() void {
// Exceptions. // Exceptions.
idt.setGate(0, idt.INTERRUPT_GATE, isr0); idt.setGate(0, idt.INTERRUPT_GATE, isr0);
idt.setGate(1, idt.INTERRUPT_GATE, isr1); // idt.setGate(1, idt.INTERRUPT_GATE, isr1);
idt.setGate(2, idt.INTERRUPT_GATE, isr2); // idt.setGate(2, idt.INTERRUPT_GATE, isr2);
idt.setGate(3, idt.INTERRUPT_GATE, isr3); // idt.setGate(3, idt.INTERRUPT_GATE, isr3);
idt.setGate(4, idt.INTERRUPT_GATE, isr4); // idt.setGate(4, idt.INTERRUPT_GATE, isr4);
idt.setGate(5, idt.INTERRUPT_GATE, isr5); // idt.setGate(5, idt.INTERRUPT_GATE, isr5);
idt.setGate(6, idt.INTERRUPT_GATE, isr6); // idt.setGate(6, idt.INTERRUPT_GATE, isr6);
idt.setGate(7, idt.INTERRUPT_GATE, isr7); // idt.setGate(7, idt.INTERRUPT_GATE, isr7);
idt.setGate(8, idt.INTERRUPT_GATE, isr8); // idt.setGate(8, idt.INTERRUPT_GATE, isr8);
idt.setGate(9, idt.INTERRUPT_GATE, isr9); // idt.setGate(9, idt.INTERRUPT_GATE, isr9);
idt.setGate(10, idt.INTERRUPT_GATE, isr10); // idt.setGate(10, idt.INTERRUPT_GATE, isr10);
idt.setGate(11, idt.INTERRUPT_GATE, isr11); // idt.setGate(11, idt.INTERRUPT_GATE, isr11);
idt.setGate(12, idt.INTERRUPT_GATE, isr12); // idt.setGate(12, idt.INTERRUPT_GATE, isr12);
idt.setGate(13, idt.INTERRUPT_GATE, isr13); // idt.setGate(13, idt.INTERRUPT_GATE, isr13);
idt.setGate(14, idt.INTERRUPT_GATE, isr14); // idt.setGate(14, idt.INTERRUPT_GATE, isr14);
idt.setGate(15, idt.INTERRUPT_GATE, isr15); // idt.setGate(15, idt.INTERRUPT_GATE, isr15);
idt.setGate(16, idt.INTERRUPT_GATE, isr16); // idt.setGate(16, idt.INTERRUPT_GATE, isr16);
idt.setGate(17, idt.INTERRUPT_GATE, isr17); // idt.setGate(17, idt.INTERRUPT_GATE, isr17);
idt.setGate(18, idt.INTERRUPT_GATE, isr18); // idt.setGate(18, idt.INTERRUPT_GATE, isr18);
idt.setGate(19, idt.INTERRUPT_GATE, isr19); // idt.setGate(19, idt.INTERRUPT_GATE, isr19);
idt.setGate(20, idt.INTERRUPT_GATE, isr20); // idt.setGate(20, idt.INTERRUPT_GATE, isr20);
idt.setGate(21, idt.INTERRUPT_GATE, isr21); // idt.setGate(21, idt.INTERRUPT_GATE, isr21);
idt.setGate(22, idt.INTERRUPT_GATE, isr22); // idt.setGate(22, idt.INTERRUPT_GATE, isr22);
idt.setGate(23, idt.INTERRUPT_GATE, isr23); // idt.setGate(23, idt.INTERRUPT_GATE, isr23);
idt.setGate(24, idt.INTERRUPT_GATE, isr24); // idt.setGate(24, idt.INTERRUPT_GATE, isr24);
idt.setGate(25, idt.INTERRUPT_GATE, isr25); // idt.setGate(25, idt.INTERRUPT_GATE, isr25);
idt.setGate(26, idt.INTERRUPT_GATE, isr26); // idt.setGate(26, idt.INTERRUPT_GATE, isr26);
idt.setGate(27, idt.INTERRUPT_GATE, isr27); // idt.setGate(27, idt.INTERRUPT_GATE, isr27);
idt.setGate(28, idt.INTERRUPT_GATE, isr28); // idt.setGate(28, idt.INTERRUPT_GATE, isr28);
idt.setGate(29, idt.INTERRUPT_GATE, isr29); // idt.setGate(29, idt.INTERRUPT_GATE, isr29);
idt.setGate(30, idt.INTERRUPT_GATE, isr30); // idt.setGate(30, idt.INTERRUPT_GATE, isr30);
idt.setGate(31, idt.INTERRUPT_GATE, isr31); // idt.setGate(31, idt.INTERRUPT_GATE, isr31);
// IRQs. // // IRQs.
idt.setGate(32, idt.INTERRUPT_GATE, isr32); // idt.setGate(32, idt.INTERRUPT_GATE, isr32);
idt.setGate(33, idt.INTERRUPT_GATE, isr33); // idt.setGate(33, idt.INTERRUPT_GATE, isr33);
idt.setGate(34, idt.INTERRUPT_GATE, isr34); // idt.setGate(34, idt.INTERRUPT_GATE, isr34);
idt.setGate(35, idt.INTERRUPT_GATE, isr35); // idt.setGate(35, idt.INTERRUPT_GATE, isr35);
idt.setGate(36, idt.INTERRUPT_GATE, isr36); // idt.setGate(36, idt.INTERRUPT_GATE, isr36);
idt.setGate(37, idt.INTERRUPT_GATE, isr37); // idt.setGate(37, idt.INTERRUPT_GATE, isr37);
idt.setGate(38, idt.INTERRUPT_GATE, isr38); // idt.setGate(38, idt.INTERRUPT_GATE, isr38);
idt.setGate(39, idt.INTERRUPT_GATE, isr39); // idt.setGate(39, idt.INTERRUPT_GATE, isr39);
idt.setGate(40, idt.INTERRUPT_GATE, isr40); // idt.setGate(40, idt.INTERRUPT_GATE, isr40);
idt.setGate(41, idt.INTERRUPT_GATE, isr41); // idt.setGate(41, idt.INTERRUPT_GATE, isr41);
idt.setGate(42, idt.INTERRUPT_GATE, isr42); // idt.setGate(42, idt.INTERRUPT_GATE, isr42);
idt.setGate(43, idt.INTERRUPT_GATE, isr43); // idt.setGate(43, idt.INTERRUPT_GATE, isr43);
idt.setGate(44, idt.INTERRUPT_GATE, isr44); // idt.setGate(44, idt.INTERRUPT_GATE, isr44);
idt.setGate(45, idt.INTERRUPT_GATE, isr45); // idt.setGate(45, idt.INTERRUPT_GATE, isr45);
idt.setGate(46, idt.INTERRUPT_GATE, isr46); // idt.setGate(46, idt.INTERRUPT_GATE, isr46);
idt.setGate(47, idt.INTERRUPT_GATE, isr47); // idt.setGate(47, idt.INTERRUPT_GATE, isr47);
// Syscalls. // // Syscalls.
idt.setGate(128, idt.SYSCALL_GATE, isr128); // idt.setGate(128, idt.SYSCALL_GATE, isr128);
} }

View file

@ -1,4 +1,5 @@
ENTRY(_start) /* ENTRY(_start) */
ENTRY(x86_main)
/* OUTPUT_FORMAT(elf32-i386) */ /* OUTPUT_FORMAT(elf32-i386) */
SECTIONS { SECTIONS {

View file

@ -1,13 +1,16 @@
use @import("kernel").main; use @import("kernel").main;
use @import("kernel").multiboot;
const idt = @import("idt.zig"); const idt = @import("idt.zig");
const gdt = @import("gdt.zig"); const gdt = @import("gdt.zig");
const x86 = @import("lib/index.zig"); const x86 = @import("lib/index.zig");
const assert = @import("std").debug.assert;
/// x86 specific intialization /// x86 specific intialization
/// first entry point (see linker.ld) /// first entry point (see linker.ld)
export nakedcc fn _start() noreturn { export nakedcc fn x86_main(magic: u32, info: *const MultibootInfo) noreturn {
// assert(magic == MULTIBOOT_BOOTLOADER_MAGIC);
gdt.initialize(); gdt.initialize();
idt.initialize(); idt.initialize();
x86.sti(); x86.sti();
kmain(); kmain(magic, info);
} }

View file

@ -1,2 +1,3 @@
pub const vga = @import("vga.zig"); pub const vga = @import("vga.zig");
pub const main = @import("main.zig"); pub const main = @import("main.zig");
pub const multiboot = @import("multiboot.zig");

View file

@ -2,9 +2,11 @@ use @import("multiboot.zig");
const pci = @import("pci.zig"); const pci = @import("pci.zig");
const arch = @import("arch/x86/lib/index.zig"); const arch = @import("arch/x86/lib/index.zig");
const console = @import("console.zig"); const console = @import("console.zig");
const vga = @import("vga.zig");
// platform independant initialization // platform independant initialization
pub fn kmain() noreturn { pub fn kmain(magic: u32, info: *const MultibootInfo) noreturn {
console.initialize(); console.initialize();
vga.printf("magic 0x{x}\n", magic);
while (true) {} while (true) {}
} }