forked from AbleOS/ableos
Compare commits
143 commits
Author | SHA1 | Date | |
---|---|---|---|
|
1ea3257921 | ||
|
2d4a66598d | ||
|
3d925aa13b | ||
|
b2f830faf7 | ||
|
91df131850 | ||
|
19715ef6fd | ||
|
abaac886ef | ||
|
cb68df6a7f | ||
|
5e369d43c1 | ||
|
1fdef70144 | ||
|
d5dfd1d086 | ||
|
507704234f | ||
|
89e5e2c0ad | ||
|
ffee890842 | ||
|
c6da72f393 | ||
|
c50b722fca | ||
|
5d90ae9e4d | ||
|
09bf7053b6 | ||
|
9da66e7b29 | ||
|
9142c02da0 | ||
|
62f9fa1fd4 | ||
|
5616e0ba03 | ||
|
90f1b3fdc5 | ||
|
986077435f | ||
|
530b62aa3d | ||
|
b864463ad8 | ||
|
1e1943d940 | ||
|
47d727855d | ||
|
5b123be9ea | ||
|
2fb17ac610 | ||
|
1ec9d0fd46 | ||
|
59cf6ef4d7 | ||
|
8cce5ef731 | ||
|
0fc95160cc | ||
|
25fecab5b3 | ||
|
f6bfb73bd7 | ||
|
f8523f5b3e | ||
|
d2cb73c2ce | ||
|
d0bd3714ee | ||
|
e8f1bce4d6 | ||
|
dc4878bc2b | ||
|
04ca5f07d5 | ||
|
ad587fe464 | ||
|
9a06b329f4 | ||
|
936c9e6525 | ||
|
a8572da351 | ||
|
b059faa7f8 | ||
|
d55fd895c9 | ||
|
e2dd379fea | ||
|
d907df14dd | ||
|
3506c83535 | ||
|
eff1323e94 | ||
|
8849017db2 | ||
|
f3b78d1699 | ||
|
5eff0facb1 | ||
|
6e3fea0713 | ||
|
55c8d9b8b2 | ||
|
642b0b74b5 | ||
|
5b3a97e580 | ||
|
ee68a2662c | ||
|
72cf91a928 | ||
|
f714775091 | ||
|
6af68994d8 | ||
|
df7982d9e5 | ||
|
e688fdf4f0 | ||
|
bcc7c827ab | ||
|
eff2a22018 | ||
|
883c01b2ba | ||
|
635ed1be42 | ||
|
36d50f6b38 | ||
|
559f25bb4e | ||
|
82b9cb1206 | ||
|
2afa83a615 | ||
|
28258e0d45 | ||
|
190f0941dc | ||
|
68840571c0 | ||
|
dc3b7f71d5 | ||
|
bff8db4c13 | ||
|
13c4649fd6 | ||
|
f7f5b677e9 | ||
|
821497fbe6 | ||
|
5abdef4be6 | ||
|
b5282ea6fb | ||
|
498cfbf913 | ||
|
e3abec2927 | ||
|
b3d07b5235 | ||
|
a93512eed1 | ||
|
c429641f98 | ||
|
db01da58e1 | ||
|
38d3a10659 | ||
|
a551b2672f | ||
|
fd26ec734b | ||
|
9d1c59b65d | ||
|
cda022e6f0 | ||
|
95cf948d59 | ||
|
f6a8a78b6c | ||
|
5d152811b2 | ||
|
685c6f0b20 | ||
|
1b3dc153e8 | ||
|
9aa84a0f40 | ||
|
bdb762c986 | ||
|
0b57c2e9bb | ||
|
8c88c0b5ae | ||
|
8b2b50e433 | ||
|
d7e0d573e2 | ||
|
0ee8b7a4e4 | ||
|
2261f36101 | ||
|
6f82c92c30 | ||
|
5ea3ee9fe1 | ||
|
241139f5af | ||
|
5c4056bc5c | ||
|
5028062e39 | ||
|
f7f9fece4f | ||
|
f4ceab972c | ||
|
96c07e137b | ||
|
d78878a12f | ||
|
8f265ebf40 | ||
|
3d5a8f6f10 | ||
|
f11122e58e | ||
|
2fdede7199 | ||
|
13422dfd9f | ||
|
90a97cd160 | ||
|
23b45b1887 | ||
|
cf37eaf086 | ||
|
284aa5a5e6 | ||
|
11976b752f | ||
|
98b15d4c10 | ||
|
f5c6d7d822 | ||
|
efcd6c0631 | ||
|
b795aced8e | ||
|
08099b0877 | ||
|
a1bfd8e85f | ||
|
edfb588060 | ||
|
cc4a32afaa | ||
|
be6a095c14 | ||
|
aac1164d55 | ||
|
89d08d8a62 | ||
|
8f5833955f | ||
|
4c0adbe15d | ||
|
3708acc077 | ||
|
b5b122f451 | ||
|
39ebaa03ba | ||
|
de8000f596 |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"editor.detectIndentation": false,
|
||||||
"rust-analyzer.checkOnSave.allTargets": false,
|
"rust-analyzer.checkOnSave.allTargets": false,
|
||||||
"rust-analyzer.showUnlinkedFileNotification": false,
|
"rust-analyzer.showUnlinkedFileNotification": false,
|
||||||
"C_Cpp.errorSquiggles": "disabled"
|
"C_Cpp.errorSquiggles": "disabled"
|
||||||
|
|
140
Cargo.lock
generated
140
Cargo.lock
generated
|
@ -13,15 +13,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.2.20"
|
version = "0.2.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9"
|
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.93"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
|
@ -61,9 +61,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.6.0"
|
version = "2.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
|
@ -73,9 +73,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.1"
|
version = "1.2.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47"
|
checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
@ -88,18 +88,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-queue"
|
name = "crossbeam-queue"
|
||||||
version = "0.3.11"
|
version = "0.3.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35"
|
checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.20"
|
version = "0.8.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_more"
|
name = "derive_more"
|
||||||
|
@ -175,9 +175,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foldhash"
|
name = "foldhash"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "form_urlencoded"
|
name = "form_urlencoded"
|
||||||
|
@ -201,9 +201,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.15.1"
|
version = "0.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
|
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"allocator-api2",
|
"allocator-api2",
|
||||||
"equivalent",
|
"equivalent",
|
||||||
|
@ -213,12 +213,12 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbytecode"
|
name = "hbbytecode"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#18e8a831ab6b710dbdd9b0d6a0880c67df0cec26"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hblang"
|
name = "hblang"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#18e8a831ab6b710dbdd9b0d6a0880c67df0cec26"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
|
@ -229,7 +229,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#18e8a831ab6b710dbdd9b0d6a0880c67df0cec26"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
]
|
]
|
||||||
|
@ -375,9 +375,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.6.0"
|
version = "2.7.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
|
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
|
@ -401,7 +401,7 @@ dependencies = [
|
||||||
"uart_16550",
|
"uart_16550",
|
||||||
"versioning",
|
"versioning",
|
||||||
"x2apic",
|
"x2apic",
|
||||||
"x86_64 0.15.1",
|
"x86_64 0.15.2",
|
||||||
"xml",
|
"xml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -421,9 +421,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.164"
|
version = "0.2.169"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "limine"
|
name = "limine"
|
||||||
|
@ -449,24 +449,24 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.22"
|
version = "0.4.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "logos"
|
name = "logos"
|
||||||
version = "0.14.2"
|
version = "0.14.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1c6b6e02facda28ca5fb8dbe4b152496ba3b1bd5a4b40bb2b1b2d8ad74e0f39b"
|
checksum = "7251356ef8cb7aec833ddf598c6cb24d17b689d20b993f9d11a3d764e34e6458"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"logos-derive",
|
"logos-derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "logos-codegen"
|
name = "logos-codegen"
|
||||||
version = "0.14.2"
|
version = "0.14.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b32eb6b5f26efacd015b000bfc562186472cd9b34bdba3f6b264e2a052676d10"
|
checksum = "59f80069600c0d66734f5ff52cc42f2dabd6b29d205f333d61fd7832e9e9963f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"beef",
|
"beef",
|
||||||
"fnv",
|
"fnv",
|
||||||
|
@ -479,9 +479,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "logos-derive"
|
name = "logos-derive"
|
||||||
version = "0.14.2"
|
version = "0.14.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3e5d0c5463c911ef55624739fc353238b4e310f0144be1f875dc42fec6bfd5ec"
|
checksum = "24fb722b06a9dc12adb0963ed585f19fc61dc5413e6a9be9422ef92c091e731d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"logos-codegen",
|
"logos-codegen",
|
||||||
]
|
]
|
||||||
|
@ -512,18 +512,18 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.92"
|
version = "1.0.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.37"
|
version = "1.0.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
@ -539,11 +539,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "raw-cpuid"
|
name = "raw-cpuid"
|
||||||
version = "11.2.0"
|
version = "11.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0"
|
checksum = "c6928fa44c097620b706542d428957635951bade7143269085389d42c8a4927e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -561,7 +561,7 @@ dependencies = [
|
||||||
"fatfs",
|
"fatfs",
|
||||||
"hblang",
|
"hblang",
|
||||||
"log",
|
"log",
|
||||||
"raw-cpuid 11.2.0",
|
"raw-cpuid 11.3.0",
|
||||||
"str-reader",
|
"str-reader",
|
||||||
"toml",
|
"toml",
|
||||||
"ureq",
|
"ureq",
|
||||||
|
@ -593,9 +593,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.23.18"
|
version = "0.23.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f"
|
checksum = "9fb9263ab4eb695e42321db096e3b8fbd715a59b154d5c88d82db2175b681ba7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -608,9 +608,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-pki-types"
|
name = "rustls-pki-types"
|
||||||
version = "1.10.0"
|
version = "1.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b"
|
checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-webpki"
|
name = "rustls-webpki"
|
||||||
|
@ -625,9 +625,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.18"
|
version = "1.0.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sbi"
|
name = "sbi"
|
||||||
|
@ -643,24 +643,24 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "1.0.23"
|
version = "1.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.215"
|
version = "1.0.217"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.215"
|
version = "1.0.217"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -726,9 +726,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.89"
|
version = "2.0.96"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e"
|
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -785,9 +785,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_edit"
|
name = "toml_edit"
|
||||||
version = "0.22.22"
|
version = "0.22.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
|
checksum = "02a8b472d1a3d7c18e2d61a489aee3453fd9031c33e4f55bd533f4a7adca1bee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -802,16 +802,16 @@ version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e492212ac378a5e00da953718dafb1340d9fbaf4f27d6f3c5cab03d931d1c049"
|
checksum = "e492212ac378a5e00da953718dafb1340d9fbaf4f27d6f3c5cab03d931d1c049"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.8.0",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"x86",
|
"x86",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.14"
|
version = "1.0.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
|
@ -827,9 +827,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ureq"
|
name = "ureq"
|
||||||
version = "2.10.1"
|
version = "2.12.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a"
|
checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"log",
|
"log",
|
||||||
|
@ -967,9 +967,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.6.20"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
|
checksum = "7e49d2d35d3fad69b39b94139037ecfb4f359f08958b9c11e7315ce770462419"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
@ -996,7 +996,7 @@ dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"paste",
|
"paste",
|
||||||
"raw-cpuid 10.7.0",
|
"raw-cpuid 10.7.0",
|
||||||
"x86_64 0.14.12",
|
"x86_64 0.14.13",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1012,24 +1012,24 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x86_64"
|
name = "x86_64"
|
||||||
version = "0.14.12"
|
version = "0.14.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "96cb6fd45bfeab6a5055c5bffdb08768bd0c069f1d946debe585bbb380a7c062"
|
checksum = "c101112411baafbb4bf8d33e4c4a80ab5b02d74d2612331c61e8192fc9710491"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.8.0",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"volatile",
|
"volatile",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x86_64"
|
name = "x86_64"
|
||||||
version = "0.15.1"
|
version = "0.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df"
|
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.8.0",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"volatile",
|
"volatile",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,3 +7,11 @@ members = ["dev", "kernel", "repbuild"]
|
||||||
# codegen-units = 1
|
# codegen-units = 1
|
||||||
# lto = true
|
# lto = true
|
||||||
# panic = "abort"
|
# panic = "abort"
|
||||||
|
|
||||||
|
[profile.release.package.hblang]
|
||||||
|
debug-assertions = true
|
||||||
|
overflow-checks = false
|
||||||
|
|
||||||
|
[profile.dev.package.hblang]
|
||||||
|
debug-assertions = true
|
||||||
|
overflow-checks = false
|
||||||
|
|
77
STYLE_GUIDE.md
Normal file
77
STYLE_GUIDE.md
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# Style Guide
|
||||||
|
This style guide has two modes that a guideline may be.
|
||||||
|
|
||||||
|
`strict` means that prs will be rejected if they do not follow the guideline.
|
||||||
|
|
||||||
|
`loose` means that a pr would be accepted but should later be fixed.
|
||||||
|
|
||||||
|
## Empty Functions | loose
|
||||||
|
Empty functions are typically a sign of an unfinished program or driver.
|
||||||
|
|
||||||
|
In cases where there is a clear reason to have an empty function it will be allowed.
|
||||||
|
For example FakeAlloc is only empty functions because it is a example of an the allocator api.
|
||||||
|
|
||||||
|
### Allowed
|
||||||
|
```rust
|
||||||
|
/// in example.hb
|
||||||
|
a := fn(): void {}
|
||||||
|
```
|
||||||
|
### Not Allowed
|
||||||
|
```rust
|
||||||
|
/// in fat32.hb
|
||||||
|
a := fn(): void {}
|
||||||
|
```
|
||||||
|
## Magic Functions | loose
|
||||||
|
'Magic functions' are what I am calling small helper functions that do one or two things.
|
||||||
|
### Example
|
||||||
|
```rust
|
||||||
|
a := null
|
||||||
|
magic_a := fn(){
|
||||||
|
a = 10
|
||||||
|
}
|
||||||
|
```
|
||||||
|
The exact policy I want to have here is a bit fuzzy. I think that functions like this are nice in certain situations and not in others.
|
||||||
|
Regardless of if you use them or not, put a comment above the function explaining rational.
|
||||||
|
|
||||||
|
|
||||||
|
## Magic Numbers | loose
|
||||||
|
The policy on magic numbers is make them const and have a comment above them. Typically linking to a source of information about the magic number.
|
||||||
|
|
||||||
|
This helps cut down on magic numbers while making acceptable names and atleast half assed documentation.
|
||||||
|
|
||||||
|
Constants are inlined anyways, so its the same thing in the binary.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// The standard vga port is mapped at 0xB8000
|
||||||
|
$VGA_PTR := 0xB8000
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tabs Vs Spaces | strict
|
||||||
|
I prefer for hblang code to use hard tabs.
|
||||||
|
|
||||||
|
The rational behind this is that a tab is `1 Indent` which some developers might want to be various different sizes when displayed
|
||||||
|
|
||||||
|
Soft tabs do not allow this user/editor specific as soft tabs always become spaces.
|
||||||
|
|
||||||
|
Bottom line is this is an accessibility feature.
|
||||||
|
|
||||||
|
There are some samples below.
|
||||||
|
```
|
||||||
|
\t means hard tab
|
||||||
|
\n means new line
|
||||||
|
\0x20 means space
|
||||||
|
```
|
||||||
|
|
||||||
|
### Allowed
|
||||||
|
```rust
|
||||||
|
if x == y {\n
|
||||||
|
\tlog(z)\n
|
||||||
|
}\n
|
||||||
|
```
|
||||||
|
|
||||||
|
### Not Allowed
|
||||||
|
```rust
|
||||||
|
if x == y {\n
|
||||||
|
\0x20\0x20\0x20\0x20log(z)\n
|
||||||
|
}\n
|
||||||
|
```
|
|
@ -9,7 +9,7 @@ ktest = []
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# embedded-graphics = "0.8"
|
# embedded-graphics = "0.8"
|
||||||
hbvm = { git = "https://git.ablecorp.us/AbleOS/holey-bytes.git", features = [
|
hbvm = { git = "https://git.ablecorp.us/AbleOS/holey-bytes.git", features = [
|
||||||
"nightly",
|
"nightly", "alloc", "disasm"
|
||||||
] }
|
] }
|
||||||
ktest_macro = { path = "ktest_macro" }
|
ktest_macro = { path = "ktest_macro" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
proc_macro::TokenStream,
|
proc_macro::TokenStream,
|
||||||
quote::quote,
|
quote::quote,
|
||||||
|
|
|
@ -6,12 +6,12 @@ SECTIONS
|
||||||
.text.boot : { *(.text.boot) }
|
.text.boot : { *(.text.boot) }
|
||||||
.text : { *(.text) }
|
.text : { *(.text) }
|
||||||
.data : { *(.data) }
|
.data : { *(.data) }
|
||||||
.rodata : { *(.rodata) }
|
|
||||||
.note.ktest : {
|
.note.ktest : {
|
||||||
__ktest_start = .;
|
__ktest_start = .;
|
||||||
*(.note.ktest)
|
*(.note.ktest)
|
||||||
__ktest_end = .;
|
__ktest_end = .;
|
||||||
}
|
}
|
||||||
|
.rodata : { *(.rodata) }
|
||||||
.bss : {
|
.bss : {
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
*(.bss .bss.*)
|
*(.bss .bss.*)
|
||||||
|
|
|
@ -62,7 +62,7 @@ extern "x86-interrupt" fn page_fault(
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) {
|
extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) {
|
||||||
// interrupt(Interrupt::Timer);
|
interrupt(Interrupt::Timer);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
LAPIC.end_of_interrupt();
|
LAPIC.end_of_interrupt();
|
||||||
|
@ -83,28 +83,31 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_imports)]
|
||||||
fn interrupt(interrupt_type: Interrupt) {
|
fn interrupt(interrupt_type: Interrupt) {
|
||||||
use crate::arch::INTERRUPT_LIST;
|
use crate::{arch::INTERRUPT_LIST, kmain::EXECUTOR};
|
||||||
let il = INTERRUPT_LIST.lock();
|
// let il = INTERRUPT_LIST.lock();
|
||||||
let val = il.list.get(&interrupt_type).unwrap();
|
// let val = il.list.get(&interrupt_type).unwrap();
|
||||||
|
|
||||||
use crate::holeybytes::kernel_services::service_definition_service::sds_search_service;
|
// use crate::holeybytes::kernel_services::service_definition_service::sds_search_service;
|
||||||
let buffer = sds_search_service(val);
|
// let buffer = sds_search_service(val);
|
||||||
if buffer != 0 {
|
// if buffer != 0 {
|
||||||
use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec};
|
// use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec};
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
// let mut buffs = IPC_BUFFERS.lock();
|
||||||
match buffs.get_mut(&buffer) {
|
// match buffs.get_mut(&buffer) {
|
||||||
Some(buff) => {
|
// Some(buff) => {
|
||||||
let mut msg_vec = Vec::new();
|
// let mut msg_vec = Vec::new();
|
||||||
msg_vec.push(0xFF);
|
// msg_vec.push(0xFF);
|
||||||
buff.push(msg_vec.to_vec());
|
// buff.push(msg_vec.to_vec());
|
||||||
log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer);
|
// log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer);
|
||||||
}
|
// }
|
||||||
None => {
|
// None => {
|
||||||
log::error!("Access of non-existent buffer {}", buffer)
|
// log::error!("Access of non-existent buffer {}", buffer)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// log::info!("{}", buffer);
|
unsafe {
|
||||||
|
EXECUTOR.send_interrupt(interrupt_type as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,13 @@ use crate::{
|
||||||
block_read, dt_msg_handler::dt_msg_handler, logging_service::log_msg_handler,
|
block_read, dt_msg_handler::dt_msg_handler, logging_service::log_msg_handler,
|
||||||
service_definition_service::sds_msg_handler,
|
service_definition_service::sds_msg_handler,
|
||||||
},
|
},
|
||||||
ExecThread,
|
ExecThread, STACK_SIZE,
|
||||||
},
|
},
|
||||||
kmain::EXECUTOR,
|
kmain::EXECUTOR,
|
||||||
task::Executor,
|
task::Executor,
|
||||||
};
|
};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
super::Vm,
|
|
||||||
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
||||||
hbvm::value::Value,
|
hbvm::value::Value,
|
||||||
log::{debug, error, info, trace},
|
log::{debug, error, info, trace},
|
||||||
|
@ -33,21 +32,21 @@ unsafe fn x86_in<T: x86_64::instructions::port::PortRead>(address: u16) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn handler(vm: &mut Vm) {
|
pub fn handler(thr: &mut ExecThread, pid: &usize) {
|
||||||
let ecall_number = vm.registers[2].cast::<u64>();
|
let ecall_number = thr.vm.registers[2].cast::<u64>();
|
||||||
|
|
||||||
match ecall_number {
|
match ecall_number {
|
||||||
0 => {
|
0 => {
|
||||||
// TODO: explode computer
|
// TODO: explode computer
|
||||||
// hello world ecall
|
// hello world ecall
|
||||||
for x in 0u64..=255 {
|
for x in 0u64..=255 {
|
||||||
vm.registers[x as usize] = x.into();
|
thr.vm.registers[x as usize] = x.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
// Make buffer
|
// Make buffer
|
||||||
|
|
||||||
let bounded = match vm.registers[3] {
|
let bounded = match thr.vm.registers[3] {
|
||||||
Value(0) => false,
|
Value(0) => false,
|
||||||
Value(1) => true,
|
Value(1) => true,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -55,7 +54,7 @@ pub fn handler(vm: &mut Vm) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let length = vm.registers[4].cast::<u64>();
|
let length = thr.vm.registers[4].cast::<u64>();
|
||||||
|
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
let mut buffs = IPC_BUFFERS.lock();
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ pub fn handler(vm: &mut Vm) {
|
||||||
true => IpcBuffer::new(true, length),
|
true => IpcBuffer::new(true, length),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
vm.registers[1] = hbvm::value::Value(buff_id);
|
thr.vm.registers[1] = hbvm::value::Value(buff_id);
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
log::error!("Oops, deleting buffers is not implemented.")
|
log::error!("Oops, deleting buffers is not implemented.")
|
||||||
|
@ -75,23 +74,27 @@ pub fn handler(vm: &mut Vm) {
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
// Send a message to a buffer
|
// Send a message to a buffer
|
||||||
let buffer_id = vm.registers[3].cast::<u64>();
|
let buffer_id = thr.vm.registers[3].cast::<u64>();
|
||||||
let mem_addr = vm.registers[4].cast::<u64>();
|
let mem_addr = thr.vm.registers[4].cast::<u64>();
|
||||||
let length = vm.registers[5].cast::<u64>() as usize;
|
let length = thr.vm.registers[5].cast::<u64>() as usize;
|
||||||
trace!("IPC address: {:?}", mem_addr);
|
trace!("IPC address: {:?}", mem_addr);
|
||||||
|
|
||||||
|
unsafe { LazyCell::<Executor>::get_mut(&mut EXECUTOR) }
|
||||||
|
.unwrap()
|
||||||
|
.send_buffer(buffer_id as usize);
|
||||||
|
|
||||||
match buffer_id {
|
match buffer_id {
|
||||||
0 => match sds_msg_handler(vm, mem_addr, length) {
|
0 => match sds_msg_handler(&mut thr.vm, mem_addr, length) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => log::error!("Improper sds format: {err:?}"),
|
Err(err) => log::error!("Improper sds format: {err:?}"),
|
||||||
},
|
},
|
||||||
1 => match log_msg_handler(vm, mem_addr, length) {
|
1 => match log_msg_handler(&mut thr.vm, mem_addr, length) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => log::error!("Improper log format"),
|
Err(_) => log::error!("Improper log format"),
|
||||||
},
|
},
|
||||||
2 => {
|
2 => {
|
||||||
use crate::holeybytes::kernel_services::mem_serve::memory_msg_handler;
|
use crate::holeybytes::kernel_services::mem_serve::memory_msg_handler;
|
||||||
match memory_msg_handler(vm, mem_addr, length) {
|
match memory_msg_handler(&mut thr.vm, mem_addr, length) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +115,7 @@ pub fn handler(vm: &mut Vm) {
|
||||||
_ => panic!("Trying to read size other than: 8, 16, 32 from port."),
|
_ => panic!("Trying to read size other than: 8, 16, 32 from port."),
|
||||||
};
|
};
|
||||||
// info!("Read the value {} from address {}", value, addr);
|
// info!("Read the value {} from address {}", value, addr);
|
||||||
vm.registers[1] = hbvm::value::Value(value);
|
thr.vm.registers[1] = hbvm::value::Value(value);
|
||||||
},
|
},
|
||||||
1 => unsafe {
|
1 => unsafe {
|
||||||
let size = msg_vec[1];
|
let size = msg_vec[1];
|
||||||
|
@ -146,9 +149,9 @@ pub fn handler(vm: &mut Vm) {
|
||||||
&crate::arch::hardware_random_u64().to_le_bytes()[..chunk.len()],
|
&crate::arch::hardware_random_u64().to_le_bytes()[..chunk.len()],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
vm.registers[1] = hbvm::value::Value(mem_addr);
|
thr.vm.registers[1] = hbvm::value::Value(mem_addr);
|
||||||
}
|
}
|
||||||
5 => match dt_msg_handler(vm, mem_addr, length) {
|
5 => match dt_msg_handler(&mut thr.vm, mem_addr, length) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => log::error!("Improper dt query"),
|
Err(_) => log::error!("Improper dt query"),
|
||||||
},
|
},
|
||||||
|
@ -177,18 +180,39 @@ pub fn handler(vm: &mut Vm) {
|
||||||
let end = (code_length + data_length) as usize;
|
let end = (code_length + data_length) as usize;
|
||||||
log::debug!("{code_length} + {data_length} = {end}");
|
log::debug!("{code_length} + {data_length} = {end}");
|
||||||
|
|
||||||
let thr = ExecThread::new(&program[offset..end], Address::new(0));
|
let thr2 = ExecThread::new(program[offset..end].into(), Address::new(0));
|
||||||
vm.registers[1] = Value(
|
thr.vm.registers[1] = Value(
|
||||||
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.spawn(Box::pin(async move {
|
.spawn(Box::pin(async move {
|
||||||
if let Err(e) = thr.await {
|
if let Err(e) = thr2.await {
|
||||||
log::error!("{e:?}");
|
log::error!("{e:?}");
|
||||||
}
|
}
|
||||||
})) as u64,
|
})) as u64,
|
||||||
);
|
);
|
||||||
log::debug!("spawned a process");
|
log::debug!("spawned a process");
|
||||||
},
|
},
|
||||||
|
7 => unsafe {
|
||||||
|
let mut thr2 = ExecThread::new(
|
||||||
|
thr.program,
|
||||||
|
thr.vm.pc.wrapping_sub(thr.program.as_ptr() as u64),
|
||||||
|
);
|
||||||
|
thr.stack_bottom
|
||||||
|
.copy_to_nonoverlapping(thr2.stack_bottom, STACK_SIZE);
|
||||||
|
thr2.vm.registers = thr.vm.registers;
|
||||||
|
thr2.vm.registers[1] = Value(0);
|
||||||
|
|
||||||
|
thr.vm.registers[1] = Value(
|
||||||
|
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||||
|
.unwrap()
|
||||||
|
.spawn(Box::pin(async move {
|
||||||
|
if let Err(e) = thr2.await {
|
||||||
|
log::error!("{e:?}");
|
||||||
|
}
|
||||||
|
})) as u64,
|
||||||
|
);
|
||||||
|
log::debug!("forked a process")
|
||||||
|
},
|
||||||
|
|
||||||
buffer_id => {
|
buffer_id => {
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
let mut buffs = IPC_BUFFERS.lock();
|
||||||
|
@ -206,10 +230,9 @@ pub fn handler(vm: &mut Vm) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4 => {
|
4 => {
|
||||||
let buffer_id = vm.registers[3].cast::<u64>();
|
let buffer_id = thr.vm.registers[3].cast::<u64>();
|
||||||
let map_ptr = vm.registers[4].cast::<u64>();
|
let map_ptr = thr.vm.registers[4].cast::<u64>();
|
||||||
let max_length = vm.registers[5].cast::<u64>();
|
let max_length = thr.vm.registers[5].cast::<u64>();
|
||||||
|
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
let mut buffs = IPC_BUFFERS.lock();
|
||||||
let buff: &mut IpcBuffer = match buffs.get_mut(&buffer_id) {
|
let buff: &mut IpcBuffer = match buffs.get_mut(&buffer_id) {
|
||||||
Some(buff) => buff,
|
Some(buff) => buff,
|
||||||
|
@ -237,14 +260,36 @@ pub fn handler(vm: &mut Vm) {
|
||||||
5 => {
|
5 => {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
{
|
{
|
||||||
let r2 = vm.registers[2].cast::<u64>();
|
let r2 = thr.vm.registers[2].cast::<u64>();
|
||||||
let x = hbvm::value::Value(unsafe { x86_in::<u8>(r2 as u16) } as u64);
|
let x = hbvm::value::Value(unsafe { x86_in::<u8>(r2 as u16) } as u64);
|
||||||
// info!("Read {:?} from Port {:?}", x, r2);
|
// info!("Read {:?} from Port {:?}", x, r2);
|
||||||
vm.registers[3] = x
|
thr.vm.registers[3] = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6 => {
|
||||||
|
// Wait till interrupt
|
||||||
|
use crate::kmain::EXECUTOR;
|
||||||
|
let interrupt_type = thr.vm.registers[3].cast::<u8>();
|
||||||
|
debug!("Interrupt subscribed: {}", interrupt_type);
|
||||||
|
unsafe {
|
||||||
|
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||||
|
.unwrap()
|
||||||
|
.interrupt_subscribe(*pid, interrupt_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
7 => {
|
||||||
|
// Wait till buffer
|
||||||
|
use crate::kmain::EXECUTOR;
|
||||||
|
let buffer_id = thr.vm.registers[3].cast::<u64>() as usize;
|
||||||
|
debug!("Buffer subscribed: {}", buffer_id);
|
||||||
|
unsafe {
|
||||||
|
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
|
||||||
|
.unwrap()
|
||||||
|
.buffer_subscribe(*pid, buffer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers);
|
log::error!("Syscall unknown {:?}{:?}", ecall_number, thr.vm.registers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use {
|
use {
|
||||||
crate::holeybytes::{kernel_services::block_read, Vm},
|
crate::holeybytes::{kernel_services::block_read, Vm},
|
||||||
alloc::alloc::{alloc, dealloc},
|
alloc::alloc::{alloc, alloc_zeroed, dealloc, realloc},
|
||||||
core::alloc::Layout,
|
core::alloc::Layout,
|
||||||
log::{debug, info},
|
log::{debug, info},
|
||||||
};
|
};
|
||||||
|
@ -48,29 +48,29 @@ pub fn memory_msg_handler(
|
||||||
let msg_type = msg_vec[0];
|
let msg_type = msg_vec[0];
|
||||||
match msg_type {
|
match msg_type {
|
||||||
0 => unsafe {
|
0 => unsafe {
|
||||||
let page_count = msg_vec[1];
|
let page_count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()) as usize;
|
||||||
|
let zeroed = msg_vec[9];
|
||||||
|
let ptr = if zeroed > 0 {
|
||||||
|
alloc_zeroed(Layout::from_size_align_unchecked(page_count * 4096, 8))
|
||||||
|
} else {
|
||||||
|
alloc(Layout::from_size_align_unchecked(page_count * 4096, 8))
|
||||||
|
};
|
||||||
|
|
||||||
let ptr = alloc(Layout::from_size_align_unchecked(
|
log::debug!("Allocating {} pages @ {:?}", page_count, ptr);
|
||||||
page_count as usize * 4096,
|
|
||||||
8,
|
|
||||||
));
|
|
||||||
|
|
||||||
log::debug!("Allocating {} pages @ {:x}", page_count, ptr as u64);
|
|
||||||
|
|
||||||
vm.registers[1] = hbvm::value::Value(ptr as u64);
|
vm.registers[1] = hbvm::value::Value(ptr as u64);
|
||||||
log::debug!("Kernel ptr: {:x}", ptr as u64);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
1 => unsafe {
|
1 => unsafe {
|
||||||
let page_count = msg_vec[1];
|
let page_count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()) as usize;
|
||||||
|
|
||||||
let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap();
|
let mptr = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as *mut u8;
|
||||||
let mptr: u64 = u64::from_le_bytes(mptr_raw);
|
debug_assert!(mptr.addr() & 0xFFFF000000000000 != 0);
|
||||||
log::debug!("Deallocating {} pages @ {:x}", page_count, mptr);
|
log::debug!("Deallocating {} pages @ {:?}", page_count, mptr);
|
||||||
|
|
||||||
dealloc(
|
dealloc(
|
||||||
mptr as *mut u8,
|
mptr,
|
||||||
Layout::from_size_align_unchecked(page_count as usize * 4096, 8),
|
Layout::from_size_align_unchecked(page_count * 4096, 8),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
2 => {
|
2 => {
|
||||||
|
@ -96,19 +96,51 @@ pub fn memory_msg_handler(
|
||||||
log::debug!(" {} pages", page_count);
|
log::debug!(" {} pages", page_count);
|
||||||
}
|
}
|
||||||
4 => unsafe {
|
4 => unsafe {
|
||||||
let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize;
|
let count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap_unchecked()) as usize;
|
||||||
let src = u64::from_le_bytes(msg_vec[5..13].try_into().unwrap_unchecked()) as *const u8;
|
let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8;
|
||||||
let dest = u64::from_le_bytes(msg_vec[13..21].try_into().unwrap_unchecked()) as *mut u8;
|
let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8;
|
||||||
|
debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
|
||||||
src.copy_to_nonoverlapping(dest, count);
|
src.copy_to_nonoverlapping(dest, count);
|
||||||
},
|
},
|
||||||
5 => unsafe {
|
5 => unsafe {
|
||||||
let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize;
|
let count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap_unchecked()) as usize;
|
||||||
let size = u32::from_le_bytes(msg_vec[5..9].try_into().unwrap_unchecked()) as usize;
|
let size = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as usize;
|
||||||
|
let src =
|
||||||
|
u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *const u8;
|
||||||
|
let dest = u64::from_le_bytes(msg_vec[25..33].try_into().unwrap_unchecked()) as *mut u8;
|
||||||
|
debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
memset(dest, src, count, size);
|
||||||
|
},
|
||||||
|
6 => unsafe {
|
||||||
|
let count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap_unchecked()) as usize;
|
||||||
let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8;
|
let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8;
|
||||||
let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8;
|
let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8;
|
||||||
|
debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
src.copy_to(dest, count);
|
||||||
|
},
|
||||||
|
7 => unsafe {
|
||||||
|
let page_count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()) as usize;
|
||||||
|
let page_count_new = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize;
|
||||||
|
let ptr = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap()) as *mut u8;
|
||||||
|
debug_assert!(ptr.addr() & 0xFFFF000000000000 != 0);
|
||||||
|
let ptr_new = realloc(
|
||||||
|
ptr,
|
||||||
|
Layout::from_size_align_unchecked(page_count * 4096, 8),
|
||||||
|
page_count_new * 4096,
|
||||||
|
);
|
||||||
|
|
||||||
memset(dest, src, count, size);
|
log::debug!(
|
||||||
|
"Re-allocating {} (now {}) pages from {:?} to {:?}",
|
||||||
|
page_count,
|
||||||
|
page_count_new,
|
||||||
|
ptr,
|
||||||
|
ptr_new
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.registers[1] = hbvm::value::Value(ptr_new as u64);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
log::debug!("Unknown memory service message type: {}", msg_type);
|
log::debug!("Unknown memory service message type: {}", msg_type);
|
||||||
|
|
|
@ -15,8 +15,10 @@ fn calc_start_of_page(ptr: u64) -> u64 {
|
||||||
panic!("unaligned");
|
panic!("unaligned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
// TODO: map page aligned segments of memory into a table or some sort here
|
// TODO: map page aligned segments of memory into a table or some sort here
|
||||||
|
logger: hbvm::mem::InstrLogger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
|
@ -56,4 +58,12 @@ impl hbvm::mem::Memory for Memory {
|
||||||
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
|
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
|
||||||
(addr.get() as *const T).read()
|
(addr.get() as *const T).read()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
#[allow(unused)]
|
||||||
|
fn log_instr(&mut self, at: Address, regs: &[hbvm::value::Value]) {
|
||||||
|
// log::debug!("exec: [{:02x}] {}", at.get(), unsafe {
|
||||||
|
// self.logger.display_instr(at, regs)
|
||||||
|
// });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ type Vm = hbvm::Vm<mem::Memory, TIMER_QUOTIENT>;
|
||||||
pub struct ExecThread {
|
pub struct ExecThread {
|
||||||
vm: Vm,
|
vm: Vm,
|
||||||
stack_bottom: *mut u8,
|
stack_bottom: *mut u8,
|
||||||
|
program: &'static [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for ExecThread {}
|
unsafe impl Send for ExecThread {}
|
||||||
|
@ -34,9 +35,9 @@ impl ExecThread {
|
||||||
self.vm.registers[2] = hbvm::value::Value(length);
|
self.vm.registers[2] = hbvm::value::Value(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn new(program: &[u8], entrypoint: Address) -> Self {
|
pub unsafe fn new(program: &'static [u8], entrypoint: Address) -> Self {
|
||||||
let mut vm = Vm::new(
|
let mut vm = Vm::new(
|
||||||
mem::Memory {},
|
mem::Memory::default(),
|
||||||
Address::new(program.as_ptr() as u64 + entrypoint.get()),
|
Address::new(program.as_ptr() as u64 + entrypoint.get()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -44,7 +45,11 @@ impl ExecThread {
|
||||||
|
|
||||||
vm.write_reg(254, (stack_bottom as usize + STACK_SIZE - 1) as u64);
|
vm.write_reg(254, (stack_bottom as usize + STACK_SIZE - 1) as u64);
|
||||||
|
|
||||||
ExecThread { vm, stack_bottom }
|
ExecThread {
|
||||||
|
vm,
|
||||||
|
stack_bottom,
|
||||||
|
program,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +70,12 @@ impl<'p> Future for ExecThread {
|
||||||
return Poll::Ready(Err(err));
|
return Poll::Ready(Err(err));
|
||||||
}
|
}
|
||||||
Ok(VmRunOk::End) => return Poll::Ready(Ok(())),
|
Ok(VmRunOk::End) => return Poll::Ready(Ok(())),
|
||||||
Ok(VmRunOk::Ecall) => ecah::handler(&mut self.vm),
|
Ok(VmRunOk::Ecall) => ecah::handler(
|
||||||
|
&mut self,
|
||||||
|
cx.ext()
|
||||||
|
.downcast_ref()
|
||||||
|
.expect("PID did not exist in Context"),
|
||||||
|
),
|
||||||
Ok(VmRunOk::Timer) => (),
|
Ok(VmRunOk::Timer) => (),
|
||||||
Ok(VmRunOk::Breakpoint) => {
|
Ok(VmRunOk::Breakpoint) => {
|
||||||
log::error!(
|
log::error!(
|
||||||
|
|
|
@ -19,16 +19,14 @@ use {
|
||||||
spin::{Lazy, Mutex},
|
spin::{Lazy, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
pub fn kmain(_cmdline: &str, boot_modules: BootModules<'static>) -> ! {
|
||||||
debug!("Entered kmain");
|
debug!("Entered kmain");
|
||||||
|
|
||||||
#[cfg(feature = "ktest")] {
|
#[cfg(feature = "ktest")]
|
||||||
use {
|
{
|
||||||
crate::ktest::test_main,
|
use {crate::ktest, log::info};
|
||||||
log::info,
|
|
||||||
};
|
|
||||||
info!("Running tests");
|
info!("Running tests");
|
||||||
test_main();
|
ktest::test_main();
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +76,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
||||||
"Graphics front ptr {:?}",
|
"Graphics front ptr {:?}",
|
||||||
fb1.address.as_ptr().unwrap() as *const u8
|
fb1.address.as_ptr().unwrap() as *const u8
|
||||||
);
|
);
|
||||||
|
log::info!("Started AbleOS");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let executor = LazyCell::<Executor>::force_mut(&mut EXECUTOR);
|
let executor = LazyCell::<Executor>::force_mut(&mut EXECUTOR);
|
||||||
|
@ -123,7 +122,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
||||||
if cmd_len > 0 {
|
if cmd_len > 0 {
|
||||||
thr.set_arguments(cmd.as_ptr() as u64, cmd_len);
|
thr.set_arguments(cmd.as_ptr() as u64, cmd_len);
|
||||||
}
|
}
|
||||||
executor.spawn(Box::pin(async move {
|
executor.spawn(Box::pin(async {
|
||||||
if let Err(e) = thr.await {
|
if let Err(e) = thr.await {
|
||||||
log::error!("{e:?}");
|
log::error!("{e:?}");
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,6 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
|
||||||
|
|
||||||
executor.run();
|
executor.run();
|
||||||
};
|
};
|
||||||
|
|
||||||
crate::arch::spin_loop()
|
crate::arch::spin_loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use {
|
|
||||||
alloc::string::String,
|
|
||||||
log::{info, error},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use ktest_macro::*;
|
pub use ktest_macro::*;
|
||||||
|
|
||||||
|
use {
|
||||||
|
alloc::string::String,
|
||||||
|
log::{error, info},
|
||||||
|
};
|
||||||
|
|
||||||
#[allow(improper_ctypes)]
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static __ktest_start: fn() -> Result<String, String>;
|
static __ktest_start: fn() -> Result<String, String>;
|
||||||
static __ktest_end: fn() -> Result<String, String>;
|
static __ktest_end: fn() -> Result<String, String>;
|
||||||
|
@ -21,8 +19,8 @@ pub fn test_main() {
|
||||||
let mut current_test = &__ktest_start as *const fn() -> Result<String, String>;
|
let mut current_test = &__ktest_start as *const fn() -> Result<String, String>;
|
||||||
let test_end = &__ktest_end as *const fn() -> Result<String, String>;
|
let test_end = &__ktest_end as *const fn() -> Result<String, String>;
|
||||||
|
|
||||||
let mut pass = 0;
|
let mut pass = 0;
|
||||||
let mut fail = 0;
|
let mut fail = 0;
|
||||||
|
|
||||||
while current_test < test_end {
|
while current_test < test_end {
|
||||||
let test_fn = *current_test;
|
let test_fn = *current_test;
|
||||||
|
@ -47,7 +45,7 @@ pub fn test_main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ktest]
|
#[ktest]
|
||||||
fn trivial_assertion() {
|
pub fn trivial_assertion() {
|
||||||
ktest_eq!(1, 1);
|
ktest_eq!(1, 1);
|
||||||
ktest_neq!(0, 1);
|
ktest_neq!(0, 1);
|
||||||
}
|
}
|
|
@ -10,9 +10,11 @@
|
||||||
abi_x86_interrupt,
|
abi_x86_interrupt,
|
||||||
lazy_get,
|
lazy_get,
|
||||||
alloc_error_handler,
|
alloc_error_handler,
|
||||||
|
local_waker,
|
||||||
|
context_ext,
|
||||||
ptr_sub_ptr,
|
ptr_sub_ptr,
|
||||||
naked_functions,
|
naked_functions,
|
||||||
pointer_is_aligned_to,
|
pointer_is_aligned_to
|
||||||
)]
|
)]
|
||||||
#![allow(dead_code, internal_features, static_mut_refs)]
|
#![allow(dead_code, internal_features, static_mut_refs)]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
@ -27,12 +29,14 @@ mod handle;
|
||||||
mod holeybytes;
|
mod holeybytes;
|
||||||
mod ipc;
|
mod ipc;
|
||||||
mod kmain;
|
mod kmain;
|
||||||
mod ktest;
|
|
||||||
mod logger;
|
mod logger;
|
||||||
mod memory;
|
mod memory;
|
||||||
mod task;
|
mod task;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
#[allow(improper_ctypes, non_upper_case_globals)]
|
||||||
|
mod ktest;
|
||||||
|
|
||||||
use versioning::Version;
|
use versioning::Version;
|
||||||
|
|
||||||
/// Kernel's version
|
/// Kernel's version
|
||||||
|
@ -45,8 +49,7 @@ pub const VERSION: Version = Version {
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(target_os = "none")]
|
||||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||||
use crate::alloc::string::ToString;
|
use alloc::string::ToString;
|
||||||
|
|
||||||
arch::register_dump();
|
arch::register_dump();
|
||||||
|
|
||||||
if let Some(loc) = info.location() {
|
if let Some(loc) = info.location() {
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
use {
|
use {
|
||||||
alloc::{boxed::Box, sync::Arc},
|
alloc::{
|
||||||
|
boxed::Box,
|
||||||
|
collections::{BTreeMap, BTreeSet},
|
||||||
|
sync::Arc,
|
||||||
|
},
|
||||||
core::{
|
core::{
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
|
task::{Context, ContextBuilder, Poll, RawWaker, RawWakerVTable, Waker},
|
||||||
},
|
},
|
||||||
crossbeam_queue::SegQueue,
|
crossbeam_queue::SegQueue,
|
||||||
slab::Slab,
|
slab::Slab,
|
||||||
|
@ -14,7 +19,6 @@ pub fn yield_now() -> impl Future<Output = ()> {
|
||||||
impl Future for YieldNow {
|
impl Future for YieldNow {
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
if self.0 {
|
if self.0 {
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
|
@ -29,150 +33,184 @@ pub fn yield_now() -> impl Future<Output = ()> {
|
||||||
YieldNow(false)
|
YieldNow(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Process: Future<Output = ()> + Send {}
|
||||||
|
impl<T: Future<Output = ()> + Send> Process for T {}
|
||||||
|
|
||||||
pub struct Executor {
|
pub struct Executor {
|
||||||
tasks: Slab<Task>,
|
tasks: Slab<Task>,
|
||||||
task_queue: Arc<TaskQueue>,
|
task_queue: Arc<SegQueue<usize>>,
|
||||||
|
interrupt_lookup: [Option<usize>; u8::MAX as usize],
|
||||||
|
buffer_lookup: BTreeMap<usize, BTreeSet<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Executor {
|
impl Executor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
tasks: Slab::new(),
|
tasks: Slab::new(),
|
||||||
task_queue: Arc::new(TaskQueue::new()),
|
task_queue: Arc::new(SegQueue::new()),
|
||||||
|
interrupt_lookup: [None; u8::MAX as usize],
|
||||||
|
buffer_lookup: BTreeMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
pub fn spawn(&mut self, future: Pin<Box<dyn Process>>) -> usize {
|
||||||
pub fn spawn(&mut self, future: Pin<Box<dyn Future<Output = ()> + Send>>) -> usize {
|
|
||||||
let id = self.tasks.insert(Task::new(future));
|
let id = self.tasks.insert(Task::new(future));
|
||||||
self.task_queue.queue.push(id);
|
self.task_queue.push(id);
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pause(&self, id: usize) {
|
||||||
|
if let Some(task) = self.tasks.get(id) {
|
||||||
|
task.set_paused(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unpause(&self, id: usize) {
|
||||||
|
if let Some(task) = self.tasks.get(id) {
|
||||||
|
task.set_paused(false);
|
||||||
|
self.task_queue.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) {
|
||||||
|
self.pause(pid);
|
||||||
|
self.interrupt_lookup[interrupt_type as usize] = Some(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) {
|
||||||
|
self.pause(pid);
|
||||||
|
if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) {
|
||||||
|
buf.insert(pid);
|
||||||
|
} else {
|
||||||
|
self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
let mut task_batch = [0; 32];
|
let mut task_batch = [0; 32];
|
||||||
let mut batch_len = 0;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
self.task_queue.batch_pop(&mut task_batch, &mut batch_len);
|
let mut batch_len = 0;
|
||||||
|
|
||||||
if batch_len == 0 {
|
while let Some(id) = self.task_queue.pop() {
|
||||||
if self.task_queue.is_empty() {
|
task_batch[batch_len] = id;
|
||||||
|
batch_len += 1;
|
||||||
|
if batch_len == task_batch.len() {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for &id in &task_batch[..batch_len] {
|
if batch_len == 0 {
|
||||||
if let Some(task) = self.tasks.get_mut(id) {
|
// break;
|
||||||
let waker = task
|
continue;
|
||||||
.waker
|
}
|
||||||
.get_or_insert_with(|| TaskWaker::new(id, Arc::clone(&self.task_queue)));
|
|
||||||
|
|
||||||
let waker = unsafe { Waker::from_raw(TaskWaker::into_raw_waker(waker)) };
|
for &(mut id) in &task_batch[..batch_len] {
|
||||||
let mut cx = Context::from_waker(&waker);
|
if let Some(task) = self.tasks.get_mut(id) {
|
||||||
|
if task.is_paused() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let waker = create_waker(id, Arc::clone(&self.task_queue));
|
||||||
|
let mut cx = ContextBuilder::from_waker(&waker).ext(&mut id).build();
|
||||||
|
|
||||||
if let Poll::Ready(()) = task.poll(&mut cx) {
|
if let Poll::Ready(()) = task.poll(&mut cx) {
|
||||||
self.tasks.remove(id);
|
self.tasks.remove(id);
|
||||||
self.task_queue.free_tasks.push(id);
|
self.interrupt_lookup.map(|pid| {
|
||||||
|
if let Some(pid) = pid {
|
||||||
|
if pid == id {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pid;
|
||||||
|
});
|
||||||
|
self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| {
|
||||||
|
pid_set.remove(&id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_interrupt(&self, interrupt: u8) {
|
||||||
|
let id = self.interrupt_lookup[interrupt as usize];
|
||||||
|
if let Some(id) = id {
|
||||||
|
self.unpause(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn send_buffer(&self, id: usize) {
|
||||||
|
if let Some(buf) = self.buffer_lookup.get(&id) {
|
||||||
|
buf.iter().for_each(|pid| self.unpause(*pid));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Task {
|
struct Task {
|
||||||
future: Pin<Box<dyn Future<Output = ()> + Send>>,
|
future: Pin<Box<dyn Process>>,
|
||||||
waker: Option<TaskWaker>,
|
paused: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
#[inline(always)]
|
fn new(future: Pin<Box<dyn Process>>) -> Self {
|
||||||
pub fn new(future: Pin<Box<dyn Future<Output = ()> + Send>>) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
future,
|
future,
|
||||||
waker: None,
|
paused: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn poll(&mut self, cx: &mut Context) -> Poll<()> {
|
fn poll(&mut self, cx: &mut Context) -> Poll<()> {
|
||||||
self.future.as_mut().poll(cx)
|
self.future.as_mut().poll(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_paused(&self) -> bool {
|
||||||
|
self.paused.load(Ordering::Acquire)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_paused(&self, paused: bool) {
|
||||||
|
self.paused.store(paused, Ordering::Release)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_waker(task_id: usize, task_queue: Arc<SegQueue<usize>>) -> Waker {
|
||||||
|
let data = Box::new(TaskWaker {
|
||||||
|
task_id,
|
||||||
|
task_queue,
|
||||||
|
});
|
||||||
|
let raw_waker = RawWaker::new(Box::into_raw(data) as *const (), &VTABLE);
|
||||||
|
unsafe { Waker::from_raw(raw_waker) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct TaskWaker {
|
struct TaskWaker {
|
||||||
id: usize,
|
task_id: usize,
|
||||||
task_queue: Arc<TaskQueue>,
|
task_queue: Arc<SegQueue<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskWaker {
|
impl TaskWaker {
|
||||||
#[inline(always)]
|
|
||||||
fn new(id: usize, task_queue: Arc<TaskQueue>) -> Self {
|
|
||||||
Self { id, task_queue }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn wake(&self) {
|
fn wake(&self) {
|
||||||
self.task_queue.queue.push(self.id);
|
self.task_queue.push(self.task_id);
|
||||||
}
|
|
||||||
|
|
||||||
fn into_raw_waker(waker: &TaskWaker) -> RawWaker {
|
|
||||||
let ptr = waker as *const TaskWaker;
|
|
||||||
RawWaker::new(ptr.cast(), &VTABLE)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const VTABLE: RawWakerVTable = RawWakerVTable::new(clone_raw, wake_raw, wake_by_ref_raw, drop_raw);
|
const VTABLE: RawWakerVTable = RawWakerVTable::new(clone_raw, wake_raw, wake_by_ref_raw, drop_raw);
|
||||||
|
|
||||||
unsafe fn clone_raw(ptr: *const ()) -> RawWaker {
|
unsafe fn clone_raw(ptr: *const ()) -> RawWaker {
|
||||||
let waker = &*(ptr as *const TaskWaker);
|
let task_waker = Box::from_raw(ptr as *mut TaskWaker);
|
||||||
TaskWaker::into_raw_waker(waker)
|
let raw_waker = RawWaker::new(Box::into_raw(task_waker.clone()) as *const (), &VTABLE);
|
||||||
|
raw_waker
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn wake_raw(ptr: *const ()) {
|
unsafe fn wake_raw(ptr: *const ()) {
|
||||||
let waker = &*(ptr as *const TaskWaker);
|
let task_waker = Box::from_raw(ptr as *mut TaskWaker);
|
||||||
waker.wake();
|
task_waker.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn wake_by_ref_raw(ptr: *const ()) {
|
unsafe fn wake_by_ref_raw(ptr: *const ()) {
|
||||||
let waker = &*(ptr as *const TaskWaker);
|
let task_waker = &*(ptr as *const TaskWaker);
|
||||||
waker.wake();
|
task_waker.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn drop_raw(_: *const ()) {}
|
unsafe fn drop_raw(ptr: *const ()) {
|
||||||
|
drop(Box::from_raw(ptr as *mut TaskWaker));
|
||||||
struct TaskQueue {
|
|
||||||
queue: SegQueue<usize>,
|
|
||||||
next_task: usize,
|
|
||||||
free_tasks: SegQueue<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TaskQueue {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
queue: SegQueue::new(),
|
|
||||||
next_task: 0,
|
|
||||||
free_tasks: SegQueue::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn batch_pop(&self, output: &mut [usize], len: &mut usize) {
|
|
||||||
*len = 0;
|
|
||||||
while let Some(id) = self.queue.pop() {
|
|
||||||
output[*len] = id;
|
|
||||||
*len += 1;
|
|
||||||
if *len == output.len() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn is_empty(&self) -> bool {
|
|
||||||
self.queue.is_empty()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
{
|
{
|
||||||
"arch": "aarch64",
|
"arch": "aarch64",
|
||||||
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
||||||
"disable-redzone": true,
|
"disable-redzone": true,
|
||||||
"env": "",
|
"env": "",
|
||||||
"executables": true,
|
"executables": true,
|
||||||
"features": "+strict-align,+neon,+fp-armv8",
|
"features": "+strict-align,+neon,+fp-armv8",
|
||||||
"linker": "rust-lld",
|
"linker": "rust-lld",
|
||||||
"linker-flavor": "ld.lld",
|
"linker-flavor": "ld.lld",
|
||||||
"linker-is-gnu": true,
|
"linker-is-gnu": true,
|
||||||
"pre-link-args": {
|
"pre-link-args": {
|
||||||
"ld.lld": [
|
"ld.lld": [
|
||||||
"-Tkernel/lds/aarch64-qemu.ld"
|
"-Tkernel/lds/aarch64-qemu.ld"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"llvm-target": "aarch64-unknown-none",
|
"llvm-target": "aarch64-unknown-none",
|
||||||
"max-atomic-width": 128,
|
"max-atomic-width": 128,
|
||||||
"os": "none",
|
"os": "none",
|
||||||
"panic-strategy": "abort",
|
"panic-strategy": "abort",
|
||||||
"relocation-model": "static",
|
"relocation-model": "static",
|
||||||
"target-c-int-width": "32",
|
"target-c-int-width": "32",
|
||||||
"target-endian": "little",
|
"target-endian": "little",
|
||||||
"target-pointer-width": "64",
|
"target-pointer-width": "64",
|
||||||
"vendor": ""
|
"vendor": "ablecorp"
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ fatfs = { version = "0.3", default-features = false, features = [
|
||||||
] }
|
] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
hblang.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git"
|
hblang.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git"
|
||||||
|
# hblang.path = "../../holey-bytes/lang/"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
raw-cpuid = "11"
|
raw-cpuid = "11"
|
||||||
ureq = { version = "2", default-features = false, features = ["tls"] }
|
ureq = { version = "2", default-features = false, features = ["tls"] }
|
||||||
|
|
|
@ -83,7 +83,8 @@ impl Package {
|
||||||
&path,
|
&path,
|
||||||
Options {
|
Options {
|
||||||
fmt: true,
|
fmt: true,
|
||||||
in_house_regalloc: true,
|
resolver: Some(hblang::ABLEOS_PATH_RESOLVER),
|
||||||
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
out,
|
out,
|
||||||
|
@ -99,7 +100,7 @@ impl Package {
|
||||||
hblang::run_compiler(
|
hblang::run_compiler(
|
||||||
&path,
|
&path,
|
||||||
Options {
|
Options {
|
||||||
in_house_regalloc: true,
|
resolver: Some(hblang::ABLEOS_PATH_RESOLVER),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
out,
|
out,
|
||||||
|
@ -108,18 +109,20 @@ impl Package {
|
||||||
std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?;
|
std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?;
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
hblang::run_compiler(
|
let err = hblang::run_compiler(
|
||||||
&path,
|
&path,
|
||||||
Options {
|
Options {
|
||||||
|
resolver: Some(hblang::ABLEOS_PATH_RESOLVER),
|
||||||
dump_asm: true,
|
dump_asm: true,
|
||||||
in_house_regalloc: true,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
out,
|
out,
|
||||||
&mut warnings,
|
&mut warnings,
|
||||||
)?;
|
);
|
||||||
std::fs::write(format!("target/programs/{}.hba", self.name), &out)?;
|
std::fs::write(format!("target/programs/{}.hba", self.name), &out)?;
|
||||||
out.clear();
|
out.clear();
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,10 +253,10 @@ TERM_BACKDROP={}
|
||||||
);
|
);
|
||||||
match p.build(&mut out) {
|
match p.build(&mut out) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => {
|
Err(e) => {
|
||||||
writeln!(errors, "========= while compiling {} =========", path)
|
writeln!(errors, "========= while compiling {} {} =========", path, e)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
errors.push_str(core::str::from_utf8(&out).expect("no"));
|
errors.push_str(&String::from_utf8_lossy(&out));
|
||||||
out.clear();
|
out.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,6 +411,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
};
|
};
|
||||||
let (mut com, mut com2) = (Command::new(target_str), Command::new(target_str));
|
let (mut com, mut com2) = (Command::new(target_str), Command::new(target_str));
|
||||||
let ovmf_path = fetch_ovmf(target);
|
let ovmf_path = fetch_ovmf(target);
|
||||||
|
let mut cpu = "max";
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
let accel = if do_accel {
|
let accel = if do_accel {
|
||||||
let supported = String::from_utf8(
|
let supported = String::from_utf8(
|
||||||
|
@ -440,7 +441,8 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
{
|
{
|
||||||
"accel=hax"
|
"accel=hax"
|
||||||
} else if supported.contains("whpx") {
|
} else if supported.contains("whpx") {
|
||||||
"accel=whpx"
|
cpu = "Westmere";
|
||||||
|
"accel=whpx,kernel-irqchip=off"
|
||||||
} else {
|
} else {
|
||||||
"accel=tcg"
|
"accel=tcg"
|
||||||
}
|
}
|
||||||
|
@ -455,7 +457,8 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
com.args([
|
com.args([
|
||||||
"-bios", &ovmf_path.change_context(Error::OvmfFetch)?,
|
"-bios", &ovmf_path.change_context(Error::OvmfFetch)?,
|
||||||
"-drive", "file=target/disk.img,format=raw",
|
//"-hda", "target/disk.img",
|
||||||
|
"-drive", "file=target/disk.img,index=0,if=ide,format=raw",
|
||||||
"-device", "vmware-svga",
|
"-device", "vmware-svga",
|
||||||
// "-serial", "stdio",
|
// "-serial", "stdio",
|
||||||
"-m", "2G",
|
"-m", "2G",
|
||||||
|
@ -463,7 +466,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
"-parallel", "none",
|
"-parallel", "none",
|
||||||
"-monitor", "none",
|
"-monitor", "none",
|
||||||
"-machine", accel,
|
"-machine", accel,
|
||||||
"-cpu", "max",
|
"-cpu", cpu,
|
||||||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04",
|
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -485,7 +488,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
com.args([
|
com.args([
|
||||||
"-M", "virt",
|
"-M", "virt",
|
||||||
"-cpu", "neoverse-n2",
|
"-cpu", "max",
|
||||||
"-device", "ramfb",
|
"-device", "ramfb",
|
||||||
"-device", "qemu-xhci",
|
"-device", "qemu-xhci",
|
||||||
"-device", "usb-kbd",
|
"-device", "usb-kbd",
|
||||||
|
@ -506,7 +509,6 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn fetch_ovmf(target: Target) -> Result<String, OvmfFetchError> {
|
fn fetch_ovmf(target: Target) -> Result<String, OvmfFetchError> {
|
||||||
let (ovmf_url, ovmf_path) = match target {
|
let (ovmf_url, ovmf_path) = match target {
|
||||||
Target::X86_64 | Target::X86_64Avx2 => (
|
Target::X86_64 | Target::X86_64Avx2 => (
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
# old toolchain
|
# old toolchain
|
||||||
# channel = "nightly-2024-07-27"
|
# channel = "nightly-2024-07-27"
|
||||||
channel = "nightly-2024-11-20"
|
# last stable
|
||||||
|
# channel = "nightly-2024-11-20"
|
||||||
|
# locking here to prevent compile error in holey-bytes crate
|
||||||
|
channel = "nightly-2025-01-25"
|
||||||
components = ["rust-src", "llvm-tools"]
|
components = ["rust-src", "llvm-tools"]
|
||||||
|
|
2
sysdata/libraries/clippy/README.md
Normal file
2
sysdata/libraries/clippy/README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# clippy
|
||||||
|
Uhm maybe change the name haha
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "processes"
|
name = "clippy"
|
||||||
authors = ["koniifer"]
|
authors = [""]
|
||||||
|
|
||||||
[dependants.libraries]
|
[dependants.libraries]
|
||||||
|
|
63
sysdata/libraries/clippy/src/lib.hb
Normal file
63
sysdata/libraries/clippy/src/lib.hb
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
TagType := enum {
|
||||||
|
Binary,
|
||||||
|
// Text is in UTF8 format.
|
||||||
|
Text,
|
||||||
|
// Images are in QOI format
|
||||||
|
Image,
|
||||||
|
// A path to a file or folder on disk. In the format of FileID.
|
||||||
|
Path,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transdimensionally located here to make following code easier
|
||||||
|
FileID := struct {
|
||||||
|
host_id: HostID,
|
||||||
|
id: ID,
|
||||||
|
}
|
||||||
|
|
||||||
|
Note := struct {
|
||||||
|
tag: TagType,
|
||||||
|
data_length: uint,
|
||||||
|
data: ^u8,
|
||||||
|
next_note: ^Note,
|
||||||
|
last_note: ^Note,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Clipboard = struct {
|
||||||
|
current_note_count: u8,
|
||||||
|
// Maybe max it at like 5.
|
||||||
|
total_note_count: u8,
|
||||||
|
start_notes: ^Note,
|
||||||
|
// Does it even make sense to have this?
|
||||||
|
end_notes: ^Note,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Ctrl + Up arrow moves the clip board forward
|
||||||
|
flip_board_forward = fn(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl + arrow moves the clip board backward
|
||||||
|
flip_board_backward = fn(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Ctrl + V soft paste. Pastes text without removing it from your clipboard.
|
||||||
|
soft_paste = fn(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Ctrl + Shift + V hard paste. Pastes text removing it from your clipboard.
|
||||||
|
hard_paste = fn(): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl + C copy. Copies text into the clipboard on a new page. Filling a blank one or pushing the oldest page out.
|
||||||
|
copy = fn(): void {}
|
||||||
|
|
||||||
|
|
||||||
|
// Ctrl + X Cut. Cuts text into the clipboard on a new page. Filling a blank one or pushing the oldest page out.
|
||||||
|
cut = fn(): void {}
|
|
@ -9,39 +9,33 @@ widgets := @use("widgets/widgets.hb")
|
||||||
ui := @use("ui.hb")
|
ui := @use("ui.hb")
|
||||||
|
|
||||||
WindowID := struct {
|
WindowID := struct {
|
||||||
host_id: int,
|
host_id: uint,
|
||||||
window_id: int,
|
window_id: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
VoidWindowID := WindowID.(0, 0)
|
VoidWindowID := WindowID.(0, 0)
|
||||||
|
|
||||||
create_window := fn(channel: int): ^render.Surface {
|
create_window := fn(channel: uint): ^render.Surface {
|
||||||
// get the horizon buffer
|
// get the horizon buffer
|
||||||
// request a new window and provide the callback buffer
|
// request a new window and provide the callback buffer
|
||||||
// wait to recieve a message
|
// wait to recieve a message
|
||||||
|
|
||||||
windowing_system_buffer := buffer.search("XHorizon\0")
|
windowing_system_buffer := buffer.search("XHorizon")
|
||||||
mem_buf := memory.request_page(1)
|
mem_buf := memory.request_page(1, false)
|
||||||
|
|
||||||
if windowing_system_buffer == 0 {
|
if windowing_system_buffer == 0 {
|
||||||
return @as(^render.Surface, idk)
|
return @as(^render.Surface, idk)
|
||||||
} else {
|
} else {
|
||||||
// ! bad able, stop using string messages :ragey:
|
|
||||||
// msg := "\{01}\0"
|
|
||||||
// msg_length := 2
|
|
||||||
|
|
||||||
// @as(void, @eca(3, windowing_system_buffer, msg, msg_length))
|
|
||||||
|
|
||||||
x := 0
|
x := 0
|
||||||
loop if x > 1000 break else x += 1
|
loop if x > 1000 break else x += 1
|
||||||
|
|
||||||
ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf)
|
ret := buffer.recv([4096]u8, windowing_system_buffer, mem_buf)
|
||||||
if ret == null {
|
if ret == null {
|
||||||
log.info("No messages\0")
|
log.info("No messages")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *mem_buf == 0 {
|
if *mem_buf == 0 {
|
||||||
log.info("No messages\0")
|
log.info("No messages")
|
||||||
}
|
}
|
||||||
|
|
||||||
return @as(^render.Surface, idk)
|
return @as(^render.Surface, idk)
|
||||||
|
|
|
@ -6,7 +6,7 @@ render := @use("../../../libraries/render/src/lib.hb");
|
||||||
.{Surface} := render;
|
.{Surface} := render;
|
||||||
.{Font} := render.text
|
.{Font} := render.text
|
||||||
|
|
||||||
UI := struct {raw: ^u8, raw_length: uint, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte
|
UI := struct {raw: []u8, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte
|
||||||
// children: ^^u8,
|
// children: ^^u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,29 +19,26 @@ render_ui := fn(surface: Surface, ui: UI): void {
|
||||||
render.put_surface(surface, ui.surface, pos, false)
|
render.put_surface(surface, ui.surface, pos, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
sexpr_parser := fn(sexpr: ^u8): UI {
|
sexpr_parser := fn(sexpr: []u8): UI {
|
||||||
cursor := sexpr
|
i := 0
|
||||||
paren_balance := 0
|
paren_balance := 0
|
||||||
loop {
|
loop {
|
||||||
if *cursor == 0 {
|
if i == sexpr.len {
|
||||||
if paren_balance != 0 {
|
if paren_balance != 0 {
|
||||||
log.error("Unbalanced Parens\0")
|
log.error("Unbalanced Parens")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else if *cursor == 40 {
|
} else if sexpr[i] == '(' {
|
||||||
log.info("Open paren\0")
|
log.info("Open paren")
|
||||||
paren_balance += 1
|
paren_balance += 1
|
||||||
} else if *cursor == 41 {
|
} else if sexpr[i] == ')' {
|
||||||
log.info("Closed paren\0")
|
log.info("Closed paren")
|
||||||
paren_balance -= 1
|
paren_balance -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor += 1
|
i += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
length := string.length(sexpr)
|
|
||||||
|
|
||||||
ui_surface := render.new_surface(100, 100)
|
ui_surface := render.new_surface(100, 100)
|
||||||
|
return UI.(sexpr, true, ui_surface)
|
||||||
return UI.(sexpr, length, true, ui_surface)
|
|
||||||
}
|
}
|
|
@ -10,37 +10,32 @@ Label := struct {
|
||||||
magic: uint,
|
magic: uint,
|
||||||
is_dirty: bool,
|
is_dirty: bool,
|
||||||
surface: Surface,
|
surface: Surface,
|
||||||
text: ^u8,
|
text: []u8,
|
||||||
text_length: uint,
|
|
||||||
bg: Color,
|
bg: Color,
|
||||||
fg: Color,
|
fg: Color,
|
||||||
}
|
|
||||||
|
|
||||||
set_label_text := fn(label: Label, text: ^u8): void {
|
new_label := fn(text: []u8, width: uint): Self {
|
||||||
text_length := string.length(text)
|
text_surface := render.Surface.new(width, 20)
|
||||||
|
label := Self.(3, true, text_surface, text, render.BLACK, render.WHITE)
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
|
||||||
label.is_dirty = true
|
$set_label_text := fn(self: ^Self, text: []u8): void {
|
||||||
label.text = text
|
self.is_dirty = true
|
||||||
label.text_length = text_length
|
self.text = text
|
||||||
|
}
|
||||||
|
|
||||||
|
$set_color := fn(self: ^Self, bg: Color, fg: Color): void {
|
||||||
|
self.bg = bg
|
||||||
|
self.fg = fg
|
||||||
|
self.is_dirty = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
||||||
if label.is_dirty {
|
if label.is_dirty {
|
||||||
render.clear(label.surface, label.bg)
|
label.surface.clear(label.bg)
|
||||||
render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
|
label.surface.put_text(font, .(0, 0), label.fg, label.text)
|
||||||
}
|
}
|
||||||
render.put_surface(surface, label.surface, pos, false)
|
surface.put_surface(label.surface, pos, false)
|
||||||
}
|
|
||||||
|
|
||||||
new_label := fn(text: ^u8): Label {
|
|
||||||
text_surface := render.new_surface(1024, 20)
|
|
||||||
text_length := string.length(text)
|
|
||||||
label := Label.(3, true, text_surface, text, text_length, render.black, render.white)
|
|
||||||
return label
|
|
||||||
}
|
|
||||||
|
|
||||||
$set_color := fn(label: Label, bg: Color, fg: Color): void {
|
|
||||||
label.bg = bg
|
|
||||||
label.fg = fg
|
|
||||||
label.is_dirty = true
|
|
||||||
}
|
}
|
|
@ -2,17 +2,17 @@ keycodes := @use("keycodes.hb");
|
||||||
.{KeyCode} := keycodes
|
.{KeyCode} := keycodes
|
||||||
|
|
||||||
KeyEvent := packed struct {
|
KeyEvent := packed struct {
|
||||||
up: bool,
|
up: bool = false,
|
||||||
just_triggered: bool,
|
just_triggered: bool = false,
|
||||||
key: KeyCode,
|
key: KeyCode = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseEvent := packed struct {
|
MouseEvent := packed struct {
|
||||||
x_change: i8,
|
x_change: i8 = 0,
|
||||||
y_change: i8,
|
y_change: i8 = 0,
|
||||||
left: bool,
|
left: bool = false,
|
||||||
middle: bool,
|
middle: bool = false,
|
||||||
right: bool,
|
right: bool = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
GamepadEvent := struct {}
|
GamepadEvent := struct {}
|
|
@ -7,115 +7,89 @@ I am now modelling it as I see fit. This is likely not the final version.
|
||||||
|
|
||||||
KeyCode := u32
|
KeyCode := u32
|
||||||
|
|
||||||
// Typically this is not a keycode you will ever recieve.
|
$NONE: KeyCode = 0
|
||||||
None := KeyCode.(0)
|
$ESCAPE: KeyCode = 1
|
||||||
|
$A: KeyCode = 2
|
||||||
Escape := KeyCode.(1)
|
$B: KeyCode = 3
|
||||||
/* Alphabet keycodes */
|
$C: KeyCode = 4
|
||||||
|
$D: KeyCode = 5
|
||||||
A := KeyCode.(2)
|
$E: KeyCode = 6
|
||||||
B := KeyCode.(3)
|
$F: KeyCode = 7
|
||||||
C := KeyCode.(4)
|
$G: KeyCode = 8
|
||||||
D := KeyCode.(5)
|
$H: KeyCode = 9
|
||||||
E := KeyCode.(6)
|
$I: KeyCode = 10
|
||||||
F := KeyCode.(7)
|
$J: KeyCode = 11
|
||||||
G := KeyCode.(8)
|
$K: KeyCode = 12
|
||||||
H := KeyCode.(9)
|
$L: KeyCode = 13
|
||||||
I := KeyCode.(10)
|
$M: KeyCode = 14
|
||||||
J := KeyCode.(11)
|
$N: KeyCode = 15
|
||||||
K := KeyCode.(12)
|
$O: KeyCode = 16
|
||||||
L := KeyCode.(13)
|
$P: KeyCode = 17
|
||||||
M := KeyCode.(14)
|
$Q: KeyCode = 18
|
||||||
N := KeyCode.(15)
|
$R: KeyCode = 19
|
||||||
O := KeyCode.(16)
|
$S: KeyCode = 20
|
||||||
P := KeyCode.(17)
|
$T: KeyCode = 21
|
||||||
Q := KeyCode.(18)
|
$U: KeyCode = 22
|
||||||
R := KeyCode.(19)
|
$V: KeyCode = 23
|
||||||
S := KeyCode.(20)
|
$W: KeyCode = 24
|
||||||
T := KeyCode.(21)
|
$X: KeyCode = 25
|
||||||
U := KeyCode.(22)
|
$Y: KeyCode = 26
|
||||||
V := KeyCode.(23)
|
$Z: KeyCode = 27
|
||||||
W := KeyCode.(24)
|
$NUMBER0: KeyCode = 28
|
||||||
X := KeyCode.(25)
|
$NUMBER1: KeyCode = 29
|
||||||
Y := KeyCode.(26)
|
$NUMBER2: KeyCode = 30
|
||||||
Z := KeyCode.(27)
|
$NUMBER3: KeyCode = 31
|
||||||
|
$NUMBER4: KeyCode = 32
|
||||||
/* Numeric keycodes*/
|
$NUMBER5: KeyCode = 33
|
||||||
|
$NUMBER6: KeyCode = 34
|
||||||
Number0 := KeyCode.(28)
|
$NUMBER7: KeyCode = 35
|
||||||
Number1 := KeyCode.(29)
|
$NUMBER8: KeyCode = 36
|
||||||
Number2 := KeyCode.(30)
|
$NUMBER9: KeyCode = 37
|
||||||
Number3 := KeyCode.(31)
|
$KEYPADNUMBER0: KeyCode = 38
|
||||||
Number4 := KeyCode.(32)
|
$KEYPADNUMBER1: KeyCode = 39
|
||||||
Number5 := KeyCode.(33)
|
$KEYPADNUMBER2: KeyCode = 40
|
||||||
Number6 := KeyCode.(34)
|
$KEYPADNUMBER3: KeyCode = 41
|
||||||
Number7 := KeyCode.(35)
|
$KEYPADNUMBER4: KeyCode = 42
|
||||||
Number8 := KeyCode.(36)
|
$KEYPADNUMBER5: KeyCode = 43
|
||||||
Number9 := KeyCode.(37)
|
$KEYPADNUMBER6: KeyCode = 44
|
||||||
|
$KEYPADNUMBER7: KeyCode = 45
|
||||||
KeypadNumber0 := KeyCode.(38)
|
$KEYPADNUMBER8: KeyCode = 46
|
||||||
KeypadNumber1 := KeyCode.(39)
|
$KEYPADNUMBER9: KeyCode = 47
|
||||||
KeypadNumber2 := KeyCode.(40)
|
$KEYPADPERIOD: KeyCode = 48
|
||||||
KeypadNumber3 := KeyCode.(41)
|
$KEYPADDIVIDE: KeyCode = 49
|
||||||
KeypadNumber4 := KeyCode.(42)
|
$KEYPADMULTIPLY: KeyCode = 50
|
||||||
KeypadNumber5 := KeyCode.(43)
|
$KEYPADMINUS: KeyCode = 51
|
||||||
KeypadNumber6 := KeyCode.(44)
|
$KEYPADPLUS: KeyCode = 52
|
||||||
KeypadNumber7 := KeyCode.(45)
|
$KEYPADENTER: KeyCode = 53
|
||||||
KeypadNumber8 := KeyCode.(46)
|
$KEYPADEQUALS: KeyCode = 54
|
||||||
KeypadNumber9 := KeyCode.(47)
|
$DELETE: KeyCode = 55
|
||||||
|
$NUMLOCK: KeyCode = 56
|
||||||
KeypadPeriod := KeyCode.(48)
|
$CAPSLOCK: KeyCode = 57
|
||||||
KeypadDivide := KeyCode.(49)
|
$SCROLLLOCK: KeyCode = 58
|
||||||
KeypadMultiply := KeyCode.(50)
|
$MODE: KeyCode = 59
|
||||||
KeypadMinus := KeyCode.(51)
|
$COMPOSE: KeyCode = 60
|
||||||
KeypadPlus := KeyCode.(52)
|
$LEFTALT: KeyCode = 61
|
||||||
KeypadEnter := KeyCode.(53)
|
$LEFTCONTROL: KeyCode = 62
|
||||||
KeypadEquals := KeyCode.(54)
|
$LEFTMETA: KeyCode = 63
|
||||||
|
$LEFTSHIFT: KeyCode = 64
|
||||||
Delete := KeyCode.(55)
|
$LEFTSUPER: KeyCode = 65
|
||||||
/* Locking Keys */
|
$RIGHTALT: KeyCode = 66
|
||||||
NumLock := KeyCode.(56)
|
$RIGHTCONTROL: KeyCode = 67
|
||||||
CapsLock := KeyCode.(57)
|
$RIGHTMETA: KeyCode = 68
|
||||||
ScrollLock := KeyCode.(58)
|
$RIGHTSHIFT: KeyCode = 69
|
||||||
|
$RIGHTSUPER: KeyCode = 70
|
||||||
/* "Alt Gr" key */
|
$ANYNUMBER0: KeyCode = 71
|
||||||
Mode := KeyCode.(59)
|
$ANYNUMBER1: KeyCode = 72
|
||||||
|
$ANYNUMBER2: KeyCode = 73
|
||||||
/* Multi-key compose key */
|
$ANYNUMBER3: KeyCode = 74
|
||||||
Compose := KeyCode.(60)
|
$ANYNUMBER4: KeyCode = 75
|
||||||
|
$ANYNUMBER5: KeyCode = 76
|
||||||
LeftAlt := KeyCode.(61)
|
$ANYNUMBER6: KeyCode = 77
|
||||||
LeftControl := KeyCode.(62)
|
$ANYNUMBER7: KeyCode = 78
|
||||||
LeftMeta := KeyCode.(63)
|
$ANYNUMBER8: KeyCode = 79
|
||||||
LeftShift := KeyCode.(64)
|
$ANYNUMBER9: KeyCode = 80
|
||||||
/* Left "Windows" key */
|
$ANYALT: KeyCode = 81
|
||||||
LeftSuper := KeyCode.(65)
|
$ANYCONTROL: KeyCode = 82
|
||||||
|
$ANYMETA: KeyCode = 83
|
||||||
RightAlt := KeyCode.(66)
|
$ANYSHIFT: KeyCode = 84
|
||||||
RightControl := KeyCode.(67)
|
$ANYSUPER: KeyCode = 85
|
||||||
RightMeta := KeyCode.(68)
|
|
||||||
RightShift := KeyCode.(69)
|
|
||||||
/* Right "Windows" key */
|
|
||||||
RightSuper := KeyCode.(70)
|
|
||||||
|
|
||||||
/*
|
|
||||||
This block of any triggers on any press of any of the keys.
|
|
||||||
Typically this is the event to care about.
|
|
||||||
*/
|
|
||||||
AnyNumber0 := KeyCode.(71)
|
|
||||||
AnyNumber1 := KeyCode.(72)
|
|
||||||
AnyNumber2 := KeyCode.(73)
|
|
||||||
AnyNumber3 := KeyCode.(74)
|
|
||||||
AnyNumber4 := KeyCode.(75)
|
|
||||||
AnyNumber5 := KeyCode.(76)
|
|
||||||
AnyNumber6 := KeyCode.(77)
|
|
||||||
AnyNumber7 := KeyCode.(78)
|
|
||||||
AnyNumber8 := KeyCode.(79)
|
|
||||||
AnyNumber9 := KeyCode.(80)
|
|
||||||
|
|
||||||
AnyAlt := KeyCode.(81)
|
|
||||||
AnyControl := KeyCode.(82)
|
|
||||||
AnyMeta := KeyCode.(83)
|
|
||||||
AnyShift := KeyCode.(84)
|
|
||||||
/* Any "Windows" key */
|
|
||||||
AnySuper := KeyCode.(85)
|
|
|
@ -1,19 +1,25 @@
|
||||||
stn := @use("../../stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{log, buffer, memory} := stn
|
.{log, buffer, memory} := stn
|
||||||
keycodes := @use("keycodes.hb")
|
keycodes := @use("keycodes.hb")
|
||||||
|
|
||||||
events := @use("events.hb");
|
events := @use("events.hb");
|
||||||
.{KeyEvent, MouseEvent} := events
|
.{KeyEvent, MouseEvent} := events
|
||||||
|
|
||||||
recieve_key_event := fn(): ?KeyEvent {
|
key_buf := 0
|
||||||
kevent := KeyEvent.(false, false, 0)
|
mouse_buf := 0
|
||||||
|
|
||||||
buf_id := buffer.search("PS/2 Keyboard\0")
|
recieve_key_event := fn(): ?KeyEvent {
|
||||||
|
kevent := KeyEvent.{}
|
||||||
|
|
||||||
|
if key_buf == 0 {
|
||||||
|
key_buf = buffer.search("PS/2 Keyboard")
|
||||||
|
if key_buf == 0 return null
|
||||||
|
}
|
||||||
|
|
||||||
// Read out of the Keyboard buffer here
|
// Read out of the Keyboard buffer here
|
||||||
buffer.recv(KeyEvent, buf_id, &kevent)
|
buffer.recv(KeyEvent, key_buf, &kevent)
|
||||||
|
|
||||||
if kevent.just_triggered {
|
if kevent != .{} {
|
||||||
return kevent
|
return kevent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +27,17 @@ recieve_key_event := fn(): ?KeyEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
recieve_mouse_event := fn(): ?MouseEvent {
|
recieve_mouse_event := fn(): ?MouseEvent {
|
||||||
mevent := MouseEvent.(0, 0, false, false, false)
|
mevent := MouseEvent.{}
|
||||||
|
|
||||||
buf_id := buffer.search("PS/2 Mouse\0")
|
if mouse_buf == 0 {
|
||||||
|
mouse_buf = buffer.search("PS/2 Mouse")
|
||||||
|
if mouse_buf == 0 return null
|
||||||
|
}
|
||||||
|
|
||||||
// Read out of the Mouse buffer here
|
// Read out of the Mouse buffer here
|
||||||
buffer.recv(MouseEvent, buf_id, &mevent)
|
buffer.recv(MouseEvent, mouse_buf, &mevent)
|
||||||
|
|
||||||
if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right {
|
if mevent != .{} {
|
||||||
return mevent
|
return mevent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.{string, memory, buffer, log} := @use("../../stn/src/lib.hb")
|
.{string, memory, buffer, log} := @use("stn")
|
||||||
|
|
||||||
PCIAddress := struct {
|
PCIAddress := struct {
|
||||||
bus: u8,
|
bus: u8,
|
||||||
|
@ -51,9 +51,9 @@ check_device := fn(bus: u8, device: u8): PciDeviceInfo {
|
||||||
pci_id := get_ids(bus, device, 0)
|
pci_id := get_ids(bus, device, 0)
|
||||||
|
|
||||||
if pci_id.vendor == 0xFFFF {
|
if pci_id.vendor == 0xFFFF {
|
||||||
log.warn(":|\0")
|
log.warn(":|")
|
||||||
} else {
|
} else {
|
||||||
log.info(":)\0")
|
log.info(":)")
|
||||||
}
|
}
|
||||||
address := calculate_address(bus, device, 0, 0x8)
|
address := calculate_address(bus, device, 0, 0x8)
|
||||||
reg2 := config_read32(bus, device, 0, 0x8)
|
reg2 := config_read32(bus, device, 0, 0x8)
|
||||||
|
|
|
@ -4,6 +4,3 @@ Rendering interface for SVGA and Software renderers
|
||||||
|
|
||||||
- SVGA Driver
|
- SVGA Driver
|
||||||
- needs pci driver
|
- needs pci driver
|
||||||
- needs init (requiring program)
|
|
||||||
- Double Buffer mode for Software renderer
|
|
||||||
- needs init (requiring program)
|
|
|
@ -1,5 +1,5 @@
|
||||||
.{Color, Surface, new_surface, put_surface} := @use("../lib.hb");
|
.{Color, Surface, new_surface, put_surface} := @use("lib:render");
|
||||||
.{log} := @use("../../../stn/src/lib.hb")
|
.{log} := @use("stn")
|
||||||
|
|
||||||
BitmapFileHeader := packed struct {
|
BitmapFileHeader := packed struct {
|
||||||
magic: u16,
|
magic: u16,
|
||||||
|
@ -37,13 +37,13 @@ from := fn(bmp: ^u8): ?Surface {
|
||||||
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
|
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
|
||||||
|
|
||||||
if file_header.magic != 0x4D42 | info_header.width == 0 | info_header.height == 0 {
|
if file_header.magic != 0x4D42 | info_header.width == 0 | info_header.height == 0 {
|
||||||
log.error("Invalid BMP image.\0")
|
log.error("Invalid BMP image.")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height, info_header.width * info_header.height)
|
lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height, info_header.width * info_header.height)
|
||||||
rhs := new_surface(info_header.width, info_header.height)
|
rhs := Surface.new(info_header.width, info_header.height)
|
||||||
put_surface(rhs, lhs, .(0, 0), true)
|
rhs.put_surface(lhs, .(0, 0), true)
|
||||||
|
|
||||||
return rhs
|
return rhs
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
.{log} := @use("../../../stn/src/lib.hb");
|
.{log} := @use("stn");
|
||||||
.{Surface} := @use("../lib.hb")
|
.{Surface} := @use("lib:render")
|
||||||
bmp := @use("bmp.hb")
|
bmp := @use("bmp.hb")
|
||||||
qoi := @use("qoi.hb")
|
qoi := @use("qoi.hb")
|
||||||
$BMP := 0x4D42
|
$BMP := 0x4D42
|
||||||
|
@ -19,7 +19,7 @@ from := fn(file: ^u8): ?Surface {
|
||||||
format := get_format(file)
|
format := get_format(file)
|
||||||
|
|
||||||
if format == null {
|
if format == null {
|
||||||
log.error("Could not detect image format.\0")
|
log.error("Could not detect image format.")
|
||||||
return null
|
return null
|
||||||
} else if format == BMP {
|
} else if format == BMP {
|
||||||
return bmp.from(file)
|
return bmp.from(file)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
.{Color, Surface, new_surface} := @use("../lib.hb");
|
.{Color, Surface, new_surface} := @use("lib:render");
|
||||||
.{log} := @use("../../../stn/src/lib.hb")
|
.{log} := @use("stn")
|
||||||
|
|
||||||
/* source:
|
/* source:
|
||||||
https://github.com/phoboslab/qoi/blob/master/qoi.h */
|
https://github.com/phoboslab/qoi/blob/master/qoi.h */
|
||||||
|
@ -40,12 +40,12 @@ from := fn(qoi: ^u8): ?Surface {
|
||||||
height := be_to_le(header.height)
|
height := be_to_le(header.height)
|
||||||
|
|
||||||
if be_to_le(header.magic) != QOI_MAGIC | width == 0 | height == 0 | header.channels < 3 | header.channels > 4 {
|
if be_to_le(header.magic) != QOI_MAGIC | width == 0 | height == 0 | header.channels < 3 | header.channels > 4 {
|
||||||
log.error("Invalid QOI image.\0")
|
log.error("Invalid QOI image.")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
surface := new_surface(width, height)
|
surface := Surface.new(width, height)
|
||||||
index := @as([Color; 64], idk)
|
index := @as([64]Color, idk)
|
||||||
|
|
||||||
run := 0
|
run := 0
|
||||||
px := Color.(0, 0, 0, 255)
|
px := Color.(0, 0, 0, 255)
|
||||||
|
|
|
@ -6,52 +6,23 @@ text := @use("text.hb")
|
||||||
mode := software
|
mode := software
|
||||||
|
|
||||||
init := mode.init
|
init := mode.init
|
||||||
doublebuffer := mode.doublebuffer
|
|
||||||
Surface := mode.Surface
|
Surface := mode.Surface
|
||||||
new_surface := mode.new_surface
|
|
||||||
surface_from_ptr := mode.surface_from_ptr
|
|
||||||
clone_surface := mode.clone_surface
|
|
||||||
free_surface := mode.free_surface
|
|
||||||
index := mode.index
|
|
||||||
indexptr := mode.indexptr
|
|
||||||
|
|
||||||
// Colours
|
// Colours
|
||||||
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
|
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
|
||||||
$white := Color.(255, 255, 255, 255)
|
$WHITE := Color.(255, 255, 255, 255)
|
||||||
$black := Color.(0, 0, 0, 255)
|
$BLACK := Color.(0, 0, 0, 255)
|
||||||
$gray := Color.(127, 127, 127, 255)
|
$GRAY := Color.(127, 127, 127, 255)
|
||||||
$red := Color.(0, 0, 205, 255)
|
$RED := Color.(0, 0, 205, 255)
|
||||||
$green := Color.(0, 205, 0, 255)
|
$GREEN := Color.(0, 205, 0, 255)
|
||||||
$yellow := Color.(0, 205, 205, 255)
|
$YELLOW := Color.(0, 205, 205, 255)
|
||||||
$blue := Color.(205, 0, 0, 255)
|
$BLUE := Color.(205, 0, 0, 255)
|
||||||
$magenta := Color.(205, 0, 205, 255)
|
$MAGENTA := Color.(205, 0, 205, 255)
|
||||||
$cyan := Color.(205, 205, 0, 255)
|
$CYAN := Color.(205, 205, 0, 255)
|
||||||
$light_gray := Color.(229, 229, 229, 255)
|
$LIGHT_GRAY := Color.(229, 229, 229, 255)
|
||||||
$light_red := Color.(0, 0, 255, 255)
|
$LIGHT_RED := Color.(0, 0, 255, 255)
|
||||||
$light_green := Color.(0, 255, 0, 255)
|
$LIGHT_GREEN := Color.(0, 255, 0, 255)
|
||||||
$light_yellow := Color.(0, 255, 255, 255)
|
$LIGHT_YELLOW := Color.(0, 255, 255, 255)
|
||||||
$light_blue := Color.(255, 0, 0, 255)
|
$LIGHT_BLUE := Color.(255, 0, 0, 255)
|
||||||
$light_magenta := Color.(255, 0, 255, 255)
|
$LIGHT_MAGENTA := Color.(255, 0, 255, 255)
|
||||||
$light_cyan := Color.(255, 255, 0, 255)
|
$LIGHT_CYAN := Color.(255, 255, 0, 255)
|
||||||
|
|
||||||
// Drawing
|
|
||||||
put_pixel := mode.put_pixel
|
|
||||||
put_rect := mode.put_rect
|
|
||||||
put_filled_rect := mode.put_filled_rect
|
|
||||||
put_trirect := mode.put_trirect
|
|
||||||
put_circle := mode.put_circle
|
|
||||||
put_filled_circle := mode.put_filled_circle
|
|
||||||
put_textured_circle := mode.put_textured_circle
|
|
||||||
put_line := mode.put_line
|
|
||||||
put_vline := mode.put_vline
|
|
||||||
put_hline := mode.put_hline
|
|
||||||
clear := mode.clear
|
|
||||||
put_surface := mode.put_surface
|
|
||||||
put_text := mode.put_text
|
|
||||||
// thanks peony for these three!
|
|
||||||
//put_trirect := mode.put_trirect
|
|
||||||
//put_vline := mode.put_vline
|
|
||||||
//put_hline := mode.put_hline
|
|
||||||
|
|
||||||
// Display
|
|
||||||
sync := mode.sync
|
|
|
@ -1,472 +1,443 @@
|
||||||
.{math, memory, dt} := @use("../../stn/src/lib.hb");
|
.{math, memory, dt} := @use("stn");
|
||||||
.{Color, text} := @use("lib.hb");
|
.{Color, text} := @use("lib:render");
|
||||||
.{get_glyph, get_glyph_unicode, Font, UNC_TABLE_SIZE} := text;
|
.{get_glyph, get_glyph_unicode, Font, UNC_TABLE_SIZE} := text;
|
||||||
.{Vec2} := math
|
.{Vec2} := math
|
||||||
|
|
||||||
// safety: don't use before init() or you will get a memory access violation
|
// safety: don't use before init() or you will get a memory access violation
|
||||||
framebuffer := memory.dangling(Color)
|
framebuffer := memory.dangling(Color)
|
||||||
|
utf8_len_table := u8.[0, 0, 2, 3]
|
||||||
|
|
||||||
|
init := fn(doublebuffer: bool): Surface {
|
||||||
|
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr")
|
||||||
|
width := dt.get(uint, "framebuffer/fb0/width")
|
||||||
|
height := dt.get(uint, "framebuffer/fb0/height")
|
||||||
|
if doublebuffer {
|
||||||
|
return Surface.new(width, height)
|
||||||
|
} else {
|
||||||
|
return .(framebuffer, width, height, width * height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Surface := struct {
|
Surface := struct {
|
||||||
buf: ^Color,
|
buf: ^Color,
|
||||||
width: uint,
|
width: uint,
|
||||||
height: uint,
|
height: uint,
|
||||||
size: uint,
|
size: uint,
|
||||||
}
|
|
||||||
|
|
||||||
new_surface := fn(width: uint, height: uint): Surface {
|
new := fn(width: uint, height: uint): Self {
|
||||||
return .(
|
size := width * height
|
||||||
memory.alloc(Color, width * height),
|
return .(
|
||||||
width,
|
memory.alloc(Color, size),
|
||||||
height,
|
width,
|
||||||
width * height,
|
height,
|
||||||
)
|
size,
|
||||||
}
|
)
|
||||||
|
|
||||||
clone_surface := fn(surface: ^Surface): Surface {
|
|
||||||
new := new_surface(surface.width, surface.height)
|
|
||||||
memory.copy(Color, surface.buf, new.buf, @intcast(surface.size))
|
|
||||||
return new
|
|
||||||
}
|
|
||||||
|
|
||||||
init := fn(doublebuffer: bool): Surface {
|
|
||||||
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
|
|
||||||
width := dt.get(uint, "framebuffer/fb0/width\0")
|
|
||||||
height := dt.get(uint, "framebuffer/fb0/height\0")
|
|
||||||
if doublebuffer {
|
|
||||||
return new_surface(width, height)
|
|
||||||
} else {
|
|
||||||
return .(framebuffer, width, height, width * height)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$clear := fn(surface: Surface, color: Color): void {
|
|
||||||
memory.set(Color, &color, surface.buf, surface.width * surface.height)
|
|
||||||
}
|
|
||||||
|
|
||||||
$sync := fn(surface: Surface): void {
|
|
||||||
memory.copy(Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height))
|
|
||||||
}
|
|
||||||
|
|
||||||
$index := fn(surface: Surface, x: uint, y: uint): uint {
|
|
||||||
return x + surface.width * y
|
|
||||||
}
|
|
||||||
|
|
||||||
$indexptr := fn(surface: Surface, x: uint, y: uint): ^Color {
|
|
||||||
return surface.buf + index(surface, x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
$put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void {
|
|
||||||
return *indexptr(surface, pos.x, pos.y) = color
|
|
||||||
}
|
|
||||||
|
|
||||||
put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
|
|
||||||
top_start_idx := indexptr(surface, pos.x, pos.y)
|
|
||||||
bottom_start_idx := indexptr(surface, pos.x, pos.y + tr.y - 1)
|
|
||||||
rows_to_fill := tr.y
|
|
||||||
|
|
||||||
loop if rows_to_fill <= 1 break else {
|
|
||||||
memory.set(Color, &color, top_start_idx, tr.x)
|
|
||||||
memory.set(Color, &color, bottom_start_idx, tr.x)
|
|
||||||
|
|
||||||
top_start_idx += surface.width
|
|
||||||
bottom_start_idx -= surface.width
|
|
||||||
rows_to_fill -= 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows_to_fill == 1 {
|
clone := fn(self: ^Self): Self {
|
||||||
memory.set(Color, &color, top_start_idx, tr.x)
|
new_self := Self.new(self.width, self.height)
|
||||||
|
memory.copy(Color, self.buf, new_self.buf, self.size)
|
||||||
|
return new_self
|
||||||
|
}
|
||||||
|
$clear := fn(self: Self, color: Color): void {
|
||||||
|
memory.set(Color, &color, self.buf, self.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
$sync := fn(self: Self): void {
|
||||||
}
|
memory.copy(Color, self.buf, framebuffer, self.size)
|
||||||
|
|
||||||
put_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
|
|
||||||
start_idx := indexptr(surface, pos.x, pos.y)
|
|
||||||
end_idx := indexptr(surface, pos.x, pos.y + tr.y)
|
|
||||||
right_start_idx := indexptr(surface, pos.x + tr.x, pos.y)
|
|
||||||
|
|
||||||
loop if start_idx > end_idx break else {
|
|
||||||
*start_idx = color;
|
|
||||||
*right_start_idx = color
|
|
||||||
start_idx += surface.width
|
|
||||||
right_start_idx += surface.width
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memory.set(Color, &color, indexptr(surface, pos.x, pos.y), @bitcast(tr.x + 1))
|
$index := fn(self: Self, x: uint, y: uint): uint {
|
||||||
memory.set(Color, &color, indexptr(surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
|
return x + self.width * y
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_line_low := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
|
||||||
dx := @as(int, @bitcast(p1.x - p0.x))
|
|
||||||
dy := @as(int, @bitcast(p1.y - p0.y))
|
|
||||||
yi := 1
|
|
||||||
if dy < 0 {
|
|
||||||
yi = -1
|
|
||||||
dy = -dy
|
|
||||||
}
|
}
|
||||||
D := @as(int, 2) * dy - dx
|
|
||||||
y := p0.y
|
$indexptr := fn(self: Self, x: uint, y: uint): ^Color {
|
||||||
x := p0.x
|
return self.buf + self.index(x, y)
|
||||||
loop if x == p1.x break else {
|
}
|
||||||
*indexptr(surface, x, y) = color
|
|
||||||
if D > 0 {
|
$put_pixel := fn(self: Self, pos: Vec2(uint), color: Color): void {
|
||||||
y += yi
|
*self.indexptr(pos.x, pos.y) = color
|
||||||
D += 2 * (dy - dx)
|
}
|
||||||
} else {
|
|
||||||
D += 2 * dy
|
put_filled_rect := fn(self: Self, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
|
||||||
|
top_start_idx := self.indexptr(pos.x, pos.y)
|
||||||
|
bottom_start_idx := self.indexptr(pos.x, pos.y + tr.y - 1)
|
||||||
|
rows_to_fill := tr.y
|
||||||
|
|
||||||
|
loop if rows_to_fill <= 1 break else {
|
||||||
|
memory.set(Color, &color, top_start_idx, tr.x)
|
||||||
|
memory.set(Color, &color, bottom_start_idx, tr.x)
|
||||||
|
|
||||||
|
top_start_idx += self.width
|
||||||
|
bottom_start_idx -= self.width
|
||||||
|
rows_to_fill -= 2
|
||||||
}
|
}
|
||||||
x += 1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_line_high := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
if rows_to_fill == 1 {
|
||||||
dx := @as(int, @bitcast(p1.x - p0.x))
|
memory.set(Color, &color, top_start_idx, tr.x)
|
||||||
dy := @as(int, @bitcast(p1.y - p0.y))
|
|
||||||
xi := 1
|
|
||||||
if dy < 0 {
|
|
||||||
xi = -1
|
|
||||||
dx = -dx
|
|
||||||
}
|
|
||||||
D := @as(int, 2) * dx - dy
|
|
||||||
x := p0.x
|
|
||||||
y := p0.y
|
|
||||||
loop if y == p1.y break else {
|
|
||||||
*indexptr(surface, x, y) = color
|
|
||||||
if D > 0 {
|
|
||||||
x += xi
|
|
||||||
D += 2 * (dx - dy)
|
|
||||||
} else {
|
|
||||||
D += 2 * dx
|
|
||||||
}
|
|
||||||
y += 1
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_line := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
|
||||||
if math.abs(uint, p1.y - p0.y) < math.abs(uint, p1.x - p0.x) {
|
|
||||||
if p0.x > p1.x {
|
|
||||||
@inline(put_line_low, surface, p1, p0, color)
|
|
||||||
} else {
|
|
||||||
@inline(put_line_low, surface, p0, p1, color)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if p0.y > p1.y {
|
|
||||||
@inline(put_line_high, surface, p1, p0, color)
|
|
||||||
} else {
|
|
||||||
@inline(put_line_high, surface, p0, p1, color)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool): void {
|
put_rect := fn(self: Self, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
|
||||||
src_top_cursor := top.buf
|
start_idx := self.indexptr(pos.x, pos.y)
|
||||||
src_bottom_cursor := top.buf + top.width * (top.height - 1)
|
end_idx := self.indexptr(pos.x, pos.y + tr.y)
|
||||||
|
right_start_idx := self.indexptr(pos.x + tr.x, pos.y)
|
||||||
|
|
||||||
dst_top_idx := indexptr(surface, pos.x, pos.y)
|
loop if start_idx > end_idx break else {
|
||||||
dst_bottom_idx := indexptr(surface, pos.x, pos.y + top.height - 1)
|
*start_idx = color;
|
||||||
|
*right_start_idx = color
|
||||||
dst_increment := surface.width
|
start_idx += self.width
|
||||||
|
right_start_idx += self.width
|
||||||
if flip_v {
|
|
||||||
dst_increment = -dst_increment
|
|
||||||
tmp := dst_top_idx
|
|
||||||
dst_top_idx = dst_bottom_idx
|
|
||||||
dst_bottom_idx = tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
rows_to_copy := top.height
|
|
||||||
|
|
||||||
loop if rows_to_copy <= 1 break else {
|
|
||||||
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
|
|
||||||
memory.copy(Color, src_bottom_cursor, dst_bottom_idx, top.width)
|
|
||||||
|
|
||||||
dst_top_idx += dst_increment
|
|
||||||
dst_bottom_idx -= dst_increment
|
|
||||||
src_top_cursor += top.width
|
|
||||||
src_bottom_cursor -= top.width
|
|
||||||
rows_to_copy -= 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if rows_to_copy == 1 {
|
|
||||||
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// peony-made
|
|
||||||
put_trirect := fn(surface: Surface, pos: Vec2(uint), size: Vec2(int), color0: Color, color1: Color): void {
|
|
||||||
step := Vec2(int).(1, 1)
|
|
||||||
if size.x < 0 {
|
|
||||||
step.x = -1
|
|
||||||
}
|
|
||||||
if size.y < 0 {
|
|
||||||
step.y /= @bitcast(size.x)
|
|
||||||
}
|
|
||||||
|
|
||||||
start_y := pos.y
|
|
||||||
target := pos + @bitcast(size)
|
|
||||||
|
|
||||||
loop if pos.x == target.x break else {
|
|
||||||
@inline(put_vline, surface, pos.x, pos.y, target.y, color0)
|
|
||||||
@inline(put_vline, surface, pos.x, pos.y, start_y, color1)
|
|
||||||
pos += @bitcast(step)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// peony-made
|
|
||||||
put_vline := fn(surface: Surface, x: uint, y0: uint, y1: uint, color: Color): void {
|
|
||||||
if y1 < y0 {
|
|
||||||
tmp := y0
|
|
||||||
y0 = y1
|
|
||||||
y1 = tmp
|
|
||||||
}
|
|
||||||
y := y0
|
|
||||||
|
|
||||||
loop if y == y1 break else {
|
|
||||||
*indexptr(surface, x, y) = color
|
|
||||||
y += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// peony-made
|
|
||||||
put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): void {
|
|
||||||
if x1 < x0 {
|
|
||||||
tmp := x0
|
|
||||||
x0 = x1
|
|
||||||
x1 = tmp
|
|
||||||
}
|
|
||||||
// x0 = math.min(x0, x1)
|
|
||||||
memory.set(Color, &color, indexptr(surface, x0, y), @bitcast(x1 - x0 - 1))
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void {
|
|
||||||
x := 0
|
|
||||||
y := radius
|
|
||||||
error := @as(int, 3) - @intcast(2 * radius);
|
|
||||||
*indexptr(surface, pos.x + radius, pos.y) = color;
|
|
||||||
*indexptr(surface, pos.x - radius, pos.y) = color;
|
|
||||||
*indexptr(surface, pos.x, pos.y + radius) = color;
|
|
||||||
*indexptr(surface, pos.x, pos.y - radius) = color
|
|
||||||
|
|
||||||
loop if y < x break else {
|
|
||||||
x += 1
|
|
||||||
|
|
||||||
if error > 0 {
|
|
||||||
y -= 1
|
|
||||||
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
|
||||||
} else {
|
|
||||||
error += 4 * @intcast(x) + 6
|
|
||||||
};
|
|
||||||
*indexptr(surface, pos.x + x, pos.y + y) = color;
|
|
||||||
*indexptr(surface, pos.x + y, pos.y + x) = color;
|
|
||||||
*indexptr(surface, pos.x - x, pos.y + y) = color;
|
|
||||||
*indexptr(surface, pos.x - y, pos.y + x) = color;
|
|
||||||
*indexptr(surface, pos.x + x, pos.y - y) = color;
|
|
||||||
*indexptr(surface, pos.x + y, pos.y - x) = color;
|
|
||||||
*indexptr(surface, pos.x - x, pos.y - y) = color;
|
|
||||||
*indexptr(surface, pos.x - y, pos.y - x) = color
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
put_filled_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void {
|
|
||||||
x := 0
|
|
||||||
y := radius
|
|
||||||
error := @as(int, 3) - @intcast(2 * radius)
|
|
||||||
put_hline(surface, pos.y - x, pos.x - radius, pos.x + radius, color);
|
|
||||||
*indexptr(surface, pos.x, pos.y + radius) = color;
|
|
||||||
*indexptr(surface, pos.x, pos.y - radius) = color
|
|
||||||
|
|
||||||
loop if y < x break else {
|
|
||||||
x += 1
|
|
||||||
|
|
||||||
if error > 0 {
|
|
||||||
put_hline(surface, pos.y + y, pos.x - x, pos.x + x, color)
|
|
||||||
put_hline(surface, pos.y - y, pos.x - x, pos.x + x, color)
|
|
||||||
y -= 1
|
|
||||||
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
|
||||||
} else {
|
|
||||||
error += 4 * @intcast(x) + 6
|
|
||||||
}
|
}
|
||||||
put_hline(surface, pos.y + x, pos.x - y, pos.x + y, color)
|
|
||||||
put_hline(surface, pos.y - x, pos.x - y, pos.x + y, color)
|
memory.set(Color, &color, self.indexptr(pos.x, pos.y), @bitcast(tr.x + 1))
|
||||||
|
memory.set(Color, &color, self.indexptr(pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
put_line_low := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
||||||
}
|
dx := @as(int, @bitcast(p1.x - p0.x))
|
||||||
|
dy := @as(int, @bitcast(p1.y - p0.y))
|
||||||
put_textured_circle := fn(surface: Surface, source: Surface, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void {
|
yi := 1
|
||||||
x := 0
|
if dy < 0 {
|
||||||
y := radius
|
yi = -1
|
||||||
error := @as(int, 3) - @intcast(2 * radius)
|
dy = -dy
|
||||||
memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y), indexptr(surface, pos.x - y, pos.y), 2 * y);
|
}
|
||||||
*indexptr(surface, pos.x, pos.y + y) = *indexptr(source, source_pos.x, source_pos.y + y);
|
D := @as(int, 2) * dy - dx
|
||||||
*indexptr(surface, pos.x, pos.y - y) = *indexptr(source, source_pos.x, source_pos.y - y)
|
y := p0.y
|
||||||
|
x := p0.x
|
||||||
loop if y < x break else {
|
loop if x == p1.x break else {
|
||||||
x += 1
|
*self.indexptr(x, y) = color
|
||||||
|
if D > 0 {
|
||||||
if error > 0 {
|
y += yi
|
||||||
memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y + y), indexptr(surface, pos.x - x, pos.y + y), 2 * x)
|
D += 2 * (dy - dx)
|
||||||
memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y - y), indexptr(surface, pos.x - x, pos.y - y), 2 * x)
|
} else {
|
||||||
y -= 1
|
D += 2 * dy
|
||||||
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
}
|
||||||
} else {
|
x += 1
|
||||||
error += 4 * @intcast(x) + 6
|
|
||||||
}
|
}
|
||||||
memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y + x), indexptr(surface, pos.x - y, pos.y + x), 2 * y)
|
|
||||||
memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y - x), indexptr(surface, pos.x - y, pos.y - x), 2 * y)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
put_line_high := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
||||||
}
|
dx := @as(int, @bitcast(p1.x - p0.x))
|
||||||
|
dy := @as(int, @bitcast(p1.y - p0.y))
|
||||||
|
xi := 1
|
||||||
|
if dy < 0 {
|
||||||
|
xi = -1
|
||||||
|
dx = -dx
|
||||||
|
}
|
||||||
|
D := @as(int, 2) * dx - dy
|
||||||
|
x := p0.x
|
||||||
|
y := p0.y
|
||||||
|
loop if y == p1.y break else {
|
||||||
|
*self.indexptr(x, y) = color
|
||||||
|
if D > 0 {
|
||||||
|
x += xi
|
||||||
|
D += 2 * (dx - dy)
|
||||||
|
} else {
|
||||||
|
D += 2 * dx
|
||||||
|
}
|
||||||
|
y += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
utf8_len_table := [u8].(0, 0, 2, 3)
|
put_line := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
|
||||||
|
if math.abs(int, @bitcast(p1.y - p0.y)) < math.abs(int, @bitcast(p1.x - p0.x)) {
|
||||||
|
if p0.x > p1.x {
|
||||||
|
@inline(put_line_low, self, p1, p0, color)
|
||||||
|
} else {
|
||||||
|
@inline(put_line_low, self, p0, p1, color)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if p0.y > p1.y {
|
||||||
|
@inline(put_line_high, self, p1, p0, color)
|
||||||
|
} else {
|
||||||
|
@inline(put_line_high, self, p0, p1, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void {
|
put_surface := fn(self: Self, top: Self, pos: Vec2(uint), flip_v: bool): void {
|
||||||
cursor := Vec2(uint).(pos.x, pos.y)
|
src_top_cursor := top.buf
|
||||||
|
src_bottom_cursor := top.buf + top.width * (top.height - 1)
|
||||||
|
|
||||||
max_y := surface.height - font.height
|
dst_top_idx := self.indexptr(pos.x, pos.y)
|
||||||
next_line_y := font.height + font.line_gap
|
dst_bottom_idx := self.indexptr(pos.x, pos.y + top.height - 1)
|
||||||
char_advance := font.width + font.char_gap
|
|
||||||
surface_width := surface.width
|
|
||||||
|
|
||||||
loop if *str == 0 break else {
|
dst_increment := self.width
|
||||||
if cursor.y > max_y break
|
|
||||||
|
|
||||||
glyph_data := @as(^u8, idk)
|
if flip_v {
|
||||||
code_point := @as(uint, 0)
|
dst_increment = -dst_increment
|
||||||
|
tmp := dst_top_idx
|
||||||
|
dst_top_idx = dst_bottom_idx
|
||||||
|
dst_bottom_idx = tmp
|
||||||
|
}
|
||||||
|
|
||||||
if (*str & 0x80) == 0 {
|
rows_to_copy := top.height
|
||||||
if *str == 10 {
|
|
||||||
cursor.x = pos.x
|
loop if rows_to_copy <= 1 break else {
|
||||||
cursor.y += next_line_y
|
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
|
||||||
str += 1
|
memory.copy(Color, src_bottom_cursor, dst_bottom_idx, top.width)
|
||||||
continue
|
|
||||||
|
dst_top_idx += dst_increment
|
||||||
|
dst_bottom_idx -= dst_increment
|
||||||
|
src_top_cursor += top.width
|
||||||
|
src_bottom_cursor -= top.width
|
||||||
|
rows_to_copy -= 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if rows_to_copy == 1 {
|
||||||
|
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// peony-made
|
||||||
|
put_trirect := fn(self: Self, pos: Vec2(uint), size: Vec2(int), color0: Color, color1: Color): void {
|
||||||
|
step := Vec2(int).(1, 1)
|
||||||
|
if size.x < 0 {
|
||||||
|
step.x = -1
|
||||||
|
}
|
||||||
|
if size.y < 0 {
|
||||||
|
step.y /= @bitcast(size.x)
|
||||||
|
}
|
||||||
|
|
||||||
|
start_y := pos.y
|
||||||
|
target := pos + @bitcast(size)
|
||||||
|
|
||||||
|
loop if pos.x == target.x break else {
|
||||||
|
@inline(put_vline, self, pos.x, pos.y, target.y, color0)
|
||||||
|
@inline(put_vline, self, pos.x, pos.y, start_y, color1)
|
||||||
|
pos += @bitcast(step)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// peony-made
|
||||||
|
put_vline := fn(self: Self, x: uint, y0: uint, y1: uint, color: Color): void {
|
||||||
|
if y1 < y0 {
|
||||||
|
tmp := y0
|
||||||
|
y0 = y1
|
||||||
|
y1 = tmp
|
||||||
|
}
|
||||||
|
y := y0
|
||||||
|
|
||||||
|
loop if y == y1 break else {
|
||||||
|
*self.indexptr(x, y) = color
|
||||||
|
y += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// peony-made
|
||||||
|
put_hline := fn(self: Self, y: uint, x0: uint, x1: uint, color: Color): void {
|
||||||
|
if x1 < x0 {
|
||||||
|
tmp := x0
|
||||||
|
x0 = x1
|
||||||
|
x1 = tmp
|
||||||
|
}
|
||||||
|
memory.set(Color, &color, self.indexptr(x0, y), @bitcast(x1 - x0))
|
||||||
|
}
|
||||||
|
|
||||||
|
put_circle := fn(self: Self, pos: Vec2(uint), radius: uint, color: Color): void {
|
||||||
|
x := 0
|
||||||
|
y := radius
|
||||||
|
error := @as(int, 3) - 2 * @intcast(radius)
|
||||||
|
loop if x > y break else {
|
||||||
|
self.put_pixel(pos + .(x, y), color)
|
||||||
|
self.put_pixel(pos + .(-x, y), color)
|
||||||
|
self.put_pixel(pos + .(x, -y), color)
|
||||||
|
self.put_pixel(pos + .(-x, -y), color)
|
||||||
|
self.put_pixel(pos + .(y, x), color)
|
||||||
|
self.put_pixel(pos + .(-y, x), color)
|
||||||
|
self.put_pixel(pos + .(y, -x), color)
|
||||||
|
self.put_pixel(pos + .(-y, -x), color)
|
||||||
|
if error < 0 {
|
||||||
|
error += 4 * @intcast(x) + 6
|
||||||
|
} else {
|
||||||
|
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
||||||
|
y -= 1
|
||||||
|
}
|
||||||
|
x += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put_filled_circle := fn(self: Self, pos: Vec2(uint), radius: uint, color: Color): void {
|
||||||
|
x := 0
|
||||||
|
y := radius
|
||||||
|
error := @as(int, 3) - 2 * @intcast(radius)
|
||||||
|
|
||||||
|
loop if x > y break else {
|
||||||
|
self.put_hline(pos.y + y, pos.x - x, pos.x + x, color)
|
||||||
|
self.put_hline(pos.y - y, pos.x - x, pos.x + x, color)
|
||||||
|
|
||||||
|
if x != y {
|
||||||
|
self.put_hline(pos.y + x, pos.x - y, pos.x + y, color)
|
||||||
|
self.put_hline(pos.y - x, pos.x - y, pos.x + y, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
if font.unicode == null {
|
if error < 0 {
|
||||||
if *str > font.num_glyphs {
|
error += 4 * @intcast(x) + 6
|
||||||
str += 1
|
} else {
|
||||||
|
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
||||||
|
y -= 1
|
||||||
|
}
|
||||||
|
x += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put_textured_circle := fn(self: Self, source: Self, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void {
|
||||||
|
x := 0
|
||||||
|
y := radius
|
||||||
|
error := @as(int, 3) - 2 * @intcast(radius)
|
||||||
|
|
||||||
|
loop if x > y break else {
|
||||||
|
memory.copy(Color, source.indexptr(source_pos.x - x, source_pos.y + y), self.indexptr(pos.x - x, pos.y + y), 2 * x)
|
||||||
|
memory.copy(Color, source.indexptr(source_pos.x - x, source_pos.y - y), self.indexptr(pos.x - x, pos.y - y), 2 * x)
|
||||||
|
|
||||||
|
if x != y {
|
||||||
|
memory.copy(Color, source.indexptr(source_pos.x - y, source_pos.y + x), self.indexptr(pos.x - y, pos.y + x), 2 * y)
|
||||||
|
memory.copy(Color, source.indexptr(source_pos.x - y, source_pos.y - x), self.indexptr(pos.x - y, pos.y - x), 2 * y)
|
||||||
|
}
|
||||||
|
|
||||||
|
if error < 0 {
|
||||||
|
error += 4 * @intcast(x) + 6
|
||||||
|
} else {
|
||||||
|
error += 4 * (@intcast(x) - @intcast(y)) + 10
|
||||||
|
y -= 1
|
||||||
|
}
|
||||||
|
x += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put_text := fn(self: Self, font: Font, pos: Vec2(uint), color: Color, str: []u8): void {
|
||||||
|
cursor := Vec2(uint).(pos.x, pos.y)
|
||||||
|
|
||||||
|
max_y := self.height - font.height
|
||||||
|
next_line_y := font.height + font.line_gap
|
||||||
|
char_advance := font.width + font.char_gap
|
||||||
|
self_width := self.width
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
|
||||||
|
loop if i >= str.len break else {
|
||||||
|
if cursor.y > max_y break
|
||||||
|
|
||||||
|
glyph_data := @as(^u8, idk)
|
||||||
|
code_point := @as(uint, 0)
|
||||||
|
|
||||||
|
if (str[i] & 0x80) == 0 {
|
||||||
|
if str[i] == '\n' {
|
||||||
|
cursor.x = pos.x
|
||||||
|
cursor.y += next_line_y
|
||||||
|
i += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glyph_data = get_glyph(font, *str)
|
|
||||||
} else {
|
if font.unicode == null {
|
||||||
if *str < UNC_TABLE_SIZE {
|
if str[i] > font.num_glyphs {
|
||||||
glyph_index := *(font.unicode + *str)
|
i += 1
|
||||||
if glyph_index == 0xFFFF {
|
|
||||||
str += 1
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
glyph_data = font.data + glyph_index * font.bytes_per_glyph
|
glyph_data = get_glyph(font, str[i])
|
||||||
} else {
|
} else {
|
||||||
str += 1
|
if str[i] < UNC_TABLE_SIZE {
|
||||||
|
glyph_index := *(font.unicode + str[i])
|
||||||
|
if glyph_index == 0xFFFF {
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
glyph_data = font.data + glyph_index * font.bytes_per_glyph
|
||||||
|
} else {
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
} else if font.unicode != null {
|
||||||
|
first_byte := str[i]
|
||||||
|
num_bytes := @as(uint, 0)
|
||||||
|
|
||||||
|
num_bytes = utf8_len_table[first_byte >> 5 & 0x3]
|
||||||
|
|
||||||
|
if num_bytes == 0 {
|
||||||
|
i += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
str += 1
|
|
||||||
} else if font.unicode != null {
|
|
||||||
first_byte := *str
|
|
||||||
num_bytes := @as(uint, 0)
|
|
||||||
|
|
||||||
num_bytes = utf8_len_table[first_byte >> 5 & 0x3]
|
code_point = first_byte & (0x7F >> num_bytes | 0x1F)
|
||||||
|
|
||||||
if num_bytes == 0 {
|
valid_sequence := true
|
||||||
str += 1
|
bytes_processed := 1
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
code_point = first_byte & (0x7F >> num_bytes | 0x1F)
|
loop if bytes_processed >= num_bytes break else {
|
||||||
|
i += 1
|
||||||
valid_sequence := true
|
if i == str.len | (str[i] & 0xC0) != 0x80 {
|
||||||
bytes_processed := 1
|
valid_sequence = false
|
||||||
|
}
|
||||||
loop if bytes_processed >= num_bytes break else {
|
if valid_sequence == false {
|
||||||
str += 1
|
break
|
||||||
if *str == 0 | (*str & 0xC0) != 0x80 {
|
}
|
||||||
valid_sequence = false
|
code_point = code_point << 6 | str[i] & 0x3F
|
||||||
|
bytes_processed += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if valid_sequence == false {
|
if valid_sequence == false {
|
||||||
break
|
i += 1
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
code_point = code_point << 6 | *str & 0x3F
|
|
||||||
bytes_processed += 1
|
i += 1
|
||||||
|
|
||||||
|
if code_point == '\n' {
|
||||||
|
cursor.x = pos.x
|
||||||
|
cursor.y += next_line_y
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if code_point >= UNC_TABLE_SIZE {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
glyph_index := *(font.unicode + code_point)
|
||||||
|
if glyph_index == 0xFFFF {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
glyph_data = font.data + glyph_index * font.bytes_per_glyph
|
||||||
}
|
}
|
||||||
|
|
||||||
if valid_sequence == false {
|
if cursor.x + font.width >= self_width {
|
||||||
str += 1
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
str += 1
|
|
||||||
|
|
||||||
if code_point == 10 {
|
|
||||||
cursor.x = pos.x
|
cursor.x = pos.x
|
||||||
cursor.y += next_line_y
|
cursor.y += next_line_y
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if code_point >= UNC_TABLE_SIZE {
|
dest := self.indexptr(cursor.x, cursor.y)
|
||||||
continue
|
rows := font.height
|
||||||
}
|
|
||||||
|
|
||||||
glyph_index := *(font.unicode + code_point)
|
loop if rows == 0 break else {
|
||||||
if glyph_index == 0xFFFF {
|
byte := *glyph_data
|
||||||
continue
|
pixel_dest := dest
|
||||||
}
|
mask := @as(u8, 0x80)
|
||||||
glyph_data = font.data + glyph_index * font.bytes_per_glyph
|
bits := font.width
|
||||||
}
|
|
||||||
|
|
||||||
if cursor.x + font.width >= surface_width {
|
loop if bits == 0 break else {
|
||||||
cursor.x = pos.x
|
if (byte & mask) != 0 {
|
||||||
cursor.y += next_line_y
|
*pixel_dest = color
|
||||||
}
|
}
|
||||||
|
pixel_dest += 1
|
||||||
dest := indexptr(surface, cursor.x, cursor.y)
|
mask >>= 1
|
||||||
rows := font.height
|
if mask == 0 & bits > 0 {
|
||||||
|
glyph_data += 1
|
||||||
loop if rows == 0 break else {
|
byte = *glyph_data
|
||||||
byte := *glyph_data
|
mask = 0x80
|
||||||
pixel_dest := dest
|
}
|
||||||
mask := @as(u8, 0x80)
|
bits -= 1
|
||||||
bits := font.width
|
|
||||||
|
|
||||||
loop if bits == 0 break else {
|
|
||||||
if (byte & mask) != 0 {
|
|
||||||
*pixel_dest = color
|
|
||||||
}
|
}
|
||||||
pixel_dest += 1
|
|
||||||
mask >>= 1
|
if mask != 0x80 {
|
||||||
if mask == 0 & bits > 0 {
|
|
||||||
glyph_data += 1
|
glyph_data += 1
|
||||||
byte = *glyph_data
|
|
||||||
mask = 0x80
|
|
||||||
}
|
}
|
||||||
bits -= 1
|
dest += self_width
|
||||||
|
rows -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if mask != 0x80 {
|
cursor.x += char_advance
|
||||||
glyph_data += 1
|
|
||||||
}
|
|
||||||
dest += surface_width
|
|
||||||
rows -= 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.x += char_advance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
.{log, memory} := @use("../../stn/src/lib.hb")
|
.{log, memory} := @use("stn")
|
||||||
|
|
||||||
PSF1Header := packed struct {
|
PSF1Header := packed struct {
|
||||||
magic: u16,
|
magic: u16,
|
||||||
|
@ -31,7 +31,7 @@ Font := struct {
|
||||||
font_from_psf1 := fn(psf: ^u8): ?Font {
|
font_from_psf1 := fn(psf: ^u8): ?Font {
|
||||||
header := @as(^PSF1Header, @bitcast(psf))
|
header := @as(^PSF1Header, @bitcast(psf))
|
||||||
if header.magic != 0x436 {
|
if header.magic != 0x436 {
|
||||||
log.error("failed to load psf font: not a psf1 font, idiot\0")
|
log.error("failed to load psf font: not a psf1 font, idiot")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ font_from_psf1 := fn(psf: ^u8): ?Font {
|
||||||
font_from_psf2 := fn(psf: ^u8, unicode: bool): ?Font {
|
font_from_psf2 := fn(psf: ^u8, unicode: bool): ?Font {
|
||||||
header := @as(^PSF2Header, @bitcast(psf))
|
header := @as(^PSF2Header, @bitcast(psf))
|
||||||
if header.magic != 0x864AB572 {
|
if header.magic != 0x864AB572 {
|
||||||
log.error("failed to load psf font: not a psf2 font, idiot\0")
|
log.error("failed to load psf font: not a psf2 font, idiot")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
sysdata/libraries/stn/src/alloc/alloc_return.hb
Normal file
4
sysdata/libraries/stn/src/alloc/alloc_return.hb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
AllocReturn := struct {
|
||||||
|
byte_count: uint,
|
||||||
|
ptr: ?^u8,
|
||||||
|
}
|
90
sysdata/libraries/stn/src/alloc/block_alloc.hb
Normal file
90
sysdata/libraries/stn/src/alloc/block_alloc.hb
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
.{log, panic, memory} := @use("stn")
|
||||||
|
alloc_return := @use("alloc_return.hb")
|
||||||
|
|
||||||
|
/* the block size is 64 bytes, 64 blocks of 64 bytes.
|
||||||
|
this will very quickly lead to exhaustion of free blocks.
|
||||||
|
*/
|
||||||
|
BlockAlloc := struct {
|
||||||
|
// hi
|
||||||
|
state: uint,
|
||||||
|
ptr: ?^u8,
|
||||||
|
|
||||||
|
$init := fn(): Self {
|
||||||
|
alloc_page_ptr := memory.request_page(1, false)
|
||||||
|
state := 0xFFFFFFFFFFFFFFFF
|
||||||
|
return .(state, alloc_page_ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn {
|
||||||
|
offset := 0
|
||||||
|
state_2 := 0
|
||||||
|
loop {
|
||||||
|
xyz := self.state & 1
|
||||||
|
abc := if xyz == 1 {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
// check if the `offset` bit is 1, if it is move to the next offset
|
||||||
|
if abc {
|
||||||
|
offset += 1
|
||||||
|
return .(0, null)
|
||||||
|
} else {
|
||||||
|
log.info("Already Allocated")
|
||||||
|
}
|
||||||
|
|
||||||
|
// else {
|
||||||
|
// // self it to 1 and return the ptr to the allocation
|
||||||
|
// self.state |= a
|
||||||
|
// // return ptr + offset * 64
|
||||||
|
// if self.ptr != null {
|
||||||
|
// return .(64, self.ptr + offset * 64)
|
||||||
|
// } else {
|
||||||
|
// // panic.panic("Allocator is not inited.")
|
||||||
|
// // return .(0, null)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// there are only 64 blocks
|
||||||
|
if offset >= 64 {
|
||||||
|
return .(0, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void {
|
||||||
|
// size := size_of(alloc_type)*count
|
||||||
|
size := 64
|
||||||
|
// get the size alligned to the nearest block
|
||||||
|
// rounded_size := nearest_block_size_rounded_up(size)
|
||||||
|
rounded_size := 64
|
||||||
|
|
||||||
|
state_bit_start := {
|
||||||
|
// Do math here to figure out what starting ptr corresponds to what bit
|
||||||
|
3
|
||||||
|
}
|
||||||
|
|
||||||
|
offset := 0
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if rounded_size > 0 {
|
||||||
|
// set state_bit_start+offset to 0
|
||||||
|
|
||||||
|
// at the end move to the next one
|
||||||
|
offset += 1
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
rounded_size -= 64
|
||||||
|
}
|
||||||
|
return void
|
||||||
|
}
|
||||||
|
|
||||||
|
$deinit := fn(self: Self): void {
|
||||||
|
self.state = 0
|
||||||
|
self.ptr = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// request a kernel page
|
||||||
|
// ptr := memory.alloc(1)
|
19
sysdata/libraries/stn/src/alloc/fake_alloc.hb
Normal file
19
sysdata/libraries/stn/src/alloc/fake_alloc.hb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
alloc_return := @use("alloc_return.hb")
|
||||||
|
|
||||||
|
FakeAlloc := struct {
|
||||||
|
$init := fn(): Self {
|
||||||
|
return .()
|
||||||
|
}
|
||||||
|
|
||||||
|
$alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn {
|
||||||
|
return .(0, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
$dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void {
|
||||||
|
return void
|
||||||
|
}
|
||||||
|
// Nothing to clean up here
|
||||||
|
$deinit := fn(self: Self): void {
|
||||||
|
return void
|
||||||
|
}
|
||||||
|
}
|
2
sysdata/libraries/stn/src/alloc/lib.hb
Normal file
2
sysdata/libraries/stn/src/alloc/lib.hb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.{BlockAlloc} := @use("block_alloc.hb");
|
||||||
|
.{FakeAlloc} := @use("fake_alloc.hb")
|
25
sysdata/libraries/stn/src/alloc/main.hb
Normal file
25
sysdata/libraries/stn/src/alloc/main.hb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
allocators := @use("alloc/alloc.hb")
|
||||||
|
|
||||||
|
AStruct := struct {
|
||||||
|
a_field: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
main := fn():void{
|
||||||
|
alloc := allocators.FakeAlloc.init()
|
||||||
|
astruct := alloc.alloc(AStruct, 2)
|
||||||
|
if astruct.ptr != null{
|
||||||
|
panic("FakeAlloc actually allocated.")
|
||||||
|
}
|
||||||
|
alloc.dealloc(astruct_ptr, AStruct, 2)
|
||||||
|
alloc.deinit()
|
||||||
|
|
||||||
|
balloc := allocators.BlockAlloc.init()
|
||||||
|
bstruct_ptr := balloc.alloc(AStruct, 2)
|
||||||
|
if bstruct_ptr == null {
|
||||||
|
panic("BlockAlloc actually didn't allocate.")
|
||||||
|
}
|
||||||
|
balloc.dealloc(bstruct_ptr, AStruct, 2)
|
||||||
|
balloc.deinit()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
string := @use("string.hb")
|
$await := fn(buffer_id: uint): void {
|
||||||
|
return @eca(7, buffer_id)
|
||||||
|
}
|
||||||
|
|
||||||
$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void {
|
$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void {
|
||||||
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
|
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
|
||||||
|
@ -18,18 +20,18 @@ $write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void {
|
||||||
|
|
||||||
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
||||||
|
|
||||||
create := fn(msg: ^u8): uint {
|
$create := fn(msg: []u8): uint {
|
||||||
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
return @eca(3, 0, BufferMsg.(0, msg.ptr, msg.len), @sizeof(BufferMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
$create_nameless := fn(): uint {
|
$create_nameless := fn(): uint {
|
||||||
return @eca(1, 0)
|
return @eca(1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
$delete_buffer := fn(buffer_id: uint): void {
|
$delete := fn(buffer_id: uint): void {
|
||||||
return @eca(2, buffer_id)
|
return @eca(2, buffer_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
search := fn(msg: ^u8): uint {
|
$search := fn(msg: []u8): uint {
|
||||||
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
return @eca(3, 0, BufferMsg.(3, msg.ptr, msg.len), @sizeof(BufferMsg))
|
||||||
}
|
}
|
|
@ -1,5 +1,3 @@
|
||||||
.{string} := @use("../../stn/src/lib.hb")
|
$get := fn($Expr: type, query: []u8): Expr {
|
||||||
|
return @eca(3, 5, query.ptr, query.len)
|
||||||
get := fn($Expr: type, query: ^u8): Expr {
|
|
||||||
return @eca(3, 5, query, @inline(string.length, query))
|
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ acs := @use("acs.hb");
|
||||||
.{DiskID, FileID} := acs
|
.{DiskID, FileID} := acs
|
||||||
|
|
||||||
// Paths without a node-disk component are to be treated as local files.
|
// Paths without a node-disk component are to be treated as local files.
|
||||||
// file_path := "DID:/test\0";
|
// file_path := "DID:/test"
|
||||||
Path := struct {
|
Path := struct {
|
||||||
// DiskID holds the host id
|
// DiskID holds the host id
|
||||||
disk_id: DiskID,
|
disk_id: DiskID,
|
||||||
|
|
285
sysdata/libraries/stn/src/fmt.hb
Normal file
285
sysdata/libraries/stn/src/fmt.hb
Normal file
|
@ -0,0 +1,285 @@
|
||||||
|
.{Kind, usize, string, signed_int, panic, float, integer, memory, log: .{LogLevel}} := @use("stn")
|
||||||
|
|
||||||
|
fmt_int := fn(v: @Any(), str: []u8, radix: @TypeOf(v)): uint {
|
||||||
|
is_negative := signed_int(@TypeOf(v)) & v < 0
|
||||||
|
prefix_len := 0
|
||||||
|
if is_negative {
|
||||||
|
v = -v
|
||||||
|
str[0] = '-'
|
||||||
|
prefix_len += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if radix == 16 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0x".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
} else if radix == 2 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0b".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
} else if radix == 8 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0o".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if v == 0 {
|
||||||
|
str[prefix_len] = '0'
|
||||||
|
return prefix_len + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
i := prefix_len
|
||||||
|
loop if v <= 0 break else {
|
||||||
|
remainder := v % radix
|
||||||
|
v /= radix
|
||||||
|
if remainder > 9 {
|
||||||
|
str[i] = @intcast(remainder - 10 + 'A')
|
||||||
|
} else {
|
||||||
|
str[i] = @intcast(remainder + '0')
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
string.reverse(str[prefix_len..i])
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt_bool := fn(v: bool, str: []u8): uint {
|
||||||
|
if v {
|
||||||
|
*@as(^[4]u8, @bitcast(str.ptr)) = *@bitcast("true".ptr)
|
||||||
|
return 4
|
||||||
|
} else {
|
||||||
|
*@as(^[5]u8, @bitcast(str.ptr)) = *@bitcast("false".ptr)
|
||||||
|
return 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$FP_TOLERANCE := 0.00000001
|
||||||
|
|
||||||
|
fmt_float := fn(v: @Any(), str: []u8, precision: uint, radix: int): uint {
|
||||||
|
is_negative := v < 0
|
||||||
|
|
||||||
|
prefix_len := 0
|
||||||
|
|
||||||
|
if is_negative {
|
||||||
|
v = -v
|
||||||
|
str[0] = '-'
|
||||||
|
prefix_len += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if radix == 16 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0x".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
} else if radix == 2 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0b".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
} else if radix == 8 {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0o".ptr)
|
||||||
|
prefix_len += 2
|
||||||
|
}
|
||||||
|
|
||||||
|
integer_part := @fti(v)
|
||||||
|
fractional_part := v - @itf(integer_part)
|
||||||
|
|
||||||
|
i := prefix_len
|
||||||
|
loop if integer_part == 0 & i > prefix_len break else {
|
||||||
|
remainder := integer_part % radix
|
||||||
|
integer_part /= radix
|
||||||
|
if remainder > 9 {
|
||||||
|
str[i] = @intcast(remainder - 10 + 'A')
|
||||||
|
} else {
|
||||||
|
str[i] = @intcast(remainder + '0')
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
string.reverse(str[prefix_len..i])
|
||||||
|
str[i] = '.'
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
p := precision
|
||||||
|
loop if p <= 0 | fractional_part < FP_TOLERANCE break else {
|
||||||
|
fractional_part *= @itf(radix)
|
||||||
|
digit := @fti(fractional_part)
|
||||||
|
if digit > 9 {
|
||||||
|
str[i] = @intcast(digit - 10 + 'A')
|
||||||
|
} else {
|
||||||
|
str[i] = @intcast(digit + '0')
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
fractional_part -= @itf(digit)
|
||||||
|
p -= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt_container := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||||
|
T2 := @TypeOf(v)
|
||||||
|
kind := Kind.of(T2)
|
||||||
|
i := 0
|
||||||
|
len := 0
|
||||||
|
if kind == .Struct {
|
||||||
|
*@as(^[@intcast(@nameof(T2).len)]u8, @bitcast(str.ptr + len)) = *@bitcast(@nameof(T2).ptr)
|
||||||
|
len += @nameof(T2).len;
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||||
|
len += 2
|
||||||
|
} else if kind == .Slice {
|
||||||
|
*@as(^[@intcast(@nameof(@ChildOf(T2)).len)]u8, @bitcast(str.ptr + len)) = *@bitcast(@nameof(@ChildOf(T2)).ptr)
|
||||||
|
len += @nameof(@ChildOf(T2)).len;
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".[".ptr)
|
||||||
|
len += 2
|
||||||
|
} else if kind == .Tuple {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||||
|
len += 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if kind == .Slice {
|
||||||
|
loop {
|
||||||
|
len += @inline(format, v[i], str[len..], opts)
|
||||||
|
i += 1
|
||||||
|
if i == v.len break else {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr)
|
||||||
|
len += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$loop {
|
||||||
|
len += @inline(format, v[i], str[len..], opts)
|
||||||
|
i += 1
|
||||||
|
if i == @lenof(T2) break else {
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr)
|
||||||
|
len += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if kind == .Struct | kind == .Tuple {
|
||||||
|
*@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr)
|
||||||
|
len += 1
|
||||||
|
} else if kind == .Slice {
|
||||||
|
*@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast("]".ptr)
|
||||||
|
len += 1
|
||||||
|
}
|
||||||
|
return len
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt_nullable := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||||
|
if v == null {
|
||||||
|
*@as(^[4]u8, @bitcast(str.ptr)) = *@bitcast("null".ptr)
|
||||||
|
return 4
|
||||||
|
} else {
|
||||||
|
return @inline(format, @as(@ChildOf(@TypeOf(v)), v), str, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt_enum := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||||
|
T := @TypeOf(v)
|
||||||
|
len := @nameof(T).len;
|
||||||
|
*@as(^[@intcast(@nameof(T).len)]u8, @bitcast(str.ptr)) = *@bitcast(@nameof(T).ptr);
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||||
|
len += 2
|
||||||
|
len += fmt_int(@as(usize(T), @bitcast(v)), str[len..], 10);
|
||||||
|
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr)
|
||||||
|
return len + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO:
|
||||||
|
* Custom formatters using struct methods (T._fmt(self, str): uint),
|
||||||
|
* Format struct fields "Name.{a: x, b: y, c: z}"
|
||||||
|
* Optionally tabulate
|
||||||
|
* Add more FormatOption fields
|
||||||
|
* Support scientific notation for floating point
|
||||||
|
* Support format string
|
||||||
|
*/
|
||||||
|
|
||||||
|
FormatOptions := struct {
|
||||||
|
precision: uint = 2,
|
||||||
|
radix: uint = 10,
|
||||||
|
// temporarily here, will change later maybe
|
||||||
|
log: LogLevel = .Info,
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SAFETY:
|
||||||
|
* Assumes the buffer is wide enough for the formatted text and a null char
|
||||||
|
* Does not clear the buffer for you
|
||||||
|
*/
|
||||||
|
|
||||||
|
format := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||||
|
T := @TypeOf(v)
|
||||||
|
match Kind.of(T) {
|
||||||
|
.Pointer => return @inline(fmt_int, @as(uint, @bitcast(v)), str, 16),
|
||||||
|
.Builtin => {
|
||||||
|
if integer(T) {
|
||||||
|
return @inline(fmt_int, v, str, @intcast(opts.radix))
|
||||||
|
} else if T == bool {
|
||||||
|
return @inline(fmt_bool, v, str)
|
||||||
|
} else if float(T) {
|
||||||
|
return @inline(fmt_float, v, str, opts.precision, @intcast(opts.radix))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.Opt => return @inline(fmt_nullable, v, str, opts),
|
||||||
|
.Enum => return @inline(fmt_enum, v, str, opts),
|
||||||
|
.Struct => return @inline(fmt_container, v, str, opts),
|
||||||
|
.Tuple => return @inline(fmt_container, v, str, opts),
|
||||||
|
.Slice => if T != []u8 return @inline(fmt_container, v, str, opts) else {
|
||||||
|
i := 0
|
||||||
|
loop if i == v.len break else {
|
||||||
|
str[i] = v[i]
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return v.len
|
||||||
|
},
|
||||||
|
_ => @error("Type: \"", T, "\" is not supported."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
format_with_str := fn(v: @Any(), read: []u8, write: []u8, opts: FormatOptions): uint {
|
||||||
|
T := @TypeOf(v)
|
||||||
|
n := string.count(read, '{')
|
||||||
|
if n != string.count(read, '}') panic("Missing closing '}' in format string.")
|
||||||
|
if Kind.of(T) == .Tuple {
|
||||||
|
if @lenof(T) != n panic("Format string has different number of '{}' than args given.")
|
||||||
|
m := 0
|
||||||
|
i := 0
|
||||||
|
j := 0
|
||||||
|
$loop if m > @lenof(T) break else {
|
||||||
|
if m == @lenof(T) {
|
||||||
|
loop if i == read.len break else {
|
||||||
|
write[j] = read[i]
|
||||||
|
i += 1
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
m += 1
|
||||||
|
} else {
|
||||||
|
v2 := v[m]
|
||||||
|
loop if i == read.len break else {
|
||||||
|
if read[i] == '{' & read[i + 1] == '}' {
|
||||||
|
j += format(v2, write[j..], opts)
|
||||||
|
i += 2
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
write[j] = read[i]
|
||||||
|
i += 1
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
} else if n > 1 {
|
||||||
|
panic("Format string has multiple '{}' but value provided is not a tuple.")
|
||||||
|
} else {
|
||||||
|
i := 0
|
||||||
|
j := 0
|
||||||
|
loop if i == read.len break else {
|
||||||
|
if read[i] == '{' & read[i + 1] == '}' {
|
||||||
|
j += format(v, write[j..], opts)
|
||||||
|
i += 2
|
||||||
|
} else {
|
||||||
|
write[j] = read[i]
|
||||||
|
i += 1
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
}
|
||||||
|
}
|
181
sysdata/libraries/stn/src/hash/foldhash.hb
Normal file
181
sysdata/libraries/stn/src/hash/foldhash.hb
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
/*
|
||||||
|
* This code is an implementation of the FoldHash algorithm from https://github.com/orlp/foldhash,
|
||||||
|
* originally written by Orson Peters under the zlib license.
|
||||||
|
*
|
||||||
|
* Changes to the original code were made to meet the simplicity requirements of this implementation.
|
||||||
|
* Behaviour aims to be equivalent but not identical to the original code.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Orson Peters
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied warranty. In
|
||||||
|
* no event will the authors be held liable for any damages arising from the use of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose, including
|
||||||
|
* commercial applications, and to alter it and redistribute it freely, subject to
|
||||||
|
* the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not claim
|
||||||
|
* that you wrote the original software. If you use this software in a product,
|
||||||
|
* an acknowledgment in the product documentation would be appreciated but is
|
||||||
|
* not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/;
|
||||||
|
|
||||||
|
.{math, random} := @use("stn")
|
||||||
|
|
||||||
|
$ARBITRARY0 := 0x243F6A8885A308D3
|
||||||
|
$ARBITRARY1 := 0x13198A2E03707344
|
||||||
|
$ARBITRARY2 := 0xA4093822299F31D0
|
||||||
|
$ARBITRARY3 := 0x82EFA98EC4E6C89
|
||||||
|
$ARBITRARY4 := 0x452821E638D01377
|
||||||
|
$ARBITRARY5 := 0xBE5466CF34E90C6C
|
||||||
|
$ARBITRARY6 := 0xC0AC29B7C97C50DD
|
||||||
|
$ARBITRARY7 := 0x3F84D5B5B5470917
|
||||||
|
$ARBITRARY8 := 0x9216D5D98979FB1B
|
||||||
|
$ARBITRARY9 := 0xD1310BA698DFB5AC
|
||||||
|
$FIXED_GLOBAL_SEED := uint.[ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7]
|
||||||
|
|
||||||
|
global_seed := 0
|
||||||
|
|
||||||
|
u128 := packed struct {a: uint, b: uint}
|
||||||
|
|
||||||
|
$folded_multiply := fn(x: uint, y: uint): uint {
|
||||||
|
lx := @as(u32, @intcast(x))
|
||||||
|
ly := @as(u32, @intcast(y))
|
||||||
|
hx := x >> 32
|
||||||
|
hy := y >> 32
|
||||||
|
afull := lx * hy
|
||||||
|
bfull := hx * ly
|
||||||
|
return afull ^ (bfull << 32 | bfull >> 32)
|
||||||
|
}
|
||||||
|
|
||||||
|
hash_bytes_medium := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, fold_seed: uint): uint {
|
||||||
|
lo := bytes
|
||||||
|
end := bytes + len
|
||||||
|
hi := end - 16
|
||||||
|
|
||||||
|
loop if lo >= hi break else {
|
||||||
|
a := *@as(^uint, @bitcast(lo))
|
||||||
|
b := *@as(^uint, @bitcast(lo + 8))
|
||||||
|
c := *@as(^uint, @bitcast(hi))
|
||||||
|
d := *@as(^uint, @bitcast(hi + 8))
|
||||||
|
s0 = folded_multiply(a ^ s0, c ^ fold_seed)
|
||||||
|
s1 = folded_multiply(b ^ s1, d ^ fold_seed)
|
||||||
|
hi -= 16
|
||||||
|
lo += 16
|
||||||
|
}
|
||||||
|
return s0 ^ s1
|
||||||
|
}
|
||||||
|
|
||||||
|
hash_bytes_long := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, s2: uint, s3: uint, fold_seed: uint): uint {
|
||||||
|
$chunk_size := 64
|
||||||
|
chunks := len / chunk_size
|
||||||
|
remainder := len % chunk_size
|
||||||
|
|
||||||
|
ptr := bytes
|
||||||
|
i := 0
|
||||||
|
loop if i >= chunks break else {
|
||||||
|
a := *@as(^uint, @bitcast(ptr))
|
||||||
|
b := *@as(^uint, @bitcast(ptr + 8))
|
||||||
|
c := *@as(^uint, @bitcast(ptr + 16))
|
||||||
|
d := *@as(^uint, @bitcast(ptr + 24))
|
||||||
|
e := *@as(^uint, @bitcast(ptr + 32))
|
||||||
|
f := *@as(^uint, @bitcast(ptr + 40))
|
||||||
|
g := *@as(^uint, @bitcast(ptr + 48))
|
||||||
|
h := *@as(^uint, @bitcast(ptr + 56))
|
||||||
|
|
||||||
|
s0 = folded_multiply(a ^ s0, e ^ fold_seed)
|
||||||
|
s1 = folded_multiply(b ^ s1, f ^ fold_seed)
|
||||||
|
s2 = folded_multiply(c ^ s2, g ^ fold_seed)
|
||||||
|
s3 = folded_multiply(d ^ s3, h ^ fold_seed)
|
||||||
|
|
||||||
|
ptr += chunk_size
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
s0 ^= s2
|
||||||
|
s1 ^= s3
|
||||||
|
|
||||||
|
if remainder > 0 {
|
||||||
|
remainder_start := bytes + len - math.max(uint, remainder, 16)
|
||||||
|
return @inline(hash_bytes_medium, remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s0 ^ s1
|
||||||
|
}
|
||||||
|
|
||||||
|
FoldHasher := struct {
|
||||||
|
accumulator: uint,
|
||||||
|
original_seed: uint,
|
||||||
|
sponge: u128,
|
||||||
|
sponge_len: u8,
|
||||||
|
fold_seed: uint,
|
||||||
|
expand_seed: uint,
|
||||||
|
expand_seed2: uint,
|
||||||
|
expand_seed3: uint,
|
||||||
|
|
||||||
|
$new := fn(seed: uint): Self {
|
||||||
|
return .(
|
||||||
|
seed,
|
||||||
|
seed,
|
||||||
|
.(0, 0),
|
||||||
|
0,
|
||||||
|
FIXED_GLOBAL_SEED[0],
|
||||||
|
FIXED_GLOBAL_SEED[1],
|
||||||
|
FIXED_GLOBAL_SEED[2],
|
||||||
|
FIXED_GLOBAL_SEED[3],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
default := fn(): Self {
|
||||||
|
if global_seed == 0 {
|
||||||
|
// ! consider this "secure enough" for now
|
||||||
|
global_seed = random.any(uint)
|
||||||
|
}
|
||||||
|
return Self.new(global_seed)
|
||||||
|
}
|
||||||
|
|
||||||
|
write := fn(self: ^Self, bytes: ^u8, len: uint): void {
|
||||||
|
s0 := self.accumulator
|
||||||
|
s1 := self.expand_seed
|
||||||
|
if len <= 16 {
|
||||||
|
if len >= 8 {
|
||||||
|
s0 ^= *@bitcast(bytes)
|
||||||
|
s1 ^= *@bitcast(bytes + len - 8)
|
||||||
|
} else if len >= 4 {
|
||||||
|
s0 ^= *@as(^u32, @bitcast(bytes))
|
||||||
|
s1 ^= *@as(^u32, @bitcast(bytes + len - 4))
|
||||||
|
} else if len > 0 {
|
||||||
|
lo := *bytes
|
||||||
|
mid := *(bytes + len / 2)
|
||||||
|
hi := *(bytes + len - 1)
|
||||||
|
s0 ^= lo
|
||||||
|
s1 ^= @as(uint, hi) << 8 | mid
|
||||||
|
}
|
||||||
|
self.accumulator = folded_multiply(s0, s1)
|
||||||
|
} else if len < 256 {
|
||||||
|
self.accumulator = @inline(hash_bytes_medium, bytes, len, s0, s1, self.fold_seed)
|
||||||
|
} else {
|
||||||
|
self.accumulator = @inline(hash_bytes_long, bytes, len, s0, s1, self.expand_seed2, self.expand_seed3, self.fold_seed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
finish := fn(self: ^Self): uint {
|
||||||
|
if self.sponge_len > 0 {
|
||||||
|
return folded_multiply(self.sponge.b ^ self.accumulator, self.sponge.a ^ self.fold_seed)
|
||||||
|
} else {
|
||||||
|
return self.accumulator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reset := fn(self: ^Self): void {
|
||||||
|
self.accumulator = self.original_seed
|
||||||
|
self.sponge = .(0, 0)
|
||||||
|
self.sponge_len = 0
|
||||||
|
}
|
||||||
|
}
|
2
sysdata/libraries/stn/src/hash/lib.hb
Normal file
2
sysdata/libraries/stn/src/hash/lib.hb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
//! NON CRYPTOGRAPHIC HASHER
|
||||||
|
foldhash := @use("foldhash.hb")
|
|
@ -1,4 +1,7 @@
|
||||||
acs := @use("acs.hb")
|
acs := @use("acs.hb")
|
||||||
|
allocators := @use("alloc/lib.hb")
|
||||||
|
fmt := @use("fmt.hb")
|
||||||
|
hashers := @use("hash/lib.hb")
|
||||||
string := @use("string.hb")
|
string := @use("string.hb")
|
||||||
log := @use("log.hb")
|
log := @use("log.hb")
|
||||||
memory := @use("memory.hb")
|
memory := @use("memory.hb")
|
||||||
|
@ -8,13 +11,56 @@ random := @use("random.hb")
|
||||||
file := @use("file_io.hb")
|
file := @use("file_io.hb")
|
||||||
dt := @use("dt.hb")
|
dt := @use("dt.hb")
|
||||||
process := @use("process.hb")
|
process := @use("process.hb")
|
||||||
|
sleep := @use("sleep.hb")
|
||||||
|
|
||||||
panic := fn(message: ?^u8): never {
|
panic := fn(message: ?[]u8): never {
|
||||||
log.error("Error: Panic Called, Message:\0")
|
log.printf("HBLang Panic: {}", message, .{log: .Error})
|
||||||
if message == null {
|
|
||||||
log.error("None\0")
|
|
||||||
} else {
|
|
||||||
log.error(message)
|
|
||||||
}
|
|
||||||
die
|
die
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kind := enum {
|
||||||
|
Builtin,
|
||||||
|
Struct,
|
||||||
|
Tuple,
|
||||||
|
Enum,
|
||||||
|
Union,
|
||||||
|
Pointer,
|
||||||
|
Slice,
|
||||||
|
Opt,
|
||||||
|
Function,
|
||||||
|
Template,
|
||||||
|
Global,
|
||||||
|
Const,
|
||||||
|
Module,
|
||||||
|
$of := fn($T: type): Self {
|
||||||
|
return @bitcast(@kindof(T))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$unsigned_int := fn($T: type): bool {
|
||||||
|
return T == uint | T == u8 | T == u16 | T == u32
|
||||||
|
}
|
||||||
|
|
||||||
|
$signed_int := fn($T: type): bool {
|
||||||
|
return T == int | T == i8 | T == i16 | T == i32
|
||||||
|
}
|
||||||
|
|
||||||
|
$integer := fn($T: type): bool {
|
||||||
|
return unsigned_int(T) | signed_int(T)
|
||||||
|
}
|
||||||
|
|
||||||
|
$float := fn($T: type): bool {
|
||||||
|
return T == f32 | T == f64
|
||||||
|
}
|
||||||
|
|
||||||
|
$usize := fn($T: type): type {
|
||||||
|
if @sizeof(T) == 1 return u8 else if @sizeof(T) == 2 return u16 else if @sizeof(T) == 4 return u32 else return uint
|
||||||
|
}
|
||||||
|
|
||||||
|
$bits := fn($T: type): usize(T) {
|
||||||
|
return @sizeof(T) << 3
|
||||||
|
}
|
||||||
|
|
||||||
|
$bitmask := fn($T: type): usize(T) {
|
||||||
|
return -1
|
||||||
|
}
|
|
@ -1,13 +1,41 @@
|
||||||
string := @use("string.hb")
|
.{string, fmt, memory} := @use("stn")
|
||||||
|
|
||||||
LogMsg := packed struct {level: u8, string: ^u8, strlen: uint}
|
LogMsg := packed struct {level: LogLevel, string: ^u8, strlen: uint}
|
||||||
|
|
||||||
log := fn(level: u8, message: ^u8): void {
|
LogLevel := enum {
|
||||||
return @eca(3, 1, LogMsg.(level, message, @inline(string.length, message)), @sizeof(LogMsg))
|
Error,
|
||||||
|
Warn,
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
Trace,
|
||||||
}
|
}
|
||||||
|
|
||||||
error := fn(message: ^u8): void return @inline(log, 0, message)
|
$log := fn(level: LogLevel, message: []u8): void {
|
||||||
warn := fn(message: ^u8): void return @inline(log, 1, message)
|
return @eca(3, 1, LogMsg.(level, message.ptr, message.len), @sizeof(LogMsg))
|
||||||
info := fn(message: ^u8): void return @inline(log, 2, message)
|
}
|
||||||
debug := fn(message: ^u8): void return @inline(log, 3, message)
|
|
||||||
trace := fn(message: ^u8): void return @inline(log, 4, message)
|
$error := fn(message: []u8): void return log(LogLevel.Error, message)
|
||||||
|
$warn := fn(message: []u8): void return log(LogLevel.Warn, message)
|
||||||
|
$info := fn(message: []u8): void return log(LogLevel.Info, message)
|
||||||
|
$debug := fn(message: []u8): void return log(LogLevel.Debug, message)
|
||||||
|
$trace := fn(message: []u8): void return log(LogLevel.Trace, message)
|
||||||
|
|
||||||
|
print_buffer := memory.dangling(u8)
|
||||||
|
|
||||||
|
print := fn(v: @Any(), opts: fmt.FormatOptions): void {
|
||||||
|
if print_buffer == memory.dangling(u8) {
|
||||||
|
print_buffer = memory.request_page(1, false)
|
||||||
|
}
|
||||||
|
len := @inline(fmt.format, v, print_buffer[0..memory.PAGE_SIZE], opts)
|
||||||
|
@eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg))
|
||||||
|
memory.set(u8, &0, print_buffer, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
printf := fn(str: []u8, v: @Any(), opts: fmt.FormatOptions): void {
|
||||||
|
if print_buffer == memory.dangling(u8) {
|
||||||
|
print_buffer = memory.request_page(1, false)
|
||||||
|
}
|
||||||
|
len := @inline(fmt.format_with_str, v, str, print_buffer[0..memory.PAGE_SIZE], opts)
|
||||||
|
@eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg))
|
||||||
|
memory.set(u8, &0, print_buffer, len)
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -1,8 +1,10 @@
|
||||||
$PAGE_SIZE := 4096
|
$PAGE_SIZE := 4096
|
||||||
$MAX_ALLOC := 0xFF
|
|
||||||
$MAX_FREE := 0xFF
|
|
||||||
|
|
||||||
$uninit := fn($Expr: type): ?Expr {
|
$uninit := fn($Expr: type): Expr {
|
||||||
|
return idk
|
||||||
|
}
|
||||||
|
|
||||||
|
$nulled := fn($Expr: type): ?Expr {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,37 +13,30 @@ $dangling := fn($Expr: type): ^Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
$calc_pages := fn($Expr: type, num: uint): uint {
|
$calc_pages := fn($Expr: type, num: uint): uint {
|
||||||
return 1 + @sizeof(Expr) * num / PAGE_SIZE
|
return (num + PAGE_SIZE - 1) / PAGE_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! will be replaced, don't get attached
|
// ! will be replaced, don't get attached
|
||||||
alloc := fn($Expr: type, num: uint): ^Expr {
|
$alloc := fn($Expr: type, num: uint): ^Expr {
|
||||||
pages := calc_pages(Expr, num)
|
return @bitcast(request_page(calc_pages(Expr, num * @sizeof(Expr)), false))
|
||||||
if pages <= MAX_ALLOC {
|
}
|
||||||
return @bitcast(request_page(@intcast(pages)))
|
|
||||||
}
|
$alloc_zeroed := fn($Expr: type, num: uint): ^Expr {
|
||||||
ptr := request_page(MAX_ALLOC)
|
return @bitcast(request_page(calc_pages(Expr, num * @sizeof(Expr)), true))
|
||||||
remaining := pages - MAX_ALLOC
|
|
||||||
loop if remaining < MAX_ALLOC break else {
|
|
||||||
_ = request_page(MAX_ALLOC)
|
|
||||||
remaining -= MAX_ALLOC
|
|
||||||
}
|
|
||||||
_ = request_page(@intcast(remaining))
|
|
||||||
return @bitcast(ptr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! stub
|
// ! stub
|
||||||
$free := fn($Expr: type, ptr: ^Expr, num: uint, nullify: bool): void {
|
$free := fn($Expr: type, ptr: ^Expr, num: uint): void {
|
||||||
return
|
release_page(@bitcast(ptr), calc_pages(Expr, num * @sizeof(Expr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
RqPageMsg := packed struct {a: u8, count: u8}
|
RqPageMsg := packed struct {a: u8, count: uint, zeroed: bool}
|
||||||
$request_page := fn(count: u8): ^u8 {
|
$request_page := fn(count: uint, zeroed: bool): ^u8 {
|
||||||
return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg))
|
return @eca(3, 2, &RqPageMsg.(0, count, zeroed), @sizeof(RqPageMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
RlPageMsg := packed struct {a: u8, count: u8, ptr: ^u8}
|
RlPageMsg := packed struct {a: u8, count: uint, ptr: ^u8}
|
||||||
$release_page := fn(ptr: ^u8, count: u8): void {
|
$release_page := fn(ptr: ^u8, count: uint): void {
|
||||||
return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg))
|
return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +60,26 @@ $inl := fn(addr: u16): u32 {
|
||||||
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
|
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyMsg := packed struct {a: u8, count: u32, src: ^u8, dest: ^u8}
|
OutsMsg := packed struct {a: u8, b: u8, addr: u16, value: u16}
|
||||||
$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
$outs := fn(addr: u16, value: u32): void {
|
||||||
return @eca(3, 2, &CopyMsg.(4, @intcast(count * @sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
|
return @eca(3, 3, &OutsMsg.(1, 1, addr, value), @sizeof(OutsMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8}
|
InsMsg := packed struct {a: u8, b: u8, addr: u16}
|
||||||
$set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
$ins := fn(addr: u16): u16 {
|
||||||
return @eca(3, 2, &SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg))
|
return @eca(3, 3, &InsMsg.(0, 1, addr), @sizeof(InsMsg))
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyMsg := packed struct {a: u8, count: uint, src: ^u8, dest: ^u8}
|
||||||
|
$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
||||||
|
return @eca(3, 2, &CopyMsg.(4, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
|
||||||
|
}
|
||||||
|
|
||||||
|
SetMsg := packed struct {a: u8, count: uint, size: uint, src: ^u8, dest: ^u8}
|
||||||
|
$set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
||||||
|
return @eca(3, 2, &SetMsg.(5, count, @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg))
|
||||||
|
}
|
||||||
|
|
||||||
|
$move := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
|
||||||
|
return @eca(3, 2, &CopyMsg.(7, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))
|
||||||
}
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
// ! will be rewritten to take a file object when filesystem is exist
|
|
||||||
// returns PID
|
// returns PID
|
||||||
$spawn := fn(proc_exe: ^u8, length: uint): uint {
|
$spawn := fn(proc_exe: ^u8, length: uint): uint {
|
||||||
return @eca(3, 6, proc_exe, length)
|
return @eca(3, 6, proc_exe, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns: 0 if child process, child PID if parent process
|
||||||
|
$fork := fn(): uint return @eca(3, 7)
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
- Spawn an empty process
|
- Spawn an empty process
|
||||||
- Call a function to load bytes into that process from a function
|
- Call a function to load bytes into that process from a function
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
subscribe_to_interrupt := fn(interrupt_number: u8): bool {
|
$subscribe_to_interrupt := fn(interrupt_number: u8): bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// Pauses execution until the interrupt occures
|
// Pauses execution until the interrupt occures
|
||||||
sleep_until_interrupt := fn(interrupt_number: u8): void {
|
$sleep_until_interrupt := fn(interrupt_number: u8): void {
|
||||||
|
@eca(6, interrupt_number)
|
||||||
}
|
}
|
|
@ -1,216 +1,172 @@
|
||||||
length := fn(ptr: ^u8): uint {
|
// todo: splice function
|
||||||
len := 0
|
|
||||||
loop if *(ptr + len) == 0 return len else len += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
display_int := fn(num: int, p: ^u8, radix: uint): ^u8 {
|
reverse := fn(str: []u8): void {
|
||||||
is_negative := num < 0
|
if str.len == 0 return;
|
||||||
if is_negative num = -num
|
j := str.len - 1
|
||||||
|
i := 0
|
||||||
ptr := p
|
|
||||||
|
|
||||||
if num == 0 {
|
|
||||||
*ptr = 0x30;
|
|
||||||
*(ptr + 1) = 0
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
loop if num == 0 break else {
|
|
||||||
remainder := num % @bitcast(radix)
|
|
||||||
num /= @bitcast(radix);
|
|
||||||
*ptr = @intcast(remainder + 0x30)
|
|
||||||
if remainder > 9 {
|
|
||||||
*ptr = @intcast(remainder - 10 + 0x41)
|
|
||||||
}
|
|
||||||
ptr += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_negative {
|
|
||||||
*ptr = 0x2D
|
|
||||||
ptr += 1
|
|
||||||
}
|
|
||||||
// ! it gets broked when you do this ??
|
|
||||||
// *ptr = 0
|
|
||||||
|
|
||||||
@inline(reverse, p)
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
reverse := fn(s: ^u8): void {
|
|
||||||
j := s + @inline(length, s) - 1
|
|
||||||
temp := @as(u8, 0)
|
temp := @as(u8, 0)
|
||||||
loop if s < j {
|
loop if i < j {
|
||||||
temp = *s;
|
temp = str[i]
|
||||||
*s = *j;
|
str[i] = str[j]
|
||||||
*j = temp
|
str[j] = temp
|
||||||
s += 1
|
i += 1
|
||||||
j -= 1
|
j -= 1
|
||||||
} else return
|
} else return
|
||||||
}
|
}
|
||||||
|
|
||||||
equals := fn(lhs: ^u8, rhs: ^u8): bool {
|
equals := fn(lhs: []u8, rhs: []u8): bool {
|
||||||
if lhs == rhs {
|
if lhs.len != rhs.len return false
|
||||||
return true
|
if lhs.ptr == rhs.ptr return true
|
||||||
|
i := 0
|
||||||
|
loop if i == lhs.len break else {
|
||||||
|
if lhs[i] != rhs[i] return false
|
||||||
|
i += 1
|
||||||
}
|
}
|
||||||
loop if *lhs != *rhs {
|
return true
|
||||||
return false
|
}
|
||||||
} else if *lhs == 0 {
|
|
||||||
return true
|
clear := fn(str: []u8): void {
|
||||||
|
i := 0
|
||||||
|
loop if i == str.len break else {
|
||||||
|
str[i] = 0
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
split_once := fn(haystack: []u8, needle: @Any()): ?struct {left: []u8, right: []u8} {
|
||||||
|
T := @TypeOf(needle)
|
||||||
|
i := 0
|
||||||
|
if T == []u8 {
|
||||||
|
if needle.len == 0 return null
|
||||||
|
loop {
|
||||||
|
if i + needle.len > haystack.len return null
|
||||||
|
if haystack[i] == needle[0] {
|
||||||
|
matches := true
|
||||||
|
n := 1
|
||||||
|
loop {
|
||||||
|
if n == needle.len break
|
||||||
|
if haystack[i + n] != needle[n] {
|
||||||
|
matches = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
n += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches return .(haystack[0..i], haystack[i + needle.len..])
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
} else if T == u8 {
|
||||||
|
loop {
|
||||||
|
if haystack[i] == needle {
|
||||||
|
return .(haystack[0..i], haystack[i + 1..])
|
||||||
|
} else if i == haystack.len return null
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
lhs += 1
|
@error("Type of needle must be []u8 or u8.")
|
||||||
rhs += 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear := fn(ptr: ^u8): void {
|
split := fn(iter: []u8, needle: @Any()): struct {
|
||||||
loop if *ptr == 0 break else {
|
str: []u8,
|
||||||
*ptr = 0
|
needle: @TypeOf(needle),
|
||||||
ptr += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
split_once := fn(haystack: ^u8, needle: u8): ?^u8 {
|
|
||||||
loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
split_once_str := fn(haystack: ^u8, needle: ^u8): ?^u8 {
|
|
||||||
if *needle == 0 return null
|
|
||||||
|
|
||||||
loop if *haystack == 0 return null else {
|
|
||||||
if *haystack == *needle {
|
|
||||||
h := haystack
|
|
||||||
n := needle
|
|
||||||
|
|
||||||
loop {
|
|
||||||
n += 1
|
|
||||||
h += 1
|
|
||||||
if *n == 0 {
|
|
||||||
return haystack
|
|
||||||
} else if *h == 0 | *h != *n {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
haystack += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Split := struct {
|
|
||||||
str: ^u8,
|
|
||||||
needle: u8,
|
|
||||||
done: bool,
|
done: bool,
|
||||||
}
|
|
||||||
|
|
||||||
split := fn(iter: ^u8, needle: u8): Split {
|
next := fn(self: ^Self): ?[]u8 {
|
||||||
return .(
|
if self.done return null;
|
||||||
iter,
|
|
||||||
needle,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
iter_split := fn(iter: ^Split): ?^u8 {
|
splits := split_once(self.str, self.needle)
|
||||||
if iter.done | *iter.str == 0 {
|
if splits != null {
|
||||||
return null
|
self.str = splits.right
|
||||||
}
|
return splits.left
|
||||||
|
|
||||||
next := split_once(iter.str + 1, iter.needle)
|
|
||||||
|
|
||||||
if next == null {
|
|
||||||
iter.done = true
|
|
||||||
return iter.str
|
|
||||||
}
|
|
||||||
s := iter.str
|
|
||||||
iter.str = next + 1
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
SplitStr := struct {
|
|
||||||
str: ^u8,
|
|
||||||
needle: ^u8,
|
|
||||||
done: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
split_str := fn(iter: ^u8, needle: ^u8): SplitStr {
|
|
||||||
return .(
|
|
||||||
iter,
|
|
||||||
needle,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
iter_split_str := fn(iter: ^SplitStr): ?^u8 {
|
|
||||||
if iter.done | *iter.str == 0 {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
next := split_once_str(iter.str, iter.needle)
|
|
||||||
|
|
||||||
if next == null {
|
|
||||||
iter.done = true
|
|
||||||
return iter.str
|
|
||||||
}
|
|
||||||
|
|
||||||
s := iter.str
|
|
||||||
|
|
||||||
iter.str = next + length(iter.needle)
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
find_once := fn(haystack: ^u8, needle: u8): ?uint {
|
|
||||||
return @bitcast(@inline(split_once, haystack, needle) - haystack)
|
|
||||||
}
|
|
||||||
|
|
||||||
find_once_str := fn(haystack: ^u8, needle: ^u8): ?uint {
|
|
||||||
return @bitcast(@inline(split_once_str, haystack, needle) - haystack)
|
|
||||||
}
|
|
||||||
|
|
||||||
count := fn(haystack: ^u8, needle: ^u8): uint {
|
|
||||||
c := 0
|
|
||||||
loop if *haystack == needle {
|
|
||||||
c += 1
|
|
||||||
haystack += 1
|
|
||||||
} else if *haystack == 0 return c else haystack += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
count_str := fn(haystack: ^u8, needle: ^u8): uint {
|
|
||||||
if *needle == 0 return 0
|
|
||||||
c := 0
|
|
||||||
loop if *haystack == 0 return c else {
|
|
||||||
if *haystack == *needle {
|
|
||||||
h := haystack
|
|
||||||
n := needle
|
|
||||||
|
|
||||||
loop {
|
|
||||||
n += 1
|
|
||||||
h += 1
|
|
||||||
if *n == 0 {
|
|
||||||
c += 1
|
|
||||||
break
|
|
||||||
} else if *h == 0 | *h != *n {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
haystack += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
left_trim := fn(str: ^u8, sub: ^u8): ^u8 {
|
|
||||||
original := str
|
|
||||||
if *str == *sub {
|
|
||||||
loop if *sub == 0 {
|
|
||||||
return str
|
|
||||||
} else if *str != *sub {
|
|
||||||
return original
|
|
||||||
} else if *str == 0 {
|
|
||||||
return original
|
|
||||||
} else {
|
} else {
|
||||||
str += 1
|
self.done = true
|
||||||
sub += 1
|
return self.str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
T := @TypeOf(needle)
|
||||||
|
if T != []u8 & T != u8 {
|
||||||
|
@error("Type of needle must be []u8 or u8.")
|
||||||
|
}
|
||||||
|
return .(iter, needle, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
chars := fn(iter: []u8): struct {
|
||||||
|
str: []u8,
|
||||||
|
|
||||||
|
next := fn(self: ^Self): ?u8 {
|
||||||
|
if self.str.len == 0 return null
|
||||||
|
self.str = self.str[1..]
|
||||||
|
return self.str[0]
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
return .(iter)
|
||||||
|
}
|
||||||
|
|
||||||
|
count := fn(haystack: []u8, needle: @Any()): uint {
|
||||||
|
T := @TypeOf(needle)
|
||||||
|
i := 0
|
||||||
|
c := 0
|
||||||
|
if T == []u8 {
|
||||||
|
if needle.len == 0 return null
|
||||||
|
loop {
|
||||||
|
if i + needle.len > haystack.len return c
|
||||||
|
if haystack[i] == needle[0] {
|
||||||
|
matches := true
|
||||||
|
n := 1
|
||||||
|
loop {
|
||||||
|
if n == needle.len break
|
||||||
|
if haystack[i + n] != needle[n] {
|
||||||
|
matches = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
n += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches c += 1
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
} else if T == u8 {
|
||||||
|
loop {
|
||||||
|
if haystack[i] == needle c += 1 else if i == haystack.len return c
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
@error("Type of needle must be []u8 or u8.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
left_trim := fn(str: []u8, sub: []u8): []u8 {
|
||||||
|
i := 0
|
||||||
|
if str[0] == sub[0] {
|
||||||
|
loop if i == sub.len {
|
||||||
|
return str[i..str.len]
|
||||||
|
} else if str[i] != sub[i] | i == str.len {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
i += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
right_trim := fn(str: []u8, sub: []u8): []u8 {
|
||||||
|
i := 0
|
||||||
|
if str[str.len - 1] == sub[sub.len - 1] {
|
||||||
|
loop if i == sub.len {
|
||||||
|
return str[0..str.len - i]
|
||||||
|
} else if str[str.len - i - 1] != sub[sub.len - i - 1] | i == str.len {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
trim := fn(str: []u8, sub: []u8): []u8 {
|
||||||
|
return right_trim(left_trim(str, sub), sub)
|
||||||
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
.{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb");
|
.{math: .{Vec2}, buffer, log, memory, string} := @use("stn");
|
||||||
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb");
|
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("lib:sunset_proto");
|
||||||
.{new_surface, Color} := @use("../../render/src/lib.hb")
|
.{Surface, Color} := @use("lib:render")
|
||||||
|
|
||||||
// ! in the future this should be safely handled
|
// ! in the future this should be safely handled
|
||||||
channel := Channel.(0, 0)
|
channel := Channel.(0, 0)
|
||||||
|
|
||||||
find_server := fn(): void {
|
find_server := fn(): void {
|
||||||
log.info("client: locating server\0")
|
log.info("client: locating server")
|
||||||
channel2 := await_channel()
|
channel2 := await_channel()
|
||||||
channel.server = channel2.server
|
channel.server = channel2.server
|
||||||
channel.client = channel2.client
|
channel.client = channel2.client
|
||||||
log.info("client: server located\0")
|
log.info("client: server located")
|
||||||
}
|
}
|
||||||
|
|
||||||
new := fn(props: WindowProps): ?Window {
|
new := fn(props: WindowProps): ?Window {
|
||||||
|
@ -19,14 +19,14 @@ new := fn(props: WindowProps): ?Window {
|
||||||
if response.header.kind != message.ack {
|
if response.header.kind != message.ack {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
log.info("client: recv ack\0")
|
log.info("client: recv ack")
|
||||||
send_message(WindowProps, message.props, props, response.body.server)
|
send_message(WindowProps, message.props, props, response.body.server)
|
||||||
windowdata := await_message(WindowData, response.body.client)
|
windowdata := await_message(WindowData, response.body.client)
|
||||||
if windowdata.header.kind != message.ack {
|
if windowdata.header.kind != message.ack {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
log.info("client: recv windowdata\0")
|
log.info("client: recv windowdata")
|
||||||
surface := new_surface(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
|
surface := Surface.new(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
|
||||||
return .(windowdata.body, surface)
|
return .(windowdata.body, surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb");
|
.{math: .{Vec2}, buffer, memory} := @use("stn");
|
||||||
.{Surface} := @use("../../render/src/lib.hb")
|
.{Surface} := @use("lib:render")
|
||||||
|
|
||||||
$BUFFER_SERVER := "sunset_server\0"
|
$BUFFER_SERVER := "sunset_server"
|
||||||
$BUFFER_CLIENT := "sunset_client\0"
|
$BUFFER_CLIENT := "sunset_client"
|
||||||
|
|
||||||
Channel := packed struct {
|
Channel := packed struct {
|
||||||
client: uint,
|
client: uint,
|
||||||
|
@ -48,6 +48,8 @@ await_channel := fn(): Channel {
|
||||||
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
||||||
response := @as(?Message(Expr), null)
|
response := @as(?Message(Expr), null)
|
||||||
loop {
|
loop {
|
||||||
|
// awaiting here causes flickering... idk why
|
||||||
|
buffer.await(buffer_id)
|
||||||
buffer.recv(?Message(Expr), buffer_id, &response)
|
buffer.recv(?Message(Expr), buffer_id, &response)
|
||||||
if response != null {
|
if response != null {
|
||||||
return @as(Message(Expr), response)
|
return @as(Message(Expr), response)
|
||||||
|
@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
|
||||||
await_header := fn(buffer_id: uint): MessageHeader {
|
await_header := fn(buffer_id: uint): MessageHeader {
|
||||||
response := @as(?MessageHeader, null)
|
response := @as(?MessageHeader, null)
|
||||||
loop {
|
loop {
|
||||||
|
// awaiting here causes flickering... idk why
|
||||||
|
buffer.await(buffer_id)
|
||||||
buffer.recv(?MessageHeader, buffer_id, &response)
|
buffer.recv(?MessageHeader, buffer_id, &response)
|
||||||
if response != null {
|
if response != null {
|
||||||
return @as(?MessageHeader, response)
|
return @as(MessageHeader, response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,8 +85,7 @@ Message := fn($Expr: type): type {
|
||||||
WindowProps := struct {
|
WindowProps := struct {
|
||||||
position: Vec2(uint),
|
position: Vec2(uint),
|
||||||
dimensions: Vec2(uint),
|
dimensions: Vec2(uint),
|
||||||
// ! replace with owned string type later
|
title: []u8,
|
||||||
title: ^u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowData := struct {
|
WindowData := struct {
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb");
|
.{math, log, string, random, buffer, memory} := @use("stn");
|
||||||
.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text, clear, white, black} := @use("../../render/src/lib.hb");
|
.{Color, Surface, text} := @use("lib:render");
|
||||||
.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb")
|
.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("lib:sunset_proto")
|
||||||
|
|
||||||
WindowServer := struct {
|
WindowServer := struct {
|
||||||
window_count: uint,
|
window_count: uint,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
// ! replace this with a collection when we get an allocator
|
// ! replace this with a collection when we get an allocator
|
||||||
windows: [?Window; 10],
|
windows: [10]?Window,
|
||||||
font: text.Font,
|
font: text.Font,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! in the future this should be safely handled
|
// ! in the future this should be safely handled
|
||||||
server := @as(WindowServer, idk)
|
server := @as(WindowServer, idk)
|
||||||
|
|
||||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
|
|
||||||
start := fn(): void {
|
start := fn(): void {
|
||||||
font := text.font_from_psf2(@bitcast(&psf), false)
|
font := text.font_from_psf2(@bitcast(&psf), false)
|
||||||
if font == null {
|
if font == null {
|
||||||
log.error("server: failed to load asset\0")
|
log.error("server: failed to load asset")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
server = .(
|
server = .(
|
||||||
0,
|
0,
|
||||||
.{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)},
|
.{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)},
|
||||||
.(null, null, null, null, null, null, null, null, null, null),
|
.[null, null, null, null, null, null, null, null, null, null],
|
||||||
@as(text.Font, font),
|
@as(text.Font, font),
|
||||||
)
|
)
|
||||||
log.info("server: started server\0")
|
log.info("server: started server")
|
||||||
}
|
}
|
||||||
|
|
||||||
incoming := fn(): bool {
|
incoming := fn(): bool {
|
||||||
|
@ -36,14 +36,14 @@ incoming := fn(): bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if msg.kind == message.syn {
|
if msg.kind == message.syn {
|
||||||
log.info("server: recv syn\0")
|
log.info("server: recv syn")
|
||||||
channel := Channel.(buffer.create_nameless(), buffer.create_nameless())
|
channel := Channel.(buffer.create_nameless(), buffer.create_nameless())
|
||||||
send_message(Channel, message.ack, channel, server.channel.client)
|
send_message(Channel, message.ack, channel, server.channel.client)
|
||||||
props := await_message(WindowProps, channel.server)
|
props := await_message(WindowProps, channel.server)
|
||||||
if props.header.kind != message.props {
|
if props.header.kind != message.props {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
log.info("server: recv props\0")
|
log.info("server: recv props")
|
||||||
// ! do inspection of requested props here
|
// ! do inspection of requested props here
|
||||||
data := WindowData.(props.body, channel, permissions.default)
|
data := WindowData.(props.body, channel, permissions.default)
|
||||||
send_message(WindowData, message.ack, data, channel.client)
|
send_message(WindowData, message.ack, data, channel.client)
|
||||||
|
@ -51,17 +51,16 @@ incoming := fn(): bool {
|
||||||
// decorations
|
// decorations
|
||||||
{
|
{
|
||||||
title := data.props.title
|
title := data.props.title
|
||||||
title_length := string.length(title)
|
deco_length := title.len * 10
|
||||||
deco_length := title_length * 10
|
|
||||||
// draw the window tab bar
|
// draw the window tab bar
|
||||||
put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR)
|
surface.put_filled_rect(.(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR)
|
||||||
// Draw the window tab
|
// Draw the window tab
|
||||||
put_filled_rect(surface, .(0, 0), .(deco_length, DECO_HEIGHT_TOP - 1), DECO_COLOUR_DARKER)
|
surface.put_filled_rect(.(0, 0), .(deco_length, DECO_HEIGHT_TOP - 1), DECO_COLOUR_DARKER)
|
||||||
|
|
||||||
// Draw the outside box
|
// Draw the outside box
|
||||||
put_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH - 1, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM - 1), DECO_COLOUR)
|
surface.put_rect(.(0, 0), data.props.dimensions + .(DECO_WIDTH - 1, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM - 1), DECO_COLOUR)
|
||||||
|
|
||||||
put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title)
|
surface.put_text(server.font, .(2, 1), .(0, 0, 0, 255), data.props.title)
|
||||||
}
|
}
|
||||||
server.windows[server.window_count] = .(data, surface)
|
server.windows[server.window_count] = .(data, surface)
|
||||||
server.window_count += 1
|
server.window_count += 1
|
||||||
|
@ -76,10 +75,7 @@ $DECO_COLOUR := Color.(100, 200, 255, 255)
|
||||||
$DECO_COLOUR_DARKER := Color.(89, 57, 89, 255)
|
$DECO_COLOUR_DARKER := Color.(89, 57, 89, 255)
|
||||||
|
|
||||||
new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface {
|
new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface {
|
||||||
return new_surface(
|
return @inline(Surface.new, dimensions.x + DECO_WIDTH, dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM)
|
||||||
dimensions.x + DECO_WIDTH,
|
|
||||||
dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! compositor code. this currently disallows tearing.
|
// ! compositor code. this currently disallows tearing.
|
||||||
|
@ -104,10 +100,10 @@ collect_frames := fn(): void {
|
||||||
send_header(message.ack, window.data.channel.client)
|
send_header(message.ack, window.data.channel.client)
|
||||||
ptr := await_message(^Color, window.data.channel.server)
|
ptr := await_message(^Color, window.data.channel.server)
|
||||||
if ptr.header.kind != message.ack {
|
if ptr.header.kind != message.ack {
|
||||||
return
|
i += 1
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
put_surface(
|
window.surface.put_surface(
|
||||||
window.surface,
|
|
||||||
Surface.(
|
Surface.(
|
||||||
ptr.body,
|
ptr.body,
|
||||||
window.data.props.dimensions.x,
|
window.data.props.dimensions.x,
|
||||||
|
@ -129,7 +125,7 @@ render_clients := fn(screen: Surface): void {
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
put_surface(screen, window.surface, window.data.props.position, false)
|
screen.put_surface(window.surface, window.data.props.position, false)
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
1
sysdata/programs/ablefetch/README.md
Normal file
1
sysdata/programs/ablefetch/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# ablefetch
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "serial_driver_test"
|
name = "ablefetch"
|
||||||
authors = ["able"]
|
authors = [""]
|
||||||
|
|
||||||
[dependants.libraries]
|
[dependants.libraries]
|
||||||
|
|
43
sysdata/programs/ablefetch/src/main.hb
Normal file
43
sysdata/programs/ablefetch/src/main.hb
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
stn := @use("stn")
|
||||||
|
sunset := @use("lib:sunset_proto")
|
||||||
|
render := @use("lib:render")
|
||||||
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
|
horizon_api := @use("lib:horizon_api");
|
||||||
|
|
||||||
|
.{Vec2} := stn.math;
|
||||||
|
.{log} := stn;
|
||||||
|
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
||||||
|
|
||||||
|
main := fn(): void {
|
||||||
|
sunset.client.find_server()
|
||||||
|
|
||||||
|
window := sunset.client.new(.(.(10, 10), .(400, 300), "ableFetch!"))
|
||||||
|
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
|
||||||
|
// pos := Vec2(uint).(1, 100)
|
||||||
|
|
||||||
|
if window == null {
|
||||||
|
log.error("got no window")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
text_label := Label.new_label("kernel : akern 0.2.0", 300)
|
||||||
|
text_label_2 := Label.new_label("os : ableos", 300)
|
||||||
|
text_label_3 := Label.new_label("wm : sunset", 300)
|
||||||
|
text_label.set_color(render.BLACK, render.WHITE)
|
||||||
|
|
||||||
|
text_label_2.set_color(render.BLACK, render.WHITE)
|
||||||
|
text_label_3.set_color(render.BLACK, render.WHITE)
|
||||||
|
|
||||||
|
pos1 := Vec2(uint).(1, 1)
|
||||||
|
pos2 := Vec2(uint).(1, 20)
|
||||||
|
pos3 := Vec2(uint).(1, 40)
|
||||||
|
|
||||||
|
render_label_to_surface(window.surface, text_label, font, pos1)
|
||||||
|
render_label_to_surface(window.surface, text_label_2, font, pos2)
|
||||||
|
render_label_to_surface(window.surface, text_label_3, font, pos3)
|
||||||
|
loop {
|
||||||
|
// stn.log.info("AAAA")
|
||||||
|
_ = sunset.client.send_frame(window)
|
||||||
|
// stn.sleep.sleep_until_interrupt(100)
|
||||||
|
}
|
||||||
|
}
|
5
sysdata/programs/angels_halo/README.md
Normal file
5
sysdata/programs/angels_halo/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# angels_halo
|
||||||
|
|
||||||
|
A Minix 3 style reincarnation service.
|
||||||
|
|
||||||
|
Running in the background restarting your drivers.
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "dt_buffer_test"
|
name = "angels_halo"
|
||||||
authors = ["able"]
|
authors = ["able"]
|
||||||
|
|
||||||
[dependants.libraries]
|
[dependants.libraries]
|
7
sysdata/programs/angels_halo/pkg.lisp
Normal file
7
sysdata/programs/angels_halo/pkg.lisp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
(pkg angels-halo
|
||||||
|
(authors ("able"))
|
||||||
|
(version 0 1 0))
|
||||||
|
|
||||||
|
(dependencies
|
||||||
|
(libraries ())
|
||||||
|
(programs (hblang)))
|
18
sysdata/programs/angels_halo/src/main.hb
Normal file
18
sysdata/programs/angels_halo/src/main.hb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
stn := @use("stn");
|
||||||
|
.{log} := stn;
|
||||||
|
.{ProcessID} := stn.acs
|
||||||
|
|
||||||
|
Strategy := enum {
|
||||||
|
None,
|
||||||
|
Restart,
|
||||||
|
}
|
||||||
|
|
||||||
|
MonitoredProcess := struct {
|
||||||
|
pid: ProcessID,
|
||||||
|
}
|
||||||
|
|
||||||
|
main := fn(): int {
|
||||||
|
log.info("Angels Halo reincarnation server started.")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -1,13 +1,111 @@
|
||||||
.{memory, buffer} := @use("../../../libraries/stn/src/lib.hb")
|
.{memory: .{inb, outb, ins, alloc}, log} := @use("stn")
|
||||||
|
|
||||||
main := fn(): int {
|
$ATA_PRIMARY_DATA := 0x1F0
|
||||||
// shuts down ableOS
|
$ATA_PRIMARY_ERR := 0x1F1
|
||||||
// memory.outb(0xF400, 0)
|
$ATA_PRIMARY_SECCOUNT := 0x1F2
|
||||||
|
$ATA_PRIMARY_LBA_LO := 0x1F3
|
||||||
|
$ATA_PRIMARY_LBA_MID := 0x1F4
|
||||||
|
$ATA_PRIMARY_LBA_HI := 0x1F5
|
||||||
|
$ATA_PRIMARY_DRIVE_HEAD := 0x1F6
|
||||||
|
$ATA_PRIMARY_COMM_REGSTAT := 0x1F7
|
||||||
|
$ATA_PRIMARY_ALTSTAT_DCR := 0x3F6
|
||||||
|
|
||||||
a := memory.inb(0x4600)
|
$STAT_ERR := 1 << 0
|
||||||
b := memory.inb(0x4700)
|
$STAT_DRQ := 1 << 3
|
||||||
|
$STAT_SRV := 1 << 4
|
||||||
|
$STAT_DF := 1 << 5
|
||||||
|
$STAT_RDY := 1 << 6
|
||||||
|
$STAT_BSY := 1 << 7
|
||||||
|
|
||||||
c := buffer.search("XNumber\0")
|
Drive := enum {Master, Slave}
|
||||||
|
|
||||||
|
select_drive := fn(drive: Drive): void {
|
||||||
|
match drive {
|
||||||
|
.Master => outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0),
|
||||||
|
.Slave => outb(ATA_PRIMARY_DRIVE_HEAD, 0xB0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identify := fn(drive: Drive): u8 {
|
||||||
|
if inb(ATA_PRIMARY_COMM_REGSTAT) == 0xFF {
|
||||||
|
log.error("(ata: drive not present) status=0xFF")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
select_drive(drive)
|
||||||
|
inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
outb(ATA_PRIMARY_SECCOUNT, 0)
|
||||||
|
inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
outb(ATA_PRIMARY_LBA_LO, 0)
|
||||||
|
inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
outb(ATA_PRIMARY_LBA_MID, 0)
|
||||||
|
inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
outb(ATA_PRIMARY_LBA_HI, 0)
|
||||||
|
inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
outb(ATA_PRIMARY_COMM_REGSTAT, 0xEC)
|
||||||
|
outb(ATA_PRIMARY_COMM_REGSTAT, 0xE7)
|
||||||
|
|
||||||
|
status := inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
|
||||||
|
loop if (status & STAT_BSY) == 0 break else {
|
||||||
|
if DEBUG_PRINT log.printf("(ata: waiting for status) status={}", .(status), .{radix: 16, log: .Warn})
|
||||||
|
status = inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status == 0 {
|
||||||
|
log.error("(ata: drive not present) status=0")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
loop if (status & STAT_BSY) == 0 break else {
|
||||||
|
if DEBUG_PRINT log.printf("(ata: waiting for busy to end) status={}", .(status), .{radix: 16, log: .Warn})
|
||||||
|
status = inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
}
|
||||||
|
|
||||||
|
mid := inb(ATA_PRIMARY_LBA_MID)
|
||||||
|
hi := inb(ATA_PRIMARY_LBA_HI)
|
||||||
|
if (mid | hi) != 0 {
|
||||||
|
log.error("the drive is not ata...?")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
loop if (status & (STAT_ERR | STAT_DRQ)) != 0 break else {
|
||||||
|
if DEBUG_PRINT log.printf("(ata: waiting for ERR or DRQ) status={}", .(status), .{radix: 16, log: .Warn})
|
||||||
|
status = inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & STAT_ERR) != 0 {
|
||||||
|
if DEBUG_PRINT log.printf("(ata: drive error) status={}", .(status), .{radix: 16, log: .Error})
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if DEBUG_PRINT log.printf("status={}", .(status), .{radix: 16})
|
||||||
|
|
||||||
|
buffer := alloc(u16, 255)[0..255]
|
||||||
|
read(buffer)
|
||||||
|
|
||||||
|
if DEBUG_PRINT {
|
||||||
|
if (buffer[83] & 1 << 10) != 0 {
|
||||||
|
log.info("LBA48 mode supported")
|
||||||
|
log.printf("{} 48 bit addressable sectors", *@as(^uint, @bitcast(buffer[100..].ptr)), .{})
|
||||||
|
}
|
||||||
|
log.print(buffer, .{})
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read := fn(buffer: []u16): void {
|
||||||
|
i := 0
|
||||||
|
loop if i == buffer.len break else {
|
||||||
|
buffer[i] = ins(ATA_PRIMARY_DATA)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inflates asm a lot
|
||||||
|
$DEBUG_PRINT := true
|
||||||
|
|
||||||
|
main := fn(): void {
|
||||||
|
identify(.Master)
|
||||||
|
}
|
35
sysdata/programs/diskio_driver/src/regs.hb
Normal file
35
sysdata/programs/diskio_driver/src/regs.hb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// $ATA_PRIMARY_DATA := @intcast(0x1F0)
|
||||||
|
// $ATA_PRIMARY_ERR := @intcast(0x1F1)
|
||||||
|
// $ATA_PRIMARY_SECCOUNT := @intcast(0x1F2)
|
||||||
|
// $ATA_PRIMARY_LBA_LO := @intcast(0x1F3)
|
||||||
|
// $ATA_PRIMARY_LBA_MID := @intcast(0x1F4)
|
||||||
|
// $ATA_PRIMARY_LBA_HI := @intcast(0x1F5)
|
||||||
|
// $ATA_PRIMARY_DRIVE_HEAD := @intcast(0x1F6)
|
||||||
|
// $ATA_PRIMARY_COMM_REGSTAT := @intcast(0x1F7)
|
||||||
|
// $ATA_PRIMARY_ALTSTAT_DCR := @intcast(0x3F6)
|
||||||
|
|
||||||
|
$ATA_PRIMARY_IO := @intcast(0x1F0)
|
||||||
|
|
||||||
|
$ATA_PRIMARY_DEVCTL := @intcast(0x3F6)
|
||||||
|
$ATA_SECONDARY_DEVCTL := @intcast(0x3F6)
|
||||||
|
|
||||||
|
$ATA_REG_STAT := @intcast(0x7)
|
||||||
|
|
||||||
|
// // Indicates an error occurred. Send a new command to clear it
|
||||||
|
// STAT_ERR := 1 << 0
|
||||||
|
// // Set when the drive has PIO data to transfer, or is ready to accept PIO data.
|
||||||
|
// STAT_DRQ := 1 << 3
|
||||||
|
// // Overlapped Mode Service Request.
|
||||||
|
// STAT_SRV := 1 << 4
|
||||||
|
// // Drive Fault Error (does not set ERR).
|
||||||
|
// STAT_DF := 1 << 5
|
||||||
|
// // Bit is clear when drive is spun down, or after an error. Set otherwise.
|
||||||
|
// STAT_RDY := 1 << 6
|
||||||
|
// // Indicates the drive is preparing to send/receive data (wait for it to clear).
|
||||||
|
// // In case of 'hang' (it never clears), do a software reset.
|
||||||
|
// STAT_BSY := 1 << 7
|
||||||
|
|
||||||
|
$ATA_SR_BSY := 0x80
|
||||||
|
$ATA_SR_DF := 0x20
|
||||||
|
$ATA_SR_DRQ := 0x8
|
||||||
|
$ATA_SR_ERR := 0x1
|
|
@ -1 +0,0 @@
|
||||||
# dt_buffer_test
|
|
|
@ -1,13 +0,0 @@
|
||||||
.{dt} := @use("../../../libraries/stn/src/lib.hb")
|
|
||||||
|
|
||||||
main := fn(): void {
|
|
||||||
dt.get(void, "framebuffer/fb0/width\0")
|
|
||||||
dt.get(void, "cpu/cpu0/architecture\0")
|
|
||||||
|
|
||||||
// Checking if the first detected serial port is memory mapped or port mapped
|
|
||||||
// 0 -> memory mapped
|
|
||||||
// 1 -> port mapped
|
|
||||||
dt.get(void, "serial_ports/sp0/mapping\0")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
READ_ONLY := @as(u32, 0x1)
|
$READ_ONLY := 0x1
|
||||||
HIDDEN := @as(u32, 0x2)
|
$HIDDEN := 0x2
|
||||||
SYSTEM := @as(u32, 0x4)
|
$SYSTEM := 0x4
|
||||||
VOLUME_ID := @as(u32, 0x8)
|
$VOLUME_ID := 0x8
|
||||||
DIRECTORY := @as(u32, 0x10)
|
$DIRECTORY: 0x10
|
||||||
ARCHIVE := @as(u32, 0x20)
|
$ARCHIVE := 0x20
|
||||||
LFN := READ_ONLY | HIDDEN | SYSTEM | VOLUME_ID
|
LFN := READ_ONLY | HIDDEN | SYSTEM | VOLUME_ID
|
|
@ -1,19 +1,19 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{string, memory, buffer, log} := stn
|
.{string, memory, buffer, log} := stn
|
||||||
|
|
||||||
VALID_JUMP_BYTES := [u8].(0xEB, 0x3C, 0x90)
|
VALID_JUMP_BYTES := u8.[0xEB, 0x3C, 0x90]
|
||||||
|
|
||||||
OemIdent := struct {
|
OemIdent := struct {
|
||||||
dos_version: [u8; 8],
|
dos_version: [8]u8,
|
||||||
dos_version_name: [u8; 8],
|
dos_version_name: [8]u8,
|
||||||
}
|
|
||||||
|
|
||||||
new_oem_ident := fn(major: int, minor: int): OemIdent {
|
new := fn(major: int, minor: int): OemIdent {
|
||||||
return .(.(0, 0, 0, 0, 0, 0, 0, 0), .(0, 0, 0, 0, 0, 0, 0, 0))
|
return .(.[0, 0, 0, 0, 0, 0, 0, 0], .[0, 0, 0, 0, 0, 0, 0, 0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BiosParameterBlock := struct {
|
BiosParameterBlock := struct {
|
||||||
jump_bytes: [u8; 3],
|
jump_bytes: [3]u8,
|
||||||
oem_ident: OemIdent,
|
oem_ident: OemIdent,
|
||||||
bytes_per_sector: u16,
|
bytes_per_sector: u16,
|
||||||
sectors_per_cluster: u8,
|
sectors_per_cluster: u8,
|
||||||
|
@ -30,21 +30,21 @@ BiosParameterBlock := struct {
|
||||||
head_count: u16,
|
head_count: u16,
|
||||||
hidden_sectors: u32,
|
hidden_sectors: u32,
|
||||||
large_sector_count: u32,
|
large_sector_count: u32,
|
||||||
}
|
|
||||||
|
|
||||||
bpb_sanity_check := fn(bpb: BiosParameterBlock): int {
|
sanity_check := fn(bpb: BiosParameterBlock): int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
new_bpb := fn(): BiosParameterBlock {
|
new := fn(): BiosParameterBlock {
|
||||||
return .(VALID_JUMP_BYTES, new_oem_ident(0, 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
return .(VALID_JUMP_BYTES, OemIdent.new(0, 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
sector_count := fn(bpb: BiosParameterBlock): u32 {
|
sector_count := fn(bpb: BiosParameterBlock): u32 {
|
||||||
if bpb.total_sectors == 0 {
|
if bpb.total_sectors == 0 {
|
||||||
return bpb.large_sector_count
|
return bpb.large_sector_count
|
||||||
} else {
|
} else {
|
||||||
return bpb.total_sectors
|
return bpb.total_sectors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,16 +53,16 @@ FatVersionNumber := struct {
|
||||||
minor_version: u8,
|
minor_version: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
FormatReservation := [u8; 12]
|
FormatReservation := [12]u8
|
||||||
|
|
||||||
// Padded with spaces.
|
// Padded with spaces.
|
||||||
VolumeName := [u8; 11]
|
VolumeName := [11]u8
|
||||||
|
|
||||||
SystemIdentifierString := [u8; 8]
|
SystemIdentifierString := [8]u8
|
||||||
VALID_SYSTEM_IDENTIFIER_STRING := [u8].(46, 41, 54, 33, 32, 20, 20, 20)
|
VALID_SYSTEM_IDENTIFIER_STRING := u8.[46, 41, 54, 33, 32, 20, 20, 20]
|
||||||
BOOTABLE_PARTITION_SIGNATURE := @as(u32, 0xAA55)
|
BOOTABLE_PARTITION_SIGNATURE := @as(u32, 0xAA55)
|
||||||
|
|
||||||
BootCode := [u8; 420]
|
BootCode := [420]u8
|
||||||
|
|
||||||
ExtendedBootRecord := struct {
|
ExtendedBootRecord := struct {
|
||||||
sectors_per_fat: u32,
|
sectors_per_fat: u32,
|
||||||
|
@ -85,48 +85,48 @@ ExtendedBootRecord := struct {
|
||||||
system_identifier_string: SystemIdentifierString,
|
system_identifier_string: SystemIdentifierString,
|
||||||
boot_code: BootCode,
|
boot_code: BootCode,
|
||||||
partition_signature: u16,
|
partition_signature: u16,
|
||||||
}
|
|
||||||
|
|
||||||
ebr_sanity_check := fn(ebr: ExtendedBootRecord): int {
|
sanity_check := fn(ebr: ExtendedBootRecord): int {
|
||||||
ret := 0
|
ret := 0
|
||||||
if ebr.drive_number != 0x0 | ebr.drive_number != 0x80 {
|
if ebr.drive_number != 0x0 | ebr.drive_number != 0x80 {
|
||||||
log.warn("EBR-Drive-Number sanity check failed\0")
|
log.warn("EBR-Drive-Number sanity check failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ebr.signature != 0x28 | ebr.signature != 0x29 {
|
||||||
|
log.warn("EBR-Signature sanity check failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! comparison between [u8] is not supported in hblang
|
||||||
|
// if ebr.system_identifier_string != VALID_SYSTEM_IDENTIFIER_STRING {
|
||||||
|
// log.warn("EBR-Signature-Identifier-String sanity check failed")
|
||||||
|
// }
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if ebr.signature != 0x28 | ebr.signature != 0x29 {
|
new := fn(): ExtendedBootRecord {
|
||||||
log.warn("EBR-Signature sanity check failed\0")
|
version := FatVersionNumber.(0, 0)
|
||||||
|
fmt_res := u8.[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
vol_name := @as([11]u8, idk)
|
||||||
|
boot_code := @as([420]u8, idk)
|
||||||
|
|
||||||
|
return ExtendedBootRecord.(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
version,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
fmt_res,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
vol_name,
|
||||||
|
VALID_SYSTEM_IDENTIFIER_STRING,
|
||||||
|
boot_code,
|
||||||
|
0,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! comparison between [u8] is not supported in hblang
|
|
||||||
// if ebr.system_identifier_string != VALID_SYSTEM_IDENTIFIER_STRING {
|
|
||||||
// log.warn("EBR-Signature-Identifier-String sanity check failed\0")
|
|
||||||
// }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
new_ebr := fn(): ExtendedBootRecord {
|
|
||||||
version := FatVersionNumber.(0, 0)
|
|
||||||
fmt_res := FormatReservation.(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
||||||
vol_name := @as([u8; 11], idk)
|
|
||||||
boot_code := @as([u8; 420], idk)
|
|
||||||
|
|
||||||
return ExtendedBootRecord.(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
version,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
fmt_res,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
vol_name,
|
|
||||||
VALID_SYSTEM_IDENTIFIER_STRING,
|
|
||||||
boot_code,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALID_LEAD_FS_INFO := @as(u32, 0x41615252)
|
VALID_LEAD_FS_INFO := @as(u32, 0x41615252)
|
||||||
|
@ -135,45 +135,45 @@ VALID_TRAIL_FS_INFO := @as(u32, 0xAA550000)
|
||||||
FSInfo := struct {
|
FSInfo := struct {
|
||||||
// Must be 0x41615252 to indicate a valid FSInfo structure
|
// Must be 0x41615252 to indicate a valid FSInfo structure
|
||||||
lead_signature: u32,
|
lead_signature: u32,
|
||||||
lead_reserved: [u8; 480],
|
lead_reserved: [480]u8,
|
||||||
// If the value is 0xFFFFFFFF, then the free count is unknown and must be computed. However, this value might be incorrect and should at least be range checked (<= volume cluster count)
|
// If the value is 0xFFFFFFFF, then the free count is unknown and must be computed. However, this value might be incorrect and should at least be range checked (<= volume cluster count)
|
||||||
last_known_free_cluster_count: u32,
|
last_known_free_cluster_count: u32,
|
||||||
last_known_avalible_cluster: u32,
|
last_known_avalible_cluster: u32,
|
||||||
trail_reserved: [u8; 12],
|
trail_reserved: [12]u8,
|
||||||
trail_signature: u32,
|
trail_signature: u32,
|
||||||
}
|
|
||||||
|
|
||||||
fs_info_sanity_check := fn(fs_info: FSInfo): uint {
|
sanity_check := fn(fs_info: FSInfo): uint {
|
||||||
ret := 0
|
ret := 0
|
||||||
if fs_info.lead_signature != VALID_LEAD_FS_INFO {
|
if fs_info.lead_signature != VALID_LEAD_FS_INFO {
|
||||||
ret &= 1
|
ret &= 1
|
||||||
log.warn("Invalid leading signature in FSInfo.\0")
|
log.warn("Invalid leading signature in FSInfo.")
|
||||||
}
|
}
|
||||||
if fs_info.last_known_free_cluster_count == 0xFFFFFFFF {
|
if fs_info.last_known_free_cluster_count == 0xFFFFFFFF {
|
||||||
ret &= 2
|
ret &= 2
|
||||||
log.warn("Last known free cluster count unknown.\0")
|
log.warn("Last known free cluster count unknown.")
|
||||||
}
|
}
|
||||||
if fs_info.last_known_avalible_cluster == 0xFFFFFFFF {
|
if fs_info.last_known_avalible_cluster == 0xFFFFFFFF {
|
||||||
ret &= 4
|
ret &= 4
|
||||||
log.warn("Last known avalible cluster count unknown.\0")
|
log.warn("Last known avalible cluster count unknown.")
|
||||||
}
|
}
|
||||||
if fs_info.trail_signature != VALID_TRAIL_FS_INFO {
|
if fs_info.trail_signature != VALID_TRAIL_FS_INFO {
|
||||||
ret &= 8
|
ret &= 8
|
||||||
log.warn("Invalid trailing signature in FSInfo.\0")
|
log.warn("Invalid trailing signature in FSInfo.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
new := fn(): FSInfo {
|
||||||
}
|
lead_reserved := @as([480]u8, idk)
|
||||||
|
trail_reserved := @as([12]u8, idk)
|
||||||
new_fs_info := fn(): FSInfo {
|
return FSInfo.(
|
||||||
lead_reserved := @as([u8; 480], idk)
|
VALID_LEAD_FS_INFO,
|
||||||
trail_reserved := @as([u8; 12], idk)
|
lead_reserved,
|
||||||
return FSInfo.(
|
0,
|
||||||
VALID_LEAD_FS_INFO,
|
0,
|
||||||
lead_reserved,
|
trail_reserved,
|
||||||
0,
|
VALID_TRAIL_FS_INFO,
|
||||||
0,
|
)
|
||||||
trail_reserved,
|
}
|
||||||
VALID_TRAIL_FS_INFO,
|
|
||||||
)
|
|
||||||
}
|
}
|
|
@ -2,24 +2,25 @@ Date := struct {
|
||||||
year: u16,
|
year: u16,
|
||||||
month: u16,
|
month: u16,
|
||||||
day: u16,
|
day: u16,
|
||||||
|
|
||||||
|
compress_date := fn(year: u16, month: u16, day: u16): u16 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
decompress_date := fn(date: u16): Date {
|
||||||
|
return Date.(0, 0, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Time := struct {
|
Time := struct {
|
||||||
hour: u16,
|
hour: u16,
|
||||||
minutes: u16,
|
minutes: u16,
|
||||||
seconds: u16,
|
seconds: u16,
|
||||||
}
|
|
||||||
|
|
||||||
compress_date := fn(year: u16, month: u16, day: u16): u16 {
|
compress_time := fn(hour: u16, minutes: u16, seconds: u16): u16 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
decompress_date := fn(date: u16): Date {
|
|
||||||
return Date.(0, 0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
compress_time := fn(hour: u16, minutes: u16, seconds: u16): u16 {
|
decompress_time := fn(time: u16): Time {
|
||||||
return 0
|
return Time.(0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
decompress_time := fn(time: u16): Time {
|
|
||||||
return Time.(0, 0, 0)
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
attributes := @use("attributes.hb")
|
attributes := @use("attributes.hb")
|
||||||
datetime := @use("datetime.hb")
|
datetime := @use("datetime.hb")
|
||||||
|
|
||||||
FileName := [u8; 11]
|
FileName := [11]u8
|
||||||
|
|
||||||
// This is the File Allocation Table entry that tells us where on disk the File is.
|
// This is the File Allocation Table entry that tells us where on disk the File is.
|
||||||
FileEntry := struct {
|
FileEntry := struct {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{string, memory, buffer, log} := stn
|
.{string, memory, buffer, log} := stn
|
||||||
|
|
||||||
attributes := @use("attributes.hb")
|
attributes := @use("attributes.hb")
|
||||||
|
@ -6,19 +6,19 @@ datetime := @use("datetime.hb")
|
||||||
directory := @use("file.hb")
|
directory := @use("file.hb")
|
||||||
bios_parameter_block := @use("bios_parameter_block.hb");
|
bios_parameter_block := @use("bios_parameter_block.hb");
|
||||||
.{bpb_sanity_check, ebr_sanity_check, fs_info_sanity_check} := bios_parameter_block;
|
.{bpb_sanity_check, ebr_sanity_check, fs_info_sanity_check} := bios_parameter_block;
|
||||||
.{new_bpb, new_ebr, new_fs_info} := bios_parameter_block
|
.{BiosParameterBlock, ExtendedBootRecord, FSInfo} := bios_parameter_block
|
||||||
|
|
||||||
FAT12_THRESHOLD := 4085
|
$FAT12_THRESHOLD := 4085
|
||||||
FAT16_THRESHOLD := 65525
|
$FAT16_THRESHOLD := 65525
|
||||||
|
|
||||||
ExFAT := 0
|
$EXFAT := 0
|
||||||
FAT12 := 1
|
$FAT12 := 1
|
||||||
FAT16 := 2
|
$FAT16 := 2
|
||||||
FAT32 := 3
|
$FAT32 := 3
|
||||||
|
|
||||||
calculate_fat_type := fn(sector_size: uint, total_clusters: uint): uint {
|
calculate_fat_type := fn(sector_size: uint, total_clusters: uint): uint {
|
||||||
if sector_size == 0 {
|
if sector_size == 0 {
|
||||||
return ExFAT
|
return EXFAT
|
||||||
} else if total_clusters < 4085 {
|
} else if total_clusters < 4085 {
|
||||||
return FAT12
|
return FAT12
|
||||||
} else if total_clusters < 65525 {
|
} else if total_clusters < 65525 {
|
||||||
|
@ -29,19 +29,19 @@ calculate_fat_type := fn(sector_size: uint, total_clusters: uint): uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
bpb := new_bpb()
|
bpb := BiosParameterBlock.new()
|
||||||
ebr := new_ebr()
|
ebr := ExtendedBootRecord.new()
|
||||||
fsi := new_fs_info()
|
fsi := FSInfo.new()
|
||||||
|
|
||||||
fat_type := calculate_fat_type(1, 100)
|
fat_type := calculate_fat_type(1, 100)
|
||||||
|
|
||||||
if fat_type != FAT32 {
|
if fat_type != FAT32 {
|
||||||
log.warn("filesystem_fat32 driver only supports Fat32.\0")
|
log.warn("filesystem_fat32 driver only supports Fat32.")
|
||||||
}
|
}
|
||||||
|
|
||||||
bsc := bpb_sanity_check(bpb)
|
bsc := bpb.sanity_check()
|
||||||
esc := ebr_sanity_check(ebr)
|
esc := ebr.sanity_check()
|
||||||
fssc := fs_info_sanity_check(fsi)
|
fssc := fsi.sanity_check()
|
||||||
|
|
||||||
msg_type := 0
|
msg_type := 0
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ main := fn(): int {
|
||||||
// Open file
|
// Open file
|
||||||
if msg_type == 0 {
|
if msg_type == 0 {
|
||||||
// Paths without a node-disk component are to be treated as local files.
|
// Paths without a node-disk component are to be treated as local files.
|
||||||
file_path := "node-disk:/test\0"
|
file_path := "node-disk:/test"
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
5
sysdata/programs/hblang2/README.md
Normal file
5
sysdata/programs/hblang2/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# hblang²
|
||||||
|
The hblang² or hblang2 compiler is intended to compile hblang to hbvm bytecode while also being written in hblang.
|
||||||
|
|
||||||
|
This is the first step in bootstrapping ableOS.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sunset_client_2"
|
name = "hblang2"
|
||||||
authors = ["koniifer"]
|
authors = [""]
|
||||||
|
|
||||||
[dependants.libraries]
|
[dependants.libraries]
|
||||||
|
|
5
sysdata/programs/hblang2/src/main.hb
Normal file
5
sysdata/programs/hblang2/src/main.hb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
stn := @use("stn")
|
||||||
|
|
||||||
|
main := fn(): int {
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{string, memory, buffer, random, log} := stn;
|
.{string, memory, buffer, random, log} := stn;
|
||||||
.{Vec2} := stn.math
|
.{Vec2} := stn.math
|
||||||
|
|
||||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
horizon_api := @use("lib:horizon_api");
|
||||||
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label;
|
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label;
|
||||||
.{sexpr_parser, render_ui} := horizon_api.ui
|
.{sexpr_parser, render_ui} := horizon_api.ui
|
||||||
|
|
||||||
render := @use("../../../libraries/render/src/lib.hb");
|
render := @use("lib:render");
|
||||||
.{Surface} := render;
|
.{Surface} := render;
|
||||||
.{Font} := render.text
|
.{Font} := render.text
|
||||||
|
|
||||||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
intouch := @use("lib:intouch")
|
||||||
|
|
||||||
Window := struct {
|
Window := struct {
|
||||||
// TODO: Replace this with widgets
|
// TODO: Replace this with widgets
|
||||||
|
@ -21,25 +21,25 @@ Window := struct {
|
||||||
y: int,
|
y: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
img := @embed("../../../assets/wallpaper.qoi")
|
img := @embed("sysdata:assets/wallpaper.qoi")
|
||||||
|
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
win_buff := buffer.create("XHorizon\0")
|
win_buff := buffer.create("XHorizon")
|
||||||
|
|
||||||
screen := render.init(true)
|
screen := render.init(true)
|
||||||
|
|
||||||
// Clear the screen to black.
|
// Clear the screen to black.
|
||||||
render.clear(screen, render.black)
|
screen.clear(render.BLACK)
|
||||||
|
|
||||||
wallpaper := render.image.from(@bitcast(&img))
|
wallpaper := render.image.from(@bitcast(&img))
|
||||||
if wallpaper == null {
|
if wallpaper == null {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
window := render.new_surface(screen.width / 3, screen.height / 3)
|
window := render.Surface.new(screen.width / 3, screen.height / 3)
|
||||||
|
|
||||||
mem_buf := memory.request_page(1)
|
mem_buf := memory.request_page(1, false)
|
||||||
color := random.any(render.Color)
|
color := random.any(render.Color)
|
||||||
side := window.width / 8
|
side := window.width / 8
|
||||||
|
|
||||||
|
@ -48,16 +48,16 @@ main := fn(): int {
|
||||||
|
|
||||||
mouse_x := @as(i16, 0)
|
mouse_x := @as(i16, 0)
|
||||||
mouse_y := @as(i16, 0)
|
mouse_y := @as(i16, 0)
|
||||||
text_label := new_label("Hi\0")
|
text_label := new_label("Hi")
|
||||||
|
|
||||||
// widgets := "()\0"
|
// widgets := "()"
|
||||||
// ui := sexpr_parser(widgets)
|
// ui := sexpr_parser(widgets)
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
render.clear(screen, render.black)
|
screen.clear(render.BLACK)
|
||||||
|
|
||||||
render.put_surface(screen, wallpaper, .(0, 0), false)
|
screen.put_surface(wallpaper, .(0, 0), false)
|
||||||
|
|
||||||
// TODO: Read the window buffer here
|
// TODO: Read the window buffer here
|
||||||
{
|
{
|
||||||
|
@ -65,33 +65,33 @@ main := fn(): int {
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
// Scroll bar :ThumbsUp:
|
// Scroll bar :ThumbsUp:
|
||||||
render.put_rect(screen, .(100, 100), .(100, 10), render.white)
|
screen.put_rect(.(100, 100), .(100, 10), render.WHITE)
|
||||||
render.put_filled_rect(screen, .(110, 100), .(20, 10), render.white)
|
screen.put_filled_rect(.(110, 100), .(20, 10), render.WHITE)
|
||||||
|
|
||||||
render.put_rect(screen, .(90, 110), .(10, 100), render.white)
|
screen.put_rect(.(90, 110), .(10, 100), render.WHITE)
|
||||||
render.put_filled_rect(screen, .(90, 120), .(10, 20), render.white)
|
screen.put_filled_rect(.(90, 120), .(10, 20), render.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// osu dots
|
// osu dots
|
||||||
render.put_rect(screen, .(400, 100), .(100, 100), render.red)
|
screen.put_rect(.(400, 100), .(100, 100), render.RED)
|
||||||
render.put_rect(screen, .(100, 100 + 300), .(100, 100), render.red)
|
screen.put_rect(.(100, 100 + 300), .(100, 100), render.RED)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
pos := Vec2(uint).(1, screen.height - 21)
|
pos := Vec2(uint).(1, screen.height - 21)
|
||||||
render_label_to_surface(screen, text_label, font, pos)
|
render_label_to_surface(screen, text_label, font, pos)
|
||||||
render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), render.white)
|
screen.put_rect(.(0, screen.height - 21), .(screen.width - 1, 20), render.WHITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Screen border
|
// Screen border
|
||||||
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
|
screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), render.WHITE)
|
||||||
|
|
||||||
// get input events from drivers via intouch
|
// get input events from drivers via intouch
|
||||||
if false {
|
if false {
|
||||||
key_event := intouch.recieve_key_event()
|
key_event := intouch.recieve_key_event()
|
||||||
if key_event != null {
|
if key_event != null {
|
||||||
log.info("Key event \0")
|
log.info("Key event ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ main := fn(): int {
|
||||||
//
|
//
|
||||||
|
|
||||||
if mouse_event != null {
|
if mouse_event != null {
|
||||||
// log.warn("Mouse event received\0")
|
// log.warn("Mouse event received")
|
||||||
|
|
||||||
change_x := @as(i16, mouse_event.x_change)
|
change_x := @as(i16, mouse_event.x_change)
|
||||||
change_x = change_x << 8
|
change_x = change_x << 8
|
||||||
|
@ -127,18 +127,18 @@ main := fn(): int {
|
||||||
mouse_y -= change_y
|
mouse_y -= change_y
|
||||||
|
|
||||||
if mouse_event.left {
|
if mouse_event.left {
|
||||||
set_label_text(text_label, "LEFT CLICK\0")
|
set_label_text(text_label, "LEFT CLICK")
|
||||||
}
|
}
|
||||||
if mouse_event.middle {
|
if mouse_event.middle {
|
||||||
set_label_text(text_label, "MIDDLE CLICK\0")
|
set_label_text(text_label, "MIDDLE CLICK")
|
||||||
}
|
}
|
||||||
if mouse_event.right {
|
if mouse_event.right {
|
||||||
set_label_text(text_label, "RIGHT CLICK\0")
|
set_label_text(text_label, "RIGHT CLICK")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.black)
|
screen.put_filled_rect(.(mouse_x, mouse_y), .(20, 20), render.BLACK)
|
||||||
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
|
screen.put_rect(.(mouse_x, mouse_y), .(20, 20), render.WHITE)
|
||||||
|
|
||||||
// Send events to focused window
|
// Send events to focused window
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ main := fn(): int {
|
||||||
// TODO: Get windows out of a collection and iter through
|
// TODO: Get windows out of a collection and iter through
|
||||||
|
|
||||||
// Sync the screen
|
// Sync the screen
|
||||||
render.sync(screen)
|
screen.sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
stn := @use("stn");
|
||||||
.{string, memory, buffer, log} := stn
|
.{string, memory, buffer, log} := stn
|
||||||
|
|
||||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
horizon_api := @use("lib:horizon_api");
|
||||||
.{create_window} := horizon_api
|
.{create_window} := horizon_api
|
||||||
|
|
||||||
ignim := @use("../../../libraries/ignim/src/lib.hb");
|
ignim := @use("lib:ignim");
|
||||||
.{errors} := ignim
|
.{errors} := ignim
|
||||||
|
|
||||||
psf := @embed("../../../consolefonts/tamsyn/10x20r.psf")
|
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
|
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
x := 0
|
x := 0
|
||||||
// loop if x > 10000 break else x += 1
|
// loop if x > 10000 break else x += 1
|
||||||
|
|
||||||
windowing_system_buffer := buffer.search("XHorizon\0")
|
windowing_system_buffer := buffer.search("XHorizon")
|
||||||
// TODO: get WindowID
|
// TODO: get WindowID
|
||||||
wid := create_window(windowing_system_buffer)
|
wid := create_window(windowing_system_buffer)
|
||||||
if false {
|
if false {
|
||||||
program_name := "Horizon Testing Program\0"
|
program_name := "Horizon Testing Program"
|
||||||
program_version := ignim.version.make_version(0, 1, 0)
|
program_version := ignim.version.make_version(0, 1, 0)
|
||||||
engine_name := "None\0"
|
engine_name := "None"
|
||||||
engine_version := ignim.version.make_version(0, 0, 0)
|
engine_version := ignim.version.make_version(0, 0, 0)
|
||||||
api_version := ignim.version.make_api_version(0, 1, 0, 0)
|
api_version := ignim.version.make_api_version(0, 1, 0, 0)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ main := fn(): int {
|
||||||
// // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
|
// // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
|
||||||
ret := ignim.instance.create_instance(&create_info, 0, &instance)
|
ret := ignim.instance.create_instance(&create_info, 0, &instance)
|
||||||
if ret == errors.IncompatibleDriver {
|
if ret == errors.IncompatibleDriver {
|
||||||
log.error("Driver Incompatible with Vulkan\0")
|
log.error("Driver Incompatible with Vulkan")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
sysdata/programs/pcspkr/README.md
Normal file
1
sysdata/programs/pcspkr/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# pcspkr
|
11
sysdata/programs/pcspkr/meta.toml
Normal file
11
sysdata/programs/pcspkr/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "pcspkr"
|
||||||
|
authors = [""]
|
||||||
|
|
||||||
|
[dependants.libraries]
|
||||||
|
|
||||||
|
[dependants.binaries]
|
||||||
|
hblang.version = "1.0.0"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "hblang src/main.hb"
|
45
sysdata/programs/pcspkr/src/main.hb
Normal file
45
sysdata/programs/pcspkr/src/main.hb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
stn := @use("stn");
|
||||||
|
.{memory, buffer, log, string, math} := stn;
|
||||||
|
.{inb, outb} := memory
|
||||||
|
|
||||||
|
$PIT_CLOCK := 1193180
|
||||||
|
|
||||||
|
play_sound := fn(frequency: u32): void {
|
||||||
|
div := 0
|
||||||
|
|
||||||
|
div = PIT_CLOCK / frequency
|
||||||
|
memory.outb(0x43, 0xB6)
|
||||||
|
memory.outb(0x42, @intcast(div))
|
||||||
|
memory.outb(0x42, @intcast(div >> 8))
|
||||||
|
|
||||||
|
tmp := inb(0x61)
|
||||||
|
if tmp != (tmp | 3) {
|
||||||
|
outb(0x61, tmp | 3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
no_sound := fn(): void {
|
||||||
|
tmp := memory.inb(0x61) & 0xFC
|
||||||
|
|
||||||
|
memory.outb(0x61, tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
beep := fn(): void {
|
||||||
|
play_sound(1000)
|
||||||
|
idx := 0
|
||||||
|
loop {
|
||||||
|
if idx >= 1000000 {
|
||||||
|
idx += 1
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
no_sound()
|
||||||
|
}
|
||||||
|
|
||||||
|
main := fn(): int {
|
||||||
|
no_sound()
|
||||||
|
beep()
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
|
||||||
|
|
||||||
main := fn(): void {
|
|
||||||
log.info("Hello, World!\0")
|
|
||||||
loop {
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
|
@ -1,19 +0,0 @@
|
||||||
.{process, log, string, memory} := @use("../../../libraries/stn/src/lib.hb")
|
|
||||||
|
|
||||||
exe := @embed("./hello_world_and_spin.hbf")
|
|
||||||
|
|
||||||
main := fn(): void {
|
|
||||||
buf := "\0\0\0\0\0\0\0"
|
|
||||||
loop {
|
|
||||||
log.info(
|
|
||||||
string.display_int(
|
|
||||||
@bitcast(process.spawn(@bitcast(&exe), 356)),
|
|
||||||
buf,
|
|
||||||
10,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// spin so we don't spawn 10 quattuordecillion processes
|
|
||||||
i := 0
|
|
||||||
loop if i == 1000000 break else i += 1
|
|
||||||
}
|
|
||||||
}
|
|
23
sysdata/programs/ps2_driver/README.md
Normal file
23
sysdata/programs/ps2_driver/README.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Unified PS/2 Driver
|
||||||
|
|
||||||
|
Te entire thing is held together inspite
|
||||||
|
|
||||||
|
## !!Assumptions!!
|
||||||
|
Anyone who works on this should work to keep this list as small as possible/remove as many of these as possible.
|
||||||
|
- Bit 5 of the response form 0x64 indicates which port the data is coming from. (Not true on all systems)
|
||||||
|
- A parity or timeout error never occurs.
|
||||||
|
- PS/2 controller exists.
|
||||||
|
- Both PS/2 ports being broken doesn't need handling.
|
||||||
|
- One PS/2 port being broken doesn't need special attention.
|
||||||
|
- PS/2 controller doesn't need to perform a self-check.
|
||||||
|
- These DeviceIDs never exist:
|
||||||
|
- 0xFFFD
|
||||||
|
- 0xFFFE
|
||||||
|
- 0xFFFF
|
||||||
|
- 0x01xx
|
||||||
|
- 0x03xx
|
||||||
|
- 0x04xx
|
||||||
|
- Literally all PS/2 keyboards can be handeled the exact same way. We have the capability for detecting different keyboard types, I just don't bother with it because that would litreally take months to get working.
|
||||||
|
- The device doesn't send any data while we're waiting for an `ACK`.
|
||||||
|
|
||||||
|
Supporting mice in the keyboard port and vice versa was a ***bad*** idea, but I do not regret it because it means we're "superior" to real world operating systems.
|
11
sysdata/programs/ps2_driver/meta.toml
Normal file
11
sysdata/programs/ps2_driver/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "ps2_driver"
|
||||||
|
authors = ["Peony"]
|
||||||
|
|
||||||
|
[dependants.libraries]
|
||||||
|
|
||||||
|
[dependants.binaries]
|
||||||
|
hblang.version = "1.0.0"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "hblang src/main.hb"
|
26
sysdata/programs/ps2_driver/src/bits.hb
Normal file
26
sysdata/programs/ps2_driver/src/bits.hb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//Do not question.
|
||||||
|
|
||||||
|
$bit0 := fn(value: u8): bool {
|
||||||
|
return (value & 0x1) > 0
|
||||||
|
}
|
||||||
|
$bit1 := fn(value: u8): bool {
|
||||||
|
return (value & 0x2) > 0
|
||||||
|
}
|
||||||
|
$bit2 := fn(value: u8): bool {
|
||||||
|
return (value & 0x4) > 0
|
||||||
|
}
|
||||||
|
$bit3 := fn(value: u8): bool {
|
||||||
|
return (value & 0x8) > 0
|
||||||
|
}
|
||||||
|
$bit4 := fn(value: u8): bool {
|
||||||
|
return (value & 0x10) > 0
|
||||||
|
}
|
||||||
|
$bit5 := fn(value: u8): bool {
|
||||||
|
return (value & 0x20) > 0
|
||||||
|
}
|
||||||
|
$bit6 := fn(value: u8): bool {
|
||||||
|
return (value & 0x40) > 0
|
||||||
|
}
|
||||||
|
$bit7 := fn(value: u8): bool {
|
||||||
|
return (value & 0x80) > 0
|
||||||
|
}
|
101
sysdata/programs/ps2_driver/src/controller.hb
Normal file
101
sysdata/programs/ps2_driver/src/controller.hb
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
.{memory, log} := @use("stn");
|
||||||
|
.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb");
|
||||||
|
.{Port, PORT_AT_STARTUP} := @use("port.hb")
|
||||||
|
|
||||||
|
port1 := @as(Port, PORT_AT_STARTUP)
|
||||||
|
port2 := @as(Port, PORT_AT_STARTUP)
|
||||||
|
|
||||||
|
//wiki.osdev.org/"8042"_PS/2_Controller#PS/2_Controller_IO_Ports
|
||||||
|
$CONTROLLER_PORT := 0x64
|
||||||
|
$DATA_PORT := 0x60
|
||||||
|
|
||||||
|
$disable_port1 := fn(): void memory.outb(CONTROLLER_PORT, 0xAD)
|
||||||
|
$enable_port1 := fn(): void memory.outb(CONTROLLER_PORT, 0xAE)
|
||||||
|
$disable_port2 := fn(): void memory.outb(CONTROLLER_PORT, 0xA7)
|
||||||
|
$enable_port2 := fn(): void memory.outb(CONTROLLER_PORT, 0xA8)
|
||||||
|
|
||||||
|
test_port1 := fn(): bool {
|
||||||
|
memory.outb(CONTROLLER_PORT, 0xAB)
|
||||||
|
loop if has_input(get_info()) break
|
||||||
|
input := get_input()
|
||||||
|
return input == 0x0
|
||||||
|
}
|
||||||
|
|
||||||
|
test_port2 := fn(): bool {
|
||||||
|
memory.outb(CONTROLLER_PORT, 0xA9)
|
||||||
|
loop if has_input(get_info()) break
|
||||||
|
input := get_input()
|
||||||
|
return input == 0x0
|
||||||
|
}
|
||||||
|
|
||||||
|
get_config_byte := fn(): u8 {
|
||||||
|
memory.outb(CONTROLLER_PORT, 0x20)
|
||||||
|
loop if has_input(get_info()) break
|
||||||
|
return get_input()
|
||||||
|
}
|
||||||
|
|
||||||
|
Info := struct {d: u8}
|
||||||
|
|
||||||
|
$get_info := fn(): Info return .(memory.inb(CONTROLLER_PORT))
|
||||||
|
//inline when can
|
||||||
|
has_input := fn(info: Info): bool return bit0(info.d)
|
||||||
|
can_send := fn(info: Info): bool return bit1(info.d) == false
|
||||||
|
timed_out := fn(info: Info): bool return bit6(info.d)
|
||||||
|
check_parity := fn(info: Info): bool return bit7(info.d)
|
||||||
|
get_port := fn(info: Info): ^Port {
|
||||||
|
if bit5(info.d) {
|
||||||
|
return &port2
|
||||||
|
} else {
|
||||||
|
return &port1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//T
|
||||||
|
port2_ptr := &port2
|
||||||
|
send_byte := fn(port: ^Port, byte: u8): void {
|
||||||
|
if port == port2_ptr {
|
||||||
|
memory.outb(CONTROLLER_PORT, 0xD4)
|
||||||
|
}
|
||||||
|
loop if can_send(get_info()) break
|
||||||
|
memory.outb(DATA_PORT, byte)
|
||||||
|
}
|
||||||
|
|
||||||
|
$get_input := fn(): u8 return memory.inb(DATA_PORT)
|
||||||
|
$write_out := fn(data: u8): void memory.outb(DATA_PORT, data)
|
||||||
|
|
||||||
|
flush_input := fn(): void {
|
||||||
|
loop if has_input(get_info()) == false break else get_info()
|
||||||
|
}
|
||||||
|
|
||||||
|
init := fn(): void {
|
||||||
|
disable_port1()
|
||||||
|
disable_port2()
|
||||||
|
//Disables ports to make sure that they won't interfere with the setup process.
|
||||||
|
|
||||||
|
flush_input()
|
||||||
|
|
||||||
|
enable_port2()
|
||||||
|
port2.exists = bit5(@inline(get_config_byte)) == false
|
||||||
|
disable_port2()
|
||||||
|
|
||||||
|
flush_input()
|
||||||
|
|
||||||
|
port1.exists = test_port1()
|
||||||
|
|
||||||
|
if port2.exists {
|
||||||
|
port2.exists = test_port2()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port1.exists | port2.exists) == false {
|
||||||
|
log.error("No ports detected! No input will be processed! Cannot handle this!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if port1.exists {
|
||||||
|
log.info("Port 1 exists.")
|
||||||
|
enable_port1()
|
||||||
|
}
|
||||||
|
if port2.exists {
|
||||||
|
log.info("Port 2 exists.")
|
||||||
|
enable_port2()
|
||||||
|
}
|
||||||
|
}
|
15
sysdata/programs/ps2_driver/src/devices.hb
Normal file
15
sysdata/programs/ps2_driver/src/devices.hb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
DeviceID := struct {value: u16}
|
||||||
|
|
||||||
|
$MOUSE_3_BUTTON := DeviceID.(0x0)
|
||||||
|
$MOUSE_SCROLLWHEEL := DeviceID.(0x3)
|
||||||
|
$MOUSE_5_BUTTON := DeviceID.(0x4)
|
||||||
|
$KEYBOARD_SPACESAVER := DeviceID.(0x84AB)
|
||||||
|
$KEYBOARD_122_KEY := DeviceID.(0x86AB)
|
||||||
|
$KEYBOARD_JAPANESE_G := DeviceID.(0x90AB)
|
||||||
|
$KEYBOARD_JAPANESE_P := DeviceID.(0x91AB)
|
||||||
|
$KEYBOARD_JAPANESE_A := DeviceID.(0x92AB)
|
||||||
|
$KEYBOARD_NCD_SUN := DeviceID.(0xA1AC)
|
||||||
|
|
||||||
|
$MOUSE_INIT_1 := DeviceID.(0xFFFD)
|
||||||
|
$MOUSE_INIT_2 := DeviceID.(0xFFFE)
|
||||||
|
$NO_DEVICE := DeviceID.(0xFFFF)
|
150
sysdata/programs/ps2_driver/src/main.hb
Normal file
150
sysdata/programs/ps2_driver/src/main.hb
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
.{memory, log, buffer, string} := @use("stn");
|
||||||
|
.{MouseEvent} := @use("lib:intouch").events;
|
||||||
|
.{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb")
|
||||||
|
devices := @use("devices.hb")
|
||||||
|
controller := @use("controller.hb");
|
||||||
|
.{Info, Port} := controller
|
||||||
|
mouse := @use("mouse.hb")
|
||||||
|
|
||||||
|
mouse_buffer := 0
|
||||||
|
keyboard_buffer := 0
|
||||||
|
info := Info.(0)
|
||||||
|
|
||||||
|
send_command := fn(port: ^Port, byte: u8): void {
|
||||||
|
tries := 3
|
||||||
|
loop if tries == 0 break else {
|
||||||
|
controller.send_byte(port, byte)
|
||||||
|
loop {
|
||||||
|
info = controller.get_info()
|
||||||
|
if controller.has_input(info) == false {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
input := controller.get_input()
|
||||||
|
if controller.get_port(info) != port {
|
||||||
|
if check_complete(port) == false {
|
||||||
|
port.packet[port.packet_length] = input
|
||||||
|
port.packet_length += 1
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if input == 0xFA {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tries -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enable_streaming := fn(port: ^Port): void {
|
||||||
|
@inline(send_command, port, 0xF4)
|
||||||
|
}
|
||||||
|
|
||||||
|
process := fn(port: ^controller.Port): void {
|
||||||
|
if port.device.value < devices.MOUSE_5_BUTTON.value {
|
||||||
|
event := MouseEvent.(0, 0, false, false, false)
|
||||||
|
|
||||||
|
event.left = bit0(port.packet[0])
|
||||||
|
event.right = bit1(port.packet[0])
|
||||||
|
event.middle = bit2(port.packet[0])
|
||||||
|
|
||||||
|
event.x_change = @intcast(port.packet[1])
|
||||||
|
event.y_change = @intcast(port.packet[2])
|
||||||
|
|
||||||
|
buffer.write(MouseEvent, mouse_buffer, &event)
|
||||||
|
} else if port.device == devices.MOUSE_INIT_1 {
|
||||||
|
port.device.value = port.packet[0]
|
||||||
|
if port.device != devices.MOUSE_SCROLLWHEEL {
|
||||||
|
enable_streaming(port)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
port.device = devices.MOUSE_INIT_2
|
||||||
|
} else if port.device == devices.MOUSE_INIT_2 {
|
||||||
|
port.device.value = port.packet[0]
|
||||||
|
} else if port.device == devices.NO_DEVICE {
|
||||||
|
if port.packet_length == 1 {
|
||||||
|
port.device.value = port.packet[0]
|
||||||
|
enable_streaming(port)
|
||||||
|
//TODO: Upgrade mouse.
|
||||||
|
} else {
|
||||||
|
port.device.value = port.packet[1] | port.packet[0] << 8
|
||||||
|
enable_streaming(port)
|
||||||
|
}
|
||||||
|
log.info("Identified device!")
|
||||||
|
log.print(port.device.value, .{radix: 16})
|
||||||
|
} else {
|
||||||
|
log.info("KEY PRESSED")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_complete := fn(port: ^controller.Port): bool {
|
||||||
|
last_value := port.packet[port.packet_length - 1]
|
||||||
|
if port.device == devices.NO_DEVICE {
|
||||||
|
if last_value == 0 | last_value == 3 | last_value == 4 {
|
||||||
|
return true
|
||||||
|
} else if port.packet_length == 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if port.device == devices.MOUSE_3_BUTTON {
|
||||||
|
if port.packet_length == 3 return true
|
||||||
|
} else if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON {
|
||||||
|
if port.packet_length == 4 return true
|
||||||
|
} else {
|
||||||
|
if port.packet[0] == 0xE1 {
|
||||||
|
if port.packet_length == 6 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if port.packet[0] != 0xE0 {
|
||||||
|
return true
|
||||||
|
} else if port.packet_length == 2 & port.packet[1] != 0x2A & port.packet[1] != 0xB7 {
|
||||||
|
return true
|
||||||
|
} else if port.packet_length == 4 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
main := fn(): void {
|
||||||
|
mouse_buffer = buffer.create("PS/2 Mouse")
|
||||||
|
|
||||||
|
controller.init()
|
||||||
|
|
||||||
|
if controller.port1.exists {
|
||||||
|
//log.info("Port 1 exists.")
|
||||||
|
controller.send_byte(@bitcast(0), 0xF4)
|
||||||
|
}
|
||||||
|
if controller.port2.exists {
|
||||||
|
//controller.send_byte(&controller.port2, 0xF4)
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
info = controller.get_info()
|
||||||
|
|
||||||
|
if controller.timed_out(info) {
|
||||||
|
log.error("Timeout error! Cannot handle these!")
|
||||||
|
}
|
||||||
|
if controller.check_parity(info) {
|
||||||
|
log.error("Parity error! Cannot handle these!")
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if controller.has_input(info) {
|
||||||
|
port := controller.get_port(info)
|
||||||
|
if port.packet_length > 0 & check_complete(port) {
|
||||||
|
process(port)
|
||||||
|
}
|
||||||
|
input := controller.get_input()
|
||||||
|
/*if input == 0xAA & port.can_hot_plug {
|
||||||
|
port.device = devices.NO_DEVICE
|
||||||
|
controller.send_byte(port, 0xF4)
|
||||||
|
}*/
|
||||||
|
port.packet[port.packet_length] = input
|
||||||
|
port.packet_length += 1
|
||||||
|
if check_complete(port) {
|
||||||
|
process(port)
|
||||||
|
port.packet_length = 0
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
21
sysdata/programs/ps2_driver/src/mouse.hb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Button := struct {id: u8}
|
||||||
|
$LEFT_BUTTON := Button.(1)
|
||||||
|
$RIGHT_BUTTON := Button.(2)
|
||||||
|
$MIDDLE_BUTTON := Button.(4)
|
||||||
|
$BUTTON4 := Button.(8)
|
||||||
|
$BUTTON5 := Button.(16)
|
||||||
|
|
||||||
|
SampleRate := struct {value: u8}
|
||||||
|
$SR10 := SampleRate.(10)
|
||||||
|
$SR20 := SampleRate.(20)
|
||||||
|
$SR40 := SampleRate.(40)
|
||||||
|
$SR60 := SampleRate.(60)
|
||||||
|
$SR80 := SampleRate.(80)
|
||||||
|
$SR100 := SampleRate.(100)
|
||||||
|
$SR200 := SampleRate.(200)
|
||||||
|
|
||||||
|
Resolution := struct {value: u8}
|
||||||
|
$RES_1COUNT_PER_MM := Resolution.(0)
|
||||||
|
$RES_2COUNT_PER_MM := Resolution.(1)
|
||||||
|
$RES_4COUNT_PER_MM := Resolution.(2)
|
||||||
|
$RES_8COUNT_PER_MM := Resolution.(3)
|
21
sysdata/programs/ps2_driver/src/port.hb
Normal file
21
sysdata/programs/ps2_driver/src/port.hb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
.{DeviceID, NO_DEVICE} := @use("devices.hb")
|
||||||
|
|
||||||
|
State := struct {s: u8}
|
||||||
|
$Recive := State.(0)
|
||||||
|
$Reboot := State.(1)
|
||||||
|
|
||||||
|
Port := packed struct {
|
||||||
|
exists: bool,
|
||||||
|
device: DeviceID,
|
||||||
|
packet: [8]u8,
|
||||||
|
packet_length: u8,
|
||||||
|
can_hot_plug: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
$PORT_AT_STARTUP := Port.(
|
||||||
|
true,
|
||||||
|
NO_DEVICE,
|
||||||
|
.[0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
)
|
|
@ -1,3 +0,0 @@
|
||||||
# PS/2 Driver
|
|
||||||
|
|
||||||
This program is a simple driver to read keypresses from a PS/2 Keyboard Also will contain an abstraction for the PS/2 controller in general so the Mouse code will probably also live here...maybe
|
|
|
@ -1,11 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "ps2_keyboard_driver"
|
|
||||||
authors = ["Talha Qamar"]
|
|
||||||
|
|
||||||
[dependants.libraries]
|
|
||||||
|
|
||||||
[dependants.binaries]
|
|
||||||
hblang.version = "1.0.0"
|
|
||||||
|
|
||||||
[build]
|
|
||||||
command = "hblang src/main.hb"
|
|
|
@ -1,40 +0,0 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
|
||||||
.{memory, log, buffer} := stn
|
|
||||||
|
|
||||||
intouch := @use("../../../libraries/intouch/src/lib.hb");
|
|
||||||
.{KeyEvent} := intouch
|
|
||||||
|
|
||||||
send_byte := fn(byte: u8): u8 {
|
|
||||||
memory.outb(96, byte)
|
|
||||||
return memory.inb(96)
|
|
||||||
}
|
|
||||||
|
|
||||||
main := fn(): int {
|
|
||||||
buf := buffer.create("PS/2 Keyboard\0")
|
|
||||||
_ = send_byte(238)
|
|
||||||
log.info("PS/2 Driver Loaded\0")
|
|
||||||
|
|
||||||
if send_byte(238) == 238 {
|
|
||||||
log.info("PS/2 Keyboard Echoed\0")
|
|
||||||
}
|
|
||||||
|
|
||||||
if send_byte(244) == 250 {
|
|
||||||
log.info("Enabled scanning\0")
|
|
||||||
}
|
|
||||||
|
|
||||||
prev_input := 250
|
|
||||||
loop {
|
|
||||||
loop if (memory.inb(0x64) & 0x20) == 0x20 break
|
|
||||||
|
|
||||||
input := memory.inb(96)
|
|
||||||
|
|
||||||
if input == prev_input {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
prev_input = input
|
|
||||||
kevent := KeyEvent.(false, true, input)
|
|
||||||
|
|
||||||
buffer.write(KeyEvent, buf, &kevent)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb")
|
.{memory, buffer, log, string, math} := @use("stn")
|
||||||
Vec2 := math.Vec2
|
Vec2 := math.Vec2
|
||||||
|
|
||||||
intouch := @use("../../../libraries/intouch/src/lib.hb");
|
intouch := @use("lib:intouch");
|
||||||
.{MouseEvent} := intouch.events
|
.{MouseEvent} := intouch.events
|
||||||
|
|
||||||
i9 := packed struct {sign: bool, value: u8}
|
i9 := packed struct {sign: bool, value: u8}
|
||||||
|
@ -21,7 +21,7 @@ reset_mouse := fn(): void {
|
||||||
@inline(send_byte, 0x64, 0xD4)
|
@inline(send_byte, 0x64, 0xD4)
|
||||||
@inline(send_byte, 0x60, 0xFF)
|
@inline(send_byte, 0x60, 0xFF)
|
||||||
loop if memory.inb(0x60) == 0xAA {
|
loop if memory.inb(0x60) == 0xAA {
|
||||||
log.info("Self check passed.\0")
|
log.info("Self check passed.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,11 @@ set_up_mouse := fn(): void {
|
||||||
button_states := @as(u8, 0)
|
button_states := @as(u8, 0)
|
||||||
|
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
mouse_buffer := buffer.create("PS/2 Mouse\0")
|
mouse_buffer := buffer.create("PS/2 Mouse")
|
||||||
format_page := memory.alloc(u8, 1024)
|
format_page := memory.alloc(u8, 1024)
|
||||||
|
|
||||||
send_byte(0x64, 0xA8)
|
send_byte(0x64, 0xA8)
|
||||||
log.info("Aux mouse device enabled.\0")
|
log.info("Aux mouse device enabled.")
|
||||||
|
|
||||||
set_up_mouse()
|
set_up_mouse()
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ main := fn(): int {
|
||||||
|
|
||||||
if status == 0xAA {
|
if status == 0xAA {
|
||||||
loop if memory.inb(0x60) == 0 break
|
loop if memory.inb(0x60) == 0 break
|
||||||
log.info("Mouse plugged in!\0")
|
log.info("Mouse plugged in!")
|
||||||
set_up_mouse()
|
set_up_mouse()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb")
|
stn := @use("stn")
|
||||||
|
|
||||||
main := fn(): int {
|
main := fn(): int {
|
||||||
stn.log.info("\r
|
stn.log.info("\r
|
||||||
|
@ -9,7 +9,7 @@ main := fn(): int {
|
||||||
| : '=.:.=' : |\r
|
| : '=.:.=' : |\r
|
||||||
| : :'.___.': : |\r
|
| : :'.___.': : |\r
|
||||||
'-:__:__:__:__:-'\r
|
'-:__:__:__:__:-'\r
|
||||||
\0")
|
")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
render := @use("../../../../libraries/render/src/lib.hb")
|
render := @use("lib:render")
|
||||||
|
|
||||||
/* expected result:
|
/* expected result:
|
||||||
the impostor travels left and loops around the screen */
|
the impostor travels left and loops around the screen */
|
||||||
|
@ -7,13 +7,13 @@ example := fn(): void {
|
||||||
screen := render.init(true)
|
screen := render.init(true)
|
||||||
x := 0
|
x := 0
|
||||||
loop {
|
loop {
|
||||||
render.put_rect(screen, .(200 - x, 80), .(430, 380), render.red)
|
screen.clear(render.BLACK)
|
||||||
render.put_rect(screen, .(630 - x, 120), .(120, 300), render.red)
|
screen.put_rect(.(200 - x, 80), .(430, 380), render.RED)
|
||||||
render.put_rect(screen, .(200 - x, 460), .(160, 270), render.red)
|
screen.put_rect(.(630 - x, 120), .(120, 300), render.RED)
|
||||||
render.put_rect(screen, .(470 - x, 460), .(160, 270), render.red)
|
screen.put_rect(.(200 - x, 460), .(160, 270), render.RED)
|
||||||
render.put_rect(screen, .(140 - x, 140), .(340, 250), render.cyan)
|
screen.put_rect(.(470 - x, 460), .(160, 270), render.RED)
|
||||||
render.sync(screen)
|
screen.put_rect(.(140 - x, 140), .(340, 250), render.CYAN)
|
||||||
render.clear(screen, render.black)
|
screen.sync()
|
||||||
x += 1
|
x += 1
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue