Compare commits

...

127 Commits

Author SHA1 Message Date
antifallobst f0bf8ac3f5 docs (README): fixed documentation reference 2023-06-10 15:35:14 +02:00
antifallobst b498cb2c98 docs (roadmap): updated progress 2023-06-10 15:30:31 +02:00
antifallobst 81fc9ca9fc feature (syscalls): implemented 'nx_proc_create' 2023-06-10 15:08:31 +02:00
antifallobst 91f7aa4009 feature (drivers): created infrastructure to config drivers to load on startup 2023-06-06 23:22:08 +02:00
antifallobst d7c79e1bdf feature (symbol tables): upgraded symbol tables from static lists to hashmaps 2023-06-06 22:28:47 +02:00
antifallobst ae0ef5c85d fix (hashmaps): fixed bug that caused PFs and GPFs while handling collisions 2023-06-06 22:27:43 +02:00
antifallobst 8c273f4dc7 refactor (kernel): removed unused and unfinished modules system. The new drivers system performs the same task 2023-06-06 22:05:14 +02:00
antifallobst b00b57b180 feature (syscalls): implemented 'nx_drv_register' 2023-06-06 21:43:23 +02:00
antifallobst 4070959736 refactor (syscalls): refactored syscalls to match the documented SysABI 2023-06-06 21:20:29 +02:00
antifallobst 3fbc9dc274 fix (JSON): fixed array parsing 2023-06-06 20:32:30 +02:00
antifallobst 83f5e77d52 feature (strings): implemented DJB string hashing function 2023-06-05 17:51:10 +02:00
antifallobst e69065f889 feature (drivers API): implemented 'nx_drv_log' 2023-06-01 19:40:52 +02:00
antifallobst 2902215904 docs (readme): removed second roadmap header 2023-06-01 17:09:17 +02:00
antifallobst e85621ec55 docs (readme): updated and extended roadmap 2023-06-01 17:04:21 +02:00
antifallobst b50750653d fix (drivers): applied the fix for PCI to USB too 🤦 2023-06-01 13:52:42 +02:00
antifallobst 78ea65ec75 fix (drivers): pushing without testing was a bad idea ^^ 2023-06-01 13:50:51 +02:00
antifallobst 74aa1a4e4d feature (drivers): implemented driver registration and lookup 2023-06-01 13:12:34 +02:00
antifallobst a904629abd feature (drivers): implemented a function for API functions to determine the calling driver 2023-06-01 11:59:39 +02:00
antifallobst 263e7305cf feature (memory management): implemented a function to read the caller from the stack 2023-06-01 11:40:12 +02:00
antifallobst 7d33377806 feature (drivers): implemented an infrastructure to link drivers into the kernel 2023-06-01 00:10:15 +02:00
antifallobst 3d4cea2060 refactor (drivers): moved test driver to drivers repository 2023-06-01 00:03:36 +02:00
antifallobst bb19ff02e1 feature (ELF): defined structs to parse dynamic section 2023-05-31 00:16:25 +02:00
antifallobst 82af1f195b feature (drivers): started work on a driver handler / loader 2023-05-30 22:26:58 +02:00
antifallobst 7e53ab9e7c feature (drivers): setup a small driver to test stuff 2023-05-30 22:26:20 +02:00
antifallobst 0732a19f8a fix (VFS): fixed path resolving bug, that caused random strings to be resolved as part of the path 2023-05-30 20:47:44 +02:00
antifallobst 713ffbc089 feature (hashmaps): implemented hashmaps (NOT TESTED YET) 2023-05-29 16:23:03 +02:00
antifallobst cd5737dba7 feature (drivers): started work on a generic driver interface / driver manager 2023-05-29 14:40:37 +02:00
antifallobst 6ddd4587cf refactor (drivers): applied driver directory change to include statements 2023-05-28 21:06:06 +02:00
antifallobst 4227ea131a fix (build-system): fixed error with iso directory 2023-05-28 20:55:02 +02:00
Eric-Paul Ickhorn 2ccbf17625 refactor (drivers): Moved actual builtin drivers to a more sensible path 2023-05-28 20:40:21 +02:00
antifallobst f554c96469 docs: updated roadmap progress 2023-05-26 22:32:54 +00:00
antifallobst 007851c0ea feature (crypto): implemented SHA-1 2023-05-26 21:24:23 +02:00
antifallobst fc81e9f458 feature (sysconfig): connected sysconfig to 'noxos.json' 2023-05-26 16:49:00 +02:00
antifallobst 2ffbaa5322 feature (JSON parser): implemented AST 2023-05-26 14:53:34 +02:00
antifallobst a5233b7fe1 fix (boot config): removed JSON parser test values from noxos.json 2023-05-19 02:19:09 +02:00
antifallobst 3ec2729755 feature (JSON parser): implemented a tokenizer 2023-05-19 02:17:15 +02:00
antifallobst c60e8f9564 feature (utils): implemented function to check if a char is a special character 2023-05-19 01:50:55 +02:00
antifallobst abf22ba917 fix (heap): fixed bug that caused invalid addresses as result of memory allocations 2023-05-19 01:20:15 +02:00
antifallobst 9a35aa6648 feature (modules): started work on kernel modules 2023-05-17 00:18:25 +02:00
antifallobst 7f711d853e feature (drive manager): added device pointer to drive struct 2023-05-16 23:38:14 +02:00
antifallobst 0bed26ff26 feature (drive manager): implemented a manager for drives/storage media 2023-05-15 18:13:58 +02:00
antifallobst 7e5fee1437 feature (GPT): improved GPT decoding and GUID representation in code 2023-05-08 17:30:35 +02:00
antifallobst c9d57639c1 feature (GPT): implemented basic GPT decoding 2023-05-08 00:19:36 +02:00
antifallobst b8cafaf24d feature (MBR): implemented MBR 2023-05-07 23:14:43 +02:00
antifallobst 7d104a2745 feature (AHCI): implemented port reading 2023-05-07 14:13:07 +02:00
antifallobst 20112833d5 feature (AHCI): implemented port initialization 2023-05-07 12:38:59 +02:00
antifallobst caacc16f35 feature (processes): implemented signals and the 'nx_psignal' syscall 2023-05-07 01:16:33 +02:00
antifallobst c0e1b688a4 feature (syscalls): implemented 'nx_pcreate' 2023-05-07 00:34:20 +02:00
antifallobst 12ff4ec3dd feature (status): added a few more error status codes 2023-05-07 00:33:10 +02:00
antifallobst c02fdd7249 fix (processes): changed process spawning to copy the null terminator at the end of the name 2023-05-07 00:31:46 +02:00
antifallobst 8edd425fee refactor (build-system): added libnx and shell to build pipeline 2023-05-06 16:33:53 +02:00
antifallobst 091220ac71 feature (AHCI): implemented ahci controllers and ahci controller device enumeration 2023-05-04 13:28:55 +02:00
antifallobst 62bbc52205 feature (renderer): implemented cursor moving ascii extension 2023-05-04 11:30:28 +02:00
antifallobst f2584f7754 refactor (PS/2 keyboard): removed debug logs when handling cursor keys 2023-05-03 22:49:18 +02:00
antifallobst be508dae9f feature (strings): implemented the noxos ascii extension 2023-05-03 22:46:15 +02:00
antifallobst fb66944b0e feature (PS/2): finished up initialization process 2023-05-03 22:01:08 +02:00
antifallobst c5cbf51e75 feature (shell): implemented basic interactions 2023-05-02 21:21:07 +02:00
antifallobst 0d36dac39b refactor (build-system): renamed cmake project 2023-05-02 21:19:56 +02:00
antifallobst 6709aa9de5 feature (threads): added default end point for thread execution 2023-05-02 21:19:23 +02:00
antifallobst 23af4ccdab feature (syscalls): changed 'nx_fread' and 'nx_fwrite' to match updated sysabi 2023-05-02 18:07:31 +02:00
antifallobst 406dc0ee9e feature (VFS): returning amount of written/read bytes 2023-05-02 18:01:53 +02:00
antifallobst ce905f1a36 feature (shell): starting shell on startup 2023-05-02 00:44:20 +02:00
antifallobst 1101b83939 refactor (syscalls): removed debug logs when writing to stdout 2023-05-02 00:44:01 +02:00
antifallobst 18a0fc3eb7 fix (scheduler): fixed PF when pausing the running thread 2023-05-02 00:43:01 +02:00
antifallobst d493ebc64f fix (stream): fixed bug that allowed reading nonexistent data 2023-05-02 00:42:09 +02:00
antifallobst 0c084d00c0 fix (renderer): fixed possible PF when printing \n 2023-05-02 00:40:40 +02:00
antifallobst ddc47b3ea3 feature (shell): started work on a basic shell 2023-05-02 00:39:54 +02:00
antifallobst 99cd492570 feature (TTY): implemented a cursor 2023-05-01 22:53:23 +02:00
antifallobst ee90b275b2 Merge branch 'master' of https://git.nerdcult.net/antifallobst/noxos 2023-05-01 01:14:42 +02:00
antifallobst 66e6b0d3f8 refacotr (TTY): removed not needed function tty_alloc 2023-05-01 01:14:14 +02:00
antifallobst 820d3ed14a docs (readme): updated roadmap 2023-04-30 17:27:09 +00:00
antifallobst 33713a805a feature (TTY): made tty easy linkable with process stdio/pipes 2023-04-30 17:25:53 +02:00
antifallobst 328d48e381 fix (scheduler): fixed bug that caused double execution of the threads first cpu time 2023-04-30 12:46:14 +02:00
antifallobst 2b8a39feac feature (PS/2): implemented a basic ps/2 keyboard driver and TTY 2023-04-30 12:07:54 +02:00
antifallobst aa5ca306ca fix (streams): fixed bug in max readable bytes calculation 2023-04-30 11:52:30 +02:00
antifallobst 1777ca2150 refacotr (ahci): moved ahci.h from src to inc ^^ 2023-04-28 19:00:43 +02:00
antifallobst 31fd385d41 feature (proc): implemented basic pipes and whole process pausing 2023-04-27 12:27:12 +02:00
antifallobst a6e11d7e4e feature (sysconfig): implemented basic system configuration 2023-04-27 00:18:05 +02:00
antifallobst c1ec695ff6 feature (logger): implemented debug log macro which logs file and line number of its call in adition to a given format string 2023-04-26 20:14:06 +02:00
antifallobst 6dc7e0a11e feature (AHCI): defined FIS stuff 2023-04-26 00:06:36 +02:00
antifallobst 62816ebcbd fix (ELF): commented elf status messages out 2023-04-25 23:14:17 +02:00
antifallobst 203a8c2049 feature (PCI): implemented a BASIC pci device manager 2023-04-25 23:03:03 +02:00
Eric-Paul Ickhorn f8b70e4469 feature (PCI): Added rest of subclass stringify data 2023-04-25 22:28:10 +02:00
antifallobst b3d06f829e feature (PCI): added subclass strings 2023-04-26 21:57:18 +02:00
antifallobst 8dd28a6bf6 feature (font): Ported Erics monocle font :) 2023-04-25 18:41:53 +02:00
antifallobst da46a78219 feature (PCI): implemented basic PCI enumerating 2023-04-25 17:13:09 +02:00
Eric-Paul Ickhorn a904ffaaad Starting from 0 2023-04-22 11:10:58 +02:00
Eric-Paul Ickhorn b1f71e0230 Can't seem to get this working. 2023-04-22 10:48:15 +02:00
Eric-Paul Ickhorn 389868e848 fix (pci): Solved compilation errors 2023-04-22 03:35:07 +02:00
Eric-Paul Ickhorn 457bf6aa60 feature (pci): Added PCI subclass enums 2023-04-22 03:28:42 +02:00
antifallobst cae02e598d feature (syscalls): implemented basic stdout printing 2023-04-21 13:45:58 +02:00
antifallobst 766110435a refactor (kernel): refactored the directory structure 2023-04-20 23:00:56 +02:00
antifallobst eaf189b545 feature (utils): implemented streams 2023-04-20 22:10:02 +02:00
antifallobst 2544dc2346 feature (syscalls): implemented syscalls (nx_mmap, nx_munmap) 2023-04-20 18:53:01 +02:00
antifallobst 1b7be49c34 feature (page maps): implemented a function to check if a page is mapped or not 2023-04-20 18:29:21 +02:00
antifallobst 18be33952f feature (file_descriptors): added a few more standard file descriptors 2023-04-20 16:47:05 +02:00
antifallobst e3d3faf8e0 feature (syscalls): implemented syscalls (nx_fdelete, nx_flist) 2023-04-20 16:26:20 +02:00
antifallobst 2fa608ac41 fix (VFS): added node destruct call on node deletion 2023-04-20 16:07:38 +02:00
antifallobst 2105446463 feature (VFS): implemented a general 'vfs_node_delete' 2023-04-20 15:30:19 +02:00
antifallobst 6d102f6520 feature (syscalls): implemented basic file syscalls (nx_fopen, nx_fclose, nx_fread, nx_fwrite) 2023-04-19 01:02:45 +02:00
antifallobst 88c46a8f38 fix (utils): fixed bug in memory_compare, that lead to not comparing the 64-bit stuff 2023-04-19 00:29:03 +02:00
antifallobst 45edbfb64e fix (proc): changed fd_array chunk size back to 32. I forgot this after testing. 2023-04-18 19:19:20 +02:00
antifallobst c14013efaa feature (proc): implemented file descriptors 2023-04-18 19:06:25 +02:00
antifallobst af95bd2ba1 refactor (syscalls): improved syscall handling infrastructure 2023-04-18 17:06:48 +02:00
antifallobst d9c3b4060b fix (build-system): fixed cmake build & source directory 2023-04-18 16:24:01 +02:00
Eric-Paul Ickhorn c1083f9c8a Added font as wanted in #12 2023-04-16 06:01:36 +02:00
antifallobst 7fe93891b0 feature (acpi): implemented FADT 2023-03-22 13:08:57 +01:00
antifallobst ed977586a5 feature (acpi): implemented acpi table lookup 2023-03-22 00:03:06 +01:00
antifallobst 148dfe5a62 docs: removed '.wiki' directory from git 2023-03-19 16:03:06 +01:00
antifallobst e9cd7c63b6 docs: removed '.wiki' directory 2023-03-19 15:52:19 +01:00
antifallobst a77b8b9b14 feature (acpi): implemented RSDP descriptor verification 2023-03-11 13:25:48 +01:00
antifallobst a6af38bb39 feature (string utils): replacing NULL reference strings in format with warning 2023-03-11 11:23:53 +01:00
antifallobst b89c2fba83 docs: documented basic ACPI implementation 2023-03-11 11:05:26 +01:00
antifallobst fedca7b7e4 fix (acpi): fixed oem_id field in RSDP_v1 struct 2023-03-11 11:04:47 +01:00
antifallobst 606e4b619c fix (scheduler): added chunk NULL reference check when resolving processes 2023-03-11 10:37:44 +01:00
antifallobst b5e2945165 feature (acpi): requesting RSDP from bootloader 2023-03-11 10:36:55 +01:00
antifallobst a4c1d17aac feature (build system): running in UEFI mode by default, bios mode stays accessible with the 'bios' argument 2023-03-10 12:58:02 +01:00
antifallobst 088efd4b56 feature (build system): added toolchain check to build.sh 2023-03-10 12:48:57 +01:00
antifallobst cebae95696 fix (init): fixed crash when emulating in uefi mode 2023-03-10 12:24:31 +01:00
antifallobst aa9dbb7b6d fix (paging): removed accidentally placed stuff 2023-03-10 12:14:35 +01:00
antifallobst ff71a366c3 license: removed unnecessary license comment blocks 2023-03-10 11:32:50 +01:00
antifallobst ed490817e2 fix (stack-tracing): added rip memory region check for process resolving 2023-03-10 02:30:22 +01:00
antifallobst 3d0aedeeca docs: documented fix of symbol name resolve bug when function is extern / assembly 2023-03-09 00:45:00 +01:00
antifallobst 6d60157da0 fix (stack-tracing): fixed symbol name resolve bug when function is extern / assembly 2023-03-09 00:43:15 +01:00
antifallobst 9b50ca77da feature (syscalls): implemented nx_panic syscall 2023-03-09 00:19:59 +01:00
antifallobst 70db6f961c Merge branch 'master' of https://git.antifallobst.tech/antifallobst/noxos 2023-03-09 00:10:46 +01:00
antifallobst b2733a3810 fix (stack-tracing): added NULL reference check for current process 2023-03-09 00:09:20 +01:00
194 changed files with 6800 additions and 5247 deletions

