Skip to content

Instantly share code, notes, and snippets.

@heiher
heiher / crossbuild-openssl.sh
Last active July 13, 2022 04:47
Cross build OpenSSL (Debian)
#!/bin/bash
set -e
if [ ! -d openssl ]; then
git clone -b OpenSSL_1_1_1q https://github.com/openssl/openssl
fi
pushd openssl
@heiher
heiher / timetctxsw.c
Created June 20, 2022 16:55
Benchmarks the overhead of context switching between 2 threads.
// Copyright (C) 2010 Benoit Sigoure
// Copyright (C) 2022 hev
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@heiher
heiher / grub-serial.patch
Created June 20, 2022 07:06
GRUB EFI Serial Read workaround for 3A5000
diff --git a/grub-core/term/efi/serial.c b/grub-core/term/efi/serial.c
index 4c94723..0caa724 100644
--- a/grub-core/term/efi/serial.c
+++ b/grub-core/term/efi/serial.c
@@ -65,20 +65,52 @@ do_real_config (struct grub_serial_port *port)
port->configured = 1;
}
+#define SERIAL_BASE 0x800000001fe001e0ul
+
@heiher
heiher / portmap.c
Created September 24, 2021 15:47
TCP port mapping
/*
============================================================================
Name : portmap.c
Author : hev <r@hev.cc>
Copyright : Copyright (c) 2021 xyz
Description : TCP port mapping
============================================================================
*/
#include <errno.h>
@heiher
heiher / loongarch64-li-test-gen.c
Last active August 27, 2021 17:17
LoongArch64 load immediate test generator
/*
* li-test-gen.c
* wangrui <wangrui@loongson.cn>
*
* gcc -o li-test-gen li-test-gen.c
* ./li-test-gen
* gcc -o li-test li-test.c li-test.S
* ./li-test
*/
@heiher
heiher / read-read-reorder.c
Last active August 3, 2021 13:58
Test for reads from the same address out of order (5000)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static volatile unsigned long s;
static void *
write_handler (void *data)
{
for (;;) {
@heiher
heiher / read-read-reorder.c
Last active August 3, 2021 13:28
Test for reads from the same address out of order
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static volatile unsigned long s;
static void *
write_handler (void *data)
{
for (;;) {
@heiher
heiher / mg90s-bootauto.c
Created April 1, 2020 11:26
外置硬盘盒电源开关伺服电机控制程序(树莓派开机自动触发,配合继电器)
#include <poll.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
@heiher
heiher / sg90.c
Created April 1, 2020 05:39
外置硬盘盒电源开关伺服电机控制程序(NanoPi M4版)
/*
============================================================================
Name : sg90.c
Author : Heiher <r@hev.cc>
Copyright : Copyright (c) 2020 everyone.
Description : SG90 Motor Controller
============================================================================
*/
#include <poll.h>
@heiher
heiher / switch
Created March 31, 2020 13:40
NAS外置硬盘盒开关程序(NanoPi侧)
#!/bin/bash
if [ ! -e /sys/class/gpio/gpio33 ]; then
echo 33 > /sys/class/gpio/export
sleep 0.1
echo out > /sys/class/gpio/gpio33/direction
fi
if [ ! -e /sys/class/gpio/gpio35 ]; then
echo 35 > /sys/class/gpio/export