Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: squidgetx on December 11, 2010, 08:18:38 pm

Title: How do apps work?
Post by: squidgetx on December 11, 2010, 08:18:38 pm
Not exactly an asm question, but I figured I'd have the best audience in this board.

So my question is, how do apps run without using up user RAM? Are they copied to a page reserved for apps? And if so, at what location/address is that?

Title: Re: How do apps work?
Post by: FloppusMaximus on December 11, 2010, 10:19:58 pm
Seems like a fine asm question to me.

Apps are stored in Flash, and execute from Flash, just like the OS.  Flash is divided into 16384-byte "pages"; any page can be mapped to the Z80 address space starting at 4000h, simply by writing the page number to port 6.  So basically, all the OS needs to do to run an app is to write the appropriate value to port 6, and jump to the start of the app's code.  The app is never copied into RAM - there's no free RAM you could use for that purpose.

In order for this to work, the app needs to be stored at the start of a page, which is why every app effectively takes up a multiple of 16k bytes.  Being stored in Flash also means the app can't modify itself (well, that and the fact that they need to be digitally signed.)
Title: Re: How do apps work?
Post by: jnesselr on December 11, 2010, 10:21:28 pm
Seems like a fine asm question to me.

Apps are stored in Flash, and execute from Flash, just like the OS.  Flash is divided into 16384-byte "pages"; any page can be mapped to the Z80 address space starting at 4000h, simply by writing the page number to port 6.  So basically, all the OS needs to do to run an app is to write the appropriate value to port 6, and jump to the start of the app's code.  The app is never copied into RAM - there's no free RAM you could use for that purpose.

In order for this to work, the app needs to be stored at the start of a page, which is why every app effectively takes up a multiple of 16k bytes.  Being stored in Flash also means the app can't modify itself (well, that and the fact that they need to be digitally signed.)
Wait, are they checked every time they are run for digital signatures?
Title: Re: How do apps work?
Post by: FloppusMaximus on December 11, 2010, 10:30:39 pm
No, only when it's transferred to another calculator (it's checked at the receiving end, that is.)
Title: Re: How do apps work?
Post by: ZippyDee on March 24, 2011, 01:24:23 am
Why does it have to be signed? (I've never understood the whole signing thing with apps)
Title: Re: How do apps work?
Post by: mikehill2003 on March 24, 2011, 01:32:13 am
Why does it have to be signed? (I've never understood the whole signing thing with apps)

If they are signed (I have no idea if they are) it would be to control who could make programs.
Title: Re: How do apps work?
Post by: z80man on March 24, 2011, 01:39:34 am
But if you used your own link protocol, could you send an app to another calculator without having to sign it correctly.
Title: Re: How do apps work?
Post by: DJ Omnimaga on March 24, 2011, 01:42:27 am
Welcome to the forums ZippyDee!

I do not know why they are signed, but I suspect this is some protection TI added to their calcs to make it harder to distribute paid ones. However I have no clue why freeware apps still need to be signed.
Title: Re: How do apps work?
Post by: mikehill2003 on March 24, 2011, 01:49:13 am
But if you used your own link protocol, could you send an app to another calculator without having to sign it correctly.

Can you?
Title: Re: How do apps work?
Post by: DJ Omnimaga on March 24, 2011, 01:53:03 am
Wait I missed that post. That would be awesome if this was possible. O.O

The only problem is that such apps gets auto-deleted after being ran 16 times, though... (since the calc thinks they are trial apps). Take Axe Parser-generated apps, for example.
Title: Re: How do apps work?
Post by: mikehill2003 on March 24, 2011, 01:54:43 am
Wait I missed that post. That would be awesome if this was possible. O.O

The only problem is that such apps gets auto-deleted after being ran 16 times, though... (since the calc thinks they are trial apps). Take Axe Parser-generated apps, for example.

Whoah! LAME

They couldn't make a better trial system then that?
Title: Re: How do apps work?
Post by: DJ Omnimaga on March 24, 2011, 02:16:57 am
Well... it's Texas Instruments we're talking about here, after all. :P

(Although if Casio tried to lock down the Prizm, then they failed even harder, since it got cracked a few weeks after its release)
Title: Re: How do apps work?
Post by: z80man on March 24, 2011, 02:56:47 am
Well... it's Texas Instruments we're talking about here, after all. :P

(Although if Casio tried to lock down the Prizm, then they failed even harder, since it got cracked a few weeks after its release)
A couple of weeks, I'm pretty sure we got our own apps on in under a week. In fact we were running apps before the announced release of the Prizm on January 15th.

I never knew that Axe apps were deleted after 16 runs ??? Probably because I've never ran one of my Axe apps more than 16 times before recompiling. but still it just sounds strange to see apps get deleted like that.
Title: Re: How do apps work?
Post by: Freyaday on March 24, 2011, 03:04:38 am
Yeesh. So is it possible to sign an app on calc, or does it have to be done on a computer?
Title: Re: How do apps work?
Post by: ZippyDee on March 24, 2011, 04:04:16 am
Welcome to the forums ZippyDee!
Thanks :D

The only problem is that such apps gets auto-deleted after being ran 16 times, though... (since the calc thinks they are trial apps). Take Axe Parser-generated apps, for example.
Well then that answers the question of why they need to be signed, so I guess the only question left is
Yeesh. So is it possible to sign an app on calc, or does it have to be done on a computer?
Title: Re: How do apps work?
Post by: Compynerd255 on March 24, 2011, 10:39:01 am
Why does it have to be signed? (I've never understood the whole signing thing with apps)
If it is only checked on the recieving end, it might also have to do with checksum validation (to check whether the app made it to the other side unscathed, since that's a lot of bytes to transfer).
Title: Re: How do apps work?
Post by: Xeda112358 on March 24, 2011, 10:47:14 am
One reason for the trials is that back when TI was selling Apps, people wanted to release trial versions of their software. After the trials were used up, the app couldn't be used and the customer would need to buy the official version made with official software and with a special signature.
Title: Re: How do apps work?
Post by: Deep Toaster on March 24, 2011, 11:17:58 am
TI pretty much gave up on paid apps though :D

And just a point of clarification for the original question: Remember that code can be executed from any location between $0000 and $BFFF (but not $C000 and beyond, which cause a RAM clear for security purposes). Flash pages are usually switched in to the area between $4000 and $7FFF, so it runs fine. You could even switch it into $8000-$BFFF (instead of the usual RAM page that's there) and it would still run. Pointers would get messed up though, of course.
Title: Re: How do apps work?
Post by: Xeda112358 on March 24, 2011, 11:20:33 am
I'm just curious about what these "security reasons" are that I keep hearing about...
Title: Re: How do apps work?
Post by: Deep Toaster on March 24, 2011, 12:09:55 pm
I'm just curious about what these "security reasons" are that I keep hearing about...

Security, as in keeping programs under 8 KB so no one can release awesome games :P

I think it's to protect the VAT/stack, but IMO it's really unnecessary.
Title: Re: How do apps work?
Post by: Xeda112358 on March 24, 2011, 12:11:05 pm
Yeah, I don't see the necessity, either. Is it hardware that does that? I know there is a memory map mode that doesn't do this...
Title: Re: How do apps work?
Post by: jnesselr on March 24, 2011, 06:29:49 pm
Why does it have to be signed? (I've never understood the whole signing thing with apps)
If they are signed (I have no idea if they are) it would be to control who could make programs.
It has to be signed to make sure it's a "valid" source.  Before, when TI made paid apps, those required a special key.  The free key 0104 was released, and so, we use that to make apps.

Yeesh. So is it possible to sign an app on calc, or does it have to be done on a computer?
It's quite possible to be done on-calc, it would just take forever and ever.  There was a program made to sign axe apps.  It takes like 10 minutes, IIRC.  You're dealing with 256 and 512 bit numbers here, though.

Yeah, I don't see the necessity, either. Is it hardware that does that? I know there is a memory map mode that doesn't do this...
I believe it mostly has to do with how the chip is set up for flash and ram.  In one memory map mode, you have page 0 in 0000-3FFF, some flash page in 4000-7FFF, a ram page (82 I think) in 8000-BFFF, and ram page 0 (81 or 80, I can't remember) in C000-FFFF.
Title: Re: How do apps work?
Post by: Compynerd255 on March 24, 2011, 06:31:47 pm
You know, I have a question. Why is it that the filesize of an App on the computer is always several times bigger that what it will actually be on the calc?
Title: Re: How do apps work?
Post by: jnesselr on March 24, 2011, 06:33:20 pm
You know, I have a question. Why is it that the filesize of an App on the computer is always several times bigger that what it will actually be on the calc?
Because there's more stuff on the computer than there is on the calc.  There's header stuff for the app and more.  I don't know why it would be several times bigger, though.
Title: Re: How do apps work?
Post by: Freyaday on March 24, 2011, 06:38:03 pm
512 bit numbers--now those are some bignums. O.O
Title: Re: How do apps work?
Post by: Ashbad on March 24, 2011, 06:39:47 pm
not as big as 65536 bit numbers >:D
Title: Re: How do apps work?
Post by: Freyaday on March 24, 2011, 06:51:23 pm
Which are not as big as 10^(10^100
Title: Re: How do apps work?
Post by: Xeda112358 on March 24, 2011, 09:55:33 pm
Yeah, I don't see the necessity, either. Is it hardware that does that? I know there is a memory map mode that doesn't do this...
I believe it mostly has to do with how the chip is set up for flash and ram.  In one memory map mode, you have page 0 in 0000-3FFF, some flash page in 4000-7FFF, a ram page (82 I think) in 8000-BFFF, and ram page 0 (81 or 80, I can't remember) in C000-FFFF.
Yeah, in the second memory map mode, page 0 is in 0000-3FFF and if page x is in 4000-7FFF, then x+1 is in 8000-BFFF and then whatever other page you load goes into C000-FFFF (at least I believe that is how it works... I haven't experimented with it yet :D)
You know, I have a question. Why is it that the filesize of an App on the computer is always several times bigger that what it will actually be on the calc?
Because there's more stuff on the computer than there is on the calc.  There's header stuff for the app and more.  I don't know why it would be several times bigger, though.
It is because the data in the App is stored as hexadecimal instead of bytes, so it should be over twice the size of the actual code. There are about 9 or 10 bytes (I forget) before the actual hex data and then I think there are either 16 or 32 bytes of code following (32 or 64 hex digits).
Title: Re: How do apps work?
Post by: ZippyDee on March 25, 2011, 03:16:03 am
I don't really even understand how the signing works, so I don't really get what would have to be done to sign an app on calc. Why would anything ever need to use 512 bit numbers except for high decimal precision?
Title: Re: How do apps work?
Post by: jnesselr on March 25, 2011, 02:54:58 pm
I don't really even understand how the signing works, so I don't really get what would have to be done to sign an app on calc. Why would anything ever need to use 512 bit numbers except for high decimal precision?
For security reasons.  The object of cracking the the signature is finding the private key from the public key.  I think I do pretty well in documenting it here (http://ourl.ca/6418/103741). Note, TL;DR: Factoring larger integers is exponentially harder.
Title: Re: How do apps work?
Post by: Deep Toaster on March 25, 2011, 02:56:13 pm
I don't really even understand how the signing works, so I don't really get what would have to be done to sign an app on calc. Why would anything ever need to use 512 bit numbers except for high decimal precision?

You can't sign on-calc. Software like RabbitSign are used to sign an app after it's assembled on a computer. Signing an app basically makes it "valid" to the calculator, which checks the 512-bit signature to see if it's valid or not. If it's not valid, the app gets deleted after a certain number of runs (like a "trial" app).
Title: Re: How do apps work?
Post by: Ashbad on March 25, 2011, 02:57:48 pm
What about DuckSign by Floppus/thepenguin77? ;D (forgot which one made it -- it signs apps on calc)
Title: Re: How do apps work?
Post by: Michael_Lee on March 25, 2011, 03:00:04 pm
Ducksign lets you send applications from one calc to another (unsigned apps will refuse to do so), but the expiration count will still exist unless Axe changes or unless you sign in on the computer.
Title: Re: How do apps work?
Post by: jnesselr on March 25, 2011, 03:16:15 pm
No, I know there was a program to sign apps on calc, I just can't find it.
Title: Re: How do apps work?
Post by: FloppusMaximus on March 26, 2011, 12:09:14 am
That was me. :)  And, no, it doesn't take 10 minutes, it takes less than one minute for normal-sized apps.

See http://ourl.ca/7447/149857

Ducksign lets you send applications from one calc to another (unsigned apps will refuse to do so), but the expiration count will still exist unless Axe changes or unless you sign in on the computer.
That's also not entirely correct.  DuckSign signs the application; once it's signed, it's perfectly valid, just as if you signed it using RabbitSign or Wappsign or whatever.

The expiration count is not part of the application; it's something that's set by the OS as part of the normal installation process (I don't remember whether it's set at the beginning or end of the transfer, but anyway...)  And it doesn't have anything directly to do with app signatures.  If you write an application directly into Flash - regardless of whether or not it's signed - without also setting the expiration count, the app will expire after 16 runs.

As far as Axe goes, I believe Quigibo has said that he doesn't want to do this in Axe because of the risk of corrupting the calculator certificate.
Title: Re: How do apps work?
Post by: jnesselr on March 26, 2011, 11:19:17 am
Oh yeah, I forgot that directly modifies the calc's certificate.  I remember freaking out when I was told how often TI does that.