lowlevelprogramming-university/README_pt.md
2024-01-09 18:03:00 -03:00

29 KiB
Raw Blame History

Universidade de Programação em Baixo Nível

Nota 1: Por favor, não copie o conteúdo dessa página para o seu blog. Você pode compartilhar essa página, mas, por favor, compartilhe com o link original. Essa é a forma que nós elogiamos os autores de bons documentos e projetos open source.

Nota 2: Por favor, note que programação de baixo nível está fora de moda e atualente não há muitas companhias contratando desenvolvedores de baixo nível. Está ficando mais difícil para eu encontrar um trabalho. Se você ainda não começou a sua carreira profissional, eu recomendaria considerar outros campos cuidadosamente.

Nota 3: Se você quer ir direto ao ponto, vá para Como começar?.

Sumário

O que é esse repositório?

Eu me inspirei na google-interview-university. Eu gostaria de compartilhar minha experiência e um roteiro de como se tornar um programador de baixo nível porque acredito que essas habilidades não são tão comuns quanto antigamente. Além disso, muitos iniciantes e estudantes me perguntam como poderiam se tornar desenvolvedores de baixo nível e engenheiros do kernel Linux.

Essa página não inclui todos os links, livros ou cursos. Por exemplo, essa página introduz Arduino, mas não tem informações detalhados sobre Arduino de sistemas embarcados. Você deve se aprofundar por si mesmo. Você tem a palavra-chave "Arduino" para começar, então seu próximo passo é provalmente pesquisar sobre Arduino, comprar um kit e fazer alguma coisa você mesmo, e não colecionar links e livros. Por favor, lembre que essa página é apenas um roteiro para iniciantes.

Programação de baixo nível é uma parte de Ciências da Computação, de tal forma que, é certamente muito melhor ter esse conhecimento primeiro.

O que é programação de baixo nível?

Eu classifico programação de baixo nível como uma programação que é muito próxima da máquina. Usa-se uma linguagem de programação de mais baixo nível, como C ou assembly, diferentimente de linguagens de programação de alto nível, típicas de aplicações do espaço de usuário, como Python ou Java.

Sim, o conceito de programação de sistemas é bem próximo do de programação de baixo nível. Esse roteiro inclui o desenvolvimento de hardware e firmware que não estão inclusos no desenvolvimento de sistemas.

Finalmente, esse roteiro inclui tópicos indo de componentes de hardware até o kernel Linux. Isso é uma variedade enorme de camadas. Um documento de uma página nunca conseguiria cobrir detalhadamente todas elas, então o foco deste é servir de ponto inicial para programação de baixo nível.

Teoria

Existem dois conhecimentos teóricos para se programar em baixo nível:

  • Arquitetura de Computadores
  • Sistemas Operacinais

Acredito que a melhor maneira de aprender teoria é fazendo um curso. Ler livros não é ruim, mas consome muito tempo e esforço. Você pode achar várias aulas em univerisades online, por exemplo: Coursera e edX.

Teoria é teoria. Eu não acho que você necessite de uma 10 em uma matéria, apenas entenda seu conteúdo geral; você evoluirá com experiência.

Irei apresentar vários livros que li. Eles são comumente usados como livros-texto em universidades. Se não existe uma matéria com esses livros na sua universidade, vale a pena gastar um pouco de tempo os lendo.

  • Arquitetura de Computadores
    • Organização e Projeto de Computadores, 5ª edição. HENNESSY, John. 2021.
    • Arquitetura de Computadores: Uma Abordagem Quantitativa, 6ª edição. HENNESSY, John. 2019.
    • Computer Systems: A Programmer's Perspective, 3rd Edition. BRYANT, Randal; O'HALLARON, David. 2015.
  • Sistemas Operacionais
    • The Magic Garden Explained: The Internals of UNIX System V Release 4 an Open Systems Design. GOODHEART, Berny; COX, James. 1994.
    • The Design of the UNIX Operating System. BACH, Maurice. 1986.
    • Operating Systems: Internals and Design Principles, 9th Edition. STALLINGS, William. 2017.
    • Adicionado pelo tradutor: Operating Systems: Three Easy Pieces. ARPACI-DUSSEAU, Remzi H.; ARPACI-DUSSEAU, Andrea C.. E-book online e gratuito sendo mantido atualizado constantemente. Se encontra na versão 1.10 no momento do lançamento desta tradução.
  • Cursos Recomendados
  • Habilidades Gerais de Programação
  • Design de Hardware
    • Faça seu próprio kit do microprocessador 8086.
      • Se você não fizer seu próprio hardware, você não entenderá o que é um dispositivo físico de memória mapeada.
      • Pontos de acesso modernos incluem muitos IPs, então você não tem a chance de entender como a CPU e os periféricos estão conectados.
      • Fazendo seu próprio kit 8086, você tem uma oportunidade de colocar cada dispositivo periférico na memória física e definir como os componentes de hardware principais (barramentos, interrupções do sistema, clock, alimentação, etc.) funcionam com seus próprios olhos.
      • Eu montei o meu kit na universidade. Foi uma das mais valiosas atividades que eu fiz. Tente fazer seu próprio kit, sendo melhor que o hardware seja mais velho e simples, porque deve lhe dar mais trabalho.
      • Pesquise "kit 8086", você deve achar alguns sites em que pode comprar uma esquema de hardware, partes e manuais.

Existe uma lista infinita de bons livros, e eu não quero dizer que você deve ler todos; leia um com cuidado: fazendo marcações, anotações e pesquisas. Sempre que aprender uma teoria, implemente um código simulando isso. Implementar algo é melhor do que saber 100 teorias.

Languages

Assembly

Choose one between x86 or ARM. No need to know both. It doesn't matter to know assembly language. The essential thing is understanding the internals of a CPU and computer. So you don't need to practice the assembly of the latest CPU. Select 8086 or Corex-M.

C language

There is no shortcut. Just read the entire book and solve all the exercises.

If you want to be expert of C programming, visit https://leetcode.com/. Good luck!

Rust language

I am sure that the next language for the systems programming would be Rust. I will make a list what I did to learn Rust.

Linus Torvalds said "Unless something odd happens, it [Rust] will make it into 6.1."

  • The Rust Programming Language
    • Great introduction, but lack of examples and exercises.
  • Rust by Example
    • While reading "The Rust Programming Language", you can find examples and exercises here.
    • But there are not many exercises you can do something for yourself. Only some examples includes "do-this" exercises and they are very simple.
  • Programming Rust, 2nd
    • Deeper introduction, but still lack of examples and exercises.
  • Exercism
    • Good exercises to practice indivisual features of RUST.
    • I am not sure Mentors are working actively but it would be enough to compare your solution with others.
      • After submitting your solution, you can see other's solutions with "Community solutions" tab (since Exercism V3).
      • Many easy level exercises are for functional feature such as map/filter/any and etc.
  • Easy rust
  • Let's get rusty
    • There are many Youtubers uploading Rust course but I enjoyed this course most.
    • He has been uploading the latest news for Rust. It's worth subscribing.
  • Rust for Linux
    • See the example sources and check how Rust will get into the Linux kernel

Applications

Hardware && Firmware

If you want to be an embedded systems engineer, it would be best to start from a simple hardware kit, rather than starting with the latest ARM chipset.

  • Arduino Start Kit
    • There are many series of Arduinos but "Arduino Start Kit" has the most simple processor(Atmega328P) and guide book
    • Atmega328P has an 8-bit core which is a good place to start digital circuit design and firmware development.
    • You don't need to know how to draw schematics and layouts and assemble the chips.
    • But you do need to know how to read schematics and understand how the chips are connected.
    • Firmware developers should be able to read the schematics and figure out how to send data to the target device.
    • Follow the guide book!
  • 8086 manual
    • If you're a beginner to x86 architecture, 8086 is also very good guide for processor architecture and 80x86 assembly
  • 80386 manual

At this point, you should be good to start the latest ARM or x86 processor.

For example, the Raspberry Pi board has a Cortex-A53 Processor that supports a 64-bit instruction set. This allows you to experience a modern processor architecture with rPi. Yes, you can buy it... but... what are you going to do with it? If you have no target project, you would be likely to throw the board into a drawer and forget it like other gadgets you may have bought before.

So, I recommend one project for you.

I've made a toy kernel that supports 64-bit long mode, paging and very simple context switching. Making a toy kernel is good way to understand modern computer architecture and hardware control.

In fact, you have already the latest processor and the latest hardware devices. Your laptop! Your desktop! You already have all that you need in order to start! You don't need to buy anything. The qemu emulator can emulate the latest ARM processors and Intel processors. So everything you need is already on hand. There are many toy kernels and documents you can refer to. Just install qemu emulator and make a tiny kernel that just boots, turns on paging, and prints some messages.

Other toy kernels:

Linux kernel and device driver

You don't need to make a complete operating system. Join the Linux community and participate in development.

Some resources for Linux kernel and device driver development from beginner to advanced.

References

Check when you need something

Other application

Yes, you might not be interested in Linux or firmware. If so, you can find other applications:

  • Windows systems programming & device drivers
  • Security
  • Reverse engineering

I don't have any knowledge about those applications. Please send me any information for beginners.

Kernels and drivers are not all of low-level programming. One more important application of low-level programming is the software-defined storage or distributed filesystem. Detailed descriptions of them is beyond the scope of this document but there is an excellent course where you can try a simple distributed filesystem.

Future of low-level programming

I do not know the future, but I keep my eye on Rust.

If I could have one week free and alone, I would learn Rust. That is because Rust is the latest language with which I can develop Linux device drivers.

IoT is new trend, so it's worth to check what OSs are for IoT. ARM, Samsung and some companies has their own realtime OS but sadly many of them are closed source. But Linux Foundation also has a solution: Zephyr

Typical cloud servers have many layers; for instance, host OS, kvm driver, qemu process, guest OS and service application. A container has been developed to provide light virtualization. In the near future, a new concept of OS, a so-called library OS or Unikernel, would replace the typical stack of SW for virtualization.

Big data and cloud computing require bigger and bigger storage. Some disks directly attached to server machines cannot satisfy the required capacity, stability and performance. Therefore there has been research to make huge storage systems with many storage machines connected by a high speed network. It used to be focused on making one huge storage volume. But currently they are providing many volumes dedicated for many virtual machines.

How to start?

I received an email asking how to start. There are many information about books, courses and projects in this page. It is my mistake to forget to write how to start. Unfortunately, there is no King's Road to King's Landing. I will just write what I did in order. If you have already done something, please skip it. AGAIN, this is just an example that you could do in order, just in case if you do not know how to start or what to do.

  • Reading OS theory books: at least "The Design of the UNIX Operating System by Maurice J. Bach"
  • Learn assembly and C
  • Do something practical with C
    • C Project Based Tutorials?: Find one or two interesting projects and make your own project.
    • leetcode.com: If you cannot find an interesting project, it would be also good to focus on data structure and algorithm.
  • Do a hardware project
    • Raspberrypi or Arduino does not matter. You need experience to control a hardware directly with only C. ONLY C!
    • I recommend to buy a Atmega128 kit and make a firmware to turn on/off LEDs, detect switch input and display message on the text LCD. Motor control program is also a very good project: for instance, the line tracer.
    • DO NOT use any library. You should make everything on your own, except program downloader.
  • Basic of the Linux kernel
  • Go to the professional field
    • If you want to be a professional Linux Kernel Developer
    • Or find other topics
      • There are many fields where the low-level engineer can work: security, Compiler, Firmware, robot/car and so on

Translation

Please send me the pull request if you'd like to translate this page. I'll list it here.

Who am I?

I'm inspired by google-interview-university. I'd like to share my experience and show a roadmap to becoming a low-level programmer because I have found that these skills are not as common as they once were. In addition, many students and beginners ask me how they could become low-level programmers and Linux kernel engineers.

FYI, I have over 10 years of experience as a low-level programmer:

  • 80x86 Assembly programming
  • Hardware device with Atmel chip and firmware
  • C language system programming for Unix
  • Device driver in Linux
  • Linux kernel: page allocation
  • Linux kernel: block device driver and md module