10.3.2. Patching example to emulate a serial port

To emulate a serial port in your source code:

  1. Define a macro that emulates a serial port:

    add unsigned long last_time;    /* create local symbol */	
    def int ser_port(offset,base)   /* macro definition */
        int offset;                 /* offset of device reg */
        unsigned short *base;       /* base of port */
    {
        unsigned short value;
    if (offset == 0)
    {                               /* control register */
        if (last_time && @cycle-last_time < 20)
        {
            error (0, “ser_port: access less than
        	        allowed time: %d”, @cycle-last_time);
            return (0);
        }
        last_time = @cycle;
        value = base[offset];   /* cache written value */
        base[offset] = 0;       /* reset */
        if (value == 0x20)
        {                       /* want to read */
    .
    .
    .
    
  2. Start a debugging session and set a breakpoint on the source code to stop execution before it accesses the serial port, for example at line 20, and attach your macro to this breakpoint:

    >bi \module_name\#20 ;ser_port(0,&ser_port)
    
  3. Continue debugging using the newly-inserted serial port emulation.

As with the previous example, this is only a temporary patch so the source code must be edited and then recompiled. Be careful, however, when using such a patch in optimized code.

Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0234B
Non-Confidential