> compile NEMU
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 19:49:57 up 6:13, 1 user, load average: 0.22, 0.11, 0.13
This commit is contained in:
@ -5,27 +5,47 @@
|
||||
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
|
||||
|
||||
size_t strlen(const char *s) {
|
||||
panic("Not implemented");
|
||||
size_t len;
|
||||
for (len = 0; *s != '\0'; len++, s++);
|
||||
return len;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
panic("Not implemented");
|
||||
char* _dst = dst;
|
||||
for (; *src != '\0'; _dst++, src++) {
|
||||
*_dst = *src;
|
||||
}
|
||||
*_dst = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t n) {
|
||||
panic("Not implemented");
|
||||
char* _dst = dst;
|
||||
for (; n > 0; n--, _dst++, src++) {
|
||||
if (*src == '\0') {
|
||||
*_dst = '\0';
|
||||
src--;
|
||||
}
|
||||
*_dst = *src;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strcat(char *dst, const char *src) {
|
||||
panic("Not implemented");
|
||||
return strcpy(dst + strlen(dst), src);
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
panic("Not implemented");
|
||||
return strncmp(s1, s2, SIZE_MAX);
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
panic("Not implemented");
|
||||
for (; *s1 != '\0' && *s2 != '\0'; s1++, s2++, n--) {
|
||||
if (*s1 != *s2 || n == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *(unsigned char*)s1 - *(unsigned char*)s2;
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
@ -37,11 +57,23 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||
}
|
||||
|
||||
void *memcpy(void *out, const void *in, size_t n) {
|
||||
panic("Not implemented");
|
||||
unsigned char *_out = (unsigned char*)out;
|
||||
const unsigned char *_in = (const unsigned char*)in;
|
||||
for (; n > 0; n--, _out++, _in++) {
|
||||
*_out = *_in;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
panic("Not implemented");
|
||||
unsigned char *in1 = (unsigned char*)s1;
|
||||
const unsigned char *in2 = (const unsigned char*)s2;
|
||||
for (; n > 0; n--, in1++, in2++) {
|
||||
if (*in1 != *in2) {
|
||||
return *in1 - *in2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -70,15 +70,8 @@ static int decode_exec(Decode *s) {
|
||||
}
|
||||
|
||||
INSTPAT_START();
|
||||
INSTPAT("??????? ????? ????? 000 ????? 00100 11", addi , I, R(rd) = src1 + imm);
|
||||
// INSTPAT("??????? ????? ????? 010 ????? 00100 11", slti , I, R(rd) = (int32_t)src1 < (int32_t)imm ? 1 : 0);
|
||||
INSTPAT("??????? ????? ????? 011 ????? 00100 11", sltiu , I, R(rd) = (uint32_t)src1 < (uint32_t)imm ? 1 : 0);
|
||||
INSTPAT("??????? ????? ????? 100 ????? 00100 11", xori , I, R(rd) = src1 ^ imm);
|
||||
// INSTPAT("??????? ????? ????? 110 ????? 00100 11", ori , I, R(rd) = src1 | imm);
|
||||
INSTPAT("??????? ????? ????? 111 ????? 00100 11", andi , I, R(rd) = src1 & imm);
|
||||
INSTPAT("0000000 ????? ????? 001 ????? 00100 11", slli , I, R(rd) = src1 << imm);
|
||||
INSTPAT("0000000 ????? ????? 101 ????? 00100 11", srli , I, R(rd) = (uint32_t)src1 >> imm);
|
||||
INSTPAT("0100000 ????? ????? 101 ????? 00100 11", srai , I, R(rd) = (int32_t) src1 >> imm);
|
||||
INSTPAT("??????? ????? ????? ??? ????? 01101 11", lui , U, R(rd) = imm);
|
||||
INSTPAT("??????? ????? ????? ??? ????? 00101 11", auipc , U, R(rd) = s->pc + imm);
|
||||
|
||||
INSTPAT("??????? ????? ????? ??? ????? 11011 11", jal , J, R(rd) = s->pc + 4, s->dnpc = s->pc + imm);
|
||||
INSTPAT("??????? ????? ????? 000 ????? 11001 11", jalr , I, R(rd) = s->pc + 4, s->dnpc = src1 + imm);
|
||||
@ -90,18 +83,26 @@ static int decode_exec(Decode *s) {
|
||||
INSTPAT("??????? ????? ????? 110 ????? 11000 11", bltu , B, s->dnpc = (uint32_t)src1 < (uint32_t)src2 ? (s->pc + imm) : s->dnpc);
|
||||
INSTPAT("??????? ????? ????? 111 ????? 11000 11", bgeu , B, s->dnpc = (uint32_t)src1 >= (uint32_t)src2 ? (s->pc + imm) : s->dnpc);
|
||||
|
||||
// INSTPAT("??????? ????? ????? 000 ????? 00000 11", lb , I, R(rd) = (int32_t) Mr(src1 + imm, 1));
|
||||
INSTPAT("??????? ????? ????? 000 ????? 00000 11", lb , I, R(rd) = SEXT(Mr(src1 + imm, 1), 8)); // never used
|
||||
INSTPAT("??????? ????? ????? 001 ????? 00000 11", lh , I, R(rd) = SEXT(Mr(src1 + imm, 2), 16));
|
||||
INSTPAT("??????? ????? ????? 010 ????? 00000 11", lw , I, R(rd) = SEXT(Mr(src1 + imm, 4), 32));
|
||||
// INSTPAT("??????? ????? ????? 011 ????? 00000 11", ld , I, R(rd) = (int32_t) Mr(src1 + imm, 8));
|
||||
INSTPAT("??????? ????? ????? 100 ????? 00000 11", lbu , I, R(rd) = Mr(src1 + imm, 1));
|
||||
INSTPAT("??????? ????? ????? 101 ????? 00000 11", lhu , I, R(rd) = Mr(src1 + imm, 2));
|
||||
// INSTPAT("??????? ????? ????? 110 ????? 00000 11", lwu , I, R(rd) = Mr(src1 + imm, 4));
|
||||
|
||||
INSTPAT("??????? ????? ????? 000 ????? 01000 11", sb , S, Mw(src1 + imm, 1, src2));
|
||||
INSTPAT("??????? ????? ????? 001 ????? 01000 11", sh , S, Mw(src1 + imm, 2, src2));
|
||||
INSTPAT("??????? ????? ????? 010 ????? 01000 11", sw , S, Mw(src1 + imm, 4, src2));
|
||||
|
||||
INSTPAT("??????? ????? ????? 000 ????? 00100 11", addi , I, R(rd) = src1 + imm);
|
||||
INSTPAT("??????? ????? ????? 010 ????? 00100 11", slti , I, R(rd) = (int32_t)src1 < (int32_t)imm ? 1 : 0); // never used
|
||||
INSTPAT("??????? ????? ????? 011 ????? 00100 11", sltiu , I, R(rd) = (uint32_t)src1 < (uint32_t)imm ? 1 : 0);
|
||||
INSTPAT("??????? ????? ????? 100 ????? 00100 11", xori , I, R(rd) = src1 ^ imm);
|
||||
INSTPAT("??????? ????? ????? 110 ????? 00100 11", ori , I, R(rd) = src1 | imm); // never used
|
||||
INSTPAT("??????? ????? ????? 111 ????? 00100 11", andi , I, R(rd) = src1 & imm);
|
||||
INSTPAT("0000000 ????? ????? 001 ????? 00100 11", slli , I, R(rd) = src1 << imm);
|
||||
INSTPAT("0000000 ????? ????? 101 ????? 00100 11", srli , I, R(rd) = (uint32_t)src1 >> imm);
|
||||
INSTPAT("0100000 ????? ????? 101 ????? 00100 11", srai , I, R(rd) = (int32_t) src1 >> imm);
|
||||
|
||||
INSTPAT("0000000 ????? ????? 000 ????? 01100 11", add , R, R(rd) = src1 + src2);
|
||||
INSTPAT("0100000 ????? ????? 000 ????? 01100 11", sub , R, R(rd) = src1 - src2);
|
||||
INSTPAT("0000000 ????? ????? 001 ????? 01100 11", sll , R, R(rd) = src1 << src2);
|
||||
@ -113,15 +114,13 @@ static int decode_exec(Decode *s) {
|
||||
INSTPAT("0000000 ????? ????? 110 ????? 01100 11", or , R, R(rd) = src1 | src2);
|
||||
INSTPAT("0000000 ????? ????? 111 ????? 01100 11", and , R, R(rd) = src1 & src2);
|
||||
|
||||
INSTPAT("??????? ????? ????? ??? ????? 00101 11", auipc , U, R(rd) = s->pc + imm);
|
||||
INSTPAT("??????? ????? ????? ??? ????? 01101 11", lui , U, R(rd) = imm);
|
||||
|
||||
// INSTPAT("0000000 00000 00000 000 00000 11100 11", ecall , N, );
|
||||
INSTPAT("0000000 00001 00000 000 00000 11100 11", ebreak , N, NEMUTRAP(s->pc, R(10))); // R(10) is $a0
|
||||
|
||||
INSTPAT("0000001 ????? ????? 000 ????? 01100 11", mul , R, R(rd) = (int32_t) src1 * (int32_t) src2);
|
||||
INSTPAT("0000001 ????? ????? 001 ????? 01100 11", mulh , R, R(rd) = (((int64_t)(int32_t) src1 * (int64_t)(int32_t) src2) >> 32));
|
||||
// INSTPAT("0000001 ????? ????? 010 ????? 01100 11", mulhsu , R, R(rd) = ((int64_t) src1 * (uint64_t)src2) >> 32);
|
||||
// INSTPAT("0000001 ????? ????? 011 ????? 01100 11", mulhu , R, R(rd) = ((uint64_t)src1 * (uint64_t)src2) >> 32);
|
||||
INSTPAT("0000001 ????? ????? 001 ????? 01100 11", mulh , R, R(rd) = ((int64_t)(int32_t) src1 * (int64_t)(int32_t) src2) >> 32);
|
||||
INSTPAT("0000001 ????? ????? 010 ????? 01100 11", mulhsu , R, R(rd) = ((int64_t)(int32_t) src1 * (uint64_t)src2) >> 32); // never used
|
||||
INSTPAT("0000001 ????? ????? 011 ????? 01100 11", mulhu , R, R(rd) = ((uint64_t)src1 * (uint64_t)src2) >> 32); // never used
|
||||
INSTPAT("0000001 ????? ????? 100 ????? 01100 11", div , R, R(rd) = (int32_t) src1 / (int32_t) src2);
|
||||
INSTPAT("0000001 ????? ????? 101 ????? 01100 11", divu , R, R(rd) = (uint32_t)src1 /(uint32_t) src2);
|
||||
INSTPAT("0000001 ????? ????? 110 ????? 01100 11", rem , R, R(rd) = (int32_t) src1 % (int32_t) src2);
|
||||
|
Reference in New Issue
Block a user