Move to cmake build system
This commit is contained in:
parent
25537eeab8
commit
f22591ad93
172
CMakeLists.txt
Normal file
172
CMakeLists.txt
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
project(yggdrasil-kernel)
|
||||||
|
enable_language(C ASM)
|
||||||
|
|
||||||
|
set(SRC arch/amd64/kernel.c
|
||||||
|
arch/amd64/acpi_osl_mem.c
|
||||||
|
arch/amd64/acpi_osl_printf.c
|
||||||
|
arch/amd64/acpi_osl_thread.c
|
||||||
|
arch/amd64/acpi_osl_init.c
|
||||||
|
arch/amd64/acpi_osl_table.c
|
||||||
|
arch/amd64/acpi_osl_irq.c
|
||||||
|
arch/amd64/acpi_osl_hw.c
|
||||||
|
arch/amd64/hw/rs232.c
|
||||||
|
arch/amd64/hw/con.c
|
||||||
|
arch/amd64/hw/gdt.c
|
||||||
|
arch/amd64/hw/gdt_s.S
|
||||||
|
arch/amd64/hw/acpi.c
|
||||||
|
arch/amd64/mm/mm.c
|
||||||
|
arch/amd64/hw/apic.c
|
||||||
|
arch/amd64/hw/idt.c
|
||||||
|
arch/amd64/hw/exc_s.S
|
||||||
|
arch/amd64/hw/exc.c
|
||||||
|
arch/amd64/hw/irq0.S
|
||||||
|
arch/amd64/hw/timer.c
|
||||||
|
arch/amd64/hw/ioapic.c
|
||||||
|
arch/amd64/hw/irqs_s.S
|
||||||
|
arch/amd64/sys/spin_s.S
|
||||||
|
arch/amd64/cpu.c
|
||||||
|
arch/amd64/mm/heap.c
|
||||||
|
arch/amd64/mm/map.c
|
||||||
|
arch/amd64/mm/phys.c
|
||||||
|
arch/amd64/mm/vmalloc.c
|
||||||
|
arch/amd64/mm/pool.c
|
||||||
|
arch/amd64/hw/ps2.c
|
||||||
|
arch/amd64/hw/irq.c
|
||||||
|
arch/amd64/hw/rtc.c
|
||||||
|
arch/amd64/fpu.S
|
||||||
|
arch/amd64/cpuid.c
|
||||||
|
arch/amd64/sched_s.S
|
||||||
|
arch/amd64/syscall_s.S
|
||||||
|
arch/amd64/syscall.c
|
||||||
|
arch/amd64/binfmt_elf.c
|
||||||
|
|
||||||
|
sys/debug.c
|
||||||
|
sys/ubsan.c
|
||||||
|
sys/panic.c
|
||||||
|
sys/string.c
|
||||||
|
sys/config.c
|
||||||
|
sys/ctype.c
|
||||||
|
sys/errno.c
|
||||||
|
sys/kernel.c
|
||||||
|
sys/time.c
|
||||||
|
sys/char/input.c
|
||||||
|
sys/char/ring.c
|
||||||
|
sys/char/line.c
|
||||||
|
sys/char/tty.c
|
||||||
|
sys/char/chr.c
|
||||||
|
sys/char/pipe.c
|
||||||
|
sys/block/pseudo.c
|
||||||
|
sys/block/part_gpt.c
|
||||||
|
sys/block/ram.c
|
||||||
|
sys/block/blk.c
|
||||||
|
sys/block/cache.c
|
||||||
|
sys/execve.c
|
||||||
|
sys/dev.c
|
||||||
|
sys/sys_file.c
|
||||||
|
sys/sys_sys.c
|
||||||
|
sys/thread.c
|
||||||
|
sys/snprintf.c
|
||||||
|
sys/random.c
|
||||||
|
sys/reboot.c
|
||||||
|
sys/init.c
|
||||||
|
sys/mem/shmem.c
|
||||||
|
sys/mem/slab.c
|
||||||
|
sys/console.c
|
||||||
|
sys/display.c
|
||||||
|
sys/wait.c
|
||||||
|
sys/sched.c
|
||||||
|
sys/font/psf.c
|
||||||
|
sys/font/logo.c
|
||||||
|
sys/mod.c
|
||||||
|
|
||||||
|
fs/vfs.c
|
||||||
|
fs/vfs_ops.c
|
||||||
|
fs/vfs_access.c
|
||||||
|
fs/fs_class.c
|
||||||
|
fs/ofile.c
|
||||||
|
fs/node.c
|
||||||
|
fs/sysfs.c
|
||||||
|
fs/tar.c
|
||||||
|
fs/ext2/block.c
|
||||||
|
fs/ext2/ext2.c
|
||||||
|
fs/ext2/node.c
|
||||||
|
|
||||||
|
drivers/pci/pci.c
|
||||||
|
drivers/pci/pcidb.c
|
||||||
|
drivers/ata/ahci.c
|
||||||
|
drivers/usb/usb_uhci.c
|
||||||
|
drivers/usb/usb.c
|
||||||
|
drivers/usb/driver.c
|
||||||
|
drivers/usb/device.c
|
||||||
|
drivers/usb/usbkbd.c
|
||||||
|
drivers/usb/hub.c
|
||||||
|
|
||||||
|
net/net.c
|
||||||
|
net/if.c
|
||||||
|
net/socket.c
|
||||||
|
net/util.c
|
||||||
|
net/ports.c
|
||||||
|
net/unix.c
|
||||||
|
sys/sys_net.c)
|
||||||
|
|
||||||
|
#### CFLAGS and LDFLAGS
|
||||||
|
set(CMAKE_C_FLAGS "${CFLAGS} \
|
||||||
|
-ffreestanding \
|
||||||
|
-fPIE \
|
||||||
|
-fno-plt \
|
||||||
|
-fno-pic \
|
||||||
|
-DARCH_AMD64 \
|
||||||
|
-DKERNEL_VERSION_STR=\\\"cmake\\\" \
|
||||||
|
-D__KERNEL__ \
|
||||||
|
-mcmodel=large \
|
||||||
|
-mno-sse \
|
||||||
|
-mno-sse2 \
|
||||||
|
-mno-red-zone \
|
||||||
|
-mno-mmx \
|
||||||
|
-z max-page-size=0x1000 \
|
||||||
|
-Wall \
|
||||||
|
-Wextra \
|
||||||
|
-Wno-unused \
|
||||||
|
-O0 \
|
||||||
|
-ggdb \
|
||||||
|
-Werror")
|
||||||
|
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${LDFLAGS} \
|
||||||
|
-nostdlib \
|
||||||
|
-fPIE \
|
||||||
|
-fno-plt \
|
||||||
|
-fno-pic \
|
||||||
|
-static \
|
||||||
|
-Wl,--build-id=none \
|
||||||
|
-z max-page-size=0x1000 \
|
||||||
|
-T${CMAKE_SOURCE_DIR}/arch/amd64/link.ld")
|
||||||
|
|
||||||
|
set(ASM_OPTIONS "-x assembler-with-cpp")
|
||||||
|
set(CMAKE_ASM_FLAGS "${CFLAGS} -D__ASM__")
|
||||||
|
#### Options
|
||||||
|
# ...
|
||||||
|
|
||||||
|
#### Dependencies
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/include
|
||||||
|
${CMAKE_SOURCE_DIR}/include/arch/amd64/acpica)
|
||||||
|
add_subdirectory(${CMAKE_SOURCE_DIR}/arch/amd64/acpica)
|
||||||
|
|
||||||
|
#### Compile font file
|
||||||
|
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/default8x16.psfu.o
|
||||||
|
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/etc &&
|
||||||
|
${CMAKE_C_COMPILER} -c -DINCBIN_FILE='"default8x16.psfu"' -DINCBIN_START="_psf_start"
|
||||||
|
-DINCBIN_END="_psf_end" -o ${CMAKE_BINARY_DIR}/default8x16.psfu.o
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/arch/amd64/incbin.S)
|
||||||
|
set_source_files_properties(${CMAKE_BINARY_DIR}/default8x16.psfu.o
|
||||||
|
PROPERTIES EXTERNAL_OBJECT true GENERATED true)
|
||||||
|
|
||||||
|
#### Kernel linkage and options
|
||||||
|
configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||||
|
|
||||||
|
add_executable(kernel ${CMAKE_SOURCE_DIR}/arch/amd64/entry.S
|
||||||
|
${SRC}
|
||||||
|
${CMAKE_BINARY_DIR}/default8x16.psfu.o)
|
||||||
|
target_link_libraries(kernel acpica)
|
||||||
|
#target_link_libraries(kernel fonts)
|
28
Makefile
28
Makefile
@ -1,28 +0,0 @@
|
|||||||
.PHONY: doc
|
|
||||||
#ifeq ($(ARCH),)
|
|
||||||
#$(error Target architecture is not specified: $${ARCH})
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),amd64)
|
|
||||||
CFLAGS+=-DARCH_AMD64
|
|
||||||
endif
|
|
||||||
|
|
||||||
include config
|
|
||||||
|
|
||||||
export O?=$(abspath build)
|
|
||||||
|
|
||||||
# Include base system
|
|
||||||
include etc/make/conf.mk
|
|
||||||
# Arch details
|
|
||||||
include etc/make/$(ARCH)/conf.mk
|
|
||||||
|
|
||||||
all: mkdirs config $(TARGETS)
|
|
||||||
|
|
||||||
docs: $(HDRS)
|
|
||||||
@make -C doc
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -rf $(O)
|
|
||||||
|
|
||||||
mkdirs:
|
|
||||||
@mkdir -p $(O) $(DIRS)
|
|
3
arch/amd64/acpica/CMakeLists.txt
Normal file
3
arch/amd64/acpica/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
file(GLOB_RECURSE ACPICA_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
|
||||||
|
|
||||||
|
add_library(acpica STATIC ${ACPICA_SRC})
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <config.h>
|
||||||
|
|
||||||
.section .multiboot
|
.section .multiboot
|
||||||
.set MAGIC, 0xE85250D6
|
.set MAGIC, 0xE85250D6
|
||||||
.set ARCH, 0x0
|
.set ARCH, 0x0
|
||||||
@ -7,7 +9,7 @@
|
|||||||
.long MAGIC
|
.long MAGIC
|
||||||
.long ARCH
|
.long ARCH
|
||||||
.long HDRLEN
|
.long HDRLEN
|
||||||
.long CHKSUM
|
.long (CHKSUM & 0xFFFFFFFF)
|
||||||
|
|
||||||
#if defined(VESA_ENABLE)
|
#if defined(VESA_ENABLE)
|
||||||
// Framebuffer tag
|
// Framebuffer tag
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "arch/amd64/hw/gdt.h"
|
#include "arch/amd64/hw/gdt.h"
|
||||||
|
#include <config.h>
|
||||||
#define GDT_SIZE 7
|
#define GDT_SIZE 7
|
||||||
|
|
||||||
extern void amd64_gdt_load(void *p);
|
extern void amd64_gdt_load(void *p);
|
||||||
|
@ -21,9 +21,14 @@
|
|||||||
#include "sys/string.h"
|
#include "sys/string.h"
|
||||||
#include "sys/debug.h"
|
#include "sys/debug.h"
|
||||||
#include "sys/panic.h"
|
#include "sys/panic.h"
|
||||||
|
#include "sys/attr.h"
|
||||||
#include "sys/elf.h"
|
#include "sys/elf.h"
|
||||||
#include "sys/mm.h"
|
#include "sys/mm.h"
|
||||||
|
|
||||||
|
__init(test) {
|
||||||
|
*((uint16_t *) 0xB8000) = 'A' | 0x700;
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t multiboot_info_addr;
|
static uintptr_t multiboot_info_addr;
|
||||||
static struct multiboot_tag_mmap *multiboot_tag_mmap;
|
static struct multiboot_tag_mmap *multiboot_tag_mmap;
|
||||||
static struct multiboot_tag_module *multiboot_tag_initrd_module;
|
static struct multiboot_tag_module *multiboot_tag_initrd_module;
|
||||||
|
@ -18,6 +18,10 @@ SECTIONS {
|
|||||||
{
|
{
|
||||||
*(.multiboot)
|
*(.multiboot)
|
||||||
*(.text)
|
*(.text)
|
||||||
|
. = ALIGN(0x10);
|
||||||
|
_init_start = .;
|
||||||
|
*(.init)
|
||||||
|
_init_end = .;
|
||||||
*(.rodata)
|
*(.rodata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
config.h.in
Normal file
4
config.h.in
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define AMD64_KERNEL_STACK 32768
|
||||||
|
#define AMD64_MAX_SMP 1
|
15
defconfig
15
defconfig
@ -1,15 +0,0 @@
|
|||||||
# vi: ft=make :
|
|
||||||
|
|
||||||
# Compilation settings
|
|
||||||
# amd64-specific
|
|
||||||
export AMD64_TRACE_IRQ=1
|
|
||||||
|
|
||||||
export ALL_SETUID_0=0
|
|
||||||
|
|
||||||
# Emulation
|
|
||||||
export QEMU_SMP=4
|
|
||||||
# export QEMU_MEM=512
|
|
||||||
export VESA_MODE=0
|
|
||||||
export VESA_WIDTH=1024
|
|
||||||
export VESA_HEIGHT=768
|
|
||||||
export VESA_DEPTH=32
|
|
@ -603,6 +603,6 @@ static void pci_ahci_init(struct pci_device *pci_dev) {
|
|||||||
ahci_controller_init(obj);
|
ahci_controller_init(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __init void ahci_register_class(void) {
|
__init(ahci_register_class) {
|
||||||
pci_add_class_driver(0x010601, pci_ahci_init, "ahci");
|
pci_add_class_driver(0x010601, pci_ahci_init, "ahci");
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,6 @@ static int usb_hub_init(struct usb_device *dev) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __init void usb_hub_register_driver(void) {
|
__init(usb_hub_register_driver) {
|
||||||
usb_add_driver(&g_usb_hub);
|
usb_add_driver(&g_usb_hub);
|
||||||
}
|
}
|
||||||
|
@ -494,6 +494,6 @@ void pci_usb_uhci_init(struct pci_device *pci_dev) {
|
|||||||
usb_controller_add((struct usb_controller *) hc);
|
usb_controller_add((struct usb_controller *) hc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __init void pci_usb_uhci_register(void) {
|
__init(pci_usb_uhci_register) {
|
||||||
pci_add_class_driver(0x0C0300, pci_usb_uhci_init, "usb_uhci");
|
pci_add_class_driver(0x0C0300, pci_usb_uhci_init, "usb_uhci");
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,6 @@ static int usb_kbd_init(struct usb_device *dev) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __init void usb_kbd_register_driver(void) {
|
__init(usb_kbd_register_driver) {
|
||||||
usb_add_driver(&g_usbkbd);
|
usb_add_driver(&g_usbkbd);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
CC64?=x86_64-elf-gcc
|
|
||||||
AR64?=x86_64-elf-ar
|
|
||||||
LD64?=x86_64-elf-ld
|
|
||||||
|
|
||||||
ifeq (,$(shell which $(CC64)))
|
|
||||||
$(error Failed to find "$${CC64}": $(CC64))
|
|
||||||
endif
|
|
||||||
ifeq (,$(shell which $(LD64)))
|
|
||||||
$(error Failed to find "$${LD64}": $(LD64))
|
|
||||||
endif
|
|
@ -1,48 +0,0 @@
|
|||||||
include etc/make/amd64/compiler.mk
|
|
||||||
include etc/make/amd64/platform.mk
|
|
||||||
include etc/make/amd64/config.mk
|
|
||||||
|
|
||||||
.PHONY+=$(O)/arch/amd64/hw/ap_code_blob.o
|
|
||||||
|
|
||||||
all:
|
|
||||||
|
|
||||||
TARGETS+=$(O)/kernel.elf
|
|
||||||
|
|
||||||
# add .inc includes for asm
|
|
||||||
HEADERS+=$(shell find include -name "*.inc")
|
|
||||||
|
|
||||||
$(O)/kernel.elf: $(kernel_OBJS) $(kernel_LINKER) config
|
|
||||||
@printf " LD\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@$(CC64) $(kernel_LDFLAGS) -o $@ $(kernel_OBJS)
|
|
||||||
|
|
||||||
$(O)/%.o: %.S $(HEADERS) config
|
|
||||||
@printf " AS\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@$(CC64) $(kernel_CFLAGS) -D__ASM__ -c -o $@ $<
|
|
||||||
|
|
||||||
$(O)/%.o: %.c $(HEADERS) config
|
|
||||||
@printf " CC\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@$(CC64) $(kernel_CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
$(O)/arch/amd64/acpica/%.o: arch/amd64/acpica/%.c
|
|
||||||
@printf " CC\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@$(CC64) $(kernel_CFLAGS_BASE) -c -o $@ $<
|
|
||||||
|
|
||||||
$(O)/arch/amd64/hw/ap_code_blob.o: $(O)/arch/amd64/hw/ap_code.bin config
|
|
||||||
@printf " AS\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@$(CC64) $(kernel_CFLAGS) -c \
|
|
||||||
-DINCBIN_FILE='"$<"' \
|
|
||||||
-DINCBIN_START="amd64_ap_code_start" \
|
|
||||||
-DINCBIN_END="amd64_ap_code_end" \
|
|
||||||
-o $@ arch/amd64/incbin.S
|
|
||||||
|
|
||||||
$(O)/arch/amd64/hw/ap_code.bin: arch/amd64/hw/ap_code.nasm config
|
|
||||||
@printf " NASM\t%s\n" $(@:$(O)/%=%)
|
|
||||||
@nasm -f bin -o $@ $<
|
|
||||||
|
|
||||||
$(O)/sys/font/%.o: etc/%.psfu config
|
|
||||||
@printf " FONT\t%s\n" $(@:$(O)/%.o=%.psfu)
|
|
||||||
@$(CC64) $(kernel_CFLAGS) -c \
|
|
||||||
-DINCBIN_FILE='"$<"' \
|
|
||||||
-DINCBIN_START="_psf_start" \
|
|
||||||
-DINCBIN_END="_psf_end" \
|
|
||||||
-o $@ arch/amd64/incbin.S
|
|
@ -1,32 +0,0 @@
|
|||||||
### This file contains configurable options for amd64 platform
|
|
||||||
### Defaults
|
|
||||||
AMD64_SMP?=1 # SMP enabled
|
|
||||||
AMD64_MAX_SMP?=2 # Maximum SMP CPUs supported
|
|
||||||
AMD64_KERNEL_STACK?=65536 # Kernel stack size (when bootstrapping + task kstack)
|
|
||||||
|
|
||||||
QEMU_MEM?=512
|
|
||||||
QEMU_SMP?=2
|
|
||||||
|
|
||||||
ifeq ($(AMD64_SMP),1)
|
|
||||||
DEFINES+=-DAMD64_SMP \
|
|
||||||
-DAMD64_MAX_SMP=$(AMD64_MAX_SMP)
|
|
||||||
OBJS+=$(O)/arch/amd64/hw/ap_code_blob.o \
|
|
||||||
$(O)/arch/amd64/smp/smp.o \
|
|
||||||
$(O)/arch/amd64/smp/ipi.o \
|
|
||||||
$(O)/arch/amd64/smp/irq_ipi_s.o
|
|
||||||
DIRS+=$(O)/arch/amd64/smp
|
|
||||||
else
|
|
||||||
DEFINES+=-DAMD64_MAX_SMP=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(VESA_ENABLE),1)
|
|
||||||
DEFINES+=-DVESA_ENABLE=1 \
|
|
||||||
-DVESA_WIDTH=$(VESA_WIDTH) \
|
|
||||||
-DVESA_HEIGHT=$(VESA_HEIGHT) \
|
|
||||||
-DVESA_DEPTH=$(VESA_DEPTH) \
|
|
||||||
-DVESA_MODE=0
|
|
||||||
OBJS+=$(O)/arch/amd64/hw/vesa.o
|
|
||||||
endif
|
|
||||||
|
|
||||||
### From config
|
|
||||||
DEFINES+=-DAMD64_KERNEL_STACK=$(AMD64_KERNEL_STACK)
|
|
@ -1,100 +0,0 @@
|
|||||||
### This file contains all things for a generic amd64-build
|
|
||||||
|
|
||||||
### Kernel build
|
|
||||||
DEFINES+=-DARCH_AMD64
|
|
||||||
|
|
||||||
ACPICA_SRCS=$(shell find arch/amd64/acpica -type f -name "*.c")
|
|
||||||
ACPICA_OBJS=$(ACPICA_SRCS:%.c=$(O)/%.o)
|
|
||||||
ACPICA_SRCD=$(shell find arch/amd64/acpica -type d)
|
|
||||||
ACPICA_OBJD=$(ACPICA_SRCD:%=$(O)/%)
|
|
||||||
|
|
||||||
OBJS+=$(ACPICA_OBJS) \
|
|
||||||
$(O)/arch/amd64/acpi_osl_mem.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_printf.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_thread.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_init.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_table.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_irq.o \
|
|
||||||
$(O)/arch/amd64/acpi_osl_hw.o \
|
|
||||||
$(O)/arch/amd64/hw/rs232.o \
|
|
||||||
$(O)/arch/amd64/hw/con.o \
|
|
||||||
$(O)/arch/amd64/kernel.o \
|
|
||||||
$(O)/arch/amd64/hw/gdt.o \
|
|
||||||
$(O)/arch/amd64/hw/gdt_s.o \
|
|
||||||
$(O)/arch/amd64/hw/acpi.o \
|
|
||||||
$(O)/arch/amd64/mm/mm.o \
|
|
||||||
$(O)/arch/amd64/hw/apic.o \
|
|
||||||
$(O)/arch/amd64/hw/idt.o \
|
|
||||||
$(O)/arch/amd64/hw/exc_s.o \
|
|
||||||
$(O)/arch/amd64/hw/exc.o \
|
|
||||||
$(O)/arch/amd64/hw/irq0.o \
|
|
||||||
$(O)/arch/amd64/hw/timer.o \
|
|
||||||
$(O)/arch/amd64/hw/ioapic.o \
|
|
||||||
$(O)/arch/amd64/hw/irqs_s.o \
|
|
||||||
$(O)/arch/amd64/sys/spin_s.o \
|
|
||||||
$(O)/arch/amd64/cpu.o \
|
|
||||||
$(O)/arch/amd64/mm/heap.o \
|
|
||||||
$(O)/arch/amd64/mm/map.o \
|
|
||||||
$(O)/arch/amd64/mm/phys.o \
|
|
||||||
$(O)/arch/amd64/mm/vmalloc.o \
|
|
||||||
$(O)/arch/amd64/mm/pool.o \
|
|
||||||
$(O)/arch/amd64/hw/ps2.o \
|
|
||||||
$(O)/arch/amd64/hw/irq.o \
|
|
||||||
$(O)/arch/amd64/hw/rtc.o \
|
|
||||||
$(O)/arch/amd64/fpu.o \
|
|
||||||
$(O)/arch/amd64/cpuid.o \
|
|
||||||
$(O)/arch/amd64/sched_s.o \
|
|
||||||
$(O)/arch/amd64/syscall_s.o \
|
|
||||||
$(O)/arch/amd64/syscall.o \
|
|
||||||
$(O)/arch/amd64/binfmt_elf.o
|
|
||||||
|
|
||||||
kernel_LINKER=arch/amd64/link.ld
|
|
||||||
kernel_LDFLAGS=-nostdlib \
|
|
||||||
-fPIE \
|
|
||||||
-fno-plt \
|
|
||||||
-fno-pic \
|
|
||||||
-static \
|
|
||||||
-Wl,--build-id=none \
|
|
||||||
-z max-page-size=0x1000 \
|
|
||||||
-ggdb \
|
|
||||||
-T$(kernel_LINKER)
|
|
||||||
kernel_CFLAGS_BASE=-ffreestanding \
|
|
||||||
-I. \
|
|
||||||
-I include/arch/amd64/acpica \
|
|
||||||
$(DEFINES) \
|
|
||||||
$(CFLAGS) \
|
|
||||||
-nostdlib \
|
|
||||||
-fPIE \
|
|
||||||
-fno-plt \
|
|
||||||
-fno-pic \
|
|
||||||
-static \
|
|
||||||
-fno-asynchronous-unwind-tables \
|
|
||||||
-Wno-format \
|
|
||||||
-Wno-comment \
|
|
||||||
-Wno-unused-but-set-variable \
|
|
||||||
-mcmodel=large \
|
|
||||||
-mno-red-zone \
|
|
||||||
-mno-mmx \
|
|
||||||
-mno-sse \
|
|
||||||
-mno-sse2 \
|
|
||||||
-z max-page-size=0x1000 \
|
|
||||||
-D__KERNEL__ \
|
|
||||||
-fstack-protector-all \
|
|
||||||
-fstack-protector-strong
|
|
||||||
kernel_CFLAGS=-fsanitize=undefined \
|
|
||||||
-fsanitize-address-use-after-scope \
|
|
||||||
$(kernel_CFLAGS_BASE)
|
|
||||||
|
|
||||||
kernel_OBJS=$(O)/arch/amd64/crti.o \
|
|
||||||
$(O)/arch/amd64/entry.o \
|
|
||||||
$(shell $(CC64) $(CFLAGS) -print-file-name=crtbegin.o) \
|
|
||||||
$(OBJS) \
|
|
||||||
$(shell $(CC64) $(CFLAGS) -print-file-name=crtend.o) \
|
|
||||||
$(O)/arch/amd64/crtn.o
|
|
||||||
|
|
||||||
DIRS+=$(O)/arch/amd64/image/boot/grub \
|
|
||||||
$(O)/arch/amd64/hw/pci \
|
|
||||||
$(O)/arch/amd64/hw \
|
|
||||||
$(O)/arch/amd64/sys \
|
|
||||||
$(O)/arch/amd64/mm \
|
|
||||||
$(ACPICA_OBJD)
|
|
123
etc/make/conf.mk
123
etc/make/conf.mk
@ -1,123 +0,0 @@
|
|||||||
HEADERS=$(shell find ./include -name "*.h")
|
|
||||||
|
|
||||||
KERNEL_VERSION_GIT=$(shell git describe --always --tags)
|
|
||||||
KERNEL_VERSION_STR=$(KERNEL_VERSION_GIT)
|
|
||||||
ifeq ($(AMD64_SMP),1)
|
|
||||||
KERNEL_VERSION_STR+= +SMP
|
|
||||||
endif
|
|
||||||
|
|
||||||
OPTIMIZE?=g
|
|
||||||
|
|
||||||
CFLAGS+=-Wall \
|
|
||||||
-Wextra \
|
|
||||||
-Werror \
|
|
||||||
-Wno-unused-parameter \
|
|
||||||
-Iinclude \
|
|
||||||
-Wno-unused-variable \
|
|
||||||
-Wno-language-extension-token \
|
|
||||||
-Wno-gnu-zero-variadic-macro-arguments \
|
|
||||||
-O$(OPTIMIZE) \
|
|
||||||
-ggdb
|
|
||||||
|
|
||||||
ifeq ($(KERNEL_TEST_MODE),1)
|
|
||||||
CFLAGS+=-DKERNEL_TEST_MODE
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ALL_SETUID_0),1)
|
|
||||||
CFLAGS+=-DALL_SETUID_0
|
|
||||||
endif
|
|
||||||
|
|
||||||
CFLAGS+=-D__KERNEL__ \
|
|
||||||
-DKERNEL_VERSION_STR='"$(KERNEL_VERSION_STR)"'
|
|
||||||
|
|
||||||
OBJS+=$(O)/sys/debug.o \
|
|
||||||
$(O)/sys/ubsan.o \
|
|
||||||
$(O)/sys/panic.o \
|
|
||||||
$(O)/sys/string.o \
|
|
||||||
$(O)/sys/config.o \
|
|
||||||
$(O)/sys/ctype.o \
|
|
||||||
$(O)/sys/errno.o \
|
|
||||||
$(O)/sys/kernel.o \
|
|
||||||
$(O)/sys/time.o \
|
|
||||||
$(O)/sys/char/input.o \
|
|
||||||
$(O)/sys/char/ring.o \
|
|
||||||
$(O)/sys/char/line.o \
|
|
||||||
$(O)/sys/char/tty.o \
|
|
||||||
$(O)/sys/char/chr.o \
|
|
||||||
$(O)/sys/char/pipe.o \
|
|
||||||
$(O)/sys/block/pseudo.o \
|
|
||||||
$(O)/sys/block/part_gpt.o \
|
|
||||||
$(O)/sys/block/ram.o \
|
|
||||||
$(O)/sys/block/blk.o \
|
|
||||||
$(O)/sys/block/cache.o \
|
|
||||||
$(O)/sys/execve.o \
|
|
||||||
$(O)/sys/dev.o \
|
|
||||||
$(O)/sys/sys_file.o \
|
|
||||||
$(O)/sys/sys_sys.o \
|
|
||||||
$(O)/sys/thread.o \
|
|
||||||
$(O)/sys/snprintf.o \
|
|
||||||
$(O)/sys/random.o \
|
|
||||||
$(O)/sys/reboot.o \
|
|
||||||
$(O)/sys/init.o \
|
|
||||||
$(O)/sys/mem/shmem.o \
|
|
||||||
$(O)/sys/mem/slab.o \
|
|
||||||
$(O)/sys/console.o \
|
|
||||||
$(O)/sys/display.o \
|
|
||||||
$(O)/sys/wait.o \
|
|
||||||
$(O)/sys/sched.o \
|
|
||||||
$(O)/sys/font/psf.o \
|
|
||||||
$(O)/sys/font/logo.o \
|
|
||||||
$(O)/sys/font/default8x16.o \
|
|
||||||
$(O)/sys/mod.o
|
|
||||||
|
|
||||||
DIRS+=$(O)/sys \
|
|
||||||
$(O)/sys/char \
|
|
||||||
$(O)/sys/block \
|
|
||||||
$(O)/sys/font \
|
|
||||||
$(O)/sys/mem
|
|
||||||
|
|
||||||
OBJS+=$(O)/fs/vfs.o \
|
|
||||||
$(O)/fs/vfs_ops.o \
|
|
||||||
$(O)/fs/vfs_access.o \
|
|
||||||
$(O)/fs/fs_class.o \
|
|
||||||
$(O)/fs/ofile.o \
|
|
||||||
$(O)/fs/node.o \
|
|
||||||
$(O)/fs/sysfs.o \
|
|
||||||
$(O)/fs/tar.o \
|
|
||||||
$(O)/fs/ext2/block.o \
|
|
||||||
$(O)/fs/ext2/ext2.o \
|
|
||||||
$(O)/fs/ext2/node.o
|
|
||||||
|
|
||||||
|
|
||||||
DIRS+=$(O)/fs \
|
|
||||||
$(O)/fs/ext2
|
|
||||||
|
|
||||||
OBJS+=$(O)/drivers/pci/pci.o \
|
|
||||||
$(O)/drivers/pci/pcidb.o \
|
|
||||||
$(O)/drivers/ata/ahci.o \
|
|
||||||
$(O)/drivers/usb/usb_uhci.o \
|
|
||||||
$(O)/drivers/usb/usb.o \
|
|
||||||
$(O)/drivers/usb/driver.o \
|
|
||||||
$(O)/drivers/usb/device.o \
|
|
||||||
$(O)/drivers/usb/usbkbd.o \
|
|
||||||
$(O)/drivers/usb/hub.o
|
|
||||||
DIRS+=$(O)/drivers/pci \
|
|
||||||
$(O)/drivers/ata \
|
|
||||||
$(O)/drivers/usb
|
|
||||||
|
|
||||||
#OBJS+=$(O)/drivers/net/rtl8139.o
|
|
||||||
DIRS+=$(O)/drivers/net
|
|
||||||
|
|
||||||
OBJS+=$(O)/net/net.o \
|
|
||||||
$(O)/net/if.o \
|
|
||||||
$(O)/net/socket.o \
|
|
||||||
$(O)/net/util.o \
|
|
||||||
$(O)/net/ports.o \
|
|
||||||
$(O)/net/unix.o \
|
|
||||||
$(O)/sys/sys_net.o
|
|
||||||
|
|
||||||
DIRS+=$(O)/net
|
|
||||||
|
|
||||||
ifeq ($(DEBUG_COUNTERS),1)
|
|
||||||
CFLAGS+=-DDEBUG_COUNTERS
|
|
||||||
endif
|
|
@ -139,6 +139,6 @@ static struct vnode *ext2_get_root(struct fs *ext2) {
|
|||||||
return data->root;
|
return data->root;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __init ext2_class_init(void) {
|
__init(ext2_class_init) {
|
||||||
fs_class_register(&g_ext2);
|
fs_class_register(&g_ext2);
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,6 @@ void sysfs_populate(void) {
|
|||||||
sysfs_add_config_endpoint(NULL, "mem", SYSFS_MODE_DEFAULT, 512, NULL, system_mem_getter, NULL);
|
sysfs_add_config_endpoint(NULL, "mem", SYSFS_MODE_DEFAULT, 512, NULL, system_mem_getter, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __init sysfs_class_init(void) {
|
__init(sysfs_class_init) {
|
||||||
fs_class_register(&g_sysfs);
|
fs_class_register(&g_sysfs);
|
||||||
}
|
}
|
||||||
|
2
fs/tar.c
2
fs/tar.c
@ -660,6 +660,6 @@ static int tarfs_vnode_truncate(struct vnode *node, size_t length) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
static __init void tarfs_init(void) {
|
__init(tarfs_init) {
|
||||||
fs_class_register(&_tarfs);
|
fs_class_register(&_tarfs);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "sys/types.h"
|
#include "sys/types.h"
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
#define IDT_FLG_TASK32 0x5
|
#define IDT_FLG_TASK32 0x5
|
||||||
#define IDT_FLG_INT16 0x6
|
#define IDT_FLG_INT16 0x6
|
||||||
|
@ -6,4 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define __weak __attribute__((weak))
|
#define __weak __attribute__((weak))
|
||||||
#define __init __attribute__((constructor))
|
#define __init(name) \
|
||||||
|
static void name(void); \
|
||||||
|
const void *__init_##name __attribute__((section(".init"),used)) = name; \
|
||||||
|
static void name(void)
|
||||||
|
@ -367,6 +367,6 @@ static ssize_t unix_conn_recvfrom(struct socket *s,
|
|||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
static __init void unix_class_register(void) {
|
__init(unix_class_register) {
|
||||||
socket_class_register(&unix_socket_class);
|
socket_class_register(&unix_socket_class);
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,6 @@ static int devfs_vnode_stat(struct vnode *node, struct stat *st) {
|
|||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
static void __init devfs_class_init(void) {
|
__init(devfs_class_init) {
|
||||||
fs_class_register(&_devfs);
|
fs_class_register(&_devfs);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ extern char _psf_start;
|
|||||||
extern char _psf_end;
|
extern char _psf_end;
|
||||||
struct psf_font *font;
|
struct psf_font *font;
|
||||||
|
|
||||||
static __init void psf_init(void) {
|
__init(psf_init) {
|
||||||
font = (struct psf_font *) &_psf_start;
|
font = (struct psf_font *) &_psf_start;
|
||||||
if (font->magic != PSF_FONT_MAGIC) {
|
if (font->magic != PSF_FONT_MAGIC) {
|
||||||
panic("Invalid PSF magic\n");
|
panic("Invalid PSF magic\n");
|
||||||
|
18
sys/kernel.c
18
sys/kernel.c
@ -3,6 +3,7 @@
|
|||||||
#include "drivers/usb/usb.h"
|
#include "drivers/usb/usb.h"
|
||||||
#include "sys/char/tty.h"
|
#include "sys/char/tty.h"
|
||||||
#include "sys/console.h"
|
#include "sys/console.h"
|
||||||
|
#include "sys/assert.h"
|
||||||
#include "sys/sched.h"
|
#include "sys/sched.h"
|
||||||
#include "sys/panic.h"
|
#include "sys/panic.h"
|
||||||
#include "fs/sysfs.h"
|
#include "fs/sysfs.h"
|
||||||
@ -10,6 +11,23 @@
|
|||||||
#include "net/net.h"
|
#include "net/net.h"
|
||||||
#include "fs/vfs.h"
|
#include "fs/vfs.h"
|
||||||
|
|
||||||
|
void _init(void) {
|
||||||
|
extern char _init_start, _init_end;
|
||||||
|
typedef void (*init_func_t) (void);
|
||||||
|
|
||||||
|
init_func_t *init_array = (init_func_t *) &_init_start;
|
||||||
|
|
||||||
|
// Sanity checks
|
||||||
|
_assert(((uintptr_t) init_array & 0xF) == 0);
|
||||||
|
_assert(((uintptr_t) (&_init_end) & 0xF) == 0);
|
||||||
|
size_t count = ((uintptr_t) &_init_end - (uintptr_t) &_init_start) / sizeof(init_func_t);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
_assert((((uintptr_t) init_array[i]) & 0xFFFFFF0000000000) == 0xFFFFFF0000000000);
|
||||||
|
init_array[i]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
pci_init();
|
pci_init();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ static void slab_init_cache(struct slab_cache *cp, size_t object_size) {
|
|||||||
cp->objects_per_slab -= (bufctl_array_size + cp->object_size - 1) / cp->object_size;
|
cp->objects_per_slab -= (bufctl_array_size + cp->object_size - 1) / cp->object_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __init void slab_init_caches(void) {
|
__init(slab_init_caches) {
|
||||||
for (size_t i = 0; i < PREALLOC_COUNT; ++i) {
|
for (size_t i = 0; i < PREALLOC_COUNT; ++i) {
|
||||||
kdebug("Initializing predefined cache: %u\n", 1UL << (i + 4));
|
kdebug("Initializing predefined cache: %u\n", 1UL << (i + 4));
|
||||||
slab_init_cache(&predefined_caches[i], 1UL << (i + 4));
|
slab_init_cache(&predefined_caches[i], 1UL << (i + 4));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user