5
.gitignore vendored
View File

@ -1,4 +1,5 @@
build
cmake-build-debug
.idea
noxos.log
noxos.log
ramdisk/shell.elf
*.nxkm

View File

@ -1,45 +0,0 @@
# Build instructions
**DISCLAIMER: To build this project you need a linux system (WSL could work for windows users, but I haven't tested it)**
First you need to clone the repository:
`git clone https://codeberg.org/antifallobst/noxos/`
then there are a few tools required, that need to be installed:
* **gcc** - compiler
* **ld** - linker
* **nasm** - assembler
* **cmake** - build system
* **xorriso** - ISO creation tools
* **qemu** - emulator
There is a shell script to setup the workspace and compile.
Just run it using the following commands:
```bash
cd noxos
./build.sh
```
If the Bootloader (Limine ([github](https://github.com/limine-bootloader/limine))) isn't downloaded yet, the script will download it.
The final ISO file will be written to the *build* directory.
To launch the ISO, run the `run.sh` script.
# UEFI Emulation
To emulate an UEFI system, you need to install the `ovmf` package.
Then you can do `./run.sh uefi` to start qemu with uefi instead of bios.
# Debugging
## Logs
When running through the script, qemu is configured to write the kernels logs to *STDOUT* and a file called *noxos.log*.
## GDB
You can connect GDB to qemu.
To achieve this, run `./run.sh debug`.
QEMU will wait until you connect GDB to it as a 'remote' target on `localhost:1234`.
```bash
gdb build/cmake/kernel/kernel
target remote localhost:1234
c
```
(note, that the last to commands have to be 'executed' in gdb not in your shell)

View File

@ -1,61 +0,0 @@
# Code Style
## Naming conventions
- **structs** are suffixed with **_T**
- **typedefs** are suffixed with **_t**
- **enums** are suffixed with **_E**
- **global** variables are prefixed with **g_**
Everything is **snake_case**.
## Code readability
To make the code as readable and self explaining as possible, there are a few patterns that should be used.
### Avoid abbreviations
Give your variables, functions, etc. meaningfull names.
The times of 80char wide screens are over, feel free to use that space :D
Example: `sym_at_idx` -> `get_symbol_at_index`
But you're not forced to (anything) write out everything.
For example the **Interrupt Descriptor Table** is simply referred to as **idt** (this abbreviation is btw standard).
### Avoid indentation nesting
In a perfect codebase, the maximum indention level would be 3.
The goal of NoxOS is not to be a perfect codebase, but please avoid huge indention nesting.
To achieve this, you can break parts into extra functions and/or use the early return pattern.
Example:
```c
bool likes_pigs (void* a) {
if (a != NULL) {
if (a == 0xACAB) {
return false;
}
}
return true;
}
```
->
```c
bool likes_pigs (void* a) {
if (a != NULL) { return true; }
if (a != 0xACAB) { return true; }
return false;
}
```
### align declarations
Please align declarations, definitions, etc like in the example:
```c
char am_i_a_variable = '?';
uint64_t number = 0;
bool i_waste_bits = true;
```
### namespaces
Unlike C++ C has no namespaces.
To achieve the goal of namespaces, please prefix your functions, structs, etc. with the "namespace" they are in.
Example: `out_byte` -> `io_out_byte`

View File

@ -1,47 +0,0 @@
Welcome :D
Nice, that you're interested in contributing.
There are several ways to contribute to NoxOS:
- Write code
- Maintain Documentation
- Typos
- Grammar
- Is the documentation up to date?
- Plan stuff (e.g. syscalls)
- open Issues
# Before Contribution
Please read the [Code-Style wiki entry](https://codeberg.org/antifallobst/noxos/wiki/Code-Style) before you start to contribute.
For workspace setup and build instructions look at [this wiki entry](https://codeberg.org/antifallobst/noxos/wiki/Build-instructions).
**We don't accept any Assholes! If you're a fascist, racist, or discriminate others for anything, go fuck yourself.**
# Contributing
When you contribute code, please [document](https://codeberg.org/antifallobst/noxos/wiki/Kernel-documentation) it.
You don't have to (and you also shouldn't) write romans, but a few lines for every in a header exposed function, struct etc. help others (and yourself) understanding how to interact with your code.
## What dafuq is ...?
OS development can be quite complicated/confusing. That's Ok.
Stuff like Paging can be really weird, if you don't have osdev experience.
But there are learning resources and places, where you can ask questions.
**A small overview about such resources and places:**
- The [osdev wiki](https://wiki.osdev.org) is like wikipedia - just for hobby os developers.
- The [osdev subreddit](https://reddit.com/r/osdev) is a great place to ask questions and share knowledge
- Intel's [developer manual](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html) is a more advanced but kinda precise information source
Also feel free to join the [NoxOS Matrix space](https://matrix.to/#/#noxos:systemausfall.org),
where you can chat with other NoxOS devs and ask questions.
**But Stay Respectful, Or We `sudo rm -rf /` Your PC ;)**
# Where to start?
Get the codebase and play a bit around with it.
Try to understand basic concepts of the codebase, the [documentation](https://codeberg.org/antifallobst/noxos/wiki/Kernel-documentation) will help you.
After that you can search the [Issues](https://codeberg.org/antifallobst/noxos/issues) for the `Good First Issue` label,
to find easy improvements, etc. that you can try to implement.
Another option is to ask in the [Matrix Space](https://matrix.to/#/#noxos:systemausfall.org).

View File

@ -1,11 +0,0 @@
**DISCLAIMER: We don't accept any Assholes! If you're a fascist, racist, or discriminate others for anything, go fuck yourself.** If not, welcome :)
The wiki on codeberg is probably less frequently updated, than the `.wiki` directory in the codebase.
Wiki Content:
* [Contribution guide](https://codeberg.org/antifallobst/noxos/wiki/Contribution-guide)
* [Build instructions](https://codeberg.org/antifallobst/noxos/wiki/Build-instructions)
* [Code Style](https://codeberg.org/antifallobst/noxos/wiki/Code-Style)
* [Kernel Documentation](https://codeberg.org/antifallobst/noxos/wiki/Kernel-documentation)
* [Project Roadmap](https://codeberg.org/antifallobst/noxos/wiki/Roadmap)

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +0,0 @@
# Roadmap
- [x] Bootable system
- [x] Logger
- [X] Page frame manager
- [X] Interrupts
- [X] Page maps
- [X] Heap
- [X] Format strings
- [X] Graphics Renderer
- [X] Text
- [X] Double buffering
- [X] Buffer requests
- [X] Panic Screen
- [X] Register dump
- [X] Stack tracing
- [X] Scheduler
- [X] (Kernel) Threads
- [X] Ramdisk
- [X] USTAR
- [X] RAMFS
- [X] VFS
- [X] ELF loading
- [X] Processes
- [ ] Keyboard input (ps/2 int)
- [ ] Shell
- [ ] JSON parser for system config
- [ ] FAT32
- [ ] Text Editor
- [ ] TCC

View File

@ -1,4 +1,25 @@
cmake_minimum_required(VERSION 3.00)
project(NoxOS)
add_subdirectory(kernel)
project(kernel)
set(C 99)
set(CMAKE_NASM_COMPILE_OBJECT "nasm <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
add_executable(kernel)
add_library (kernel_asm OBJECT)
target_include_directories(kernel PRIVATE inc)
file(GLOB_RECURSE kernel_src_c "src/**/*.c")
file(GLOB_RECURSE kernel_inc "inc/**/*.h")
file(GLOB_RECURSE kernel_src_asm "src/**/*.asm")
target_compile_options(kernel PRIVATE -g -fno-stack-protector -fno-stack-check -mno-red-zone -ffreestanding -m64 -march=x86-64 -mabi=sysv)
target_link_options(kernel PRIVATE -nostdlib -static -T "${CMAKE_CURRENT_LIST_DIR}/kernel.ld")
enable_language(ASM_NASM)
set(CAN_USE_ASSEMBLER TRUE)
target_sources(kernel_asm PRIVATE ${kernel_src_asm})
target_sources(kernel PRIVATE ${kernel_src_c} ${kernel_inc} $<TARGET_OBJECTS:kernel_asm>)

View File

@ -1,4 +1,4 @@
Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
Copyright 2023 the noxos team <antifallobst@systemausfall.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in

View File

@ -3,39 +3,53 @@
NoxOS is a small x86 operating system (currently just a kernel).
The kernel is booted using the limine boot protocol and is fully documented.
## Roadmap
# Roadmap
- [x] Bootable system
- [x] Logger
- [X] Page frame manager
- [X] Interrupts
- [X] Page maps
- [X] Heap
- [X] Format strings
- [X] Graphics Renderer
- [X] Text
- [X] Double buffering
- [X] Buffer requests
- [X] Panic Screen
- [X] Register dump
- [X] Stack tracing
- [X] Scheduler
- [X] (Kernel) Threads
- [X] Ramdisk
- [X] USTAR
- [X] RAMFS
- [X] VFS
- [X] ELF loading
- [X] Processes
- [ ] Keyboard input (ps/2 int)
- [x] Page frame manager
- [x] Interrupts
- [x] Page maps
- [x] Heap
- [x] Format strings
- [x] Graphics Renderer
- [x] Text
- [x] Double buffering
- [x] Buffer requests
- [x] Panic Screen
- [x] Register dump
- [x] Stack tracing
- [x] Scheduler
- [x] Threads
- [x] Processes
- [x] Ramdisk
- [x] USTAR
- [x] RAMFS
- [x] VFS
- [x] ELF loading
- [x] Keyboard input (ps/2 int)
- [x] JSON parser for system config
- [ ] Drivers
- [X] Loading / Linking into kernel
- [X] Driver Device assignment (PCI / USB / FS)
- [ ] API
- [ ] Syscalls
- [x] Filesystem
- [x] Memory
- [ ] Processing
- [x] Drivers
- [X] Kernel
- [ ] FAT32 (driver)
- [ ] TUI framework
- [ ] Shell
- [ ] JSON parser for system config
- [ ] FAT32
- [ ] Text Editor
- [ ] TCC
- [ ] Tetris
- [ ] Init System
## Contribution Welcome :D
Install instructions, Code Documentation and a Contribution guide can be found in the [wiki](https://codeberg.org/antifallobst/noxos/wiki/).
Install instructions, Code Documentation and a Contribution guide can be found [here](https://git.nerdcult.net/noxos/documentation).
## Copyright / License (MIT)
Copyright 2023 Antifallobst <antifallobst@systemausfall.org>

BIN
assets/monocle_8x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

100
build.sh
View File

@ -1,25 +1,6 @@
#!/usr/bin/bash
# Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the “Software”), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# This file is part of noxos and licensed under the MIT open source license
set -e
@ -30,16 +11,61 @@ workspace_setup() {
echo ""
}
check_toolchain() {
echo " --> Checking Toolchain"
hash gcc
echo " |--> found gcc"
hash ld
echo " |--> found ld"
hash nasm
echo " |--> found nasm"
hash cmake
echo " |--> found cmake"
hash xorriso
echo " |--> found xorriso"
hash qemu-system-x86_64
echo " |--> found qemu"
[ ! -d "/usr/share/ovmf/x64/" ] && echo "OVMF binaries not found!" && exit 255
echo " |--> found ovmf"
echo " --> All checks passed"
}
kernel_build() {
echo " --> Building kernel"
cd build/cmake
cmake ../..
cmake -S ../.. -B .
make
cd ../..
echo ""
}
libnx_build() {
cd ../libraries/libnx
bash build.sh
cd ../../kernel
}
libnxdrv_build() {
cd ../libraries/libnxdrv
bash build.sh
cd ../../kernel
cd ../drivers/test
bash build.sh
cd ../../kernel
mkdir -pv ramdisk/drv/
cp ../drivers/build/test.nxkm ramdisk/drv/test.nxkm
}
shell_build() {
echo " --> Building shell"
# gcc shell.c -o ramdisk/shell.elf -nostdlib -nolibc -fno-stack-protector -I../libraries/libnx/inc/public ../libraries/libnx/build/cmake/libnx.so
}
limine_install() {
echo " --> Installing Limine"
@ -65,12 +91,12 @@ generate_image() {
rm -rfv iso
mkdir -pv iso
cp limine/limine-cd.bin iso
cp limine/limine-cd-efi.bin iso
cp limine/limine.sys iso
cp ../limine.cfg iso
cp initrd.tar iso
cp cmake/kernel/kernel iso/kernel.elf
cp limine/limine-cd.bin iso/
cp limine/limine-cd-efi.bin iso/
cp limine/limine.sys iso/
cp ../limine.cfg iso/
cp initrd.tar iso/
cp cmake/kernel iso/kernel.elf
xorriso -as mkisofs -b limine-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
@ -88,11 +114,21 @@ generate_image() {
echo "!=====[ NoxOS build script ]=====!"
workspace_setup
kernel_build
[ ! -d "build/limine" ] && limine_install
generate_initial_ramdisk
generate_image
case $1 in
"check")
check_toolchain
;;
*)
workspace_setup
kernel_build
[ ! -d "build/limine" ] && limine_install
libnx_build
libnxdrv_build
shell_build
generate_initial_ramdisk
generate_image
;;
esac
echo "!=====[ Finished ]=====!"

18
inc/boot/boot_info.h Normal file
View File

@ -0,0 +1,18 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_BOOT_INFO_H
#define NOX_BOOT_INFO_H
#include "utils/stdtypes.h"
#include "limine.h"
typedef struct {
struct limine_framebuffer_response* framebuffer;
struct limine_terminal_response* terminal;
struct limine_memmap_response* memory_map;
struct limine_file* kernel_file;
struct limine_file* ramdisk_file;
void* rsdp;
} boot_info_T;
#endif //NOX_BOOT_INFO_H

17
inc/boot/config.h Normal file
View File

@ -0,0 +1,17 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_CONFIG_H
#define NOXOS_CONFIG_H
#include "utils/stdtypes.h"
typedef struct {
bool ps2_acpi_validation;
bool log_graphical;
} sysconfig_T;
void sysconfig_init();
extern sysconfig_T* g_sysconfig;
#endif //NOXOS_CONFIG_H

View File

@ -0,0 +1,32 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_ACPI_H
#define NOX_ACPI_H
#include "boot/boot_info.h"
#include "utils/string.h"
typedef struct {
char signature [4];
uint32_t length;
uint8_t revision;
uint8_t checksum;
char oem_id [6];
char oem_table_id [8];
uint32_t oem_revision;
uint32_t creator_id;
uint32_t creator_revision;
} __attribute__((packed)) acpi_sdt_header_T;
typedef struct {
uint8_t address_space;
uint8_t bit_width;
uint8_t bit_offset;
uint8_t access_size;
uint64_t address;
} __attribute__((packed)) acpi_gas_T;
void acpi_init (boot_info_T* boot_info);
acpi_sdt_header_T* acpi_find_table (acpi_sdt_header_T* xsdt, string_t table_id);
#endif //NOX_ACPI_H

View File

@ -0,0 +1,68 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_FADT_H
#define NOX_FADT_H
#include "drivers/builtin/acpi/acpi.h"
typedef struct {
acpi_sdt_header_T header;
uint32_t firmware_control;
uint32_t dsdt;
uint8_t reserved;
uint8_t preferred_power_management_profile;
uint16_t sci_interrupt;
uint32_t smi_command_port;
uint8_t apci_enable;
uint8_t apci_disable;
uint8_t s4_bios_request;
uint8_t pstate_control;
uint32_t pm1a_event_block;
uint32_t pm1b_event_block;
uint32_t pm1a_control_block;
uint32_t pm1b_control_block;
uint32_t pm2_control_block;
uint32_t pm_timer_block;
uint32_t gpe0_block;
uint32_t gpe1_block;
uint8_t pm1_event_length;
uint8_t pm1_control_length;
uint8_t pm2_control_length;
uint8_t pm_timer_length;
uint8_t gpe0_length;
uint8_t gpe1_length;
uint8_t gpe1_base;
uint8_t c_state_control;
uint16_t c2_worst_latency;
uint16_t c3_worst_latency;
uint16_t flush_size;
uint16_t flush_stride;
uint8_t duty_offset;
uint8_t duty_width;
uint8_t day_alarm;
uint8_t month_alarm;
uint8_t century;
uint16_t ia_boot_architecture_flags;
uint8_t reserved_2;
uint32_t flags;
acpi_gas_T reset_register;
uint8_t reset_value;
uint8_t reserved_3[3];
uint64_t x_firmware_control;
uint64_t x_dsdt;
acpi_gas_T x_pm1a_event_block;
acpi_gas_T x_pm1b_event_block;
acpi_gas_T x_pm1a_control_block;
acpi_gas_T x_pm1b_control_block;
acpi_gas_T x_pm2_control_block;
acpi_gas_T x_pm_timer_block;
acpi_gas_T x_gpe0_block;
acpi_gas_T x_gpe1_block;
acpi_gas_T sleep_control_register;
acpi_gas_T sleep_status_register;
uint64_t hypervisor_vendor_identity;
} __attribute__((packed)) acpi_fadt_T;
extern acpi_fadt_T* g_acpi_table_fadt;
#endif //NOX_FADT_H

View File

@ -0,0 +1,23 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_MCFG_H
#define NOXOS_MCFG_H
#include "drivers/builtin/acpi/acpi.h"
typedef struct {
acpi_sdt_header_T header;
uint64_t reserved;
} __attribute__((packed)) acpi_mcfg_T;
typedef struct {
uint64_t base;
uint16_t pci_segment_group;
uint8_t pci_start_bus;
uint8_t pci_end_bus;
uint32_t reserved;
} __attribute__((packed)) acpi_mcfg_device_config_T;
extern acpi_mcfg_T* g_acpi_table_mcfg;
#endif //NOXOS_MCFG_H

View File

@ -0,0 +1,27 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_RSDP_H
#define NOX_RSDP_H
#include "utils/stdtypes.h"
typedef struct {
char signature [8];
uint8_t checksum;
char oem_id [6];
uint8_t revision;
uint32_t rsdt_address;
} __attribute__((packed)) rsdp_descriptor_v1_T;
typedef struct {
rsdp_descriptor_v1_T descriptor_v1;
uint32_t length;
uint64_t xsdt_address;
uint8_t checksum_extended;
uint8_t reserved [3];
} __attribute__((packed)) rsdp_descriptor_v2_T;
bool rsdp_descriptor_v1_verify(rsdp_descriptor_v1_T* descriptor);
bool rsdp_descriptor_v2_verify(rsdp_descriptor_v2_T* descriptor);
#endif //NOX_RSDP_H

250
inc/drivers/builtin/ahci.h Normal file
View File

@ -0,0 +1,250 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_AHCI_H
#define NOXOS_AHCI_H
#include "utils/stdtypes.h"
#include "drivers/builtin/pci.h"
#include "drivers/builtin/drive_manager.h"
#define SATA_SIG_ATA 0x00000101
#define SATA_SIG_ATAPI 0xEB140101
#define SATA_SIG_SEMB 0xC33C0101
#define SATA_SIG_PORT_MULTIPLIER 0x96690101
#define ATA_DEVICE_BUSY 0x80
#define ATA_DEVICE_DRQ 0x08
#define ATA_CMD_READ_DMA_EX 0x25
#define ATA_CMD_WRITE_DMA_EX 0x35
#define HBA_PX_IS_TFES (1 << 30)
#define HBA_PX_COMMAND_CMD_LIST_RUNNING 0x8000
#define HBA_PX_COMMAND_START 0x0001
#define HBA_PX_COMMAND_FIS_RECV_ENABLE 0x0010
#define HBA_PX_COMMAND_FIS_RECV_RUNNING 0x4000
#define HBA_PORT_DEVICE_PRESENT 0x03
#define HBA_PORT_IPM_ACTIVE 0x01
typedef enum {
AHCI_DEVICE_NONE,
AHCI_DEVICE_SATA,
AHCI_DEVICE_SEMB,
AHCI_DEVICE_PORT_MULTIPLIER,
AHCI_DEVICE_SATAPI,
AHCI_DEVICE_TYPE_END_OF_ENUM
} ahci_device_type_E;
typedef enum {
AHCI_FIS_REGISTER_HOST_TO_DEVICE = 0x27, // host --> device
AHCI_FIS_REGISTER_DEVICE_TO_HOST = 0x34, // host <-- device
AHCI_FIS_DMA_ACTIVATE = 0x39, // host <-- device
AHCI_FIS_DMA_SETUP = 0x41, // host <--> device
AHCI_FIS_DATA = 0x46, // host <--> device
AHCI_FIS_BIST = 0x58, // host <--> device
AHCI_FIS_PIO_SETUP = 0x5F, // host <-- device
AHCI_FIS_DEVICE_BITS = 0xA1 // host <-- device
} ahci_fis_type_E;
typedef struct {
uint8_t type;
uint8_t port_multiplier:4;
uint8_t reserved_0:3;
uint8_t command_control_select:1;
uint8_t command;
uint8_t feature_0;
uint8_t lba_0;
uint8_t lba_1;
uint8_t lba_2;
uint8_t device;
uint8_t lba_3;
uint8_t lba_4;
uint8_t lba_5;
uint8_t feature_1;
uint8_t count_low;
uint8_t count_high;
uint8_t icc;
uint8_t control;
uint32_t reserved_1;
} ahci_fis_register_host_to_device_T;
typedef struct {
uint8_t type;
uint8_t port_multiplier:4;
uint8_t reserved_0:2;
uint8_t interrupt:1;
uint8_t reserved_1:1;
uint8_t status;
uint8_t error;
uint8_t lba_0;
uint8_t lba_1;
uint8_t lba_2;
uint8_t device;
uint8_t lba_3;
uint8_t lba_4;
uint8_t lba_5;
uint8_t reserved_2;
uint16_t count;
uint16_t reserved_3;
uint32_t reserved_4;
} ahci_fis_register_device_to_host_T;
typedef struct {
uint8_t type;
uint8_t port_multiplier:4;
uint8_t reserved_0:4;
uint16_t reserved_1;
uint32_t data; // this can be followed by more data
} ahci_fis_data_T;
typedef struct {
uint8_t type;
uint8_t port_multiplier:4;
uint8_t reserved_0:1;
uint8_t transfer_direction:1;
uint8_t interrupt:1;
uint8_t reserved_1:1;
uint8_t status;
uint8_t error;
uint8_t lba_0;
uint8_t lba_1;
uint8_t lba_2;
uint8_t device;
uint8_t lba_3;
uint8_t lba_4;
uint8_t lba_5;
uint8_t reserved_2;
uint16_t count;
uint8_t reserved_3;
uint8_t new_status;
uint16_t transfer_count;
uint16_t reserved_4;
} ahci_fis_pio_setup_T;
typedef struct {
uint8_t type;
uint8_t port_multiplier:4;
uint8_t reserved_0:1;
uint8_t transfer_direction:1;
uint8_t interrupt:1;
uint8_t auto_activate:1;
uint16_t reserved_1;
uint64_t dma_buffer_id;
uint32_t reserved_2;
uint32_t dma_buffer_offset;
uint32_t transfer_count;
uint32_t reserved_3;
} ahci_fis_dma_setup_T;
typedef struct {
uint32_t command_list_base;
uint32_t command_list_base_upper;
uint32_t fis_base_address;
uint32_t fis_base_address_upper;
uint32_t interrupt_status;
uint32_t interrupt_enable;
uint32_t command_status;
uint32_t reserved_0;
uint32_t task_file_data;
uint32_t signature;
uint32_t sata_status;
uint32_t sata_control;
uint32_t sata_error;
uint32_t sata_active;
uint32_t command_issue;
uint32_t sata_notification;
uint32_t fis_switch_control;
uint32_t reserved_1 [11];
uint32_t vendor [4];
} ahci_hba_port_T;
typedef struct {
uint32_t host_capability;
uint32_t global_host_control;
uint32_t interrupt_status;
uint32_t ports_implemented;
uint32_t version;
uint32_t ccc_control;
uint32_t ccc_ports;
uint32_t enclosure_management_location;
uint32_t enclosure_management_control;
uint32_t host_capabilities_extended;
uint32_t bios_handoff_control_status;
uint8_t reserved_0 [0x74];
uint8_t vendor [0x60];
ahci_hba_port_T ports [1];
} ahci_hba_memory_T;
typedef struct {
uint8_t command_fis_length:5;
uint8_t atapi:1;
uint8_t write:1;
uint8_t prefetchable:1;
uint8_t reset:1;
uint8_t bist:1;
uint8_t clear_busy:1;
uint8_t reserved_0:1;
uint8_t port_multiplier:4;
uint16_t prdt_length;
uint32_t prdb_count;
uint32_t command_table_base_address;
uint32_t command_table_base_address_upper;
uint32_t reserved_1 [4];
} ahci_hba_command_T;
typedef struct {
uint32_t data_base_address;
uint32_t data_base_address_upper;
uint32_t reserved_0;
uint32_t byte_count:22;
uint32_t reserved_1:9;
uint32_t interrupt_on_completion:1;
} ahci_hba_prdt_entry_T;
typedef struct{
uint8_t command_fis [64];
uint8_t atapi_command [16];
uint8_t reserved [48];
ahci_hba_prdt_entry_T prdt_entry [];
} ahci_hba_command_table_T;
typedef struct ahci_controller_T ahci_controller_T;
typedef struct {
ahci_hba_port_T* hba_port;
ahci_device_type_E type;
ahci_controller_T* controller;
uint8_t id;
drive_T* drive;
void* cmd_list_base;
void* fis_base;
void* command_tables [32];
} ahci_port_T;
struct ahci_controller_T {
ahci_port_T ports [32];
int num_ports;
pci_device_T* pci_device;
ahci_hba_memory_T* abar;
};
ahci_controller_T* ahci_controller_alloc (pci_device_T* pci_device);
void ahci_controller_destruct (ahci_controller_T* controller);
void ahci_port_init (ahci_port_T* port);
void ahci_port_init_partitions_mbr (ahci_port_T* port);
void ahci_port_init_partitions_gpt (ahci_port_T* port);
void ahci_port_destruct (ahci_port_T* port);
ahci_device_type_E ahci_port_get_type (ahci_hba_port_T* port);
void ahci_port_command_stop (ahci_port_T* port);
void ahci_port_command_start (ahci_port_T* port);
bool ahci_port_read (ahci_port_T* port, uint64_t sector, uint32_t num_sectors, void* buffer_out);
bool ahci_port_write (ahci_port_T* port, uint64_t sector, uint32_t num_sectors, void* buffer_in);
extern string_t g_ahci_device_type_strings[AHCI_DEVICE_TYPE_END_OF_ENUM];
#endif //NOXOS_AHCI_H

View File

@ -0,0 +1,72 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_DRIVE_MANAGER_H
#define NOXOS_DRIVE_MANAGER_H
#include "drivers/builtin/fs/vfs.h"
#include "utils/stdtypes.h"
#include "utils/bitmap.h"
#define DRIVE_CHUNK_SIZE 16
#define DRIVE_PARTITION_CHUNK_SIZE 16
typedef enum {
DRIVE_CONTROLLER_AHCI
} drive_controller_types_E;
typedef struct drive_chunk_T drive_chunk_T;
typedef struct drive_partition_chunk_T drive_partition_chunk_T;
typedef struct drive_partition_T drive_partition_T;
typedef struct drive_T drive_T;
struct drive_partition_T{
drive_partition_chunk_T* chunk;
uint32_t id_in_chunk;
uint32_t id;
drive_T* drive;
fs_T filesystem;
uint32_t start_sector;
uint32_t end_sector;
};
struct drive_T {
drive_chunk_T* chunk;
uint32_t id_in_chunk;
uint32_t id;
drive_partition_chunk_T* partitions_chunks;
drive_controller_types_E controller_type;
void* controller;
void* device;
};
struct drive_chunk_T {
drive_T drives [DRIVE_CHUNK_SIZE];
bitmap_T drives_bitmap;
uint32_t num_drives;
drive_chunk_T* prev;
drive_chunk_T* next;
};
struct drive_partition_chunk_T {
drive_partition_T partitions [DRIVE_PARTITION_CHUNK_SIZE];
bitmap_T partitions_bitmap;
uint32_t num_partitions;
drive_partition_chunk_T* prev;
drive_partition_chunk_T* next;
};
typedef struct {
drive_chunk_T* chunks;
} drive_manager_T;
drive_chunk_T* drive_chunk_alloc (drive_chunk_T* prev);
drive_partition_chunk_T* drive_partition_chunk_alloc (drive_partition_chunk_T* prev);
void drive_partition_chunk_destruct (drive_partition_chunk_T* chunk);
void drive_manager_init ();
drive_T* drive_manager_add_drive (drive_controller_types_E controller_type, void* controller, void* device);
void drive_manager_remove_drive (drive_T* drive);
drive_partition_T* drive_manager_add_partition (drive_T* drive, uint32_t start_sector, uint32_t end_sector);
void drive_manager_remove_partition (drive_partition_T* partition);
#endif //NOXOS_DRIVE_MANAGER_H

View File

@ -0,0 +1,23 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_DYNAMIC_H
#define NOXOS_DYNAMIC_H
#include <utils/stdtypes.h>
typedef enum {
ELF_DYNAMIC_TAG_NULL,
ELF_DYNAMIC_TAG_NEEDED,
ELF_DYNAMIC_TAG_PLT_REL_SIZE,
ELF_DYNAMIC_TAG_HASH,
ELF_DYNAMIC_TAG_STRTAB,
ELF_DYNAMIC_TAG_RELA,
ELF_DYNAMIC_TAG_RELA_SIZE
} elf_dynamic_tag_E;
typedef struct {
uint32_t tag;
uint64_t value;
} elf_dynamic_T;
#endif //NOXOS_DYNAMIC_H

View File

@ -0,0 +1,30 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_ELF_H
#define NOX_ELF_H
#include "drivers/builtin/elf/header.h"
#include "drivers/builtin/elf/section.h"
#include "drivers/builtin/elf/mapping.h"
#include "utils/symbol.h"
typedef struct {
elf_header_T header;
symbol_table_T symbol_table;
uint64_t num_mappings;
elf_mapping_T* mappings;
void* string_table;
} elf_executable_T;
typedef struct {
elf_executable_T* executable;
elf_section_T* symbol_table;
elf_section_T* section_header_string_table;
uint8_t* buffer;
} elf_executable_temp_T;
elf_executable_T* elf_executable_create (uint8_t* buffer);
void elf_executable_destruct (elf_executable_T* executable);
#endif //NOX_ELF_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_ELF_HEADER_H
#define NOX_ELF_HEADER_H

View File

@ -0,0 +1,18 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_MAPPING_H
#define NOX_MAPPING_H
#include "utils/stdtypes.h"
#include "mm/page_map.h"
typedef struct {
uint64_t offset_file;
uint64_t offset_virtual;
uint64_t length_file;
uint64_t length_virtual;
} elf_mapping_T;
void elf_mappings_apply(elf_mapping_T* mappings, uint64_t num_mappings, uint8_t* buffer, void* base, page_map_T* page_map);
#endif //NOX_MAPPING_H

View File

@ -0,0 +1,37 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_RELOCATION_H
#define NOXOS_RELOCATION_H
#include <utils/stdtypes.h>
#include <drivers/builtin/elf/elf.h>
#define ELF_RELOCATION_SYMBOL(i) ((i) >> 32)
#define ELF_RELOCATION_TYPE(i) ((i) & 0xFFFFFFFFL)
#define ELF_RELOCATION_INFO(s,t) (((s) << 32) + ((t) & 0xFFFFFFFFL))
#define ELF_RELOCATION_X86_64_PC32(s,a,p) (s + a - p)
#define ELF_RELOCATION_X86_64_PLT32(l,a,p) (l + a - p)
typedef enum {
ELF_REL_NONE,
ELF_REL_64,
ELF_REL_PC32,
ELF_REL_GOT32,
ELF_REL_PLT32,
ELF_REL_COPY,
ELF_REL_GLOB_DAT,
ELF_REL_JUMP_SLOT,
ELF_REL_RELATIVE
} elf_relocation_type_E;
typedef struct {
uint64_t offset;
uint64_t info;
int64_t addend;
} elf_relocation_a_T;
//void elf_relocate (elf_executable_T* executable, uint8_t* buffer, void* address);
bool elf_relocate_driver(elf_executable_T* executable, uint8_t* buffer, void* load_address);
#endif //NOXOS_RELOCATION_H

View File

@ -0,0 +1,41 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SECTION_H
#define NOX_SECTION_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
ELF_SECTION_NULL,
ELF_SECTION_PROGRAM_DATA,
ELF_SECTION_SYMBOL_TABLE,
ELF_SECTION_STRING_TABLE,
ELF_SECTION_RELOCATION_A,
ELF_SECTION_HASH,
ELF_SECTION_DYNAMIC,
ELF_SECTION_NOTE,
ELF_SECTION_NOBITS,
ELF_SECTION_REL,
ELF_SECTION_SHLIB,
ELF_SECTION_DYNAMIC_SYMBOL_TABLE,
ELF_SECTION_ENUM_END
} elf_section_type_E;
typedef struct {
uint32_t name_offset;
uint32_t type;
uint64_t flags;
uint64_t virtual_address;
uint64_t offset;
uint64_t length;
uint32_t link;
uint32_t info;
uint64_t alignment;
uint64_t entry_size;
} elf_section_T;
extern string_t g_elf_section_type_strings[ELF_SECTION_ENUM_END+1];
#endif //NOX_SECTION_H

View File

@ -0,0 +1,34 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SEGMENT_H
#define NOX_SEGMENT_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
ELF_SEGMENT_NULL,
ELF_SEGMENT_LOAD,
ELF_SEGMENT_DYNAMIC,
ELF_SEGMENT_INTERPRETER,
ELF_SEGMENT_NOTE,
ELF_SEGMENT_PROGRAM_HEADER_TABLE,
ELF_SEGMENT_TLS,
ELF_SEGMENT_ENUM_END
} elf_segment_type_E;
typedef struct {
uint32_t type;
uint32_t flags;
uint64_t offset;
uint64_t address_virtual;
uint64_t address_physical;
uint64_t length_file;
uint64_t length_memory;
uint64_t align;
} elf_segment_T;
extern string_t g_elf_segment_type_strings[ELF_SEGMENT_ENUM_END+1];
#endif //NOX_SEGMENT_H

View File

@ -0,0 +1,32 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_ELF_SYMBOL_H
#define NOX_ELF_SYMBOL_H
#include "utils/stdtypes.h"
#include "utils/string.h"
#define ELF_SYMBOL_TYPE(info) ((info) & 0xF)
extern string_t g_elf_symbol_type_strings[7];
typedef enum {
ELF_SYMBOL_NONE,
ELF_SYMBOL_OBJECT,
ELF_SYMBOL_FUNC,
ELF_SYMBOL_SECTION,
ELF_SYMBOL_FILE,
ELF_SYMBOL_COMMON,
ELF_SYMBOL_TLS
} elf_symbol_type_E;
typedef struct {
uint32_t name_offset;
uint8_t info;
uint8_t other;
uint16_t related_section_index;
uint64_t value;
uint64_t length;
} elf_symbol_T;
#endif //NOX_ELF_SYMBOL_H

View File

@ -0,0 +1,50 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_GPT_H
#define NOXOS_GPT_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
GPT_PARTITION_GUID_UNUSED,
GPT_PARTITION_GUID_UNKNOWN,
GPT_PARTITION_GUID_PRIMARY,
GPT_PARTITION_GUID_EFI_SYSTEM,
GPT_PARTITION_GUID_ENUM_END
} gpt_partition_type_guids_E;
typedef struct {
uint8_t signature [8];
uint32_t revision;
uint32_t header_size;
uint32_t checksum_crc32;
uint32_t reserved;
uint64_t current_lba;
uint64_t backup_lba;
uint64_t first_usable_lba;
uint64_t last_usable_lba;
uint8_t disk_guid [16];
uint64_t starting_lba;
uint32_t num_partitions;
uint32_t partition_entry_size;
uint32_t partition_entry_crc32;
uint8_t reserved2 [0x1A4];
}__attribute__((packed)) gpt_table_header_T;
typedef struct {
uint8_t partition_type_guid [16];
uint8_t partition_guid [16];
uint64_t starting_lba;
uint64_t ending_lba;
uint64_t attributes;
uint16_t name [36]; // UTF-16 encoded
}__attribute__((packed)) gpt_partition_entry_T;
gpt_partition_type_guids_E gpt_get_partition_type (uint8_t guid[16]);
string_t gpt_partition_type_to_string(gpt_partition_type_guids_E type);
extern uint8_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][16];
#endif //NOXOS_GPT_H

View File

@ -0,0 +1,40 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_MBR_H
#define NOXOS_MBR_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
MBR_PARTITION_TYPE_UNUSED = 0x00,
MBR_PARTITION_TYPE_GPT = 0xEE,
MBR_PARTITION_TYPE_EXT2 = 0x83,
MBR_PARTITION_TYPE_FAT12 = 0x01,
MBR_PARTITION_TYPE_FAT16 = 0x04,
MBR_PARTITION_TYPE_FAT32_CHS = 0x0B,
MBR_PARTITION_TYPE_FAT32_LBA = 0x0C
} mbr_partition_types_E;
typedef struct {
uint8_t boot_indicator;
uint8_t start_head;
uint16_t start_sector:6;
uint16_t start_cylinder:10;
uint8_t partition_type;
uint8_t end_head;
uint16_t end_sector:6;
uint16_t end_cylinder:10;
uint32_t start_lba;
uint32_t num_sectors;
}__attribute__((packed)) mbr_partition_header_T;
typedef struct {
uint8_t bootstrap [446];
mbr_partition_header_T partitions [4];
uint8_t signature [2];
} mbr_header_T;
string_t mbr_partition_type_to_string(mbr_partition_types_E type);
#endif //NOXOS_MBR_H

View File

@ -0,0 +1,13 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_RAMFS_H
#define NOX_RAMFS_H
#include "drivers/builtin/fs/vfs.h"
void ramfs_file_delete (vfs_node_T* node);
uint64_t ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in);
uint64_t ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out);
#endif //NOX_RAMFS_H

View File

@ -0,0 +1,37 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_USTAR_H
#define NOX_USTAR_H
#include "utils/stdtypes.h"
typedef enum {
USTAR_FILE,
USTAR_LINK_HARD,
USTAR_LINK_SYM,
USTAR_CHAR_DEVICE,
USTAR_BLOCK_DEVICE,
USTAR_DIRECTORY,
USTAR_PIPE
} ustar_type_E;
typedef struct {
char name [100];
uint64_t mode;
uint64_t owner_id;
uint64_t group_id;
char size [12]; // octal based string (don't ask me why, the ustar standard is weird)
char last_modification [12]; // unix timestamp (octal)
uint64_t checksum;
uint8_t type;
char name_linked [100];
char indicator [6];
uint16_t version;
char owner_user_name [32];
char owner_group_name [32];
uint64_t device_major;
uint64_t device_minor;
char name_prefix [155];
}__attribute__((packed)) __attribute__((aligned(512))) ustar_header_T;
#endif //NOX_USTAR_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_VFS_H
#define NOX_VFS_H
@ -80,13 +59,14 @@ void vfs_node_cache_destruct (vfs_node_cache_T* node_cache);
vfs_node_T* vfs_node_create (vfs_node_T* parent, string_t name, vfs_node_type_E type, void* specific);
void vfs_node_destruct (vfs_node_T* node);
void vfs_node_delete (vfs_node_T* node);
void vfs_node_dump_info (vfs_node_T* node, uint64_t indent);
vfs_node_T* vfs_node_resolve_child (vfs_node_T* node, string_t child_name);
vfs_node_T* vfs_file_create (fs_T* filesystem, string_t path);
void vfs_file_delete (vfs_node_T* file);
void vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in);
void vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out);
uint64_t vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in);
uint64_t vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out);
vfs_node_T* vfs_directory_create (fs_T* filesystem, string_t path);
void vfs_directory_delete (vfs_node_T* directory);

View File

@ -0,0 +1,34 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_COLOR_H
#define NOX_COLOR_H
#include "utils/stdtypes.h"
// Colors from https://gogh-co.github.io/Gogh/
typedef enum {
COLOR_PAL_GREY_DARK,
COLOR_PAL_PINK,
COLOR_PAL_GREEN_SIGNAL,
COLOR_PAL_ORANGE,
COLOR_PAL_BLUE,
COLOR_PAL_PURPLE,
COLOR_PAL_GREEN,
COLOR_PAL_GREY_LIGHT,
COLOR_PAL_RED,
COLOR_PAL_ENUM_END
} color_palette_E;
typedef struct {
uint8_t alpha;
uint8_t red;
uint8_t green;
uint8_t blue;
} color_argb_T;
extern color_argb_T g_color_palette[COLOR_PAL_ENUM_END];
color_argb_T color_argb_blend_alpha(color_argb_T background, color_argb_T foreground);
#endif //NOX_COLOR_H

View File

@ -0,0 +1,17 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_FONT_H
#define NOX_FONT_H
#include "utils/stdtypes.h"
typedef struct {
uint8_t width;
uint8_t height;
uint8_t glyph_size;
uint8_t* buffer;
} font_T;
extern font_T g_font;
#endif //NOX_FONT_H

View File

@ -0,0 +1,20 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_FRAMEBUFFER_H
#define NOX_FRAMEBUFFER_H
#include "utils/stdtypes.h"
typedef struct {
void* address;
uint64_t width;
uint64_t height;
uint64_t pitch;
uint16_t bits_per_pixel;
uint8_t bytes_per_pixel;
uint8_t shift_red;
uint8_t shift_green;
uint8_t shift_blue;
} framebuffer_T;
#endif //NOX_FRAMEBUFFER_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_RENDERER_H
#define NOX_RENDERER_H
@ -27,9 +6,9 @@
#include "utils/stdtypes.h"
#include "utils/string.h"
#include "utils/math.h"
#include "drivers/graphics/color.h"
#include "drivers/graphics/font.h"
#include "drivers/graphics/framebuffer.h"
#include "drivers/builtin/graphics/color.h"
#include "drivers/builtin/graphics/font.h"
#include "drivers/builtin/graphics/framebuffer.h"
#include "boot/boot_info.h"
typedef enum {
@ -66,6 +45,7 @@ typedef struct {
graphics_buffer_T* graphics_buffer_request (uint32_t pos_x, uint32_t pos_y, uint32_t width, uint32_t height, graphics_buffer_layer_E layer);
void graphics_buffer_show (graphics_buffer_T* graphics_buffer);
void graphics_buffer_hide (graphics_buffer_T* graphics_buffer);
void graphics_buffer_move (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y);
void graphics_buffer_destruct (graphics_buffer_T* graphics_buffer);
void graphics_buffer_shift_up (graphics_buffer_T* graphics_buffer, uint16_t shift);
void graphics_buffer_set_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color);

View File

@ -0,0 +1,98 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_JSON_H
#define NOXOS_JSON_H
#include "utils/string.h"
#include "utils/stdtypes.h"
/*
* JSON node schematic
*
* +-----------+
* +----------| Root Node |------------+
* | +-----------+ |
* | ^ |
* | | |
* [childs_start] /----[parent]------\ [childs_end]
* | / | \ |
* v / | \ v
* +------+ +------+ +------+
* | Node |--[next]->| Node |--[next]->| Node |
* | |<-[prev]--| |<-[prev]--| | ---> . . .
* +------+ +------+ +------+
*
* |
* v
* . . .
*
* */
#define JSON_INCREMENT_TOKEN_ID \
*token_id += 1; \
/* DEBUG("token: %d - %s", *token_id, json->tokens[*token_id].string);*/ \
if (*token_id >= json->num_tokens) { \
log(LOG_ERROR, "failed to parse json -> unexpected EOF"); \
json_node_dump(json->root_node, 0); \
return false; \
}
typedef enum {
JSON_TOKEN_NUMERIC,
JSON_TOKEN_TEXT,
JSON_TOKEN_STRING,
JSON_TOKEN_SPECIAL
} json_token_type_E;
typedef enum {
JSON_NODE_OBJECT,
JSON_NODE_ARRAY,
JSON_NODE_STRING,
JSON_NODE_NUMBER,
JSON_NODE_BOOL,
JSON_NODE_NULL
} json_node_type_E;
typedef struct {
json_token_type_E type;
uint64_t value;
string_t string;
uint32_t line;
uint32_t column;
} json_token_T;
typedef struct json_node_T json_node_T;
struct json_node_T {
json_node_type_E type;
string_t string;
uint64_t value;
json_node_T* parent;
json_node_T* childs_start;
json_node_T* childs_end;
json_node_T* prev;
json_node_T* next;
};
typedef struct {
json_token_T* tokens;
uint64_t num_tokens;
void* string_buffer;
json_node_T* root_node;
} json_T;
json_T* json_from_string (string_t str);
void json_destruct (json_T* json);
json_node_T* json_node_alloc (json_node_T* parent, json_node_type_E type, json_token_T* token);
void json_node_destruct (json_node_T* node);
void json_node_dump (json_node_T* node, uint32_t indent);
string_t json_node_type_to_string (json_node_type_E type);
void json_tokenize (json_T* json, string_t str);
bool json_parse (json_T* json);
bool json_parse_assignment (json_T* json, uint32_t* token_id, json_node_T* node);
bool json_parse_object (json_T* json, uint32_t* token_id, json_node_T* node);
bool json_parse_array (json_T* json, uint32_t* token_id, json_node_T* node);
#endif //NOXOS_JSON_H

255
inc/drivers/builtin/pci.h Normal file
View File

@ -0,0 +1,255 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_PCI_H
#define NOXOS_PCI_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
PCI_CLASS_UNCLASSIFIED = 0x00,
PCI_CLASS_MASS_STORAGE_CONTROLLER = 0x01,
PCI_CLASS_NETWORK_CONTROLLER = 0x02,
PCI_CLASS_DISPLAY_CONTROLLER = 0x03,
PCI_CLASS_MULTIMEDIA_CONTROLLER = 0x04,
PCI_CLASS_MEMORY_CONTROLLER = 0x05,
PCI_CLASS_BRIDGE = 0x06,
PCI_CLASS_SIMPLE_COMMUNICATION_CONTROLLER = 0x07,
PCI_CLASS_BASE_SYSTEM_PERIPHERAL = 0x08,
PCI_CLASS_INPUT_DEVICE_CONTROLLER = 0x09,
PCI_CLASS_DOCKING_STATION = 0x0a,
PCI_CLASS_PROCESSOR = 0x0b,
PCI_CLASS_SERIAL_BUS_CONTROLLER = 0x0c,
PCI_CLASS_WIRELESS_CONTROLLER = 0x0d,
PCI_CLASS_INTELLIGENT_CONTROLLER = 0x0e,
PCI_CLASS_SATELLITE_COMMUNICATION_CONTROLLER = 0x0f,
PCI_CLASS_ENCRYPTION_CONTROLLER = 0x10,
PCI_CLASS_SIGNAL_PROCESSING_CONTROLLER = 0x11,
PCI_CLASS_PROCESSING_ACCELERATOR = 0x12,
PCI_CLASS_NON_ESSENTIAL_INSTRUMENTATION = 0x13,
PCI_CLASS_COPROCESSOR = 0x40
} pci_class_E;
typedef enum {
PCI_SUBCLASS_NON_VGA_COMPATIBLE_UNCLASSIFIED_DEVICE = 0x00,
PCI_SUBCLASS_VGA_COMPATIBLE_UNCLASSIFIED_DEVICE = 0x01
} pci_unclassified_sublasses_E;
typedef enum {
PCI_SUBCLASS_SCSI_BUS_CONTROLLER = 0x00,
PCI_SUBCLASS_IDE_CONTROLLER = 0x01,
PCI_SUBCLASS_FLOPPY_DISK_CONTROLLER = 0x02,
PCI_SUBCLASS_IPI_BUS_CONTROLLER = 0x03,
PCI_SUBCLASS_RAID_CONTROLLER = 0x04,
PCI_SUBCLASS_ATA_CONTROLLER = 0x05,
PCI_SUBCLASS_SERIAL_ATA_CONTROLLER = 0x06,
PCI_SUBCLASS_SERIAL_ATTACHED_SCSI_CONTROLLER = 0x07,
PCI_SUBCLASS_NON_VOLATILE_MEMORY_CONTROLLER = 0x08,
PCI_SUBCLASS_OTHER_MASS_STORAGE_CONTROLLER = 0x80
} pci_mass_storage_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_ETHERNET_CONTROLLER = 0x00,
PCI_SUBCLASS_TOKEN_RING_CONTROLLER = 0x01,
PCI_SUBCLASS_FDDI_CONTROLLER = 0x02,
PCI_SUBCLASS_ATM_CONTROLLER = 0x03,
PCI_SUBCLASS_ISDN_CONTROLLER = 0x04,
PCI_SUBCLASS_WORLDFIP_CONTROLLER = 0x05,
PCI_SUBCLASS_PICMG_2_14_MULTI_COMPUTING_CONTROLLER = 0x06,
PCI_SUBCLASS_INFINIBAND_NETWORKCONTROLLER = 0x07,
PCI_SUBCLASS_FABRIC_CONTROLLER = 0x08,
PCI_SUBCLASS_OTHER_NETWORK_CONTROLLER = 0x80
} pci_network_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_VGA_COMPATIBLE_CONTROLLER = 0x00,
PCI_SUBCLASS_XGA_COMPATIBLE_CONTROLLER = 0x01,
PCI_SUBCLASS_3D_CONTROLLER_NOT_VGA_COMPATIBLE = 0x02,
PCI_SUBCLASS_OTHER_DISPLAY_CONTROLLER = 0x80
} pci_display_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_MULTIMEDIA_VIDEO_CONTROLLER = 0x00,
PCI_SUBCLASS_MULTIMEDIA_AUDIO_CONTROLLER = 0x01,
PCI_SUBCLASS_COMPUTER_TELEPHONY_DEVICE = 0x02,
PCI_SUBCLASS_AUDIO_DEVICE = 0x03,
PCI_SUBCLASS_OTHER_MULTIMEDIA_CONTROLLER = 0x80
} pci_multimedia_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_RAM_CONTROLLER = 0x00,
PCI_SUBCLASS_FLASH_CONTROLLER = 0x01,
PCI_SUBCLASS_OTHER_MEMORY_CONTROLLER = 0x80
} pci_memory_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_HOST_BRIDGE = 0x00,
PCI_SUBCLASS_ISA_BRIDGE = 0x01,
PCI_SUBCLASS_EISA_BRIDGE = 0x02,
PCI_SUBCLASS_MCA_BRIDGE = 0x03,
PCI_SUBCLASS_PCI_TO_PCI_BRIDGE = 0x04,
PCI_SUBCLASS_PCMCIA_BRIDGE = 0x05,
PCI_SUBCLASS_NUBUS_BRIDGE = 0x06,
PCI_SUBCLASS_CARDBUS_BRIDGE = 0x07,
PCI_SUBCLASS_RACEWAY_BRIDGE = 0x08,
PCI_SUBCLASS_PCI_TO_PCI_BRIDGE_2 = 0x09,
PCI_SUBCLASS_INFINIBAND_TO_PCI_HOST_BRIDGE = 0x0a,
PCI_SUBCLASS_OTHER_BRIDGE = 0x80
} pci_bridge_subclasses_E;
typedef enum {
PCI_SUBCLASS_SERIAL_SIMPLE_COMMUNICATION_CONTROLLER = 0x00,
PCI_SUBCLASS_PARALLEL_SIMPLE_COMMUNICATION_CONTROLLER = 0x01,
PCI_SUBCLASS_MULTIPORT_SERIAL_CONTROLLER = 0x02,
PCI_SUBCLASS_MODEM = 0x03,
PCI_SUBCLASS_IEEE_488_1_2_GPIB_CONTROLLER = 0x04,
PCI_SUBCLASS_SMART_CARD_CONTROLLER = 0x05,
PCI_SUBCLASS_OTHER_SIMPLE_COMMUNICATION_CONTROLLER = 0x80
} pci_simple_communication_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_PIC = 0x00,
PCI_SUBCLASS_DMA_CONTROLLER = 0x01,
PCI_SUBCLASS_TIMER = 0x02,
PCI_SUBCLASS_RTC_CONTROLLER = 0x03,
PCI_SUBCLASS_PCI_HOT_PLUG_CONTROLLER = 0x04,
PCI_SUBCLASS_SD_HOST_CONTROLLER = 0x05,
PCI_SUBCLASS_IOMMU = 0x06,
PCI_SUBCLASS_OTHER_BASE_SYSTEM_PERIPHERAL = 0x80
} pci_base_system_peripheral_subclasses_E;
typedef enum {
PCI_SUBCLASS_KEYBOARD_CONTROLLER = 0x00,
PCI_SUBCLASS_DIGITIZER_PEN = 0x01,
PCI_SUBCLASS_MOUSE_CONTROLLER = 0x02,
PCI_SUBCLASS_SCANNER_CONTROLLER = 0x03,
PCI_SUBCLASS_GAMEPORT_CONTROLLER = 0x04,
PCI_SUBCLASS_OTHER_INPUT_DEVICE_CONTROLLER = 0x80
} pci_input_device_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_GENERIC_DOCKING_STATION = 0x00,
PCI_SUBCLASS_OTHER_DOCKING_STATION = 0x80
} pci_docking_station_subclasses_E;
typedef enum {
PCI_SUBCLASS_386_PROCESSOR = 0x00,
PCI_SUBCLASS_486_PROCESSOR = 0x01,
PCI_SUBCLASS_PENTIUM_PROCESSOR = 0x02,
PCI_SUBCLASS_PENTIUM_PRO_PROCESSOR = 0x03,
PCI_SUBCLASS_ALPHA_PROCESSOR = 0x10,
PCI_SUBCLASS_POWERPC_PROCESSOR = 0x20,
PCI_SUBCLASS_MIPS_PROCESSOR = 0x30,
PCI_SUBCLASS_COPROCESSOR = 0x40,
PCI_SUBCLASS_OTHER_PROCESSOR = 0x80
} pci_processor_subclasses_E;
typedef enum {
PCI_SUBCLASS_FIREWIRE_CONTROLLER = 0x00,
PCI_SUBCLASS_ACCESS_BUS_CONTROLLER = 0x01,
PCI_SUBCLASS_SSA = 0x02,
PCI_SUBCLASS_USB_CONTROLLER = 0x03,
PCI_SUBCLASS_FIBRE_CHANNEL = 0x04,
PCI_SUBCLASS_SMBUS_CONTROLLER = 0x05,
PCI_SUBCLASS_INFINIBAND_SERIAL_BUS_CONTROLLER = 0x06,
PCI_SUBCLASS_IPMI_INTERFACE = 0x07,
PCI_SUBCLASS_SERCOS_INTERFACE = 0x08,
PCI_SUBCLASS_CANBUS_CONTROLLER = 0x09,
PCI_SUBCLASS_OTHER_SERIAL_BUS_CONTROLLER = 0x80
} pci_serial_bus_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_IRDA_COMPATIBLE_CONTROLLER = 0x00,
PCI_SUBCLASS_CONSUMER_IR_CONTROLLER = 0x01,
PCI_SUBCLASS_RF_CONTROLLER = 0x10,
PCI_SUBCLASS_BLUETOOTH_CONTROLLER = 0x11,
PCI_SUBCLASS_BROADBAND_CONTROLLER = 0x12,
PCI_SUBCLASS_ETHERNET_CONTROLLER_802_1A = 0x20,
PCI_SUBCLASS_ETHERNET_CONTROLLER_802_1B = 0x21,
PCI_SUBCLASS_OTHER_WIRELESS_CONTROLLER = 0x80
} pci_wireless_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_I20_INTELLIGENT_CONTROLLER = 0x00
} pci_intelligent_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_SATELLITE_TV_CONTROLLER = 0x01,
PCI_SUBCLASS_SATELLITE_AUDIO_CONTROLLER = 0x02,
PCI_SUBCLASS_SATELLITE_VOICE_CONTROLLER = 0x03,
PCI_SUBCLASS_SATELLITE_DATA_CONTROLLER = 0x04
} pci_satellite_communication_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_NETWORK_AND_COMPUTING_ENCRYPTION_DECRYPTION = 0x00,
PCI_SUBCLASS_ENTERTAINMENT_ENCRYPTION_DECRYPTION = 0x10,
PCI_SUBCLASS_OTHER_ENCRYPTION_CONTROLLER = 0x80
} pci_encryption_controller_subclasses_E;
typedef enum {
PCI_SUBCLASS_DPIO_MODULES = 0x00,
PCI_SUBCLASS_PERFORMANCE_COUNTERS = 0x01,
PCI_SUBCLASS_COMMUNICATION_SYNCHRONIZER = 0x10,
PCI_SUBCLASS_SIGNAL_PROCESSING_MANAGEMENT = 0x20,
PCI_SUBCLASS_OTHER_SIGNAL_PROCESSING_CONTROLLER = 0x80
} pci_signal_processing_controller_subclasses_E;
typedef struct {
uint16_t vendor_id;
uint16_t device_id;
uint16_t command_reg;
uint16_t status_reg;
uint8_t revision_id;
uint8_t progif; // Programming Interface Byte
uint8_t subclass;
uint8_t main_class;
uint8_t cache_line_size;
uint8_t latency_timer;
uint8_t header_type;
uint8_t bist; // Built-in Self-Test
} __attribute__((packed)) pci_device_header_T;
typedef struct {
pci_device_header_T header;
uint32_t bar0;
uint32_t bar1;
uint32_t bar2;
uint32_t bar3;
uint32_t bar4;
uint32_t bar5;
uint32_t cardbus_cis_pointer;
uint16_t subsystem_vendor_id;
uint16_t subsystem_id;
uint32_t expansion_rom_base_address;
uint8_t capabilities;
uint8_t reserved[7];
uint8_t interrupt_line;
uint8_t interrupt_pin;
uint8_t min_grant;
uint8_t max_latency;
} __attribute__((packed)) pci_header_0_T;
typedef struct pci_device_T pci_device_T;
struct pci_device_T {
pci_device_header_T* header;
void* specific;
pci_device_T* prev;
pci_device_T* next;
};
typedef struct {
pci_device_T* devices;
} pci_manager_T;
void pci_init ();
void pci_manager_add_device (pci_device_header_T* header);
void pci_manager_remove_device (pci_device_T* device);
pci_device_T* pci_manager_find_device (pci_class_E class, uint8_t subclass, uint8_t progif);
void pci_manager_dump_devices ();
string_t pci_get_subclass_string (pci_class_E class, uint8_t subclass);
string_t pci_get_vendor_string (uint16_t vendor_id);
#endif // NOXOS_PCI_H

View File

@ -0,0 +1,23 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_CONTROLLER_H
#define NOX_CONTROLLER_H
#include "utils/stdtypes.h"
#define PS2_CONTROLLER_DATA_PORT 0x60
#define PS2_CONTROLLER_STATUS_PORT 0x64
#define PS2_CONTROLLER_COMMAND_PORT 0x64
#define PS2_CONTROLLER_TIMEOUT 0xFFFFF
void ps2_controller_init ();
uint8_t ps2_controller_command (uint8_t command);
uint8_t ps2_controller_command_with_data (uint8_t command, uint8_t data);
bool ps2_controller_command_has_response (uint8_t command);
bool ps2_controller_wait_until_ready_for_input ();
bool ps2_controller_wait_until_ready_for_output ();
uint8_t ps2_controller_read_data ();
void ps2_controller_write_data (uint8_t data);
#endif //NOX_CONTROLLER_H

View File

@ -0,0 +1,39 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_KEYBOARD_H
#define NOX_KEYBOARD_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
PS2_KEYBOARD_COMMAND_SET_LEDS = 0xED,
PS2_KEYBOARD_COMMAND_ECHO = 0xEE,
PS2_KEYBOARD_COMMAND_SET_SCANCODE_SET = 0xF0,
PS2_KEYBOARD_COMMAND_IDENTIFY = 0xF2,
PS2_KEYBOARD_COMMAND_SET_TYPEMATIC = 0xF3,
PS2_KEYBOARD_COMMAND_ENABLE_SCAN = 0xF4,
PS2_KEYBOARD_COMMAND_DISABLE_SCAN = 0xF5,
PS2_KEYBOARD_COMMAND_SET_DEFAULT_PARAMS = 0xF6,
PS2_KEYBOARD_COMMAND_RESEND_LAST_BYTE = 0xFE,
PS2_KEYBOARD_COMMAND_SELF_TEST = 0xFF
} ps2_keyboard_command_E;
typedef enum {
PS2_KEYBOARD_RESPONSE_KEY_DETECTION_ERROR_1 = 0x00,
PS2_KEYBOARD_RESPONSE_SELF_TEST_PASSED = 0xAA,
PS2_KEYBOARD_RESPONSE_ECHO = 0xEE,
PS2_KEYBOARD_RESPONSE_ACKNOWLEDGED = 0xFA,
PS2_KEYBOARD_RESPONSE_SELF_TEST_FAILED_1 = 0xFC,
PS2_KEYBOARD_RESPONSE_SELF_TEST_FAILED_2 = 0xFD,
PS2_KEYBOARD_RESPONSE_RESEND = 0xFE,
PS2_KEYBOARD_RESPONSE_KEY_DETECTION_ERROR_2 = 0xFF
} ps2_keyboard_response_E;
uint8_t ps2_keyboard_command (ps2_keyboard_command_E command);
void ps2_keyboard_init ();
void ps2_keyboard_read ();
string_t ps2_keyboard_command_to_string (ps2_keyboard_command_E command);
#endif //NOX_KEYBOARD_H

