summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-01 22:24:48 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-01 22:24:48 +0000
commitd57a02efd8b6388c43c85078ccd20fd6bd7a8e37 (patch)
tree81c38f63bb521df191ce3f1a4ed6ad8b7763ca5a
parent6aaff7ae54dbe34ea6bf3f9ee8c93e9d79db3c22 (diff)
downloadpp2cc-d57a02efd8b6388c43c85078ccd20fd6bd7a8e37.tar.gz
Update TODO, README and add notes for call convention
-rw-r--r--README12
-rw-r--r--TODO2
-rw-r--r--notes.txt46
3 files changed, 51 insertions, 9 deletions
diff --git a/README b/README
index 1770a4f..08fa293 100644
--- a/README
+++ b/README
@@ -35,7 +35,7 @@ A2.5 Constants - integers (hexadecimal 0x1a, 0X1A, octal 07, decimal 1), signed
A4 Identifiers - functions, variables (int) are supported. struct, union are
not yet supported
A4.1 Storage class - static is supported (actually, everything is static).
- Automatic variables are unsupported.
+ Automatic variables are supported.
A4.2-A4.3 Types - supported: int; unsupported: char, enum, float, double,
struct, union, arrays, pointers
A4.4 Type qualifiers - volatile won't be supported, const is unsupported
@@ -53,7 +53,8 @@ A7.3 Postfix Expressions - unsupported
function calls - supported, result is stored in register R0 (for int functions)
Other types (void) are not checked when using their value. If an
undefined function is used, it'll still try to branch to the label
- Parameters are not supported. Pointers to functions are unsupported
+ Parameters are supported. Pointers to functions are unsupported.
+ Recursive function calls are supported
A7.4 Unary Operators - supported: ++ -- + - ~ ! & * Unsupported: sizeof
A7.5 Casts - unsupported and ignored
A7.6-A7.7, A7.9-7.13 - supported: * / % + - < > <= >= == != & ^ | Left to right
@@ -108,11 +109,8 @@ A10.1 Function Definitions - unsupported: extern static, parameters. Old style
A10.2 External declarations - unsupported/unchecked
A11 Scope and Linkage
-A11.1 Lexical scope - objects (variables), functions use the same namespace,
- thereby not conforming to the Standard. Block scope is not
- supported, everything is global. Variables with the same name in
- different block scopes do not affect each other, but recursive
- functions do
+A11.1 Lexical scope - objects (variables) and functions use the same namespace
+ conforming to the Standard
A11.2 Linkage - not applicable / unsupported
A12 Preprocessing
diff --git a/TODO b/TODO
index 23d2c62..a5d5ecc 100644
--- a/TODO
+++ b/TODO
@@ -2,5 +2,3 @@ Post decrement/increment operators:
p-- p++
x.y x->y
-
-Function calls with arguments
diff --git a/notes.txt b/notes.txt
new file mode 100644
index 0000000..d2998c1
--- /dev/null
+++ b/notes.txt
@@ -0,0 +1,46 @@
+Build a table for a (x+1)-bit number and their signed values in binary/decimal
+var a = [], x=4;
+var zpad = (new Array(x+1)).join("0"), pad = (new Array(x+1)).join(" ");
+for(var i=0;i<2<<x;i++) {
+ var n = i & ((2<<(x-1))-1);
+ n-=i&(2<<(x-1))
+ a.push((zpad+i.toString(2)).substr(-(x+1)) + " = " + (pad+n).substr(-(x+1)))
+}
+a.join("\n")
+
+Function call try to follow the convention at
+http://www.cs.virginia.edu/~evans/cs216/guides/x86.html#calling
+
+Reminder
+The stack starts at the end of the memory. If the stack grows, SP decreases.
+
+Caller:
+1. <no regs to push>
+2. For n parameters, do a PUSH. The last parameter is the first on the stack
+3. Call subroutine (BRS: PUSH return address on stack and BRanch Always)
+(after call when returned:)
+4. Remove parameters from the stack: ADD SP n
+5. Result is in R0
+6. (perhaps a CMP R0 0 or LOAD R0 R0 if in expression context?)
+
+Callee:
+1. push R5 (base pointer "BP" in stack for local variables and parameters)
+2. Store current stack pointer in R5 (LOAD R5 SP). [R5] now contains the return
+ address, [R5+i] the i-th parameter and [R5+-i] the i-th local var
+3. Grow stack for local variables (by SUB SP n) if necessary
+4. <function body>
+5. LOAD SP R5 (clear local vars)
+5. PULL R5 (restore the "BP" of the caller)
+6. RTS (go back to caller)
+
+parameter access (i-th parameter):
+LOAD R0 [R5+i]
+local variable access (i-th local var)
+LOAD R0 [R5+-i]
+global variable access
+LOAD R0 [GB+name]
+
+
+Initially, the stack size on the PP2 is 240 words, but it can be adjusted with:
+@STACKSIZE newsize
+The constant 'stacksize' (lowercase) contains the previous stack size