1.1 --- a/stage2/cpu.c Sat Feb 27 23:41:17 2016 +0100
1.2 +++ b/stage2/cpu.c Sun Feb 28 01:18:09 2016 +0100
1.3 @@ -125,41 +125,22 @@
1.4 );
1.5 }
1.6
1.7 -void init_stack(u32 top, u32 got, void (*function)(), u32 args[], u8 nargs)
1.8 +void init_registers(u32 *base, u32 got, void (*function)(), u32 args[], u8 nargs)
1.9 {
1.10 u8 i;
1.11
1.12 - asm volatile(
1.13 - "move $t3, %0\n" /* refer to the stack frame */
1.14 - "addi $t3, $t3, -16\n" /* refer to the first parameter */
1.15 - :
1.16 - : "r" (top)
1.17 - );
1.18 -
1.19 /* Provide arguments to the function. */
1.20
1.21 for (i = 0; i < nargs; i++)
1.22 {
1.23 - asm volatile(
1.24 - "sw %0, 0($t3)\n"
1.25 - "addi $t3, $t3, -4\n"
1.26 - :
1.27 - : "r" (args[i])
1.28 - );
1.29 + base[i+4] = args[i];
1.30 }
1.31
1.32 /* Store essential data for the function environment. */
1.33
1.34 - asm volatile(
1.35 - "subu %1, %1, 0x80000000\n" /* obtain user mode addresses */
1.36 - "subu %2, %2, 0x80000000\n"
1.37 - "sw %2, -100(%0)\n" /* store the function address as t9 */
1.38 - "sw %1, -104(%0)\n" /* store the global pointer */
1.39 - "sw %2, -112(%0)\n" /* store the function address as ra (for invoke_task) */
1.40 - "sw %2, -116(%0)\n" /* store the function address as EPC (for the handler) */
1.41 - :
1.42 - : "r" (top), "r" (got), "r" (function)
1.43 - );
1.44 + base[25] = (u32) function - 0x80000000; /* store the function address as t9 */
1.45 + base[26] = got - 0x80000000; /* store the global pointer */
1.46 + base[29] = (u32) function - 0x80000000; /* store the function address as EPC (for the handler) */
1.47 }
1.48
1.49 void enter_user_mode(void)
1.50 @@ -174,14 +155,18 @@
1.51
1.52 void init_tlb(void)
1.53 {
1.54 - /* Wire in the kseg0 mapping and the page tables. */
1.55 + unsigned short first_random = 0;
1.56
1.57 asm volatile(
1.58 - "li $t1, 1\n" /* index of first randomly-replaced entry */
1.59 - "mtc0 $t1, $6\n" /* CP0_WIRED */
1.60 "mtc0 $zero, $4\n" /* CP0_CONTEXT */
1.61 "mtc0 $zero, $10\n" /* CP0_ENTRYHI */
1.62 - "nop\n");
1.63 + "mtc0 $zero, $2\n" /* CP0_ENTRYLO0 */
1.64 + "mtc0 $zero, $3\n" /* CP0_ENTRYLO1 */
1.65 + "mtc0 %0, $6\n" /* CP0_WIRED */
1.66 + "nop"
1.67 + :
1.68 + : "r" (first_random)
1.69 + );
1.70 }
1.71
1.72 void map_page_index(u32 virtual, u32 physical, u32 pagesize, u8 flags, u8 asid, u32 index)