Imported Upstream version 2.9.0
[debian/cc1111] / doc / avr / avr_design.txt
1 Design Document for AVR Port
2 ----------------------------
3
4 The first release will support all AVR architectures except ATMega & ATtiny
5 (i.e. all variants with 64K or less of code/data space will be supported)
6
7 All functions will be REENTRANT .
8
9 I) Language extensions.
10 -----------------------
11
12 a) Storage classes
13 ------------------
14
15 "bit"   - not applicable (will be returned to user name space)
16 "data"  - not applicable (will be returned to user name space)
17 "idata" - not applicable (will be returned to user name space)
18 "xdata" - not applicable (will be returned to user name space)
19 "code"  - will place variable in "code" space. NOTE code space is NOT read-only.
20 "eeprom"- (new) will place the variable in eeprom (read & write)
21 "sram"  - (new) will place the variable in "SRAM" after the SFRs (default).
22
23
24 b) register/sfr bit access.
25 --------------------------
26 Operator '.' will be overloaded ( the compiler will decide if it
27 is a structure access or register bit access depending on context)
28 eg.
29
30 sfr SOME_SFR = 0x40;
31 sfr SOME_OTHER_SFR = 0x41;
32 foobar() 
33 {
34         ...
35         SOME_SFR.4 = 1; // set bit 4 of sfr SOME_SFR
36         ...
37         SOME_SFR.5 = SOME_OTHER_SFR.6; // copy bit 6 of SOME_OTHER_SFR to SOME_SFR's bit 5.
38         ...
39 }
40
41 II) Pointers 
42 ------------
43 As mentioned above initial releases will NOT support ATMega. 
44
45 Keeping with the three byte pointers for generic pointers,
46 the compiler will treat unqualified pointers as 3 byte pointers, 
47 the storage area will be saved in the upper nibble of the third byte 
48 (this will facilitate later support for ATMega). Here we differ for 
49 IAR (they seem to make copies of variables in code & other address 
50 spaces into data space, seemed like a needless waste of data space).
51
52 pointer declaration examples.
53
54 char *cp;        /* generic three byte pointer */
55 code char *cp;   /* pointer to code space */
56 eeprom char *cp; /* pointer to data in eepromp */
57 sram char *cp;   /* pointer to data in SRAM space */
58
59 III) Function calls
60 -------------------
61 The previous issue of function calls has been somewhat resolved.
62 SDCC will NOT support ATtiny & other variants (such as AT90S1200)
63 which have limited stack depth. It will however support variants
64 with 8 bit stack pointers.
65
66 IV) Register Usage
67 ------------------
68
69 R0-R7      -  Parameter passing & return value (differs from IAR I don't
70               like IAR's usage of R16-R23, specially since R0-R1 has
71               to be kept free anyway for divide & multiply operations)
72 R8-R25     -  General purpose registers for local variables.
73 R28-R29(Y) -  Stack Frame (Same as IAR)
74 R26-R27(X) -  GPRs assigned to pointers (non generic pointers).
75 R30-R31(Z) -  GPRs assigned to pointers (non generic pointers).
76
77 V) Parameter passing & return values
78 ------------------------------------
79 Registers R0-R7 (eight) registers will be used for parameter passing.
80 Unlike the 8051 port the AVR port will pass the first eight bytes of
81 parameters in a registers (8051 passes only the first parameter in
82 registers), the exception being.. part of a parameter will not be put
83 into registers.
84
85 Examples
86 int foo (char a,long b);
87     R0    <- a,
88     R1-R4 <- b;
89
90 int foo (long a, char b, long c)
91     R0-R3   <- a,
92     R4      <- b,
93     (STACK) <- c;
94
95 int foo (long a,long b)
96     R0-R3   <- a,
97     R4-R7   <- b;
98
99 Return values will be placed in registers R0-R3;
100
101 VI) Memory models
102 -----------------
103 The memory model will be used primarily to determine the 
104 width of the stack pointer.
105
106 --model-small - stack pointer 8 bit
107 --model-large - stack pointer 16 bit.