Compare commits
No commits in common. "bab9600be5c7bb67fae6b988fd5fdbae9b710710" and "51f0bdff0e8c4f74cd91c4c5fc4e14f9cd95fc73" have entirely different histories.
bab9600be5
...
51f0bdff0e
@ -24,19 +24,18 @@ int main()
|
||||
{
|
||||
if (getpid() != 1)
|
||||
{
|
||||
fprintf(stderr, "error: init not running as PID 1.\n");
|
||||
printf("error: init not running as PID 1.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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)
|
||||
// can print stuff.
|
||||
stdin = fopen("/dev/console", "r");
|
||||
// Before this point, we don't even have an stdout and stderr. Set it up now so that child processes (and us) can
|
||||
// print stuff.
|
||||
stdout = 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();
|
||||
|
||||
|
@ -4,11 +4,9 @@
|
||||
#include "arch/Timer.h"
|
||||
#include "arch/x86_64/CPU.h"
|
||||
#include "arch/x86_64/IO.h"
|
||||
#include "fs/devices/ConsoleDevice.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include "video/TextConsole.h"
|
||||
#include <cpuid.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/CircularQueue.h>
|
||||
@ -126,11 +124,7 @@ void io_thread()
|
||||
while (!scancode_queue.try_pop(scancode)) { kernel_sleep(10); }
|
||||
|
||||
char key;
|
||||
if (Keyboard::decode_scancode(scancode).try_set_value(key))
|
||||
{
|
||||
TextConsole::putchar(key);
|
||||
ConsoleDevice::did_press_key(key);
|
||||
}
|
||||
if (Keyboard::decode_scancode(scancode).try_set_value(key)) { kdbgln("Read key: %c", key); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,15 @@
|
||||
#include "fs/devices/ConsoleDevice.h"
|
||||
#include "video/TextConsole.h"
|
||||
#include <luna/Buffer.h>
|
||||
#include <luna/CString.h>
|
||||
|
||||
static Buffer g_console_input;
|
||||
|
||||
Result<SharedPtr<Device>> ConsoleDevice::create()
|
||||
{
|
||||
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();
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return g_console_input.size() == 0;
|
||||
}
|
||||
|
||||
void ConsoleDevice::did_press_key(char key)
|
||||
{
|
||||
*g_console_input.slice_at_end(1).value() = (u8)key;
|
||||
return false;
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ class ConsoleDevice : public Device
|
||||
|
||||
Result<usize> write(const u8*, usize, usize) override;
|
||||
|
||||
static void did_press_key(char key);
|
||||
|
||||
bool blocking() const override;
|
||||
|
||||
virtual ~ConsoleDevice() = default;
|
||||
|
@ -13,9 +13,6 @@ extern "C"
|
||||
/* Open a file path and return a file descriptor to it. */
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
@ -16,10 +16,8 @@ typedef struct
|
||||
|
||||
#define EOF -1
|
||||
|
||||
extern FILE* stdin;
|
||||
extern FILE* stdout;
|
||||
extern FILE* stderr;
|
||||
#define stdin stdin
|
||||
#define stdout stdout
|
||||
#define stderr stderr
|
||||
|
||||
|
@ -10,9 +10,8 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
#define STDERR_FILENO 2
|
||||
#define STDOUT_FILENO 0
|
||||
#define STDERR_FILENO 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -18,9 +18,4 @@ extern "C"
|
||||
va_end(ap);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int creat(const char* path, mode_t mode)
|
||||
{
|
||||
return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ extern "C"
|
||||
{
|
||||
void libc_init()
|
||||
{
|
||||
stdin = fdopen(STDIN_FILENO, "r");
|
||||
stdout = fdopen(STDOUT_FILENO, "w");
|
||||
stderr = fdopen(STDERR_FILENO, "w");
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
FILE* stdin = nullptr;
|
||||
FILE* stderr = nullptr;
|
||||
FILE* stdout = nullptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user