Skip to content

Commit ed6751b

Browse files
committed
wip
1 parent 0bb7511 commit ed6751b

File tree

37 files changed

+555
-364
lines changed

37 files changed

+555
-364
lines changed

.github/workflows/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ jobs:
3333

3434
- name: Build Userspace (Host)
3535
run: ./skift.sh build
36+
37+
- name: Test Userspace (Host)
38+
run: ./skift.sh test

data

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#include <stddef.h>
2+
#include <stdint.h>
3+
4+
#include <iostream>
5+
#include <tuple>
6+
7+
/* --- Eval ----------------------------------------------------------------- */
8+
9+
#define __eval0(...) __VA_ARGS__
10+
#define __eval1(...) __eval0(__eval0(__eval0(__VA_ARGS__)))
11+
#define __eval2(...) __eval1(__eval1(__eval1(__VA_ARGS__)))
12+
#define __eval3(...) __eval2(__eval2(__eval2(__VA_ARGS__)))
13+
#define __eval4(...) __eval3(__eval3(__eval3(__VA_ARGS__)))
14+
15+
#define eval$(...) __eval4(__eval4(__eval4(__VA_ARGS__)))
16+
17+
/* --- Map ------------------------------------------------------------------ */
18+
19+
#define __MAP_END__(...)
20+
#define __MAP_OUT__
21+
#define __MAP_COMMA__ ,
22+
23+
#define __mapGetEnd2() 0, __MAP_END__
24+
#define __mapGetEnd1(...) __mapGetEnd2
25+
#define __mapGetEnd(...) __mapGetEnd1
26+
27+
#define __mapNext0(test, next, ...) next __MAP_OUT__
28+
#define __mapNext1(test, next) __mapNext0(test, next, 0)
29+
#define __mapNext(test, next) __mapNext1(__mapGetEnd test, next)
30+
31+
#define __map0(f, x, peek, ...) \
32+
f(x) __mapNext(peek, __map1)(f, peek, __VA_ARGS__)
33+
#define __map1(f, x, peek, ...) \
34+
f(x) __mapNext(peek, __map0)(f, peek, __VA_ARGS__)
35+
36+
#define __mapListNext1(test, next) __mapNext0(test, __MAP_COMMA__ next, 0)
37+
#define __mapListNext(test, next) __mapListNext1(__mapGetEnd test, next)
38+
39+
#define __mapList0(f, x, peek, ...) \
40+
f(x) __mapListNext(peek, __mapList1)(f, peek, __VA_ARGS__)
41+
#define __mapList1(f, x, peek, ...) \
42+
f(x) __mapListNext(peek, __mapList0)(f, peek, __VA_ARGS__)
43+
44+
// Applies the function macro `f` to each of the remaining parameters.
45+
#define map$(f, ...) eval$(__map1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
46+
47+
// Applies the function macro `f` to each of the remaining parameters and
48+
// inserts commas between the results.
49+
#define mapList$(f, ...) \
50+
eval$(__mapList1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
51+
52+
namespace Karm {
53+
54+
using usize = size_t;
55+
using isize = ptrdiff_t;
56+
57+
using u8 = uint8_t;
58+
using u16 = uint16_t;
59+
using u32 = uint32_t;
60+
using u64 = uint64_t;
61+
using u128 = __uint128_t;
62+
63+
using i8 = int8_t;
64+
using i16 = int16_t;
65+
using i32 = int32_t;
66+
using i64 = int64_t;
67+
using i128 = __int128_t;
68+
69+
using f16 = __fp16;
70+
using f32 = float;
71+
using f64 = double;
72+
using f128 = long double;
73+
74+
using Str = std::string_view;
75+
76+
template <auto N> struct StrLit {
77+
char _buf[N];
78+
constexpr StrLit(char const (&buf)[N]) {
79+
for (usize i = 0; i < N; i++)
80+
_buf[i] = buf[i];
81+
}
82+
constexpr operator char const *() { return _buf; }
83+
};
84+
85+
template <typename T, typename FT, StrLit N, FT T::*P> struct _Field {
86+
using Type = FT;
87+
static constexpr char const *NAME = N;
88+
static constexpr auto PTR = P;
89+
90+
static auto &access(T &t) { return t.*PTR; }
91+
92+
static auto const &access(T const &t) { return t.*PTR; }
93+
};
94+
95+
template <typename T, StrLit N> struct _Type {
96+
using Type = T;
97+
static constexpr char const *NAME = N;
98+
};
99+
100+
template <typename T> struct Reflect;
101+
102+
template <typename T> static constexpr auto nameOf() {
103+
Str v = __PRETTY_FUNCTION__;
104+
auto start = v.find('=');
105+
start += 2;
106+
return v.substr(start, v.length() - start - 1);
107+
}
108+
109+
} // namespace Karm
110+
111+
#define __reflectableField(F) \
112+
Karm::_Field<Type, decltype(std::declval<Type>().F), #F, &Type::F>
113+
114+
#define __reflectableFields(...) \
115+
std::tuple<mapList$(__reflectableField, __VA_ARGS__)>
116+
117+
#define __reflectableType(T, ...) \
118+
struct Karm::Reflect<T> { \
119+
using Type = T; \
120+
static constexpr auto NAME = Karm::nameOf<T>(); \
121+
using Fields = __reflectableFields(__VA_ARGS__); \
122+
}
123+
124+
#define Reflectable$(T, ...) \
125+
template <> __reflectableType(T __VA_OPT__(, ) __VA_ARGS__)
126+
127+
#define ReflectableTemplate$(T, ...) \
128+
__reflectableType(T __VA_OPT__(, ) __VA_ARGS__)
129+
130+
template <typename T> struct Vec {
131+
T x, y, z;
132+
};
133+
134+
template <typename T> ReflectableTemplate$(Vec<T>, x, y, z);
135+
136+
int main() {
137+
std::cout << "'" << Karm::Reflect<Vec<int>>::NAME << "'" << std::endl;
138+
return 0;
139+
}

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
![skiftOS Screenshot](doc/screenshots/2023-06-06.png)
3131

32+
If linux is a bazare, MacOS a cathedral, then skiftOS is a home build for me, my familly, and my friends
33+
3234
## Building
3335

3436
> 🛈 **Note:** If you are having trouble building skiftOS, feel free to ask for help in the [Discord server](https://discord.com/invite/gamGsfg)

src/apps/hideo-colorpicker/model.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ inline void reduce(State &s, Action action) {
3535
});
3636
}
3737

