IRC channel logs

2024-05-13.log

back to list of logs

<oriansj>fossy: reviewed and merged
<Piraty>ACTION reviews oriansj
<oriansj>ACTION a flower is born to blush unseen.
<roconnor>What's the difference between hex2 and M0. The documentation just says that M0 is an archetecture specific version of M1, and that M1 is a cross platform version of "M0", without saying what either one is.
<stikonas>roconnor: hi
<stikonas>M0 is assembler, hex2 is linker
<stikonas>there are some readme files with examples
<stikonas>let me find it
<roconnor>oh. I thought hex2 was an assembler.
<stikonas>roconnor: compare https://github.com/fosslinux/live-bootstrap/blob/master/parts.rst#hex2 and https://github.com/fosslinux/live-bootstrap/blob/master/parts.rst#hex2
<stikonas>well, hex assembler is basically a linker in some sense
<stikonas>at least in the simple cases of stage0...
<stikonas>so hex0 can take pair of hex characters and creates a byte. The main addition in hex2 on top of that is ability to resolve addresses for jumps and branches
<stikonas>so it kind of makes it into a simple linker
<roconnor>oh hex2 has no DEFINE.
<stikonas>indeed
<stikonas>so you still program using hex sequences (except for references to other labels which hex2 calculates)
<roconnor>does M0 subsume hex2, i.e. it can operate on .hex2 files and produces the same output that hex2 does?
<stikonas>no
<stikonas>you chain them
<stikonas>so M0 takes file with DEFINES and produces something that hex2 can process
<roconnor>oh M0 outputs hex2?
<stikonas>yes
<stikonas>then similarly cc_* and M2-Planet produce something M0 (or later M1) can process
<roconnor>so M0 mostly just inlines DEFINES?
<stikonas>a bit more than that but that's the main addition
<stikonas>it can also encode numbers for you
<roconnor>oh the %2 thing?
<stikonas>e.g. sub_ebx, %2
<stikonas>yeah
<stikonas>on x86 it will become 02000000
<stikonas>on riscv it's far more shuffled
<roconnor>Good good.
<stikonas>so M0 is fairly close to GAS assembler
<stikonas>but with somewhat weird syntax
<stikonas>in GAS you would have sub ebx, 2
<stikonas>so actually even mescc compiler (part of GNU mes project) that you can use after stage0-posix still produces M1 files as output, then you run them through M1 to get hex2 output and then hex2 produces final binary
<stikonas>only next stage (tcc) starts producing binutils compatible object files...
<roconnor>Looks like M1 is the format and M0 and M2 are the assemblers.
<stikonas>it's slightly more confusing
<stikonas>M0 and M1 are related but M2 is not
<stikonas>so M0 is arch specific tool written in hex that processes that file with DEFINES
<stikonas>M1 is the C cross-platform version of the same tool
<stikonas>but it does support more features too
<stikonas>it has far nicer argument praser, so you can specify multiple files, better error checking
<stikonas>and also supports woth lowercase and uppercacse hex numbers
<stikonas>but generally they work on the same format
<stikonas>on the other hand M2 refers to M2-Planet
<stikonas>which is the simple C compiler written in an even simpler cc_* dialect
<stikonas>in stage0-posix we build it twice
<stikonas>first build is compiled using cc_* (e..g. cc_x86) and binary is saved as M2
<stikonas>(it also uses simplified version of M2libc)
<stikonas>then we build C versions of hex2 and M1
<stikonas>and rebuild the whole thing from just C tools
<stikonas>i.e. use M2 binary to rebuilt itself from source (but this time using full M2libc library)
<stikonas>that binary is then saved as M2-Planet
<stikonas>roconnor: hopefully this clarrifies things a bit
<roconnor>Yep.
<stikonas>so we actually have lots of different versions of those early tools (M0_x86, M0_amd64, M0_riscv64...) but just one M1
<stikonas>(we even have amd64 version of them for UEFI
<roconnor>oh I see. So M1 can cross-compile.
<roconnor>or something like that.
<stikonas>yeah, M2, M1 and C version of hex2 can indeed cross-compile
<stikonas>roconnor: and this might be especially useful for bootstrapping on UEFI
<roconnor>does M1 produce the same output that M0 does on all the inputs that M0 can handle? (when not cross compiling)
<stikonas>you start with native UEFI binaries (stage0-uefi) but then mescc has no support for UEFI
<stikonas>so you cross-compile POSIX versions
<stikonas>and try to continue using some kind of posix emulation
<stikonas>roconnor: almost the output
<stikonas>I think line endings are different in .hex2 file
<roconnor>interesting.
<stikonas>I think one of them does one token per line
<stikonas>and the other multiple
<stikonas>but it will result in the same binary once you pass it through hex2
<roconnor>ah
<stikonas>so intermediate output is not exactly the same
<stikonas>but final binary should ne
<stikonas>should be
<stikonas>but I did use those C versions for debugging when working on assembly level tools too
<roconnor>which C versions?