Skip to content

Commit

Permalink
kernel: process: omit debug addrs for fixed apps
Browse files Browse the repository at this point in the history
If an app is compiled for a fixed address, then we do not need to custom
make an LST file based on where it actually executed. The `make lst`
command will work just fine.
  • Loading branch information
bradjc committed Jun 12, 2020
1 parent 84b8fe6 commit 21c3695
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,16 +1473,65 @@ impl<C: Chip> ProcessType for Process<'_, C> {
let _ = writer.write_fmt(format_args!("{}", config));
});

let sram_start = self.memory.as_ptr() as usize;
let flash_start = self.flash.as_ptr() as usize;
let flash_init_fn = flash_start + self.header.get_init_function_offset() as usize;
/// Return Ok(Flash Address, RAM address) if this app has
/// fixed_addresses, Err(()) otherwise.
fn check_for_fixed_address(flash: &'static [u8]) -> Result<(u32, u32), ()> {
// Need to re-parse the TBF header to find if this app has fixed
// addresses or not.
let test_header_slice = flash.get(0..8).ok_or(())?;
let (version, header_length, _) =
tbfheader::parse_tbf_header_lengths(test_header_slice.try_into().or(Err(()))?)
.or(Err(()))?;
let header_flash = flash.get(0..header_length as usize).ok_or(())?;

// Parse the full TBF header to check if there is a fixed addresses
// header.
let tbf_header = tbfheader::parse_tbf_header(header_flash, version).or(Err(()))?;

// If either address is specified, we say that there is a fixed
// address.
if tbf_header.get_fixed_address_flash().is_some()
|| tbf_header.get_fixed_address_ram().is_some()
{
Ok((
tbf_header.get_fixed_address_flash().unwrap_or(0),
tbf_header.get_fixed_address_ram().unwrap_or(0),
))
} else {
Err(())
}
}

let _ = writer.write_fmt(format_args!(
"\
\r\nTo debug, run `make debug RAM_START={:#x} FLASH_INIT={:#x}`\
\r\nin the app's folder and open the .lst file.\r\n\r\n",
sram_start, flash_init_fn
));
// Print a helpful message on how to re-compile a process to view the
// listing file. If a process is PIC, then we also need to print the
// actual addresses the process executed at so that the .lst file can be
// generated for those addresses. If the process was already compiled
// for a fixed address, then just generating a .lst file is fine.

match check_for_fixed_address(self.flash) {
Ok((flash, ram)) => {
// Fixed addresses, can just run `make lst`.
let _ = writer.write_fmt(format_args!(
"\
\r\nTo debug, run `make lst` in the app's folder\
\r\nand open the arch.{:#x}.{:#x}.lst file.\r\n\r\n",
flash, ram
));
}
Err(()) => {
// PIC, need to specify the addresses.
let sram_start = self.memory.as_ptr() as usize;
let flash_start = self.flash.as_ptr() as usize;
let flash_init_fn = flash_start + self.header.get_init_function_offset() as usize;

let _ = writer.write_fmt(format_args!(
"\
\r\nTo debug, run `make debug RAM_START={:#x} FLASH_INIT={:#x}`\
\r\nin the app's folder and open the .lst file.\r\n\r\n",
sram_start, flash_init_fn
));
}
}
}
}

Expand Down

0 comments on commit 21c3695

Please sign in to comment.