2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: m68k-amiga bootstrap to exec.
9 #include <aros/kernel.h>
10 #include <exec/resident.h>
11 #include <exec/execbase.h>
12 #include <exec/memory.h>
14 #include "exec_intern.h"
15 #include "kernel_romtags.h"
19 extern const struct Resident Exec_resident
;
21 extern void __clear_bss(const struct KernelBSS
*bss
);
23 /** Screen/Serial Debug **/
25 #define SERPER_BASE_PAL 3546895
26 #define SERPER_BASE_NTSC 3579545
28 #define SERPER_BAUD(base, x) (((base)/(x)-1) & 0x7fff) /* Baud rate */
30 #define SERDATR_OVRUN (1 << 15) /* Overrun */
31 #define SERDATR_RBF (1 << 14) /* Rx Buffer Full */
32 #define SERDATR_TBE (1 << 13) /* Tx Buffer Empty */
33 #define SERDATR_TSRE (1 << 12) /* Tx Shift Empty */
34 #define SERDATR_RXD (1 << 11) /* Rx Pin */
35 #define SERDATR_STP9 (1 << 9) /* Stop bit (if 9 data) */
36 #define SERDATR_STP8 (1 << 8) /* Stop bit (if 8 data) */
37 #define SERDATR_DB9_of(x) ((x) & 0x1ff) /* 9-bit data */
38 #define SERDATR_DB8_of(x) ((x) & 0xff) /* 8-bit data */
40 #define ADKCON_SETCLR (1 << 15)
41 #define ADKCON_UARTBRK (1 << 11) /* Force break */
43 #define SERDAT_STP9 (1 << 9)
44 #define SERDAT_STP8 (1 << 8)
45 #define SERDAT_DB9(x) ((x) & 0x1ff)
46 #define SERDAT_DB8(x) ((x) & 0xff)
52 static inline void reg_w(ULONG reg
, UWORD val
)
54 volatile UWORD
*r
= (void *)(0xdff000 + reg
);
59 static inline UWORD
reg_r(ULONG reg
)
61 volatile UWORD
*r
= (void *)(0xdff000 + reg
);
66 #define RGB(r,g,b) ((((r) & 0xf) << 8) | (((g) & 0xf) << 4) | (((b) & 0xf) << 0))
68 #define CODE_ROM_CHECK RGB( 4, 4, 4)
69 #define CODE_RAM_CHECK RGB( 9, 9, 9)
70 #define CODE_EXEC_CHECK RGB( 9, 0, 9)
71 #define CODE_TRAP_FAIL RGB(12, 12, 0)
73 static void Exec_ScreenCode(UWORD code
)
75 reg_w(BPLCON0
, 0x0200);
76 reg_w(BPL1DAT
, 0x0000);
82 /* Set the debug UART to 9600 */
83 reg_w(SERPER
, SERPER_BAUD(SERPER_BASE_PAL
, 9600));
86 int DebugPutChar(register int chr
)
88 while ((reg_r(SERDATR
) & SERDATR_TBE
) == 0);
90 /* Output a char to the debug UART */
91 reg_w(SERDAT
, SERDAT_STP8
| SERDAT_DB8(chr
));
96 int DebugGetChar(void)
98 while ((reg_r(SERDATR
) & SERDATR_RBF
) == 0);
100 return SERDATR_DB8_of(reg_r(SERDATR
));
105 #include "m68k-gdbstub.c"
108 static __attribute__((interrupt
)) void Exec_FatalException(void)
112 Exec_ScreenCode(CODE_TRAP_FAIL
);
114 /* FIXME: Idle loop delay
115 * We should really wait for a number of
116 * verical retrace intervals
118 for (i
= 0; i
< 150000; i
++);
120 /* Reset everything but the CPU, then restart
121 * at the ROM exception vector
128 static void DebugPuts(register const char *buff
)
130 for (; *buff
!= 0; buff
++)
134 #define MEM_START 0x00040000
135 #define MEM_SIZE 0x001c0000
137 struct MemHeader ChipRAM
;
139 void DebugPutHex(const char *what
, ULONG val
)
144 for (i
= 0; i
< 8; i
++) {
145 DebugPutChar("0123456789abcdef"[(val
>> (28 - (i
* 4))) & 0xf]);
150 extern void __attribute__((interrupt
)) Exec_Supervisor_Trap (void);
155 extern void *_bss_end
;
157 extern void *_stack_end
;
160 UWORD
*kickrom
[4] = {
166 const struct KernelBSS kbss
[2] = {
169 .len
= &_bss_end
- &_bss
,
176 struct ExecBase
*sysBase
;
178 struct MemHeader
*mh
= &ChipRAM
;
180 *((APTR
*)(NULL
+ 0x4)) = NULL
;
182 /* Set the world know we exist
185 DebugPuts("[reset]\n");
187 /* Fill exception table with a stub that will
190 tmp
= (APTR
*)(NULL
+ 0x8);
191 for (i
= 0; i
< 46; i
++)
192 tmp
[i
] = Exec_FatalException
;
194 /* Set privilige violation trap - we
195 * need this to support the Exec/Supervisor call
197 tmp
[8] = Exec_Supervisor_Trap
;
200 __clear_bss(&kbss
[0]);
201 DebugPuts("[bss clear]\n");
204 /* Must be after the BSS clear! */
208 Exec_ScreenCode(CODE_RAM_CHECK
);
210 DebugPuts("[prep SysBase]\n");
211 Exec_ScreenCode(CODE_EXEC_CHECK
);
212 mc
= (struct MemChunk
*)(NULL
+ MEM_START
);
214 mc
->mc_Bytes
= MEM_SIZE
;
216 mh
->mh_Node
.ln_Succ
= NULL
;
217 mh
->mh_Node
.ln_Pred
= NULL
;
218 mh
->mh_Node
.ln_Type
= NT_MEMORY
;
219 mh
->mh_Node
.ln_Name
= "chip memory";
220 mh
->mh_Node
.ln_Pri
= -5;
221 mh
->mh_Attributes
= MEMF_CHIP
| MEMF_PUBLIC
| MEMF_LOCAL
| MEMF_24BITDMA
| MEMF_KICK
;
223 mh
->mh_Lower
= (APTR
)mc
;
224 mh
->mh_Upper
= ((APTR
)mc
) + mc
->mc_Bytes
;
225 mh
->mh_Free
= mc
->mc_Bytes
;
226 sysBase
= PrepareExecBase(mh
, NULL
, NULL
);
227 DebugPutHex("PrepareExecBase [ret]",(ULONG
)sysBase
);
228 *((APTR
*)(NULL
+ 0x4)) = sysBase
;
229 DebugPuts("[init SysBase]\n");
231 sysBase
->SysStkUpper
= (APTR
)&_stack_end
-1;
232 sysBase
->SysStkLower
= (APTR
)&_stack
;
233 sysBase
->ChkBase
=~(ULONG
)sysBase
;
235 /* Scan for all other ROM Tags */
236 sysBase
->ResModules
= krnRomTagScanner(sysBase
, kickrom
);
237 DebugPuts("[start] InitCode(RTF_SINGLETASK, 0)\n");
238 InitCode(RTF_SINGLETASK
, 0);
240 /* We shouldn't get here */
241 DebugPuts("[DOS Task failed to start]\n");