###########################################################################
# コンパイルは
# $ gcc boot.s -nostdlib -Wl,-T ipl.ls -o a.img
# でOK! ipl.lsファイルは別途DLしてね
# あとは、
# a.imgというイメージファイルができあがるので、
# それをBochsなどで起動するだけ。
#
###########################################################################

.code16
.text

.global _start
_start:

step1:
# First step. Move ourself from 0x7C -> 0x9000 and junp there.

  movw $0x07C0, %ax
  movw %ax, %ds
  #--  %ds = 0x07C0

  movw $0x9000, %ax
  movw %ax, %es
  #--  %es = 0x9000

  movw $0x0100, %cx
  #--  %cx = 0x0100 (256)

  xorw %si, %si
  xorw %di, %di
  #--  %si = %di = 0
 
  cld
  rep  movsw

  #-- read corsor pos
  movb $0x03, %ah
  xorb %bh, %bh
  int $0x10

  #-- print "boot"
  movw $0x1301, %ax
  movw $0x0007, %bx
  movw $0x0004, %cx
  movw $print_boot, %bp
  int $0x10

  ljmp $0x9000, $step2

step2:

  movw $0x1000-12, %di
  #-- 0x1000 is an arbitrary value
  #-- 0x1000 >= length of bootsect + length of setup.c + room for stack
  #-- 12 is disk parm size.

  #-- %es is 0x9000
  movw %es, %ax
  movw %ax, %ds
  movw %ax, %ss
  #-- %es = %ds = %ss = 0x9000

  #-- 0x1000-12 is stack top address.
  movw %di, %sp

  call put_dot

go:  jmp go


put_dot:
# Print dot.
# VIDEO - TELETYPE OUTPUT
# AH = 0Eh, AL = charactet to write, 
# BH = page number, BL = foreground color (graphics modes only)
# Return: nothing

  pusha
  movw $0x0E2E, %ax
  xorw %bx, %bx
  int $0x10
  popa
  ret


print_boot: .ascii "boot"


