Merge branch 'cmake'

This commit is contained in:
c0repwn3r 2022-06-12 15:23:25 -04:00
commit b4f5f50804
Signed by: core
GPG Key ID: FDBF740DADDCEECF
16 changed files with 108 additions and 152 deletions

9
.gitignore vendored
View File

@ -1,2 +1,7 @@
bin/ # Build artifacts
obj/ build/
include/shade/version.h
src/iso/boot/shade.bin
*.o
*.bin
*.iso

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)
project(shadeOS LANGUAGES C ASM_NASM)
# Configure CFLAGS
set(CMAKE_C_FLAGS -ffreestanding)
set(CMAKE_LINKER x86_64-elf-ld)
set(CMAKE_C_COMPILER x86_64-elf-gcc)
set(CMAKE_ASM_NASM_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> -n <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
# Configure versioning info
set(SHADE_KERNEL_VERSION "0.1.1-alpha")
set(SHADE_RELEASE_STREAM "shade-development")
execute_process(COMMAND "git rev-parse --short HEAD | tr -d '\n'" SHADE_GIT_BUILD)
execute_process(COMMAND "date | tr -d '\n'" OUTPUT_VARIABLE SHADE_COMPILE_DATE)
set(SHADE_CODENAME willow)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/libc)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/kernel)
# Generate the iso
#add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.iso COMMAND ${CMAKE_SOURCE_DIR}/shade-build/mkiso.sh ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.bin ${CMAKE_CURRENT_SOURCE_DIR}/../iso/ ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.iso ${CMAKE_SOURCE_DIR}/shade-build/checkbin.sh)
# Add target to run the file
#add_custom_target(run COMMAND ${CMAKE_SOURCE_DIR}/shade-build/run_qemu.sh DEPENDS shadeOS.iso WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

View File

