2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #include "ao-bringup.h"
20 #define AO_STACK_SIZE 128
22 uint8_t new_stack[512];
25 #define PUSH8(stack, val) (*((stack)--) = (val))
27 #define PUSH16(stack, val) PUSH8(stack, ((uint16_t) (val))); PUSH8(stack, ((uint16_t) (val)) >> 8)
39 LEDPORT ^= (1 << LEDOUT);
51 init_stack(void (*f) (void))
53 uint8_t *stack = new_stack + AO_STACK_SIZE - 1;
64 /* Clear register values */
69 /* SREG with interrupts enabled */
71 stack_count = stack - new_stack;
72 printf("Function is at %p. Stack[1] is %02x Stack[2] is %02x\n",
73 f, stack[1], stack[2]);
74 printf ("stack_count is %d\n", stack_count);
75 printf ("stack is %p\n", stack);
79 switch_stack(void) __attribute__((naked));
81 void show_stack(char *s, uint8_t h, uint8_t l)
83 printf ("SP at %s %02x %02x\n", s, h, l);
89 uint8_t *sp = (new_stack + stack_count);
93 sp_h = ((uint16_t) sp) >> 8;
94 asm volatile ("out __SP_H__,%0" : : "r" (sp_h) );
95 asm volatile ("out __SP_L__,%0" : : "r" (sp_l) );
96 asm volatile("pop r0" "\n\t"
98 asm volatile("pop r0" "\n\t"
103 asm volatile("pop r5" "\n\t"
108 asm volatile("pop r10" "\n\t"
113 asm volatile("pop r15" "\n\t"
118 asm volatile("pop r20" "\n\t"
123 asm volatile("pop r25" "\n\t"
128 asm volatile("pop r30" "\n\t"
143 printf("starting\n");