ESTE: Light Keyboard from Scrach using GNU GCC and Binutils

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar

In the light keyboard exercise, you relied on the compiler to solve some annoying tasks in embedded system programming, such as interrupt handler generation and language integration. Let's suppose now that you were supplied a very simple compiler that isn't able to perform such tasks. This is a rather normal situation in embedded systems development and, if you're a privileged developer that has the proper tools available, knowing the details behind such tasks is never useless.

So, try now to reimplement the light keyboard considering the following restrictions:

  • Interrupt handlers must be implemented as C routines;
  • The compiler is no longer able to automatically handle ISRs and interrupt vector generation, and you'll need to manually build the interrupt vector and implement the ISRs (complete with context saving and context restoring operations);
  • GCC's initialization routines are taking too long! Now you'll have to implement them by yourself.

Usefull links

Some tips

  • Compiling with -nostartfiles -nodefaultlibs will remove the interrupt vector and all initialization routines;
  • syntax.c and syntax_weak.c contains examples of some usefull function attributes.
  • Use gcc with the flags -nostartfiles and -nodefaultlibs, so the compiler code won't be included in the binary;
avr-gcc -mmcu=atmega328p -nostartfiles -nodefaultlibs -c syntax.c
  • Compile with -S and take a look at the generated assembly code. Pay attention on the code generated for the interrupt handlers;
avr-gcc -mmcu=atmega328p -nostartfiles -nodefaultlibs -S syntax.c
  • Use the linker to link multiple object files together;
avr-gcc -mmcu=atmega328p -nostartfiles -nodefaultlibs -c syntax.c
avr-gcc -mmcu=atmega328p -nostartfiles -nodefaultlibs -c syntax_weak.c
avr-gcc -mmcu=atmega328p -nostartfiles -nodefaultlibs syntax.o syntax_weak.o -o syntax
  • Use objdump from binutils to see the generated assembly code for your elf file. Take a look at what needs to be done before running your main() function;
avr-objdump -D syntax