Commit Graph

283 Commits

Author SHA1 Message Date
0bad662c2f sh: If fork() fails, show an error containing fork 2022-10-26 17:13:47 +02:00
af452e2b2a Kernel, libc: Add dup2() 2022-10-25 18:58:06 +02:00
8bf2904d74 libc: Implement a basic subset of dirent.h 2022-10-23 14:41:45 +02:00
32db366781 apps: Add a little ls utility that lists the files in /bin 2022-10-23 14:06:11 +02:00
06f9ffc184 libc: Add EXIT_SUCCESS, EXIT_FAILURE, RAND_MAX and BUFSIZ 2022-10-22 21:39:51 +02:00
26324259f2 uname: Use fgets() 2022-10-22 15:43:21 +02:00
a1a1157151 sh: update it 2022-10-22 15:09:09 +02:00
4aa979bd87 sh: remove duplicate code 2022-10-22 15:08:27 +02:00
189986d23f libc: Rename pstname() to pstatname()
To avoid confusion with ptsname().
2022-10-22 14:30:41 +02:00
727e227b09 apps: Add ps (uses pstat) 2022-10-22 14:26:59 +02:00
31e0f0efed uptime: Use fgets() 2022-10-22 14:23:34 +02:00
27a18a608c libc: Implement fgets, fgetc, getc, getchar (with buffered read IO) 2022-10-22 11:38:16 +02:00
b2f5a0502f Kernel, libc: Implement O_NONBLOCK 2022-10-21 21:51:03 +02:00
da61e3648f Kernel: Implement blocking reads
This is a huge step forward!! bc actually runs now, without echo or backspace, but it runs!!
2022-10-21 21:26:19 +02:00
0720b3245b sh: Do not backspace if command is empty 2022-10-20 19:32:32 +02:00
b69fbd46bf init: Add a Message of the Day 2022-10-20 19:27:37 +02:00
bd4c587409 sh: Try to execute programs in /bin if they are not found 2022-10-20 19:12:17 +02:00
de167c3c67 sh: Show last command' exit status in prompt if non-zero 2022-10-20 08:21:18 +02:00
44bd93b8b4 apps: Add a hello app 2022-10-19 21:13:47 +02:00
f682258fc9 sym: do not sleep 2022-10-19 21:13:38 +02:00
2c813f5901 apps: Add more simple apps
Now that we can start them at will from the command line, bring them on!!
2022-10-19 21:11:38 +02:00
aebd860947 libc: Add stdin
Aka keyboard :)
2022-10-19 20:43:04 +02:00
ba57f32f39 init: wait less before starting sh 2022-10-19 20:36:27 +02:00
a815beacfb sh: add builtins 2022-10-19 20:34:10 +02:00
20db8eaba6 Init: exit if the primary child process exits 2022-10-19 20:33:59 +02:00
7e9744419e sh: Improve it 2022-10-19 20:16:21 +02:00
3c5c92c7c3 sh: Add a simple interactive shell 2022-10-19 19:42:05 +02:00
f3af3e252b Kernel: refresh task_misbehave()
That function was severely outdated.
2022-10-19 17:26:36 +02:00
656667812a Kernel: reparent child processes to PID 1 when their parent exits 2022-10-19 17:16:01 +02:00
671f2a2de3 Kernel, libc: Implement waitpid()
FIXME: exec() is now doing weird page table stuff. But at least it works, no panics :)
2022-10-18 21:30:52 +02:00
f1bfa6bec8 Build system: more cflags + stripping 2022-10-18 18:28:28 +02:00
01564cb905 libc: Adapt libc to getprocid() + add getppid() 2022-10-18 17:36:33 +02:00
3c1146f2c5 libc: Implement setjmp() and longjmp() 2022-10-17 21:22:18 +02:00
494b48bbe3 init: Adjust init 2022-10-17 20:53:09 +02:00
8b17065718 Kernel, libc: Rename gettid() to getpid() and move it to unistd.h 2022-10-17 20:08:44 +02:00
1e96a45f33 Change 'tid' to 'PID' in init.c
I think tasks can be considered programs now. So, gettid() is equal to getpid().