@ -1,84 +0,0 @@
ASM := nasm
CC := x86_64-elf-gcc
CCFLAGS :=
LD := x86_64-elf-ld
LDFLAGS :=
INCLUDE := include/
# Target: kernel, type: C ASM
kernel_c_source_files = $(shell find src/kernel/ -type f -name *.c)
kernel_c_object_files = $(patsubst src/%.c,obj/%.o,$(kernel_c_source_files))
kernel_asm_source_files = $(shell find src/kernel/ -type f -name *.asm)
kernel_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(kernel_asm_source_files))
kernel_source_files = $(kernel_c_source_files) $(kernel_asm_object_files)
kernel_object_files = $(kernel_c_object_files) $(kernel_asm_object_files)
# Target: libc, type: C ASM
libc_c_source_files = $(shell find src/libc/ -type f -name *.c)
libc_c_object_files = $(patsubst src/%.c,obj/%.o,$(libc_c_source_files))
libc_asm_source_files = $(shell find src/libc/ -type f -name *.asm)
libc_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(libc_c_object_files))
libc_source_files = $(libc_c_source_files) $(libc_asm_source_files)
libc_object_files = $(libc_c_object_files) $(libc_asm_object_files)
# Target: sboot, type: ASM
# Override: 32-bit
sboot_asm_source_files = $(shell find src/boot/ -type f -name *.asm)
sboot_asm_object_files = $(patsubst src/%.asm,obj/%.o,$(sboot_asm_source_files))
sboot_source_files = $(sboot_asm_source_files)
sboot_object_files = $(sboot_asm_object_files)
shade_bin_ldfile = src/linker.ld
version = 0.1.1-alpha
stream = shade-development
git_build = $(shell git rev-parse --short HEAD)
date = $(shell date)
codename = willow
default: run
.FORCE:
bin/shade.iso: bin/shade.bin
cp bin/shade.bin src/iso/boot/shade.bin
grub-mkrescue src/iso/ -o $@
rm src/iso/boot/shade.bin
bin/shade.bin: $(sboot_object_files) $(kernel_object_files) $(libc_object_files)
echo "#ifndef SHADE_VERSION_H" > include/shade/version.h
echo "#define SHADE_VERSION_H" >> include/shade/version.h
echo "// This file was autogenerated by the shadeOS build system. It should not be modified." >> include/shade/version.h
echo "#define SHADE_OS_KERNEL_VERSION \"$(version)\"" >> include/shade/version.h
echo "#define SHADE_OS_KERNEL \"$(stream)\"" >> include/shade/version.h
echo "#define SHADE_OS_BUILD \"$(git_build)\"" >> include/shade/version.h
echo "#define SHADE_OS_COMPILE_DATE \"$(date)\"" >> include/shade/version.h
echo "#define SHADE_OS_CODENAME \"$(codename)\"" >> include/shade/version.h
echo "#endif" >> include/shade/version.h
mkdir -p "$(@D)"
$(LD) $(LDFLAGS) -n -T $(shade_bin_ldfile) $^ -o $@
grub-file --is-x86-multiboot2 $@
# Generics
# Source file types: C ASM
# C
obj/%.o: src/%.c
mkdir -p "$(@D)"
$(CC) $(CCFLAGS) -I $(INCLUDE) -ffreestanding -c $< -o $@
# ASM
obj/%.o: src/%.asm
mkdir -p "$(@D)"
$(ASM) -felf64 $< -o $@
# Other
run: clean bin/shade.iso
qemu-system-x86_64 -drive file=bin/shade.iso,index=0,media=disk,format=raw -d int -no-reboot
clean:
rm -rf bin/*
rm -rf obj/*

Binary file not shown.

Binary file not shown.

View File

@ -1,57 +0,0 @@
# configuration file generated by Bochs
plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, iodebug=true, pcidev=false, usb_uhci=false
config_interface: textconfig
display_library: x
memory: host=32, guest=32
romimage: file="/usr/share/bochs/BIOS-bochs-latest", address=0x00000000, options=none
vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
floppya: type=1_44
# no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="bin/shade.iso", mode=flat, cylinders=1, heads=1, spt=63, sect_size=512, model="Generic 1234", biosdetect=auto, translation=auto
ata0-slave: type=none
ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=false
ata3: enabled=false
optromimage1: file=none
optromimage2: file=none
optromimage3: file=none
optromimage4: file=none
optramimage1: file=none
optramimage2: file=none
optramimage3: file=none
optramimage4: file=none
pci: enabled=1, chipset=i440fx, slot1=none, slot2=none, slot3=none, slot4=none, slot5=none
vga: extension=vbe, update_freq=5, realtime=1, ddc=builtin
cpu: count=1:1:1, ips=4000000, quantum=16, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor"
cpuid: mmx=true, apic=xapic, simd=sse2, sse4a=false, misaligned_sse=false, sep=true
cpuid: movbe=false, adx=false, aes=false, sha=false, xsave=false, xsaveopt=false, avx_f16c=false
cpuid: avx_fma=false, bmi=0, xop=false, fma4=false, tbm=false, x86_64=true, 1g_pages=false
cpuid: pcid=false, fsgsbase=false, smep=false, smap=false, mwait=true
print_timestamps: enabled=0
debugger_log: -
magic_break: enabled=0
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=none, time0=local, rtc_sync=0
# no cmosimage
log: -
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=ask
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
mouse: type=ps2, enabled=false, toggle=ctrl+mbutton
speaker: enabled=true, mode=system
parport1: enabled=true, file=none
parport2: enabled=false
com1: enabled=true, mode=null
com2: enabled=false
com3: enabled=false
com4: enabled=false

6
include/shade/terminal.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SHADE_TERMINAL_H
#define SHADE_TERMINAL_H
#endif

View File

@ -1,9 +0,0 @@
#ifndef SHADE_VERSION_H
#define SHADE_VERSION_H
// This file was autogenerated by the shadeOS build system. It should not be modified.
#define SHADE_OS_KERNEL_VERSION "0.1.1-alpha"
#define SHADE_OS_KERNEL "shade-development"
#define SHADE_OS_BUILD "09c487e"
#define SHADE_OS_COMPILE_DATE "Sat May 21 03:18:24 PM EDT 2022"
#define SHADE_OS_CODENAME "willow"
#endif

View File

@ -0,0 +1,11 @@
#ifndef SHADE_VERSION_H
#define SHADE_VERSION_H
// This file was autogenerated by the shadeOS build system.
// It should not be modified by hand.
// To change these values, modify them in CMakeLists.txt.
#define SHADE_OS_KERNEL_VERSION "${SHADE_KERNEL_VERSION}"
#define SHADE_OS_KERNEL "${SHADE_RELEASE_STREAM}"
#define SHADE_OS_BUILD "${SHADE_GIT_BUILD}"
#define SHADE_OS_COMPILE_DATE "${SHADE_COMPILE_DATE}"
#define SHADE_OS_CODENAME "${SHADE_CODENAME}"
#endif

Binary file not shown.

Binary file not shown.

5
shade-build/checkbin.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
echo "Checking binary $1"
grub-file --is-x86-multiboot2 $1
echo "$1 is a valid mb2 binary"

7
shade-build/mkiso.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
$4 $1
echo "Packaging $1 into shadeOS ISO $3"
# mkiso.sh build/src/kernel/shadeOS.bin src/iso/ build/shade.iso check_command
cp $1 $2/boot/shade.bin
grub-mkrescue $2 -o $3

2
shade-build/run_qemu.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
qemu-system-x86_64 -drive file=build/src/kernel/shade.iso,index=0,media=disk,format=raw -no-reboot

35
src/kernel/CMakeLists.txt Normal file
View File

@ -0,0 +1,35 @@
# Define ASM source files
set(KERNEL_ASM_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/int.asm)
# Define C source files
set(KERNEL_C_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/platform/drivers/keyboard.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/drivers/vga_text_mode.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/idt.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/isr.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/interrupts/pic.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/ports.c
${CMAKE_CURRENT_SOURCE_DIR}/cansid.c
${CMAKE_CURRENT_SOURCE_DIR}/kernel.c
${CMAKE_CURRENT_SOURCE_DIR}/kmsg.c
${CMAKE_CURRENT_SOURCE_DIR}/util.c)
set(SBOOT_ASM_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/../boot/entry.asm
${CMAKE_CURRENT_SOURCE_DIR}/../boot/entry64.asm
${CMAKE_CURRENT_SOURCE_DIR}/../boot/mb2_header.asm)
set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../linker.ld)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}")
configure_file(${CMAKE_SOURCE_DIR}/include/shade/version.h.in ${CMAKE_SOURCE_DIR}/include/shade/version.h)
add_executable(shadeOS.bin ${SBOOT_ASM_SOURCE_FILES} ${KERNEL_ASM_SOURCE_FILES} ${KERNEL_C_SOURCE_FILES})
target_link_libraries(shadeOS.bin LINK_PUBLIC shadeOS_libc) # Link the kernel to libc
# Generate the iso
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shade.iso COMMAND ${CMAKE_SOURCE_DIR}/shade-build/mkiso.sh ${CMAKE_CURRENT_BINARY_DIR}/shadeOS.bin ${CMAKE_CURRENT_SOURCE_DIR}/../iso/ ${CMAKE_CURRENT_BINARY_DIR}/shade.iso ${CMAKE_SOURCE_DIR}/shade-build/checkbin.sh DEPENDS shadeOS.bin)
# Add target to run the file
add_custom_target(run COMMAND ${CMAKE_SOURCE_DIR}/shade-build/run_qemu.sh DEPENDS shade.iso WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

10
src/libc/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
# Define C source files
set(LIBC_C_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/printf.c
${CMAKE_CURRENT_SOURCE_DIR}/strings.c)
# Define ASM source files
# none currently
add_library(shadeOS_libc ${LIBC_C_SOURCE_FILES}) # Create the libc library
target_include_directories(shadeOS_libc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include) # Set the include dir