raven[x]: it begins.
raven[x]: https://git.citrons.xyz/tinycc
olive[x]: are you aware you can push directly to tinycc proper
raven[x]: what do you mean?
olive[x]: they have a "mob" branch
olive[x]: the idea is like wikipages
olive[x]: anyone can push or so
olive[x]: repo.or.cz has an explanation page somewhere
raven[x]: so, I could commit malware to the mob branch right now?
olive[x]: https://repo.or.cz/h/mob.html
olive[x]: plausibly
olive[x]: just as one can add disinformation to wikipedia
olive[x]: but that is easier to spot
raven[x]: that's true, but ugh.
raven[x]: the last actual commit to master was 8 years ago
olive[x]: the tinycc maintainer is awol
olive[x]: yea
raven[x]: I like the idea of "finished software" that stops receiving
updates. everyone is always saying "dead project!!!1! it's not maintained!!!!"
raven[x]: however.
raven[x]: tcc is far from finished. that's why I'm working on it
olive[x]: lots of Luanti mods are effectively "finished"
viba[x]: > I like the idea of "finished software" that stops receiving
updates. everyone is always saying "dead project!!!1! it's not maintained!!!!"
viba[x]: im still trying to turn off the part of my brain that instantly
discards things based on the last commit date
raven[x]: hm, ok, I'm kind of starting to get how this works in practice
raven[x]:
https://repo.or.cz/tinycc.git/commit/d9a6d9aec058ec92c1ad19ccf9e7913bc8ea945f
olive[x]: miu i can't see what's behind this link
raven[x]:
https://web.archive.org/https://repo.or.cz/tinycc.git/commit/d9a6d9aec058ec92c1ad19ccf9e7913bc8ea945f
raven[x]: ok, I just pushed to the mob branch. hi mom
raven[x]: I did --unset-upstream so I don't accidentally do that.
raven[x]: because I can run git push sort of reflexively sometimes
raven[x]: this is kind of neat. I mean, it's a little scarier of an idea
than wikipedia in my opinion.
raven[x]: because you can't put malware on wikipedia. at least, not easily.
raven[x]: I think it would be interesting to try to take the pseudocode in
architecture manuals and create an interpreter for it
raven[x]: thus deriving an emulator directly from the specification
raven[x]: the assembler does not support PC-relative ADR or LDR. evidently
these aren't needed in the C compiler. the relocations they require are not
implemented in the linker, so to implement them, I'll have to touch the linker
raven[x]: however, actually, that makes me wonder what it does instead.
raven[x]: the limited featureset of the linker implies that you'd probably
have trouble linking code generated by other compilers
raven[x]: ah. I see.
raven[x]: you can just do ldr r0, [pc], offset
raven[x]: um, yes, so, it puts the constant in the middle of the code, loads
with pc as the base register, and then jumps over the constant
raven[x]: that seems at least somewhat suboptimal
raven[x]: nonetheless, I suppose I could use the same approach in my
assembler code and avoid hacking on TCC anymore
raven[x]: because although I think it would be very worthwhile to improve
TCC, it's distracting from the project I'm using TCC for.
rebecca[x]: what's the project?
raven[x]: I've contracted osdev disease again.
raven[x]: I want to make my operating system with TCC, so then I can port
TCC to my operating system, and then have it be selfhosting.
the raspberry pi's firmware loads a flat binary into memory. it doesn't understand ELF images or anything; it just starts executing from the beginning. the osdev wiki tells you to use GNU linker scripts, but as I am not using binutils, I'm going to use the advanced linker called "cat."
I'm going to have a tiny loader that is compiled as a flat binary. an ELF image of the kernel will be concatenated to the end of it. the loader will peek into the ELF header, hollow out .bss, and jump into the entry point.
if I understand how ELF images work correctly, this should work.
ok, well, I've been staring at objdump output, not necessarily understanding what it all means, and I think it might expect me to map things where they don't end up necessarily just by blindly copying it into memory.
if I can't make this work easily, it might actually just be better to have my entire kernel be a single compilation unit, compile it all as a flat binary, and presumably everything will appear in the order I specify it.
I wonder, actually, if I could have separate compilation units, but name the unit containing the init code alphabetically before the others. that would be such a nasty hack, haha.
it can also emit flat binaries, but it's unclear where the entry point is. of course, that can be solved by my "having everything be in one compilation unit" idea, which I'm starting to think would be a good idea, especially considering TCC's breakneck compilation speeds.
a reasonable question would be: "how are you going to write an entry point in assembler if you're compiling everything as one C compilation unit?" of course, the answer to that is that mercifully and quite conveniently, TCC supports asm at the toplevel.
you know, I'm actually pretty sure that if I just specify the entry point object file first in the command line arguments, it will probably put that first in the file in the beginning of the output. I'll just try doing that.
booting my image in qemu, it of course does not work the first time. I'm having to debug the classic issue of "it's jumping somewhere random in memory for some reason." of course, the issue seems unrelated to linker nonsense, so that's good. it's probably a silly mistake of mine.
wait a minute! tcc generated adrp! that's not supported in the assembler! I was under the impression that the C compiler couldn't generate it either because the linker doesn't seem to handle the relocation that's required.
so, I'm going to implement SMP as soon as possible, so that I produce code that is amenable to parallelism from the very start. as it turns out, ARM has some very neat instructions to put cores in a low power state for waiting for things.
ARMv7 provides a locking mechanism based on events. The Wait For Event lock mechanism permits a processor that has failed to obtain a lock to enter a low-power state. When the processor that currently holds the required lock releases the lock it sends an event that causes any waiting processors to wake up and attempt to gain the lock again.
this is what wfe is for. you go to sleep with your w(i)fe. then, you're awoken by sev. sev wakes up all the processors that are waiting, and they check their respective locks/semaphores/what have you.
it's pretty frustrating when I want to do something in TCC and then it says, "sorry, can't do that thing." but then, I can hack on it and then it does that thing. the only drawback is that now it's 7am.
I had to squint my eyes at the ARM manual for hours to start understanding how everything fits together, so it took me a while to implement all these instructions. however, as I progressively page more and more of this information into my brain, it will probably become easier and I will be able to work a lot faster.
if I generate a flat binary, I lack debugging symbols. this is making debugging difficult. even if I separately compile an ELF, the symbols don't end up in the same place.
most kernels need to be mapped into the higher half of memory. so, remapping pages is something I already need to do. so, what I'm going to do is go back to my idea of appending an ELF image onto the flat binary, but I'm going to read the ELF properly and map its segments, and I'm going to compile it targeting the higher half of memory.