Skip to content

Instantly share code, notes, and snippets.

View paranlee's full-sized avatar
🐧
Run RISC-V run!

Paran Lee paranlee

🐧
Run RISC-V run!
View GitHub Profile
@paranlee
paranlee / page_anon_try_to_unmap_one.c
Last active May 27, 2021 17:23
pageAnon(page) at try_to_unmap_one
/**
* v5.10.37
* https://elixir.bootlin.com/linux/v5.10.37/source/mm/rmap.c#L1617
*/
/*
* @arg: enum ttu_flags will be passed to this argument
*/
static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
unsigned long address, void *arg)
@paranlee
paranlee / linux-kernel-build-for-gdb-in-qemu.sh
Created May 25, 2021 13:43
Linux kernel build for qemu runtime to source code review.
make clean
make defconfig
sed -i 's/-O2/-Og/g' Makefile
make -j $(nproc)
make -j8 cscope tags
<< 'MULTILINE-COMMENT'
~/linux$ git diff
diff --git a/Makefile b/Makefile
index 18b4cebe5564..cd61d89aebfb 100644
@paranlee
paranlee / riscv64-qemu-linux-kernel-ttyS0.sh
Last active June 20, 2021 03:26
runtime analyize for RISC-V linux kernel
~/qemu/build/qemu-system-riscv64 \
-cpu sifive-u54 \
-smp cpus=4,maxcpus=4 \
-M virt \
-m 4096 \
-nographic \
-no-reboot \
-kernel ~/linux/arch/riscv/boot/Image \
-append "root=/dev/vda rw console=ttyS0" \
-drive file=~/busybox/root.bin,format=raw,id=hd0 \
@paranlee
paranlee / riscv64-qemu-linux-kernel.sh
Last active May 31, 2021 10:24
Runtime debugging analyize for RISC-V Linux kernel build from (https://gist.github.com/paranlee/8d83db088e766c0409f3d69146ebfe14)
#!/bin/bash
qemu-system-riscv64 -s -S \
-cpu sifive-u54 \
-smp cpus=4,maxcpus=4 \
-M sifive_u \
-m 4096 \
-kernel arch/riscv/boot/Image \
-bios none \
-nographic \
@paranlee
paranlee / riscv64-build-gdb-symbol.sh
Last active May 31, 2021 23:33
RISC-V build with debugging symbol (Need check to gdb-multiarch can read this debgging symbol)
export CFLAGS="-g -Wall -Wextra"
export ARCH=riscv
export CROSS_COMPILE=riscv64-linux-gnu-
@paranlee
paranlee / riscv64-cross-debugging-packages-debian.sh
Last active April 25, 2022 03:29
Packages for build & runtime debug essential.
sudo apt -y install build-essential cscope universal-ctags curl \
crossbuild-essential-riscv64 gdb-multiarch \
autoconf automake autotools-dev gawk bison flex texinfo gperf libtool patchutils bc \
libncurses-dev libssl-dev libmpc-dev libmpfr-dev libgmp-dev zlib1g-dev libexpat-dev
# sudo apt -y install qemu-system-misc # latest debian package too old (archived 2019 version)
@paranlee
paranlee / xv6-memlayout.h
Last active May 27, 2021 17:22
example of memlayout.h from xv6
// Physical memory layout
// qemu -machine virt is set up like this,
// based on qemu's hw/riscv/virt.c:
//
// 00001000 -- boot ROM, provided by qemu
// 02000000 -- CLINT
// 0C000000 -- PLIC
// 10000000 -- uart0
// 10001000 -- virtio disk
@paranlee
paranlee / monte-carlo-pi-srand.c
Created May 27, 2021 17:21
Program to compute Pi using Monte Carlo methods
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define SEED 35791246
int main(int argc, char* argv) {
int niter = 1UL << 20;
double x, y;
@paranlee
paranlee / riscv64-make-qemu.sh
Last active May 31, 2021 10:19
Make RISC-V 64 QEMU.
<< 'MULTILINE-COMMENT'
sudo apt -y install git git-email ninja-build libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev \
libaio-dev libbluetooth-dev libbrlapi-dev libbz2-dev \
libcap-dev libcap-ng-dev libcurl4-gnutls-dev libgtk-3-dev \
libibverbs-dev libjpeg8-dev libncurses5-dev libnuma-dev \
librbd-dev librdmacm-dev \
libsasl2-dev libsdl1.2-dev libseccomp-dev libsnappy-dev libssh2-1-dev \
libvde-dev libvdeplug-dev libvte-dev libxen-dev liblzo2-dev \
valgrind xfslibs-dev \
@paranlee
paranlee / linux-kernel-checkout.sh
Created May 31, 2021 23:25
Checkout linux kernel stable version.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
# git tag | grep v5.4.123
# git checkout v5.4.123