Post AWzlb6gNCRh3vxhdGC by xerz@fedi.xerz.one
(DIR) More posts by xerz@fedi.xerz.one
(DIR) Post #AWzYdmOBo7IKSa8q6y by xerz@fedi.xerz.one
2023-06-23T18:55:32.455266Z
0 likes, 0 repeats
I want to write a kernel in RustI'm gonna write a kernel in Rust
(DIR) Post #AWzYy5OkqEp3Cv5ZHk by efi@chitter.xyz
2023-06-23T18:56:24Z
0 likes, 0 repeats
@xerz stahp
(DIR) Post #AWzYy63WOfQrFMA7pQ by xerz@fedi.xerz.one
2023-06-23T18:59:10.772058Z
0 likes, 0 repeats
@efi octagon
(DIR) Post #AWzZQF3sVVZ9HmkY9Q by xerz@fedi.xerz.one
2023-06-23T19:04:16.555037Z
0 likes, 0 repeats
I have officially pulled off the hardest part of making software
(DIR) Post #AWzZtDWhIHlovG2vQ0 by xerz@fedi.xerz.one
2023-06-23T19:09:28.951159Z
0 likes, 0 repeats
Next up is figuring out how to define a new target and use it.This is the part where I wonder if I should use `xargo` (abandonware) or if I can get away with something more reasonable as long as I don't need a port of the stdlib
(DIR) Post #AWza5D1uxvDmrFMqjg by xerz@fedi.xerz.one
2023-06-23T19:11:38.753311Z
0 likes, 0 repeats
…I believe I should be fine as long as I simply do something like cargo build --target x86_64-unknown-none :blobcatthink:
(DIR) Post #AWzaDweFF4KeemSb5M by xerz@fedi.xerz.one
2023-06-23T19:13:15.802805Z
0 likes, 0 repeats
@arcade where's the fun in that tho asdjlnskfljhnkjds :blobcatsadreach: (that may end up being pretty handy, thxthx! although I already have a few contacts, personally I just like to bother people as little as possible...)
(DIR) Post #AWzaIlMAeQXF5JIsvQ by MeDueleLaTeta@awoo.fai.st
2023-06-23T19:13:49.135639Z
1 likes, 1 repeats
@xerz mi me te hizo este salto: ah si xargo el cargo en gallego
(DIR) Post #AWzaNH6aYIRSi4AOVk by xerz@fedi.xerz.one
2023-06-23T19:14:57.435452Z
0 likes, 0 repeats
@MeDueleLaTeta ……………también podría ser fargiña………….me voy chao
(DIR) Post #AWzafceFC9wsjhepKC by xerz@fedi.xerz.one
2023-06-23T19:18:16.177086Z
0 likes, 0 repeats
I know how to make a bootloader (both a tiny MBR boot sector payload in assembly and compiling a custom UEFI program... in C++), but I will try to use this pretty popular crate https://github.com/rust-osdev/bootloader#kernel
(DIR) Post #AWzamWwSoCph49TQ92 by xerz@fedi.xerz.one
2023-06-23T19:19:31.568699Z
0 likes, 0 repeats
(I can also, just, yeet the bootloader altogether and make my kernel an UEFI program)(.......................................maybe)
(DIR) Post #AWzb048sgMHhncjgTw by xerz@fedi.xerz.one
2023-06-23T19:21:57.259919Z
0 likes, 0 repeats
gathering everything uprustup target add x86_64-unknown-nonerustup target add x86_64-unknown-uefi
(DIR) Post #AWzbTpIwPfbAT6dGoS by spinach@tech.lgbt
2023-06-23T19:26:18Z
0 likes, 0 repeats
@xerz isn’t the Linux kernel already partially in Rust
(DIR) Post #AWzbTqBX8hGdCQAruC by xerz@fedi.xerz.one
2023-06-23T19:27:18.425840Z
0 likes, 0 repeats
@spinach a tiny irrelevant portion (it's only being used for little more than Asahi Linux drivers iirc)
(DIR) Post #AWzbc2hgTmpULF7iXw by xerz@fedi.xerz.one
2023-06-23T19:28:50.346075Z
0 likes, 0 repeats
o, #[no_mangle] doesn’t work anymorethings moving at a moderately accelerated pace in crab world
(DIR) Post #AWzboc2WvTN9PTrrgu by mian@miniwa.moe
2023-06-23T19:31:06.551368Z
0 likes, 0 repeats
@xerz Why not contribute https://www.redox-os.org/ ?
(DIR) Post #AWzby88cxEojZFG46i by xerz@fedi.xerz.one
2023-06-23T19:32:46.676428Z
0 likes, 0 repeats
@mian ...did I imply at any point that I want to make a prod kernel or that my vision for a prod kernel aligns with that of Redox? :blobcatsweat:
(DIR) Post #AWzcPl5KG90kB3t7Hk by mian@miniwa.moe
2023-06-23T19:37:49.139660Z
0 likes, 0 repeats
@xerz So u wana be like Terry Davis?
(DIR) Post #AWzcTAFDApI74p8UUK by xerz@fedi.xerz.one
2023-06-23T19:38:25.384962Z
0 likes, 0 repeats
@mian :blobcatpeekaboo:
(DIR) Post #AWzcY2NppNdG91UdrE by xerz@fedi.xerz.one
2023-06-23T19:39:19.944931Z
1 likes, 0 repeats
now this is what I call programming certified hood classic
(DIR) Post #AWzd2zEzYtnLNJ7Azw by xerz@fedi.xerz.one
2023-06-23T19:44:51.390445Z
0 likes, 0 repeats
apparently you need something called the Never type (!) which is equivalent to an useless enum and which basically tells Rust “hey, this function just, never ends, that’s it” https://doc.rust-lang.org/reference/types/never.html
(DIR) Post #AWzdUX2I1KUw0WJ9KS by xerz@fedi.xerz.one
2023-06-23T19:49:52.525073Z
0 likes, 0 repeats
`bootloader` has an issue, however: it is too high levelit tries to define `_start` on my behalf and creates an ELF executable:blobcatsipglare:
(DIR) Post #AWzdni0HT2NFWbVplw by xerz@fedi.xerz.one
2023-06-23T19:53:20.743694Z
1 likes, 0 repeats
(.....oh my gosh it actually is running within Linux and looping as intended)
(DIR) Post #AWze7AGcbm1sgWQug4 by xerz@fedi.xerz.one
2023-06-23T19:56:49.838521Z
0 likes, 0 repeats
that does imply that my codebase is already generating an ELF executable, which I guess makes sense considering I'm building a program that looks (mostly) like any other
(DIR) Post #AWzeA3BrNNZxbaa8bg by tromino@mstdn.io
2023-06-23T19:54:25Z
0 likes, 0 repeats
@xerz now port doom to your new complete fully featured kernel :3
(DIR) Post #AWzeA46vxBEUSbHiZE by xerz@fedi.xerz.one
2023-06-23T19:57:23.698014Z
0 likes, 0 repeats
@tromino what about going straight for Crysis :blobcatthinkOwO:
(DIR) Post #AWzeGb0YYVm8E6PqM4 by xerz@fedi.xerz.one
2023-06-23T19:58:34.262588Z
0 likes, 0 repeats
also: #[no_mangle] works now, guess Rust wanted me to give a little bit more context
(DIR) Post #AWzfeauCgisIoSS3ii by xerz@fedi.xerz.one
2023-06-23T20:14:05.244169Z
0 likes, 0 repeats
I just checked using x86_64-unknown-none-elf and it seems the LLVM target for x86_64-unknown-none is… x86_64-unknown-none-elfhuh
(DIR) Post #AWzfn5wv9TBNPUmAca by xerz@fedi.xerz.one
2023-06-23T20:15:39.349865Z
0 likes, 0 repeats
I just checked using rustc +nightly -Z unstable-options --target=x86_64-unknown-none --print target-spec-json and it seems the LLVM target is… x86_64-unknown-none-elfhuh
(DIR) Post #AWzgAb0rp93yPepOYS by xerz@fedi.xerz.one
2023-06-23T20:19:53.244045Z
0 likes, 0 repeats
so, it seems that at this point I must chooseeither keep going using ELF executablesor recompile the std (which might as well not even work)
(DIR) Post #AWzgP8mX4LY7CP3gRM by xerz@fedi.xerz.one
2023-06-23T20:22:31.723935Z
0 likes, 0 repeats
I think I’m gonna pull out the third option (which is the second but without xargo, still might as well not even work) https://doc.rust-lang.org/cargo/reference/unstable.html#build-std
(DIR) Post #AWzh1ZT6IUwUyDIJUm by xerz@fedi.xerz.one
2023-06-23T20:29:27.085527Z
0 likes, 0 repeats
..........I have accidentally ended up basically copy-pasting most of this tutorialsurprisingly, almost entirely just by looking up stuff on my own :blobcatderpy: https://os.phil-opp.com/minimal-rust-kernel/
(DIR) Post #AWzh6TDKygxt1MG18C by xerz@fedi.xerz.one
2023-06-23T20:30:21.674229Z
1 likes, 0 repeats
I still get an ELF file, guess that is unavoidable
(DIR) Post #AWzhR6IBObng0lMRkm by xerz@fedi.xerz.one
2023-06-23T20:34:04.760653Z
0 likes, 0 repeats
I am being informed `objcopy` is what I'm looking for
(DIR) Post #AWziXueh9yaftwhf72 by bugaevc@floss.social
2023-06-23T20:44:16Z
1 likes, 1 repeats
@xerz objcopy is so out of fashion, check out this new hotness that GNU binutils developers don't want you to know about: https://github.com/systemd/systemd/blob/main/tools/elf2efi.pyYes, they really have a Python script, of all things, that makes a PE out of an ELF
(DIR) Post #AWziZV9wvLoxPG50Qy by xerz@fedi.xerz.one
2023-06-23T20:46:49.558372Z
0 likes, 0 repeats
@bugaevc .....................what use case does this satisfy :blobcatsweat:
(DIR) Post #AWzieXKMI7X3ZtLiyW by bugaevc@floss.social
2023-06-23T20:45:43Z
0 likes, 0 repeats
@xerz more seriously though, why don't you want to use ELF? you really really should
(DIR) Post #AWzieXy3uVI7Z1vQrQ by xerz@fedi.xerz.one
2023-06-23T20:47:43.127635Z
0 likes, 0 repeats
@bugaevc Basically? Just trying to create something as low level as possible without going straight up into assembly (with the exception of whatever payload I strictly need). Learning and all of that.
(DIR) Post #AWzjfCeYk75dhZgDKq by bugaevc@floss.social
2023-06-23T20:51:42Z
0 likes, 0 repeats
@xerz ........so how is not using ELF is going to help with that?
(DIR) Post #AWzjfDTFhddiEnOhLk by xerz@fedi.xerz.one
2023-06-23T20:58:56.922580Z
0 likes, 0 repeats
@bugaevc Using an executable format for a kernel image, like ELF or PE, implies that you need something else to read the format and find where to start running. My intention, to start with and for very useless reasons, was to get so ridiculously basic that the whole kernel fits into the MBR bootstrap code area
(DIR) Post #AWzkH5lWnbOnLQ0Rou by chjara@snowdin.town
2023-06-23T21:00:09.316158Z
0 likes, 0 repeats
@xerz @bugaevc you're not gonna do much in 512 bytes without hand-optimizing the assembly
(DIR) Post #AWzkH6R0JOZlQ3PZT6 by xerz@fedi.xerz.one
2023-06-23T21:05:50.630075Z
0 likes, 0 repeats
@chjara @bugaevc why would I want to do much when I can make a kernel that just does a sequential read of a floppy and implements what’s needed for an echo
(DIR) Post #AWzl6MtarxkzF1EHFQ by bugaevc@floss.social
2023-06-23T21:07:05Z
1 likes, 0 repeats
@xerz ...ohBut isn't that like 512 bytes or something? You're not going to fit anything there, certainly not in Rust.But yes if you want that, just build an ELF (as you should anyway) and objcopy .text out of it. When I was doing some firmware hacking at $PREV_DAYJOB, I had to deal with both raw ROM images (that's how the device wanted its firmware) and ELFs (that's how every single tool, including GDB, wants it), and converted between the two with objcopy.
(DIR) Post #AWzlb6gNCRh3vxhdGC by xerz@fedi.xerz.one
2023-06-23T21:20:39.073330Z
0 likes, 0 repeats
wait where was Ioh yeah right, objcopy workslook at all that fancy code
(DIR) Post #AWzmrbo7LUm53Nl2XY by xerz@fedi.xerz.one
2023-06-23T21:34:53.204075Z
0 likes, 0 repeats
so now that I have a raw binary program, all I need to do is insert it within the first 446 bytes of a floppy (or whatever the equivalent is, like El Torito), followed by 0x55AA at 0x1FE ‒ this can be done with a linker script or a mix of tools like dd and echo :blobcatuwu:
(DIR) Post #AWzmz4KhgdLvYEYaTQ by xerz@fedi.xerz.one
2023-06-23T21:36:13.902720Z
0 likes, 0 repeats
…or xxd -r because that’s apparently a thing I can use
(DIR) Post #AWznHz5hOtKInNYfRI by xerz@fedi.xerz.one
2023-06-23T21:39:39.895908Z
0 likes, 0 repeats
yep, that worksecho "1FE: 55AA" | xxd -r - elmos.bin
(DIR) Post #AWznPcS3SPG0tgehSC by xerz@fedi.xerz.one
2023-06-23T21:40:59.896809Z
0 likes, 0 repeats
it works :blobcatgooglyheadache:
(DIR) Post #AWzoVg7kocT7ylc4h6 by xerz@fedi.xerz.one
2023-06-23T21:53:19.442679Z
0 likes, 0 repeats
> 11088 bytes for just a simple loophaha that's very funny Rust
(DIR) Post #AWzonaFFPe0OxRejTs by xerz@fedi.xerz.one
2023-06-23T21:56:34.630280Z
0 likes, 0 repeats
it seems that the entirety of the baggage is caused by the very expensive and complicated act ofincrementing a counter
(DIR) Post #AWzpQWSrOzFcWiagqW by xerz@fedi.xerz.one
2023-06-23T22:03:36.258696Z
0 likes, 0 repeats
changed to looping per item instead of incrementing a counterstill 4285 bytes
(DIR) Post #AWzpv2AA72UHWcOTNQ by xerz@fedi.xerz.one
2023-06-23T22:09:01.146102Z
0 likes, 0 repeats
ok I figured this out, I really really need to let Rust handle things for me instead of trying to think of it rather like C or assembly
(DIR) Post #AWzqCaUfizMcvIMDOi by xerz@fedi.xerz.one
2023-06-23T22:12:18.431019Z
0 likes, 0 repeats
Sadly, it seems like my code is not *really* running. After adding that bit of code so I can print text in VGA text mode, I try to boot up from my newly created binary, it's just... looping again.
(DIR) Post #AWzqG72v9UI8ke3e2y by xerz@fedi.xerz.one
2023-06-23T22:12:57.222619Z
0 likes, 0 repeats
gonna git commit this so I can keep it for later, I’m gonna try to use the bootloader crate now
(DIR) Post #AWzqhVbLxokwj9E7SS by xerz@fedi.xerz.one
2023-06-23T22:17:51.923805Z
0 likes, 0 repeats
...wait of courseI'm using 64 bit instructions for a 16 bit machine
(DIR) Post #AWzqzHkKDSioy5tqRE by xerz@fedi.xerz.one
2023-06-23T22:21:06.355214Z
0 likes, 0 repeats
this will come in handy https://github.com/Serentty/rusty-dos/blob/master/dos.json
(DIR) Post #AWzrNUIDDh6OpZI5Vg by xerz@fedi.xerz.one
2023-06-23T22:25:28.179544Z
0 likes, 0 repeats
sadly tho, while that IS useful, I'm still ultimately constrained by my biggest enemy: LLVM (wait what)https://reddit.com/r/rust/comments/zzqfn8/how_can_i_compile_rust_for_16bit_x86_intel_8086/(remember to access through whatever helps you keep up the protest)
(DIR) Post #AWzrVHwJ27ACpmlQYq by xerz@fedi.xerz.one
2023-06-23T22:26:53.419071Z
0 likes, 0 repeats
I guess THIS is the real reason why you cannot build an OS entirely in Rust without assembly: there's just no support in LLVM for 8086 real mode
(DIR) Post #AWzsCuJAFs7MHiFrbE by xerz@fedi.xerz.one
2023-06-23T22:34:45.709619Z
0 likes, 0 repeats
ohmygosh
(DIR) Post #AWzsEQCh9YnPUrx1ZA by xerz@fedi.xerz.one
2023-06-23T22:35:03.700379Z
0 likes, 0 repeats
WHY DOES THIS WORK, I'M USING A 32 BIT TARGET WHAT THE ABSOLUTE HELL
(DIR) Post #AWztGIK3Whe9aRqopE by xerz@fedi.xerz.one
2023-06-23T22:46:33.525701Z
0 likes, 0 repeats
...I broke it while trying to create a Makefile and I can't tell why, what happened...
(DIR) Post #AWzta5K9Z1mp44KipM by xerz@fedi.xerz.one
2023-06-23T22:50:10.299133Z
0 likes, 0 repeats
ah, KVM breaks my OS, that's what happened
(DIR) Post #AWzua2quqxFTLyCceu by xerz@fedi.xerz.one
2023-06-23T23:01:19.085518Z
0 likes, 0 repeats
@gabboman elmOS, in reference to the priest of the glorious shape, the octagon(this is a YTPMV joke from a decade ago...........)definitely far from POSIX-like since this one is merely my way to learn what exactly do I need to make a x86 kernel in Rust, although it seems I'm pretty much there already
(DIR) Post #AWzuvjV7TxzNhrLhuy by xerz@fedi.xerz.one
2023-06-23T23:05:13.523493Z
0 likes, 0 repeats
there's definitely memory alignment issues too since I'm using 32 bit pointers, or at least I think that's why my loops ain't behaving exactly as expected
(DIR) Post #AWzvMzukZ8ewQkL2Uy by xerz@fedi.xerz.one
2023-06-23T23:10:07.787225Z
0 likes, 0 repeats
worked around it, honestly it's pretty minor
(DIR) Post #AWzw0zz5izhkENRWZk by tromino@snug.moe
2023-06-23T23:16:29.090Z
1 likes, 1 repeats
@xerz@fedi.xerz.one SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
(DIR) Post #AWzw11vcUs7GGBpmRU by tromino@snug.moe
2023-06-23T23:17:00.529Z
0 likes, 0 repeats
@xerz@fedi.xerz.one nooo akkoma doesn't support mfm colors
(DIR) Post #AWzw12a24cRUHWk3Qu by xerz@fedi.xerz.one
2023-06-23T23:17:23.848702Z
0 likes, 0 repeats
@tromino I think I need to upgrade tbh
(DIR) Post #AWzxJQGWqmFMuJwqzA by xerz@fedi.xerz.one
2023-06-23T23:31:56.661300Z
0 likes, 0 repeats
I broke it again and I have no idea what's going on anymore
(DIR) Post #AWzxhQte9jgHoXh6Xo by xerz@fedi.xerz.one
2023-06-23T23:36:19.132287Z
0 likes, 0 repeats
I'm desperate, I seriously don't know what I broke and I want to sleep, I've been like this for 15 minutes
(DIR) Post #AWzxwCncqp8UR7vEKe by xerz@fedi.xerz.one
2023-06-23T23:38:59.239409Z
0 likes, 0 repeats
…o, apparently xxd is no longer doing what it’s supposed to??????
(DIR) Post #AWzy0jAgR1x1zirb96 by xerz@fedi.xerz.one
2023-06-23T23:39:49.087289Z
0 likes, 0 repeats
yep, I missed the dash, my fault
(DIR) Post #AWzydv0mLZtM0gv04m by xerz@fedi.xerz.one
2023-06-23T23:46:51.083799Z
0 likes, 0 repeats
It's here now, just `make run` https://codeberg.org/xerz/elmOS
(DIR) Post #AWzyflMLCksOeZspVo by xerz@fedi.xerz.one
2023-06-23T23:47:14.121608Z
0 likes, 0 repeats
ok here it is, just make run and enjoy :blobcrab: https://codeberg.org/xerz/elmOS
(DIR) Post #AX0zLZe9KxZNeD6tLk by xerz@fedi.xerz.one
2023-06-24T11:02:17.292320Z
0 likes, 0 repeats
Mornyan, guess I should check if the symbol stripping step is needed and if I can fix the weird offse issuealso, figure out why it even works in the first place
(DIR) Post #AX0zLaX62fWQOcolzk by xerz@fedi.xerz.one
2023-06-24T11:27:24.576593Z
0 likes, 0 repeats
OK, strip does remove around 200 bytes already, it stays
(DIR) Post #AX10dWuAMwkCJLjB1E by xerz@fedi.xerz.one
2023-06-24T11:43:47.184661Z
0 likes, 0 repeats
also there’s no way around, you have to use the 32 bit pointer settingI’m gonna presume this works at all because x86 is little endian, which means that the values are always appended at the start, and thus anything works in 16 bits so long as your pointers and integers fit as well in that portion ‒ also, presumably the instruction set is just the same and does not break in whichever ways x86_64 doesbut that still feels wrong
(DIR) Post #AX10t8SJ2Tcx7G8azA by xerz@fedi.xerz.one
2023-06-24T11:45:11.942067Z
0 likes, 0 repeats
(…is the rest of the data interpreted as a NOP?)
(DIR) Post #AX11TxMvDqq5RgB23M by famicom@pl.kotobank.ch
2023-06-24T11:54:09.246095Z
1 likes, 0 repeats
@xerz Yep, opcodes for 32-bit operations in protected mode are the same as for 16-bit operations in real mode and the size override prefix 0x66 makes them the opposite size (so you can operate on 32-bit values in real mode on 386 and higher).Offsets work because they're little-endian, so the first two bytes are interpreted to be a 16-bit offset and the following 0x00 0x00 are decoded into `add [ax], al`, which has a lot of potential to mess stuff up.
(DIR) Post #AX13BJvVKRhZoUaspE by xerz@fedi.xerz.one
2023-06-24T12:10:04.146333Z
0 likes, 0 repeats
@famicom ...ah, guess I cannot use this for anything other than a toy then unless I do some magic :blobcatthink:
(DIR) Post #AXEIC1qWXttcSIDIhM by xerz@fedi.xerz.one
2023-06-30T21:31:32.176490Z
0 likes, 0 repeats
so I just checked back on the kernel and dunno I guess I made the loop work as expected
(DIR) Post #AXEKOc5tnnjSGAX9Jg by xerz@fedi.xerz.one
2023-06-30T21:56:33.218750Z
0 likes, 0 repeats
somehow I can't manage to run it on bare metal from USB, I tried both direct booting and GRUB2 and nothingit works on QEMU thoweh
(DIR) Post #AXELTLw3PKaHXvkiTA by xerz@fedi.xerz.one
2023-06-30T22:08:34.277744Z
0 likes, 0 repeats
ftr: for GRUB2 boot what I did wasinsmod chainlsset root=(hd1)chainloader +1boot
(DIR) Post #AXELW9UQ8XrrocA6YS by xerz@fedi.xerz.one
2023-06-30T22:09:08.654608Z
0 likes, 0 repeats
(I also did chainloader (hd1)+1, still nothing)
(DIR) Post #AXEMFiaSUaGNhPiJfs by xerz@fedi.xerz.one
2023-06-30T22:17:23.069426Z
0 likes, 0 repeats
like, does USB boot need anything outside the first 512 bytes?
(DIR) Post #AXEPwxmcAY6R8xiDNg by xerz@fedi.xerz.one
2023-06-30T22:58:12.852508Z
0 likes, 0 repeats
hmmm, maybe it's because the sector size differs?
(DIR) Post #AXESZjQDhIg9nyqpay by xerz@fedi.xerz.one
2023-06-30T23:28:06.959542Z
0 likes, 0 repeats
maybe it's because I don't define any partitions…?