IRC channel logs

2022-10-10.log

back to list of logs

<stikonas>hmm, interesting cc_amd64 problems when running directly in qemu without first going into bios menu or uefi shell seem to be stack related
<stikonas>in particular that user stack thing
<stikonas>though I don't yet understand how exactly
<muurkha>oriansj: I agree; it's kind of based on the PDP-8 or the DG NOVA, but the NOVA *did* have 4 registers
<stikonas>hmm, it's definitely UEFI shell that initializes something... BIOS menu only works after you exit from uefi shell but not before...
<Christoph[m]>If there was, say, editor support for dealing with relative jumps, would you consider the result as written not by humans and thus not acceptable for bootstrap?
<Christoph[m]>Or are there so few files that would be benefiting such an effort that it's not worth it?
<AwesomeAdam54321>Christoph[m]: I would consider editor support for relative jumps to be acceptable for bootstrapping, if the relative jumps in the editor's source code were calculated by hand
<stikonas[m]>Well, there isn't that much hex0 code
<stikonas[m]>Relative jumps are painful to cal calculate but we don't have that many of them
<stikonas[m]>And if they are automatically calculated then it's a bit of cheating
<Christoph[m]>hex0 code has to be written for each supported architecture?
<unmatched-paren>Christoph[m]: yes
<unmatched-paren>it's just a different and more tedious way to write assembly
<oriansj>stikonas: merged
<oriansj>Christoph[m]: well the hardest part of getting started with hex0, usually if you have to figure out all the stupid details which are never documented or are often documented incorrectly.
<oriansj>for example ARM incorrectly documents the order of the bits. it isn't [condition code] [operation] [register][register][shift][register], it is actually [shift][register][register][part opcode][register][condition code][part opcode]
<oriansj>PowerPC does ELF headers e_entry entirely differently from everyone else
<oriansj>RISC-V required a whole song and dance just to get to a minimal working state
<oriansj>muurkha: I think their 15bit immediate is probably to blame for the technical choices made in the design.
<oriansj>if they went with 32bit instructions, 16bit immediate and 16 registers and added just a handful more circuits to the main design (barrel shifter, call and return); then the assembly programming becomes so much cleaner and you can avoid having to do A = A ^ D; D = A ^D; A = A ^ D; (XOR swaps make me feel like a dirty little programming whore)
<stikonas[m]>Christoph: And UEFI versions of hex0 required oriansj to figure out PE32 header
<stikonas[m]>There is a bit of documentation but very incomplete
<stikonas[m]>So a lot of trial and error
<stikonas[m]>And PE32 header is huge, bigger than whole hex0 on POSIX
<stikonas[m]>But a lot of it can be set to zero
<Christoph[m]>Wow! I expected at least RISC-V to be properly documented!
<Christoph[m]>And hex1? Is hex1 architecture independent? Or does that later start with C?
<stikonas[m]>Christoph: hex1 is architecture dependent
<stikonas[m]>Both code and algorithm
<stikonas[m]>hex0 code is architecture dependent (needs to be ported to each ISA/platform) but algorithm is the same
<stikonas[m]>So riscv version of hex0 can build hex0_x86.hex0 into 32-bit Elf executable hex0
<stikonas[m]>Hex1, hex2 and M0 are then generally incompatible
<stikonas[m]>Though x86 and amd64 version are compatible
<stikonas[m]>Then later once we have M2-planet we build C versions (hex2 and M1) to replace early hex2 and M0
<stikonas[m]>Those support all arches
<stikonas[m]>(They accept --architecture command line arguments)
<stikonas[m]>The reason is that different arches do quite different things with labels and immediate constants
<stikonas[m]>E.g. on x86 call function 5 bytes later is E8 05000000
<stikonas[m]>Whereas on RISC that number is encoded very non trivially
<stikonas[m]> https://i.stack.imgur.com/MUKIE.png
<stikonas[m]>Calling function is jump style instruction
<stikonas[m]>And you can see bits are shuffled arround
<stikonas[m]>First you have bit 20 then 10, 9 8, ..., 1, 11, 19, 18, ..., 12
<stikonas[m]>Actually the other way, this diagram is right to left...
<stikonas[m]>But still shuffled a lot
<stikonas[m]>So writing hex0 code is much harder on risc-v compared to x86/amd64
<stikonas[m]>On x86 you just take a number, convert to hex and swap byte order to little endian
<stikonas[m]>No other shuffling of bits is necessary
<stikonas[m]>And on risc-v I used this template to help me: https://github.com/oriansj/stage0-posix-riscv64/blob/master/Development/immediate_transformations.txt
<aggi>this hex0 language, is this equivalent to directly feeding opcodes into the CPU?
<muurkha>oriansj: or 17-bit instructions
<stikonas[m]>aggi: basically yes, plus two things: comments and conversion of a pair of ASCII hex numbers to bytes
<stikonas[m]>And we only write 3 things in it
<stikonas[m]>1. hex0 itself. This should be as small as possible
<stikonas[m]>2. kaem-optional-sees: trivial shell that can run other commands, this might be optional if you have a way of running hex0 but is often useful in scripting automations
<stikonas[m]>3. hex1 which can calculate relative jumps
<stikonas[m]>One can just start with hex1 but then your minimal seed would be bigger
<stikonas[m]>Though amount of hex0 code smaller...
***jackhill is now known as KM4MBG
***KM4MBG is now known as jackhill