Skip to content

Commit

Permalink
m68k stuff, scheduler improvement, start of vix ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
theverygaming committed Jul 29, 2024
1 parent 8416ff6 commit c944fc8
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 17 deletions.
6 changes: 5 additions & 1 deletion kernel/abi/Kconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
config ENABLE_LINUX_ABI
config ENABLE_ABI_LINUX
default y
bool "Enable Linux ABI"

config ENABLE_ABI_VIX
default y
bool "Enable vix ABI"
2 changes: 1 addition & 1 deletion kernel/abi/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
obj-d += linux
obj-d += linux vix
2 changes: 1 addition & 1 deletion kernel/abi/linux/syscalls/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
obj-$(CONFIG_ENABLE_LINUX_ABI) += exit.ocpp write.ocpp read.ocpp sysinfo.ocpp
obj-$(CONFIG_ENABLE_ABI_LINUX) += exit.ocpp write.ocpp read.ocpp sysinfo.ocpp
1 change: 1 addition & 0 deletions kernel/abi/vix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-d += syscalls
1 change: 1 addition & 0 deletions kernel/abi/vix/syscalls/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-$(CONFIG_ENABLE_ABI_VIX) += exit.ocpp
10 changes: 10 additions & 0 deletions kernel/abi/vix/syscalls/exit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <abi/vix/calls.h>
#include <kprintf.h>
#include <sched.h>

__DEF_VIX_SYSCALL(sys_exit) {
int status = (int)sysarg0;
kprintf(KP_INFO, "PID %d dying status: %d\n", sched::mypid(), status);
sched::die();
return 0;
}
4 changes: 2 additions & 2 deletions kernel/arch/m68k/Makefile.arch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
override INT_CFLAGS += -march=68000 -fno-pie -ffreestanding -nostdinc -nostdlib -nostartfiles -fno-exceptions
override INT_CXXFLAGS += -march=68000 -fno-pie -ffreestanding -nostdinc -nostdlib -nostartfiles -fno-exceptions
override INT_CFLAGS += -march=68000 -fno-pie -ffreestanding -nostdinc -nostdlib -nostartfiles -fno-exceptions
override INT_CXXFLAGS += -march=68000 -fno-pie -ffreestanding -nostdinc -nostdlib -nostartfiles -fno-exceptions
override INT_LDFLAGS += -nostdlib

ifeq ($(CONFIG_ENABLE_FTRACE), y)
Expand Down
4 changes: 3 additions & 1 deletion kernel/arch/m68k/archinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ extern "C" uint8_t __bss_end;
extern "C" uint8_t __kernel_end;

