Here's the way the IRS orders things when the principal residence exclusion applies to only a portion of the loan (http://www.irs.gov/publications/p4681/):
"Ordering rule. If only a part of a loan is qualified principal residence indebtedness, the exclusion applies only to the extent the amount canceled is more than the amount of the loan (immediately before the cancellation) that is not qualified principal residence indebtedness. The remaining part of the loan may qualify for another exclusion.
Ken incurred recourse debt of $800,000 when he bought his main home for $880,000. When the FMV of the property was $1,000,000, Ken refinanced the debt for $850,000. At the time of the refinancing, the principal balance of the original mortgage loan was $740,000. Ken used the $110,000 he obtained from the refinancing ($850,000 minus $740,000) to pay off his credit cards and to buy a new car.
About 2 years after the refinancing, Ken lost his job and was unable to get another job paying a comparable salary. Ken's home had declined in value to between $700,000 and $750,000. Based on Ken's circumstances, the lender agreed to allow a short sale of the property for $735,000 and to cancel the remaining $115,000 of the $850,000 debt. Under the ordering rule, Ken can exclude only $5,000 of the canceled debt from his income
under the exclusion for canceled qualified principal residence indebtedness ($115,000 canceled debt minus the $110,000 amount of the debt that was not qualified principal residence indebtedness). Ken must include the remaining $110,000 of canceled debt in income on line 21 of his Form 1040
(unless another exclusion applies).
How to report the qualified principal residence indebtedness exclusion. To show that all or part of your canceled debt is excluded from income because it is qualified principal residence indebtedness, attach Form 982 to your federal income
tax return and check the box on line 1e. On line 2 of Form 982, include the amount of canceled qualified principal residence indebtedness, but not more than the amount of the exclusion limit (explained earlier). If you continue to own your home after a cancellation of qualified principal residence indebtedness, you must reduce your basis in the home as explained under Reduction of Tax Attributes, next."