Skip to content

Commit d4611d4

Browse files
authored
Add files via upload
1 parent 5849a6c commit d4611d4

22 files changed

+2694
-0
lines changed

Makefile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
SRCDIR := sources
2+
BUILDDIR := objects
3+
DISTDIR := distribution
4+
INCDIR := headers
5+
6+
KERNEL_SRCS := $(wildcard $(SRCDIR)/kernel/*.c)
7+
DEVICE_SRCS := $(wildcard $(SRCDIR)/devices/*.c)
8+
SYSTEM_SRCS := $(wildcard $(SRCDIR)/system/*.c)
9+
ARCH_C_SRCS := $(wildcard $(SRCDIR)/arch/x86_64/*.c)
10+
ARCH_ASM_SRCS := $(wildcard $(SRCDIR)/arch/x86_64/*.s)
11+
12+
KERNEL_OBJS := $(KERNEL_SRCS:$(SRCDIR)/kernel/%.c=$(BUILDDIR)/kernel/%.o)
13+
DEVICE_OBJS := $(DEVICE_SRCS:$(SRCDIR)/devices/%.c=$(BUILDDIR)/devices/%.o)
14+
SYSTEM_OBJS := $(SYSTEM_SRCS:$(SRCDIR)/system/%.c=$(BUILDDIR)/system/%.o)
15+
ARCH_C_OBJS := $(ARCH_C_SRCS:$(SRCDIR)/arch/x86_64/%.c=$(BUILDDIR)/arch/%.o)
16+
ARCH_ASM_OBJS := $(ARCH_ASM_SRCS:$(SRCDIR)/arch/x86_64/%.s=$(BUILDDIR)/arch/%.o)
17+
18+
ALL_OBJS := $(KERNEL_OBJS) $(DEVICE_OBJS) $(SYSTEM_OBJS) $(ARCH_C_OBJS) $(ARCH_ASM_OBJS)
19+
20+
CROSS_COMPILER := x86_64-elf-gcc
21+
ASSEMBLER := nasm
22+
LINKER := x86_64-elf-ld
23+
24+
CFLAGS := -I$(INCDIR) -std=c99 -ffreestanding -O2 -Wall -Wextra \
25+
-nostdlib -mno-red-zone -mno-mmx -mno-sse -mno-sse2 \
26+
-mcmodel=kernel -fno-stack-protector -fno-pic
27+
28+
ASMFLAGS := -f elf64
29+
LDFLAGS := -nostdlib -T bootloader/linker.ld -N
30+
31+
.PHONY: all kernel iso clean run debug verify
32+
33+
all: iso
34+
35+
kernel: $(DISTDIR)/apollo.bin
36+
37+
iso: $(DISTDIR)/apollo.iso
38+
39+
$(BUILDDIR)/kernel/%.o: $(SRCDIR)/kernel/%.c
40+
@mkdir -p $(dir $@)
41+
$(CROSS_COMPILER) $(CFLAGS) -c $< -o $@
42+
43+
$(BUILDDIR)/arch/%.o: $(SRCDIR)/arch/x86_64/%.c
44+
@mkdir -p $(dir $@)
45+
$(CROSS_COMPILER) $(CFLAGS) -c $< -o $@
46+
47+
$(BUILDDIR)/arch/%.o: $(SRCDIR)/arch/x86_64/%.s
48+
@mkdir -p $(dir $@)
49+
$(ASSEMBLER) $(ASMFLAGS) $< -o $@
50+
51+
$(BUILDDIR)/devices/%.o: $(SRCDIR)/devices/%.c
52+
@mkdir -p $(dir $@)
53+
$(CROSS_COMPILER) $(CFLAGS) -c $< -o $@
54+
55+
$(BUILDDIR)/system/%.o: $(SRCDIR)/system/%.c
56+
@mkdir -p $(dir $@)
57+
$(CROSS_COMPILER) $(CFLAGS) -c $< -o $@
58+
59+
$(DISTDIR)/apollo.bin: $(ALL_OBJS)
60+
@mkdir -p $(DISTDIR)
61+
$(LINKER) $(LDFLAGS) -o $@ $(ALL_OBJS)
62+
63+
$(DISTDIR)/apollo.iso: $(DISTDIR)/apollo.bin
64+
@mkdir -p $(DISTDIR)/iso_root/boot/grub
65+
@cp $(DISTDIR)/apollo.bin $(DISTDIR)/iso_root/boot/apollo.bin
66+
@cp bootloader/grub.cfg $(DISTDIR)/iso_root/boot/grub/
67+
grub-mkrescue -o $@ $(DISTDIR)/iso_root
68+
69+
clean:
70+
rm -rf $(BUILDDIR) $(DISTDIR)
71+
72+
run: iso
73+
qemu-system-x86_64 -cdrom $(DISTDIR)/apollo.iso -m 512M -display gtk
74+
75+
debug: iso
76+
qemu-system-x86_64 -cdrom $(DISTDIR)/apollo.iso -m 512M -s -S -monitor stdio
77+
78+
verify: $(DISTDIR)/apollo.bin
79+
@chmod +x verify_elf.sh
80+
@./verify_elf.sh

bootloader/grub.cfg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
set timeout=3
2+
set timeout_style=menu
3+
set default=0
4+
5+
set gfxmode=auto
6+
set gfxpayload=keep
7+
terminal_output console
8+
9+
menuentry "Apollo Kernel v1.0" {
10+
echo "Loading Apollo Kernel..."
11+
multiboot /boot/apollo.bin
12+
echo "Booting Apollo Operating System..."
13+
boot
14+
}
15+
16+
menuentry "Apollo Kernel v1.0 (Multiboot2)" {
17+
echo "Loading Apollo Kernel with Multiboot2..."
18+
multiboot2 /boot/apollo.bin
19+
echo "Booting Apollo Operating System..."
20+
boot
21+
}
22+
23+
menuentry "Apollo Kernel v1.0 (Debug)" {
24+
echo "Loading Apollo Kernel in debug mode..."
25+
multiboot /boot/apollo.bin debug
26+
echo "Booting Apollo Operating System in debug mode..."
27+
boot
28+
}

bootloader/linker.ld

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
OUTPUT_FORMAT("elf64-x86-64")
2+
OUTPUT_ARCH("i386:x86-64")
3+
ENTRY(boot_entry_point)
4+
5+
SECTIONS
6+
{
7+
. = 0x100000;
8+
9+
.multiboot :
10+
{
11+
KEEP(*(.multiboot))
12+
}
13+
14+
. = ALIGN(0x1000);
15+
16+
.text :
17+
{
18+
*(.text)
19+
*(.text.*)
20+
}
21+
22+
. = ALIGN(0x1000);
23+
.rodata :
24+
{
25+
*(.rodata)
26+
*(.rodata.*)
27+
}
28+
29+
. = ALIGN(0x1000);
30+
.data :
31+
{
32+
*(.data)
33+
*(.data.*)
34+
}
35+
36+
. = ALIGN(0x1000);
37+
.bss :
38+
{
39+
*(COMMON)
40+
*(.bss)
41+
*(.bss.*)
42+
}
43+
44+
/DISCARD/ :
45+
{
46+
*(.comment)
47+
*(.note)
48+
*(.note.*)
49+
*(.eh_frame)
50+
*(.eh_frame_hdr)
51+
*(.gnu.hash)
52+
*(.gnu.version*)
53+
*(.rel.*)
54+
*(.rela.*)
55+
}
56+
}

debug_header.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
BINARY="distribution/apollo.bin"
2+
3+
if [ ! -f "$BINARY" ]; then
4+
echo "Error: Binary file $BINARY not found"
5+
exit 1
6+
fi
7+
8+
echo "=== Multiboot Header Debug ==="
9+
echo "Binary file: $BINARY"
10+
echo "File size: $(stat -c%s "$BINARY") bytes"
11+
echo ""
12+
13+
echo "First 64 bytes (hex):"
14+
hexdump -C -n 64 "$BINARY"
15+
echo ""
16+
17+
echo "Searching for Multiboot2 magic (0xe85250d6):"
18+
MAGIC_POS=$(xxd -p "$BINARY" | tr -d '\n' | grep -b -o "d65052e8" | head -1 | cut -d: -f1)
19+
20+
if [ -n "$MAGIC_POS" ]; then
21+
BYTE_POS=$((MAGIC_POS / 2))
22+
echo "Found multiboot2 magic at byte offset: $BYTE_POS"
23+
24+
if [ $BYTE_POS -le 32768 ]; then
25+
echo "✓ Magic is within first 32KB (GRUB requirement)"
26+
else
27+
echo "✗ Magic is beyond 32KB - GRUB won't find it"
28+
fi
29+
else
30+
echo "✗ Multiboot2 magic not found!"
31+
fi
32+
33+
echo ""
34+
echo "First 16 bytes as 32-bit words:"
35+
hexdump -e '4/4 "0x%08x " "\n"' -n 16 "$BINARY"

headers/command_processor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef APOLLO_COMMAND_PROCESSOR_H
2+
#define APOLLO_COMMAND_PROCESSOR_H
3+
4+
#include <stdint.h>
5+
6+
void command_processor_initialize(void);
7+
8+
void command_processor_handle_input(uint8_t scan_code);
9+
10+
#endif

headers/config.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#ifndef APOLLO_CONFIG_H
2+
#define APOLLO_CONFIG_H
3+
4+
#define APOLLO_VERSION_MAJOR 1
5+
#define APOLLO_VERSION_MINOR 0
6+
#define APOLLO_VERSION_PATCH 0
7+
#define APOLLO_VERSION_STRING "1.0.0"
8+
9+
#define APOLLO_ARCH_X86_64 1
10+
#define APOLLO_ARCH_STRING "x86_64"
11+
12+
#define APOLLO_PAGE_SIZE 4096
13+
#define APOLLO_KERNEL_HEAP_SIZE (16 * 1024 * 1024) // 16MB
14+
#define APOLLO_KERNEL_STACK_SIZE (64 * 1024) // 64KB
15+
#define APOLLO_MEMORY_ALIGNMENT 8
16+
17+
#define APOLLO_VGA_WIDTH 80
18+
#define APOLLO_VGA_HEIGHT 25
19+
#define APOLLO_VGA_COLORS 16
20+
21+
#define APOLLO_KEYBOARD_BUFFER_SIZE 256
22+
#define APOLLO_COMMAND_MAX_LENGTH 256
23+
#define APOLLO_COMMAND_HISTORY_SIZE 32
24+
#define APOLLO_MAX_COMMAND_ARGS 16
25+
26+
#define APOLLO_MULTIBOOT2_MAGIC 0xe85250d6
27+
#define APOLLO_KERNEL_LOAD_ADDRESS 0x100000 // 1MB
28+
29+
#ifdef DEBUG
30+
#define APOLLO_DEBUG_ENABLED 1
31+
#define APOLLO_SERIAL_DEBUG 1
32+
#else
33+
#define APOLLO_DEBUG_ENABLED 0
34+
#define APOLLO_SERIAL_DEBUG 0
35+
#endif
36+
37+
#define APOLLO_FEATURE_MEMORY_MANAGER 1
38+
#define APOLLO_FEATURE_COMMAND_SHELL 1
39+
#define APOLLO_FEATURE_VGA_GRAPHICS 1
40+
#define APOLLO_FEATURE_PS2_KEYBOARD 1
41+
#define APOLLO_FEATURE_RTC_CLOCK 1
42+
43+
#define APOLLO_COMPILER_NAME "GCC"
44+
#define APOLLO_BUILD_DATE __DATE__
45+
#define APOLLO_BUILD_TIME __TIME__
46+
47+
#define APOLLO_MAX_FILENAME_LENGTH 255
48+
#define APOLLO_MAX_PATH_LENGTH 1024
49+
#define APOLLO_MAX_PROCESSES 32
50+
#define APOLLO_MAX_THREADS 128
51+
52+
#define APOLLO_ASSERT_ENABLED 1
53+
#define APOLLO_ERROR_CHECKING 1
54+
55+
#define APOLLO_CPU_VENDOR_INTEL 0x756e6547 // "Genu"
56+
#define APOLLO_CPU_VENDOR_AMD 0x68747541 // "Auth"
57+
58+
#define APOLLO_TIMER_FREQUENCY 1000 // 1000 Hz
59+
#define APOLLO_SCHEDULER_QUANTUM 10 // 10ms
60+
61+
#define APOLLO_VGA_CTRL_PORT 0x3D4
62+
#define APOLLO_VGA_DATA_PORT 0x3D5
63+
#define APOLLO_KB_DATA_PORT 0x60
64+
#define APOLLO_KB_STATUS_PORT 0x64
65+
#define APOLLO_CMOS_ADDRESS_PORT 0x70
66+
#define APOLLO_CMOS_DATA_PORT 0x71
67+
68+
#define APOLLO_HEAP_MAGIC 0xDEADBEEF
69+
#define APOLLO_STACK_MAGIC 0xCAFEBABE
70+
#define APOLLO_KERNEL_MAGIC 0x41504F4C // "APOL"
71+
72+
#define APOLLO_DEFAULT_FG_COLOR 7 // Light gray
73+
#define APOLLO_DEFAULT_BG_COLOR 0 // Black
74+
#define APOLLO_LOGO_COLOR 14 // Yellow
75+
#define APOLLO_ACCENT_COLOR 3 // Orange
76+
77+
#define APOLLO_KB(x) ((x) * 1024)
78+
#define APOLLO_MB(x) ((x) * 1024 * 1024)
79+
#define APOLLO_GB(x) ((x) * 1024ULL * 1024 * 1024)
80+
81+
#define APOLLO_STRINGIFY(x) #x
82+
#define APOLLO_TOSTRING(x) APOLLO_STRINGIFY(x)
83+
84+
#if APOLLO_DEBUG_ENABLED
85+
#define APOLLO_DEBUG_PRINT(fmt, ...) debug_printf(fmt, ##__VA_ARGS__)
86+
#else
87+
#define APOLLO_DEBUG_PRINT(fmt, ...) do {} while(0)
88+
#endif
89+
90+
#define APOLLO_STATIC_ASSERT(cond, msg) \
91+
typedef char apollo_static_assert_##msg[(cond) ? 1 : -1]
92+
93+
APOLLO_STATIC_ASSERT(APOLLO_PAGE_SIZE == 4096, page_size_must_be_4k);
94+
APOLLO_STATIC_ASSERT(APOLLO_MEMORY_ALIGNMENT >= 8, alignment_must_be_at_least_8);
95+
APOLLO_STATIC_ASSERT(APOLLO_KEYBOARD_BUFFER_SIZE > 0, keyboard_buffer_must_be_positive);
96+
97+
#endif

headers/heap_allocator.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef APOLLO_HEAP_ALLOCATOR_H
2+
#define APOLLO_HEAP_ALLOCATOR_H
3+
4+
#include <stddef.h>
5+
#include <stdint.h>
6+
7+
void heap_allocator_initialize(void);
8+
9+
void* apollo_allocate_memory(size_t size);
10+
void apollo_free_memory(void* ptr);
11+
void* apollo_allocate_zeroed_memory(size_t count, size_t element_size);
12+
void* apollo_reallocate_memory(void* ptr, size_t new_size);
13+
14+
size_t heap_allocator_get_used_memory(void);
15+
size_t heap_allocator_get_free_memory(void);
16+
size_t heap_allocator_get_total_memory(void);
17+
18+
void heap_allocator_dump_info(void);
19+
20+
#endif

headers/input_manager.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef APOLLO_INPUT_MANAGER_H
2+
#define APOLLO_INPUT_MANAGER_H
3+
4+
#include <stdint.h>
5+
#include <stdbool.h>
6+
7+
#define SCANCODE_UP_ARROW 0x48
8+
#define SCANCODE_DOWN_ARROW 0x50
9+
#define SCANCODE_LEFT_ARROW 0x4B
10+
#define SCANCODE_RIGHT_ARROW 0x4D
11+
#define SCANCODE_ESCAPE 0x01
12+
#define SCANCODE_ENTER 0x1C
13+
#define SCANCODE_BACKSPACE 0x0E
14+
#define SCANCODE_TAB 0x0F
15+
#define SCANCODE_SPACE 0x39
16+
#define SCANCODE_DELETE 0x53
17+
#define SCANCODE_INSERT 0x52
18+
#define SCANCODE_HOME 0x47
19+
#define SCANCODE_END 0x4F
20+
#define SCANCODE_PAGE_UP 0x49
21+
#define SCANCODE_PAGE_DOWN 0x51
22+
23+
#define SCANCODE_F1 0xF1
24+
#define SCANCODE_F2 0xF2
25+
#define SCANCODE_F3 0xF3
26+
#define SCANCODE_F4 0xF4
27+
#define SCANCODE_F5 0xF5
28+
#define SCANCODE_F6 0xF6
29+
#define SCANCODE_F7 0xF7
30+
#define SCANCODE_F8 0xF8
31+
#define SCANCODE_F9 0xF9
32+
#define SCANCODE_F10 0xFA
33+
#define SCANCODE_F11 0xFB
34+
#define SCANCODE_F12 0xFC
35+
36+
void input_manager_initialize(void);
37+
38+
bool input_manager_has_input(void);
39+
uint8_t input_manager_read_scancode(void);
40+
41+
char input_manager_scancode_to_ascii(uint8_t scan_code);
42+
43+
bool input_manager_is_shift_pressed(void);
44+
bool input_manager_is_ctrl_pressed(void);
45+
bool input_manager_is_alt_pressed(void);
46+
47+
bool input_manager_is_caps_lock_on(void);
48+
bool input_manager_is_num_lock_on(void);
49+
bool input_manager_is_scroll_lock_on(void);
50+
51+
uint8_t input_manager_get_last_scancode(void);
52+
53+
#endif

0 commit comments

Comments
 (0)