1*758370f9Sbluhm /* $OpenBSD: codepatch.h,v 1.3 2023/07/31 17:10:31 bluhm Exp $ */ 264e2e800Ssf /* 364e2e800Ssf * Copyright (c) 2014-2015 Stefan Fritsch <sf@sfritsch.de> 464e2e800Ssf * 564e2e800Ssf * Permission to use, copy, modify, and distribute this software for any 664e2e800Ssf * purpose with or without fee is hereby granted, provided that the above 764e2e800Ssf * copyright notice and this permission notice appear in all copies. 864e2e800Ssf * 964e2e800Ssf * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1064e2e800Ssf * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1164e2e800Ssf * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1264e2e800Ssf * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1364e2e800Ssf * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1464e2e800Ssf * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1564e2e800Ssf * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1664e2e800Ssf */ 1764e2e800Ssf 1864e2e800Ssf #ifndef _MACHINE_CODEPATCH_H_ 1964e2e800Ssf #define _MACHINE_CODEPATCH_H_ 2064e2e800Ssf 2164e2e800Ssf #include <machine/param.h> 2264e2e800Ssf 2364e2e800Ssf #ifndef _LOCORE 2464e2e800Ssf 2564e2e800Ssf void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); 2664e2e800Ssf void codepatch_unmaprw(vaddr_t nva); 2764e2e800Ssf void codepatch_fill_nop(void *caddr, uint16_t len); 2864e2e800Ssf void codepatch_nop(uint16_t tag); 29*758370f9Sbluhm void codepatch_replace(uint16_t tag, const void *code, size_t len); 3064e2e800Ssf void codepatch_call(uint16_t tag, void *func); 3164e2e800Ssf 3264e2e800Ssf #endif /* !_LOCORE */ 3364e2e800Ssf 3464e2e800Ssf /* 3564e2e800Ssf * Mark the start of some code snippet to be patched. 3664e2e800Ssf */ 3764e2e800Ssf #define CODEPATCH_START 998: 3864e2e800Ssf /* 3964e2e800Ssf * Mark the end of some code to be patched, and assign the given tag. 4064e2e800Ssf */ 4164e2e800Ssf #define CODEPATCH_END(tag) \ 4264e2e800Ssf 999: \ 4364e2e800Ssf .section .codepatch, "a" ;\ 448d3e0a5bSsf .int 998b ;\ 4564e2e800Ssf .short (999b - 998b) ;\ 4664e2e800Ssf .short tag ;\ 4764e2e800Ssf .previous 4864e2e800Ssf 4964e2e800Ssf #define CPTAG_STAC 1 5064e2e800Ssf #define CPTAG_CLAC 2 5164e2e800Ssf 5264e2e800Ssf #endif /* _MACHINE_CODEPATCH_H_ */ 53