Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include common.mk

OS := $(shell uname)
FS_DIRS := fs/redos/user
FS_DIRS := fs/redos/system

ifeq ($(OS),Darwin)
BOOTFS := /Volumes/bootfs
Expand All @@ -11,7 +11,7 @@ endif

.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install

all: kshared modules kernel shared user utils bins
all: kshared modules kernel shared user tools
@echo "Build complete."
./createfs

Expand All @@ -30,11 +30,8 @@ user: shared prepare-fs
kernel: kshared modules
$(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) QEMU=$(QEMU) TEST=$(TEST)

utils: shared prepare-fs
$(MAKE) -C utils

bins: shared prepare-fs
$(MAKE) -C bin
tools: shared prepare-fs
$(MAKE) -C tools

test:
$(MAKE) $(MODE) QEMU=true TEST=true all
Expand All @@ -44,8 +41,7 @@ clean:
$(MAKE) -C shared $@
$(MAKE) -C user $@
$(MAKE) -C kernel $@
$(MAKE) -C utils $@
$(MAKE) -C bin $@
$(MAKE) -C tools $@
$(MAKE) -C modules $@
@echo "removing images"
$(RM) kernel.img kernel.elf dump
Expand All @@ -68,7 +64,6 @@ debug:
dump:
$(ARCH)objdump -D kernel.elf > dump
$(MAKE) -C user $@
$(MAKE) -C utils $@

