IRC channel logs

2022-10-27.log

back to list of logs

<oriansj>stikonas: that is mkdirat; not mkdir
<oriansj>(it is also on my list)
<oriansj>but it does look like we are setting the wrong registers
<oriansj>as we only need to set X1 and X0 (with the syscall in X8)
<oriansj>pretty easy to use GDB to confirm that
<oriansj>USA-RedDragon: if you would like I can talk you through the process
<USA-RedDragon>I made a draft PR with what I've got so far: https://github.com/oriansj/M2libc/pull/17
<oriansj>as all C functions output by M2-Planet have FUNCTION_ prefixes and if you used blood-elf, you can just set a breakpoint at FUNCTION_mkdir
<stikonas>oriansj: as far as I can see, aarch64 does not have mkdir, only mkdirat
<stikonas>and stage0-uefi changes pushed (now reaches M1-0)
<stikonas>I've skipped blood-elf as it's not immediately useful
<stikonas>we can maybe build blood-elf once we have full non-bootstrap M2libc
<stikonas>in case somebody wants to build debug POSIX binaries on UEFI
<oriansj>USA-RedDragon: your SET_X2_FROM_X1 define decodes to: orr x2, xzr, x1, lsl 8 and no arguments are passed to functions via registers (they are passed on the stack)
<oriansj>so you probably want to use e20301aa
<oriansj>(you can verify it with: rasm2 -a arm -b 64 -d 'e20300aa' if you would like)
<oriansj>stikonas: well we could figure out the debug format for PE binaries and then our UEFI binaries can be debuggable as well
<USA-RedDragon>Weird. https://onlinedisassembler.com/odaweb/ decoded both e22301aa and e20301aa to `mov x2, x1`
<USA-RedDragon>But that's alright, that part is going to get reverted anyway
<USA-RedDragon>Got mkdir working
<USA-RedDragon>without that
<USA-RedDragon>Thanks for the `rasm2` top
<USA-RedDragon>tip*
<oriansj>just install radare2 and you can also do things like: rasm2 -a arm -b 64 'mov x2, x1'
<oriansj>that way you don't depend upon a web service to lookup instruction encodings/decodings
<USA-RedDragon>love it
<oriansj>stikonas: Well I did pull these syscall numbers from the Linux kernel itself about 3 years ago but I can't image they removed public syscalls unless no one was using them or they were non-functional
<oriansj>USA-RedDragon: If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than relative to the current working directory of the calling process) mov x0, #-0x64 translates to: mov X0, AT_FDCWD
<oriansj>which just ultimately just causes mkdirat to behave exactly like mkdir
<stikonas>oriansj: not sure if it's that easy, I briefly looked, addind debug sections might make UEFI not run them
<stikonas>so you might need to build two binaries
<stikonas>and we don't have internal gdb either
<stikonas>so one would still have to connect with external gdb
<stikonas>but I found that radare2 (at least on amd64) often gives wrong answers...
<stikonas>so it might be good to use it but double check with web server
<stikonas>actually, the way risc-v was implemented, I didn't have to use anything at all
<stikonas>neither web service nor radare
<stikonas>so that's nice, though at the expense of more complicated hex2 (but that was unavoidable on riscv)
<oriansj>stikonas: well gdb can also be used to disassemble a binary while you run it
<stikonas>anyway, debug binaries can be left for future improvement if somebody bothers
<oriansj>stikonas: completely fair as it looks messy
<USA-RedDragon>I got to stage 4 with the changes in my PR
<stikonas>USA-RedDragon: of live-bootstrap?
<USA-RedDragon>Yeah, sorry
<stikonas>well, those are easy steps
<stikonas>mes -> tcc 0.9.26 is the hard one...
<stikonas>which only works for x86, not even amd64
<USA-RedDragon>Ah I see why mes failed. Comment in the kaem file says "# Restore once mes adds arch specific kaem files". I know my next task
<USA-RedDragon>Well here's hoping I can figure something out. :)
<stikonas>USA-RedDragon: that might have been done already
<stikonas>in the latest mes release
<stikonas>there was one recently and I've already pushed it into live-bootstrap
<USA-RedDragon>Yeah I see some recent arm stuff
<USA-RedDragon>Will kaem pass in variables? Like, for https://git.savannah.gnu.org/cgit/mes.git/tree/kaem.run#n22, can I run `mes_cpu=arm64 kaem --verbose --strict --file kaem.run`
<stikonas>USA-RedDragon: I think so
<stikonas>kaem automatically exports all it's variables to child processes
<stikonas>USA-RedDragon: basically kaem stores all it's env variables in a linked list here https://github.com/oriansj/mescc-tools/blob/master/Kaem/kaem_globals.h#L32
<oriansj>USA-RedDragon: yes, kaem will use any environment you give it
<stikonas>and then passes it to execve call https://github.com/oriansj/mescc-tools/blob/master/Kaem/kaem.c#L1095
<stikonas>hmm, for UEFI we'll have to do som ifdefs here...
<stikonas>to implement passing of environmental variables and also don't do forking
<oriansj>well the lack of forking presents a serious problem for a shell.
<stikonas>well, should still be possible to implement
<stikonas>we can spawn other processes, so just need to correctly pass command line options and env variables
<stikonas>which are all stored in a single string
<stikonas>but I think ifdefs will be unavoidable
<stikonas>we can't make it full POSIX compatible
<stikonas>hmm, speaking of shell
<stikonas>I wonder how hard would it be to add an optional interactive mode to kaem
<stikonas>(possibly without any editing capabilities)
<oriansj>stikonas: not hard at all actually
<stikonas>probably not too hard though for now not high priority
<oriansj>just need to add a couple little things to M2libc: https://paste.debian.net/1258374/
<oriansj>(specifically termios.h)
<oriansj>the following: struct termios' definition, the function isatty, the function tcgetattr, the function tcsetattr and the #defines for BRKINT | ICRNL | INPCK | ISTRIP | IXON | OPOST | CS8 | ECHO | ICANON | IEXTEN | ISIG | TCSAFLUSH | VMIN | VTIME
<muurkha>ugh
<muurkha>oriansj: PDP-7 Unix implemented exit() by execing the shell
<muurkha>so it could run an interactive shell without forking
<muurkha>because the PDP-7 didn't have virtual memory, not even a base register, forking was quite a heavyweight operation that involved dumping the computer's memory out to a disk. likewise context switches
<stikonas>this is different kind of forking
<stikonas>when I said we have no forking, I meant no fork() type of call that makes a clone of process
<stikonas>instead it spawns
<muurkha>right, because it's from the VMS→WindowsNT→UEFI lineage
<muurkha>EFI
<muurkha>which doesn't have execve() or anything similar either, does it?
<stikonas>no, there is only LoadImage function and then StartImage
<stikonas>there is a call for exiting too but it's optional
<stikonas>you can just do return and it goes back to the caller
<stikonas>callers address is saved on stack
<muurkha>StartImage is sort of like execve() I guess
<oriansj>good thing M2-Planet supports #ifdef statements
<stikonas>yeah, I guess it is somewhat similar
<stikonas>or at least we can implement execve that way
<stikonas>hmm, I wonder if we can then somehow fake fork call...
<stikonas>hmm
<stikonas>probably not...
<stikonas>we could always just have return 0;
<stikonas>then it will think that it's a child and do execve (start image)
<stikonas>but then the next line in kaem https://github.com/oriansj/mescc-tools/blob/master/Kaem/kaem.c#L1099 will have to be #ifdefed
<muurkha>heh, that's an amusing idea
<stikonas>not sure if that's the best way, as it is a bit against the spec
<stikonas>execve does not return on success
<muurkha>implement fork to be setjmp() and return 0, and exit() to be longjmp? :)
<stikonas>probably less hacky way, is to just #ifdef the whole fork/execve stuff and just add spawn function...
<stikonas>hmm, interesting, I think mkdir in UEFI is just open call
<stikonas>with create atribute (but we already use it for files)
<oriansj>stikonas: actually spawn would be in the #ifdef and the fork/execve bit would be inside the #else block
<stikonas>anyway, I'll probably do it in smaller bits
<stikonas>first get enough to build hex2 and M1 from C sources
<stikonas>that will need far fewer things than kaem
<oriansj>and less hacking around a bad spec
<oriansj>although you really should do an announce for getting M2-Planet self-hosting on UEFI; as you might be right about it being the first self-hosting Compiler to run on UEFI
<oriansj>stikonas: could we use EFI_GLOBAL_VARIABLE as environment variables?
<oriansj>using GetVariable and SetVariable
<stikonas[m]>Hmm, maybe we could but do we need?
<stikonas[m]>Hmm
<stikonas[m]>Those are completely global
<stikonas[m]>And I'm not sure if they are persistent or not
<stikonas[m]>We don't really want them stored in nvram...
<oriansj>we only need them to persist for the duration of kaem's life
<stikonas[m]>OK, nvram is a separate attribute
<stikonas[m]>We can use BOOTSERVICE_ACCESS
<stikonas[m]>Though finding out what to read withGetVariable is tricky
<oriansj>that should simplify passing an environment to a process
<oriansj>fortunately we know exactly what environment variables are available/used
<oriansj>and once we have process execution, M2libc will become the most powerful C Posix library for UEFI
<oriansj>as we already blow https://gitlab.com/bztsrc/posix-uefi out of the water.
<stikonas[m]>Oh we have more than posix-uefi?
<stikonas[m]>I saw it briefly
<oriansj>a good deal more
<oriansj>we have fcntl.c, signal.h, stddef.h, our stdlib.h is bigger and our stdio.h supports more
<oriansj>the only bits they have which we don't are: qsort.c and time.c
***lanodan is now known as Guest8010