- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在 MIPS Linux 机器上运行我的代码(小端,没有硬件 float ):
# cat /proc/cpuinfo | grep model
cpu model : MIPS 24Kc V5.5
我的程序在 x86 和 ARM 系统上运行良好,但在 MIPS 上因段错误而崩溃,总是在(或接近)pthreads
库函数调用中。我尝试了两个工具链(来自 here 的 MTI GNU/Linux 工具链 MIPS32R2-MIPS32R5 和来自 here 的 Sourcery CodeBench Lite 2016.05-8)——细节略有不同,但段错误总是发生。
阅读邮件列表我发现了 MIPS 平台上 pthreads
段错误的两个原因:
pthread_unlock_mutex()
和 pthread_wait_cond()
的实现可能有误。但是我使用 glibc(尽管设备上的操作系统是基于 uClibc 的);pthreads
中的动态库加载问题;但我的程序是静态链接的。我写了一个非常简单的程序:
#include <chrono>
#include <iostream>
#include <thread>
using namespace std;
void sayHello() {
this_thread::sleep_for(chrono::seconds(2));
cout << "Hello world!" << endl;
}
int main(int argc, char* argv[]) {
thread t(sayHello);
t.join();
return 0;
}
它也在 MIPS 上崩溃。在 t.join()
断点的调试器中,我看到以下内容:
(gdb) c
Continuing.
Breakpoint 1, __start () at ../sysdeps/mips/start.S:84
84 in ../sysdeps/mips/start.S
(gdb) disassemble
Dump of assembler code for function __start:
0x004059b0 <+0>: lui gp,0x5b
0x004059b4 <+4>: addiu gp,gp,-30464
=> 0x004059b8 <+8>: move ra,zero
0x004059bc <+12>: lui a0,0x40
0x004059c0 <+16>: addiu a0,a0,21584
0x004059c4 <+20>: lw a1,0(sp)
0x004059c8 <+24>: addiu a2,sp,4
0x004059cc <+28>: li at,-8
0x004059d0 <+32>: and sp,sp,at
0x004059d4 <+36>: addiu sp,sp,-32
0x004059d8 <+40>: lui a3,0x4d
0x004059dc <+44>: addiu a3,a3,-208
0x004059e0 <+48>: lui t0,0x4d
0x004059e4 <+52>: addiu t0,t0,4
0x004059e8 <+56>: sw t0,16(sp)
0x004059ec <+60>: sw v0,20(sp)
0x004059f0 <+64>: jal 0x4cf8a0 <__libc_start_main>
0x004059f4 <+68>: sw sp,24(sp)
End of assembler dump.
… (some boring "n"-s here) …
(gdb) n
109 in ../sysdeps/mips/start.S
(gdb) disassemble
Dump of assembler code for function __start:
0x004059b0 <+0>: lui gp,0x5b
0x004059b4 <+4>: addiu gp,gp,-30464
0x004059b8 <+8>: move ra,zero
0x004059bc <+12>: lui a0,0x40
0x004059c0 <+16>: addiu a0,a0,21584
0x004059c4 <+20>: lw a1,0(sp)
0x004059c8 <+24>: addiu a2,sp,4
0x004059cc <+28>: li at,-8
0x004059d0 <+32>: and sp,sp,at
0x004059d4 <+36>: addiu sp,sp,-32
0x004059d8 <+40>: lui a3,0x4d
0x004059dc <+44>: addiu a3,a3,-208
0x004059e0 <+48>: lui t0,0x4d
0x004059e4 <+52>: addiu t0,t0,4
0x004059e8 <+56>: sw t0,16(sp)
0x004059ec <+60>: sw v0,20(sp)
=> 0x004059f0 <+64>: jal 0x4cf8a0 <__libc_start_main>
0x004059f4 <+68>: sw sp,24(sp)
End of assembler dump.
(gdb) n
[New Thread 29775]
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) info registers
zero at v0 v1 a0 a1 a2 a3
R0 00000000 00000000 00000016 005af490 2bc7d310 00000000 2bc7d378 00000000
t0 t1 t2 t3 t4 t5 t6 t7
R8 00000000 00000000 00000000 82ee2000 00000000 00000000 00000001 74697773
s0 s1 s2 s3 s4 s5 s6 s7
R16 7fbbf194 004450c4 00464200 004641f0 00460000 2b929478 0045742c 00000001
t8 t9 k0 k1 gp sp s8 ra
R24 00000000 00000000 2bc847a0 00000000 005a8900 7fbbf158 7f894280 0041bd54
status lo hi badvaddr cause pc
0100ff13 3b9aca00 00000000 00000000 50800008 00000000
fcsr fir hi1 lo1 hi2 lo2 hi3 lo3
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
dspctl restart
00000000 00000000
没有线程的示例程序运行良好。
我现在可以做什么?是否有人对 MIPS 上的 pthreads
有类似的体验?
最佳答案
回答我自己的问题。
Erik Alapää是的,使用 uClibc 构建解决了这个问题。我仍然不明白为什么(程序是静态链接的)。
顺便说一句:我使用 glibc 因为无法使用 uClibc 构建 Boost.Asio — pthreads
从我的工具链中使用 uClibc 构建的库不包含 pthread_condattr_setclock()
函数.使用以下 Boost.Asio 补丁修复了它:
diff --git a/include/boost/asio/detail/impl/posix_event.ipp b/include/boost/asio/detail/impl/posix_event.ipp
index 4ff246f3..04f87a3a 100644
--- a/include/boost/asio/detail/impl/posix_event.ipp
+++ b/include/boost/asio/detail/impl/posix_event.ipp
@@ -33,10 +33,12 @@ posix_event::posix_event()
: state_(0)
{
#if (defined(__MACH__) && defined(__APPLE__)) \
- || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
+ || (defined(__ANDROID__) && (__ANDROID_API__ < 21)) \
+ || (defined(__UCLIBC__))
int error = ::pthread_cond_init(&cond_, 0);
#else // (defined(__MACH__) && defined(__APPLE__))
// || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
+ // || (defined(__UCLIBC__))
::pthread_condattr_t attr;
::pthread_condattr_init(&attr);
int error = ::pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
@@ -44,7 +46,7 @@ posix_event::posix_event()
error = ::pthread_cond_init(&cond_, &attr);
#endif // (defined(__MACH__) && defined(__APPLE__))
// || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
-
+ // || (defined(__UCLIBC__))
boost::system::error_code ec(error,
boost::asio::error::get_system_category());
boost::asio::detail::throw_error(ec, "event");
好吧,这是一种拼凑,但它确实有效。
关于c++ - MIPS 上 pthreads 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51153677/
我的老师说你可以像这样简单地将一个字符加载到寄存器中: li $s2 "A" li $s1 "0" 除了,当我将我的文件加载到 Qtspim 中时,它一直向我抛出一个语法错误。有谁知道我的老师是否对我
我正在使用二进制 MIPS 指令,我发现 this helpful document .但是,我需要澄清一下:所有分支指令都具有立即值。这是立即值符号扩展吗? 大多数其他立即数是,如果不是,那将意味着
我有一个寄存器($t2),它有一个随机生成的数字,然后我乘以 4。我的问题是,在使用 lw 指令时,是否可以将 $t2 中的值用作偏移量? 最佳答案 在 MIPS 中,您可以使用寄存器、偏移量或两者的
因此,我正在MIPS中构建一个计算器程序,并且试图编写乘法和除法函数。 目前,我像这样在循环中读取整数: li $v0, 5 syscall 然后根据用户要执行的操作最终调用我的函数multi和div
我们目前正在讨论 MIPS 架构。我逐渐了解了计算机体系结构和 MIPS 汇编,这很好。 但是,我尝试用谷歌搜索这个答案,但没有找到合适的答案。我对 ISA 和微架构设计下面的一层感到困惑。 MIPS
我正在研究分支延迟槽。在 spim 上尝试过。 j some j a j b j c j d ori $9, $0, 13 some: a: b: c: d: 令我惊讶的是,它将 9 美元更改
好吧,这个问题更像是一个讨论。我有一个在 VHDL 中实现 pipelined MIPS 处理器的项目。 我完全熟悉流水线的概念,但我从未用 VHDL 实现它。在VHDL 中学习流水线处理器 的实现有
关于带有流水线和转发的 MIPS 架构: add $s0, $t1, $t2 sw $s0, 0($sp) add 指令将在第 3 步(执行操作)准备好结果,但我假设 sw 指令需要第 2 步(指令解
我刚开始学习 MIPS 指令的异常处理程序。 我需要让我的程序有算术溢出异常,以便我可以测试我的异常处理程序。 我有两个数组 A 和 B。数组 A 有十六进制数,数组 B 有整数。 如何通过添加十六进
我正在学习微编程,但对微指令到底是什么感到困惑。我正在使用 MIPS 架构。我的问题如下 例如,我有 ADD 指令,微指令会是什么样子? add指令有多少条微指令。在网上有什么地方可以看到 MIPS
我需要多少档才能正确执行以下指令。我对我所做的事情有点困惑,所以我在这里看到专家的答案。 lw $1,0($2); beq $1,$2,Label; 请注意,检查是否会发生分支将在解码阶段完成。但是源
.data stack: .word 3, 2 .text .globl main main: la $s1, stack #assign stack start
我正在用 MIPS 编写一个回文检查器,我试图让它不区分重音,这样像“ahà”这样的东西也会被认为是一个回文。然而,它看起来并不像小写和大写字母之间有固定值的不区分大小写的场景那么简单。 我问过我的老
我正在尝试向以下内容添加 jal 功能,但我对它的工作原理感到困惑。我知道它将旧的 PC+4 值存储在 $ra 寄存器中,然后将控制权转移到函数,该函数通过 return $ra 传回控制权 但是如何
我正在学习如何执行 MIPS,但我对乘法感到困惑。假设我正在将以下 C 代码转换为 MIPS。 c = b + a*3 a,b,c分别存放在寄存器$s1,$s2,$s3中。我应该如何在 MIPS 中编
我正在为明天的考试而学习,并且我对加载/存储字节主题感到困惑。我有这个例子: 我完全不明白他是怎么得到红色答案的。有人可以帮我解释一下吗? 最佳答案 add $s3, $zero, $zero
我不明白如何翻译标签。任何人都可以给我一个帮助 假设我们有以下代码: loop: add $t2,$t2,$t1 addi $t2,$t2,4 sw $t2,4($s0)
当我阅读 MIPS 架构时,我遇到了影子寄存器,据说它们是通用寄存器的副本。 我无法理解以下内容:何时使用影子寄存器? 最佳答案 MIPS 影子寄存器用于减少处理中断时的寄存器加载/存储开销。分配了影
您好,我想让 hello world 输出用户输入的次数,比如如果他们写了 3 ,那么 hello world 将被打印 3 次。我该怎么做呢?这是我目前正在使用的: .data n:
我正在使用 MARS MIPS 模拟器,我想在我的程序中打印一个换行符。 .data space: .asciiz "\n" .text addi $v0, $zero, 4 # print
我是一名优秀的程序员,十分优秀!