1/*
2 * Copyright 2008-2010, François Revol, revol@free.fr. 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
8#define FUNCTION(x) .global x; .type x,@function; x
9
10/*
11 * stage1 boot code for TOS for use as boot block of HDD partitions.
12 * cf.
13 * http://www.fortunecity.com/skyscraper/apple/308/html/chap3.htm
14 * http://leonard.oxg.free.fr/articles/multi_atari/multi_atari.html
15 * http://alive.atari.org/alive10/btmania.php
16 * AHDI boot args:
17 * http://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/arch/atari/stand/xxboot/ahdi-xxboot/xxboot.ahdi.S
18 * gas stuff:
19 * http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_chapter/as_18.html#SEC214
20 *
21 * x86:
22 * The offset of the partition in 512 byte blocks must be written at
23 * position PARTITION_OFFSET_OFFSET (32 bit little endian; makebootable does
24 * that) or otherwise the code can't find the partition.
25 * The partition must be a BFS formatted. The file "system/haiku_loader"
26 * (the stage 2 boot loader) loaded into memory at 0x1000:0x0000 (linear address
27 * 0x10000) and entered at 0x:1000:0x0200 with parameters eax - partition offset
28 * in 512 byte blocks and dl - BIOS ID of the boot drive.
29 *
30 * Compile via:
31 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-gcc -nostdlib -fpic -c -o stage1.o src/system/boot/platform/atari_m68k/stage1.S
32 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-objcopy -O binary stage1.o stage1
33 *
34 * Add to image:
35 * dd conv=notrunc if=haiku/trunk/stage1 of=em-20-200.swapped.hd bs=1 count=30
36 * set bootable:
37 * XXX: that's wrong! echo -en '\x12\x34' | dd conv=notrunc seek=510 bs=1 count=2 of=em-20-200.swapped.hd
38 *
39 * .PRG file format:
40 * http://mail-index.netbsd.org/tech-userlevel/2007/04/02/0000.html
41 * http://pagesperso-orange.fr/patrice.mandin/en/howto-binutils.html
42 * http://www.wotsit.org/download.asp?f=atariexe&sc=252874182
43 *
44 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-gcc -nostdlib -fpic -Wa,--pcrel -c -o stage1.o src/system/boot/platform/atari_m68k/stage1.S
45 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-ld -o stage1.prg stage1.o -T src/system/boot/platform/atari_m68k/prg.ld
46 *
47 */
48
49#include "toscalls.h"
50
51// 1 enabled verbose output
52//#define DEBUG 1
53
54
55#define	BOOT_BLOCK_START_ADDRESS	0x7c00
56#define	STACK_ADDRESS				BOOT_BLOCK_START_ADDRESS
57#define	READ_BUFFER_STACK			STACK_ADDRESS - 0x2000
58#define	PARTITION_OFFSET_OFFSET		506
59#define	BFS_SUPERBLOCK_OFFSET		512
60
61
62// BFS definitions
63
64#define SUPER_BLOCK_MAGIC1			'1SFB'		; nasm reverses '...' consts
65#define SUPER_BLOCK_MAGIC2			0xdd121031
66#define SUPER_BLOCK_MAGIC3			0x15b6830e
67
68#define	INODE_MAGIC1				0x3bbe0ad9
69
70#define	NUM_DIRECT_BLOCKS			12
71
72#define	S_IFMT						00000170000o
73#define	S_IFDIR						00000040000o
74
75
76// NOTE: normal programs (.prg) run as user mode,
77// while boot sector is chained in supervisor mode.
78// this means using Super(SUP_INQUIRE) we can know
79// from the same entry point if we were run from boot code or prg.
80
81
82	//Pterm0
83	//move.w	#1,%d0
84	//trap	#1
85	//rts
86
87	lea.l	str,%a0
88.loopt:
89	move.b	(%a0)+,%d0
90	beq	.strout
91	bsr	putc
92	bra	.loopt
93.strout:
94	//Pterm0
95	move.w	#1,%d0
96	trap	#1
97
98	rts
99
100.loop:
101	move	#'.',%d0
102	bsr		putc
103	bra		.loop
104	rts
105
106/* prints the char in d0.b to the console */
107putc:
108	movem.l	%a0,-(%sp)
109	move.w	%d0,-(%sp)
110	move.w	#DEV_CON,-(%sp)	// DEV_CON
111	move.w	#3,-(%sp)	// Bconout
112	trap	#13
113	add.l	#6,%sp
114	movem.l	(%sp)+,%a0
115	rts
116str:
117	.ascii "Haiku!"
118	.byte 0
119