diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2b00dcf..619032b 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,57 +1,36 @@ name: MacOS on: - push: - branches-ignore: - - "releases/**" - paths-ignore: - - "**.md" - - ".gitignore" - - "ubuntu.yml" - pull_request: - paths-ignore: - - "**.md" - - ".gitignore" - - "ubuntu.yml" + push: + branches-ignore: + - "releases/**" + paths-ignore: + - "**.md" + - ".gitignore" + - "**/ubuntu.yml" + - "**/windows.yml" + pull_request: + paths-ignore: + - "**.md" + - ".gitignore" + - "**/ubuntu.yml" + - "**/windows.yml" jobs: - doxygen: - name: Doxygen - runs-on: macos-latest - env: - # We globally set CC and CXX. - CC: x86_64-elf-gcc - CXX: x86_64-elf-g++ - steps: - - name: Clone repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - brew update - brew install x86_64-elf-binutils x86_64-elf-gcc git cmake qemu nasm e2fsprogs doxygen - - - name: Generate documentation - run: | - cmake -B build -D DOXYGEN_WARN_AS_ERROR=NO - cmake --build build --target mentos_documentation - - build: - name: Build - runs-on: macos-latest - # Set environment variables - env: - # We globally set CC and CXX. - CC: x86_64-elf-gcc - CXX: x86_64-elf-g++ - steps: - - name: Clone repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - brew update - brew install x86_64-elf-binutils x86_64-elf-gcc git cmake qemu nasm e2fsprogs - - - name: Build - run: | - cmake -B build - cmake --build build --parallel 2 + build: + name: Build + runs-on: macos-latest + # Set environment variables + env: + # We globally set CC and CXX. + CC: x86_64-elf-gcc + CXX: x86_64-elf-g++ + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Install dependencies + run: | + brew update + brew install x86_64-elf-binutils x86_64-elf-gcc git cmake qemu nasm e2fsprogs + - name: Build + run: | + cmake -B build + cmake --build build --parallel 2 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 0e85bc5..88e022a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -6,12 +6,14 @@ on: paths-ignore: - "**.md" - ".gitignore" - - "macos.yml" + - "**/macos.yml" + - "**/windows.yml" pull_request: paths-ignore: - "**.md" - ".gitignore" - - "macos.yml" + - "**/macos.yml" + - "**/windows.yml" jobs: doxygen: name: Doxygen @@ -19,73 +21,65 @@ jobs: steps: - name: Clone repository uses: actions/checkout@v3 - - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y doxygen nasm - - name: Generate documentation run: | cmake -B build -D DOXYGEN_WARN_AS_ERROR=NO cmake --build build --target mentos_documentation - build: name: Build strategy: fail-fast: false matrix: include: [ - # You can access the following values via ${{ matrix.??? }} - # - # pkgs : apt-get package names. It can include multiple package names which are delimited by space. - # cc : C compiler executable. - # cxx : C++ compiler executable for `make ctocpptest`. - # x32 : Set 'true' if compiler supports x32. Otherwise, set 'false'. - # Set 'fail' if it supports x32 but fails for now. 'fail' cases must be removed. - # x86 : Set 'true' if compiler supports x86 (-m32). Otherwise, set 'false'. - # Set 'fail' if it supports x86 but fails for now. 'fail' cases must be removed. - # cxxtest : Set 'true' if it can be compiled as C++ code. Otherwise, set 'false'. - # freestanding : Set 'true' if it can be compiled and execute freestanding code. Otherwise, set 'false'. - # Usually, it requires Linux, x86_64 and gcc/g++. - # os : GitHub Actions YAML workflow label. See https://github.com/actions/virtual-environments#available-environments - # gcc - { pkgs: 'nasm', cc: gcc, cxx: g++, os: ubuntu-latest, }, - { pkgs: 'gcc-12 g++-12 nasm', cc: gcc-12, cxx: g++-12, os: ubuntu-22.04, }, - { pkgs: 'gcc-11 g++-11 nasm', cc: gcc-11, cxx: g++-11, os: ubuntu-22.04, }, - { pkgs: 'gcc-10 g++-10 nasm', cc: gcc-10, cxx: g++-10, os: ubuntu-22.04, }, - { pkgs: 'gcc-9 g++-9 nasm', cc: gcc-9, cxx: g++-9, os: ubuntu-22.04, }, - { pkgs: 'gcc-8 g++-8 nasm', cc: gcc-8, cxx: g++-8, os: ubuntu-20.04, }, - { pkgs: 'gcc-7 g++-7 nasm', cc: gcc-7, cxx: g++-7, os: ubuntu-20.04, }, - # clang - { pkgs: 'nasm', cc: clang, cxx: clang++, os: ubuntu-latest, }, - { pkgs: 'clang-14 nasm', cc: clang-14, cxx: clang++-14, os: ubuntu-22.04, }, - { pkgs: 'clang-13 nasm', cc: clang-13, cxx: clang++-13, os: ubuntu-22.04, }, - { pkgs: 'clang-12 nasm', cc: clang-12, cxx: clang++-12, os: ubuntu-22.04, }, - { pkgs: 'clang-11 nasm', cc: clang-11, cxx: clang++-11, os: ubuntu-22.04, }, - { pkgs: 'clang-10 nasm', cc: clang-10, cxx: clang++-10, os: ubuntu-20.04, }, - { pkgs: 'clang-9 nasm', cc: clang-9, cxx: clang++-9, os: ubuntu-20.04, }, - { pkgs: 'clang-8 nasm', cc: clang-8, cxx: clang++-8, os: ubuntu-20.04, }, - { pkgs: 'clang-7 nasm', cc: clang-7, cxx: clang++-7, os: ubuntu-20.04, }, - ] - + # You can access the following values via ${{ matrix.??? }} + # + # pkgs : apt-get package names. It can include multiple package names which are delimited by space. + # cc : C compiler executable. + # cxx : C++ compiler executable for `make ctocpptest`. + # x32 : Set 'true' if compiler supports x32. Otherwise, set 'false'. + # Set 'fail' if it supports x32 but fails for now. 'fail' cases must be removed. + # x86 : Set 'true' if compiler supports x86 (-m32). Otherwise, set 'false'. + # Set 'fail' if it supports x86 but fails for now. 'fail' cases must be removed. + # cxxtest : Set 'true' if it can be compiled as C++ code. Otherwise, set 'false'. + # freestanding : Set 'true' if it can be compiled and execute freestanding code. Otherwise, set 'false'. + # Usually, it requires Linux, x86_64 and gcc/g++. + # os : GitHub Actions YAML workflow label. See https://github.com/actions/virtual-environments#available-environments + # gcc + { pkgs: "nasm", cc: gcc, cxx: g++, os: ubuntu-latest }, + { pkgs: "gcc-12 g++-12 nasm", cc: gcc-12, cxx: g++-12, os: ubuntu-22.04 }, + { pkgs: "gcc-11 g++-11 nasm", cc: gcc-11, cxx: g++-11, os: ubuntu-22.04 }, + { pkgs: "gcc-10 g++-10 nasm", cc: gcc-10, cxx: g++-10, os: ubuntu-22.04 }, + { pkgs: "gcc-9 g++-9 nasm", cc: gcc-9, cxx: g++-9, os: ubuntu-22.04 }, + { pkgs: "gcc-8 g++-8 nasm", cc: gcc-8, cxx: g++-8, os: ubuntu-20.04 }, + { pkgs: "gcc-7 g++-7 nasm", cc: gcc-7, cxx: g++-7, os: ubuntu-20.04 }, + # clang + { pkgs: "nasm", cc: clang, cxx: clang++, os: ubuntu-latest }, + { pkgs: "clang-14 nasm", cc: clang-14, cxx: clang++-14, os: ubuntu-22.04 }, + { pkgs: "clang-13 nasm", cc: clang-13, cxx: clang++-13, os: ubuntu-22.04 }, + { pkgs: "clang-12 nasm", cc: clang-12, cxx: clang++-12, os: ubuntu-22.04 }, + { pkgs: "clang-11 nasm", cc: clang-11, cxx: clang++-11, os: ubuntu-22.04 }, + { pkgs: "clang-10 nasm", cc: clang-10, cxx: clang++-10, os: ubuntu-20.04 }, + { pkgs: "clang-9 nasm", cc: clang-9, cxx: clang++-9, os: ubuntu-20.04 }, + { pkgs: "clang-8 nasm", cc: clang-8, cxx: clang++-8, os: ubuntu-20.04 }, + { pkgs: "clang-7 nasm", cc: clang-7, cxx: clang++-7, os: ubuntu-20.04 }, + ] runs-on: ${{ matrix.os }} - # Set environment variables env: # We globally set CC and CXX. CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} - steps: - name: Clone repository uses: actions/checkout@v3 - - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y ${{ matrix.pkgs }} - - name: Build run: | cmake -B build diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..4279ef9 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,36 @@ +name: Windows +on: + push: + branches-ignore: + - "releases/**" + paths-ignore: + - "**.md" + - ".gitignore" + - "**/macos.yml" + - "**/ubuntu.yml" + pull_request: + paths-ignore: + - "**.md" + - ".gitignore" + - "**/macos.yml" + - "**/ubuntu.yml" +jobs: + test: + name: Build + runs-on: windows-latest + steps: + - name: Clone repo + uses: actions/checkout@v3 + - name: Install dependencies + run: | + choco install nasm + echo "C:\Program Files\NASM" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Set up MinGW + uses: egor-tensin/setup-mingw@v2 + with: + version: latest + platform: x32 + - name: Build + run: | + cmake -B build + cmake --build build --parallel 2 diff --git a/.gitignore b/.gitignore index 8ef34f9..a7ea7fb 100644 --- a/.gitignore +++ b/.gitignore @@ -116,7 +116,4 @@ src/initscp/initfscp files/bin/** # ISO creation files. -iso/boot/*.bin - -# Visual Studio Code -.vscode \ No newline at end of file +iso/boot/*.bin \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ead0294 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.h": "c", + "*.c": "c" + }, +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 12e1e84..8796736 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ # ============================================================================= # Set the minimum required version of cmake. cmake_minimum_required(VERSION 3.1...3.22) -# -set(HAVE_FLAG_SEARCH_PATHS_FIRST 0) + # Initialize the project. project(mentos C ASM) @@ -168,15 +167,15 @@ add_custom_target( add_custom_target( qemu-gdb COMMAND test -e ${CMAKE_BINARY_DIR}/rootfs.img || ${CMAKE_COMMAND} -E cmake_echo_color --red "No filesystem file detected, you need to run: make filesystem" - COMMAND echo "\n\n" - COMMAND echo "Now, QEMU has loaded the kernel, and it is waiting that you\n" - COMMAND echo "remotely connect to it. To start debugging, open a new shell\n" - COMMAND echo "in THIS same folder, and just type :\n" + COMMAND echo "" + COMMAND echo "Now, QEMU has loaded the kernel, and it is waiting that you" + COMMAND echo "remotely connect to it. To start debugging, open a new shell" + COMMAND echo "in THIS same folder, and just type :" COMMAND printf " cgdb -q -iex %q" "add-auto-load-safe-path ." - COMMAND echo "\n\n" + COMMAND echo "" COMMAND ${EMULATOR} ${EMULATOR_FLAGS} -s -S -kernel ${CMAKE_BINARY_DIR}/mentos/kernel-bootloader.bin DEPENDS kernel-bootloader.bin - DEPENDS .gdbinit + DEPENDS gdbinit ) # ============================================================================= diff --git a/README.md b/README.md index 9f2ae1e..2d4381c 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,11 @@ 4. [Compiling MentOS](#4-compiling-mentos) 5. [Generating the EXT2 filesystem](#5-generating-the-ext2-filesystem) 6. [Running MentOS](#6-running-mentos) - 7. [Kernel logging](#7-kernel-logging) - 8. [Change the scheduling algorithm](#8-change-the-scheduling-algorithm) - 9. [Debugging the kernel](#9-debugging-the-kernel) - 10. [Contributors](#10-contributors) + 7. [Running MentOS from GRUB](#7-running-mentos-from-grub) + 8. [Kernel logging](#8-kernel-logging) + 9. [Change the scheduling algorithm](#9-change-the-scheduling-algorithm) + 10. [Debugging the kernel](#10-debugging-the-kernel) + 11. [Contributors](#11-contributors) ## 1. What is MentOS @@ -180,11 +181,32 @@ To login, use one of the usernames listed in `files/etc/passwd`. *[Back to the Table of Contents](#table-of-contents)* -## 7. Kernel logging +## 7. Running MentOS from GRUB + +For booting MentOS from GRUB in QEMU we need the following tools: + + - xorriso + - grub-mkrescue (from grub-common) + +We also need `grub-pc-bin`, otherwise GRUB won't start in QEMU. + +Which can be installed in Ubuntu with the following command: +```bash +sudo apt-get update && sudo apt-get upgrade -y +sudo apt-get install -y grub-common grub-pc-bin xorriso +``` + +Boot MentOS with qemu through GRUB by calling: + +```bash +make qemu-grub +``` + +## 8. Kernel logging The kernel provides ways of printing logging messages *from* inside the kernel code *to* the bash where you executed the `make qemu`. These *logging* functions are: -```C++ +```C #define pr_emerg(...) #define pr_alert(...) #define pr_crit(...) @@ -197,7 +219,7 @@ These *logging* functions are: ``` You use them like you would use a `printf`: -```C++ +```C if (fd < 0) { pr_err("Failed to open file '%s', received file descriptor %d.\n", filename, fd); return 1; @@ -207,7 +229,7 @@ You use them like you would use a `printf`: By default only message that goes from `pr_notice` included down to `pr_emerg` are displayed. Each logging function (they are actually macros) is a wrapper that automatically sets the desired **log level**. Each log level is identified by a number, and declared as follows: -```C++ +```C #define LOGLEVEL_DEFAULT (-1) ///< default-level messages. #define LOGLEVEL_EMERG 0 ///< system is unusable. #define LOGLEVEL_ALERT 1 ///< action must be taken immediately. @@ -220,19 +242,21 @@ Each logging function (they are actually macros) is a wrapper that automatically ``` You can change the logging level by including the following lines at the beginning of your source code: -```C++ +```C // Include the kernel log levels. #include "sys/kernel_levels.h" /// Change the header. #define __DEBUG_HEADER__ "[ATA ]" /// Set the log level. #define __DEBUG_LEVEL__ LOGLEVEL_INFO +// Include the debuggin header. +#include "io/debug.h" ``` This example sets the `__DEBUG_LEVEL__`, so that all the messages from `INFO` and below are shown. While `__DEBUG_HEADER__` is just a string that is automatically prepended to your message, helping you identifying from which code the message is coming from. *[Back to the Table of Contents](#table-of-contents)* -## 8. Change the scheduling algorithm +## 9. Change the scheduling algorithm MentOS supports scheduling algorithms for aperiodic: @@ -300,7 +324,7 @@ make qemu *[Back to the Table of Contents](#table-of-contents)* -## 9. Debugging the kernel +## 10. Debugging the kernel If you want to use GDB to debug MentOS, first you need to compile everything: @@ -353,7 +377,7 @@ Breakpoint 2, kmain (...) at .../mentos/src/kernel.c:95 *[Back to the Table of Contents](#table-of-contents)* -## 10. Contributors +## 11. Contributors Project Manager: diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index f8f5048..83a21f0 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -20,126 +20,22 @@ if (DOXYGEN_FOUND) set(DOXYGEN_SHOW_INCLUDE_FILES NO) set(DOXYGEN_GENERATE_TREEVIEW NO) set(DOXYGEN_WARN_NO_PARAMDOC YES) + + set(DOXYGEN_ENABLE_PREPROCESSING YES) + set(DOXYGEN_EXTRACT_STATIC YES) + set(DOXYGEN_MACRO_EXPANSION YES) + set(DOXYGEN_EXPAND_ONLY_PREDEF YES) + set(DOXYGEN_PREDEFINED "__attribute__((x))= _syscall0= _syscall0(x)= _syscall1(x)= _syscall2(x)= _syscall3(x)=") + + set(DOXYGEN_WARN_FORMAT "$file($line): $text") set(DOXYGEN_HTML_STYLESHEET ${PROJECT_SOURCE_DIR}/doc/doxygen.css) doxygen_add_docs( ${PROJECT_NAME}_documentation ${PROJECT_SOURCE_DIR}/README.md - ${PROJECT_SOURCE_DIR}/CODING_STYLE.md ${PROJECT_SOURCE_DIR}/LICENSE.md - ${PROJECT_SOURCE_DIR}/TODO.md ${PROJECT_SOURCE_DIR}/doc/signal.md ${PROJECT_SOURCE_DIR}/doc/syscall.md - ${PROJECT_SOURCE_DIR}/libc/src/crt0.S - ${PROJECT_SOURCE_DIR}/libc/inc/array.h - ${PROJECT_SOURCE_DIR}/libc/inc/assert.h - ${PROJECT_SOURCE_DIR}/libc/inc/bits/ioctls.h - ${PROJECT_SOURCE_DIR}/libc/inc/bits/stat.h - ${PROJECT_SOURCE_DIR}/libc/inc/bits/termios-struct.h - ${PROJECT_SOURCE_DIR}/libc/inc/ctype.h - ${PROJECT_SOURCE_DIR}/libc/inc/debug.h - ${PROJECT_SOURCE_DIR}/libc/inc/fcntl.h - ${PROJECT_SOURCE_DIR}/libc/inc/fcvt.h - ${PROJECT_SOURCE_DIR}/libc/inc/grp.h - ${PROJECT_SOURCE_DIR}/libc/inc/io/mm_io.h - ${PROJECT_SOURCE_DIR}/libc/inc/io/port_io.h - ${PROJECT_SOURCE_DIR}/libc/inc/ipc/ipc.h - ${PROJECT_SOURCE_DIR}/libc/inc/ipc/msg.h - ${PROJECT_SOURCE_DIR}/libc/inc/ipc/sem.h - ${PROJECT_SOURCE_DIR}/libc/inc/ipc/shm.h - ${PROJECT_SOURCE_DIR}/libc/inc/libgen.h - ${PROJECT_SOURCE_DIR}/libc/inc/limits.h - ${PROJECT_SOURCE_DIR}/libc/inc/math.h - ${PROJECT_SOURCE_DIR}/libc/inc/pwd.h - ${PROJECT_SOURCE_DIR}/libc/inc/ring_buffer.h - ${PROJECT_SOURCE_DIR}/libc/inc/sched.h - ${PROJECT_SOURCE_DIR}/libc/inc/signal.h - ${PROJECT_SOURCE_DIR}/libc/inc/stdarg.h - ${PROJECT_SOURCE_DIR}/libc/inc/stdbool.h - ${PROJECT_SOURCE_DIR}/libc/inc/stddef.h - ${PROJECT_SOURCE_DIR}/libc/inc/stdint.h - ${PROJECT_SOURCE_DIR}/libc/inc/stdio.h - ${PROJECT_SOURCE_DIR}/libc/inc/stdlib.h - ${PROJECT_SOURCE_DIR}/libc/inc/strerror.h - ${PROJECT_SOURCE_DIR}/libc/inc/string.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/bitops.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/dirent.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/errno.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/ioctl.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/reboot.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/stat.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/types.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/unistd.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/utsname.h - ${PROJECT_SOURCE_DIR}/libc/inc/sys/wait.h - ${PROJECT_SOURCE_DIR}/libc/inc/system/syscall_types.h - ${PROJECT_SOURCE_DIR}/libc/inc/termios.h - ${PROJECT_SOURCE_DIR}/libc/inc/time.h - ${PROJECT_SOURCE_DIR}/libc/src/abort.c - ${PROJECT_SOURCE_DIR}/libc/src/assert.c - ${PROJECT_SOURCE_DIR}/libc/src/ctype.c - ${PROJECT_SOURCE_DIR}/libc/src/debug.c - ${PROJECT_SOURCE_DIR}/libc/src/fcvt.c - ${PROJECT_SOURCE_DIR}/libc/src/grp.c - ${PROJECT_SOURCE_DIR}/libc/src/io/mm_io.c - ${PROJECT_SOURCE_DIR}/libc/src/io/port_io.c - ${PROJECT_SOURCE_DIR}/libc/src/ipc/ipc.c - ${PROJECT_SOURCE_DIR}/libc/src/libc_start.c - ${PROJECT_SOURCE_DIR}/libc/src/libgen.c - ${PROJECT_SOURCE_DIR}/libc/src/math.c - ${PROJECT_SOURCE_DIR}/libc/src/pwd.c - ${PROJECT_SOURCE_DIR}/libc/src/sched.c - ${PROJECT_SOURCE_DIR}/libc/src/setenv.c - ${PROJECT_SOURCE_DIR}/libc/src/stdio.c - ${PROJECT_SOURCE_DIR}/libc/src/stdlib.c - ${PROJECT_SOURCE_DIR}/libc/src/strerror.c - ${PROJECT_SOURCE_DIR}/libc/src/string.c - ${PROJECT_SOURCE_DIR}/libc/src/sys/errno.c - ${PROJECT_SOURCE_DIR}/libc/src/sys/ioctl.c - ${PROJECT_SOURCE_DIR}/libc/src/sys/unistd.c - ${PROJECT_SOURCE_DIR}/libc/src/sys/utsname.c - ${PROJECT_SOURCE_DIR}/libc/src/termios.c - ${PROJECT_SOURCE_DIR}/libc/src/time.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/chdir.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/close.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/creat.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/exec.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/exit.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/fork.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getcwd.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getdents.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getgid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getpgid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getpid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getppid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getsid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/getuid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/interval.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/kill.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/lseek.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/mkdir.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/nice.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/open.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/read.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/reboot.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/rmdir.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/setgid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/setpgid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/setsid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/setuid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/signal.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/stat.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/unlink.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/waitpid.c - ${PROJECT_SOURCE_DIR}/libc/src/unistd/write.c - ${PROJECT_SOURCE_DIR}/libc/src/vscanf.c - ${PROJECT_SOURCE_DIR}/libc/src/vsprintf.c - ${PROJECT_SOURCE_DIR}/mentos/src/boot.S - ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/exception.S - ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.S - ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/idt.S - ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.S - ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/tss.S - ${PROJECT_SOURCE_DIR}/mentos/src/process/user.S + ${PROJECT_SOURCE_DIR}/mentos/inc/boot.h ${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/gdt.h ${PROJECT_SOURCE_DIR}/mentos/inc/descriptor_tables/idt.h @@ -163,9 +59,6 @@ if (DOXYGEN_FOUND) ${PROJECT_SOURCE_DIR}/mentos/inc/hardware/cpuid.h ${PROJECT_SOURCE_DIR}/mentos/inc/hardware/pic8259.h ${PROJECT_SOURCE_DIR}/mentos/inc/hardware/timer.h - ${PROJECT_SOURCE_DIR}/mentos/inc/io/debug.h - ${PROJECT_SOURCE_DIR}/mentos/inc/io/mm_io.h - ${PROJECT_SOURCE_DIR}/mentos/inc/io/port_io.h ${PROJECT_SOURCE_DIR}/mentos/inc/io/proc_modules.h ${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga.h ${PROJECT_SOURCE_DIR}/mentos/inc/io/vga/vga_font.h @@ -200,7 +93,6 @@ if (DOXYGEN_FOUND) ${PROJECT_SOURCE_DIR}/mentos/inc/proc_access.h ${PROJECT_SOURCE_DIR}/mentos/inc/sys/errno.h ${PROJECT_SOURCE_DIR}/mentos/inc/sys/ipc.h - ${PROJECT_SOURCE_DIR}/mentos/inc/sys/kernel_levels.h ${PROJECT_SOURCE_DIR}/mentos/inc/sys/module.h ${PROJECT_SOURCE_DIR}/mentos/inc/sys/reboot.h ${PROJECT_SOURCE_DIR}/mentos/inc/sys/types.h @@ -210,6 +102,7 @@ if (DOXYGEN_FOUND) ${PROJECT_SOURCE_DIR}/mentos/inc/system/signal.h ${PROJECT_SOURCE_DIR}/mentos/inc/system/syscall.h ${PROJECT_SOURCE_DIR}/mentos/inc/version.h + ${PROJECT_SOURCE_DIR}/mentos/src/boot.c ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/exception.c ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.c @@ -286,5 +179,122 @@ if (DOXYGEN_FOUND) ${PROJECT_SOURCE_DIR}/mentos/src/system/printk.c ${PROJECT_SOURCE_DIR}/mentos/src/system/signal.c ${PROJECT_SOURCE_DIR}/mentos/src/system/syscall.c + + ${PROJECT_SOURCE_DIR}/mentos/src/boot.S + ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/exception.S + ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/gdt.S + ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/idt.S + ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/interrupt.S + ${PROJECT_SOURCE_DIR}/mentos/src/descriptor_tables/tss.S + ${PROJECT_SOURCE_DIR}/mentos/src/process/user.S + + ${PROJECT_SOURCE_DIR}/libc/inc/array.h + ${PROJECT_SOURCE_DIR}/libc/inc/assert.h + ${PROJECT_SOURCE_DIR}/libc/inc/bits/ioctls.h + ${PROJECT_SOURCE_DIR}/libc/inc/bits/stat.h + ${PROJECT_SOURCE_DIR}/libc/inc/bits/termios-struct.h + ${PROJECT_SOURCE_DIR}/libc/inc/ctype.h + ${PROJECT_SOURCE_DIR}/libc/inc/fcntl.h + ${PROJECT_SOURCE_DIR}/libc/inc/fcvt.h + ${PROJECT_SOURCE_DIR}/libc/inc/grp.h + ${PROJECT_SOURCE_DIR}/libc/inc/io/ansi_colors.h + ${PROJECT_SOURCE_DIR}/libc/inc/io/debug.h + ${PROJECT_SOURCE_DIR}/libc/inc/io/mm_io.h + ${PROJECT_SOURCE_DIR}/libc/inc/io/port_io.h + ${PROJECT_SOURCE_DIR}/libc/inc/ipc/ipc.h + ${PROJECT_SOURCE_DIR}/libc/inc/ipc/msg.h + ${PROJECT_SOURCE_DIR}/libc/inc/ipc/sem.h + ${PROJECT_SOURCE_DIR}/libc/inc/ipc/shm.h + ${PROJECT_SOURCE_DIR}/libc/inc/libgen.h + ${PROJECT_SOURCE_DIR}/libc/inc/limits.h + ${PROJECT_SOURCE_DIR}/libc/inc/math.h + ${PROJECT_SOURCE_DIR}/libc/inc/pwd.h + ${PROJECT_SOURCE_DIR}/libc/inc/ring_buffer.h + ${PROJECT_SOURCE_DIR}/libc/inc/sched.h + ${PROJECT_SOURCE_DIR}/libc/inc/signal.h + ${PROJECT_SOURCE_DIR}/libc/inc/stdarg.h + ${PROJECT_SOURCE_DIR}/libc/inc/stdbool.h + ${PROJECT_SOURCE_DIR}/libc/inc/stddef.h + ${PROJECT_SOURCE_DIR}/libc/inc/stdint.h + ${PROJECT_SOURCE_DIR}/libc/inc/stdio.h + ${PROJECT_SOURCE_DIR}/libc/inc/stdlib.h + ${PROJECT_SOURCE_DIR}/libc/inc/strerror.h + ${PROJECT_SOURCE_DIR}/libc/inc/string.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/bitops.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/dirent.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/errno.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/ioctl.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/kernel_levels.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/reboot.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/stat.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/types.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/unistd.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/utsname.h + ${PROJECT_SOURCE_DIR}/libc/inc/sys/wait.h + ${PROJECT_SOURCE_DIR}/libc/inc/system/syscall_types.h + ${PROJECT_SOURCE_DIR}/libc/inc/termios.h + ${PROJECT_SOURCE_DIR}/libc/inc/time.h + + ${PROJECT_SOURCE_DIR}/libc/src/abort.c + ${PROJECT_SOURCE_DIR}/libc/src/assert.c + ${PROJECT_SOURCE_DIR}/libc/src/ctype.c + ${PROJECT_SOURCE_DIR}/libc/src/fcvt.c + ${PROJECT_SOURCE_DIR}/libc/src/grp.c + ${PROJECT_SOURCE_DIR}/libc/src/io/debug.c + ${PROJECT_SOURCE_DIR}/libc/src/io/mm_io.c + ${PROJECT_SOURCE_DIR}/libc/src/io/port_io.c + ${PROJECT_SOURCE_DIR}/libc/src/ipc/ipc.c + ${PROJECT_SOURCE_DIR}/libc/src/libc_start.c + ${PROJECT_SOURCE_DIR}/libc/src/libgen.c + ${PROJECT_SOURCE_DIR}/libc/src/math.c + ${PROJECT_SOURCE_DIR}/libc/src/pwd.c + ${PROJECT_SOURCE_DIR}/libc/src/sched.c + ${PROJECT_SOURCE_DIR}/libc/src/setenv.c + ${PROJECT_SOURCE_DIR}/libc/src/stdio.c + ${PROJECT_SOURCE_DIR}/libc/src/stdlib.c + ${PROJECT_SOURCE_DIR}/libc/src/strerror.c + ${PROJECT_SOURCE_DIR}/libc/src/string.c + ${PROJECT_SOURCE_DIR}/libc/src/sys/errno.c + ${PROJECT_SOURCE_DIR}/libc/src/sys/ioctl.c + ${PROJECT_SOURCE_DIR}/libc/src/sys/unistd.c + ${PROJECT_SOURCE_DIR}/libc/src/sys/utsname.c + ${PROJECT_SOURCE_DIR}/libc/src/termios.c + ${PROJECT_SOURCE_DIR}/libc/src/time.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/chdir.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/close.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/creat.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/exec.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/exit.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/fork.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getcwd.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getdents.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getgid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getpgid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getpid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getppid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getsid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/getuid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/interval.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/kill.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/lseek.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/mkdir.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/nice.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/open.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/read.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/reboot.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/rmdir.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/setgid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/setpgid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/setsid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/setuid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/signal.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/stat.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/unlink.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/waitpid.c + ${PROJECT_SOURCE_DIR}/libc/src/unistd/write.c + ${PROJECT_SOURCE_DIR}/libc/src/vscanf.c + ${PROJECT_SOURCE_DIR}/libc/src/vsprintf.c + + ${PROJECT_SOURCE_DIR}/libc/src/crt0.S ) endif (DOXYGEN_FOUND) \ No newline at end of file diff --git a/doc/syscall.md b/doc/syscall.md index 3a01c3c..19596e5 100644 --- a/doc/syscall.md +++ b/doc/syscall.md @@ -7,6 +7,7 @@ specifically: 1. Implemented 2. Tested +X. Obsolete If the column is empty it means that it's not implemented yet. @@ -22,7 +23,7 @@ If the column is empty it means that it's not implemented yet. 2 | 5 | sys_open | fs/open.c | const char * | int | int | - | - | 2 | 6 | sys_close | fs/open.c | int | - | - | - | - | 2 | 7 | sys_waitpid | kernel/exit.c | pid_t | unsigned int * | int | - | - | - | 8 | sys_creat | fs/open.c | const char * | int | - | - | - | + 2 | 8 | sys_creat | fs/open.c | const char * | int | - | - | - | | 9 | sys_link | fs/namei.c | const char * | const char * | - | - | - | 2 | 10 | sys_unlink | fs/namei.c | const char * | - | - | - | - | 2 | 11 | sys_execve | arch/i386/kernel/process.c | struct pt_regs | - | - | - | - | @@ -36,11 +37,11 @@ If the column is empty it means that it's not implemented yet. 2 | 20 | sys_getpid | kernel/sched.c | - | - | - | - | - | | 21 | sys_mount | fs/super.c | char * | char * | char * | - | - | | 22 | sys_oldumount | fs/super.c | char * | - | - | - | - | - | 23 | sys_setuid | kernel/sys.c | uid_t | - | - | - | - | - | 24 | sys_getuid | kernel/sched.c | - | - | - | - | - | + 2 | 23 | sys_setuid | kernel/sys.c | uid_t | - | - | - | - | + 2 | 24 | sys_getuid | kernel/sched.c | - | - | - | - | - | | 25 | sys_stime | kernel/time.c | int * | - | - | - | - | | 26 | sys_ptrace | arch/i386/kernel/ptrace.c | long | long | long | long | - | - | 27 | sys_alarm | kernel/sched.c | unsigned int | - | - | - | - | + 2 | 27 | sys_alarm | kernel/sched.c | unsigned int | - | - | - | - | 2 | 28 | sys_fstat | fs/stat.c | unsigned int | struct __old_kernel_stat * | - | - | - | | 29 | sys_pause | arch/i386/kernel/sys_i386.c | - | - | - | - | - | | 30 | sys_utime | fs/open.c | char * | struct utimbuf * | - | - | - | @@ -55,8 +56,8 @@ If the column is empty it means that it's not implemented yet. | 42 | sys_pipe | arch/i386/kernel/sys_i386.c | unsigned long * | - | - | - | - | | 43 | sys_times | kernel/sys.c | struct tms * | - | - | - | - | 2 | 45 | sys_brk | mm/mmap.c | unsigned long | - | - | - | - | - | 46 | sys_setgid | kernel/sys.c | gid_t | - | - | - | - | - | 47 | sys_getgid | kernel/sched.c | - | - | - | - | - | + 2 | 46 | sys_setgid | kernel/sys.c | gid_t | - | - | - | - | + 2 | 47 | sys_getgid | kernel/sched.c | - | - | - | - | - | 1 | 48 | sys_signal | kernel/signal.c | int | __sighandler_t | - | - | - | | 49 | sys_geteuid | kernel/sched.c | - | - | - | - | - | | 50 | sys_getegid | kernel/sched.c | - | - | - | - | - | @@ -64,7 +65,7 @@ If the column is empty it means that it's not implemented yet. | 52 | sys_umount | fs/super.c | char * | int | - | - | - | 1 | 54 | sys_ioctl | fs/ioctl.c | unsigned int | unsigned int | unsigned long | - | - | | 55 | sys_fcntl | fs/fcntl.c | unsigned int | unsigned int | unsigned long | - | - | - | 57 | sys_setpgid | kernel/sys.c | pid_t | pid_t | - | - | - | + 2 | 57 | sys_setpgid | kernel/sys.c | pid_t | pid_t | - | - | - | | 59 | sys_olduname | arch/i386/kernel/sys_i386.c | struct oldold_utsname * | - | - | - | - | | 60 | sys_umask | kernel/sys.c | int | - | - | - | - | | 61 | sys_chroot | fs/open.c | const char * | - | - | - | - | @@ -72,10 +73,10 @@ If the column is empty it means that it's not implemented yet. | 63 | sys_dup2 | fs/fcntl.c | unsigned int | unsigned int | - | - | - | 2 | 64 | sys_getppid | kernel/sched.c | - | - | - | - | - | | 65 | sys_getpgrp | kernel/sys.c | - | - | - | - | - | - | 66 | sys_setsid | kernel/sys.c | - | - | - | - | - | + 2 | 66 | sys_setsid | kernel/sys.c | - | - | - | - | - | 1 | 67 | sys_sigaction | arch/i386/kernel/signal.c | int | const struct old_sigaction * | struct old_sigaction * | - | - | - | 68 | sys_sgetmask | kernel/signal.c | - | - | - | - | - | - | 69 | sys_ssetmask | kernel/signal.c | int | - | - | - | - | + X | 68 | sys_sgetmask | kernel/signal.c | - | - | - | - | - | + X | 69 | sys_ssetmask | kernel/signal.c | int | - | - | - | - | | 70 | sys_setreuid | kernel/sys.c | uid_t | uid_t | - | - | - | | 71 | sys_setregid | kernel/sys.c | gid_t | gid_t | - | - | - | | 72 | sys_sigsuspend | arch/i386/kernel/signal.c | int | int | old_sigset_t | - | - | diff --git a/iso/boot/grub/grub.cfg b/iso/boot/grub/grub.cfg index 71a17cf..3095edf 100644 --- a/iso/boot/grub/grub.cfg +++ b/iso/boot/grub/grub.cfg @@ -1,4 +1,4 @@ -set timeout=1 +set timeout=5 set default=0 menuentry "MentOS" { diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index ac759d2..bd8ae41 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -99,6 +99,7 @@ add_library( ${PROJECT_SOURCE_DIR}/src/abort.c ${PROJECT_SOURCE_DIR}/src/io/mm_io.c ${PROJECT_SOURCE_DIR}/src/io/port_io.c + ${PROJECT_SOURCE_DIR}/src/io/debug.c ${PROJECT_SOURCE_DIR}/src/ipc/ipc.c ${PROJECT_SOURCE_DIR}/src/sys/unistd.c ${PROJECT_SOURCE_DIR}/src/sys/errno.c @@ -137,7 +138,6 @@ add_library( ${PROJECT_SOURCE_DIR}/src/unistd/signal.c ${PROJECT_SOURCE_DIR}/src/unistd/interval.c ${PROJECT_SOURCE_DIR}/src/libc_start.c - ${PROJECT_SOURCE_DIR}/src/debug.c ${PROJECT_SOURCE_DIR}/src/crt0.S ) diff --git a/libc/inc/array.h b/libc/inc/array.h index c235398..b687027 100644 --- a/libc/inc/array.h +++ b/libc/inc/array.h @@ -1,6 +1,6 @@ /// @file array.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -34,5 +34,5 @@ ARRAY_FREE(arr->buffer); \ } -#undef ARRAY_ALLOC malloc -#undef ARRAY_FREE free \ No newline at end of file +#undef ARRAY_ALLOC +#undef ARRAY_FREE diff --git a/libc/inc/assert.h b/libc/inc/assert.h index 9b4630b..061affa 100644 --- a/libc/inc/assert.h +++ b/libc/inc/assert.h @@ -1,6 +1,6 @@ /// @file assert.h /// @brief Defines the function and pre-processor macro for assertions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/bits/ioctls.h b/libc/inc/bits/ioctls.h index cb74c6c..698541b 100644 --- a/libc/inc/bits/ioctls.h +++ b/libc/inc/bits/ioctls.h @@ -1,6 +1,6 @@ /// @file ioctls.h /// @brief Input/Output ConTroL (IOCTL) numbers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/bits/stat.h b/libc/inc/bits/stat.h index 3122221..edc5856 100644 --- a/libc/inc/bits/stat.h +++ b/libc/inc/bits/stat.h @@ -1,6 +1,6 @@ /// @file stat.h /// @brief Defines the structure used by the functiosn fstat(), lstat(), and stat(). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/bits/termios-struct.h b/libc/inc/bits/termios-struct.h index b8171b9..a104fdf 100644 --- a/libc/inc/bits/termios-struct.h +++ b/libc/inc/bits/termios-struct.h @@ -1,6 +1,6 @@ /// @file termios-struct.h /// @brief Definition of the `termios` structure. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/ctype.h b/libc/inc/ctype.h index e3cf80a..49240f7 100644 --- a/libc/inc/ctype.h +++ b/libc/inc/ctype.h @@ -1,6 +1,6 @@ /// @file ctype.h /// @brief Functions related to character handling. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/debug.h b/libc/inc/debug.h deleted file mode 100644 index 39c52fc..0000000 --- a/libc/inc/debug.h +++ /dev/null @@ -1,44 +0,0 @@ -/// @file debug.h -/// @brief Debugging primitives. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. -/// See LICENSE.md for details. - -#pragma once - -#ifndef __DEBUG_HEADER__ -/// Header for identifying outputs coming from a mechanism. -#define __DEBUG_HEADER__ -#endif - -/// @brief Extract the filename from the full path provided by __FILE__. -#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) - -/// @brief Prints the given character to debug output. -/// @param c The character to print. -void dbg_putchar(char c); - -/// @brief Prints the given string to debug output. -/// @param s The string to print. -void dbg_puts(const char *s); - -/// @brief Prints the given string to the debug output. -/// @param file The name of the file. -/// @param fun The name of the function. -/// @param line The line inside the file. -/// @param format The format to used, see printf. -/// @param ... The list of arguments. -void dbg_printf(const char *file, const char *fun, int line, const char *format, ...); - -/// @brief Transforms the given amount of bytes to a readable string. -/// @param bytes The bytes to turn to string. -/// @return String representing the bytes in human readable form. -const char *to_human_size(unsigned long bytes); - -/// @brief Transforms the given value to a binary string. -/// @param value to print. -/// @param length of the binary output. -/// @return String representing the binary value. -const char *dec_to_binary(unsigned long value, unsigned length); - -/// Prints a debugging message. -#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__ __VA_ARGS__) diff --git a/libc/inc/fcntl.h b/libc/inc/fcntl.h index 24b767b..4d7310e 100644 --- a/libc/inc/fcntl.h +++ b/libc/inc/fcntl.h @@ -1,6 +1,6 @@ /// @file fcntl.h /// @brief Headers of functions fcntl() and open(). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/fcvt.h b/libc/inc/fcvt.h index de0d7cb..e77650f 100644 --- a/libc/inc/fcvt.h +++ b/libc/inc/fcvt.h @@ -1,6 +1,6 @@ /// @file fcvt.h /// @brief Declare the functions required to turn double values into a string. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/grp.h b/libc/inc/grp.h index 7d725f5..8aeb5d0 100644 --- a/libc/inc/grp.h +++ b/libc/inc/grp.h @@ -1,6 +1,6 @@ /// @file grp.h /// @brief Defines the structures and functions for managing groups. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/programs/ansi_colors.h b/libc/inc/io/ansi_colors.h similarity index 96% rename from programs/ansi_colors.h rename to libc/inc/io/ansi_colors.h index 65b9cc6..ec518ee 100644 --- a/programs/ansi_colors.h +++ b/libc/inc/io/ansi_colors.h @@ -1,6 +1,7 @@ /// @file ansi_colors.h -/// @author Enrico Fraccaroli (enry.frak@gmail.com) -/// @brief Macros for ANSI colors. +/// @brief List of ANSI colors. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. +/// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/io/debug.h b/libc/inc/io/debug.h similarity index 69% rename from mentos/inc/io/debug.h rename to libc/inc/io/debug.h index 45dac64..205964d 100644 --- a/mentos/inc/io/debug.h +++ b/libc/inc/io/debug.h @@ -1,16 +1,14 @@ /// @file debug.h /// @brief Debugging primitives. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once #include "sys/kernel_levels.h" -struct pt_regs; - #ifndef __DEBUG_LEVEL__ -/// Defines the debug level. +/// Defines the debug level, by default we set it to notice. #define __DEBUG_LEVEL__ LOGLEVEL_NOTICE #endif @@ -39,17 +37,14 @@ void dbg_putchar(char c); void dbg_puts(const char *s); /// @brief Prints the given string to the debug output. -/// @param file The name of the file. -/// @param fun The name of the function. -/// @param line The line inside the file. -/// @param header The header to print. -/// @param format The format to used, see printf. -/// @param ... The list of arguments. -void dbg_printf(const char *file, const char *fun, int line, char *header, const char *format, ...); - -/// @brief Prints the registers on debug output. -/// @param frame Pointer to the register. -void dbg_print_regs(struct pt_regs *frame); +/// @param file the name of the file. +/// @param fun the name of the function. +/// @param line the line inside the file. +/// @param header the header to print. +/// @param log_level the log level. +/// @param format the format to used, see printf. +/// @param ... the list of arguments. +void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...); /// @brief Transforms the given amount of bytes to a readable string. /// @param bytes The bytes to turn to string. @@ -62,53 +57,71 @@ const char *to_human_size(unsigned long bytes); /// @return String representing the binary value. const char *dec_to_binary(unsigned long value, unsigned length); -/// Prints a KERN_DEFAULT. -#define pr_default(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_DEFAULT __VA_ARGS__) -/// Prints a KERN_EMERG. +/// Prints a default message, which is always shown. +#define pr_default(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEFAULT, __VA_ARGS__) + +/// Prints an emergency message. #if __DEBUG_LEVEL__ >= LOGLEVEL_EMERG -#define pr_emerg(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_EMERG __VA_ARGS__) +#define pr_emerg(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_EMERG, __VA_ARGS__) #else #define pr_emerg(...) #endif -/// Prints a KERN_ALERT. + +/// Prints an alert message. #if __DEBUG_LEVEL__ >= LOGLEVEL_ALERT -#define pr_alert(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_ALERT __VA_ARGS__) +#define pr_alert(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ALERT, __VA_ARGS__) #else #define pr_alert(...) #endif -/// Prints a KERN_CRIT. + +/// Prints a critical message. #if __DEBUG_LEVEL__ >= LOGLEVEL_CRIT -#define pr_crit(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_CRIT __VA_ARGS__) +#define pr_crit(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_CRIT, __VA_ARGS__) #else #define pr_crit(...) #endif -/// Prints a KERN_ERR. + +/// Prints an error message. #if __DEBUG_LEVEL__ >= LOGLEVEL_ERR -#define pr_err(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_ERR __VA_ARGS__) +#define pr_err(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ERR, __VA_ARGS__) #else #define pr_err(...) #endif -/// Prints a KERN_WARNING. + +/// Prints a warning message. #if __DEBUG_LEVEL__ >= LOGLEVEL_WARNING -#define pr_warning(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_WARNING __VA_ARGS__) +#define pr_warning(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_WARNING, __VA_ARGS__) #else #define pr_warning(...) #endif -/// Prints a KERN_NOTICE. + +/// Prints a notice message. #if __DEBUG_LEVEL__ >= LOGLEVEL_NOTICE -#define pr_notice(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_NOTICE __VA_ARGS__) +#define pr_notice(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_NOTICE, __VA_ARGS__) #else #define pr_notice(...) #endif -/// Prints a KERN_INFO. + +/// Prints a info message. #if __DEBUG_LEVEL__ >= LOGLEVEL_INFO -#define pr_info(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_INFO __VA_ARGS__) +#define pr_info(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_INFO, __VA_ARGS__) #else #define pr_info(...) #endif -/// Prints a KERN_DEBUG. + +/// Prints a debug message. #if __DEBUG_LEVEL__ >= LOGLEVEL_DEBUG -#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, KERN_DEBUG __VA_ARGS__) +#define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEBUG, __VA_ARGS__) #else #define pr_debug(...) #endif + +#ifdef __KERNEL__ + +struct pt_regs; + +/// @brief Prints the registers on debug output. +/// @param frame Pointer to the register. +void dbg_print_regs(struct pt_regs *frame); + +#endif diff --git a/libc/inc/io/mm_io.h b/libc/inc/io/mm_io.h index 1eecdae..255ff43 100644 --- a/libc/inc/io/mm_io.h +++ b/libc/inc/io/mm_io.h @@ -1,6 +1,6 @@ /// @file mm_io.h /// @brief Memory Mapped IO functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -8,19 +8,31 @@ #include "stdint.h" /// @brief Reads a 8-bit value from the given address. +/// @param addr the address we want to read from. +/// @return the value we read. uint8_t in_memb(uint32_t addr); /// @brief Reads a 16-bit value from the given address. +/// @param addr the address we want to read from. +/// @return the value we read. uint16_t in_mems(uint32_t addr); /// @brief Reads a 32-bit value from the given address. +/// @param addr the address we want to read from. +/// @return the value we read. uint32_t in_meml(uint32_t addr); /// @brief Writes a 8-bit value at the given address. +/// @param addr the address we want to write to. +/// @param value the value we want to write. void out_memb(uint32_t addr, uint8_t value); /// @brief Writes a 16-bit value at the given address. +/// @param addr the address we want to write to. +/// @param value the value we want to write. void out_mems(uint32_t addr, uint16_t value); /// @brief Writes a 32-bit value at the given address. +/// @param addr the address we want to write to. +/// @param value the value we want to write. void out_meml(uint32_t addr, uint32_t value); diff --git a/libc/inc/io/port_io.h b/libc/inc/io/port_io.h index 2f6871c..ef0bab1 100644 --- a/libc/inc/io/port_io.h +++ b/libc/inc/io/port_io.h @@ -1,42 +1,50 @@ /// @file port_io.h /// @brief Byte I/O on ports prototypes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once #include "stdint.h" -/// @brief Used for reading from the I/O ports. -/// @param port The input port. -/// @return The read value. +/// @brief Reads a 8-bit value from the given port. +/// @param port the port we want to read from. +/// @return the value we read. uint8_t inportb(uint16_t port); -/// @brief Used for reading 2 bytes from the I/O ports. -/// @param port The input port. -/// @return The read value. +/// @brief Reads a 16-bit value from the given port. +/// @param port the port we want to read from. +/// @return the value we read. uint16_t inports(uint16_t port); -void inportsm(uint16_t port, uint8_t *data, unsigned long size); - -/// @brief Used for reading 4 bytes from the I/O ports. -/// @param port The input port. -/// @return The read value. +/// @brief Reads a 32-bit value from the given port. +/// @param port the port we want to read from. +/// @return the value we read. uint32_t inportl(uint16_t port); -/// @brief Use this to write to I/O ports to send bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outportb(uint16_t port, uint8_t data); +/// @brief Writes a 8-bit value at the given port. +/// @param port the port we want to write to. +/// @param value the value we want to write. +void outportb(uint16_t port, uint8_t value); -/// @brief Use this to write to I/O ports to send 2 bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outports(uint16_t port, uint16_t data); +/// @brief Writes a 16-bit value at the given port. +/// @param port the port we want to write to. +/// @param value the value we want to write. +void outports(uint16_t port, uint16_t value); -void outportsm(uint16_t port, uint8_t *data, uint16_t size); +/// @brief Writes a 32-bit value at the given port. +/// @param port the port we want to write to. +/// @param value the value we want to write. +void outportl(uint16_t port, uint32_t value); -/// @brief Use this to write to I/O ports to send 4 bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outportl(uint16_t port, uint32_t data); +/// @brief Reads multiple 16-bit values from the given port. +/// @param port the port we want to read from. +/// @param value the location where we store the values we read. +/// @param size the amount of values we want to read. +void inportsm(uint16_t port, uint8_t *value, unsigned long size); + +/// @brief Writes multiple 16-bit values to the given port. +/// @param port the port we want to write to. +/// @param value the location where we get the values we need to write. +/// @param size the amount of values we want to write. +void outportsm(uint16_t port, uint8_t *value, uint16_t size); diff --git a/libc/inc/ipc/ipc.h b/libc/inc/ipc/ipc.h index 1cd888e..ed2413d 100644 --- a/libc/inc/ipc/ipc.h +++ b/libc/inc/ipc/ipc.h @@ -1,6 +1,6 @@ /// @file ipc.h /// @brief Inter-Process Communication (IPC) structures. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/ipc/msg.h b/libc/inc/ipc/msg.h index b7a9656..c04e958 100644 --- a/libc/inc/ipc/msg.h +++ b/libc/inc/ipc/msg.h @@ -1,6 +1,6 @@ /// @file msg.h /// @brief Definition of structure for managing message queues. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/ipc/sem.h b/libc/inc/ipc/sem.h index 4b72c34..6d5f0c9 100644 --- a/libc/inc/ipc/sem.h +++ b/libc/inc/ipc/sem.h @@ -1,6 +1,6 @@ /// @file sem.h /// @brief Definition of structure for managing semaphores. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/ipc/shm.h b/libc/inc/ipc/shm.h index 8b1965b..deb9192 100644 --- a/libc/inc/ipc/shm.h +++ b/libc/inc/ipc/shm.h @@ -1,6 +1,6 @@ /// @file shm.h /// @brief Definition of structure for managing shared memories. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/libgen.h b/libc/inc/libgen.h index 72585c6..34869eb 100644 --- a/libc/inc/libgen.h +++ b/libc/inc/libgen.h @@ -1,6 +1,6 @@ /// @file libgen.h /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "stddef.h" diff --git a/libc/inc/limits.h b/libc/inc/limits.h index a0cce66..6a18610 100644 --- a/libc/inc/limits.h +++ b/libc/inc/limits.h @@ -1,6 +1,6 @@ /// @file limits.h /// @brief OS numeric limits. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/math.h b/libc/inc/math.h index 1547d8c..981bdd6 100644 --- a/libc/inc/math.h +++ b/libc/inc/math.h @@ -1,6 +1,6 @@ /// @file math.h /// @brief Mathematical constants and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/pwd.h b/libc/inc/pwd.h index aa3271b..67349df 100644 --- a/libc/inc/pwd.h +++ b/libc/inc/pwd.h @@ -1,6 +1,6 @@ /// @file pwd.h /// @brief Contains the structure and functions for managing passwords. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/ring_buffer.h b/libc/inc/ring_buffer.h index 6d8b09f..64410e6 100644 --- a/libc/inc/ring_buffer.h +++ b/libc/inc/ring_buffer.h @@ -1,6 +1,6 @@ /// @file ring_buffer.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sched.h b/libc/inc/sched.h index 73df580..8f2c4b2 100644 --- a/libc/inc/sched.h +++ b/libc/inc/sched.h @@ -1,6 +1,6 @@ /// @file sched.h /// @brief Structures and functions for managing the scheduler. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/types.h" diff --git a/libc/inc/signal.h b/libc/inc/signal.h index a07b7bd..f82785b 100644 --- a/libc/inc/signal.h +++ b/libc/inc/signal.h @@ -1,6 +1,6 @@ /// @file signal.h /// @brief Signals definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/stdarg.h b/libc/inc/stdarg.h index f24dda3..9d754e3 100644 --- a/libc/inc/stdarg.h +++ b/libc/inc/stdarg.h @@ -1,6 +1,6 @@ /// @file stdarg.h /// @brief Contains the macros required to manage variable number of arguments. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/stdbool.h b/libc/inc/stdbool.h index a4c2618..80b523e 100644 --- a/libc/inc/stdbool.h +++ b/libc/inc/stdbool.h @@ -1,6 +1,6 @@ /// @file stdbool.h /// @brief Defines the boolean values. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/stddef.h b/libc/inc/stddef.h index 5c95d4d..6752a72 100644 --- a/libc/inc/stddef.h +++ b/libc/inc/stddef.h @@ -1,6 +1,6 @@ /// @file stddef.h /// @brief Define basic data types. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/stdint.h b/libc/inc/stdint.h index 855be23..4edf19b 100644 --- a/libc/inc/stdint.h +++ b/libc/inc/stdint.h @@ -1,6 +1,6 @@ /// @file stdint.h /// @brief Standard integer data-types. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/stdio.h b/libc/inc/stdio.h index 1f3692d..460836a 100644 --- a/libc/inc/stdio.h +++ b/libc/inc/stdio.h @@ -1,6 +1,6 @@ /// @file stdio.h /// @brief Standard I/0 functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -30,7 +30,7 @@ void putchar(int character); /// @brief Writes the string pointed by str to the standard output (stdout) /// and appends a newline character. /// @param str The string to send to stdout. -void puts(char *str); +void puts(const char *str); /// @brief Returns the next character from the standard input (stdin). /// @return The character received from stdin. @@ -124,3 +124,7 @@ int sscanf(const char *str, const char *fmt, ...); /// argument list successfully filled. EOF otherwise. int fscanf(int fd, const char *fmt, ...); #endif + +/// @brief Prints a system error message. +/// @param s the message we prepend to the actual error message. +void perror(const char *s); \ No newline at end of file diff --git a/libc/inc/stdlib.h b/libc/inc/stdlib.h index 4da327d..76fe92c 100644 --- a/libc/inc/stdlib.h +++ b/libc/inc/stdlib.h @@ -1,12 +1,15 @@ /// @file stdlib.h /// @brief Useful generic functions and macros. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once #include "stddef.h" +#define EXIT_SUCCESS 0 ///< Successful execution of a program. +#define EXIT_FAILURE 1 ///< Unsuccessful execution of a program. + /// @brief Returns the number of usable bytes in the block pointed to by ptr. /// @param ptr The pointer for which we want to retrieve the usable size. /// @return The number of usable bytes in the block of allocated memory diff --git a/libc/inc/strerror.h b/libc/inc/strerror.h index d6a0aed..ea9c406 100644 --- a/libc/inc/strerror.h +++ b/libc/inc/strerror.h @@ -1,6 +1,6 @@ /// @file strerror.h /// @brief Contains the function that transfornms an errno into a string. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/string.h b/libc/inc/string.h index d7b386e..eb6f84b 100644 --- a/libc/inc/string.h +++ b/libc/inc/string.h @@ -1,6 +1,6 @@ /// @file string.h /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/bitops.h b/libc/inc/sys/bitops.h index 53a77c4..98cdf73 100644 --- a/libc/inc/sys/bitops.h +++ b/libc/inc/sys/bitops.h @@ -1,6 +1,6 @@ /// @file bitops.h /// @brief Bitmasks functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/dirent.h b/libc/inc/sys/dirent.h index 06745f0..9af04ec 100644 --- a/libc/inc/sys/dirent.h +++ b/libc/inc/sys/dirent.h @@ -1,6 +1,6 @@ /// @file dirent.h /// @brief Functions used to manage directories. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/errno.h b/libc/inc/sys/errno.h index df957da..d815ed3 100644 --- a/libc/inc/sys/errno.h +++ b/libc/inc/sys/errno.h @@ -1,6 +1,6 @@ /// @file errno.h /// @brief System call errors definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/ioctl.h b/libc/inc/sys/ioctl.h index 3b54fbe..6eac0c7 100644 --- a/libc/inc/sys/ioctl.h +++ b/libc/inc/sys/ioctl.h @@ -1,6 +1,6 @@ /// @file ioctl.h /// @brief Input/Output ConTroL (IOCTL) functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/kernel_levels.h b/libc/inc/sys/kernel_levels.h new file mode 100644 index 0000000..c9ff24e --- /dev/null +++ b/libc/inc/sys/kernel_levels.h @@ -0,0 +1,17 @@ +/// @file kernel_levels.h +/// @brief +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. +/// See LICENSE.md for details. + +#pragma once + +// Integer equivalents of KERN_ +#define LOGLEVEL_DEFAULT (-1) ///< default-level messages. +#define LOGLEVEL_EMERG 0 ///< system is unusable. +#define LOGLEVEL_ALERT 1 ///< action must be taken immediately. +#define LOGLEVEL_CRIT 2 ///< critical conditions. +#define LOGLEVEL_ERR 3 ///< error conditions. +#define LOGLEVEL_WARNING 4 ///< warning conditions. +#define LOGLEVEL_NOTICE 5 ///< normal but significant condition. +#define LOGLEVEL_INFO 6 ///< informational. +#define LOGLEVEL_DEBUG 7 ///< debug-level messages. diff --git a/libc/inc/sys/reboot.h b/libc/inc/sys/reboot.h index fbf4529..b68b019 100644 --- a/libc/inc/sys/reboot.h +++ b/libc/inc/sys/reboot.h @@ -1,6 +1,6 @@ /// @file reboot.h /// @brief Defines the values required to issue a reboot. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/stat.h b/libc/inc/sys/stat.h index 4154c80..3b55cd4 100644 --- a/libc/inc/sys/stat.h +++ b/libc/inc/sys/stat.h @@ -1,6 +1,6 @@ /// @file stat.h /// @brief Stat functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/types.h b/libc/inc/sys/types.h index 424a076..35276fe 100644 --- a/libc/inc/sys/types.h +++ b/libc/inc/sys/types.h @@ -1,6 +1,6 @@ /// @file types.h /// @brief Collection of Kernel datatype -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/unistd.h b/libc/inc/sys/unistd.h index 691d66e..55be6e3 100644 --- a/libc/inc/sys/unistd.h +++ b/libc/inc/sys/unistd.h @@ -1,6 +1,6 @@ /// @file unistd.h /// @brief Functions used to manage files. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -25,7 +25,7 @@ ssize_t read(int fd, void *buf, size_t nbytes); /// @param buf The buffer collecting data to written. /// @param nbytes The number of bytes to write. /// @return The number of written bytes. -ssize_t write(int fd, void *buf, size_t nbytes); +ssize_t write(int fd, const void *buf, size_t nbytes); /// @brief Opens the file specified by pathname. /// @param pathname A pathname for a file. @@ -238,7 +238,7 @@ int fchdir(int fd); /// @return On success, the number of bytes read is returned. On end of /// directory, 0 is returned. On error, -1 is returned, and errno is set /// appropriately. -int getdents(int fd, dirent_t *dirp, unsigned int count); +ssize_t getdents(int fd, dirent_t *dirp, unsigned int count); /// @brief Send signal to calling thread after desired seconds. /// @param seconds the amount of seconds. diff --git a/libc/inc/sys/utsname.h b/libc/inc/sys/utsname.h index ca72a16..1d66ba5 100644 --- a/libc/inc/sys/utsname.h +++ b/libc/inc/sys/utsname.h @@ -1,6 +1,6 @@ /// @file utsname.h /// @brief Functions used to provide information about the machine & OS. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/sys/wait.h b/libc/inc/sys/wait.h index bb75e77..a4b1f2c 100644 --- a/libc/inc/sys/wait.h +++ b/libc/inc/sys/wait.h @@ -1,6 +1,6 @@ /// @file wait.h /// @brief Event management functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/system/syscall_types.h b/libc/inc/system/syscall_types.h index 668322c..6c29f8c 100644 --- a/libc/inc/system/syscall_types.h +++ b/libc/inc/system/syscall_types.h @@ -1,6 +1,6 @@ /// @file syscall_types.h /// @brief System Call numbers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -217,39 +217,36 @@ #define __inline_syscall1(res, name, arg1) \ __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ : "=a"(res) \ - : "0"(__NR_##name), "ri"((int)(arg1)) \ + : "0"(__NR_##name), "ri"(arg1) \ : "memory"); /// @brief Heart of the code that calls a system call with 2 parameters. -#define __inline_syscall2(res, name, arg1, arg2) \ - __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ - : "=a"(res) \ - : "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)) \ +#define __inline_syscall2(res, name, arg1, arg2) \ + __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ + : "=a"(res) \ + : "0"(__NR_##name), "ri"(arg1), "c"(arg2) \ : "memory"); /// @brief Heart of the code that calls a system call with 3 parameters. -#define __inline_syscall3(res, name, arg1, arg2, arg3) \ - __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ - : "=a"(res) \ - : "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \ - "d"((int)(arg3)) \ +#define __inline_syscall3(res, name, arg1, arg2, arg3) \ + __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ + : "=a"(res) \ + : "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3) \ : "memory"); /// @brief Heart of the code that calls a system call with 4 parameters. -#define __inline_syscall4(res, name, arg1, arg2, arg3, arg4) \ - __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ - : "=a"(res) \ - : "0"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \ - "d"((int)(arg3)), "S"((int)(arg4)) \ +#define __inline_syscall4(res, name, arg1, arg2, arg3, arg4) \ + __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ + : "=a"(res) \ + : "0"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4) \ : "memory"); /// @brief Heart of the code that calls a system call with 5 parameters. -#define __inline_syscall5(res, name, arg1, arg2, arg3, arg4, arg5) \ - __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \ - "int $0x80 ; pop %%ebx" \ - : "=a"(res) \ - : "i"(__NR_##name), "ri"((int)(arg1)), "c"((int)(arg2)), \ - "d"((int)(arg3)), "S"((int)(arg4)), "D"((int)(arg5)) \ +#define __inline_syscall5(res, name, arg1, arg2, arg3, arg4, arg5) \ + __asm__ __volatile__("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \ + "int $0x80 ; pop %%ebx" \ + : "=a"(res) \ + : "i"(__NR_##name), "ri"(arg1), "c"(arg2), "d"(arg3), "S"(arg4), "D"(arg5) \ : "memory"); /// @brief System call with 0 parameters. diff --git a/libc/inc/termios.h b/libc/inc/termios.h index b61fa27..288d21a 100644 --- a/libc/inc/termios.h +++ b/libc/inc/termios.h @@ -1,6 +1,6 @@ /// @file termios.h /// @brief Defines the termios functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/inc/time.h b/libc/inc/time.h index 663eb2a..f8ffde4 100644 --- a/libc/inc/time.h +++ b/libc/inc/time.h @@ -1,6 +1,6 @@ /// @file time.h /// @brief Time-related functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/libc/src/abort.c b/libc/src/abort.c index 4d4862f..5596b77 100644 --- a/libc/src/abort.c +++ b/libc/src/abort.c @@ -1,6 +1,6 @@ /// @file abort.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/assert.c b/libc/src/assert.c index accb6ca..cbb53a6 100644 --- a/libc/src/assert.c +++ b/libc/src/assert.c @@ -1,6 +1,6 @@ /// @file assert.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "assert.h" diff --git a/libc/src/ctype.c b/libc/src/ctype.c index c74c9db..dcd4244 100644 --- a/libc/src/ctype.c +++ b/libc/src/ctype.c @@ -1,6 +1,6 @@ /// @file ctype.c /// @brief Functions related to character handling. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "ctype.h" diff --git a/libc/src/debug.c b/libc/src/debug.c deleted file mode 100644 index 8682c38..0000000 --- a/libc/src/debug.c +++ /dev/null @@ -1,108 +0,0 @@ -/// @file debug.c -/// @brief Debugging primitives. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. -/// See LICENSE.md for details. - -#include - -#include -#include -#include -#include -#include -#include - -/// Serial port for QEMU. -#define SERIAL_COM1 (0x03F8) - -#define FG_RESET "\033[0m" ///< ANSI code for resetting. - -void dbg_putchar(char c) -{ - outportb(SERIAL_COM1, (uint8_t)c); -} - -void dbg_puts(const char *s) -{ - while ((*s) != 0) - dbg_putchar(*s++); -} - -static inline void __debug_print_header(const char *file, const char *fun, int line) -{ - static char tmp_prefix[BUFSIZ], final_prefix[BUFSIZ]; - dbg_puts(FG_RESET); - dbg_puts("[ LB |"); - sprintf(tmp_prefix, "%s:%d", file, line); - sprintf(final_prefix, " %-20s ", tmp_prefix); - dbg_puts(final_prefix); -#if 0 - dbg_putchar('|'); - sprintf(final_prefix, " %-25s ]", fun); - dbg_puts(final_prefix); -#else - dbg_putchar(']'); -#endif -} - -void dbg_printf(const char *file, const char *fun, int line, const char *format, ...) -{ - // Define a buffer for the formatted string. - static char formatted[BUFSIZ]; - static short new_line = 1; - - // Stage 1: FORMAT - if (strlen(format) >= BUFSIZ) - return; - - // Start variabile argument's list. - va_list ap; - va_start(ap, format); - // Format the message. - vsprintf(formatted, format, ap); - // End the list of arguments. - va_end(ap); - - // Stage 2: SEND - if (new_line) { - __debug_print_header(file, fun, line); - new_line = 0; - } - for (size_t it = 0; (formatted[it] != 0) && (it < BUFSIZ); ++it) { - dbg_putchar(formatted[it]); - if (formatted[it] != '\n') { - continue; - } - if ((it + 1) >= BUFSIZ) { - continue; - } - if (formatted[it + 1] == 0) { - new_line = 1; - } else { - __debug_print_header(file, fun, line); - } - } -} - -const char *to_human_size(unsigned long bytes) -{ - static char output[200]; - const char *suffix[] = { "B", "KB", "MB", "GB", "TB" }; - char length = sizeof(suffix) / sizeof(suffix[0]); - int i = 0; - double dblBytes = bytes; - if (bytes > 1024) { - for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024) - dblBytes = bytes / 1024.0; - } - sprintf(output, "%.03lf %2s", dblBytes, suffix[i]); - return output; -} - -const char *dec_to_binary(unsigned long value, unsigned length) -{ - static char buffer[33]; - for (int i = 0, j = 32 - min(max(0, length), 32); j < 32; ++i, ++j) - buffer[i] = bit_check(value, 31 - j) ? '1' : '0'; - return buffer; -} diff --git a/libc/src/fcvt.c b/libc/src/fcvt.c index f3e61cb..6b5f1b5 100644 --- a/libc/src/fcvt.c +++ b/libc/src/fcvt.c @@ -1,6 +1,6 @@ /// @file fcvt.c /// @brief Define the functions required to turn double values into a string. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fcvt.h" diff --git a/libc/src/grp.c b/libc/src/grp.c index 1a55bc8..5ae5fe6 100644 --- a/libc/src/grp.c +++ b/libc/src/grp.c @@ -1,17 +1,18 @@ /// @file grp.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "grp.h" #include "sys/unistd.h" #include "sys/errno.h" +#include "io/debug.h" #include "assert.h" #include "string.h" #include "stdio.h" -#include "debug.h" #include "fcntl.h" +/// Holds the file descriptor while we are working with `/etc/group`. static int __fd = -1; /// @brief It parses the line (as string) and saves its content inside the @@ -42,6 +43,13 @@ static inline void __parse_line(group_t *grp, char *buf) grp->gr_mem[found_users] = "\0"; } +/// @brief Searches an entry in `/etc/group`. +/// @param fd the file descriptor pointing to `/etc/group`. +/// @param buf the buffer we are going to use to search the entry. +/// @param buflen the length of the buffer. +/// @param name the name we are looking for. +/// @param gid the group id we must match. +/// @return a pointer to the filled input buffer on success, NULL on failure. static inline char *__search_entry(int fd, char *buf, int buflen, const char *name, gid_t gid) { int ret; diff --git a/libc/src/io/debug.c b/libc/src/io/debug.c new file mode 100644 index 0000000..ae3a0eb --- /dev/null +++ b/libc/src/io/debug.c @@ -0,0 +1,179 @@ +/// @file debug.c +/// @brief Debugging primitives. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. +/// See LICENSE.md for details. + +#include "io/debug.h" +#include "io/port_io.h" +#include "io/ansi_colors.h" +#include "sys/bitops.h" +#include "string.h" +#include "stdio.h" +#include "math.h" + +/// Serial port for QEMU. +#define SERIAL_COM1 (0x03F8) +/// Determines the log level. +static int max_log_level = LOGLEVEL_DEBUG; + +void dbg_putchar(char c) +{ + outportb(SERIAL_COM1, (uint8_t)c); +} + +void dbg_puts(const char *s) +{ + while ((*s) != 0) + dbg_putchar(*s++); +} + +static inline void __debug_print_header(const char *file, const char *fun, int line, short log_level, char *header) +{ + // "EMERG ", "ALERT ", "CRIT ", "ERR ", "WARNING", "NOTICE ", "INFO ", "DEBUG ", "DEFAULT", + static const char *log_level_label[] = { " EM ", " AL ", " CR ", " ER ", " WR ", " NT ", " IN ", " DB ", " DF " }; + static const char *log_level_color[] = { + FG_RED_BRIGHT, // "EMERG " + FG_RED_BRIGHT, // "ALERT " + FG_RED, // "CRIT " + FG_RED, // "ERR " + FG_YELLOW_BRIGHT, // "WARNING" + FG_RESET, // "NOTICE " + FG_CYAN, // "INFO " + FG_YELLOW, // "DEBUG " + FG_RESET // "DEFAULT" + }; + static char tmp_prefix[BUFSIZ], final_prefix[BUFSIZ]; + // Check the log level. + if ((log_level < LOGLEVEL_EMERG) || (log_level > LOGLEVEL_DEBUG)) { + // Set it to default. + log_level = 8; + } + // Set the color. + dbg_puts(log_level_color[log_level]); + dbg_putchar('['); + // Set the label. + dbg_puts(log_level_label[log_level]); + dbg_putchar('|'); + // Print the file and line. + sprintf(tmp_prefix, "%s:%d", file, line); + // Print the message. + sprintf(final_prefix, " %-20s ", tmp_prefix); + // Print the actual message. + dbg_puts(final_prefix); +#if 0 + dbg_putchar('|'); + sprintf(final_prefix, " %-25s ]", fun); + dbg_puts(final_prefix); +#else + dbg_putchar(']'); +#endif + dbg_putchar(' '); + if (header) { + dbg_puts(header); + dbg_putchar(' '); + } +} + +void set_log_level(int level) +{ + if ((level >= LOGLEVEL_EMERG) && (level <= LOGLEVEL_DEBUG)) + max_log_level = level; +} + +int get_log_level() +{ + return max_log_level; +} + +void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...) +{ + // Define a buffer for the formatted string. + static char formatted[BUFSIZ]; + static short new_line = 1; + + // Stage 1: FORMAT + if (strlen(format) >= BUFSIZ) + return; + + // Start variabile argument's list. + va_list ap; + va_start(ap, format); + // Format the message. + vsprintf(formatted, format, ap); + // End the list of arguments. + va_end(ap); + + // Stage 2: SEND + if (new_line) { + __debug_print_header(file, fun, line, log_level, header); + new_line = 0; + } + for (int it = 0; (formatted[it] != 0) && (it < BUFSIZ); ++it) { + dbg_putchar(formatted[it]); + if (formatted[it] != '\n') { + continue; + } + if ((it + 1) >= BUFSIZ) { + continue; + } + if (formatted[it + 1] == 0) { + new_line = 1; + } else { + __debug_print_header(file, fun, line, log_level, header); + } + } +} + +const char *to_human_size(unsigned long bytes) +{ + static char output[200]; + const char *suffix[] = { "B", "KB", "MB", "GB", "TB" }; + char length = sizeof(suffix) / sizeof(suffix[0]); + int i = 0; + double dblBytes = bytes; + if (bytes > 1024) { + for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024) + dblBytes = bytes / 1024.0; + } + sprintf(output, "%.02lf %2s", dblBytes, suffix[i]); + return output; +} + +const char *dec_to_binary(unsigned long value, unsigned length) +{ + static char buffer[33]; + memset(buffer, 0, 33); + for (int i = 0, j = 32 - min(max(0, length), 32); j < 32; ++i, ++j) + buffer[i] = bit_check(value, 31 - j) ? '1' : '0'; + return buffer; +} + +#ifdef __KERNEL__ + +#include "kernel.h" + +void dbg_print_regs(pt_regs *frame) +{ + pr_debug("Interrupt stack frame:\n"); + pr_debug("GS = 0x%-04x\n", frame->gs); + pr_debug("FS = 0x%-04x\n", frame->fs); + pr_debug("ES = 0x%-04x\n", frame->es); + pr_debug("DS = 0x%-04x\n", frame->ds); + pr_debug("EDI = 0x%-09x\n", frame->edi); + pr_debug("ESI = 0x%-09x\n", frame->esi); + pr_debug("EBP = 0x%-09x\n", frame->ebp); + pr_debug("ESP = 0x%-09x\n", frame->esp); + pr_debug("EBX = 0x%-09x\n", frame->ebx); + pr_debug("EDX = 0x%-09x\n", frame->edx); + pr_debug("ECX = 0x%-09x\n", frame->ecx); + pr_debug("EAX = 0x%-09x\n", frame->eax); + pr_debug("INT_NO = %-9d\n", frame->int_no); + pr_debug("ERR_CD = %-9d\n", frame->err_code); + pr_debug("EIP = 0x%-09x\n", frame->eip); + pr_debug("CS = 0x%-04x\n", frame->cs); + pr_debug("EFLAGS = 0x%-09x\n", frame->eflags); + pr_debug("UESP = 0x%-09x\n", frame->useresp); + pr_debug("SS = 0x%-04x\n", frame->ss); +} + +#endif diff --git a/libc/src/io/mm_io.c b/libc/src/io/mm_io.c index 1271c45..2211ed2 100644 --- a/libc/src/io/mm_io.c +++ b/libc/src/io/mm_io.c @@ -1,36 +1,36 @@ /// @file mm_io.c /// @brief Memory Mapped IO functions implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/mm_io.h" -uint8_t in_memb(uint32_t addr) +inline uint8_t in_memb(uint32_t addr) { return *((uint8_t *) (addr)); } -uint16_t in_mems(uint32_t addr) +inline uint16_t in_mems(uint32_t addr) { return *((uint16_t *) (addr)); } -uint32_t in_meml(uint32_t addr) +inline uint32_t in_meml(uint32_t addr) { return *((uint32_t *) (addr)); } -void out_memb(uint32_t addr, uint8_t value) +inline void out_memb(uint32_t addr, uint8_t value) { (*((uint8_t *) (addr))) = (value); } -void out_mems(uint32_t addr, uint16_t value) +inline void out_mems(uint32_t addr, uint16_t value) { (*((uint16_t *) (addr))) = (value); } -void out_meml(uint32_t addr, uint32_t value) +inline void out_meml(uint32_t addr, uint32_t value) { (*((uint32_t *) (addr))) = (value); } diff --git a/libc/src/io/port_io.c b/libc/src/io/port_io.c index a2011c1..1b06e5f 100644 --- a/libc/src/io/port_io.c +++ b/libc/src/io/port_io.c @@ -1,57 +1,67 @@ /// @file port_io.c /// @brief Byte I/O on ports prototypes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/port_io.h" inline uint8_t inportb(uint16_t port) { - unsigned char data = 0; - __asm__ __volatile__("inb %%dx, %%al" : "=a"(data) : "d"(port)); - - return data; + unsigned char value = 0; + __asm__ __volatile__("inb %%dx, %%al" + : "=a"(value) + : "d"(port)); + return value; } inline uint16_t inports(uint16_t port) { uint16_t rv; - __asm__ __volatile__("inw %1, %0" : "=a"(rv) : "dN"(port)); - + __asm__ __volatile__("inw %1, %0" + : "=a"(rv) + : "dN"(port)); return rv; } -void inportsm(uint16_t port, uint8_t *data, unsigned long size) -{ - __asm__ __volatile__("rep insw" - : "+D"(data), "+c"(size) - : "d"(port) - : "memory"); -} - inline uint32_t inportl(uint16_t port) { uint32_t rv; - __asm__ __volatile__("inl %%dx, %%eax" : "=a"(rv) : "dN"(port)); + __asm__ __volatile__("inl %%dx, %%eax" + : "=a"(rv) + : "dN"(port)); return rv; } -inline void outportb(uint16_t port, uint8_t data) +inline void outportb(uint16_t port, uint8_t value) { - __asm__ __volatile__("outb %%al, %%dx" ::"a"(data), "d"(port)); + __asm__ __volatile__("outb %%al, %%dx" ::"a"(value), "d"(port)); } -inline void outports(uint16_t port, uint16_t data) +inline void outports(uint16_t port, uint16_t value) { - __asm__ __volatile__("outw %1, %0" : : "dN"(port), "a"(data)); + __asm__ __volatile__("outw %1, %0" + : + : "dN"(port), "a"(value)); } -void outportsm(uint16_t port, uint8_t *data, uint16_t size) +inline void outportl(uint16_t port, uint32_t value) { - __asm__ __volatile__("rep outsw" : "+S"(data), "+c"(size) : "d"(port)); + __asm__ __volatile__("outl %%eax, %%dx" + : + : "dN"(port), "a"(value)); } -inline void outportl(uint16_t port, uint32_t data) +void inportsm(uint16_t port, uint8_t *value, unsigned long size) { - __asm__ __volatile__("outl %%eax, %%dx" : : "dN"(port), "a"(data)); + __asm__ __volatile__("rep insw" + : "+D"(value), "+c"(size) + : "d"(port) + : "memory"); +} + +void outportsm(uint16_t port, uint8_t *value, uint16_t size) +{ + __asm__ __volatile__("rep outsw" + : "+S"(value), "+c"(size) + : "d"(port)); } diff --git a/libc/src/ipc/ipc.c b/libc/src/ipc/ipc.c index 0f90f91..7e1a213 100644 --- a/libc/src/ipc/ipc.c +++ b/libc/src/ipc/ipc.c @@ -1,6 +1,6 @@ /// @file ipc.c /// @brief Inter-Process Communication (IPC) system call implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/libc_start.c b/libc/src/libc_start.c index 04eca04..410f994 100644 --- a/libc/src/libc_start.c +++ b/libc/src/libc_start.c @@ -1,6 +1,6 @@ /// @file libc_start.c /// @brief Contains the programs initialization procedure. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/libgen.c b/libc/src/libgen.c index c3b8977..5886d5d 100644 --- a/libc/src/libgen.c +++ b/libc/src/libgen.c @@ -1,6 +1,6 @@ /// @file libgen.c /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/libc/src/math.c b/libc/src/math.c index 14e67ce..55daa98 100644 --- a/libc/src/math.c +++ b/libc/src/math.c @@ -1,6 +1,6 @@ /// @file math.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "math.h" diff --git a/libc/src/pwd.c b/libc/src/pwd.c index 5127048..4c79c2f 100644 --- a/libc/src/pwd.c +++ b/libc/src/pwd.c @@ -1,17 +1,20 @@ /// @file pwd.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "pwd.h" #include "sys/unistd.h" #include "sys/errno.h" +#include "io/debug.h" #include "assert.h" #include "string.h" #include "stdio.h" #include "fcntl.h" -#include "debug.h" +/// @brief Parses the input buffer and fills pwd with its details. +/// @param pwd the structure we need to fill. +/// @param buf the buffer from which we extract the information. static inline void __parse_line(passwd_t *pwd, char *buf) { assert(pwd && "Received null pwd!"); diff --git a/libc/src/sched.c b/libc/src/sched.c index 1daec08..67d7257 100644 --- a/libc/src/sched.c +++ b/libc/src/sched.c @@ -1,6 +1,6 @@ /// @file sched.c /// @brief Function for managing scheduler. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/syscall_types.h" diff --git a/libc/src/setenv.c b/libc/src/setenv.c index 2e7386a..7c83593 100644 --- a/libc/src/setenv.c +++ b/libc/src/setenv.c @@ -1,6 +1,6 @@ /// @file setenv.c /// @brief Defines the functions used to manipulate the environmental variables. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -10,7 +10,9 @@ char **environ; -static char **__environ = NULL; +/// @brief Global environ list. +static char **__environ = NULL; +/// @brief Size of the global environ list. static size_t __environ_size = 0; /// @brief Finds the entry in the environ. diff --git a/libc/src/stdio.c b/libc/src/stdio.c index 3dc7913..7cb6802 100644 --- a/libc/src/stdio.c +++ b/libc/src/stdio.c @@ -1,6 +1,6 @@ /// @file stdio.c /// @brief Standard I/0 functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -9,13 +9,14 @@ #include "string.h" #include "stdbool.h" #include "sys/unistd.h" +#include "strerror.h" void putchar(int character) { write(STDOUT_FILENO, &character, 1); } -void puts(char *str) +void puts(const char *str) { write(STDOUT_FILENO, str, strlen(str)); } @@ -206,3 +207,13 @@ char *fgets(char *buf, int n, int fd) return NULL; return (p); } + +void perror(const char *s) +{ + if (s) { + puts(s); + putchar(':'); + putchar(' '); + } + puts(strerror(errno)); +} \ No newline at end of file diff --git a/libc/src/stdlib.c b/libc/src/stdlib.c index cc62f2f..ee0b2ad 100644 --- a/libc/src/stdlib.c +++ b/libc/src/stdlib.c @@ -1,6 +1,6 @@ /// @file stdlib.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/syscall_types.h" diff --git a/libc/src/strerror.c b/libc/src/strerror.c index 0c245e2..45fb6a3 100644 --- a/libc/src/strerror.c +++ b/libc/src/strerror.c @@ -1,6 +1,6 @@ /// @file strerror.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "strerror.h" diff --git a/libc/src/string.c b/libc/src/string.c index b52a0a3..e36c170 100644 --- a/libc/src/string.c +++ b/libc/src/string.c @@ -1,27 +1,36 @@ /// @file string.c /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -#include #include "string.h" #include "ctype.h" #include "stdio.h" #include "stdlib.h" +#include "fcntl.h" + +#ifdef __KERNEL__ +#include "mem/kheap.h" +#endif char *strncpy(char *destination, const char *source, size_t num) { - char *start = destination; - while (num && (*destination++ = *source++)) { - num--; - } + // Check if we have a valid number. if (num) { - while (--num) { - *destination++ = '\0'; + // Copies the first num characters of source to destination. + while (num && (*destination++ = *source++)) { + num--; + } + // If the end of the source C string (which is signaled by a null-character) + // is found before num characters have been copied, destination is padded + // with zeros until a total of num characters have been written to it. + if (num) { + while (--num) + *destination++ = '\0'; } } - - return start; + // Pointer to destination is returned. + return destination; } int strncmp(const char *s1, const char *s2, size_t n) @@ -32,7 +41,6 @@ int strncmp(const char *s1, const char *s2, size_t n) s1++; s2++; } - return *(unsigned char *)s1 - *(unsigned char *)s2; } @@ -266,12 +274,24 @@ char *strupr(char *s) return s; } +char *strcat(char *dst, const char *src) +{ + char *cp = dst; + + while (*cp) { + cp++; + } + + while ((*cp++ = *src++) != '\0') {} + + return dst; +} + char *strncat(char *s1, const char *s2, size_t n) { char *start = s1; while (*s1++) {} - s1--; while (n--) { @@ -284,15 +304,6 @@ char *strncat(char *s1, const char *s2, size_t n) return start; } -char *strnset(char *s, int c, size_t n) -{ - while (n-- && *s) { - *s++ = (char)c; - } - - return s; -} - char *strrev(char *s) { char *start = s; @@ -386,53 +397,51 @@ char *strtok_r(char *str, const char *delim, char **saveptr) void *memset(void *ptr, int value, size_t num) { - // Truncate c to 8 bits. - value = (value & 0xFF); - - char *dst = (char *)ptr; - - // Initialize the rest of the size. - while (num--) { - *dst++ = (char)value; - } - + // Turn the pointer into a char * pointer. Here, we use the volatile keyword + // to prevent the compiler from optimizing away the operations involving the + // pointer. + unsigned char volatile *dst = (unsigned char volatile *)ptr; + // Initialize the content of the memory. + while (num--) *dst++ = (unsigned char)value; + // Return the pointer. return ptr; } -int memcmp(const void *ptr1, const void *ptr2, size_t n) +int memcmp(const void *dst, const void *src, size_t n) { if (!n) { return 0; } - while (--n && *(char *)ptr1 == *(char *)ptr2) { - ptr1 = (char *)ptr1 + 1; - ptr2 = (char *)ptr2 + 1; + while (--n && *(char *)dst == *(char *)src) { + dst = (char *)dst + 1; + src = (char *)src + 1; } - return *((unsigned char *)ptr1) - *((unsigned char *)ptr2); + return *((unsigned char *)dst) - *((unsigned char *)src); } -void *memcpy(void *ptr1, const void *ptr2, size_t num) +void *memcpy(void *dst, const void *src, size_t num) { - char *_dst = ptr1; - const char *_src = ptr2; - - while (num--) { - *_dst++ = *_src++; - } - - return ptr1; + // Turn the pointer into a char * pointer. Here, we use the volatile keyword + // to prevent the compiler from optimizing away the operations involving the + // pointer. + unsigned char volatile *_dst = (unsigned char volatile *)dst; + const unsigned char volatile *_src = (const unsigned char volatile *)src; + // Initialize the content of the memory. + while (num--) *_dst++ = *_src++; + // Return the pointer. + return (void *)dst; } -void *memccpy(void *ptr1, const void *ptr2, int c, size_t n) +void *memccpy(void *dst, const void *src, int c, size_t n) { - while (n && (*((char *)(ptr1 = (char *)ptr1 + 1) - 1) = - *((char *)(ptr2 = (char *)ptr2 + 1) - 1)) != (char)c) { + while (n && (*((char *)(dst = (char *)dst + 1) - 1) = + *((char *)(src = (char *)src + 1) - 1)) != (char)c) { n--; } - return n ? ptr1 : NULL; + return n ? dst : NULL; } char *strcpy(char *dst, const char *src) @@ -477,19 +486,6 @@ int strcmp(const char *s1, const char *s2) 0; } -char *strcat(char *dst, const char *src) -{ - char *cp = dst; - - while (*cp) { - cp++; - } - - while ((*cp++ = *src++) != '\0') {} - - return dst; -} - char *strset(char *s, int c) { char *start = s; @@ -501,6 +497,15 @@ char *strset(char *s, int c) return start; } +char *strnset(char *s, int c, size_t n) +{ + while (n-- && *s) { + *s++ = (char)c; + } + + return s; +} + char *strtok(char *str, const char *delim) { const char *spanp; @@ -593,7 +598,11 @@ char *trim(char *str) char *strdup(const char *s) { size_t len = strlen(s) + 1; - char *new = malloc(len); +#ifdef __KERNEL__ + char *new = kmalloc(len); +#else + char *new = malloc(len); +#endif if (new == NULL) return NULL; new[len] = '\0'; @@ -603,7 +612,11 @@ char *strdup(const char *s) char *strndup(const char *s, size_t n) { size_t len = strnlen(s, n); - char *new = malloc(len); +#ifdef __KERNEL__ + char *new = kmalloc(len); +#else + char *new = malloc(len); +#endif if (new == NULL) return NULL; new[len] = '\0'; diff --git a/libc/src/sys/errno.c b/libc/src/sys/errno.c index 03f08a8..d700ebd 100644 --- a/libc/src/sys/errno.c +++ b/libc/src/sys/errno.c @@ -1,6 +1,6 @@ /// @file errno.c /// @brief Stores the error number. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/errno.h" diff --git a/libc/src/sys/ioctl.c b/libc/src/sys/ioctl.c index 0152b54..25225ad 100644 --- a/libc/src/sys/ioctl.c +++ b/libc/src/sys/ioctl.c @@ -1,6 +1,6 @@ /// @file ioctl.c /// @brief Input/Output ConTroL (IOCTL) functions implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/ioctl.h" diff --git a/libc/src/sys/unistd.c b/libc/src/sys/unistd.c index caa3661..97e51d6 100644 --- a/libc/src/sys/unistd.c +++ b/libc/src/sys/unistd.c @@ -1,6 +1,6 @@ /// @file unistd.c /// @brief Functions used to manage files. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/sys/utsname.c b/libc/src/sys/utsname.c index 7af15d2..e8990cb 100644 --- a/libc/src/sys/utsname.c +++ b/libc/src/sys/utsname.c @@ -1,6 +1,6 @@ /// @file utsname.c /// @brief Functions used to provide information about the machine & OS. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/utsname.h" diff --git a/libc/src/termios.c b/libc/src/termios.c index dada98e..b691983 100644 --- a/libc/src/termios.c +++ b/libc/src/termios.c @@ -1,6 +1,6 @@ /// @file termios.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "termios.h" diff --git a/libc/src/time.c b/libc/src/time.c index 7a11ae0..0af6036 100644 --- a/libc/src/time.c +++ b/libc/src/time.c @@ -1,6 +1,6 @@ /// @file time.c /// @brief Clock functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "time.h" @@ -9,10 +9,12 @@ #include "string.h" #include "stdio.h" +/// @brief List of week days name. static const char *weekdays[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; +/// @brief List of months name. static const char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" diff --git a/libc/src/unistd/chdir.c b/libc/src/unistd/chdir.c index 1840705..1557053 100644 --- a/libc/src/unistd/chdir.c +++ b/libc/src/unistd/chdir.c @@ -1,6 +1,6 @@ /// @file chdir.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/close.c b/libc/src/unistd/close.c index b0ee451..d7b15d7 100644 --- a/libc/src/unistd/close.c +++ b/libc/src/unistd/close.c @@ -1,6 +1,6 @@ /// @file close.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/creat.c b/libc/src/unistd/creat.c index c9194ff..69555e4 100644 --- a/libc/src/unistd/creat.c +++ b/libc/src/unistd/creat.c @@ -1,6 +1,6 @@ /// @file creat.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/exec.c b/libc/src/unistd/exec.c index ac08c32..3e9ccf8 100644 --- a/libc/src/unistd/exec.c +++ b/libc/src/unistd/exec.c @@ -1,14 +1,13 @@ /// @file exec.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -#include #include "sys/unistd.h" #include "system/syscall_types.h" #include "sys/errno.h" - #include "sys/stat.h" +#include "io/debug.h" #include "stdlib.h" #include "string.h" #include "stdarg.h" @@ -59,16 +58,12 @@ static inline int __find_in_path(const char *file, char *buf, size_t buf_len) return -1; } -/// @brief Replaces the current process image with a new process -/// image (argument vector), allows the caller to specify -/// the environment of the executed program via `envp`. -/// @param path The absolute path to the binary file to execute. -/// @param argv A vector of one or more pointers to null-terminated strings that represent -/// the argument list available to the executed program. -/// @param envp A vector of one or more pointers to null-terminated strings that represent -/// the environment list available to the executed program. -/// @return Returns -1 only if an error has occurred, and sets errno. -_syscall3(int, execve, const char *, path, char *const *, argv, char *const *, envp) +int execve(const char *path, char *const argv[], char *const envp[]) +{ + long __res; + __inline_syscall3(__res, execve, path, argv, envp); + __syscall_return(int, __res); +} int execv(const char *path, char *const argv[]) { diff --git a/libc/src/unistd/exit.c b/libc/src/unistd/exit.c index 6eea34d..7148c1d 100644 --- a/libc/src/unistd/exit.c +++ b/libc/src/unistd/exit.c @@ -1,6 +1,6 @@ /// @file exit.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/fork.c b/libc/src/unistd/fork.c index 86d4da8..c7cbe9d 100644 --- a/libc/src/unistd/fork.c +++ b/libc/src/unistd/fork.c @@ -1,6 +1,6 @@ /// @file fork.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getcwd.c b/libc/src/unistd/getcwd.c index 9fbf73c..1879005 100644 --- a/libc/src/unistd/getcwd.c +++ b/libc/src/unistd/getcwd.c @@ -1,6 +1,6 @@ /// @file getcwd.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getdents.c b/libc/src/unistd/getdents.c index 1e586b3..e490c53 100644 --- a/libc/src/unistd/getdents.c +++ b/libc/src/unistd/getdents.c @@ -1,6 +1,6 @@ /// @file getdents.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" @@ -8,4 +8,4 @@ #include "sys/errno.h" -_syscall3(int, getdents, int, fd, dirent_t *, dirp, unsigned int, count) +_syscall3(ssize_t, getdents, int, fd, dirent_t *, dirp, unsigned int, count) diff --git a/libc/src/unistd/getgid.c b/libc/src/unistd/getgid.c index df2ed77..c5060d0 100644 --- a/libc/src/unistd/getgid.c +++ b/libc/src/unistd/getgid.c @@ -1,6 +1,6 @@ /// @file getgid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getpgid.c b/libc/src/unistd/getpgid.c index 59f94c1..b5cd9d3 100644 --- a/libc/src/unistd/getpgid.c +++ b/libc/src/unistd/getpgid.c @@ -1,6 +1,6 @@ /// @file getpgid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getpid.c b/libc/src/unistd/getpid.c index a1c51d3..8d2b1af 100644 --- a/libc/src/unistd/getpid.c +++ b/libc/src/unistd/getpid.c @@ -1,6 +1,6 @@ /// @file getpid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getppid.c b/libc/src/unistd/getppid.c index b287b04..208280f 100644 --- a/libc/src/unistd/getppid.c +++ b/libc/src/unistd/getppid.c @@ -1,6 +1,6 @@ /// @file getppid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getsid.c b/libc/src/unistd/getsid.c index 14ff4cd..75dfe36 100644 --- a/libc/src/unistd/getsid.c +++ b/libc/src/unistd/getsid.c @@ -1,6 +1,6 @@ /// @file getsid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/getuid.c b/libc/src/unistd/getuid.c index 7b5c3de..3b18f7e 100644 --- a/libc/src/unistd/getuid.c +++ b/libc/src/unistd/getuid.c @@ -1,6 +1,6 @@ /// @file getuid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/interval.c b/libc/src/unistd/interval.c index 3694b05..0dccc73 100644 --- a/libc/src/unistd/interval.c +++ b/libc/src/unistd/interval.c @@ -1,6 +1,6 @@ /// @file interval.c /// @brief Function for setting allarms. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/kill.c b/libc/src/unistd/kill.c index c21c96a..6a5bf6f 100644 --- a/libc/src/unistd/kill.c +++ b/libc/src/unistd/kill.c @@ -1,6 +1,6 @@ /// @file kill.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/lseek.c b/libc/src/unistd/lseek.c index 791e620..3eab910 100644 --- a/libc/src/unistd/lseek.c +++ b/libc/src/unistd/lseek.c @@ -1,6 +1,6 @@ /// @file open.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/mkdir.c b/libc/src/unistd/mkdir.c index 1ea8e60..85d38f1 100644 --- a/libc/src/unistd/mkdir.c +++ b/libc/src/unistd/mkdir.c @@ -1,6 +1,6 @@ /// @file mkdir.c /// @brief Make directory functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/nice.c b/libc/src/unistd/nice.c index aaa5ab6..d1b3dfb 100644 --- a/libc/src/unistd/nice.c +++ b/libc/src/unistd/nice.c @@ -1,6 +1,6 @@ /// @file nice.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/open.c b/libc/src/unistd/open.c index 20fc647..2d79963 100644 --- a/libc/src/unistd/open.c +++ b/libc/src/unistd/open.c @@ -1,6 +1,6 @@ /// @file open.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/read.c b/libc/src/unistd/read.c index 7fc6769..6228d94 100644 --- a/libc/src/unistd/read.c +++ b/libc/src/unistd/read.c @@ -1,6 +1,6 @@ /// @file read.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/reboot.c b/libc/src/unistd/reboot.c index fab8c4f..72071db 100644 --- a/libc/src/unistd/reboot.c +++ b/libc/src/unistd/reboot.c @@ -1,6 +1,6 @@ /// @file reboot.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/rmdir.c b/libc/src/unistd/rmdir.c index 077b520..2f341a2 100644 --- a/libc/src/unistd/rmdir.c +++ b/libc/src/unistd/rmdir.c @@ -1,6 +1,6 @@ /// @file rmdir.c /// @brief Make directory functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/setgid.c b/libc/src/unistd/setgid.c index 673c10d..7e2a897 100644 --- a/libc/src/unistd/setgid.c +++ b/libc/src/unistd/setgid.c @@ -1,6 +1,6 @@ /// @file setgid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/setpgid.c b/libc/src/unistd/setpgid.c index d72266f..cdcd36b 100644 --- a/libc/src/unistd/setpgid.c +++ b/libc/src/unistd/setpgid.c @@ -1,6 +1,6 @@ /// @file setpgid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/setsid.c b/libc/src/unistd/setsid.c index 2f47e07..6d7ee54 100644 --- a/libc/src/unistd/setsid.c +++ b/libc/src/unistd/setsid.c @@ -1,6 +1,6 @@ /// @file setsid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/setuid.c b/libc/src/unistd/setuid.c index 388f6f8..e5068ac 100644 --- a/libc/src/unistd/setuid.c +++ b/libc/src/unistd/setuid.c @@ -1,6 +1,6 @@ /// @file setuid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/signal.c b/libc/src/unistd/signal.c index 281e412..10a5328 100644 --- a/libc/src/unistd/signal.c +++ b/libc/src/unistd/signal.c @@ -1,6 +1,6 @@ /// @file signal.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" @@ -10,10 +10,13 @@ #include "signal.h" #include "sys/bitops.h" +/// @brief Implement the sigreturn function. _syscall0(int, sigreturn) +/// @brief Implement the sigprocmask function. _syscall3(int, sigprocmask, int, how, const sigset_t *, set, sigset_t *, oldset) +/// @brief List of signals names. static const char *sys_siglist[] = { "HUP", "INT", diff --git a/libc/src/unistd/stat.c b/libc/src/unistd/stat.c index 603da74..5873649 100644 --- a/libc/src/unistd/stat.c +++ b/libc/src/unistd/stat.c @@ -1,6 +1,6 @@ /// @file stat.c /// @brief Stat functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/unlink.c b/libc/src/unistd/unlink.c index 9ba5356..b9c3b1e 100644 --- a/libc/src/unistd/unlink.c +++ b/libc/src/unistd/unlink.c @@ -1,6 +1,6 @@ /// @file unlink.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/waitpid.c b/libc/src/unistd/waitpid.c index f58ee27..a06b2c1 100644 --- a/libc/src/unistd/waitpid.c +++ b/libc/src/unistd/waitpid.c @@ -1,6 +1,6 @@ /// @file waitpid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" diff --git a/libc/src/unistd/write.c b/libc/src/unistd/write.c index 413ba14..e7bf2cf 100644 --- a/libc/src/unistd/write.c +++ b/libc/src/unistd/write.c @@ -1,10 +1,10 @@ /// @file write.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/unistd.h" #include "system/syscall_types.h" #include "sys/errno.h" -_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes) +_syscall3(ssize_t, write, int, fd, const void *, buf, size_t, nbytes) diff --git a/libc/src/vscanf.c b/libc/src/vscanf.c index c4b0933..5a06ad1 100644 --- a/libc/src/vscanf.c +++ b/libc/src/vscanf.c @@ -1,6 +1,6 @@ /// @file vscanf.c /// @brief Reading formatting routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -8,7 +8,13 @@ #include #include -static int vsscanf(const char *buf, const char *s, va_list ap) +/// @brief Read formatted data from string. +/// @param buf String processed as source to retrieve the data. +/// @param s Format string, following the same specifications as printf. +/// @param ap The list of arguments where the values are stored. +/// @return On success, the function returns the number of items of the +/// argument list successfully filled. EOF otherwise. +static int __vsscanf(const char *buf, const char *s, va_list ap) { int count = 0, noassign = 0, width = 0, base = 0; const char *tc; @@ -92,14 +98,20 @@ static int vsscanf(const char *buf, const char *s, va_list ap) return (count); } -static int vfscanf(int fd, const char *fmt, va_list ap) +/// @brief Read formatted data from file. +/// @param fd the file descriptor associated with the file. +/// @param fmt format string, following the same specifications as printf. +/// @param ap the list of arguments where the values are stored. +/// @return On success, the function returns the number of items of the +/// argument list successfully filled. EOF otherwise. +static int __vfscanf(int fd, const char *fmt, va_list ap) { int count; char buf[BUFSIZ + 1]; if (fgets(buf, BUFSIZ, fd) == 0) return (-1); - count = vsscanf(buf, fmt, ap); + count = __vsscanf(buf, fmt, ap); return (count); } @@ -109,7 +121,7 @@ int scanf(const char *fmt, ...) va_list ap; va_start(ap, fmt); - count = vfscanf(STDIN_FILENO, fmt, ap); + count = __vfscanf(STDIN_FILENO, fmt, ap); va_end(ap); return (count); } @@ -120,7 +132,7 @@ int fscanf(int fd, const char *fmt, ...) va_list ap; va_start(ap, fmt); - count = vfscanf(fd, fmt, ap); + count = __vfscanf(fd, fmt, ap); va_end(ap); return (count); } @@ -131,7 +143,7 @@ int sscanf(const char *buf, const char *fmt, ...) va_list ap; va_start(ap, fmt); - count = vsscanf(buf, fmt, ap); + count = __vsscanf(buf, fmt, ap); va_end(ap); return (count); } diff --git a/libc/src/vsprintf.c b/libc/src/vsprintf.c index 8fd8da6..b864dfa 100644 --- a/libc/src/vsprintf.c +++ b/libc/src/vsprintf.c @@ -1,9 +1,9 @@ /// @file vsprintf.c /// @brief Print formatting routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -#include +#include "sys/bitops.h" #include "fcvt.h" #include "ctype.h" #include "string.h" @@ -30,6 +30,8 @@ static char *_digits = "0123456789abcdefghijklmnopqrstuvwxyz"; static char *_upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /// @brief Returns the index of the first non-integer character. +/// @param s the string we need to analyze. +/// @return the index of the first non-integer character. static inline int skip_atoi(const char **s) { int i = 0; @@ -38,6 +40,14 @@ static inline int skip_atoi(const char **s) return i; } +/// @brief Transforms the number into a string. +/// @param str the output string. +/// @param num the number to transform to string. +/// @param base the base to use for number transformation. +/// @param size the size of the output string. +/// @param precision the precision for floating point numbers. +/// @param flags control flags. +/// @return the number turned into a string. static char *number(char *str, long num, int base, int size, int32_t precision, unsigned flags) { char c, tmp[66] = { 0 }; diff --git a/mentos/CMakeLists.txt b/mentos/CMakeLists.txt index 13fc177..932a7d9 100644 --- a/mentos/CMakeLists.txt +++ b/mentos/CMakeLists.txt @@ -97,88 +97,88 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug") # Define the list of files. set(KERNEL_SOURCES - src/kernel.c - src/multiboot.c - src/devices/pci.c - src/devices/fpu.c - src/drivers/ata.c - src/drivers/rtc.c - src/drivers/fdc.c - src/drivers/mouse.c - src/drivers/ps2.c - src/drivers/keyboard/keyboard.c - src/drivers/keyboard/keymap.c - src/fs/vfs.c - src/fs/read_write.c - src/fs/open.c - src/fs/stat.c - src/fs/readdir.c - src/fs/procfs.c - src/fs/ioctl.c - src/fs/namei.c - src/fs/ext2.c - src/hardware/timer.c - src/hardware/cpuid.c - src/hardware/pic8259.c - src/io/port_io.c - src/io/mm_io.c - src/io/video.c - src/io/stdio.c - src/io/debug.c - src/io/proc_video.c - src/io/proc_running.c - src/io/proc_feedback.c - src/io/proc_system.c - src/io/vga/vga.c - src/ipc/msg.c - src/ipc/sem.c - src/ipc/shm.c - src/kernel/sys.c - src/klib/assert.c - src/klib/ctype.c - src/klib/mutex.c - src/klib/string.c - src/klib/vsprintf.c - src/klib/vscanf.c - src/klib/time.c - src/klib/libgen.c - src/klib/strerror.c - src/klib/math.c - src/klib/fcvt.c - src/klib/spinlock.c - src/klib/rbtree.c - src/klib/ndtree.c - src/klib/hashmap.c - src/klib/list.c - src/mem/kheap.c - src/mem/paging.c - src/mem/slab.c - src/mem/vmem_map.c - src/mem/zone_allocator.c - src/elf/elf.c - src/descriptor_tables/gdt.c - src/descriptor_tables/gdt.S - src/descriptor_tables/interrupt.c - src/descriptor_tables/exception.c - src/descriptor_tables/interrupt.S - src/descriptor_tables/exception.S - src/descriptor_tables/idt.c - src/descriptor_tables/idt.S - src/descriptor_tables/tss.c - src/descriptor_tables/tss.S - src/process/scheduler_algorithm.c - src/process/scheduler_feedback.c - src/process/scheduler.c - src/process/process.c - src/process/wait.c - src/process/user.S - src/sys/utsname.c - src/sys/module.c - src/system/errno.c - src/system/panic.c - src/system/printk.c - src/system/signal.c - src/system/syscall.c + ${PROJECT_SOURCE_DIR}/src/kernel.c + ${PROJECT_SOURCE_DIR}/src/multiboot.c + ${PROJECT_SOURCE_DIR}/src/devices/pci.c + ${PROJECT_SOURCE_DIR}/src/devices/fpu.c + ${PROJECT_SOURCE_DIR}/src/drivers/ata.c + ${PROJECT_SOURCE_DIR}/src/drivers/rtc.c + ${PROJECT_SOURCE_DIR}/src/drivers/fdc.c + ${PROJECT_SOURCE_DIR}/src/drivers/mouse.c + ${PROJECT_SOURCE_DIR}/src/drivers/ps2.c + ${PROJECT_SOURCE_DIR}/src/drivers/keyboard/keyboard.c + ${PROJECT_SOURCE_DIR}/src/drivers/keyboard/keymap.c + ${PROJECT_SOURCE_DIR}/src/fs/vfs.c + ${PROJECT_SOURCE_DIR}/src/fs/read_write.c + ${PROJECT_SOURCE_DIR}/src/fs/open.c + ${PROJECT_SOURCE_DIR}/src/fs/stat.c + ${PROJECT_SOURCE_DIR}/src/fs/readdir.c + ${PROJECT_SOURCE_DIR}/src/fs/procfs.c + ${PROJECT_SOURCE_DIR}/src/fs/ioctl.c + ${PROJECT_SOURCE_DIR}/src/fs/namei.c + ${PROJECT_SOURCE_DIR}/src/fs/ext2.c + ${PROJECT_SOURCE_DIR}/src/hardware/timer.c + ${PROJECT_SOURCE_DIR}/src/hardware/cpuid.c + ${PROJECT_SOURCE_DIR}/src/hardware/pic8259.c + ${PROJECT_SOURCE_DIR}/src/io/debug.c + ${PROJECT_SOURCE_DIR}/src/io/port_io.c + ${PROJECT_SOURCE_DIR}/src/io/mm_io.c + ${PROJECT_SOURCE_DIR}/src/io/video.c + ${PROJECT_SOURCE_DIR}/src/io/stdio.c + ${PROJECT_SOURCE_DIR}/src/io/proc_video.c + ${PROJECT_SOURCE_DIR}/src/io/proc_running.c + ${PROJECT_SOURCE_DIR}/src/io/proc_feedback.c + ${PROJECT_SOURCE_DIR}/src/io/proc_system.c + ${PROJECT_SOURCE_DIR}/src/io/vga/vga.c + ${PROJECT_SOURCE_DIR}/src/ipc/msg.c + ${PROJECT_SOURCE_DIR}/src/ipc/sem.c + ${PROJECT_SOURCE_DIR}/src/ipc/shm.c + ${PROJECT_SOURCE_DIR}/src/kernel/sys.c + ${PROJECT_SOURCE_DIR}/src/klib/assert.c + ${PROJECT_SOURCE_DIR}/src/klib/ctype.c + ${PROJECT_SOURCE_DIR}/src/klib/mutex.c + ${PROJECT_SOURCE_DIR}/src/klib/string.c + ${PROJECT_SOURCE_DIR}/src/klib/vsprintf.c + ${PROJECT_SOURCE_DIR}/src/klib/vscanf.c + ${PROJECT_SOURCE_DIR}/src/klib/time.c + ${PROJECT_SOURCE_DIR}/src/klib/libgen.c + ${PROJECT_SOURCE_DIR}/src/klib/strerror.c + ${PROJECT_SOURCE_DIR}/src/klib/math.c + ${PROJECT_SOURCE_DIR}/src/klib/fcvt.c + ${PROJECT_SOURCE_DIR}/src/klib/spinlock.c + ${PROJECT_SOURCE_DIR}/src/klib/rbtree.c + ${PROJECT_SOURCE_DIR}/src/klib/ndtree.c + ${PROJECT_SOURCE_DIR}/src/klib/hashmap.c + ${PROJECT_SOURCE_DIR}/src/klib/list.c + ${PROJECT_SOURCE_DIR}/src/mem/kheap.c + ${PROJECT_SOURCE_DIR}/src/mem/paging.c + ${PROJECT_SOURCE_DIR}/src/mem/slab.c + ${PROJECT_SOURCE_DIR}/src/mem/vmem_map.c + ${PROJECT_SOURCE_DIR}/src/mem/zone_allocator.c + ${PROJECT_SOURCE_DIR}/src/elf/elf.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/gdt.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/gdt.S + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/interrupt.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/exception.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/interrupt.S + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/exception.S + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/idt.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/idt.S + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/tss.c + ${PROJECT_SOURCE_DIR}/src/descriptor_tables/tss.S + ${PROJECT_SOURCE_DIR}/src/process/scheduler_algorithm.c + ${PROJECT_SOURCE_DIR}/src/process/scheduler_feedback.c + ${PROJECT_SOURCE_DIR}/src/process/scheduler.c + ${PROJECT_SOURCE_DIR}/src/process/process.c + ${PROJECT_SOURCE_DIR}/src/process/wait.c + ${PROJECT_SOURCE_DIR}/src/process/user.S + ${PROJECT_SOURCE_DIR}/src/sys/utsname.c + ${PROJECT_SOURCE_DIR}/src/sys/module.c + ${PROJECT_SOURCE_DIR}/src/system/errno.c + ${PROJECT_SOURCE_DIR}/src/system/panic.c + ${PROJECT_SOURCE_DIR}/src/system/printk.c + ${PROJECT_SOURCE_DIR}/src/system/signal.c + ${PROJECT_SOURCE_DIR}/src/system/syscall.c ) # ============================================================================= diff --git a/mentos/inc/boot.h b/mentos/inc/boot.h index 7163e2b..67c2615 100644 --- a/mentos/inc/boot.h +++ b/mentos/inc/boot.h @@ -1,6 +1,6 @@ /// @file boot.h /// @brief Bootloader structures -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/descriptor_tables/gdt.h b/mentos/inc/descriptor_tables/gdt.h index 4f2c5b0..40080ce 100644 --- a/mentos/inc/descriptor_tables/gdt.h +++ b/mentos/inc/descriptor_tables/gdt.h @@ -1,6 +1,6 @@ /// @file gdt.h /// @brief Data structures concerning the Global Descriptor Table (GDT). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup descriptor_tables Descriptor Tables /// @brief GDT, IDT and TSS are all data structures specified by Intel x86 diff --git a/mentos/inc/descriptor_tables/idt.h b/mentos/inc/descriptor_tables/idt.h index 2fbb506..5758365 100644 --- a/mentos/inc/descriptor_tables/idt.h +++ b/mentos/inc/descriptor_tables/idt.h @@ -1,6 +1,6 @@ /// @file idt.h /// @brief Data structures concerning the Interrupt Descriptor Table (IDT). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup descriptor_tables Descriptor Tables /// @{ diff --git a/mentos/inc/descriptor_tables/isr.h b/mentos/inc/descriptor_tables/isr.h index c9e1083..376d593 100644 --- a/mentos/inc/descriptor_tables/isr.h +++ b/mentos/inc/descriptor_tables/isr.h @@ -1,6 +1,6 @@ /// @file isr.h /// @brief Data structures concerning the Interrupt Service Routines (ISRs). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup descriptor_tables Descriptor Tables /// @{ diff --git a/mentos/inc/descriptor_tables/tss.h b/mentos/inc/descriptor_tables/tss.h index 46a6414..a946966 100644 --- a/mentos/inc/descriptor_tables/tss.h +++ b/mentos/inc/descriptor_tables/tss.h @@ -1,6 +1,6 @@ /// @file tss.h /// @brief Data structures concerning the Task State Segment (TSS). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup descriptor_tables Descriptor Tables /// @{ diff --git a/mentos/inc/devices/fpu.h b/mentos/inc/devices/fpu.h index af58e2b..049db82 100644 --- a/mentos/inc/devices/fpu.h +++ b/mentos/inc/devices/fpu.h @@ -1,6 +1,6 @@ /// @file fpu.h /// @brief Floating Point Unit (FPU). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup devices Hardware Interfaces /// @brief Data structures and functions for managing hardware devices. diff --git a/mentos/inc/devices/pci.h b/mentos/inc/devices/pci.h index 562892d..90f3270 100644 --- a/mentos/inc/devices/pci.h +++ b/mentos/inc/devices/pci.h @@ -1,6 +1,6 @@ /// @file pci.h /// @brief Routines for interfacing with the Peripheral Component Interconnect (PCI). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup devices Hardware Interfaces /// @{ @@ -233,24 +233,33 @@ typedef enum { typedef void (*pci_scan_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra); /// @brief Extract the `bus` from the device. +/// @param device the device details. +/// @return the `bus` value. static inline int pci_extract_bus(uint32_t device) { return (uint8_t)((device >> 16)); } /// @brief Extract the `slot` from the device. +/// @param device the device details. +/// @return the `slot` value. static inline int pci_extract_slot(uint32_t device) { return (uint8_t)((device >> 8)); } /// @brief Extract the `func` from the device. +/// @param device the device details. +/// @return the `func` value. static inline int pci_extract_func(uint32_t device) { return (uint8_t)(device); } -/// @brief TODO: doxygen comment. +/// @brief TODO: Comment. +/// @param device +/// @param field +/// @return static inline uint32_t pci_get_addr(uint32_t device, int field) { return 0x80000000 | (pci_extract_bus(device) << 16) | diff --git a/mentos/inc/drivers/ata.h b/mentos/inc/drivers/ata.h index cf398fe..d274b45 100644 --- a/mentos/inc/drivers/ata.h +++ b/mentos/inc/drivers/ata.h @@ -7,7 +7,7 @@ /// can terminate at an IDE card connected to PCI. /// ATAPI is an extension to ATA (recently renamed to PATA) which adds support /// for the SCSI command set. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @{ diff --git a/mentos/inc/drivers/fdc.h b/mentos/inc/drivers/fdc.h index 835fe3f..56d4d87 100644 --- a/mentos/inc/drivers/fdc.h +++ b/mentos/inc/drivers/fdc.h @@ -1,6 +1,6 @@ /// @file fdc.h /// @brief Definitions about the floppy. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @{ diff --git a/mentos/inc/drivers/keyboard/keyboard.h b/mentos/inc/drivers/keyboard/keyboard.h index bd33768..1ea1e70 100644 --- a/mentos/inc/drivers/keyboard/keyboard.h +++ b/mentos/inc/drivers/keyboard/keyboard.h @@ -1,6 +1,6 @@ /// @file keyboard.h /// @brief Drivers for the Keyboard devices. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @{ diff --git a/mentos/inc/drivers/keyboard/keymap.h b/mentos/inc/drivers/keyboard/keymap.h index 65abd2c..594e16b 100644 --- a/mentos/inc/drivers/keyboard/keymap.h +++ b/mentos/inc/drivers/keyboard/keymap.h @@ -1,6 +1,6 @@ /// @file keymap.h /// @brief Keymap for keyboard. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @{ @@ -157,7 +157,6 @@ void init_keymaps(); #define KEY_DOWN_ARROW 0xE050U ///< Down Arrow 57424 #define CODE_BREAK 0x0080U ///< Code break code -#define MULTIMEDIA_SCAN_CODE 0xE0 /// @} /// @} diff --git a/mentos/inc/drivers/mouse.h b/mentos/inc/drivers/mouse.h index 09f71a5..f5ad9ff 100644 --- a/mentos/inc/drivers/mouse.h +++ b/mentos/inc/drivers/mouse.h @@ -1,6 +1,6 @@ /// @file mouse.h /// @brief Driver for *PS2* Mouses. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @{ diff --git a/mentos/inc/drivers/ps2.h b/mentos/inc/drivers/ps2.h index b080ff9..b525e3c 100644 --- a/mentos/inc/drivers/ps2.h +++ b/mentos/inc/drivers/ps2.h @@ -1,6 +1,6 @@ /// @file ps2.h /// @brief PS/2 drivers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/drivers/rtc.h b/mentos/inc/drivers/rtc.h index db9b6a3..e4b28f7 100644 --- a/mentos/inc/drivers/rtc.h +++ b/mentos/inc/drivers/rtc.h @@ -1,6 +1,6 @@ /// @file rtc.h /// @brief Real Time Clock (RTC) driver. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup drivers Device Drivers /// @brief Routines for interfacing with peripheral devices. diff --git a/mentos/inc/elf/elf.h b/mentos/inc/elf/elf.h index a2b36ef..0aacaa3 100644 --- a/mentos/inc/elf/elf.h +++ b/mentos/inc/elf/elf.h @@ -1,6 +1,6 @@ /// @file elf.h /// @brief Function for managing the Executable and Linkable Format (ELF). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/fs/ext2.h b/mentos/inc/fs/ext2.h index 5db9bdc..1c23108 100644 --- a/mentos/inc/fs/ext2.h +++ b/mentos/inc/fs/ext2.h @@ -1,6 +1,6 @@ /// @file ext2.h /// @brief EXT2 driver. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/fs/ioctl.h b/mentos/inc/fs/ioctl.h index 215f292..fc4b1a8 100644 --- a/mentos/inc/fs/ioctl.h +++ b/mentos/inc/fs/ioctl.h @@ -1,6 +1,6 @@ /// @file ioctl.h /// @brief Declares device controlling operations. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @brief Manipulates the underlying device parameters of special files, or operating diff --git a/mentos/inc/fs/procfs.h b/mentos/inc/fs/procfs.h index 3097ad2..1de8b31 100644 --- a/mentos/inc/fs/procfs.h +++ b/mentos/inc/fs/procfs.h @@ -1,6 +1,6 @@ /// @file procfs.h /// @brief Proc file system public functions and structures. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/fs/vfs.h b/mentos/inc/fs/vfs.h index b5035b2..6258b7b 100644 --- a/mentos/inc/fs/vfs.h +++ b/mentos/inc/fs/vfs.h @@ -1,6 +1,6 @@ /// @file vfs.h /// @brief Headers for Virtual File System (VFS). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -64,7 +64,7 @@ ssize_t vfs_read(vfs_file_t *file, void *buf, size_t offset, size_t nbytes); /// @param offset The offset from which the function starts to write. /// @param nbytes The number of bytes to write. /// @return The number of written characters. -ssize_t vfs_write(vfs_file_t *file, void *buf, size_t offset, size_t nbytes); +ssize_t vfs_write(vfs_file_t *file, const void *buf, size_t offset, size_t nbytes); /// @brief Repositions the file offset inside a file. /// @param file The file for which we reposition the offest. @@ -84,7 +84,7 @@ off_t vfs_lseek(vfs_file_t *file, off_t offset, int whence); /// @return On success, the number of bytes read is returned. On end of /// directory, 0 is returned. On error, -1 is returned, and errno is set /// appropriately. -int vfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t off, size_t count); +ssize_t vfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t off, size_t count); /// @brief Perform the I/O control operation specified by REQUEST on FD. /// One argument may follow; its presence and type depend on REQUEST. diff --git a/mentos/inc/fs/vfs_types.h b/mentos/inc/fs/vfs_types.h index 02bfd72..1e0057e 100644 --- a/mentos/inc/fs/vfs_types.h +++ b/mentos/inc/fs/vfs_types.h @@ -1,6 +1,6 @@ /// @file vfs_types.h /// @brief Virtual filesystem data types. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -25,7 +25,7 @@ typedef int (*vfs_rmdir_callback)(const char *); /// Function used to open a file (or directory). typedef vfs_file_t *(*vfs_creat_callback)(const char *, mode_t); /// Function used to read the entries of a directory. -typedef int (*vfs_getdents_callback)(vfs_file_t *, dirent_t *, off_t, size_t); +typedef ssize_t (*vfs_getdents_callback)(vfs_file_t *, dirent_t *, off_t, size_t); /// Function used to open a file (or directory). typedef vfs_file_t *(*vfs_open_callback)(const char *, int, mode_t); /// Function used to remove a file. diff --git a/mentos/inc/hardware/cpuid.h b/mentos/inc/hardware/cpuid.h index b78e54b..5babfff 100644 --- a/mentos/inc/hardware/cpuid.h +++ b/mentos/inc/hardware/cpuid.h @@ -4,7 +4,7 @@ /// CPUID instruction (identified by a CPUID opcode) is a processor /// supplementary instruction (its name derived from CPU IDentification) /// allowing software to discover details of the processor. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/hardware/pic8259.h b/mentos/inc/hardware/pic8259.h index 983e613..059a9d9 100644 --- a/mentos/inc/hardware/pic8259.h +++ b/mentos/inc/hardware/pic8259.h @@ -3,7 +3,7 @@ /// @details /// The Intel 8259 is a Programmable Interrupt Controller (PIC) designed /// for the Intel 8085 and Intel 8086 microprocessors. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/hardware/timer.h b/mentos/inc/hardware/timer.h index d521e3d..cd3f587 100644 --- a/mentos/inc/hardware/timer.h +++ b/mentos/inc/hardware/timer.h @@ -1,6 +1,6 @@ /// @file timer.h /// @brief Programmable Interval Timer (PIT) definitions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/io/mm_io.h b/mentos/inc/io/mm_io.h deleted file mode 100644 index 75f9084..0000000 --- a/mentos/inc/io/mm_io.h +++ /dev/null @@ -1,38 +0,0 @@ -/// @file mm_io.h -/// @brief Memory Mapped IO functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. -/// See LICENSE.md for details. - -#pragma once - -#include "stdint.h" - -/// @brief Reads a 8-bit value from the given address. -/// @param addr The address from which we read. -/// @return The content read from the address. -uint8_t in_memb(uint32_t addr); - -/// @brief Reads a 16-bit value from the given address. -/// @param addr The address from which we read. -/// @return The content read from the address. -uint16_t in_mems(uint32_t addr); - -/// @brief Reads a 32-bit value from the given address. -/// @param addr The address from which we read. -/// @return The content read from the address. -uint32_t in_meml(uint32_t addr); - -/// @brief Writes a 8-bit value at the given address. -/// @param addr The address where we want to write. -/// @param value The value we want to write. -void out_memb(uint32_t addr, uint8_t value); - -/// @brief Writes a 16-bit value at the given address. -/// @param addr The address where we want to write. -/// @param value The value we want to write. -void out_mems(uint32_t addr, uint16_t value); - -/// @brief Writes a 32-bit value at the given address. -/// @param addr The address where we want to write. -/// @param value The value we want to write. -void out_meml(uint32_t addr, uint32_t value); diff --git a/mentos/inc/io/port_io.h b/mentos/inc/io/port_io.h deleted file mode 100644 index c151556..0000000 --- a/mentos/inc/io/port_io.h +++ /dev/null @@ -1,50 +0,0 @@ -/// @file port_io.h -/// @brief Byte I/O on ports prototypes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. -/// See LICENSE.md for details. - -#pragma once - -#include "stdint.h" - -/// @brief Used for reading from the I/O ports. -/// @param port The input port. -/// @return The read value. -uint8_t inportb(uint16_t port); - -/// @brief Used for reading 2 bytes from the I/O ports. -/// @param port The input port. -/// @return The read value. -uint16_t inports(uint16_t port); - -/// @brief Read from the given port and store what we read in `data`. -/// @param port The input port. -/// @param data The buffer where we store what we read. -/// @param size The dimension of the buffer. -void inportsm(uint16_t port, uint8_t *data, unsigned long size); - -/// @brief Used for reading 4 bytes from the I/O ports. -/// @param port The input port. -/// @return The read value. -uint32_t inportl(uint16_t port); - -/// @brief Use this to write to I/O ports to send bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outportb(uint16_t port, uint8_t data); - -/// @brief Use this to write to I/O ports to send 2 bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outports(uint16_t port, uint16_t data); - -/// @brief Write to the given port what it is stored inside `data`. -/// @param port The output port. -/// @param data The buffer where we have the data. -/// @param size The dimension of the buffer. -void outportsm(uint16_t port, uint8_t *data, uint16_t size); - -/// @brief Use this to write to I/O ports to send 4 bytes to devices. -/// @param port The output port. -/// @param data The data to write. -void outportl(uint16_t port, uint32_t data); diff --git a/mentos/inc/io/proc_modules.h b/mentos/inc/io/proc_modules.h index 5712a5f..367be00 100644 --- a/mentos/inc/io/proc_modules.h +++ b/mentos/inc/io/proc_modules.h @@ -1,6 +1,6 @@ /// @file proc_modules.h /// @brief Contains functions for managing procfs filesystems. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/io/vga/vga.h b/mentos/inc/io/vga/vga.h index 4e04a28..0b56d85 100644 --- a/mentos/inc/io/vga/vga.h +++ b/mentos/inc/io/vga/vga.h @@ -1,6 +1,6 @@ /// @file vga.h /// @brief Functions required to manage the Video Graphics Array (VGA). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -38,6 +38,7 @@ void vga_draw_pixel(int x, int y, unsigned char color); /// @brief Reads a pixel at the given position. /// @param x x-axis position. /// @param y y-axis position. +/// @return the pixel we read. unsigned int vga_read_pixel(int x, int y); /// @brief Draws a character at the given position. @@ -114,6 +115,8 @@ void vga_get_screen_size(unsigned int * width, unsigned int * height); void vga_new_line(); /// @brief Change the color. +/// @param color the color to set. void vga_set_color(unsigned int color); +/// @brief Run some VGA tests. void vga_run_test(); diff --git a/mentos/inc/io/vga/vga_mode.h b/mentos/inc/io/vga/vga_mode.h index a7d4de8..cf92f4c 100644 --- a/mentos/inc/io/vga/vga_mode.h +++ b/mentos/inc/io/vga/vga_mode.h @@ -1,6 +1,6 @@ /// @file vga_mode.h /// @brief VGA models. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/io/vga/vga_palette.h b/mentos/inc/io/vga/vga_palette.h index a2addea..9a831aa 100644 --- a/mentos/inc/io/vga/vga_palette.h +++ b/mentos/inc/io/vga/vga_palette.h @@ -1,6 +1,6 @@ /// @file vga_palette.h /// @brief VGA color palettes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/io/video.h b/mentos/inc/io/video.h index 8924071..a92a37a 100644 --- a/mentos/inc/io/video.h +++ b/mentos/inc/io/video.h @@ -1,67 +1,12 @@ /// @file video.h /// @brief Video functions and costants. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once #include "stdint.h" - -#define FG_RESET "\033[0m" ///< ANSI code for resetting. - -#define FG_BLACK "\033[30m" ///< ANSI code for setting a BLACK foreground. -#define FG_RED "\033[31m" ///< ANSI code for setting a RED foreground. -#define FG_GREEN "\033[32m" ///< ANSI code for setting a GREEN foreground. -#define FG_YELLOW "\033[33m" ///< ANSI code for setting a YELLOW foreground. -#define FG_BLUE "\033[34m" ///< ANSI code for setting a BLUE foreground. -#define FG_MAGENTA "\033[35m" ///< ANSI code for setting a MAGENTA foreground. -#define FG_CYAN "\033[36m" ///< ANSI code for setting a CYAN foreground. -#define FG_WHITE "\033[37m" ///< ANSI code for setting a WHITE foreground. - -#define FG_BLACK_BOLD "\033[1;30m" ///< ANSI code for setting a BLACK foreground. -#define FG_RED_BOLD "\033[1;31m" ///< ANSI code for setting a RED foreground. -#define FG_GREEN_BOLD "\033[1;32m" ///< ANSI code for setting a GREEN foreground. -#define FG_YELLOW_BOLD "\033[1;33m" ///< ANSI code for setting a YELLOW foreground. -#define FG_BLUE_BOLD "\033[1;34m" ///< ANSI code for setting a BLUE foreground. -#define FG_MAGENTA_BOLD "\033[1;35m" ///< ANSI code for setting a MAGENTA foreground. -#define FG_CYAN_BOLD "\033[1;36m" ///< ANSI code for setting a CYAN foreground. -#define FG_WHITE_BOLD "\033[1;37m" ///< ANSI code for setting a WHITE foreground. - -#define FG_BLACK_BRIGHT "\033[90m" ///< ANSI code for setting a BRIGHT_BLACK foreground. -#define FG_RED_BRIGHT "\033[91m" ///< ANSI code for setting a BRIGHT_RED foreground. -#define FG_GREEN_BRIGHT "\033[92m" ///< ANSI code for setting a BRIGHT_GREEN foreground. -#define FG_YELLOW_BRIGHT "\033[93m" ///< ANSI code for setting a BRIGHT_YELLOW foreground. -#define FG_BLUE_BRIGHT "\033[94m" ///< ANSI code for setting a BRIGHT_BLUE foreground. -#define FG_MAGENTA_BRIGHT "\033[95m" ///< ANSI code for setting a BRIGHT_MAGENTA foreground. -#define FG_CYAN_BRIGHT "\033[96m" ///< ANSI code for setting a BRIGHT_CYAN foreground. -#define FG_WHITE_BRIGHT "\033[97m" ///< ANSI code for setting a BRIGHT_WHITE foreground. - -#define FG_BLACK_BRIGHT_BOLD "\033[1;90m" ///< ANSI code for setting a BRIGHT_BLACK foreground. -#define FG_RED_BRIGHT_BOLD "\033[1;91m" ///< ANSI code for setting a BRIGHT_RED foreground. -#define FG_GREEN_BRIGHT_BOLD "\033[1;92m" ///< ANSI code for setting a BRIGHT_GREEN foreground. -#define FG_YELLOW_BRIGHT_BOLD "\033[1;93m" ///< ANSI code for setting a BRIGHT_YELLOW foreground. -#define FG_BLUE_BRIGHT_BOLD "\033[1;94m" ///< ANSI code for setting a BRIGHT_BLUE foreground. -#define FG_MAGENTA_BRIGHT_BOLD "\033[1;95m" ///< ANSI code for setting a BRIGHT_MAGENTA foreground. -#define FG_CYAN_BRIGHT_BOLD "\033[1;96m" ///< ANSI code for setting a BRIGHT_CYAN foreground. -#define FG_WHITE_BRIGHT_BOLD "\033[1;97m" ///< ANSI code for setting a BRIGHT_WHITE foreground. - -#define BG_BLACK "\033[40m" ///< ANSI code for setting a BLACK background. -#define BG_RED "\033[41m" ///< ANSI code for setting a RED background. -#define BG_GREEN "\033[42m" ///< ANSI code for setting a GREEN background. -#define BG_YELLOW "\033[43m" ///< ANSI code for setting a YELLOW background. -#define BG_BLUE "\033[44m" ///< ANSI code for setting a BLUE background. -#define BG_MAGENTA "\033[45m" ///< ANSI code for setting a MAGENTA background. -#define BG_CYAN "\033[46m" ///< ANSI code for setting a CYAN background. -#define BG_WHITE "\033[47m" ///< ANSI code for setting a WHITE background. - -#define BG_BRIGHT_BLACK "\033[100m" ///< ANSI code for setting a BRIGHT_BLACK background. -#define BG_BRIGHT_RED "\033[101m" ///< ANSI code for setting a BRIGHT_RED background. -#define BG_BRIGHT_GREEN "\033[102m" ///< ANSI code for setting a BRIGHT_GREEN background. -#define BG_BRIGHT_YELLOW "\033[103m" ///< ANSI code for setting a BRIGHT_YELLOW background. -#define BG_BRIGHT_BLUE "\033[104m" ///< ANSI code for setting a BRIGHT_BLUE background. -#define BG_BRIGHT_MAGENTA "\033[105m" ///< ANSI code for setting a BRIGHT_MAGENTA background. -#define BG_BRIGHT_CYAN "\033[106m" ///< ANSI code for setting a BRIGHT_CYAN background. -#define BG_BRIGHT_WHITE "\033[107m" ///< ANSI code for setting a BRIGHT_WHITE background. +#include "io/ansi_colors.h" /// @brief Initialize the video. void video_init(); diff --git a/mentos/inc/kernel.h b/mentos/inc/kernel.h index c4dc707..37712d0 100644 --- a/mentos/inc/kernel.h +++ b/mentos/inc/kernel.h @@ -1,6 +1,6 @@ /// @file kernel.h /// @brief Kernel generic data structure and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/compiler.h b/mentos/inc/klib/compiler.h index 89a5d4b..916a013 100644 --- a/mentos/inc/klib/compiler.h +++ b/mentos/inc/klib/compiler.h @@ -36,7 +36,7 @@ /// CPU are perceived by the rest of the system as the operations cross the /// interface between the CPU and rest of the system (the dotted lines). /// -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/hashmap.h b/mentos/inc/klib/hashmap.h index f3f4291..b1eb0ed 100644 --- a/mentos/inc/klib/hashmap.h +++ b/mentos/inc/klib/hashmap.h @@ -1,6 +1,6 @@ /// @file hashmap.h /// @brief Functions for managing a structure that can map keys to values. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/irqflags.h b/mentos/inc/klib/irqflags.h index 6aba60e..825986c 100644 --- a/mentos/inc/klib/irqflags.h +++ b/mentos/inc/klib/irqflags.h @@ -1,6 +1,6 @@ /// @file irqflags.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -10,9 +10,10 @@ #include "stdint.h" /// @brief Enable IRQs (nested). -/// @details If called after calling irq_nested_disable, this function will -/// not activate IRQs if they were not active before. -inline static void irq_nested_enable(uint8_t flags) +/// @details If called after calling irq_disable, this function will not +/// activate IRQs if they were not active before. +/// @param flags the flags to control this behaviour. +inline static void irq_enable(uint8_t flags) { if (flags) { sti(); @@ -20,32 +21,32 @@ inline static void irq_nested_enable(uint8_t flags) } /// @brief Disable IRQs (nested). -/// @details Disable IRQs when unsure if IRQs were enabled at all. -/// This function together with irq_nested_enable can be used in -/// situations when interrupts shouldn't be activated if they were not -/// activated before calling this function. -inline static uint8_t irq_nested_disable() +/// @details Disable IRQs when unsure if IRQs were enabled at all. This function +/// together with irq_enable can be used in situations when interrupts +/// shouldn't be activated if they were not activated before calling this +/// function. +/// @return 1 if the IRQ is enable for the CPU. +inline static uint8_t irq_disable() { size_t flags; - __asm__ __volatile__("pushf; cli; pop %0" + // We are pushing the entire contents of the EFLAGS register onto the stack, + // clearing the interrupt line, and with the pop, getting the current status + // of the flags. + __asm__ __volatile__("pushf; cli; pop %0;" : "=r"(flags) : : "memory"); - if (flags & (1 << 9)) - return 1; - return 0; + return flags & (1 << 9); } /// @brief Determines, if the interrupt flags (IF) is set. +/// @return 1 if the IRQ is enable for the CPU. inline static uint8_t is_irq_enabled() { size_t flags; - __asm__ __volatile__("pushf; pop %0" + __asm__ __volatile__("pushf; pop %0;" : "=r"(flags) : : "memory"); - if (flags & (1 << 9)) { - return 1; - } - return 0; + return flags & (1 << 9); } diff --git a/mentos/inc/klib/list.h b/mentos/inc/klib/list.h index 99f90a7..9de0e35 100644 --- a/mentos/inc/klib/list.h +++ b/mentos/inc/klib/list.h @@ -1,6 +1,6 @@ /// @file list.h /// @brief An implementation for generic list. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/list_head.h b/mentos/inc/klib/list_head.h index f000c97..bcb41e6 100644 --- a/mentos/inc/klib/list_head.h +++ b/mentos/inc/klib/list_head.h @@ -1,6 +1,6 @@ /// @file list_head.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -62,8 +62,9 @@ static inline int list_head_empty(const list_head *head) return head->next == head; } -/// @brief Initializes the list_head. -/// @param head The head for your list. +/// @brief Computes the size of the list. +/// @param head The head of the list. +/// @return the size of the list. static inline unsigned list_head_size(const list_head *head) { unsigned size = 0; diff --git a/mentos/inc/klib/mutex.h b/mentos/inc/klib/mutex.h index ec25346..2e9a91c 100644 --- a/mentos/inc/klib/mutex.h +++ b/mentos/inc/klib/mutex.h @@ -1,6 +1,6 @@ /// @file mutex.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/ndtree.h b/mentos/inc/klib/ndtree.h index 826659d..da4ee76 100644 --- a/mentos/inc/klib/ndtree.h +++ b/mentos/inc/klib/ndtree.h @@ -1,6 +1,6 @@ /// @file ndtree.h /// @brief N-Dimensional tree. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/rbtree.h b/mentos/inc/klib/rbtree.h index e990197..255cbb0 100644 --- a/mentos/inc/klib/rbtree.h +++ b/mentos/inc/klib/rbtree.h @@ -1,6 +1,6 @@ /// @file rbtree.h /// @brief Red/Black tree. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/spinlock.h b/mentos/inc/klib/spinlock.h index 8b8e1f1..7e094c7 100644 --- a/mentos/inc/klib/spinlock.h +++ b/mentos/inc/klib/spinlock.h @@ -1,6 +1,6 @@ /// @file spinlock.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/stack_helper.h b/mentos/inc/klib/stack_helper.h index 3da2807..00a33b4 100644 --- a/mentos/inc/klib/stack_helper.h +++ b/mentos/inc/klib/stack_helper.h @@ -1,6 +1,6 @@ /// @file stack_helper.h /// @brief Couple of macros that help accessing the stack. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/klib/stdatomic.h b/mentos/inc/klib/stdatomic.h index f56af0a..4ad9510 100644 --- a/mentos/inc/klib/stdatomic.h +++ b/mentos/inc/klib/stdatomic.h @@ -1,12 +1,10 @@ /// @file stdatomic.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once -#include "stdint.h" -#include "stdbool.h" #include "klib/compiler.h" /// @brief Standard structure for atomic operations (see below @@ -28,87 +26,109 @@ typedef volatile unsigned atomic_t; : \ : "memory") -/// @brief Atomically sets the value of ptr with the value of x. -/// -/// @param ptr Pointer to the atomic variable to set. -/// @param x The value to set. +/// @brief Atomically sets `value` at `ptr`. +/// @param ptr the pointer we are working with. +/// @param value the value to set. /// @return The final value of the atomic variable. -inline static int32_t atomic_set_and_test(atomic_t *ptr, int32_t x) +inline static int atomic_set_and_test(atomic_t *ptr, int value) { - __asm__ __volatile__("xchgl %0,%1" // instruction - : "=r"(x) // outputs - : "m"(*ptr), "0"(x) // inputs - : "memory"); // side effects - return x; + // The + in "+r" and "+m" denotes a read-modify-write operand. + __asm__ __volatile__(LOCK_PREFIX // Lock + "xchgl %0, %1" // Instruction + : "+r"(value), "+m"(*ptr) // Input + Output + : // No input-only + : "memory"); // Side effects + return value; } -/// @brief Atomically set ptr equal to i. -inline static void atomic_set(atomic_t *ptr, int32_t i) +/// @brief Atomically set the value pointed by `ptr` to `value`. +/// @param ptr the pointer we are working with. +/// @param value the value we need to set. +inline static void atomic_set(atomic_t *ptr, int value) { - atomic_set_and_test(ptr, i); + atomic_set_and_test(ptr, value); } -/// @brief Atomically read the integer value of ptr. -inline static int32_t atomic_read(const atomic_t *ptr) +/// @brief Atomically read the value pointed by `ptr`. +/// @param ptr the pointer we are working with. +/// @return the value we read. +inline static int atomic_read(const atomic_t *ptr) { return READ_ONCE(*ptr); } -/// @brief Atomically add i to ptr. -inline static int32_t atomic_add(atomic_t const *ptr, int32_t i) +/// @brief Atomically add `value` to the value pointed by `ptr`. +/// @param ptr the pointer we are working with. +/// @param value the value we need to add. +/// @return the result of the operation. +inline static int atomic_add(atomic_t *ptr, int value) { - int result = i; - __asm__ __volatile__(LOCK_PREFIX "xaddl %0, %1" - : "=r"(i) - : "m"(ptr), "0"(i) - : "memory", "cc"); - return result + i; + // The + in "+r" and "+m" denotes a read-modify-write operand. + __asm__ __volatile__(LOCK_PREFIX // Lock + "xaddl %0, %1" // Instruction + : "+r"(value), "+m"(*ptr) // Input + Output + : // No input-only + : "memory"); // Side effects + return value; } -/// @brief Atomically subtract i from ptr. -inline static int32_t atomic_sub(atomic_t *ptr, int32_t i) +/// @brief Atomically subtract `value` from the value pointed by `ptr`. +/// @param ptr the pointer we are working with. +/// @param value the value we need to subtract. +/// @return the result of the operation. +inline static int atomic_sub(atomic_t *ptr, int value) { - return atomic_add(ptr, -i); + return atomic_add(ptr, -value); } -/// @brief Atomically add one to ptr. -inline static int32_t atomic_inc(atomic_t *ptr) +/// @brief Atomically increment the value at `ptr`. +/// @param ptr the pointer we are working with. +/// @return the result of the operation. +inline static int atomic_inc(atomic_t *ptr) { return atomic_add(ptr, 1); } -/// @brief Atomically subtract one from ptr. -inline static int32_t atomic_dec(atomic_t *ptr) +/// @brief Atomically decrement the value at `ptr`. +/// @param ptr the pointer we are working with. +/// @return the result of the operation. +inline static int atomic_dec(atomic_t *ptr) { return atomic_add(ptr, -1); } -/// @brief Atomically add i to ptr and return true if the result is negative; -/// otherwise false. -inline static bool_t atomic_add_negative(atomic_t *ptr, int32_t i) +/// @brief Atomically add `value` to `ptr` and checks if the result is negative. +/// @param ptr the pointer we are working with. +/// @param value the value we need to add. +/// @return true if the result is negative, false otherwise. +inline static int atomic_add_negative(atomic_t *ptr, int value) { - return (bool_t)(atomic_add(ptr, i) < 0); + return atomic_add(ptr, value) < 0; } -/// @brief Atomically subtract i from ptr and return true if the result is -/// zero; otherwise false. -inline static bool_t atomic_sub_and_test(atomic_t *ptr, int32_t i) +/// @brief Atomically subtract `value` from `ptr` and checks if the result is zero. +/// @param ptr the pointer we are working with. +/// @param value the value we need to subtract. +/// @return true if the result is zero, false otherwise. +inline static int atomic_sub_and_test(atomic_t *ptr, int value) { - return (bool_t)(atomic_sub(ptr, i) == 0); + return atomic_sub(ptr, value) == 0; } -/// @brief Atomically increment ptr by one and return true if the result is -/// zero; false otherwise. -inline static int32_t atomic_inc_and_test(atomic_t *ptr) +/// @brief Atomically increment `ptr` and checks if the result is zero. +/// @param ptr the pointer we are working with. +/// @return true if the result is zero, false otherwise. +inline static int atomic_inc_and_test(atomic_t *ptr) { - return (bool_t)(atomic_inc(ptr) == 0); + return atomic_inc(ptr) == 0; } -/// @brief Atomically decrement ptr by one and return true if zero; false -/// otherwise. -inline static int32_t atomic_dec_and_test(atomic_t *ptr) +/// @brief Atomically decrement `ptr` and checks if the result is zero. +/// @param ptr the pointer we are working with. +/// @return true if the result is zero, false otherwise. +inline static int atomic_dec_and_test(atomic_t *ptr) { - return (bool_t)(atomic_dec(ptr) == 0); + return atomic_dec(ptr) == 0; } /// @brief Atomically sets a bit in memory, using Bit Test And Set (bts). @@ -116,7 +136,7 @@ inline static int32_t atomic_dec_and_test(atomic_t *ptr) /// @param base The base address. static inline void set_bit(int offset, volatile unsigned long *base) { - __asm__ __volatile__("btsl %[offset],%[base]" + __asm__ __volatile__("btsl %[offset], %[base]" : [base] "=m"(*(volatile long *)base) : [offset] "Ir"(offset)); } diff --git a/mentos/inc/link_access.h b/mentos/inc/link_access.h index c0072fa..1c735e8 100644 --- a/mentos/inc/link_access.h +++ b/mentos/inc/link_access.h @@ -1,6 +1,6 @@ /// @file link_access.h /// @brief Set of macros that provide access to linking symbols. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/buddysystem.h b/mentos/inc/mem/buddysystem.h index 13dbf5c..fe78de5 100644 --- a/mentos/inc/mem/buddysystem.h +++ b/mentos/inc/mem/buddysystem.h @@ -1,6 +1,6 @@ /// @file buddysystem.h /// @brief Buddy System. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/gfp.h b/mentos/inc/mem/gfp.h index 2094e06..11f7d45 100644 --- a/mentos/inc/mem/gfp.h +++ b/mentos/inc/mem/gfp.h @@ -1,6 +1,6 @@ /// @file gfp.h /// @brief List of Get Free Pages (GFP) Flags. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/kheap.h b/mentos/inc/mem/kheap.h index 46aba53..f3aefcf 100644 --- a/mentos/inc/mem/kheap.h +++ b/mentos/inc/mem/kheap.h @@ -1,7 +1,7 @@ /// @file kheap.h /// @brief Interface for kernel heap functions, also provides a placement /// malloc() for use before the heap is initialised. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/paging.h b/mentos/inc/mem/paging.h index a2c1797..abdeac4 100644 --- a/mentos/inc/mem/paging.h +++ b/mentos/inc/mem/paging.h @@ -1,6 +1,6 @@ /// @file paging.h /// @brief Implementation of a memory paging management. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/slab.h b/mentos/inc/mem/slab.h index 67e3d6c..7908022 100644 --- a/mentos/inc/mem/slab.h +++ b/mentos/inc/mem/slab.h @@ -1,6 +1,6 @@ /// @file slab.h /// @brief Functions and structures for managing memory slabs. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/vmem_map.h b/mentos/inc/mem/vmem_map.h index 07f7719..343c1d2 100644 --- a/mentos/inc/mem/vmem_map.h +++ b/mentos/inc/mem/vmem_map.h @@ -1,6 +1,6 @@ /// @file vmem_map.h /// @brief Virtual memory mapping routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/mem/zone_allocator.h b/mentos/inc/mem/zone_allocator.h index e828ef1..a24c50b 100644 --- a/mentos/inc/mem/zone_allocator.h +++ b/mentos/inc/mem/zone_allocator.h @@ -1,6 +1,6 @@ /// @file zone_allocator.h /// @brief Implementation of the Zone Allocator -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/multiboot.h b/mentos/inc/multiboot.h index 212c5a7..f1c9aa0 100644 --- a/mentos/inc/multiboot.h +++ b/mentos/inc/multiboot.h @@ -1,6 +1,6 @@ /// @file multiboot.h /// @brief Data structures used for multiboot. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. // Do not inc here in boot.s. diff --git a/mentos/inc/proc_access.h b/mentos/inc/proc_access.h index eb2f3ae..835904e 100644 --- a/mentos/inc/proc_access.h +++ b/mentos/inc/proc_access.h @@ -1,15 +1,12 @@ /// @file proc_access.h /// @brief Set of functions and flags used to manage processors registers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once #include "stdint.h" -/// Macro that encapsulate asm and volatile directives. -#define ASM(a) __asm__ __volatile__(a) - #define CR0_PE 0x00000001u ///< Protected mode Enable. #define CR0_MP 0x00000002u ///< "Math" Present (e.g. npx), wait for it. #define CR0_EM 0x00000004u ///< EMulate NPX, e.g. trap, don't execute code. @@ -37,218 +34,275 @@ #define CR4_PVI 0x00000002u ///< Protected-mode Virtual Interrupts. #define CR4_VME 0x00000001u ///< Virtual-8086 Mode Extensions. -static inline uint16_t get_es(void) +/// @brief Reads the Extra Segment (DS). +/// @return the value we read. +static inline uint16_t get_es() { uint16_t es; - ASM("mov %%es, %0" - : "=r"(es)); + __asm__ __volatile__("mov %%es, %0" + : "=r"(es)); return es; } +/// @brief Sets the Extra Segment (DS). +/// @param es the value we set. static inline void set_es(uint16_t es) { - ASM("mov %0, %%es" - : - : "r"(es)); + __asm__ __volatile__("mov %0, %%es" + : + : "r"(es)); } -static inline uint16_t get_ds(void) +/// @brief Reads the Data Segment (DS). +/// @return the value we read. +static inline uint16_t get_ds() { uint16_t ds; - ASM("mov %%ds, %0" - : "=r"(ds)); + __asm__ __volatile__("mov %%ds, %0" + : "=r"(ds)); return ds; } +/// @brief Sets the Data Segment (DS). +/// @param ds the value we set. static inline void set_ds(uint16_t ds) { - ASM("mov %0, %%ds" - : - : "r"(ds)); + __asm__ __volatile__("mov %0, %%ds" + : + : "r"(ds)); } -static inline uint16_t get_fs(void) +/// @brief Reads FS. +/// @return the value we read. +static inline uint16_t get_fs() { uint16_t fs; - ASM("mov %%fs, %0" - : "=r"(fs)); + __asm__ __volatile__("mov %%fs, %0" + : "=r"(fs)); return fs; } +/// @brief Sets FS. +/// @param fs the value we set. static inline void set_fs(uint16_t fs) { - ASM("mov %0, %%fs" - : - : "r"(fs)); + __asm__ __volatile__("mov %0, %%fs" + : + : "r"(fs)); } -static inline uint16_t get_gs(void) +/// @brief Reads GS. +/// @return the value we read. +static inline uint16_t get_gs() { uint16_t gs; - ASM("mov %%gs, %0" - : "=r"(gs)); + __asm__ __volatile__("mov %%gs, %0" + : "=r"(gs)); return gs; } +/// @brief Sets GS. +/// @param gs the value we set. static inline void set_gs(uint16_t gs) { - ASM("mov %0, %%gs" - : - : "r"(gs)); + __asm__ __volatile__("mov %0, %%gs" + : + : "r"(gs)); } -static inline uint16_t get_ss(void) +/// @brief Reads the Stack Segment (SS). +/// @return the value we read. +static inline uint16_t get_ss() { uint16_t ss; - ASM("mov %%ss, %0" - : "=r"(ss)); + __asm__ __volatile__("mov %%ss, %0" + : "=r"(ss)); return ss; } +/// @brief Sets the Stack Segment (SS). +/// @param ss the value we set. static inline void set_ss(uint16_t ss) { - ASM("mov %0, %%ss" - : - : "r"(ss)); + __asm__ __volatile__("mov %0, %%ss" + : + : "r"(ss)); } -static inline uintptr_t get_cr0(void) +/// @brief Reads the current cr0 value. +/// @return the value we read. +static inline uintptr_t get_cr0() { uintptr_t cr0; - ASM("mov %%cr0, %0" - : "=r"(cr0)); + __asm__ __volatile__("mov %%cr0, %0" + : "=r"(cr0)); return (cr0); } +/// @brief Sets the cr0 value. +/// @param cr0 the value we want to set. static inline void set_cr0(uintptr_t cr0) { - ASM("mov %0, %%cr0" - : - : "r"(cr0)); + __asm__ __volatile__("mov %0, %%cr0" + : + : "r"(cr0)); } -static inline uintptr_t get_cr3(void) +/// @brief Reads the current cr3 value. +/// @return the value we read. +static inline uintptr_t get_cr3() { uintptr_t cr3; - ASM("mov %%cr3, %0" - : "=r"(cr3)); + __asm__ __volatile__("mov %%cr3, %0" + : "=r"(cr3)); return (cr3); } +/// @brief Sets the cr3 value. +/// @param cr3 the value we want to set. static inline void set_cr3(uintptr_t cr3) { - ASM("mov %0, %%cr3" - : - : "r"(cr3)); + __asm__ __volatile__("mov %0, %%cr3" + : + : "r"(cr3)); } -static inline uintptr_t get_cr4(void) +/// @brief Reads the current cr4 value. +/// @return the value we read. +static inline uintptr_t get_cr4() { uintptr_t cr4; - ASM("mov %%cr4, %0" - : "=r"(cr4)); + __asm__ __volatile__("mov %%cr4, %0" + : "=r"(cr4)); return (cr4); } +/// @brief Sets the cr4 value. +/// @param cr4 the value we want to set. static inline void set_cr4(uintptr_t cr4) { - ASM("mov %0, %%cr4" - : - : "r"(cr4) - : "memory"); + __asm__ __volatile__("mov %0, %%cr4" + : + : "r"(cr4) + : "memory"); } -static inline uintptr_t get_eflags(void) +/// @brief Reads entire contents of the EFLAGS register. +/// @return the content of EFLAGS. +static inline uintptr_t get_eflags() { uintptr_t eflags; - /* "=rm" is safe here, because "pop" adjusts the stack before - * it evaluates its effective address -- this is part of the - * documented behavior of the "pop" instruction. - */ - ASM("pushf ; pop %0" - : "=rm"(eflags) - : /* no input */ - : "memory"); + // "=rm" is safe here, because "pop" adjusts the stack before + // it evaluates its effective address -- this is part of the + // documented behavior of the "pop" instruction. + __asm__ __volatile__("pushf; pop %0" + : "=rm"(eflags) + : // no input + : "memory"); return eflags; } -static inline void clear_ts(void) +/// @brief Clears the task-switched (TS) flag in the CR0 register. +static inline void clear_ts() { - ASM("clts"); + __asm__ __volatile__("clts"); } -static inline unsigned short get_tr(void) +/// @brief Reads the segment selector from the task register (TR). +/// @return +static inline unsigned short get_tr() { unsigned short seg; - ASM("str %0" - : "=rm"(seg)); + __asm__ __volatile__("str %0" + : "=rm"(seg)); return (seg); } -static inline void set_tr(unsigned int seg) +/// @brief Loads the source operand into the segment selector field of the task register. +/// @param seg the segment selector we want to set. +static inline void set_tr(unsigned short seg) { - ASM("ltr %0" - : - : "rm"((unsigned short)(seg))); + __asm__ __volatile__("ltr %0" + : + : "rm"(seg)); } -static inline unsigned short sldt(void) +/// @brief Reads the segment selector from the local descriptor table register (LDTR). +/// @return the segment selector. +static inline unsigned short sldt() { unsigned short seg; - ASM("sldt %0" - : "=rm"(seg)); + __asm__ __volatile__("sldt %0" + : "=rm"(seg)); return (seg); } -static inline void lldt(unsigned int seg) +/// @brief Loads the source operand into the segment selector field of the local descriptor table register (LDTR). +/// @param seg The segment selector we need to set. +static inline void lldt(unsigned short seg) { - ASM("lldt %0" - : - : "rm"((unsigned short)(seg))); + __asm__ __volatile__("lldt %0" + : + : "rm"(seg)); } +/// @brief Loads the values in the source operand into the global descriptor +/// table register (GDTR) or the interrupt descriptor table register (IDTR). +/// @param desc the value we need to load. static inline void lgdt(uintptr_t *desc) { - ASM("lgdt %0" - : - : "m"(*desc)); + __asm__ __volatile__("lgdt %0" + : + : "m"(*desc)); } +/// @brief Loads the values in the source operand into the global descriptor +/// table register (GDTR) or the interrupt descriptor table register (IDTR). +/// @param desc the value we need to load. static inline void lidt(uintptr_t *desc) { - ASM("lidt %0" - : - : "m"(*desc)); + __asm__ __volatile__("lidt %0" + : + : "m"(*desc)); } -/// @brief Enable IRQs. +/// @brief Set interrupt flag; external, maskable interrupts enabled at the end +/// of the next instruction. static inline void sti() { - ASM("sti" :: - : "memory"); + __asm__ __volatile__("sti" + : + : + : "memory"); } -/// @brief Disable IRQs. +/// @brief Clear interrupt flag; interrupts disabled when interrupt flag +/// cleared. static inline void cli() { - ASM("cli" :: - : "memory"); + __asm__ __volatile__("cli" + : + : + : "memory"); } -static inline void swapgs(void) +/// @brief Exchanges the current GS base register value with the value contained +/// in MSR address C0000102H. +static inline void swapgs() { - ASM("swapgs"); + __asm__ __volatile__("swapgs"); } -static inline void hlt(void) +/// @brief Halts the CPU until the next external interrupt is fired. +static inline void hlt() { - ASM("hlt"); + __asm__ __volatile__("hlt"); } -/// @brief Pause. +/// @brief Gives hint to processor that improves performance of spin-wait loops. static inline void pause() { - ASM("pause"); + __asm__ __volatile__("pause"); } // == Memory clobbers ========================================================= @@ -266,6 +320,6 @@ static inline void pause() // Making an inline asm block "volatile" as in this example, ensures that, // as it optimizes, the compiler does not move any instructions above or // below the block of asm statements. -// ASM(" addic. %0,%1,%2\n" : "=r"(res): "=r"(a),"r"(a)) +// __asm__ __volatile__(" addic. %0,%1,%2\n" : "=r"(res): "=r"(a),"r"(a)) // This can be particularly important in cases when the code is accessing // shared memory. diff --git a/mentos/inc/process/prio.h b/mentos/inc/process/prio.h index 157006d..44bc73a 100644 --- a/mentos/inc/process/prio.h +++ b/mentos/inc/process/prio.h @@ -1,6 +1,6 @@ /// @file prio.h /// @brief Defines processes priority value. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. // Priority of a process goes from 0..MAX_PRIO-1, valid RT diff --git a/mentos/inc/process/process.h b/mentos/inc/process/process.h index 6c0e032..8e134f0 100644 --- a/mentos/inc/process/process.h +++ b/mentos/inc/process/process.h @@ -1,6 +1,6 @@ /// @file process.h /// @brief Process data structures and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -10,6 +10,7 @@ #include "system/signal.h" #include "devices/fpu.h" #include "mem/paging.h" +#include "stdbool.h" /// The maximum length of a name for a task_struct. #define TASK_NAME_MAX_LENGTH 100 diff --git a/mentos/inc/process/scheduler.h b/mentos/inc/process/scheduler.h index 350debe..14b9f30 100644 --- a/mentos/inc/process/scheduler.h +++ b/mentos/inc/process/scheduler.h @@ -1,6 +1,6 @@ /// @file scheduler.h /// @brief Scheduler structures and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/process/wait.h b/mentos/inc/process/wait.h index 28858d1..b40eeb2 100644 --- a/mentos/inc/process/wait.h +++ b/mentos/inc/process/wait.h @@ -1,6 +1,6 @@ /// @file wait.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/errno.h b/mentos/inc/sys/errno.h index 92ecf41..bda3daa 100644 --- a/mentos/inc/sys/errno.h +++ b/mentos/inc/sys/errno.h @@ -1,6 +1,6 @@ /// @file errno.h /// @brief Errors definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/ipc.h b/mentos/inc/sys/ipc.h index 8acd173..6c0c2ff 100644 --- a/mentos/inc/sys/ipc.h +++ b/mentos/inc/sys/ipc.h @@ -1,6 +1,6 @@ /// @file ipc.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/kernel_levels.h b/mentos/inc/sys/kernel_levels.h deleted file mode 100644 index 3832468..0000000 --- a/mentos/inc/sys/kernel_levels.h +++ /dev/null @@ -1,30 +0,0 @@ -/// @file kernel_levels.h -/// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. -/// See LICENSE.md for details. - -#pragma once - -#define KERN_SOH "\001" ///< ASCII Start Of Header. -#define KERN_SOH_ASCII '\001' ///< Character version of the SOH. - -#define KERN_EMERG KERN_SOH "0" ///< Emergency messages (precede a crash) -#define KERN_ALERT KERN_SOH "1" ///< Error requiring immediate attention -#define KERN_CRIT KERN_SOH "2" ///< Critical error (hardware or software) -#define KERN_ERR KERN_SOH "3" ///< Error conditions (common in drivers) -#define KERN_WARNING KERN_SOH "4" ///< Warning conditions (could lead to errors) -#define KERN_NOTICE KERN_SOH "5" ///< Not an error but a significant condition -#define KERN_INFO KERN_SOH "6" ///< Informational message -#define KERN_DEBUG KERN_SOH "7" ///< Used only for debug messages -#define KERN_DEFAULT "" ///< Default kernel logging level - -// Integer equivalents of KERN_ -#define LOGLEVEL_DEFAULT (-1) ///< default-level messages. -#define LOGLEVEL_EMERG 0 ///< system is unusable. -#define LOGLEVEL_ALERT 1 ///< action must be taken immediately. -#define LOGLEVEL_CRIT 2 ///< critical conditions. -#define LOGLEVEL_ERR 3 ///< error conditions. -#define LOGLEVEL_WARNING 4 ///< warning conditions. -#define LOGLEVEL_NOTICE 5 ///< normal but significant condition. -#define LOGLEVEL_INFO 6 ///< informational. -#define LOGLEVEL_DEBUG 7 ///< debug-level messages. diff --git a/mentos/inc/sys/module.h b/mentos/inc/sys/module.h index 2767c16..41429ee 100644 --- a/mentos/inc/sys/module.h +++ b/mentos/inc/sys/module.h @@ -1,6 +1,6 @@ /// @file module.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/reboot.h b/mentos/inc/sys/reboot.h index de4da85..49c18f2 100644 --- a/mentos/inc/sys/reboot.h +++ b/mentos/inc/sys/reboot.h @@ -1,6 +1,6 @@ /// @file reboot.h /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/types.h b/mentos/inc/sys/types.h index 424a076..35276fe 100644 --- a/mentos/inc/sys/types.h +++ b/mentos/inc/sys/types.h @@ -1,6 +1,6 @@ /// @file types.h /// @brief Collection of Kernel datatype -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/sys/utsname.h b/mentos/inc/sys/utsname.h index 512b9ff..ce520ab 100644 --- a/mentos/inc/sys/utsname.h +++ b/mentos/inc/sys/utsname.h @@ -1,6 +1,6 @@ /// @file utsname.h /// @brief Functions used to provide information about the machine & OS. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/system/panic.h b/mentos/inc/system/panic.h index 98ca362..bbb2ce7 100644 --- a/mentos/inc/system/panic.h +++ b/mentos/inc/system/panic.h @@ -1,13 +1,13 @@ /// @file panic.h /// @brief Functions used to manage kernel panic. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once -/// @brief Prints the given message and then safely stop the execution of -/// the kernel. +/// @brief Prints the given message and safely stop the execution of the kernel. /// @param msg The message that has to be shown. void kernel_panic(const char *msg); +/// @brief Sends a kernel panic with the given message. #define TODO(msg) kernel_panic(#msg); diff --git a/mentos/inc/system/printk.h b/mentos/inc/system/printk.h index 38212c4..63213b4 100644 --- a/mentos/inc/system/printk.h +++ b/mentos/inc/system/printk.h @@ -1,6 +1,6 @@ /// @file printk.h /// @brief Functions for managing the kernel messages. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/inc/system/signal.h b/mentos/inc/system/signal.h index bf892c0..a40589b 100644 --- a/mentos/inc/system/signal.h +++ b/mentos/inc/system/signal.h @@ -1,6 +1,6 @@ /// @file signal.h /// @brief Signals definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -285,12 +285,16 @@ int sys_sigaction(int signum, const sigaction_t *act, sigaction_t *oldact, uint3 /// @param set The set of signals to manage by the function. /// @param oldset If non-NULL, the previous value of the signal mask is stored here. /// @return returns 0 on success, and -1 on error (errno is set to indicate the cause). -/// @details -/// If set is NULL, then the signal mask is unchanged (i.e., how is -/// ignored), but the current value of the signal mask is -/// nevertheless returned in oldset (if it is not NULL). +/// @details If set is NULL, then the signal mask is unchanged (i.e., how is +/// ignored), but the current value of the signal mask is nevertheless returned +/// in oldset (if it is not NULL). int sys_sigprocmask(int how, const sigset_t *set, sigset_t *oldset); +/// @brief Provides a snapshot of pending signals. +/// @param set where the set of pending signals is returned. +/// @return 0 on success, -1 on failure and errno is set to indicate the error. +int sys_sigpending(sigset_t *set); + /// @brief Returns the string describing the given signal. /// @param sig The signal to inquire. /// @return String representing the signal. diff --git a/mentos/inc/system/syscall.h b/mentos/inc/system/syscall.h index a2d08aa..a1e7778 100644 --- a/mentos/inc/system/syscall.h +++ b/mentos/inc/system/syscall.h @@ -1,6 +1,6 @@ /// @file syscall.h /// @brief System Call handler definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once @@ -38,7 +38,7 @@ ssize_t sys_read(int fd, void *buf, size_t nbytes); /// @param buf The buffer collecting data to written. /// @param nbytes The number of bytes to write. /// @return The number of written bytes. -ssize_t sys_write(int fd, void *buf, size_t nbytes); +ssize_t sys_write(int fd, const void *buf, size_t nbytes); /// @brief Repositions the file offset inside a file. /// @param fd The file descriptor of the file. @@ -225,7 +225,7 @@ int sys_creat(const char *path, mode_t mode); /// @return On success, the number of bytes read is returned. On end of /// directory, 0 is returned. On error, -1 is returned, and errno is set /// appropriately. -int sys_getdents(int fd, dirent_t *dirp, unsigned int count); +ssize_t sys_getdents(int fd, dirent_t *dirp, unsigned int count); /// @brief Returns the current time. /// @param time Where the time should be stored. diff --git a/mentos/inc/version.h b/mentos/inc/version.h index 6d65b36..ef4fba8 100644 --- a/mentos/inc/version.h +++ b/mentos/inc/version.h @@ -1,6 +1,6 @@ /// @file version.h /// @brief Version information. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #pragma once diff --git a/mentos/src/boot.c b/mentos/src/boot.c index be96160..16817f8 100644 --- a/mentos/src/boot.c +++ b/mentos/src/boot.c @@ -1,7 +1,6 @@ -/// MentOS, The Mentoring Operating system project /// @file boot.c /// @brief Bootloader. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "boot.h" @@ -42,7 +41,7 @@ static page_directory_t boot_pgdir; /// @brief Boot page tables. static page_table_t boot_pgtables[1024]; -/// @brief Use this to write to I/O ports to send bytes to devices. +/// @brief Use this to write to I/O ports to send bytes to devices. /// @param port The output port. /// @param data The data to write. static inline void __outportb(uint16_t port, uint8_t data) diff --git a/mentos/src/descriptor_tables/exception.c b/mentos/src/descriptor_tables/exception.c index 6747f57..a571a96 100644 --- a/mentos/src/descriptor_tables/exception.c +++ b/mentos/src/descriptor_tables/exception.c @@ -1,20 +1,18 @@ /// @file exception.c /// @brief Functions which manage the Interrupt Service Routines (ISRs). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[EXEPT ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[EXEPT ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "system/panic.h" #include "descriptor_tables/isr.h" #include "descriptor_tables/idt.h" #include "stdio.h" -#include "io/debug.h" // Default error messages for exceptions. static const char *exception_messages[32] = { diff --git a/mentos/src/descriptor_tables/gdt.c b/mentos/src/descriptor_tables/gdt.c index 8420e3c..0dbaeb4 100644 --- a/mentos/src/descriptor_tables/gdt.c +++ b/mentos/src/descriptor_tables/gdt.c @@ -1,16 +1,14 @@ /// @file gdt.c /// @brief Functions which manage the Global Descriptor Table (GDT). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[GDT ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[GDT ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. -#include "io/debug.h" #include "descriptor_tables/gdt.h" #include "descriptor_tables/tss.h" diff --git a/mentos/src/descriptor_tables/idt.c b/mentos/src/descriptor_tables/idt.c index 7e2c151..ecade14 100644 --- a/mentos/src/descriptor_tables/idt.c +++ b/mentos/src/descriptor_tables/idt.c @@ -1,14 +1,13 @@ /// @file idt.c /// @brief Functions which manage the Interrupt Descriptor Table (IDT). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[IDT ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[IDT ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "descriptor_tables/idt.h" #include "descriptor_tables/gdt.h" diff --git a/mentos/src/descriptor_tables/interrupt.c b/mentos/src/descriptor_tables/interrupt.c index 333c29d..dc9f647 100644 --- a/mentos/src/descriptor_tables/interrupt.c +++ b/mentos/src/descriptor_tables/interrupt.c @@ -1,23 +1,20 @@ /// @file interrupt.c /// @brief Functions which manage the Interrupt Service Routines (ISRs). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[IRQ ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[IRQ ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "descriptor_tables/isr.h" - #include "process/scheduler.h" #include "hardware/pic8259.h" #include "system/printk.h" #include "assert.h" #include "stdio.h" -#include "io/debug.h" #include "descriptor_tables/idt.h" /// @brief Shared interrupt handlers, stored into a double-linked list. diff --git a/mentos/src/descriptor_tables/tss.c b/mentos/src/descriptor_tables/tss.c index 542c8b1..271e8f5 100644 --- a/mentos/src/descriptor_tables/tss.c +++ b/mentos/src/descriptor_tables/tss.c @@ -1,19 +1,16 @@ /// @file tss.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[TSS ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[TSS ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "descriptor_tables/tss.h" - #include "string.h" -#include "io/debug.h" #include "descriptor_tables/gdt.h" static tss_entry_t kernel_tss; diff --git a/mentos/src/devices/fpu.c b/mentos/src/devices/fpu.c index 00612dd..b45e034 100644 --- a/mentos/src/devices/fpu.c +++ b/mentos/src/devices/fpu.c @@ -1,18 +1,16 @@ /// @file fpu.c /// @brief Floating Point Unit (FPU). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[FPU ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[FPU ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "devices/fpu.h" #include "descriptor_tables/isr.h" -#include "io/debug.h" #include "string.h" #include "assert.h" #include "process/scheduler.h" diff --git a/mentos/src/devices/pci.c b/mentos/src/devices/pci.c index d6866d2..b14f29f 100644 --- a/mentos/src/devices/pci.c +++ b/mentos/src/devices/pci.c @@ -1,18 +1,16 @@ /// @file pci.c /// @brief Routines for PCI initialization. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. ///! @cond Doxygen_Suppress -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PCI ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PCI ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "devices/pci.h" -#include "io/debug.h" #include "string.h" #include "io/port_io.h" diff --git a/mentos/src/drivers/ata.c b/mentos/src/drivers/ata.c index 2739ecb..c771ce7 100644 --- a/mentos/src/drivers/ata.c +++ b/mentos/src/drivers/ata.c @@ -1,19 +1,17 @@ /// @file ata.c /// @brief Advanced Technology Attachment (ATA) and Advanced Technology Attachment Packet Interface (ATAPI) drivers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup ata /// @{ -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[ATA ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[ATA ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/ata.h" - #include "descriptor_tables/isr.h" #include "hardware/pic8259.h" #include "klib/spinlock.h" @@ -23,7 +21,6 @@ #include "io/port_io.h" #include "sys/errno.h" #include "mem/kheap.h" -#include "io/debug.h" #include "string.h" #include "fs/vfs.h" #include "fcntl.h" diff --git a/mentos/src/drivers/fdc.c b/mentos/src/drivers/fdc.c index f01f2d0..d4d1eac 100644 --- a/mentos/src/drivers/fdc.c +++ b/mentos/src/drivers/fdc.c @@ -1,20 +1,19 @@ /// @file fdc.c /// @brief Floppy driver controller handling. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup fdc /// @{ -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[FDC ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[FDC ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/fdc.h" -#include "io/video.h" #include "io/port_io.h" +#include "io/video.h" /// @brief Floppy Disk Controller (FDC) registers. typedef enum fdc_registers_t { diff --git a/mentos/src/drivers/keyboard/keyboard.c b/mentos/src/drivers/keyboard/keyboard.c index 4457dac..4a0704d 100644 --- a/mentos/src/drivers/keyboard/keyboard.c +++ b/mentos/src/drivers/keyboard/keyboard.c @@ -1,25 +1,22 @@ /// @file keyboard.c /// @brief Keyboard handling. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup keyboard /// @{ -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[KEYBRD]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[KEYBRD]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/keyboard/keyboard.h" - #include "io/port_io.h" #include "hardware/pic8259.h" #include "drivers/keyboard/keymap.h" #include "sys/bitops.h" #include "io/video.h" -#include "io/debug.h" #include "drivers/ps2.h" #include "ctype.h" #include "descriptor_tables/isr.h" diff --git a/mentos/src/drivers/keyboard/keymap.c b/mentos/src/drivers/keyboard/keymap.c index b5d8677..407c370 100644 --- a/mentos/src/drivers/keyboard/keymap.c +++ b/mentos/src/drivers/keyboard/keymap.c @@ -1,6 +1,6 @@ /// @file keymap.c /// @brief Keymap for keyboard. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup keyboard /// @{ diff --git a/mentos/src/drivers/mouse.c b/mentos/src/drivers/mouse.c index b730cd9..b819459 100644 --- a/mentos/src/drivers/mouse.c +++ b/mentos/src/drivers/mouse.c @@ -1,16 +1,15 @@ /// @file mouse.c /// @brief Driver for *PS2* Mouses. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details.is distributed under the MIT License. /// @addtogroup mouse /// @{ -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[MOUSE ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[MOUSE ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/mouse.h" #include "descriptor_tables/isr.h" diff --git a/mentos/src/drivers/ps2.c b/mentos/src/drivers/ps2.c index 969a539..6b41868 100644 --- a/mentos/src/drivers/ps2.c +++ b/mentos/src/drivers/ps2.c @@ -1,20 +1,18 @@ /// @file ps2.c /// @brief PS/2 drivers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PS/2 ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PS/2 ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/ps2.h" #include "proc_access.h" #include "sys/bitops.h" #include "io/port_io.h" -#include "io/debug.h" #include "stdbool.h" #define PS2_DATA 0x60 ///< Data signal line. diff --git a/mentos/src/drivers/rtc.c b/mentos/src/drivers/rtc.c index f783ad9..047deb5 100644 --- a/mentos/src/drivers/rtc.c +++ b/mentos/src/drivers/rtc.c @@ -1,19 +1,17 @@ /// @file rtc.c /// @brief Real Time Clock (RTC) driver. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. /// @addtogroup rtc /// @{ -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[RTC ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[RTC ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "drivers/rtc.h" - #include "hardware/pic8259.h" #include "string.h" #include "io/port_io.h" diff --git a/mentos/src/elf/elf.c b/mentos/src/elf/elf.c index 172e6b8..b777c46 100644 --- a/mentos/src/elf/elf.c +++ b/mentos/src/elf/elf.c @@ -1,23 +1,20 @@ /// @file elf.c /// @brief Function for multiboot support. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[ELF ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[ELF ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "elf/elf.h" - #include "process/scheduler.h" #include "mem/vmem_map.h" #include "process/process.h" #include "string.h" #include "stddef.h" -#include "io/debug.h" #include "stdio.h" #include "mem/slab.h" #include "fs/vfs.h" diff --git a/mentos/src/fs/ext2.c b/mentos/src/fs/ext2.c index b02e111..7831a21 100644 --- a/mentos/src/fs/ext2.c +++ b/mentos/src/fs/ext2.c @@ -1,23 +1,20 @@ /// @file ext2.c /// @brief EXT2 driver. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[EXT2 ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "fs/ext2.h" - -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[EXT2 ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE - #include "process/scheduler.h" #include "process/process.h" #include "klib/spinlock.h" #include "fs/vfs_types.h" #include "sys/errno.h" -#include "io/debug.h" #include "fs/vfs.h" #include "assert.h" #include "libgen.h" @@ -380,7 +377,7 @@ static ssize_t ext2_write(vfs_file_t *file, const void *buffer, off_t offset, si static off_t ext2_lseek(vfs_file_t *file, off_t offset, int whence); static int ext2_fstat(vfs_file_t *file, stat_t *stat); static int ext2_ioctl(vfs_file_t *file, int request, void *data); -static int ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count); +static ssize_t ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count); static int ext2_mkdir(const char *path, mode_t mode); static int ext2_rmdir(const char *path); @@ -2651,7 +2648,7 @@ static int ext2_ioctl(vfs_file_t *file, int request, void *data) /// @param doff The offset inside the buffer where the data should be written. /// @param count The maximum length of the buffer. /// @return The number of written bytes in the buffer. -static int ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count) +static ssize_t ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count) { pr_debug("ext2_getdents(%s, %p, %d, %d)\n", file->name, dirp, doff, count); // Get the filesystem. @@ -2666,7 +2663,8 @@ static int ext2_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t co pr_err("Failed to read the inode (%d).\n", file->ino); return -ENOENT; } - uint32_t current = 0, written = 0; + uint32_t current = 0; + ssize_t written = 0; // Allocate the cache. uint8_t *cache = kmem_cache_alloc(fs->ext2_buffer_cache, GFP_KERNEL); // Clean the cache. diff --git a/mentos/src/fs/ioctl.c b/mentos/src/fs/ioctl.c index d9c9946..5c93dea 100644 --- a/mentos/src/fs/ioctl.c +++ b/mentos/src/fs/ioctl.c @@ -1,6 +1,6 @@ /// @file ioctl.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fs/ioctl.h" diff --git a/mentos/src/fs/namei.c b/mentos/src/fs/namei.c index 270876e..f68995b 100644 --- a/mentos/src/fs/namei.c +++ b/mentos/src/fs/namei.c @@ -1,6 +1,6 @@ /// @file namei.c /// @brief Implementation of functions fcntl() and open(). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "process/scheduler.h" diff --git a/mentos/src/fs/open.c b/mentos/src/fs/open.c index 2896b1c..c7f689f 100644 --- a/mentos/src/fs/open.c +++ b/mentos/src/fs/open.c @@ -1,6 +1,6 @@ /// @file open.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "process/scheduler.h" diff --git a/mentos/src/fs/procfs.c b/mentos/src/fs/procfs.c index af36a83..8d1e54a 100644 --- a/mentos/src/fs/procfs.c +++ b/mentos/src/fs/procfs.c @@ -1,20 +1,18 @@ /// @file procfs.c /// @brief Proc file system implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PROCFS]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PROCFS]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "fs/procfs.h" #include "fs/vfs.h" #include "string.h" #include "sys/errno.h" -#include "io/debug.h" #include "fcntl.h" #include "libgen.h" #include "assert.h" @@ -92,7 +90,7 @@ static ssize_t procfs_write(vfs_file_t *file, const void *buffer, off_t offset, static off_t procfs_lseek(vfs_file_t *file, off_t offset, int whence); static int procfs_fstat(vfs_file_t *file, stat_t *stat); static int procfs_ioctl(vfs_file_t *file, int request, void *data); -static int procfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count); +static ssize_t procfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count); // ============================================================================ // Virtual FileSystem (VFS) Operaions @@ -693,63 +691,71 @@ static int procfs_ioctl(vfs_file_t *file, int request, void *data) /// @param doff The offset inside the buffer where the data should be written. /// @param count The maximum length of the buffer. /// @return The number of written bytes in the buffer. -static inline int procfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count) +static inline ssize_t procfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t doff, size_t count) { if (!file || !dirp) return -1; + // Check if the size of the buffer is big enough to hold the data about the + // directory entry. + if (count < sizeof(dirent_t)) + return -1; + // If there are no file, stop right here. + if (list_head_empty(&fs.files)) + return 0; + // Find the directory entry. procfs_file_t *direntry = procfs_find_entry_inode(file->ino); if (direntry == NULL) { return -ENOENT; } + // Check if it is a directory. if ((direntry->flags & DT_DIR) == 0) return -ENOTDIR; + // Clear the buffer. memset(dirp, 0, count); + // Initialize, the length of the directory name. int len = strlen(direntry->name); - size_t written = 0; - off_t current = 0; + ssize_t written_size = 0; + off_t iterated_size = 0; char *parent = NULL; - procfs_file_t *entry; - if (!list_head_empty(&fs.files)) { - list_for_each_decl(it, &fs.files) - { - // Get the file structure. - entry = procfs_get_file(it); - // Check if it a valid procfs file. - if (!entry) - continue; - - // If the entry is the directory itself, skip. - if (strcmp(direntry->name, entry->name) == 0) { - continue; - } - // Get the parent directory. - parent = dirname(entry->name); - // Check if the entry is inside the directory. - if (strcmp(direntry->name, parent) != 0) { - continue; - } - // Skip if already provided. - if (current++ < doff) { - continue; - } - if (*(entry->name + len) == '/') - ++len; - // Write on current dirp. - dirp->d_ino = entry->inode; - dirp->d_type = entry->flags; - strcpy(dirp->d_name, entry->name + len); - dirp->d_off = sizeof(dirent_t); - dirp->d_reclen = sizeof(dirent_t); - // Increment the written counter. - written += sizeof(dirent_t); - // Move to next writing position. - dirp += 1; - - if (written >= count) - break; + // Iterate the filesystem files. + list_for_each_decl(it, &fs.files) + { + // Get the file structure. + procfs_file_t *entry = procfs_get_file(it); + // Check if it a valid procfs file. + if (!entry) + continue; + // If the entry is the directory itself, skip. + if (!strcmp(direntry->name, entry->name)) + continue; + // Get the parent directory. + parent = dirname(entry->name); + // Check if the parent of the entry is the directory we are iterating. + if (strcmp(direntry->name, parent)) + continue; + // Advance the size we just iterated. + iterated_size += sizeof(dirent_t); + // Check if the iterated size is still below the offset. + if (iterated_size < doff) { + continue; } + // Check if the last character of the entry is a slash. + if (*(entry->name + len) == '/') + ++len; + // Write on current dirp. + dirp->d_ino = entry->inode; + dirp->d_type = entry->flags; + strcpy(dirp->d_name, entry->name + len); + dirp->d_off = sizeof(dirent_t); + dirp->d_reclen = sizeof(dirent_t); + // Increment the written counter. + written_size += sizeof(dirent_t); + // Move to next writing position. + ++dirp; + if (written_size >= count) + break; } - return written; + return written_size; } /// @brief Mounts the block device as an EXT2 filesystem. diff --git a/mentos/src/fs/read_write.c b/mentos/src/fs/read_write.c index b8d551c..ad0a7b4 100644 --- a/mentos/src/fs/read_write.c +++ b/mentos/src/fs/read_write.c @@ -1,6 +1,6 @@ /// @file read_write.c /// @brief Read and write functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "process/scheduler.h" @@ -46,7 +46,7 @@ ssize_t sys_read(int fd, void *buf, size_t nbytes) return read; } -ssize_t sys_write(int fd, void *buf, size_t nbytes) +ssize_t sys_write(int fd, const void *buf, size_t nbytes) { // Get the current task. task_struct *task = scheduler_get_current_process(); diff --git a/mentos/src/fs/readdir.c b/mentos/src/fs/readdir.c index 212cdd4..430cb1f 100644 --- a/mentos/src/fs/readdir.c +++ b/mentos/src/fs/readdir.c @@ -1,6 +1,6 @@ /// @file readdir.c /// @brief Function for accessing directory entries. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/dirent.h" @@ -11,45 +11,40 @@ #include "stdio.h" #include "fs/vfs.h" #include "string.h" +#include "assert.h" -int sys_getdents(int fd, dirent_t *dirp, unsigned int count) +ssize_t sys_getdents(int fd, dirent_t *dirp, unsigned int count) { if (dirp == NULL) { printf("getdents: cannot read directory :" "Directory pointer is not valid\n"); return 0; } - // Get the current task. - task_struct *task = scheduler_get_current_process(); - + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Check the current FD. - if (fd < 0 || fd >= task->max_fd) { + if ((fd < 0) || (fd >= current_process->max_fd)) { return -EMFILE; } - - // Get the file descriptor. - vfs_file_descriptor_t *vfd = &task->fd_list[fd]; - - // Check the permissions. + // Get the process-specific file descriptor. + vfs_file_descriptor_t *process_fd = ¤t_process->fd_list[fd]; #if 0 - if (!(task->fd_list[fd].flags_mask & O_RDONLY)) { + // Check the permissions. + if (!(current_process->fd_list[fd].flags_mask & O_RDONLY)) { return -EROFS; } #endif - - // Get the file. - vfs_file_t *file = vfd->file_struct; + // Get the associated file. + vfs_file_t *file = process_fd->file_struct; if (file == NULL) { return -ENOSYS; } - // Clean the buffer. - memset(dirp, 0, count); - // Perform the read. - int actual_read = vfs_getdents(file, dirp, vfd->file_struct->f_pos, count); - - // Update the offset. + ssize_t actual_read = vfs_getdents(file, dirp, process_fd->file_struct->f_pos, count); + // Update the offset, only if the value the function returns is positive. if (actual_read > 0) - vfd->file_struct->f_pos += actual_read; + process_fd->file_struct->f_pos += actual_read; return actual_read; } diff --git a/mentos/src/fs/stat.c b/mentos/src/fs/stat.c index 12dfc93..aba6b6a 100644 --- a/mentos/src/fs/stat.c +++ b/mentos/src/fs/stat.c @@ -1,6 +1,6 @@ /// @file stat.c /// @brief Stat functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/debug.h" diff --git a/mentos/src/fs/vfs.c b/mentos/src/fs/vfs.c index 4d1d62d..daaa2c9 100644 --- a/mentos/src/fs/vfs.c +++ b/mentos/src/fs/vfs.c @@ -1,17 +1,15 @@ /// @file vfs.c /// @brief Headers for Virtual File System (VFS). -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[VFS ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "fs/vfs.h" - -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[VFS ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE - #include "process/scheduler.h" #include "klib/spinlock.h" #include "strerror.h" @@ -21,7 +19,6 @@ #include "fs/procfs.h" #include "assert.h" #include "libgen.h" -#include "io/debug.h" #include "system/panic.h" #include "stdio.h" @@ -175,7 +172,7 @@ ssize_t vfs_read(vfs_file_t *file, void *buf, size_t offset, size_t nbytes) return file->fs_operations->read_f(file, buf, offset, nbytes); } -ssize_t vfs_write(vfs_file_t *file, void *buf, size_t offset, size_t nbytes) +ssize_t vfs_write(vfs_file_t *file, const void *buf, size_t offset, size_t nbytes) { if (file->fs_operations->write_f == NULL) { pr_err("No WRITE function found for the current filesystem.\n"); @@ -193,7 +190,7 @@ off_t vfs_lseek(vfs_file_t *file, off_t offset, int whence) return file->fs_operations->lseek_f(file, offset, whence); } -int vfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t off, size_t count) +ssize_t vfs_getdents(vfs_file_t *file, dirent_t *dirp, off_t off, size_t count) { if (file->fs_operations->getdents_f == NULL) { pr_err("No GETDENTS function found for the current filesystem.\n"); diff --git a/mentos/src/hardware/cpuid.c b/mentos/src/hardware/cpuid.c index b8fa8f1..5726be1 100644 --- a/mentos/src/hardware/cpuid.c +++ b/mentos/src/hardware/cpuid.c @@ -1,6 +1,6 @@ /// @file cpuid.c /// @brief CPUID-based function to detect CPU type. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "hardware/cpuid.h" diff --git a/mentos/src/hardware/pic8259.c b/mentos/src/hardware/pic8259.c index b1dadc0..1830547 100644 --- a/mentos/src/hardware/pic8259.c +++ b/mentos/src/hardware/pic8259.c @@ -1,14 +1,13 @@ /// @file pic8259.c /// @brief pic8259 definitions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PIC ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PIC ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "hardware/pic8259.h" #include "io/port_io.h" diff --git a/mentos/src/hardware/timer.c b/mentos/src/hardware/timer.c index e18e369..e9a3767 100644 --- a/mentos/src/hardware/timer.c +++ b/mentos/src/hardware/timer.c @@ -1,22 +1,19 @@ /// @file timer.c /// @brief Timer implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[TIMER ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[TIMER ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "hardware/timer.h" - #include "klib/irqflags.h" #include "process/scheduler.h" #include "hardware/pic8259.h" #include "io/port_io.h" -#include "io/debug.h" #include "io/video.h" #include "stdint.h" #include "mem/kheap.h" diff --git a/mentos/src/io/debug.c b/mentos/src/io/debug.c index 0bb7d4d..6b3a9db 100644 --- a/mentos/src/io/debug.c +++ b/mentos/src/io/debug.c @@ -1,16 +1,15 @@ /// @file debug.c /// @brief Debugging primitives. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -#include "sys/bitops.h" #include "io/debug.h" -#include "klib/spinlock.h" #include "io/port_io.h" +#include "io/ansi_colors.h" +#include "sys/bitops.h" #include "kernel.h" #include "string.h" #include "stdio.h" -#include "io/video.h" #include "math.h" /// Serial port for QEMU. @@ -29,41 +28,38 @@ void dbg_puts(const char *s) dbg_putchar(*s++); } -static inline void __debug_print_header(const char *file, const char *fun, int line, int log_level, char *header) +static inline void __debug_print_header(const char *file, const char *fun, int line, short log_level, char *header) { + // "EMERG ", "ALERT ", "CRIT ", "ERR ", "WARNING", "NOTICE ", "INFO ", "DEBUG ", "DEFAULT", + static const char *log_level_label[] = { " EM ", " AL ", " CR ", " ER ", " WR ", " NT ", " IN ", " DB ", " DF " }; + static const char *log_level_color[] = { + FG_RED_BRIGHT, // "EMERG " + FG_RED_BRIGHT, // "ALERT " + FG_RED, // "CRIT " + FG_RED, // "ERR " + FG_YELLOW_BRIGHT, // "WARNING" + FG_RESET, // "NOTICE " + FG_CYAN, // "INFO " + FG_YELLOW, // "DEBUG " + FG_RESET // "DEFAULT" + }; static char tmp_prefix[BUFSIZ], final_prefix[BUFSIZ]; - if (log_level == LOGLEVEL_EMERG) - dbg_puts(FG_RED_BRIGHT); - else if (log_level == LOGLEVEL_ALERT) - dbg_puts(FG_RED_BRIGHT); - else if (log_level == LOGLEVEL_CRIT) - dbg_puts(FG_RED); - else if (log_level == LOGLEVEL_ERR) - dbg_puts(FG_RED); - else if (log_level == LOGLEVEL_WARNING) - dbg_puts(FG_YELLOW_BRIGHT); - else if (log_level == LOGLEVEL_DEBUG) - dbg_puts(FG_CYAN); - else if (log_level == LOGLEVEL_NOTICE) - dbg_puts(FG_RESET); - else if (log_level == LOGLEVEL_INFO) - dbg_puts(FG_RESET); - else - dbg_puts(FG_RESET); + // Check the log level. + if ((log_level < LOGLEVEL_EMERG) || (log_level > LOGLEVEL_DEBUG)) { + // Set it to default. + log_level = 8; + } + // Set the color. + dbg_puts(log_level_color[log_level]); dbg_putchar('['); - dbg_puts( - (log_level == LOGLEVEL_EMERG) ? " EM " /*"EMERG "*/ : - (log_level == LOGLEVEL_ALERT) ? " AL " /*"ALERT "*/ : - (log_level == LOGLEVEL_CRIT) ? " CR " /*"CRIT "*/ : - (log_level == LOGLEVEL_ERR) ? " ER " /*"ERR "*/ : - (log_level == LOGLEVEL_WARNING) ? " WR " /*"WARNING"*/ : - (log_level == LOGLEVEL_NOTICE) ? " NT " /*"NOTICE "*/ : - (log_level == LOGLEVEL_INFO) ? " IN " /*"INFO "*/ : - (log_level == LOGLEVEL_DEBUG) ? " DB " /*"DEBUG "*/ : - " DF " /*"DEFAULT*/); + // Set the label. + dbg_puts(log_level_label[log_level]); dbg_putchar('|'); + // Print the file and line. sprintf(tmp_prefix, "%s:%d", file, line); + // Print the message. sprintf(final_prefix, " %-20s ", tmp_prefix); + // Print the actual message. dbg_puts(final_prefix); #if 0 dbg_putchar('|'); @@ -90,7 +86,7 @@ int get_log_level() return max_log_level; } -void dbg_printf(const char *file, const char *fun, int line, char *header, const char *format, ...) +void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...) { // Define a buffer for the formatted string. static char formatted[BUFSIZ]; @@ -100,23 +96,6 @@ void dbg_printf(const char *file, const char *fun, int line, char *header, const if (strlen(format) >= BUFSIZ) return; - // Check the log level. - int log_level = LOGLEVEL_DEFAULT; - if ((format[0] != '\0') && (format[0] == KERN_SOH_ASCII)) { - // Remove the Start Of Header. - ++format; - // Compute the log level. - log_level = (format[0] - '0'); - // Check the log_level. - if ((log_level < LOGLEVEL_EMERG) || (log_level > LOGLEVEL_DEBUG)) - log_level = 8; - // Remove the log_level; - ++format; - } - if (log_level > max_log_level) { - return; - } - // Start variabile argument's list. va_list ap; va_start(ap, format); @@ -128,7 +107,7 @@ void dbg_printf(const char *file, const char *fun, int line, char *header, const // Stage 2: SEND if (new_line) { __debug_print_header(file, fun, line, log_level, header); - new_line = false; + new_line = 0; } for (int it = 0; (formatted[it] != 0) && (it < BUFSIZ); ++it) { dbg_putchar(formatted[it]); @@ -139,37 +118,13 @@ void dbg_printf(const char *file, const char *fun, int line, char *header, const continue; } if (formatted[it + 1] == 0) { - new_line = true; + new_line = 1; } else { __debug_print_header(file, fun, line, log_level, header); } } } -void dbg_print_regs(pt_regs *frame) -{ - pr_debug("Interrupt stack frame:\n"); - pr_debug("GS = 0x%-04x\n", frame->gs); - pr_debug("FS = 0x%-04x\n", frame->fs); - pr_debug("ES = 0x%-04x\n", frame->es); - pr_debug("DS = 0x%-04x\n", frame->ds); - pr_debug("EDI = 0x%-09x\n", frame->edi); - pr_debug("ESI = 0x%-09x\n", frame->esi); - pr_debug("EBP = 0x%-09x\n", frame->ebp); - pr_debug("ESP = 0x%-09x\n", frame->esp); - pr_debug("EBX = 0x%-09x\n", frame->ebx); - pr_debug("EDX = 0x%-09x\n", frame->edx); - pr_debug("ECX = 0x%-09x\n", frame->ecx); - pr_debug("EAX = 0x%-09x\n", frame->eax); - pr_debug("INT_NO = %-9d\n", frame->int_no); - pr_debug("ERR_CD = %-9d\n", frame->err_code); - pr_debug("EIP = 0x%-09x\n", frame->eip); - pr_debug("CS = 0x%-04x\n", frame->cs); - pr_debug("EFLAGS = 0x%-09x\n", frame->eflags); - pr_debug("UESP = 0x%-09x\n", frame->useresp); - pr_debug("SS = 0x%-04x\n", frame->ss); -} - const char *to_human_size(unsigned long bytes) { static char output[200]; @@ -193,3 +148,27 @@ const char *dec_to_binary(unsigned long value, unsigned length) buffer[i] = bit_check(value, 31 - j) ? '1' : '0'; return buffer; } + +void dbg_print_regs(pt_regs *frame) +{ + pr_debug("Interrupt stack frame:\n"); + pr_debug("GS = 0x%-04x\n", frame->gs); + pr_debug("FS = 0x%-04x\n", frame->fs); + pr_debug("ES = 0x%-04x\n", frame->es); + pr_debug("DS = 0x%-04x\n", frame->ds); + pr_debug("EDI = 0x%-09x\n", frame->edi); + pr_debug("ESI = 0x%-09x\n", frame->esi); + pr_debug("EBP = 0x%-09x\n", frame->ebp); + pr_debug("ESP = 0x%-09x\n", frame->esp); + pr_debug("EBX = 0x%-09x\n", frame->ebx); + pr_debug("EDX = 0x%-09x\n", frame->edx); + pr_debug("ECX = 0x%-09x\n", frame->ecx); + pr_debug("EAX = 0x%-09x\n", frame->eax); + pr_debug("INT_NO = %-9d\n", frame->int_no); + pr_debug("ERR_CD = %-9d\n", frame->err_code); + pr_debug("EIP = 0x%-09x\n", frame->eip); + pr_debug("CS = 0x%-04x\n", frame->cs); + pr_debug("EFLAGS = 0x%-09x\n", frame->eflags); + pr_debug("UESP = 0x%-09x\n", frame->useresp); + pr_debug("SS = 0x%-04x\n", frame->ss); +} diff --git a/mentos/src/io/mm_io.c b/mentos/src/io/mm_io.c index 51e8210..c082b39 100644 --- a/mentos/src/io/mm_io.c +++ b/mentos/src/io/mm_io.c @@ -1,6 +1,6 @@ /// @file mm_io.c /// @brief Memory Mapped IO functions implementation. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/mm_io.h" diff --git a/mentos/src/io/port_io.c b/mentos/src/io/port_io.c index deb9c3a..8a29154 100644 --- a/mentos/src/io/port_io.c +++ b/mentos/src/io/port_io.c @@ -1,6 +1,6 @@ /// @file port_io.c /// @brief Byte I/O on ports prototypes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/port_io.h" diff --git a/mentos/src/io/proc_running.c b/mentos/src/io/proc_running.c index 864eddd..46ff314 100644 --- a/mentos/src/io/proc_running.c +++ b/mentos/src/io/proc_running.c @@ -1,6 +1,6 @@ /// @file proc_running.c /// @brief Implementaiton of procr filesystem. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fs/procfs.h" diff --git a/mentos/src/io/proc_system.c b/mentos/src/io/proc_system.c index c0c5ee4..484e6d2 100644 --- a/mentos/src/io/proc_system.c +++ b/mentos/src/io/proc_system.c @@ -1,6 +1,6 @@ /// @file proc_system.c /// @brief Contains callbacks for procfs system files. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fs/procfs.h" diff --git a/mentos/src/io/proc_video.c b/mentos/src/io/proc_video.c index 3513602..eb5f2d6 100644 --- a/mentos/src/io/proc_video.c +++ b/mentos/src/io/proc_video.c @@ -1,14 +1,13 @@ /// @file proc_video.c /// @brief Contains callbacks for procv system files. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PROCV ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PROCV ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "bits/termios-struct.h" #include "drivers/keyboard/keyboard.h" @@ -17,7 +16,6 @@ #include "bits/ioctls.h" #include "sys/bitops.h" #include "io/video.h" -#include "io/debug.h" #include "sys/errno.h" #include "fcntl.h" #include "fs/vfs.h" diff --git a/mentos/src/io/stdio.c b/mentos/src/io/stdio.c index 2826471..7dd841e 100644 --- a/mentos/src/io/stdio.c +++ b/mentos/src/io/stdio.c @@ -1,6 +1,6 @@ /// @file stdio.c /// @brief Standard IO functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/syscall.h" diff --git a/mentos/src/io/vga/vga.c b/mentos/src/io/vga/vga.c index 6f81cbd..0ae87e6 100644 --- a/mentos/src/io/vga/vga.c +++ b/mentos/src/io/vga/vga.c @@ -1,24 +1,20 @@ /// @file vga.c /// @brief Implementation of Video Graphics Array (VGA) drivers. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[VGA ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[VGA ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "io/vga/vga.h" - #include "io/vga/vga_palette.h" #include "io/vga/vga_mode.h" #include "io/vga/vga_font.h" - #include "hardware/timer.h" #include "io/port_io.h" -#include "io/debug.h" #include "io/video.h" #include "stdbool.h" #include "string.h" diff --git a/mentos/src/io/video.c b/mentos/src/io/video.c index 7f86de3..e73651a 100644 --- a/mentos/src/io/video.c +++ b/mentos/src/io/video.c @@ -1,6 +1,6 @@ /// @file video.c /// @brief Video functions and costants. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/port_io.h" diff --git a/mentos/src/ipc/msg.c b/mentos/src/ipc/msg.c index 79a0bab..7a287ee 100644 --- a/mentos/src/ipc/msg.c +++ b/mentos/src/ipc/msg.c @@ -1,9 +1,15 @@ /// @file msg.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. ///! @cond Doxygen_Suppress +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[IPCmsg]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "ipc/msg.h" #include "system/panic.h" diff --git a/mentos/src/ipc/sem.c b/mentos/src/ipc/sem.c index a875d12..3818eb4 100644 --- a/mentos/src/ipc/sem.c +++ b/mentos/src/ipc/sem.c @@ -1,9 +1,15 @@ /// @file sem.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. ///! @cond Doxygen_Suppress +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[IPCsem]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "ipc/sem.h" #include "system/panic.h" diff --git a/mentos/src/ipc/shm.c b/mentos/src/ipc/shm.c index 28e1fce..59751a3 100644 --- a/mentos/src/ipc/shm.c +++ b/mentos/src/ipc/shm.c @@ -1,9 +1,15 @@ /// @file shm.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. ///! @cond Doxygen_Suppress +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[IPCshm]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "ipc/shm.h" #include "system/panic.h" diff --git a/mentos/src/kernel.c b/mentos/src/kernel.c index abe8ef7..78ce7cf 100644 --- a/mentos/src/kernel.c +++ b/mentos/src/kernel.c @@ -1,14 +1,13 @@ /// @file kernel.c /// @brief Kernel main function. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[KERNEL]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[KERNEL]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "io/proc_modules.h" #include "mem/vmem_map.h" @@ -23,7 +22,6 @@ #include "version.h" #include "io/video.h" #include "hardware/pic8259.h" -#include "io/debug.h" #include "drivers/fdc.h" #include "fs/ext2.h" #include "klib/irqflags.h" diff --git a/mentos/src/kernel/sys.c b/mentos/src/kernel/sys.c index 7a07206..b0222a5 100644 --- a/mentos/src/kernel/sys.c +++ b/mentos/src/kernel/sys.c @@ -1,6 +1,6 @@ /// @file sys.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "stdio.h" @@ -11,7 +11,7 @@ static void machine_power_off() { - while (true) { + while (1) { cpu_relax(); } } diff --git a/mentos/src/klib/assert.c b/mentos/src/klib/assert.c index 153efc5..cb6f348 100644 --- a/mentos/src/klib/assert.c +++ b/mentos/src/klib/assert.c @@ -1,6 +1,6 @@ /// @file assert.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "assert.h" diff --git a/mentos/src/klib/ctype.c b/mentos/src/klib/ctype.c index c74c9db..dcd4244 100644 --- a/mentos/src/klib/ctype.c +++ b/mentos/src/klib/ctype.c @@ -1,6 +1,6 @@ /// @file ctype.c /// @brief Functions related to character handling. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "ctype.h" diff --git a/mentos/src/klib/fcvt.c b/mentos/src/klib/fcvt.c index f3e61cb..6b5f1b5 100644 --- a/mentos/src/klib/fcvt.c +++ b/mentos/src/klib/fcvt.c @@ -1,6 +1,6 @@ /// @file fcvt.c /// @brief Define the functions required to turn double values into a string. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fcvt.h" diff --git a/mentos/src/klib/hashmap.c b/mentos/src/klib/hashmap.c index 1f60fb6..094c904 100644 --- a/mentos/src/klib/hashmap.c +++ b/mentos/src/klib/hashmap.c @@ -1,6 +1,6 @@ /// @file hashmap.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "klib/hashmap.h" diff --git a/mentos/src/klib/libgen.c b/mentos/src/klib/libgen.c index c36671d..fc286b6 100644 --- a/mentos/src/klib/libgen.c +++ b/mentos/src/klib/libgen.c @@ -1,6 +1,6 @@ /// @file libgen.c /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/syscall.h" diff --git a/mentos/src/klib/list.c b/mentos/src/klib/list.c index d0cdf09..79299de 100644 --- a/mentos/src/klib/list.c +++ b/mentos/src/klib/list.c @@ -1,6 +1,6 @@ /// @file list.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "klib/list.h" diff --git a/mentos/src/klib/math.c b/mentos/src/klib/math.c index 14e67ce..55daa98 100644 --- a/mentos/src/klib/math.c +++ b/mentos/src/klib/math.c @@ -1,6 +1,6 @@ /// @file math.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "math.h" diff --git a/mentos/src/klib/mutex.c b/mentos/src/klib/mutex.c index fdc8ecd..2c1a5e6 100644 --- a/mentos/src/klib/mutex.c +++ b/mentos/src/klib/mutex.c @@ -1,6 +1,6 @@ /// @file mutex.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "klib/mutex.h" diff --git a/mentos/src/klib/ndtree.c b/mentos/src/klib/ndtree.c index 2356c52..368a63f 100644 --- a/mentos/src/klib/ndtree.c +++ b/mentos/src/klib/ndtree.c @@ -1,6 +1,6 @@ /// @file ndtree.c /// @brief Red/Black tree. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/debug.h" diff --git a/mentos/src/klib/rbtree.c b/mentos/src/klib/rbtree.c index 048606c..4124c37 100644 --- a/mentos/src/klib/rbtree.c +++ b/mentos/src/klib/rbtree.c @@ -1,6 +1,6 @@ /// @file rbtree.c /// @brief Red/Black tree. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "klib/rbtree.h" diff --git a/mentos/src/klib/spinlock.c b/mentos/src/klib/spinlock.c index f3585da..f0ed1aa 100644 --- a/mentos/src/klib/spinlock.c +++ b/mentos/src/klib/spinlock.c @@ -1,6 +1,6 @@ /// @file spinlock.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "klib/spinlock.h" diff --git a/mentos/src/klib/strerror.c b/mentos/src/klib/strerror.c index 0c245e2..45fb6a3 100644 --- a/mentos/src/klib/strerror.c +++ b/mentos/src/klib/strerror.c @@ -1,6 +1,6 @@ /// @file strerror.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "strerror.h" diff --git a/mentos/src/klib/string.c b/mentos/src/klib/string.c index 287a53d..5528aa7 100644 --- a/mentos/src/klib/string.c +++ b/mentos/src/klib/string.c @@ -1,27 +1,36 @@ /// @file string.c /// @brief String routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -#include "mem/kheap.h" -#include "stdio.h" -#include "fcntl.h" #include "string.h" #include "ctype.h" +#include "stdio.h" +#include "stdlib.h" +#include "fcntl.h" + +#ifdef __KERNEL__ +#include "mem/kheap.h" +#endif char *strncpy(char *destination, const char *source, size_t num) { - char *start = destination; - while (num && (*destination++ = *source++)) { - num--; - } + // Check if we have a valid number. if (num) { - while (--num) { - *destination++ = '\0'; + // Copies the first num characters of source to destination. + while (num && (*destination++ = *source++)) { + num--; + } + // If the end of the source C string (which is signaled by a null-character) + // is found before num characters have been copied, destination is padded + // with zeros until a total of num characters have been written to it. + if (num) { + while (--num) + *destination++ = '\0'; } } - - return start; + // Pointer to destination is returned. + return destination; } int strncmp(const char *s1, const char *s2, size_t n) @@ -389,16 +398,13 @@ char *strtok_r(char *str, const char *delim, char **saveptr) void *memset(void *ptr, int value, size_t num) { - // Truncate c to 8 bits. - value = (value & 0xFF); - - char *dst = (char *)ptr; - - // Initialize the rest of the size. - while (num--) { - *dst++ = (char)value; - } - + // Turn the pointer into a char * pointer. Here, we use the volatile keyword + // to prevent the compiler from optimizing away the operations involving the + // pointer. + unsigned char volatile *dst = (unsigned char volatile *)ptr; + // Initialize the content of the memory. + while (num--) *dst++ = (unsigned char)value; + // Return the pointer. return ptr; } @@ -418,14 +424,15 @@ int memcmp(const void *dst, const void *src, size_t n) void *memcpy(void *dst, const void *src, size_t num) { - char *_dst = dst; - const char *_src = src; - - while (num--) { - *_dst++ = *_src++; - } - - return dst; + // Turn the pointer into a char * pointer. Here, we use the volatile keyword + // to prevent the compiler from optimizing away the operations involving the + // pointer. + unsigned char volatile *_dst = (unsigned char volatile *)dst; + const unsigned char volatile *_src = (const unsigned char volatile *)src; + // Initialize the content of the memory. + while (num--) *_dst++ = *_src++; + // Return the pointer. + return (void *)dst; } void *memccpy(void *dst, const void *src, int c, size_t n) @@ -592,7 +599,11 @@ char *trim(char *str) char *strdup(const char *s) { size_t len = strlen(s) + 1; - char *new = kmalloc(len); +#ifdef __KERNEL__ + char *new = kmalloc(len); +#else + char *new = malloc(len); +#endif if (new == NULL) return NULL; new[len] = '\0'; @@ -602,7 +613,11 @@ char *strdup(const char *s) char *strndup(const char *s, size_t n) { size_t len = strnlen(s, n); - char *new = kmalloc(len); +#ifdef __KERNEL__ + char *new = kmalloc(len); +#else + char *new = malloc(len); +#endif if (new == NULL) return NULL; new[len] = '\0'; diff --git a/mentos/src/klib/time.c b/mentos/src/klib/time.c index 597b5ee..5eac650 100644 --- a/mentos/src/klib/time.c +++ b/mentos/src/klib/time.c @@ -1,6 +1,6 @@ /// @file time.c /// @brief Clock functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "io/debug.h" diff --git a/mentos/src/klib/vscanf.c b/mentos/src/klib/vscanf.c index 1b55c69..33fb22b 100644 --- a/mentos/src/klib/vscanf.c +++ b/mentos/src/klib/vscanf.c @@ -1,6 +1,6 @@ /// @file vscanf.c /// @brief Reading formatting routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "fs/vfs.h" diff --git a/mentos/src/klib/vsprintf.c b/mentos/src/klib/vsprintf.c index a00d6b6..ce4f295 100644 --- a/mentos/src/klib/vsprintf.c +++ b/mentos/src/klib/vsprintf.c @@ -1,6 +1,6 @@ /// @file vsprintf.c /// @brief Print formatting routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "math.h" diff --git a/mentos/src/mem/buddysystem.c b/mentos/src/mem/buddysystem.c index a381339..f8bd412 100644 --- a/mentos/src/mem/buddysystem.c +++ b/mentos/src/mem/buddysystem.c @@ -1,20 +1,18 @@ /// @file buddysystem.c /// @brief Buddy System. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[BUDDY ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_DEBUG +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[BUDDY ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/buddysystem.h" #include "mem/paging.h" -#include "assert.h" -#include "io/debug.h" #include "system/panic.h" +#include "assert.h" /// @brief Cache level low limit after which allocation starts. #define LOW_WATERMARK_LEVEL 10 @@ -114,8 +112,8 @@ static inline bb_free_area_t *__get_area_of_order(bb_instance_t *instance, unsig /// @brief Checks if the page is FREE and has the same order. /// @param page the page to check. /// @param order the oder to check. -/// @return true if the page is buddy, false otherwise. -static inline bool_t __page_is_buddy(bb_page_t *page, unsigned int order) +/// @return 1 if the page is buddy, 0 otherwise. +static inline int __page_is_buddy(bb_page_t *page, unsigned int order) { return __bb_test_flag(page, FREE_PAGE) && (page->order == order); } diff --git a/mentos/src/mem/kheap.c b/mentos/src/mem/kheap.c index f09ed31..d81b8d4 100644 --- a/mentos/src/mem/kheap.c +++ b/mentos/src/mem/kheap.c @@ -1,22 +1,20 @@ /// @file kheap.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[KHEAP ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[KHEAP ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/kheap.h" -#include "math.h" -#include "io/debug.h" -#include "string.h" #include "mem/paging.h" -#include "assert.h" #include "klib/list_head.h" +#include "string.h" +#include "assert.h" +#include "math.h" /// Overhead given by the block_t itself. #define OVERHEAD sizeof(block_t) @@ -785,8 +783,8 @@ void *sys_brk(void *addr) task_struct *current_task = scheduler_get_current_process(); mm_struct_t *current_mm = current_task->mm; current_mm->start_brk = create_vm_area(current_mm, - 0x40000000 /*FIXME! stabilize this*/, - UHEAP_INITIAL_SIZE, MM_RW | MM_PRESENT | MM_USER | MM_UPDADDR, GFP_HIGHUSER); + 0x40000000 /*FIXME! stabilize this*/, + UHEAP_INITIAL_SIZE, MM_RW | MM_PRESENT | MM_USER | MM_UPDADDR, GFP_HIGHUSER); current_mm->brk = current_mm->start_brk; // Reserved space for: // 1) First memory block. @@ -856,5 +854,5 @@ void kheap_dump() pr_debug("(%p)->", it); } pr_debug("\n\n"); - (void) total, (void) total_overhead; + (void)total, (void)total_overhead; } diff --git a/mentos/src/mem/paging.c b/mentos/src/mem/paging.c index 7ededbf..a8a09a3 100644 --- a/mentos/src/mem/paging.c +++ b/mentos/src/mem/paging.c @@ -1,24 +1,22 @@ /// @file paging.c /// @brief Implementation of a memory paging management. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PAGING]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PAGING]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/paging.h" -#include "descriptor_tables/isr.h" #include "mem/vmem_map.h" #include "mem/zone_allocator.h" #include "mem/kheap.h" -#include "io/debug.h" +#include "descriptor_tables/isr.h" +#include "system/panic.h" #include "assert.h" #include "string.h" -#include "system/panic.h" /// Cache for storing mm_struct. kmem_cache_t *mm_cache; @@ -68,8 +66,8 @@ void paging_switch_directory_va(page_directory_t *dir) void paging_flush_tlb_single(unsigned long addr) { - ASM("invlpg (%0)" ::"r"(addr) - : "memory"); + __asm__ __volatile__("invlpg (%0)" ::"r"(addr) + : "memory"); } uint32_t create_vm_area(mm_struct_t *mm, @@ -165,12 +163,12 @@ uint32_t clone_vm_area(mm_struct_t *mm, vm_area_struct_t *area, int cow, uint32_ static void __init_pagedir(page_directory_t *pdir) { - *pdir = (page_directory_t){ {0} }; + *pdir = (page_directory_t){ { 0 } }; } static void __init_pagetable(page_table_t *ptable) { - *ptable = (page_table_t){ {0} }; + *ptable = (page_table_t){ { 0 } }; } void paging_init(boot_info_t *info) diff --git a/mentos/src/mem/slab.c b/mentos/src/mem/slab.c index da1b01f..13e4ae9 100644 --- a/mentos/src/mem/slab.c +++ b/mentos/src/mem/slab.c @@ -1,20 +1,18 @@ /// @file mouse.h /// @brief Driver for *PS2* Mouses. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[SLAB ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[SLAB ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/zone_allocator.h" #include "mem/paging.h" -#include "assert.h" -#include "io/debug.h" #include "mem/slab.h" +#include "assert.h" /// @brief Use it to manage cached pages. typedef struct kmem_obj { diff --git a/mentos/src/mem/vmem_map.c b/mentos/src/mem/vmem_map.c index 3c0dced..a30d950 100644 --- a/mentos/src/mem/vmem_map.c +++ b/mentos/src/mem/vmem_map.c @@ -1,18 +1,17 @@ /// @file vmem_map.c /// @brief Virtual memory mapping routines. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[VMEM ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[VMEM ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/vmem_map.h" -#include "string.h" #include "system/panic.h" +#include "string.h" /// Virtual addresses manager. static virt_map_page_manager_t virt_default_mapping; diff --git a/mentos/src/mem/zone_allocator.c b/mentos/src/mem/zone_allocator.c index 851d8dc..6d7ce83 100644 --- a/mentos/src/mem/zone_allocator.c +++ b/mentos/src/mem/zone_allocator.c @@ -1,14 +1,13 @@ /// @file zone_allocator.c /// @brief Implementation of the Zone Allocator -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PMM ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PMM ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/zone_allocator.h" #include "mem/buddysystem.h" @@ -17,7 +16,6 @@ #include "assert.h" #include "mem/paging.h" #include "string.h" -#include "io/debug.h" /// TODO: Comment. #define MIN_PAGE_ALIGN(addr) ((addr) & (~(PAGE_SIZE - 1))) diff --git a/mentos/src/multiboot.c b/mentos/src/multiboot.c index 6cb109b..466a395 100644 --- a/mentos/src/multiboot.c +++ b/mentos/src/multiboot.c @@ -1,20 +1,18 @@ /// @file multiboot.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[BOOT ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[MTBOOT]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "multiboot.h" #include "kernel.h" #include "sys/bitops.h" #include "stddef.h" -#include "io/debug.h" #include "system/panic.h" #include "stddef.h" diff --git a/mentos/src/process/process.c b/mentos/src/process/process.c index 1e0105f..49888e3 100644 --- a/mentos/src/process/process.c +++ b/mentos/src/process/process.c @@ -1,14 +1,13 @@ /// @file process.c /// @brief Process data structures and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[PROC ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[PROC ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "process/process.h" #include "process/scheduler.h" @@ -19,7 +18,6 @@ #include "sys/errno.h" #include "fcntl.h" #include "system/panic.h" -#include "io/debug.h" #include "process/wait.h" #include "process/prio.h" #include "fs/vfs.h" diff --git a/mentos/src/process/scheduler.c b/mentos/src/process/scheduler.c index 0906601..7a647f8 100644 --- a/mentos/src/process/scheduler.c +++ b/mentos/src/process/scheduler.c @@ -1,14 +1,13 @@ /// @file scheduler.c /// @brief Scheduler structures and functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[SCHED ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[SCHED ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "assert.h" #include "strerror.h" @@ -21,7 +20,6 @@ #include "process/wait.h" #include "mem/kheap.h" #include "system/panic.h" -#include "io/debug.h" #include "time.h" #include "sys/errno.h" #include "klib/list_head.h" @@ -443,40 +441,45 @@ int sys_nice(int increment) pid_t sys_waitpid(pid_t pid, int *status, int options) { - // Get the current task. - if (runqueue.curr == NULL) { + task_struct *current_process, *entry; + // Get the current process. + current_process = scheduler_get_current_process(); + // Check the current task. + if (current_process == NULL) { kernel_panic("There is no current process!"); } - - /* For now we do not support waiting for processes inside the given - * process group (pid < -1). - */ + // For now we do not support waiting for processes inside the given process + // group (pid < -1). if ((pid < -1) || (pid == 0)) { return -ESRCH; } - if (pid == runqueue.curr->pid) { + // Check if the pid we are waiting for is the process itself. + if (pid == current_process->pid) { return -ECHILD; } - if (options != 0 && options != WNOHANG) { + // Check if the options are one of: WNOHANG, WUNTRACED. + if ((options != 0) && !bit_check(options, WNOHANG) && !bit_check(options, WUNTRACED)) { return -EINVAL; } -#if 0 - if (status == NULL) { - return -EFAULT; - } -#endif - if (list_head_empty(&runqueue.curr->children)) { + // Check if there are children to wait. + if (list_head_empty(¤t_process->children)) { return -ECHILD; } - list_head *it; - list_for_each (it, &runqueue.curr->children) { - task_struct *entry = list_entry(it, task_struct, sibling); + // Iterate the children. + list_for_each_decl(it, ¤t_process->children) + { + // Get the entry. + entry = list_entry(it, task_struct, sibling); + // Check the entry. if (entry == NULL) { continue; } + // If the entry is not in a zombie state, keep searching. if (entry->state != EXIT_ZOMBIE) { continue; } + // If a pid was provided, and is different from the pid we are + // exhamining, skip it. if ((pid > 1) && (entry->pid != pid)) { continue; } @@ -493,7 +496,7 @@ pid_t sys_waitpid(pid_t pid, int *status, int options) scheduler_dequeue_task(entry); // Delete the task_struct. kmem_cache_free(entry); - pr_debug("Process %d is freeing memory of process %d.\n", runqueue.curr->pid, ppid); + pr_debug("Process %d is freeing memory of process %d.\n", current_process->pid, ppid); return ppid; } return 0; diff --git a/mentos/src/process/scheduler_algorithm.c b/mentos/src/process/scheduler_algorithm.c index c3f8153..2e441fe 100644 --- a/mentos/src/process/scheduler_algorithm.c +++ b/mentos/src/process/scheduler_algorithm.c @@ -1,18 +1,16 @@ /// @file scheduler_algorithm.c /// @brief Round Robin algorithm. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[SCHALG]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[SCHALG]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "hardware/timer.h" #include "process/prio.h" -#include "io/debug.h" #include "assert.h" #include "klib/list_head.h" #include "process/wait.h" @@ -45,7 +43,8 @@ static inline task_struct *__scheduler_rr(runqueue_t *runqueue, bool_t skip_peri if (list_head_size(&runqueue->curr->run_list) <= 1) { return runqueue->curr; } - + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; // Search for the next task (we do not start from the head, so INSIDE, skip the head). list_for_each_decl(it, &runqueue->curr->run_list) { @@ -53,7 +52,7 @@ static inline task_struct *__scheduler_rr(runqueue_t *runqueue, bool_t skip_peri if (it == &runqueue->queue) continue; // Get the current entry. - task_struct *entry = list_entry(it, task_struct, run_list); + entry = list_entry(it, task_struct, run_list); // We consider only runnable processes if (entry->state != TASK_RUNNING) continue; @@ -61,7 +60,6 @@ static inline task_struct *__scheduler_rr(runqueue_t *runqueue, bool_t skip_peri if (__is_periodic_task(entry) && skip_periodic) continue; // We have our next entry. - return entry; } @@ -99,9 +97,10 @@ static inline task_struct *__scheduler_priority(runqueue_t *runqueue, bool_t ski #ifdef SCHEDULER_PRIORITY // Get the first element of the list. task_struct *next = list_entry(runqueue->queue.next, struct task_struct, run_list); - - // Get its static priority. - time_t min = (next->se).prio; + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; + // Get the static priority of the first element of the list we just extracted. + time_t min = /*...*/; // Search for the task with the smallest static priority. list_for_each_decl(it, &runqueue->queue) @@ -110,7 +109,7 @@ static inline task_struct *__scheduler_priority(runqueue_t *runqueue, bool_t ski if (it == &runqueue->queue) continue; // Get the current entry. - task_struct *entry = list_entry(it, struct task_struct, run_list); + entry = list_entry(it, task_struct, run_list); // We consider only runnable processes if (entry->state != TASK_RUNNING) continue; @@ -118,12 +117,11 @@ static inline task_struct *__scheduler_priority(runqueue_t *runqueue, bool_t ski if (__is_periodic_task(entry) && skip_periodic) continue; // Check if the entry has a lower priority. - if ((entry->se).prio <= min) { - min = (entry->se).prio; // aggiorno la priorità piu bassa trovata - next = entry; // scambio il prossimo processo con quello a priorità piu bassa trovato + if (/*...*/) { + // Chose the `entry` as the `next` task. + /*...*/ } } - return next; #else return __scheduler_rr(runqueue, skip_periodic); @@ -144,9 +142,10 @@ static inline task_struct *__scheduler_cfs(runqueue_t *runqueue, bool_t skip_per #ifdef SCHEDULER_CFS // Get the first element of the list. task_struct *next = list_entry(runqueue->queue.next, struct task_struct, run_list); - - // Get its virtual runtime. - time_t min = (next->se).vruntime; // prendo il peso del processo attuale in esecuzione + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; + // Get the virtual runtime of the first element of the list we just extracted. + time_t min = /*...*/; // Search for the task with the smallest vruntime value. list_for_each_decl(it, &runqueue->queue) @@ -155,7 +154,7 @@ static inline task_struct *__scheduler_cfs(runqueue_t *runqueue, bool_t skip_per if (it == &runqueue->queue) continue; // Get the current entry. - task_struct *entry = list_entry(it, task_struct, run_list); + entry = list_entry(it, task_struct, run_list); // We consider only runnable processes if (entry->state != TASK_RUNNING) continue; @@ -165,10 +164,6 @@ static inline task_struct *__scheduler_cfs(runqueue_t *runqueue, bool_t skip_per // Check if the element in the list has a smaller vruntime value. /* ... */ - if ((entry->se).vruntime <= min) { - min = (entry->se).vruntime; // aggiorno il vrtime con quello piu basso trovato - next = entry; // scambio il prossimo processo con quello a priorità piu bassa trovato - } } return next; @@ -183,6 +178,54 @@ static inline task_struct *__scheduler_cfs(runqueue_t *runqueue, bool_t skip_per /// @return the next task on success, NULL on failure. static inline task_struct *__scheduler_aedf(runqueue_t *runqueue) { +#ifdef SCHEDULER_AEDF + // This will hold the pointer to the next task to schedule. + task_struct *next = list_entry(runqueue->queue.next, struct task_struct, run_list); + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; + // Initialize the nearest "next deadline". + time_t min = UINT_MAX; + + // Iter over the runqueue to find the task with the earliest absolute deadline. + list_for_each_decl(it, &runqueue->queue) + { + // Check if we reached the head of list_head, and skip it. + if (it == &runqueue->queue) + continue; + // Get the current entry. + entry = list_entry(it, task_struct, run_list); + // We consider only runnable processes + if (entry->state != TASK_RUNNING) + continue; + // If entry is not a periodic task, skip it. + if (!__is_periodic_task(entry)) + continue; + // If the entry has passed its deadline, we output a warning but it + // might still be selected as next task. + if (/*...*/) { + pr_warning("Process %d passed its deadline %d < %d \n", + entry->pid, + /*...*/, + /*...*/); + } + // Now, select the task if it has the minimum absolute deadline. + if (/*...*/ < /*...*/) { + // Set it as next task. + next = entry; + // Update the minimum absolute deadline. + min = /*...*/; + } + } + if (next) { + pr_debug("[%9d] Activating task '%16s', deadline: %5d \t\n", + next->pid, + next->name, + /*...*/); + return next; + } +#endif + // If there are no tasks with deadline != 0 to execute, just pick another + // task by using Round-Robin. return __scheduler_rr(runqueue, false); } @@ -194,6 +237,60 @@ static inline task_struct *__scheduler_aedf(runqueue_t *runqueue) /// @return the next task on success, NULL on failure. static inline task_struct *__scheduler_edf(runqueue_t *runqueue) { +#ifdef SCHEDULER_EDF + // This will hold the pointer to the next task to schedule. + task_struct *next = NULL; + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; + // Initialize the nearest "next deadline". + time_t min = UINT_MAX; + + // Iter over the runqueue to find the task with the earliest absolute deadline. + list_for_each_decl(it, &runqueue->queue) + { + // Check if we reached the head of list_head, and skip it. + if (it == &runqueue->queue) + continue; + // Get the current entry. + entry = list_entry(it, task_struct, run_list); + // We consider only runnable processes + if (entry->state != TASK_RUNNING) + continue; + // If entry is not a periodic task, skip it. + if (!__is_periodic_task(entry)) + continue; + + if (entry->se.executed) { + // If the period for the entry is starting again and it has already + // executed, set it as 'executable again'. Deadline and next_period + // are propagated. + if (/*...*/ <= /*...*/) { + entry->se.executed = /*...*/; + entry->se.deadline += /*...*/; + entry->se.next_period += /*...*/; + pr_debug("[%9d] Activating task '%16s' [period:%d], deadline:%5d; next_period:%5d, WCET:%6d\t\n", + timer_get_ticks(), + entry->name, + /*...*/, + /*...*/, + /*...*/, + /*...*/); + } else { + // If the deadline of the process is less than the minimum value, pick it. + if (/*...*/ < /*...*/) { + // Set it as next task. + next = entry; + // Update the minimum value. + min = /*...*/; + } + } + } + } + if (next) + return next; +#endif + // If there are no periodic task to execute, just pick an aperiodic task by + // using Round-Robin. return __scheduler_rr(runqueue, false); } @@ -206,6 +303,60 @@ static inline task_struct *__scheduler_edf(runqueue_t *runqueue) /// @return the next task on success, NULL on failure. static inline task_struct *__scheduler_rm(runqueue_t *runqueue) { +#ifdef SCHEDULER_RM + // This will hold the pointer to the next task to schedule. + task_struct *next = NULL; + // This will hold a given entry, while iterating the list of tasks. + task_struct *entry = NULL; + // Initialize the nearest "next deadline". + time_t min = UINT_MAX; + + // Iter over the runqueue to find the task with the earliest absolute deadline. + list_for_each_decl(it, &runqueue->queue) + { + // Check if we reached the head of list_head, and skip it. + if (it == &runqueue->queue) + continue; + // Get the current entry. + entry = list_entry(it, task_struct, run_list); + // We consider only runnable processes + if (entry->state != TASK_RUNNING) + continue; + // If entry is not a periodic task, skip it. + if (!__is_periodic_task(entry)) + continue; + + if (entry->se.executed) { + // If the period for the entry is starting again and it has already + // executed, set it as 'executable again'. Deadline and next_period + // are propagated. + if (/*...*/ <= /*...*/) { + entry->se.executed = /*...*/; + entry->se.deadline += /*...*/; + entry->se.next_period += /*...*/; + pr_debug("[%9d] Activating task '%16s' [period:%d], deadline:%5d; next_period:%5d, WCET:%6d\t\n", + timer_get_ticks(), + entry->name, + /*...*/, + /*...*/, + /*...*/, + /*...*/); + } else { + // If the next period of the process is less than the minimum value, pick it. + if (/*...*/ < /*...*/) { + // Set it as next task. + next = entry; + // Update the minimum value. + min = /*...*/; + } + } + } + } + if (next) + return next; +#endif + // If there are no periodic task to execute, just pick an aperiodic task by + // using Round-Robin. return __scheduler_rr(runqueue, false); } @@ -237,7 +388,9 @@ task_struct *scheduler_pick_next_task(runqueue_t *runqueue) // Update the last context switch time of the next task. next->se.exec_start = timer_get_ticks(); + // Update the feedback statistics for the new scheduled task. scheduler_feedback_task_update(next); + // Update the overall feedback system. scheduler_feedback_update(); return next; diff --git a/mentos/src/process/scheduler_feedback.c b/mentos/src/process/scheduler_feedback.c index dbecb02..e062f03 100644 --- a/mentos/src/process/scheduler_feedback.c +++ b/mentos/src/process/scheduler_feedback.c @@ -17,7 +17,7 @@ /// Change the header. #define __DEBUG_HEADER__ "[SCHFBK]" /// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_DEBUG +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE #include "io/debug.h" /// @brief How often the feedback is shown. diff --git a/mentos/src/process/wait.c b/mentos/src/process/wait.c index cbd1b4c..7101124 100644 --- a/mentos/src/process/wait.c +++ b/mentos/src/process/wait.c @@ -1,14 +1,13 @@ /// @file wait.c /// @brief wait functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[WAIT ]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[WAIT ]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "process/wait.h" diff --git a/mentos/src/sys/module.c b/mentos/src/sys/module.c index 1879610..f842a26 100644 --- a/mentos/src/sys/module.c +++ b/mentos/src/sys/module.c @@ -1,20 +1,18 @@ /// @file module.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[MODULE]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[MODULE]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "mem/slab.h" #include "sys/module.h" #include "string.h" #include "sys/bitops.h" -#include "io/debug.h" /// Defined in kernel.ld, points at the end of kernel's data segment. extern void *_kernel_end; diff --git a/mentos/src/sys/utsname.c b/mentos/src/sys/utsname.c index 1d123a4..b7c63ed 100644 --- a/mentos/src/sys/utsname.c +++ b/mentos/src/sys/utsname.c @@ -1,12 +1,17 @@ /// @file utsname.c /// @brief Functions used to provide information about the machine & OS. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[UTSNAM]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. + #include "string.h" #include "sys/utsname.h" #include "version.h" -#include "io/debug.h" #include "sys/errno.h" #include "fcntl.h" #include "fs/vfs.h" diff --git a/mentos/src/system/errno.c b/mentos/src/system/errno.c index 27a916c..b39806b 100644 --- a/mentos/src/system/errno.c +++ b/mentos/src/system/errno.c @@ -1,6 +1,6 @@ /// @file errno.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "sys/errno.h" diff --git a/mentos/src/system/panic.c b/mentos/src/system/panic.c index fa27d7d..9ac52ac 100644 --- a/mentos/src/system/panic.c +++ b/mentos/src/system/panic.c @@ -1,6 +1,6 @@ /// @file panic.c /// @brief Functions used to manage kernel panic. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/panic.h" diff --git a/mentos/src/system/printk.c b/mentos/src/system/printk.c index 3f14953..19713ff 100644 --- a/mentos/src/system/printk.c +++ b/mentos/src/system/printk.c @@ -1,6 +1,6 @@ /// @file printk.c /// @brief Functions for managing the kernel messages. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "system/printk.h" diff --git a/mentos/src/system/signal.c b/mentos/src/system/signal.c index 75105bd..26de7b8 100644 --- a/mentos/src/system/signal.c +++ b/mentos/src/system/signal.c @@ -1,14 +1,13 @@ /// @file signal.c /// @brief Signals definition. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[SIGNAL]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[SIGNAL]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "system/signal.h" #include "process/wait.h" @@ -16,7 +15,6 @@ #include "process/process.h" #include "sys/errno.h" #include "assert.h" -#include "io/debug.h" #include "string.h" #include "klib/irqflags.h" #include "klib/stack_helper.h" @@ -62,14 +60,24 @@ static const char *sys_siglist[] = { NULL, }; +static inline void __copy_sigaction(sigaction_t *to, const sigaction_t *from) +{ + memcpy(to, from, sizeof(sigaction_t)); +} + +static inline void __copy_sigset(sigset_t *to, const sigset_t *from) +{ + memcpy(to, from, sizeof(sigset_t)); +} + static inline void __copy_siginfo(siginfo_t *to, const siginfo_t *from) { - memcpy(to, from, sizeof(*to)); + memcpy(to, from, sizeof(siginfo_t)); } static inline void __clear_siginfo(siginfo_t *info) { - memset(info, 0, sizeof(*info)); + memset(info, 0, sizeof(siginfo_t)); } static inline void __lock_task_sighand(struct task_struct *t) @@ -159,7 +167,7 @@ static int __send_signal(int sig, siginfo_t *info, struct task_struct *t) } list_head_insert_before(&q->list, &t->pending.list); if (info != SEND_SIG_NOINFO) - memcpy(&q->info, info, sizeof(siginfo_t)); + __copy_siginfo(&q->info, info); // Set that there is a signal pending. sigaddset(&t->pending.signal, sig); pr_debug("Added pending signal (%2d)`%s` to task (%2d)`%s`, pending `%d, %d`.\n", @@ -229,15 +237,16 @@ static inline void __collect_signal(int sig, sigpending_t *list, siginfo_t *info // Ok, it wasn't in the queue, zero out the info. __clear_siginfo(info); // Get the current process. - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Initialize the info. info->si_signo = sig; info->si_code = SI_USER; info->si_value.sival_int = 0; info->si_errno = 0; - info->si_pid = current->pid; - info->si_uid = current->uid; + info->si_pid = current_process->pid; + info->si_uid = current_process->uid; info->si_addr = NULL; info->si_status = 0; info->si_band = 0; @@ -260,26 +269,26 @@ static inline int __dequeue_signal(sigpending_t *pending, sigset_t *mask, siginf static inline int __handle_signal(int signr, siginfo_t *info, sigaction_t *ka, struct pt_regs *regs) { pr_debug("__handle_signal(%d, %p, %p, %p)\n", signr, info, ka, regs); - // The do_signal() function is usually only invoked when the CPU is going - // to return in User Mode. - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Skip the `init` process, always. - if (current->pid == 1) { + if (current_process->pid == 1) { errno = ESRCH; return 0; } // Save the previous signal mask. - memcpy(¤t->saved_sigmask, ¤t->blocked, sizeof(sigset_t)); + __copy_sigset(¤t_process->saved_sigmask, ¤t_process->blocked); // Add the signal to the list of blocked signals. - sigaddset(¤t->blocked, signr); + sigaddset(¤t_process->blocked, signr); // Store the registers before setting the ones required by the signal handling. - current->thread.signal_regs = *regs; + current_process->thread.signal_regs = *regs; // Restore the registers for the process that has set the signal. - *regs = current->thread.regs; + *regs = current_process->thread.regs; // Set the instruction pointer. regs->eip = (uintptr_t)ka->sa_handler; @@ -300,7 +309,7 @@ static inline int __handle_signal(int signr, siginfo_t *info, sigaction_t *ka, s PUSH_VALUE_ON_STACK(regs->useresp, signr); // Push on the stack the function required to handle the signal return. - PUSH_VALUE_ON_STACK(regs->useresp, current->sigreturn_addr); + PUSH_VALUE_ON_STACK(regs->useresp, current_process->sigreturn_addr); return 1; } @@ -308,14 +317,16 @@ static inline int __handle_signal(int signr, siginfo_t *info, sigaction_t *ka, s long sys_sigreturn(struct pt_regs *f) { pr_debug("sys_sigreturn(%p)\n", f); - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Restore the registers before the signal handling. - *f = current->thread.signal_regs; + *f = current_process->thread.signal_regs; // Restore the previous signal mask. - memcpy(¤t->blocked, ¤t->saved_sigmask, sizeof(sigset_t)); + __copy_sigset(¤t_process->blocked, ¤t_process->saved_sigmask); // Switch to process page directory - paging_switch_directory_va(current->mm->pgd); + paging_switch_directory_va(current_process->mm->pgd); pr_debug("sys_sigreturn(%p) : done!\n", f); return 0; } @@ -375,10 +386,10 @@ int do_signal(struct pt_regs *f) { // The do_signal() function is usually only invoked when the CPU is going // to return in User Mode. - struct task_struct *current = scheduler_get_current_process(); - if (current == NULL) - return 0; - + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // First, checks whether the function itself was triggered by an interrupt; // if so, it simply returns. Otherwise, if the function was triggered by an // exception that was raised while the process was running in User Mode, @@ -392,14 +403,14 @@ int do_signal(struct pt_regs *f) int signr, exit_code; // Lock the signal handling for the given task. - __lock_task_sighand(current); + __lock_task_sighand(current_process); // The heart of the do_signal( ) function consists of a loop that // repeatedly invokes the __dequeue_signal( ) function until no // non-blocked pending signals are left. - while (!list_head_empty(¤t->pending.list)) { + while (!list_head_empty(¤t_process->pending.list)) { // Get the signal to deliver. - signr = exit_code = __dequeue_signal(¤t->pending, ¤t->blocked, &info); + signr = exit_code = __dequeue_signal(¤t_process->pending, ¤t_process->blocked, &info); // Check the signal that we want to send. if ((signr < 0) || (signr >= NSIG)) { @@ -411,16 +422,16 @@ int do_signal(struct pt_regs *f) // handled and do_signal( ) can finish. if (signr == 0) { pr_debug("There are no more signals to handle.\n"); - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); return 0; } // Get the associated signal action. - sigaction_t *ka = ¤t->sighand.action[signr - 1]; + sigaction_t *ka = ¤t_process->sighand.action[signr - 1]; // The only exception comes when the receiving process is init, in // which case the signal is discarded. - if (current->pid == 1) + if (current_process->pid == 1) continue; // When a delivered signal is explicitly ignored, the do_signal( ) @@ -456,13 +467,13 @@ int do_signal(struct pt_regs *f) case SIGTSTP: case SIGTTIN: case SIGTTOU: - if (is_orphaned_pgrp(current->pgid)) + if (is_orphaned_pgrp(current_process->pgid)) continue; case SIGSTOP: - __unlock_task_sighand(current); - __do_signal_stop(current, f, signr); - __lock_task_sighand(current); + __unlock_task_sighand(current_process); + __do_signal_stop(current_process, f, signr); + __lock_task_sighand(current_process); continue; case SIGQUIT: @@ -485,20 +496,20 @@ int do_signal(struct pt_regs *f) #endif default: #if 0 - current->flags |= PF_SIGNALED; + current_process->flags |= PF_SIGNALED; #endif sys_exit(exit_code); - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); return 1; } } if (__handle_signal(signr, &info, ka, f) == 1) { - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); return 1; } pr_emerg("Failed to handle signal.\n"); } - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); return 0; } @@ -611,9 +622,9 @@ int __send_sig_info(int sig, siginfo_t *info, struct task_struct *p) int sys_kill(pid_t pid, int sig) { pr_debug("sys_kill(%d, %d)\n", pid, sig); - struct task_struct *current = scheduler_get_running_process(pid); + struct task_struct *process = scheduler_get_running_process(pid); // Check the task associated with the pid. - if (!current) + if (!process) return -ESRCH; // Check the signal that we want to send. if ((sig < 0) || (sig >= NSIG)) @@ -623,12 +634,12 @@ int sys_kill(pid_t pid, int sig) info.si_code = SI_USER; info.si_value.sival_int = 0; info.si_errno = 0; - info.si_pid = current->pid; - info.si_uid = current->uid; + info.si_pid = process->pid; + info.si_uid = process->uid; info.si_addr = NULL; info.si_status = 0; info.si_band = 0; - return __send_sig_info(sig, &info, current); + return __send_sig_info(sig, &info, process); } sighandler_t sys_signal(int signum, sighandler_t handler, uint32_t sigreturn_addr) @@ -639,12 +650,12 @@ sighandler_t sys_signal(int signum, sighandler_t handler, uint32_t sigreturn_add pr_err("sys_signal(%d, %p): Wrong signal number!\n", signum, handler); return SIG_ERR; } - // The do_signal() function is usually only invoked when the CPU is going - // to return in User Mode. - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Skip the `init` process, always. - if (current->pid == 1) { + if (current_process->pid == 1) { pr_err("sys_signal(%d, %p): Cannot signal init!\n", signum, handler); return SIG_ERR; } @@ -657,19 +668,19 @@ sighandler_t sys_signal(int signum, sighandler_t handler, uint32_t sigreturn_add // Reset the set for the signal action. sigemptyset(&new_sigaction.sa_mask); // Lock the signal handling for the given task. - __lock_task_sighand(current); + __lock_task_sighand(current_process); // Set the address of the sigreturn. - current->sigreturn_addr = sigreturn_addr; + current_process->sigreturn_addr = sigreturn_addr; // Get the old sigaction. - sigaction_t *old_sigaction = ¤t->sighand.action[signum - 1]; + sigaction_t *old_sigaction = ¤t_process->sighand.action[signum - 1]; pr_err("sys_signal(%d, %p): Signal action ptr %p\n", signum, handler, old_sigaction); pr_err("sys_signal(%d, %p): Old signal handler %p\n", signum, handler, old_sigaction->sa_handler); // Get the old handler (to return). - sighandler_t old_handler = current->sighand.action[signum - 1].sa_handler; + sighandler_t old_handler = current_process->sighand.action[signum - 1].sa_handler; // Set the new action. - memcpy(old_sigaction, &new_sigaction, sizeof(sigaction_t)); + __copy_sigaction(old_sigaction, &new_sigaction); // Unlock the signal handling for the given task. - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); // Return the old sighandler. return old_handler; } @@ -682,30 +693,30 @@ int sys_sigaction(int signum, const sigaction_t *act, sigaction_t *oldact, uint3 pr_err("sys_sigaction(%d, %p, %p): Wrong signal number!\n", signum, act, oldact); return -EINVAL; } - // The do_signal() function is usually only invoked when the CPU is going - // to return in User Mode. - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Skip the `init` process, always. - if (current->pid == 1) { + if (current_process->pid == 1) { pr_err("sys_sigaction(%d, %p, %p): Cannot set signal for init!\n", signum, act, oldact); return -EINVAL; } // Lock the signal handling for the given task. - __lock_task_sighand(current); + __lock_task_sighand(current_process); // Set the address of the sigreturn. - current->sigreturn_addr = sigreturn_addr; + current_process->sigreturn_addr = sigreturn_addr; // Get a pointer to the entry in the sighand.action array. - sigaction_t *current_sigaction = ¤t->sighand.action[signum - 1]; - pr_debug("sys_sigaction(%d, %p, %p): : Signal old action ptr %p\n", signum, act, oldact, current_sigaction); + sigaction_t *current_process_sigaction = ¤t_process->sighand.action[signum - 1]; + pr_debug("sys_sigaction(%d, %p, %p): : Signal old action ptr %p\n", signum, act, oldact, current_process_sigaction); // If requested, get the old sigaction. if (oldact) { - memcpy(oldact, current_sigaction, sizeof(sigaction_t)); + __copy_sigaction(oldact, current_process_sigaction); } // Set the new action. - memcpy(current_sigaction, act, sizeof(sigaction_t)); + __copy_sigaction(current_process_sigaction, act); // Unlock the signal handling for the given task. - __unlock_task_sighand(current); + __unlock_task_sighand(current_process); // Return the old sighandler. return 0; } @@ -719,42 +730,57 @@ int sys_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) if ((how < SIG_BLOCK) || (how > SIG_SETMASK)) { return -EINVAL; } - // The do_signal() function is usually only invoked when the CPU is going - // to return in User Mode. - struct task_struct *current = scheduler_get_current_process(); - assert(current && "There is no running process."); + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); // Skip the `init` process, always. - if (current->pid == 1) { + if (current_process->pid == 1) { pr_warning("sys_sigprocmask(%d, %p, %p): Cannot set signal for init!\n", how, set, oldset); return -EINVAL; } // If `oldset` is not, return the old set. if (oldset) { - oldset->sig[0] = current->blocked.sig[0]; - oldset->sig[1] = current->blocked.sig[1]; + oldset->sig[0] = current_process->blocked.sig[0]; + oldset->sig[1] = current_process->blocked.sig[1]; } // Set the new signal mask. if (set) { if (how == SIG_BLOCK) { // The set of blocked signals is the union of the current set // and the set argument. - current->blocked.sig[0] |= set->sig[0]; - current->blocked.sig[1] |= set->sig[1]; + current_process->blocked.sig[0] |= set->sig[0]; + current_process->blocked.sig[1] |= set->sig[1]; } else if (how == SIG_UNBLOCK) { // The signals in set are removed from the current set of // blocked signals. It is permissible to attempt to unblock // a signal which is not blocked. - current->blocked.sig[0] &= ~(set->sig[0]); - current->blocked.sig[1] &= ~(set->sig[1]); + current_process->blocked.sig[0] &= ~(set->sig[0]); + current_process->blocked.sig[1] &= ~(set->sig[1]); } else if (how == SIG_SETMASK) { // The set of blocked signals is set to the argument set. - current->blocked.sig[0] = set->sig[0]; - current->blocked.sig[1] = set->sig[1]; + current_process->blocked.sig[0] = set->sig[0]; + current_process->blocked.sig[1] = set->sig[1]; } } return 0; } +int sys_sigpending(sigset_t *set) +{ + // Get the current process. + task_struct *current_process = scheduler_get_current_process(); + // Check the current task. + assert(current_process && "There is no current process!"); + // Check the pointer we were provided with. + if (set == NULL) { + return -EFAULT; + } + // Copy the pending set. + __copy_sigset(set, ¤t_process->pending.signal); + return 0; +} + const char *strsignal(int sig) { if ((sig >= SIGHUP) && (sig < NSIG)) diff --git a/mentos/src/system/syscall.c b/mentos/src/system/syscall.c index 259866b..a6d1ff8 100644 --- a/mentos/src/system/syscall.c +++ b/mentos/src/system/syscall.c @@ -1,14 +1,13 @@ /// @file syscall.c /// @brief System Call management functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. -// Include the kernel log levels. -#include "sys/kernel_levels.h" -/// Change the header. -#define __DEBUG_HEADER__ "[SYSCLL]" -/// Set the log level. -#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE +// Setup the logging for this file (do this before any other include). +#include "sys/kernel_levels.h" // Include kernel log levels. +#define __DEBUG_HEADER__ "[SYSCLL]" ///< Change header. +#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level. +#include "io/debug.h" // Include debugging functions. #include "devices/fpu.h" #include "mem/kheap.h" @@ -50,68 +49,194 @@ static inline int sys_ni_syscall() void syscall_init() { // Initialize the list of system calls. - for (uint32_t it = 0; it < SYSCALL_NUMBER; ++it) { - sys_call_table[it] = sys_ni_syscall; - } - - sys_call_table[__NR_exit] = (SystemCall)sys_exit; - sys_call_table[__NR_read] = (SystemCall)sys_read; - sys_call_table[__NR_write] = (SystemCall)sys_write; - sys_call_table[__NR_open] = (SystemCall)sys_open; - sys_call_table[__NR_close] = (SystemCall)sys_close; - sys_call_table[__NR_stat] = (SystemCall)sys_stat; - sys_call_table[__NR_fstat] = (SystemCall)sys_fstat; - sys_call_table[__NR_mkdir] = (SystemCall)sys_mkdir; - sys_call_table[__NR_rmdir] = (SystemCall)sys_rmdir; - sys_call_table[__NR_creat] = (SystemCall)sys_creat; - sys_call_table[__NR_unlink] = (SystemCall)sys_unlink; - sys_call_table[__NR_getdents] = (SystemCall)sys_getdents; - sys_call_table[__NR_lseek] = (SystemCall)sys_lseek; - sys_call_table[__NR_getpid] = (SystemCall)sys_getpid; - sys_call_table[__NR_getsid] = (SystemCall)sys_getsid; - sys_call_table[__NR_setsid] = (SystemCall)sys_setsid; - sys_call_table[__NR_getpgid] = (SystemCall)sys_getpgid; - sys_call_table[__NR_setpgid] = (SystemCall)sys_setpgid; - sys_call_table[__NR_getuid] = (SystemCall)sys_getuid; - sys_call_table[__NR_setuid] = (SystemCall)sys_setuid; - sys_call_table[__NR_getgid] = (SystemCall)sys_getgid; - sys_call_table[__NR_setgid] = (SystemCall)sys_setgid; - sys_call_table[__NR_getppid] = (SystemCall)sys_getppid; - sys_call_table[__NR_sigaction] = (SystemCall)sys_sigaction; - sys_call_table[__NR_fork] = (SystemCall)sys_fork; - sys_call_table[__NR_execve] = (SystemCall)sys_execve; - sys_call_table[__NR_nice] = (SystemCall)sys_nice; - sys_call_table[__NR_kill] = (SystemCall)sys_kill; - sys_call_table[__NR_reboot] = (SystemCall)sys_reboot; - sys_call_table[__NR_uname] = (SystemCall)sys_uname; - sys_call_table[__NR_sigreturn] = (SystemCall)sys_sigreturn; - sys_call_table[__NR_waitpid] = (SystemCall)sys_waitpid; - sys_call_table[__NR_chdir] = (SystemCall)sys_chdir; - sys_call_table[__NR_fchdir] = (SystemCall)sys_fchdir; - sys_call_table[__NR_time] = (SystemCall)sys_time; - sys_call_table[__NR_sigprocmask] = (SystemCall)sys_sigprocmask; - sys_call_table[__NR_brk] = (SystemCall)sys_brk; - sys_call_table[__NR_signal] = (SystemCall)sys_signal; - sys_call_table[__NR_ioctl] = (SystemCall)sys_ioctl; - sys_call_table[__NR_sched_setparam] = (SystemCall)sys_sched_setparam; - sys_call_table[__NR_sched_getparam] = (SystemCall)sys_sched_getparam; - sys_call_table[__NR_nanosleep] = (SystemCall)sys_nanosleep; - sys_call_table[__NR_getcwd] = (SystemCall)sys_getcwd; - sys_call_table[__NR_waitperiod] = (SystemCall)sys_waitperiod; - sys_call_table[__NR_msgctl] = (SystemCall)sys_msgctl; - sys_call_table[__NR_msgget] = (SystemCall)sys_msgget; - sys_call_table[__NR_msgrcv] = (SystemCall)sys_msgrcv; - sys_call_table[__NR_msgsnd] = (SystemCall)sys_msgsnd; - sys_call_table[__NR_semctl] = (SystemCall)sys_semctl; - sys_call_table[__NR_semget] = (SystemCall)sys_semget; - sys_call_table[__NR_semop] = (SystemCall)sys_semop; - sys_call_table[__NR_shmat] = (SystemCall)sys_shmat; - sys_call_table[__NR_shmctl] = (SystemCall)sys_shmctl; - sys_call_table[__NR_shmdt] = (SystemCall)sys_shmdt; - sys_call_table[__NR_shmget] = (SystemCall)sys_shmget; - sys_call_table[__NR_alarm] = (SystemCall)sys_alarm; - sys_call_table[__NR_setitimer] = (SystemCall)sys_setitimer; - sys_call_table[__NR_getitimer] = (SystemCall)sys_getitimer; + sys_call_table[__NR_exit] = (SystemCall)sys_exit; + sys_call_table[__NR_fork] = (SystemCall)sys_fork; + sys_call_table[__NR_read] = (SystemCall)sys_read; + sys_call_table[__NR_write] = (SystemCall)sys_write; + sys_call_table[__NR_open] = (SystemCall)sys_open; + sys_call_table[__NR_close] = (SystemCall)sys_close; + sys_call_table[__NR_waitpid] = (SystemCall)sys_waitpid; + sys_call_table[__NR_creat] = (SystemCall)sys_creat; + sys_call_table[__NR_link] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_unlink] = (SystemCall)sys_unlink; + sys_call_table[__NR_execve] = (SystemCall)sys_execve; + sys_call_table[__NR_chdir] = (SystemCall)sys_chdir; + sys_call_table[__NR_time] = (SystemCall)sys_time; + sys_call_table[__NR_mknod] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_chmod] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_lchown] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_stat] = (SystemCall)sys_stat; + sys_call_table[__NR_lseek] = (SystemCall)sys_lseek; + sys_call_table[__NR_getpid] = (SystemCall)sys_getpid; + sys_call_table[__NR_mount] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_oldumount] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setuid] = (SystemCall)sys_setuid; + sys_call_table[__NR_getuid] = (SystemCall)sys_getuid; + sys_call_table[__NR_stime] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ptrace] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_alarm] = (SystemCall)sys_alarm; + sys_call_table[__NR_fstat] = (SystemCall)sys_fstat; + sys_call_table[__NR_pause] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_utime] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_access] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_nice] = (SystemCall)sys_nice; + sys_call_table[__NR_sync] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_kill] = (SystemCall)sys_kill; + sys_call_table[__NR_rename] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_mkdir] = (SystemCall)sys_mkdir; + sys_call_table[__NR_rmdir] = (SystemCall)sys_rmdir; + sys_call_table[__NR_dup] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_pipe] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_times] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_brk] = (SystemCall)sys_brk; + sys_call_table[__NR_setgid] = (SystemCall)sys_setgid; + sys_call_table[__NR_getgid] = (SystemCall)sys_getgid; + sys_call_table[__NR_signal] = (SystemCall)sys_signal; + sys_call_table[__NR_geteuid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getegid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_acct] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_umount] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ioctl] = (SystemCall)sys_ioctl; + sys_call_table[__NR_fcntl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setpgid] = (SystemCall)sys_setpgid; + sys_call_table[__NR_olduname] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_umask] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_chroot] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ustat] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_dup2] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getppid] = (SystemCall)sys_getppid; + sys_call_table[__NR_getpgrp] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setsid] = (SystemCall)sys_setsid; + sys_call_table[__NR_sigaction] = (SystemCall)sys_sigaction; + sys_call_table[__NR_sgetmask] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ssetmask] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setreuid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setregid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sigsuspend] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sigpending] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sethostname] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setrlimit] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getrlimit] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getrusage] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_gettimeofday] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_settimeofday] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getgroups] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setgroups] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_symlink] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_lstat] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_readlink] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_uselib] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_swapon] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_reboot] = (SystemCall)sys_reboot; + sys_call_table[__NR_readdir] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_mmap] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_munmap] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_truncate] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ftruncate] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_fchmod] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_fchown] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getpriority] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setpriority] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_statfs] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_fstatfs] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ioperm] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_socketcall] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_syslog] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setitimer] = (SystemCall)sys_setitimer; + sys_call_table[__NR_getitimer] = (SystemCall)sys_getitimer; + sys_call_table[__NR_newstat] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_newlstat] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_newfstat] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_uname] = (SystemCall)sys_uname; + sys_call_table[__NR_iopl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_vhangup] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_idle] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_vm86old] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_wait4] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_swapoff] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sysinfo] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_ipc] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_fsync] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sigreturn] = (SystemCall)sys_sigreturn; + sys_call_table[__NR_clone] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setdomainname] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_newuname] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_modify_ldt] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_adjtimex] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_mprotect] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sigprocmask] = (SystemCall)sys_sigprocmask; + sys_call_table[__NR_create_module] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_init_module] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_delete_module] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_get_kernel_syms] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_quotactl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getpgid] = (SystemCall)sys_getpgid; + sys_call_table[__NR_fchdir] = (SystemCall)sys_fchdir; + sys_call_table[__NR_bdflush] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sysfs] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_personality] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setfsuid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setfsgid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_llseek] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getdents] = (SystemCall)sys_getdents; + sys_call_table[__NR_select] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_flock] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_msync] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_readv] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_writev] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getsid] = (SystemCall)sys_getsid; + sys_call_table[__NR_fdatasync] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sysctl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_mlock] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_munlock] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_mlockall] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_munlockall] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_setparam] = (SystemCall)sys_sched_setparam; + sys_call_table[__NR_sched_getparam] = (SystemCall)sys_sched_getparam; + sys_call_table[__NR_sched_setscheduler] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_getscheduler] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_yield] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_get_priority_max] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_get_priority_min] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sched_rr_get_interval] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_nanosleep] = (SystemCall)sys_nanosleep; + sys_call_table[__NR_mremap] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setresuid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getresuid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_vm86] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_query_module] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_poll] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_nfsservctl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_setresgid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getresgid] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_prctl] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigreturn] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigaction] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigprocmask] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigpending] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigtimedwait] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigqueueinfo] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_rt_sigsuspend] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_pread] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_pwrite] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_chown] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_getcwd] = (SystemCall)sys_getcwd; + sys_call_table[__NR_capget] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_capset] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sigaltstack] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_sendfile] = (SystemCall)sys_ni_syscall; + sys_call_table[__NR_waitperiod] = (SystemCall)sys_waitperiod; + sys_call_table[__NR_msgctl] = (SystemCall)sys_msgctl; + sys_call_table[__NR_msgget] = (SystemCall)sys_msgget; + sys_call_table[__NR_msgrcv] = (SystemCall)sys_msgrcv; + sys_call_table[__NR_msgsnd] = (SystemCall)sys_msgsnd; + sys_call_table[__NR_semctl] = (SystemCall)sys_semctl; + sys_call_table[__NR_semget] = (SystemCall)sys_semget; + sys_call_table[__NR_semop] = (SystemCall)sys_semop; + sys_call_table[__NR_shmat] = (SystemCall)sys_shmat; + sys_call_table[__NR_shmctl] = (SystemCall)sys_shmctl; + sys_call_table[__NR_shmdt] = (SystemCall)sys_shmdt; + sys_call_table[__NR_shmget] = (SystemCall)sys_shmget; isr_install_handler(SYSTEM_CALL, &syscall_handler, "syscall_handler"); } diff --git a/programs/cat.c b/programs/cat.c index 3720d7f..739da34 100644 --- a/programs/cat.c +++ b/programs/cat.c @@ -1,6 +1,6 @@ /// @file cat.c /// @brief `cat` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/clear.c b/programs/clear.c index 9e6f3e1..e806e57 100644 --- a/programs/clear.c +++ b/programs/clear.c @@ -1,6 +1,6 @@ /// @file clear.c /// @brief `clear` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/cpuid.c b/programs/cpuid.c index 2b47ecb..0d6b169 100644 --- a/programs/cpuid.c +++ b/programs/cpuid.c @@ -1,6 +1,6 @@ /// @file cpuid.c /// @brief `cpuid` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/date.c b/programs/date.c index 9895bd4..627bdd4 100644 --- a/programs/date.c +++ b/programs/date.c @@ -1,6 +1,6 @@ /// @file date.c /// @brief `date` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/echo.c b/programs/echo.c index 6488d77..8a3f156 100644 --- a/programs/echo.c +++ b/programs/echo.c @@ -1,6 +1,6 @@ /// @file echo.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/edit.c b/programs/edit.c index 4166a53..7c6a45a 100644 --- a/programs/edit.c +++ b/programs/edit.c @@ -1,10 +1,15 @@ +/// @file edit.c +/// @brief +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. +/// See LICENSE.md for details. + #include #include #include #include #include #include -#include +#include #include #include #include diff --git a/programs/env.c b/programs/env.c index 1248558..275d304 100644 --- a/programs/env.c +++ b/programs/env.c @@ -1,6 +1,6 @@ /// @file env.c /// @brief `env` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/init.c b/programs/init.c index 7178c97..b8c1315 100644 --- a/programs/init.c +++ b/programs/init.c @@ -1,6 +1,6 @@ /// @file init.c /// @brief `init` program. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/ipcrm.c b/programs/ipcrm.c index 6f8b50c..520f462 100644 --- a/programs/ipcrm.c +++ b/programs/ipcrm.c @@ -1,6 +1,6 @@ /// @file ipcrm.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. int main(int argc, char **argv) diff --git a/programs/ipcs.c b/programs/ipcs.c index b61cdb0..e4d4551 100644 --- a/programs/ipcs.c +++ b/programs/ipcs.c @@ -1,6 +1,6 @@ /// @file ipcs.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #if 0 diff --git a/programs/kill.c b/programs/kill.c index 5b11b2e..795b547 100644 --- a/programs/kill.c +++ b/programs/kill.c @@ -1,6 +1,6 @@ /// @file kill.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -9,7 +9,7 @@ #include #include #include -#include +#include static inline int is_number(char *s) { diff --git a/programs/login.c b/programs/login.c index 51e1f86..7df633d 100644 --- a/programs/login.c +++ b/programs/login.c @@ -1,6 +1,6 @@ ///// @file login.c /// @brief Functions used to manage login. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -14,9 +14,8 @@ #include #include #include -#include - -#include "ansi_colors.h" +#include +#include /// Maximum length of credentials. #define CREDENTIALS_LENGTH 50 @@ -52,7 +51,7 @@ static inline void __set_io_flags(unsigned flag, bool_t active) tcsetattr(STDIN_FILENO, 0, &_termios); } -static inline void __print_message_file(const char * file) +static inline void __print_message_file(const char *file) { char buffer[256]; ssize_t nbytes, total = 0; @@ -94,7 +93,7 @@ static inline bool_t __get_input(char *input, size_t max_len, bool_t hide) } else if (c == '\033') { c = getchar(); if (c == '[') { - c = getchar(); // Get the char, and ignore it. + getchar(); // Get the char, and ignore it. } else if (c == '^') { c = getchar(); // Get the char. if (c == 'C') { @@ -159,12 +158,12 @@ int main(int argc, char **argv) // Get the username. do { printf("Username :"); - } while (!__get_input(username, CREDENTIALS_LENGTH, false)); + } while (!__get_input(username, sizeof(username), false)); // Get the password. do { printf("Password :"); - } while (!__get_input(password, CREDENTIALS_LENGTH, true)); + } while (!__get_input(password, sizeof(password), true)); // Check if we can find the user. if ((pwd = getpwnam(username)) == NULL) { @@ -200,10 +199,16 @@ int main(int argc, char **argv) } // Set the group id. - setgid(pwd->pw_gid); + if (setgid(pwd->pw_gid) < 0) { + printf("login: Failed to change group id: %s\n", strerror(errno)); + return 1; + } // Set the user id. - setuid(pwd->pw_uid); + if (setuid(pwd->pw_uid) < 0) { + printf("login: Failed to change user id: %s\n", strerror(errno)); + return 1; + } printf("\n"); diff --git a/programs/logo.c b/programs/logo.c index 1e92a45..3625fe7 100644 --- a/programs/logo.c +++ b/programs/logo.c @@ -1,6 +1,6 @@ /// @file logo.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/ls.c b/programs/ls.c index 60fafdc..7ab2b08 100644 --- a/programs/ls.c +++ b/programs/ls.c @@ -1,6 +1,6 @@ /// @file ls.c /// @brief Command 'ls'. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -14,7 +14,7 @@ #include #include #include -#include +#include #define FLAG_L (1U << 0U) #define FLAG_A (1U << 1U) diff --git a/programs/man.c b/programs/man.c index dc588a7..aadc317 100644 --- a/programs/man.c +++ b/programs/man.c @@ -1,6 +1,6 @@ /// @file man.c /// @brief Shows the available commands. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/mkdir.c b/programs/mkdir.c index 56f2c90..a068d47 100644 --- a/programs/mkdir.c +++ b/programs/mkdir.c @@ -1,6 +1,6 @@ /// @file mkdir.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/nice.c b/programs/nice.c index 91c0051..c5075aa 100644 --- a/programs/nice.c +++ b/programs/nice.c @@ -1,6 +1,6 @@ /// @file nice.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/poweroff.c b/programs/poweroff.c index 954918d..3aa1f52 100644 --- a/programs/poweroff.c +++ b/programs/poweroff.c @@ -1,6 +1,6 @@ /// @file poweroff.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/ps.c b/programs/ps.c index da27671..efbcc6b 100644 --- a/programs/ps.c +++ b/programs/ps.c @@ -1,27 +1,25 @@ /// @file ps.c /// @brief Report a snapshot of the current processes. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include #include #include #include -#include #include +#include #define FORMAT_S "%5s %5s %6s %s\n" #define FORMAT "%5d %5d %6c %s\n" -static inline void __iterate_proc_dirs(int fd) +static inline void __iterate_proc_dirs(int proc_fd) { char absolute_path[PATH_MAX] = "/proc/"; // Holds the file descriptor of the stat file. int stat_fd; // Buffer used to read the stat file. char stat_buffer[BUFSIZ] = { 0 }; - // Holds the number of bytes read from stat file. - ssize_t ret; // Variables used to read the stat file. // (1) pid %d // (2) comm %s @@ -33,7 +31,20 @@ static inline void __iterate_proc_dirs(int fd) pid_t ppid; // The directory entry. dirent_t dent; - while (getdents(fd, &dent, sizeof(dirent_t)) == sizeof(dirent_t)) { + // Holds the number of bytes read. + ssize_t read_bytes; + do { + // Read an entry. + read_bytes = getdents(proc_fd, &dent, sizeof(dirent_t)); + // We reached the end of the folder. + if (read_bytes == 0) { + break; + } + // We encountered an error. + if (read_bytes == -1) { + perror("Failed to read entry in `/proc` folder"); + exit(EXIT_FAILURE); + } // Skip non-directories. if (dent.d_type != DT_DIR) continue; @@ -42,14 +53,20 @@ static inline void __iterate_proc_dirs(int fd) strcat(absolute_path, "/stat"); // Open the `/proc//stat` file. if ((stat_fd = open(absolute_path, O_RDONLY, 0)) == -1) { - printf("Failed to open `%s`\n", absolute_path); + printf("Failed to open `%s`: ", absolute_path); + perror(NULL); + putchar('\n'); continue; } // Reset the stat buffer. memset(stat_buffer, 0, BUFSIZ); // Read the content of the stat file. - if ((ret = read(stat_fd, stat_buffer, BUFSIZ)) <= 0) { - printf("Cannot read `%s`\n", absolute_path); + read_bytes = read(stat_fd, stat_buffer, BUFSIZ); + // Check if the read failed. + if (read_bytes <= 0) { + printf("Cannot read `%s`", absolute_path); + perror(NULL); + putchar('\n'); close(stat_fd); continue; } @@ -61,14 +78,15 @@ static inline void __iterate_proc_dirs(int fd) printf(FORMAT, pid, ppid, state, comm); // Closing stat FD. close(stat_fd); - } + } while (1); } int main(int argc, char **argv) { int fd = open("/proc", O_RDONLY | O_DIRECTORY, 0); if (fd == -1) { - printf("ps: cannot access '/proc': %s\n\n", strerror(errno)); + perror("ps: cannot access '/proc' folder"); + return EXIT_FAILURE; } else { printf(FORMAT_S, "PID", "PPID", "STATUS", "CMD"); __iterate_proc_dirs(fd); @@ -124,5 +142,5 @@ int main(int argc, char **argv) } close(fd_self); #endif - return 0; + return EXIT_SUCCESS; } diff --git a/programs/pwd.c b/programs/pwd.c index e8fef61..ad9e6b7 100644 --- a/programs/pwd.c +++ b/programs/pwd.c @@ -1,6 +1,6 @@ /// @file pwd.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/rm.c b/programs/rm.c index 444ff74..0b5b08c 100644 --- a/programs/rm.c +++ b/programs/rm.c @@ -1,6 +1,6 @@ /// @file rm.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/rmdir.c b/programs/rmdir.c index aeadaa9..ee96147 100644 --- a/programs/rmdir.c +++ b/programs/rmdir.c @@ -1,6 +1,6 @@ /// @file rmdir.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/shell.c b/programs/shell.c index a0605fa..0a78d91 100644 --- a/programs/shell.c +++ b/programs/shell.c @@ -1,6 +1,6 @@ /// @file shell.c /// @brief Implement shell functions. -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include @@ -9,19 +9,19 @@ #include #include #include -#include +#include +#include #include -#include "stdbool.h" -#include "stddef.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" -#include "strerror.h" -#include "termios.h" -#include "limits.h" -#include "sys/utsname.h" -#include "ctype.h" -#include "ansi_colors.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /// Maximum length of commands. #define CMD_LEN 32 diff --git a/programs/showpid.c b/programs/showpid.c index 7128c65..5891a62 100644 --- a/programs/showpid.c +++ b/programs/showpid.c @@ -1,6 +1,6 @@ /// @file showpid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/sleep.c b/programs/sleep.c index 6c9affe..312d48f 100644 --- a/programs/sleep.c +++ b/programs/sleep.c @@ -1,6 +1,6 @@ /// @file sleep.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_abort.c b/programs/tests/t_abort.c index 28f35a5..b0ddf04 100644 --- a/programs/tests/t_abort.c +++ b/programs/tests/t_abort.c @@ -1,6 +1,6 @@ /// @file t_abort.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_alarm.c b/programs/tests/t_alarm.c index 0cf136a..6982b4d 100644 --- a/programs/tests/t_alarm.c +++ b/programs/tests/t_alarm.c @@ -1,6 +1,6 @@ /// @file t_alarm.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_exec.c b/programs/tests/t_exec.c index 6979379..c348fbe 100644 --- a/programs/tests/t_exec.c +++ b/programs/tests/t_exec.c @@ -1,6 +1,6 @@ /// @file t_exec.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_exec_callee.c b/programs/tests/t_exec_callee.c index 3f78b44..34bf229 100644 --- a/programs/tests/t_exec_callee.c +++ b/programs/tests/t_exec_callee.c @@ -1,6 +1,6 @@ /// @file t_exec_callee.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_fork.c b/programs/tests/t_fork.c index 004f806..f3ee399 100644 --- a/programs/tests/t_fork.c +++ b/programs/tests/t_fork.c @@ -1,6 +1,6 @@ /// @file t_fork.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_getenv.c b/programs/tests/t_getenv.c index 05fabcc..fa1a528 100644 --- a/programs/tests/t_getenv.c +++ b/programs/tests/t_getenv.c @@ -1,6 +1,6 @@ /// @file t_getenv.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_gid.c b/programs/tests/t_gid.c index f91e827..bf5b809 100644 --- a/programs/tests/t_gid.c +++ b/programs/tests/t_gid.c @@ -1,6 +1,6 @@ /// @file t_gid.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include "grp.h" diff --git a/programs/tests/t_groups.c b/programs/tests/t_groups.c index 5c8a555..5519706 100644 --- a/programs/tests/t_groups.c +++ b/programs/tests/t_groups.c @@ -1,6 +1,6 @@ /// @file t_groups.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_itimer.c b/programs/tests/t_itimer.c index 695ae27..e1cbcf2 100644 --- a/programs/tests/t_itimer.c +++ b/programs/tests/t_itimer.c @@ -1,6 +1,6 @@ /// @file t_itimer.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_kill.c b/programs/tests/t_kill.c index 0ff9afe..ae1d460 100644 --- a/programs/tests/t_kill.c +++ b/programs/tests/t_kill.c @@ -1,6 +1,6 @@ /// @file t_kill.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_mem.c b/programs/tests/t_mem.c index 189d60f..962be64 100644 --- a/programs/tests/t_mem.c +++ b/programs/tests/t_mem.c @@ -1,6 +1,6 @@ /// @file t_mem.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_periodic1.c b/programs/tests/t_periodic1.c index 813c9e9..b54642e 100644 --- a/programs/tests/t_periodic1.c +++ b/programs/tests/t_periodic1.c @@ -1,6 +1,6 @@ /// @file t_periodic1.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_periodic2.c b/programs/tests/t_periodic2.c index 9f77495..6ab05f1 100644 --- a/programs/tests/t_periodic2.c +++ b/programs/tests/t_periodic2.c @@ -1,6 +1,6 @@ /// @file t_periodic2.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_periodic3.c b/programs/tests/t_periodic3.c index 314d9e5..fc9e591 100644 --- a/programs/tests/t_periodic3.c +++ b/programs/tests/t_periodic3.c @@ -1,6 +1,6 @@ /// @file t_periodic3.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_setenv.c b/programs/tests/t_setenv.c index 442e674..396796c 100644 --- a/programs/tests/t_setenv.c +++ b/programs/tests/t_setenv.c @@ -1,6 +1,6 @@ /// @file t_setenv.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_sigaction.c b/programs/tests/t_sigaction.c index cf92f08..d56e4af 100644 --- a/programs/tests/t_sigaction.c +++ b/programs/tests/t_sigaction.c @@ -1,6 +1,6 @@ /// @file t_sigaction.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_sigfpe.c b/programs/tests/t_sigfpe.c index ed03944..f0087aa 100644 --- a/programs/tests/t_sigfpe.c +++ b/programs/tests/t_sigfpe.c @@ -1,6 +1,6 @@ /// @file t_sigfpe.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_siginfo.c b/programs/tests/t_siginfo.c index 8b285db..8058e68 100644 --- a/programs/tests/t_siginfo.c +++ b/programs/tests/t_siginfo.c @@ -1,6 +1,6 @@ /// @file t_siginfo.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_sigmask.c b/programs/tests/t_sigmask.c index 9fec449..81fb74f 100644 --- a/programs/tests/t_sigmask.c +++ b/programs/tests/t_sigmask.c @@ -1,6 +1,6 @@ /// @file t_sigmask.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_sigusr.c b/programs/tests/t_sigusr.c index a71ae6e..d1372a3 100644 --- a/programs/tests/t_sigusr.c +++ b/programs/tests/t_sigusr.c @@ -1,6 +1,6 @@ /// @file t_sigusr.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_sleep.c b/programs/tests/t_sleep.c index 57b3017..74e5996 100644 --- a/programs/tests/t_sleep.c +++ b/programs/tests/t_sleep.c @@ -1,6 +1,6 @@ /// @file t_sleep.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/tests/t_stopcont.c b/programs/tests/t_stopcont.c index 8b24b27..d17468a 100644 --- a/programs/tests/t_stopcont.c +++ b/programs/tests/t_stopcont.c @@ -1,6 +1,6 @@ /// @file t_stopcont.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/touch.c b/programs/touch.c index 63ae6df..49fc87d 100644 --- a/programs/touch.c +++ b/programs/touch.c @@ -1,6 +1,6 @@ /// @file touch.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/uname.c b/programs/uname.c index 25cbc62..ef9d1c5 100644 --- a/programs/uname.c +++ b/programs/uname.c @@ -1,6 +1,6 @@ /// @file uname.c /// @brief -/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. /// See LICENSE.md for details. #include diff --git a/programs/uptime.c b/programs/uptime.c index d3846f3..840935e 100644 --- a/programs/uptime.c +++ b/programs/uptime.c @@ -1,3 +1,8 @@ +/// @file uptime.c +/// @brief +/// @copyright (c) 2014-2023 This file is distributed under the MIT License. +/// See LICENSE.md for details. + #include #include #include