diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | LICENSE | 14 | ||||
-rw-r--r-- | kernel/Makefile | 10 | ||||
-rw-r--r-- | kernel/scalls/sigaction.c | 9 | ||||
-rw-r--r-- | kernel/scalls/sigaction.h | 3 | ||||
-rwxr-xr-x | meta/build.sh | 4 | ||||
-rw-r--r-- | meta/debug.sh | 3 | ||||
-rwxr-xr-x | meta/kernel.sh | 4 | ||||
-rwxr-xr-x | meta/new.sh | 8 | ||||
-rwxr-xr-x | meta/run.sh | 5 | ||||
-rwxr-xr-x | meta/sync.sh | 10 | ||||
-rwxr-xr-x | meta/userland.sh | 39 | ||||
-rwxr-xr-x | new.sh | 3 | ||||
-rwxr-xr-x | sync.sh | 74 | ||||
-rw-r--r-- | userland/libppm/.gitignore | 1 | ||||
-rw-r--r-- | userland/libppm/Makefile | 15 | ||||
-rw-r--r-- | userland/libppm/file.ppm | 7 | ||||
-rw-r--r-- | userland/libppm/ppm.c | 199 |
18 files changed, 309 insertions, 101 deletions
@@ -8,6 +8,8 @@ *.tar.xz *.tar.xz.sig .cache/ +logs/ +sysroot/* toolchain/bin/ toolchain/binutils-*/ toolchain/gcc-*/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3b16888..0000000 --- a/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (C) 2022 - 2023 Anton Kling <anton@kling.gg> - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <https://www.gnu.org/licenses/>. diff --git a/kernel/Makefile b/kernel/Makefile index 5098944..8fd5df1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,16 +15,6 @@ all: myos.iso myos.bin: $(OBJ) $(CC) $(INCLUDE) -shared -T linker.ld -o myos.bin -ffreestanding -nostdlib $(CFLAGS) $^ -lgcc -debug: - qemu-system-i386 -no-reboot -no-shutdown -serial file:./serial.log -hda ext2.img -m 1G -cdrom myos.iso -s -S & - gdb -x .gdbinit - -nk: - qemu-system-i386 -d int -netdev user,id=n0,hostfwd=udp:127.0.0.1:6001-:6000 -device rtl8139,netdev=n0 -no-reboot -no-shutdown -serial file:./serial.log -hda ext2.img -m 1G -cdrom myos.iso -s - -run: - qemu-system-i386 -enable-kvm -netdev user,id=n0,hostfwd=udp:127.0.0.1:6001-:6000 -device rtl8139,netdev=n0 -object filter-dump,id=id,netdev=n0,file=netout -d int -no-reboot -no-shutdown -chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0 -hda ext2.img -m 1G -cdrom myos.iso -s - myos.iso: myos.bin cp myos.bin isodir/boot grub-mkrescue -o myos.iso isodir diff --git a/kernel/scalls/sigaction.c b/kernel/scalls/sigaction.c new file mode 100644 index 0000000..0166fab --- /dev/null +++ b/kernel/scalls/sigaction.c @@ -0,0 +1,9 @@ +#include <scalls/sigaction.h> +#include <signal.h> +#include <sched/scheduler.h> + +int syscall_sigaction(int sig, const struct sigaction *restrict act, + struct sigaction *restrict oact) { + set_signal_handler(sig, act->sa_handler); + return 0; +} diff --git a/kernel/scalls/sigaction.h b/kernel/scalls/sigaction.h new file mode 100644 index 0000000..0f0aa5f --- /dev/null +++ b/kernel/scalls/sigaction.h @@ -0,0 +1,3 @@ +#include <signal.h> +int syscall_sigaction(int sig, const struct sigaction *restrict act, + struct sigaction *restrict oact) ; diff --git a/meta/build.sh b/meta/build.sh new file mode 100755 index 0000000..39d778a --- /dev/null +++ b/meta/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh +scriptdir="$(dirname "$0")" +cd "$scriptdir" +./kernel.sh && ./userland.sh && ./sync.sh diff --git a/meta/debug.sh b/meta/debug.sh new file mode 100644 index 0000000..7fcb185 --- /dev/null +++ b/meta/debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh +qemu-system-i386 -no-reboot -no-shutdown -serial file:./logs/serial.log -hda ext2.img -m 1G -cdrom ./kernel/myos.iso -s -S & +gdb -x .gdbinit diff --git a/meta/kernel.sh b/meta/kernel.sh new file mode 100755 index 0000000..4cd02b8 --- /dev/null +++ b/meta/kernel.sh @@ -0,0 +1,4 @@ +#!/bin/sh +scriptdir="$(dirname "$0")" +cd "$scriptdir" +make -C ../kernel diff --git a/meta/new.sh b/meta/new.sh new file mode 100755 index 0000000..deb0774 --- /dev/null +++ b/meta/new.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# If the filesystem becomes corrupted this shell script is used to +# completly reset it +scriptdir="$(dirname "$0")" +cd "$scriptdir" +rm ext2.img +mkfs.ext2 ext2.img 20M +./sync.sh diff --git a/meta/run.sh b/meta/run.sh new file mode 100755 index 0000000..d72efdb --- /dev/null +++ b/meta/run.sh @@ -0,0 +1,5 @@ +#!/bin/sh +scriptdir="$(dirname "$0")" +cd "$scriptdir" +cd .. +qemu-system-i386 -enable-kvm -netdev user,id=n0,hostfwd=udp:127.0.0.1:6001-:6000 -device rtl8139,netdev=n0 -object filter-dump,id=id,netdev=n0,file=./logs/netout -d int -no-reboot -no-shutdown -chardev stdio,id=char0,logfile=./logs/serial.log,signal=off -serial chardev:char0 -hda ./meta/ext2.img -m 1G -cdrom ./kernel/myos.iso -s diff --git a/meta/sync.sh b/meta/sync.sh new file mode 100755 index 0000000..036ad18 --- /dev/null +++ b/meta/sync.sh @@ -0,0 +1,10 @@ +#!/bin/sh +scriptdir="$(dirname "$0")" +cd "$scriptdir" + +# Sync the sysroot with the bootable image +mkdir ./mount +sudo mount ext2.img mount +sudo cp -r ../sysroot/* ./mount/ +sudo umount mount +rmdir ./mount diff --git a/meta/userland.sh b/meta/userland.sh new file mode 100755 index 0000000..1686023 --- /dev/null +++ b/meta/userland.sh @@ -0,0 +1,39 @@ +#!/bin/sh +scriptdir="$(dirname "$0")" +cd "$scriptdir" +cd .. +make -C ./userland/libgui +make -C ./userland/libc +make -C ./userland/sh +make -C ./userland/terminal +make -C ./userland/snake +make -C ./userland/ante +make -C ./userland/windowserver +make -C ./userland/test +make -C ./userland/minibox +make -C ./userland/libppm + +mkdir sysroot +sudo cp ./userland/libppm/ppm ./sysroot/ppm +sudo cp ./userland/sh/sh ./sysroot/sh +sudo cp ./userland/terminal/term ./sysroot/term +sudo cp ./userland/snake/snake ./sysroot/snake +sudo cp ./userland/ante/ante ./sysroot/ante +sudo cp ./userland/windowserver/ws ./sysroot/ws +sudo cp ./userland/test/test ./sysroot/test +sudo cp ./userland/minibox/minibox ./sysroot/minibox + +cd ./sysroot +rm ./init +rm ./cat +rm ./yes +rm ./echo +rm ./wc +rm ./ls +ln -s ./minibox ./init +ln -s ./minibox ./cat +ln -s ./minibox ./yes +ln -s ./minibox ./echo +ln -s ./minibox ./wc +ln -s ./minibox ./ls +cd .. @@ -1,3 +0,0 @@ -#!/bin/sh -cp new_ext2.img ext2.img -./sync.sh diff --git a/sync.sh b/sync.sh deleted file mode 100755 index 3a7498b..0000000 --- a/sync.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -cd ./userland/libgui -make clean -make -cd ../.. -# -cd ./userland/libc -#make clean -make -make install -cd ../.. - -cd ./userland/sh -make clean -make -cd ../.. -cd ./userland/terminal -make clean -make -cd ../.. -# -cd ./userland/snake -make clean -make -cd ../.. -# -cd ./userland/ante -make clean -make -cd ../.. -# -cd ./userland/windowserver -make clean -make -cd ../.. -# -cd ./userland/test -make clean -make -cd ../.. -# -cd ./userland/minibox -make clean -make -cd ../.. - -pwd -sudo mount ext2.img mount -sudo cp ./userland/sh/sh ./mount/sh -sudo cp ./userland/terminal/term ./mount/term -sudo cp ./userland/snake/snake ./mount/snake -sudo cp ./userland/ante/ante ./mount/ante -sudo cp ./userland/windowserver/ws ./mount/ws -sudo cp ./userland/test/test ./mount/test -sudo cp ./userland/minibox/minibox ./mount/minibox - -echo -e "int main(void) {\nprintf(\"hi\");\nreturn 0;\n}" > /tmp/main.c - -cd ./mount -sudo rm ./init -sudo rm ./cat -sudo rm ./yes -sudo rm ./echo -sudo rm ./wc -sudo rm ./ls -sudo ln -s ./minibox ./init -sudo ln -s ./minibox ./cat -sudo ln -s ./minibox ./yes -sudo ln -s ./minibox ./echo -sudo ln -s ./minibox ./wc -sudo ln -s ./minibox ./ls -sudo cp /tmp/main.c ./main.c -cd .. -sudo umount mount diff --git a/userland/libppm/.gitignore b/userland/libppm/.gitignore new file mode 100644 index 0000000..2f046a8 --- /dev/null +++ b/userland/libppm/.gitignore @@ -0,0 +1 @@ +ppm diff --git a/userland/libppm/Makefile b/userland/libppm/Makefile new file mode 100644 index 0000000..405e1dd --- /dev/null +++ b/userland/libppm/Makefile @@ -0,0 +1,15 @@ +CC="i686-sb-gcc" +CFLAGS = -ggdb -O3 -Wall -Wextra -pedantic +LIB=-L../libgui -lgui +INC=-I../libgui/ +BINS=ppm +all: $(BINS) + +ppm.o: ppm.c + $(CC) $(CFLAGS) $(INC) $(LIB) -o $@ -c $< + +ppm: ppm.o + $(CC) $(CFLAGS) -o $@ $^ $(LIB) + +clean: + rm $(BINS) *.o diff --git a/userland/libppm/file.ppm b/userland/libppm/file.ppm new file mode 100644 index 0000000..2925e2e --- /dev/null +++ b/userland/libppm/file.ppm @@ -0,0 +1,7 @@ +P3 +4 4 +15 + 0 0 0 0 0 0 0 0 0 15 0 15 + 0 0 0 0 15 7 0 0 0 0 0 0 + 0 0 0 0 0 0 0 15 7 0 0 0 +15 0 15 0 0 0 0 0 0 0 0 0 diff --git a/userland/libppm/ppm.c b/userland/libppm/ppm.c new file mode 100644 index 0000000..030c68d --- /dev/null +++ b/userland/libppm/ppm.c @@ -0,0 +1,199 @@ +// Very unfinished application that can view images and set the +// wallpaper. It only supports ppm3 and ppm6 files. +#include <assert.h> +#include <fcntl.h> +#include <libgui.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +GUI_Window *global_w; + +struct PPM_IMAGE { + uint8_t version; + uint32_t width; + uint32_t height; + uint32_t maxval; + long file_location; +}; + +int parse_ppm_header(FILE *fp, struct PPM_IMAGE *img) { + char magic[3]; + int width; + int height; + int maxval; + // TODO: Use %2s when scanf supports that + char c1; + char c2; + fscanf(fp, "%c%c\n%d %d\n%d", &c1, &c2, &width, &height, &maxval); + if ('P' != c1) + return 0; + if (!isdigit(c2)) + return 0; + img->version = c2 - '0'; + if (3 != img->version && 6 != img->version) + return 0; + if (maxval > 255) { + printf("maxval is: %d\n", maxval); + return 0; + } + img->width = width; + img->height = height; + img->maxval = maxval; + img->file_location = ftell(fp); + printf("width: %d\n", img->width); + printf("height: %d\n", img->height); + return 1; +} + +inline uint32_t low_32_reverse(uint32_t _value) { + return (((_value & 0x000000FF) << 24) | ((_value & 0x0000FF00) << 8) | + ((_value & 0x00FF0000) >> 8)); +} + +int load_ppm6_file(FILE *fp, const struct PPM_IMAGE *img, uint32_t buf_width, + uint32_t buf_height, uint32_t *buffer) { + fseek(fp, img->file_location, SEEK_SET); + const uint8_t modifier = 255 / img->maxval; + int cx = 0; + int cy = 0; + const int n_pixels = img->width * img->height; + printf("malloc\n"); + uint8_t *rgb = malloc(3 * n_pixels); + printf("end malloc\n"); + + printf("fread"); + int rc = fread(rgb, 3, n_pixels, fp); + if (0 == rc) + return 0; + printf("end fread"); + + uint32_t *p = rgb; + if (1 == modifier) { + for (; rc--; p = ((uint8_t *)p) + 3) { + uint32_t v = *p; + buffer[cy * buf_width + cx] = + ((v & 0xFF) << 16) | ((v & 0xFF00)) | ((v & 0xFF0000) >> 16); + cx++; + if (cx == img->width) { + cx = 0; + cy++; + continue; + } + } + } else { + for (; rc--; p = ((uint8_t *)p) + 3) { + ((uint8_t *)p)[0] *= modifier; + ((uint8_t *)p)[1] *= modifier; + ((uint8_t *)p)[2] *= modifier; + uint32_t v = *p; + buffer[cy * buf_width + cx] = + ((v & 0xFF) << 16) | ((v & 0xFF00)) | ((v & 0xFF0000) >> 16); + cx++; + if (cx == img->width) { + cx = 0; + cy++; + continue; + } + } + } + return 1; +} + +int load_ppm3_file(FILE *fp, const struct PPM_IMAGE *img, uint32_t buf_width, + uint32_t buf_height, uint32_t *buffer) { + fseek(fp, img->file_location, SEEK_SET); + uint8_t modifier = 255 / img->maxval; + int cx = 0; + int cy = 0; + for (int i = 0; i < img->width * img->height; i++) { + int red; + int green; + int blue; + int rc = fscanf(fp, "%d %d %d", &red, &green, &blue); + if (0 == rc) + break; + red &= 0xFF; + green &= 0xFF; + blue &= 0xFF; + red *= modifier; + green *= modifier; + blue *= modifier; + if (3 != rc) { + printf("not 3: %d\n", rc); + return 0; + } + buffer[cy * buf_width + cx] = + (red << 8 * 2) | (green << 8 * 1) | (blue << 8 * 0); + cx++; + if (cx == img->width) { + cx = 0; + cy++; + continue; + } + } + return 1; +} + +int load_ppm_file(FILE *fp, const struct PPM_IMAGE *img, uint32_t buf_width, + uint32_t buf_height, uint32_t *buffer) { + if (3 == img->version) + return load_ppm3_file(fp, img, buf_width, buf_height, buffer); + else if (6 == img->version) + return load_ppm6_file(fp, img, buf_width, buf_height, buffer); + return 0; +} + +struct DISPLAY_INFO { + uint32_t width; + uint32_t height; + uint8_t bpp; +}; + +int main(int argc, char **argv) { + if (argc < 2) { + printf("provide command line arguments dumbass\n"); + return 1; + } + argv++; + + int set_wallpaper = 0; + // Parse commandline arguments(shitty) + if (0 == strcmp(*argv, "-w")) { + set_wallpaper = 1; + argv++; + } + + const char *file = *argv; + + struct PPM_IMAGE img; + FILE *fp = fopen(file, "rb"); + assert(fp); + assert(parse_ppm_header(fp, &img)); + + if (!set_wallpaper) { + global_w = GUI_CreateWindow(80, 80, img.width, img.height); + assert(global_w); + assert( + load_ppm_file(fp, &img, img.width, img.height, global_w->bitmap_ptr)); + GUI_UpdateWindow(global_w); + fclose(fp); + GUI_EventLoop(global_w, NULL); + } else { + int wallpaper_fd = shm_open("wallpaper", O_RDWR, 0); + assert(wallpaper_fd >= 0); + + struct DISPLAY_INFO inf; + int fd = open("/dev/display_info", O_READ, 0); + assert(fd >= 0); + assert(sizeof(inf) == read(fd, &inf, sizeof(inf))); + + void *rc = mmap(NULL, inf.width * inf.height * sizeof(uint32_t), 0, 0, + wallpaper_fd, 0); + assert(rc); + assert(load_ppm_file(fp, &img, inf.width, inf.height, rc)); + close(fd); + } + return 0; +} |