mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[kernel] Make stdout channel available to processes
The "fake" stdout channel is now being passed in the new j6_process_init structure to processes, and nulldrv now uses it to print a message to the console.
This commit is contained in:
@@ -7,11 +7,14 @@
|
|||||||
|
|
||||||
#include <j6libc/syscalls.h>
|
#include <j6libc/syscalls.h>
|
||||||
|
|
||||||
const char message[] = "Hello! This is a message being sent over a channel!";
|
const char message[] = "Hello! This is a message being sent over a channel!\n";
|
||||||
char inbuf[1024];
|
char inbuf[1024];
|
||||||
j6_handle_t chan = j6_handle_invalid;
|
j6_handle_t chan = j6_handle_invalid;
|
||||||
|
|
||||||
|
j6_process_init *init = nullptr;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
void _init_libc(j6_process_init *);
|
||||||
int main(int, const char **);
|
int main(int, const char **);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +43,12 @@ thread_proc()
|
|||||||
_syscall_thread_exit(0);
|
_syscall_thread_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_init_libc(j6_process_init *i)
|
||||||
|
{
|
||||||
|
init = i;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char **argv)
|
main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
@@ -52,6 +61,11 @@ main(int argc, const char **argv)
|
|||||||
if (result != j6_status_ok)
|
if (result != j6_status_ok)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
size_t size = sizeof(message);
|
||||||
|
result = _syscall_channel_send(init->output, &size, (void*)message);
|
||||||
|
if (result != j6_status_ok)
|
||||||
|
return result;
|
||||||
|
|
||||||
_syscall_system_log("main thread created channel");
|
_syscall_system_log("main thread created channel");
|
||||||
|
|
||||||
result = _syscall_thread_create(reinterpret_cast<void*>(&thread_proc), &child);
|
result = _syscall_thread_create(reinterpret_cast<void*>(&thread_proc), &child);
|
||||||
|
|||||||
@@ -3,19 +3,22 @@ mymessage:
|
|||||||
resq 1024
|
resq 1024
|
||||||
|
|
||||||
extern main
|
extern main
|
||||||
|
extern _init_libc
|
||||||
extern exit
|
extern exit
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
|
|
||||||
global _start
|
global _start
|
||||||
_start:
|
_start:
|
||||||
xor rbp, rbp ; Sentinel rbp
|
|
||||||
push rbp
|
|
||||||
push rbp
|
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|
||||||
|
mov rdi, rsp
|
||||||
|
sub rdi, 8
|
||||||
|
call _init_libc
|
||||||
|
|
||||||
mov rdi, 0
|
mov rdi, 0
|
||||||
mov rsi, 0
|
mov rsi, 0
|
||||||
|
|
||||||
call main
|
call main
|
||||||
|
|
||||||
mov rdi, rax
|
mov rdi, rax
|
||||||
|
|||||||
@@ -20,3 +20,10 @@ typedef uint64_t j6_signal_t;
|
|||||||
typedef uint64_t j6_rights_t;
|
typedef uint64_t j6_rights_t;
|
||||||
|
|
||||||
#define j6_handle_invalid 0xffffffff
|
#define j6_handle_invalid 0xffffffff
|
||||||
|
|
||||||
|
/// A process' initial data structure for communicating with the system
|
||||||
|
struct j6_process_init
|
||||||
|
{
|
||||||
|
j6_handle_t input;
|
||||||
|
j6_handle_t output;
|
||||||
|
};
|
||||||
|
|||||||
@@ -261,11 +261,16 @@ console::set_color(uint8_t fg, uint8_t bg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
size_t
|
||||||
console::puts(const char *message)
|
console::puts(const char *message)
|
||||||
{
|
{
|
||||||
while (message && *message)
|
size_t n = 0;
|
||||||
|
while (message && *message) {
|
||||||
|
n++;
|
||||||
putc(*message++);
|
putc(*message++);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
void set_color(uint8_t fg = 7, uint8_t bg = 0);
|
void set_color(uint8_t fg = 7, uint8_t bg = 0);
|
||||||
|
|
||||||
void putc(char c);
|
void putc(char c);
|
||||||
void puts(const char *message);
|
size_t puts(const char *message);
|
||||||
void vprintf(const char *fmt, va_list args);
|
void vprintf(const char *fmt, va_list args);
|
||||||
|
|
||||||
inline void printf(const char *fmt, ...)
|
inline void printf(const char *fmt, ...)
|
||||||
|
|||||||
@@ -92,7 +92,13 @@ stdout_task()
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer[n] = 0;
|
buffer[n] = 0;
|
||||||
cons->puts(reinterpret_cast<const char *>(buffer));
|
const char *s = reinterpret_cast<const char *>(buffer);
|
||||||
|
|
||||||
|
while (n) {
|
||||||
|
size_t r = cons->puts(s);
|
||||||
|
n -= r + 1;
|
||||||
|
s += r + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +199,8 @@ kernel_main(args::header *header)
|
|||||||
syscall_enable();
|
syscall_enable();
|
||||||
scheduler *sched = new scheduler(devices.get_lapic());
|
scheduler *sched = new scheduler(devices.get_lapic());
|
||||||
|
|
||||||
|
std_out = new channel;
|
||||||
|
|
||||||
for (auto &ird : initrds) {
|
for (auto &ird : initrds) {
|
||||||
for (auto &f : ird.files()) {
|
for (auto &f : ird.files()) {
|
||||||
if (f.executable()) {
|
if (f.executable()) {
|
||||||
@@ -203,8 +211,6 @@ kernel_main(args::header *header)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std_out = new channel;
|
|
||||||
|
|
||||||
sched->create_kernel_task(logger_task, scheduler::max_priority-1, true);
|
sched->create_kernel_task(logger_task, scheduler::max_priority-1, true);
|
||||||
sched->create_kernel_task(stdout_task, scheduler::max_priority-1, true);
|
sched->create_kernel_task(stdout_task, scheduler::max_priority-1, true);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "kernel_memory.h"
|
#include "kernel_memory.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "msr.h"
|
#include "msr.h"
|
||||||
|
#include "objects/channel.h"
|
||||||
#include "objects/process.h"
|
#include "objects/process.h"
|
||||||
#include "page_manager.h"
|
#include "page_manager.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
#include "elf/elf.h"
|
#include "elf/elf.h"
|
||||||
#include "kutil/assert.h"
|
#include "kutil/assert.h"
|
||||||
|
|
||||||
|
|
||||||
scheduler *scheduler::s_instance = nullptr;
|
scheduler *scheduler::s_instance = nullptr;
|
||||||
|
|
||||||
const uint64_t rflags_noint = 0x002;
|
const uint64_t rflags_noint = 0x002;
|
||||||
@@ -69,6 +71,7 @@ load_process_image(const void *image_start, size_t bytes, TCB *tcb)
|
|||||||
page_manager *pager = page_manager::get();
|
page_manager *pager = page_manager::get();
|
||||||
|
|
||||||
thread *th = thread::from_tcb(tcb);
|
thread *th = thread::from_tcb(tcb);
|
||||||
|
process &proc = th->parent();
|
||||||
|
|
||||||
log::debug(logs::loader, "Loading task! ELF: %016lx [%d]", image_start, bytes);
|
log::debug(logs::loader, "Loading task! ELF: %016lx [%d]", image_start, bytes);
|
||||||
|
|
||||||
@@ -115,6 +118,16 @@ load_process_image(const void *image_start, size_t bytes, TCB *tcb)
|
|||||||
kutil::memcpy(dest, src, header->size);
|
kutil::memcpy(dest, src, header->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tcb->rsp3 -= 2 * sizeof(uint64_t);
|
||||||
|
uint64_t *sentinel = reinterpret_cast<uint64_t*>(tcb->rsp3);
|
||||||
|
sentinel[0] = sentinel[1] = 0;
|
||||||
|
|
||||||
|
tcb->rsp3 -= sizeof(j6_process_init);
|
||||||
|
j6_process_init *init = reinterpret_cast<j6_process_init*>(tcb->rsp3);
|
||||||
|
|
||||||
|
extern channel *std_out;
|
||||||
|
init->output = proc.add_handle(std_out);
|
||||||
|
|
||||||
th->clear_state(thread::state::loading);
|
th->clear_state(thread::state::loading);
|
||||||
|
|
||||||
uintptr_t entrypoint = image.entrypoint();
|
uintptr_t entrypoint = image.entrypoint();
|
||||||
|
|||||||
Reference in New Issue
Block a user