提交 77f4ebc9 编写于 作者: Z Zihao Yu

tests,cachetest,loader: fix pc-relative addressing for global array

* The original code is not PIC, since it accesses a gloabl array. If we
  copy the code to somewhere else, it cannot access that global array
  any longer. To fix this, we pass the global array as function argument
  to make the code PIC.
* Now NOOP can pass the loader test with fence.i.
上级 61ecf165
......@@ -2,7 +2,7 @@
int a[10] = {};
int f1(int n) {
int f1(int n, int *a) {
int sum = 0;
for (int i = 0; i < n; i ++) {
sum += a[i];
......@@ -10,7 +10,7 @@ int f1(int n) {
return sum;
}
int f2(int n) {
int f2(int n, int *a) {
int sum = 1;
for (int i = 0; i < n; i ++) {
sum *= a[i];
......@@ -24,13 +24,13 @@ int test(void *f) {
printf("copy code...\n");
memcpy(code, f, sizeof(code));
int (*p)(int) = (void *)code;
#ifdef __ISA_RISCV64__
asm volatile("fence.i");
#endif
int (*p)(int, int*) = (void *)code;
printf("jump to code...\n");
int ret = p(10);
int ret = p(10, a);
printf("ret = %d\n", ret);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册