From 62f9fa1fd41e0df112d39dc02ab27e8774a81c6a Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 8 Jan 2025 01:25:11 +0000 Subject: [PATCH] ups --- .../holeybytes/kernel_services/mem_serve.rs | 42 ++++++++++++++++-- sysdata/libraries/stn/src/memory.hb | 22 +++++---- .../tests/stn/assets/hello_world_and_spin.hb | 7 --- .../tests/stn/assets/hello_world_and_spin.hbf | Bin 273 -> 0 bytes .../test/src/tests/stn/assets/lily.axe | Bin 0 -> 6043 bytes .../test/src/tests/stn/assets/lily.hbf | Bin 4588 -> 0 bytes .../programs/test/src/tests/stn/process.hb | 2 +- 7 files changed, 53 insertions(+), 20 deletions(-) delete mode 100644 sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb delete mode 100644 sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hbf create mode 100644 sysdata/programs/test/src/tests/stn/assets/lily.axe delete mode 100644 sysdata/programs/test/src/tests/stn/assets/lily.hbf diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 6e39e3a..ccdedf6 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -1,6 +1,6 @@ use { crate::holeybytes::{kernel_services::block_read, Vm}, - alloc::alloc::{alloc, dealloc}, + alloc::alloc::{alloc, alloc_zeroed, dealloc, realloc}, core::alloc::Layout, log::{debug, info}, }; @@ -49,8 +49,12 @@ pub fn memory_msg_handler( match msg_type { 0 => unsafe { let page_count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()) as usize; - - let ptr = alloc(Layout::from_size_align_unchecked(page_count * 4096, 1)); + 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)) + }; log::debug!("Allocating {} pages @ {:?}", page_count, ptr); @@ -61,11 +65,12 @@ pub fn memory_msg_handler( let page_count = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()) as usize; let mptr = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as *mut u8; + debug_assert!(mptr.addr() & 0xFFFF000000000000 != 0); log::debug!("Deallocating {} pages @ {:?}", page_count, mptr); dealloc( mptr, - Layout::from_size_align_unchecked(page_count * 4096, 1), + Layout::from_size_align_unchecked(page_count * 4096, 8), ) }, 2 => { @@ -108,6 +113,35 @@ pub fn memory_msg_handler( 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 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, + ); + + 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); } diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index c6b818e..abf8554 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -1,6 +1,4 @@ $PAGE_SIZE := 4096 -$MAX_ALLOC := 0xFF -$MAX_FREE := 0xFF $uninit := fn($Expr: type): Expr { return idk @@ -19,18 +17,22 @@ $calc_pages := fn($Expr: type, num: uint): uint { } // ! will be replaced, don't get attached -alloc := fn($Expr: type, num: uint): ^Expr { - return @bitcast(request_page(@intcast(calc_pages(Expr, num)))) +$alloc := fn($Expr: type, num: uint): ^Expr { + return @bitcast(request_page(calc_pages(Expr, num * @sizeof(Expr)), false)) +} + +$alloc_zeroed := fn($Expr: type, num: uint): ^Expr { + return @bitcast(request_page(calc_pages(Expr, num * @sizeof(Expr)), true)) } // ! stub $free := fn($Expr: type, ptr: ^Expr, num: uint): void { - release_page(@bitcast(ptr), @intcast(calc_pages(Expr, num))) + release_page(@bitcast(ptr), calc_pages(Expr, num * @sizeof(Expr))) } -RqPageMsg := packed struct {a: u8, count: uint} -$request_page := fn(count: uint): ^u8 { - return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg)) +RqPageMsg := packed struct {a: u8, count: uint, zeroed: bool} +$request_page := fn(count: uint, zeroed: bool): ^u8 { + return @eca(3, 2, &RqPageMsg.(0, count, zeroed), @sizeof(RqPageMsg)) } RlPageMsg := packed struct {a: u8, count: uint, ptr: ^u8} @@ -76,4 +78,8 @@ $copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { 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)) } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb b/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb deleted file mode 100644 index e8d4c92..0000000 --- a/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb +++ /dev/null @@ -1,7 +0,0 @@ -.{log, sleep} := @use("stn") - -main := fn(): void { - log.info("Hello, World!") - // fake interrupt, sleep forever - sleep.sleep_until_interrupt(100) -} \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hbf b/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hbf deleted file mode 100644 index 48b140214b18d8358f18f9d8cfe6dfed8dd9f8e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 273 zcmWfgc!>cB&VmRa;Dt~)$q;!44xl8X!M}g^|3iQeFT)|AkOv==0slXkMnB$vf>1UG zgSP<8SU*0v3PuJ$fq#;4H9!rFaE>o8sthMw#+w&rtT!J_y|(}}RNjqAz>S&DjfLNh sl{dzNH^rNe4KBmy#>^W7bhaW?B$PoO%3|p}2m!XJ=RZbi`V+;~adUG)ix`G7RzBVuidoiySG6 zBV&j}4puHmQ7(>z5>5#xlvCiAgp*GwN65*CNaP3t@&i#~5bEKpntD~$J7dcjaY!F# zyQ*HjdiA~UeO0~pzw|D{^SdvZU&dZt{JHJ#caO6!29vz5U$5u(sgBpToc#q>wd+5* z#*pQqk@K2-R?NS4nHH=PwQ*^lF3V*-T)eX>mvEu#+_fuJbNAXclg7T0r}ZA;Sdv8A7{s%8AI`UT?{A()TG`?@pKYrQ?)OJ-{@ zN8G~AYVPJ8w;L1yt$vbe-qNC7NOD;!9s(#+{(ui)H&xdehKErP+h&!FY>+nHmcabN zQKUj8mEyEim(3o<`*xbPTvru)FSE$fx1>3ja?`tPGCGoPc)7{5Y(7|wRU_Y$cWv#mFc$9oejMv_OwXO3U=DmvGWCRD;Y_nZgEs1 z4cbbaqBZ*}e(YF;08lw$x>4%}KKw<22B49a=h1DRW?J3~X(3u#N~2mA<_w8}tW)Fv zLG|wesU?Em6V+ctm`k3Psjd|574=Cw1G81CrUGMSOz(9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S!oHa-#brKw&C}p2jv^{P|KF7UCq~)j!rFZ9m)sk5*;&qBGCe`mZ>unz zuT~h&cnTdk=2oz}8pQs;5S2R|*{}S?0vVt|h3&fqqYArnu>aIkmoM&LJ$Qm&*?)F* zNnGe7>(CAhhI InPd8Y004l7g8%>k literal 0 HcmV?d00001 diff --git a/sysdata/programs/test/src/tests/stn/assets/lily.hbf b/sysdata/programs/test/src/tests/stn/assets/lily.hbf deleted file mode 100644 index f85d5e6914c0d2dc353f7e3a44e47e4e6592aebc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4588 zcmcgvJ&Y7p9RJVEvRR35-s~MjwD8`1>~TOd;+mikbA@@?WSt3@#XBHIO^}4dLXBWy zVT@YPsj;D?QK<~khDvEnEQuAJlysUHmBcvf@6Eoi;p4UM~=k-0*TWx+cNUP1K_8uBt^nnXLaLETQ`@j_+FpOJ~SN)f3K5*Rv8zP%1 zU)-=aQlwjAl#&c{1nLwgoHCr&9>pn0XU_r?Z!!|N+zA)Tu&5&IsDyC+9B@iuB1*H% z2y*3z7@>bnd;cX`(Xt7*Key>HpGy`Z4Rk_Ln+67uaa3{_VP=m3Rm{W)8CJ7KivWO^ zfi)2?k62);BHez|*x*l-NZ-jYkx?vrT<%~mOQv!*)lXf;uWH4S$@-nvNoJwUqiJgR zRw8p+R7EB<>VUQi@jd=+QoMPX>FQP$FGav`IU>=lUFK_oHA-6Jp!krFhLkwW_p2++r&%~bMt3>yn!2*GfV zMnw#K(UaAnFGiwX6^2znbuOIt9hQ9|Qb={LeNm_jkGb!6L}^{K?MCUEi;_`Mz;B^U zBd=?~rLvd8*f9cE2iDjGcG~D7Wlc^x$nGb3 zOfPU0-s0QGc>?Ge&gc4Oi_^z6;X#>LZKgvMN&A&?JlC|fE0cionBrj_do^*-G6=Pt zDR*VS+cHR08MG0HEv9a|Evxa|UP)Yo;}4U+!J^KhWuvKV2_pp^kGVYDz*r-);%MJz^k|o>P`h08a z5Vppa4z|Yh7~*F|-o=bd+nMo$2^kAfwUYNHNe_ydc2Otxh}OoNT>Ao(DQ*rpfHhBB zV9FlX=V@ZAaLHBSl8h4B8>%XtupJO)CW|-hT49EGKvU-7?6i_fH#b4MWbdKd6AmEj zt^kZo+RM<>15rM#3A$0%;>P%*)%^j#Idtkbz~^8X_&`$ z(>MsI?ME`m?yuKg(NV*oHaZ+qgBt6G@~ z)%4!TG3o#Npmu&o@=Ua&yUBCYMacwWj~difDqK^jgtspsIb@`A>Dyav&vj%FVraTT zuHPwSO>YBtWaxSDTV&{Qs&ZktBSSk&i*m@~YhR390GUsddT3ty8m?<<6<*U&SLZ)n z)7fHbT?}Y;4w$9uY*UW8)P5ynb{FtVIR_>8T88QpW+R?*(>re4g1PL)dJC2TgMx;l ztDv_C8&{OdshFnPAgVGih+7%$!+NPE`3#aVJ&oau%lA77euV+++_uQ__>SxU-f6V8t-)A4fpI+lAmFL&BqFux6gyvC|a2MIFgti?%Ux1r8 zuc{@x*{K=F2U-|@7{*Ko7e9aE@v>b3`pZkp8_Q~Z?edJ-+@(f!>@#3)R5MS*Dp=M+ zkQioE8&R_hIKgP4QSNTE_p?UmIyBLR6@G5x*W#iM5Bv_#cFHyDl&ePT0j(w@UA27j z&;U3&0G!(qG-H%dK{FigTYp1 Tx6ZwD=Jf00?3?1<)2HYkfAgyQ diff --git a/sysdata/programs/test/src/tests/stn/process.hb b/sysdata/programs/test/src/tests/stn/process.hb index cf3d22c..96b879b 100644 --- a/sysdata/programs/test/src/tests/stn/process.hb +++ b/sysdata/programs/test/src/tests/stn/process.hb @@ -1,7 +1,7 @@ .{process, log} := @use("stn") // src: https://git.ablecorp.us/koniifer/lily -exe := @embed("./assets/lily.hbf") +exe := @embed("./assets/lily.axe") test := fn(): uint { process.spawn(@bitcast(&exe), @sizeof(@TypeOf(exe)))