o significado do seguinte código de montagem, help
o seguinte código é de U-boot:
/* Initialize GOT pointer.
** Global symbols can't be resolved before this is done, and as such we can't
** use any global symbols in this code. We use the bal/ move xxx,ra combination to access
** data in a PC relative manner to avoid this. This code will correctly set the
** gp regardless of whether the code has already been relocated or not.
** This code determines the current gp by computing the link time (gp - pc)
** and adding this to the current pc.
** runtime_gp = runtime_pc + (linktime_gp - linktime_pc)
** U-boot is running from the address it is linked at at this time, so this
** general case code is not strictly necessary here.
*/
/*Branch and link to get current PC in ra */
bal 1f
nop
.extern _GLOBAL_OFFSET_TABLE_
.word _GLOBAL_OFFSET_TABLE_ /* This contains the linked address of the GOT */
/* The ra register now contains the runtime address of the above memory location */
.word . - 4 /* This contains the link time address of the previous word,
which is also what the link time expected PC value is */
1:
move gp, ra /* Move current PC into gp register */
lw a5, 0(ra) /* Load linked address of the GOT into a5 */
lw a6, 4(ra) /* Load the link time address of the GOT storage location into a6 */
sub a5, a6 /* Subtract a6 from t1. */
/* a5 now contains the difference between the link-time GOT table address and the link time expected PC */
/* Add this difference to the current PC (copied into gp above) so that gp now has the current runtime
** GOT table address */
daddu gp, a5 # calculate current location of offset table
não entendo 3 directiva acima:
.extern _GLOBAL_OFFSET_TABLE_
.word _GLOBAL_OFFSET_TABLE_ //what the meaning after declaring it as a external symbol?
.word . -4 //and also this one?
TIA
2
Author: Peer Stritzinger, 2011-03-02
1 answers
.extern _GLOBAL_OFFSET_TABLE_
O símbolo está descrito fora desta unidade de compilação. Resolva - o no tempo de ligação.
.word _GLOBAL_OFFSET_TABLE_
Atribua uma palavra com valor de memória e coloque o endereço do símbolo neste local
.word . - 4
Pegue a localização actual, .
, subtraia 4 e coloque esse valor numa palavra de memória. Semelhante ao código anterior, exceto o valor que está sendo colocado neste local está sendo calculado.
Aqui está um link com uma lista de muitos dos montadores Directiva.
2
Author: linuxuser27, 2011-03-02 15:35:25