-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathpanicasm.S
140 lines (131 loc) · 4.07 KB
/
panicasm.S
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* panicasm.S - support routines for panic debug messages
*
* Copyright (C) 2001-2022 The EmuTOS development team
*
* Authors:
* LVL Laurent Vogel
*
* This file is distributed under the GPL, version 2 or at your
* option any later version. See doc/license.txt for details.
*/
#include "asmdefs.h"
.text
.extern _proc_dregs
.extern _proc_usp
.extern _proc_enum
.extern _proc_stk
.extern _proc_lives
.extern _dopanic
.extern _flush_data_cache
.extern _main
.extern resvalid
.extern resvector
.extern memvalid
.extern _warm_magic
.globl _panic
.globl _halt
.globl _kill_program
.globl _warm_reset
.globl _cold_reset
/*
* void panic(const char *fmt, ...);
* save the registers, state and stack in 0x380, then
* print the message on the console, and finally halt.
* note: the stack dump will contain the attributes.
* the exception number proc_enum will be zero.
*/
_panic:
// supervisor mode, no interrupts
move.w #0x2700,sr
// dump the registers including USP
#ifdef __mcoldfire__
move.l a0,(_proc_dregs+32).w
lea _proc_dregs.w,a0
movem.l d0-d7,(a0)
movem.l a1-a7,36(a0)
#else
movem.l d0-d7/a0-a7,_proc_dregs.w
#endif
move.l usp,a0
move.l a0,_proc_usp.w
// tell dopanic() that there are arguments following
clr.l _proc_enum.w
// dump 16 words from the stack
movem.l (sp),d0-d7
#ifdef __mcoldfire__
lea _proc_stk.w,a0
movem.l d0-d7,(a0)
// magic value
lea _proc_lives.w,a0
move.l #0x12345678,(a0)
#else
movem.l d0-d7,_proc_stk.w
// magic value
move.l #0x12345678,_proc_lives.w
#endif
// at this time, we have not altered the stack, so we can jump to the
// C routine directly in kprint.c
jmp _dopanic
/* void halt(void)
* simply halt the machine.
*/
_halt:
#if !USE_STOP_INSN_TO_FREE_HOST_CPU
// disable the interrupts
move.w #0x2700,sr
#endif
haltloop:
// endless loop
#if USE_STOP_INSN_TO_FREE_HOST_CPU
stop #0x2700
// only an NMI could theoretically wake up the CPU here
#endif
jra haltloop
/* void kill_program(void)
* try to terminate via Pterm(); if Pterm() returns here (!),
* we do a warm reset
*/
_kill_program:
move.w #-1,-(sp) // error code for program killed by OS
move.w #0x4C,-(sp) // Pterm
trap #1
// fall through _warm_reset (should not happen!)
/* void warm_reset(void)
* Restart this OS
*/
_warm_reset:
jsr _flush_data_cache
jmp _main
/* void cold_reset(void)
* Invalidate the RAM configuration and reset the computer to the ROM OS.
* It is important to flush the data cache so the values of the magic variables
* are really pushed to the RAM. Next OS may use different cache settings.
*/
_cold_reset:
clr.l resvalid.w // Don't allow jump to reset vector in startup.S
clr.l resvector.w
#if CONF_DETECT_FIRST_BOOT_WITHOUT_MEMCONF
clr.l _warm_magic.w // Next boot will be a first boot
#endif
#ifdef MACHINE_AMIGA
clr.l memvalid.w // Invalidate memvalid
jsr _flush_data_cache
move.l 0x00fc0004,a0 // Get the entry adress from offset 4 in the ROM
reset // The entry usually points just after reset
jmp (a0)
#elif defined(MACHINE_FIREBEE)
// Do not invalidate memvalid, to keep the RAM settings
jsr _flush_data_cache
move.l 0x00e00004,a0 // Get the entry adress from offset 4 in the ROM
jmp (a0)
#elif CONF_ATARI_HARDWARE
clr.l memvalid.w // Invalidate memvalid
jsr _flush_data_cache
move.l 0x004,a0 // The 2 first longs are mapped to the ROM
jmp (a0)
#else
jsr _flush_data_cache
// We don't know how to cold reset, so just warm reset this OS
jmp _main
#endif