This is retarded, GAS supports Intel syntax. Why did this require
rewriting everything in AT&T syntax and introducing bugs? And what's
up with calling AT&T syntax "GAS" Syntax.
I wonder what Brian would say....
It's funny how this project gets rid of old developers, gets new
developers, and has them make the same mistakes/idiotic things the old
developers left for in the first place...
Good job!
Best regards,
Alex Ionescu
On Thu, Sep 2, 2010 at 10:39 AM,  <akhaldi(a)svn.reactos.org> wrote:
  Author: akhaldi
 Date: Thu Sep  2 17:39:45 2010
 New Revision: 48687
 URL: 
http://svn.reactos.org/svn/reactos?rev=48687&view=rev
 Log:
 [FREELDR]
 - Convert fat12/16 boot sector helper code to gas syntax. Brought to you by the Arty.
 [CMAKE]
 - Add freeldr and setupldr to build.
 Added:
    branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S
      - copied, changed from r48568,
branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm
 Removed:
    branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm
 Modified:
    branches/cmake-bringup/boot/CMakeLists.txt
 Modified: branches/cmake-bringup/boot/CMakeLists.txt
 URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/boot/CMakeLists.t…
 ==============================================================================
 --- branches/cmake-bringup/boot/CMakeLists.txt [iso-8859-1] (original)
 +++ branches/cmake-bringup/boot/CMakeLists.txt [iso-8859-1] Thu Sep  2 17:39:45 2010
 @@ -5,3 +5,203 @@
  CreateBootSectorTarget(fat ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/bootsect/fat.asm
${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/fat.bin)
  CreateBootSectorTarget(isoboot ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/bootsect/isoboot.asm
${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/isoboot.bin)
  CreateBootSectorTarget(isobtrt ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/bootsect/isobtrt.asm
${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/isobtrt.bin)
 +
 +include_directories(BEFORE freeldr/freeldr/include)
 +include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
 +
 +if(ARCH MATCHES i386)
 +list(APPEND FREELDR_STARTUP_SOURCE
 +    freeldr/freeldr/arch/i386/fathelp.S
 +    freeldr/freeldr/arch/i386/arch.S)
 +elseif(ARCH MATCHES amd64)
 +list(APPEND FREELDR_STARTUP_SOURCE
 +    freeldr/freeldr/arch/amd64/fathelp.S
 +    freeldr/freeldr/arch/amd64/arch.S)
 +endif(ARCH MATCHES i386)
 +
 +if(ARCH MATCHES i386)
 +list(APPEND FREELDR_BASE64K_SOURCE
 +    freeldr/freeldr/arch/i386/boot.S
 +    freeldr/freeldr/arch/i386/drvmap.S
 +    freeldr/freeldr/arch/i386/i386cpu.S
 +    freeldr/freeldr/arch/i386/i386idt.S
 +    freeldr/freeldr/arch/i386/i386pnp.S
 +    freeldr/freeldr/arch/i386/i386trap.S
 +    freeldr/freeldr/arch/i386/int386.S
 +    freeldr/freeldr/arch/i386/linux.S
 +    freeldr/freeldr/arch/i386/mb.S)
 +elseif(ARCH MATCHES amd64)
 +list(APPEND FREELDR_BASE64K_SOURCE
 +    freeldr/freeldr/arch/amd64/drvmap.S
 +    freeldr/freeldr/arch/amd64/i386cpu.S
 +    freeldr/freeldr/arch/amd64/i386idt.S
 +    freeldr/freeldr/arch/amd64/i386trap.S
 +    freeldr/freeldr/arch/amd64/mb.S)
 +endif(ARCH MATCHES i386)
 +
 +set_source_files_properties(${FREELDR_BASE64K_SOURCE} PROPERTIES COMPILE_DEFINITIONS
"_NTHAL_")
 +
 +include_directories(${REACTOS_SOURCE_DIR}/lib/cmlib)
 +
 +list(APPEND FREELDR_BASE_SOURCE
 +    freeldr/freeldr/arcemul/mm.c
 +    freeldr/freeldr/arcemul/time.c
 +    freeldr/freeldr/cache/blocklist.c
 +    freeldr/freeldr/cache/cache.c
 +    freeldr/freeldr/comm/rs232.c
 +    freeldr/freeldr/disk/disk.c
 +    freeldr/freeldr/disk/partition.c
 +    freeldr/freeldr/disk/ramdisk.c
 +    freeldr/freeldr/fs/ext2.c
 +    freeldr/freeldr/fs/fat.c
 +    freeldr/freeldr/fs/fs.c
 +    freeldr/freeldr/fs/iso.c
 +    freeldr/freeldr/fs/ntfs.c
 +    freeldr/freeldr/inifile/ini_init.c
 +    freeldr/freeldr/inifile/inifile.c
 +    freeldr/freeldr/inifile/parse.c
 +    freeldr/freeldr/mm/meminit.c
 +    freeldr/freeldr/mm/mm.c
 +    freeldr/freeldr/reactos/registry.c
 +    freeldr/freeldr/reactos/arcname.c
 +    freeldr/freeldr/reactos/archwsup.c
 +    freeldr/freeldr/reactos/binhive.c
 +    freeldr/freeldr/reactos/reactos.c
 +    freeldr/freeldr/reactos/imageldr.c
 +    freeldr/freeldr/rtl/bget.c
 +    freeldr/freeldr/rtl/libsupp.c
 +    freeldr/freeldr/ui/directui.c
 +    freeldr/freeldr/ui/gui.c
 +    freeldr/freeldr/ui/minitui.c
 +    freeldr/freeldr/ui/noui.c
 +    freeldr/freeldr/ui/tui.c
 +    freeldr/freeldr/ui/tuimenu.c
 +    freeldr/freeldr/ui/ui.c
 +    freeldr/freeldr/video/fade.c
 +    freeldr/freeldr/video/palette.c
 +    freeldr/freeldr/video/video.c
 +    freeldr/freeldr/windows/conversion.c
 +    freeldr/freeldr/windows/peloader.c
 +    freeldr/freeldr/windows/winldr.c
 +    freeldr/freeldr/windows/wlmemory.c
 +    freeldr/freeldr/windows/wlregistry.c
 +    freeldr/freeldr/freeldr.c
 +    freeldr/freeldr/debug.c
 +    freeldr/freeldr/version.c
 +    freeldr/freeldr/cmdline.c
 +    freeldr/freeldr/machine.c
 +    freeldr/freeldr/options.c
 +    freeldr/freeldr/linuxboot.c
 +    freeldr/freeldr/oslist.c)
 +
 +if(ARCH MATCHES i386)
 +list(APPEND FREELDR_BASE_SOURCE freeldr/freeldr/disk/scsiport.c)
 +endif(ARCH MATCHES i386)
 +
 +set_source_files_properties(${FREELDR_BASE_SOURCE} PROPERTIES COMPILE_DEFINITIONS
"_NTHAL_;_BLDR_;_NTSYSTEM_")
 +
 +include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs)
 +include_directories(${REACTOS_SOURCE_DIR}/include/reactos/elf)
 +
 +if(ARCH MATCHES i386)
 +list(APPEND FREELDR_ARCH_SOURCE
 +    freeldr/freeldr/arch/i386/_alloca.S
 +    freeldr/freeldr/arch/i386/archmach.c
 +    freeldr/freeldr/arch/i386/custom.c
 +    freeldr/freeldr/arch/i386/drivemap.c
 +    freeldr/freeldr/arch/i386/halstub.c
 +    freeldr/freeldr/arch/i386/hardware.c
 +    freeldr/freeldr/arch/i386/hwacpi.c
 +    freeldr/freeldr/arch/i386/hwapm.c
 +    freeldr/freeldr/arch/i386/hwpci.c
 +    freeldr/freeldr/arch/i386/i386disk.c
 +    freeldr/freeldr/arch/i386/i386rtl.c
 +    freeldr/freeldr/arch/i386/i386vid.c
 +    freeldr/freeldr/arch/i386/loader.c
 +    freeldr/freeldr/arch/i386/machpc.c
 +    freeldr/freeldr/arch/i386/miscboot.c
 +    freeldr/freeldr/arch/i386/ntoskrnl.c
 +    freeldr/freeldr/arch/i386/pccons.c
 +    freeldr/freeldr/arch/i386/pcdisk.c
 +    freeldr/freeldr/arch/i386/pcmem.c
 +    freeldr/freeldr/arch/i386/pcrtc.c
 +    freeldr/freeldr/arch/i386/pcvideo.c
 +    freeldr/freeldr/arch/i386/machxbox.c
 +    freeldr/freeldr/arch/i386/xboxcons.c
 +    freeldr/freeldr/arch/i386/xboxdisk.c
 +    freeldr/freeldr/arch/i386/xboxfont.c
 +    freeldr/freeldr/arch/i386/xboxhw.c
 +    freeldr/freeldr/arch/i386/xboxi2c.c
 +    freeldr/freeldr/arch/i386/xboxmem.c
 +    freeldr/freeldr/arch/i386/xboxrtc.c
 +    freeldr/freeldr/arch/i386/xboxvideo.c
 +    freeldr/freeldr/windows/i386/ntsetup.c
 +    freeldr/freeldr/windows/i386/wlmemory.c)
 +else()
 +#TBD
 +endif(ARCH MATCHES i386)
 +
 +set_source_files_properties(${FREELDR_ARCH_SOURCE} PROPERTIES COMPILE_DEFINITIONS
"_NTHAL_;_BLDR_;_NTSYSTEM_")
 +
 +list(APPEND SETUPLDR_MAIN_SOURCE
 +    freeldr/freeldr/bootmgr.c
 +    freeldr/freeldr/inffile/inffile.c
 +    freeldr/freeldr/reactos/setupldr.c)
 +
 +if(ARCH MATCHES i386)
 +list(APPEND SETUPLDR_MAIN_SOURCE freeldr/freeldr/windows/setupldr2.c)
 +elseif(ARCH MATCHES amd64)
 +list(APPEND SETUPLDR_MAIN_SOURCE freeldr/freeldr/windows/setupldr2.c)
 +endif(ARCH MATCHES i386)
 +
 +set_source_files_properties(${SETUPLDR_MAIN_SOURCE} PROPERTIES COMPILE_DEFINITIONS
"_NTHAL_;FREELDR_REACTOS_SETUP" COMPILE_FLAGS "-ffreestanding -fno-builtin
-fno-inline -fno-zero-initialized-in-bss")
 +
 +set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER>
<CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS>
<CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS>
<LINK_LIBRARIES>")
 +
 +list(APPEND FREELDR_SOURCE
 +    freeldr/freeldr/bootmgr.c
 +    ${FREELDR_STARTUP_SOURCE}
 +    ${FREELDR_BASE64K_SOURCE}
 +    ${FREELDR_BASE_SOURCE}
 +    ${FREELDR_ARCH_SOURCE})
 +
 +add_library(freeldr SHARED
 +    ${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch
 +    ${FREELDR_SOURCE})
 +
 +set_target_properties(freeldr PROPERTIES LINK_FLAGS "-Wl,--strip-all
-Wl,-entry,_mainCRTStartup -Wl,--image-base,0x8000 -Wl,--exclude-all-symbols
-Wl,--subsystem,native" SUFFIX ".sys")
 +
 +if(ARCH MATCHES i386)
 +target_link_libraries(freeldr mini_hal)
 +endif(ARCH MATCHES i386)
 +
 +target_link_libraries(freeldr
 +    rossym
 +    cmlib
 +    rtl
 +    libcntpr)
 +add_pch(freeldr ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/freeldr/include/freeldr.h
${FREELDR_SOURCE})
 +
 +list(APPEND SETUPLDR_SOURCE
 +    ${FREELDR_STARTUP_SOURCE}
 +    ${FREELDR_BASE64K_SOURCE}
 +    ${FREELDR_BASE_SOURCE}
 +    ${FREELDR_ARCH_SOURCE}
 +    ${SETUPLDR_MAIN_SOURCE})
 +
 +add_library(setupldr SHARED
 +    ${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch
 +    ${SETUPLDR_SOURCE})
 +
 +set_target_properties(setupldr PROPERTIES LINK_FLAGS "-Wl,--strip-all
-Wl,-entry,_mainCRTStartup -Wl,--image-base,0x8000 -Wl,--exclude-all-symbols
-Wl,--subsystem,native" SUFFIX ".sys")
 +
 +if(ARCH MATCHES i386)
 +target_link_libraries(setupldr mini_hal)
 +endif(ARCH MATCHES i386)
 +
 +target_link_libraries(setupldr
 +    rossym
 +    cmlib
 +    rtl
 +    libcntpr)
 +add_pch(setupldr ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/freeldr/include/freeldr.h
${SETUPLDR_SOURCE})
 Copied: branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S (from r48568,
branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm)
 URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/boot/freeldr/free…
 ==============================================================================
 --- branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm [iso-8859-1]
(original)
 +++ branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.S [iso-8859-1] Thu Sep
 2 17:39:45 2010
 @@ -1,226 +1,222 @@
 -; FATHELP.ASM
 -; FAT12/16 Boot Sector Helper Code
 -; Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer
 -
 -
 -
 -;org 8000h
 -
 -segment .text
 -
 -bits 16
 -
 -
 -BootSectorStackTop             equ             0x7bf2
 -DataAreaStartHigh              equ             0x2
 -DataAreaStartLow               equ             0x4
 -BiosCHSDriveSizeHigh   equ             0x6
 -BiosCHSDriveSizeLow            equ             0x8
 -BiosCHSDriveSize               equ             0x8
 -ReadSectorsOffset              equ             0xa
 -ReadClusterOffset              equ             0xc
 -PutCharsOffset                 equ             0xe
 -
 -OEMName                                        equ             3
 -BytesPerSector                 equ             11
 -SectsPerCluster                        equ             13
 -ReservedSectors                        equ             14
 -NumberOfFats                   equ             16
 -MaxRootEntries                 equ             17
 -TotalSectors                   equ             19
 -MediaDescriptor                        equ             21
 -SectorsPerFat                  equ             22
 -SectorsPerTrack                        equ             24
 -NumberOfHeads                  equ             26
 -HiddenSectors                  equ             28
 -TotalSectorsBig                        equ             32
 -BootDrive                              equ             36
 -Reserved                               equ             37
 -ExtendSig                              equ             38
 -SerialNumber                   equ             39
 -VolumeLabel                            equ             43
 -FileSystem                             equ             54
 -
 -BootPartition                  equ             0x7dfd
 +// FATHELP.ASM
 +// FAT12/16 Boot Sector Helper Code
 +// Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer
 +
 +               .text
 +               .code16
 +               .intel_syntax
 +
 +#define BootSectorStackTop             0x7bf2
 +#define DataAreaStartHigh              0x2
 +#define DataAreaStartLow               0x4
 +#define BiosCHSDriveSizeHigh   0x6
 +#define BiosCHSDriveSizeLow            0x8
 +#define BiosCHSDriveSize               0x8
 +#define ReadSectorsOffset              0xa
 +#define ReadClusterOffset              0xc
 +#define PutCharsOffset                 0xe
 +
 +#define OEMName                                                        3
 +#define BytesPerSector                                 11
 +#define SectsPerCluster                                        13
 +#define ReservedSectors                                        14
 +#define NumberOfFats                                   16
 +#define MaxRootEntries                                 17
 +#define TotalSectors                                   19
 +#define MediaDescriptor                                        21
 +#define SectorsPerFat                                  22
 +#define SectorsPerTrack                                        24
 +#define NumberOfHeads                                  26
 +#define HiddenSectors                                  28
 +#define TotalSectorsBig                                        32
 +#define BootDrive                                              36
 +#define Reserved                                               37
 +#define ExtendSig                                              38
 +#define SerialNumber                                   39
 +#define VolumeLabel                                            43
 +#define FileSystem                                             54
 +
 +#define BootPartition                                  0x7dfd
 -; This code will be stored in the first 512 bytes
 -; of freeldr.sys. The first 3 bytes will be a jmp
 -; instruction to skip past the FAT helper code
 -; that is stored in the rest of the 512 bytes.
 -;
 -; This code is loaded at 0000:8000 so we have to
 -; encode a jmp instruction to jump to 0000:8200
 -
 -global _mainCRTStartup ; For Mingw32 builds where the linker looks for this symbol
 +// This code will be stored in the first 512 bytes
 +// of freeldr.sys. The first 3 bytes will be a jmp
 +// instruction to skip past the FAT helper code
 +// that is stored in the rest of the 512 bytes.
 +//
 +// This code is loaded at 0000:8000 so we have to
 +// encode a jmp instruction to jump to 0000:8200
 +
 +.globl _mainCRTStartup                                         /* For Mingw32 builds
where the linker looks for this symbol */
  _mainCRTStartup:
 -global start
 +.globl start
  start:
 -        db     0xe9
 -               db      0xfd
 -               db      0x01
 -
 -; Now starts the extra boot code that we will store
 -; in the first 512 bytes of freeldr.sys. This code
 -; allows the FAT12/16 bootsector to navigate the
 -; FAT table so that we can still load freeldr.sys
 -; even if it is fragmented.
 +               .byte   0xe9
 +               .byte   0xfd
 +               .byte   0x01
 +
 +// Now starts the extra boot code that we will store
 +// in the first 512 bytes of freeldr.sys. This code
 +// allows the FAT12/16 bootsector to navigate the
 +// FAT table so that we can still load freeldr.sys
 +// even if it is fragmented.
  FatHelperEntryPoint:
 -               push ax                                                 ; First save AX -
the start cluster of freeldr.sys
 -
 -
 -               ; Display "Loading FreeLoader..." message
 -        mov  esi,msgLoading                            ; Loading message
 -        call [bp-PutCharsOffset]               ; Display it
 +               push %ax                                                        /* First
save AX - the start cluster of freeldr.sys */
 +
 +
 +               // Display "Loading FreeLoader..." message
 +        mov  %esi,msgLoading                           /* Loading message */
 +        call [%bp-PutCharsOffset]                      /* Display it */
                call ReadFatIntoMemory
 -               pop  ax                                                 ; Restore AX
(start cluster)
 -               ; AX has start cluster of freeldr.sys
 -
 -        mov  bx,800h
 -        mov  es,bx
 +               pop  %ax                                                        /*
Restore AX (start cluster) */
 +               // AX has start cluster of freeldr.sys
 +
 +        mov  %bx,0x800
 +        mov  %es,%bx
  LoadFile:
 -               push ax
 +               push %ax
                call IsFat12
 -               pop  ax
 +               pop  %ax
                jnc  LoadFile2
 -               cmp  ax,0ff8h               ; Check to see if this is the last cluster in
the chain
 +               cmp  %ax,0xff8                                          /* Check to see
if this is the last cluster in the chain */
                jmp  LoadFile3
  LoadFile2:
 -               cmp  ax,0fff8h
 +               cmp  %ax,0xfff8
  LoadFile3:
 -               jae      LoadFile_Done          ; If so continue, if not then read then
next one
 -               push ax
 -        xor  bx,bx              ; Load ROSLDR starting at 0000:8000h
 -               push es
 -               call [bp-ReadClusterOffset]
 -               pop  es
 -
 -               xor  bx,bx
 -        mov  bl,BYTE [BYTE bp+SectsPerCluster]
 -               shl  bx,5                                                       ; BX = BX
* 512 / 16
 -               mov  ax,es                                                      ;
Increment the load address by
 -               add  ax,bx                                                      ; The
size of a cluster
 -               mov  es,ax
 +               jae      LoadFile_Done                                  /* If so
continue, if not then read then next one */
 +               push %ax
 +        xor  %bx,%bx                                           /* Load ROSLDR starting
at 0000:8000h */
 +               push %es
 +               call [%bp-ReadClusterOffset]
 +               pop  %es
 +
 +               xor  %bx,%bx
 +        mov  %bl,BYTE [%bp+SectsPerCluster]
 +               shl  %bx,5                                                      /* BX =
BX * 512 / 16 */
 +               mov  %ax,%es                                            /* Increment the
load address by */
 +               add  %ax,%bx                                            /* The size of a
cluster */
 +               mov  %es,%ax
                call IsFat12
 -               pop  ax
 -               push es
 +               pop  %ax
 +               push %es
                jnc  LoadFile4
 -               call GetFatEntry12                                      ; Get the next
entry
 +               call GetFatEntry12                                      /* Get the next
entry */
                jmp  LoadFile5
  LoadFile4:
                call GetFatEntry16
  LoadFile5:
 -               pop  es
 -
 -        jmp  LoadFile                                          ; Load the next cluster
(if any)
 +               pop  %es
 +
 +        jmp  LoadFile                                          /* Load the next cluster
(if any) */
  LoadFile_Done:
 -        mov  dl,BYTE [BYTE bp+BootDrive]       ; Load the boot drive into DL
 -               mov  dh,[BootPartition]                         ; Load the boot partition
into DH
 -
 -               push 0                                          ; push segment (0x0000)
 -               mov bx, [0x8000 + 0xA8]         ; load the RVA of the EntryPoint into eax
 -               add bx, 0x8000                          ; RVA -> VA and skip 3 bytes
(jump to fathelper code)
 -               push bx                                         ; push offset
 -               retf                                            ; Transfer control to
FreeLoader
 -
 -; Reads the entire FAT into memory at 7000:0000
 +        mov  %dl,BYTE [%bp+BootDrive]          /* Load the boot drive into DL */
 +               mov  %dh,[BootPartition]                        /* Load the boot
partition into DH */
 +
 +               push 0                                                          /* push
segment (0x0000) */
 +               mov %bx, [0x80A8]                                       /* load the RVA
of the EntryPoint into eax */
 +               add %bx, 0x8000                                         /* RVA -> VA
and skip 3 bytes (jump to fathelper code) */
 +               push %bx                                                        /* push
offset */
 +               retf                                                            /*
Transfer control to FreeLoader */
 +
 +// Reads the entire FAT into memory at 7000:0000
  ReadFatIntoMemory:
 -        mov   ax,WORD [BYTE bp+HiddenSectors]
 -        mov   dx,WORD [BYTE bp+HiddenSectors+2]
 -               add   ax,WORD [BYTE bp+ReservedSectors]
 -               adc   dx,byte 0
 -               mov   cx,WORD [BYTE bp+SectorsPerFat]
 -               mov   bx,7000h
 -               mov   es,bx
 -               xor   bx,bx
 -               call  [bp-ReadSectorsOffset]
 -               ret
 -
 -
 -; Returns the FAT entry for a given cluster number for 16-bit FAT
 -; On entry AX has cluster number
 -; On return AX has FAT entry for that cluster
 +        mov   %ax,WORD [%bp+HiddenSectors]
 +        mov   %dx,WORD [%bp+HiddenSectors+2]
 +               add   %ax,WORD [%bp+ReservedSectors]
 +               adc   %dx,0
 +               mov   %cx,WORD [%bp+SectorsPerFat]
 +               mov   %bx,0x7000
 +               mov   %es,%bx
 +               xor   %bx,%bx
 +               call  [%bp-ReadSectorsOffset]
 +               ret
 +
 +
 +// Returns the FAT entry for a given cluster number for 16-bit FAT
 +// On entry AX has cluster number
 +// On return AX has FAT entry for that cluster
  GetFatEntry16:
 -               mov   cx,2                                              ; AX = AX * 2
(since FAT16 entries are 2 bytes)
 -               mul   cx
 -               shl   dx,12
 -
 -        mov   bx,7000h
 -               add   bx,dx
 -        mov   es,bx
 -               mov   bx,ax                                             ; Restore FAT
entry offset
 -               mov   ax,WORD [es:bx]           ; Get FAT entry
 -
 -               ret
 -
 -
 -; Returns the FAT entry for a given cluster number for 12-bit FAT
 -; On entry AX has cluster number
 -; On return AX has FAT entry for that cluster
 +               mov   %cx,2                                                     /* AX =
AX * 2 (since FAT16 entries are 2 bytes) */
 +               mul   %cx
 +               shl   %dx,12
 +
 +        mov   %bx,0x7000
 +               add   %bx,%dx
 +        mov   %es,%bx
 +               mov   %bx,%ax                                           /* Restore FAT
entry offset */
 +               es mov   %ax,WORD [%bx]                         /* Get FAT entry */
 +
 +               ret
 +
 +
 +// Returns the FAT entry for a given cluster number for 12-bit FAT
 +// On entry AX has cluster number
 +// On return AX has FAT entry for that cluster
  GetFatEntry12:
 -               push  ax
 -               mov   cx,ax
 -               shr   ax,1
 -               add   ax,cx                                             ; AX = AX * 1.5
(AX = AX + (AX / 2)) (since FAT12 entries are 12 bits)
 -
 -        mov   bx,7000h
 -        mov   es,bx
 -               mov   bx,ax                                             ; Put FAT entry
offset into BX
 -               mov   ax,WORD [es:bx]           ; Get FAT entry
 -               pop   cx                                                ; Get cluster
number from stack
 -               and   cx,1
 +               push  %ax
 +               mov   %cx,%ax
 +               shr   %ax,1
 +               add   %ax,%cx                                           /* AX = AX * 1.5
(AX = AX + (AX / 2)) (since FAT12 entries are 12 bits) */
 +
 +        mov   %bx,0x7000
 +        mov   %es,%bx
 +               mov   %bx,%ax                                           /* Put FAT entry
offset into BX */
 +               es mov   %ax,WORD [%bx]                         /* Get FAT entry */
 +               pop   %cx                                                       /* Get
cluster number from stack */
 +               and   %cx,1
                jz    UseLow12Bits
 -               and   ax,0fff0h
 -               shr   ax,4
 +               and   %ax,0xfff0
 +               shr   %ax,4
                jmp   GetFatEntry12_Done
  UseLow12Bits:
 -               and   ax,0fffh
 +               and   %ax,0x0fff
  GetFatEntry12_Done:
                ret
 -; Returns CF = 1 if this is a FAT12 file system
 -; Otherwise CF = 0 for FAT16
 +// Returns CF = 1 if this is a FAT12 file system
 +// Otherwise CF = 0 for FAT16
  IsFat12:
 -               mov   ebx,DWORD [BYTE bp-DataAreaStartLow]
 -        ; EBX now has the number of the starting sector of the data area
 -               ; starting from the beginning of the disk, so subtrace hidden sectors
 -               sub   ebx,DWORD [BYTE bp+HiddenSectors]
 -
 -
 -               xor   eax,eax
 -               mov   ax,WORD [BYTE bp+TotalSectors]
 -               cmp   ax,byte 0
 +               mov   %ebx,DWORD [%bp-DataAreaStartLow]
 +        // EBX now has the number of the starting sector of the data area
 +               // starting from the beginning of the disk, so subtrace hidden sectors
 +               sub   %ebx,DWORD [%bp+HiddenSectors]
 +
 +
 +               xor   %eax,%eax
 +               mov   %ax,WORD [%bp+TotalSectors]
 +               cmp   %ax,0
                jnz   IsFat12_2
 -               mov   eax,DWORD [BYTE bp+TotalSectorsBig]
 -
 -               ; EAX now contains the number of sectors on the volume
 +               mov   %eax,DWORD [%bp+TotalSectorsBig]
 +
 +               // EAX now contains the number of sectors on the volume
  IsFat12_2:
 -               sub   eax,ebx                           ; Subtract data area start sector
 -               xor   edx,edx                           ; from total sectors of volume
 -
 -               ; EDX:EAX now contains the number of data sectors on the volume
 -               movzx ebx,BYTE [BYTE bp+SectsPerCluster]
 -               div   ebx
 -               ; EAX now has the number of clusters on the volume
 +               sub   %eax,%ebx                                         /* Subtract data
area start sector */
 +               xor   %edx,%edx                                         /* from total
sectors of volume */
 +
 +               // EDX:EAX now contains the number of data sectors on the volume
 +               xor %ebx,%ebx
 +               mov %bl,BYTE [%bp+SectsPerCluster]
 +               div   %ebx
 +               // EAX now has the number of clusters on the volume
                stc
 -               cmp   eax,4085
 +               cmp   %eax,4085
                jb    IsFat12_Done
                clc
 @@ -229,7 +225,9 @@
 -msgLoading     db 'Loading FreeLoader...',0dh,0ah,0
 -
 -                       times 510-($-$$) db 0   ; Pad to 510 bytes
 -                       dw 0aa55h                               ; BootSector signature
 +msgLoading:
 +               .asciz "Loading FreeLoader...\r\n"
 +
 +               .org 0x1fe
 +blockend:
 +               .word 0x0aa55                                           /* BootSector
signature */
 Removed: branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm
 URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/boot/freeldr/free…
 ==============================================================================
 --- branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm [iso-8859-1]
(original)
 +++ branches/cmake-bringup/boot/freeldr/freeldr/arch/i386/fathelp.asm (removed)
 @@ -1,235 +1,0 @@
 -; FATHELP.ASM
 -; FAT12/16 Boot Sector Helper Code
 -; Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer
 -
 -
 -
 -;org 8000h
 -
 -segment .text
 -
 -bits 16
 -
 -
 -BootSectorStackTop             equ             0x7bf2
 -DataAreaStartHigh              equ             0x2
 -DataAreaStartLow               equ             0x4
 -BiosCHSDriveSizeHigh   equ             0x6
 -BiosCHSDriveSizeLow            equ             0x8
 -BiosCHSDriveSize               equ             0x8
 -ReadSectorsOffset              equ             0xa
 -ReadClusterOffset              equ             0xc
 -PutCharsOffset                 equ             0xe
 -
 -OEMName                                        equ             3
 -BytesPerSector                 equ             11
 -SectsPerCluster                        equ             13
 -ReservedSectors                        equ             14
 -NumberOfFats                   equ             16
 -MaxRootEntries                 equ             17
 -TotalSectors                   equ             19
 -MediaDescriptor                        equ             21
 -SectorsPerFat                  equ             22
 -SectorsPerTrack                        equ             24
 -NumberOfHeads                  equ             26
 -HiddenSectors                  equ             28
 -TotalSectorsBig                        equ             32
 -BootDrive                              equ             36
 -Reserved                               equ             37
 -ExtendSig                              equ             38
 -SerialNumber                   equ             39
 -VolumeLabel                            equ             43
 -FileSystem                             equ             54
 -
 -BootPartition                  equ             0x7dfd
 -
 -
 -; This code will be stored in the first 512 bytes
 -; of freeldr.sys. The first 3 bytes will be a jmp
 -; instruction to skip past the FAT helper code
 -; that is stored in the rest of the 512 bytes.
 -;
 -; This code is loaded at 0000:8000 so we have to
 -; encode a jmp instruction to jump to 0000:8200
 -
 -global _mainCRTStartup ; For Mingw32 builds where the linker looks for this symbol
 -_mainCRTStartup:
 -global start
 -start:
 -        db     0xe9
 -               db      0xfd
 -               db      0x01
 -
 -; Now starts the extra boot code that we will store
 -; in the first 512 bytes of freeldr.sys. This code
 -; allows the FAT12/16 bootsector to navigate the
 -; FAT table so that we can still load freeldr.sys
 -; even if it is fragmented.
 -
 -
 -FatHelperEntryPoint:
 -
 -               push ax                                                 ; First save AX -
the start cluster of freeldr.sys
 -
 -
 -               ; Display "Loading FreeLoader..." message
 -        mov  esi,msgLoading                            ; Loading message
 -        call [bp-PutCharsOffset]               ; Display it
 -
 -
 -               call ReadFatIntoMemory
 -
 -               pop  ax                                                 ; Restore AX
(start cluster)
 -               ; AX has start cluster of freeldr.sys
 -
 -        mov  bx,800h
 -        mov  es,bx
 -
 -LoadFile:
 -               push ax
 -               call IsFat12
 -               pop  ax
 -               jnc  LoadFile2
 -               cmp  ax,0ff8h               ; Check to see if this is the last cluster in
the chain
 -               jmp  LoadFile3
 -LoadFile2:
 -               cmp  ax,0fff8h
 -LoadFile3:
 -               jae      LoadFile_Done          ; If so continue, if not then read then
next one
 -               push ax
 -        xor  bx,bx              ; Load ROSLDR starting at 0000:8000h
 -               push es
 -               call [bp-ReadClusterOffset]
 -               pop  es
 -
 -               xor  bx,bx
 -        mov  bl,BYTE [BYTE bp+SectsPerCluster]
 -               shl  bx,5                                                       ; BX = BX
* 512 / 16
 -               mov  ax,es                                                      ;
Increment the load address by
 -               add  ax,bx                                                      ; The
size of a cluster
 -               mov  es,ax
 -
 -               call IsFat12
 -               pop  ax
 -               push es
 -               jnc  LoadFile4
 -               call GetFatEntry12                                      ; Get the next
entry
 -               jmp  LoadFile5
 -LoadFile4:
 -               call GetFatEntry16
 -LoadFile5:
 -               pop  es
 -
 -        jmp  LoadFile                                          ; Load the next cluster
(if any)
 -
 -LoadFile_Done:
 -        mov  dl,BYTE [BYTE bp+BootDrive]       ; Load the boot drive into DL
 -               mov  dh,[BootPartition]                         ; Load the boot partition
into DH
 -
 -               push 0                                          ; push segment (0x0000)
 -               mov bx, [0x8000 + 0xA8]         ; load the RVA of the EntryPoint into eax
 -               add bx, 0x8000                          ; RVA -> VA and skip 3 bytes
(jump to fathelper code)
 -               push bx                                         ; push offset
 -               retf                                            ; Transfer control to
FreeLoader
 -
 -; Reads the entire FAT into memory at 7000:0000
 -ReadFatIntoMemory:
 -        mov   ax,WORD [BYTE bp+HiddenSectors]
 -        mov   dx,WORD [BYTE bp+HiddenSectors+2]
 -               add   ax,WORD [BYTE bp+ReservedSectors]
 -               adc   dx,byte 0
 -               mov   cx,WORD [BYTE bp+SectorsPerFat]
 -               mov   bx,7000h
 -               mov   es,bx
 -               xor   bx,bx
 -               call  [bp-ReadSectorsOffset]
 -               ret
 -
 -
 -; Returns the FAT entry for a given cluster number for 16-bit FAT
 -; On entry AX has cluster number
 -; On return AX has FAT entry for that cluster
 -GetFatEntry16:
 -
 -               mov   cx,2                                              ; AX = AX * 2
(since FAT16 entries are 2 bytes)
 -               mul   cx
 -               shl   dx,12
 -
 -        mov   bx,7000h
 -               add   bx,dx
 -        mov   es,bx
 -               mov   bx,ax                                             ; Restore FAT
entry offset
 -               mov   ax,WORD [es:bx]           ; Get FAT entry
 -
 -               ret
 -
 -
 -; Returns the FAT entry for a given cluster number for 12-bit FAT
 -; On entry AX has cluster number
 -; On return AX has FAT entry for that cluster
 -GetFatEntry12:
 -
 -               push  ax
 -               mov   cx,ax
 -               shr   ax,1
 -               add   ax,cx                                             ; AX = AX * 1.5
(AX = AX + (AX / 2)) (since FAT12 entries are 12 bits)
 -
 -        mov   bx,7000h
 -        mov   es,bx
 -               mov   bx,ax                                             ; Put FAT entry
offset into BX
 -               mov   ax,WORD [es:bx]           ; Get FAT entry
 -               pop   cx                                                ; Get cluster
number from stack
 -               and   cx,1
 -               jz    UseLow12Bits
 -               and   ax,0fff0h
 -               shr   ax,4
 -               jmp   GetFatEntry12_Done
 -
 -UseLow12Bits:
 -               and   ax,0fffh
 -
 -GetFatEntry12_Done:
 -
 -               ret
 -
 -
 -; Returns CF = 1 if this is a FAT12 file system
 -; Otherwise CF = 0 for FAT16
 -IsFat12:
 -
 -               mov   ebx,DWORD [BYTE bp-DataAreaStartLow]
 -        ; EBX now has the number of the starting sector of the data area
 -               ; starting from the beginning of the disk, so subtrace hidden sectors
 -               sub   ebx,DWORD [BYTE bp+HiddenSectors]
 -
 -
 -               xor   eax,eax
 -               mov   ax,WORD [BYTE bp+TotalSectors]
 -               cmp   ax,byte 0
 -               jnz   IsFat12_2
 -               mov   eax,DWORD [BYTE bp+TotalSectorsBig]
 -
 -               ; EAX now contains the number of sectors on the volume
 -
 -IsFat12_2:
 -               sub   eax,ebx                           ; Subtract data area start sector
 -               xor   edx,edx                           ; from total sectors of volume
 -
 -               ; EDX:EAX now contains the number of data sectors on the volume
 -               movzx ebx,BYTE [BYTE bp+SectsPerCluster]
 -               div   ebx
 -               ; EAX now has the number of clusters on the volume
 -               stc
 -               cmp   eax,4085
 -               jb    IsFat12_Done
 -               clc
 -
 -IsFat12_Done:
 -               ret
 -
 -
 -
 -msgLoading     db 'Loading FreeLoader...',0dh,0ah,0
 -
 -                       times 510-($-$$) db 0   ; Pad to 510 bytes
 -                       dw 0aa55h                               ; BootSector signature