In fact, it should be renamed. And moved to unistd.h. Soon.
2022-10-17 19:39:26 +02:00
64f5078494 Kernel, libc: Implement fork()
This time for real.

Also, add a new per-user-task virtual address allocator (UserHeap), so that mmap'ed pages are in user range and can be copied.
2022-10-17 18:43:35 +02:00
3bf4f854c7 init: return 0 at the end of main 2022-10-17 17:19:31 +02:00
8b70635e79 Do not strip apps 2022-10-17 17:19:23 +02:00
9b39d618de Kernel, libc: Implement spawn()
This function is a Luna alternative to fork() and exec().

Why? Simply because I can't figure out for the life of me how to implement a working fork().

So meanwhile, we have spawn() as a replacement. exec() still exists, though.
2022-10-16 18:48:35 +02:00
6d821d2638 libc: Add support for mkdir() 2022-10-16 17:37:29 +02:00
d30010d524 apps/sym: Read from the end of the file 2022-10-15 17:45:53 +02:00
45afd3e243 Replace the rand() which reads from /dev/random with a Mersenne PRNG.
Much better now.

Also, it is seeded by reading from /dev/random at startup. Not sure if that's the best idea, but we'll see.
2022-10-15 16:46:54 +02:00
1e86acd4c0 libc: Implement fcntl(F_DUPFD) and dup() 2022-10-15 11:16:34 +02:00
91d76a2ee4 Devices: Add a new RandomDevice :)
This new device uses the seeded Mersenne PRNG we use in the kernel.
This device is not meant for regular userspace use, but more for userspace to seed their own PRNGs from.

If the DeviceFS is mounted at /dev, this device can be found at /dev/random.
2022-10-14 20:14:49 +02:00
97461c7c1f Prepare for moon 0.11 2022-10-14 19:49:52 +02:00
26211bd49f It (almost) works now
The only thing doing weird stuff is exec(), so that's commented out and throws ENOSYS right now.

But we have two user tasks running in parallel, isolated from each other!
2022-10-14 16:46:00 +02:00
531b2848ac init: Execute /bin/sym instead of /sys/config
We have now proven that exec() does fail and return to userspace when a file is not a valid executable.
We can now go back to executing a normal program.
2022-10-12 20:54:32 +02:00
4091799701 Kernel, libc: Add ENOEXEC (Exec format error) 2022-10-12 19:15:44 +02:00
7a2e313a20 init: demo execv() 2022-10-12 18:04:27 +02:00
edda41a7bb libc: Implement fseek(), ftell() and rewind()
All three use the new syscall seek() (with its lseek() wrapper in unistd.h)!!
2022-10-12 15:56:03 +02:00
eb03ae91e0 Devices: Add a new Serial device
This device permits userspace to interface with the serial port.
2022-10-12 10:44:30 +02:00
44834b8a0f libc: Implement fputs, fputc, putc and putchar 2022-10-12 10:05:14 +02:00
e145690db8 apps: Remove demo programs (except for init)
We no longer need those, and they just make the initrd larger.
2022-10-11 21:37:27 +02:00
f6e783ea45 init: do not show 'read n bytes' when printing version
that was to debug why reading /dev/version returned 'versionmoon 0.10-' instead of 'moon 0.10-fffffff'

it works now, so...
2022-10-11 20:13:00 +02:00
8e57df518f apps: build with optimizations enabled 2022-10-11 19:57:24 +02:00
0a7d4a530d VFS, DeviceFS: Implement a device filesystem
For now, we just have a version device. (this will allow us to get rid of sys_getversion!!)
More should be implemented soon.
2022-10-11 19:21:16 +02:00
7a097f16ea apps: add a new example app which does all kinds of stdio misbehaving >.< 2022-10-11 17:31:06 +02:00
6c51477197 libc: Implement ferror() and feof() 2022-10-11 16:57:08 +02:00
d25e8a43db build system: strip apps 2022-10-10 21:24:21 +02:00
93f6be9319 libc: Implement the start of a FILE* API (the standard, portable C way of doing file stuff) 2022-10-10 21:08:57 +02:00
9e0bd39964 libc: Implement wrappers for sys_{open,read,write}
read() and close() are in unistd.h, but open() in fnctl.h.
I thought only the definitions for O_SOMETHING were in fnctl.h, but it is as it is.
Don't know why, but let's not anger the Unix gods.

