diff --git a/bootstrap/sys-apps.yml b/bootstrap/sys-apps.yml index a186ab0d2..45312d53f 100644 --- a/bootstrap/sys-apps.yml +++ b/bootstrap/sys-apps.yml @@ -183,7 +183,7 @@ packages: # - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' # - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: store + - name: store-ui source: subdir: 'sources/core/apps' tools_required: @@ -209,15 +209,44 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: store-ui + - name: welcome + source: + subdir: 'sources/core/apps' + tools_required: + - host-gcc + pkgs_required: + - mlibc + - freetype + - libjpeg + - kot-graphics + build: + - args: + - 'make' + - '-C' + - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@' + - 'build' + environ: + CC: "@OPTION:cc@" + CXX: "@OPTION:cxx@" + LD: "@OPTION:ld@" + ASMC: "@OPTION:asmc@" + - args: + - 'cp' + - '-r' + - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' + - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' + + - name: lock source: subdir: 'sources/core/apps' tools_required: - host-gcc pkgs_required: - mlibc - - curl - cjson + - freetype + - libjpeg + - kot-graphics build: - args: - 'make' @@ -235,13 +264,15 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: welcome + - name: weather-ui source: subdir: 'sources/core/apps' tools_required: - host-gcc pkgs_required: - mlibc + - curl + - cjson - freetype - libjpeg - kot-graphics @@ -262,7 +293,7 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: lock + - name: desktop source: subdir: 'sources/core/apps' tools_required: @@ -290,14 +321,13 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: weather-ui + - name: explorer source: subdir: 'sources/core/apps' tools_required: - host-gcc pkgs_required: - mlibc - - curl - cjson - freetype - libjpeg @@ -319,7 +349,7 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: desktop + - name: image-reader source: subdir: 'sources/core/apps' tools_required: @@ -347,7 +377,7 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: explorer + - name: text-reader source: subdir: 'sources/core/apps' tools_required: @@ -375,7 +405,7 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: image-reader + - name: shutdown source: subdir: 'sources/core/apps' tools_required: @@ -403,7 +433,7 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' - - name: text-reader + - name: reboot source: subdir: 'sources/core/apps' tools_required: diff --git a/bootstrap/sys-modules.yml b/bootstrap/sys-modules.yml index 299c775d8..0ef251868 100644 --- a/bootstrap/sys-modules.yml +++ b/bootstrap/sys-modules.yml @@ -219,6 +219,28 @@ packages: - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' + - name: devpower + source: + subdir: 'sources/core/modules' + tools_required: + - host-gcc + build: + - args: + - 'make' + - '-C' + - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@' + - 'build' + environ: + CC: "@OPTION:cc@" + CXX: "@OPTION:cxx@" + LD: "@OPTION:ld@" + ASMC: "@OPTION:asmc@" + - args: + - 'cp' + - '-r' + - '@THIS_SOURCE_DIR@/target/@OPTION:arch_name@/bin/.' + - '@SOURCE_ROOT@/target/boot_disk_kot_mount/.' + - name: devfb source: subdir: 'sources/core/modules' diff --git a/sources/core/apps/desktop/icons/icons.json b/sources/core/apps/desktop/icons/icons.json index 34ddea74c..f733458a6 100644 --- a/sources/core/apps/desktop/icons/icons.json +++ b/sources/core/apps/desktop/icons/icons.json @@ -1,4 +1,16 @@ [ + { + "cwdPath": "/usr/", + "iconPath": "/usr/bin/icons/shutdown.tga", + "executablePath": "/usr/bin/shutdown", + "appName": "Shutdown" + }, + { + "cwdPath": "/usr/", + "iconPath": "/usr/bin/icons/reboot.tga", + "executablePath": "/usr/bin/reboot", + "appName": "Reboot" + }, { "cwdPath": "/usr/", "iconPath": "/usr/bin/icons/bash.tga", diff --git a/sources/core/apps/desktop/icons/reboot.tga b/sources/core/apps/desktop/icons/reboot.tga new file mode 100644 index 000000000..5d9581d52 Binary files /dev/null and b/sources/core/apps/desktop/icons/reboot.tga differ diff --git a/sources/core/apps/desktop/icons/shutdown.tga b/sources/core/apps/desktop/icons/shutdown.tga new file mode 100644 index 000000000..ca024202e Binary files /dev/null and b/sources/core/apps/desktop/icons/shutdown.tga differ diff --git a/sources/core/apps/reboot/source/core/core.c b/sources/core/apps/reboot/source/core/core.c new file mode 100644 index 000000000..b44d1d582 --- /dev/null +++ b/sources/core/apps/reboot/source/core/core.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +int main(){ + const char *device = "/dev/power"; + int fd; + int ret; + + fd = open(device, O_RDWR); + if(fd == -1){ + perror("Error opening file"); + return EXIT_FAILURE; + } + + ret = ioctl(fd, 1); + if(ret == -1){ + perror("Error during ioctl call"); + close(fd); + return EXIT_FAILURE; + } + + close(fd); + + printf("Your computer is not yet compatible with the Kot shutdown method.\n"); + return EXIT_SUCCESS; +} diff --git a/sources/core/apps/reboot/target/amd64/.gitignore b/sources/core/apps/reboot/target/amd64/.gitignore new file mode 100644 index 000000000..1c8d0bd3a --- /dev/null +++ b/sources/core/apps/reboot/target/amd64/.gitignore @@ -0,0 +1,3 @@ +**/bin +**/lib +**/tar \ No newline at end of file diff --git a/sources/core/apps/reboot/target/amd64/makefile b/sources/core/apps/reboot/target/amd64/makefile new file mode 100644 index 000000000..f2c1a848a --- /dev/null +++ b/sources/core/apps/reboot/target/amd64/makefile @@ -0,0 +1,39 @@ +cyan = /bin/echo -e "\x1b[36m\#\# $1\x1b[0m" + +# Project Root +override HOME = ../.. + +# Project Resources +SYSROOT = $(HOME)/../../../../sysroot +INCLUDE = $(SYSROOT)/usr/include +LIBRARIES = $(SYSROOT)/usr/lib +SOURCE = $(HOME)/source +TOOLS = $(HOME)/../../tools +BIN = bin/usr/bin +LIB = lib + +# Tools Config +CFLAGS = -Werror + +LDFLAGS = -Wall \ + -lc + +# Recursive Wild Card +rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) + +# Source Files +C_SRC = $(call rwildcard,$(SOURCE),*.c) + +OBJS = $(patsubst $(SOURCE)/%.c,$(LIB)/%_c.o,$(C_SRC)) + +# Target +$(LIB)/%_c.o: $(SOURCE)/%.c + @ mkdir -m 777 -p $(@D) + @ $(call cyan,"$(subst ../,,$^)") + @ $(CC) $(CFLAGS) -c $^ -o $@ + +link: + @ mkdir -m 777 -p $(BIN) + $(CC) $(LDFLAGS) -o $(BIN)/reboot $(OBJS) + +build: $(OBJS) link diff --git a/sources/core/apps/shutdown/source/core/core.c b/sources/core/apps/shutdown/source/core/core.c new file mode 100644 index 000000000..99f154b33 --- /dev/null +++ b/sources/core/apps/shutdown/source/core/core.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +int main(){ + const char *device = "/dev/power"; + int fd; + int ret; + + fd = open(device, O_RDWR); + if(fd == -1){ + perror("Error opening file"); + return EXIT_FAILURE; + } + + ret = ioctl(fd, 0); + if(ret == -1){ + perror("Error during ioctl call"); + close(fd); + return EXIT_FAILURE; + } + + close(fd); + + printf("Your computer is not yet compatible with the Kot shutdown method.\n"); + return EXIT_SUCCESS; +} diff --git a/sources/core/apps/shutdown/target/amd64/.gitignore b/sources/core/apps/shutdown/target/amd64/.gitignore new file mode 100644 index 000000000..1c8d0bd3a --- /dev/null +++ b/sources/core/apps/shutdown/target/amd64/.gitignore @@ -0,0 +1,3 @@ +**/bin +**/lib +**/tar \ No newline at end of file diff --git a/sources/core/apps/shutdown/target/amd64/makefile b/sources/core/apps/shutdown/target/amd64/makefile new file mode 100644 index 000000000..a75872297 --- /dev/null +++ b/sources/core/apps/shutdown/target/amd64/makefile @@ -0,0 +1,39 @@ +cyan = /bin/echo -e "\x1b[36m\#\# $1\x1b[0m" + +# Project Root +override HOME = ../.. + +# Project Resources +SYSROOT = $(HOME)/../../../../sysroot +INCLUDE = $(SYSROOT)/usr/include +LIBRARIES = $(SYSROOT)/usr/lib +SOURCE = $(HOME)/source +TOOLS = $(HOME)/../../tools +BIN = bin/usr/bin +LIB = lib + +# Tools Config +CFLAGS = -Werror + +LDFLAGS = -Wall \ + -lc + +# Recursive Wild Card +rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) + +# Source Files +C_SRC = $(call rwildcard,$(SOURCE),*.c) + +OBJS = $(patsubst $(SOURCE)/%.c,$(LIB)/%_c.o,$(C_SRC)) + +# Target +$(LIB)/%_c.o: $(SOURCE)/%.c + @ mkdir -m 777 -p $(@D) + @ $(call cyan,"$(subst ../,,$^)") + @ $(CC) $(CFLAGS) -c $^ -o $@ + +link: + @ mkdir -m 777 -p $(BIN) + $(CC) $(LDFLAGS) -o $(BIN)/shutdown $(OBJS) + +build: $(OBJS) link diff --git a/sources/core/kernel/source/arch/amd64/arch.c b/sources/core/kernel/source/arch/amd64/arch.c index eb5e19ccf..6d8ba2a01 100644 --- a/sources/core/kernel/source/arch/amd64/arch.c +++ b/sources/core/kernel/source/arch/amd64/arch.c @@ -4,6 +4,7 @@ #include #include +#include ARCH_INCLUDE(io.h) #include ARCH_INCLUDE(idt.h) #include ARCH_INCLUDE(gdt.h) #include ARCH_INCLUDE(cpu.h) @@ -82,11 +83,19 @@ noreturn void arch_idle(void) { } noreturn void arch_reboot(void) { - // todo + uint8_t val = 0x02; + while(val & 0x02){ + val = io_read8(0x64); + } + + io_write8(0x64, 0xFE); arch_idle(); } noreturn void arch_shutdown(void) { - // todo + io_write16(0xB004, 0x2000); + io_write16(0x604, 0x2000); + io_write16(0x4004, 0x3400); + io_write16(0x600, 0x34); arch_idle(); } diff --git a/sources/core/modules/devfb/source/interface.c b/sources/core/modules/devfb/source/interface.c index ed68d406f..ae456e0b6 100644 --- a/sources/core/modules/devfb/source/interface.c +++ b/sources/core/modules/devfb/source/interface.c @@ -157,7 +157,7 @@ int fb_interface_seek(off_t offset, int whence, off_t* new_offset, kernel_file_t } int fb_interface_ioctl(uint32_t request, void* arg, int* result, kernel_file_t* file){ - switch (request){ + switch(request){ case FBIOGET_FSCREENINFO:{ if(vmm_check_memory(vmm_get_current_space(), (memory_range_t){arg, sizeof(struct fb_fix_screeninfo)})){ return EINVAL; diff --git a/sources/core/modules/devpower/source/interface.c b/sources/core/modules/devpower/source/interface.c new file mode 100644 index 000000000..3f65db925 --- /dev/null +++ b/sources/core/modules/devpower/source/interface.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include ARCH_INCLUDE(impl/arch.h) + +int power_interface_write(void* buffer, size_t size, size_t* bytes_write, kernel_file_t* file){ + *bytes_write = size; + return 0; +} + +int power_interface_read(void* buffer, size_t size, size_t* bytes_read, struct kernel_file_t* file){ + *bytes_read = size; + return 0; +} + +int power_interface_seek(off_t offset, int whence, off_t* new_offset, kernel_file_t* file){ + return 0; +} + +int power_interface_ioctl(uint32_t request, void* arg, int* result, kernel_file_t* file){ + switch(request){ + case 0:{ + arch_shutdown(); + break; + } + case 1:{ + arch_reboot(); + break; + } + default:{ + return EINVAL; + } + } + + return 0; +} + +int power_interface_stat(int flags, struct stat* statbuf, kernel_file_t* file){ + memset(statbuf, 0, sizeof(struct stat)); + statbuf->st_mode = S_IFIFO; + return 0; +} + +int power_interface_close(kernel_file_t* file){ + free(file); + return 0; +} + +int power_interface_get_event(kernel_file_t* file, short event, short* revent){ + *revent = (event & (POLLIN | POLLOUT)); + + int event_count = 0; + if(event & POLLIN){ + event_count++; + } + if(event & POLLOUT){ + event_count++; + } + + return event_count; +} + +kernel_file_t* power_interface_open(struct fs_t* ctx, const char* path, int flags, mode_t mode, int* error){ + kernel_file_t* file = malloc(sizeof(kernel_file_t)); + + file->fs_ctx = ctx; + file->seek_position = 0; + file->file_size_initial = 0; + file->internal_data = NULL; + + file->read = power_interface_read; + file->write = power_interface_write; + file->seek = power_interface_seek; + file->ioctl = power_interface_ioctl; + file->stat = power_interface_stat; + file->close = power_interface_close; + file->get_event = power_interface_get_event; + + return file; +} + + +void interface_init(void){ + devfs_add_dev("power", &power_interface_open); +} \ No newline at end of file diff --git a/sources/core/modules/devpower/source/main.c b/sources/core/modules/devpower/source/main.c new file mode 100644 index 000000000..33ebc6962 --- /dev/null +++ b/sources/core/modules/devpower/source/main.c @@ -0,0 +1,29 @@ +#include +#include +#include + +#define MODULE_NAME "devpower" + +#include + +int init(int argc, char* args[]){ + log_printf("[module/"MODULE_NAME"] loading start\n"); + + assert(modules_request_dependency(MODULE_TYPE_DEVFS) == 0); + + interface_init(); + + log_printf("[module/"MODULE_NAME"] loading end\n"); + return 0; +} + +int fini(void){ + return 0; +} + +module_metadata_t module_metadata = { + &init, + &fini, + MODULE_TYPE_UNDEFINE, + MODULE_NAME +}; diff --git a/sources/core/modules/devpower/target/amd64/.gitignore b/sources/core/modules/devpower/target/amd64/.gitignore new file mode 100644 index 000000000..7a6439a78 --- /dev/null +++ b/sources/core/modules/devpower/target/amd64/.gitignore @@ -0,0 +1,3 @@ +**/disk +**/bin +**/lib diff --git a/sources/core/modules/devpower/target/amd64/makefile b/sources/core/modules/devpower/target/amd64/makefile new file mode 100644 index 000000000..b90f79889 --- /dev/null +++ b/sources/core/modules/devpower/target/amd64/makefile @@ -0,0 +1,40 @@ +cyan = /bin/echo -e "\x1b[36m\#\# $1\x1b[0m" + +# Project Root +override HOME = ../.. + +# Project Resources +SOURCE = $(HOME)/source +KERNEL_SOURCE = $(HOME)/../../kernel/source +BIN = bin/system/modules + +# Tools Config +CFLAGS = -I$(SOURCE) \ + -I$(KERNEL_SOURCE) \ + -ffreestanding \ + -nostdlib \ + -fno-stack-protector \ + -mno-avx \ + -mno-sse \ + -mno-mmx \ + -mno-3dnow \ + -mno-red-zone \ + -g \ + -fshort-wchar \ + -Werror \ + -Wstrict-prototypes \ + -static \ + -mcmodel=large + + +# Recursive Wild Card +rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) + +# Source Files +C_SRC = $(filter-out $(SOURCE)/main.c,$(call rwildcard,$(SOURCE),*.c)) + +# Target +build: + @ mkdir -m 777 -p $(BIN) + @ $(CC) $(CFLAGS) -c $(SOURCE)/main.c -o $(BIN)/devpower.ksys + diff --git a/target/initrd/system/starter/modules.cfg b/target/initrd/system/starter/modules.cfg index 3911895a9..ac06ab04a 100644 --- a/target/initrd/system/starter/modules.cfg +++ b/target/initrd/system/starter/modules.cfg @@ -9,6 +9,7 @@ MODULE_PATH=/initrd/system/modules/hid.ksys MODULE_PATH=/initrd/system/modules/ps2.ksys MODULE_PATH=/initrd/system/modules/devfs.ksys MODULE_PATH=/initrd/system/modules/devfb.ksys +MODULE_PATH=/initrd/system/modules/devpower.ksys MODULE_PATH=/initrd/system/modules/devconsole.ksys MODULE_PATH=/initrd/system/modules/net.ksys MODULE_PATH=/initrd/system/modules/e1000.ksys \ No newline at end of file diff --git a/target/limine.cfg b/target/limine.cfg index fd8b66347..fc81ff6cb 100644 --- a/target/limine.cfg +++ b/target/limine.cfg @@ -18,6 +18,7 @@ TIMEOUT=0 MODULE_PATH=boot:///system/modules/e1000.ksys MODULE_PATH=boot:///system/modules/devfs.ksys MODULE_PATH=boot:///system/modules/devfb.ksys + MODULE_PATH=boot:///system/modules/devpower.ksys MODULE_PATH=boot:///system/starter/modules.cfg MODULE_PATH=boot:///system/modules/storage.ksys MODULE_PATH=boot:///system/default/scancode.scd diff --git a/target/makefile b/target/makefile index acfff516d..bd9de6d16 100644 --- a/target/makefile +++ b/target/makefile @@ -33,9 +33,7 @@ LIAMD_QEMU_FLAGS = \ -serial stdio \ -device e1000e,netdev=net0 \ -netdev user,id=net0,hostfwd=tcp::5001-:5000,hostfwd=udp::5001-:5000 \ - -object filter-dump,id=f1,netdev=net0,file=dump.bin \ - -no-reboot \ - -no-shutdown + -object filter-dump,id=f1,netdev=net0,file=dump.bin liamd/run: liamd/build ovmf-amd64 sudo qemu-system-x86_64 $(LIAMD_QEMU_FLAGS) -enable-kvm