This commit is contained in:
parent
29bd8a69fa
commit
7e377ef712
16
apps/app.c
16
apps/app.c
@ -4,24 +4,18 @@
|
||||
|
||||
void bye()
|
||||
{
|
||||
console_print("byeee!\n");
|
||||
printf("byeee!\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
atexit(bye);
|
||||
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), "Welcome to %s!\n", "Luna");
|
||||
|
||||
console_print(buffer);
|
||||
printf("Welcome to %s!\n", "Luna");
|
||||
|
||||
time_t now = time(NULL);
|
||||
snprintf(buffer, sizeof(buffer), "Realtime clock: %ld s\n", now);
|
||||
printf("Realtime clock: %ld s\n", now);
|
||||
|
||||
console_print(buffer);
|
||||
for (int i = 0; i < atoi("8"); i++) { console_write(".", 1); }
|
||||
|
||||
for (int i = 0; i < atoi("8"); i++) { console_print("."); }
|
||||
|
||||
console_print("\n");
|
||||
console_write("\n", 1);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ set(SOURCES
|
||||
src/thread/Scheduler.cpp
|
||||
src/sys/Syscall.cpp
|
||||
src/sys/exit.cpp
|
||||
src/sys/console_print.cpp
|
||||
src/sys/console_write.cpp
|
||||
src/sys/clock_gettime.cpp
|
||||
src/InitRD.cpp
|
||||
src/ELF.cpp
|
||||
|
@ -1,12 +0,0 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "video/TextConsole.h"
|
||||
|
||||
Result<u64> sys_console_print(Registers*, SyscallArgs args)
|
||||
{
|
||||
if (!MemoryManager::validate_userspace_string(args[0])) return err(EFAULT);
|
||||
|
||||
TextConsole::print((char*)args[0]);
|
||||
|
||||
return { 0 };
|
||||
}
|
15
kernel/src/sys/console_write.cpp
Normal file
15
kernel/src/sys/console_write.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "video/TextConsole.h"
|
||||
|
||||
Result<u64> sys_console_write(Registers*, SyscallArgs args)
|
||||
{
|
||||
char* ptr = (char*)args[0];
|
||||
usize size = (usize)args[1];
|
||||
|
||||
if (!MemoryManager::validate_user_read(ptr, size)) return err(EFAULT);
|
||||
|
||||
while (size--) { TextConsole::putchar(*ptr++); }
|
||||
|
||||
return { 0 };
|
||||
}
|
@ -49,8 +49,14 @@ extern "C"
|
||||
/* Write up to max bytes of formatted output into a buffer. */
|
||||
int vsnprintf(char*, size_t, const char*, va_list);
|
||||
|
||||
/* Write formatted output to standard output. */
|
||||
int printf(const char*, ...);
|
||||
|
||||
/* Write a string followed by a newline to standard output. */
|
||||
int puts(const char* s);
|
||||
|
||||
/* Output a message to the console. */
|
||||
int console_print(const char* msg);
|
||||
int console_write(const char* msg, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <bits/errno-return.h>
|
||||
#include <luna/Format.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -9,9 +10,9 @@ FILE* stderr = nullptr;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int console_print(const char* str)
|
||||
int console_write(const char* str, size_t size)
|
||||
{
|
||||
long rc = syscall(SYS_console_print, str);
|
||||
long rc = syscall(SYS_console_write, str, size);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
@ -48,4 +49,25 @@ extern "C"
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int printf(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
int rc = (int)pure_cstyle_format(
|
||||
format, [](char c, void*) { console_write(&c, 1); }, nullptr, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int puts(const char* s)
|
||||
{
|
||||
if (console_write(s, strlen(s)) < 0) return -1;
|
||||
if (console_write("\n", 1) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define enumerate_syscalls(_e) _e(exit) _e(console_print) _e(clock_gettime)
|
||||
#define enumerate_syscalls(_e) _e(exit) _e(console_write) _e(clock_gettime)
|
||||
|
||||
enum Syscalls
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user