wip: IPC and Runtime

This commit is contained in:
karina
2026-05-03 21:57:20 +04:00
parent 5f343c991b
commit 39b2af7626
25 changed files with 371 additions and 66 deletions
+3 -31
View File
@@ -4,44 +4,16 @@
cmake_minimum_required(VERSION 3.20)
project(ksOS_init LANGUAGES C ASM)
include("${CMAKE_CURRENT_SOURCE_DIR}/../../Common/ksOS_SDK.cmake")
file(GLOB_RECURSE INIT_SOURCES CMAKE_CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.S
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.c
)
add_executable(init ${INIT_SOURCES})
add_ksos_executable(Init ${INIT_SOURCES})
target_include_directories(init PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Source
${CMAKE_CURRENT_SOURCE_DIR}/../../Common
)
target_compile_options(init PRIVATE
$<$<COMPILE_LANGUAGE:C>:
-std=c23
-fno-stack-protector
-fno-builtin
-Wall
-Wextra
>
-ffreestanding
-g
-mgeneral-regs-only
)
target_link_options(init PRIVATE
-nostdlib
-static
-no-pie
-T "${CMAKE_CURRENT_SOURCE_DIR}/../../Common/linker.ld"
-Ttext=0x400000
-e _start
-z max-page-size=0x1000
--no-dynamic-linker
)
set_target_properties(init PROPERTIES
set_target_properties(Init PROPERTIES
OUTPUT_NAME "Init"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
+5 -5
View File
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
void main(void) {
__asm__ volatile(
"svc #0\n"
"b .\n"
);
#include <ksOS/Syscall.h>
int main(void) {
SysSend(1, 0xa0a0a0a0a);
while (1) {}
}
+19
View File
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (c) 2026 0xKSor
cmake_minimum_required(VERSION 3.20)
project(ksOS_test LANGUAGES C ASM)
include("${CMAKE_CURRENT_SOURCE_DIR}/../../Common/ksOS_SDK.cmake")
file(GLOB_RECURSE INIT_SOURCES CMAKE_CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.S
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.c
)
add_ksos_executable(Init ${INIT_SOURCES})
set_target_properties(Init PROPERTIES
OUTPUT_NAME "Test"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
+9
View File
@@ -0,0 +1,9 @@
#include <ksOS/Syscall.h>
int main() {
IPCMessage message = SysRecive();
if (message.data == 0xa0a0a0a0a) {
Sys228();
}
}
+17
View File
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.20)
project(libksOS LANGUAGES C ASM)
file(GLOB_RECURSE LIB_SOURCES CMAKE_CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/*.c
)
add_library(ksOS STATIC ${LIB_SOURCES})
target_include_directories(ksOS PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/Include
)
target_compile_options(ksOS PRIVATE
-std=c23 -fno-stack-protector -fno-builtin -Wall -Wextra
)
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
#pragma once
#include <ksOS/Types.h>
enum {
kSyscallSend = 1,
kSyscallReceive,
};
typedef struct IPCMessage {
UInt64 senderID;
UInt64 data;
} IPCMessage;
static inline UInt64 SysSend(UInt64 handleID, UInt64 data) {
register UInt64 x8 __asm__("x8") = kSyscallSend;
register UInt64 x0 __asm__("x0") = handleID;
register UInt64 x1 __asm__("x1") = data;
__asm__ volatile(
"svc #0\n"
: "+r" (x0)
: "r" (x1), "r" (x8)
: "memory", "cc"
);
return x0;
}
static inline IPCMessage SysRecive(void) {
register UInt64 x8 __asm__("x8") = kSyscallReceive;
register UInt64 x0 __asm__("x0");
register UInt64 x1 __asm__("x1");
__asm__ volatile(
"svc #0\n"
: "=r" (x0), "=r" (x1)
: "r" (x8)
: "memory", "cc"
);
struct IPCMessage msg = { x0, x1 };
return msg;
}
static inline void Sys228(void) {
register UInt64 x8 __asm__("x8") = 228;
__asm__ volatile(
"svc #0\n"
:
: "r" (x8)
: "memory", "cc"
);
}
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
#pragma once
#if defined(NDEBUG) || defined(__OPTIMIZE__)
#define IS_RELEASE 1
#else
#define IS_RELEASE 0
#endif
typedef unsigned char UInt8;
typedef unsigned short UInt16;
typedef unsigned int UInt32;
typedef unsigned long long UInt64;
typedef unsigned long long UInt;
typedef void* Pointer;
typedef UInt Address;
typedef UInt32 Address32;
typedef UInt8* BytePointer;
typedef UInt8* MemoryPointer;
typedef signed char Int8;
typedef signed short Int16;
typedef signed int Int32;
typedef signed long long Int64;
typedef int Int;
typedef UInt64 Size;
typedef char ASCII;
typedef _Bool Boolean;
+2
View File
@@ -0,0 +1,2 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
@@ -4,14 +4,9 @@
.section .text.entry, "ax"
.global _start
_start:
// Set up stack pointer (8KB stack)
adrp x0, stack_top
add sp, x0, :lo12:stack_top
// Jump to C main
bl main
// If main returns, loop forever
b .
.section .bss, "aw", @nobits