/* nspirelinuxloader - A in-place Linux bootloader for TI-Nspire calculator Copyright (C) 2011 Daniel Tang 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 3 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. You should have received a copy of the GNU General Public License along with this program. If not, see . */ .global _start _start: /* r0 contains pointer to structure for kernel r1 contains pointer to structure for params */ mov r7, r1 /* First, get the information from the structures before we do anything since we cant trust the memory after our destructive memcpys*/ bl getDataFromStruct /* kernel */ mov r4, r0 /* ksrc */ mov r5, r1 /* kdest (also our kernel address) */ mov r6, r2 /* ksize */ mov r0, r7 bl getDataFromStruct /* params */ mov r7, r1 /* parameter address */ bl memcpy /* copy parameters */ mov r0, r4 mov r1, r5 mov r2, r6 bl memcpy /* copy kernel */ /* Finally, boot the kernel */ mov r0, #0 /* Always zero */ mov r1, #21 /* 21 is our machine number? */ mov r2, r7 /* Address of the parameter list */ mcr p15, 0, r12, c7, c7, 0 /*Flush data cache*/ ldr r12, =0x0005107A mcr p15, 0, r12, c1, c0, 0 /*Reset c1 contents (disable MMU and some other cool stuff)*/ mov r15, r5 /* Jump to kernel and never return*/ panic: b panic memcpy: /* r0 = src r1 = dest r2 = size */ ldrb r3, [r0, #0] strb r3, [r1, #0] add r0, r0, #1 add r1, r1, #1 sub r2, r2, #1 cmp r2, #0 bne memcpy mov pc,lr getDataFromStruct: /* r0 = addr returns: r0 = src r1 = dest r2 = size This quick hack works because 3 x 32bit ints fit perfectly in a struct with no padding at all (tested with gcc 4.5.3) */ mov r3, r0 ldr r0, [r3, #0] ldr r1, [r3, #4] ldr r2, [r3, #8] mov pc,lr