syslinux/diag/geodsp/geodsp1s.asm
<<
>>
Prefs
   1; -----------------------------------------------------------------------
   2;
   3;   Copyright 2010 Gene Cumm
   4;
   5;   Portions from diskstart.inc:
   6;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
   7;   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
   8;
   9;   This program is free software; you can redistribute it and/or modify
  10;   it under the terms of the GNU General Public License as published by
  11;   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  12;   Boston MA 02110-1301, USA; either version 2 of the License, or
  13;   (at your option) any later version; incorporated herein by reference.
  14;
  15; -----------------------------------------------------------------------
  16
  17;
  18; geodsp1s.asm
  19;
  20; Display geometry translation info for diagnosing misconceptions
  21; 1 sector variant
  22;
  23;       nasm -Ox -f bin -o geodsp.bin -l geodsp.lst geodsp.asm
  24;
  25;       nasm -Ox -f elf -o geodsp.o -l geodsp.lst geodsp.asm
  26;       ld -m elf_i386  -T syslinux.ld -M -o geodsp.elf geodsp.o > geodsp.map
  27;       objcopy -O binary geodsp.elf geodsp.raw
  28;
  29;       # OF=/dev/sdb
  30;       # dd if=core/geodsp.bin of=$OF
  31;       # dd skip=1 seek=1 if=../dbg/lba-img/lba-img.bin of=$OF
  32;       # eject $OF
  33;       # dd count=$() if=/dev/zero of=$OF
  34;
  35;       # OF=geo-2.255.63.i
  36;       # (dd if=core/geodsp.bin; dd skip=1 if=../dbg/lba-img/lba-img.bin; dd count=$((2*255*63 - 256*63 - 1)) if=/dev/zero )|dd of=$OF
  37;       # OF=geo-20.16.63.i
  38;       # (dd if=core/geodsp.bin; dd skip=1 if=../dbg/lba-img/lba-img.bin; dd count=$((40*16*63 - 256*63 - 1)) if=/dev/zero )|dd of=$OF
  39;
  40
  41%include "macros.inc"
  42; %include "layout.inc"
  43
  44;               global STACK_LEN, STACK_TOP, STACK_BASE
  45; STACK_LEN     equ 4096
  46STACK_TOP       equ 7c00h
  47; STACK_BASE    equ STACK_TOP - STACK_LEN
  48
  49StackBuf        equ STACK_TOP-44-92     ; Start the stack here (grow down - 4K)
  50DriveNumber     equ StackBuf-4          ; Drive number
  51m_CHS0          equ 00534843h           ;'CHS',0
  52m_EDD0          equ 00444445h           ;'EDD',0
  53m_EDD_SP        equ 20444445h           ;'EDD '
  54retry_count     equ 16
  55dbuf            equ 8000h
  56int13_ret       equ 7e00h
  57
  58
  59
  60;               extern  real_mode_seg
  61;               section .real_mode      write nobits align=65536
  62;               global  core_real_mode
  63; core_real_mode        resb 65536
  64;               extern  xfer_buf_seg
  65;               section .xfer_buf       write nobits align=65536
  66;               global  core_xfer_buf
  67; core_xfer_buf resb 65536
  68
  69                section .text
  70                org STACK_TOP
  71
  72
  73                global _start
  74bootsec         equ $
  75_start:
  76                        ; In case we want to pull more of the standard diskstart stuff in
  77;               jmp short start         ; 2 bytes
  78;               nop                     ; 1 byte
  79start:
  80                cli
  81                cld
  82                xor cx,cx
  83                mov ss,cx
  84                mov sp,StackBuf-2       ; Just below BSS (-2 for alignment)
  85                push dx                 ; Save drive number (in DL)
  86                        ; Kill everything else and let the BIOS sort it out later
  87                mov es,cx
  88                mov ds,cx
  89                sti
  90
  91get_geo:                ; DL and ES ready
  92                mov ah,08h
  93                mov di,0
  94                int 13h
  95write_geo:
  96                jc .bad_geo
  97                mov si,s_chs
  98                call writestr_early
  99                call write_chs
 100                call crlf
 101                jmp short .done
 102.bad_geo:
 103.done:
 104
 105                mov bx,dbuf
 106get_h1c:                ; 0,1,1
 107                mov cx,0001h
 108                mov dh,01h
 109                call getonesec_chs
 110                call write_chs_lba
 111get_c1c:                ; 1,0,1
 112                mov cx,0101h
 113                mov dh,00h
 114                call getonesec_chs
 115                call write_chs_lba
 116
 117;
 118; Do we have EBIOS (EDD)?
 119;
 120edd:
 121.check:
 122                mov bx,55AAh
 123                mov ah,41h              ; EDD existence query
 124                mov dl,[DriveNumber]
 125                int 13h
 126                jc .noedd
 127                cmp bx,0AA55h
 128                jne .noedd
 129                test cl,1               ; Extended disk access functionality set
 130                jz .noedd
 131                ;
 132                ; We have EDD support...
 133                ;
 134                mov bx,dbuf
 135                xor edx,edx
 136                mov dword [s_chs],m_EDD_SP
 137.get_lba63:
 138                mov eax,63      ; Same length as mov al,64; movzx eax,al
 139                call getonesec_ebios
 140                jc .bad_edd     ;read error
 141                call write_edd_lba
 142.get_lba16065:
 143                mov eax,16065
 144                call getonesec_ebios
 145                jc .bad_edd     ;read error
 146                call write_edd_lba
 147.good_edd:
 148                mov dword [s_type],m_EDD0
 149.bad_edd:
 150.noedd:
 151.end:
 152
 153write_final_type:
 154                mov si,s_typespec
 155                call writestr_early
 156
 157                jmp short kaboom
 158
 159;
 160; getonesec_ebios:
 161;
 162; getonesec implementation for EBIOS (EDD)
 163;
 164getonesec_ebios:
 165                mov cx,retry_count
 166.retry:
 167                ; Form DAPA on stack
 168                push edx
 169                push eax
 170                push es
 171                push bx
 172                push word 1
 173                push word 16
 174                mov si,sp
 175                pushad
 176                mov ah,42h                      ; Extended Read
 177                call xint13
 178                popad
 179                lea sp,[si+16]                  ; Remove DAPA
 180                jc .error
 181                ret
 182
 183.error:
 184                ; Some systems seem to get "stuck" in an error state when
 185                ; using EBIOS.  Doesn't happen when using CBIOS, which is
 186                ; good, since some other systems get timeout failures
 187                ; waiting for the floppy disk to spin up.
 188
 189                pushad                          ; Try resetting the device
 190                xor ax,ax
 191                call xint13
 192                popad
 193                loop .retry                     ; CX-- and jump if not zero
 194
 195                ; Total failure.
 196                stc
 197                ret
 198
 199;
 200; getonesec_chs:
 201;
 202; CX,DH specifies CHS address
 203;
 204getonesec_chs:  ; We could use an xchg and get a loop
 205;               mov cx,retry_count
 206.retry:
 207                pushad
 208                mov ax,0201h            ; Read one sector
 209                call xint13
 210                popad
 211                jc .error
 212                ret
 213
 214.error:
 215;               loop .retry
 216                ; Fall through to disk_error
 217;
 218; kaboom: write a message and bail out.
 219;
 220                global kaboom
 221disk_error:
 222kaboom:
 223.patch:
 224                mov si,bailmsg
 225                call writestr_early
 226                xor eax,eax
 227.again:         int 16h                 ; Wait for keypress
 228                                        ; NB: replaced by int 18h if
 229                                        ; chosen at install time..
 230                int 19h                 ; And try once more to boot...
 231.norge:         hlt                     ; If int 19h returned; this is the end
 232                jmp short .norge
 233
 234;
 235; INT 13h wrapper function
 236;
 237xint13:
 238                mov dl,[DriveNumber]
 239                int 13h
 240                mov [int13_ret],ax
 241                ret
 242
 243;
 244;
 245; writestr_early: write a null-terminated string to the console
 246;           This assumes we're on page 0.  This is only used for early
 247;           messages, so it should be OK.
 248;
 249writestr_early:
 250                pushad
 251.loop:          lodsb
 252                and al,al
 253                jz .return
 254                call writechr
 255                jmp short .loop
 256.return:        popad
 257                ret
 258
 259%include "geodsplib.inc"
 260bailmsg         equ s_end
 261
 262                ; This fails if the boot sector overflowsg
 263                zb 1BEh-($-$$)
 264
 265ptable          zb 40h          ; Partition table
 266
 267bootsignature   dw 0xAA55
 268
 269sector_2:
 270
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.