diff options
-rw-r--r-- | CMakeLists.txt | 43 | ||||
-rw-r--r-- | Makefile | 22 | ||||
-rw-r--r-- | apps/test.c | 5 | ||||
-rwxr-xr-x | run | 37 | ||||
-rw-r--r-- | src/drivers/vesa.c | 25 | ||||
-rw-r--r-- | src/inc/vesa.h | 53 | ||||
-rw-r--r-- | src/main.c | 11 |
7 files changed, 122 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 1ad8dbe..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(Melvix) -enable_language(ASM) -# set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_COLOR_MAKEFILE on) -set(CMAKE_EXPORT_COMPILE_COMMANDS on) - -find_program(CCACHE_FOUND ccache) -if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) -endif(CCACHE_FOUND) - -# Compiler and linker -set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS " ") -set(CMAKE_C_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc") -set(CMAKE_ASM_COMPILER "nasm") -set(CMAKE_LINKER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc") -set(CMAKE_ASM_LINKER_PREFERENCE ${CMAKE_LINKER}) -set(CMAKE_C_LINKER_PREFERENCE ${CMAKE_LINKER}) - -# Compiler and linker flags -set(CMAKE_C_FLAGS "-Wall -Wextra -nostdlib -nostdinc -ffreestanding -std=c99 -pedantic-errors -c -I${CMAKE_CURRENT_SOURCE_DIR}/src/lib/") -set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -O2 -nostdlib -nostdinc -emain") -set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> -o <OBJECT> -f bin -O0") -set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") -set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") - -# Recursive sources -file(GLOB_RECURSE sources src/*.c) -file(GLOB_RECURSE apps_sources apps/*.c) - -# MELVIX -add_executable(melvix ${sources}) -set_target_properties(melvix PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/melvix.o") -target_link_libraries(melvix PRIVATE "-Ttext 0x0050000") - -# APPS -foreach(loop_file ${apps_sources}) - get_filename_component(testname ${loop_file} NAME_WE) - add_executable(${testname} ${loop_file}) - set_target_properties(${testname} PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/disk/bin/${testname}") -endforeach(loop_file ${user_sources}) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c25895f --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +COBJS = src/main.o \ + src/drivers/vesa.o +CC = cross/opt/bin/i686-elf-gcc +LD = cross/opt/bin/i686-elf-ld +AS = nasm + +CFLAGS = -Wall -Wextra -nostdlib -nostdinc -ffreestanding -std=c99 -pedantic-errors -Isrc/lib/ -Isrc/inc/ -c + +all: compile clean + +%.o: %.c + $(CC) $(CFLAGS) $< -o $@ + +kernel: $(COBJS) + +compile: kernel + mkdir -p build/ + $(AS) -f bin src/entry.asm -o build/boot.bin + $(LD) -N -emain -Ttext 0x00050000 -o build/kernel.bin $(COBJS) --oformat binary + +clean: + find src/ -name "*.o" -type f -delete diff --git a/apps/test.c b/apps/test.c deleted file mode 100644 index bce7343..0000000 --- a/apps/test.c +++ /dev/null @@ -1,5 +0,0 @@ -int main() -{ - int a = 42 >> 6; - return a; -} @@ -62,27 +62,17 @@ make_cross() { } make_build() { - rm -rf disk/bin/ disk/ build/disk.img - mkdir -p build/ disk/bin/ disk/ + mkdir -p build/ + rm -rf build/* echo "Building..." - cd build/ - cmake .. >/dev/null make - cd .. - - # Assemble bootloader - nasm src/entry.asm -f bin -o disk/boot.bin - - # Make kernel binary - objcopy -O binary build/melvix.o build/melvix.bin - cp build/melvix.bin disk/ # Create disk image dd if=/dev/zero of=build/disk.img bs=1k count=16k sudo mke2fs build/disk.img >/dev/null - dd if=disk/boot.bin of=build/disk.img conv=notrunc - ./ext2util/ext2util -x build/disk.img -wf disk/melvix.bin -i 5 >/dev/null + dd if=build/boot.bin of=build/disk.img conv=notrunc + ./ext2util/ext2util -x build/disk.img -wf build/kernel.bin -i 5 >/dev/null printf "Build finshed successfully!\n\n" } @@ -96,17 +86,18 @@ make_debug() { } make_disasm() { - objdump -drwC -Mintel build/kernel.bin --visualize-jumps=color | less -R + objdump -drwC -Mintel build/melvix.bin --visualize-jumps=color | less -R + #hexdump -C build/melvix.bin | less -R } make_sync() { - #rm tags compile_commands.json ctags -R --exclude=.git --exclude=build --exclude=iso --exclude=cross . - mkdir -p build - cd build - cmake .. >/dev/null - mv compile_commands.json .. - cd .. + + make --always-make --dry-run | + grep -wE 'gcc|g++' | + grep -w '\-c' | + jq -nR '[inputs|{directory:".", command:., file: match(" [^ ]+$").string[1:]}]' \ + >compile_commands.json } make_tidy() { @@ -117,7 +108,7 @@ make_tidy() { } make_clean() { - rm -rf ./disk/bin/ ./disk/boot/ ./build/ + rm -rf ./build/ } if [ "${mode}" = "cross" ]; then @@ -130,6 +121,7 @@ elif [ "${mode}" = "clean" ]; then make_clean elif [ "${mode}" = "test" ]; then make_cross + make_clean make_build make_sync & make_test @@ -150,6 +142,7 @@ elif [ "${mode}" = "tidy" ]; then make_tidy elif [ "${mode}" = "" ]; then # TODO: Prevent code duplication in build script via functions? make_cross + make_clean make_build make_sync & make_test diff --git a/src/drivers/vesa.c b/src/drivers/vesa.c new file mode 100644 index 0000000..ca130db --- /dev/null +++ b/src/drivers/vesa.c @@ -0,0 +1,25 @@ +#include <def.h> +#include <vesa.h> + +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) +{ + int vbe_bpl = vbe->bpp >> 3; + int vbe_pitch = vbe->pitch; + u8 *fb = (u8 *)vbe->framebuffer; + + int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; + char *draw = (char *)&fb[pos1]; + for (int i = 0; i <= y2 - y1; i++) { + for (int j = 0; j <= x2 - x1; j++) { + draw[vbe_bpl * j] = (char)color[2]; + draw[vbe_bpl * j + 1] = (char)color[1]; + draw[vbe_bpl * j + 2] = (char)color[0]; + } + draw += vbe_pitch; + } +} + +void vesa_clear(const u32 color[3]) +{ + vesa_draw_rectangle(0, 0, vbe->width - 1, vbe->height - 1, color); +} diff --git a/src/inc/vesa.h b/src/inc/vesa.h new file mode 100644 index 0000000..e2ac4e5 --- /dev/null +++ b/src/inc/vesa.h @@ -0,0 +1,53 @@ +#ifndef VBE_H +#define VBE_H + +#include <def.h> + +struct vbe { + u16 attributes; + u8 window_a; + u8 window_b; + u16 granularity; + u16 window_size; + u16 segment_a; + u16 segment_b; + u32 win_func_ptr; + u16 pitch; + u16 width; + u16 height; + u8 w_char; + u8 y_char; + u8 planes; + u8 bpp; + u8 banks; + u8 memory_model; + u8 bank_size; + u8 image_pages; + u8 reserved0; + + u8 red_mask; + u8 red_position; + u8 green_mask; + u8 green_position; + u8 blue_mask; + u8 blue_position; + u8 reserved_mask; + u8 reserved_position; + u8 direct_color_attributes; + + u32 framebuffer; + u32 off_screen_mem_off; + u16 off_screen_mem_size; + u8 reserved1[206]; +}; + +struct vid_info { + u32 mode; + struct vbe *info; +}; + +struct vbe *vbe; + +void vesa_clear(const u32 color[3]); + +#endif @@ -1,11 +1,14 @@ #include <def.h> +#include <vesa.h> -// This must kinda be at the top -int main(u32 *mem_info, u32 *vid_info) +void main(u32 *mem_info, struct vid_info *vid_info) { mem_info++; // TODO: Use the mmap! - vid_info++; // TODO: Use the VBE struct! + vbe = vid_info->info; + + u32 terminal_background[3] = { 0x1d, 0x1f, 0x24 }; + vesa_clear(terminal_background); + while (1) { }; - return 0; } |