38-
using Model = Karm::Ui::Model<State, Action, reduce>;
38+
using Model = Ui::Model<State, Action, reduce>;
3939

4040
} // namespace ColorPicker

src/kernel/hal-x86_64/asm.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ enum struct Msrs : u64 {
140140
EFER = 0xC0000080,
141141
STAR = 0xC0000081,
142142
LSTAR = 0xC0000082,
143-
COMPAT_STAR = 0xC0000083,
144-
SYSCALL_FLAG_MASK = 0xC0000084,
145-
FS_BASE = 0xC0000100,
146-
GS_BASE = 0xC0000101,
147-
KERN_GS_BASE = 0xc0000102,
143+
CSTAR = 0xC0000083,
144+
FMASK = 0xC0000084,
145+
FSBAS = 0xC0000100,
146+
UGSBAS = 0xC0000101,
147+
KGSBAS = 0xc0000102,
148148
};
149149

150150
inline u64 rdmsr(Msrs msr) {

src/kernel/hal-x86_64/rtc.h

-54
This file was deleted.

src/kernel/hal-x86_64/sys.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ inline void sysInit(void (*handler)()) {
99
wrmsr(Msrs::EFER, rdmsr(Msrs::EFER) | 1);
1010
wrmsr(Msrs::STAR, ((u64)(Gdt::KCODE * 8) << 32) | ((u64)(((Gdt::UDATA - 1) * 8) | 3) << 48));
1111
wrmsr(Msrs::LSTAR, (u64)handler);
12-
wrmsr(Msrs::SYSCALL_FLAG_MASK, 0xfffffffe);
12+
wrmsr(Msrs::FMASK, 0xfffffffe);
1313
}
1414

1515
inline void sysSetGs(usize addr) {
16-
wrmsr(Msrs::GS_BASE, addr);
17-
wrmsr(Msrs::KERN_GS_BASE, addr);
16+
wrmsr(Msrs::KGSBAS, addr);
1817
}
1918

2019
} // namespace x86_64

src/kernel/hjert-x86_64/sys.s

+22-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@ section .text
22

