xref: /haiku/src/system/boot/platform/atari_m68k/shell.S (revision 93861ead3ee93e79e9f60c09555159aee4ab0299)
1/*
2 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
4 * Copyright 2007, Haiku, Inc. All Rights Reserved.
5 * Distributed under the terms of the MIT license.
6 *
7 * Author:
8 *		François Revol, revol@free.fr.
9 */
10
11/**	This file contains the boot floppy and BFS boot block entry points for
12 *	the stage 2 boot loader.
13 * x86 ahead:
14 *	The floppy entry point is at offset 0. It's loaded at 0x07c0:0x000. It
15 *	will load the rest of the loader to 0x1000:0x0200 and execute it.
16 *	The BFS boot block will load the whole stage 2 loader to 0x1000:0x0000
17 *	and will then jump to 0x1000:0x0200 as its entry point.
18 *	This code will then switch to protected mode and will directly call
19 *	the entry function of the embedded ELF part of the loader.
20 */
21
22/*
23 * generate boot floppy:
24 * cd src/system/boot/platform/atari_m68k/ ; make fixup_tos_floppy_chksum; cd -
25 * dd if=generated/objects/haiku/m68k/release/system/boot/zbeos of=~/floppy.img bs=512 count=20 conv=notrunc
26 * src/system/boot/platform/atari_m68k/fixup_tos_floppy_chksum ~/floppy.img
27 * generate .prg:
28 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-ld -o haiku.prg -T src/system/ldscripts/m68k/boot_prg_atari_m68k.ld generated/objects/haiku/m68k/release/system/boot/boot_loader_atari_m68k
29 */
30
31#include "atari_memory_map.h"
32#include "toscalls.h"
33
34// 1 enabled verbose output
35//#define DEBUG 1
36
37#define GLOBAL(x) .globl x ; x
38#define FUNCTION(x) .global x; .type x,@function; x
39
40#define DRIVE_RETRIES 3
41	// when the drive reading fails for some reason, it will
42	// retry this many times until it will report a failure
43
44//.text
45_bs_entry:
46/* main entry point, both from the floppy boot and .prg */
47	bra.s	real_entry
48
49//FAT lookalike to avoid nasty things from happening
50// http://alive.atari.org/alive10/btmania.php
51	.ascii	"Haiku0"
52	.byte	0xbe, 0x50, 0x38 // id
53	//LE
54	.byte	0x00, 0x02	//BPS
55	.byte	0x02		//SPC
56	//.byte	0x00		//???
57	.byte	0x00, 0x02	//RES - number of reserved sectors
58	.byte	0x00//0x02	//NFATS
59	.byte	0x00/*70*/, 0x00	//NDIRS
60	.byte	0xa0, 0x05		//NSECTS
61	.byte	0xf9			//MEDIA
62	.byte	0x05, 0x00		//SPF
63	.byte	0x09, 0x00		//SPT
64	.byte	0x02, 0x00		//NSIDES
65	.byte	0x00, 0x00		//NHID
66	// we're done
67
68sNumSectors:
69	// this location will contain the length of the boot loader as
70	// written by the "makeflop" command in 512 byte blocks
71	// 0x180 is the allowed maximum, as the zipped TAR with the
72	// kernel and the boot module might start at offset 192 kB
73	.word	0x0300 //0x0180
74
75real_entry:
76
77#if 0
78	lea		h1,%a0
79	bsr		puts
80	move.l		#0x1234aa55,%d0
81	bsr		putx
82#endif
83
84
85	// first, determine if .prg (user) or bootsect (super)
86	// Super()
87	move.l		#SUP_INQUIRE,-(%sp)
88	move.w		#0x20,-(%sp)
89	trap		#1
90	addq.l		#6,%sp
91
92	bsr		putx
93
94	cmp.l		#SUP_USER,%d0
95	bne			floppy_start
96	lea		h2,%a0
97	bsr		puts
98
99	bra			prg_start
100	//bra			bootsect_start
101
102/*
103 * floppy boot support code
104 */
105
106floppy_start:
107	lea		h3,%a0
108	bsr		puts
109	lea		str,%a0
110	bsr		puts
111	//bra floppy_start
112
113	// no interrupt
114	or.w		#0x0700,%sr
115
116	//XXX: check for enough RAM
117
118	// load the rest
119	move.w		sNumSectors,%d2
120	// load at base + this code.
121	move.l		#(ATARI_ZBEOS_BASE+512),%a2
122	//move.l		%a2,%d0
123	//bsr putx
124	bsr			load_sectors
125	tst.w			%d0
126	beq			floppy_done
127	lea			failure_string,%a0
128	bsr			puts
129	bra			spin
130floppy_done:
131	lea		h4,%a0
132	bsr		puts
133	// setup stack
134	move.l		#ATARI_ZBEOS_STACK_END,%sp
135	lea		h5,%a0
136	bsr		puts
137	move.l		#0,%d0
138	//jmp			ATARI_ZBEOS_BASE+512
139	jmp		_start
140
141	//rts
142
143/**	Loads %d2 sectors from floppy disk, starting at head XXX %dh, sector %cx.
144 *	The data is loaded to %a2.
145 */
146
147load_sectors:
148
149#if 0
150	/* it seems to skip 9 every 9 sectors, buggy side handling ? */
151	// Rwabs
152	//move.l		#1,-(%sp)
153	move.w		#0,-(%sp)	// A:
154	//move.w		#2,-(%sp)	// C:
155	//move.w		#-1,-(%sp)	// 2nd sector
156	move.w		#1,-(%sp)	// 2nd sector
157	move.w		%d2,-(%sp)
158	move.l		%a2,-(%sp)
159	//move.w		#RW_READ+RW_NOTRANSLATE,-(%sp)
160	move.w		#RW_READ+RW_NOMEDIACH,-(%sp)
161	move.w		#4,-(%sp)
162	trap		#13
163	add.l		#14,%sp
164#endif
165#if 0
166	// d2:
167
168	//move.w		%d2,-(%sp)
169	move.w		#9,-(%sp)
170	move.w		#0,-(%sp)
171	move.w		#0,-(%sp)
172	move.w		#1,-(%sp)
173	move.w		#0,-(%sp)
174	move.l		#0,-(%sp)
175	//move.w		#0,-(%sp)
176	//move.l		%a2,-(%sp)
177	move.l		#ATARI_ZBEOS_BASE,-(%sp)
178	move.w		#8,-(%sp)	// floprd
179	trap		#XBIOS_TRAP
180	add.l		#20,%sp
181#endif
182
183	bsr	putx
184	rts
185
186floppy_end:
187//	.org	FAILURE_STRING
188failure_string:
189//	.string " Loading failed! Press key to reboot.\r\n"
190
191//	.org	DOT_STRING
192	.string	"."
193
194/*
195 * \AUTO\HAIKU.PRG and ARAnyM BOOTSTRAP() support code
196 */
197
198prg_start:
199	//lea		h4,%a0
200	//bsr		puts
201
202	// .prg:
203	// we need to switch to supervisor mode anyway
204	move.l		#SUP_SET,-(%sp)
205	move.w		#0x20,-(%sp)
206	trap		#1
207	addq.l		#6,%sp
208	move.l		%d0,saved_super_stack
209
210#if 1
211			//_membot
212	move.l		#0x432,%a0
213	move.l		(%a0),%d0
214	bsr		putx
215
216			//_memtop
217	move.l		#0x436,%a0
218	move.l		(%a0),%d0
219	bsr		putx
220
221			//_v_bas_ad
222	move.l		#0x44e,%a0
223	move.l		(%a0),%d0
224	bsr		putx
225#endif
226	// disable interrupts
227	//or.w		#0x0700,%sr
228
229	// setup stack
230	move.l		#ATARI_ZBEOS_STACK_END,%sp
231
232	lea		h5,%a0
233	bsr		puts
234	lea		_bs_entry,%a0
235	move.l		%a0,%d0
236	bsr		putx
237
238	// copy the rest of the prg
239
240	// load counter
241	clr.l		%d0
242	move.w		sNumSectors,%d0
243	sub.w		#1,%d0
244	// load addresses
245	lea		_bs_entry,%a0
246	move.l		#ATARI_ZBEOS_BASE,%a1
247
248
249nextsect:
250	move.l		#512/4-1,%d1
251copysect_loop:
252	move.l		(%a0)+,(%a1)+
253	dbf		%d1,copysect_loop
254	//bsr		putx
255	dbf		%d0,nextsect
256
257	lea		msg_j1,%a0
258	bsr		puts
259	// all done
260spin:
261	//bra			spin
262
263super_done:
264	// XXX: copy the rest !
265	move.l		#0,%d0
266	//jmp			ATARI_ZBEOS_BASE+512
267	jmp			_start
268
269saved_super_stack:
270	.long	0
271
272GLOBAL(gBootedFromImage):
273	.byte	0
274
275GLOBAL(gBootDriveID):
276	.byte	0
277
278GLOBAL(gBootPartitionOffset):
279	.long	0
280
281
282
283putx:
284	movem.l	%d0-%d2/%a0-%a2,-(%sp)
285	move.l	#8-1,%d2
286	move.l	%d0,%d1
287putxloop:
288	move.l	%d1,%d0
289	lsl.l	#4,%d1
290	//swap	%d0
291	//lsr.l	#8,%d0
292	//lsr.l	#4,%d0
293	rol.l	#4,%d0
294	and.l	#0x0f,%d0
295	cmp.b	#9,%d0
296	ble	putx0
297	add.b	#'a'-'0'-10,%d0
298	//bra	putxdisp
299putx0:
300	add.b	#'0',%d0
301putxdisp:
302	bsr	putc
303	dbf	%d2,putxloop
304	move.b	#'\r',%d0
305	bsr	putc
306	move.b	#'\n',%d0
307	bsr	putc
308	movem.l	(%sp)+,%d0-%d2/%a0-%a2
309	rts
310
311	lea.l	str,%a0
312puts:
313.loopt:
314	move.b	(%a0)+,%d0
315	beq	.strout
316	bsr	putc
317	bra	.loopt
318.strout:
319	move.b	#'\r',%d0
320	bsr	putc
321	move.b	#'\n',%d0
322	bsr	putc
323	rts
324
325.loop:
326	move	#'.',%d0
327	bsr		putc
328	bra		.loop
329	rts
330
331
332/* prints the char in d0.b to the console */
333putc:
334	movem.l	%d0-%d2/%a0-%a2,-(%sp)
335	move.w	%d0,-(%sp)
336	move.w	#DEV_CON,-(%sp)	// DEV_CON
337	move.w	#3,-(%sp)	// Bconout
338	trap	#13
339	add.l	#6,%sp
340	movem.l	(%sp)+,%d0-%d2/%a0-%a2
341	rts
342
343str:
344	.string "Haiku!"
345h1:
346	.string "H1"
347h2:
348	.string "H2"
349h3:
350	.string "H3"
351h4:
352	.string "H4"
353h5:
354	.string "H5"
355unimpl:
356	.string "Unimplemented."
357msg_j1:
358	.string "jumping to zbeos."
359
360
361shell_end:
362	//.fill	(0x01fe - shell_end), 1, 0x55
363	.org	0x01fe
364	.word	0xaa55-1	// will be replaced by the one calculated by the build.
365				// we make sure we PCs don't try to execute it.
366		// this bumps the "start" label to offset 0x0200 as
367		// expected by the BFS boot loader, and also marks
368		// this block as valid boot block for the BIOS
369		// XXX: actually TOS wants a real checksum here so sum is 0x1234!
370
371