Skip to content
Snippets Groups Projects
Verified Commit c29f7514 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

> Manual commit: Adjust makefile for qemu-diff

U201614531
recolic
Linux RECOLICPC 5.4.2-arch1-1 #1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000 x86_64 GNU/Linux
 20:55:53 up 4 days,  2:04,  1 user,  load average: 0.65, 0.50, 0.47
e3d87462f69f26419a41b6a38703c531e489c
parent b0731913
No related branches found
No related tags found
No related merge requests found
...@@ -155,7 +155,7 @@ static inline void rtl_sr(int r, const rtlreg_t* src1, int width) { ...@@ -155,7 +155,7 @@ static inline void rtl_sr(int r, const rtlreg_t* src1, int width) {
static inline void rtl_not(rtlreg_t *dest, const rtlreg_t* src1) { static inline void rtl_not(rtlreg_t *dest, const rtlreg_t* src1) {
// dest <- ~src1 // dest <- ~src1
TODO(); *dest = ~ *src1;
} }
static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) { static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
make_EHelper(add) { make_EHelper(add) {
rtl_sext(&t1, &id_dest->val, id_dest->width); rtl_sext(&t1, &id_dest->val, id_dest->width);
rtl_sext(&t2, &id_src->val, id_src->width); rtl_sext(&t2, &id_src->val, id_src->width);
rtl_add(&t0, &t1, &t2); rtl_add(&t0, &t1, &t2);
t3 = (t0 < t1); t3 = (t0 < t1);
rtl_set_CF(&t3); rtl_set_CF(&t3);
......
#include "cpu/exec.h" #include "cpu/exec.h"
#include "cpu/cc.h" #include "cpu/cc.h"
void sign_extend_if_required(const Operand &dest, Operand &src) {
if(dest.width > src.width) {
rtl_sext(&src.val, &src.val, src.width);
src.imm = src.val;
src.width = dest.width;
}
}
make_EHelper(test) { make_EHelper(test) {
// `and` without write_back. // `and` without write_back.
sign_extend_if_required(*id_dest, *id_src);
rtl_and(&t1, &id_dest->val, &id_src->val); rtl_and(&t1, &id_dest->val, &id_src->val);
rtl_update_ZFSF(&t1, id_dest->width); rtl_update_ZFSF(&t1, id_dest->width);
...@@ -12,6 +21,10 @@ make_EHelper(test) { ...@@ -12,6 +21,10 @@ make_EHelper(test) {
} }
make_EHelper(and) { make_EHelper(and) {
rlib::printfln("before test, id_dest={}, src={}", *id_dest, *id_src);
sign_extend_if_required(*id_dest, *id_src);
rlib::printfln("after test, id_dest={}, src={}", *id_dest, *id_src);
rtl_and(&id_dest->val, &id_dest->val, &id_src->val); rtl_and(&id_dest->val, &id_dest->val, &id_src->val);
operand_write(id_dest, &id_dest->val); operand_write(id_dest, &id_dest->val);
...@@ -22,6 +35,8 @@ make_EHelper(and) { ...@@ -22,6 +35,8 @@ make_EHelper(and) {
} }
make_EHelper(xor) { make_EHelper(xor) {
sign_extend_if_required(*id_dest, *id_src);
rtl_xor(&id_dest->val, &id_dest->val, &id_src->val); rtl_xor(&id_dest->val, &id_dest->val, &id_src->val);
operand_write(id_dest, &id_dest->val); operand_write(id_dest, &id_dest->val);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
%% %%
[ \t\n] {} [ \t\n] {}
0x[0-9]+ {yylval.ival = (int)strtol(yytext, NULL, 16); return T_INT;} 0x[0-9a-f]+ {yylval.ival = (int)strtol(yytext, NULL, 16); return T_INT;}
[0-9]+ {yylval.ival = atoi(yytext); return T_INT;} [0-9]+ {yylval.ival = atoi(yytext); return T_INT;}
"==" {return T_EQUAL;} "==" {return T_EQUAL;}
"!=" {return T_NEQUAL;} "!=" {return T_NEQUAL;}
......
...@@ -71,7 +71,7 @@ static struct { ...@@ -71,7 +71,7 @@ static struct {
{ "c", "Continue the execution of the program", cmd_c }, { "c", "Continue the execution of the program", cmd_c },
{ "n", "= GDB `n`", cmd_n }, { "n", "= GDB `n`", cmd_n },
{ "info", "= GDB `info`, supporting `info r` / `info w`", cmd_info }, { "info", "= GDB `info`, supporting `info r` / `info w`", cmd_info },
{ "x", "x <bytes> <start address>, dump memory content.", cmd_x }, { "x", "x <bytes> <startAddr or expr>, dump memory content.", cmd_x },
{ "w", "w <expr>, add watchpoint for $expr", cmd_w }, { "w", "w <expr>, add watchpoint for $expr", cmd_w },
{ "p", "p <expr>, show value of $expr", cmd_p }, { "p", "p <expr>, show value of $expr", cmd_p },
{ "d", "d <watchpoint id>, delete watchpoint by id", cmd_d }, { "d", "d <watchpoint id>, delete watchpoint by id", cmd_d },
...@@ -185,12 +185,13 @@ static int cmd_info(char *_args) { ...@@ -185,12 +185,13 @@ static int cmd_info(char *_args) {
static int cmd_x(char *_args) { static int cmd_x(char *_args) {
if(_args == NULL) if(_args == NULL)
throw std::runtime_error("Usage: x <size> <startAddr>"); throw std::runtime_error("Usage: x <size> <startAddr/expr>");
auto args = string(_args).strip().split(); auto args = string(_args).strip().split();
if(args.size() != 2) if(args.size() != 2)
throw std::runtime_error("Usage: x <size> <startAddr>"); throw std::runtime_error("Usage: x <size> <startAddr/expr>");
println(dumpMem(std::stoull(args[1], 0, 16), args[0].as<uint64_t>())); uint32_t beginAddr = evaluate_expr(args[1]);
println(dumpMem(beginAddr, args[0].as<uint64_t>()));
return 0; return 0;
} }
......
...@@ -6,20 +6,20 @@ BINARY ?= $(BUILD_DIR)/qemu-so ...@@ -6,20 +6,20 @@ BINARY ?= $(BUILD_DIR)/qemu-so
.DEFAULT_GOAL = app .DEFAULT_GOAL = app
# Compilation flags # Compilation flags
CC = gcc CXX ?= g++
LD = gcc LD = $(CXX)
INCLUDES = $(addprefix -I, $(INC_DIR)) INCLUDES = $(addprefix -I, $(INC_DIR))
CFLAGS += -O2 -fPIC -MMD -Wall -Werror -ggdb3 $(INCLUDES) -fomit-frame-pointer CFLAGS += -O2 -fPIC -MMD -Wall -Werror -ggdb3 $(INCLUDES) -fomit-frame-pointer
# Files to be compiled # Files to be compiled
SRCS = $(shell find src/ -name "*.c") SRCS = $(shell find src/ -name "*.cc")
OBJS = $(SRCS:src/%.c=$(OBJ_DIR)/%.o) OBJS = $(SRCS:src/%.cc=$(OBJ_DIR)/%.o)
# Compilation patterns # Compilation patterns
$(OBJ_DIR)/%.o: src/%.c $(OBJ_DIR)/%.o: src/%.cc
@echo + CC $< @echo + CXX $<
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $< @$(CXX) $(CFLAGS) -c -o $@ $<
# Depencies # Depencies
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
typedef uint8_t bool;
#define true 1
#define false 0
#include "protocol.h" #include "protocol.h"
#endif #endif
...@@ -12,7 +12,7 @@ bool gdb_connect_qemu(void) { ...@@ -12,7 +12,7 @@ bool gdb_connect_qemu(void) {
} }
static bool gdb_memcpy_to_qemu_small(uint32_t dest, void *src, int len) { static bool gdb_memcpy_to_qemu_small(uint32_t dest, void *src, int len) {
char *buf = malloc(len * 2 + 128); char *buf = (char *)malloc(len * 2 + 128);
assert(buf != NULL); assert(buf != NULL);
int p = sprintf(buf, "M0x%x,%x:", dest, len); int p = sprintf(buf, "M0x%x,%x:", dest, len);
int i; int i;
...@@ -31,7 +31,8 @@ static bool gdb_memcpy_to_qemu_small(uint32_t dest, void *src, int len) { ...@@ -31,7 +31,8 @@ static bool gdb_memcpy_to_qemu_small(uint32_t dest, void *src, int len) {
return ok; return ok;
} }
bool gdb_memcpy_to_qemu(uint32_t dest, void *src, int len) { bool gdb_memcpy_to_qemu(uint32_t dest, void *_src, int len) {
char *src = (char *)_src;
const int mtu = 1500; const int mtu = 1500;
bool ok = true; bool ok = true;
while (len > mtu) { while (len > mtu) {
...@@ -49,10 +50,9 @@ bool gdb_getregs(union gdb_regs *r) { ...@@ -49,10 +50,9 @@ bool gdb_getregs(union gdb_regs *r) {
size_t size; size_t size;
uint8_t *reply = gdb_recv(conn, &size); uint8_t *reply = gdb_recv(conn, &size);
int i;
uint8_t *p = reply; uint8_t *p = reply;
uint8_t c; uint8_t c;
for (i = 0; i < sizeof(union gdb_regs) / sizeof(uint32_t); i ++) { for (size_t i = 0; i < sizeof(union gdb_regs) / sizeof(uint32_t); i ++) {
c = p[8]; c = p[8];
p[8] = '\0'; p[8] = '\0';
r->array[i] = gdb_decode_hex_str(p); r->array[i] = gdb_decode_hex_str(p);
...@@ -67,7 +67,7 @@ bool gdb_getregs(union gdb_regs *r) { ...@@ -67,7 +67,7 @@ bool gdb_getregs(union gdb_regs *r) {
bool gdb_setregs(union gdb_regs *r) { bool gdb_setregs(union gdb_regs *r) {
int len = sizeof(union gdb_regs); int len = sizeof(union gdb_regs);
char *buf = malloc(len * 2 + 128); char *buf = (char *)malloc(len * 2 + 128);
assert(buf != NULL); assert(buf != NULL);
buf[0] = 'G'; buf[0] = 'G';
......
...@@ -65,7 +65,7 @@ uint64_t gdb_decode_hex_str(uint8_t *bytes) { ...@@ -65,7 +65,7 @@ uint64_t gdb_decode_hex_str(uint8_t *bytes) {
static struct gdb_conn* gdb_begin(int fd) { static struct gdb_conn* gdb_begin(int fd) {
struct gdb_conn *conn = calloc(1, sizeof(struct gdb_conn *)); struct gdb_conn *conn = (gdb_conn *)calloc(1, sizeof(struct gdb_conn *));
if (conn == NULL) if (conn == NULL)
err(1, "calloc"); err(1, "calloc");
...@@ -174,7 +174,7 @@ void gdb_send(struct gdb_conn *conn, const uint8_t *command, size_t size) { ...@@ -174,7 +174,7 @@ void gdb_send(struct gdb_conn *conn, const uint8_t *command, size_t size) {
static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) { static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) {
size_t i = 0; size_t i = 0;
size_t size = 4096; size_t size = 4096;
uint8_t *reply = malloc(size); uint8_t *reply = (uint8_t *)malloc(size);
if (reply == NULL) if (reply == NULL)
err(1, "malloc"); err(1, "malloc");
...@@ -205,7 +205,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) { ...@@ -205,7 +205,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) {
// terminate it for good measure // terminate it for good measure
if (i == size) { if (i == size) {
reply = realloc(reply, size + 1); reply = (uint8_t *)realloc(reply, size + 1);
if (reply == NULL) if (reply == NULL)
err(1, "realloc"); err(1, "realloc");
} }
...@@ -234,7 +234,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) { ...@@ -234,7 +234,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) {
// get a bigger buffer if needed // get a bigger buffer if needed
if (i + count > size) { if (i + count > size) {
size *= 2; size *= 2;
reply = realloc(reply, size); reply = (uint8_t *)realloc(reply, size);
if (reply == NULL) if (reply == NULL)
err(1, "realloc"); err(1, "realloc");
} }
...@@ -257,7 +257,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) { ...@@ -257,7 +257,7 @@ static uint8_t* recv_packet(FILE *in, size_t *ret_size, bool* ret_sum_ok) {
// get a bigger buffer if needed // get a bigger buffer if needed
if (i == size) { if (i == size) {
size *= 2; size *= 2;
reply = realloc(reply, size); reply = (uint8_t *)realloc(reply, size);
if (reply == NULL) if (reply == NULL)
err(1, "realloc"); err(1, "realloc");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment