Cleanup and Actions build (#6)

Thanks dpeter!
This commit is contained in:
dpeter99 2021-06-14 16:41:07 +02:00 committed by GitHub
parent 5ffa467b7d
commit 40bc58b8a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 590 additions and 503 deletions

61
.github/workflows/build.yaml vendored Normal file
View File

@ -0,0 +1,61 @@
name: Build Chroma
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: cache-elf-tools
uses: actions/cache@v2
with:
path: ./tools/x86_64-elf-tools/
key: ${{ runner.os }}-elf_test12-${{ hashFiles('tools/elf_url.txt') }}
- name: Get elf tools 🧝‍♀️
if: steps.cache-elf-tools.outputs.cache-hit != 'true'
id: elf_tools
run: |
mkdir ${GITHUB_WORKSPACE}/tools/x86_64-elf-tools
cd ${GITHUB_WORKSPACE}/tools/x86_64-elf-tools
ELFTOOLS=`cat ${GITHUB_WORKSPACE}/tools/elf_url.txt`
wget ${ELFTOOLS}
unzip x86_64-elf-tools-linux.zip
export PATH=${GITHUB_WORKSPACE}/tools/x86_64-elf-tools/bin:$PATH
- name: Setup
run: |
export PATH=${GITHUB_WORKSPACE}/tools/x86_64-elf-tools/bin:$PATH
chmod +x "${GITHUB_WORKSPACE}/pre.sh"
./pre.sh
- name: Build
run: |
export PATH=${GITHUB_WORKSPACE}/tools/x86_64-elf-tools/bin:$PATH
make kernel
- name: Make img
run: |
mkdir -p bin/img
chmod +x "${GITHUB_WORKSPACE}/tools/mkbootimg/mkbootimg"
./tools/mkbootimg/mkbootimg chroma.json bin/img/chroma.img
- uses: actions/upload-artifact@v2
with:
name: kernel
path: |
bin/kernel
- uses: actions/upload-artifact@v2
with:
name: img
path: |
bin/img/chroma.img

11
.gitignore vendored
View File

@ -8,3 +8,14 @@
Makefile
CMakeFiles
CMakeCache.txt
.idea/
cmake_install.cmake
temp/
/bin/
/img/boot/exe
tools/x86_64-elf-tools
!src/global/*.o

View File

@ -11,49 +11,52 @@ SET(CMAKE_CROSSCOMPILING 1)
project(chroma)
SET(src_files
${CMAKE_SOURCE_DIR}/chroma/kernel.c
${CMAKE_SOURCE_DIR}/chroma/video/draw.c
${CMAKE_SOURCE_DIR}/chroma/video/print.c
${CMAKE_SOURCE_DIR}/chroma/system/cpu.c
${CMAKE_SOURCE_DIR}/chroma/system/rw.c
${CMAKE_SOURCE_DIR}/chroma/system/serial.c
${CMAKE_SOURCE_DIR}/chroma/system/pci.c
${CMAKE_SOURCE_DIR}/chroma/system/memory/stack.c
${CMAKE_SOURCE_DIR}/chroma/system/memory/paging.c
${CMAKE_SOURCE_DIR}/chroma/system/memory/abstract_allocator.c
${CMAKE_SOURCE_DIR}/chroma/system/memory/physmem.c
${CMAKE_SOURCE_DIR}/chroma/system/drivers/keyboard.c
${CMAKE_SOURCE_DIR}/chroma/system/drivers/elf.c
${CMAKE_SOURCE_DIR}/src/chroma/kernel.c
${CMAKE_SOURCE_DIR}/src/chroma/video/draw.c
${CMAKE_SOURCE_DIR}/src/chroma/video/print.c
${CMAKE_SOURCE_DIR}/src/chroma/system/cpu.c
${CMAKE_SOURCE_DIR}/src/chroma/system/rw.c
${CMAKE_SOURCE_DIR}/src/chroma/system/serial.c
${CMAKE_SOURCE_DIR}/src/chroma/system/pci.c
${CMAKE_SOURCE_DIR}/src/chroma/system/memory/stack.c
${CMAKE_SOURCE_DIR}/src/chroma/system/memory/paging.c
${CMAKE_SOURCE_DIR}/src/chroma/system/memory/abstract_allocator.c
${CMAKE_SOURCE_DIR}/src/chroma/system/memory/physmem.c
${CMAKE_SOURCE_DIR}/src/chroma/system/drivers/keyboard.c
${CMAKE_SOURCE_DIR}/src/chroma/system/drivers/elf.c
)
SET(lib_files
${CMAKE_SOURCE_DIR}/chroma/lainlib/list/basic_list.c
${CMAKE_SOURCE_DIR}/chroma/lainlib/mutex/ticketlock.c
${CMAKE_SOURCE_DIR}/chroma/lainlib/compression/lzgmini.c
${CMAKE_SOURCE_DIR}/src/chroma/lainlib/list/basic_list.c
${CMAKE_SOURCE_DIR}/src/chroma/lainlib/mutex/ticketlock.c
${CMAKE_SOURCE_DIR}/src/chroma/lainlib/compression/lzgmini.c
)
include_directories("chroma/inc")
include_directories("src/chroma/inc")
SET(src_no_sse
${CMAKE_SOURCE_DIR}/chroma/system/interrupts.c
${CMAKE_SOURCE_DIR}/src/chroma/system/interrupts.c
)
SET(src_preamble
${CMAKE_SOURCE_DIR}/global/crt0.o
${CMAKE_SOURCE_DIR}/global/crti.o
${CMAKE_SOURCE_DIR}/global/crtbegin.o
${CMAKE_SOURCE_DIR}/src/global/crt0.o
${CMAKE_SOURCE_DIR}/src/global/crti.o
${CMAKE_SOURCE_DIR}/src/global/crtbegin.o
)
set(src_epilogue
${CMAKE_SOURCE_DIR}/global/crtend.o
${CMAKE_SOURCE_DIR}/global/crtn.o
${CMAKE_SOURCE_DIR}/src/global/crtend.o
${CMAKE_SOURCE_DIR}/src/global/crtn.o
)
set_property(SOURCE ${src_no_sse} PROPERTY COMPILE_FLAGS -mgeneral-regs-only)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(kernel)
target_sources(kernel PUBLIC ${src_preamble} PUBLIC ${src_files} PUBLIC ${src_no_sse} PUBLIC ${lib_files} PUBLIC ${CMAKE_SOURCE_DIR}/font.o PUBLIC ${src_epilogue})
target_sources(kernel PUBLIC ${src_preamble} PUBLIC ${src_files} PUBLIC ${src_no_sse} PUBLIC ${lib_files} PUBLIC ${CMAKE_SOURCE_DIR}/src/assets/font.o PUBLIC ${src_epilogue})
target_compile_options(kernel PRIVATE -ffreestanding -O0 -Wall -Wextra -Wall -Werror -pedantic -fPIC -fno-exceptions -fno-omit-frame-pointer -mno-red-zone -fno-stack-protector -ggdb3)
target_link_options(kernel PRIVATE -T linker.ld -ffreestanding -O2 -nostdlib -nostartfiles -lgcc)

8
build_and_run.sh Normal file
View File

@ -0,0 +1,8 @@
echo "Build"
make kernel
echo "POST:"
./post.sh
echo "RUN"
./run.bat

11
post.sh
View File

@ -1,18 +1,19 @@
cp kernel img/boot/exe
cp bin/kernel img/boot/exe
echo "Performing post-build actions:"
echo "Creating raw img file for writing to a drive:"
./mkbootimg.exe chroma.json chroma.img # for linux remove the .exe
mkdir -p bin/img
./tools/mkbootimg/mkbootimg.exe chroma.json bin/img/chroma.img # for linux remove the .exe
echo "Checking for VirtualBox management tools"
if [ -x "$(command -v VBoxManage)" ]; then
echo " VBoxManage found.. integrating."
echo " Clearing VirtualBox cache:"
VBoxManage storageattach Chroma --port 0 --storagectl AHCI --medium none # removing a drive in virtualbox = attaching nothing
VBoxManage closemedium disk --delete "`pwd`/chroma.vdi" # remove the existing .vdi image from the registry so we can overwrite it
VBoxManage closemedium disk --delete "`pwd`/bin/img/chroma.vdi" # remove the existing .vdi image from the registry so we can overwrite it
echo " Creating new VirtualBox VDI image:"
VBoxManage convertfromraw chroma.img --format VDI chroma.vdi # generate the new vdi from the img
VBoxManage convertfromraw bin/img/chroma.img --format VDI bin/img/chroma.vdi # generate the new vdi from the img
echo " Attaching image to the VM."
VBoxManage storageattach Chroma --port 0 --storagectl AHCI --type hdd --medium "`pwd`/chroma.vdi" # attach the new vdi to the vm so we can run it
VBoxManage storageattach Chroma --port 0 --storagectl AHCI --type hdd --medium "`pwd`/bin/img/chroma.vdi" # attach the new vdi to the vm so we can run it
echo " VirtualBox integrations complete. You may execute run.sh to run your VirtualBox VM."
fi

4
pre.sh
View File

@ -1,3 +1,5 @@
#!/bin/sh
x86_64-elf-ld -r -b binary -o font.o font.psf
mkdir -p obj/assets
x86_64-elf-ld -r -b binary -o src/assets/font.o src/assets/font.psf
cmake -G"Unix Makefiles" .

View File

@ -29,7 +29,7 @@ extern size_t LoadAddr;
extern bootinfo bootldr;
extern unsigned char* environment;
extern uint8_t fb;
extern volatile unsigned char _binary_font_psf_start;
extern volatile unsigned char _binary_src_assets_font_psf_start;
extern volatile size_t* _kernel_text_start;
extern address_space_t KernelAddressSpace;

View File

@ -291,7 +291,7 @@ void WriteString(const char* string) {
void WriteStringWithFont(const char *inChar)
{
psf_t *font = (psf_t*) &_binary_font_psf_start;
psf_t *font = (psf_t*) &_binary_src_assets_font_psf_start;
unsigned int drawX, drawY, kx = 0, fontLine, bitMask, offset;
@ -299,10 +299,10 @@ void WriteStringWithFont(const char *inChar)
while(*inChar) {
unsigned char *glyph =
(unsigned char*) &_binary_font_psf_start
(unsigned char*) &_binary_src_assets_font_psf_start
+ font->headerSize
+ (*inChar > 0 && *inChar < (int)font->numGlyphs ? *inChar : 0)
* font->glyphSize;
+ (*inChar > 0 && *inChar < (int)font->numGlyphs ? *inChar : 0) *
font->glyphSize;
offset = (kx * (font->glyphWidth + 1) * 4);

1
tools/elf_url.txt Normal file
View File

@ -0,0 +1 @@
https://github.com/lordmilko/i686-elf-tools/releases/download/7.1.0/x86_64-elf-tools-linux.zip