33
extern _sysDispatch
44

5-
%macro push_all 0
5+
6+
ALIGN 4096
7+
global _sysHandler
8+
_sysHandler:
9+
swapgs ; swap from USER gs to KERNEL gs
10+
mov [gs:0x8], rsp ; save current stack to the local cpu structure
11+
mov rsp, [gs:0x0] ; use the kernel syscall stack
12+
13+
sti
14+
15+
push qword 0x1b ; user data
16+
push qword [gs:0x8] ; saved stack
17+
push r11 ; saved rflags
18+
push qword 0x18 ; user code
19+
push rcx ; current IP
20+
push qword 0
21+
push qword 0
22+
23+
cld
624

725
push rax
826
push rbx
@@ -20,9 +38,10 @@ extern _sysDispatch
2038
push r14
2139
push r15
2240

23-
%endmacro
41+
mov rdi, rsp
42+
mov rbp, 0
2443

25-
%macro pop_all 0
44+
call _sysDispatch
2645

2746
pop r15
2847
pop r14
@@ -39,36 +58,6 @@ extern _sysDispatch
3958
pop rcx
4059
pop rbx
4160

42-
%endmacro
43-
44-
ALIGN 4096
45-
global _sysHandler
46-
_sysHandler:
47-
swapgs ; swap from USER gs to KERNEL gs
48-
mov [gs:0x8], rsp ; save current stack to the local cpu structure
49-
mov rsp, [gs:0x0] ; use the kernel syscall stack
50-
51-
sti
52-
53-
push qword 0x1b ; user data
54-
push qword [gs:0x8] ; saved stack
55-
push r11 ; saved rflags
56-
push qword 0x18 ; user code
57-
push rcx ; current IP
58-
59-
push qword 0
60-
push qword 0
61-
62-
cld
63-
push_all
64-
65-
mov rdi, rsp
66-
mov rbp, 0
67-
68-
call _sysDispatch
69-
70-
pop_all ; pop everything except rax because we use it for the return value
71-
7261
cli
7362
mov rsp, [gs:0x8] ; return to the user stack
7463
swapgs

src/libs/karm-base/enum.h

-20
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,6 @@ struct Flags {
9797
bool operator==(Flags other) const {
9898
return _value == other._value;
9999
}
100-
101-
bool operator!=(Flags other) const {
102-
return _value != other._value;
103-
}
104-
105-
bool operator<(Flags other) const {
106-
return _value < other._value;
107-
}
108-
109-
bool operator>(Flags other) const {
110-
return _value > other._value;
111-
}
112-
113-
bool operator<=(Flags other) const {
114-
return _value <= other._value;
115-
}
116-
117-
bool operator>=(Flags other) const {
118-
return _value >= other._value;
119-
}
120100
};
121101

122102
#define FlagsEnum$(T) \

src/libs/karm-base/macros.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,11 @@ namespace Karm {
5858
#define __mapList0(f, x, peek, ...) f(x) __mapListNext(peek, __mapList1)(f, peek, __VA_ARGS__)
5959
#define __mapList1(f, x, peek, ...) f(x) __mapListNext(peek, __mapList0)(f, peek, __VA_ARGS__)
6060

61-
/**
62-
* Applies the function macro `f` to each of the remaining parameters.
63-
*/
61+
// Applies the function macro `f` to each of the remaining parameters.
6462
#define map$(f, ...) eval$(__map1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
6563

66-
/**
67-
* Applies the function macro `f` to each of the remaining parameters and
68-
* inserts commas between the results.
69-
*/
64+
// Applies the function macro `f` to each of the remaining parameters and
65+
// inserts commas between the results.
7066
#define mapList$(f, ...) eval$(__mapList1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
7167

7268
/* --- Utilities ------------------------------------------------------------ */
@@ -83,4 +79,12 @@ ALWAYS_INLINE static inline T unionCast(U value)
8379
return X{.u = value}.t;
8480
}
8581

82+
/* --- Reflect -------------------------------------------------------------- */
83+
84+
#define __visitorField(F) v(#F, F);
85+
#define Reflect$(...) \
86+
static void reflect(auto &t, auto v) { \
87+
map$(__visitorField, __VA_ARGS__) \
88+
}
89+
8690
} // namespace Karm

0 commit comments

Comments
 (0)