Re: C question 2



On Wed, 27 Jul 2005 15:50:39 +0200, Xarion wrote:

> why would i want to place a code segment at a specific location in memory
> rather than let the linker decide where to put it?
>
> - Xarion

Two examples come to mind.

When you power up the computer it jumps to the special start location
expecting to find the start of your program.

When an interrupt occurs, again the computer jumps to a special location
expecting to find an interrupt service routine that will handle the
interrupt.

For example on most 16F Microchip PIC processors, the program starts at
address 0x0 and the interrupt handler starts at address 0x4. So most PIC
programs in assembler look something like:

ORG 0x0
goto Start

ORG 0x4
goto ISR


Start:
...

ISR:
...
retfie ; return from interrupt instruction


A C compiler must arrange for the C code to mimic the assembler layout for
the code to function as expected.

Some linkers can force load a subroutine at a specified location. Usually
this information is passed from the compiler or read from a linker
configuration file that you create for the application you are developing.


.



Relevant Pages

  • Re: Linker error: L1907
    ... I'm not so familiar with OSEK, but I do know the compiler/linker. ... The code uses the address of an interrupt function to initialize a global 16 bit pointer and the interrupt function is allocated non banked. ... Older compilers (this checking depends on the compiler, not on the linker) did probably not set the "check overflow" flag for this case. ...
    (codewarrior.embedded)
  • Re: Using Visual Basic to Write System-Wide Hooks
    ... How would you find the address to the system keyboard routines? ... I'd need to know the name of the keyboard interception routine, ... revector from the old Interrupt address to a new ... intercept the calls to the VB compiler, C2.EXE, and linker, ...
    (microsoft.public.vb.winapi)
  • RE: floppy disk behavior (when empty)
    ... > chattering and an hourglass is displayed and I can't interrupt the process. ... However, when I reboot the machine and do the same thing, ... > expecting, but it is temporary for me. ... > there a fix? ...
    (microsoft.public.windowsxp.general)
  • thread; interrupt_main() doesnt seem to work?
    ... I was expecting this short test prog to run and then finish ... with the KeyboardInterrupt exception at the bottom in the pause ... interrupt and get the expected bactrace and program exit. ...
    (comp.lang.python)
  • Re: spin lock
    ... Interrupt code can complete the time-critical part of the service, then RELEASE the device and awaken the task to do further processing, if any. ... A nice side-effect of this scheme is that the GET associates the task handle with the facility, so the interrupt code knows who is expecting the interrupt and hence whom to wake up. ... Stopping the IRQ would kill the task, ...
    (comp.lang.forth)