View File

@ -0,0 +1,38 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SCANCODES_H
#define NOX_SCANCODES_H
#define PS2_SCANCODE_SET_1_ESCAPE 0x01
#define PS2_SCANCODE_SET_1_BACKSPACE 0x0E
#define PS2_SCANCODE_SET_1_TABULATOR 0x0F
#define PS2_SCANCODE_SET_1_RETURN 0x1C
#define PS2_SCANCODE_SET_1_SHIFT_LEFT 0x2A
#define PS2_SCANCODE_SET_1_SHIFT_RIGHT 0x36
#define PS2_SCANCODE_SET_1_ALT_LEFT 0x38
#define PS2_SCANCODE_SET_1_SPACE 0x39
#define PS2_SCANCODE_SET_1_CAPSLOCK 0x3A
#define PS2_SCANCODE_SET_1_NUMLOCK 0x45
#define PS2_SCANCODE_SET_1_SCROLLLOCK 0x46
#define PS2_SCANCODE_SET_1_F1 0x3B
#define PS2_SCANCODE_SET_1_F2 0x3C
#define PS2_SCANCODE_SET_1_F3 0x3D
#define PS2_SCANCODE_SET_1_F4 0x3E
#define PS2_SCANCODE_SET_1_F5 0x3F
#define PS2_SCANCODE_SET_1_F6 0x40
#define PS2_SCANCODE_SET_1_F7 0x41
#define PS2_SCANCODE_SET_1_F8 0x42
#define PS2_SCANCODE_SET_1_F9 0x43
#define PS2_SCANCODE_SET_1_F10 0x44
#define PS2_SCANCODE_SET_1_F11 0x57
#define PS2_SCANCODE_SET_1_F12 0x58
#define PS2_SCANCODE_SET_1_E0_CURSOR_UP 0x48
#define PS2_SCANCODE_SET_1_E0_CURSOR_LEFT 0x4B
#define PS2_SCANCODE_SET_1_E0_CURSOR_RIGHT 0x4D
#define PS2_SCANCODE_SET_1_E0_CURSOR_DOWN 0x50
#define PS2_SCANCODE_SET_1_RELEASE 0x80
#define PS2_SCANCODE_SET_1_MODIFIER 0xE0
#endif //NOX_SCANCODES_H

View File

@ -0,0 +1,13 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_PIT_H
#define NOX_PIT_H
#include "utils/stdtypes.h"
#define PIT_CHANNEL_0_PORT 0x40
#define PIT_DIVISOR 32768 // This gives an interrupt every ~27.46ms
void pit_set_divisor(uint16_t divisor);
#endif //NOX_PIT_H

25
inc/drivers/builtin/tty.h Normal file
View File

@ -0,0 +1,25 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_TTY_H
#define NOXOS_TTY_H
#include "drivers/builtin/graphics/renderer.h"
#include "utils/stream.h"
#include "proc/pipe.h"
typedef struct {
graphics_buffer_T* graphics_buffer;
pipe_T* output;
pipe_T input;
graphics_buffer_T* cursor_overlay;
position_T cursor;
color_argb_T color;
} tty_T;
void tty_init ();
void tty_update ();
uint32_t tty_write (string_t string);
extern tty_T* g_tty;
#endif //NOXOS_TTY_H

115
inc/drivers/driver.h Normal file
View File

@ -0,0 +1,115 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_DRIVER_H
#define NOXOS_DRIVER_H
#include <utils/stdtypes.h>
#include <utils/bitmap.h>
#include <utils/hashmap.h>
#include <drivers/builtin/elf/elf.h>
#define DRIVER_MANAGER_CHUNK_SIZE 64
#define DRIVER_MANAGER_HASHMAP_SIZE 128
#define DRIVER_MEMORY_REGION_SIZE 0x100000000 // 4 GB
typedef enum {
DRIVER_TRANSPORT_PCI,
DRIVER_TRANSPORT_USB,
DRIVER_TRANSPORT_FS
} __attribute__((packed)) driver_transport_protocol_E;
typedef enum {
DRIVER_UNKNOWN = 0x0000,
DRIVER_RESERVED = 0x0001,
// Specific Driver
DRIVER_MASS_STORAGE = 0x0101,
DRIVER_FILESYSTEM = 0x0102,
DRIVER_GRAPHICS = 0x0103,
DRIVER_AUDIO = 0x0104,
// Drivers which define the transmission of data but have multiple
// intended usages, such as USB for mass storage, input, etc..
DRIVER_TRANSMISSION = 0x0201,
DRIVER_USB_DEVICE = 0x0202,
DRIVER_PCI_DEVICE = 0x0203,
DRIVER_PCIE_DEVICE = 0x0204,
DRIVER_BLUETOOTH = 0x0205,
DRIVER_ETHERNET = 0x0206,
// MISCELLANEOUS
DRIVER_EMULATION = 0x7fff
} driver_category_E;
typedef struct {
uint16_t vendor_id;
uint16_t device_id;
} __attribute__((packed)) driver_config_device_id_T;
typedef struct {
bool enable_progif;
uint8_t class;
uint8_t subclass;
uint8_t progif;
uint16_t num_device_ids;
driver_config_device_id_T device_ids[];
} __attribute__((packed)) driver_config_pci_T;
typedef struct {
uint8_t min_version;
uint16_t num_device_ids;
driver_config_device_id_T device_ids[];
} __attribute__((packed)) driver_config_usb_T;
typedef struct {
uint8_t gpt_guid[16];
uint8_t mbr_type;
} __attribute__((packed)) driver_config_fs_T;
typedef union {
driver_config_pci_T* pci;
driver_config_usb_T* usb;
driver_config_fs_T* fs;
} conf_U;
typedef struct {
uint64_t id;
void* base;
elf_executable_T* executable;
} driver_T;
typedef struct driver_manager_chunk_T driver_manager_chunk_T;
struct driver_manager_chunk_T {
driver_T drivers [DRIVER_MANAGER_CHUNK_SIZE];
bitmap_T drivers_bitmap;
uint32_t free_slots;
driver_manager_chunk_T* prev;
driver_manager_chunk_T* next;
};
typedef struct {
driver_manager_chunk_T* driver_pool;
hashmap_T lookup_table_pci;
hashmap_T lookup_table_usb;
hashmap_T lookup_table_fs_gpt;
hashmap_T lookup_table_fs_mbr;
} driver_manager_T;
void driver_manager_init ();
driver_manager_chunk_T* driver_manager_chunk_alloc(driver_manager_chunk_T* prev);
driver_T* driver_register (elf_executable_T* executable, uint8_t* buffer);
void driver_init (driver_T* driver, driver_transport_protocol_E protocol, conf_U conf);
driver_T* driver_lookup_pci_device (uint16_t vendor_id, uint16_t device_id);
driver_T* driver_lookup_usb_device (uint16_t vendor_id, uint16_t device_id);
driver_T* driver_lookup_fs_gpt (uint8_t guid[16]);
driver_T* driver_lookup_fs_mbr (uint8_t type);
driver_T* driver_lookup_by_address (void* address);
#endif //NOXOS_DRIVER_H