The FILE* C API is pending as well.
2022-10-10 20:45:26 +02:00
da2ede3450 Kernel, libc, userspace: Implement file descriptors
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those.
Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now)
Implement three new errors: ENOENT, EBADF and EMFILE.

libc: Implement the new errors, and the new syscalls in syscall().
Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror().

userspace: make init demonstrate the new file API.
2022-10-10 20:21:39 +02:00
49c7900407 Add %m to userspace printf
%m as a format specifier is a nonstandard glibc extension, but I like it so I'm implementing it.
What it does is print the value of strerror(errno), without consuming any arguments to printf().
2022-10-08 18:44:14 +02:00
40099feb80 Apps: Use the new %p in printf() 2022-10-08 18:11:41 +02:00
f83a6ace51 Kernel, libc: Add support for providing a status code to exit()
The exit() libc function already accepted an integer, but didn't pass it on to the kernel since we had no mechanism for it to do that.
Now, the kernel stores a task's exit status to display it later (and in the future, return it to userspace via wait()/waitpid())
2022-10-08 17:56:40 +02:00
e76d903642 apps: make memeater use perror 2022-10-08 12:42:46 +02:00
21e8ea1486 apps: make memeater use strerror() 2022-10-08 12:29:19 +02:00
71e15e94af Kernel, libc and userspace: Add basic errno support.
Kernel: Add an errno.h header with definitions for each header,
and return those, negated, from syscalls when there is an error.
mmap() returns an invalid address with errno encoded, instead of
returning a negated errno; this address is encoded as ffffffffffffffEE
where EE is errno in hex.

libc: make syscall() return -1 and set errno on error, instead of
returning the raw return value of the system call. Also, add mmap()
and munmap() wrappers in sys/mman.h :).

userspace: make the memeater program show the value of errno
when allocating memory fails.

Things to improve: add perror() and strerror() to make the errno
experience even better! >.<
2022-10-08 12:06:09 +02:00
5d8b825659 Add a few example apps/demos in C, and make the kernel choose a random one to demonstrate every boot 2022-10-03 21:24:38 +02:00
34aa953dbc Add printf() and puts(), quite primitive, looks like hex printing isn't there yet... 2022-10-03 19:00:10 +02:00
dae2ff8d50 Add mmap and munmap syscalls, and thus, add malloc and free to libc!! (yet again, thanks to the wonderful liballoc) 2022-10-02 20:45:04 +02:00
1ecd24f5d6 Kernel: Add SSE support (enable SSE on boot and save context (user tasks only) on task switch) 2022-10-02 18:53:54 +02:00
d2f9e17c86 Use __luna_abort in init 2022-10-02 18:16:27 +02:00
ae95a528f2 Make function stubs in libc loudly abort instead of silently failing 2022-10-02 18:10:53 +02:00
8e6741ebd6 Rename SYS_version to SYS_getversion 2022-10-02 17:25:56 +02:00
6bacded5cf Update build system 2022-10-02 17:01:30 +02:00
f8a72f15c8 Adjust build system to be more flexible and to work with the new toolchain 2022-10-02 12:44:32 +02:00
c7f46f96ff Use the new syscalls in init 2022-10-01 17:32:50 +02:00
96f53922c9 Write a (kindof) proper init, at least with the capabilities we have right now 2022-10-01 15:54:42 +02:00
cde850258d Don't assume we are located at /bin/init 2022-10-01 13:16:59 +02:00
1c4383dea4 Add an apps/ folder and build-system to build userspace apps which can now be loaded from the initrd 2022-10-01 12:17:16 +02:00
867d312177 Let's try to start parsing ELFs! 2022-09-30 17:43:14 +02:00