/* * 2007+ Copyright (c) Evgeniy Polyakov * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ .global start start: /* Get base pointer, to be position independent */ mova next, r0 mov #0x02, r1 shll8 r1 sub r1, r0 mov r0, r12 ! Base pointer mov #0x10, r1 shll8 r1 mov r12, r15 add r1, r15 ! Setup stack pointer /* Enable cache */ mov #6, r0 ! Cache "on" mov #0, r4 trapa #0x3f /* Output message */ mova message, r0 mov r0, r4 mov #18, r5 mov #0, r0 ! Serial Output trapa #0x3f nop mov #0x10, r13 shll8 r13 add r12, r13 mov r13, r6 ! destination address mov #1, r5 ! source address mov #1, r7 ! number of sectors per read shll8 r7 ! each step is 2^8 sectors mov r7, r10 mov #9, r0 shad r0, r10 ! number of bytes each step takes ! equals to number of segments * segment size mov #9, r8 ! number of above steps ! ~1 Mb in 512 byte sectors sectors mov #1, r1 read_sector: mov #2, r0 ! READ SECTORS mov #0, r4 ! device number (?) trapa #0x3f tst r0, r0 bf read_sector_error add r7, r5 add r10, r6 sub r1, r8 tst r8, r8 bf read_sector bra checksum nop read_sector_error: mov r0, r10 ! Error mova message_err, r0 mov r0, r4 mov #6, r5 mov #0, r0 ! Serial Output trapa #0x3f bsr print_32 mov r10, r5 bra final_loop checksum: mov #18, r1 ! number of iterations shll16 r1 mov #2, r1 shll16 r1 mov r13, r2 ! initial address mov #4, r6 ! step xor r5, r5 ! checksum l: mov.l @r2+, r4 xor r4, r5 sub r6, r1 tst r1, r1 bf l bsr print_32 nop second_loader: mova message_ret, r0 mov r0, r4 mov #25, r5 mov #0, r0 ! Serial Output trapa #0x3f mov #6, r0 ! Cache "on" mov #0, r4 trapa #0x3f mov r13, r0 jmp @r0 nop final_loop: nop bra final_loop ! Clobbers everything, use only for deubg. ! r5 contains 32 bit value to display print_32: mov #8, r6 ! max mov #1, r2 ! step mov r5, r3 ! checksum mov #-4, r10 ! bits to shift pl: mov r3, r0 and #0xf, r0 mov r0, r11 mova hex, r0 mov r0, r4 add r11, r4 mov #0, r0 mov #1, r5 trapa #0x3f shad r10, r3 sub r2, r6 tst r6, r6 bf pl rts nop .align 2 message: .string "Starting from MBR\n" .align 2 message_ret: .string "\nJumping to second stage\n" .align 2 message_err: .string "Error\n" .align 2 hex: .string "0123456789abcdef" next: