__builtin_unreachable();
}
-// extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t len) {
-extern "C" std::int64_t syscall_read(std::int64_t, char*, std::int64_t) {
- os::assert(false, "read not implemented yet.");
- __builtin_unreachable();
+extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t len) {
+ os::assert(file == 0, "Read isn't really implemented for now.");
+ os::assert(len >= 0, "Read expects a positive size.");
+ if (len == 0) {
+ return 0;
+ }
+ for (std::int64_t i = 0; i < len; i++) {
+ if (i == 0) {
+ data[i] = os::read_serial();
+ continue;
+ }
+ if (os::serial_received()) {
+ data[i] = os::read_serial();
+ } else {
+ return i;
+ }
+ }
+ return len;
}
-// extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) {
-extern "C" std::int64_t syscall_write(std::int64_t, char const*, std::int64_t) {
- os::assert(false, "write not implemented yet.");
- __builtin_unreachable();
+extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) {
+ os::assert(file == 0, "Write isn't really implemented for now.");
+ os::assert(len >= 0, "Write expects a positive size.");
+ if (len == 0) {
+ return 0;
+ }
+ for (std::int64_t i = 0; i < len; i++) {
+ if (os::serial_transmit_empty()) {
+ os::write_serial(data[i]);
+ } else {
+ return i;
+ }
+ }
+ return len;
}
// extern "C" std::int64_t syscall_fseek(std::int64_t file, std::int64_t offset, int from) {
#include <stddef.h>
#include <stdint.h>
-extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, int options);
+enum open_options {
+ MODE_RO = 0x1,
+ MODE_WO = 0x2,
+ MODE_RW = MODE_RO | MODE_WO,
+ MODE_DIRECTORY = 0x4,
+ OPTION_INPLACE = 0x8,
+};
+
+namespace sys {
+extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, open_options options);
extern "C" int64_t read(int64_t file, char* data, int64_t len);
extern "C" int64_t write(int64_t file, char const* data, int64_t len);
extern "C" int64_t fseek(int64_t file, int64_t offset, int from);
+} // namespace sys
extern "C" void _start() {
+ const int64_t fd = 0; // sys::open(0, "/serial", 7, sys::MODE_RW | sys::OPTION_INPLACE);
+
+ sys::write(fd, "Entrez votre nom: ", 18);
+ char data[32];
+ int64_t read = 0;
+ int64_t read_this_time;
+ do {
+ read_this_time = sys::read(fd, data + read, 1);
+ if (read_this_time) {
+ if (data[read] == '\r') {
+ sys::write(fd, "\n", 1);
+ } else {
+ sys::write(fd, data + read, 1);
+ }
+ }
+ read += read_this_time;
+ } while (read_this_time != 0 && read < 32 && data[read - 1] != '\r');
+ sys::write(fd, "Bonjour, ", 9);
+ sys::write(fd, data, read - (data[read - 1] == '\r' ? 1 : 0));
+ sys::write(fd, ".\n", 2);
+
while (true) {
- fseek(0, 0, 1);
+ sys::fseek(0, 0, 1);
}
}