Commit Graph

250 Commits

Author SHA1 Message Date
4f2b3ce5d1 fclose: restore errno after call to free() if close() fails 2022-10-10 21:18:24 +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
1b84c443fe Merge branch VFS into main
Reviewed-on: #10
2022-10-10 18:25:43 +00: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
63b2de4e3c Basic FDs 2022-10-10 19:00:24 +02:00
da84f1713c InitRD: Use get_blocks_from_size() 2022-10-10 18:45:49 +02:00
bbe7c6e658 VFS: Implement resolve_path and form the initial ramdisk's VFS properly
Finally, resolve_path: a function which takes a path (/etc/fstab for example), and walks the VFS:
In this case, it would start with the root FS node, and ask it: "do you have a directory/file named etc?"
The node could say 'yes', 'no', or 'i'm not a directory, I'm a file' (should not be the case for the VFS root, but for the other ones it could be)
If it says yes, we continue and ask the child if it has a file named fstab. Etc...
2022-10-10 18:44:43 +02:00
2be70d0bc1 VFS: Use 64-bit numbers in read()
There is no need for any kind of 32-bit compatibility.
2022-10-09 21:30:38 +02:00
8158ddc94f VFS: be more verbose 2022-10-09 21:19:22 +02:00
b38c52f8c7 more vfs stuff 2022-10-08 21:35:19 +02:00
f3d7e220ac The beginnings of a VFS implementation!! 2022-10-08 21:22:46 +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
4b74c14f1b Merge branch printf_pointers into main
Reviewed-on: #9
2022-10-08 16:27:37 +00:00
3686e03bb7 Cast %p usage to void*
Apparently, %p only accepts void*, and not any pointer type. Still better than casting a pointer to uint64_t.
2022-10-08 18:27:05 +02:00
3feb7782bc Kernel/mmap, munmap: Use %p in printf 2022-10-08 18:24:05 +02:00
d5f59b666a Kernel/Memory: Use %p in printf 2022-10-08 18:21:02 +02:00
8ce58e9e30 Kernel/InitRD: Use %p with printf() 2022-10-08 18:16:55 +02:00
5fc543c179 Kernel/ACPI: Use printf() with %p 2022-10-08 18:15:08 +02:00
40099feb80 Apps: Use the new %p in printf() 2022-10-08 18:11:41 +02:00
3ee1f34bc4 Forgot to add break :)
And that, is why you test before pushing and commiting >.<
2022-10-08 18:08:50 +02:00
c67079dd74 Kernel, libc: Implement %p in *printf()
So we can avoid writing (unsigned long)ptr or (uint64_t)ptr everywhere when wanting to print a pointer.
2022-10-08 18:07:33 +02:00
247645d301 Merge branch exit_status into main
Reviewed-on: #8
2022-10-08 15:58:51 +00: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
1e0c8c5fe7 Kernel: Strip kernel symbols when installing
Since we already extract the symbols into a separate file which the kernel then uses for backtraces, this only brings us a smaller kernel, with no downsides :)
2022-10-08 15:57:07 +02:00
4a212b4c92 Modify shebangs to use /usr/bin/env bash instead of /bin/sh 2022-10-08 15:35:39 +02:00
aa5c1be945 Separate building a debug image and running it, and provide a script for GDB. 2022-10-08 15:32:48 +02:00
309058888c Bugfix: remove duplicate error check when loading a userspace ELF program
Also, remember to delete the allocated task, since we do not want memory leaks :)
2022-10-08 13:12:19 +00:00
159d025d9f ACPI::get_rsdt_or_xsdt(): Use a temporary variable to do mappings, then set cache to it. 2022-10-08 15:05:59 +02:00
a5daa24fbf Fix bug :) 2022-10-08 15:03:10 +02:00
533b7c9e71 Refactor ACPI::get_rsdt_or_xsdt()
Much better now.

Also, remove a FIXME in PMM.cpp, since we do map the page bitmap to virtual memory now.
2022-10-08 15:00:42 +02:00
abcf1b6118 Define PAGE_SIZE as 4096 and use it everywhere instead of using 4096 as a magic number 2022-10-08 14:52:28 +02:00
1235ce8b32 Avoid magic numbers 2022-10-08 14:44:48 +02:00
ce6ec3585c Kernel, libc: Add ENOSYS
This error is returned by the kernel/C Library when an attempt is made to use a system call that doesn't exist.
2022-10-08 14:18:25 +02:00
ac72d64490 Make (v)fprintf alias to (v)printf instead of throwing an error
We don't have files :) (yet)
But if someone wants to fprintf(stderr), then fine. Do it. Except it won't be any different from fprintf(stdout) or printf().
2022-10-08 13:45:57 +02:00
a086ec514b Remove the Superblock.h file which has never been used.
This file was included for a future Ext2 implementation. It should be included when said Ext2 implementation is actually started.
2022-10-08 13:28:30 +02:00
9b778254f1 Merge branch perror into main
Reviewed-on: #6
2022-10-08 10:46:02 +00:00
e76d903642 apps: make memeater use perror 2022-10-08 12:42:46 +02:00
ee7558a9b7 Add a perror() function 2022-10-08 12:42:25 +02:00
d6f45c284e Merge branch strerror into main
Reviewed-on: #5
2022-10-08 10:32:12 +00:00
21e8ea1486 apps: make memeater use strerror() 2022-10-08 12:29:19 +02:00
8f0b6d80b2 libc: Implement strerror() 2022-10-08 12:29:06 +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
ad115e9bab libc: Correct include guards 2022-10-08 11:32:01 +02:00
1f655fabe2 The beginnings of Moon 0.10
Right now the kernel is the only thing with a version number, the user apps just fetch it from the kernel using the sys_getversion() syscall
2022-10-07 20:33:00 +02:00
8bf1aac961 Finally, add a README.
It's perhaps too long, but that's better than it being too short.
2022-10-07 20:16:44 +02:00
028a1b1a3c libc: Enable even more warnings 2022-10-07 18:19:06 +02:00
b7ee746da3 Kernel: Enable even more warnings 2022-10-07 18:10:20 +02:00
dc389da74e Implement an ELFImage struct
This struct allows us to keep track of what memory is used by the loaded executable. For some reason, freeing this memory when the task exits triggers a kernel page fault, so I'm not doing that right now.
2022-10-07 17:54:05 +02:00
b2d43d66c4 Remove boot/font.psf from the initrd
This font file is not being used, since we are using an embedded font and that seems to work (should be loaded from the initrd in the future though)
2022-10-07 15:38:08 +02:00