state-threads
state-threads copied to clipboard
Adapted for RISCV
Now risc-v is more and more popular. Support risc-v is very easy.
my code take some example from libc https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/swapcontext.S;h=53480a085c3418b5ba84ba115785f40f3c19ad89;hb=HEAD
If have glic and glibc version is bigger than 2.0, use glibc's setjmp and longjmp . If no glibc , use that in md_linux.S
-
the register labeled Callee should be saved. ra is return address, and is saved too.
https://en.wikichip.org/wiki/risc-v/registers -
glibc do the same. glibc setjmp.S
-
about the macro define gcc macro defination
Beside of the comment, the glibc use LGPL, so the code you copy is also LGPL. While ST use MPL and GPLv2, after this PullRequest is merged, if someone need the RISCV feature, he must follow the GPLv2 LICENSE. That is:
- StateThread use MPL or GPLv2, so is able to merge the code from glibc with LGPL.
- If someone need RISCV feature, he could not choose MPL, he MUST follow GPLv2 license.
- If someone do not use RISCV feature, he could choose MPL or GPLv2.
So I think it's too complex and break the MPL license. Could you please rewrite the code by yourself?
我用中文解释下。专门请教了下LICNESE方面的专家:
- 如果patch的代码是复制glibc(而非调用),ST可以合并该patch,但合并后的ST需要遵循GPLv2(只能选择双重许可中的GPLv2来分发后续版本)。
- 原因:ST采用双重授权ST(在MPL-1.1和GPL-2.0+下双重授权),后续版本可以采用MPL-1.1或GPLv2+中任一许可证授权,glibc采用LGPLv2.1授权,LGPLv2.1 允许把代码重新按照 GPLv2 及新版本发布,因此合并该patch的后续版本只能选择GPLv2+。
因此如果合并后,一般用户不会注意到授权,可能导致误用了这部分代码,实际上是LGPL但却当成了MPL,从而违反了开源协议,这会有很大的隐患。
希望能按自己的理解重写这部分代码,可以参考glibc但是不能直接抄。不知道是否愿意?
后面可以研究一下改写一下,暂时可以直接链接glibc的实现,riscv的编译器基本都比较新,里面的libc也比较新,都自带setjmp和longjmp了。
我还是坚持用汇编实现,而不要用glibc的setjmp和longjmp,不知道哪天这个库改了后就不可用了,是个大坑。
如果暂时没时间重写,可以有空后写也可以,不着急。这个PR可以先留着,不在乎版权的朋友可以Merge到自己的分支。
再次感谢提交Patch。 👍
已经用汇编实现了: https://github.com/ossrs/state-threads/pull/28
再次感谢。