crozone / ipodloader2

Bootloader for classic iPods. Supports Rockbox, iPod Linux, and stock iPod OS.
44 stars 1 forks source link

why r0 cmp to 0x55 #5

Closed buzai closed 1 year ago

buzai commented 2 years ago

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L65

If possible, I would like to talk about this project. I have a lot of questions. Can you give me a contact method?

crozone commented 1 year ago

Disclaimer: I didn't write any of this assembly boot code and I wasn't around when it was written. However, I think I've finally figured this one out (TODO: Comment the assembly code).

iPod Linux documentation for the PP5002 and PP5020 CPUs.

The _start code uses the current PC instruction address to figure out if it has been booted on a PP5002 or a PP5020 model CPU, since these have different starting addresses. PP5002 SDRAM starts at 0x28000000, PP5020 SDRAM starts at 0x10000000.

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L56-L60

It then loads the Processor ID from either #PP5002_PROC_ID (0xc4000000) or #PP5020_PROC_ID (0x60000000), depending on what CPU was detected. This is in a magic memory mapped address that contains the current CPU processor ID. The two CPUs have different memory mappings which is why the two values are necessary.

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L61-L62

The lowest byte of the processor ID indicates whether it's the main CPU or the COP (co-processor) CPU.

location description
0xc4000000 Processor ID
  0x55 CPU
  0xaa COP

So it extracts the lowest byte of the processor ID:

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L63-L64

And then jumps to 1f if the current CPU is the main CPU (0x55)

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L65-L66

Else, if it's running on the COP (coprocessor), sleep itself by writing to the COP Control register address (CPU dependent) until it is woken back up by the main CPU:

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L68-L74

After it wakes back up it jumps to cop_wake_start

https://github.com/crozone/ipodloader2/blob/6b69848984b5124e6a4a244ddf29d0626bcc0b79/startup.s#L75