The translation is temporarily closed for contributions due to maintenance, please come back later.
Context English Portuguese (Brazil) State
The value of <literal>0xfffffff0</literal> is slightly less than 4 GB, so unless the machine has 4 GB of physical memory, it cannot point to a valid memory address. The computer's hardware translates this address so that it points to a <acronym>BIOS</acronym> memory block. O valor de <literal>0xfffffff0</literal> é um pouco menor que 4 GB, portanto, a menos que a máquina tenha 4 GB de memória física, ela não pode apontar para um endereço de memória válido. O hardware do computador traduz esse endereço para que ele aponte para um bloco de memória da <acronym>BIOS</acronym> .
As <filename>boot0</filename> is loaded by the <acronym>BIOS</acronym> to address <literal>0x7C00</literal>, it copies itself to address <literal>0x600</literal> and then transfers control there (recall that it was linked to execute at address <literal>0x600</literal>). The source address, <literal>0x7c00</literal>, is copied to register <literal>%si</literal>. The destination address, <literal>0x600</literal>, to register <literal>%di</literal>. The number of bytes to copy, <literal>512</literal> (the program's size), is copied to register <literal>%cx</literal>. Next, the <literal>rep</literal> instruction repeats the instruction that follows, that is, <literal>movsb</literal>, the number of times dictated by the <literal>%cx</literal> register. The <literal>movsb</literal> instruction copies the byte pointed to by <literal>%si</literal> to the address pointed to by <literal>%di</literal>. This is repeated another 511 times. On each repetition, both the source and destination registers, <literal>%si</literal> and <literal>%di</literal>, are incremented by one. Thus, upon completion of the 512-byte copy, <literal>%di</literal> has the value <literal>0x600</literal>+<literal>512</literal>= <literal>0x800</literal>, and <literal>%si</literal> has the value <literal>0x7c00</literal>+<literal>512</literal>= <literal>0x7e00</literal>; we have thus completed the code <emphasis>relocation</emphasis>. Porque <filename>boot0</filename> é carregado pelo <acronym>BIOS</acronym> para endereçar <literal>0x7C00</literal>, copia-se para endereçar <literal>0x600</literal> e depois transfere o controle para lá (lembre-se de que estava ligado para executar no endereço <literal>0x600</literal>. O endereço de origem, <literal>0x7c00</literal>, é copiado para se registrar <literal>%si</literal>. O endereço de destino, <literal>0x600</literal>, registrar <literal>%di</literal>. O número de bytes para copiar, <literal>512</literal> (tamanho do programa), é copiado para registrar <literal>%cx</literal>. Em seguida, a instrução <literal>rep</literal> repete a instrução que se segue, isto é, <literal>movsb</literal>, o número de vezes ditado pelo registrador <literal>%cx</literal>. A instrução <literal>movsb</literal> copia o byte apontado por <literal>%si</literal> para o endereço apontado por <literal>%di</literal>. Isso é repetido mais 511 vezes. Em cada repetição, os registros de origem e destino, <literal>%si</literal> e <literal>%di</literal>, são incrementados por um. Assim, após a conclusão da cópia de 512 bytes, <literal>%di</literal> tem o valor <literal>0x600</literal> + <literal>512</literal> = <literal>0x800</literal> e <literal>%si</literal> tem o valor <literal>0x7c00</literal> + <literal>512</literal> = <literal>0x7e00</literal>; assim, completamos o código de <emphasis>relocação</emphasis>.
An interrupt is requested with number <literal>0x1a</literal> and argument <literal>0</literal> in register <literal>%ah</literal>. The <acronym>BIOS</acronym> has a predefined set of services, requested by applications as software-generated interrupts through the <literal>int</literal> instruction and receiving arguments in registers (in this case, <literal>%ah</literal>). Here, particularly, we are requesting the number of clock ticks since last midnight; this value is computed by the <acronym>BIOS</acronym> through the <acronym>RTC</acronym> (Real Time Clock). This clock can be programmed to work at frequencies ranging from 2 Hz to 8192 Hz. The <acronym>BIOS</acronym> sets it to 18.2 Hz at startup. When the request is satisfied, a 32-bit result is returned by the <acronym>BIOS</acronym> in registers <literal>%cx</literal> and <literal>%dx</literal> (lower bytes in <literal>%dx</literal>). This result (the <literal>%dx</literal> part) is copied to register <literal>%di</literal>, and the value of the <varname>TICKS</varname> variable is added to <literal>%di</literal>. This variable resides in <filename>boot0</filename> at offset <literal>_TICKS</literal> (a negative value) from register <literal>%bp</literal> (which, recall, points to <literal>0x800</literal>). The default value of this variable is <literal>0xb6</literal> (182 in decimal). Now, the idea is that <filename>boot0</filename> constantly requests the time from the <acronym>BIOS</acronym>, and when the value returned in register <literal>%dx</literal> is greater than the value stored in <literal>%di</literal>, the time is up and the default selection will be made. Since the RTC ticks 18.2 times per second, this condition will be met after 10 seconds (this default behavior can be changed in the <filename>Makefile</filename>). Until this time has passed, <filename>boot0</filename> continually asks the <acronym>BIOS</acronym> for any user input; this is done through <literal>int 0x16</literal>, argument <literal>1</literal> in <literal>%ah</literal>. Uma interrupção é solicitada com o número <literal>0x1a</literal> e argumento <literal> </literal> no registrador <literal>%ah</literal>. A <acronym>BIOS</acronym> possui um conjunto predefinido de serviços, solicitados pelos aplicativos como interrupções geradas por software através de uma instrução <literal>int</literal> e receber argumentos nos registradores (neste caso, <literal>%ah</literal>). Aqui, particularmente, estamos solicitando o número de pulsos de clock desde a última meia-noite; esse valor é computado pela <acronym>BIOS</acronym> por meio do <acronym>RTC</acronym> (Real Time Clock). Este clock pode ser programado para funcionar em frequências que variam de 2 Hz a 8192 Hz. A <acronym>BIOS</acronym> define isso a 18,2 Hz na inicialização. Quando a solicitação é satisfeita, um resultado de 32 bits é retornado pela <acronym>BIOS</acronym> em registradores <literal>%cx</literal> e <literal>%dx</literal> (bytes inferiores em <literal>%dx</literal> ). Este resultado (a parte <literal>%dx</literal>) é copiado para registrador <literal>%di</literal> e o valor das variáveis <varname>TICKS</varname> � adicionado ao <literal>%di</literal> . Esta variável reside em <filename>boot0</filename> no deslocamento <literal>_TICKS</literal> (um valor negativo) do registrador <literal>%pb</literal> (que, lembre-se, aponta para <literal>0x800</literal> ). O valor padrão desta variável é <literal>0xb6</literal> (182 em decimal). Agora, a ideia é que <filename>boot0</filename> constantemente solicita o tempo da <acronym>BIOS</acronym>, e quando o valor retornado no registro <literal>%dx</literal> é maior que o valor armazenado em <literal>%di</literal>, o tempo acabou e a seleção padrão será feita. Como o RTC é de 18,2 vezes por segundo, essa condição será atendida após 10 segundos (esse comportamento padrão pode ser alterado no <filename>Makefile</filename> ). Até que esse tempo tenha passado <filename>boot0</filename> continuamente pede à <acronym>BIOS</acronym> por qualquer entrada do usuário; isso é feito através <literal>int 0x16</literal> argumento <literal>1</literal> em <literal>%ah</literal>.
So <filename>boot1</filename> occupies exactly the first 512 bytes of <filename>boot</filename> and, because <filename>boot</filename> is written to the first sector of the FreeBSD slice, <filename>boot1</filename> fits exactly in this first sector. When <literal>nread</literal> reads the first 16 sectors of the FreeBSD slice, it effectively reads the entire <filename>boot</filename> file <_:footnote-1/>. We will see more details about how <filename>boot</filename> is formed from <filename>boot1</filename> and <filename>boot2</filename> in the next section. Assim <filename>boot1</filename> ocupa exatamente os primeiros 512 bytes de <filename>boot</filename> e porque <filename>boot</filename> é escrito para o primeiro setor da fatia do FreeBSD, <filename>boot1</filename> cabe exatamente neste primeiro setor. Porque <literal>nread</literal> lê os primeiros 16 setores da fatia do FreeBSD, lê efetivamente toda o arquivo <filename>boot</filename> <_:footnote-1/>. Vamos ver mais detalhes sobre como <filename>boot</filename> é formado a partir de <filename>boot1</filename> e <filename>boot2</filename> na próxima seção.
The <acronym>BTX</acronym> Server O servidor <acronym>BTX</acronym>
The <acronym>BIOS</acronym> loads the absolute sector one (the <acronym>MBR</acronym>, or <filename>boot0</filename>), to address <literal>0x7c00</literal> and jumps there. O <acronym>BIOS</acronym> carrega o setor absoluto (o <acronym>MBR</acronym> , ou <filename> boot0 </filename> ), endere�ar <literal> 0x7c00 </literal> e pula l�.
<filename>boot0</filename> relocates itself to <literal>0x600</literal>, the address it was linked to execute, and jumps over there. It then reads the first sector of the FreeBSD slice (which consists of <filename>boot1</filename>) into address <literal>0x7c00</literal> and jumps over there. <filename> boot0 </filename> se muda para <literal> 0x600 </literal> , o endere�o que estava ligado para executar e salta para l�. Ele ent�o l� o primeiro setor da fatia do FreeBSD (que consiste em <filename> boot1 </filename> ) no endere�o <literal> 0x7c00 </literal> e pula ali
<filename>boot1</filename> loads the first 16 sectors of the FreeBSD slice into address <literal>0x8c00</literal>. This 16 sectors, or 8192 bytes, is the whole file <filename>boot</filename>. The file is a concatenation of <filename>boot1</filename> and <filename>boot2</filename>. <filename>boot2</filename>, in turn, contains the <acronym>BTX</acronym> server and the <filename>boot2</filename> client. Finally, a jump is made to address <literal>0x9010</literal>, the entry point of the <acronym>BTX</acronym> server. <filename> boot1 </filename> carrega os primeiros 16 setores da fatia do FreeBSD no endere�o <literal> 0x8c00 </literal> . Este 16 setores, ou 8192 bytes, � o arquivo inteiro <filename> bota </filename> . O arquivo � uma concatena��o de <filename> boot1 </filename> e <filename> boot2 </filename> . <filename> boot2 </filename> , por sua vez, cont�m o servidor <acronym>BTX</acronym> eo <filename> boot2 </filename> cliente. Finalmente, um salto � feito para abordar <literal> 0x9010 </literal> , o ponto de entrada do servidor <acronym>BTX</acronym> .
Before studying the <acronym>BTX</acronym> Server in detail, let us further review how the single, all-in-one <filename>boot</filename> file is created. The way <filename>boot</filename> is built is defined in its <filename>Makefile</filename> (<filename>/usr/src/sys/boot/i386/boot2/Makefile</filename>). Let us look at the rule that creates the <filename>boot</filename> file: Antes de estudar o <acronym>BTX</acronym> Server detalhadamente, vamos revisar ainda mais como o single, all-in-one <filename> bota </filename> arquivo � criado. O caminho <filename> bota </filename> � constru�do � definido em sua <filename> Makefile </filename> ( <filename> / usr / src / sys / boot / i386 / boot2 / Makefile </filename> ). Vamos olhar para a regra que cria o <filename> bota </filename> Arquivo:
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:
To apply the rule for creating <filename>boot1</filename>, <filename>boot1.out</filename> must be resolved. This, in turn, depends on the existence of <filename>boot1.o</filename>. This last file is simply the result of assembling our familiar <filename>boot1.S</filename>, without linking. Now, the rule for creating <filename>boot1.out</filename> is applied. This tells us that <filename>boot1.o</filename> should be linked with <literal>start</literal> as its entry point, and starting at address <literal>0x7c00</literal>. Finally, <filename>boot1</filename> is created from <filename>boot1.out</filename> applying the appropriate rule. This rule is the <filename>objcopy</filename> command applied to <filename>boot1.out</filename>. Note the flags passed to <filename>objcopy</filename>: <literal>-S</literal> tells it to strip all relocation and symbolic information; <literal>-O binary</literal> indicates the output format, that is, a simple, unformatted binary file. Para aplicar a regra para criar <filename> boot1 </filename> , <filename> boot1.out </filename> deve ser resolvido. Isso, por sua vez, depende da exist�ncia de <filename> boot1.o </filename> . Este �ltimo arquivo � simplesmente o resultado da montagem de nosso familiar <filename> boot1.S </filename> , sem vincular. Agora, a regra para criar <filename> boot1.out </filename> � aplicado. Isso nos diz que <filename> boot1.o </filename> deve estar ligado a <literal> come�ar </literal> como seu ponto de entrada, e come�ando no endere�o <literal> 0x7c00 </literal> . Finalmente, <filename> boot1 </filename> � criado a partir de <filename> boot1.out </filename> aplicar a regra apropriada. Esta regra � a <filename> objcopy </filename> comando aplicado a <filename> boot1.out </filename> . Observe as bandeiras passadas para <filename> objcopy </filename> : <literal> -S </literal> diz para remover toda a reloca��o e informa��es simb�licas; <literal> Bin�rio -O </literal> indica o formato de sa�da, isto �, um arquivo bin�rio simples e n�o formatado.
Having <filename>boot1</filename>, let us take a look at how <filename>boot2</filename> is constructed: Tendo <filename> boot1 </filename> , vamos dar uma olhada em como <filename> boot2 </filename> � constru�do:
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:
<filename>sys/boot/i386/boot2/boot2.h</filename> <filename> sys / boot / i386 / boot2 / boot2.h </filename>
#define XREADORG 0x725
#define XREADORG 0x725
Recall that <filename>boot1</filename> was relocated (i.e., copied from <literal>0x7c00</literal> to <literal>0x700</literal>). This relocation will now make sense, because as we will see, the <acronym>BTX</acronym> server reclaims some memory, including the space where <filename>boot1</filename> was originally loaded. However, the <acronym>BTX</acronym> server needs access to <filename>boot1</filename>'s <literal>xread</literal> function; this function, according to the output of <filename>boot2.h</filename>, is at location <literal>0x725</literal>. Indeed, the <acronym>BTX</acronym> server uses the <literal>xread</literal> function from <filename>boot1</filename>'s relocated code. This function is now accessible from within the <filename>boot2</filename> client. Lembre-se que <filename> boot1 </filename> foi realocado (ou seja, copiado de <literal> 0x7c00 </literal> para <literal> 0x700 </literal> ). Essa realoca��o far� agora sentido, porque, como veremos, o servidor <acronym>BTX</acronym> recupera alguma mem�ria, incluindo o espa�o onde <filename> boot1 </filename> foi originalmente carregado. No entanto, o servidor <acronym>BTX</acronym> precisa de acesso a <filename> boot1 </filename> ';s <literal> xread </literal> fun��o; esta fun��o, de acordo com a sa�da de <filename> boot2.h </filename> est� no local <literal> 0x725 </literal> . De fato, o servidor <acronym>BTX</acronym> usa o <literal> xread </literal> fun��o de <filename> boot1 </filename> c�digo realocado. Esta fun��o est� agora acess�vel a partir do <filename> boot2 </filename> cliente.
We next build <filename>boot2.s</filename> from files <filename>boot2.h</filename>, <filename>boot2.c</filename> and <filename>/usr/src/sys/boot/common/ufsread.c</filename>. The rule for this is to compile the code in <filename>boot2.c</filename> (which includes <filename>boot2.h</filename> and <filename>ufsread.c</filename>) into assembly code. Having <filename>boot2.s</filename>, the next rule assembles <filename>boot2.s</filename>, creating the object file <filename>boot2.o</filename>. The next rule directs the linker to link various files (<filename>crt0.o</filename>, <filename>boot2.o</filename> and <filename>sio.o</filename>). Note that the output file, <filename>boot2.out</filename>, is linked to execute at address <literal>0x2000</literal>. Recall that <filename>boot2</filename> will be executed in user mode, within a special user segment set up by the <acronym>BTX</acronym> server. This segment starts at <literal>0xa000</literal>. Also, remember that the <filename>boot2</filename> portion of <filename>boot</filename> was copied to address <literal>0xc000</literal>, that is, offset <literal>0x2000</literal> from the start of the user segment, so <filename>boot2</filename> will work properly when we transfer control to it. Next, <filename>boot2.bin</filename> is created from <filename>boot2.out</filename> by stripping its symbols and format information; boot2.bin is a <emphasis>raw</emphasis> binary. Now, note that a file <filename>boot2.ldr</filename> is created as a 512-byte file full of zeros. This space is reserved for the bsdlabel. Em seguida, constru�mos <filename> boot2.s </filename> de arquivos <filename> boot2.h </filename> , <filename> boot2.c </filename> e <filename> /usr/src/sys/boot/common/ufsread.c </filename> . A regra para isso � compilar o c�digo em <filename> boot2.c </filename> (que inclui <filename> boot2.h </filename> e <filename> ufsread.c </filename> ) no c�digo de montagem. Tendo <filename> boot2.s </filename> , a pr�xima regra � montada <filename> boot2.s </filename> , criando o arquivo objeto <filename> boot2.o </filename> . A pr�xima regra direciona o vinculador para vincular v�rios arquivos ( <filename> crt0.o </filename> , <filename> boot2.o </filename> e <filename> sio.o </filename> ). Note que o arquivo de sa�da, <filename> boot2.out </filename> , est� ligado para executar no endere�o <literal> 0x2000 </literal> . Lembre-se de que <filename> boot2 </filename> ser� executado no modo de usu�rio, dentro de um segmento de usu�rio especial configurado pelo servidor <acronym>BTX</acronym> . Este segmento come�a em <literal> 0xa000 </literal> . Al�m disso, lembre-se de que <filename> boot2 </filename> por��o de <filename> bota </filename> foi copiado para endere�ar <literal> 0xc000 </literal> , isto �, offset <literal> 0x2000 </literal> desde o in�cio do segmento de usu�rio, ent�o <filename> boot2 </filename> funcionar� corretamente quando transferirmos o controle para ele. Pr�ximo, <filename> boot2.bin </filename> � criado a partir de <filename> boot2.out </filename> descascando seus s�mbolos e formando informa��es; boot2.bin � um <emphasis> cru </emphasis> bin�rio. Agora, observe que um arquivo <filename> boot2.ldr </filename> � criado como um arquivo de 512 bytes cheio de zeros. Este espa�o � reservado para o bsdlabel.
Now that we have files <filename>boot1</filename>, <filename>boot2.bin</filename> and <filename>boot2.ldr</filename>, only the <acronym>BTX</acronym> server is missing before creating the all-in-one <filename>boot</filename> file. The <acronym>BTX</acronym> server is located in <filename>/usr/src/sys/boot/i386/btx/btx</filename>; it has its own <filename>Makefile</filename> with its own set of rules for building. The important thing to notice is that it is also compiled as a <emphasis>raw</emphasis> binary, and that it is linked to execute at address <literal>0x9000</literal>. The details can be found in <filename>/usr/src/sys/boot/i386/btx/btx/Makefile</filename>. Agora que temos arquivos <filename> boot1 </filename> , <filename> boot2.bin </filename> e <filename> boot2.ldr </filename> , apenas o servidor <acronym>BTX</acronym> est� ausente antes de criar o all-in-one <filename> bota </filename> Arquivo. O servidor <acronym>BTX</acronym> est� localizado em <filename> / usr / src / sys / boot / i386 / btx / btx </filename> ; tem o seu pr�prio <filename> Makefile </filename> com seu pr�prio conjunto de regras para a constru��o. O importante � notar que tamb�m � compilado como um <emphasis> cru </emphasis> bin�rio, e que est� ligado para executar no endere�o <literal> 0x9000 </literal> . Os detalhes podem ser encontrados em <filename> / usr / src / sys / boot / i386 / btx / btx / Makefile </filename>
Having the files that comprise the <filename>boot</filename> program, the final step is to <emphasis>merge</emphasis> them. This is done by a special program called <filename>btxld</filename> (source located in <filename>/usr/src/usr.sbin/btxld</filename>). Some arguments to this program include the name of the output file (<filename>boot</filename>), its entry point (<literal>0x2000</literal>) and its file format (raw binary). The various files are finally merged by this utility into the file <filename>boot</filename>, which consists of <filename>boot1</filename>, <filename>boot2</filename>, the <literal>bsdlabel</literal> and the <acronym>BTX</acronym> server. This file, which takes exactly 16 sectors, or 8192 bytes, is what is actually written to the beginning of the FreeBSD slice during installation. Let us now proceed to study the <acronym>BTX</acronym> server program. Tendo os arquivos que comp�em o <filename> bota </filename> programa, o passo final � <emphasis> fundir </emphasis> eles. Isso � feito por um programa especial chamado <filename> btxld </filename> (fonte localizada em <filename> /usr/src/usr.sbin/btxld </filename> ). Alguns argumentos para este programa incluem o nome do arquivo de sa�da ( <filename> bota </filename> ), o seu ponto de entrada ( <literal> 0x2000 </literal> ) e seu formato de arquivo (bin�rio bruto). Os v�rios arquivos s�o finalmente mesclados por esse utilit�rio no arquivo <filename> bota </filename> , que consiste em <filename> boot1 </filename> , <filename> boot2 </filename> , a <literal> bsdlabel </literal> e o servidor <acronym>BTX</acronym> . Este arquivo, que leva exatamente 16 setores, ou 8192 bytes, � o que realmente � gravado no in�cio da fatia do FreeBSD durante a instala��o. Vamos agora continuar a estudar o programa do servidor <acronym>BTX</acronym> .