lcms2.library: fixed strict aliasing issue detected with gcc 4.8.3
[AROS.git] / arch / m68k-amiga / c / SetPatchAROS.c
blobc46ee27b43774f07ff66be16fd20b7d39b762d3e
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code to dynamically load ELF executables under AOS.
6 Lang: english
7 */
9 /* Compile for AROS:
11 * $ bin/linux-x86_64/tools/m68k-amiga-aros-gcc -Os -I /path/to/src/AROS \
12 * SetPatchAROS.c -o SetPatchAROS.elf
13 * $ bin/linux-x86_64/tools/elf2hunk SetPatchAROS.elf SetPatchAROS
15 * Copy SetPatchAROS to your AOS installation, and add the following
16 * to your startup script:
18 * Run SetPatchAROS
20 * Send a ^C to the SetPatchAROS to unload it.
23 #define MINSTACK 8192
25 #include <aros/asmcall.h>
26 #include <dos/stdio.h>
28 #include <proto/alib.h>
29 #include <proto/utility.h>
30 #include <proto/exec.h>
31 #include <proto/dos.h>
33 #include <exec/rawfmt.h>
35 #include <loadseg.h>
37 /************* ExecBase Patches ********************/
39 static APTR oldRawDoFmt;
40 static AROS_UFH5(APTR, myRawDoFmt,
41 AROS_UFHA(CONST_STRPTR, fmt, A0),
42 AROS_UFHA(APTR, args, A1),
43 AROS_UFHA(VOID_FUNC, putch, A2),
44 AROS_UFHA(APTR, putptr, A3),
45 AROS_UFHA(struct ExecBase *, SysBase, A6))
47 AROS_USERFUNC_INIT
49 /* moveb %d0, %a3@+
50 * rts
52 const ULONG m68k_string = 0x16c04e75;
53 /* addql #1, %a3@
54 * rts
56 const ULONG m68k_count = 0x52934e75;
57 /* jmp %a6@(-86 * 6)
59 const ULONG m68k_serial = 0x4eeefdfc;
61 switch ((IPTR)putch) {
62 case (IPTR)RAWFMTFUNC_STRING:
63 putch = (VOID_FUNC)&m68k_string;
64 break;
65 case (IPTR)RAWFMTFUNC_COUNT:
66 putch = (VOID_FUNC)&m68k_count;
67 break;
68 case (IPTR)RAWFMTFUNC_SERIAL:
69 putch = (VOID_FUNC)&m68k_serial;
70 break;
71 default:
72 break;
75 return AROS_UFC5(APTR, oldRawDoFmt,
76 AROS_UFCA(CONST_STRPTR, fmt, A0),
77 AROS_UFCA(APTR, args, A1),
78 AROS_UFCA(VOID_FUNC, putch, A2),
79 AROS_UFCA(APTR, putptr, A3),
80 AROS_UFCA(struct ExecBase *, SysBase, A6));
82 AROS_USERFUNC_EXIT
85 /************* DosLibrary Patches ******************/
87 #define PROTO_KERNEL_H /* Don't pick up AROS kernel hooks */
89 /* Really stupid way to deal with this,
90 * but what we're going to do is make our
91 * patches, and wait for a ^C.
93 * When we get a ^C, unpatch ourselves from
94 * Dos/LoadSeg(), and exit.
96 * To use:
98 * > Run SetPatchAROS
100 int main(int argc, char **argv)
102 APTR DOSBase;
104 DOSBase = OpenLibrary("dos.library", 0);
105 if (DOSBase != NULL) {
106 struct Library *sbl = (APTR)SysBase;
107 if (sbl->lib_Version > 40) {
108 FPrintf(Output(), "SetPatchAROS: Unsupported exec.library %ld.%ld\n",
109 sbl->lib_Version, sbl->lib_Revision);
110 CloseLibrary((APTR)DOSBase);
111 return RETURN_ERROR;
114 Disable();
115 oldRawDoFmt = SetFunction((struct Library *)SysBase, -87 * LIB_VECTSIZE, myRawDoFmt);
116 Enable();
118 PutStr("AROS Support active. Press ^C to unload.\n");
119 Wait(SIGBREAKF_CTRL_C);
121 Disable();
122 SetFunction((struct Library *)SysBase, -87 * LIB_VECTSIZE, oldRawDoFmt);
123 Enable();
125 PutStr("AROS Support unloaded.\n");
126 CloseLibrary(DOSBase);
129 return RETURN_OK;