1 /* $OpenBSD: codepatch.h,v 1.2 2015/04/19 19:45:21 sf Exp $ */ 2 /* 3 * Copyright (c) 2014-2015 Stefan Fritsch <sf@sfritsch.de> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _MACHINE_CODEPATCH_H_ 19 #define _MACHINE_CODEPATCH_H_ 20 21 #include <machine/param.h> 22 23 #ifndef _LOCORE 24 25 void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); 26 void codepatch_unmaprw(vaddr_t nva); 27 void codepatch_fill_nop(void *caddr, uint16_t len); 28 void codepatch_nop(uint16_t tag); 29 void codepatch_replace(uint16_t tag, void *code, size_t len); 30 void codepatch_call(uint16_t tag, void *func); 31 32 #endif /* !_LOCORE */ 33 34 /* 35 * Mark the start of some code snippet to be patched. 36 */ 37 #define CODEPATCH_START 998: 38 /* 39 * Mark the end of some code to be patched, and assign the given tag. 40 */ 41 #define CODEPATCH_END(tag) \ 42 999: \ 43 .section .codepatch, "a" ;\ 44 .int (998b - KERNBASE) ;\ 45 .short (999b - 998b) ;\ 46 .short tag ;\ 47 .previous 48 49 #define CPTAG_STAC 1 50 #define CPTAG_CLAC 2 51 #define CPTAG_EOI 3 52 53 #endif /* _MACHINE_CODEPATCH_H_ */ 54