IRC channel logs

2023-05-19.log

back to list of logs

<stikonas>janneke: got some partial success with scaffold/hello.c
<stikonas>it compiles, runs and exists with 42 but didn't print anything
<stikonas>so I will have to debug what went wrong with printing
<stikonas>hmm, printing works if I comment out environ = envp in __init_io
<stikonas>probably something wrong with crt1.c then...
<stikonas>oh, it's actually variable padding that is broken...
<stikonas>!0x00 is encoded to .00000000 which ends up being empty in binary
<stikonas>it's coming from https://gitlab.com/janneke/mes/-/blob/wip-riscv/module/mescc/M1.scm#L139 ...
<oriansj>stikonas, janneke wouldn't the syscall numbers be best defined in the C library and thus asm ("li_____%a7,SYS_write"); would become asm ("rd_a7 !" SYSCALL_WRITE " addi");
<oriansj>Irvise_: well rain1 did a bit of work with TCC to get it into a state where it could compile GCC again (it for a bit there lost that ability)
<stikonas>oriansj: we do have them in syscall library
<stikonas>I might come back to it later
<stikonas>oriansj: though at the moment C library defines them as #defines
<stikonas>so it's not a string
<stikonas>anyway, I don't think I'll resolve that mescc global variable padding issue today
<stikonas>there is a hack to replace ! with % and overpad everything
<stikonas>but it's a bit ugly
<oriansj>stikonas: no you missed what I am pointing out
<oriansj> https://paste.debian.net/1280621/
<stikonas[m]>Yes, that does work
<oriansj>you just do #DEFINE SYSCALL_WRITE "64"
<stikonas[m]>But currently meslibc has 42 instead of "42"
<stikonas[m]>Oh but that can be solves
<stikonas[m]>I can just add
<oriansj>inside of #ifdef block to determine what architecture uses which values
<stikonas[m]>fputs("hello "'SYSCALL_HUH"" back", stdout)
<stikonas[m]>oriansj: anyway, the bigger issue is global variable padding with zeroes
<stikonas[m]>mescc just prints required number of !0x00
<stikonas[m]>Which is noop in word based hex2...
<oriansj>well we could switch it to the padding in M1 (aka <100 does 100 null bytes)
<stikonas[m]>We should discuss it with janneke anyway...
<oriansj>but if the goal is to padd to alignment < will work
<stikonas[m]>Alignment is optional in mescc right now
<oriansj>but alignment support is required in hex2 and padding support is required in M1
<stikonas[m]>But it will print wither sizeof(var) of !0x00 or register size of !0x00
<oriansj>so just output <sizeof(var)
<oriansj>if sizeof(var) is 42 => <42
<stikonas[m]>Yeah, that might work
<stikonas[m]>Though will still need rewriting that bit of mescc
<stikonas[m]>I guess here https://gitlab.com/janneke/mes/-/blob/wip-riscv/module/mescc/M1.scm#L233
<oriansj>but it would probably simplify things as no need to loop to produce a block of !0x00
<stikonas[m]>Well, it's scheme..., so no loop already
<stikonas[m]>It just creates a list of (0 0 0...) with that iota
<stikonas[m]>And there is another function that converts numbers to M1...
<stikonas[m]>Quite a bit different from how M2-Planet emits code...
<oriansj>yep
<stikonas[m]>Though after a few days it's getting a bit easier to write lisp...
<oriansj>yeah, the hardest bit of using Lisp is just remembering the names and the varargs behavior of functions
<sam_>haha yes
<sam_>glad it's not just me :)
<janneke>"<stikonas> [23:45:25] janneke: got some partial success with scaffold/hello.c"
<janneke>\o/
<janneke>oriansj, stikonas[m]: syscall defines for x86: https://git.savannah.gnu.org/cgit/mes.git/tree/lib/x86-mes/x86.M1#n327
<muurkha>hi joeyh_, thanks for writing git-annex and like a third of Debian
<[exa]><3
<stikonas>oriansj, janneke: I think I found a reasonably nice way to write out those riscv syscalls
<stikonas>oriansj's way didn't work I think because in mescc multiple strings are not concatenated, it has to be a single line string
<stikonas>but I managed to sort it out using macros
<stikonas>e.g. now it looks like asm(RISCV_SYSCALL(SYS_write));
<stikonas>amd then RISCV_SYSCALL is define via
<stikonas>#define MAKESTRING(s) #s
<stikonas>#define MAKESTRING2(str) MAKESTRING(rd_a7 ! ## str addi)
<stikonas>#define RISCV_SYSCALL(str) MAKESTRING2(str
<stikonas>so this way we only need to have one canonical place for syscall numbers (just in syscall.h)
<stikonas>well, there is probably another copy in m2 folder but that's unavoidable, M2-Planet is not capable of parsing such complex macros
<stikonas>still need to deal with the other problem...
<stikonas>that is adding zeroes to store global variables
<stikonas>hmm, I think I should actually more or less port M2-Planet's padding/global variable initialization code to mescc...