-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.c
83 lines (68 loc) · 2.53 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
SEthernet and SEthernet/30 Driver
Copyright (C) 2023-2024 Richard Halkyard
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 MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "util.h"
#include <MacTypes.h>
#include <OSUtils.h>
#include <Timer.h>
#include <Traps.h>
#include "driver.h"
#if defined(DEBUG)
void DebugPrintf(const char * format, ...) {
static char strbuf[256];
va_list args;
va_start(args, format);
strbuf[0] = vsprintf(strbuf+1, format, args);
DebugStr((unsigned char *)strbuf);
}
#endif
/* Check whether a given trap is available. Adapted from IM: Devices listing
8-1 */
Boolean trapAvailable(const unsigned short trap) {
TrapType type;
/* First determine whether it is an OS or Toolbox routine */
if (trap & 0x800) {
type = OSTrap;
} else {
type = ToolTrap;
}
/* filter cases where older systems mask with 0x1ff rather than 0x3ff */
if (type == ToolTrap && (trap & 0x3ff) >= 0x200 &&
GetToolboxTrapAddress(0xa86e) == GetToolboxTrapAddress(0xaa6e)) {
return false;
} else {
return NGetTrapAddress(trap, type) != GetToolboxTrapAddress(_Unimplemented);
}
}
#if defined(DEBUG)
void debug_log(driverGlobals *theGlobals, unsigned short eventType,
unsigned short eventData) {
eventLog *log = &theGlobals->log;
/* Disable interrupts so that log operations are atomic */
unsigned short srSave;
asm("MOVE.W %%sr, %[srSave] \n\t"
"ORI.W %[srMaskInterrupts], %%sr \n\t"
: [srSave] "=dm"(srSave)
: [srMaskInterrupts] "i"(0x700));
log->entries[log->head].ticks = TickCount();
log->entries[log->head].eventType = eventType;
log->entries[log->head].eventData = eventData;
log->head = (log->head + 1) % LOG_LEN;
/* Make head of log buffer look distinctive so that we can spot it in a dump */
log->entries[log->head].ticks = 0xffffffff;
log->entries[log->head].eventType = 0xffff;
log->entries[log->head].eventData = 0xffff;
/* Restore processor state */
asm volatile("MOVE.W %[srSave], %%sr \n\t" : : [srSave] "dm"(srSave));
}
#endif