Skip to content

Commit

Permalink
Add shutdown and reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
konect-V committed Sep 22, 2024
1 parent 6ece291 commit f96995b
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 17 deletions.
52 changes: 41 additions & 11 deletions bootstrap/sys-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions bootstrap/sys-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions sources/core/apps/desktop/icons/icons.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Binary file added sources/core/apps/desktop/icons/reboot.tga
Binary file not shown.
Binary file added sources/core/apps/desktop/icons/shutdown.tga
Binary file not shown.
29 changes: 29 additions & 0 deletions sources/core/apps/reboot/source/core/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

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;
}
3 changes: 3 additions & 0 deletions sources/core/apps/reboot/target/amd64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/bin
**/lib
**/tar
39 changes: 39 additions & 0 deletions sources/core/apps/reboot/target/amd64/makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions sources/core/apps/shutdown/source/core/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

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;
}
3 changes: 3 additions & 0 deletions sources/core/apps/shutdown/target/amd64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/bin
**/lib
**/tar
39 changes: 39 additions & 0 deletions sources/core/apps/shutdown/target/amd64/makefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions sources/core/kernel/source/arch/amd64/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <global/hw_interrupt.h>

#include <arch/include.h>
#include ARCH_INCLUDE(io.h)
#include ARCH_INCLUDE(idt.h)
#include ARCH_INCLUDE(gdt.h)
#include ARCH_INCLUDE(cpu.h)
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion sources/core/modules/devfb/source/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f96995b

Please sign in to comment.