0

I want to write a small OS to grow my programming skills, which worked to a certain point. Now i try to understand linux 0.01 source code to learn more about it. To compile it i need to translate a certain file (head.s) into nasm syntax because my toolchain dislikes the gas file. That wasn't a big deal (i thought) until i realized that i forgot something.

Piece of code:

_pg_dir:
startup_32:
    movl $0x10,%eax
    mov %ax,%ds
    mov %ax,%es
    mov %ax,%fs
    mov %ax,%gs
    lss _stack_start,%esp
    call setup_idt
    call setup_gdt
    movl $0x10,%eax     # reload all the segment registers
    mov %ax,%ds     # after changing gdt. CS was already
    mov %ax,%es     # reloaded in 'setup_gdt'
    mov %ax,%fs
    mov %ax,%gs
    lss _stack_start,%esp
    xorl %eax,%eax
1:  incl %eax       # check that A20 really IS enabled  ~~~
    movl %eax,0x000000
    cmpl %eax,0x100000
    je 1b                                             ~~~
    movl %cr0,%eax      # check math chip
    andl $0x80000011,%eax   # Save PG,ET,PE
    testl $0x10,%eax
    jne 1f          # ET is set - 387 is present      ~~~
    orl $4,%eax     # else set emulate bit
1:  movl %eax,%cr0                                    ~~~
jmp after_page_tables

"~~~" marks the lines i don't fully understand. The 1b and 1f aren't labels. At least not ones like those i know from intel syntax. How do i have to translate the labels and conditional jumps?

RAVN Mateus
  • 560
  • 3
  • 13
  • 1
    Just give the numbered labels some sensible name. – Jester Sep 13 '20 at 19:02
  • @Jester well the problem is, that there are the labels named 1: in this file, but they are called by 1b and 1f and a second time 1b. which of them calls what? – RAVN Mateus Sep 13 '20 at 19:07
  • Read the GAS manual (https://sourceware.org/binutils/docs/as/Symbol-Names.html), or assemble with `as` and disassemble with a NASM disassembler like `objconv`. (It's 1-forward or 1-backward.) – Peter Cordes Sep 13 '20 at 19:11

1 Answers1

3

These are local labels, a gas-specific feature.

Here 1f refers to the next instance of the 1 label (forward) and 1b refers to the previous instance (backward).

So code like

1:  blah blah
    jmp 1b
    blah blah
    jmp 1f
    blah blah
1:  blah blah

can be rewritten as

xx: blah blah
    jmp xx
    blah blah
    jmp yy
    blah blah
yy: blah blah
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82