instructions in masterboot.s - Minix

This is a discussion on instructions in masterboot.s - Minix ; Hi all, I'm trying to understand masterboot.s (2.0 version), but now that I've reached the line 122 I'm not be able to go forward. The line, in load0 label, is the follow: mov si, #BUFFER+zero-lowsec ! si = where lowsec(si) ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: instructions in masterboot.s

  1. instructions in masterboot.s

    Hi all,
    I'm trying to understand masterboot.s (2.0 version), but now that I've
    reached the line 122 I'm not be able to go forward. The line, in load0
    label, is the follow:

    mov si, #BUFFER+zero-lowsec ! si = where lowsec(si)

    My ask is: which is the value in si after that instruction?

    I guess: si = 0x05F8....

    Besides in lines 146 and 147 we have:

    mov ax, lowsec+0(si)
    mov dx, lowsec+2(si) ! dx:ax = sector within drive

    I don't know that syntax ( lowsec+0(si) ); how does it work?

    Thank you in advance.

    Regards,
    Luca.

  2. Re: instructions in masterboot.s

    Riff_451 dixit:

    >mov ax, lowsec+0(si)
    >mov dx, lowsec+2(si) ! dx:ax = sector within drive
    >
    >I don't know that syntax ( lowsec+0(si) ); how does it work?


    I assume these are the following insns in the more common format:
    mov ax,lowsec+0[si]
    mov dx,lowsec+2[si]

    This is easy. The displacement is either lowsec+0 or lowsec+2,
    then it is converted to a register plus displacement operation.
    It could be rewritten as
    mov ax,[si+lowsec]
    mov dx,[si+(lowsec+2)]
    which I hope you recognise more easily. My guess is that this
    alternate syntax has been chosen to mimic structs.

    //mirabilos
    --
    Sometimes they [people] care too much: pretty printers [and syntax highligh-
    ting, d.A.] mechanically produce pretty output that accentuates irrelevant
    detail in the program, which is as sensible as putting all the prepositions
    in English text in bold font. -- Rob Pike in "Notes on Programming in C"

  3. Re: instructions in masterboot.s

    Thanks Thorsten, and what about the first instruction?

    mov si, #BUFFER+zero-lowsec ! si = where lowsec(si) is zero

    BUFFER = 0x0600
    lowsec = 8

    zero: .data4 0

    which is the word in si after that?


  4. Re: instructions in masterboot.s

    Riff_451 va escriure en
    news:34fb6b37-4716-4222-8245-5e1ff8f6b854@v72g2000hsv.googlegroups.com,
    > I'm trying to understand masterboot.s (2.0 version), but now that I've
    > reached the line 122 I'm not be able to go forward. The line, in load0
    > label, is the follow:
    >
    > mov si, #BUFFER+zero-lowsec ! si = where lowsec(si)
    >
    > My ask is: which is the value in si after that instruction?


    "lowsec" (8) bytes before the address of variable zero. The "lowsec"
    negative offset is because the code below (which was coded earlier) used
    SI+lowsec as base address for the variable, so this addition was carefully
    crafted to point at the "right" place in order for the subsequent code to
    aim at the "correct" place, which is the zero variable (a 4-byte variable,
    so a double-word for this 16-bit code.)


    > I guess: si = 0x05F8....


    Bad guess. Furthermore, there is no need to guess, you can either assemble
    masterboot.s asking for the listing (depending on the assembler you're
    using, maybe not available possibility for you), or even easier just look at
    the binary (in mine it's at offset 0x9B for my 2.0.4) and you'll find the
    right answer (which happen to be 0x0766, again for my 2.0.4)


    > Besides in lines 146 and 147 we have:
    >
    > mov ax, lowsec+0(si)
    > mov dx, lowsec+2(si) ! dx:ax = sector within drive
    >
    > I don't know that syntax ( lowsec+0(si) ); how does it work?


    Indexed with offset, so points "lowsec" (=8) bytes or lowsec+2 (=10) after
    where is currently pointing SI.
    In the normal (MBR) case, this would aim at the "offset sector" in the IBM
    partition table design; in the crafted case you signalled above, it would
    aim at the zero variable, which happen to be zero-initialized, so it
    effectively zeroes out AX and DX.


    Antoine


  5. Re: instructions in masterboot.s

    Thank you Antoine.
    Now I know that I have to study addressing methods more and more and
    more...


+ Reply to Thread