31
inc/mm/heap.h Normal file
View File

@ -0,0 +1,31 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_HEAP_H
#define NOX_HEAP_H
#include "utils/stdtypes.h"
#define HEAP_SEGMENT_MAGIC 0xA1C3A1B2
typedef struct heap_segment_T heap_segment_T;
struct heap_segment_T {
uint32_t magic;
uint64_t size;
bool free;
heap_segment_T* next;
heap_segment_T* prev;
};
typedef struct {
void* start;
void* end;
heap_segment_T* last_segment;
} heap_T;
void heap_init (heap_T* heap, void* base);
void* heap_memory_allocate (heap_T* heap, uint64_t size);
void heap_memory_free (heap_T* heap, void* address);
void heap_dump_segments (heap_T* heap);
void heap_destruct (heap_T* heap);
#endif //NOX_HEAP_H

11
inc/mm/memory_map.h Normal file
View File

@ -0,0 +1,11 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_MEMORY_MAP_H
#define NOX_MEMORY_MAP_H
#include "utils/stdtypes.h"
#include "boot/boot_info.h"
uint64_t memory_map_get_total_memory_size(boot_info_T* boot_info);
#endif //NOX_MEMORY_MAP_H

30
inc/mm/page_frame.h Normal file
View File

@ -0,0 +1,30 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_PAGE_FRAME_H
#define NOX_PAGE_FRAME_H
#include "utils/stdtypes.h"
#include "utils/bitmap.h"
#include "boot/boot_info.h"
#define PFRAME_SIZE 4096 // The size of a page frame
typedef struct {
uint64_t free_memory;
uint64_t reserved_memory;
uint64_t used_memory;
uint64_t page_bitmap_index;
bitmap_T page_bitmap;
bool blocked;
} page_frame_manager_T;
void pframe_manager_init (boot_info_T* boot_info);
void pframe_reserve (void* address);
void pframe_reserve_multi (void* address, uint32_t n);
void pframe_unreserve (void* address);
void pframe_unreserve_multi (void* address, uint32_t n);
void pframe_free (void* address);
void pframe_free_multi (void* address, uint32_t n);
void* pframe_request ();
#endif //NOX_PAGE_FRAME_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_PAGE_MAP_H
#define NOX_PAGE_MAP_H
@ -52,6 +31,7 @@ extern page_map_T* page_map_fetch_current ();
extern void page_map_load (page_map_T* page_map);
void page_map_map_memory (page_map_T* page_map, void* virtual_address, void* physical_address, uint64_t flags);
void page_map_unmap_memory (page_map_T* page_map, void* virtual_address);
bool page_map_check_memory (page_map_T* page_map, void* virtual_address);
void* page_map_get_physical_address (page_map_T* page_map, void* virtual_address);
void page_map_destruct (page_map_T* page_map);
void page_map_dump_info (page_map_T* page_map);

28
inc/mm/region.h Normal file
View File

@ -0,0 +1,28 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_REGION_H
#define NOX_REGION_H
#include "utils/stdtypes.h"
#define KERNEL_START_ADDRESS (uint64_t)&_kernel_start
#define KERNEL_END_ADDRESS (uint64_t)&_kernel_end
#define MEM_REGION_THREAD_OFFSET 0x100000000
#define MEM_REGION_PROCESS 0x0000000000000000
#define MEM_REGION_PROCESS_EXEC 0x0000010000000000
#define MEM_REGION_PROCESS_THREAD_BASE 0x0000010100000000
#define MEM_REGION_PROCESS_USABLE 0x0000080000000000
#define MEM_REGION_KERNEL 0x0000800000000000
#define MEM_REGION_KERNEL_DRIVERS 0xFFFFE80000000000 // size: up to 8 TB
#define MEM_REGION_KERNEL_STACK_DUMMY 0xFFFFF00000000000 // size: 4 KB
#define MEM_REGION_KERNEL_HEAP 0xFFFFF80000000000 // size: up to 8 TB
#define MEM_REGION_KERNEL_THREAD_BASE 0xFFFFFF0000000000 // size: up to 1022 GB
#define MEM_REGION_KERNEL_EXEC 0xFFFFFFFF80000000 // size: up to 2 GB
extern uint64_t _kernel_start;
extern uint64_t _kernel_end;
#endif //NOX_REGION_H

16
inc/mm/stack.h Normal file
View File

@ -0,0 +1,16 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_STACK_H
#define NOX_STACK_H
#include "utils/stdtypes.h"
#include "utils/symbol.h"
#include "drivers/builtin/elf/elf.h"
void stack_dump_call_info (uint64_t rip, symbol_T* symbol);
void stack_trace_call_stack (uint64_t rbp);
extern uint64_t stack_get_caller();
#endif //NOX_STACK_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_CPU_H
#define NOX_CPU_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_EXCEPTIONS_H
#define NOX_EXCEPTIONS_H

45
inc/platform/gdt.h Normal file
View File

@ -0,0 +1,45 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_GDT_H
#define NOX_GDT_H
#include "utils/stdtypes.h"
typedef enum {
GDT_SELECTOR_NULL = 0x00,
GDT_SELECTOR_KERNEL_CODE = 0x08,
GDT_SELECTOR_KERNEL_DATA = 0x10,
GDT_SELECTOR_USER_NULL = 0x18,
GDT_SELECTOR_USER_CODE = 0x20,
GDT_SELECTOR_USER_DATA = 0x28
} gdt_selector_E;
typedef struct {
uint16_t size;
uint64_t offset;
}__attribute__((packed)) gdt_descriptor_T;
typedef struct {
uint16_t limit0;
uint16_t base0;
uint8_t base1;
uint8_t access;
uint8_t limit1_flags;
uint8_t base2;
}__attribute__((packed)) gdt_entry_T;
typedef struct {
gdt_entry_T null; // 0x00
gdt_entry_T kernel_code; // 0x08
gdt_entry_T kernel_data; // 0x10
gdt_entry_T user_null; // 0x18
gdt_entry_T user_code; // 0x20
gdt_entry_T user_data; // 0x28
}__attribute__((packed)) __attribute__((aligned(0x1000))) gdt_T;
extern gdt_T g_default_gdt;
void gdt_init();
#endif //NOX_GDT_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_INTERRUPTS_H
#define NOX_INTERRUPTS_H

55
inc/platform/syscall.h Normal file
View File