static void mmio_putc(char c) {
*((volatile char *)0xfef00) = c;
//*((volatile uint16_t *)0x100000) = (uint16_t)c;
*((volatile uint32_t *)0x100000) = (uint32_t)c | ((uint32_t)c << 8) | ((uint32_t)c << 16) | ((uint32_t)c << 24);
//for(int i = 0; i < 6942; i++) {}
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions kernel/arch/m68k/startup.S
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
.fill 254, 4, (256*4) // ... all the other vectors point to loop_infinite

loop_infinite:
move.l #0xfef00, %a0
move.l #0x100000, %a0
move.b #'L', (%a0)
.L1:
jmp .L1

init:
move.w #0x2600, %sr // supervisor set, IPL 6
move.l #0xfef00, %a0
move.w #0x2700, %sr // supervisor set, IPL 7
move.l #0x100000, %a0
move.b #'S', (%a0)
bsr _kentry
jmp loop_infinite
2 changes: 0 additions & 2 deletions kernel/arch/xtensa/include/arch/common/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace sched {
}

#define SCHED_ARCH_HAS_CUSTOM_SWITCH
#define SCHED_ARCH_CUSTOM_SWITCH_YIELD_IGNORE_IF(task_prev, task_next) \
(memcmp(&task_prev->ctx, &task_next->ctx, sizeof(struct sched::xtensa_sched_ctx)))
#define SCHED_ARCH_CUSTOM_SWITCH_STRUCT_TASK_CTX_DEF struct sched::xtensa_sched_ctx ctx
#define SCHED_ARCH_CUSTOM_SWITCH(task_prev, task_next) sched_switch(&task_prev->ctx, &task_next->ctx)
#define SCHED_ARCH_CUSTOM_SWITCH_ENTRY(task_prev, task_next) \
Expand Down
13 changes: 13 additions & 0 deletions kernel/include/abi/abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include <config.h>

namespace abi {
enum class type {
#ifdef CONFIG_ENABLE_ABI_LINUX
LINUX,
#endif
#ifdef CONFIG_ENABLE_ABI_VIX
VIX,
#endif
};
}
16 changes: 16 additions & 0 deletions kernel/include/abi/vix/calls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <abi/vix/vix.h>

#define __DECL_VIX_SYSCALL(name) \
abi::vix::syscall_arg_t name(abi::vix::syscall_arg_t sysarg0, \
abi::vix::syscall_arg_t sysarg1, \
abi::vix::syscall_arg_t sysarg2, \
abi::vix::syscall_arg_t sysarg3, \
abi::vix::syscall_arg_t sysarg4, \
abi::vix::syscall_arg_t sysarg5)

#define __DEF_VIX_SYSCALL(name) __DECL_VIX_SYSCALL(abi::vix::name)

namespace abi::vix {
__DECL_VIX_SYSCALL(sys_exit);
}
8 changes: 8 additions & 0 deletions kernel/include/abi/vix/vix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include <types.h>

namespace abi::vix {
struct task {};
typedef uintptr_t syscall_arg_t;
typedef uintptr_t syscall_return_t;
}
10 changes: 10 additions & 0 deletions kernel/include/sched.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include <abi/abi.h>
#include <abi/linux/linux.h>
#include <abi/vix/vix.h>
#include <arch/common/cpu.h>
#include <arch/common/sched.h>
#include <forward_list>
Expand All @@ -22,7 +24,15 @@ namespace sched {

struct arch_task task_arch;

enum abi::type abi_type;

#ifdef CONFIG_ENABLE_ABI_LINUX
struct abi::linux::task task_linux;
#endif

#ifdef CONFIG_ENABLE_ABI_VIX
struct abi::vix::task task_vix;
#endif

// TLS
void *data;
Expand Down
6 changes: 1 addition & 5 deletions kernel/kernel/sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ void sched::yield() {
push_interrupt_disable();
struct sched::task *last = current;
current = get_next();
#ifndef SCHED_ARCH_HAS_CUSTOM_SWITCH
if (last->ctx == current->ctx) {
#else
if (SCHED_ARCH_CUSTOM_SWITCH_YIELD_IGNORE_IF(last, current)) {
#endif
if (last->pid == current->pid) {
pop_interrupt_disable();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/mm/pmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ static void populate_pmm_info() {
uintptr_t required_bytes = ALIGN_UP(get_memmap_required_space(&pm_n_areas, &pm_n_total_pages), ARCH_PAGE_SIZE);
const mm::mem_map_entry *entry = get_suitable_memmap_entry(required_bytes);
uintptr_t entry_phys_start = ALIGN_UP(entry->base, ARCH_PAGE_SIZE);
uintptr_t required_pages = required_bytes / ARCH_PAGE_SIZE;
pm_phys_addr = entry_phys_start;
#ifdef CONFIG_ARCH_HAS_PAGING
uintptr_t required_pages = required_bytes / ARCH_PAGE_SIZE;
void *vaddr = mm::vmm::kalloc(required_pages);
for (uintptr_t i = 0; i < required_pages; i++) {
uintptr_t virt = ((uintptr_t)vaddr) + (i * ARCH_PAGE_SIZE);
Expand Down

0 comments on commit c944fc8

Please sign in to comment.