1/* 2 * Copyright 2009, François Revol, revol@free.fr. 3 */ 4 5#define FUNCTION(x) .global x; .type x,@function; x 6 7/* 8 * stage1 boot code for AmigaDOS for use as boot block of HDD partitions. 9 * 10 * cf. 11 * http://wandel.ca/homepage/execdis/virus_disassembly.txt 12 * http://ciarang.com/wiki/page/Minimal_Amiga_Boot_Code 13 * 14 * x86: 15 * The offset of the partition in 512 byte blocks must be written at 16 * position PARTITION_OFFSET_OFFSET (32 bit little endian; makebootable does 17 * that) or otherwise the code can't find the partition. 18 * The partition must be a BFS formatted. The file "system/haiku_loader" 19 * (the stage 2 boot loader) loaded into memory at 0x1000:0x0000 (linear address 20 * 0x10000) and entered at 0x:1000:0x0200 with parameters eax - partition offset 21 * in 512 byte blocks and dl - BIOS ID of the boot drive. 22 * 23 * Compile via: 24 * 25 * jam -q '<build>fixup_amiga_boot_checksum' 26 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-gcc -nostdlib -fpic -Wa,--pcrel -c -o stage1.o src/system/boot/platform/amiga_m68k/stage1.S 27 * generated-m68k/cross-tools/bin/m68k-unknown-haiku-ld --oformat binary -o stage1.bin stage1.o 28 * generated-m68k/objects/linux/x86/release/tools/fixup_amiga_boot_checksum/fixup_amiga_boot_checksum stage1.bin 29 * generated.m68k/cross-tools/bin/m68k-unknown-haiku-ld -o stage1.prg stage1.o -T src/system/boot/platform/atari_m68k/prg.ld 30 * 31 * Add to image: 32 * dd if=/dev/zero bs=512 count=$((80*2*11)) of=df0.adf 33 * dd if=stage1.bin bs=512 conv=notrunc of=df0.adf 34 * 35 */ 36 37 38// 1 enabled verbose output 39//#define DEBUG 1 40 41 42#define BOOT_BLOCK_START_ADDRESS 0x7c00 43#define STACK_ADDRESS BOOT_BLOCK_START_ADDRESS 44#define READ_BUFFER_STACK STACK_ADDRESS - 0x2000 45#define PARTITION_OFFSET_OFFSET 506 46#define BFS_SUPERBLOCK_OFFSET 512 47 48 49// BFS definitions 50 51#define SUPER_BLOCK_MAGIC1 '1SFB' ; nasm reverses '...' consts 52#define SUPER_BLOCK_MAGIC2 0xdd121031 53#define SUPER_BLOCK_MAGIC3 0x15b6830e 54 55#define INODE_MAGIC1 0x3bbe0ad9 56 57#define NUM_DIRECT_BLOCKS 12 58 59#define S_IFMT 00000170000o 60#define S_IFDIR 00000040000o 61 62// AmigaDOS calls 63// exec.library 64#define _Supervisor -0x1e 65#define _FindResident -0x60 66#define _Alert -0x6c 67#define _SuperState -0x96 68#define _UserState -0x9c 69#define _OldOpenLibrary -0x198 70#define _CloseLibrary -0x19e 71// dos.library 72#define Old_mode 1005 73#define New_mode 1006 74#define _Open -0x1e 75#define _Close -0x24 76#define _Read -0x2a 77#define _Write -0x30 78#define _Input -0x36 79#define _Output -0x3c 80#define _IoErr -0x84 81#define _Delay -0xc6 82// intuition.library 83#define _DisplayAlert -90 84 85 86_floppy_entry: 87 .ascii "DOS" 88// .ascii "BFS" 89 .byte 0 90_floppy_checksum: 91 .long 0 92_floppy_osversion: // ?? 93//_super_stack: // also used as a variable in the code 94 //.long 0x370 95 .long 0x09D5A859 // dos private ??? 96 97_floppy_boot: 98 99 // we get an open IO request in A1 100 101 // seems like a6 is already set to ExecBase when called from the ROM ? 102 // copy it 103 move.l 4.w,%a6 104 lea _execbase(%pc),%a2 105 move.l %a6,(%a2) 106 107// jsr _SuperState(%a6) 108// move.l %d0,_super_stack 109 110 111 112// bra _continue 113 114/* 115 move.l %d0,%a6 116 117 lea window_name(%pc),%a0 118 move.l %a0,%d1 119 move.l #Old_mode,%d2 120 jsr _Open(%a6) 121 tst.l %d0 122 beq.s _floppy_err 123_loop_1: 124 bra _loop_1 125 126 127_loop_2: 128 bra _loop_2 129*/ 130 131 //lea _display_alert,%a5 132 //jsr _Supervisor(%a6) 133 134 jsr _display_alert 135 136 137 bra _floppy_err 138 139 140// lea dosname_boot(%pc),%a1 141//// jsr -0x60(%a6) // FindResident() 142// move.l 4.w,%a6 143// jsr -96(%a6) 144 145 146 tst.l %d0 147 beq.s _floppy_err 148 149 150 151_continue: 152 move.l 4.w,%a6 153 154 155 lea dosname_boot(%pc),%a1 156 jsr _FindResident(%a6) 157 lea _dosbase(%pc),%a2 158 tst.l %d0 159 beq.s _floppy_err 160 move.l %d0,(%a2) 161 162// move.l _super_stack,%d0 163// jsr _UserState(%a6) 164 165 move.l _dosbase,%a0 166 move.l 0x16(%a0),%a0 167 168 moveq #0,%d0 169 170 rts 171 172_floppy_err: 173// move.l 4.w,%a6 174// move.l _super_stack,%d0 175// jsr _UserState(%a6) 176 177 moveq #-1,%d0 178 rts 179 180_display_alert: 181 move.l 4.w,%a6 182 lea intname_boot(%pc),%a1 183 jsr _OldOpenLibrary(%a6) 184 tst.l %d0 185 beq.s _floppy_err 186 lea _intbase(%pc),%a2 187 move.l %d0,(%a2) 188 move.l %d0,%a6 189 190 lea alert_data(%pc),%a0 191 moveq #0,%d0 192 move.l #30,%d1 193 jsr _DisplayAlert(%a6) 194 rts 195 196dosname_boot: 197 .ascii "dos.library" 198 .byte 0 199 200intname_boot: 201 .ascii "intuition.library" 202 .byte 0 203 204alert_data: 205 .word 10 206 .byte 12 207 .ascii "Welcome to Haiku\0" 208alert_extra: 209 .ascii "\0\0" 210 .byte 0 211 212window_name: 213 .ascii "CON:0/0/640/255/plop\0" 214 215_execbase: 216 .long 0 217_dosbase: 218 .long 0 219_intbase: 220 .long 0 221 222end_buff: 223// equ *-_floppy_entry 224 .dcb.b (1024)-(end_buff-_floppy_entry),0 225 226