~mcf/drawterm

d28c5f37cfbd0507796d76ced17ad01fd11ea564 — 5 months ago ec8c48a
add preliminary riscv64 support from archlinux (thanks Sören Tempel)
3 files changed, 54 insertions(+), 0 deletions(-)

A posix-riscv64/Makefile
A posix-riscv64/getcallerpc.c
A posix-riscv64/tas.c
A posix-riscv64/Makefile => posix-riscv64/Makefile +18 -0
@@ 0,0 1,18 @@
ROOT=..
include ../Make.config
LIB=../libmachdep.a

OFILES=\
	getcallerpc.$O\
	tas.$O

default: $(LIB)
$(LIB): $(OFILES)
	$(AR) r $(LIB) $(OFILES)
	$(RANLIB) $(LIB)

%.$O: %.c
	$(CC) $(CFLAGS) $*.c

%.$O: %.s
	$(AS) -o $*.$O $*.s

A posix-riscv64/getcallerpc.c => posix-riscv64/getcallerpc.c +8 -0
@@ 0,0 1,8 @@
#include "u.h"
#include "libc.h"

uintptr
getcallerpc(void *a)
{
	return ((uintptr*)a)[-1];
}

A posix-riscv64/tas.c => posix-riscv64/tas.c +28 -0
@@ 0,0 1,28 @@
#include "u.h"
#include "libc.h"

int
tas(int *x)
{
	int v, i = 1;

	__asm__(
		"1:	lr.w t0, (%1)\n"
		"	sc.w t1, %2, (%1)\n"
		"	bnez t1, 1b\n"
		"       mv %0, t0"
		: "=r" (v)
		: "r" (x), "r" (i)
		: "t1", "t0"
	);

	switch(v) {
	case 0:
	case 1:
		return v;
	default:
		print("canlock: corrupted 0x%lux\n", v);
		return 1;
	}
}