Mudanças entre as edições de "ESTE: Light Keyboard from Scrach using GNU GCC and Binutils"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
(Criou página com '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 integrat...')
 
 
Linha 1: Linha 1:
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 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.
+
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 (specially the part in which the button must be pressed for four seconds before leds are lit) considering the following restrictions:
+
So, try now to reimplement the light keyboard considering the following restrictions:
 
*Interrupt handlers must be implemented as C routines;
 
*Interrupt handlers must be implemented as C routines;
*The system has now severe time constraints and the compiler handling of read and write operations on the I/O ports isn't adequate anymore, and you'll need to manually encode IN/OUT assembly instructions to give the system a good performance;
+
*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''');
*The compiler isn't able to automatically handle ISRs and interrupt vector generation anymore, 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.
*GCC's initialization routines are taking too long ! Now you'll have to implement them by yourself.
 
  
Usefull links
+
'''Usefull links'''
*AVR Instruction Set
+
*[http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet_complete.pdf ATMega328P manual]
*ATMega328P manual
+
*[https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html GCC - Declaring Attributes of Functions]
*GCC - Declaring Attributes of Functions
+
*[https://sourceware.org/binutils/docs-2.21/binutils/index.html GNU Binary Utilities documentation]
*GNU Binary Utilities documentation
+
*[http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html GNU - Inline-Assembly-HOWTO]
*GNU - Inline-Assembly-HOWTO
+
*[http://www.nongnu.org/avr-libc/user-manual/mem_sections.html Memory Sections - AVR-GCC]
*Memory Sections - AVR-GCC
+
*[https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options GCC - Optimization control]
*GCC - Optimization control
+
*[https://www.google.com Google]
*Google
 
  
Some tips
+
'''Some tips'''
 +
*Compiling with -nostartfiles -nodefaultlibs will remove the interrupt vector and all initialization routines;
 +
*[http://www.lisha.ufsc.br/teaching/esl/exercises/syntax.c syntax.c] and [http://www.lisha.ufsc.br/teaching/esl/exercises/syntax_weak.c 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;
 
*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;
 
*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;
*Compiling with -nostartfiles -nodefaultlibs will remove the interrupt vector and all initialization routines;
+
avr-objdump -D syntax
*[http://www.lisha.ufsc.br/teaching/esl/exercises/syntax.c syntax.c] and [http://www.lisha.ufsc.br/teaching/esl/exercises/syntax_weak.c syntax_weak.c] contains examples of some usefull function attributes.
 

Edição atual tal como às 18h04min de 15 de abril de 2016

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