Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for CentOS7 and other small contributions #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sw/basic-asm/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all : sum.o
riscv32-unknown-elf-ld sum.o -o main
riscv32-unknown-elf-ld sum.o -o main -melf32lriscv

sim: all
riscv-vp main
Expand Down
22 changes: 12 additions & 10 deletions sw/basic-c/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
all : main.c sum.c bootstrap.S
all: main

main: main.c sum.c bootstrap.S
riscv32-unknown-elf-gcc main.c sum.c bootstrap.S -o main -march=rv32i -mabi=ilp32 -nostartfiles -Wl,--no-relax
sim: all

sim: main
riscv-vp --intercept-syscalls main
dump-elf: all

dump-elf: main
riscv32-unknown-elf-readelf -a main
dump-code: all

dump-code: main
riscv32-unknown-elf-objdump -D main
dump-comment: all

dump-comment: main
objdump -s --section .comment main

clean:
rm -f main
2 changes: 1 addition & 1 deletion sw/basic-e/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all : sum.o
riscv32-unknown-elf-ld sum.o -o main
riscv32-unknown-elf-ld sum.o -o main -melf32lriscv

sim: all
riscv-vp --use-E-base-isa main
Expand Down
8 changes: 6 additions & 2 deletions sw/blocking-sleep/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ override CC = riscv32-unknown-elf-gcc

CFLAGS = -ggdb -march=rv32i -mabi=ilp32
ASFLAGS = $(CFLAGS)
LDFLAGS = -nostartfiles -Wl,--no-relax
LDFLAGS = -nostartfiles -Wl,--no-relax -march=rv32i -mabi=ilp32

all: main
main: main.o irq.o bootstrap.o
sim: main
tiny32-vp --intercept-syscalls $<

.PHONY: all sim
clean:
rm -f *.o
rm -f main

.PHONY: all sim clean
8 changes: 6 additions & 2 deletions sw/busy-wait-sleep/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ override CC = riscv32-unknown-elf-gcc

CFLAGS = -march=rv32i -mabi=ilp32
ASFLAGS = $(CFLAGS)
LDFLAGS = -nostartfiles -Wl,--no-relax
LDFLAGS = -nostartfiles -Wl,--no-relax -march=rv32i -mabi=ilp32

all: main
main: main.o bootstrap.o
sim: main
tiny32-vp --intercept-syscalls $<

.PHONY: all sim
clean:
rm -f *.o
rm -f main

.PHONY: all sim clean
32 changes: 24 additions & 8 deletions sw/printf-float/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
all : main.c entry.S
all: main printf variable_arguments

main: main.c entry.S
riscv64-unknown-elf-gcc main.c entry.S -o main -march=rv32imafd -mabi=ilp32d -Wl,-e_reset_vector
sim: all

sim: main
riscv-vp main

dump-elf: all

printf: printf.c entry.S
riscv64-unknown-elf-gcc printf.c entry.S -o printf -march=rv32ima -mabi=ilp32 -Wl,-e_reset_vector

sim-printf: printf
riscv-vp --intercept-syscalls printf

variable_arguments: variable_arguments.c entry.S
riscv64-unknown-elf-gcc variable_arguments.c entry.S -o variable_arguments -march=rv32ima -mabi=ilp32 -Wl,-e_reset_vector

sim-variable_arguments: variable_arguments
riscv-vp --intercept-syscalls variable_arguments

dump-elf: main
riscv32-unknown-elf-readelf -a main
dump-code: all

dump-code: main
riscv32-unknown-elf-objdump -D main

clean:
rm -f main
rm -f printf
rm -f variable_arguments
42 changes: 42 additions & 0 deletions sw/printf-float/printf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// printf.c: (05/09/21, RD)
// experiments (extended from printf/main.c)

#include "stdio.h"
#include "errno.h"
#include "string.h"
#include "unistd.h"

int main(int argc, char **argv) {
int n = printf("ABCDEFX %s\n", "Done");
int e = errno;
printf("n = %d\n", n);
puts(strerror(e));

puts("Hello World!");
putchar('a');
putchar('b');
putchar('c');
putchar('\n');
printf("Hello World!\n");
printf("printf(%%c, 'x') %c\n", 'x');
printf("printf(%%d, 12) %d\n", 12);
printf("printf(%%f, 1.2f) %f\n", 1.2f);
printf("printf(%%f, 1.2) %f\n", 1.2);
printf("printf(%%Lf, 1.2) %Lf\n", 1.2L);

float f = 1.2f;
double d = 1.2;
long double ld = 1.2L;
printf("printf(%%f, f) %f\n", f);
printf("printf(%%f, d) %f\n", d);
printf("printf(%%Lf, ld) %Lf\n", ld);

f = 3.1415f;
d = 3.1415;
ld = 3.1415L;
printf("printf(%%f, f) %f\n", f);
printf("printf(%%f, d) %f\n", d);
printf("printf(%%Lf, ld) %Lf\n", ld);

return 0;
}
171 changes: 171 additions & 0 deletions sw/printf-float/variable_arguments.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// 06/17/21, RD: variable_arguments.c, example expanded from
// https://www.tutorialspoint.com/cprogramming/c_variable_arguments.htm

#include <stdio.h>
#include <stdarg.h>

int char_average(int num,...) {
va_list valist;
char sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, int); // 'char' is promoted to 'int' when passed through '...'
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int short_average(int num,...) {
va_list valist;
short sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, int); // 'short' is promoted to 'int' when passed through '...'
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int int_average(int num,...) {
va_list valist;
int sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, int);
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int l_average(int num,...) {
va_list valist;
long sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, long);
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int ll_average(int num,...) {
va_list valist;
long long sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, long long);
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int f_average(int num,...) {
va_list valist;
float sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, double); // 'float' is promoted to 'double' when passed through '...'
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int d_average(int num,...) {
va_list valist;
double sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, double);
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int ld_average(int num,...) {
va_list valist;
long double sum = 0;
int i;

/* initialize valist for num number of arguments */
va_start(valist, num);
/* access all the arguments assigned to valist */
for (i = 0; i < num; i++) {
sum += va_arg(valist, long double);
}
/* clean memory reserved for valist */
va_end(valist);
return sum/num;
}

int main() {
printf("Char:%u Average of 2, 3, 4, 5 = %d\n", sizeof(char),
char_average(4, '\02','\03','\04','\05'));
printf("Char:%u Average of 5, 10, 15 = %d\n", sizeof(char),
char_average(3, '\05','\012','\017'));
printf("Shrt:%u Average of 2, 3, 4, 5 = %d\n", sizeof(short),
short_average(4, (short)2,(short)3,(short)4,(short)5));
printf("Shrt:%u Average of 5, 10, 15 = %d\n", sizeof(short),
short_average(3, (short)5,(short)10,(short)15));
printf("Int: %u Average of 2, 3, 4, 5 = %d\n", sizeof(int),
int_average(4, 2,3,4,5));
printf("Int: %u Average of 5, 10, 15 = %d\n", sizeof(int),
int_average(3, 5,10,15));
printf("Long:%u Average of 2, 3, 4, 5 = %d\n", sizeof(long),
l_average(4, 2l,3l,4l,5l));
printf("Long:%u Average of 5, 10, 15 = %d\n", sizeof(long),
l_average(3, 5l,10l,15l));
printf("LL: %u Average of 2, 3, 4, 5 = %d\n", sizeof(long long),
ll_average(4, 2ll,3ll,4ll,5ll));
printf("LL: %u Average of 5, 10, 15 = %d\n", sizeof(long long),
ll_average(3, 5ll,10ll,15ll));
printf("F: %u Average of 2, 3, 4, 5 = %d\n", sizeof(float),
f_average(4, 2.f,3.f,4.f,5.f));
printf("F: %u Average of 5, 10, 15 = %d\n", sizeof(float),
f_average(3, 5.f,10.f,15.f));
printf("D: %u Average of 2, 3, 4, 5 = %d\n", sizeof(double),
d_average(4, 2.0,3.0,4.0,5.0));
printf("D: %u Average of 5, 10, 15 = %d\n", sizeof(double),
d_average(3, 5.0,10.0,15.0));
printf("LD: %u Average of 2, 3, 4, 5 = %d\n", sizeof(long double),
ld_average(4, 2.0L,3.0L,4.0L,5.0L));
printf("LD: %u Average of 5, 10, 15 = %d\n", sizeof(long double),
ld_average(3, 5.0L,10.0L,15.0L));
return 0;
}

// EOF
2 changes: 2 additions & 0 deletions sw/simple-display/libDisplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "../../env/basic/vp-display/framebuffer.h"

using namespace frame; // bug-fix RD (on CentOS7, this only works with this line)

extern Framebuffer* volatile const framebuffer;

inline Color fromRGB(uint8_t r, uint8_t g, uint8_t b) {
Expand Down
2 changes: 1 addition & 1 deletion vp/src/platform/common/fu540_plic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct FU540_PLIC : public sc_core::sc_module, public interrupt_gateway {

std::vector<RegisterRange*> register_ranges;

/* hart_id (0..4) → hart_config */
/* hart_id (0..4) -> hart_config */
typedef std::map<unsigned int, HartConfig*> hartmap;
hartmap enabled_irqs;
hartmap hart_context;
Expand Down
4 changes: 2 additions & 2 deletions vp/src/platform/common/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <sys/types.h>

/* character control key */
/* character -> control key */
#define CTRL(c) ((c) & 0x1f)

#define KEY_ESC CTRL('a') /* Ctrl-a (character to enter command mode) */
Expand Down Expand Up @@ -62,7 +62,7 @@ void UART::handle_cmd(uint8_t cmd) {
exit(EXIT_SUCCESS);
break;
default:
return; /* unknown command → ignore */
return; /* unknown command -> ignore */
}
}

Expand Down