SHARE
TWEET

Untitled

a guest Jun 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (c) 2018 Atmosphère-NX
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify it
  5.  * under the terms and conditions of the GNU General Public License,
  6.  * version 2, as published by the Free Software Foundation.
  7.  *
  8.  * This program is distributed in the hope it will be useful, but WITHOUT
  9.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  11.  * more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  */
  16.  
  17. .section .text.start
  18. .align 4
  19.  
  20. .globl _start
  21.  
  22. _start:
  23.   b   reboot_to_rcm
  24.   adr r0, (restore_svc_vector+1)
  25.   mov lr, pc
  26.   bx r0
  27.   bl  usb_init
  28.   b   _crt0
  29.  
  30. .pool
  31.  
  32. .globl _crt0
  33. .type  _crt0,%function
  34.  
  35. reboot_to_rcm:
  36.     ldr r0, =0x7000E400
  37.     mov r1, #1
  38.     str r1, [r0, #0x50]
  39.     mov r1, #0x10
  40.     str r1, [r0]
  41.  
  42. _crt0:
  43.   ldr   r0,=0x52425430 @ RBT0
  44.   mov   r1, #0x0
  45.   mov   r2, #0x0
  46.   mov   r3, #0x0
  47.   mov   r4, #0x0
  48.   mov   r5, #0x0
  49.   mov   r6, #0x0
  50.   mov   r7, #0x0
  51.   mov   r8, #0x0
  52.   mov   r9, #0x0
  53.   mov   r10,#0x0
  54.   mov   r11,#0x0
  55.   mov   r12,#0x0
  56.   mov   lr, #0x0
  57.   ldr   sp,=0x40010000
  58.   ldr   pc,=0x40010000
  59.  
  60. .thumb
  61.  
  62. restore_svc_vector:
  63.     ldr r0, =0x6000F208 /* SVC vector address */
  64.     ldr r1, =0x40004C30 /* original SVC handler address */
  65.     str r1, [r0]
  66.     bx lr
  67.  
  68. usb_init:
  69.     push {lr} /* save return address on the stack */
  70.     adr r0, usb_mode
  71.     ldr r1, =0x1021B3
  72.     ldr r2, =(set_usb_ops+1)
  73.     mov lr, r2 /* required; early revision ARM does not have the ability to load directly into r8-r15 in thumb mode. */
  74.     bx r1 /* get_usb_mode(&usb_mode) */
  75. set_usb_ops:
  76.     adr r0, usb_mode
  77.     ldr r0, [r0]
  78.     ldr r1, =0x102B75
  79.     ldr r2, =(usb_initialize+1)
  80.     mov lr, r2
  81.     bx r1 /* set_usb_ops(usb_mode) */
  82. usb_initialize:
  83.     ldr r0, =0x40003114 /* r0 = &g_usb_ops */
  84.     ldr r0, [r0, #4] /* load usb_initialize func ptr from usb_ops */
  85.     ldr r1, =(charger_setup+1)
  86.     mov lr, r1
  87.     bx r0 /* usb_ops->usb_initialize() */
  88. charger_setup:
  89.     ldr r0, =0x40003114 /* r0 = &g_usb_ops */
  90.     mov r1, #1
  91.     strb r1, [r0, #1] /* set is_initialized flag to 1 */
  92.     strb r1, [r0, #2] /* set buffer to 1; causes rcm_read_command_and_payload() to be called immediately */
  93.     ldr r0, =0x104283
  94.     ldr r1, =(handle_rcm+1)
  95.     mov lr, r1
  96.     bx r0
  97. handle_rcm:
  98.     ldr r0, =0x40003114 /* r0 = &g_usb_ops */
  99.     pop {r1} /* set r1 to the return address */
  100.     str r1, [r0, #0x10] /* replace read_ep1_out_finish with a jump to return address */
  101.     mov r0, #0 /* this seems to be an "rcm reason" flag. Doesn't matter how it's set */
  102.     mov r1, r0 /* set other args to 0 as they are unused for our purposes. */
  103.     mov r2, r0
  104.     mov r3, r0
  105.     ldr r4, =0x102897 /* handle_rcm(0, 0, 0, 0) */
  106.     bx r4
  107. .pool
  108.  
  109. usb_mode:
  110.     .word 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top