Author Topic: Boot Code Transfer to OS  (Read 8821 times)

0 Members and 1 Guest are viewing this topic.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Boot Code Transfer to OS
« on: December 23, 2011, 04:23:13 pm »
How does boot code give control to the OS?  Where does it jump to?  Are there any integrity checks?  If so, what are they?
ld a, 0
ld a, a

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1591
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Boot Code Transfer to OS
« Reply #1 on: December 23, 2011, 10:04:01 pm »
A fun question :D

Well, firstly, I recommend you actually take a look at the boot code yourself. In all honesty, this will allow you to understand it far better than I can explain it. Just start at $4000 and figure out what it's doing. The route from boot to OS is only like 300 instructions.

But here's what happens (I'm reading from a disassembly):

The boot code...
1. sets up all of the calculator hardware through ports (port (07) gets 80h except for an OS installation where it gets 00h).
2. checks for Stat and Del and does its usual if they are pressed
3. checks (0038h) to make sure it's not FFh
4. checks (0056h) to make sure it's A55Ah, (5Ah, A5h in memory)
5. jumps to 0053h

Also, if you are going to send your own OS, (0056h) should be $A5FF when sending. Something gets angry if it's not, but I don't remember what it is.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Boot Code Transfer to OS
« Reply #2 on: December 23, 2011, 11:59:18 pm »
1. sets up all of the calculator hardware through ports (port (07) gets 80h except for an OS installation where it gets 00h).
2. checks for Stat and Del and does its usual if they are pressed
3. checks (0038h) to make sure it's not FFh
4. checks (0056h) to make sure it's A55Ah, (5Ah, A5h in memory)
5. jumps to 0053h

Also, if you are going to send your own OS, (0056h) should be $A5FF when sending. Something gets angry if it's not, but I don't remember what it is.
Thanks!  I'll try that.  :)

Ok, so I took a look at the code and made some notes.  I only got so far until I got incredibly annoyed at the code.  :P
Spoiler For Spoiler:
0002 Check if calc is 83+BE  (I have an 84+SE.)
029A Set up hardware timers and memory banking.
8130 waste time...
813D waste moar time...
814C Set up hardware timers
4151 MUST WASTE ALL THE TIME!!!!!
4165 Unlock flash
4173 Abuses SP in a very weird way (???)
4193 The coding on this is so bad... Please put me out of this misery!
60E1 Set up link port
41D3 Set up LCD
4204 Set up flash and ram execution limits
421A What are port $39 and $4A?
4225 No comment about the programming... x.x
628F AARRGGH!!! You used CPL before!!! DX
423D Check for keypresses (Such as DEL)
4248 Check if 00:0053 is $A55A
FFFF FFUUUU Ok, I give up on this.  The coding on this is the worst I've ever seen... Since worse TI stuff.  uugghh...
« Last Edit: December 24, 2011, 12:01:16 am by ralphdspam »
ld a, 0
ld a, a

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1591
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Boot Code Transfer to OS
« Reply #3 on: December 24, 2011, 09:02:08 am »
Your analysis entertained me, so here is a commented version I just whipped up.

A few notes:
  • The boot code starts on page 7F at 4000, not 0000 on page 00 of the OS. (Technically the boot code starts on page 7F at 0000, but I'm not going into that)
  • A lot of the useless code you saw was so people can't trick the boot code into unlocking flash for them. When we unlock flash, we have to trick those things into returning to our control with flash unlocked
  • And as much as you'd like to think otherwise, TI's code is actually pretty well written :)
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Boot Code Transfer to OS
« Reply #4 on: December 25, 2011, 01:47:53 am »
  • The boot code starts on page 7F at 4000, not 0000 on page 00 of the OS. (Technically the boot code starts on page 7F at 0000, but I'm not going into that)
I noticed the way the code switches out the pages and jumps up to the $4000 bank.  It seemed useless at first, but it's actually kind of clever.
Quote
  • A lot of the useless code you saw was so people can't trick the boot code into unlocking flash for them. When we unlock flash, we have to trick those things into returning to our control with flash unlocked
  • And as much as you'd like to think otherwise, TI's code is actually pretty well written :)
Yeah, maybe I'm just nitpicking.  :P
« Last Edit: December 25, 2011, 01:48:40 am by ralphdspam »
ld a, 0
ld a, a