chore: clang format
This commit is contained in:
parent
f5ea31f676
commit
b317827c3c
16 changed files with 216 additions and 181 deletions
|
@ -1,5 +1,5 @@
|
||||||
#include <stdatomic.h>
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
int __am_mpe_init = 0;
|
int __am_mpe_init = 0;
|
||||||
extern bool __am_has_ioe;
|
extern bool __am_has_ioe;
|
||||||
|
@ -16,7 +16,8 @@ bool mpe_init(void (*entry)()) {
|
||||||
char ch;
|
char ch;
|
||||||
assert(read(sync_pipe[0], &ch, 1) == 1);
|
assert(read(sync_pipe[0], &ch, 1) == 1);
|
||||||
assert(ch == '+');
|
assert(ch == '+');
|
||||||
close(sync_pipe[0]); close(sync_pipe[1]);
|
close(sync_pipe[0]);
|
||||||
|
close(sync_pipe[1]);
|
||||||
|
|
||||||
thiscpu->cpuid = i;
|
thiscpu->cpuid = i;
|
||||||
__am_init_timer_irq();
|
__am_init_timer_irq();
|
||||||
|
@ -31,7 +32,8 @@ bool mpe_init(void (*entry)()) {
|
||||||
for (int i = 1; i < cpu_count(); i++) {
|
for (int i = 1; i < cpu_count(); i++) {
|
||||||
assert(write(sync_pipe[1], "+", 1) == 1);
|
assert(write(sync_pipe[1], "+", 1) == 1);
|
||||||
}
|
}
|
||||||
close(sync_pipe[0]); close(sync_pipe[1]);
|
close(sync_pipe[0]);
|
||||||
|
close(sync_pipe[1]);
|
||||||
|
|
||||||
entry();
|
entry();
|
||||||
panic("MP entry should not return\n");
|
panic("MP entry should not return\n");
|
||||||
|
@ -42,9 +44,7 @@ int cpu_count() {
|
||||||
return __am_ncpu;
|
return __am_ncpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_current() {
|
int cpu_current() { return thiscpu->cpuid; }
|
||||||
return thiscpu->cpuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
int atomic_xchg(int *addr, int newval) {
|
int atomic_xchg(int *addr, int newval) {
|
||||||
return atomic_exchange((int *)addr, newval);
|
return atomic_exchange((int *)addr, newval);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <klib.h>
|
|
||||||
#include <klib-macros.h>
|
#include <klib-macros.h>
|
||||||
|
#include <klib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
|
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
|
||||||
|
@ -7,14 +7,15 @@
|
||||||
size_t strlen(const char *s) {
|
size_t strlen(const char *s) {
|
||||||
const char *p = s;
|
const char *p = s;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
while(*(p++) != '\0') len++;
|
while (*(p++) != '\0')
|
||||||
|
len++;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strcpy(char *dst, const char *src) {
|
char *strcpy(char *dst, const char *src) {
|
||||||
char *p_dst = dst;
|
char *p_dst = dst;
|
||||||
const char *p_src = src;
|
const char *p_src = src;
|
||||||
for(; *p_src != '\0'; p_src++, p_dst++) {
|
for (; *p_src != '\0'; p_src++, p_dst++) {
|
||||||
*p_dst = *p_src;
|
*p_dst = *p_src;
|
||||||
}
|
}
|
||||||
*p_dst = '\0';
|
*p_dst = '\0';
|
||||||
|
@ -23,10 +24,10 @@ char *strcpy(char *dst, const char *src) {
|
||||||
|
|
||||||
char *strncpy(char *dst, const char *src, size_t n) {
|
char *strncpy(char *dst, const char *src, size_t n) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(; i < n && src[i] != '\0'; i++) {
|
for (; i < n && src[i] != '\0'; i++) {
|
||||||
dst[i] = src[i];
|
dst[i] = src[i];
|
||||||
}
|
}
|
||||||
for(; i < n; i++) {
|
for (; i < n; i++) {
|
||||||
dst[i] = '\0';
|
dst[i] = '\0';
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
|
@ -35,8 +36,9 @@ char *strncpy(char *dst, const char *src, size_t n) {
|
||||||
char *strcat(char *dst, const char *src) {
|
char *strcat(char *dst, const char *src) {
|
||||||
char *p_dst = dst;
|
char *p_dst = dst;
|
||||||
const char *p_src = src;
|
const char *p_src = src;
|
||||||
while(*p_dst != '\0') p_dst++;
|
while (*p_dst != '\0')
|
||||||
for(; *p_src != '\0'; p_src++, p_dst++) {
|
p_dst++;
|
||||||
|
for (; *p_src != '\0'; p_src++, p_dst++) {
|
||||||
*p_dst = *p_src;
|
*p_dst = *p_src;
|
||||||
}
|
}
|
||||||
*p_dst = '\0';
|
*p_dst = '\0';
|
||||||
|
@ -45,8 +47,8 @@ char *strcat(char *dst, const char *src) {
|
||||||
|
|
||||||
int strcmp(const char *s1, const char *s2) {
|
int strcmp(const char *s1, const char *s2) {
|
||||||
const char *p_s1 = s1, *p_s2 = s2;
|
const char *p_s1 = s1, *p_s2 = s2;
|
||||||
for(; *p_s1 == *p_s2; p_s1++, p_s2++) {
|
for (; *p_s1 == *p_s2; p_s1++, p_s2++) {
|
||||||
if(*p_s1 == '\0' || *p_s2 == '\0') {
|
if (*p_s1 == '\0' || *p_s2 == '\0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +58,8 @@ int strcmp(const char *s1, const char *s2) {
|
||||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||||
const char *p_s1 = s1, *p_s2 = s2;
|
const char *p_s1 = s1, *p_s2 = s2;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(i = 0; i < n - 1; i++) {
|
for (i = 0; i < n - 1; i++) {
|
||||||
if(s1[i] == '\0' || s2[i] == '\0')
|
if (s1[i] == '\0' || s2[i] == '\0')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return s1[i] - s2[i];
|
return s1[i] - s2[i];
|
||||||
|
@ -65,33 +67,35 @@ int strncmp(const char *s1, const char *s2, size_t n) {
|
||||||
|
|
||||||
void *memset(void *s, int c, size_t n) {
|
void *memset(void *s, int c, size_t n) {
|
||||||
uint8_t *p = s;
|
uint8_t *p = s;
|
||||||
for(int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
p[i] = c;
|
p[i] = c;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memmove(void *dst, const void *src, size_t n) {
|
void *memmove(void *dst, const void *src, size_t n) {
|
||||||
if (src + n > dst && src < dst) {
|
if (src + n > dst && src < dst) {
|
||||||
size_t len = dst - src;
|
size_t len = dst - src;
|
||||||
void *p_dst = (void *)src + n;
|
void *p_dst = (void *)src + n;
|
||||||
const void *p_src = src + n - len;
|
const void *p_src = src + n - len;
|
||||||
while(p_dst >= dst) {
|
while (p_dst >= dst) {
|
||||||
memcpy(p_dst, p_src, len);
|
memcpy(p_dst, p_src, len);
|
||||||
p_src -= len;
|
p_src -= len;
|
||||||
p_dst -= len;
|
p_dst -= len;
|
||||||
}
|
}
|
||||||
if(n % len) memcpy(dst, src, n % len);
|
if (n % len)
|
||||||
|
memcpy(dst, src, n % len);
|
||||||
} else if (dst < src && dst + n > src) {
|
} else if (dst < src && dst + n > src) {
|
||||||
size_t len = src - dst;
|
size_t len = src - dst;
|
||||||
void *p_dst = dst;
|
void *p_dst = dst;
|
||||||
const void *p_src = src;
|
const void *p_src = src;
|
||||||
while(p_src < src + n) {
|
while (p_src < src + n) {
|
||||||
memcpy(p_dst, p_src, len);
|
memcpy(p_dst, p_src, len);
|
||||||
p_src += len;
|
p_src += len;
|
||||||
p_dst += len;
|
p_dst += len;
|
||||||
}
|
}
|
||||||
if(n % len) memcpy(p_dst, p_src, n % len);
|
if (n % len)
|
||||||
|
memcpy(p_dst, p_src, n % len);
|
||||||
} else {
|
} else {
|
||||||
memcpy(dst, src, n);
|
memcpy(dst, src, n);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +104,7 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memcpy(void *out, const void *in, size_t n) {
|
void *memcpy(void *out, const void *in, size_t n) {
|
||||||
for (size_t i = 0 ; i < n ; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
*(uint8_t *)(out + i) = *(uint8_t *)(in + i);
|
*(uint8_t *)(out + i) = *(uint8_t *)(in + i);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
@ -109,9 +113,10 @@ void *memcpy(void *out, const void *in, size_t n) {
|
||||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||||
const uint8_t *p1 = s1, *p2 = s2;
|
const uint8_t *p1 = s1, *p2 = s2;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if(*p1 != *p2)
|
if (*p1 != *p2)
|
||||||
return p1 - p2;
|
return p1 - p2;
|
||||||
p1++; p2++;
|
p1++;
|
||||||
|
p2++;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
2
diffu
2
diffu
|
@ -1 +1 @@
|
||||||
Subproject commit 0c590d218be4b2df4f8f827a9fd40278c227a1ca
|
Subproject commit 645b0f607ae510fda4d71b8152ea932a2b38bc32
|
|
@ -28,51 +28,50 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char isa_logo[] = {
|
unsigned char isa_logo[] = {
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x5f, 0x5f, 0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20,
|
0x5f, 0x5f, 0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x0a, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x0a, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x5f, 0x29,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x28, 0x5f, 0x29,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c, 0x5f, 0x5f,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c, 0x5f, 0x5f,
|
||||||
0x5f, 0x20, 0x5c, 0x5f, 0x5f, 0x20, 0x5c, 0x20, 0x20, 0x7c, 0x20, 0x20,
|
0x5f, 0x20, 0x5c, 0x5f, 0x5f, 0x20, 0x5c, 0x20, 0x20, 0x7c, 0x20, 0x20,
|
||||||
0x5c, 0x2f, 0x20, 0x20, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x5c, 0x2f, 0x20, 0x20, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x20, 0x5f, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x20, 0x5f, 0x20,
|
||||||
0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x20, 0x5f, 0x20,
|
0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x20, 0x5f, 0x20,
|
||||||
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x29,
|
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x29,
|
||||||
0x20, 0x7c, 0x20, 0x29, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x5c, 0x20, 0x20,
|
0x20, 0x7c, 0x20, 0x29, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x5c, 0x20, 0x20,
|
||||||
0x2f, 0x20, 0x7c, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20, 0x5f, 0x20, 0x5f,
|
0x2f, 0x20, 0x7c, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20, 0x5f, 0x20, 0x5f,
|
||||||
0x5f, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x5f, 0x5f,
|
0x5f, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x5f, 0x5f,
|
||||||
0x20, 0x5f, 0x7c, 0x20, 0x7c, 0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f, 0x5f, 0x5f, 0x5f, 0x2f, 0x5f, 0x5f, 0x5f, 0x5f, 0x7c,
|
||||||
0x20, 0x7c, 0x5f, 0x7c, 0x20, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
|
0x20, 0x7c, 0x5f, 0x7c, 0x20, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
|
||||||
0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
|
0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
|
||||||
0x2c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x0a,
|
0x2c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x0a,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x7c, 0x20, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x7c, 0x20, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
|
||||||
0x5f, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x5f, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, '\0'
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0a, '\0'};
|
||||||
};
|
|
||||||
|
|
|
@ -25,39 +25,49 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char isa_logo[] = {
|
unsigned char
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x20,
|
isa_logo
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
[] =
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x20,
|
{
|
||||||
0x20, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x28, 0x5f, 0x29, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x7c, 0x20, 0x20, 0x5c, 0x2f, 0x20, 0x20, 0x7c, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x5f, 0x20, 0x0a, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c, 0x20,
|
0x20, 0x20, 0x20, 0x28, 0x5f, 0x29, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x7c, 0x0a, 0x20, 0x20, 0x5f, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20, 0x5f,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x5f, 0x5f, 0x20, 0x5f, 0x5f, 0x5f, 0x5f,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7c,
|
||||||
0x5f, 0x5f, 0x5f, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x20, 0x7c, 0x20,
|
0x20, 0x20, 0x5c, 0x2f, 0x20, 0x20, 0x7c, 0x20, 0x20, 0x20,
|
||||||
0x5c, 0x20, 0x20, 0x2f, 0x20, 0x7c, 0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x5f, 0x20, 0x5f, 0x5f, 0x20, 0x20, 0x5f, 0x20, 0x20, 0x20, 0x5f, 0x20,
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
0x20, 0x5f, 0x5f, 0x20, 0x5f, 0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x7c, 0x20,
|
0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x20, 0x5f, 0x20, 0x5f, 0x5f,
|
||||||
0x27, 0x5f, 0x5f, 0x7c, 0x20, 0x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, 0x20,
|
||||||
0x2c, 0x5f, 0x7c, 0x5f, 0x7c, 0x0a, '\0' /* Termination Character is indispensable! */
|
0x7c, 0x20, 0x7c, 0x20, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x28,
|
||||||
|
0x5f, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c, 0x20, 0x7c,
|
||||||
|
0x20, 0x7c, 0x5f, 0x7c, 0x20, 0x7c, 0x20, 0x28, 0x5f, 0x7c,
|
||||||
|
0x20, 0x7c, 0x20, 0x7c, 0x0a, 0x20, 0x7c, 0x5f, 0x7c, 0x20,
|
||||||
|
0x20, 0x7c, 0x5f, 0x7c, 0x5f, 0x5f, 0x5f, 0x2f, 0x5c, 0x5f,
|
||||||
|
0x5f, 0x5f, 0x7c, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x5c, 0x5f, 0x2f, 0x20, 0x20, 0x20, 0x7c, 0x5f, 0x7c,
|
||||||
|
0x20, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f,
|
||||||
|
0x7c, 0x5f, 0x7c, 0x20, 0x7c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f,
|
||||||
|
0x2c, 0x5f, 0x7c, 0x5c, 0x5f, 0x5f, 0x2c, 0x5f, 0x7c, 0x5f,
|
||||||
|
0x7c, 0x0a, '\0' /* Termination Character is indispensable! */
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,10 +17,12 @@ static int cmp_func_t(const void *a, const void *b) {
|
||||||
|
|
||||||
static func_t *get_func(vaddr_t addr) {
|
static func_t *get_func(vaddr_t addr) {
|
||||||
int l = 0, r = func_table_len - 1;
|
int l = 0, r = func_table_len - 1;
|
||||||
while(l <= r) {
|
while (l <= r) {
|
||||||
int mid = (l + r) / 2;
|
int mid = (l + r) / 2;
|
||||||
if(func_table[mid].start <= addr) l = mid + 1;
|
if (func_table[mid].start <= addr)
|
||||||
else r = mid - 1;
|
l = mid + 1;
|
||||||
|
else
|
||||||
|
r = mid - 1;
|
||||||
}
|
}
|
||||||
return l == 0 ? NULL : &func_table[l - 1];
|
return l == 0 ? NULL : &func_table[l - 1];
|
||||||
}
|
}
|
||||||
|
@ -33,20 +35,27 @@ void init_elf(const char *path) {
|
||||||
func_table = (func_t *)calloc(func_table_size, sizeof(func_t));
|
func_table = (func_t *)calloc(func_table_size, sizeof(func_t));
|
||||||
assert(func_table);
|
assert(func_table);
|
||||||
|
|
||||||
FAILED_GOTO(failed_header, fread(&header, sizeof(Elf32_Ehdr), 1, elf_file) <= 0);
|
FAILED_GOTO(failed_header,
|
||||||
|
fread(&header, sizeof(Elf32_Ehdr), 1, elf_file) <= 0);
|
||||||
FAILED_GOTO(failed_header, fseek(elf_file, header.e_shoff, SEEK_SET) != 0);
|
FAILED_GOTO(failed_header, fseek(elf_file, header.e_shoff, SEEK_SET) != 0);
|
||||||
FAILED_GOTO(failed_header, fread(section_header, header.e_shentsize, header.e_shnum, elf_file) <= 0);
|
FAILED_GOTO(failed_header, fread(section_header, header.e_shentsize,
|
||||||
|
header.e_shnum, elf_file) <= 0);
|
||||||
|
|
||||||
char *shstrtab = calloc(1, section_header[header.e_shstrndx].sh_size);
|
char *shstrtab = calloc(1, section_header[header.e_shstrndx].sh_size);
|
||||||
FAILED_GOTO(failed_shstrtab, fseek(elf_file, section_header[header.e_shstrndx].sh_offset, SEEK_SET) != 0);
|
FAILED_GOTO(failed_shstrtab,
|
||||||
FAILED_GOTO(failed_shstrtab, fread(shstrtab, section_header[header.e_shstrndx].sh_size, 1, elf_file) <= 0);
|
fseek(elf_file, section_header[header.e_shstrndx].sh_offset,
|
||||||
|
SEEK_SET) != 0);
|
||||||
|
FAILED_GOTO(failed_shstrtab,
|
||||||
|
fread(shstrtab, section_header[header.e_shstrndx].sh_size, 1,
|
||||||
|
elf_file) <= 0);
|
||||||
|
|
||||||
Elf32_Shdr *symtab = NULL, *strtab = NULL;
|
Elf32_Shdr *symtab = NULL, *strtab = NULL;
|
||||||
for(int i = 0; i < header.e_shnum; i++) {
|
for (int i = 0; i < header.e_shnum; i++) {
|
||||||
psh = section_header + i;
|
psh = section_header + i;
|
||||||
if (psh->sh_type == SHT_SYMTAB) {
|
if (psh->sh_type == SHT_SYMTAB) {
|
||||||
symtab = psh;
|
symtab = psh;
|
||||||
} else if (psh->sh_type == SHT_STRTAB && strncmp(shstrtab + psh->sh_name, ".strtab", 8) == 0) {
|
} else if (psh->sh_type == SHT_STRTAB &&
|
||||||
|
strncmp(shstrtab + psh->sh_name, ".strtab", 8) == 0) {
|
||||||
strtab = psh;
|
strtab = psh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,22 +63,28 @@ void init_elf(const char *path) {
|
||||||
int sym_length = symtab->sh_size / sizeof(Elf32_Sym);
|
int sym_length = symtab->sh_size / sizeof(Elf32_Sym);
|
||||||
Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym));
|
Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym));
|
||||||
assert(sym);
|
assert(sym);
|
||||||
FAILED_GOTO(failed_funcname, fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0);
|
FAILED_GOTO(failed_funcname,
|
||||||
FAILED_GOTO(failed_funcname, fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0);
|
fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0);
|
||||||
|
FAILED_GOTO(failed_funcname,
|
||||||
|
fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0);
|
||||||
|
|
||||||
for(int j = 0; j < sym_length; j++) {
|
for (int j = 0; j < sym_length; j++) {
|
||||||
if(ELF32_ST_TYPE(sym[j].st_info) != STT_FUNC) continue;
|
if (ELF32_ST_TYPE(sym[j].st_info) != STT_FUNC)
|
||||||
|
continue;
|
||||||
// Only read function type symbol
|
// Only read function type symbol
|
||||||
func_t *f = &func_table[func_table_len];
|
func_t *f = &func_table[func_table_len];
|
||||||
char *func = (char *)malloc(30);
|
char *func = (char *)malloc(30);
|
||||||
FAILED_GOTO(failed_funcname, fseek(elf_file, strtab->sh_offset + sym[j].st_name, SEEK_SET) != 0);
|
FAILED_GOTO(failed_funcname,
|
||||||
|
fseek(elf_file, strtab->sh_offset + sym[j].st_name, SEEK_SET) !=
|
||||||
|
0);
|
||||||
FAILED_GOTO(failed_funcname, fgets(func, 30, elf_file) <= 0);
|
FAILED_GOTO(failed_funcname, fgets(func, 30, elf_file) <= 0);
|
||||||
f->start = sym[j].st_value;
|
f->start = sym[j].st_value;
|
||||||
f->len = sym[j].st_size;
|
f->len = sym[j].st_size;
|
||||||
f->name = func;
|
f->name = func;
|
||||||
++func_table_len;
|
++func_table_len;
|
||||||
if(func_table_len >= func_table_size) {
|
if (func_table_len >= func_table_size) {
|
||||||
Assert(func_table_size * 2 > func_table_size, "Function table exceed memory limit");
|
Assert(func_table_size * 2 > func_table_size,
|
||||||
|
"Function table exceed memory limit");
|
||||||
func_table_size *= 2;
|
func_table_size *= 2;
|
||||||
func_table = realloc(func_table, func_table_size * sizeof(func_t));
|
func_table = realloc(func_table, func_table_size * sizeof(func_t));
|
||||||
Assert(func_table, "Function table exceed memory limit");
|
Assert(func_table, "Function table exceed memory limit");
|
||||||
|
@ -88,9 +103,11 @@ failed_funcname:
|
||||||
failed_shstrtab:
|
failed_shstrtab:
|
||||||
free(shstrtab);
|
free(shstrtab);
|
||||||
failed_header:
|
failed_header:
|
||||||
for(int i = 0; i < func_table_len; i++) {
|
for (int i = 0; i < func_table_len; i++) {
|
||||||
func_t *f = &func_table[i];
|
func_t *f = &func_table[i];
|
||||||
if(f->name) { free(f->name); }
|
if (f->name) {
|
||||||
|
free(f->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(func_table);
|
free(func_table);
|
||||||
Error("Failed reading elf file");
|
Error("Failed reading elf file");
|
||||||
|
@ -114,8 +131,9 @@ void ftrace_return(vaddr_t pc, vaddr_t addr) {
|
||||||
ftrace_stack_len--) {
|
ftrace_stack_len--) {
|
||||||
vaddr_t tco_addr = ftrace_stack[ftrace_stack_len];
|
vaddr_t tco_addr = ftrace_stack[ftrace_stack_len];
|
||||||
func_t *f = get_func(tco_addr);
|
func_t *f = get_func(tco_addr);
|
||||||
Trace("%*s0x%x ret 0x%x <%s+0x%x> (TCO)", ftrace_stack_len, "", pc, tco_addr,
|
Trace("%*s0x%x ret 0x%x <%s+0x%x> (TCO)", ftrace_stack_len, "", pc,
|
||||||
f == NULL ? "???" : f->name, f == NULL ? addr : addr - f->start);
|
tco_addr, f == NULL ? "???" : f->name,
|
||||||
|
f == NULL ? addr : addr - f->start);
|
||||||
}
|
}
|
||||||
func_t *f = get_func(addr);
|
func_t *f = get_func(addr);
|
||||||
Trace("%*s0x%x ret 0x%x <%s+0x%x>", ftrace_stack_len, "", pc, addr,
|
Trace("%*s0x%x ret 0x%x <%s+0x%x>", ftrace_stack_len, "", pc, addr,
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
#if defined(CONFIG_ISA_mips32)
|
#if defined(CONFIG_ISA_mips32)
|
||||||
#define ISA_QEMU_BIN "qemu-system-mipsel"
|
#define ISA_QEMU_BIN "qemu-system-mipsel"
|
||||||
#define ISA_QEMU_ARGS "-machine", "mipssim",\
|
#define ISA_QEMU_ARGS \
|
||||||
"-kernel", NEMU_HOME "/resource/mips-elf/mips.dummy",
|
"-machine", "mipssim", "-kernel", NEMU_HOME "/resource/mips-elf/mips.dummy",
|
||||||
#elif defined(CONFIG_ISA_riscv) && !defined(CONFIG_RV64)
|
#elif defined(CONFIG_ISA_riscv) && !defined(CONFIG_RV64)
|
||||||
#define ISA_QEMU_BIN "qemu-system-riscv32"
|
#define ISA_QEMU_BIN "qemu-system-riscv32"
|
||||||
#define ISA_QEMU_ARGS "-bios", "none",
|
#define ISA_QEMU_ARGS "-bios", "none",
|
||||||
|
@ -41,7 +41,7 @@ union isa_gdb_regs {
|
||||||
#elif defined(CONFIG_ISA_riscv) && !defined(CONFIG_RV64)
|
#elif defined(CONFIG_ISA_riscv) && !defined(CONFIG_RV64)
|
||||||
uint32_t gpr[32];
|
uint32_t gpr[32];
|
||||||
uint32_t pc;
|
uint32_t pc;
|
||||||
#elif defined(CONFIG_ISA_riscv) && defined(CONFIG_RV64)
|
#elif defined(CONFIG_ISA_riscv) && defined(CONFIG_RV64)
|
||||||
uint64_t gpr[32];
|
uint64_t gpr[32];
|
||||||
uint64_t fpr[32];
|
uint64_t fpr[32];
|
||||||
uint64_t pc;
|
uint64_t pc;
|
||||||
|
|
3
npc/.gdbinit
Normal file
3
npc/.gdbinit
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
set substitute-path /build/am-kernels /home/xin/repo/ysyx-workbench/am-kernels
|
||||||
|
file /nix/store/g8hi9rlby6xm7grzcpfc8lpmdfgv1i92-am-kernel-riscv32-none-elf-2024-07-10/libexec/am-kernels/add
|
||||||
|
target remote /tmp/gdbstub-npc.sock
|
|
@ -1,36 +1,36 @@
|
||||||
#include <cstdlib>
|
#include <VSwitch.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <verilated.h>
|
#include <verilated.h>
|
||||||
#include <verilated_vcd_c.h>
|
#include <verilated_vcd_c.h>
|
||||||
#include <VSwitch.h>
|
|
||||||
|
|
||||||
const int MAX_SIM_TIME=100;
|
const int MAX_SIM_TIME = 100;
|
||||||
|
|
||||||
int main(int argc, char **argv, char **env) {
|
int main(int argc, char **argv, char **env) {
|
||||||
int sim_time = 0;
|
int sim_time = 0;
|
||||||
Verilated::commandArgs(argc, argv);
|
Verilated::commandArgs(argc, argv);
|
||||||
VSwitch *top = new VSwitch;
|
VSwitch *top = new VSwitch;
|
||||||
|
|
||||||
Verilated::traceEverOn(true);
|
Verilated::traceEverOn(true);
|
||||||
VerilatedVcdC *m_trace = new VerilatedVcdC;
|
VerilatedVcdC *m_trace = new VerilatedVcdC;
|
||||||
#ifdef VERILATOR_TRACE
|
#ifdef VERILATOR_TRACE
|
||||||
top->trace(m_trace, 5);
|
top->trace(m_trace, 5);
|
||||||
m_trace->open("waveform.vcd");
|
m_trace->open("waveform.vcd");
|
||||||
#endif
|
#endif
|
||||||
for (sim_time = 0; sim_time < MAX_SIM_TIME; sim_time++) {
|
for (sim_time = 0; sim_time < MAX_SIM_TIME; sim_time++) {
|
||||||
top->io_sw_0 = rand() % 2;
|
top->io_sw_0 = rand() % 2;
|
||||||
top->io_sw_1 = rand() % 2;
|
top->io_sw_1 = rand() % 2;
|
||||||
top->eval();
|
top->eval();
|
||||||
printf("sw0 = %d, sw1 = %d, ledr = %d\n", top->io_sw_0, top->io_sw_1, top->io_out);
|
printf("sw0 = %d, sw1 = %d, ledr = %d\n", top->io_sw_0, top->io_sw_1,
|
||||||
assert(top->io_out == (top->io_sw_0 ^ top->io_sw_1));
|
top->io_out);
|
||||||
|
assert(top->io_out == (top->io_sw_0 ^ top->io_sw_1));
|
||||||
#ifdef VERILATOR_TRACE
|
#ifdef VERILATOR_TRACE
|
||||||
m_trace->dump(sim_time);
|
m_trace->dump(sim_time);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef VERILATOR_TRACE
|
#ifdef VERILATOR_TRACE
|
||||||
m_trace->close();
|
m_trace->close();
|
||||||
#endif
|
#endif
|
||||||
delete top;
|
delete top;
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue