home .. forth .. colorforth mail list archive ..

Re: [colorforth] Booting from HDD


Nick here,

Thanks Ray, for your boot.asm printout (below).  It
shows a boot process that has already set up video
4FO2/4117 and copied the 512 byte boot sector before
relocating to "at0:" to copy the remaining code via
floppy then jumping to "start2" via the floppy call
"stop" motor.  For comparison, here is JC's boot.asm. 
Unlike yours (or Howerd's original CFDOS4 floppy) this
CD version does not set up video before relocating, and
seems to rely on MSDOS or ElTorito (non-emulation
mode) to have copied all of the code before setting up 
the Graphic Output Display ("god"). See lines 98, 99 in
JC's version (below). This is a long way from the
simplicity of Chuck's original boot.asm (which one can
consult on JC's site under "as/", together with a very
helpful commentary by John himself). As Albert van der
Horst has just remarked, "CF is simple but this is the
other side of the coin".  I find that Howerd's
CFDOS4.blk (simply DeeDee'd onto a floppy) boots a new
Pentium D with no OS apart from BIOS, but John's CFDOS4
CD does not.

IMHO Jason is on the right track: floppy emulation; just
dd a reliable floppy image onto the flash stick 
(after all, CF is meant to be self booting). I could
expatiate if anyone is interested.  

Caritas, 

NickM 


JC's boot.asm

http://colorforth.cvs.sourceforge.net/colorforth/colorforth/jc2007/boot.asm?revision=1.69&view=markup

intel_syntax ;# floppy boot segment
    2 ;# 0x000-0x400 is BIOS interrupt table
    3 ;# 0x400-0x500 is BIOS system information area
    4 ;# we can use starting at 0x500
    5 
    6 .equ upper_right, 158 ;# address of upper-right
corner of screen
    7 .ifdef LOADBLOCKS
    8  ;# this 'ifdef' is only here to trigger the
Makefile to include this number
    9  ;# but let's use it to define other constants
while we're at it
   10  .equ HEADS, 2
   11  .equ SECTORS_PER_TRACK, 18
   12  .equ BYTES_PER_CYLINDER, 512 * HEADS *
SECTORS_PER_TRACK
   13  .equ LOAD_CYLINDERS, (LOADBLOCKS * 1024) /
BYTES_PER_CYLINDER
   14  .if (LOADBLOCKS * 1024) % BYTES_PER_CYLINDER > 0
   15   .equ LOAD_CYLINDERS, LOAD_CYLINDERS + 1
   16  .endif
   17 .endif
   18 .macro showprogress
   19   .ifdef DEBUGGING
   20   call progress
   21   .endif
   22 .endm
   23 .macro shownumber
   24  .ifdef DEBUGGING
   25  call shownumber
   26  .endif
   27 .endm
   28 
   29 .org 0 ;# actually 0x7c00, where the BIOS loads
the bootsector
   30 start:
   31     jmp  start0
   32 bootmode: ;# this byte after the short jmp above
is normally just padding
   33 ;# we will use it to indicate a startup from
MSDOS
   34 ;# also to indicate El Torito boot
   35 .ifdef EL_TORITO_BOOT
   36     .byte 0xfe ;# even number so we can use MSDOS
check odd parity
   37 .else
   38     .byte 0 ;# pad to offset 3
   39 .endif
   40     .ascii "cmcf 1.0"
   41 bps:
   42     .word 512     ;# bytes/sector
   43     .byte 1       ;# sector/cluster
   44     .word 1       ;# sector reserved
   45     .byte 2       ;# fats
   46     .word 16*14   ;# root directory entries
   47     .word 80 * HEADS * SECTORS_PER_TRACK ;#
sectors
   48     .byte 0x0f0   ;# media
   49     .word 9       ;# sectors/fat
   50 spt:
   51     .word SECTORS_PER_TRACK ;# sectors/track
   52 heads:
   53     .word HEADS   ;# heads
   54     .long 0       ;# hidden sectors
   55     .long 80 * HEADS * SECTORS_PER_TRACK ;#
sectors again
   56 drive:
   57     .byte 0       ;# drive
   58 cylinder: .word 0
   59 .align 4
   60 ;# forth+icons+blocks 24-LOADBLOCKS ;# number of
cylinders to load (out of 80)
   61 ;# needs to be on longword boundary, see nc_ in
color.asm
   62 nc:  .long LOAD_CYLINDERS
   63 gdt: .word gdt_end - gdt0 - 1 ;# GDT limit
   64     .long gdt0 + loadaddr ;# pointer to start of
table
   65 .align 8
   66 gdt0: .word 0, 0, 0, 0 ;# start of table must be
a
null entry
   67     .equ code32p, . - gdt0
   68     .word 0xffff, 0, 0x9a00, 0xcf ;# 32-bit
protected-mode code
   69     .equ data32p, . - gdt0
   70     .word 0xffff, 0, 0x9200, 0xcf ;# 32-bit
protected-mode data
   71     .equ code16r, . - gdt0
   72     .word 0xffff, 0, 0x9a00, 0x00 ;# 16-bit
real-mode code
   73     .equ data16r, . - gdt0
   74     .word 0xffff, 0, 0x9200, 0x00 ;# 16-bit
real-mode data
   75 gdt_end:
   76 real_mode_idt:
   77     .word 0xffff ;# limit
   78     .long 0 ;# base is that of BIOS interrupt
table
   79 .code16
   80 start0:
   81     cmp  word ptr cs:0, 0x20cd ;# INT 20h at
start
of .com program header
   82     jnz  0f
   83     dec  byte ptr [cs: bootmode + 0x100]
   84 0:  cli
   85     push cs ;# need to set DS=CS, especially on
VMWare, DS was 0x40
   86     pop  ds
   87     zero ss ;# set stack to something low and out
of the way
   88     mov  esp, iobuffer + 0x1000
   89     call whereami ;# set EBP to load location
   90     call relocate ;# move past BIOS stuff and
buffer space
   91     mov  esp, gods ;# stack pointer now where it
really belongs
   92     call whereami ;# set EBP to where we
relocated
   93     showprogress
   94     data32 call protected_mode
   95 .code32
   96     call a20 ;# set A20 gate to enable access to
addresses with 1xxxxx
   97     mov  al, byte ptr bootmode + loadaddr
   98     or   al, al  ;# negative if MSDOS-loaded or
El
Torito non-emulation mode
   99     jz   0f ;# otherwise we need to load bootcode
from floppy
  100 9:  mov  esi, godd ;# set up data stack pointer
for 'god' task
  101     jmp  start1
  102 0:  mov  byte ptr [es: 0xb8000 | (upper_right -
8)], 'P'
  103     call unreal_mode
  104 .code16
  105     ;# fall through to cold-start routine
  106 cold:
  107     mov  edi, loadaddr  ;# start by overwriting
this code
  108     ;# that's why it's so critical that
'cylinder'
be reset to zero before
  109     ;# saving the image; if it's anything but
that, when this block is
  110     ;# overwritten, 'cylinder' will be changed,
and cylinders will be skipped
  111     ;# in loading, making the bootblock unusable
  112     call read
  113     inc  byte ptr cylinder + loadaddr
  114     xor  cx, cx
  115     mov  cl, nc + loadaddr ;# number of cylinders
used
  116     dec  cx
  117 0:  push cx
  118     call read
  119     inc  byte ptr cylinder + loadaddr
  120     mov  dx, word ptr cylinder + loadaddr
  121     shownumber
  122     pop  cx
  123     loop 0b
  124     showprogress
  125     data32 call protected_mode

**********************

Quoting "Ray St. Marie" <ray.stmarie@xxxxxxxxx>:

>... " On Sat, Mar 15, 2008 at 5:25 PM, Ray St. Marie
>... " <ray.stmarie@xxxxxxxxx> wrote:
>... " >
>
>... " > --
>... " > Raymond St. Marie ii,
>... " > colorforthray.info
>... " >
>... " 
>... " Microsoft (R) Macro Assembler Version
>... " 6.14.8444		    10/12/07 23:04:39
>... " color.asm						     Page 1 - 1
>... " 
>... " 
>... " 				;colorForth, 2001 Jul 22, Chuck Moore,
>... " Public Domain
>... " 				;modified 8/06/01 for 800x600 operation
>... " Terry Loveall, loveall@xxxxxxxxx
>... " 				;modified ras20040728 returned to 1024x768
>... " operation for the pentium 4
>... " 				;by Ray St. Marie
>... " Rastm2@xxxxxxxxxxxxxxxxxxxxx
>... " 				.MODEL tiny
>... " 				.486p
>... "  00000000			only SEGMENT USE32
>... " 				ASSUME DS:only
>... " 
>... " 				next MACRO adr
>... " 				    dec  ECX
>... " 				    jnz  adr
>... " 				ENDM
>... " 
>... " 				DUP_ MACRO
>... " 				    lea  ESI, [ESI-4]
>... " 				    mov  [ESI], EAX
>... " 				ENDM
>... " 
>... " 				DROP MACRO
>... " 				    lodsd
>... " 				ENDM
>... " 
>... " 				;;hp equ 800
>... " 				;;vp equ 600
>... " 				;;vesa equ 114h
>... "  = 00000400			hp equ 1024
>... "  = 00000300			vp equ 768
>... "  = 00004117			vesa equ 4117h ; 117h but with
>... " LinearFrameBuffer Bit on
>... "  = 00025C00			buffer equ 604*256
>... " 				include boot.asm ; boot boot0 hard
>... " 			      C ; Floppy boot segment
>... " 			      C
>... " 			      C org 0 ; actually 7c00
>... "  00000000  EB 56	      C start: jmp  start0
>... "  00000002  90		      C     nop
>... " 			      C
>... "  00000003  63 6D 63 66 20     C     db 'cmcf
>... " 1.0'
>... " 	   31 2E 30
>... "  0000000B  0200		      C     dw 512     ;
>... " bytes/sector
>... "  0000000D  01		      C     db 1       ;
>... " sector/cluster
>... "  0000000E  0001		      C     dw 1       ; sector
>... " reserved
>... "  00000010  02		      C     db 2       ; FATs
>... "  00000011  00E0		      C     dw 16*14   ; root
>... " directory entries
>... "  00000013  0B40		      C     dw 80*2*18 ;
>... " sectors
>... "  00000015  F0		      C     db 0F0h    ; media
>... "  00000016  0009		      C     dw 9       ;
>... " sectors/FAT
>... "  00000018  0012		      C     dw 18      ;
>... " sectors/track
>... "  0000001A  0002		      C     dw 2       ; heads
>... "  0000001C  00000000	      C     dd 0       ;
>... " hidden sectors
>... "  00000020  00000B40	      C     dd 80*2*18 ;
>... " sectors again
>... "  00000024  00		      C     db 0       ; drive
>... " 			      C ;    db 0
>... " 			      C ;    db 29h     ; signature
>... " 			      C ;    dd 44444444h     ; serial
>... " 			      C ;    db 'COLOR FORTH' ; label
>... " 			      C ;    db '        '
>... " 			      C
>... "  00000025 00		      C command  db 0
>... "  00000026  00		      C          db 0   ; head,
>... " drive
>... "  00000027 00		      C cylinder db 0
>... "  00000028  00		      C          db 0   ; head
>... "  00000029  01		      C          db 1   ; sector
>... "  0000002A  02		      C          db 2   ; 512
>... " bytes/sector
>... "  0000002B  12		      C          db 18  ;
>... " sectors/track
>... "  0000002C  1B		      C          db 1bh ; gap
>... "  0000002D  FF		      C          db 0ffh
>... " 			      C ALIGN 4
>... "  00000030 00000012	      C nc dd 18 ;
>... " Forth+Icons+blocks 24-161
>... "  00000034 0017		      C gdt dw 17h
>... "  00000036  00000040 R	      C     dd offset
>... " gdt0
>... " 			      C ALIGN 8
>... "  00000040 0000 0000 0000      C gdt0 dw 0, 0, 0,
>... " 0
>... " 	   0000
>... "  00000048  FFFF 0000 9A00     C     dw 0FFFFh,
>... " 0, 9A00h, 0CFh ; code
>... " 	   00CF
>... "  00000050  FFFF 0000 9200     C     dw 0FFFFh,
>... " 0, 9200h, 0CFh ; data
>... " 	   00CF
>... " 			      C
>... " 			      C ; Code is compiled in Protected
>... " 32-bit mode.
>... " 			      C ; Hence  org $-2  to fix 16-bit
>... " words
>... " 			      C ; and 4 hand-assembled instructions.
>... " 			      C ; and EAX and AX exchanged
>... " 			      C ; This code is in Real 16-bit mode
>... " 			      C
>... "  00000058  B8 00004F02	      C start0: mov  EAX,
>... " 4F02h ; Video mode
>... " 			      C org $-2
>... "  0000005B  BB 00004117	      C     mov  EBX,
>... " vesa ; hp*vp rgb: 565
>... " 			      C org $-2
>... "  0000005E  CD 10	      C     int  10h
>... "  00000060  FA		      C     cli
>... "  00000061  66| 33 C0	      C     xor  AX, AX   
>... " ; Move code to 0
>... "  00000064  66| 8B D8	      C     mov  BX, AX
>... "  00000067  8C CB	      C     mov  EBX, CS
>... "  00000069  8E DB	      C     mov  DS, EBX
>... "  0000006B  8E C0	      C     mov  ES, EAX
>... "  0000006D  66| 8B F8	      C     mov  DI, AX
>... "  00000070  66| 8B F0	      C     mov  SI, AX
>... "  00000073  E8 00000000	      C     call $+5 ;
>... " Where are we? IP+4*CS
>... " 			      C org $-2
>... "  00000076  5E		      C loc: pop  ESI
>... "  00000077  81 EE 00000076     C     sub  ESI,
>... " offset loc-offset start
>... " 			      C org $-2
>... "  0000007B  B9 00000080	      C     mov  ECX,
>... " 512/4
>... " 			      C org $-2
>... "  0000007E  F3/ 66| A5	      C     rep movsw
>... " 			      C ;    jmp  0:relocate
>... "  00000081  EA		      C     db 0eah
>... "  00000082  0086 0000	      C     dw offset
>... " relocate-offset start, 0
>... " 			      C
>... "  00000086		      C relocate: ; This code is
>... " executed from 0
>... "  00000086  8E D8	      C     mov  DS, EAX
>... " 			      C ;   lgdt fword ptr gdt
>... "  00000088  0F 01 16	      C     db 0fh, 1, 16h
>... "  0000008B  0034		      C     dw offset
>... " gdt-offset start
>... "  0000008D  B0 01	      C     mov  AL, 1
>... "  0000008F  0F 22 C0	      C     mov  CR0, EAX
>... " 			      C ;    jmp  8:protected
>... "  00000092  EA		      C     db 0eah
>... "  00000093  0097 0008	      C     dw offset
>... " protected-offset start, 8
>... " 			      C
>... "  00000097		      C protected: ; Now in Protected
>... " 32-bit mode
>... "  00000097  B0 10	      C     mov  AL, 10h
>... "  00000099  8E D8	      C     mov  DS, EAX
>... "  0000009B  8E C0	      C     mov  ES, EAX
>... "  0000009D  8E D0	      C     mov  SS, EAX
>... "  0000009F  BC 000A0000	      C     mov  ESP,
>... " Gods
>... "  000000A4  33 C9	      C     xor  ECX, ECX
>... " 			      C
>... " 
>... " -- 
>... " Raymond St. Marie ii,
>... " colorforthray.info
>... " 
>... "
---------------------------------------------------------------------
>... " To unsubscribe, e-mail:
>... " colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
>... " For additional commands, e-mail:
>... " colorforth-help@xxxxxxxxxxxxxxxxxx
>... " Main web page - http://www.colorforth.com
>... " 


-- 
Dr Nicolas George Maroudas
Avigdor Meiri 9/1 
Sea View 
Haifa 3 55 00 
Israel 
Tel +972 048 337 315 

****************************

No trees were killed in the sending of this message.
However, a large number of electrons were terribly
inconvenienced

****

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com