Merge pull request #70 from vmttmv/main

Kernel build fixes
This commit is contained in:
2025-11-18 18:11:18 -08:00
committed by GitHub
8 changed files with 28 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ $(BUILD_DIR)/%.o: kernel/%.c
$(CC) -std=c11 -ffreestanding -nostdlib -fno-stack-protector -m32 -g -c -o $@ $< $(CC) -std=c11 -ffreestanding -nostdlib -fno-stack-protector -m32 -g -c -o $@ $<
kernel: $(KERNEL_OBJ) | $(BUILD_DIR) kernel: $(KERNEL_OBJ) | $(BUILD_DIR)
$(LD) -melf_i386 -Tbootloader/linker.ld -o $(BUILD_DIR)/kernel.elf $(KERNEL_OBJ) $(LD) -melf_i386 -Tkernel/linker.ld -o $(BUILD_DIR)/kernel.elf $(KERNEL_OBJ)
$(DISK_IMG): stage1 stage2 kernel $(DISK_IMG): stage1 stage2 kernel
dd if=$(BUILD_DIR)/stage1.bin of=$@ dd if=$(BUILD_DIR)/stage1.bin of=$@

View File

@@ -1,3 +1,4 @@
#include "idt.h"
#include "irq.h" #include "irq.h"
#include "io.h" #include "io.h"
#include "isr.h" #include "isr.h"
@@ -7,6 +8,25 @@
#define PIC2_CMD 0xA0 #define PIC2_CMD 0xA0
#define PIC2_DATA 0xA1 #define PIC2_DATA 0xA1
// FIXME: stubs
void irq0() {}
void irq1() {}
void irq2() {}
void irq3() {}
void irq4() {}
void irq5() {}
void irq6() {}
void irq7() {}
void irq8() {}
void irq9() {}
void irq10() {}
void irq11() {}
void irq12() {}
void irq13() {}
void irq14() {}
void irq15() {}
// --- stubs end
void irq_remap(void) void irq_remap(void)
{ {
outb(PIC1_CMD, 0x11); // ICW1 edge triggered, cascade, need ICW4 outb(PIC1_CMD, 0x11); // ICW1 edge triggered, cascade, need ICW4
@@ -31,8 +51,8 @@ void irq_install(void)
irq_remap(); irq_remap();
/* Fill IRQ entries in the IDT (0x20 … 0x2F) */ /* Fill IRQ entries in the IDT (0x20 … 0x2F) */
extern void irq0(), irq1(), irq2(), irq3(), irq4(), irq5(), irq6(), irq7(); //extern void irq0(), irq1(), irq2(), irq3(), irq4(), irq5(), irq6(), irq7();
extern void irq8(), irq9(), irq10(), irq11(), irq12(), irq13(), irq14(), irq15(); //extern void irq8(), irq9(), irq10(), irq11(), irq12(), irq13(), irq14(), irq15();
idt_set_gate(0x20, (uint32_t)irq0); idt_set_gate(0x20, (uint32_t)irq0);
idt_set_gate(0x21, (uint32_t)irq1); idt_set_gate(0x21, (uint32_t)irq1);

View File

@@ -1,6 +1,8 @@
#ifndef IRQ_H #ifndef IRQ_H
#define IRQ_H #define IRQ_H
#include "types.h"
void irq_remap(void); void irq_remap(void);
void irq_install(void); void irq_install(void);
void irq_handler(uint32_t int_num); void irq_handler(uint32_t int_num);

View File

@@ -4,7 +4,7 @@
#include "io.h" #include "io.h"
#include "print.h" #include "print.h"
static isr_callback_t interrupt_handlers[MAX_INTERRUPTS] = { 0 }; isr_callback_t interrupt_handlers[MAX_INTERRUPTS] = { 0 };
void isr_handler(uint32_t int_num, uint32_t err_code) { void isr_handler(uint32_t int_num, uint32_t err_code) {
terminal_write("Interrupt occurred: "); terminal_write("Interrupt occurred: ");

View File

@@ -6,6 +6,7 @@
#define MAX_INTERRUPTS 256 #define MAX_INTERRUPTS 256
typedef void (*isr_callback_t)(void); typedef void (*isr_callback_t)(void);
extern isr_callback_t interrupt_handlers[MAX_INTERRUPTS];
void isr_handler(uint32_t int_num, uint32_t err_code); void isr_handler(uint32_t int_num, uint32_t err_code);
void register_interrupt_handler(uint8_t n, isr_callback_t handler); void register_interrupt_handler(uint8_t n, isr_callback_t handler);

View File

@@ -11,7 +11,7 @@ extern "C" {
/* C11 / POSIX-2004 signatures */ /* C11 / POSIX-2004 signatures */
void *memcpy(void *restrict dst, const void *restrict src, size_t n); void *memcpy(void *restrict dst, const void *restrict src, size_t n);
void *memmove(void *dst, const void *src, size_t n); void *memmove(void *dst, const void *src, size_t n);
/*int memcmp(const void *s1, const void *s2, size_t n); */ int memcmp(const void *s1, const void *s2, size_t n);
/* Optional fast-path using 32-bit loads (x86 only) */ /* Optional fast-path using 32-bit loads (x86 only) */
#if defined(__i386__) && !defined(MEMORY_NO_OPT) #if defined(__i386__) && !defined(MEMORY_NO_OPT)

View File

@@ -77,16 +77,6 @@ char* utoa(unsigned int value, char* str, int base) {
return str; return str;
} }
int memcmp(const void *ptr1, const void *ptr2, size_t num) {
const uint8_t *p1 = ptr1, *p2 = ptr2;
for (size_t i = 0; i < num; i++) {
if (p1[i] != p2[i]) {
return p1[i] < p2[i] ? -1 : 1;
}
}
return 0;
}
void *memset(void *dest, int value, size_t len) { void *memset(void *dest, int value, size_t len) {
unsigned char *ptr = (unsigned char *)dest; unsigned char *ptr = (unsigned char *)dest;
while (len-- > 0) while (len-- > 0)

View File

@@ -9,7 +9,6 @@ char* itoa(int value, char* str, int base);
// Convert unsigned integer to string (base is typically 10, 16, etc.) // Convert unsigned integer to string (base is typically 10, 16, etc.)
char* utoa(unsigned int value, char* str, int base); char* utoa(unsigned int value, char* str, int base);
int memcmp(const void *ptr1, const void *ptr2, size_t num);
void *memset(void *dest, int value, size_t len); void *memset(void *dest, int value, size_t len);
#endif // UTILS_H #endif // UTILS_H