Compare commits
1
Commits
main
..
c26227951f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26227951f |
@@ -98,8 +98,7 @@ namespace BAN
|
|||||||
|
|
||||||
struct EntryHash
|
struct EntryHash
|
||||||
{
|
{
|
||||||
template<detail::HashMapFindable<Key, HASH, COMP> U>
|
constexpr bool operator()(const Key& a)
|
||||||
constexpr bool operator()(const U& a)
|
|
||||||
{
|
{
|
||||||
return HASH()(a);
|
return HASH()(a);
|
||||||
}
|
}
|
||||||
@@ -111,8 +110,7 @@ namespace BAN
|
|||||||
|
|
||||||
struct EntryComp
|
struct EntryComp
|
||||||
{
|
{
|
||||||
template<detail::HashMapFindable<Key, HASH, COMP> U>
|
constexpr bool operator()(const Entry& a, const Key& b)
|
||||||
constexpr bool operator()(const Entry& a, const U& b)
|
|
||||||
{
|
{
|
||||||
return COMP()(a.key, b);
|
return COMP()(a.key, b);
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-44
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <BAN/Limits.h>
|
#include <BAN/Limits.h>
|
||||||
#include <BAN/Numbers.h>
|
#include <BAN/Numbers.h>
|
||||||
#include <BAN/Swap.h>
|
|
||||||
#include <BAN/Traits.h>
|
#include <BAN/Traits.h>
|
||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
@@ -82,37 +81,6 @@ namespace BAN::Math
|
|||||||
return x + 1;
|
return x + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned_integral T>
|
|
||||||
requires is_same_v<T, unsigned int> || is_same_v<T, unsigned long> || is_same_v<T, unsigned long long>
|
|
||||||
inline constexpr int clz(T x)
|
|
||||||
{
|
|
||||||
if constexpr (is_same_v<T, unsigned int>)
|
|
||||||
return __builtin_clz(x);
|
|
||||||
if constexpr (is_same_v<T, unsigned long>)
|
|
||||||
return __builtin_clzl(x);
|
|
||||||
return __builtin_clzll(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<unsigned_integral T> requires(sizeof(T) <= sizeof(unsigned long long))
|
|
||||||
inline constexpr int ctz(T x)
|
|
||||||
{
|
|
||||||
if constexpr (sizeof(T) <= sizeof(unsigned int))
|
|
||||||
return __builtin_ctz(x);
|
|
||||||
if constexpr (sizeof(T) <= sizeof(unsigned long))
|
|
||||||
return __builtin_ctzl(x);
|
|
||||||
return __builtin_ctzll(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<unsigned_integral T> requires(sizeof(T) <= sizeof(unsigned long long))
|
|
||||||
inline constexpr int popcount(T x)
|
|
||||||
{
|
|
||||||
if constexpr (sizeof(T) <= sizeof(unsigned int))
|
|
||||||
return __builtin_popcount(x);
|
|
||||||
if constexpr (sizeof(T) <= sizeof(unsigned long))
|
|
||||||
return __builtin_popcountl(x);
|
|
||||||
return __builtin_popcountll(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<integral T>
|
template<integral T>
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
inline constexpr bool will_multiplication_overflow(T a, T b)
|
inline constexpr bool will_multiplication_overflow(T a, T b)
|
||||||
@@ -133,7 +101,11 @@ namespace BAN::Math
|
|||||||
requires is_same_v<T, unsigned int> || is_same_v<T, unsigned long> || is_same_v<T, unsigned long long>
|
requires is_same_v<T, unsigned int> || is_same_v<T, unsigned long> || is_same_v<T, unsigned long long>
|
||||||
inline constexpr T ilog2(T x)
|
inline constexpr T ilog2(T x)
|
||||||
{
|
{
|
||||||
return sizeof(T) * 8 - clz(x) - 1;
|
if constexpr(is_same_v<T, unsigned int>)
|
||||||
|
return sizeof(T) * 8 - __builtin_clz(x) - 1;
|
||||||
|
if constexpr(is_same_v<T, unsigned long>)
|
||||||
|
return sizeof(T) * 8 - __builtin_clzl(x) - 1;
|
||||||
|
return sizeof(T) * 8 - __builtin_clzll(x) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is ugly but my clangd does not like including
|
// This is ugly but my clangd does not like including
|
||||||
@@ -336,6 +308,36 @@ namespace BAN::Math
|
|||||||
return exp2<T>(y * log2<T>(x));
|
return exp2<T>(y * log2<T>(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<floating_point T>
|
||||||
|
inline constexpr T scalbn(T x, int n)
|
||||||
|
{
|
||||||
|
asm("fscale" : "+t"(x) : "u"(static_cast<T>(n)));
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<floating_point T>
|
||||||
|
inline constexpr T ldexp(T x, int y)
|
||||||
|
{
|
||||||
|
const bool exp_sign = y < 0;
|
||||||
|
if (exp_sign)
|
||||||
|
y = -y;
|
||||||
|
|
||||||
|
T exp = (T)1.0;
|
||||||
|
T mult = (T)2.0;
|
||||||
|
while (y)
|
||||||
|
{
|
||||||
|
if (y & 1)
|
||||||
|
exp *= mult;
|
||||||
|
mult *= mult;
|
||||||
|
y >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exp_sign)
|
||||||
|
exp = (T)1.0 / exp;
|
||||||
|
|
||||||
|
return x * exp;
|
||||||
|
}
|
||||||
|
|
||||||
template<floating_point T>
|
template<floating_point T>
|
||||||
inline constexpr T sqrt(T x)
|
inline constexpr T sqrt(T x)
|
||||||
{
|
{
|
||||||
@@ -468,17 +470,7 @@ namespace BAN::Math
|
|||||||
template<floating_point T>
|
template<floating_point T>
|
||||||
inline constexpr T hypot(T x, T y)
|
inline constexpr T hypot(T x, T y)
|
||||||
{
|
{
|
||||||
x = abs(x);
|
return sqrt<T>(x * x + y * y);
|
||||||
y = abs(y);
|
|
||||||
|
|
||||||
if (x < y)
|
|
||||||
swap(x, y);
|
|
||||||
|
|
||||||
if (y == (T)0.0)
|
|
||||||
return x;
|
|
||||||
|
|
||||||
const T r = y / x;
|
|
||||||
return x * sqrt<T>((T)1.0 + r * r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BAN_MATH_POP_OPTIONS
|
#ifdef BAN_MATH_POP_OPTIONS
|
||||||
|
|||||||
+7
-31
@@ -67,20 +67,11 @@ namespace BAN::sort
|
|||||||
template<typename It, typename Comp = less<it_value_type_t<It>>>
|
template<typename It, typename Comp = less<it_value_type_t<It>>>
|
||||||
void quick_sort(It begin, It end, Comp comp = {})
|
void quick_sort(It begin, It end, Comp comp = {})
|
||||||
{
|
{
|
||||||
while (distance(begin, end) > 1)
|
if (distance(begin, end) <= 1)
|
||||||
{
|
return;
|
||||||
const auto [lt, gt] = detail::partition(begin, end, comp);
|
const auto [lt, gt] = detail::partition(begin, end, comp);
|
||||||
if (distance(begin, lt) < distance(gt, end))
|
quick_sort(begin, lt, comp);
|
||||||
{
|
quick_sort(gt, end, comp);
|
||||||
quick_sort(begin, lt);
|
|
||||||
begin = gt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
quick_sort(gt, end);
|
|
||||||
end = lt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename It, typename Comp = less<it_value_type_t<It>>>
|
template<typename It, typename Comp = less<it_value_type_t<It>>>
|
||||||
@@ -111,28 +102,13 @@ namespace BAN::sort
|
|||||||
template<typename It, typename Comp>
|
template<typename It, typename Comp>
|
||||||
void intro_sort_impl(It begin, It end, size_t max_depth, Comp comp)
|
void intro_sort_impl(It begin, It end, size_t max_depth, Comp comp)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < max_depth; i++)
|
if (distance(begin, end) <= 16)
|
||||||
{
|
|
||||||
const size_t len = distance(begin, end);
|
|
||||||
if (len <= 1)
|
|
||||||
return;
|
|
||||||
if (len <= 16)
|
|
||||||
return insertion_sort(begin, end, comp);
|
return insertion_sort(begin, end, comp);
|
||||||
|
if (max_depth == 0)
|
||||||
|
return heap_sort(begin, end, comp);
|
||||||
const auto [lt, gt] = detail::partition(begin, end, comp);
|
const auto [lt, gt] = detail::partition(begin, end, comp);
|
||||||
if (distance(begin, lt) < distance(gt, end))
|
|
||||||
{
|
|
||||||
intro_sort_impl(begin, lt, max_depth - 1, comp);
|
intro_sort_impl(begin, lt, max_depth - 1, comp);
|
||||||
begin = gt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
intro_sort_impl(gt, end, max_depth - 1, comp);
|
intro_sort_impl(gt, end, max_depth - 1, comp);
|
||||||
end = lt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
heap_sort(begin, end, comp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,22 +100,3 @@ namespace BAN
|
|||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <BAN/Formatter.h>
|
|
||||||
|
|
||||||
namespace BAN::Formatter
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename F, typename T>
|
|
||||||
void print_argument(F putc, const Span<T>& span, const ValueFormat& format)
|
|
||||||
{
|
|
||||||
putc('[');
|
|
||||||
for (typename Span<T>::size_type i = 0; i < span.size(); i++)
|
|
||||||
{
|
|
||||||
if (i != 0) putc(',');
|
|
||||||
print_argument(putc, span[i], format);
|
|
||||||
}
|
|
||||||
putc(']');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,12 +27,6 @@ set(BUILD_SHARED_LIBS True)
|
|||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
find_program(CCACHE_PROGRAM "ccache")
|
|
||||||
if (CCACHE_PROGRAM)
|
|
||||||
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
|
|
||||||
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# include headers of ${library} to ${target}
|
# include headers of ${library} to ${target}
|
||||||
function(banan_include_headers target library)
|
function(banan_include_headers target library)
|
||||||
target_include_directories(${target} PUBLIC $<TARGET_PROPERTY:${library},SOURCE_DIR>/include)
|
target_include_directories(${target} PUBLIC $<TARGET_PROPERTY:${library},SOURCE_DIR>/include)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ This is my hobby operating system written in C++. Currently supports x86\_64 and
|
|||||||
|
|
||||||
You can find a live demo [here](https://bananymous.com/banan-os)
|
You can find a live demo [here](https://bananymous.com/banan-os)
|
||||||
|
|
||||||

|
If you want to try out DOOM, you should first enter the GUI environment using the `start-gui` command. Then you can run `doom` in the GUI terminal.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
@@ -18,8 +18,6 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [x] SMP (multiprocessing)
|
- [x] SMP (multiprocessing)
|
||||||
- [x] Linear framebuffer (VESA and GOP)
|
- [x] Linear framebuffer (VESA and GOP)
|
||||||
- [x] Network stack
|
- [x] Network stack
|
||||||
- [x] USB stack
|
|
||||||
- [x] Audio support
|
|
||||||
- [x] ELF executable loading
|
- [x] ELF executable loading
|
||||||
- [x] AML interpreter (partial)
|
- [x] AML interpreter (partial)
|
||||||
- [x] Basic graphical environment
|
- [x] Basic graphical environment
|
||||||
@@ -29,14 +27,16 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [ ] Some nice apps
|
- [ ] Some nice apps
|
||||||
- [x] ELF dynamic linking
|
- [x] ELF dynamic linking
|
||||||
- [x] copy-on-write memory
|
- [x] copy-on-write memory
|
||||||
|
- [x] file mappings
|
||||||
|
- [ ] anonymous mappings
|
||||||
|
|
||||||
#### Drivers
|
#### Drivers
|
||||||
- [x] NVMe disks
|
- [x] NVMe disks
|
||||||
- [x] ATA (IDE, SATA) disks
|
- [x] ATA (IDE, SATA) disks
|
||||||
- [x] E1000 and E1000E NICs
|
- [x] E1000 and E1000E NICs
|
||||||
- [x] RTL8111/8168/8211/8411 NICs
|
- [x] RTL8111/8168/8211/8411 NICs
|
||||||
- [x] AC97 and iHDA audio cards
|
- [x] PS2 keyboard (all scancode sets)
|
||||||
- [x] PS2 keyboard and mouse
|
- [x] PS2 mouse
|
||||||
- [x] USB
|
- [x] USB
|
||||||
- [x] xHCI
|
- [x] xHCI
|
||||||
- [ ] EHCI
|
- [ ] EHCI
|
||||||
@@ -46,8 +46,7 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [x] Mouse
|
- [x] Mouse
|
||||||
- [x] Mass storage
|
- [x] Mass storage
|
||||||
- [x] Hubs
|
- [x] Hubs
|
||||||
- [ ] Network
|
- [ ] ...
|
||||||
- [ ] Audio
|
|
||||||
- [ ] virtio devices (network, storage)
|
- [ ] virtio devices (network, storage)
|
||||||
|
|
||||||
#### Network
|
#### Network
|
||||||
@@ -55,7 +54,7 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [x] ICMP
|
- [x] ICMP
|
||||||
- [x] IPv4
|
- [x] IPv4
|
||||||
- [x] UDP
|
- [x] UDP
|
||||||
- [x] TCP
|
- [x] TCP (partial and buggy)
|
||||||
- [x] Unix domain sockets
|
- [x] Unix domain sockets
|
||||||
- [ ] SSL
|
- [ ] SSL
|
||||||
|
|
||||||
@@ -66,6 +65,7 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [x] Dev
|
- [x] Dev
|
||||||
- [x] Ram
|
- [x] Ram
|
||||||
- [x] Proc
|
- [x] Proc
|
||||||
|
- [ ] Sys
|
||||||
- [ ] 9P
|
- [ ] 9P
|
||||||
|
|
||||||
#### Bootloader support
|
#### Bootloader support
|
||||||
@@ -73,6 +73,8 @@ You can find a live demo [here](https://bananymous.com/banan-os)
|
|||||||
- [x] Custom BIOS bootloader
|
- [x] Custom BIOS bootloader
|
||||||
- [ ] Custom UEFI bootloader
|
- [ ] Custom UEFI bootloader
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Code structure
|
## Code structure
|
||||||
|
|
||||||
Each major component and library has its own subdirectory (kernel, userspace, libc, ...). Each directory contains directory *include*, which has **all** of the header files of the component. Every header is included by its absolute path.
|
Each major component and library has its own subdirectory (kernel, userspace, libc, ...). Each directory contains directory *include*, which has **all** of the header files of the component. Every header is included by its absolute path.
|
||||||
@@ -116,29 +118,15 @@ To change the bootloader you can set environment variable BANAN\_BOOTLOADER; sup
|
|||||||
|
|
||||||
To run with UEFI set environment variable BANAN\_UEFI\_BOOT=1. You will also have to set OVMF\_PATH to the correct OVMF (default */usr/share/ovmf/x64/OVMF.fd*).
|
To run with UEFI set environment variable BANAN\_UEFI\_BOOT=1. You will also have to set OVMF\_PATH to the correct OVMF (default */usr/share/ovmf/x64/OVMF.fd*).
|
||||||
|
|
||||||
To build an image with no physical root filesystem, but an initrd set environment variable BANAN\_INITRD=1. This can be used when testing on hardware with unsupported USB controller. If BANAN\_INITRD is set to a value larger than 1, initrd will be gzip compressed.
|
To build an image with no physical root filesystem, but an initrd set environment variable BANAN\_INITRD=1. This can be used when testing on hardware with unsupported USB controller.
|
||||||
|
|
||||||
If you have corrupted your disk image or want to create new one, you can either manually delete *build/banan-os.img* and build system will automatically create you a new one or you can run the following command.
|
If you have corrupted your disk image or want to create new one, you can either manually delete *build/banan-os.img* and build system will automatically create you a new one or you can run the following command.
|
||||||
```sh
|
```sh
|
||||||
./bos image-full
|
./bos image-full
|
||||||
```
|
```
|
||||||
|
|
||||||
To test on real hardware, I have a script to generate a compressed ISO. The ISO can be copied directly to an USB drive with for example `dd`. The file is created at build/banan-os.iso and can be generated with
|
|
||||||
```sh
|
|
||||||
./bos iso
|
|
||||||
```
|
|
||||||
|
|
||||||
I have also created shell completion script for zsh. You can either copy the file in _script/shell-completion/zsh/\_bos_ to _/usr/share/zsh/site-functions/_ or add the _script/shell-completion/zsh_ to your fpath in _.zshrc_.
|
I have also created shell completion script for zsh. You can either copy the file in _script/shell-completion/zsh/\_bos_ to _/usr/share/zsh/site-functions/_ or add the _script/shell-completion/zsh_ to your fpath in _.zshrc_.
|
||||||
|
|
||||||
### Package Manager
|
|
||||||
|
|
||||||
banan-os uses xbps as its package manager for ports. All upstream ports are packaged into xbps packages hosted on a [repository on my server](https://packages.bananymous.com/banan-os). You can manage sysroot's xbps packages with `./bos` wrapper. You can use `xbps-install`, `xbps-remove` and `xbps-query` with repository and sysroot set to the correct values. For example to install xbps that can be used inside banan-os you can use
|
|
||||||
```sh
|
|
||||||
./bos xbps-install -S xbps
|
|
||||||
```
|
|
||||||
For xbps usage see [their documentation](https://docs.voidlinux.org/xbps/index.html).
|
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
As the upstream is hosted on my server https://git.bananymous.com/Bananymous/banan-os, merging contributions is not as trivial as it would be on GitHub. You can still send PRs in GitHub in which case I should be able to download the diff and apply it manually. If you want, I can also provide you an account to my git server. In this case please contact me ([email](mailto:[email protected]), [discord](https://discord.gg/ehjGySwYdK)).
|
As the upstream is hosted on my server https://git.bananymous.com/Bananymous/banan-os, merging contributions is not as trivial as it would be on GitHub. You can still send PRs in GitHub in which case I should be able to download the diff and apply it manually. If you want, I can also provide you an account to my git server. In this case please contact me ([email](mailto:[email protected]), [discord](https://discord.gg/ehjGySwYdK)).
|
||||||
|
|||||||
Binary file not shown.
@@ -35,13 +35,13 @@ read_user_command_line:
|
|||||||
cmpb $'\n', %al
|
cmpb $'\n', %al
|
||||||
je .read_user_command_line_done
|
je .read_user_command_line_done
|
||||||
|
|
||||||
movb %al, %bl
|
pushw %ax
|
||||||
|
|
||||||
call isprint
|
call isprint
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .read_user_command_line_loop
|
jz .read_user_command_line_loop
|
||||||
|
|
||||||
movb %bl, %al
|
popw %ax
|
||||||
|
|
||||||
# put byte to buffer
|
# put byte to buffer
|
||||||
movb %al, (%di)
|
movb %al, (%di)
|
||||||
|
|||||||
@@ -108,11 +108,9 @@ vesa_find_video_mode:
|
|||||||
cmpb $0x4F, %al; jne .vesa_unsupported
|
cmpb $0x4F, %al; jne .vesa_unsupported
|
||||||
cmpb $0x00, %ah; jne .vesa_error
|
cmpb $0x00, %ah; jne .vesa_error
|
||||||
|
|
||||||
# check whether in graphics mode and linear framebuffer
|
# check whether in graphics mode
|
||||||
movb (vesa_mode_info_buffer + 0), %al
|
testb $0x10, (vesa_mode_info_buffer + 0)
|
||||||
andb $(0x80 | 0x10), %al
|
jz .vesa_find_video_mode_next_mode
|
||||||
cmpb $(0x80 | 0x10), %al
|
|
||||||
jne .vesa_find_video_mode_next_mode
|
|
||||||
|
|
||||||
# compare mode's dimensions
|
# compare mode's dimensions
|
||||||
movw -2(%ebp), %ax; cmpw %ax, (vesa_mode_info_buffer + 0x12)
|
movw -2(%ebp), %ax; cmpw %ax, (vesa_mode_info_buffer + 0x12)
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
.section .stage2
|
.section .stage2
|
||||||
|
|
||||||
.set mmap_entry_size, 24
|
|
||||||
|
|
||||||
# fills memory map data structure
|
# fills memory map data structure
|
||||||
# doesn't return on error
|
# doesn't return on error
|
||||||
# NO REGISTERS SAVED
|
# NO REGISTERS SAVED
|
||||||
@@ -14,7 +12,7 @@ get_memory_map:
|
|||||||
movl $0x0000E820, %eax
|
movl $0x0000E820, %eax
|
||||||
movl $0x534D4150, %edx
|
movl $0x534D4150, %edx
|
||||||
xorl %ebx, %ebx
|
xorl %ebx, %ebx
|
||||||
movl $mmap_entry_size, %ecx
|
movl $20, %ecx
|
||||||
movw $memory_map_entries, %di
|
movw $memory_map_entries, %di
|
||||||
|
|
||||||
clc
|
clc
|
||||||
@@ -26,15 +24,15 @@ get_memory_map:
|
|||||||
cmpl $0x534D4150, %eax
|
cmpl $0x534D4150, %eax
|
||||||
jne .get_memory_map_error
|
jne .get_memory_map_error
|
||||||
|
|
||||||
# confirm that we got at least 20 bytes
|
# FIXME: don't assume BIOS to always return 20 bytes
|
||||||
cmpl $20, %ecx
|
cmpl $20, %ecx
|
||||||
jl .get_memory_map_error
|
jne .get_memory_map_error
|
||||||
|
|
||||||
# increment entry count
|
# increment entry count
|
||||||
incl (memory_map_entry_count)
|
incl (memory_map_entry_count)
|
||||||
|
|
||||||
# increment entry pointer
|
# increment entry pointer
|
||||||
addw $mmap_entry_size, %di
|
addw %cx, %di
|
||||||
|
|
||||||
# BIOS can indicate end of list by 0 in ebx
|
# BIOS can indicate end of list by 0 in ebx
|
||||||
testl %ebx, %ebx
|
testl %ebx, %ebx
|
||||||
@@ -109,7 +107,7 @@ print_memory_map:
|
|||||||
|
|
||||||
call print_newline
|
call print_newline
|
||||||
|
|
||||||
addw $mmap_entry_size, %si
|
addw $20, %si
|
||||||
|
|
||||||
decl %edx
|
decl %edx
|
||||||
jnz .loop_memory_map
|
jnz .loop_memory_map
|
||||||
@@ -129,8 +127,6 @@ memory_map_error_msg:
|
|||||||
memory_map:
|
memory_map:
|
||||||
memory_map_entry_count:
|
memory_map_entry_count:
|
||||||
.skip 4
|
.skip 4
|
||||||
memory_map_padding:
|
# 100 entries should be enough...
|
||||||
.skip 4
|
|
||||||
# 128 entries should be enough...
|
|
||||||
memory_map_entries:
|
memory_map_entries:
|
||||||
.skip mmap_entry_size * 128
|
.skip 20 * 100
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ set(KERNEL_SOURCES
|
|||||||
kernel/Audio/Controller.cpp
|
kernel/Audio/Controller.cpp
|
||||||
kernel/Audio/HDAudio/AudioFunctionGroup.cpp
|
kernel/Audio/HDAudio/AudioFunctionGroup.cpp
|
||||||
kernel/Audio/HDAudio/Controller.cpp
|
kernel/Audio/HDAudio/Controller.cpp
|
||||||
kernel/Banos.cpp
|
|
||||||
kernel/BootInfo.cpp
|
kernel/BootInfo.cpp
|
||||||
kernel/CPUID.cpp
|
kernel/CPUID.cpp
|
||||||
kernel/Credentials.cpp
|
kernel/Credentials.cpp
|
||||||
@@ -41,7 +40,6 @@ set(KERNEL_SOURCES
|
|||||||
kernel/FS/USTARModule.cpp
|
kernel/FS/USTARModule.cpp
|
||||||
kernel/FS/VirtualFileSystem.cpp
|
kernel/FS/VirtualFileSystem.cpp
|
||||||
kernel/GDT.cpp
|
kernel/GDT.cpp
|
||||||
kernel/Graphics/BGA.cpp
|
|
||||||
kernel/IDT.cpp
|
kernel/IDT.cpp
|
||||||
kernel/Input/InputDevice.cpp
|
kernel/Input/InputDevice.cpp
|
||||||
kernel/Input/PS2/Controller.cpp
|
kernel/Input/PS2/Controller.cpp
|
||||||
@@ -52,8 +50,6 @@ set(KERNEL_SOURCES
|
|||||||
kernel/Interruptable.cpp
|
kernel/Interruptable.cpp
|
||||||
kernel/InterruptController.cpp
|
kernel/InterruptController.cpp
|
||||||
kernel/kernel.cpp
|
kernel/kernel.cpp
|
||||||
kernel/Lock/Mutex.cpp
|
|
||||||
kernel/Lock/RWLock.cpp
|
|
||||||
kernel/Lock/SpinLock.cpp
|
kernel/Lock/SpinLock.cpp
|
||||||
kernel/Memory/ByteRingBuffer.cpp
|
kernel/Memory/ByteRingBuffer.cpp
|
||||||
kernel/Memory/DMARegion.cpp
|
kernel/Memory/DMARegion.cpp
|
||||||
@@ -86,7 +82,6 @@ set(KERNEL_SOURCES
|
|||||||
kernel/Processor.cpp
|
kernel/Processor.cpp
|
||||||
kernel/Random.cpp
|
kernel/Random.cpp
|
||||||
kernel/Scheduler.cpp
|
kernel/Scheduler.cpp
|
||||||
kernel/SchedulerThreadNode.cpp
|
|
||||||
kernel/SSP.cpp
|
kernel/SSP.cpp
|
||||||
kernel/Storage/ATA/AHCI/Controller.cpp
|
kernel/Storage/ATA/AHCI/Controller.cpp
|
||||||
kernel/Storage/ATA/AHCI/Device.cpp
|
kernel/Storage/ATA/AHCI/Device.cpp
|
||||||
@@ -126,7 +121,6 @@ set(KERNEL_SOURCES
|
|||||||
kernel/USB/USBManager.cpp
|
kernel/USB/USBManager.cpp
|
||||||
kernel/USB/XHCI/Controller.cpp
|
kernel/USB/XHCI/Controller.cpp
|
||||||
kernel/USB/XHCI/Device.cpp
|
kernel/USB/XHCI/Device.cpp
|
||||||
kernel/UserCopy.cpp
|
|
||||||
icxxabi.cpp
|
icxxabi.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ namespace Kernel
|
|||||||
constexpr uint64_t s_page_flag_mask = 0x8000000000000FFF;
|
constexpr uint64_t s_page_flag_mask = 0x8000000000000FFF;
|
||||||
constexpr uint64_t s_page_addr_mask = ~s_page_flag_mask;
|
constexpr uint64_t s_page_addr_mask = ~s_page_flag_mask;
|
||||||
|
|
||||||
|
static bool s_is_initialized = false;
|
||||||
|
|
||||||
static PageTable* s_kernel = nullptr;
|
static PageTable* s_kernel = nullptr;
|
||||||
static bool s_has_nxe = false;
|
static bool s_has_nxe = false;
|
||||||
static bool s_has_pge = false;
|
static bool s_has_pge = false;
|
||||||
@@ -258,11 +260,7 @@ namespace Kernel
|
|||||||
|
|
||||||
ASSERT(index < 512);
|
ASSERT(index < 512);
|
||||||
ASSERT(s_fast_page_pt);
|
ASSERT(s_fast_page_pt);
|
||||||
|
|
||||||
if (index < reserved_fast_pages)
|
|
||||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||||
else
|
|
||||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
|
||||||
|
|
||||||
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
||||||
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
||||||
@@ -276,11 +274,7 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
ASSERT(index < 512);
|
ASSERT(index < 512);
|
||||||
ASSERT(s_fast_page_pt);
|
ASSERT(s_fast_page_pt);
|
||||||
|
|
||||||
if (index < reserved_fast_pages)
|
|
||||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||||
else
|
|
||||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
|
||||||
|
|
||||||
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
||||||
s_fast_page_pt[index] = 0;
|
s_fast_page_pt[index] = 0;
|
||||||
@@ -347,10 +341,32 @@ namespace Kernel
|
|||||||
const bool is_userspace = (vaddr < KERNEL_OFFSET);
|
const bool is_userspace = (vaddr < KERNEL_OFFSET);
|
||||||
if (is_userspace && this != &PageTable::current())
|
if (is_userspace && this != &PageTable::current())
|
||||||
;
|
;
|
||||||
else if (pages >= full_tlb_flush_threshold)
|
else if (pages <= 32 || !s_is_initialized)
|
||||||
invalidate_full_address_space(!is_userspace);
|
{
|
||||||
else for (size_t i = 0; i < pages; i++)
|
for (size_t i = 0; i < pages; i++)
|
||||||
asm volatile("invlpg (%0)" :: "r"(vaddr + i * PAGE_SIZE));
|
asm volatile("invlpg (%0)" :: "r"(vaddr + i * PAGE_SIZE));
|
||||||
|
}
|
||||||
|
else if (is_userspace || !s_has_pge)
|
||||||
|
{
|
||||||
|
asm volatile("movl %0, %%cr3" :: "r"(static_cast<uint32_t>(m_highest_paging_struct)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"movl %%cr4, %%eax;"
|
||||||
|
|
||||||
|
"andl $~0x80, %%eax;"
|
||||||
|
"movl %%eax, %%cr4;"
|
||||||
|
|
||||||
|
"movl %0, %%cr3;"
|
||||||
|
|
||||||
|
"orl $0x80, %%eax;"
|
||||||
|
"movl %%eax, %%cr4;"
|
||||||
|
:
|
||||||
|
: "r"(static_cast<uint32_t>(m_highest_paging_struct))
|
||||||
|
: "eax"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (send_smp_message)
|
if (send_smp_message)
|
||||||
{
|
{
|
||||||
@@ -365,34 +381,6 @@ namespace Kernel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::invalidate_full_address_space(bool global)
|
|
||||||
{
|
|
||||||
if (!global || !s_has_pge)
|
|
||||||
{
|
|
||||||
asm volatile(
|
|
||||||
"movl %%cr3, %%eax;"
|
|
||||||
"movl %%eax, %%cr3;"
|
|
||||||
::: "eax"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
asm volatile(
|
|
||||||
"movl %%cr4, %%eax;"
|
|
||||||
|
|
||||||
"andl $~0x80, %%eax;"
|
|
||||||
"movl %%eax, %%cr4;"
|
|
||||||
|
|
||||||
"movl %%cr3, %%ecx;"
|
|
||||||
"movl %%ecx, %%cr3;"
|
|
||||||
|
|
||||||
"orl $0x80, %%eax;"
|
|
||||||
"movl %%eax, %%cr4;"
|
|
||||||
::: "eax", "ecx"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTable::unmap_page(vaddr_t vaddr, bool invalidate)
|
void PageTable::unmap_page(vaddr_t vaddr, bool invalidate)
|
||||||
{
|
{
|
||||||
ASSERT(vaddr);
|
ASSERT(vaddr);
|
||||||
@@ -609,24 +597,30 @@ namespace Kernel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::reserve_page(vaddr_t vaddr)
|
bool PageTable::reserve_page(vaddr_t vaddr, bool only_free, bool send_smp_message)
|
||||||
{
|
{
|
||||||
ASSERT(vaddr % PAGE_SIZE == 0);
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
ASSERT(is_page_free(vaddr));
|
ASSERT(vaddr % PAGE_SIZE == 0);
|
||||||
map_page_at(0, vaddr, Flags::Reserved, MemoryType::Normal, false);
|
if (only_free && !is_page_free(vaddr))
|
||||||
|
return false;
|
||||||
|
map_page_at(0, vaddr, Flags::Reserved, MemoryType::Normal, send_smp_message);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::reserve_range(vaddr_t vaddr, size_t bytes)
|
bool PageTable::reserve_range(vaddr_t vaddr, size_t bytes, bool only_free)
|
||||||
{
|
{
|
||||||
if (size_t rem = bytes % PAGE_SIZE)
|
if (size_t rem = bytes % PAGE_SIZE)
|
||||||
bytes += PAGE_SIZE - rem;
|
bytes += PAGE_SIZE - rem;
|
||||||
ASSERT(vaddr % PAGE_SIZE == 0);
|
ASSERT(vaddr % PAGE_SIZE == 0);
|
||||||
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
ASSERT(is_range_free(vaddr, bytes));
|
if (only_free && !is_range_free(vaddr, bytes))
|
||||||
|
return false;
|
||||||
for (size_t offset = 0; offset < bytes; offset += PAGE_SIZE)
|
for (size_t offset = 0; offset < bytes; offset += PAGE_SIZE)
|
||||||
reserve_page(vaddr + offset);
|
reserve_page(vaddr + offset, true, false);
|
||||||
|
invalidate_range(vaddr, bytes / PAGE_SIZE, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vaddr_t PageTable::reserve_free_page(vaddr_t first_address, vaddr_t last_address)
|
vaddr_t PageTable::reserve_free_page(vaddr_t first_address, vaddr_t last_address)
|
||||||
@@ -681,7 +675,7 @@ namespace Kernel
|
|||||||
vaddr |= (vaddr_t)pdpte << 30;
|
vaddr |= (vaddr_t)pdpte << 30;
|
||||||
vaddr |= (vaddr_t)pde << 21;
|
vaddr |= (vaddr_t)pde << 21;
|
||||||
vaddr |= (vaddr_t)pte << 12;
|
vaddr |= (vaddr_t)pte << 12;
|
||||||
reserve_page(vaddr);
|
ASSERT(reserve_page(vaddr));
|
||||||
return vaddr;
|
return vaddr;
|
||||||
}
|
}
|
||||||
unmap_fast_page(2);
|
unmap_fast_page(2);
|
||||||
@@ -699,7 +693,7 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
if (is_page_free(vaddr))
|
if (is_page_free(vaddr))
|
||||||
{
|
{
|
||||||
reserve_page(vaddr);
|
ASSERT(reserve_page(vaddr));
|
||||||
return vaddr;
|
return vaddr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -732,7 +726,7 @@ namespace Kernel
|
|||||||
}
|
}
|
||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
reserve_range(vaddr, page_count * PAGE_SIZE);
|
ASSERT(reserve_range(vaddr, page_count * PAGE_SIZE));
|
||||||
return vaddr;
|
return vaddr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ signal_trampoline:
|
|||||||
addl $24, %esp
|
addl $24, %esp
|
||||||
|
|
||||||
// restore sigmask
|
// restore sigmask
|
||||||
movl $79, %eax // SYS_SIGPROCMASK
|
movl $83, %eax // SYS_SIGPROCMASK
|
||||||
movl $3, %ebx // SIG_SETMASK
|
movl $3, %ebx // SIG_SETMASK
|
||||||
leal 72(%esp), %ecx // set
|
leal 72(%esp), %ecx // set
|
||||||
xorl %edx, %edx // oset
|
xorl %edx, %edx // oset
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ sys_fork_trampoline:
|
|||||||
|
|
||||||
call read_ip
|
call read_ip
|
||||||
testl %eax, %eax
|
testl %eax, %eax
|
||||||
jz .Lsys_fork_trampoline_done
|
jz .done
|
||||||
|
|
||||||
movl %esp, %ebx
|
movl %esp, %ebx
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ sys_fork_trampoline:
|
|||||||
call sys_fork
|
call sys_fork
|
||||||
addl $16, %esp
|
addl $16, %esp
|
||||||
|
|
||||||
.Lsys_fork_trampoline_done:
|
.done:
|
||||||
popl %edi
|
popl %edi
|
||||||
popl %esi
|
popl %esi
|
||||||
popl %ebx
|
popl %ebx
|
||||||
|
|||||||
@@ -28,26 +28,27 @@ safe_user_strncpy:
|
|||||||
testl %ecx, %ecx
|
testl %ecx, %ecx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.Lsafe_user_strncpy_loop:
|
.safe_user_strncpy_loop:
|
||||||
movb (%esi), %al
|
movb (%esi), %al
|
||||||
movb %al, (%edi)
|
movb %al, (%edi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .Lsafe_user_strncpy_done
|
jz .safe_user_strncpy_done
|
||||||
|
|
||||||
incl %edi
|
incl %edi
|
||||||
incl %esi
|
incl %esi
|
||||||
decl %ecx
|
decl %ecx
|
||||||
jnz .Lsafe_user_strncpy_loop
|
jnz .safe_user_strncpy_loop
|
||||||
|
|
||||||
safe_user_strncpy_fault:
|
safe_user_strncpy_fault:
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
jmp .Lsafe_user_strncpy_return
|
jmp .safe_user_strncpy_return
|
||||||
|
|
||||||
.Lsafe_user_strncpy_done:
|
.safe_user_strncpy_done:
|
||||||
movl $1, %eax
|
movl $1, %eax
|
||||||
|
|
||||||
.Lsafe_user_strncpy_return:
|
.safe_user_strncpy_return:
|
||||||
movl 4(%esp), %edi
|
movl 4(%esp), %edi
|
||||||
movl 8(%esp), %esi
|
movl 8(%esp), %esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
safe_user_strncpy_end:
|
safe_user_strncpy_end:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ asm_yield_trampoline:
|
|||||||
pushl %ebp
|
pushl %ebp
|
||||||
|
|
||||||
pushl %esp
|
pushl %esp
|
||||||
call scheduler_on_yield_trampoline
|
call scheduler_on_yield
|
||||||
addl $4, %esp
|
addl $4, %esp
|
||||||
|
|
||||||
popl %ebp
|
popl %ebp
|
||||||
|
|||||||
+17
-15
@@ -168,12 +168,14 @@ has_sse:
|
|||||||
|
|
||||||
check_requirements:
|
check_requirements:
|
||||||
call has_cpuid
|
call has_cpuid
|
||||||
jz system_halt
|
jz .exit
|
||||||
call has_pae
|
call has_pae
|
||||||
jz system_halt
|
jz .exit
|
||||||
call has_sse
|
call has_sse
|
||||||
jz system_halt
|
jz .exit
|
||||||
ret
|
ret
|
||||||
|
.exit:
|
||||||
|
jmp system_halt
|
||||||
|
|
||||||
enable_sse:
|
enable_sse:
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
@@ -223,8 +225,8 @@ _start:
|
|||||||
|
|
||||||
# load boot GDT
|
# load boot GDT
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $V2P(.Lgdt_flush)
|
ljmpl $0x08, $V2P(gdt_flush)
|
||||||
.Lgdt_flush:
|
gdt_flush:
|
||||||
# set correct segment registers
|
# set correct segment registers
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
@@ -241,10 +243,10 @@ _start:
|
|||||||
movl $g_boot_stack_top, %esp
|
movl $g_boot_stack_top, %esp
|
||||||
|
|
||||||
# jump to higher half
|
# jump to higher half
|
||||||
leal .Lhigher_half, %ecx
|
leal higher_half, %ecx
|
||||||
jmp *%ecx
|
jmp *%ecx
|
||||||
|
|
||||||
.Lhigher_half:
|
higher_half:
|
||||||
# call global constuctors
|
# call global constuctors
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
@@ -296,18 +298,18 @@ ap_ready:
|
|||||||
.skip 4
|
.skip 4
|
||||||
|
|
||||||
1: cli; cld
|
1: cli; cld
|
||||||
ljmpl $0x00, $AP_REL(.Lap_cs_clear)
|
ljmpl $0x00, $AP_REL(ap_cs_clear)
|
||||||
|
|
||||||
.Lap_cs_clear:
|
ap_cs_clear:
|
||||||
# load ap gdt and enter protected mode
|
# load ap gdt and enter protected mode
|
||||||
lgdt AP_REL(ap_gdtr)
|
lgdt AP_REL(ap_gdtr)
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
orb $1, %al
|
orb $1, %al
|
||||||
movl %eax, %cr0
|
movl %eax, %cr0
|
||||||
ljmpl $0x08, $AP_REL(.Lap_protected_mode)
|
ljmpl $0x08, $AP_REL(ap_protected_mode)
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
.Lap_protected_mode:
|
ap_protected_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -321,13 +323,13 @@ ap_ready:
|
|||||||
|
|
||||||
# load boot gdt and enter long mode
|
# load boot gdt and enter long mode
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $AP_REL(.Lap_flush_gdt)
|
ljmpl $0x08, $AP_REL(ap_flush_gdt)
|
||||||
|
|
||||||
.Lap_flush_gdt:
|
ap_flush_gdt:
|
||||||
movl $.Lap_higher_half, %ecx
|
movl $ap_higher_half, %ecx
|
||||||
jmp *%ecx
|
jmp *%ecx
|
||||||
|
|
||||||
.Lap_higher_half:
|
ap_higher_half:
|
||||||
movl AP_REL(ap_prepare_paging), %eax
|
movl AP_REL(ap_prepare_paging), %eax
|
||||||
call *%eax
|
call *%eax
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,14 @@
|
|||||||
|
|
||||||
isr_stub:
|
isr_stub:
|
||||||
intr_header 12
|
intr_header 12
|
||||||
|
movl %cr0, %eax; pushl %eax
|
||||||
|
movl %cr2, %eax; pushl %eax
|
||||||
|
movl %cr3, %eax; pushl %eax
|
||||||
|
movl %cr4, %eax; pushl %eax
|
||||||
|
|
||||||
movl 32(%esp), %edi // isr number
|
movl 48(%esp), %edi // isr number
|
||||||
movl 36(%esp), %esi // error code
|
movl 52(%esp), %esi // error code
|
||||||
leal 40(%esp), %edx // interrupt stack ptr
|
leal 56(%esp), %edx // interrupt stack ptr
|
||||||
movl %esp, %ecx // register ptr
|
movl %esp, %ecx // register ptr
|
||||||
|
|
||||||
# stack frame for stack trace
|
# stack frame for stack trace
|
||||||
@@ -48,7 +52,7 @@ isr_stub:
|
|||||||
call cpp_isr_handler
|
call cpp_isr_handler
|
||||||
|
|
||||||
movl %ebp, %esp
|
movl %ebp, %esp
|
||||||
addl $8, %esp
|
addl $24, %esp
|
||||||
|
|
||||||
intr_footer 12
|
intr_footer 12
|
||||||
addl $8, %esp
|
addl $8, %esp
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace Kernel
|
|||||||
SpinLock PageTable::s_fast_page_lock;
|
SpinLock PageTable::s_fast_page_lock;
|
||||||
|
|
||||||
static constexpr vaddr_t s_hhdm_offset = 0xFFFF800000000000;
|
static constexpr vaddr_t s_hhdm_offset = 0xFFFF800000000000;
|
||||||
|
static bool s_is_initialized = false;
|
||||||
|
|
||||||
constexpr uint64_t s_page_flag_mask = 0x8000000000000FFF;
|
constexpr uint64_t s_page_flag_mask = 0x8000000000000FFF;
|
||||||
constexpr uint64_t s_page_addr_mask = ~s_page_flag_mask;
|
constexpr uint64_t s_page_addr_mask = ~s_page_flag_mask;
|
||||||
@@ -382,11 +383,7 @@ namespace Kernel
|
|||||||
|
|
||||||
ASSERT(index < 512);
|
ASSERT(index < 512);
|
||||||
ASSERT(s_fast_page_pt);
|
ASSERT(s_fast_page_pt);
|
||||||
|
|
||||||
if (index < reserved_fast_pages)
|
|
||||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||||
else
|
|
||||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
|
||||||
|
|
||||||
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
||||||
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
||||||
@@ -400,11 +397,7 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
ASSERT(index < 512);
|
ASSERT(index < 512);
|
||||||
ASSERT(s_fast_page_pt);
|
ASSERT(s_fast_page_pt);
|
||||||
|
|
||||||
if (index < reserved_fast_pages)
|
|
||||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||||
else
|
|
||||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
|
||||||
|
|
||||||
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
||||||
s_fast_page_pt[index] = 0;
|
s_fast_page_pt[index] = 0;
|
||||||
@@ -477,10 +470,32 @@ namespace Kernel
|
|||||||
const bool is_userspace = (vaddr < KERNEL_OFFSET);
|
const bool is_userspace = (vaddr < KERNEL_OFFSET);
|
||||||
if (is_userspace && this != &PageTable::current())
|
if (is_userspace && this != &PageTable::current())
|
||||||
;
|
;
|
||||||
else if (pages >= full_tlb_flush_threshold)
|
else if (pages <= 32 || !s_is_initialized)
|
||||||
invalidate_full_address_space(!is_userspace);
|
{
|
||||||
else for (size_t i = 0; i < pages; i++)
|
for (size_t i = 0; i < pages; i++)
|
||||||
asm volatile("invlpg (%0)" :: "r"(vaddr + i * PAGE_SIZE));
|
asm volatile("invlpg (%0)" :: "r"(vaddr + i * PAGE_SIZE));
|
||||||
|
}
|
||||||
|
else if (is_userspace || !s_has_pge)
|
||||||
|
{
|
||||||
|
asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
asm volatile(
|
||||||
|
"movq %%cr4, %%rax;"
|
||||||
|
|
||||||
|
"andq $~0x80, %%rax;"
|
||||||
|
"movq %%rax, %%cr4;"
|
||||||
|
|
||||||
|
"movq %0, %%cr3;"
|
||||||
|
|
||||||
|
"orq $0x80, %%rax;"
|
||||||
|
"movq %%rax, %%cr4;"
|
||||||
|
:
|
||||||
|
: "r"(m_highest_paging_struct)
|
||||||
|
: "rax"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (send_smp_message)
|
if (send_smp_message)
|
||||||
{
|
{
|
||||||
@@ -495,34 +510,6 @@ namespace Kernel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::invalidate_full_address_space(bool global)
|
|
||||||
{
|
|
||||||
if (!global || !s_has_pge)
|
|
||||||
{
|
|
||||||
asm volatile(
|
|
||||||
"movq %%cr3, %%rax;"
|
|
||||||
"movq %%rax, %%cr3;"
|
|
||||||
::: "rax"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
asm volatile(
|
|
||||||
"movq %%cr4, %%rax;"
|
|
||||||
|
|
||||||
"andq $~0x80, %%rax;"
|
|
||||||
"movq %%rax, %%cr4;"
|
|
||||||
|
|
||||||
"movq %%cr3, %%rcx;"
|
|
||||||
"movq %%rcx, %%cr3;"
|
|
||||||
|
|
||||||
"orq $0x80, %%rax;"
|
|
||||||
"movq %%rax, %%cr4;"
|
|
||||||
::: "rax", "rcx"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PageTable::unmap_page(vaddr_t vaddr, bool invalidate)
|
void PageTable::unmap_page(vaddr_t vaddr, bool invalidate)
|
||||||
{
|
{
|
||||||
ASSERT(vaddr);
|
ASSERT(vaddr);
|
||||||
@@ -564,70 +551,12 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
ASSERT(vaddr % PAGE_SIZE == 0);
|
ASSERT(vaddr % PAGE_SIZE == 0);
|
||||||
|
|
||||||
ASSERT(is_canonical(vaddr));
|
const size_t page_count = range_page_count(vaddr, size);
|
||||||
ASSERT(is_canonical(vaddr + size - 1));
|
|
||||||
|
|
||||||
const vaddr_t uc_vaddr_start = uncanonicalize(vaddr);
|
|
||||||
const vaddr_t uc_vaddr_end = uncanonicalize(vaddr + size - 1);
|
|
||||||
|
|
||||||
uint16_t pml4e = (uc_vaddr_start >> 39) & 0x1FF;
|
|
||||||
uint16_t pdpte = (uc_vaddr_start >> 30) & 0x1FF;
|
|
||||||
uint16_t pde = (uc_vaddr_start >> 21) & 0x1FF;
|
|
||||||
uint16_t pte = (uc_vaddr_start >> 12) & 0x1FF;
|
|
||||||
|
|
||||||
const uint16_t e_pml4e = (uc_vaddr_end >> 39) & 0x1FF;
|
|
||||||
const uint16_t e_pdpte = (uc_vaddr_end >> 30) & 0x1FF;
|
|
||||||
const uint16_t e_pde = (uc_vaddr_end >> 21) & 0x1FF;
|
|
||||||
const uint16_t e_pte = (uc_vaddr_end >> 12) & 0x1FF;
|
|
||||||
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
|
for (vaddr_t page = 0; page < page_count; page++)
|
||||||
uint64_t* pml4 = P2V(m_highest_paging_struct);
|
unmap_page(vaddr + page * PAGE_SIZE, false);
|
||||||
for (; pml4e <= e_pml4e; pml4e++)
|
invalidate_range(vaddr, page_count, true);
|
||||||
{
|
|
||||||
#define UNALLOCATE_TABLE_IF_EMPTY(outer, inner) \
|
|
||||||
if (old_##inner##e == 0 && inner##e == 512) { \
|
|
||||||
unallocate_page(outer[outer##e] & s_page_addr_mask); \
|
|
||||||
outer[outer##e] = 0; \
|
|
||||||
}
|
|
||||||
if (!(pml4[pml4e] & Flags::Present))
|
|
||||||
continue;
|
|
||||||
const uint16_t old_pdpte = pdpte;
|
|
||||||
uint64_t* pdpt = P2V(pml4[pml4e] & s_page_addr_mask);
|
|
||||||
for (; pdpte < 512; pdpte++)
|
|
||||||
{
|
|
||||||
if (pml4e == e_pml4e && pdpte > e_pdpte)
|
|
||||||
break;
|
|
||||||
if (!(pdpt[pdpte] & Flags::Present))
|
|
||||||
continue;
|
|
||||||
const uint16_t old_pde = pde;
|
|
||||||
uint64_t* pd = P2V(pdpt[pdpte] & s_page_addr_mask);
|
|
||||||
for (; pde < 512; pde++)
|
|
||||||
{
|
|
||||||
if (pml4e == e_pml4e && pdpte == e_pdpte && pde > e_pde)
|
|
||||||
break;
|
|
||||||
if (!(pd[pde] & Flags::Present))
|
|
||||||
continue;
|
|
||||||
const uint16_t old_pte = pte;
|
|
||||||
uint64_t* pt = P2V(pd[pde] & s_page_addr_mask);
|
|
||||||
for (; pte < 512; pte++)
|
|
||||||
{
|
|
||||||
if (pml4e == e_pml4e && pdpte == e_pdpte && pde == e_pde && pte > e_pte)
|
|
||||||
break;
|
|
||||||
pt[pte] = 0;
|
|
||||||
}
|
|
||||||
UNALLOCATE_TABLE_IF_EMPTY(pd, pt);
|
|
||||||
pte = 0;
|
|
||||||
}
|
|
||||||
UNALLOCATE_TABLE_IF_EMPTY(pdpt, pd);
|
|
||||||
pde = 0;
|
|
||||||
}
|
|
||||||
UNALLOCATE_TABLE_IF_EMPTY(pml4, pdpt);
|
|
||||||
pdpte = 0;
|
|
||||||
#undef UNALLOCATE_TABLE_IF_EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidate_range(vaddr, range_page_count(vaddr, size), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::map_page_at(paddr_t paddr, vaddr_t vaddr, flags_t flags, MemoryType memory_type, bool invalidate)
|
void PageTable::map_page_at(paddr_t paddr, vaddr_t vaddr, flags_t flags, MemoryType memory_type, bool invalidate)
|
||||||
@@ -817,71 +746,29 @@ namespace Kernel
|
|||||||
return get_page_data(addr) & s_page_addr_mask;
|
return get_page_data(addr) & s_page_addr_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::reserve_page(vaddr_t vaddr)
|
bool PageTable::reserve_page(vaddr_t vaddr, bool only_free, bool invalidate)
|
||||||
{
|
{
|
||||||
ASSERT(vaddr % PAGE_SIZE == 0);
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
ASSERT(is_page_free(vaddr));
|
ASSERT(vaddr % PAGE_SIZE == 0);
|
||||||
map_page_at(0, vaddr, Flags::Reserved, MemoryType::Normal, false);
|
if (only_free && !is_page_free(vaddr))
|
||||||
|
return false;
|
||||||
|
map_page_at(0, vaddr, Flags::Reserved, MemoryType::Normal, invalidate);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageTable::reserve_range(vaddr_t vaddr, size_t bytes)
|
bool PageTable::reserve_range(vaddr_t vaddr, size_t bytes, bool only_free)
|
||||||
{
|
{
|
||||||
if (size_t rem = bytes % PAGE_SIZE)
|
if (size_t rem = bytes % PAGE_SIZE)
|
||||||
bytes += PAGE_SIZE - rem;
|
bytes += PAGE_SIZE - rem;
|
||||||
ASSERT(vaddr % PAGE_SIZE == 0);
|
ASSERT(vaddr % PAGE_SIZE == 0);
|
||||||
|
|
||||||
ASSERT(is_canonical(vaddr));
|
|
||||||
ASSERT(is_canonical(vaddr + bytes - 1));
|
|
||||||
|
|
||||||
const vaddr_t uc_vaddr_start = uncanonicalize(vaddr);
|
|
||||||
uint16_t pml4e = (uc_vaddr_start >> 39) & 0x1FF;
|
|
||||||
uint16_t pdpte = (uc_vaddr_start >> 30) & 0x1FF;
|
|
||||||
uint16_t pde = (uc_vaddr_start >> 21) & 0x1FF;
|
|
||||||
uint16_t pte = (uc_vaddr_start >> 12) & 0x1FF;
|
|
||||||
|
|
||||||
size_t pages_to_reserve = bytes / PAGE_SIZE;
|
|
||||||
ASSERT(pages_to_reserve);
|
|
||||||
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
|
if (only_free && !is_range_free(vaddr, bytes))
|
||||||
uint64_t* pml4 = P2V(m_highest_paging_struct);
|
return false;
|
||||||
for (;; pml4e++)
|
for (size_t offset = 0; offset < bytes; offset += PAGE_SIZE)
|
||||||
{
|
reserve_page(vaddr + offset, true, false);
|
||||||
#define CHECK_IF_PRESENT(expr) \
|
invalidate_range(vaddr, bytes / PAGE_SIZE, true);
|
||||||
if (!((expr) & Flags::Present)) { \
|
return true;
|
||||||
const paddr_t paddr = allocate_zeroed_page_aligned_page(); \
|
|
||||||
ASSERT(paddr); \
|
|
||||||
(expr) = paddr | Flags::Present; \
|
|
||||||
}
|
|
||||||
CHECK_IF_PRESENT(pml4[pml4e]);
|
|
||||||
uint64_t* pdpt = P2V(pml4[pml4e] & s_page_addr_mask);
|
|
||||||
for (; pdpte < 512; pdpte++)
|
|
||||||
{
|
|
||||||
CHECK_IF_PRESENT(pdpt[pdpte]);
|
|
||||||
uint64_t* pd = P2V(pdpt[pdpte] & s_page_addr_mask);
|
|
||||||
for (; pde < 512; pde++)
|
|
||||||
{
|
|
||||||
CHECK_IF_PRESENT(pd[pde]);
|
|
||||||
uint64_t* pt = P2V(pd[pde] & s_page_addr_mask);
|
|
||||||
for (; pte < 512; pte++)
|
|
||||||
{
|
|
||||||
ASSERT(!(pt[pte] & Flags::Used));
|
|
||||||
pt[pte] = Flags::Reserved;
|
|
||||||
|
|
||||||
pages_to_reserve--;
|
|
||||||
if (pages_to_reserve == 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pte = 0;
|
|
||||||
}
|
|
||||||
pde = 0;
|
|
||||||
}
|
|
||||||
pdpte = 0;
|
|
||||||
#undef CHECK_IF_PRESENT
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vaddr_t PageTable::reserve_free_page(vaddr_t first_address, vaddr_t last_address)
|
vaddr_t PageTable::reserve_free_page(vaddr_t first_address, vaddr_t last_address)
|
||||||
@@ -895,7 +782,6 @@ namespace Kernel
|
|||||||
|
|
||||||
ASSERT(is_canonical(first_address));
|
ASSERT(is_canonical(first_address));
|
||||||
ASSERT(is_canonical(last_address - 1));
|
ASSERT(is_canonical(last_address - 1));
|
||||||
|
|
||||||
const vaddr_t uc_vaddr_start = uncanonicalize(first_address);
|
const vaddr_t uc_vaddr_start = uncanonicalize(first_address);
|
||||||
const vaddr_t uc_vaddr_end = uncanonicalize(last_address - 1);
|
const vaddr_t uc_vaddr_end = uncanonicalize(last_address - 1);
|
||||||
|
|
||||||
@@ -945,7 +831,7 @@ namespace Kernel
|
|||||||
vaddr |= static_cast<uint64_t>(pde) << 21;
|
vaddr |= static_cast<uint64_t>(pde) << 21;
|
||||||
vaddr |= static_cast<uint64_t>(pte) << 12;
|
vaddr |= static_cast<uint64_t>(pte) << 12;
|
||||||
vaddr = canonicalize(vaddr);
|
vaddr = canonicalize(vaddr);
|
||||||
reserve_page(vaddr);
|
ASSERT(reserve_page(vaddr));
|
||||||
return vaddr;
|
return vaddr;
|
||||||
}
|
}
|
||||||
pte = 0;
|
pte = 0;
|
||||||
@@ -959,7 +845,7 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
if (vaddr_t vaddr = canonicalize(uc_vaddr); is_page_free(vaddr))
|
if (vaddr_t vaddr = canonicalize(uc_vaddr); is_page_free(vaddr))
|
||||||
{
|
{
|
||||||
reserve_page(vaddr);
|
ASSERT(reserve_page(vaddr));
|
||||||
return vaddr;
|
return vaddr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -969,90 +855,44 @@ namespace Kernel
|
|||||||
|
|
||||||
vaddr_t PageTable::reserve_free_contiguous_pages(size_t page_count, vaddr_t first_address, vaddr_t last_address)
|
vaddr_t PageTable::reserve_free_contiguous_pages(size_t page_count, vaddr_t first_address, vaddr_t last_address)
|
||||||
{
|
{
|
||||||
if (first_address >= KERNEL_OFFSET && first_address < reinterpret_cast<vaddr_t>(g_kernel_start))
|
if (first_address >= KERNEL_OFFSET && first_address < (vaddr_t)g_kernel_start)
|
||||||
first_address = reinterpret_cast<vaddr_t>(g_kernel_start);
|
first_address = (vaddr_t)g_kernel_start;
|
||||||
if (const auto rem = first_address % PAGE_SIZE)
|
if (size_t rem = first_address % PAGE_SIZE)
|
||||||
first_address += PAGE_SIZE - rem;
|
first_address += PAGE_SIZE - rem;
|
||||||
if (const auto rem = last_address % PAGE_SIZE)
|
if (size_t rem = last_address % PAGE_SIZE)
|
||||||
last_address -= rem;
|
last_address -= rem;
|
||||||
|
|
||||||
ASSERT(is_canonical(first_address));
|
ASSERT(is_canonical(first_address));
|
||||||
ASSERT(is_canonical(last_address - 1));
|
ASSERT(is_canonical(last_address - 1));
|
||||||
|
|
||||||
const vaddr_t uc_vaddr_start = uncanonicalize(first_address);
|
|
||||||
const vaddr_t uc_vaddr_end = uncanonicalize(last_address - 1);
|
|
||||||
|
|
||||||
uint16_t pml4e = (uc_vaddr_start >> 39) & 0x1FF;
|
|
||||||
uint16_t pdpte = (uc_vaddr_start >> 30) & 0x1FF;
|
|
||||||
uint16_t pde = (uc_vaddr_start >> 21) & 0x1FF;
|
|
||||||
uint16_t pte = (uc_vaddr_start >> 12) & 0x1FF;
|
|
||||||
|
|
||||||
const uint16_t e_pml4e = (uc_vaddr_end >> 39) & 0x1FF;
|
|
||||||
const uint16_t e_pdpte = (uc_vaddr_end >> 30) & 0x1FF;
|
|
||||||
const uint16_t e_pde = (uc_vaddr_end >> 21) & 0x1FF;
|
|
||||||
const uint16_t e_pte = (uc_vaddr_end >> 12) & 0x1FF;
|
|
||||||
|
|
||||||
vaddr_t vaddr = first_address;
|
|
||||||
size_t free_count = 0;
|
|
||||||
|
|
||||||
SpinLockGuard _(m_lock);
|
SpinLockGuard _(m_lock);
|
||||||
|
|
||||||
const uint64_t* pml4 = P2V(m_highest_paging_struct);
|
for (vaddr_t vaddr = first_address; vaddr < last_address;)
|
||||||
for (; pml4e <= e_pml4e; pml4e++)
|
|
||||||
{
|
{
|
||||||
#define CHECK_IF_PRESENT(expr, advance) \
|
bool valid { true };
|
||||||
if (!((expr) & Flags::Present)) { \
|
for (size_t page = 0; page < page_count; page++)
|
||||||
if ((free_count += advance) >= page_count) \
|
|
||||||
goto found_free_region; \
|
|
||||||
continue; \
|
|
||||||
}
|
|
||||||
CHECK_IF_PRESENT(pml4[pml4e], 512 * 512 * 512);
|
|
||||||
const uint64_t* pdpt = P2V(pml4[pml4e] & s_page_addr_mask);
|
|
||||||
for (; pdpte < 512; pdpte++)
|
|
||||||
{
|
{
|
||||||
if (pml4e == e_pml4e && pdpte > e_pdpte)
|
if (!is_canonical(vaddr + page * PAGE_SIZE))
|
||||||
|
{
|
||||||
|
vaddr = canonicalize(uncanonicalize(vaddr + page * PAGE_SIZE));
|
||||||
|
valid = false;
|
||||||
break;
|
break;
|
||||||
CHECK_IF_PRESENT(pdpt[pdpte], 512 * 512);
|
}
|
||||||
const uint64_t* pd = P2V(pdpt[pdpte] & s_page_addr_mask);
|
if (!is_page_free(vaddr + page * PAGE_SIZE))
|
||||||
for (; pde < 512; pde++)
|
|
||||||
{
|
{
|
||||||
if (pml4e == e_pml4e && pdpte == e_pdpte && pde > e_pde)
|
vaddr += (page + 1) * PAGE_SIZE;
|
||||||
|
valid = false;
|
||||||
break;
|
break;
|
||||||
CHECK_IF_PRESENT(pd[pde], 512);
|
}
|
||||||
uint64_t* pt = P2V(pd[pde] & s_page_addr_mask);
|
}
|
||||||
for (; pte < 512; pte++)
|
if (valid)
|
||||||
{
|
{
|
||||||
if (pml4e == e_pml4e && pdpte == e_pdpte && pde == e_pde && pte > e_pte)
|
ASSERT(reserve_range(vaddr, page_count * PAGE_SIZE));
|
||||||
break;
|
return vaddr;
|
||||||
if (!(pt[pte] & Flags::Used))
|
|
||||||
{
|
|
||||||
if (++free_count >= page_count)
|
|
||||||
goto found_free_region;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
vaddr = 0;
|
|
||||||
vaddr |= static_cast<uint64_t>(pml4e) << 39;
|
|
||||||
vaddr |= static_cast<uint64_t>(pdpte) << 30;
|
|
||||||
vaddr |= static_cast<uint64_t>(pde) << 21;
|
|
||||||
vaddr |= static_cast<uint64_t>(pte) << 12;
|
|
||||||
vaddr = canonicalize(vaddr + PAGE_SIZE);
|
|
||||||
free_count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pte = 0;
|
|
||||||
}
|
|
||||||
pde = 0;
|
|
||||||
}
|
|
||||||
pdpte = 0;
|
|
||||||
#undef CHECK_IF_PRESENT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
found_free_region:
|
|
||||||
reserve_range(vaddr, page_count * PAGE_SIZE);
|
|
||||||
return vaddr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageTable::is_page_free(vaddr_t page) const
|
bool PageTable::is_page_free(vaddr_t page) const
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ signal_trampoline:
|
|||||||
addq $40, %rsp
|
addq $40, %rsp
|
||||||
|
|
||||||
// restore sigmask
|
// restore sigmask
|
||||||
movq $79, %rdi // SYS_SIGPROCMASK
|
movq $83, %rdi // SYS_SIGPROCMASK
|
||||||
movq $3, %rsi // SIG_SETMASK
|
movq $3, %rsi // SIG_SETMASK
|
||||||
leaq 192(%rsp), %rdx // set
|
leaq 192(%rsp), %rdx // set
|
||||||
xorq %r10, %r10 // oset
|
xorq %r10, %r10 // oset
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ sys_fork_trampoline:
|
|||||||
|
|
||||||
call read_ip
|
call read_ip
|
||||||
testq %rax, %rax
|
testq %rax, %rax
|
||||||
jz .Lsys_fork_trampoline_done
|
jz .done
|
||||||
|
|
||||||
movq %rax, %rsi
|
movq %rax, %rsi
|
||||||
movq %rsp, %rdi
|
movq %rsp, %rdi
|
||||||
call sys_fork
|
call sys_fork
|
||||||
|
|
||||||
.Lsys_fork_trampoline_done:
|
.done:
|
||||||
popq %r15
|
popq %r15
|
||||||
popq %r14
|
popq %r14
|
||||||
popq %r13
|
popq %r13
|
||||||
|
|||||||
+14
-14
@@ -20,28 +20,28 @@ safe_user_strncpy:
|
|||||||
testq %rcx, %rcx
|
testq %rcx, %rcx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.Lsafe_user_strncpy_align_loop:
|
.safe_user_strncpy_align_loop:
|
||||||
testb $0x7, %sil
|
testb $0x7, %sil
|
||||||
jz .Lsafe_user_strncpy_align_done
|
jz .safe_user_strncpy_align_done
|
||||||
|
|
||||||
movb (%rsi), %al
|
movb (%rsi), %al
|
||||||
movb %al, (%rdi)
|
movb %al, (%rdi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .Lsafe_user_strncpy_done
|
jz .safe_user_strncpy_done
|
||||||
|
|
||||||
incq %rdi
|
incq %rdi
|
||||||
incq %rsi
|
incq %rsi
|
||||||
decq %rcx
|
decq %rcx
|
||||||
jnz .Lsafe_user_strncpy_align_loop
|
jnz .safe_user_strncpy_align_loop
|
||||||
jmp safe_user_strncpy_fault
|
jmp safe_user_strncpy_fault
|
||||||
|
|
||||||
.Lsafe_user_strncpy_align_done:
|
.safe_user_strncpy_align_done:
|
||||||
movq $0x0101010101010101, %r8
|
movq $0x0101010101010101, %r8
|
||||||
movq $0x8080808080808080, %r9
|
movq $0x8080808080808080, %r9
|
||||||
|
|
||||||
.Lsafe_user_strncpy_qword_loop:
|
.safe_user_strncpy_qword_loop:
|
||||||
cmpq $8, %rcx
|
cmpq $8, %rcx
|
||||||
jb .Lsafe_user_strncpy_qword_done
|
jb .safe_user_strncpy_qword_done
|
||||||
|
|
||||||
movq (%rsi), %rax
|
movq (%rsi), %rax
|
||||||
movq %rax, %r10
|
movq %rax, %r10
|
||||||
@@ -52,36 +52,36 @@ safe_user_strncpy:
|
|||||||
notq %r11
|
notq %r11
|
||||||
andq %r11, %r10
|
andq %r11, %r10
|
||||||
andq %r9, %r10
|
andq %r9, %r10
|
||||||
jnz .Lsafe_user_strncpy_byte_loop
|
jnz .safe_user_strncpy_byte_loop
|
||||||
|
|
||||||
movq %rax, (%rdi)
|
movq %rax, (%rdi)
|
||||||
|
|
||||||
addq $8, %rdi
|
addq $8, %rdi
|
||||||
addq $8, %rsi
|
addq $8, %rsi
|
||||||
subq $8, %rcx
|
subq $8, %rcx
|
||||||
jnz .Lsafe_user_strncpy_qword_loop
|
jnz .safe_user_strncpy_qword_loop
|
||||||
jmp safe_user_strncpy_fault
|
jmp safe_user_strncpy_fault
|
||||||
|
|
||||||
.Lsafe_user_strncpy_qword_done:
|
.safe_user_strncpy_qword_done:
|
||||||
testq %rcx, %rcx
|
testq %rcx, %rcx
|
||||||
jz safe_user_strncpy_fault
|
jz safe_user_strncpy_fault
|
||||||
|
|
||||||
.Lsafe_user_strncpy_byte_loop:
|
.safe_user_strncpy_byte_loop:
|
||||||
movb (%rsi), %al
|
movb (%rsi), %al
|
||||||
movb %al, (%rdi)
|
movb %al, (%rdi)
|
||||||
testb %al, %al
|
testb %al, %al
|
||||||
jz .Lsafe_user_strncpy_done
|
jz .safe_user_strncpy_done
|
||||||
|
|
||||||
incq %rdi
|
incq %rdi
|
||||||
incq %rsi
|
incq %rsi
|
||||||
decq %rcx
|
decq %rcx
|
||||||
jnz .Lsafe_user_strncpy_byte_loop
|
jnz .safe_user_strncpy_byte_loop
|
||||||
|
|
||||||
safe_user_strncpy_fault:
|
safe_user_strncpy_fault:
|
||||||
xorq %rax, %rax
|
xorq %rax, %rax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.Lsafe_user_strncpy_done:
|
.safe_user_strncpy_done:
|
||||||
movb $1, %al
|
movb $1, %al
|
||||||
ret
|
ret
|
||||||
safe_user_strncpy_end:
|
safe_user_strncpy_end:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ asm_yield_trampoline:
|
|||||||
pushq %r15
|
pushq %r15
|
||||||
|
|
||||||
movq %rsp, %rdi
|
movq %rsp, %rdi
|
||||||
call scheduler_on_yield_trampoline
|
call scheduler_on_yield
|
||||||
|
|
||||||
popq %r15
|
popq %r15
|
||||||
popq %r14
|
popq %r14
|
||||||
|
|||||||
+16
-14
@@ -161,10 +161,12 @@ is_64_bit:
|
|||||||
|
|
||||||
check_requirements:
|
check_requirements:
|
||||||
call has_cpuid
|
call has_cpuid
|
||||||
jz system_halt
|
jz .exit
|
||||||
call is_64_bit
|
call is_64_bit
|
||||||
jz system_halt
|
jz .exit
|
||||||
ret
|
ret
|
||||||
|
.exit:
|
||||||
|
jmp system_halt
|
||||||
|
|
||||||
enable_sse:
|
enable_sse:
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
@@ -224,10 +226,10 @@ _start:
|
|||||||
|
|
||||||
# flush gdt and jump to 64 bit
|
# flush gdt and jump to 64 bit
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $V2P(.Llong_mode)
|
ljmpl $0x08, $V2P(long_mode)
|
||||||
|
|
||||||
.code64
|
.code64
|
||||||
.Llong_mode:
|
long_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -238,10 +240,10 @@ _start:
|
|||||||
addq $KERNEL_OFFSET, %rsp
|
addq $KERNEL_OFFSET, %rsp
|
||||||
|
|
||||||
# jump to higher half
|
# jump to higher half
|
||||||
movabsq $.Lhigher_half, %rcx
|
movabsq $higher_half, %rcx
|
||||||
jmp *%rcx
|
jmp *%rcx
|
||||||
|
|
||||||
.Lhigher_half:
|
higher_half:
|
||||||
# call global constuctors
|
# call global constuctors
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
@@ -291,18 +293,18 @@ ap_ready:
|
|||||||
.skip 8
|
.skip 8
|
||||||
|
|
||||||
1: cli; cld
|
1: cli; cld
|
||||||
ljmpl $0x00, $AP_REL(.Lap_cs_clear)
|
ljmpl $0x00, $AP_REL(ap_cs_clear)
|
||||||
|
|
||||||
.Lap_cs_clear:
|
ap_cs_clear:
|
||||||
# load ap gdt and enter protected mode
|
# load ap gdt and enter protected mode
|
||||||
lgdt AP_REL(ap_gdtr)
|
lgdt AP_REL(ap_gdtr)
|
||||||
movl %cr0, %eax
|
movl %cr0, %eax
|
||||||
orb $1, %al
|
orb $1, %al
|
||||||
movl %eax, %cr0
|
movl %eax, %cr0
|
||||||
ljmpl $0x08, $AP_REL(.Lap_protected_mode)
|
ljmpl $0x08, $AP_REL(ap_protected_mode)
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
.Lap_protected_mode:
|
ap_protected_mode:
|
||||||
movw $0x10, %ax
|
movw $0x10, %ax
|
||||||
movw %ax, %ds
|
movw %ax, %ds
|
||||||
movw %ax, %ss
|
movw %ax, %ss
|
||||||
@@ -316,14 +318,14 @@ ap_ready:
|
|||||||
|
|
||||||
# load boot gdt and enter long mode
|
# load boot gdt and enter long mode
|
||||||
lgdt V2P(boot_gdtr)
|
lgdt V2P(boot_gdtr)
|
||||||
ljmpl $0x08, $AP_REL(.Lap_long_mode)
|
ljmpl $0x08, $AP_REL(ap_long_mode)
|
||||||
|
|
||||||
.code64
|
.code64
|
||||||
.Lap_long_mode:
|
ap_long_mode:
|
||||||
movq $.Lap_higher_half, %rax
|
movq $ap_higher_half, %rax
|
||||||
jmp *%rax
|
jmp *%rax
|
||||||
|
|
||||||
.Lap_higher_half:
|
ap_higher_half:
|
||||||
movq AP_REL(ap_prepare_paging), %rax
|
movq AP_REL(ap_prepare_paging), %rax
|
||||||
call *%rax
|
call *%rax
|
||||||
|
|
||||||
|
|||||||
@@ -44,12 +44,17 @@
|
|||||||
|
|
||||||
isr_stub:
|
isr_stub:
|
||||||
intr_header 24
|
intr_header 24
|
||||||
|
movq %cr0, %rax; pushq %rax
|
||||||
|
movq %cr2, %rax; pushq %rax
|
||||||
|
movq %cr3, %rax; pushq %rax
|
||||||
|
movq %cr4, %rax; pushq %rax
|
||||||
|
|
||||||
movq 120(%rsp), %rdi // isr number
|
movq 152(%rsp), %rdi // isr number
|
||||||
movq 128(%rsp), %rsi // error code
|
movq 160(%rsp), %rsi // error code
|
||||||
leaq 136(%rsp), %rdx // interrupt stack ptr
|
leaq 168(%rsp), %rdx // interrupt stack ptr
|
||||||
movq %rsp, %rcx // register ptr
|
movq %rsp, %rcx // register ptr
|
||||||
call cpp_isr_handler
|
call cpp_isr_handler
|
||||||
|
addq $32, %rsp
|
||||||
|
|
||||||
intr_footer 24
|
intr_footer 24
|
||||||
addq $16, %rsp
|
addq $16, %rsp
|
||||||
|
|||||||
@@ -41,18 +41,7 @@ SECTIONS
|
|||||||
{
|
{
|
||||||
g_kernel_writable_start = .;
|
g_kernel_writable_start = .;
|
||||||
*(.data)
|
*(.data)
|
||||||
|
|
||||||
. = ALIGN(8);
|
|
||||||
g_drv_builtin_begin = .;
|
|
||||||
KEEP(*(.banos-driver))
|
|
||||||
g_drv_builtin_end = .;
|
|
||||||
. = ALIGN(8);
|
|
||||||
g_banos_export = .;
|
|
||||||
KEEP(*(.banos-export))
|
|
||||||
g_banos_export_end = .;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
.bss ALIGN(4K) : AT(ADDR(.bss) - KERNEL_OFFSET)
|
||||||
{
|
{
|
||||||
g_kernel_bss_start = .;
|
g_kernel_bss_start = .;
|
||||||
|
|||||||
+13
-27
@@ -38,39 +38,25 @@ extern "C" void __cxa_finalize(void* f)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" int __cxa_guard_acquire(uint64_t* g)
|
namespace __cxxabiv1
|
||||||
{
|
{
|
||||||
uint8_t* guard = reinterpret_cast<uint8_t*>(g);
|
using __guard = uint64_t;
|
||||||
|
|
||||||
for (;;)
|
extern "C" int __cxa_guard_acquire (__guard* g)
|
||||||
{
|
{
|
||||||
if (BAN::atomic_load(guard[0], BAN::memory_order_acquire))
|
uint8_t* byte = reinterpret_cast<uint8_t*>(g);
|
||||||
return 0;
|
uint8_t zero = 0;
|
||||||
|
return __atomic_compare_exchange_n(byte, &zero, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
|
||||||
uint8_t expected = 0;
|
|
||||||
if (BAN::atomic_compare_exchange(guard[1], expected, 1, BAN::memory_order_acquire))
|
|
||||||
{
|
|
||||||
if (BAN::atomic_load(guard[0], BAN::memory_order_acquire))
|
|
||||||
{
|
|
||||||
BAN::atomic_store(guard[1], 0, BAN::memory_order_release);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (BAN::atomic_load(guard[1], BAN::memory_order_acquire))
|
extern "C" void __cxa_guard_release (__guard* g)
|
||||||
Kernel::Processor::pause();
|
{
|
||||||
|
uint8_t* byte = reinterpret_cast<uint8_t*>(g);
|
||||||
|
__atomic_store_n(byte, 0, __ATOMIC_RELEASE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void __cxa_guard_release(uint64_t* g)
|
extern "C" void __cxa_guard_abort (__guard*)
|
||||||
{
|
{
|
||||||
uint8_t* guard = reinterpret_cast<uint8_t*>(g);
|
|
||||||
BAN::atomic_store(guard[0], 1, BAN::memory_order_release);
|
|
||||||
BAN::atomic_store(guard[1], 0, BAN::memory_order_release);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void __cxa_guard_abort(uint64_t*)
|
|
||||||
{
|
|
||||||
Kernel::panic("__cxa_guard_abort");
|
Kernel::panic("__cxa_guard_abort");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
// Copyright (c) 2026 Dcraftbg
|
|
||||||
// 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.
|
|
||||||
#include "version.h"
|
|
||||||
#include "revision.h"
|
|
||||||
|
|
||||||
#define BANOS_DRIVER_REVISION_CURRENT 0
|
|
||||||
|
|
||||||
typedef struct Banos_Driver Banos_Driver;
|
|
||||||
struct Banos_Driver {
|
|
||||||
unsigned long driver_size;
|
|
||||||
banos_version_t minimal_banos_version;
|
|
||||||
const char* name;
|
|
||||||
const char* license;
|
|
||||||
banos_version_t version;
|
|
||||||
|
|
||||||
// NOTE: checkout BANOS_DRIVER_INSTANCE_SIZE.
|
|
||||||
// You may use this instance data for anything you wish to store.
|
|
||||||
// If you need more than that just allocate it on the heap or
|
|
||||||
// globally if you add the proper verification of having your driver run only
|
|
||||||
// within a single instance
|
|
||||||
int (*init)(Banos_Driver* drv);
|
|
||||||
int (*uninit)(Banos_Driver* drv);
|
|
||||||
};
|
|
||||||
#define BANOS_DRIVER_API static __attribute__((section(".banos-driver"), used, aligned(8)))
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
// Copyright (c) 2026 Dcraftbg
|
|
||||||
// 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.
|
|
||||||
typedef struct Banos_Symbol {
|
|
||||||
const char* name;
|
|
||||||
void* arg;
|
|
||||||
} Banos_Symbol;
|
|
||||||
#define BANOS_EXPORT_SYMBOL(symname, str, ptr) \
|
|
||||||
static __attribute__((section(".banos-export"), used, aligned(8))) Banos_Symbol __symbol_##symname = {\
|
|
||||||
.name = str, \
|
|
||||||
.arg = ptr \
|
|
||||||
};
|
|
||||||
#define BANOS_EXPORT(name) BANOS_EXPORT_SYMBOL(name, #name, (void*)&name)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
// Copyright (c) 2026 Dcraftbg
|
|
||||||
// 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.
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void banos_dprintln(const char* str);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
typedef unsigned long banos_revision_t;
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
// Copyright (c) 2026 Dcraftbg
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
// [ 8 bit major ] [ 8 minor ] [ 16 patch]
|
|
||||||
typedef unsigned int banos_version_t;
|
|
||||||
#define BANOS_VERSION_MAJOR_SHIFT 24
|
|
||||||
#define BANOS_VERSION_MINOR_SHIFT 16
|
|
||||||
#define BANOS_VERSION_PATCH_SHIFT 0
|
|
||||||
|
|
||||||
#define BANOS_VERSION_MAJOR_MASK 0xFF
|
|
||||||
#define BANOS_VERSION_MINOR_MASK 0xFF
|
|
||||||
#define BANOS_VERSION_PATCH_MASK 0xFFFF
|
|
||||||
|
|
||||||
#define BANOS_VERSION_MAKE(major, minor, patch) \
|
|
||||||
(banos_version_t)( \
|
|
||||||
(((major) & BANOS_VERSION_MAJOR_MASK) << BANOS_VERSION_MAJOR_SHIFT) | \
|
|
||||||
(((minor) & BANOS_VERSION_MINOR_MASK) << BANOS_VERSION_MINOR_SHIFT) | \
|
|
||||||
(((patch) & BANOS_VERSION_PATCH_MASK) << BANOS_VERSION_PATCH_SHIFT) \
|
|
||||||
)
|
|
||||||
|
|
||||||
#define BANOS_VERSION_CURRENT BANOS_VERSION_MAKE(0, 0, 1)
|
|
||||||
|
|
||||||
#define BANOS_VERSION_GET_MAJOR(v) (((v) >> BANOS_VERSION_MAJOR_SHIFT) & BANOS_VERSION_MAJOR_MASK)
|
|
||||||
#define BANOS_VERSION_GET_MINOR(v) (((v) >> BANOS_VERSION_MINOR_SHIFT) & BANOS_VERSION_MINOR_MASK)
|
|
||||||
#define BANOS_VERSION_GET_PATCH(v) (((v) >> BANOS_VERSION_PATCH_SHIFT) & BANOS_VERSION_PATCH_MASK)
|
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <kernel/ACPI/AML/Namespace.h>
|
#include <kernel/ACPI/AML/Namespace.h>
|
||||||
#include <kernel/ACPI/EmbeddedController.h>
|
#include <kernel/ACPI/EmbeddedController.h>
|
||||||
#include <kernel/ACPI/Headers.h>
|
#include <kernel/ACPI/Headers.h>
|
||||||
#include <kernel/Interruptable.h>
|
|
||||||
#include <kernel/Memory/Types.h>
|
#include <kernel/Memory/Types.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/ThreadBlocker.h>
|
||||||
|
|
||||||
@@ -24,7 +23,11 @@ namespace Kernel::ACPI
|
|||||||
|
|
||||||
const SDTHeader* get_header(BAN::StringView signature, uint32_t index);
|
const SDTHeader* get_header(BAN::StringView signature, uint32_t index);
|
||||||
|
|
||||||
BAN::ErrorOr<void> enter_acpi_mode();
|
// mode
|
||||||
|
// 0: PIC
|
||||||
|
// 1: APIC
|
||||||
|
// 2: SAPIC
|
||||||
|
BAN::ErrorOr<void> enter_acpi_mode(uint8_t mode);
|
||||||
|
|
||||||
BAN::ErrorOr<void> initialize_acpi_devices();
|
BAN::ErrorOr<void> initialize_acpi_devices();
|
||||||
|
|
||||||
@@ -54,7 +57,6 @@ namespace Kernel::ACPI
|
|||||||
|
|
||||||
BAN::ErrorOr<void> initialize_embedded_controller(const AML::Scope& embedded_controller);
|
BAN::ErrorOr<void> initialize_embedded_controller(const AML::Scope& embedded_controller);
|
||||||
BAN::ErrorOr<void> initialize_embedded_controllers();
|
BAN::ErrorOr<void> initialize_embedded_controllers();
|
||||||
void initialize_embedded_controller_gpes();
|
|
||||||
|
|
||||||
BAN::Optional<GAS> find_gpe_block(size_t index);
|
BAN::Optional<GAS> find_gpe_block(size_t index);
|
||||||
bool enable_gpe(uint8_t gpe);
|
bool enable_gpe(uint8_t gpe);
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Atomic.h>
|
#include <BAN/Atomic.h>
|
||||||
#include <BAN/Optional.h>
|
|
||||||
#include <BAN/UniqPtr.h>
|
#include <BAN/UniqPtr.h>
|
||||||
|
|
||||||
#include <kernel/ACPI/AML/Scope.h>
|
#include <kernel/ACPI/AML/Scope.h>
|
||||||
#include <kernel/Lock/Mutex.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/Thread.h>
|
||||||
|
|
||||||
namespace Kernel::ACPI
|
namespace Kernel::ACPI
|
||||||
{
|
{
|
||||||
@@ -14,7 +13,7 @@ namespace Kernel::ACPI
|
|||||||
class EmbeddedController
|
class EmbeddedController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<EmbeddedController>> create(AML::Scope&& scope, uint16_t command_port, uint16_t data_port);
|
static BAN::ErrorOr<BAN::UniqPtr<EmbeddedController>> create(AML::Scope&& scope, uint16_t command_port, uint16_t data_port, BAN::Optional<uint8_t> gpe);
|
||||||
~EmbeddedController();
|
~EmbeddedController();
|
||||||
|
|
||||||
BAN::ErrorOr<uint8_t> read_byte(uint8_t offset);
|
BAN::ErrorOr<uint8_t> read_byte(uint8_t offset);
|
||||||
@@ -22,21 +21,21 @@ namespace Kernel::ACPI
|
|||||||
|
|
||||||
const AML::Scope& scope() const { return m_scope; }
|
const AML::Scope& scope() const { return m_scope; }
|
||||||
|
|
||||||
static void handle_gpe_trampoline(void*);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EmbeddedController(AML::Scope&& scope, uint16_t command_port, uint16_t data_port)
|
EmbeddedController(AML::Scope&& scope, uint16_t command_port, uint16_t data_port, bool has_gpe)
|
||||||
: m_scope(BAN::move(scope))
|
: m_scope(BAN::move(scope))
|
||||||
, m_command_port(command_port)
|
, m_command_port(command_port)
|
||||||
, m_data_port(data_port)
|
, m_data_port(data_port)
|
||||||
|
, m_has_gpe(has_gpe)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void wait_status_bit(uint8_t mask, bool set);
|
void wait_status_bit(uint8_t bit, uint8_t value);
|
||||||
|
|
||||||
uint8_t read_one(uint16_t port);
|
uint8_t read_one(uint16_t port);
|
||||||
void write_one(uint16_t port, uint8_t value);
|
void write_one(uint16_t port, uint8_t value);
|
||||||
|
|
||||||
|
static void handle_gpe_wrapper(void*);
|
||||||
void handle_gpe();
|
void handle_gpe();
|
||||||
|
|
||||||
BAN::ErrorOr<void> call_query_method(uint8_t notification);
|
BAN::ErrorOr<void> call_query_method(uint8_t notification);
|
||||||
@@ -57,6 +56,7 @@ namespace Kernel::ACPI
|
|||||||
const AML::Scope m_scope;
|
const AML::Scope m_scope;
|
||||||
const uint16_t m_command_port;
|
const uint16_t m_command_port;
|
||||||
const uint16_t m_data_port;
|
const uint16_t m_data_port;
|
||||||
|
const bool m_has_gpe;
|
||||||
|
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ namespace Kernel::API
|
|||||||
enum SharedPageFeature : uint32_t
|
enum SharedPageFeature : uint32_t
|
||||||
{
|
{
|
||||||
SPF_GETTIME = 1 << 0,
|
SPF_GETTIME = 1 << 0,
|
||||||
SPF_RDTSCP = 1 << 1,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SharedPage
|
struct SharedPage
|
||||||
@@ -19,8 +18,9 @@ namespace Kernel::API
|
|||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint64_t realtime_s;
|
uint8_t shift;
|
||||||
uint32_t realtime_ns;
|
uint64_t mult;
|
||||||
|
uint64_t realtime_seconds;
|
||||||
} gettime_shared;
|
} gettime_shared;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
@@ -28,8 +28,6 @@ namespace Kernel::API
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t seq;
|
uint32_t seq;
|
||||||
uint32_t mult;
|
|
||||||
int8_t shift;
|
|
||||||
uint64_t last_ns;
|
uint64_t last_ns;
|
||||||
uint64_t last_tsc;
|
uint64_t last_tsc;
|
||||||
} gettime_local;
|
} gettime_local;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
#include <kernel/InterruptController.h>
|
#include <kernel/InterruptController.h>
|
||||||
#include <kernel/InterruptNumbers.h>
|
|
||||||
#include <kernel/Lock/SpinLock.h>
|
#include <kernel/Lock/SpinLock.h>
|
||||||
#include <kernel/Memory/Types.h>
|
#include <kernel/Memory/Types.h>
|
||||||
|
|
||||||
@@ -13,10 +12,10 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void eoi(uint8_t) override;
|
virtual void eoi(uint8_t) override;
|
||||||
virtual void enable_irq(uint8_t, bool level_triggered) override;
|
virtual void enable_irq(uint8_t) override;
|
||||||
virtual bool is_in_service(uint8_t) override;
|
virtual bool is_in_service(uint8_t) override;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq, bool shared) override;
|
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq) override;
|
||||||
virtual BAN::Optional<uint8_t> get_free_irq() override;
|
virtual BAN::Optional<uint8_t> get_free_irq() override;
|
||||||
|
|
||||||
virtual void initialize_multiprocessor() override;
|
virtual void initialize_multiprocessor() override;
|
||||||
@@ -24,10 +23,9 @@ namespace Kernel
|
|||||||
virtual void broadcast_ipi() override;
|
virtual void broadcast_ipi() override;
|
||||||
virtual void enable() override;
|
virtual void enable() override;
|
||||||
|
|
||||||
BAN::ErrorOr<uint8_t> reserve_gsi(uint32_t gsi, bool shared = false);
|
BAN::ErrorOr<uint8_t> reserve_gsi(uint32_t gsi);
|
||||||
|
|
||||||
void initialize_timer();
|
void initialize_timer();
|
||||||
void set_timer_dealine(uint64_t ns);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t read_from_local_apic(ptrdiff_t);
|
uint32_t read_from_local_apic(ptrdiff_t);
|
||||||
@@ -72,8 +70,7 @@ namespace Kernel
|
|||||||
Kernel::vaddr_t m_local_apic_vaddr = 0;
|
Kernel::vaddr_t m_local_apic_vaddr = 0;
|
||||||
BAN::Vector<IOAPIC> m_io_apics;
|
BAN::Vector<IOAPIC> m_io_apics;
|
||||||
uint8_t m_irq_overrides[0x100] {};
|
uint8_t m_irq_overrides[0x100] {};
|
||||||
uint8_t m_used_gsis[m_irq_count / 8] {};
|
uint8_t m_reserved_gsis[m_irq_count / 8] {};
|
||||||
uint8_t m_excl_gsis[m_irq_count / 8] {};
|
|
||||||
uint64_t m_lapic_timer_frequency_hz { 0 };
|
uint64_t m_lapic_timer_frequency_hz { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<void> create(PCI::Device& pci_device);
|
static BAN::ErrorOr<void> create(PCI::Device& pci_device);
|
||||||
|
|
||||||
|
dev_t rdev() const override { return m_rdev; }
|
||||||
BAN::StringView name() const override { return m_name; }
|
BAN::StringView name() const override { return m_name; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -38,7 +39,7 @@ namespace Kernel
|
|||||||
|
|
||||||
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
|
|
||||||
BAN::ErrorOr<long> ioctl_impl(unsigned long request, void* arg) override;
|
BAN::ErrorOr<long> ioctl_impl(int cmd, void* arg) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ThreadBlocker m_sample_data_blocker;
|
ThreadBlocker m_sample_data_blocker;
|
||||||
@@ -50,6 +51,7 @@ namespace Kernel
|
|||||||
snd_volume_info m_volume_info {};
|
snd_volume_info m_volume_info {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
char m_name[10] {};
|
char m_name[10] {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<void> enable_output_path(uint8_t index);
|
BAN::ErrorOr<void> enable_output_path(uint8_t index);
|
||||||
BAN::ErrorOr<void> disable_output_path(uint8_t index);
|
BAN::ErrorOr<void> disable_output_path(uint8_t index);
|
||||||
|
|
||||||
BAN::ErrorOr<void> reset_stream();
|
void reset_stream();
|
||||||
|
|
||||||
BAN::ErrorOr<void> recurse_output_paths(const HDAudio::AFGWidget& widget, BAN::Vector<const HDAudio::AFGWidget*>& path);
|
BAN::ErrorOr<void> recurse_output_paths(const HDAudio::AFGWidget& widget, BAN::Vector<const HDAudio::AFGWidget*>& path);
|
||||||
|
|
||||||
@@ -67,7 +67,6 @@ namespace Kernel
|
|||||||
BAN::Vector<BAN::Vector<const HDAudio::AFGWidget*>> m_output_paths;
|
BAN::Vector<BAN::Vector<const HDAudio::AFGWidget*>> m_output_paths;
|
||||||
BAN::Vector<const HDAudio::AFGWidget*> m_output_pins;
|
BAN::Vector<const HDAudio::AFGWidget*> m_output_pins;
|
||||||
size_t m_output_path_index { SIZE_MAX };
|
size_t m_output_path_index { SIZE_MAX };
|
||||||
size_t m_amplifier_idx { SIZE_MAX };
|
|
||||||
|
|
||||||
uint8_t m_stream_id { 0xFF };
|
uint8_t m_stream_id { 0xFF };
|
||||||
uint8_t m_stream_index { 0xFF };
|
uint8_t m_stream_index { 0xFF };
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Optional.h>
|
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
|
|
||||||
namespace Kernel::HDAudio
|
namespace Kernel::HDAudio
|
||||||
@@ -65,7 +64,6 @@ namespace Kernel::HDAudio
|
|||||||
};
|
};
|
||||||
|
|
||||||
BAN::Optional<Amplifier> output_amplifier;
|
BAN::Optional<Amplifier> output_amplifier;
|
||||||
BAN::Optional<Amplifier> input_amplifier;
|
|
||||||
|
|
||||||
BAN::Vector<uint16_t> connections;
|
BAN::Vector<uint16_t> connections;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,17 +21,13 @@ struct BananBootloaderMemoryMapEntry
|
|||||||
uint64_t address;
|
uint64_t address;
|
||||||
uint64_t length;
|
uint64_t length;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
uint32_t unused;
|
} __attribute__((packed));
|
||||||
};
|
|
||||||
static_assert(sizeof(BananBootloaderMemoryMapEntry) == 24);
|
|
||||||
|
|
||||||
struct BananBootloaderMemoryMapInfo
|
struct BananBootloaderMemoryMapInfo
|
||||||
{
|
{
|
||||||
uint32_t entry_count;
|
uint32_t entry_count;
|
||||||
uint32_t padding;
|
|
||||||
struct BananBootloaderMemoryMapEntry entries[];
|
struct BananBootloaderMemoryMapEntry entries[];
|
||||||
};
|
} __attribute__((packed));
|
||||||
static_assert(sizeof(BananBootloaderMemoryMapInfo) == 8);
|
|
||||||
|
|
||||||
struct BananBootloaderInfo
|
struct BananBootloaderInfo
|
||||||
{
|
{
|
||||||
@@ -39,5 +35,4 @@ struct BananBootloaderInfo
|
|||||||
uint32_t framebuffer_addr;
|
uint32_t framebuffer_addr;
|
||||||
uint32_t memory_map_addr;
|
uint32_t memory_map_addr;
|
||||||
uint32_t kernel_paddr;
|
uint32_t kernel_paddr;
|
||||||
};
|
} __attribute__((packed));
|
||||||
static_assert(sizeof(BananBootloaderInfo) == 16);
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <BAN/Vector.h>
|
|
||||||
#include <BAN/StringView.h>
|
|
||||||
typedef struct Banos_Symbol Banos_Symbol;
|
|
||||||
namespace Banos {
|
|
||||||
void* resolve_symbol(const char* name);
|
|
||||||
void import_symbols(Banos_Symbol* symbols, size_t count);
|
|
||||||
void initialize_initial_drivers(void);
|
|
||||||
BAN::ErrorOr<size_t> load_driver_from_image(const char* u_image);
|
|
||||||
}
|
|
||||||
@@ -82,8 +82,5 @@ namespace CPUID
|
|||||||
bool has_pat();
|
bool has_pat();
|
||||||
bool has_1gib_pages();
|
bool has_1gib_pages();
|
||||||
bool has_invariant_tsc();
|
bool has_invariant_tsc();
|
||||||
bool has_rdtscp();
|
|
||||||
uint64_t get_tsc_frequency();
|
|
||||||
bool has_kvm_pvclock();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,6 @@
|
|||||||
|
|
||||||
#define DEBUG_VTTY 1
|
#define DEBUG_VTTY 1
|
||||||
|
|
||||||
#define DEBUG_DEVFS 0
|
|
||||||
|
|
||||||
#define DEBUG_PCI 0
|
#define DEBUG_PCI 0
|
||||||
#define DEBUG_SCHEDULER 0
|
#define DEBUG_SCHEDULER 0
|
||||||
#define DEBUG_PS2 1
|
#define DEBUG_PS2 1
|
||||||
|
|||||||
@@ -8,14 +8,15 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<DebugDevice>> create(mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<DebugDevice>> create(mode_t, uid_t, gid_t);
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
|
|
||||||
virtual BAN::StringView name() const override { return "debug"_sv; }
|
virtual BAN::StringView name() const override { return "debug"_sv; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DebugDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
DebugDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||||
: CharacterDevice(mode, uid, gid)
|
: CharacterDevice(mode, uid, gid)
|
||||||
{
|
, m_rdev(rdev)
|
||||||
m_rdev = rdev;
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return 0; }
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return 0; }
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override;
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override;
|
||||||
@@ -24,6 +25,9 @@ namespace Kernel
|
|||||||
virtual bool can_write_impl() const override { return true; }
|
virtual bool can_write_impl() const override { return true; }
|
||||||
virtual bool has_error_impl() const override { return false; }
|
virtual bool has_error_impl() const override { return false; }
|
||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,20 +12,24 @@ namespace Kernel
|
|||||||
virtual ~Device() = default;
|
virtual ~Device() = default;
|
||||||
virtual void update() {}
|
virtual void update() {}
|
||||||
|
|
||||||
|
virtual bool is_device() const override { return true; }
|
||||||
|
virtual bool is_partition() const { return false; }
|
||||||
|
virtual bool is_storage_device() const { return false; }
|
||||||
|
|
||||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t, int status_flags)
|
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t, int status_flags)
|
||||||
{
|
{
|
||||||
(void)offset; (void)len; (void)status_flags;
|
(void)offset; (void)len; (void)status_flags;
|
||||||
return BAN::Error::from_errno(ENOTSUP);
|
return BAN::Error::from_errno(ENOTSUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override = 0;
|
||||||
|
|
||||||
virtual BAN::StringView name() const = 0;
|
virtual BAN::StringView name() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Device(mode_t, uid_t, gid_t);
|
Device(mode_t, uid_t, gid_t);
|
||||||
|
|
||||||
private:
|
virtual BAN::ErrorOr<void> fsync_impl() final override { return BAN::Error::from_errno(EINVAL); }
|
||||||
BAN::ErrorOr<void> sync_inode(SyncType) final override { return {}; }
|
|
||||||
BAN::ErrorOr<void> sync_data() final override { return {}; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BlockDevice : public Device, public BAN::Weakable<BlockDevice>
|
class BlockDevice : public Device, public BAN::Weakable<BlockDevice>
|
||||||
@@ -41,7 +45,7 @@ namespace Kernel
|
|||||||
BlockDevice(mode_t mode, uid_t uid, gid_t gid)
|
BlockDevice(mode_t mode, uid_t uid, gid_t gid)
|
||||||
: Device(mode, uid, gid)
|
: Device(mode, uid, gid)
|
||||||
{
|
{
|
||||||
m_mode |= Inode::Mode::IFBLK;
|
m_inode_info.mode |= Inode::Mode::IFBLK;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ namespace Kernel
|
|||||||
CharacterDevice(mode_t mode, uid_t uid, gid_t gid)
|
CharacterDevice(mode_t mode, uid_t uid, gid_t gid)
|
||||||
: Device(mode, uid, gid)
|
: Device(mode, uid, gid)
|
||||||
{
|
{
|
||||||
m_mode |= Inode::Mode::IFCHR;
|
m_inode_info.mode |= Inode::Mode::IFCHR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,22 +6,15 @@
|
|||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class BGAController;
|
|
||||||
|
|
||||||
class FramebufferDevice : public CharacterDevice
|
class FramebufferDevice : public CharacterDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> create(paddr_t paddr, uint32_t width, uint32_t height, uint32_t pitch, uint8_t bpp);
|
|
||||||
static BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> create(BAN::RefPtr<BGAController>);
|
|
||||||
static BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> create_from_boot_framebuffer();
|
static BAN::ErrorOr<BAN::RefPtr<FramebufferDevice>> create_from_boot_framebuffer();
|
||||||
static BAN::RefPtr<FramebufferDevice> boot_framebuffer();
|
static BAN::RefPtr<FramebufferDevice> boot_framebuffer();
|
||||||
~FramebufferDevice();
|
~FramebufferDevice();
|
||||||
|
|
||||||
uint32_t width() const { return m_width; }
|
uint32_t width() const { return m_width; }
|
||||||
uint32_t height() const { return m_height; }
|
uint32_t height() const { return m_height; }
|
||||||
uint8_t bpp() const { return m_bpp; }
|
|
||||||
|
|
||||||
BAN::ErrorOr<void> set_bga_controller(BAN::RefPtr<BGAController>);
|
|
||||||
|
|
||||||
uint32_t get_pixel(uint32_t x, uint32_t y) const;
|
uint32_t get_pixel(uint32_t x, uint32_t y) const;
|
||||||
void set_pixel(uint32_t x, uint32_t y, uint32_t rgb);
|
void set_pixel(uint32_t x, uint32_t y, uint32_t rgb);
|
||||||
@@ -37,13 +30,14 @@ namespace Kernel
|
|||||||
|
|
||||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t, int status_flags) override;
|
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t, int status_flags) override;
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
virtual BAN::StringView name() const override { return m_name.sv(); }
|
virtual BAN::StringView name() const override { return m_name.sv(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
|
|
||||||
BAN::ErrorOr<long> ioctl_impl(unsigned long request, void* arg) override;
|
BAN::ErrorOr<long> ioctl_impl(int cmd, void* arg) override;
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return true; }
|
virtual bool can_read_impl() const override { return true; }
|
||||||
virtual bool can_write_impl() const override { return true; }
|
virtual bool can_write_impl() const override { return true; }
|
||||||
@@ -56,17 +50,16 @@ namespace Kernel
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const BAN::String m_name;
|
const BAN::String m_name;
|
||||||
|
const dev_t m_rdev;
|
||||||
|
|
||||||
vaddr_t m_video_memory_vaddr { 0 };
|
vaddr_t m_video_memory_vaddr { 0 };
|
||||||
paddr_t m_video_memory_paddr { 0 };
|
const paddr_t m_video_memory_paddr;
|
||||||
|
const uint32_t m_width;
|
||||||
uint32_t m_width { 0 };
|
const uint32_t m_height;
|
||||||
uint32_t m_height { 0 };
|
const uint32_t m_pitch;
|
||||||
uint32_t m_pitch { 0 };
|
const uint8_t m_bpp;
|
||||||
uint8_t m_bpp { 0 };
|
|
||||||
|
|
||||||
BAN::UniqPtr<VirtualRange> m_video_buffer;
|
BAN::UniqPtr<VirtualRange> m_video_buffer;
|
||||||
BAN::RefPtr<BGAController> m_bga_controller;
|
|
||||||
|
|
||||||
friend class FramebufferMemoryRegion;
|
friend class FramebufferMemoryRegion;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<NullDevice>> create(mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<NullDevice>> create(mode_t, uid_t, gid_t);
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
|
|
||||||
virtual BAN::StringView name() const override { return "null"_sv; }
|
virtual BAN::StringView name() const override { return "null"_sv; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NullDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
NullDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||||
: CharacterDevice(mode, uid, gid)
|
: CharacterDevice(mode, uid, gid)
|
||||||
{
|
, m_rdev(rdev)
|
||||||
m_rdev = rdev;
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return 0; }
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return 0; }
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
||||||
@@ -27,6 +28,8 @@ namespace Kernel
|
|||||||
virtual bool has_error_impl() const override { return false; }
|
virtual bool has_error_impl() const override { return false; }
|
||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,15 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<RandomDevice>> create(mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<RandomDevice>> create(mode_t, uid_t, gid_t);
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
|
|
||||||
virtual BAN::StringView name() const override { return "random"_sv; }
|
virtual BAN::StringView name() const override { return "random"_sv; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RandomDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
RandomDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||||
: CharacterDevice(mode, uid, gid)
|
: CharacterDevice(mode, uid, gid)
|
||||||
{
|
, m_rdev(rdev)
|
||||||
m_rdev = rdev;
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
||||||
@@ -24,6 +25,9 @@ namespace Kernel
|
|||||||
virtual bool can_write_impl() const override { return false; }
|
virtual bool can_write_impl() const override { return false; }
|
||||||
virtual bool has_error_impl() const override { return false; }
|
virtual bool has_error_impl() const override { return false; }
|
||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,15 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ZeroDevice>> create(mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<ZeroDevice>> create(mode_t, uid_t, gid_t);
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
|
|
||||||
virtual BAN::StringView name() const override { return "zero"_sv; }
|
virtual BAN::StringView name() const override { return "zero"_sv; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ZeroDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
ZeroDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||||
: CharacterDevice(mode, uid, gid)
|
: CharacterDevice(mode, uid, gid)
|
||||||
{
|
, m_rdev(rdev)
|
||||||
m_rdev = rdev;
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return buffer.size(); };
|
||||||
@@ -24,6 +25,9 @@ namespace Kernel
|
|||||||
virtual bool can_write_impl() const override { return false; }
|
virtual bool can_write_impl() const override { return false; }
|
||||||
virtual bool has_error_impl() const override { return false; }
|
virtual bool has_error_impl() const override { return false; }
|
||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ namespace Kernel::ELF
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool open_execfd;
|
||||||
vaddr_t entry_point;
|
vaddr_t entry_point;
|
||||||
BAN::Optional<vaddr_t> interp_base;
|
|
||||||
BAN::Optional<TLS> master_tls;
|
BAN::Optional<TLS> master_tls;
|
||||||
BAN::Vector<BAN::UniqPtr<MemoryRegion>> regions;
|
BAN::Vector<BAN::UniqPtr<MemoryRegion>> regions;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <BAN/HashMap.h>
|
#include <BAN/HashMap.h>
|
||||||
#include <kernel/FS/Inode.h>
|
#include <kernel/FS/Inode.h>
|
||||||
#include <kernel/Lock/Mutex.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
|
||||||
|
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
|
||||||
@@ -22,7 +21,24 @@ namespace Kernel
|
|||||||
void notify(BAN::RefPtr<Inode> inode, uint32_t event);
|
void notify(BAN::RefPtr<Inode> inode, uint32_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Epoll();
|
Epoll() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ino_t ino() const override { return 0; }
|
||||||
|
Mode mode() const override { return { Mode::IRUSR | Mode::IWUSR }; }
|
||||||
|
nlink_t nlink() const override { return 0; }
|
||||||
|
uid_t uid() const override { return 0; }
|
||||||
|
gid_t gid() const override { return 0; }
|
||||||
|
off_t size() const override { return 0; }
|
||||||
|
timespec atime() const override { return {}; }
|
||||||
|
timespec mtime() const override { return {}; }
|
||||||
|
timespec ctime() const override { return {}; }
|
||||||
|
blksize_t blksize() const override { return PAGE_SIZE; }
|
||||||
|
blkcnt_t blocks() const override { return 0; }
|
||||||
|
dev_t dev() const override { return 0; }
|
||||||
|
dev_t rdev() const override { return 0; }
|
||||||
|
|
||||||
|
bool is_epoll() const override { return true; }
|
||||||
|
|
||||||
const FileSystem* filesystem() const override { return nullptr; }
|
const FileSystem* filesystem() const override { return nullptr; }
|
||||||
|
|
||||||
@@ -31,8 +47,7 @@ namespace Kernel
|
|||||||
bool has_error_impl() const override { return false; }
|
bool has_error_impl() const override { return false; }
|
||||||
bool has_hungup_impl() const override { return false; }
|
bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
BAN::ErrorOr<void> sync_inode(SyncType) override { return {}; }
|
BAN::ErrorOr<void> fsync_impl() override { return {}; }
|
||||||
BAN::ErrorOr<void> sync_data() override { return {}; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ListenEventList
|
struct ListenEventList
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
|
#include <kernel/Device/Device.h>
|
||||||
#include <kernel/FS/TmpFS/FileSystem.h>
|
#include <kernel/FS/TmpFS/FileSystem.h>
|
||||||
#include <kernel/Lock/Mutex.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/ThreadBlocker.h>
|
||||||
@@ -8,8 +9,6 @@
|
|||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class Device;
|
|
||||||
|
|
||||||
class DevFileSystem final : public TmpFileSystem
|
class DevFileSystem final : public TmpFileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <kernel/FS/Inode.h>
|
#include <kernel/FS/Inode.h>
|
||||||
#include <kernel/Lock/Mutex.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
@@ -12,27 +11,43 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(uint64_t initval, bool semaphore);
|
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(uint64_t initval, bool semaphore);
|
||||||
|
|
||||||
private:
|
ino_t ino() const override { return 0; }
|
||||||
EventFD(uint64_t initval, bool is_semaphore);
|
Mode mode() const override { return { Mode::IFCHR | Mode::IRUSR | Mode::IWUSR }; }
|
||||||
|
nlink_t nlink() const override { return ref_count(); }
|
||||||
|
uid_t uid() const override { return 0; }
|
||||||
|
gid_t gid() const override { return 0; }
|
||||||
|
off_t size() const override { return 0; }
|
||||||
|
timespec atime() const override { return {}; }
|
||||||
|
timespec mtime() const override { return {}; }
|
||||||
|
timespec ctime() const override { return {}; }
|
||||||
|
blksize_t blksize() const override { return 8; }
|
||||||
|
blkcnt_t blocks() const override { return 0; }
|
||||||
|
dev_t dev() const override { return 0; }
|
||||||
|
dev_t rdev() const override { return 0; }
|
||||||
|
|
||||||
const FileSystem* filesystem() const override { return nullptr; }
|
const FileSystem* filesystem() const override { return nullptr; }
|
||||||
|
|
||||||
BAN::ErrorOr<void> sync_inode(SyncType) override { return {}; }
|
protected:
|
||||||
BAN::ErrorOr<void> sync_data() override { return {}; }
|
|
||||||
|
|
||||||
BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
|
BAN::ErrorOr<void> fsync_impl() final override { return {}; }
|
||||||
|
|
||||||
bool can_read_impl() const override;
|
bool can_read_impl() const override { return m_value > 0; }
|
||||||
bool can_write_impl() const override;
|
bool can_write_impl() const override { return m_value < UINT64_MAX - 1; }
|
||||||
bool has_error_impl() const override { return false; }
|
bool has_error_impl() const override { return false; }
|
||||||
bool has_hungup_impl() const override { return false; }
|
bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const bool m_is_semaphore;
|
EventFD(uint64_t initval, bool is_semaphore)
|
||||||
uint64_t m_value;
|
: m_is_semaphore(is_semaphore)
|
||||||
|
, m_value(initval)
|
||||||
|
{ }
|
||||||
|
|
||||||
mutable Mutex m_mutex;
|
private:
|
||||||
|
const bool m_is_semaphore;
|
||||||
|
BAN::Atomic<uint64_t> m_value;
|
||||||
|
|
||||||
|
Mutex m_mutex;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -79,12 +79,6 @@ namespace Kernel::Ext2
|
|||||||
uint8_t __reserved[12];
|
uint8_t __reserved[12];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InodeBlocks {
|
|
||||||
uint32_t block[15];
|
|
||||||
};
|
|
||||||
struct Osd2 {
|
|
||||||
uint32_t osd2[3];
|
|
||||||
};
|
|
||||||
struct Inode
|
struct Inode
|
||||||
{
|
{
|
||||||
uint16_t mode;
|
uint16_t mode;
|
||||||
@@ -99,12 +93,12 @@ namespace Kernel::Ext2
|
|||||||
uint32_t blocks;
|
uint32_t blocks;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t osd1;
|
uint32_t osd1;
|
||||||
InodeBlocks block;
|
uint32_t block[15];
|
||||||
uint32_t generation;
|
uint32_t generation;
|
||||||
uint32_t file_acl;
|
uint32_t file_acl;
|
||||||
uint32_t dir_acl;
|
uint32_t dir_acl;
|
||||||
uint32_t faddr;
|
uint32_t faddr;
|
||||||
Osd2 osd2;
|
uint32_t osd2[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LinkedDirectoryEntry
|
struct LinkedDirectoryEntry
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
#include <BAN/HashMap.h>
|
#include <BAN/HashMap.h>
|
||||||
#include <kernel/Device/Device.h>
|
#include <kernel/Device/Device.h>
|
||||||
#include <kernel/FS/Ext2/Inode.h>
|
|
||||||
#include <kernel/FS/FileSystem.h>
|
#include <kernel/FS/FileSystem.h>
|
||||||
#include <kernel/Memory/VirtualRange.h>
|
#include <kernel/FS/Ext2/Inode.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
@@ -29,7 +28,7 @@ namespace Kernel
|
|||||||
BAN_NON_COPYABLE(BlockBufferWrapper);
|
BAN_NON_COPYABLE(BlockBufferWrapper);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BlockBufferWrapper(BAN::ByteSpan buffer, void (*callback)(void*, const uint8_t*), void* argument)
|
BlockBufferWrapper(BAN::Span<uint8_t> buffer, void (*callback)(void*, const uint8_t*), void* argument)
|
||||||
: m_buffer(buffer)
|
: m_buffer(buffer)
|
||||||
, m_callback(callback)
|
, m_callback(callback)
|
||||||
, m_argument(argument)
|
, m_argument(argument)
|
||||||
@@ -61,13 +60,13 @@ namespace Kernel
|
|||||||
const uint8_t* data() const { return m_buffer.data(); }
|
const uint8_t* data() const { return m_buffer.data(); }
|
||||||
|
|
||||||
BAN::ByteSpan span() { return m_buffer; }
|
BAN::ByteSpan span() { return m_buffer; }
|
||||||
BAN::ConstByteSpan span() const { return m_buffer; }
|
BAN::ConstByteSpan span() const { return m_buffer.as_const(); }
|
||||||
|
|
||||||
uint8_t& operator[](size_t index) { return m_buffer[index]; }
|
uint8_t& operator[](size_t index) { return m_buffer[index]; }
|
||||||
uint8_t operator[](size_t index) const { return m_buffer[index]; }
|
uint8_t operator[](size_t index) const { return m_buffer[index]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::ByteSpan m_buffer;
|
BAN::Span<uint8_t> m_buffer;
|
||||||
void (*m_callback)(void*, const uint8_t*);
|
void (*m_callback)(void*, const uint8_t*);
|
||||||
void* m_argument;
|
void* m_argument;
|
||||||
};
|
};
|
||||||
@@ -100,8 +99,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<uint32_t> reserve_free_block(uint32_t primary_bgd);
|
BAN::ErrorOr<uint32_t> reserve_free_block(uint32_t primary_bgd);
|
||||||
BAN::ErrorOr<void> release_block(uint32_t block);
|
BAN::ErrorOr<void> release_block(uint32_t block);
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::RefPtr<Ext2Inode>> open_inode(ino_t);
|
BAN::HashMap<ino_t, BAN::RefPtr<Ext2Inode>>& inode_cache() { return m_inode_cache; }
|
||||||
void remove_from_cache(ino_t);
|
|
||||||
|
|
||||||
const Ext2::Superblock& superblock() const { return m_superblock; }
|
const Ext2::Superblock& superblock() const { return m_superblock; }
|
||||||
|
|
||||||
@@ -129,7 +127,7 @@ namespace Kernel
|
|||||||
private:
|
private:
|
||||||
struct BlockBuffer
|
struct BlockBuffer
|
||||||
{
|
{
|
||||||
BAN::ByteSpan buffer;
|
BAN::Vector<uint8_t> buffer;
|
||||||
bool used { false };
|
bool used { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -145,7 +143,6 @@ namespace Kernel
|
|||||||
|
|
||||||
Mutex m_buffer_mutex;
|
Mutex m_buffer_mutex;
|
||||||
ThreadBlocker m_buffer_blocker;
|
ThreadBlocker m_buffer_blocker;
|
||||||
BAN::UniqPtr<VirtualRange> m_buffer_data;
|
|
||||||
BAN::Array<BlockBuffer, max_threads * max_buffers_per_thread> m_buffers;
|
BAN::Array<BlockBuffer, max_threads * max_buffers_per_thread> m_buffers;
|
||||||
BAN::Array<ThreadInfo, max_threads> m_thread_infos;
|
BAN::Array<ThreadInfo, max_threads> m_thread_infos;
|
||||||
};
|
};
|
||||||
@@ -158,7 +155,6 @@ namespace Kernel
|
|||||||
BAN::RefPtr<Inode> m_root_inode;
|
BAN::RefPtr<Inode> m_root_inode;
|
||||||
BAN::Vector<uint32_t> m_superblock_backups;
|
BAN::Vector<uint32_t> m_superblock_backups;
|
||||||
|
|
||||||
Mutex m_inode_cache_lock;
|
|
||||||
BAN::HashMap<ino_t, BAN::RefPtr<Ext2Inode>> m_inode_cache;
|
BAN::HashMap<ino_t, BAN::RefPtr<Ext2Inode>> m_inode_cache;
|
||||||
|
|
||||||
BlockBufferManager m_buffer_manager;
|
BlockBufferManager m_buffer_manager;
|
||||||
|
|||||||
@@ -16,12 +16,23 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
~Ext2Inode();
|
~Ext2Inode();
|
||||||
|
|
||||||
|
virtual ino_t ino() const override { return m_ino; };
|
||||||
|
virtual Mode mode() const override { return { m_inode.mode }; }
|
||||||
|
virtual nlink_t nlink() const override { return m_inode.links_count; }
|
||||||
|
virtual uid_t uid() const override { return m_inode.uid; }
|
||||||
|
virtual gid_t gid() const override { return m_inode.gid; }
|
||||||
|
virtual off_t size() const override { return m_inode.size; }
|
||||||
|
virtual timespec atime() const override { return timespec { .tv_sec = m_inode.atime, .tv_nsec = 0 }; }
|
||||||
|
virtual timespec mtime() const override { return timespec { .tv_sec = m_inode.mtime, .tv_nsec = 0 }; }
|
||||||
|
virtual timespec ctime() const override { return timespec { .tv_sec = m_inode.ctime, .tv_nsec = 0 }; }
|
||||||
|
virtual blksize_t blksize() const override;
|
||||||
|
virtual blkcnt_t blocks() const override;
|
||||||
|
virtual dev_t dev() const override { return 0; }
|
||||||
|
virtual dev_t rdev() const override { return 0; }
|
||||||
|
|
||||||
virtual const FileSystem* filesystem() const override;
|
virtual const FileSystem* filesystem() const override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
virtual BAN::ErrorOr<void> sync_inode(SyncType) override;
|
|
||||||
virtual BAN::ErrorOr<void> sync_data() override;
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
||||||
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
||||||
virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
|
virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
|
||||||
@@ -36,6 +47,10 @@ namespace Kernel
|
|||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
||||||
|
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
|
||||||
|
virtual BAN::ErrorOr<void> chown_impl(uid_t, gid_t) override;
|
||||||
|
virtual BAN::ErrorOr<void> utimens_impl(const timespec[2]) override;
|
||||||
|
virtual BAN::ErrorOr<void> fsync_impl() override;
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return true; }
|
virtual bool can_read_impl() const override { return true; }
|
||||||
virtual bool can_write_impl() const override { return true; }
|
virtual bool can_write_impl() const override { return true; }
|
||||||
@@ -49,13 +64,13 @@ namespace Kernel
|
|||||||
// NOTE: the inode might have more blocks than what this suggests if it has been shrinked
|
// NOTE: the inode might have more blocks than what this suggests if it has been shrinked
|
||||||
uint32_t max_used_data_block_count() const { return size() / blksize(); }
|
uint32_t max_used_data_block_count() const { return size() / blksize(); }
|
||||||
|
|
||||||
BAN::ErrorOr<void> sync_inode_no_lock();
|
BAN::ErrorOr<void> sync_no_lock();
|
||||||
|
|
||||||
BAN::ErrorOr<bool> is_directory_empty_no_lock();
|
BAN::ErrorOr<bool> is_directory_empty_no_lock();
|
||||||
BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_no_lock(BAN::StringView);
|
BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_no_lock(BAN::StringView);
|
||||||
|
|
||||||
/* needs write end of the lock when allocate is true*/
|
/* needs write end of the lock when allocate is true*/
|
||||||
BAN::ErrorOr<BAN::Optional<uint32_t>> block_from_indirect_block_no_lock(uint32_t block, uint32_t index, uint32_t depth, bool allocate);
|
BAN::ErrorOr<BAN::Optional<uint32_t>> block_from_indirect_block_no_lock(uint32_t& block, uint32_t index, uint32_t depth, bool allocate);
|
||||||
BAN::ErrorOr<BAN::Optional<uint32_t>> fs_block_of_data_block_index_no_lock(uint32_t data_block_index, bool allocate);
|
BAN::ErrorOr<BAN::Optional<uint32_t>> fs_block_of_data_block_index_no_lock(uint32_t data_block_index, bool allocate);
|
||||||
|
|
||||||
/* needs write end of the lock */
|
/* needs write end of the lock */
|
||||||
@@ -69,71 +84,40 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<void> cleanup_from_fs_no_lock();
|
BAN::ErrorOr<void> cleanup_from_fs_no_lock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ext2Inode(Ext2FS& fs, Ext2::Inode inode, uint32_t ino);
|
Ext2Inode(Ext2FS& fs, Ext2::Inode inode, uint32_t ino)
|
||||||
|
: m_fs(fs)
|
||||||
BAN::Optional<uint32_t> block_cache_find(uint32_t block, uint32_t index) const;
|
, m_inode(inode)
|
||||||
void block_cache_remove(uint32_t block, uint32_t index);
|
, m_ino(ino)
|
||||||
void block_cache_add(uint32_t block, uint32_t index, uint32_t target);
|
{}
|
||||||
|
static BAN::ErrorOr<BAN::RefPtr<Ext2Inode>> create(Ext2FS&, uint32_t);
|
||||||
BAN::RefPtr<Inode> dir_cache_find(BAN::StringView) const;
|
|
||||||
void dir_cache_remove(BAN::StringView);
|
|
||||||
void dir_cache_add(BAN::StringView, BAN::RefPtr<Inode>);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ScopedSync
|
struct ScopedSync
|
||||||
{
|
{
|
||||||
ScopedSync(Ext2Inode& inode)
|
ScopedSync(Ext2Inode& inode)
|
||||||
: inode(inode)
|
: inode(inode)
|
||||||
|
, inode_info(inode.m_inode)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~ScopedSync()
|
~ScopedSync()
|
||||||
{
|
{
|
||||||
// TODO: there was some memcmp smarty pants stuff here.
|
if (memcmp(&inode.m_inode, &inode_info, sizeof(Ext2::Inode)) == 0)
|
||||||
// How do we wanna approach it?
|
return;
|
||||||
if (auto ret = inode.sync_inode_no_lock(); ret.is_error())
|
if (auto ret = inode.sync_no_lock(); ret.is_error())
|
||||||
dwarnln("failed to sync inode: {}", ret.error());
|
dwarnln("failed to sync inode: {}", ret.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ext2Inode& inode;
|
Ext2Inode& inode;
|
||||||
|
Ext2::Inode inode_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ext2FS& m_fs;
|
Ext2FS& m_fs;
|
||||||
|
Ext2::Inode m_inode;
|
||||||
|
const uint32_t m_ino;
|
||||||
|
|
||||||
RWLock m_lock;
|
RWLock m_lock;
|
||||||
|
|
||||||
Ext2::InodeBlocks m_ext2_blocks;
|
|
||||||
// NOTE: some fields from the original disk inode
|
|
||||||
// that we do not use, but we keep for serialise.
|
|
||||||
const uint32_t m_og_dtime;
|
|
||||||
const uint32_t m_og_flags;
|
|
||||||
const uint32_t m_og_osd1;
|
|
||||||
const uint32_t m_og_generation;
|
|
||||||
const uint32_t m_og_file_acl;
|
|
||||||
const uint32_t m_og_dir_acl;
|
|
||||||
const uint32_t m_og_faddr;
|
|
||||||
const Ext2::Osd2 m_og_osd2;
|
|
||||||
|
|
||||||
struct BlockCacheEntry
|
|
||||||
{
|
|
||||||
mutable uint32_t freq;
|
|
||||||
uint32_t block;
|
|
||||||
uint32_t index;
|
|
||||||
uint32_t target;
|
|
||||||
};
|
|
||||||
mutable SpinLock m_block_cache_lock;
|
|
||||||
BAN::Array<BlockCacheEntry, 8> m_block_cache;
|
|
||||||
|
|
||||||
struct DirCacheEntry
|
|
||||||
{
|
|
||||||
mutable size_t freq { 0 };
|
|
||||||
BAN::RefPtr<Inode> inode;
|
|
||||||
size_t name_len { 0 };
|
|
||||||
char name[256];
|
|
||||||
};
|
|
||||||
static constexpr size_t dir_cache_size = 32;
|
|
||||||
mutable RWLock m_dir_cache_lock;
|
|
||||||
BAN::Vector<DirCacheEntry> m_dir_cache;
|
|
||||||
|
|
||||||
friend class Ext2FS;
|
friend class Ext2FS;
|
||||||
friend class BAN::RefPtr<Ext2Inode>;
|
friend class BAN::RefPtr<Ext2Inode>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <kernel/FS/FAT/Definitions.h>
|
#include <kernel/FS/FAT/Definitions.h>
|
||||||
#include <kernel/FS/FAT/Inode.h>
|
#include <kernel/FS/FAT/Inode.h>
|
||||||
#include <kernel/FS/FileSystem.h>
|
#include <kernel/FS/FileSystem.h>
|
||||||
#include <kernel/Lock/Mutex.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,14 +15,25 @@ namespace Kernel
|
|||||||
class FATInode final : public Inode, public BAN::Weakable<FATInode>
|
class FATInode final : public Inode, public BAN::Weakable<FATInode>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ino_t ino() const override { return m_ino; };
|
||||||
|
virtual Mode mode() const override { return Mode { ((m_entry.attr & FAT::FileAttr::DIRECTORY) ? Mode::IFDIR : Mode::IFREG) | 0777 }; }
|
||||||
|
virtual nlink_t nlink() const override { return 1; }
|
||||||
|
virtual uid_t uid() const override { return 0; }
|
||||||
|
virtual gid_t gid() const override { return 0; }
|
||||||
|
virtual off_t size() const override { return m_entry.file_size; }
|
||||||
|
virtual timespec atime() const override;
|
||||||
|
virtual timespec mtime() const override;
|
||||||
|
virtual timespec ctime() const override;
|
||||||
|
virtual blksize_t blksize() const override;
|
||||||
|
virtual blkcnt_t blocks() const override { return m_block_count; }
|
||||||
|
virtual dev_t dev() const override { return 0; }
|
||||||
|
virtual dev_t rdev() const override { return 0; }
|
||||||
|
|
||||||
virtual const FileSystem* filesystem() const override;
|
virtual const FileSystem* filesystem() const override;
|
||||||
|
|
||||||
const FAT::DirectoryEntry& entry() const { return m_entry; }
|
const FAT::DirectoryEntry& entry() const { return m_entry; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
virtual BAN::ErrorOr<void> sync_inode(SyncType) override { return {}; }
|
|
||||||
virtual BAN::ErrorOr<void> sync_data() override { return {}; }
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
||||||
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
||||||
//virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
|
//virtual BAN::ErrorOr<void> create_file_impl(BAN::StringView, mode_t, uid_t, gid_t) override;
|
||||||
@@ -32,6 +43,9 @@ namespace Kernel
|
|||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
//virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
//virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
//virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
//virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
||||||
|
//virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
|
||||||
|
//virtual BAN::ErrorOr<void> utimens_impl(const timespec[2]) override;
|
||||||
|
virtual BAN::ErrorOr<void> fsync_impl() override { return {}; }
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return true; }
|
virtual bool can_read_impl() const override { return true; }
|
||||||
virtual bool can_write_impl() const override { return true; }
|
virtual bool can_write_impl() const override { return true; }
|
||||||
@@ -39,8 +53,12 @@ namespace Kernel
|
|||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FATInode(FATFS& fs, const FAT::DirectoryEntry& entry, ino_t ino, uint32_t block_count);
|
FATInode(FATFS& fs, const FAT::DirectoryEntry& entry, ino_t ino, uint32_t block_count)
|
||||||
|
: m_fs(fs)
|
||||||
|
, m_entry(entry)
|
||||||
|
, m_ino(ino)
|
||||||
|
, m_block_count(block_count)
|
||||||
|
{ }
|
||||||
~FATInode() {}
|
~FATInode() {}
|
||||||
|
|
||||||
BAN::ErrorOr<void> for_each_directory_entry(BAN::ConstByteSpan, BAN::Function<BAN::Iteration(const FAT::DirectoryEntry&)>);
|
BAN::ErrorOr<void> for_each_directory_entry(BAN::ConstByteSpan, BAN::Function<BAN::Iteration(const FAT::DirectoryEntry&)>);
|
||||||
@@ -49,6 +67,7 @@ namespace Kernel
|
|||||||
private:
|
private:
|
||||||
FATFS& m_fs;
|
FATFS& m_fs;
|
||||||
FAT::DirectoryEntry m_entry;
|
FAT::DirectoryEntry m_entry;
|
||||||
|
const ino_t m_ino;
|
||||||
uint32_t m_block_count;
|
uint32_t m_block_count;
|
||||||
|
|
||||||
friend class Ext2FS;
|
friend class Ext2FS;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <kernel/Device/Device.h>
|
||||||
#include <kernel/FS/Inode.h>
|
#include <kernel/FS/Inode.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class BlockDevice;
|
|
||||||
|
|
||||||
class FileSystem : public BAN::RefCounted<FileSystem>
|
class FileSystem : public BAN::RefCounted<FileSystem>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -62,52 +62,31 @@ namespace Kernel
|
|||||||
mode_t mode;
|
mode_t mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum InodeKind : uint8_t
|
|
||||||
{
|
|
||||||
DEVICE = 0x01,
|
|
||||||
EPOLL = 0x02,
|
|
||||||
PIPE = 0x04,
|
|
||||||
TTY = 0x08,
|
|
||||||
PARTITION = 0x10,
|
|
||||||
STORAGE = 0x20,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SyncType
|
|
||||||
{
|
|
||||||
General,
|
|
||||||
Mode,
|
|
||||||
UidGid,
|
|
||||||
Times,
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Inode() {}
|
virtual ~Inode() {}
|
||||||
|
|
||||||
static bool can_access(uid_t uid, gid_t gid, mode_t mode, const Credentials& credentials, int);
|
|
||||||
bool can_access(const Credentials&, int) const;
|
bool can_access(const Credentials&, int) const;
|
||||||
|
|
||||||
bool operator==(const Inode& other) const { return dev() == other.dev() && ino() == other.ino(); }
|
bool operator==(const Inode& other) const { return dev() == other.dev() && ino() == other.ino(); }
|
||||||
|
|
||||||
ino_t ino() const { return m_ino; }
|
virtual ino_t ino() const = 0;
|
||||||
Mode mode() const { return Mode(m_mode); }
|
virtual Mode mode() const = 0;
|
||||||
nlink_t nlink() const { return m_nlink; }
|
virtual nlink_t nlink() const = 0;
|
||||||
uid_t uid() const { return m_uid; }
|
virtual uid_t uid() const = 0;
|
||||||
gid_t gid() const { return m_gid; }
|
virtual gid_t gid() const = 0;
|
||||||
off_t size() const { return m_size; }
|
virtual off_t size() const = 0;
|
||||||
timespec atime() const { return m_atime; }
|
virtual timespec atime() const = 0;
|
||||||
timespec mtime() const { return m_mtime; }
|
virtual timespec mtime() const = 0;
|
||||||
timespec ctime() const { return m_ctime; }
|
virtual timespec ctime() const = 0;
|
||||||
blksize_t blksize() const { return m_blksize; }
|
virtual blksize_t blksize() const = 0;
|
||||||
blkcnt_t blocks() const { return m_blocks; }
|
virtual blkcnt_t blocks() const = 0;
|
||||||
dev_t dev() const { return m_dev; }
|
virtual dev_t dev() const = 0;
|
||||||
dev_t rdev() const { return m_rdev; }
|
virtual dev_t rdev() const = 0;
|
||||||
|
|
||||||
bool is_device() const { return m_kind & InodeKind::DEVICE; }
|
virtual bool is_device() const { return false; }
|
||||||
bool is_epoll() const { return m_kind & InodeKind::EPOLL; }
|
virtual bool is_epoll() const { return false; }
|
||||||
bool is_pipe() const { return m_kind & InodeKind::PIPE; }
|
virtual bool is_pipe() const { return false; }
|
||||||
bool is_tty() const { return m_kind & InodeKind::TTY; }
|
virtual bool is_tty() const { return false; }
|
||||||
bool is_partition() const { return m_kind & InodeKind::PARTITION; }
|
|
||||||
bool is_storage_device() const { return m_kind & InodeKind::STORAGE; }
|
|
||||||
|
|
||||||
virtual const FileSystem* filesystem() const = 0;
|
virtual const FileSystem* filesystem() const = 0;
|
||||||
|
|
||||||
@@ -146,12 +125,12 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<void> fsync();
|
BAN::ErrorOr<void> fsync();
|
||||||
|
|
||||||
// Select/Non blocking API
|
// Select/Non blocking API
|
||||||
bool can_read() const { return can_read_impl(); }
|
bool can_read() const;
|
||||||
bool can_write() const { return can_write_impl(); }
|
bool can_write() const;
|
||||||
bool has_error() const { return has_error_impl(); }
|
bool has_error() const;
|
||||||
bool has_hungup() const { return has_hungup_impl(); }
|
bool has_hungup() const;
|
||||||
|
|
||||||
BAN::ErrorOr<long> ioctl(unsigned long request, void* arg);
|
BAN::ErrorOr<long> ioctl(int request, void* arg);
|
||||||
|
|
||||||
BAN::ErrorOr<void> add_epoll(class Epoll*);
|
BAN::ErrorOr<void> add_epoll(class Epoll*);
|
||||||
void del_epoll(class Epoll*);
|
void del_epoll(class Epoll*);
|
||||||
@@ -160,9 +139,6 @@ namespace Kernel
|
|||||||
virtual void on_close(int status_flags) { (void)status_flags; }
|
virtual void on_close(int status_flags) { (void)status_flags; }
|
||||||
virtual void on_clone(int status_flags) { (void)status_flags; }
|
virtual void on_clone(int status_flags) { (void)status_flags; }
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> sync_inode(SyncType) = 0;
|
|
||||||
virtual BAN::ErrorOr<void> sync_data() = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Directory API
|
// Directory API
|
||||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
@@ -193,6 +169,10 @@ namespace Kernel
|
|||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<void> truncate_impl(size_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
virtual BAN::ErrorOr<void> chmod_impl(mode_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
virtual BAN::ErrorOr<void> chown_impl(uid_t, gid_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
virtual BAN::ErrorOr<void> utimens_impl(const timespec[2]) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
virtual BAN::ErrorOr<void> fsync_impl() = 0;
|
||||||
|
|
||||||
// Select/Non blocking API
|
// Select/Non blocking API
|
||||||
virtual bool can_read_impl() const = 0;
|
virtual bool can_read_impl() const = 0;
|
||||||
@@ -200,28 +180,7 @@ namespace Kernel
|
|||||||
virtual bool has_error_impl() const = 0;
|
virtual bool has_error_impl() const = 0;
|
||||||
virtual bool has_hungup_impl() const = 0;
|
virtual bool has_hungup_impl() const = 0;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<long> ioctl_impl(unsigned long, void*) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<long> ioctl_impl(int, void*) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
|
||||||
protected:
|
|
||||||
// TODO: this is supposed to be const I guess?
|
|
||||||
// But the thing is I would have to refactor a big chunk of the codebase
|
|
||||||
// to add it as a parameter to Inode() soooooo yeah no, not doing that rn.
|
|
||||||
uint8_t m_kind = 0;
|
|
||||||
|
|
||||||
BAN::Atomic<ino_t> m_ino;
|
|
||||||
BAN::Atomic<mode_t> m_mode;
|
|
||||||
BAN::Atomic<nlink_t> m_nlink;
|
|
||||||
BAN::Atomic<uid_t> m_uid;
|
|
||||||
BAN::Atomic<gid_t> m_gid;
|
|
||||||
BAN::Atomic<off_t> m_size;
|
|
||||||
// TODO: make these guys atomic :)
|
|
||||||
timespec m_atime;
|
|
||||||
timespec m_mtime;
|
|
||||||
timespec m_ctime;
|
|
||||||
BAN::Atomic<blksize_t> m_blksize;
|
|
||||||
BAN::Atomic<blkcnt_t> m_blocks;
|
|
||||||
BAN::Atomic<dev_t> m_dev;
|
|
||||||
BAN::Atomic<dev_t> m_rdev;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpinLock m_shared_region_lock;
|
SpinLock m_shared_region_lock;
|
||||||
@@ -229,7 +188,6 @@ namespace Kernel
|
|||||||
|
|
||||||
SpinLock m_epoll_lock;
|
SpinLock m_epoll_lock;
|
||||||
BAN::LinkedList<class Epoll*> m_epolls;
|
BAN::LinkedList<class Epoll*> m_epolls;
|
||||||
|
|
||||||
friend class Epoll;
|
friend class Epoll;
|
||||||
friend class FileBackedRegion;
|
friend class FileBackedRegion;
|
||||||
friend class OpenFileDescriptorSet;
|
friend class OpenFileDescriptorSet;
|
||||||
|
|||||||
@@ -5,49 +5,64 @@
|
|||||||
#include <kernel/Memory/ByteRingBuffer.h>
|
#include <kernel/Memory/ByteRingBuffer.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/ThreadBlocker.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class Pipe final : public Inode, public BAN::Weakable<Pipe>
|
class Pipe : public Inode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<Inode>> open(BAN::RefPtr<Inode>, int status_flags);
|
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(const Credentials&);
|
||||||
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(uid_t, gid_t);
|
|
||||||
~Pipe();
|
virtual bool is_pipe() const override { return true; }
|
||||||
|
|
||||||
void on_close(int status_flags) override;
|
void on_close(int status_flags) override;
|
||||||
void on_clone(int status_flags) override;
|
void on_clone(int status_flags) override;
|
||||||
|
|
||||||
|
virtual ino_t ino() const override { return 0; } // FIXME
|
||||||
|
virtual Mode mode() const override { return { Mode::IFIFO | Mode::IRUSR | Mode::IWUSR }; }
|
||||||
|
virtual nlink_t nlink() const override { return 1; }
|
||||||
|
virtual uid_t uid() const override { return m_uid; }
|
||||||
|
virtual gid_t gid() const override { return m_gid; }
|
||||||
|
virtual off_t size() const override { return 0; }
|
||||||
|
virtual timespec atime() const override { return m_atime; }
|
||||||
|
virtual timespec mtime() const override { return m_mtime; }
|
||||||
|
virtual timespec ctime() const override { return m_ctime; }
|
||||||
|
virtual blksize_t blksize() const override { return 4096; }
|
||||||
|
virtual blkcnt_t blocks() const override { return 0; }
|
||||||
|
virtual dev_t dev() const override { return 0; } // FIXME
|
||||||
|
virtual dev_t rdev() const override { return 0; } // FIXME
|
||||||
|
|
||||||
virtual const FileSystem* filesystem() const override { return nullptr; }
|
virtual const FileSystem* filesystem() const override { return nullptr; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
virtual BAN::ErrorOr<void> sync_inode(SyncType) override;
|
|
||||||
virtual BAN::ErrorOr<void> sync_data() override;
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
virtual BAN::ErrorOr<void> fsync_impl() final override { return {}; }
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return !m_buffer->empty(); }
|
virtual bool can_read_impl() const override { return !m_buffer->empty(); }
|
||||||
virtual bool can_write_impl() const override { return true; }
|
virtual bool can_write_impl() const override { return true; }
|
||||||
virtual bool has_error_impl() const override { return m_reading_count == 0; }
|
virtual bool has_error_impl() const override { return m_reading_count == 0; }
|
||||||
virtual bool has_hungup_impl() const override { return m_writing_count == 0; }
|
virtual bool has_hungup_impl() const override { return m_writing_count == 0; }
|
||||||
|
|
||||||
private:
|
virtual BAN::ErrorOr<long> ioctl_impl(int, void*) override;
|
||||||
Pipe(const struct stat&);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Pipe(const Credentials&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const uid_t m_uid;
|
||||||
|
const gid_t m_gid;
|
||||||
|
timespec m_atime {};
|
||||||
|
timespec m_mtime {};
|
||||||
|
timespec m_ctime {};
|
||||||
|
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
|
|
||||||
BAN::UniqPtr<ByteRingBuffer> m_buffer;
|
BAN::UniqPtr<ByteRingBuffer> m_buffer;
|
||||||
|
|
||||||
BAN::Atomic<uint32_t> m_writing_count { 0 };
|
BAN::Atomic<uint32_t> m_writing_count { 1 };
|
||||||
BAN::Atomic<uint32_t> m_reading_count { 0 };
|
BAN::Atomic<uint32_t> m_reading_count { 1 };
|
||||||
|
|
||||||
BAN::RefPtr<Inode> m_named_inode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,17 @@
|
|||||||
|
|
||||||
#include <kernel/FS/TmpFS/FileSystem.h>
|
#include <kernel/FS/TmpFS/FileSystem.h>
|
||||||
#include <kernel/FS/TmpFS/Inode.h>
|
#include <kernel/FS/TmpFS/Inode.h>
|
||||||
|
#include <kernel/Process.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class Process;
|
|
||||||
|
|
||||||
class ProcFileSystem final : public TmpFileSystem
|
class ProcFileSystem final : public TmpFileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static ProcFileSystem& get();
|
static ProcFileSystem& get();
|
||||||
|
|
||||||
void post_scheduler_initialize();
|
|
||||||
|
|
||||||
BAN::ErrorOr<void> on_process_create(Process&);
|
BAN::ErrorOr<void> on_process_create(Process&);
|
||||||
void on_process_delete(Process&);
|
void on_process_delete(Process&);
|
||||||
|
|
||||||
|
|||||||
@@ -2,35 +2,41 @@
|
|||||||
|
|
||||||
#include <kernel/FS/TmpFS/FileSystem.h>
|
#include <kernel/FS/TmpFS/FileSystem.h>
|
||||||
#include <kernel/FS/TmpFS/Inode.h>
|
#include <kernel/FS/TmpFS/Inode.h>
|
||||||
|
#include <kernel/Process.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
class Process;
|
|
||||||
|
|
||||||
class ProcPidInode final : public TmpDirectoryInode
|
class ProcPidInode final : public TmpDirectoryInode
|
||||||
{
|
{
|
||||||
// FIXME: dynamically update ruid/rgid.
|
|
||||||
// Possibly just have a magic uid/gid of -1 or something
|
|
||||||
// which means use current process ID
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcPidInode>> create_new(Process&, TmpFileSystem&, mode_t);
|
||||||
~ProcPidInode() = default;
|
~ProcPidInode() = default;
|
||||||
|
|
||||||
|
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
|
||||||
|
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<void> unlink_impl(BAN::StringView) override { return BAN::Error::from_errno(EPERM); }
|
virtual BAN::ErrorOr<void> unlink_impl(BAN::StringView) override { return BAN::Error::from_errno(EPERM); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProcPidInode(Process&, TmpFileSystem&, const TmpInodeInfo&);
|
ProcPidInode(Process&, TmpFileSystem&, const TmpInodeInfo&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Process& m_process;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProcROProcessInode final : public TmpInode
|
class ProcROProcessInode final : public TmpInode
|
||||||
{
|
{
|
||||||
//FIXME: dynamically update ruid/rgid
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcROProcessInode>> create_new(Process&, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem&, mode_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcROProcessInode>> create_new(Process&, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem&, mode_t);
|
||||||
~ProcROProcessInode() = default;
|
~ProcROProcessInode() = default;
|
||||||
|
|
||||||
|
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
|
||||||
|
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
|
|
||||||
@@ -53,11 +59,13 @@ namespace Kernel
|
|||||||
|
|
||||||
class ProcSymlinkProcessInode final : public TmpInode
|
class ProcSymlinkProcessInode final : public TmpInode
|
||||||
{
|
{
|
||||||
//FIXME: dynamically update ruid/rgid
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcSymlinkProcessInode>> create_new(Process& process, BAN::ErrorOr<BAN::String> (Process::*callback)() const, TmpFileSystem&, mode_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcSymlinkProcessInode>> create_new(Process& process, BAN::ErrorOr<BAN::String> (Process::*callback)() const, TmpFileSystem&, mode_t);
|
||||||
~ProcSymlinkProcessInode() = default;
|
~ProcSymlinkProcessInode() = default;
|
||||||
|
|
||||||
|
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
|
||||||
|
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<BAN::String> link_target_impl() override;
|
virtual BAN::ErrorOr<BAN::String> link_target_impl() override;
|
||||||
|
|
||||||
@@ -77,7 +85,7 @@ namespace Kernel
|
|||||||
class ProcROInode final : public TmpInode
|
class ProcROInode final : public TmpInode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcROInode>> create_new(BAN::ErrorOr<size_t> (*callback)(off_t, BAN::ByteSpan, void*), TmpFileSystem&, void*, mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcROInode>> create_new(size_t (*callback)(off_t, BAN::ByteSpan), TmpFileSystem&, mode_t, uid_t, gid_t);
|
||||||
~ProcROInode() = default;
|
~ProcROInode() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -93,11 +101,10 @@ namespace Kernel
|
|||||||
virtual bool has_hungup_impl() const override { return false; }
|
virtual bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProcROInode(BAN::ErrorOr<size_t> (*callback)(off_t, BAN::ByteSpan, void*), TmpFileSystem&, void*, const TmpInodeInfo&);
|
ProcROInode(size_t (*callback)(off_t, BAN::ByteSpan), TmpFileSystem&, const TmpInodeInfo&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::ErrorOr<size_t> (*m_callback)(off_t, BAN::ByteSpan, void*);
|
size_t (*m_callback)(off_t, BAN::ByteSpan);
|
||||||
void* m_argument;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProcSymlinkInode final : public TmpInode
|
class ProcSymlinkInode final : public TmpInode
|
||||||
@@ -125,10 +132,13 @@ namespace Kernel
|
|||||||
|
|
||||||
class ProcFDDirectoryInode final : public TmpInode
|
class ProcFDDirectoryInode final : public TmpInode
|
||||||
{
|
{
|
||||||
//FIXME: dynamically update ruid/rgid
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<ProcFDDirectoryInode>> create_new(Process&, TmpFileSystem&, mode_t);
|
static BAN::ErrorOr<BAN::RefPtr<ProcFDDirectoryInode>> create_new(Process&, TmpFileSystem&, mode_t);
|
||||||
~ProcFDDirectoryInode() = default;
|
~ProcFDDirectoryInode() = default;
|
||||||
|
|
||||||
|
virtual uid_t uid() const override { return m_process.credentials().ruid(); }
|
||||||
|
virtual gid_t gid() const override { return m_process.credentials().rgid(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> find_inode_impl(BAN::StringView) override;
|
||||||
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
virtual BAN::ErrorOr<size_t> list_next_inodes_impl(off_t, struct dirent*, size_t) override;
|
||||||
|
|||||||
@@ -30,19 +30,31 @@ namespace Kernel
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ino_t ino() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
Mode mode() const final override { return Mode(m_info.mode); }
|
||||||
|
nlink_t nlink() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
uid_t uid() const final override { return m_info.uid; }
|
||||||
|
gid_t gid() const final override { return m_info.gid; }
|
||||||
|
off_t size() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
timespec atime() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
timespec mtime() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
timespec ctime() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
blksize_t blksize() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
blkcnt_t blocks() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
dev_t dev() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
dev_t rdev() const final override { ASSERT_NOT_REACHED(); }
|
||||||
|
|
||||||
const FileSystem* filesystem() const final override { return nullptr; }
|
const FileSystem* filesystem() const final override { return nullptr; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Socket(const Info& info)
|
Socket(const Info& info)
|
||||||
{
|
: m_info(info)
|
||||||
m_mode = info.mode;
|
{}
|
||||||
m_uid = info.uid;
|
|
||||||
m_gid = info.gid;
|
BAN::ErrorOr<void> fsync_impl() final override { return {}; }
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::ErrorOr<void> sync_inode(SyncType) final override { return {}; }
|
const Info m_info;
|
||||||
BAN::ErrorOr<void> sync_data() final override { return {}; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,18 @@
|
|||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TmpBlocks
|
struct TmpInodeInfo
|
||||||
{
|
{
|
||||||
|
mode_t mode { 0 };
|
||||||
|
uid_t uid { 0 };
|
||||||
|
gid_t gid { 0 };
|
||||||
|
timespec atime { 0, 0 };
|
||||||
|
timespec ctime { 0, 0 };
|
||||||
|
timespec mtime { 0, 0 };
|
||||||
|
nlink_t nlink { 0 };
|
||||||
|
size_t size { 0 };
|
||||||
|
blkcnt_t blocks { 0 };
|
||||||
|
|
||||||
#if ARCH(x86_64)
|
#if ARCH(x86_64)
|
||||||
// 2x direct blocks
|
// 2x direct blocks
|
||||||
// 1x singly indirect
|
// 1x singly indirect
|
||||||
@@ -31,23 +41,8 @@ namespace Kernel
|
|||||||
#else
|
#else
|
||||||
#error
|
#error
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
struct TmpInodeInfo
|
|
||||||
{
|
|
||||||
mode_t mode { 0 };
|
|
||||||
uid_t uid { 0 };
|
|
||||||
gid_t gid { 0 };
|
|
||||||
timespec atime { 0, 0 };
|
|
||||||
timespec ctime { 0, 0 };
|
|
||||||
timespec mtime { 0, 0 };
|
|
||||||
nlink_t nlink { 0 };
|
|
||||||
size_t size { 0 };
|
|
||||||
blkcnt_t blocks { 0 };
|
|
||||||
TmpBlocks tmp_blocks;
|
|
||||||
|
|
||||||
static constexpr size_t max_size =
|
static constexpr size_t max_size =
|
||||||
TmpBlocks::direct_block_count * PAGE_SIZE +
|
direct_block_count * PAGE_SIZE +
|
||||||
(PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE +
|
(PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE +
|
||||||
(PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE +
|
(PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE +
|
||||||
(PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE;
|
(PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * (PAGE_SIZE / sizeof(paddr_t)) * PAGE_SIZE;
|
||||||
|
|||||||
@@ -24,16 +24,36 @@ namespace Kernel
|
|||||||
|
|
||||||
class TmpInode : public Inode
|
class TmpInode : public Inode
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
virtual ino_t ino() const override { return m_ino; }
|
||||||
|
virtual Mode mode() const override { return Mode(m_inode_info.mode); }
|
||||||
|
virtual nlink_t nlink() const override { return m_inode_info.nlink; }
|
||||||
|
virtual uid_t uid() const override { return m_inode_info.uid; }
|
||||||
|
virtual gid_t gid() const override { return m_inode_info.gid; }
|
||||||
|
virtual off_t size() const override { return m_inode_info.size; }
|
||||||
|
virtual timespec atime() const override { return m_inode_info.atime; }
|
||||||
|
virtual timespec mtime() const override { return m_inode_info.mtime; }
|
||||||
|
virtual timespec ctime() const override { return m_inode_info.ctime; }
|
||||||
|
virtual blksize_t blksize() const override { return PAGE_SIZE; }
|
||||||
|
virtual blkcnt_t blocks() const override { return m_inode_info.blocks; }
|
||||||
|
virtual dev_t dev() const override;
|
||||||
|
virtual dev_t rdev() const override { return 0; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<TmpInode>> create_from_existing(TmpFileSystem&, ino_t, const TmpInodeInfo&);
|
static BAN::ErrorOr<BAN::RefPtr<TmpInode>> create_from_existing(TmpFileSystem&, ino_t, const TmpInodeInfo&);
|
||||||
virtual ~TmpInode();
|
~TmpInode();
|
||||||
|
|
||||||
virtual const FileSystem* filesystem() const override;
|
virtual const FileSystem* filesystem() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TmpInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
|
TmpInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
|
||||||
|
|
||||||
void write_inode_to_fs();
|
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
|
||||||
|
virtual BAN::ErrorOr<void> chown_impl(uid_t, gid_t) override;
|
||||||
|
virtual BAN::ErrorOr<void> utimens_impl(const timespec[2]) override;
|
||||||
|
virtual BAN::ErrorOr<void> fsync_impl() override { return {}; }
|
||||||
|
|
||||||
|
void sync();
|
||||||
virtual BAN::ErrorOr<void> prepare_unlink_no_lock() { return {}; };
|
virtual BAN::ErrorOr<void> prepare_unlink_no_lock() { return {}; };
|
||||||
|
|
||||||
void free_all_blocks();
|
void free_all_blocks();
|
||||||
@@ -45,13 +65,10 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<size_t> block_index_with_allocation(size_t data_block_index);
|
BAN::ErrorOr<size_t> block_index_with_allocation(size_t data_block_index);
|
||||||
BAN::ErrorOr<size_t> block_index_from_indirect_with_allocation_no_lock(size_t& block, size_t index, uint32_t depth);
|
BAN::ErrorOr<size_t> block_index_from_indirect_with_allocation_no_lock(size_t& block, size_t index, uint32_t depth);
|
||||||
|
|
||||||
private:
|
|
||||||
BAN::ErrorOr<void> sync_inode(SyncType) override;
|
|
||||||
BAN::ErrorOr<void> sync_data() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TmpFileSystem& m_fs;
|
TmpFileSystem& m_fs;
|
||||||
TmpBlocks m_tmp_blocks;
|
TmpInodeInfo m_inode_info;
|
||||||
|
const ino_t m_ino;
|
||||||
|
|
||||||
// TODO: try to reduce locking or replace this with rwlock(?)
|
// TODO: try to reduce locking or replace this with rwlock(?)
|
||||||
Mutex m_lock;
|
Mutex m_lock;
|
||||||
@@ -66,7 +83,7 @@ namespace Kernel
|
|||||||
static BAN::ErrorOr<BAN::RefPtr<TmpFileInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<TmpFileInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
|
||||||
~TmpFileInode();
|
~TmpFileInode();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
||||||
@@ -82,36 +99,13 @@ namespace Kernel
|
|||||||
friend class TmpInode;
|
friend class TmpInode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: this is just a dummy, when opening a fifo a pipe is created
|
|
||||||
class TmpFIFOInode : public TmpInode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static BAN::ErrorOr<BAN::RefPtr<TmpFIFOInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
|
|
||||||
~TmpFIFOInode();
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override { return BAN::Error::from_errno(ENODEV); }
|
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return false; }
|
|
||||||
virtual bool can_write_impl() const override { return false; }
|
|
||||||
virtual bool has_error_impl() const override { return false; }
|
|
||||||
virtual bool has_hungup_impl() const override { return false; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
TmpFIFOInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
|
|
||||||
|
|
||||||
friend class TmpInode;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TmpSocketInode : public TmpInode
|
class TmpSocketInode : public TmpInode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<TmpSocketInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
|
static BAN::ErrorOr<BAN::RefPtr<TmpSocketInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t);
|
||||||
~TmpSocketInode();
|
~TmpSocketInode();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
||||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override { return BAN::Error::from_errno(ENODEV); }
|
||||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override { return BAN::Error::from_errno(ENODEV); }
|
virtual BAN::ErrorOr<void> truncate_impl(size_t) override { return BAN::Error::from_errno(ENODEV); }
|
||||||
@@ -133,7 +127,7 @@ namespace Kernel
|
|||||||
static BAN::ErrorOr<BAN::RefPtr<TmpSymlinkInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t, BAN::StringView target);
|
static BAN::ErrorOr<BAN::RefPtr<TmpSymlinkInode>> create_new(TmpFileSystem&, mode_t, uid_t, gid_t, BAN::StringView target);
|
||||||
~TmpSymlinkInode();
|
~TmpSymlinkInode();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
BAN::ErrorOr<BAN::String> link_target_impl() override;
|
BAN::ErrorOr<BAN::String> link_target_impl() override;
|
||||||
BAN::ErrorOr<void> set_link_target_impl(BAN::StringView) override;
|
BAN::ErrorOr<void> set_link_target_impl(BAN::StringView) override;
|
||||||
|
|
||||||
|
|||||||
@@ -92,9 +92,8 @@ namespace Kernel
|
|||||||
MountPoint* mount_from_root_inode(BAN::RefPtr<Inode>);
|
MountPoint* mount_from_root_inode(BAN::RefPtr<Inode>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Mutex m_mutex;
|
||||||
BAN::RefPtr<FileSystem> m_root_fs;
|
BAN::RefPtr<FileSystem> m_root_fs;
|
||||||
|
|
||||||
Mutex m_mount_point_lock;
|
|
||||||
BAN::Vector<MountPoint> m_mount_points;
|
BAN::Vector<MountPoint> m_mount_points;
|
||||||
|
|
||||||
friend class BAN::RefPtr<VirtualFileSystem>;
|
friend class BAN::RefPtr<VirtualFileSystem>;
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <BAN/RefPtr.h>
|
|
||||||
#include <kernel/Lock/SpinLock.h>
|
|
||||||
#include <kernel/PCI.h>
|
|
||||||
|
|
||||||
#include <sys/framebuffer.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
|
||||||
{
|
|
||||||
|
|
||||||
class BGAController : public BAN::RefCounted<BGAController>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static BAN::ErrorOr<BAN::RefPtr<BGAController>> create(PCI::Device&);
|
|
||||||
|
|
||||||
fb_fix_info get_fb_fix_info() const;
|
|
||||||
fb_var_info get_fb_var_info() const;
|
|
||||||
BAN::ErrorOr<void> set_fb_var_info(const fb_var_info&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
BGAController(PCI::Device&);
|
|
||||||
BAN::ErrorOr<void> initialize();
|
|
||||||
|
|
||||||
void write_reg(uint16_t reg, uint16_t value);
|
|
||||||
uint16_t read_reg(uint16_t reg);
|
|
||||||
|
|
||||||
private:
|
|
||||||
mutable RecursiveSpinLock m_lock;
|
|
||||||
PCI::Device& m_pci_device;
|
|
||||||
BAN::UniqPtr<PCI::BarRegion> m_lfb_bar;
|
|
||||||
|
|
||||||
fb_fix_info m_fix_info {};
|
|
||||||
fb_var_info m_var_info {};
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,21 @@
|
|||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// IDT entries
|
||||||
|
// 0x00->0x1F (32): ISR
|
||||||
|
// 0x20->0x7F (96): PIC/IOAPIC
|
||||||
|
// 0x80->0xEF (112): MSI
|
||||||
|
// 0xF0->0xFE (15): internal
|
||||||
|
|
||||||
|
constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
|
||||||
|
constexpr uint8_t IRQ_MSI_BASE = 0x80;
|
||||||
|
constexpr uint8_t IRQ_MSI_END = 0xF0;
|
||||||
|
#if ARCH(i686)
|
||||||
|
constexpr uint8_t IRQ_SYSCALL = 0xF0; // hard coded in kernel/API/Syscall.h
|
||||||
|
#endif
|
||||||
|
constexpr uint8_t IRQ_IPI = 0xF1;
|
||||||
|
constexpr uint8_t IRQ_TIMER = 0xF2;
|
||||||
|
|
||||||
#if ARCH(x86_64)
|
#if ARCH(x86_64)
|
||||||
struct GateDescriptor
|
struct GateDescriptor
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace Kernel
|
|||||||
InputDevice(Type type);
|
InputDevice(Type type);
|
||||||
|
|
||||||
BAN::StringView name() const final override { return m_name; }
|
BAN::StringView name() const final override { return m_name; }
|
||||||
|
dev_t rdev() const final override { return m_rdev; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void add_event(BAN::ConstByteSpan);
|
void add_event(BAN::ConstByteSpan);
|
||||||
|
|
||||||
@@ -36,7 +38,8 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<size_t> read_non_block(BAN::ByteSpan);
|
BAN::ErrorOr<size_t> read_non_block(BAN::ByteSpan);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::String m_name;
|
const dev_t m_rdev;
|
||||||
|
const BAN::String m_name;
|
||||||
|
|
||||||
const Type m_type;
|
const Type m_type;
|
||||||
|
|
||||||
@@ -61,7 +64,6 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<KeyboardDevice>> create(mode_t mode, uid_t uid, gid_t gid);
|
static BAN::ErrorOr<BAN::RefPtr<KeyboardDevice>> create(mode_t mode, uid_t uid, gid_t gid);
|
||||||
static BAN::ErrorOr<void> initialize_tty_thread();
|
|
||||||
|
|
||||||
void notify();
|
void notify();
|
||||||
|
|
||||||
@@ -75,8 +77,10 @@ namespace Kernel
|
|||||||
bool has_hungup_impl() const override { return false; }
|
bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
BAN::StringView name() const final override { return m_name; }
|
BAN::StringView name() const final override { return m_name; }
|
||||||
|
dev_t rdev() const final override { return m_rdev; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
const BAN::StringView m_name;
|
const BAN::StringView m_name;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
|
|
||||||
@@ -100,7 +104,10 @@ namespace Kernel
|
|||||||
bool has_hungup_impl() const override { return false; }
|
bool has_hungup_impl() const override { return false; }
|
||||||
|
|
||||||
BAN::StringView name() const final override { return m_name; }
|
BAN::StringView name() const final override { return m_name; }
|
||||||
|
dev_t rdev() const final override { return m_rdev; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const dev_t m_rdev;
|
||||||
const BAN::StringView m_name;
|
const BAN::StringView m_name;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ namespace Kernel::Input
|
|||||||
uint8_t m_byte_index { 0 };
|
uint8_t m_byte_index { 0 };
|
||||||
bool m_basic { false };
|
bool m_basic { false };
|
||||||
|
|
||||||
bool m_scancode_set_uncertain { false };
|
|
||||||
uint8_t m_scancode_set { 0xFF };
|
uint8_t m_scancode_set { 0xFF };
|
||||||
uint16_t m_modifiers { 0 };
|
uint16_t m_modifiers { 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Kernel
|
|||||||
virtual ~InterruptController() {}
|
virtual ~InterruptController() {}
|
||||||
|
|
||||||
virtual void eoi(uint8_t) = 0;
|
virtual void eoi(uint8_t) = 0;
|
||||||
virtual void enable_irq(uint8_t, bool level_triggered = false) = 0;
|
virtual void enable_irq(uint8_t) = 0;
|
||||||
virtual bool is_in_service(uint8_t) = 0;
|
virtual bool is_in_service(uint8_t) = 0;
|
||||||
|
|
||||||
static void initialize(bool force_pic);
|
static void initialize(bool force_pic);
|
||||||
@@ -26,7 +26,7 @@ namespace Kernel
|
|||||||
virtual void broadcast_ipi() = 0;
|
virtual void broadcast_ipi() = 0;
|
||||||
virtual void enable() = 0;
|
virtual void enable() = 0;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq, bool shared = false) = 0;
|
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq) = 0;
|
||||||
virtual BAN::Optional<uint8_t> get_free_irq() = 0;
|
virtual BAN::Optional<uint8_t> get_free_irq() = 0;
|
||||||
|
|
||||||
bool is_using_apic() const { return m_using_apic; }
|
bool is_using_apic() const { return m_using_apic; }
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <kernel/Arch.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
|
||||||
{
|
|
||||||
|
|
||||||
// IDT entries
|
|
||||||
// 0x00->0x1F (32): ISR
|
|
||||||
// 0x20->0x7F (96): PIC/IOAPIC
|
|
||||||
// 0x80->0xEF (112): MSI
|
|
||||||
// 0xF0->0xFE (15): internal
|
|
||||||
|
|
||||||
constexpr uint8_t IRQ_VECTOR_BASE = 0x20;
|
|
||||||
constexpr uint8_t IRQ_MSI_BASE = 0x80;
|
|
||||||
constexpr uint8_t IRQ_MSI_END = 0xF0;
|
|
||||||
#if ARCH(i686)
|
|
||||||
constexpr uint8_t IRQ_SYSCALL = 0xF0; // hard coded in kernel/API/Syscall.h
|
|
||||||
#endif
|
|
||||||
constexpr uint8_t IRQ_IPI = 0xF1;
|
|
||||||
constexpr uint8_t IRQ_TIMER = 0xF2;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <kernel/Lock/SpinLock.h>
|
|
||||||
#include <kernel/Lock/Mutex.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
|
||||||
{
|
|
||||||
|
|
||||||
// FIXME: These classes are HACKS to allow passing spinlock
|
|
||||||
// to unblock functions. Write a better API that either
|
|
||||||
// allows passing spinlocks or do something cleaner that
|
|
||||||
// whatever shit this is
|
|
||||||
|
|
||||||
template<typename Lock> requires requires (Lock& lock) { lock.lock(); lock.unlock(InterruptState::Disabled); lock.current_processor_has_lock(); }
|
|
||||||
class BlockableSpinLock : public BaseMutex
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BlockableSpinLock(Lock& lock)
|
|
||||||
: m_lock(lock)
|
|
||||||
{
|
|
||||||
ASSERT(m_lock.current_processor_has_lock());
|
|
||||||
}
|
|
||||||
|
|
||||||
void lock() override
|
|
||||||
{
|
|
||||||
m_lock.lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void unlock() override
|
|
||||||
{
|
|
||||||
m_lock.unlock(InterruptState::Disabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t lock_depth() const override { return m_lock.lock_depth(); }
|
|
||||||
bool is_locked_by_current_thread() const override { return m_lock.current_processor_has_lock(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Lock& m_lock;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <BAN/Atomic.h>
|
#include <BAN/Atomic.h>
|
||||||
#include <BAN/NoCopyMove.h>
|
#include <BAN/NoCopyMove.h>
|
||||||
|
#include <kernel/Thread.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@@ -12,13 +13,15 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void lock() = 0;
|
virtual void lock() = 0;
|
||||||
|
virtual bool try_lock() = 0;
|
||||||
virtual void unlock() = 0;
|
virtual void unlock() = 0;
|
||||||
|
|
||||||
|
virtual pid_t locker() const = 0;
|
||||||
|
virtual bool is_locked() const = 0;
|
||||||
virtual uint32_t lock_depth() const = 0;
|
virtual uint32_t lock_depth() const = 0;
|
||||||
virtual bool is_locked_by_current_thread() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mutex final : public BaseMutex
|
class Mutex : public BaseMutex
|
||||||
{
|
{
|
||||||
BAN_NON_COPYABLE(Mutex);
|
BAN_NON_COPYABLE(Mutex);
|
||||||
BAN_NON_MOVABLE(Mutex);
|
BAN_NON_MOVABLE(Mutex);
|
||||||
@@ -26,21 +29,68 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
Mutex() = default;
|
Mutex() = default;
|
||||||
|
|
||||||
bool try_lock();
|
void lock() override
|
||||||
void lock() override;
|
{
|
||||||
void unlock() override;
|
const auto tid = Thread::current_tid();
|
||||||
|
if (tid == m_locker)
|
||||||
|
ASSERT(m_lock_depth > 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASSERT(!tid || !Thread::current().has_spinlock());
|
||||||
|
pid_t expected = -1;
|
||||||
|
while (!m_locker.compare_exchange(expected, tid))
|
||||||
|
{
|
||||||
|
Processor::yield();
|
||||||
|
expected = -1;
|
||||||
|
}
|
||||||
|
ASSERT(m_lock_depth == 0);
|
||||||
|
if (tid)
|
||||||
|
Thread::current().add_mutex();
|
||||||
|
}
|
||||||
|
m_lock_depth++;
|
||||||
|
}
|
||||||
|
|
||||||
pid_t locker() const { return m_locker; }
|
bool try_lock() override
|
||||||
bool is_locked() const { return m_locker != -1; }
|
{
|
||||||
|
const auto tid = Thread::current_tid();
|
||||||
|
if (tid == m_locker)
|
||||||
|
ASSERT(m_lock_depth > 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pid_t expected = -1;
|
||||||
|
if (!m_locker.compare_exchange(expected, tid))
|
||||||
|
return false;
|
||||||
|
ASSERT(m_lock_depth == 0);
|
||||||
|
if (tid)
|
||||||
|
Thread::current().add_mutex();
|
||||||
|
}
|
||||||
|
m_lock_depth++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock() override
|
||||||
|
{
|
||||||
|
const auto tid = Thread::current_tid();
|
||||||
|
ASSERT(m_locker == tid);
|
||||||
|
ASSERT(m_lock_depth > 0);
|
||||||
|
if (--m_lock_depth == 0)
|
||||||
|
{
|
||||||
|
m_locker = -1;
|
||||||
|
if (tid)
|
||||||
|
Thread::current().remove_mutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t locker() const override { return m_locker; }
|
||||||
|
bool is_locked() const override { return m_locker != -1; }
|
||||||
uint32_t lock_depth() const override { return m_lock_depth; }
|
uint32_t lock_depth() const override { return m_lock_depth; }
|
||||||
bool is_locked_by_current_thread() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::Atomic<pid_t> m_locker { -1 };
|
BAN::Atomic<pid_t> m_locker { -1 };
|
||||||
uint32_t m_lock_depth { 0 };
|
uint32_t m_lock_depth { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class PriorityMutex final : public BaseMutex
|
class PriorityMutex : public BaseMutex
|
||||||
{
|
{
|
||||||
BAN_NON_COPYABLE(PriorityMutex);
|
BAN_NON_COPYABLE(PriorityMutex);
|
||||||
BAN_NON_MOVABLE(PriorityMutex);
|
BAN_NON_MOVABLE(PriorityMutex);
|
||||||
@@ -48,14 +98,72 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
PriorityMutex() = default;
|
PriorityMutex() = default;
|
||||||
|
|
||||||
bool try_lock();
|
void lock() override
|
||||||
void lock() override;
|
{
|
||||||
void unlock() override;
|
const auto tid = Thread::current_tid();
|
||||||
|
|
||||||
pid_t locker() const { return m_locker; }
|
if (tid == m_locker)
|
||||||
bool is_locked() const { return m_locker != -1; }
|
ASSERT(m_lock_depth > 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ASSERT(!tid || !Thread::current().has_spinlock());
|
||||||
|
bool has_priority = tid ? !Thread::current().is_userspace() : true;
|
||||||
|
if (has_priority)
|
||||||
|
m_queue_length++;
|
||||||
|
pid_t expected = -1;
|
||||||
|
while (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
|
||||||
|
{
|
||||||
|
Processor::yield();
|
||||||
|
expected = -1;
|
||||||
|
}
|
||||||
|
ASSERT(m_lock_depth == 0);
|
||||||
|
if (tid)
|
||||||
|
Thread::current().add_mutex();
|
||||||
|
}
|
||||||
|
m_lock_depth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool try_lock() override
|
||||||
|
{
|
||||||
|
const auto tid = Thread::current_tid();
|
||||||
|
|
||||||
|
if (tid == m_locker)
|
||||||
|
ASSERT(m_lock_depth > 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool has_priority = tid ? !Thread::current().is_userspace() : true;
|
||||||
|
pid_t expected = -1;
|
||||||
|
if (!(has_priority || m_queue_length == 0) || !m_locker.compare_exchange(expected, tid))
|
||||||
|
return false;
|
||||||
|
if (has_priority)
|
||||||
|
m_queue_length++;
|
||||||
|
ASSERT(m_lock_depth == 0);
|
||||||
|
if (tid)
|
||||||
|
Thread::current().add_mutex();
|
||||||
|
}
|
||||||
|
m_lock_depth++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock() override
|
||||||
|
{
|
||||||
|
const auto tid = Thread::current_tid();
|
||||||
|
ASSERT(m_locker == tid);
|
||||||
|
ASSERT(m_lock_depth > 0);
|
||||||
|
if (--m_lock_depth == 0)
|
||||||
|
{
|
||||||
|
bool has_priority = tid ? !Thread::current().is_userspace() : true;
|
||||||
|
if (has_priority)
|
||||||
|
m_queue_length--;
|
||||||
|
m_locker = -1;
|
||||||
|
if (tid)
|
||||||
|
Thread::current().remove_mutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t locker() const override { return m_locker; }
|
||||||
|
bool is_locked() const override { return m_locker != -1; }
|
||||||
uint32_t lock_depth() const override { return m_lock_depth; }
|
uint32_t lock_depth() const override { return m_lock_depth; }
|
||||||
bool is_locked_by_current_thread() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAN::Atomic<pid_t> m_locker { -1 };
|
BAN::Atomic<pid_t> m_locker { -1 };
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <kernel/Lock/SpinLock.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/Lock/LockGuard.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
@@ -13,13 +13,51 @@ namespace Kernel
|
|||||||
public:
|
public:
|
||||||
RWLock() = default;
|
RWLock() = default;
|
||||||
|
|
||||||
void rd_lock();
|
void rd_lock()
|
||||||
void rd_unlock();
|
{
|
||||||
void wr_lock();
|
LockGuard _(m_mutex);
|
||||||
void wr_unlock();
|
while (m_writers_waiting > 0 || m_writer != -1)
|
||||||
|
m_thread_blocker.block_indefinite(&m_mutex);
|
||||||
|
m_readers_active++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rd_unlock()
|
||||||
|
{
|
||||||
|
LockGuard _(m_mutex);
|
||||||
|
if (--m_readers_active == 0)
|
||||||
|
m_thread_blocker.unblock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wr_lock()
|
||||||
|
{
|
||||||
|
if (m_writer == Thread::current_tid())
|
||||||
|
{
|
||||||
|
m_writer_depth++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LockGuard _(m_mutex);
|
||||||
|
|
||||||
|
m_writers_waiting++;
|
||||||
|
while (m_readers_active > 0 || m_writer != -1)
|
||||||
|
m_thread_blocker.block_indefinite(&m_mutex);
|
||||||
|
m_writers_waiting--;
|
||||||
|
|
||||||
|
m_writer = Thread::current_tid();
|
||||||
|
m_writer_depth = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wr_unlock()
|
||||||
|
{
|
||||||
|
if (--m_writer_depth != 0)
|
||||||
|
return;
|
||||||
|
LockGuard _(m_mutex);
|
||||||
|
m_writer = -1;
|
||||||
|
m_thread_blocker.unblock();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpinLock m_lock;
|
Mutex m_mutex;
|
||||||
ThreadBlocker m_thread_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
uint32_t m_readers_active { 0 };
|
uint32_t m_readers_active { 0 };
|
||||||
uint32_t m_writers_waiting { 0 };
|
uint32_t m_writers_waiting { 0 };
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ namespace Kernel
|
|||||||
uint32_t m_lock_depth { 0 };
|
uint32_t m_lock_depth { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Lock>
|
||||||
|
class SpinLockGuardAsMutex;
|
||||||
|
|
||||||
template<typename Lock>
|
template<typename Lock>
|
||||||
class SpinLockGuard
|
class SpinLockGuard
|
||||||
{
|
{
|
||||||
@@ -82,6 +85,7 @@ namespace Kernel
|
|||||||
private:
|
private:
|
||||||
Lock& m_lock;
|
Lock& m_lock;
|
||||||
InterruptState m_state;
|
InterruptState m_state;
|
||||||
|
friend class SpinLockGuardAsMutex<Lock>;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <kernel/Lock/SpinLock.h>
|
||||||
|
#include <kernel/Lock/Mutex.h>
|
||||||
|
|
||||||
|
namespace Kernel
|
||||||
|
{
|
||||||
|
|
||||||
|
// FIXME: These classes are HACKS to allow passing spinlock
|
||||||
|
// to unblock functions. Write a better API that either
|
||||||
|
// allows passing spinlocks or do something cleaner that
|
||||||
|
// whatever shit this is
|
||||||
|
|
||||||
|
template<typename Lock>
|
||||||
|
class SpinLockAsMutex : public BaseMutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpinLockAsMutex(Lock& lock, InterruptState state)
|
||||||
|
: m_lock(lock)
|
||||||
|
, m_lock_depth(lock.lock_depth())
|
||||||
|
, m_state(state)
|
||||||
|
, m_locker(Thread::current_tid())
|
||||||
|
{
|
||||||
|
ASSERT(m_lock.current_processor_has_lock());
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock() override
|
||||||
|
{
|
||||||
|
m_lock.lock();
|
||||||
|
m_lock_depth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool try_lock() override
|
||||||
|
{
|
||||||
|
lock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock() override
|
||||||
|
{
|
||||||
|
m_lock.unlock(--m_lock_depth ? InterruptState::Disabled : m_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t locker() const override { return is_locked() ? m_locker : -1; }
|
||||||
|
bool is_locked() const override { return m_lock_depth; }
|
||||||
|
uint32_t lock_depth() const override { return m_lock_depth; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Lock& m_lock;
|
||||||
|
uint32_t m_lock_depth { 0 };
|
||||||
|
InterruptState m_state;
|
||||||
|
const pid_t m_locker;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Lock>
|
||||||
|
class SpinLockGuardAsMutex : public SpinLockAsMutex<Lock>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpinLockGuardAsMutex(SpinLockGuard<Lock>& guard)
|
||||||
|
: SpinLockAsMutex<Lock>(guard.m_lock, guard.m_state)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ namespace Kernel
|
|||||||
// FIXME: this should probably be ordered tree like map
|
// FIXME: this should probably be ordered tree like map
|
||||||
// for fast lookup and less memory usage
|
// for fast lookup and less memory usage
|
||||||
BAN::Vector<paddr_t> pages;
|
BAN::Vector<paddr_t> pages;
|
||||||
BAN::Vector<uint32_t> writers;
|
|
||||||
BAN::RefPtr<Inode> inode;
|
BAN::RefPtr<Inode> inode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/Vector.h>
|
|
||||||
#include <kernel/Memory/MemoryRegion.h>
|
#include <kernel/Memory/MemoryRegion.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ namespace Kernel
|
|||||||
requires BAN::is_same_v<decltype(func()), void>;
|
requires BAN::is_same_v<decltype(func()), void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename F>
|
|
||||||
concept with_per_cpu_fast_page_callback = requires(F func, void* addr)
|
|
||||||
{
|
|
||||||
requires BAN::is_same_v<decltype(func(addr)), void>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
concept with_fast_page_callback_error = requires(F func)
|
concept with_fast_page_callback_error = requires(F func)
|
||||||
{
|
{
|
||||||
@@ -51,10 +45,6 @@ namespace Kernel
|
|||||||
WriteThrough,
|
WriteThrough,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr bool full_tlb_flush_threshold = 32;
|
|
||||||
|
|
||||||
static constexpr size_t reserved_fast_pages = 0x10;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void initialize_fast_page();
|
static void initialize_fast_page();
|
||||||
static void initialize_and_load();
|
static void initialize_and_load();
|
||||||
@@ -82,18 +72,6 @@ namespace Kernel
|
|||||||
unmap_fast_page();
|
unmap_fast_page();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<with_per_cpu_fast_page_callback F>
|
|
||||||
static void with_per_cpu_fast_page(paddr_t paddr, F callback)
|
|
||||||
{
|
|
||||||
const auto state = Processor::get_interrupt_state();
|
|
||||||
Processor::set_interrupt_state(InterruptState::Disabled);
|
|
||||||
const size_t index = Processor::current_index() + reserved_fast_pages;
|
|
||||||
void* addr = map_fast_page(index, paddr);
|
|
||||||
callback(addr);
|
|
||||||
unmap_fast_page(index);
|
|
||||||
Processor::set_interrupt_state(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<with_fast_page_callback_error F>
|
template<with_fast_page_callback_error F>
|
||||||
static BAN::ErrorOr<void> with_fast_page(paddr_t paddr, F callback)
|
static BAN::ErrorOr<void> with_fast_page(paddr_t paddr, F callback)
|
||||||
{
|
{
|
||||||
@@ -145,8 +123,8 @@ namespace Kernel
|
|||||||
bool is_page_free(vaddr_t) const;
|
bool is_page_free(vaddr_t) const;
|
||||||
bool is_range_free(vaddr_t, size_t bytes) const;
|
bool is_range_free(vaddr_t, size_t bytes) const;
|
||||||
|
|
||||||
void reserve_page(vaddr_t);
|
bool reserve_page(vaddr_t, bool only_free = true, bool invalidate = true);
|
||||||
void reserve_range(vaddr_t, size_t bytes);
|
bool reserve_range(vaddr_t, size_t bytes, bool only_free = true);
|
||||||
|
|
||||||
vaddr_t reserve_free_page(vaddr_t first_address, vaddr_t last_address = UINTPTR_MAX);
|
vaddr_t reserve_free_page(vaddr_t first_address, vaddr_t last_address = UINTPTR_MAX);
|
||||||
vaddr_t reserve_free_contiguous_pages(size_t page_count, vaddr_t first_address, vaddr_t last_address = UINTPTR_MAX);
|
vaddr_t reserve_free_contiguous_pages(size_t page_count, vaddr_t first_address, vaddr_t last_address = UINTPTR_MAX);
|
||||||
@@ -155,7 +133,6 @@ namespace Kernel
|
|||||||
|
|
||||||
void invalidate_page(vaddr_t addr, bool send_smp_message) { invalidate_range(addr, 1, send_smp_message); }
|
void invalidate_page(vaddr_t addr, bool send_smp_message) { invalidate_range(addr, 1, send_smp_message); }
|
||||||
void invalidate_range(vaddr_t addr, size_t pages, bool send_smp_message);
|
void invalidate_range(vaddr_t addr, size_t pages, bool send_smp_message);
|
||||||
void invalidate_full_address_space(bool global);
|
|
||||||
|
|
||||||
InterruptState lock() const { return m_lock.lock(); }
|
InterruptState lock() const { return m_lock.lock(); }
|
||||||
void unlock(InterruptState state) const { m_lock.unlock(state); }
|
void unlock(InterruptState state) const { m_lock.unlock(state); }
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <BAN/HashMap.h>
|
#include <BAN/HashMap.h>
|
||||||
#include <BAN/RefPtr.h>
|
|
||||||
#include <BAN/UniqPtr.h>
|
#include <BAN/UniqPtr.h>
|
||||||
#include <BAN/Vector.h>
|
|
||||||
#include <kernel/Lock/Mutex.h>
|
#include <kernel/Lock/Mutex.h>
|
||||||
#include <kernel/Lock/SpinLock.h>
|
#include <kernel/Lock/SpinLock.h>
|
||||||
#include <kernel/Memory/MemoryRegion.h>
|
#include <kernel/Memory/MemoryRegion.h>
|
||||||
|
|
||||||
#include <sys/shm.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class SharedMemoryObject;
|
||||||
|
|
||||||
class SharedMemoryObjectManager
|
class SharedMemoryObjectManager
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
using Key = size_t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<void> initialize();
|
static BAN::ErrorOr<void> initialize();
|
||||||
static SharedMemoryObjectManager& get();
|
static SharedMemoryObjectManager& get();
|
||||||
|
|
||||||
BAN::ErrorOr<int> shmget(key_t key, size_t size, int shmflg);
|
BAN::ErrorOr<Key> create_object(size_t size, PageTable::flags_t);
|
||||||
BAN::ErrorOr<void> shmctl(int shmid, int cmd, struct shmid_ds* user_buf);
|
BAN::ErrorOr<void> delete_object(Key);
|
||||||
BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> shmat(int shmid, const void* shmaddr, int shmflg);
|
BAN::ErrorOr<BAN::UniqPtr<SharedMemoryObject>> map_object(Key, PageTable&, AddressRange);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedMemoryObjectManager() {}
|
SharedMemoryObjectManager() {}
|
||||||
@@ -29,31 +32,49 @@ namespace Kernel
|
|||||||
private:
|
private:
|
||||||
struct Object : public BAN::RefCounted<Object>
|
struct Object : public BAN::RefCounted<Object>
|
||||||
{
|
{
|
||||||
Object(key_t key, int id, shmid_ds info)
|
|
||||||
: key(key)
|
|
||||||
, id(id)
|
|
||||||
, info(info)
|
|
||||||
{ }
|
|
||||||
~Object();
|
~Object();
|
||||||
|
|
||||||
bool can_current_process_access(int flags) const;
|
Key key;
|
||||||
|
size_t size;
|
||||||
const key_t key;
|
PageTable::flags_t flags;
|
||||||
const int id;
|
|
||||||
shmid_ds info;
|
|
||||||
|
|
||||||
Mutex mutex;
|
|
||||||
BAN::Vector<paddr_t> paddrs;
|
BAN::Vector<paddr_t> paddrs;
|
||||||
bool marked_for_deletion { false };
|
SpinLock spin_lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
BAN::HashMap<key_t, int> m_ids;
|
BAN::HashMap<Key, BAN::RefPtr<Object>> m_objects;
|
||||||
BAN::HashMap<int, BAN::RefPtr<Object>> m_objects;
|
|
||||||
|
|
||||||
friend class SharedMemoryObject;
|
friend class SharedMemoryObject;
|
||||||
friend class BAN::UniqPtr<SharedMemoryObjectManager>;
|
friend class BAN::UniqPtr<SharedMemoryObjectManager>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SharedMemoryObject : public MemoryRegion
|
||||||
|
{
|
||||||
|
BAN_NON_COPYABLE(SharedMemoryObject);
|
||||||
|
BAN_NON_MOVABLE(SharedMemoryObject);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static BAN::ErrorOr<BAN::UniqPtr<SharedMemoryObject>> create(BAN::RefPtr<SharedMemoryObjectManager::Object>, PageTable&, AddressRange);
|
||||||
|
|
||||||
|
BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> clone(PageTable& new_page_table) override;
|
||||||
|
BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> split(size_t offset) override;
|
||||||
|
|
||||||
|
BAN::ErrorOr<void> msync(vaddr_t, size_t, int) override { return {}; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
BAN::ErrorOr<bool> allocate_page_containing_impl(vaddr_t vaddr, bool wants_write) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SharedMemoryObject(BAN::RefPtr<SharedMemoryObjectManager::Object> object, PageTable& page_table)
|
||||||
|
: MemoryRegion(page_table, object->size, MemoryRegion::Type::SHARED, object->flags, O_EXEC | O_RDWR)
|
||||||
|
, m_object(object)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
private:
|
||||||
|
BAN::RefPtr<SharedMemoryObjectManager::Object> m_object;
|
||||||
|
|
||||||
|
friend class BAN::UniqPtr<SharedMemoryObject>;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <BAN/HashMap.h>
|
#include <BAN/HashMap.h>
|
||||||
#include <BAN/UniqPtr.h>
|
#include <BAN/UniqPtr.h>
|
||||||
#include <kernel/Networking/NetworkInterface.h>
|
#include <kernel/Networking/NetworkInterface.h>
|
||||||
|
#include <kernel/Thread.h>
|
||||||
|
#include <kernel/ThreadBlocker.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace Kernel
|
|||||||
REG_TDLEN = 0x3808,
|
REG_TDLEN = 0x3808,
|
||||||
REG_TDH = 0x3810,
|
REG_TDH = 0x3810,
|
||||||
REG_TDT = 0x3818,
|
REG_TDT = 0x3818,
|
||||||
REG_RXCSUM = 0x5000,
|
|
||||||
REG_MTA = 0x5200,
|
REG_MTA = 0x5200,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,15 +167,6 @@ namespace Kernel
|
|||||||
RCTL_BSIZE_16384 = (0b01 << 16) | RCTL_BSEX,
|
RCTL_BSIZE_16384 = (0b01 << 16) | RCTL_BSEX,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum E1000_RXCSUM : uint32_t
|
|
||||||
{
|
|
||||||
RXSUM_IPOFLD = 1 << 8,
|
|
||||||
RXSUM_TUOFLD = 1 << 9,
|
|
||||||
RXSUM_CRCOFLD = 1 << 11,
|
|
||||||
RXSUM_IPPCE = 1 << 12,
|
|
||||||
RXSUM_PCSD = 1 << 13,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum E1000_CMD : uint8_t
|
enum E1000_CMD : uint8_t
|
||||||
{
|
{
|
||||||
CMD_EOP = 1 << 0,
|
CMD_EOP = 1 << 0,
|
||||||
@@ -188,26 +178,6 @@ namespace Kernel
|
|||||||
CMD_IDE = 1 << 7,
|
CMD_IDE = 1 << 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum E1000_RX_STS : uint8_t
|
|
||||||
{
|
|
||||||
RX_STS_IPCS = 1 << 6,
|
|
||||||
RX_STS_TCPCS = 1 << 5,
|
|
||||||
RX_STS_UDPCS = 1 << 5,
|
|
||||||
RX_STS_EOP = 1 << 1,
|
|
||||||
RX_STS_DD = 1 << 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum E1000_RX_ERR : uint8_t
|
|
||||||
{
|
|
||||||
RX_ERR_RXE = 1 << 7,
|
|
||||||
RX_ERR_IPE = 1 << 6,
|
|
||||||
RX_ERR_TCPE = 1 << 5,
|
|
||||||
RX_ERR_CXE = 1 << 4,
|
|
||||||
RX_ERR_SEQ = 1 << 2,
|
|
||||||
RX_ERR_SE = 1 << 1,
|
|
||||||
RX_ERR_CE = 1 << 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct e1000_rx_desc
|
struct e1000_rx_desc
|
||||||
{
|
{
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Kernel
|
|||||||
uint32_t read32(uint16_t reg);
|
uint32_t read32(uint16_t reg);
|
||||||
void write32(uint16_t reg, uint32_t value);
|
void write32(uint16_t reg, uint32_t value);
|
||||||
|
|
||||||
BAN::ErrorOr<void> send_raw_bytes(BAN::Span<const BAN::ConstByteSpan> buffers) override;
|
BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::Span<const BAN::ConstByteSpan> payload) override;
|
||||||
|
|
||||||
bool can_read_impl() const override { return false; }
|
bool can_read_impl() const override { return false; }
|
||||||
bool can_write_impl() const override { return false; }
|
bool can_write_impl() const override { return false; }
|
||||||
@@ -74,8 +74,8 @@ namespace Kernel
|
|||||||
BAN::UniqPtr<DMARegion> m_rx_descriptor_region;
|
BAN::UniqPtr<DMARegion> m_rx_descriptor_region;
|
||||||
BAN::UniqPtr<DMARegion> m_tx_descriptor_region;
|
BAN::UniqPtr<DMARegion> m_tx_descriptor_region;
|
||||||
|
|
||||||
BAN::Atomic<uint32_t> m_tx_head { 0 };
|
BAN::Atomic<uint32_t> m_tx_head1 { 0 };
|
||||||
BAN::Atomic<uint32_t> m_tx_commit { 0 };
|
BAN::Atomic<uint32_t> m_tx_head2 { 0 };
|
||||||
|
|
||||||
SpinLock m_rx_lock;
|
SpinLock m_rx_lock;
|
||||||
ThreadBlocker m_rx_blocker;
|
ThreadBlocker m_rx_blocker;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <kernel/Networking/NetworkInterface.h>
|
#include <kernel/Networking/NetworkInterface.h>
|
||||||
#include <kernel/Networking/NetworkLayer.h>
|
#include <kernel/Networking/NetworkLayer.h>
|
||||||
#include <kernel/Networking/NetworkSocket.h>
|
#include <kernel/Networking/NetworkSocket.h>
|
||||||
|
#include <kernel/Thread.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
@@ -40,14 +41,14 @@ namespace Kernel
|
|||||||
|
|
||||||
ARPTable& arp_table() { return *m_arp_table; }
|
ARPTable& arp_table() { return *m_arp_table; }
|
||||||
|
|
||||||
BAN::ErrorOr<void> handle_ipv4_packet(NetworkInterface&, BAN::ConstByteSpan, uint32_t validated_cksums);
|
BAN::ErrorOr<void> handle_ipv4_packet(NetworkInterface&, BAN::ConstByteSpan);
|
||||||
|
|
||||||
virtual void unbind_socket(uint16_t port) override;
|
virtual void unbind_socket(uint16_t port) override;
|
||||||
virtual BAN::ErrorOr<void> bind_socket_with_target(BAN::RefPtr<NetworkSocket>, const sockaddr* target_address, socklen_t target_address_len) override;
|
virtual BAN::ErrorOr<void> bind_socket_with_target(BAN::RefPtr<NetworkSocket>, const sockaddr* target_address, socklen_t target_address_len) override;
|
||||||
virtual BAN::ErrorOr<void> bind_socket_to_address(BAN::RefPtr<NetworkSocket>, const sockaddr* address, socklen_t address_len) override;
|
virtual BAN::ErrorOr<void> bind_socket_to_address(BAN::RefPtr<NetworkSocket>, const sockaddr* address, socklen_t address_len) override;
|
||||||
virtual BAN::ErrorOr<void> get_socket_address(BAN::RefPtr<NetworkSocket>, sockaddr* address, socklen_t* address_len) override;
|
virtual BAN::ErrorOr<void> get_socket_address(BAN::RefPtr<NetworkSocket>, sockaddr* address, socklen_t* address_len) override;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> sendto(NetworkSocket&, BAN::ConstByteSpan, const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<size_t> sendto(NetworkSocket&, BAN::ConstByteSpan, const sockaddr*, socklen_t) override;
|
||||||
|
|
||||||
virtual Socket::Domain domain() const override { return Socket::Domain::INET ;}
|
virtual Socket::Domain domain() const override { return Socket::Domain::INET ;}
|
||||||
virtual size_t header_size() const override { return sizeof(IPv4Header); }
|
virtual size_t header_size() const override { return sizeof(IPv4Header); }
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <kernel/Networking/NetworkInterface.h>
|
#include <kernel/Networking/NetworkInterface.h>
|
||||||
#include <kernel/Memory/VirtualRange.h>
|
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
@@ -28,7 +27,7 @@ namespace Kernel
|
|||||||
{}
|
{}
|
||||||
~LoopbackInterface();
|
~LoopbackInterface();
|
||||||
|
|
||||||
BAN::ErrorOr<void> send_raw_bytes(BAN::Span<const BAN::ConstByteSpan> buffers) override;
|
BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::Span<const BAN::ConstByteSpan> payload) override;
|
||||||
|
|
||||||
bool can_read_impl() const override { return false; }
|
bool can_read_impl() const override { return false; }
|
||||||
bool can_write_impl() const override { return false; }
|
bool can_write_impl() const override { return false; }
|
||||||
@@ -47,7 +46,7 @@ namespace Kernel
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpinLock m_buffer_lock;
|
Mutex m_buffer_lock;
|
||||||
BAN::UniqPtr<VirtualRange> m_buffer;
|
BAN::UniqPtr<VirtualRange> m_buffer;
|
||||||
|
|
||||||
uint32_t m_buffer_tail { 0 };
|
uint32_t m_buffer_tail { 0 };
|
||||||
|
|||||||
@@ -23,13 +23,6 @@ namespace Kernel
|
|||||||
ARP = 0x0806,
|
ARP = 0x0806,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum NetworkChecksum : uint32_t
|
|
||||||
{
|
|
||||||
CKSUM_IPV4 = 1 << 0,
|
|
||||||
CKSUM_TCP = 1 << 1,
|
|
||||||
CKSUM_UDP = 1 << 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
class NetworkInterface : public CharacterDevice
|
class NetworkInterface : public CharacterDevice
|
||||||
{
|
{
|
||||||
BAN_NON_COPYABLE(NetworkInterface);
|
BAN_NON_COPYABLE(NetworkInterface);
|
||||||
@@ -64,38 +57,19 @@ namespace Kernel
|
|||||||
|
|
||||||
virtual size_t payload_mtu() const = 0;
|
virtual size_t payload_mtu() const = 0;
|
||||||
|
|
||||||
|
virtual dev_t rdev() const override { return m_rdev; }
|
||||||
virtual BAN::StringView name() const override { return m_name; }
|
virtual BAN::StringView name() const override { return m_name; }
|
||||||
|
|
||||||
BAN::ErrorOr<void> send_with_ethernet_header(BAN::MACAddress dst_mac, EtherType ether_type, BAN::ConstByteSpan buffer)
|
BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::ConstByteSpan payload)
|
||||||
{
|
{
|
||||||
BAN::ConstByteSpan buffer_array[1] { buffer };
|
return send_bytes(destination, protocol, { &payload, 1 });
|
||||||
return send_with_ethernet_header(dst_mac, ether_type, buffer_array);
|
|
||||||
}
|
}
|
||||||
|
virtual BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::Span<const BAN::ConstByteSpan> payload) = 0;
|
||||||
template<size_t SIZE>
|
|
||||||
BAN::ErrorOr<void> send_with_ethernet_header(BAN::MACAddress dst_mac, EtherType ether_type, const BAN::ConstByteSpan (&buffer_array)[SIZE])
|
|
||||||
{
|
|
||||||
const auto ethernet_header = EthernetHeader {
|
|
||||||
.dst_mac = dst_mac,
|
|
||||||
.src_mac = get_mac_address(),
|
|
||||||
.ether_type = ether_type,
|
|
||||||
};
|
|
||||||
|
|
||||||
BAN::ConstByteSpan new_buffer_array[SIZE + 1];
|
|
||||||
new_buffer_array[0] = BAN::ConstByteSpan::from(ethernet_header);
|
|
||||||
for (size_t i = 0; i < SIZE; i++)
|
|
||||||
new_buffer_array[i + 1] = buffer_array[i];
|
|
||||||
|
|
||||||
return send_raw_bytes({ new_buffer_array, SIZE + 1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> send_raw_bytes(BAN::Span<const BAN::ConstByteSpan> buffers) = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
BAN::ErrorOr<long> ioctl_impl(unsigned long, void*) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Type m_type;
|
const Type m_type;
|
||||||
|
|
||||||
|
const dev_t m_rdev;
|
||||||
char m_name[10];
|
char m_name[10];
|
||||||
|
|
||||||
BAN::IPv4Address m_ipv4_address { 0 };
|
BAN::IPv4Address m_ipv4_address { 0 };
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Kernel
|
|||||||
virtual BAN::ErrorOr<void> bind_socket_to_address(BAN::RefPtr<NetworkSocket>, const sockaddr* address, socklen_t address_len) = 0;
|
virtual BAN::ErrorOr<void> bind_socket_to_address(BAN::RefPtr<NetworkSocket>, const sockaddr* address, socklen_t address_len) = 0;
|
||||||
virtual BAN::ErrorOr<void> get_socket_address(BAN::RefPtr<NetworkSocket>, sockaddr* address, socklen_t* address_len) = 0;
|
virtual BAN::ErrorOr<void> get_socket_address(BAN::RefPtr<NetworkSocket>, sockaddr* address, socklen_t* address_len) = 0;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> sendto(NetworkSocket&, BAN::ConstByteSpan, const sockaddr*, socklen_t) = 0;
|
virtual BAN::ErrorOr<size_t> sendto(NetworkSocket&, BAN::ConstByteSpan, const sockaddr*, socklen_t) = 0;
|
||||||
|
|
||||||
virtual Socket::Domain domain() const = 0;
|
virtual Socket::Domain domain() const = 0;
|
||||||
virtual size_t header_size() const = 0;
|
virtual size_t header_size() const = 0;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<BAN::RefPtr<Socket>> create_socket(Socket::Domain, Socket::Type, mode_t, uid_t, gid_t);
|
BAN::ErrorOr<BAN::RefPtr<Socket>> create_socket(Socket::Domain, Socket::Type, mode_t, uid_t, gid_t);
|
||||||
BAN::ErrorOr<void> connect_sockets(Socket::Domain, BAN::RefPtr<Socket>, BAN::RefPtr<Socket>);
|
BAN::ErrorOr<void> connect_sockets(Socket::Domain, BAN::RefPtr<Socket>, BAN::RefPtr<Socket>);
|
||||||
|
|
||||||
void on_receive(NetworkInterface&, BAN::ConstByteSpan, uint32_t validated_cksums);
|
void on_receive(NetworkInterface&, BAN::ConstByteSpan);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetworkManager() {}
|
NetworkManager() {}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Kernel
|
|||||||
virtual void get_protocol_header(BAN::ByteSpan header, BAN::ConstByteSpan payload, uint16_t dst_port, PseudoHeader) = 0;
|
virtual void get_protocol_header(BAN::ByteSpan header, BAN::ConstByteSpan payload, uint16_t dst_port, PseudoHeader) = 0;
|
||||||
virtual NetworkProtocol protocol() const = 0;
|
virtual NetworkProtocol protocol() const = 0;
|
||||||
|
|
||||||
virtual void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len, uint32_t validated_cksums) = 0;
|
virtual void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len) = 0;
|
||||||
|
|
||||||
bool is_bound() const { return m_address_len >= static_cast<socklen_t>(sizeof(sa_family_t)) && m_address.ss_family != AF_UNSPEC; }
|
bool is_bound() const { return m_address_len >= static_cast<socklen_t>(sizeof(sa_family_t)) && m_address.ss_family != AF_UNSPEC; }
|
||||||
in_port_t bound_port() const
|
in_port_t bound_port() const
|
||||||
@@ -54,7 +54,7 @@ namespace Kernel
|
|||||||
protected:
|
protected:
|
||||||
NetworkSocket(NetworkLayer&, const Socket::Info&);
|
NetworkSocket(NetworkLayer&, const Socket::Info&);
|
||||||
|
|
||||||
virtual BAN::ErrorOr<long> ioctl_impl(unsigned long request, void* arg) override;
|
virtual BAN::ErrorOr<long> ioctl_impl(int request, void* arg) override;
|
||||||
virtual BAN::ErrorOr<void> getsockname_impl(sockaddr*, socklen_t*) override;
|
virtual BAN::ErrorOr<void> getsockname_impl(sockaddr*, socklen_t*) override;
|
||||||
virtual BAN::ErrorOr<void> getpeername_impl(sockaddr*, socklen_t*) override = 0;
|
virtual BAN::ErrorOr<void> getpeername_impl(sockaddr*, socklen_t*) override = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ namespace Kernel
|
|||||||
RTL8169_IO_ISR = 0x3E,
|
RTL8169_IO_ISR = 0x3E,
|
||||||
RTL8169_IO_TCR = 0x40,
|
RTL8169_IO_TCR = 0x40,
|
||||||
RTL8169_IO_RCR = 0x44,
|
RTL8169_IO_RCR = 0x44,
|
||||||
|
RTL8169_IO_9346CR = 0x50,
|
||||||
RTL8169_IO_PHYSts = 0x6C,
|
RTL8169_IO_PHYSts = 0x6C,
|
||||||
RTL8169_IO_RMS = 0xDA,
|
RTL8169_IO_RMS = 0xDA,
|
||||||
RTL8169_IO_CPlusCR = 0xE0,
|
|
||||||
RTL8169_IO_RDSAR = 0xE4,
|
RTL8169_IO_RDSAR = 0xE4,
|
||||||
RTL8169_IO_MTPS = 0xEC,
|
RTL8169_IO_MTPS = 0xEC,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Kernel
|
|||||||
virtual bool link_up() override { return m_link_up; }
|
virtual bool link_up() override { return m_link_up; }
|
||||||
virtual int link_speed() override;
|
virtual int link_speed() override;
|
||||||
|
|
||||||
virtual size_t payload_mtu() const override { return 0x1FF8 - sizeof(EthernetHeader); }
|
virtual size_t payload_mtu() const override { return 7436 - sizeof(EthernetHeader); }
|
||||||
|
|
||||||
virtual void handle_irq() override;
|
virtual void handle_irq() override;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ namespace Kernel
|
|||||||
|
|
||||||
BAN::ErrorOr<void> initialize();
|
BAN::ErrorOr<void> initialize();
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> send_raw_bytes(BAN::Span<const BAN::ConstByteSpan> buffers) override;
|
virtual BAN::ErrorOr<void> send_bytes(BAN::MACAddress destination, EtherType protocol, BAN::Span<const BAN::ConstByteSpan>) override;
|
||||||
|
|
||||||
virtual bool can_read_impl() const override { return false; }
|
virtual bool can_read_impl() const override { return false; }
|
||||||
virtual bool can_write_impl() const override { return false; }
|
virtual bool can_write_impl() const override { return false; }
|
||||||
@@ -64,17 +64,14 @@ namespace Kernel
|
|||||||
BAN::UniqPtr<DMARegion> m_rx_descriptor_region;
|
BAN::UniqPtr<DMARegion> m_rx_descriptor_region;
|
||||||
BAN::UniqPtr<DMARegion> m_tx_descriptor_region;
|
BAN::UniqPtr<DMARegion> m_tx_descriptor_region;
|
||||||
|
|
||||||
BAN::Atomic<bool> m_rx_thread_should_die { false };
|
SpinLock m_lock;
|
||||||
BAN::Atomic<bool> m_rx_thread_is_dead { true };
|
|
||||||
|
|
||||||
uint32_t m_rx_head { 0 };
|
bool m_thread_should_die { false };
|
||||||
SpinLock m_rx_lock;
|
BAN::Atomic<bool> m_thread_is_dead { true };
|
||||||
ThreadBlocker m_rx_blocker;
|
ThreadBlocker m_thread_blocker;
|
||||||
|
|
||||||
BAN::Atomic<uint32_t> m_tx_head { 0 };
|
uint32_t m_rx_current { 0 };
|
||||||
BAN::Atomic<uint32_t> m_tx_commit { 0 };
|
size_t m_tx_current { 0 };
|
||||||
SpinLock m_tx_lock;
|
|
||||||
ThreadBlocker m_tx_blocker;
|
|
||||||
|
|
||||||
BAN::MACAddress m_mac_address {};
|
BAN::MACAddress m_mac_address {};
|
||||||
BAN::Atomic<bool> m_link_up { false };
|
BAN::Atomic<bool> m_link_up { false };
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <kernel/Memory/ByteRingBuffer.h>
|
#include <kernel/Memory/ByteRingBuffer.h>
|
||||||
#include <kernel/Networking/NetworkInterface.h>
|
#include <kernel/Networking/NetworkInterface.h>
|
||||||
#include <kernel/Networking/NetworkSocket.h>
|
#include <kernel/Networking/NetworkSocket.h>
|
||||||
|
#include <kernel/Thread.h>
|
||||||
#include <kernel/ThreadBlocker.h>
|
#include <kernel/ThreadBlocker.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
@@ -65,9 +66,9 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
||||||
BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
||||||
|
|
||||||
BAN::ErrorOr<long> ioctl_impl(unsigned long, void*) override;
|
BAN::ErrorOr<long> ioctl_impl(int, void*) override;
|
||||||
|
|
||||||
void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len, uint32_t validated_cksums) override;
|
void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len) override;
|
||||||
|
|
||||||
bool can_read_impl() const override;
|
bool can_read_impl() const override;
|
||||||
bool can_write_impl() const override;
|
bool can_write_impl() const override;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace Kernel
|
|||||||
void get_protocol_header(BAN::ByteSpan header, BAN::ConstByteSpan payload, uint16_t dst_port, PseudoHeader) override;
|
void get_protocol_header(BAN::ByteSpan header, BAN::ConstByteSpan payload, uint16_t dst_port, PseudoHeader) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len, uint32_t validated_cksums) override;
|
void receive_packet(BAN::ConstByteSpan, const sockaddr* sender, socklen_t sender_len) override;
|
||||||
|
|
||||||
BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
||||||
BAN::ErrorOr<void> bind_impl(const sockaddr* address, socklen_t address_len) override;
|
BAN::ErrorOr<void> bind_impl(const sockaddr* address, socklen_t address_len) override;
|
||||||
@@ -41,7 +41,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
||||||
BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
||||||
|
|
||||||
BAN::ErrorOr<long> ioctl_impl(unsigned long, void*) override;
|
BAN::ErrorOr<long> ioctl_impl(int, void*) override;
|
||||||
|
|
||||||
bool can_read_impl() const override { return !m_packets.empty(); }
|
bool can_read_impl() const override { return !m_packets.empty(); }
|
||||||
bool can_write_impl() const override { return true; }
|
bool can_write_impl() const override { return true; }
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <kernel/FS/Socket.h>
|
#include <kernel/FS/Socket.h>
|
||||||
#include <kernel/FS/TmpFS/Inode.h>
|
#include <kernel/FS/TmpFS/Inode.h>
|
||||||
#include <kernel/FS/VirtualFileSystem.h>
|
#include <kernel/FS/VirtualFileSystem.h>
|
||||||
#include <kernel/Memory/VirtualRange.h>
|
|
||||||
#include <kernel/OpenFileDescriptorSet.h>
|
#include <kernel/OpenFileDescriptorSet.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
@@ -31,7 +30,6 @@ namespace Kernel
|
|||||||
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
||||||
virtual BAN::ErrorOr<size_t> recvmsg_impl(msghdr& message, int flags) override;
|
virtual BAN::ErrorOr<size_t> recvmsg_impl(msghdr& message, int flags) override;
|
||||||
virtual BAN::ErrorOr<size_t> sendmsg_impl(const msghdr& message, int flags) override;
|
virtual BAN::ErrorOr<size_t> sendmsg_impl(const msghdr& message, int flags) override;
|
||||||
virtual BAN::ErrorOr<void> getsockname_impl(sockaddr*, socklen_t*) override;
|
|
||||||
virtual BAN::ErrorOr<void> getpeername_impl(sockaddr*, socklen_t*) override;
|
virtual BAN::ErrorOr<void> getpeername_impl(sockaddr*, socklen_t*) override;
|
||||||
virtual BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
virtual BAN::ErrorOr<void> getsockopt_impl(int, int, void*, socklen_t*) override;
|
||||||
virtual BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
virtual BAN::ErrorOr<void> setsockopt_impl(int, int, const void*, socklen_t) override;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<int> dup2(int, int);
|
BAN::ErrorOr<int> dup2(int, int);
|
||||||
|
|
||||||
BAN::ErrorOr<int> fcntl(int fd, int cmd, uintptr_t extra);
|
BAN::ErrorOr<int> fcntl(int fd, int cmd, uintptr_t extra);
|
||||||
BAN::ErrorOr<long> ioctl(int fd, unsigned long request, void* arg);
|
|
||||||
|
|
||||||
BAN::ErrorOr<off_t> seek(int fd, off_t offset, int whence);
|
BAN::ErrorOr<off_t> seek(int fd, off_t offset, int whence);
|
||||||
BAN::ErrorOr<off_t> tell(int) const;
|
BAN::ErrorOr<off_t> tell(int) const;
|
||||||
@@ -59,8 +58,6 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<size_t> recvmsg(int socket, msghdr& message, int flags);
|
BAN::ErrorOr<size_t> recvmsg(int socket, msghdr& message, int flags);
|
||||||
BAN::ErrorOr<size_t> sendmsg(int socket, const msghdr& message, int flags);
|
BAN::ErrorOr<size_t> sendmsg(int socket, const msghdr& message, int flags);
|
||||||
|
|
||||||
int get_max_open_fd() const;
|
|
||||||
|
|
||||||
BAN::ErrorOr<VirtualFileSystem::File> file_of(int) const;
|
BAN::ErrorOr<VirtualFileSystem::File> file_of(int) const;
|
||||||
BAN::ErrorOr<BAN::String> path_of(int) const;
|
BAN::ErrorOr<BAN::String> path_of(int) const;
|
||||||
BAN::ErrorOr<BAN::RefPtr<Inode>> inode_of(int);
|
BAN::ErrorOr<BAN::RefPtr<Inode>> inode_of(int);
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
#include <BAN/UniqPtr.h>
|
#include <BAN/UniqPtr.h>
|
||||||
#include <BAN/Vector.h>
|
#include <BAN/Vector.h>
|
||||||
#include <kernel/ACPI/AML/Node.h>
|
#include <kernel/ACPI/AML/Node.h>
|
||||||
#include <kernel/InterruptNumbers.h>
|
|
||||||
#include <kernel/Interruptable.h>
|
|
||||||
#include <kernel/Memory/Types.h>
|
#include <kernel/Memory/Types.h>
|
||||||
|
#include <kernel/Storage/StorageController.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@@ -180,7 +179,7 @@ namespace Kernel::PCI
|
|||||||
private:
|
private:
|
||||||
struct PCIeInfo
|
struct PCIeInfo
|
||||||
{
|
{
|
||||||
paddr_t bus_paddr[256] {};
|
paddr_t bus_paddr[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
PCIManager() = default;
|
PCIManager() = default;
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void eoi(uint8_t) override;
|
virtual void eoi(uint8_t) override;
|
||||||
virtual void enable_irq(uint8_t, bool level_triggered) override;
|
virtual void enable_irq(uint8_t) override;
|
||||||
virtual bool is_in_service(uint8_t) override;
|
virtual bool is_in_service(uint8_t) override;
|
||||||
|
|
||||||
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq, bool shared) override;
|
virtual BAN::ErrorOr<void> reserve_irq(uint8_t irq) override;
|
||||||
virtual BAN::Optional<uint8_t> get_free_irq() override;
|
virtual BAN::Optional<uint8_t> get_free_irq() override;
|
||||||
|
|
||||||
virtual void initialize_multiprocessor() override;
|
virtual void initialize_multiprocessor() override;
|
||||||
@@ -29,8 +29,7 @@ namespace Kernel
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SpinLock m_lock;
|
SpinLock m_lock;
|
||||||
uint16_t m_used_irqs { 1u << 2 };
|
uint16_t m_reserved_irqs { 1u << 2 };
|
||||||
uint16_t m_excl_irqs { 1u << 2 };
|
|
||||||
|
|
||||||
friend class InterruptController;
|
friend class InterruptController;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/banan-os.h>
|
#include <sys/banan-os.h>
|
||||||
#include <sys/epoll.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -27,6 +26,8 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
|
struct epoll_event;
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -43,10 +44,10 @@ namespace Kernel
|
|||||||
~Process();
|
~Process();
|
||||||
void cleanup_function(Thread*);
|
void cleanup_function(Thread*);
|
||||||
|
|
||||||
BAN::ErrorOr<vaddr_t> setup_initial_process_stack(MemoryBackedRegion&, BAN::Span<BAN::String> argv, BAN::Span<BAN::String> envp, BAN::Span<LibELF::AuxiliaryVector> auxv);
|
void register_to_scheduler();
|
||||||
|
|
||||||
void exit(int status, int signal);
|
void exit(int status, int signal);
|
||||||
|
|
||||||
|
void add_thread(Thread*);
|
||||||
// returns true if thread was the last one
|
// returns true if thread was the last one
|
||||||
bool on_thread_exit(Thread&);
|
bool on_thread_exit(Thread&);
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<long> sys_exec(const char* path, const char* const* argv, const char* const* envp);
|
BAN::ErrorOr<long> sys_exec(const char* path, const char* const* argv, const char* const* envp);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_wait(pid_t pid, int* stat_loc, int options);
|
BAN::ErrorOr<long> sys_wait(pid_t pid, int* stat_loc, int options);
|
||||||
|
BAN::ErrorOr<long> sys_sleep(int seconds);
|
||||||
BAN::ErrorOr<long> sys_nanosleep(const timespec* rqtp, timespec* rmtp);
|
BAN::ErrorOr<long> sys_nanosleep(const timespec* rqtp, timespec* rmtp);
|
||||||
BAN::ErrorOr<long> sys_setitimer(int which, const itimerval* value, itimerval* ovalue);
|
BAN::ErrorOr<long> sys_setitimer(int which, const itimerval* value, itimerval* ovalue);
|
||||||
|
|
||||||
@@ -98,14 +100,13 @@ namespace Kernel
|
|||||||
|
|
||||||
BAN::ErrorOr<long> open_inode(VirtualFileSystem::File&&, int flags);
|
BAN::ErrorOr<long> open_inode(VirtualFileSystem::File&&, int flags);
|
||||||
|
|
||||||
BAN::ErrorOr<void> create_file(int fd, const char* path, mode_t) const;
|
BAN::ErrorOr<void> create_file_or_dir(int fd, const char* path, mode_t mode) const;
|
||||||
BAN::ErrorOr<long> sys_openat(int fd, const char* path, int flags, mode_t);
|
BAN::ErrorOr<long> sys_openat(int, const char* path, int, mode_t);
|
||||||
BAN::ErrorOr<long> sys_close(int fd);
|
BAN::ErrorOr<long> sys_close(int fd);
|
||||||
BAN::ErrorOr<long> sys_read(int fd, void* buffer, size_t count);
|
BAN::ErrorOr<long> sys_read(int fd, void* buffer, size_t count);
|
||||||
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
|
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
|
||||||
BAN::ErrorOr<long> sys_access(const char* path, int amode);
|
BAN::ErrorOr<long> sys_access(const char* path, int amode);
|
||||||
BAN::ErrorOr<long> sys_mkdirat(int fd, const char* path, mode_t);
|
BAN::ErrorOr<long> sys_create_dir(const char*, mode_t);
|
||||||
BAN::ErrorOr<long> sys_mkfifoat(int fd, const char* path, mode_t);
|
|
||||||
BAN::ErrorOr<long> sys_hardlinkat(int fd1, const char* path1, int fd2, const char* path2, int flag);
|
BAN::ErrorOr<long> sys_hardlinkat(int fd1, const char* path1, int fd2, const char* path2, int flag);
|
||||||
BAN::ErrorOr<long> sys_renameat(int oldfd, const char* old, int newfd, const char* _new);
|
BAN::ErrorOr<long> sys_renameat(int oldfd, const char* old, int newfd, const char* _new);
|
||||||
BAN::ErrorOr<long> sys_unlinkat(int fd, const char* path, int flag);
|
BAN::ErrorOr<long> sys_unlinkat(int fd, const char* path, int flag);
|
||||||
@@ -135,7 +136,7 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<long> sys_recvmsg(int socket, msghdr* message, int flags);
|
BAN::ErrorOr<long> sys_recvmsg(int socket, msghdr* message, int flags);
|
||||||
BAN::ErrorOr<long> sys_sendmsg(int socket, const msghdr* message, int flags);
|
BAN::ErrorOr<long> sys_sendmsg(int socket, const msghdr* message, int flags);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_ioctl(int fildes, unsigned long request, void* arg);
|
BAN::ErrorOr<long> sys_ioctl(int fildes, int request, void* arg);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_pselect(sys_pselect_t* arguments);
|
BAN::ErrorOr<long> sys_pselect(sys_pselect_t* arguments);
|
||||||
BAN::ErrorOr<long> sys_ppoll(pollfd* fds, nfds_t nfds, const timespec* tmp_p, const sigset_t* sigmask);
|
BAN::ErrorOr<long> sys_ppoll(pollfd* fds, nfds_t nfds, const timespec* tmp_p, const sigset_t* sigmask);
|
||||||
@@ -178,10 +179,9 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<long> sys_mprotect(void* addr, size_t len, int prot);
|
BAN::ErrorOr<long> sys_mprotect(void* addr, size_t len, int prot);
|
||||||
BAN::ErrorOr<long> sys_msync(void* addr, size_t len, int flags);
|
BAN::ErrorOr<long> sys_msync(void* addr, size_t len, int flags);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_shmget(key_t key, size_t size, int shmflg);
|
BAN::ErrorOr<long> sys_smo_create(size_t len, int prot);
|
||||||
BAN::ErrorOr<long> sys_shmctl(int shmid, int cmd, struct shmid_ds* buf);
|
BAN::ErrorOr<long> sys_smo_delete(SharedMemoryObjectManager::Key);
|
||||||
BAN::ErrorOr<long> sys_shmat(int shmid, const void* shmaddr, int shmflg);
|
BAN::ErrorOr<long> sys_smo_map(SharedMemoryObjectManager::Key);
|
||||||
BAN::ErrorOr<long> sys_shmdt(const void* shmaddr);
|
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_ttyname(int fildes, char* name, size_t namesize);
|
BAN::ErrorOr<long> sys_ttyname(int fildes, char* name, size_t namesize);
|
||||||
BAN::ErrorOr<long> sys_posix_openpt(int flags);
|
BAN::ErrorOr<long> sys_posix_openpt(int flags);
|
||||||
@@ -209,31 +209,27 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<long> sys_set_gsbase(void*);
|
BAN::ErrorOr<long> sys_set_gsbase(void*);
|
||||||
BAN::ErrorOr<long> sys_get_gsbase();
|
BAN::ErrorOr<long> sys_get_gsbase();
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_thread_create(void (*entry)(void*), void* arg, void* stack_base, size_t stack_size);
|
BAN::ErrorOr<long> sys_pthread_create(const pthread_attr_t* attr, void (*entry)(void*), void* arg);
|
||||||
BAN::ErrorOr<long> sys_thread_exit(void* value);
|
BAN::ErrorOr<long> sys_pthread_exit(void* value);
|
||||||
BAN::ErrorOr<long> sys_thread_join(pid_t tid, void** value);
|
BAN::ErrorOr<long> sys_pthread_join(pthread_t thread, void** value);
|
||||||
BAN::ErrorOr<long> sys_thread_getid();
|
BAN::ErrorOr<long> sys_pthread_self();
|
||||||
BAN::ErrorOr<long> sys_thread_kill(pid_t tid, int signal);
|
BAN::ErrorOr<long> sys_pthread_kill(pthread_t thread, int signal);
|
||||||
BAN::ErrorOr<long> sys_thread_detach(pid_t tid);
|
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_clock_gettime(clockid_t, timespec*);
|
BAN::ErrorOr<long> sys_clock_gettime(clockid_t, timespec*);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_load_keymap(const char* path);
|
BAN::ErrorOr<long> sys_load_keymap(const char* path);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_banos_install(const char* object);
|
|
||||||
|
|
||||||
BAN::RefPtr<TTY> controlling_terminal() { return m_controlling_terminal; }
|
BAN::RefPtr<TTY> controlling_terminal() { return m_controlling_terminal; }
|
||||||
|
|
||||||
static Process& current() { return Thread::current().process(); }
|
static Process& current() { return Thread::current().process(); }
|
||||||
|
|
||||||
vaddr_t shared_page_vaddr() const { return m_shared_page_vaddr; }
|
vaddr_t shared_page_vaddr() const { return m_shared_page_vaddr; }
|
||||||
|
|
||||||
PageTable& page_table() { return *m_page_table; }
|
PageTable& page_table() { return m_page_table ? *m_page_table : PageTable::kernel(); }
|
||||||
|
|
||||||
size_t proc_meminfo(off_t offset, BAN::ByteSpan) const;
|
size_t proc_meminfo(off_t offset, BAN::ByteSpan) const;
|
||||||
size_t proc_cmdline(off_t offset, BAN::ByteSpan) const;
|
size_t proc_cmdline(off_t offset, BAN::ByteSpan) const;
|
||||||
size_t proc_environ(off_t offset, BAN::ByteSpan) const;
|
size_t proc_environ(off_t offset, BAN::ByteSpan) const;
|
||||||
size_t proc_cputime(off_t offset, BAN::ByteSpan) const;
|
|
||||||
BAN::ErrorOr<BAN::String> proc_cwd() const;
|
BAN::ErrorOr<BAN::String> proc_cwd() const;
|
||||||
BAN::ErrorOr<BAN::String> proc_exe() const;
|
BAN::ErrorOr<BAN::String> proc_exe() const;
|
||||||
|
|
||||||
@@ -255,8 +251,6 @@ namespace Kernel
|
|||||||
const VirtualFileSystem::File& working_directory() const { return m_working_directory; }
|
const VirtualFileSystem::File& working_directory() const { return m_working_directory; }
|
||||||
const VirtualFileSystem::File& root_file() const { return m_root_file; }
|
const VirtualFileSystem::File& root_file() const { return m_root_file; }
|
||||||
|
|
||||||
BAN::ErrorOr<AddressRange> find_free_address_range(size_t size);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Process(const Credentials&, pid_t pid, pid_t parent, pid_t sid, pid_t pgrp);
|
Process(const Credentials&, pid_t pid, pid_t parent, pid_t sid, pid_t pgrp);
|
||||||
static Process* create_process(const Credentials&, pid_t parent, pid_t sid = 0, pid_t pgrp = 0);
|
static Process* create_process(const Credentials&, pid_t parent, pid_t sid = 0, pid_t pgrp = 0);
|
||||||
@@ -286,7 +280,10 @@ namespace Kernel
|
|||||||
BAN::ErrorOr<FileParent> find_parent_file(int fd, const char* path, int flags) const;
|
BAN::ErrorOr<FileParent> find_parent_file(int fd, const char* path, int flags) const;
|
||||||
BAN::ErrorOr<VirtualFileSystem::File> find_relative_parent(int fd, const char* path) const;
|
BAN::ErrorOr<VirtualFileSystem::File> find_relative_parent(int fd, const char* path) const;
|
||||||
|
|
||||||
BAN::ErrorOr<void> validate_and_pin_pointer_access(const void*, size_t, bool needs_write, BAN::Vector<MemoryRegion*>&);
|
BAN::ErrorOr<void> read_from_user(const void* user_addr, void* out, size_t size);
|
||||||
|
BAN::ErrorOr<void> read_string_from_user(const char* user_addr, char* out, size_t max_size);
|
||||||
|
BAN::ErrorOr<void> write_to_user(void* user_addr, const void* in, size_t size);
|
||||||
|
BAN::ErrorOr<MemoryRegion*> validate_and_pin_pointer_access(const void*, size_t, bool needs_write);
|
||||||
|
|
||||||
uint64_t signal_pending_mask() const
|
uint64_t signal_pending_mask() const
|
||||||
{
|
{
|
||||||
@@ -364,13 +361,13 @@ namespace Kernel
|
|||||||
|
|
||||||
BAN::Vector<Thread*> m_threads;
|
BAN::Vector<Thread*> m_threads;
|
||||||
|
|
||||||
struct exited_thread_info_t
|
struct pthread_info_t
|
||||||
{
|
{
|
||||||
pid_t tid;
|
pthread_t thread;
|
||||||
void* value;
|
void* value;
|
||||||
};
|
};
|
||||||
BAN::Vector<exited_thread_info_t> m_exited_threads;
|
BAN::Vector<pthread_info_t> m_exited_pthreads;
|
||||||
ThreadBlocker m_thread_exit_blocker;
|
ThreadBlocker m_pthread_exit_blocker;
|
||||||
|
|
||||||
uint64_t m_alarm_interval_ns { 0 };
|
uint64_t m_alarm_interval_ns { 0 };
|
||||||
uint64_t m_alarm_wake_time_ns { 0 };
|
uint64_t m_alarm_wake_time_ns { 0 };
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user