install:
$(MAKE) clean
Expand Down
19 changes: 0 additions & 19 deletions bin/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion kernel/bin/bin_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ process_t* execute(const char* prog_name, int argc, const char* argv[], uint32_t
char *full_name = (strend_case(prog_name, ".elf", true) == 0) ? string_from_literal(prog_name).data : strcat_new(prog_name, ".elf");
if (full_name) {
char pathbuf[1024] = {};
size_t pathlen = string_format_buf(pathbuf, sizeof(pathbuf), "/boot/redos/bin/%s",full_name);
size_t pathlen = string_format_buf(pathbuf, sizeof(pathbuf), "/boot/redos/tools/%s",full_name);
process_t *proc = 0;
if (pathlen < sizeof(pathbuf) - 1) proc = load_elf_process_path(prog_name, 0, pathbuf, argc, argv);
release(full_name);
Expand Down
14 changes: 14 additions & 0 deletions kernel/dev/module_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include "memory/page_allocator.h"
#include "syscalls/syscalls.h"
#include "files/dir_list.h"
#include "exceptions/exception_handler.h"

//TODO: use hashmaps
linked_list_t* modules;
void *mod_page = 0;

#define MODULE_STRICT

void* mod_alloc(size_t size){
if (!mod_page) mod_page = page_alloc(PAGE_SIZE);
return allocate(mod_page, size, page_alloc);
Expand All @@ -23,6 +26,17 @@ bool load_module(system_module *module){
if (strcmp(module->mount,"/console")) kprintf("[MODULE] module not initialized due to missing initializer");//TODO: can we make printf silently fail so logging becomes easier?
return false;
}
if (!module->version){
string format = string_format("Version number cannot be null for module /%s",module->mount);
if (strcmp(module->mount,"/console"))
#ifdef MODULE_STRICT
panic(format.data,0);
#else
kprintf(format.data);
#endif
string_free(format);
return false;
}
if (!module->init()){
if (strcmp(module->mount,"/console")) kprintf("[MODULE] failed to load module %s. Init failed",module->name);
return false;
Expand Down
1 change: 0 additions & 1 deletion kernel/exceptions/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ void irq_restore(irq_flags_t flags){

void irq_el1_handler() {
save_return_address_interrupt();
mmu_ttbr0_disable_user();
syscall_depth++;
uint32_t irq;
if (RPI_BOARD == 3){
Expand Down
4 changes: 4 additions & 0 deletions kernel/input/input_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ void sys_unset_focus(bool close){
}
}

u16 sys_get_focused_pid(){
return focused_proc ? focused_proc->id : 0;
}

void sys_set_secure(bool secure){
secure_mode = secure;
}
Expand Down
1 change: 1 addition & 0 deletions kernel/input/input_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ uint16_t sys_subscribe_shortcut_current(keypress kp);
void sys_set_focus(int pid);
void sys_focus_current();
void sys_unset_focus(bool close);
u16 sys_get_focused_pid();

///A process can request for shortcuts and others to be disabled
void sys_set_secure(bool secure);
Expand Down
3 changes: 3 additions & 0 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "dtb.h"
#include "filesystem/tmp/tmp_fs.h"
#include "std/memory.h"
#include "utils/utils.h"

extern char __bss_start[];
extern char __bss_end[];
Expand Down Expand Up @@ -110,6 +111,8 @@ void kernel_main(uint64_t board_type, uint64_t dtb_pa) {

load_module(&scheduler_module);

load_util_mods();

start_scheduler();

panic("Kernel did not activate any process", 0);
Expand Down
20 changes: 20 additions & 0 deletions kernel/kernel_processes/windows/dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ u16 mode_shortcuts[mode_count];
u16 sid_g = 0;
u16 sid_f = 0;
u16 newwin_s = 0;
u16 copy_s = 0;
u16 paste_s = 0;

static dos_mode mode;
static draw_ctx *dos_ctx;
Expand Down Expand Up @@ -154,6 +156,16 @@ void setup_shortcuts(){
.keys = { KEY_ENTER, 0, 0, 0, 0, 0}
});

// copy_s = sys_subscribe_shortcut_current((keypress){
// .modifier = KEY_MOD_LMETA,
// .keys = { KEY_C, 0, 0, 0, 0, 0}
// });

// paste_s = sys_subscribe_shortcut_current((keypress){
// .modifier = KEY_MOD_LMETA,
// .keys = { KEY_V, 0, 0, 0, 0, 0}
// });

for (int i = 0; i < 4; i++)
move_shortcuts[i] = sys_subscribe_shortcut_current((keypress){
.modifier = KEY_MOD_LMETA,
Expand All @@ -178,6 +190,14 @@ void check_shortcuts(){
}
if (sys_shortcut_triggered_current(newwin_s))
new_managed_window();
// if (sys_shortcut_triggered_current(copy_s)){
// print("Copy");
// //TODO: How do normal applications know they're supposed to copy/paste?
// }
// if (sys_shortcut_triggered_current(paste_s)){
// print("Paste");
// //TODO: How do normal applications know they're supposed to copy/paste?
// }
for (int i = 0; i < 4; i++)
if (sys_shortcut_triggered_current(move_shortcuts[i])){
int sign = i % 2 == 0 ? -1 : 1;
Expand Down
12 changes: 3 additions & 9 deletions kernel/memory/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern char __kstack_top[];
static uintptr_t *kernel_ttbr0;
static uintptr_t *kernel_ttbr1;
static uint64_t kernel_ttbr0_hw;
static bool ttbr0_user_on;

static bool mmu_verbose;
static inline void mmu_flush_icache();
Expand Down Expand Up @@ -792,21 +791,16 @@ void debug_mmu_address(uint64_t va){
}

void mmu_ttbr0_disable_user() {
asm volatile("msr ttbr0_el1, %0" :: "r"((uint64_t)kernel_ttbr0_hw));
asm volatile("dsb ish\n\tisb" ::: "memory");
ttbr0_user_on = false;
// asm volatile("msr ttbr0_el1, %0" :: "r"((uint64_t)kernel_ttbr0_hw));
// asm volatile("dsb ish\n\tisb" ::: "memory");
// ttbr0_user_on = false;
}

void mmu_ttbr0_enable_user() {
uint64_t hw = kernel_ttbr0_hw;
if (pttbr && pttbr != (uintptr_t*)kernel_ttbr0) hw = pttbr_hw;
asm volatile("msr ttbr0_el1, %0" :: "r"(hw));
asm volatile("dsb ish\n\tisb" ::: "memory");
ttbr0_user_on = pttbr && pttbr != (uintptr_t*)kernel_ttbr0;
}

bool mmu_ttbr0_user_enabled() {
return ttbr0_user_on;
}

void mmu_swap_ttbr(mm_struct *mm){
Expand Down
1 change: 0 additions & 1 deletion kernel/memory/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void mmu_enable_verbose();
void mmu_swap_ttbr(mm_struct *mm);
void mmu_ttbr0_disable_user();
void mmu_ttbr0_enable_user();
bool mmu_ttbr0_user_enabled();
void mmu_flush_asid(uint16_t asid);
void mmu_asid_ensure(mm_struct *mm);
void mmu_asid_release(mm_struct *mm);
Expand Down
4 changes: 2 additions & 2 deletions kernel/process/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ void update_sleep_timer() {
}

void switch_proc(ProcSwitchReason reason) {
if (mmu_ttbr0_user_enabled()) panic("switch_proc with user ttbr0 active", current_proc ? current_proc->id : 0);
if (proc_count == 0)
panic("No processes active", 0);
process_t*prev = current_proc, *next_proc = 0;
process_t *prev = current_proc, *next_proc = 0;
if (prev && prev->state == RUNNING) {
if (prev == idle_proc) prev->state = BLOCKED;
else ready_process(prev);
Expand Down Expand Up @@ -765,6 +764,7 @@ size_t readdir_proc(const char *path, void *buf, size_t size, file_offset *offse
irq_restore(irq);
return res;
}
irq_restore(irq);
return false;
}

Expand Down
Loading
Loading