Compare commits

..

No commits in common. "bab9600be5c7bb67fae6b988fd5fdbae9b710710" and "51f0bdff0e8c4f74cd91c4c5fc4e14f9cd95fc73" have entirely different histories.

10 changed files with 11 additions and 49 deletions

View File

@ -24,19 +24,18 @@ int main()
{ {
if (getpid() != 1) if (getpid() != 1)
{ {
fprintf(stderr, "error: init not running as PID 1.\n"); printf("error: init not running as PID 1.\n");
return 1; return 1;
} }
populate_devfs(); populate_devfs();
// Before this point, we don't even have an stdin, stdout and stderr. Set it up now so that child processes (and us) // Before this point, we don't even have an stdout and stderr. Set it up now so that child processes (and us) can
// can print stuff. // print stuff.
stdin = fopen("/dev/console", "r");
stdout = fopen("/dev/console", "w"); stdout = fopen("/dev/console", "w");
stderr = fopen("/dev/console", "w"); stderr = fopen("/dev/console", "w");
printf("init is running as PID %d\n", getpid()); fprintf(stderr, "init is running as PID %d\n", getpid());
pid_t ret = fork(); pid_t ret = fork();

View File

@ -4,11 +4,9 @@
#include "arch/Timer.h" #include "arch/Timer.h"
#include "arch/x86_64/CPU.h" #include "arch/x86_64/CPU.h"
#include "arch/x86_64/IO.h" #include "arch/x86_64/IO.h"
#include "fs/devices/ConsoleDevice.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "sys/Syscall.h" #include "sys/Syscall.h"
#include "thread/Scheduler.h" #include "thread/Scheduler.h"
#include "video/TextConsole.h"
#include <cpuid.h> #include <cpuid.h>
#include <luna/CString.h> #include <luna/CString.h>
#include <luna/CircularQueue.h> #include <luna/CircularQueue.h>
@ -126,11 +124,7 @@ void io_thread()
while (!scancode_queue.try_pop(scancode)) { kernel_sleep(10); } while (!scancode_queue.try_pop(scancode)) { kernel_sleep(10); }
char key; char key;
if (Keyboard::decode_scancode(scancode).try_set_value(key)) if (Keyboard::decode_scancode(scancode).try_set_value(key)) { kdbgln("Read key: %c", key); }
{
TextConsole::putchar(key);
ConsoleDevice::did_press_key(key);
}
} }
} }

View File

@ -1,26 +1,15 @@
#include "fs/devices/ConsoleDevice.h" #include "fs/devices/ConsoleDevice.h"
#include "video/TextConsole.h" #include "video/TextConsole.h"
#include <luna/Buffer.h>
#include <luna/CString.h>
static Buffer g_console_input;
Result<SharedPtr<Device>> ConsoleDevice::create() Result<SharedPtr<Device>> ConsoleDevice::create()
{ {
return (SharedPtr<Device>)TRY(make_shared<ConsoleDevice>()); return (SharedPtr<Device>)TRY(make_shared<ConsoleDevice>());
} }
Result<usize> ConsoleDevice::read(u8* buf, usize, usize length) const // FIXME: Read from the keyboard.
Result<usize> ConsoleDevice::read(u8*, usize, usize) const
{ {
if (length > g_console_input.size()) length = g_console_input.size(); return 0;
memcpy(buf, g_console_input.data(), length);
memmove(g_console_input.data(), g_console_input.data() + length, g_console_input.size() - length);
g_console_input.try_resize(g_console_input.size() - length).release_value();
return length;
} }
Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length) Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
@ -31,10 +20,5 @@ Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
bool ConsoleDevice::blocking() const bool ConsoleDevice::blocking() const
{ {
return g_console_input.size() == 0; return false;
}
void ConsoleDevice::did_press_key(char key)
{
*g_console_input.slice_at_end(1).value() = (u8)key;
} }

View File

@ -11,8 +11,6 @@ class ConsoleDevice : public Device
Result<usize> write(const u8*, usize, usize) override; Result<usize> write(const u8*, usize, usize) override;
static void did_press_key(char key);
bool blocking() const override; bool blocking() const override;
virtual ~ConsoleDevice() = default; virtual ~ConsoleDevice() = default;

View File

@ -13,9 +13,6 @@ extern "C"
/* Open a file path and return a file descriptor to it. */ /* Open a file path and return a file descriptor to it. */
int open(const char* path, int flags, ...); int open(const char* path, int flags, ...);
/* Create a file and return a file descriptor to it. */
int creat(const char* path, mode_t mode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -16,10 +16,8 @@ typedef struct
#define EOF -1 #define EOF -1
extern FILE* stdin;
extern FILE* stdout; extern FILE* stdout;
extern FILE* stderr; extern FILE* stderr;
#define stdin stdin
#define stdout stdout #define stdout stdout
#define stderr stderr #define stderr stderr

View File

@ -10,9 +10,8 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#define STDIN_FILENO 0 #define STDOUT_FILENO 0
#define STDOUT_FILENO 1 #define STDERR_FILENO 1
#define STDERR_FILENO 2
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -18,9 +18,4 @@ extern "C"
va_end(ap); va_end(ap);
__errno_return(rc, int); __errno_return(rc, int);
} }
int creat(const char* path, mode_t mode)
{
return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
} }

View File

@ -5,7 +5,6 @@ extern "C"
{ {
void libc_init() void libc_init()
{ {
stdin = fdopen(STDIN_FILENO, "r");
stdout = fdopen(STDOUT_FILENO, "w"); stdout = fdopen(STDOUT_FILENO, "w");
stderr = fdopen(STDERR_FILENO, "w"); stderr = fdopen(STDERR_FILENO, "w");
} }

View File

@ -8,7 +8,6 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
FILE* stdin = nullptr;
FILE* stderr = nullptr; FILE* stderr = nullptr;
FILE* stdout = nullptr; FILE* stdout = nullptr;