sorear changed the topic of #riscv to: RISC-V instruction set architecture | https://riscv.org | Logs: https://libera.irclog.whitequark.org/riscv | Matrix: #riscv:catircservices.org
levitating__ has quit [Ping timeout: 248 seconds]
emdevt has joined #riscv
jn has quit [Ping timeout: 260 seconds]
jn has joined #riscv
jn has joined #riscv
prabhakalad has quit [Ping timeout: 256 seconds]
prabhakalad has joined #riscv
naoki has joined #riscv
alexghiti has quit [Quit: Connection closed for inactivity]
_whitelogger has joined #riscv
hexdump01 has joined #riscv
drmpeg has left #riscv [#riscv]
drmpeg has joined #riscv
zjason` is now known as zjason
lechner has quit [Read error: Connection reset by peer]
vagrantc has quit [Quit: leaving]
_whitelogger has joined #riscv
haritz has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
peepsalot has quit [Read error: Connection reset by peer]
peepsalot has joined #riscv
emdevt has quit [Remote host closed the connection]
mtinman has quit [Quit: See Ya'll Later!]
ldevulder has joined #riscv
coldfeet has joined #riscv
coldfeet has quit [Quit: Lost terminal]
hightower2 has joined #riscv
hightower4 has quit [Ping timeout: 256 seconds]
psydroid3 has joined #riscv
emneo has joined #riscv
emneo has quit [Ping timeout: 256 seconds]
TMM has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
TMM has joined #riscv
emneo has joined #riscv
psydroid3 has quit [Ping timeout: 258 seconds]
Andre_Z has joined #riscv
hmw has quit [Quit: Bye.]
haritz has joined #riscv
haritz has quit [Changing host]
haritz has joined #riscv
hmw has joined #riscv
hmw has quit [Quit: Bye.]
hmw has joined #riscv
etra has quit [Quit: ZNC 1.8.2 - https://znc.in]
hmw has quit [Client Quit]
hmw has joined #riscv
Andre_Z has quit [Remote host closed the connection]
emneo has quit [Ping timeout: 256 seconds]
hmw has quit [Quit: Bye.]
hmw has joined #riscv
levitating__ has joined #riscv
hmw has quit [Quit: Bye.]
Andre_Z has joined #riscv
hmw has joined #riscv
hmw has quit [Quit: Bye.]
hmw has joined #riscv
psydroid3 has joined #riscv
levitating__ has quit [Remote host closed the connection]
hmw has quit [Quit: Bye.]
hmw has joined #riscv
hmw has quit [Client Quit]
hmw has joined #riscv
etra has joined #riscv
etra has quit [Changing host]
etra has joined #riscv
coldfeet has joined #riscv
hmw has quit [Client Quit]
hmw has joined #riscv
psydroid3 has quit [Ping timeout: 258 seconds]
cleger has quit [Ping timeout: 265 seconds]
emneo has joined #riscv
lechner has joined #riscv
cleger has joined #riscv
s1b1_ has quit [Ping timeout: 256 seconds]
<lechner> Please let me rephrase that question. Is there any reason a riscv64 platform would segfault when executing memory aligned to a page boundary and obtained via the mmap Glibc function with the "prot" argument PROT_EXEC | PROT_WRITE ?
s1b1 has joined #riscv
fxaf_ has quit [Quit: ZNC 1.8.2 - https://znc.in]
fxaf has joined #riscv
naoki has quit [Quit: naoki]
dramforever[m] has joined #riscv
<dramforever[m]> <lechner> Please let me rephrase that question. Is there any reason a riscv64 platform would segfault when executing memory aligned to a page boundary and obtained via the mmap Glibc function with the "prot" argument PROT_EXEC | PROT_WRITE ?
<dramforever[m]> what's your kernel version
coldfeet has quit [Quit: Lost terminal]
<aurel32> lechner: a failure to clear the i-cache after writing to it?
<lechner> dramforever[m] / Linux ricci 6.12.38+deb13-riscv64 #1 SMP Debian 6.12.38-1 (2025-07-16) riscv64 GNU/Linux
<lechner> aurel32 / interesting. thanks for that hint! i'm now reading https://github.com/riscvarchive/riscv-linux/issues/140
fxaf has quit [Quit: ZNC 1.8.2 - https://znc.in]
fxaf has joined #riscv
<lechner> aurel32 / how would the lack of an icache flush cause a segmentation fault, please?
<lechner> on a single RET instruction (via libffi)
<aurel32> because the cpu does not execute what you just wrote to that area
<dramforever[m]> lechner: do you have a reproducible example anywhere?
<lechner> dramforever[m] / i do, but can we do it in three hours? i have to drive some people to school. for background, i wrote an inline assembler for GNU Guile that works on other architectures. i'm trying to port it to all the Debian ports https://codeberg.org/lechner/guile-syscall/src/branch/history/scm/syscall/linux-riscv64.scm
<lechner> i think it would be somewhat cumbersome to try gdb on it, though
<sorear> kind of odd to not have PROT_READ, that could also trigger bugs years ago
<lechner> sorear / on GNU systems (Glibc via ELF header) PROT_EXEC implies PROT_READ, although the thought was that an attacker could not search for point to jump to https://sourceware.org/glibc/manual/2.42/html_node/Memory-Protection.html
emneo has quit [Ping timeout: 265 seconds]
emneo has joined #riscv
emneo has quit [Ping timeout: 258 seconds]
<sorear> "GNU system" in the glibc manual means Hurd
<sorear> non-executable stacks have been the default for a few years I think, and the stack overflow answer points at x86_64 details which are irrelevant here
<dramforever[m]> i don't think 6.12 has any of the weird problems with PROT_*
<dramforever[m]> so i'm outta ideas
emdevt has joined #riscv
<sorear> I doubt it's the icache, a SIGSEGV on the first instruction is fairly unlikely especially if the page didn't previously hold text
emdevt has quit [Ping timeout: 248 seconds]
<sorear> load-absolute-address won't work at all because the ori immediate is sign extended
<lechner> sorear / what does that mean, please?
<lechner> sorry, i get it. you looked at my code
<lechner> how may I load a 64 bit value, please?
<lechner> also, how can a logical value be sign-extended?
<lechner> i'd rather not do the memory thing
emdevt has joined #riscv
emdevt has quit [Ping timeout: 265 seconds]
<sorear> sign extension means that bit 11 of the immediate is copied to fill 63:12 so the valid values are -2048 .. 2047
<sorear> memory is the typically recommended approach, you could also use xor or a 6-instruction sequence lui, addi, lui, addi, slli, add, or just do ori in 11-bit chunks
<courmisch> is 6 instructions the shortest generalisation if using multiple registers?
<courmisch> how many registers does it take for an assembler macro that can't clobber any register other than the destination?
<sorear> fp usage is unidiomatic and possibly wrong, if you intend it to be available for debugging the fp needs to be the *old* sp with the saved fp at -8 and the ra at -16, like https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/437, also access to the frame is normally done with an sp base even if fp is set
<sorear> courmisch: yes, or 5 with Zbb pack, without a second register you need 8 lui, addi, slli, addi, slli, addi, slli, addi
psydroid2 has joined #riscv
ldevulder has quit [Ping timeout: 250 seconds]
vagrantc has joined #riscv
Andre_Z has quit [Quit: Leaving.]
<lechner> sorear / thanks! i think i get the first sequence with five. the last add is for lower half in one register to the upper half in another, right?
<lechner> out of curiosity, how would the ori in 11-bit chunks work?
libercv has joined #riscv
<sorear> lechner: yes, slli/add to combine two 32-bit chunks, just remember that they are signed
<sorear> same as you have now, but 0-11, 11-22, 22-33, etc
<sorear> ori immediates outside 0..2047 are less useful because they are interpreted as negative
<lechner> sorear / okay, thanks! maybe i will stick with the ori for now. keeping the upper bit a zero is a good solution, too. thanks for that!
<sorear> Why are you JITing something with no dynamic parts anyway? Is this being called with libffi?
<lechner> sorear / so for the add, i'd have to check the highest bit of the upper to pick either a straight add (for 0) or a sub of the two's complement (for 1)?
<sorear> It's an add either way. After you've cast the lower to int32, add 1 to the upper if the lower is negative
<lechner> thanks!
<lechner> sorear / it's part of a new concept interpreter that may or may not work as intended. the goal is to radically reduce prerequisites at the cost of some assembly, for bootstrapping
<sorear> Or cast the lower to int32, then back, then subtract, then divide the residual (exactly) by 2^32
<sorear> it seems a little weird that the arguments are nine integers but the result is a heap value (?)
<sorear> anyway none of this explains segfaulting on an 8067
<lechner> for boostrapping, i have to provide basic Guile types in assembly anyway. everything is on the heap, i think
<lechner> what's 8067, please?
<lechner> you may find interactive assembly an interesting experience. it radically reduces the number of steps in order to run something, plus you have a higher language to interpret data, structures, etc---plus formatted output
<lechner> this look better? https://bpa.st/24LQ
<lechner> also, i'd like to credit you in my code with your name or handle here. which do you prefer?
<lechner> i guess the five-step addi would be more efficient
cleger has quit [Remote host closed the connection]
<lechner> but wouldn't i also need the upper half check on the last addi?
<sorear> think of it recursively
<sorear> you can construct any 64-bit value by adding something in the range -2048 to 2047, to something divisible by 4096, which can be constructed by shifting a 52-bit number, which...
<sorear> or as a signed digit representation
<sorear> <lechner> Hi, is the 00008067 opcode the standard way to return from a function? I see a segmentation fault with the little-endian bytevector 103 128 0 0 (decimal) even though the start is aligned to a page boundary. Also, how may I find out whether my system is little-endian, please? Thanks!
<sorear> it wasn't mentioned in the replies earlier but riscv instructions are always little endian
<lechner> thanks for those
<lechner> sorear / but isn't there a chance that the uppermost bit is 1 in the last step of the recursive addi sequence, meaning it would be interpreted as a signed number and would hence require correction by adding 1?
<sorear> remember, the whole process is linear. "adding 1" at the last step "increases" the final number by 2^72, which is a noop
<sorear> if you've done six rounds of a shift-and-add-12-bits
<sorear> alternatively, do a recursive process and stop when you reach something in range of lui, which will happen since it shrinks at each step
<sorear> did your original complaint of ret (00008067) segfaults get resolved
libercv has quit [Quit: Konversation terminated!]
coldfeet has joined #riscv
<sorear> either credit is fine
<sorear> paste doesn't immediately look wrong
Trifton is now known as TDRC
<markh> If it is still segfaulting, running it under valgrind should help to narrow down the cause.
ZLima12 has quit [Remote host closed the connection]
ZLima12 has joined #riscv
<lechner> markh / sorear / yeah, it's still segfaulting. is valgrind available in Debian sid for riscv64
<lechner> >
<lechner> ?
<markh> valgrind 3.25 has riscv64 support; I don't know why debian is still on 3.24 but 3.25.1 can be compiled from source
<jrtc27> I would assume because trixie was released within the past month so debian was in increasing levels of freeze earlier this year
<sorear> oh nice, didn't realize it finally went into upstream valgrind
<markh> Yeah, valgrind 3.25.0 with riscv64 support was released in April
<sorear> my approach would have been one or more of "stare at strace and qemu output" and "throw gdb at it"; easy enough to trace traps
haritz has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
<lechner> maybe i ought to get qemu running instead of using remote equipment
Trifton has joined #riscv
<lechner> Does libffi generally work okay on riscv64?
fgarcia has quit [Ping timeout: 260 seconds]
<lechner> sorear / with your suggestions to load-absolute-address, the segfault went away. thanks for that help, and sorry to get everyone riled up!
<lechner> sorear / thanks again! credit given in code and in commit message https://codeberg.org/lechner/guile-syscall/commit/5e381c5a375eb91945200a1d97ecb03b1c274c47
<lechner> would be happy to insert your name if you tell me what it is
<lechner> if so, please email me at felix.lechner@lease-up.com
<lechner> and thanks everyone for your help, your interest and your valuable time!
psydroid2 has quit [Quit: KVIrc 5.2.6 Quasar http://www.kvirc.net/]
haritz has joined #riscv
haritz has quit [Changing host]
haritz has joined #riscv
<sorear> libffi works fine
<lechner> ok
coldfeet has quit [Quit: Lost terminal]
tlwoerner_ has joined #riscv
lechner has left #riscv [Using Circe, the loveliest of all IRC clients]
impomatic has joined #riscv
ruvam has quit [Ping timeout: 252 seconds]
ruvam_ has joined #riscv
TMM has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
ruvam_ is now known as ruvam
TMM has joined #riscv
aklsh has quit [Ping timeout: 248 seconds]
ruvam has quit [Read error: Connection reset by peer]
aklsh has joined #riscv
ruvam has joined #riscv