Skip to content

Commit

Permalink
apps: Start implementing gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed Nov 30, 2023
1 parent 515358c commit add7444
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 12 deletions.
4 changes: 3 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
set(APPS
user_tty
init
gui
)

add_subdirectory(user_tty)
add_subdirectory(init)
add_subdirectory(gui)

set(APP_FILES ${APPS})
list(TRANSFORM APP_FILES PREPEND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/")
add_custom_target(copy_apps
DEPENDS ${APPS}
COMMAND cp ${APP_FILES} ${CMAKE_BINARY_DIR}/sysroot
USES_TERMINAL VERBATIM
)
add_dependencies(copy_apps ${APPS})
7 changes: 7 additions & 0 deletions apps/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project(gui)

set(CMAKE_C_STANDARD 23)

add_executable(gui main.c)

target_link_libraries(gui PRIVATE common)
5 changes: 5 additions & 0 deletions apps/gui/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "sys.h"

int main() {
sys_dprint("hello\n", sizeof("hello\n") - 1);
}
4 changes: 3 additions & 1 deletion apps/init/init.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "sys.h"

int main() {

Handle gui_handle;
int status = sys_create_process("posix_rootfs/gui", sizeof("posix_rootfs/gui") - 1, &gui_handle);
}
2 changes: 2 additions & 0 deletions image.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ find_program(GUESTMOUNT guestmount)

add_custom_command(OUTPUT initramfs.tar
COMMAND tar -cf initramfs.tar -C ${PROJECT_BINARY_DIR}/sysroot/ .
DEPENDS copy_apps
USES_TERMINAL VERBATIM
)

if(GUESTMOUNT)
Expand Down
11 changes: 7 additions & 4 deletions kernel/src/dev/fb.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "fb.h"
#include "assert.h"
#include "sys/utils.h"
#include "mem/vm.h"
#include "arch/cpu.h"
#include "mem/utils.h"
#include "assert.h"
#include "fbcon.h"
#include "mem/page.h"
#include "mem/utils.h"
#include "mem/vm.h"
#include "sys/utils.h"

int fbdev_devmsg(FbDev* self, DevMsgFb msg, __user void* data) {
switch (msg) {
Expand Down Expand Up @@ -42,6 +43,8 @@ int fbdev_devmsg(FbDev* self, DevMsgFb msg, __user void* data) {
vm_user_dealloc(task->process, mem, ALIGNUP(size, PAGE_SIZE) / PAGE_SIZE, true);
return ERR_FAULT;
}

default_fblog_deinit();
return 0;
}
default:
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/dev/fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ void fbcon_init(FbDev* fb, const void* font) {
FBLOG.font = (const PsfFont*) font;
log_register_sink(&FBLOG.common, false);
}

void default_fblog_deinit() {
log_unregister_sink(&FBLOG.common);
}
3 changes: 2 additions & 1 deletion kernel/src/dev/fbcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

typedef struct FbDev FbDev;

void fbcon_init(FbDev* fb, const void* font);
void fbcon_init(FbDev* fb, const void* font);
void default_fblog_deinit();
2 changes: 1 addition & 1 deletion kernel/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static int stderr_vnode_write(VNode* self, const void* data, usize off, usize si
assert(fd_table_insert(&init_process->fd_table, stderr_vnode) == 2);

ACTIVE_INPUT_TASK = init_task;
ThreadHandle* h = kmalloc(sizeof(ThreadHandle));
ThreadHandle* h = kcalloc(sizeof(ThreadHandle));
assert(h);
h->refcount = 1;
h->task = init_task;
Expand Down
17 changes: 14 additions & 3 deletions kernel/src/sys/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle*
}

const char* process_name = buf + path_len - 1;
for (; process_name > buf && *process_name != '/'; --process_name);
for (; process_name > buf && process_name[-1] != '/'; --process_name);

Task* thread = arch_create_user_task(process, process_name, NULL, NULL);
kfree(buf, path_len + 1);
Expand All @@ -336,14 +336,24 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle*
void (*user_fn)(void*) = (void (*)(void*)) res.entry;
arch_set_user_task_fn(thread, user_fn);

ProcessHandle* h = kmalloc(sizeof(ProcessHandle));
ProcessHandle* h = kcalloc(sizeof(ProcessHandle));
if (!h) {
arch_destroy_task(thread);
return ERR_NO_MEM;
}

ThreadHandle* thread_h = kcalloc(sizeof(ThreadHandle));
if (!thread_h) {
arch_destroy_task(thread);
kfree(h, sizeof(ProcessHandle));
return ERR_NO_MEM;
}
thread_h->refcount = 1;
thread_h->task = thread;
thread_h->exited = false;

h->process = process;
h->exited = false;
memset(&h->lock, 0, sizeof(Mutex));
Task* task = arch_get_cur_task();
Handle handle = handle_tab_insert(&task->process->handle_table, h, HANDLE_TYPE_PROCESS);

Expand All @@ -355,6 +365,7 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle*
}

process_add_thread(process, thread);
thread->tid = handle_tab_insert(&process->handle_table, thread_h, HANDLE_TYPE_THREAD);

Ipl old = arch_ipl_set(IPL_CRITICAL);
sched_queue_task(thread);
Expand Down
2 changes: 1 addition & 1 deletion libs/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ add_library(common STATIC
sys.c
)

target_include_directories(common PUBLIC ${CMAKE_SOURCE_DIR}/kernel/include)
target_include_directories(common PUBLIC ${CMAKE_SOURCE_DIR}/kernel/include .)
target_compile_options(common PUBLIC -fno-stack-protector -Wall -Wextra)
target_link_options(common PUBLIC -nostdlib -Wl,--fatal-warnings)

0 comments on commit add7444

Please sign in to comment.