diff --git a/.gitignore b/.gitignore index dd3fcfc..e47132b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,5 @@ .idea .vscode -build -isodir - -compiler*/ \ No newline at end of file +sysroot +isodir \ No newline at end of file diff --git a/build.sh b/build.sh index c866331..2f94e28 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,16 @@ #!/bin/bash -./build_libc.sh +./build_sysroot.sh + +./build_libs.sh + ./build_programs.sh make clean bear -- make +./copy_resources.sh + ./make_img.sh make -B \ No newline at end of file diff --git a/build_libc.sh b/build_libc.sh deleted file mode 100755 index 7f4ce6a..0000000 --- a/build_libc.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -cd rocklibc -make clean -bear -- make -cd .. \ No newline at end of file diff --git a/build_libs.sh b/build_libs.sh new file mode 100755 index 0000000..9de0694 --- /dev/null +++ b/build_libs.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +cp -r kernel/sys/*.h rlibc/include/sys + +cd rlibc +make clean +bear -- make +cp rlibc.a ../sysroot/usr/lib +cp -r include/. ../sysroot/usr/include +cd .. + +cd rlibgui +make clean +bear -- make +cp rlibgui.a ../sysroot/usr/lib +cp -r include/. ../sysroot/usr/include +cd .. \ No newline at end of file diff --git a/build_programs.sh b/build_programs.sh index 48a8092..a2fcfc7 100755 --- a/build_programs.sh +++ b/build_programs.sh @@ -1,17 +1,16 @@ #!/bin/bash -TARGET_DIR="programs" +cd programs +ln -s ../sysroot sysroot 2>/dev/null -if [ ! -d "$TARGET_DIR" ]; then - exit 1 -fi - -find "$TARGET_DIR" -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do +find "." -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do dir_path=$(dirname "$makefile_path") ( cd "$dir_path" || exit make clean - make + bear -- make ) -done \ No newline at end of file +done + +cd.. \ No newline at end of file diff --git a/build_sysroot.sh b/build_sysroot.sh new file mode 100755 index 0000000..4a0f7f8 --- /dev/null +++ b/build_sysroot.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +mkdir -p sysroot + +mkdir -p sysroot/usr +mkdir -p sysroot/dev +mkdir -p sysroot/kernel + +mkdir -p sysroot/usr/include +mkdir -p sysroot/usr/lib +mkdir -p sysroot/usr/bin +mkdir -p sysroot/usr/fonts \ No newline at end of file diff --git a/clean.sh b/clean.sh index f9b4f97..1b22439 100755 --- a/clean.sh +++ b/clean.sh @@ -1,9 +1,16 @@ #!/bin/bash -cd rocklibc +# libc +cd rlibc make clean cd .. +# libgui +cd rlibgui +make clean +cd .. + +# programs cd programs find . -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do dir_path=$(dirname "$makefile_path") @@ -13,10 +20,10 @@ find . -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefi make clean ) done +rm sysroot cd .. +# kernel make clean -cd initrd -rm -f bin/*.elf -cd .. \ No newline at end of file +rm -rf sysroot \ No newline at end of file diff --git a/copy_resources.sh b/copy_resources.sh new file mode 100755 index 0000000..1ae9c4a --- /dev/null +++ b/copy_resources.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cp -r resources/fonts/. sysroot/usr/fonts + +cp -r kernel/. sysroot/kernel \ No newline at end of file diff --git a/kernel/drivers/ps2/ps2.c b/kernel/drivers/ps2/ps2.c index 7146eff..d72f0e3 100644 --- a/kernel/drivers/ps2/ps2.c +++ b/kernel/drivers/ps2/ps2.c @@ -2,6 +2,8 @@ #include +#include + static const char scancode_to_ascii[] = { 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', @@ -73,7 +75,11 @@ int init_ps2() { write_ccb(ccb); return 0; -} +} + +void ps2_init_kbd(vfs_node_t* dev) { + +} char ps2_get_ascii(uint8_t scancode) { if (scancode & 0x80) { @@ -88,4 +94,5 @@ char ps2_get_ascii(uint8_t scancode) { } return 0; -} \ No newline at end of file +} + diff --git a/kernel/drivers/ps2/ps2.h b/kernel/drivers/ps2/ps2.h index 607cf64..fa70701 100644 --- a/kernel/drivers/ps2/ps2.h +++ b/kernel/drivers/ps2/ps2.h @@ -18,8 +18,10 @@ #ifndef __ASSEMBLER__ #include +#include int init_ps2(); +void ps2_init_kbd(vfs_node_t* dev); uint8_t ps2_read_data(); char ps2_get_ascii(uint8_t scancode); diff --git a/kernel/drivers/vga/vga.c b/kernel/drivers/vga/vga.c index 4344728..8955782 100644 --- a/kernel/drivers/vga/vga.c +++ b/kernel/drivers/vga/vga.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -10,7 +10,7 @@ #include #include -#include +#include static uint32_t framebuffer_address; static uint32_t framebuffer_width; @@ -19,25 +19,11 @@ static uint32_t framebuffer_total_pixels; static uint32_t framebuffer_pitch; static uint32_t framebuffer_bpp; -static uint8_t red_mask_sz; -static uint8_t red_field_pos; -static uint8_t green_mask_sz; -static uint8_t green_field_pos; -static uint8_t blue_mask_sz; -static uint8_t blue_field_pos; - -static uint32_t create_pixel(uint8_t r, uint8_t g, uint8_t b) { - return (r >> (8 - red_mask_sz)) << red_field_pos - | (g >> (8 - green_mask_sz)) << green_field_pos - | (b >> (8 - blue_mask_sz)) << blue_field_pos; -} - vga_color_t VGA_COLOR_BLACK = {0, 0, 0, 255}; vga_color_t VGA_COLOR_RED = {0, 0, 255, 255}; vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255}; vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255}; - uint32_t vga_mmap(vfs_node_t* node, uint32_t address) { uint32_t fb_size_bytes = framebuffer_height * framebuffer_pitch; uint32_t num_pages = (fb_size_bytes + 4095) / 4096; @@ -77,6 +63,8 @@ void vga_init( framebuffer_pitch = fb_pitch; framebuffer_bpp = fb_bpp; + kprintf("mapping vga pages\n"); + uint32_t fb_size_bytes = fb_height * fb_pitch; uint32_t num_pages = (fb_size_bytes + 4095) / 4096; for (uint32_t i = 0; i < num_pages; i++) { @@ -113,9 +101,7 @@ uint8_t vga_get_bpp() { } void vga_clear_scrn(uint32_t color) { - if (framebuffer_address == 0) return; - - uint8_t* fb_bytes = (uint8_t*)framebuffer_address; + uint8_t* fb_bytes = (uint8_t*)VGA_FRAMEBUFFER; uint8_t bytes_per_pixel = framebuffer_bpp / 8; for (uint32_t y = 0; y < framebuffer_height; y++) { diff --git a/kernel/kmain.c b/kernel/kmain.c index b1d6f26..1973c8c 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -1,4 +1,3 @@ -#include "lib/font.h" #include "multiboot.h" #include "interrupts.h" #include "gdt.h" @@ -166,20 +165,16 @@ void kmain(multiboot_info* mbi) { dev->mnt = devfs; kprintf("mounted devfs\n"); - - console_init(); - kprintf("kernel console initialized\n"); - - int font_loaded = set_console_font("/fonts/kernel_font.psf"); + + int font_loaded = set_console_font("/usr/fonts/kernel_font.psf"); if (!font_loaded) { kprintf("failed to load console font\n"); } + console_init(); - kprintf("console font set\n"); + kprintf("kernel console initialized\n"); kprintf("basic initializations complete. check serial for details\n"); - kprintf("starting rockos\n"); - load_root_program("/bin/vga_text_term.elf"); - kprintf("kernel going to sleep...\n"); + load_root_program("/usr/bin/rockterm"); } diff --git a/kernel/lib/console.c b/kernel/lib/console.c index e8afdad..95122ab 100644 --- a/kernel/lib/console.c +++ b/kernel/lib/console.c @@ -16,7 +16,6 @@ static uint32_t console_text_color; static uint32_t console_backgrnd_color; static void write_vga_char(char c) { - print_serial("write_vga_char invoked\r\n"); uint32_t vga_pitch = vga_get_pitch(); uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz); @@ -71,7 +70,6 @@ void console_putchar(char c) { if (!font) return; if (c == '\n') { - print_serial("\r\n"); console_col = 0; console_row++; if (console_row >= console_height) { @@ -80,7 +78,6 @@ void console_putchar(char c) { return; } - write_serial(c); write_vga_char(c); console_col++; diff --git a/kernel/user/video.h b/kernel/sys/video.h similarity index 100% rename from kernel/user/video.h rename to kernel/sys/video.h diff --git a/make_img.sh b/make_img.sh index 16c9e63..ab8fa53 100755 --- a/make_img.sh +++ b/make_img.sh @@ -1,12 +1,5 @@ #!/bin/bash -mkdir -p initrd -rm -f initrd/bin/*.elf - -mkdir -p initrd/dev -mkdir -p initrd/bin -cp programs/bin/* initrd/bin - -cd initrd +cd sysroot find . -depth -print | cpio -o -H newc > ../isodir/boot/initrd.img cd .. \ No newline at end of file diff --git a/programs/lib/rlibc.a b/programs/lib/rlibc.a deleted file mode 100644 index b33b4c6..0000000 Binary files a/programs/lib/rlibc.a and /dev/null differ diff --git a/programs/rocksh/.gitignore b/programs/rocksh/.gitignore new file mode 100644 index 0000000..72436b4 --- /dev/null +++ b/programs/rocksh/.gitignore @@ -0,0 +1 @@ +rocksh \ No newline at end of file diff --git a/programs/rocksh/makefile b/programs/rocksh/makefile index 74e6577..adbd1c2 100644 --- a/programs/rocksh/makefile +++ b/programs/rocksh/makefile @@ -1,10 +1,14 @@ CC = i686-elf-gcc LD = i686-elf-ld -CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include +SYSROOT = ../sysroot +USR_INCLUDE = $(SYSROOT)/usr/include +USR_LIB = $(SYSROOT)/usr/lib + +CFLAGS = -ffreestanding -O2 -Wall -Wextra -I$(USR_INCLUDE) LDFLAGS = -m elf_i386 -nostdlib -TARGET = rocksh.elf +TARGET = rocksh all: $(TARGET) @@ -14,11 +18,12 @@ crt0.o: crt0.S main.o: main.c $(CC) $(CFLAGS) -c main.c -o main.o -$(TARGET): crt0.o main.o ../lib/rlibc.a - $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET) +$(TARGET): crt0.o main.o $(USR_LIB)/* + $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o $(USR_LIB)/* -o $(TARGET) + cp $(TARGET) $(SYSROOT)/usr/bin clean: - rm -f *.o $(TARGET) compile_commands.json + rm -f *.o $(TARGET) compile_commands.json rm -rf .cache .PHONY: all clean test \ No newline at end of file diff --git a/programs/rockterm/.gitignore b/programs/rockterm/.gitignore new file mode 100644 index 0000000..a801a3e --- /dev/null +++ b/programs/rockterm/.gitignore @@ -0,0 +1 @@ +rockterm \ No newline at end of file diff --git a/programs/test/crt0.S b/programs/rockterm/crt0.S similarity index 100% rename from programs/test/crt0.S rename to programs/rockterm/crt0.S diff --git a/programs/test/linker.ld b/programs/rockterm/linker.ld similarity index 100% rename from programs/test/linker.ld rename to programs/rockterm/linker.ld diff --git a/programs/vga_text_term/main.c b/programs/rockterm/main.c similarity index 63% rename from programs/vga_text_term/main.c rename to programs/rockterm/main.c index d8306d3..59ac5e2 100644 --- a/programs/vga_text_term/main.c +++ b/programs/rockterm/main.c @@ -1,46 +1,31 @@ -#include "syscall.h" #include #include -#define VGA_TEXT_W 80 -#define VGA_TEXT_H 25 +typedef struct { -void term(); +} font_t; + +void term_write_char(char c); +void render_char_at(char c, int x, int y); + +int spawn_shell(); int ptys; int ptym; +void* fb; fb_info_t fb_info; -void* framebuffer_address; int terminal_col = 0; int terminal_row = 0; -void term_write_char(char c) { - -} +font_t* terminal_font = NULL; int main(int argc, char *argv[]) { (void)argc; (void)argv; - ptym = pty(&ptys); - - if (fork() == 0) { - close(ptym); - dup2(ptys, 0); - dup2(0, 1); - dup2(0, 2); - - exec("/bin/rocksh.elf"); - } - - close(ptys); - dup2(ptym, 0); - dup2(0, 1); - dup2(0, 2); - int vga_fd = open("/dev/vga"); if (vga_fd == -1) return 1; @@ -52,9 +37,38 @@ int main(int argc, char *argv[]) { return 1; } - framebuffer_address = mmap(vga_fd); - + mmap(vga_fd); + // if (!spawn_shell()) { + // return 1; + // } return 0; +} + +void render_char_at(char c, int x, int y) { + if (!terminal_font) return; +} + +void term_write_char(char c) { + +} + +int spawn_shell() { + ptym = pty(&ptys); + + if (fork() == 0) { + close(ptym); + dup2(ptys, 0); + dup2(0, 1); + dup2(0, 2); + + if (!exec("/usr/bin/rocksh")) return 0; + } + + close(ptys); + dup2(ptym, 0); + dup2(0, 1); + dup2(0, 2); + return 1; } \ No newline at end of file diff --git a/programs/rockterm/makefile b/programs/rockterm/makefile new file mode 100644 index 0000000..183bcf0 --- /dev/null +++ b/programs/rockterm/makefile @@ -0,0 +1,29 @@ +CC = i686-elf-gcc +LD = i686-elf-ld + +SYSROOT = ../sysroot +USR_INCLUDE = $(SYSROOT)/usr/include +USR_LIB = $(SYSROOT)/usr/lib + +CFLAGS = -ffreestanding -O2 -Wall -Wextra -I$(USR_INCLUDE) +LDFLAGS = -m elf_i386 -nostdlib + +TARGET = rockterm + +all: $(TARGET) + +crt0.o: crt0.S + $(CC) $(CFLAGS) -c crt0.S -o crt0.o + +main.o: main.c + $(CC) $(CFLAGS) -c main.c -o main.o + +$(TARGET): crt0.o main.o $(USR_LIB)/* + $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o $(USR_LIB)/* -o $(TARGET) + cp $(TARGET) $(SYSROOT)/usr/bin + +clean: + rm -f *.o $(TARGET) compile_commands.json + rm -rf .cache + +.PHONY: all clean test \ No newline at end of file diff --git a/programs/test/main.c b/programs/test/main.c deleted file mode 100644 index cf4c43c..0000000 --- a/programs/test/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char** argv) { - printf("hello, world!\n"); - return 0; -} \ No newline at end of file diff --git a/programs/test/makefile b/programs/test/makefile deleted file mode 100644 index 8a0d35a..0000000 --- a/programs/test/makefile +++ /dev/null @@ -1,24 +0,0 @@ -CC = i686-elf-gcc -LD = i686-elf-ld - -CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include -LDFLAGS = -m elf_i386 -nostdlib - -TARGET = test.elf - -all: $(TARGET) - -crt0.o: crt0.S - $(CC) $(CFLAGS) -c crt0.S -o crt0.o - -main.o: main.c - $(CC) $(CFLAGS) -c main.c -o main.o - -$(TARGET): crt0.o main.o ../lib/rlibc.a - $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET) - -clean: - rm -f *.o $(TARGET) compile_commands.json - rm -rf .cache - -.PHONY: all clean test \ No newline at end of file diff --git a/programs/vga_text_term/crt0.S b/programs/vga_text_term/crt0.S deleted file mode 100644 index d97f158..0000000 --- a/programs/vga_text_term/crt0.S +++ /dev/null @@ -1,21 +0,0 @@ -.global _start -.extern exit -.section .text -_start: - xor %ebp, %ebp - - mov (%esp), %eax - lea 4(%esp), %ebx - lea 8(%esp,%eax,4), %ecx - - and $-16, %esp - - push %ecx - push %ebx - push %eax - - call main - - push %eax - call exit - diff --git a/programs/vga_text_term/linker.ld b/programs/vga_text_term/linker.ld deleted file mode 100644 index 03d6e3c..0000000 --- a/programs/vga_text_term/linker.ld +++ /dev/null @@ -1,31 +0,0 @@ -ENTRY(_start) - -SECTIONS -{ - . = 0x40000000; - - .text ALIGN(4K) : - { - /* Force the crt0.o entry code to be placed FIRST in memory */ - KEEP(*crt0.o(.text)) - *(.text .text.*) - } - - .rodata ALIGN(4K) : - { - *(.rodata .rodata.*) - } - - .data ALIGN(4K) : - { - *(.data .data.*) - } - - .bss ALIGN(4K) : - { - _bss_start = .; - *(.bss .bss.*) - *(COMMON) - _bss_end = .; - } -} \ No newline at end of file diff --git a/programs/vga_text_term/makefile b/programs/vga_text_term/makefile deleted file mode 100644 index cf3bc6b..0000000 --- a/programs/vga_text_term/makefile +++ /dev/null @@ -1,24 +0,0 @@ -CC = i686-elf-gcc -LD = i686-elf-ld - -CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include -LDFLAGS = -m elf_i386 -nostdlib - -TARGET = vga_text_term.elf - -all: $(TARGET) - -crt0.o: crt0.S - $(CC) $(CFLAGS) -c crt0.S -o crt0.o - -main.o: main.c - $(CC) $(CFLAGS) -c main.c -o main.o - -$(TARGET): crt0.o main.o ../lib/rlibc.a - $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET) - -clean: - rm -f *.o $(TARGET) compile_commands.json - rm -rf .cache - -.PHONY: all clean test \ No newline at end of file diff --git a/initrd/fonts/kernel_font.psf b/resources/fonts/kernel_font.psf similarity index 100% rename from initrd/fonts/kernel_font.psf rename to resources/fonts/kernel_font.psf diff --git a/rocklibc/.gitignore b/rlibc/.gitignore similarity index 100% rename from rocklibc/.gitignore rename to rlibc/.gitignore diff --git a/rocklibc/include/stdio.h b/rlibc/include/stdio.h similarity index 100% rename from rocklibc/include/stdio.h rename to rlibc/include/stdio.h diff --git a/rocklibc/include/stdlib.h b/rlibc/include/stdlib.h similarity index 100% rename from rocklibc/include/stdlib.h rename to rlibc/include/stdlib.h diff --git a/rocklibc/include/string.h b/rlibc/include/string.h similarity index 100% rename from rocklibc/include/string.h rename to rlibc/include/string.h diff --git a/rocklibc/include/sys/types.h b/rlibc/include/sys/types.h similarity index 100% rename from rocklibc/include/sys/types.h rename to rlibc/include/sys/types.h diff --git a/rocklibc/include/sys/video.h b/rlibc/include/sys/video.h similarity index 96% rename from rocklibc/include/sys/video.h rename to rlibc/include/sys/video.h index d87e23c..a42a03c 100644 --- a/rocklibc/include/sys/video.h +++ b/rlibc/include/sys/video.h @@ -13,4 +13,5 @@ typedef struct { uint32_t fb_size; } fb_info_t; + #endif \ No newline at end of file diff --git a/rocklibc/include/syscall.h b/rlibc/include/syscall.h similarity index 100% rename from rocklibc/include/syscall.h rename to rlibc/include/syscall.h diff --git a/rocklibc/include/unistd.h b/rlibc/include/unistd.h similarity index 100% rename from rocklibc/include/unistd.h rename to rlibc/include/unistd.h diff --git a/rocklibc/makefile b/rlibc/makefile similarity index 100% rename from rocklibc/makefile rename to rlibc/makefile diff --git a/rocklibc/src/malloc.c b/rlibc/src/malloc.c similarity index 100% rename from rocklibc/src/malloc.c rename to rlibc/src/malloc.c diff --git a/rocklibc/src/stdio.c b/rlibc/src/stdio.c similarity index 100% rename from rocklibc/src/stdio.c rename to rlibc/src/stdio.c diff --git a/rocklibc/src/strcat.c b/rlibc/src/strcat.c similarity index 100% rename from rocklibc/src/strcat.c rename to rlibc/src/strcat.c diff --git a/rocklibc/src/string.c b/rlibc/src/string.c similarity index 100% rename from rocklibc/src/string.c rename to rlibc/src/string.c diff --git a/rocklibc/src/strtok.c b/rlibc/src/strtok.c similarity index 100% rename from rocklibc/src/strtok.c rename to rlibc/src/strtok.c diff --git a/rocklibc/src/syscall.c b/rlibc/src/syscall.c similarity index 96% rename from rocklibc/src/syscall.c rename to rlibc/src/syscall.c index db175a3..fc8f6fb 100644 --- a/rocklibc/src/syscall.c +++ b/rlibc/src/syscall.c @@ -80,5 +80,5 @@ void* mmap(int fd) { } int ioctl(int fd, uint32_t request, void* arg) { - return syscall3(SYS_IOCTL, fd, request, arg); + return syscall3(SYS_IOCTL, fd, request, (uint32_t)arg); } \ No newline at end of file diff --git a/rlibgui/include/psf.h b/rlibgui/include/psf.h new file mode 100644 index 0000000..e69de29 diff --git a/rlibgui/makefile b/rlibgui/makefile new file mode 100644 index 0000000..f196297 --- /dev/null +++ b/rlibgui/makefile @@ -0,0 +1,20 @@ +CC = i686-elf-gcc +AR = i686-elf-ar +CFLAGS = -ffreestanding -O2 -Wall -Wextra -Iinclude +TARGET = rlibgui.a + +SRCS = $(shell find src -name "*.c") +OBJS = $(SRCS:.c=.o) + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) $(TARGET) compile_commands.json + +.PHONY: all clean \ No newline at end of file diff --git a/rlibgui/rlibgui.a b/rlibgui/rlibgui.a new file mode 100644 index 0000000..11195e7 Binary files /dev/null and b/rlibgui/rlibgui.a differ diff --git a/rlibgui/src/psf.c b/rlibgui/src/psf.c new file mode 100644 index 0000000..e69de29 diff --git a/sysroot/usr/fonts/cp850-8x16.psf b/sysroot/usr/fonts/cp850-8x16.psf deleted file mode 100644 index 7539f61..0000000 Binary files a/sysroot/usr/fonts/cp850-8x16.psf and /dev/null differ