The translation is temporarily closed for contributions due to maintenance, please come back later.
Context English Portuguese (Brazil) State
It is worth looking at the <filename>Makefile</filename> for <filename>boot0</filename> (<filename>sys/boot/i386/boot0/Makefile</filename>), as it defines some of the run-time behavior of <filename>boot0</filename>. For instance, if a terminal connected to the serial port (COM1) is used for I/O, the macro <literal>SIO</literal> must be defined (<literal>-DSIO</literal>). <literal>-DPXE</literal> enables boot through <acronym>PXE</acronym> by pressing <keycap>F6</keycap>. Additionally, the program defines a set of <emphasis>flags</emphasis> that allow further modification of its behavior. All of this is illustrated in the <filename>Makefile</filename>. For example, look at the linker directives which command the linker to start the text section at address <literal>0x600</literal>, and to build the output file <quote>as is</quote> (strip out any file formatting): Vale a pena olhar para o <filename>Makefile</filename> para <filename>boot0</filename> (<filename>sys/boot/i386/boot0/Makefile</filename>), uma vez que define um pouco do comportamento em tempo de execução de <filename>boot0</filename>. Por exemplo, se um terminal conectado à porta serial (COM1) for usado para E/S, a macro <literal>SIO</literal> deve ser definido (<literal>-DSIO</literal>). <literal>-DPXE</literal> permite inicializar através do <acronym>PXE</acronym> pressionando <keycap> F6 </keycap>. Além disso, o programa define um conjunto de <emphasis>bandeiras</emphasis> que permitem modificações adicionais de seu comportamento. Tudo isso é ilustrado no <filename>Makefile</filename>. Por exemplo, observe as diretivas do vinculador que comandam o vinculador para iniciar a seção de texto no endereço <literal>0x600</literal> e para construir o arquivo de saída <quote>como é</quote> (tira qualquer formatação de arquivo):
Finally, a jump is performed to <literal>start_input</literal>, where the <acronym>BIOS</acronym> services are used to start a timer and for reading user input from the keyboard; if the timer expires, the default option will be selected: Finalmente, um salto é realizado para <literal>start_input</literal> , onde os serviços da <acronym>BIOS</acronym> são usados ​​para iniciar um timer e para ler a entrada do usuário a partir do teclado; se o temporizador expirar, a opção padrão será selecionada:
Next comes a loop that looks for the FreeBSD slice. Although <filename>boot0</filename> loaded <filename>boot1</filename> from the FreeBSD slice, no information was passed to it about this <_:footnote-1/>, so <filename>boot1</filename> must rescan the partition table to find where the FreeBSD slice starts. Therefore it rereads the <acronym>MBR</acronym>: Em seguida vem um loop que procura a fatia do FreeBSD. Embora <filename>boot0</filename> carregue <filename>boot1</filename> da fatia do FreeBSD, nenhuma informação foi passada para ele sobre isso <_:footnote-1/>, então <filename>boot1</filename> deve varrer novamente a tabela de partições para encontrar onde a fatia do FreeBSD iniciou. Por isso, releia o <acronym>MBR</acronym>:
This tells us that <filename>boot1</filename> and <filename>boot2</filename> are needed, and the rule simply concatenates them to produce a single file called <filename>boot</filename>. The rules for creating <filename>boot1</filename> are also quite simple: Isso nos diz que <filename> boot1 </filename> e <filename> boot2 </filename> s�o necess�rios, e a regra simplesmente concatena-os para produzir um �nico arquivo chamado <filename> bota </filename> . As regras para criar <filename> boot1 </filename> tamb�m s�o bastante simples:
The mechanism for building <filename>boot2</filename> is far more elaborate. Let us point out the most relevant facts. The dependency list is as follows: O mecanismo de constru��o <filename> boot2 </filename> � muito mais elaborado. Vamos mostrar os fatos mais relevantes. A lista de depend�ncias � a seguinte:
Note that initially there is no header file <filename>boot2.h</filename>, but its creation depends on <filename>boot1.out</filename>, which we already have. The rule for its creation is a bit terse, but the important thing is that the output, <filename>boot2.h</filename>, is something like this: Note que inicialmente n�o h� arquivo de cabe�alho <filename> boot2.h </filename> , mas a sua cria��o depende <filename> boot1.out </filename> que j� temos. A regra para sua cria��o � um pouco concisa, mas o importante � que a sa�da, <filename> boot2.h </filename> � algo assim:
Let us now start studying the actual implementation. Recall that <filename>boot1</filename> made a jump to address <literal>0x9010</literal>, the <acronym>BTX</acronym> server's entry point. Before studying program execution there, note that the <acronym>BTX</acronym> server has a special header at address range <literal>0x9000-0x900f</literal>, right before its entry point. This header is defined as follows: Vamos agora come�ar a estudar a implementa��o real. Lembre-se que <filename> boot1 </filename> fez um salto para abordar <literal> 0x9010 </literal> , o ponto de entrada do servidor <acronym>BTX</acronym> . Antes de estudar a execu��o do programa, observe que o servidor <acronym>BTX</acronym> possui um cabe�alho especial na faixa de endere�os <literal> 0x9000-0x900f </literal> , antes do seu ponto de entrada. Esse cabe�alho � definido da seguinte maneira:
Our next code block clears (sets to <literal>0</literal>) the memory range <literal>0x5e00-0x8fff</literal>. This range is where the various data structures will be created: Nosso pr�ximo bloco de c�digo � apagado <literal> 0 </literal> ) o intervalo de mem�ria <literal> 0x5e00-0x8fff </literal> . Este intervalo � onde as v�rias estruturas de dados ser�o criadas:
The next block creates the <acronym>IDT</acronym> (Interrupt Descriptor Table). The <acronym>IDT</acronym> is analogous, in protected mode, to the <acronym>IVT</acronym> in real mode. That is, the <acronym>IDT</acronym> describes the various exception and interrupt handlers used when the processor is executing in protected mode. In essence, it also consists of an array of segment/offset pairs, although the structure is somewhat more complex, because segments in protected mode are different than in real mode, and various protection mechanisms apply: O próximo bloco cria o <acronym>IDT</acronym> (Interrupt Descriptor Table). O <acronym>IDT</acronym> é análogo, no modo protegido, ao <acronym>IVT</acronym> em modo real. Ou seja, o <acronym>IDT</acronym> descreve os vários manipuladores de exceção e interrupções usados ​​quando o processador está executando em modo protegido. Em essência, ele também consiste em uma matriz de pares segmento/deslocadores, embora a estrutura seja um pouco mais complexa, porque os segmentos no modo protegido são diferentes do modo real, e vários mecanismos de proteção se aplicam:
<literal>boot2</literal> defines an important structure, <literal>struct bootinfo</literal>. This structure is initialized by <literal>boot2</literal> and passed to the loader, and then further to the kernel. Some nodes of this structures are set by <literal>boot2</literal>, the rest by the loader. This structure, among other information, contains the kernel filename, <acronym>BIOS</acronym> harddisk geometry, <acronym>BIOS</acronym> drive number for boot device, physical memory available, <literal>envp</literal> pointer etc. The definition for it is: <literal> boot2 </literal> define uma estrutura importante, <literal> struct bootinfo </literal> . Essa estrutura � inicializada por <literal> boot2 </literal> e passou para o carregador e depois para o kernel. Alguns n�s desta estrutura s�o definidos por <literal> boot2 </literal> , o resto pelo carregador. Esta estrutura, entre outras informa��es, cont�m o nome do arquivo do kernel, <acronym>BIOS</acronym> geometria disco r�gido, n�mero da unidade <acronym>BIOS</acronym> para dispositivo de inicializa��o, mem�ria f�sica dispon�vel, <literal> envp </literal> ponteiro etc. A defini��o para isso �:
<literal>boot2</literal> enters into an infinite loop waiting for user input, then calls <function>load()</function>. If the user does not press anything, the loop breaks by a timeout, so <function>load()</function> will load the default file (<filename>/boot/loader</filename>). Functions <function>ino_t lookup(char *filename)</function> and <function>int xfsread(ino_t inode, void *buf, size_t nbyte)</function> are used to read the content of a file into memory. <filename>/boot/loader</filename> is an <acronym>ELF</acronym> binary, but where the <acronym>ELF</acronym> header is prepended with <filename>a.out</filename>'s <literal>struct exec</literal> structure. <function>load()</function> scans the loader's ELF header, loading the content of <filename>/boot/loader</filename> into memory, and passing the execution to the loader's entry: <literal> boot2 </literal> entra em um loop infinito esperando por entrada do usu�rio, ent�o chama <function> carga() </function> . Se o usu�rio n�o pressionar nada, o loop ser� interrompido por um tempo limite, <function> carga() </function> ir� carregar o arquivo padr�o ( <filename> / boot / loader </filename> ). Fun��es <function> pesquisa ino_t (char * filename) </function> e <function> int xfsread (inodo_t inode, void * buf, tamanho_t nbyte) </function> s�o usados ​​para ler o conte�do de um arquivo na mem�ria. <filename> / boot / loader </filename> � um bin�rio <acronym>ELF</acronym> , mas onde o cabe�alho <acronym>ELF</acronym> � prefixado com <filename> a.out </filename> ';s <literal> struct exec </literal> estrutura. <function> carga() </function> varre o cabe�alho ELF do carregador, carregando o conte�do do <filename> / boot / loader </filename> na mem�ria e passando a execu��o para a entrada do carregador:
says that a kernel's entry point is the symbol `btext'. This symbol is defined in <filename>locore.s</filename>: diz que o ponto de entrada de um kernel � o s�mbolo" btext ". Este s�mbolo � definido em <filename> locore.s </filename> :
btext calls the routines <function>recover_bootinfo()</function>, <function>identify_cpu()</function>, <function>create_pagetables()</function>, which are also defined in <filename>locore.s</filename>. Here is a description of what they do: btext chama as rotinas <function> recover_bootinfo () </function> , <function> identify_cpu () </function> , <function> create_pagetables () </function> , que tamb�m s�o definidos em <filename> locore.s </filename> . Aqui est� uma descri��o do que eles fazem:
The function <function>init386()</function> is called with a pointer to the first free physical page, after that <function>mi_startup()</function>. <function>init386</function> is an architecture dependent initialization function, and <function>mi_startup()</function> is an architecture independent one (the 'mi_' prefix stands for Machine Independent). The kernel never returns from <function>mi_startup()</function>, and by calling it, the kernel finishes booting: A fun��o <function> init386 () </function> � chamado com um ponteiro para a primeira p�gina f�sica livre, depois disso <function> mi_startup () </function> . <function> init386 </function> � uma fun��o de inicializa��o dependente da arquitetura e <function> mi_startup () </function> � uma arquitetura independente (o prefixo ';mi_'; significa Independente da M�quina). O kernel nunca retorna de <function> mi_startup () </function> e, ao cham�-lo, o kernel conclui a inicializa��o:
<function>init386()</function> is defined in <filename>sys/i386/i386/machdep.c</filename> and performs low-level initialization specific to the i386 chip. The switch to protected mode was performed by the loader. The loader has created the very first task, in which the kernel continues to operate. Before looking at the code, consider the tasks the processor must complete to initialize protected mode execution: <function> init386 () </function> � definido em <filename> sys / i386 / i386 / machdep.c </filename> e executa inicializa��o de baixo n�vel espec�fica para o chip i386. A mudan�a para o modo protegido foi realizada pelo carregador. O carregador criou a primeira tarefa, na qual o kernel continua a operar. Antes de examinar o c�digo, considere as tarefas que o processador deve concluir para inicializar a execu��o do modo protegido:
<function>init_param1()</function> is defined in <filename>sys/kern/subr_param.c</filename>. That file has a number of sysctls, and two functions, <function>init_param1()</function> and <function>init_param2()</function>, that are called from <function>init386()</function>: <function> init_param1 () </function> � definido em <filename> sys / kern / subr_param.c </filename> . Esse arquivo tem um n�mero de sysctls e duas fun��es, <function> init_param1 () </function> e <function> init_param2 () </function> , que s�o chamados de <function> init386 () </function> :
Then <function>init386()</function> prepares the Global Descriptors Table (GDT). Every task on an x86 is running in its own virtual address space, and this space is addressed by a segment:offset pair. Say, for instance, the current instruction to be executed by the processor lies at CS:EIP, then the linear virtual address for that instruction would be <quote>the virtual address of code segment CS</quote> + EIP. For convenience, segments begin at virtual address 0 and end at a 4Gb boundary. Therefore, the instruction's linear virtual address for this example would just be the value of EIP. Segment registers such as CS, DS etc are the selectors, i.e., indexes, into GDT (to be more precise, an index is not a selector itself, but the INDEX field of a selector). FreeBSD's GDT holds descriptors for 15 selectors per CPU: Ent�o <function> init386 () </function> prepara a Tabela de Descritores Globais (GDT). Toda tarefa em um x86 est� sendo executada em seu pr�prio espa�o de endere�o virtual e esse espa�o � endere�ado por um par segmento: offset. Digamos, por exemplo, que a instru��o atual a ser executada pelo processador esteja em CS: EIP, ent�o o endere�o virtual linear para aquela instru��o seria <quote> o endere�o virtual do segmento de c�digo CS </quote> + EIP. Por conveni�ncia, os segmentos come�am no endere�o virtual 0 e terminam em um limite de 4 Gb. Portanto, o endere�o virtual linear da instru��o para este exemplo seria apenas o valor de EIP. Registros de segmento como CS, DS etc. s�o os seletores, isto �, �ndices, em GDT (para ser mais preciso, um �ndice n�o � um seletor em si, mas o campo INDEX de um seletor). O GDT do FreeBSD possui descritores para 15 seletores por CPU:
The next step is to initialize the Interrupt Descriptor Table (IDT). This table is referenced by the processor when a software or hardware interrupt occurs. For example, to make a system call, user application issues the <literal>INT 0x80</literal> instruction. This is a software interrupt, so the processor's hardware looks up a record with index 0x80 in the IDT. This record points to the routine that handles this interrupt, in this particular case, this will be the kernel's syscall gate. The IDT may have a maximum of 256 (0x100) records. The kernel allocates NIDT records for the IDT, where NIDT is the maximum (256): O pr�ximo passo � inicializar a Tabela de Descritores de Interrup��es (IDT). Essa tabela � referenciada pelo processador quando ocorre uma interrup��o de software ou hardware. Por exemplo, para fazer uma chamada de sistema, o aplicativo de usu�rio emite a <literal> INT 0x80 </literal> instru��o. Esta � uma interrup��o de software, portanto, o hardware do processador procura um registro com o �ndice 0x80 no IDT. Este registro aponta para a rotina que lida com esta interrup��o, neste caso particular, este ser� o syscall do kernel. O IDT pode ter um m�ximo de 256 (0x100) registros. O kernel aloca registros NIDT para o IDT, onde NIDT � o m�ximo (256):
For each interrupt, an appropriate handler is set. The syscall gate for <literal>INT 0x80</literal> is set as well: Para cada interrup��o, um manipulador apropriado � definido. O syscall gate para <literal> INT 0x80 </literal> est� definido tamb�m:
Next, proc0's Process Control Block (<literal>struct pcb</literal>) structure is initialized. proc0 is a <literal>struct proc</literal> structure that describes a kernel process. It is always present while the kernel is running, therefore it is declared as global: Em seguida, o bloco de controle de processo do proc0 ( <literal> pcb struct </literal> ) estrutura � inicializada. proc0 � um <literal> struct proc </literal> estrutura que descreve um processo do kernel. Est� sempre presente enquanto o kernel est� rodando, portanto � declarado como global: