| Author |
Message |
|
|
Posted: Sep 13, 2010 - 11:52 AM |
|

Joined: Sep 12, 2010
Posts: 27
Location: Brisbane
|
|
My task is develop an application program (C combined with ASM) to load and debug the execution of another application program. Implement the following debug monitor commands:
1.LOAD - Download an application program into the flash program memory of the AVR microprocessor. The program exists in a single file in Intel Hex format and is decoded by the debug monitor.
2.UNASSEMBLE - Disassemble a portion of program memory into AVR instruction mnemonics.
3.SET BREAKPOINT and CLEAR BREAKPOINT
4.SINGLE STEP.
I'm a new buddy here. Could any one can give me some hints? I don't need many source code. Only need ideas.
Now i'm try to transfer Hex files to ASM files.
I use programer's note pad open the hex fils the first line is like this:
1000 0000(this is address) 0c94 (JMP)4600(address) 0c94 6500 0c94 6500 0c94 6500 FB.
What's the meaning of FB.
Thanks for any one read this topic. |
|
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 12:14 PM |
|


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
You face a bit of an uphill struggle here because the AVR processor is a Harvard, not Von Neumann design and it can ONLY execute opcodes from flash. So your "LOAD" is going to have to use SPM in the bootloader section of the chip to load the code in.
It'd be far more efficient to write the disassembler (unassembler) on the PC than the AVR and process the binary before you send it to the AVR but if you want to load up the flash with strings/lookup tables I guess that's your choice (hope you've picked an AVR with a large flash to accomodate this). Note also that apart from AVR Studio there are already several other ways to disassemble AVR code in the PC domain (avr-objdump -S from the GCC toolchain will do it for example, as will disavr).
Your real (and possibly insurmountable!) hurdle of everything you propose are points 3 and 4. It's true that the AVR does have a BREAK opcode but this is only for it's own On Chip Debug systems. It does not have an expection vector mechanism where you could hook control of execution so your best hope is to replace the stop point with an "(R)CALL your_stopped_routine" but this is the real problem. You have to use SPM to put this sequence into the flash where you want it to stop (and replace the original code before you can continue). This raises the question of the 10,000 cycle limit of the AVR's flash.
It sounds to me that this is the spec. for a monitor on something like a Z80, 8080, 6502, 6800, 6809 and someone has said "how about doing it on AVR?" when they don't understand the implications for processors that can ONLY execute from code flash.
In the .hex line you quote the FB will be the checksum for the line. Suggest you read this:
http://en.wikipedia.org/wiki/Intel_HEX
(see point 6)
Also see:
http://www.keil.com/support/docs/1584.htm
(see 'cc').
BTW if writing a disassembler I think you may find this list useful:
http://sourceware.org/binutils/docs/as/ ... VR-Opcodes |
_________________
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 12:28 PM |
|

Joined: Sep 12, 2010
Posts: 27
Location: Brisbane
|
|
| Thank you very much. These infor. are very helpful. |
|
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 01:32 PM |
|

Joined: Sep 12, 2010
Posts: 27
Location: Brisbane
|
|
I got a idea.
Because the hex file which I will try to test is just a simple LED flashing code. So I can add a software interruption after every instruction. In this way I can finish the single step task. |
|
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 02:01 PM |
|


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
When I'm writing C programs to test the timing of something I often do:
Code:
int main(void) {
a = b + c;
asm("nop");
a = b * c;
asm("nop");
}
So I can break point on the "NOP". I guess you could do something similar like:
Code:
int main(void) {
a = b + c;
re_enter_monitor();
a = b * c;
re_enter_monitor();
}
|
_________________
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 02:06 PM |
|

Joined: Sep 12, 2010
Posts: 27
Location: Brisbane
|
|
|
clawson wrote:
When I'm writing C programs to test the timing of something I often do:
Code:
int main(void) {
a = b + c;
asm("nop");
a = b * c;
asm("nop");
}
So I can break point on the "NOP". I guess you could do something similar like:
Code:
int main(void) {
a = b + c;
re_enter_monitor();
a = b * c;
re_enter_monitor();
Thanks for the example. The problem is The monitor function might use ASM, in terms of many access to the ram address. Can I call the asm function in C?
}
|
|
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 02:10 PM |
|


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Sure you can access Asm from C (and vice versa). It's easier if no parameters or return are involved. And ultimately you can just:
Code:
typedef void (*fn_ptr_type)(void);
fn_ptr_type re_enter_monitor = (fn_ptr_type)0x1234; // address of ASM
re_enter_monitor(); // call the Asm function.
|
_________________
|
| |
|
|
|
|
|
Posted: Sep 13, 2010 - 07:11 PM |
|

Joined: Jan 30, 2005
Posts: 852
Location: Junction City, OR USA
|
|
|
|
|
|
|