crt0.c File Reference

A C runtime. More...

#include <avr/io.h>
#include <avr/sfr_defs.h>
#include "os.h"

Go to the source code of this file.

Defines

#define zero_reg   "r1"
#define vector(name)
 A macro to simplify the vector list.

Functions

void __vectors (void)
 The vectors section.
void __vector_not_set (void)
 A default routine that is called when an interrupt occurs for which no ISR was assigned.
void __init (void)
 The beginning of the executable code in this file.
void init2 (void)
 init2
void __do_copy_data (void)
 init4
void init9 (void)
 init9


Detailed Description

A C runtime.

Use only one of crt0.S and crt0.c

This file is adapted from grct1.S in the avr source.

For use in Mantis Cheng's CSC 460 Fall 2007

To use this as startup code in AVR Studio, add "-nostartfiles" to [Linker Options] in Project>Configuration options>Custom Options.

The name of the function in the last call is where the program starts. (For project 2 it should be "OS_Init".)

Author:
Scott Craig

Justin Tanner

Definition in file crt0.c.


Define Documentation

#define zero_reg   "r1"

The "zero" register

Definition at line 28 of file crt0.c.

#define vector ( name   ) 

Value:

asm(\
    ".weak "  name "\n\t"\
    ".set  "  name " , __vector_not_set\n\t"\
    "jmp   "  name "\n\t"::);
A macro to simplify the vector list.

The symbol "__vector_i" is weakly bound to this spot in the object file. Later, other object files can reference this spot using this symbol.

The value of the symbol is set to "__vector_not_set", which is the label of a function below. Other files will change this if an ISR is declared.

The instruction at this spot is "jmp (addr)" (4 bytes). These addresses are hardwired in the mcu.

Definition at line 44 of file crt0.c.


Function Documentation

void __vectors ( void   ) 

The vectors section.

The numbers are off by 1 from the hardware manual, but consistent with iousbxx6_7.h. Vector "0" is the reset vector, which jumps to the executable code.

Any interrupt ISR definition in the C code will overwrite these default definitions.

Definition at line 61 of file crt0.c.

__vector_not_set ( void   ) 

A default routine that is called when an interrupt occurs for which no ISR was assigned.

The default action is to reset, but it could be changed to do something else.

Definition at line 115 of file crt0.c.

void __init ( void   ) 

The beginning of the executable code in this file.

The section names tell the linker where to place the code as specified in the linker script. eg. avr5.x

Definition at line 128 of file crt0.c.

void init2 ( void   ) 

init2

Clear the "zero" register, clear the status register, and set the stack pointer.

Definition at line 145 of file crt0.c.

void __do_copy_data ( void   ) 

init4

Copy data from __data_load_start in program memory to __data_start in SRAM, initializing data in the process. A similar routine with the same name is defined in libgcc.S. This routine overrides it.

Definition at line 163 of file crt0.c.

void init9 ( void   ) 

init9

The last of the init functions. Usually this would be the jump to "main()"

exit is defined in libgcc.S. It is an rjmp to itself. If the function called in init9 returns, it returns here.

Definition at line 207 of file crt0.c.


Generated on Tue Oct 23 21:49:51 2007 for RTOS by  doxygen 1.5.1