@ -0,0 +1,55 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SYSCALL_H
#define NOX_SYSCALL_H
#include "platform/cpu.h"
#include "utils/status.h"
typedef enum {
SYSCALLS_FILES = 0x00,
SYSCALLS_MEMORY = 0x01,
SYSCALLS_PROC = 0x02,
SYSCALLS_DRIVERS = 0x03,
SYSCALLS_KERNEL = 0xFF
}syscall_group_E;
typedef enum {
SYSCALL_NX_FS_OPEN = 0x0001,
SYSCALL_NX_FS_CLOSE = 0x0002,
SYSCALL_NX_FS_READ = 0x0003,
SYSCALL_NX_FS_WRITE = 0x0004,
SYSCALL_NX_FS_DELETE = 0x0005,
SYSCALL_NX_FS_LIST = 0x0006,
SYSCALL_NX_FS_INFO = 0x0007,
SYSCALL_NX_MEM_ALLOC = 0x0101,
SYSCALL_NX_MEM_FREE = 0x0102,
SYSCALL_NX_MEM_LABEL = 0x0103,
SYSCALL_NX_MEM_UNLABEL = 0x0104,
SYSCALL_NX_PROC_CREATE = 0x0201,
SYSCALL_NX_PROC_SIGNAL_SEND = 0x0202,
SYSCALL_NX_PROC_SIGNAL_SET_HANDLER = 0x0203,
SYSCALL_NX_PROC_THREAD_CREATE = 0x0204,
SYSCALL_NX_PROC_THREAD_START = 0x0205,
SYSCALL_NX_PROC_THREAD_PAUSE = 0x0206,
SYSCALL_NX_PROC_THREAD_KILL = 0x0207,
SYSCALL_NX_DRV_REGISTER = 0x0301,
SYSCALL_NX_KERNEL_SCHEDULER_START = 0xFF00,
SYSCALL_NX_KERNEL_PANIC = 0xFF01
} syscall_E;
typedef enum {
SYSCALL_NX_MMAP_FLAG_WRITE,
SYSCALL_NX_MMAP_FLAG_NO_EXEC
} syscall_nx_mmap_flags_E;
extern status_E syscall_perform(syscall_E id, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
cpu_state_T* syscall_handle(cpu_state_T* state);
#endif //NOX_SYSCALL_H

View File

@ -0,0 +1,46 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_FILE_DESCRIPTOR_H
#define NOX_FILE_DESCRIPTOR_H
#include "utils/stdtypes.h"
#include "utils/bitmap.h"
#include "drivers/builtin/fs/vfs.h"
#define FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE 32
typedef uint32_t file_descriptor_t;
typedef enum {
FILE_DESCRIPTOR_INVALID,
FILE_DESCRIPTOR_STDOUT,
FILE_DESCRIPTOR_STDIN,
FILE_DESCRIPTOR_STDERR,
FILE_DESCRIPTORS_ENUM_END
} std_file_descriptors_E;
typedef struct file_descriptor_array_chunk_T file_descriptor_array_chunk_T;
struct file_descriptor_array_chunk_T {
file_descriptor_array_chunk_T* prev;
file_descriptor_array_chunk_T* next;
vfs_node_T* lookup [FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE];
bitmap_T bitmap;
uint32_t amount;
};
typedef struct {
file_descriptor_array_chunk_T* base_chunk;
} file_descriptor_array_T;
file_descriptor_t file_descriptor_request (file_descriptor_array_T* fd_array, vfs_node_T* node);
vfs_node_T* file_descriptor_resolve (file_descriptor_array_T* fd_array, file_descriptor_t fd);
void file_descriptor_free (file_descriptor_array_T* fd_array, file_descriptor_t fd);
file_descriptor_array_T* file_descriptor_array_alloc ();
void file_descriptor_array_destruct (file_descriptor_array_T* fd_array);
file_descriptor_array_chunk_T* file_descriptor_array_chunk_alloc (file_descriptor_array_chunk_T* prev);
void file_descriptor_array_chunk_destruct (file_descriptor_array_chunk_T* chunk);
#endif //NOX_FILE_DESCRIPTOR_H

31
inc/proc/pipe.h Normal file
View File

@ -0,0 +1,31 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_PIPE_H
#define NOXOS_PIPE_H
#ifndef NOX_PROCESS
typedef struct process_T process_T;
#endif
#include "utils/stream.h"
#include "utils/bitmap.h"
#define PIPE_MAX_SENDERS 8
#define PIPE_STD_STREAM_SIZE 0x1000
typedef struct {
stream_T* stream;
process_T* receiver;
process_T* senders [PIPE_MAX_SENDERS];
bitmap_T senders_bitmap;
void (*on_write)();
} pipe_T;
void pipe_init (pipe_T* pipe, process_T* receiver, void (*on_write)());
void pipe_destruct (pipe_T* pipe);
bool pipe_add_sender (pipe_T* pipe, process_T* sender);
void pipe_remove_sender (pipe_T* pipe, process_T* sender);
uint64_t pipe_write (pipe_T* pipe, void* buffer_in, uint64_t n);
uint64_t pipe_read (pipe_T* pipe, void* buffer_out, uint64_t n);
#endif //NOXOS_PIPE_H

92
inc/proc/process.h Normal file
View File

@ -0,0 +1,92 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_PROCESS_H
#define NOX_PROCESS_H
#include "utils/stdtypes.h"
#include "utils/string.h"
#include "utils/bitmap.h"
#include "proc/file_descriptor.h"
#include "proc/pipe.h"
#include "mm/page_map.h"
#include "drivers/builtin/elf/elf.h"
#define MAX_THREADS_PER_PROCESS 64
#define THREAD_ID_INVALID (-1)
typedef uint32_t pid_t;
typedef enum {
PROCESS_NONE,
PROCESS_KERNEL
} processes_standard_E;
typedef enum {
PROCESS_BLOCK_WAIT_PIPE_OUT,
PROCESS_BLOCK_WAIT_PIPE_IN,
PROCESS_BLOCK_ENUM_SIZE
} process_blockers_E;
typedef enum {
PROCESS_SIGNAL_START, // SIGSTART
PROCESS_SIGNAL_PAUSE, // SIGPAUSE
PROCESS_SIGNAL_KILL, // SIGKILL
PROCESS_SIGNAL_PAGEFAULT, // SIGPAGEFAULT
PROCESS_SIGNAL_MATHFAULT, // SIGMATHFAULT
} process_signals_E;
typedef struct {
file_descriptor_t at_parent;
file_descriptor_t at_child;
}__attribute__((packed)) process_inherit_fd_T;
typedef struct {
uint8_t privilege_level;
char name[80];
file_descriptor_t executable;
uint16_t num_inherit_fds;
process_inherit_fd_T inherit_fds[];
}__attribute__((packed)) process_config_T;
typedef struct process_T process_T;
struct process_T {
char name [128];
pid_t id;
void* chunk;
uint32_t chunk_id;
page_map_T* page_map;
elf_executable_T* executable;
file_descriptor_array_T* fd_array;
pipe_T* stdout;
pipe_T stdin;
pipe_T* stderr;
bitmap_T waiting;
uint32_t num_threads;
void* threads;
bitmap_T thread_ids;
process_T* parent;
process_T* childs;
process_T* prev;
process_T* next;
};
void process_kernel_spawn (elf_executable_T* executable);
pid_t process_spawn (pid_t parent, string_t name, elf_executable_T* executable, void* buffer);
void process_signal (process_T* process, process_signals_E signal);
bool process_is_child_of (process_T* process, process_T* parent);
int32_t process_get_thread_id (process_T* process);
void process_clear_thread_id (process_T* process, uint32_t id);
void process_pause_pid (pid_t pid);
void process_pause (process_T* process);
void process_start_pid (pid_t pid);
void process_start (process_T* process);
void process_kill_pid (pid_t pid);
void process_kill (process_T* process);
#endif //NOX_PROCESS_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SCHEDULER_H
#define NOX_SCHEDULER_H
@ -63,6 +42,8 @@ void scheduler_start_thread (thread_T* thread);
void scheduler_kill_thread (thread_T* thread);
pid_t scheduler_register_process (process_T* process);
void scheduler_pause_process (process_T* process);
void scheduler_start_process (process_T* process);
void scheduler_kill_process (process_T* process);
process_T* scheduler_get_process (pid_t pid);

34
inc/proc/thread.h Normal file
View File

@ -0,0 +1,34 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_THREAD_H
#define NOX_THREAD_H
#include "utils/stdtypes.h"
#include "platform/cpu.h"
#include "proc/process.h"
typedef struct thread_T thread_T;
struct thread_T{
cpu_state_T* state;
uint64_t cpu_time;
void* stack;
uint32_t stack_size;
process_T* process;
// Scheduling data
thread_T* global_prev;
thread_T* global_next;
thread_T* local_prev;
thread_T* local_next;
uint32_t local_id;
};
thread_T* thread_spawn (pid_t process, void* function);
thread_T* thread_spawn_from_state (pid_t process, cpu_state_T* state);
void thread_start (thread_T* thread);
void thread_pause (thread_T* thread);
void thread_kill (thread_T* thread);
#endif //NOX_THREAD_H

20
inc/utils/bitmap.h Normal file
View File

@ -0,0 +1,20 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_BITMAP_H
#define NOX_BITMAP_H
#include "stdtypes.h"
typedef struct {
uint32_t size;
uint32_t size_bits;
uint8_t* buffer;
} bitmap_T;
bitmap_T bitmap_init_from_buffer (void* buffer, uint32_t size);
bitmap_T bitmap_init (uint32_t size);
void bitmap_destruct (bitmap_T* bitmap);
bool bitmap_set (bitmap_T* bitmap, uint32_t index, bool value);
bool bitmap_get (bitmap_T* bitmap, uint32_t index);
#endif //NOX_BITMAP_H

16
inc/utils/core.h Normal file
View File

@ -0,0 +1,16 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_CORE_H
#define NOX_CORE_H
#include "utils/logger.h"
#include "platform/interrupts.h"
#define CORE_INTERRUPTABLE_HALT_WHILE(a) while(!g_handling_interrupt && a) { asm("hlt"); }
#define CORE_HALT_WHILE(a) while(!g_handling_interrupt && a) { asm("hlt"); }
#define CORE_HALT_FOREVER log(LOG_WARNING, "!=====[ HALTING SYSTEM ]=====!"); while(1) { asm("hlt"); }
#define CORE_INTERRUPTS_ENABLE asm("sti");
#define CORE_INTERRUPTS_DISABLE asm("cli");
#endif //NOX_CORE_H

10
inc/utils/crypto/sha1.h Normal file
View File

@ -0,0 +1,10 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_SHA1_H
#define NOXOS_SHA1_H
#include <utils/stdtypes.h>
int sha1_hash(uint8_t *digest, const uint8_t* data, uint64_t len_data);
#endif //NOXOS_SHA1_H

28
inc/utils/hashmap.h Normal file
View File

@ -0,0 +1,28 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_HASHMAP_H
#define NOXOS_HASHMAP_H
#include <utils/stdtypes.h>
typedef struct hashmap_entry_T hashmap_entry_T;
struct hashmap_entry_T {
bool in_use;
uint64_t key;
void* value;
hashmap_entry_T* prev;
hashmap_entry_T* next;
};
typedef struct {
uint64_t size;
hashmap_entry_T* entries;
} hashmap_T;
hashmap_T hashmap_create (uint64_t size);
void hashmap_destruct (hashmap_T* hashmap);
void hashmap_insert (hashmap_T* hashmap, uint64_t key, void* value);
void hashmap_delete (hashmap_T* hashmap, uint64_t key);
void* hashmap_lookup (hashmap_T* hashmap, uint64_t key);
#endif //NOXOS_HASHMAP_H

15
inc/utils/io.h Normal file
View File

@ -0,0 +1,15 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_IO_H
#define NOX_IO_H
#include "stdtypes.h"
// sends one byte to a port
void io_out_byte (uint16_t port, uint8_t data);
uint8_t io_in_byte (uint16_t port);
void io_out_word (uint16_t port, uint32_t data);
uint32_t io_in_word (uint16_t port);
void io_wait ();
#endif //NOX_IO_H

26
inc/utils/logger.h Normal file
View File

@ -0,0 +1,26 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_LOGGER_H
#define NOX_LOGGER_H
#include "string.h"
#define LOG_PORT 0x3F8
#define DEBUG(f, args...) log(LOG_DEBUG, "%s:%d -> " f, __FILE_NAME__, __LINE__, ##args)
typedef enum {
LOG_NONE,
LOG_INFO,
LOG_DEBUG,
LOG_WARNING,
LOG_ERROR,
LOG_ENUM_END
} log_level_E;
// logs a string to qemu's serial port
void graphical_log_init ();
void log (log_level_E log_level, string_t string, ...);
#endif //NOX_LOGGER_H

23
inc/utils/math.h Normal file
View File

@ -0,0 +1,23 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_MATH_H
#define NOX_MATH_H
#include "stdtypes.h"
#include "string.h"
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define CEIL_TO(a, b) ((a) % (b) ? (a) + (b) - ((a) % (b)) : (a))
#define FLOOR_TO(a, b) ((a) - ((a) % (b)))
typedef struct {
uint64_t x;
uint64_t y;
} position_T;
uint64_t pow (uint64_t base, uint64_t exp);
uint64_t abs (int64_t n);
uint64_t octal_string_to_int (string_t string, uint8_t size);
#endif //NOX_MATH_H

16
inc/utils/memory.h Normal file
View File

@ -0,0 +1,16 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_MEMORY_H
#define NOX_MEMORY_H
#include "stdtypes.h"
void memory_copy (void* source, void* destination, uint32_t num);
void memory_set (void* destination, uint8_t data, uint32_t num);
bool memory_compare (void* a, void* b, uint32_t num);
void* memory_allocate (uint64_t size);
void memory_free (void* address);
void memory_allocator_init (void* base);
void memory_hexdump (uint8_t* address, uint64_t num);
#endif //NOX_MEMORY_H

11
inc/utils/panic.h Normal file
View File

@ -0,0 +1,11 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_PANIC_H
#define NOX_PANIC_H
#include "platform/cpu.h"
#include "utils/string.h"
void panic(cpu_state_T* state, string_t message);
#endif //NOX_PANIC_H

19
inc/utils/status.h Normal file
View File

@ -0,0 +1,19 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_STATUS_H
#define NOX_STATUS_H
#include "string.h"
typedef enum {
STATUS_SUCCESS,
STATUS_PERMISSION_DENIED,
STATUS_RESOURCE_NOT_AVAILABLE,
STATUS_NOT_SUPPORTED,
STATUS_GENERIC_ERROR
} status_E;
extern string_t g_status_code_strings[3];
#endif //NOX_STATUS_H

22
inc/utils/stdtypes.h Normal file
View File

@ -0,0 +1,22 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_STDTYPES_H
#define NOX_STDTYPES_H
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;
typedef _Bool bool;
#define true 1
#define false 0
#define NULL (void*)0
#endif //NOX_STDTYPES_H

20
inc/utils/stream.h Normal file
View File

@ -0,0 +1,20 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_STREAM_H
#define NOX_STREAM_H
#include "utils/stdtypes.h"
typedef struct {
uint8_t* buffer;
uint32_t size;
uint32_t pos_sender;
uint32_t pos_receiver;
} stream_T;
stream_T* stream_alloc (uint32_t size);
void stream_destruct (stream_T* stream);
uint32_t stream_write (stream_T* stream, void* buffer_in, uint32_t n);
uint32_t stream_read (stream_T* stream, void* buffer_out, uint32_t n);
#endif //NOX_STREAM_H

View File

@ -1,25 +1,4 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_STRING_H
#define NOX_STRING_H
@ -27,12 +6,35 @@
#include "stdtypes.h"
#include <stdarg.h>
#define STRING_EXT_SIZE(n) ((n) + 5)
typedef const char* string_t;
typedef enum {
STRING_EXT_CMD_CLEAR,
STRING_EXT_CMD_CURSOR_MOVE,
STRING_EXT_CMD_CURSOR_SET,
STRING_EXT_CMD_COLOR_SET,
STRING_EXT_CMD_COLOR_RESET,
STRING_EXT_CMD_RENDER_DISABLE,
STRING_EXT_CMD_RENDER_ENABLE,
STRING_EXT_CMD_KEYBOARD_ECHO
} string_ext_command_E;
typedef struct {
uint8_t shift_in;
uint16_t length;
uint8_t command;
uint8_t data;
// DATA BLOCKS
// SHIFT OUT
}__attribute__((packed)) string_ext_header_T;
uint32_t string_length (string_t string);
bool string_compare (string_t a, string_t b);
uint32_t string_find_next (string_t string, char chr);
uint32_t string_find_last (string_t string, char chr);
void string_add_ext_command (string_t string, string_ext_command_E command, int num_data, uint8_t data[]);
uint64_t variadic_format_size (string_t string, va_list args);
uint64_t format_size (string_t string, ...);
@ -50,8 +52,11 @@ void string_bool_to_alpha (string_t string, bool value);
bool string_is_char_text (char chr);
bool string_is_char_number (char chr);
bool string_is_char_special (char chr);
bool string_is_char_alpha (char chr);
bool string_is_char_uppercase (char chr);
bool string_is_char_lowercase (char chr);
uint32_t string_hash_djb (string_t str);
#endif //NOX_STRING_H

34
inc/utils/symbol.h Normal file
View File

@ -0,0 +1,34 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_SYMBOLS_H
#define NOX_SYMBOLS_H
#include "utils/string.h"
#include "utils/hashmap.h"
typedef enum {
SYMBOL_FUNCTION,
SYMBOL_VARIABLE,
SYMBOL_UNKNOWN
} symbol_type_E;
typedef struct {
string_t name;
symbol_type_E type;
uint64_t address;
} symbol_T;
typedef struct {
hashmap_T hashmap;
uint64_t num_symbols;
symbol_T* symbols;
uint64_t symbols_index;
} symbol_table_T;
symbol_table_T symbol_table_init (uint64_t num_symbols);
void symbol_table_destruct (symbol_table_T* symbol_table);
void symbol_table_insert (symbol_table_T* symbol_table, symbol_T symbol);
symbol_T* symbol_resolve_from_name (symbol_table_T* symbol_table, string_t name);
symbol_T* symbol_resolve_from_rip (symbol_table_T* symbol_table, uint64_t rip);
#endif //NOX_SYMBOLS_H

View File

@ -1,23 +0,0 @@
set(C 99)
set(CMAKE_NASM_COMPILE_OBJECT "nasm <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
add_executable(kernel)
add_library (kernel_asm OBJECT)
target_include_directories(kernel PRIVATE inc)
file(GLOB_RECURSE kernel_src_c "**/*.c")
file(GLOB_RECURSE kernel_inc "**/*.h")
file(GLOB_RECURSE kernel_src_asm "**/*.asm")
target_compile_options(kernel PRIVATE -g -fno-stack-protector -fno-stack-check -mno-red-zone -ffreestanding -m64 -march=x86-64 -mabi=sysv)
target_link_options(kernel PRIVATE -nostdlib -static -T "${CMAKE_CURRENT_LIST_DIR}/kernel.ld")
enable_language(ASM_NASM)
set(CAN_USE_ASSEMBLER TRUE)
target_sources(kernel_asm PRIVATE ${kernel_src_asm})
target_sources(kernel PRIVATE ${kernel_src_c} ${kernel_inc} $<TARGET_OBJECTS:kernel_asm>)

View File

@ -1,39 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_BOOT_INFO_H
#define NOX_BOOT_INFO_H
#include "utils/stdtypes.h"
#include "limine.h"
typedef struct {
struct limine_framebuffer_response* framebuffer;
struct limine_terminal_response* terminal;
struct limine_memmap_response* memory_map;
struct limine_file* kernel_file;
struct limine_file* ramdisk_file;
void* rsdp;
} boot_info_T;
#endif //NOX_BOOT_INFO_H

View File

@ -1,52 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_ELF_H
#define NOX_ELF_H
#include "drivers/elf/header.h"
#include "drivers/elf/section.h"
#include "drivers/elf/mapping.h"
#include "utils/symbol.h"
typedef struct {
elf_header_T header;
uint64_t num_symbols;
symbol_T* symbols;
uint64_t num_mappings;
elf_mapping_T* mappings;
void* string_table;
} elf_executable_T;
typedef struct {
elf_executable_T* executable;
elf_section_T* symbol_table;
elf_section_T* section_header_string_table;
uint8_t* buffer;
} elf_executable_temp_T;
elf_executable_T* elf_executable_create (uint8_t* buffer);
void elf_executable_destruct (elf_executable_T* executable);
#endif //NOX_ELF_H

View File

@ -1,39 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_MAPPING_H
#define NOX_MAPPING_H
#include "utils/stdtypes.h"
#include "mm/page_map.h"
typedef struct {
uint64_t offset_file;
uint64_t offset_virtual;
uint64_t length_file;
uint64_t length_virtual;
} elf_mapping_T;
void elf_mappings_apply(elf_mapping_T* mappings, uint64_t num_mappings, uint8_t* buffer, void* base, page_map_T* page_map);
#endif //NOX_MAPPING_H

View File

@ -1,59 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_SECTION_H
#define NOX_SECTION_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
ELF_SECTION_NULL,
ELF_SECTION_PROGRAM_DATA,
ELF_SECTION_SYMBOL_TABLE,
ELF_SECTION_STRING_TABLE,
ELF_SECTION_RELOCATION_A,
ELF_SECTION_HASH,
ELF_SECTION_DYNAMIC_LINK,
ELF_SECTION_NOTE,
ELF_SECTION_NOBITS,
ELF_SECTION_ENUM_END
} elf_section_type_E;
typedef struct {
uint32_t name_offset;
uint32_t type;
uint64_t flags;
uint64_t virtual_address;
uint64_t offset;
uint64_t length;
uint32_t link;
uint32_t info;
uint64_t alignment;
uint64_t entry_size;
} elf_section_T;
extern string_t g_elf_section_type_strings[ELF_SECTION_ENUM_END+1];
#endif //NOX_SECTION_H

View File

@ -1,55 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_SEGMENT_H
#define NOX_SEGMENT_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
ELF_SEGMENT_NULL,
ELF_SEGMENT_LOAD,
ELF_SEGMENT_DYNAMIC,
ELF_SEGMENT_INTERPRETER,
ELF_SEGMENT_NOTE,
ELF_SEGMENT_PROGRAM_HEADER_TABLE,
ELF_SEGMENT_TLS,
ELF_SEGMENT_ENUM_END
} elf_segment_type_E;
typedef struct {
uint32_t type;
uint32_t flags;
uint64_t offset;
uint64_t address_virtual;
uint64_t address_physical;
uint64_t length_file;
uint64_t length_memory;
uint64_t align;
} elf_segment_T;
extern string_t g_elf_segment_type_strings[ELF_SEGMENT_ENUM_END+1];
#endif //NOX_SEGMENT_H

View File

@ -1,53 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_ELF_SYMBOL_H
#define NOX_ELF_SYMBOL_H
#include "utils/stdtypes.h"
#include "utils/string.h"
#define ELF_SYMBOL_TYPE(info) ((info) & 0xF)
extern string_t g_elf_symbol_type_strings[7];
typedef enum {
ELF_SYMBOL_NONE,
ELF_SYMBOL_OBJECT,
ELF_SYMBOL_FUNC,
ELF_SYMBOL_SECTION,
ELF_SYMBOL_FILE,
ELF_SYMBOL_COMMON,
ELF_SYMBOL_TLS
} elf_symbol_type_E;
typedef struct {
uint32_t name_offset;
uint8_t info;
uint8_t other;
uint16_t related_section_index;
uint64_t value;
uint64_t length;
} elf_symbol_T;
#endif //NOX_ELF_SYMBOL_H

View File

@ -1,34 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_RAMFS_H
#define NOX_RAMFS_H
#include "drivers/fs/vfs.h"
void ramfs_file_delete (vfs_node_T* node);
void ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in);
void ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out);
#endif //NOX_RAMFS_H

View File

@ -1,58 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_USTAR_H
#define NOX_USTAR_H
#include "utils/stdtypes.h"
typedef enum {
USTAR_FILE,
USTAR_LINK_HARD,
USTAR_LINK_SYM,
USTAR_CHAR_DEVICE,
USTAR_BLOCK_DEVICE,
USTAR_DIRECTORY,
USTAR_PIPE
} ustar_type_E;
typedef struct {
char name [100];
uint64_t mode;
uint64_t owner_id;
uint64_t group_id;
char size [12]; // octal based string (don't ask me why, the ustar standard is weird)
char last_modification [12]; // unix timestamp (octal)
uint64_t checksum;
uint8_t type;
char name_linked [100];
char indicator [6];
uint16_t version;
char owner_user_name [32];
char owner_group_name [32];
uint64_t device_major;
uint64_t device_minor;
char name_prefix [155];
}__attribute__((packed)) __attribute__((aligned(512))) ustar_header_T;
#endif //NOX_USTAR_H

View File

@ -1,55 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_COLOR_H
#define NOX_COLOR_H
#include "utils/stdtypes.h"
// Colors from https://gogh-co.github.io/Gogh/
typedef enum {
COLOR_PAL_GREY_DARK,
COLOR_PAL_PINK,
COLOR_PAL_GREEN_SIGNAL,
COLOR_PAL_ORANGE,
COLOR_PAL_BLUE,
COLOR_PAL_PURPLE,
COLOR_PAL_GREEN,
COLOR_PAL_GREY_LIGHT,
COLOR_PAL_RED,
COLOR_PAL_ENUM_END
} color_palette_E;
typedef struct {
uint8_t alpha;
uint8_t red;
uint8_t green;
uint8_t blue;
} color_argb_T;
extern color_argb_T g_color_palette[COLOR_PAL_ENUM_END];
color_argb_T color_argb_blend_alpha(color_argb_T background, color_argb_T foreground);
#endif //NOX_COLOR_H

View File

@ -1,38 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_FONT_H
#define NOX_FONT_H
#include "utils/stdtypes.h"
typedef struct {
uint8_t width;
uint8_t height;
uint8_t glyph_size;
uint8_t* buffer;
} font_T;
extern font_T g_font;
#endif //NOX_FONT_H

View File

@ -1,41 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_FRAMEBUFFER_H
#define NOX_FRAMEBUFFER_H
#include "utils/stdtypes.h"
typedef struct {
void* address;
uint64_t width;
uint64_t height;
uint64_t pitch;
uint16_t bits_per_pixel;
uint8_t bytes_per_pixel;
uint8_t shift_red;
uint8_t shift_green;
uint8_t shift_blue;
} framebuffer_T;
#endif //NOX_FRAMEBUFFER_H

View File

@ -1,34 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_PIT_H
#define NOX_PIT_H
#include "utils/stdtypes.h"
#define PIT_CHANNEL_0_PORT 0x40
#define PIT_DIVISOR 32768 // This gives an interrupt every ~27.46ms
void pit_set_divisor(uint16_t divisor);
#endif //NOX_PIT_H

View File

@ -1,52 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_HEAP_H
#define NOX_HEAP_H
#include "utils/stdtypes.h"
#define HEAP_SEGMENT_MAGIC 0xA1C3A1B2
typedef struct heap_segment_T heap_segment_T;
struct heap_segment_T {
uint32_t magic;
uint64_t size;
bool free;
heap_segment_T* next;
heap_segment_T* prev;
};
typedef struct {
void* start;
void* end;
heap_segment_T* last_segment;
} heap_T;
void heap_init (heap_T* heap, void* base);
void* heap_memory_allocate (heap_T* heap, uint64_t size);
void heap_memory_free (heap_T* heap, void* address);
void heap_dump_segments (heap_T* heap);
void heap_destruct (heap_T* heap);
#endif //NOX_HEAP_H

View File

@ -1,32 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_MEMORY_MAP_H
#define NOX_MEMORY_MAP_H
#include "utils/stdtypes.h"
#include "boot/boot_info.h"
uint64_t memory_map_get_total_memory_size(boot_info_T* boot_info);
#endif //NOX_MEMORY_MAP_H

View File

@ -1,51 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_PAGE_FRAME_H
#define NOX_PAGE_FRAME_H
#include "utils/stdtypes.h"
#include "utils/bitmap.h"
#include "boot/boot_info.h"
#define PFRAME_SIZE 4096 // The size of a page frame
typedef struct {
uint64_t free_memory;
uint64_t reserved_memory;
uint64_t used_memory;
uint64_t page_bitmap_index;
bitmap_T page_bitmap;
bool blocked;
} page_frame_manager_T;
void pframe_manager_init (boot_info_T* boot_info);
void pframe_reserve (void* address);
void pframe_reserve_multi (void* address, uint32_t n);
void pframe_unreserve (void* address);
void pframe_unreserve_multi (void* address, uint32_t n);
void pframe_free (void* address);
void pframe_free_multi (void* address, uint32_t n);
void* pframe_request ();
#endif //NOX_PAGE_FRAME_H

View File

@ -1,47 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_REGION_H
#define NOX_REGION_H
#include "utils/stdtypes.h"
#define KERNEL_START_ADDRESS (uint64_t)&_kernel_start
#define KERNEL_END_ADDRESS (uint64_t)&_kernel_end
#define MEM_REGION_THREAD_OFFSET 0x100000000
#define MEM_REGION_PROCESS 0x0000000000000000
#define MEM_REGION_PROCESS_EXEC 0x0000010000000000
#define MEM_REGION_PROCESS_THREAD_BASE 0x0000010100000000
#define MEM_REGION_KERNEL 0xFFFF800000000000
#define MEM_REGION_KERNEL_STACK_DUMMY 0xFFFFF00000000000 // size 0x4000
#define MEM_REGION_KERNEL_HEAP 0xFFFFF80000000000
#define MEM_REGION_KERNEL_THREAD_BASE 0xFFFFFF0000000000
#define MEM_REGION_KERNEL_EXEC 0xFFFFFFFF80000000
extern uint64_t _kernel_start;
extern uint64_t _kernel_end;
#endif //NOX_REGION_H

View File

@ -1,35 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_STACK_H
#define NOX_STACK_H
#include "utils/stdtypes.h"
#include "utils/symbol.h"
#include "drivers/elf/elf.h"
void stack_dump_call_info (uint64_t rip, symbol_T* symbol);
void stack_trace_call_stack (uint64_t rbp);
#endif //NOX_STACK_H

View File

@ -1,66 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_GDT_H
#define NOX_GDT_H
#include "utils/stdtypes.h"
typedef enum {
GDT_SELECTOR_NULL = 0x00,
GDT_SELECTOR_KERNEL_CODE = 0x08,
GDT_SELECTOR_KERNEL_DATA = 0x10,
GDT_SELECTOR_USER_NULL = 0x18,
GDT_SELECTOR_USER_CODE = 0x20,
GDT_SELECTOR_USER_DATA = 0x28
} gdt_selector_E;
typedef struct {
uint16_t size;
uint64_t offset;
}__attribute__((packed)) gdt_descriptor_T;
typedef struct {
uint16_t limit0;
uint16_t base0;
uint8_t base1;
uint8_t access;
uint8_t limit1_flags;
uint8_t base2;
}__attribute__((packed)) gdt_entry_T;
typedef struct {
gdt_entry_T null; // 0x00
gdt_entry_T kernel_code; // 0x08
gdt_entry_T kernel_data; // 0x10
gdt_entry_T user_null; // 0x18
gdt_entry_T user_code; // 0x20
gdt_entry_T user_data; // 0x28
}__attribute__((packed)) __attribute__((aligned(0x1000))) gdt_T;
extern gdt_T g_default_gdt;
void gdt_init();
#endif //NOX_GDT_H

View File

@ -1,79 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_SYSCALL_H
#define NOX_SYSCALL_H
#include "platform/cpu.h"
#include "utils/status.h"
typedef enum {
SYSCALLS_FILES = 0x00,
SYSCALLS_MEMORY = 0x01,
SYSCALLS_PROC = 0x02,
SYSCALLS_RUNTIME_LINKER = 0x02,
SYSCALLS_COMPATABILITY = 0x02,
SYSCALLS_KERNEL = 0xFF
}syscall_group_E;
typedef enum {
SYSCALL_FILES_OPEN = 0x0101,
SYSCALL_FILES_CLOSE = 0x0102,
SYSCALL_FILES_READ = 0x0103,
SYSCALL_FILES_WRITE = 0x0104,
SYSCALL_FILES_DELETE = 0x0105,
SYSCALL_FILES_LIST = 0x0106,
SYSCALL_FILES_FOLLOW = 0x0107, // Warning: nx_follow will probably be kicked out of the ABI
SYSCALL_FILES_INFO = 0x0108,
SYSCALL_MEMORY_ALLOC = 0x0201,
SYSCALL_MEMORY_FREE = 0x0202,
SYSCALL_MEMORY_LABEL = 0x0203,
SYSCALL_MEMORY_RANGE = 0x0204,
SYSCALL_MEMORY_ACCESS = 0x0205,
SYSCALL_PROCESS_CREATE = 0x0301,
SYSCALL_PROCESS_ENVFILE = 0x0302,
SYSCALL_PROCESS_START = 0x0303,
SYSCALL_PROCESS_SIGNAL = 0x0304,
SYSCALL_RUNTIME_LINKER_OPEN = 0x0401,
SYSCALL_RUNTIME_LINKER_CLOSE = 0x0402,
SYSCALL_RUNTIME_LINKER_LOAD_SYMBOL = 0x0403,
SYSCALL_RUNTIME_LINKER_STATUS = 0x0404,
SYSCALL_RUNTIME_LINKER_STANDARD_MOD = 0x0405,
SYSCALL_COMPATABILITY_ABI_TYPE = 0x0501,
SYSCALL_COMPATABILITY_ABI_VERSION = 0x0502,
SYSCALL_COMPATABILITY_ACTION = 0x0503,
SYSCALL_KERNEL_SCHEDULER_START = 0xFF00,
SYSCALL_KERNEL_PANIC = 0xFF01
} syscall_E;
extern status_E syscall_perform(syscall_E id, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
cpu_state_T* syscall_handle(cpu_state_T* state);
#endif //NOX_SYSCALL_H

View File

@ -1,70 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_PROCESS_H
#define NOX_PROCESS_H
#include "utils/stdtypes.h"
#include "utils/string.h"
#include "utils/bitmap.h"
#include "mm/page_map.h"
#include "drivers/elf/elf.h"
#define MAX_THREADS_PER_PROCESS 64
#define THREAD_ID_INVALID (-1)
typedef uint32_t pid_t;
typedef enum {
PROCESS_NONE,
PROCESS_KERNEL
} processes_standard_E;
typedef struct process_T process_T;
struct process_T {
char name [128];
pid_t id;
void* chunk;
uint32_t chunk_id;
page_map_T* page_map;
elf_executable_T* executable;
uint32_t num_threads;
void* threads;
bitmap_T thread_ids;
process_T* parent;
process_T* childs;
process_T* prev;
process_T* next;
};
void process_kernel_spawn (elf_executable_T* executable);
pid_t process_spawn (pid_t parent, string_t name, elf_executable_T* executable, void* buffer);
int32_t process_get_thread_id (process_T* process);
void process_clear_thread_id (process_T* process, uint32_t id);
void process_kill_pid (pid_t pid);
void process_kill (process_T* process);
#endif //NOX_PROCESS_H

View File

@ -1,55 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_THREAD_H
#define NOX_THREAD_H
#include "utils/stdtypes.h"
#include "platform/cpu.h"
#include "proc/process.h"
typedef struct thread_T thread_T;
struct thread_T{
cpu_state_T* state;
uint64_t cpu_time;
void* stack;
uint32_t stack_size;
process_T* process;
// Scheduling data
thread_T* global_prev;
thread_T* global_next;
thread_T* local_prev;
thread_T* local_next;
uint32_t local_id;
};
thread_T* thread_spawn (pid_t process, void* function);
thread_T* thread_spawn_from_state (pid_t process, cpu_state_T* state);
void thread_start (thread_T* thread);
void thread_pause (thread_T* thread);
void thread_kill (thread_T* thread);
#endif //NOX_THREAD_H

View File

@ -1,41 +0,0 @@
/*
* Copyright 2023 Antifallobst <antifallobst@systemausfall.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the Software), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NOX_BITMAP_H
#define NOX_BITMAP_H
#include "stdtypes.h"
typedef struct {
uint32_t size;
uint32_t size_bits;
uint8_t* buffer;
} bitmap_T;
bitmap_T bitmap_init_from_buffer (void* buffer, uint32_t size);
bitmap_T bitmap_init (uint32_t size);
void bitmap_destruct (bitmap_T* bitmap);
bool bitmap_set (bitmap_T* bitmap, uint32_t index, bool value);
bool bitmap_get (bitmap_T* bitmap, uint32_t index);
#endif //NOX_BITMAP_H

Some files were not shown because too many files have changed in this diff Show More