Compare commits
No commits in common. "r6-struct-point" and "borysr-2024-05-17" have entirely different histories.
r6-struct-
...
borysr-202
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"user": "borysr",
|
||||
"email": "borysr@mpabi.pl",
|
||||
"remotes": [
|
||||
{
|
||||
"name": "r",
|
||||
"protocol": "http",
|
||||
"domain": "qstack.pl",
|
||||
"port": "3000",
|
||||
"token_name": "t",
|
||||
"token": "d61f1823f13e091e62d5193cb9887438742b9f52",
|
||||
"group": "1i-2023",
|
||||
"project": "struct"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
|
||||
ARCH=riscv64-unknown-elf
|
||||
GNU_DIR=$(HOME)/riscv/riscv/
|
||||
GNU_BIN=$(GNU_DIR)/bin
|
||||
|
||||
|
||||
CC=$(GNU_BIN)/$(ARCH)-gcc
|
||||
CXX=$(GNU_BIN)/$(ARCH)-g++
|
||||
AS=$(GNU_BIN)/$(ARCH)-as
|
||||
LD=$(GNU_BIN)/$(ARCH)-ld
|
||||
OBJCOPY=$(GNU_BIN)/$(ARCH)-objcopy
|
||||
OBJDUMP=$(GNU_BIN)/$(ARCH)-objdump
|
||||
SIZE=$(GNU_BIN)/$(ARCH)-size
|
||||
AR=$(GNU_BIN)/$(ARCH)-ar
|
||||
RANLIB=$(GNU_BIN)/$(ARCH)-ranlib
|
||||
|
||||
|
||||
CFLAGS+=-ffreestanding
|
||||
CFLAGS+=-fno-pic
|
||||
CFLAGS+=-march=rv32i -mabi=ilp32
|
||||
CFLAGS+= -g
|
||||
|
||||
|
||||
LDFLAGS+=-nostdlib
|
||||
LDFLAGS+=-Wl,-Ttext=0x00000000
|
||||
|
||||
# see: https://github.com/riscv/riscv-gcc/issues/120
|
||||
#LDFLAGS+=-Wl,--no-relax
|
||||
|
||||
|
||||
|
||||
ASFLAGS+=$(CFLAGS)
|
||||
CXXFLAGS+=$(CFLAGS)
|
||||
|
||||
CLEAN_DIRS=$(SUBDIRS:%=clean-%)
|
||||
ALL_DIRS=$(SUBDIRS:%=all-%)
|
||||
|
||||
OBJDUMPFLAGS+=-Mnumeric,no-aliases
|
||||
|
||||
.PHONY: all clean world $(CLEAN_DIRS) $(ALL_DIRS)
|
||||
|
||||
|
||||
%.bin : %
|
||||
$(OBJCOPY) $< -O binary $@
|
||||
|
||||
%.lst : %
|
||||
$(OBJDUMP) $(OBJDUMPFLAGS) -dr --disassemble-all $< > $<.lst
|
||||
|
||||
% : %.o
|
||||
$(LINK.cc) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||
$(SIZE) -x -A $@
|
||||
|
||||
%.s: %.c
|
||||
$(COMPILE.c) -S -o $@ $<
|
||||
|
||||
%.s: %.cc
|
||||
$(COMPILE.cc) -S -o $@ $<
|
||||
|
||||
%.o: %.c
|
||||
$(COMPILE.c) -o $@ $<
|
||||
|
||||
%.o: %.cc
|
||||
$(COMPILE.cc) -o $@ $<
|
||||
|
||||
%.srec: %
|
||||
$(OBJCOPY) $< -O srec $@
|
||||
|
||||
|
||||
|
||||
|
||||
all:: $(ALL_DIRS)
|
||||
|
||||
clean:: $(CLEAN_DIRS)
|
||||
|
||||
$(ALL_DIRS)::
|
||||
$(MAKE) -C $(@:all-%=%) all
|
||||
|
||||
$(CLEAN_DIRS)::
|
||||
$(MAKE) -C $(@:clean-%=%) clean
|
||||
|
||||
world:: clean all
|
27
cpp/Makefile
27
cpp/Makefile
|
@ -1,27 +0,0 @@
|
|||
TOP=./
|
||||
include $(TOP)/Make.rules
|
||||
|
||||
LDLIBS=
|
||||
#CFLAGS+=-O0 -g
|
||||
# CFLAGS+=-Og -ggdb3
|
||||
CFLAGS+=-O0 -ggdb3
|
||||
|
||||
LDFLAGS+=-Wl,--no-relax
|
||||
LDFLAGS+=-Wl,-Ttext=0x80000000,-Tdata=0x80010000
|
||||
# LDFLAGS+=-T murax_128k_ram.ld
|
||||
|
||||
PROGS=prog prog.bin prog.lst
|
||||
|
||||
all:: $(PROGS)
|
||||
|
||||
prog: _crt0.o _rvmain.o myfunc.o
|
||||
$(LINK.cc) -o $@ $^ $(LDLIBS)
|
||||
$(SIZE) -A -x $@
|
||||
|
||||
clean::
|
||||
rm -f $(PROGS) *.o *.s *.lst *.bin *.srec *.dis
|
||||
|
||||
.PHONY: run
|
||||
run: prog.bin
|
||||
../../../src/rvddt -l0x3000 -f prog.bin
|
||||
|
42
cpp/_crt0.S
42
cpp/_crt0.S
|
@ -1,42 +0,0 @@
|
|||
.text
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
# Initialize global pointer
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
li sp, 0x800ffff0
|
||||
|
||||
# Clear the bss segment
|
||||
la a0, __bss_start
|
||||
la a1, __BSS_END__
|
||||
|
||||
clear_bss:
|
||||
bgeu a0, a1, finish_bss
|
||||
sb x0, 0(a0)
|
||||
addi a0, a0, 1
|
||||
beq x0, x0, clear_bss
|
||||
finish_bss:
|
||||
|
||||
nop //!
|
||||
|
||||
call main
|
||||
|
||||
nop //!
|
||||
|
||||
# abort execution here
|
||||
ebreak
|
||||
|
||||
.section .rodata
|
||||
alfabet:
|
||||
.string "abcdefghijklmnopqrstuwxyz"
|
||||
slowo:
|
||||
|
||||
.section .data
|
||||
wynik:
|
||||
.string "mpabi"
|
||||
.space 26 # rezerwuje 26 bajtów dla wyniku, zainicjowane na 0
|
|
@ -1,69 +0,0 @@
|
|||
#include <stdint.h>
|
||||
|
||||
char * ptr1 = "janek";
|
||||
char * ptr2 = "kowalskii";
|
||||
|
||||
int strlen(char *s)
|
||||
{
|
||||
char *p = s;
|
||||
while (*p != '\0')
|
||||
p++;
|
||||
return p - s;
|
||||
}
|
||||
|
||||
void strcpy(char *s, char *t)
|
||||
{
|
||||
while (*s++ = *t++);
|
||||
}
|
||||
|
||||
|
||||
#define ALLOCSIZE 10000
|
||||
|
||||
static char allocbuf[ALLOCSIZE];
|
||||
static char *allocp = allocbuf;
|
||||
|
||||
char *alloc(int n)
|
||||
{
|
||||
|
||||
if (n % 4 != 0) {
|
||||
n += 4 - (n % 4);
|
||||
}
|
||||
|
||||
|
||||
if (allocbuf + ALLOCSIZE - allocp >= n) {
|
||||
allocp += n;
|
||||
return allocp - n;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sum (int32_t a, int32_t b) {
|
||||
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
struct point {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
struct point * ptrS;
|
||||
|
||||
ptrS = (struct point *) alloc(sizeof(point));
|
||||
|
||||
asm("nop");
|
||||
|
||||
ptrS->x=0x10;
|
||||
ptrS->y=0x20;
|
||||
|
||||
int32_t wynik = 0;
|
||||
|
||||
wynik = sum ( (*ptrS).x, ptrS->y);
|
||||
asm("nop");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#include "myfunc.h"
|
||||
|
||||
// Lokalna deklaracja funkcji my_strlen
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik) {
|
||||
// Użycie my_strlen do obliczenia długości alfabetu
|
||||
int alfabet_length = my_strlen(alfabet);
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
wynik[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; slowo[j] != '\0'; ++j) {
|
||||
if (alfabet[i] == slowo[j]) {
|
||||
wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #include "myfunc.h"
|
||||
|
||||
// const char* alfabet = "abcdefghijklmnopqrstuwxyz";
|
||||
// const char* slowo = "mpabi";
|
||||
// int wynik[26] = {0}; // Inicjalizacja tablicy wyników na 0
|
||||
|
||||
// count_characters(alfabet, slowo, wynik);
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef myfunc_H
|
||||
#define myfunc_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
|
||||
#endif
|
17
gdb/z.py
17
gdb/z.py
|
@ -1,17 +0,0 @@
|
|||
# set args 0x1FF80 0x80 0x30
|
||||
# source gdb/z.py
|
||||
|
||||
import gdb
|
||||
import sys
|
||||
|
||||
# Parse arguments from the GDB command
|
||||
args = gdb.string_to_argv(gdb.parameter("args"))
|
||||
if len(args) != 3:
|
||||
print("Usage: source gdb/zero_with_params.py <start_address> <num_bytes> <pattern>")
|
||||
else:
|
||||
start_address = int(args[0], 16) # Convert start address from hex to int
|
||||
num_bytes = int(args[1], 16) # Convert number of bytes from hex to int
|
||||
pattern = int(args[2], 16) # Convert pattern from hex to int
|
||||
|
||||
for i in range(num_bytes):
|
||||
gdb.execute("set *((char*)%x + %x) = %x" % (start_address, i, pattern))
|
|
@ -1,5 +0,0 @@
|
|||
#source gdb/z.py
|
||||
|
||||
import gdb
|
||||
for i in range(0, 128): # 128 bajtów
|
||||
gdb.execute("set *((char*)(0x1FF80 + %x)) = 0xaa" % i)
|
|
@ -0,0 +1,111 @@
|
|||
import argparse
|
||||
import json
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"user": "borysr",
|
||||
"email": "borysr@mpabi.pl",
|
||||
"remotes": [{
|
||||
"name": "r", # Zaktualizowano z "default" na "mpabi"
|
||||
"protocol": "http",
|
||||
"domain": "qstack.pl",
|
||||
"port": "3000",
|
||||
"token_name": "t",
|
||||
"token": "d61f1823f13e091e62d5193cb9887438742b9f52",
|
||||
"group": "1i-2023",
|
||||
"project": "struct"
|
||||
}]
|
||||
}
|
||||
|
||||
def load_or_create_config(config_file, args):
|
||||
config_exists = os.path.exists(config_file) and os.stat(config_file).st_size != 0
|
||||
if config_exists:
|
||||
with open(config_file, 'r') as file:
|
||||
config = json.load(file)
|
||||
else:
|
||||
config = DEFAULT_CONFIG.copy()
|
||||
|
||||
# Znajdź istniejące zdalne repozytorium o podanej nazwie
|
||||
remote = next((remote for remote in config['remotes'] if remote['name'] == args.remote), None)
|
||||
|
||||
# Jeśli istnieje zdalne repozytorium i podano argumenty związane z konfiguracją zdalnego repozytorium
|
||||
if remote:
|
||||
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
|
||||
# Aktualizuj tylko, jeśli argument został jawnie podany
|
||||
if getattr(args, field, None) is not None:
|
||||
remote[field] = getattr(args, field)
|
||||
|
||||
# Jeśli zdalne repozytorium nie istnieje, ale podano nazwę, tworzymy nowe zdalne repozytorium
|
||||
elif args.remote:
|
||||
new_remote = {'name': args.remote}
|
||||
for field in ['protocol', 'domain', 'port', 'token_name', 'token', 'group', 'project']:
|
||||
new_remote[field] = getattr(args, field, DEFAULT_CONFIG['remotes'][0].get(field, ''))
|
||||
if new_remote[field] == None:
|
||||
new_remote[field] = DEFAULT_CONFIG['remotes'][0].get(field, '')
|
||||
config['remotes'].append(new_remote)
|
||||
|
||||
# Aktualizuj informacje o użytkowniku i email, tylko jeśli zostały podane
|
||||
if getattr(args, 'user', None):
|
||||
config['user'] = args.user
|
||||
if getattr(args, 'email_domain', None):
|
||||
config['email'] = f"{args.user}@{args.email_domain}"
|
||||
|
||||
# Zapisz zmodyfikowaną konfigurację
|
||||
with open(config_file, 'w') as file:
|
||||
json.dump(config, file, indent=4)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def init_git_repo(config):
|
||||
user_name = config['user']
|
||||
user_email = config['email']
|
||||
branch_name = f"{user_name}-{datetime.now().strftime('%Y-%m-%d')}"
|
||||
|
||||
if subprocess.run(["git", "rev-parse", "--git-dir"], stderr=subprocess.DEVNULL).returncode != 0:
|
||||
subprocess.run(["git", "init"])
|
||||
subprocess.run(["git", "config", "user.name", user_name])
|
||||
subprocess.run(["git", "config", "user.email", user_email])
|
||||
subprocess.run(["git", "checkout", "-b", branch_name])
|
||||
print("Git repository initialized.")
|
||||
else:
|
||||
print("Already inside a Git repository. Skipping initialization.")
|
||||
|
||||
remotesFromList = str(subprocess.run(["git", "remote", "-v"], capture_output=True).stdout)
|
||||
remotesFromList = remotesFromList.replace('b\'', "").replace('\'', "").split('\\n')
|
||||
for rm in remotesFromList:
|
||||
name = rm.split("\\t")[0]
|
||||
subprocess.run(["git", "remote", "remove", name], stderr=subprocess.DEVNULL)
|
||||
|
||||
for remote in config['remotes']:
|
||||
remote_url = f"{remote['protocol']}://{remote['token_name']}:{remote['token']}@{remote['domain']}:{remote['port']}/{remote['group']}/{remote['project']}"
|
||||
# Usunięcie i ponowne dodanie zdalnego repozytorium, jeśli jest zaktualizowane
|
||||
#subprocess.run(["git", "remote", "remove", remote['name']], stderr=subprocess.DEVNULL)
|
||||
subprocess.run(["git", "remote", "add", remote['name'], remote_url])
|
||||
print(f"Remote '{remote['name']}' added or updated.")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Git repository initializer with custom configuration.")
|
||||
parser.add_argument("--user", help="User name")
|
||||
parser.add_argument("--email_domain", help="Email domain")
|
||||
parser.add_argument("--config", help="Path to the JSON config file", default="conf.json")
|
||||
parser.add_argument("--remote", help="Name of the remote to add or update")
|
||||
parser.add_argument("--protocol", help="Remote protocol")
|
||||
parser.add_argument("--domain", help="Remote domain")
|
||||
parser.add_argument("--port", help="Remote port")
|
||||
parser.add_argument("--token_name", help="Remote token name")
|
||||
parser.add_argument("--token", help="Remote token")
|
||||
parser.add_argument("--group", help="Group name")
|
||||
parser.add_argument("--project", help="Project name")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
config = load_or_create_config(args.config, args)
|
||||
init_git_repo(config)
|
||||
print("Git repository initialized and configured based on the provided configuration.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
BIN
tex/main.pdf
BIN
tex/main.pdf
Binary file not shown.
110
tex/main.tex
110
tex/main.tex
|
@ -1,110 +0,0 @@
|
|||
\documentclass{article}
|
||||
\usepackage[a4paper, margin=2cm]{geometry}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[polish]{babel}
|
||||
\usepackage{listings}
|
||||
\usepackage{color}
|
||||
|
||||
\definecolor{codegreen}{rgb}{0,0.6,0}
|
||||
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
|
||||
\definecolor{codepurple}{rgb}{0.58,0,0.82}
|
||||
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
|
||||
|
||||
\lstdefinestyle{mystyle}{
|
||||
backgroundcolor=\color{backcolour},
|
||||
commentstyle=\color{codegreen},
|
||||
keywordstyle=\color{magenta},
|
||||
numberstyle=\tiny\color{codegray},
|
||||
stringstyle=\color{codepurple},
|
||||
basicstyle=\ttfamily\footnotesize,
|
||||
breakatwhitespace=false,
|
||||
breaklines=true,
|
||||
captionpos=b,
|
||||
keepspaces=true,
|
||||
showspaces=false,
|
||||
showstringspaces=false,
|
||||
showtabs=false,
|
||||
tabsize=2
|
||||
}
|
||||
|
||||
\lstset{style=mystyle}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{GDB and DASHBOARD}
|
||||
\author{}
|
||||
\date{}
|
||||
\maketitle
|
||||
|
||||
\section{Dashboard memory watch}
|
||||
Dashboard GDB pozwala na dynamiczne obserwowanie określonych obszarów pamięci. Używając funkcji \texttt{dashboard memory watch}, można ustawić obserwację na konkretne adresy pamięci.
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
dashboard memory watch 0x1ff80 128
|
||||
\end{lstlisting}
|
||||
|
||||
\noindent
|
||||
Powyższa komenda skonfiguruje dashboard do obserwacji 128 bajtów pamięci, począwszy od adresu \texttt{0x1ff80}.
|
||||
|
||||
\section{Obserwacja pamięci przy użyciu watch w GDB}
|
||||
Aby obserwować pamięć na niskim poziomie w GDB, można użyć komendy \texttt{watch} w połączeniu z rzutowaniem i rozmiarem obserwowanego obszaru. Przykładowo, aby obserwować 128 bajty pamięci zaczynając od adresu \texttt{0x1ff80}, użyjemy następującej komendy:
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
watch *(char*)0x1ff80 @ 128
|
||||
\end{lstlisting}
|
||||
|
||||
Ta komenda spowoduje przerwanie wykonania programu, gdy wartości w obserwowanym obszarze pamięci ulegną zmianie. Użycie rzutowania na typ \texttt{(char*)} pozwala na interpretację adresu jako wskaźnika na bajty, a operator \texttt{@} określa ilość obserwowanych bajtów.
|
||||
|
||||
\section{Clear Memory}
|
||||
|
||||
\subsection{Basic Usage}
|
||||
To clear 128 bytes of memory starting from 0x1FF80, use the following script:
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
#./gdb/zero.py
|
||||
|
||||
import gdb
|
||||
for i in range(0, 128): # 128 bajtów
|
||||
gdb.execute("set *((char*)0x1FF80 + %d) = 0" % i)
|
||||
\end{lstlisting}
|
||||
|
||||
Run this script from GDB dashboard by:
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
source gdb/zero.py
|
||||
\end{lstlisting}
|
||||
|
||||
\subsection{Option 2: With Parameters}
|
||||
To dynamically set the starting address, number of bytes, and pattern from the command line, modify the script as follows:
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
#./gdb/zero_with_params.py
|
||||
|
||||
import gdb
|
||||
import sys
|
||||
|
||||
# Parse arguments from the GDB command
|
||||
args = gdb.string_to_argv(gdb.parameter("args"))
|
||||
if len(args) != 3:
|
||||
print("Usage: source gdb/zero_with_params.py <start_address> <num_bytes> <pattern>")
|
||||
else:
|
||||
start_address = int(args[0], 16) # Convert start address from hex to int
|
||||
num_bytes = int(args[1], 16) # Convert number of bytes from hex to int
|
||||
pattern = int(args[2], 16) # Convert pattern from hex to int
|
||||
|
||||
for i in range(num_bytes):
|
||||
gdb.execute("set *((char*)%d + %d) = %d" % (start_address, i, pattern))
|
||||
\end{lstlisting}
|
||||
|
||||
To run this script with parameters, set GDB's `args` parameter before sourcing the script:
|
||||
|
||||
\begin{lstlisting}[language=bash]
|
||||
set args 0x1FF80 0x80 0x30
|
||||
source gdb/zero_with_params.py
|
||||
\end{lstlisting}
|
||||
|
||||
This allows specifying the starting address, number of bytes to clear, and the pattern to use directly from the GDB command line.
|
||||
|
||||
\end{document}
|
Loading…
Reference in New Issue