Oops - forgot the [PIC] tag. Resending. I'm writing an 18F2520 bootloader. I need suggestions as to going about patching the reset vector. The patching code is PC-side, so a somewhat complex algorithm (by PIC standards) is OK. I also have a small feature to patch the interrupt vector in a similar way to allow for remote-reset (using only the UART) to reprogram without hitting the reset button, so I'll need to do the same with the interrupt vector (this is an optional setting). The bootloader sits at the end of Flash memory, and I have a 64 byte block available for duplicating the original vectors and other information (I need one byte of this block, at least, for settings). No matter what I try, there will always be a way of generating an incompatible reset vector, but I want something that works well with most compilers and isn't overly complex to implement (though some analysis of the original vector is OK by me, but I'd rather avoid a full-blown instruction parser and disassembler). What are the typical reset and interrupt vectors produced by C18? Does it always use a goto (easy) or branch (not so easy), does it try to squeeze code into the vectors (very annoying), does it just clobber the interrupt vector when no interrupts are in use (bad for the extra feature)? What about other compilers? Any suggestions from other bootloaders? I could simply replace the first two instructions with a GOTO (therefore requiring them to be two NOPs), move the first instruction assuming it's a goto, move the entire vector and add a goto at the end (and hope it's position independent), etc. For reference, the interrupt hijack function works like this: if the user code doesn't use the UART, it can request the bootloader leave interrupts enabled and hijack the low vector, and leave the UART enabled. The vector in the bootloader code checks for RCIF and receives a character. If the character looks like a bootloader init sequence, it resets the PIC. Otherwise, it restores registers and jumps back to the user vector (it uses a couple hacks to avoid the usage of any RAM at all). Thanks everyone in advance ;) -- Hector Martin (hector@marcansoft.com) Public Key: http://www.marcansoft.com/marcan.asc -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist