#!/usr/bin/perl
-open(IN, $ARGV[0]) || die("$! : $ARGV[0]");
-binmode IN;
-open(OUT, ">$ARGV[1]") || die("$! : $ARGV[1]");
-binmode OUT;
-
-$size = -s $ARGV[0];
-read(IN, $buf, $size);
-print OUT $buf;
-for ($i = $size; $i < 1474560; $i++)
+open(OUT_IMG, ">$ARGV[0]") || die("$! : $ARGV[0]");
+binmode OUT_IMG;
+
+open(IPL, $ARGV[1]) || die("$! : $ARGV[1]");
+binmode IPL;
+
+open(SWITCH32, $ARGV[2]) || die("$! : $ARGV[2]");
+binmode SWITCH32;
+
+$size = -s $ARGV[1];
+read(IPL, $buf, $size);
+print OUT_IMG $buf;
+for ($i = $size; $i < 1024; $i++)
+{
+ print OUT "\0";
+}
+
+$size = -s $ARGV[2];
+read(SWITCH32, $buf, $size);
+print OUT_IMG $buf;
+for ($i = $i + $size; $i < 1474560; $i++)
{
print OUT "\0";
}
-close(IN);
-close(OUT);
+
+
+
+close(OUT_IMG);
+close(IPL);
+close(SWITCH32);
endif
+# %jp{リンカスクリプト}
LINK_SCRIPT = link_fd.x
SRC_DIRS += . ..
# アセンブラファイルの追加
-ASRCS += ./bootloader.S \
- ./crt0.S
+ASRCS += ./crt0.S
# %jp{C言語ファイルの追加}
# --------------------------------------
.PHONY : all
-all: makeexe_all $(TARGET_BIN) $(TARGET_HEX) $(TARGET_MOT) $(TARGET).img
+all: makeexe_all ipl.bin $(TARGET_BIN) $(TARGET_HEX) $(TARGET_MOT) $(TARGET).img
.PHONY : clean
clean: makeexe_clean
mostlyclean: clean kernel_clean
# %jP{フロッピーディスクイメージ}%en{FD image}
-$(TARGET).img: $(TARGET_BIN)
- ./fd_img.pl $(TARGET_BIN) $(TARGET).img
+$(TARGET).img: ipl.bin switch32.bin
+ ./fd_img.pl $(TARGET).img ipl.bin switch32.bin switch32.bin
../kernel_cfg.c ../kernel_id.h: ../system.cfg
cpp -E ../system.cfg ../system.i
include $(KERNEL_MAKINC_DIR)/gcc_r.inc
+# %jp{BOOT部の生成}
+switch32.bin: $(OBJS_DIR)/switch32.o
+ $(GCC_ARCH)ld -Ttext=0x0000 -nostdlib $(OBJS_DIR)/switch32.o -o switch.out
+ $(CMD_OBJCNV) -O binary switch.out switch32.bin
+
+
+# %jp{IPL部の生成}
+ipl.bin: $(OBJS_DIR)/ipl.o
+ $(GCC_ARCH)ld -Ttext=0x0000 -nostdlib -fno-exceptions -ffreestanding -fno-builtin -nostartfiles $(OBJS_DIR)/ipl.o -o ipl.out
+ $(CMD_OBJCNV) -O binary ipl.out ipl.bin
+
# --------------------------------------
# %jp{依存関係}
# --------------------------------------
+$(TARGET_EXE): $(LINK_SCRIPT)
$(OBJS_DIR)/sample.$(EXT_OBJ): ../sample.c ../kernel_id.h
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * Sample program for PC/AT
+ *
+ * Copyright (C) 1998-2007 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+IPL_SEG = 0x07c0 /* ロードされるセグメントアドレス */
+INIT_SEG = 0x8000 /* 初期化コード用セグメントアドレス */
+LOAD_SEG = 0x9000 /* 本体をロードするセグメントアドレス */
+
+
+ .code16
+ .text
+ .org 0
+
+ .global ipl_top
+
+ /***** IPL部 *****/
+ipl_top:
+ cli
+ jmpl $IPL_SEG, $ipl_start /* CSの初期化 */
+ipl_start:
+ /* コードのコピー */
+ movw $IPL_SEG, %ax
+ movw %ax, %ds
+ movw $INIT_SEG, %ax
+ movw %ax, %es
+ xorw %si, %si
+ xorw %di, %di
+ movw $512, %cx
+ cld
+ rep movsw
+
+ /* コピー先に移動 */
+ movw %ax, %ds
+ movw %ax, %ss
+ xorw %sp, %sp
+ jmpl $INIT_SEG, $init_start
+
+
+ /***** 初期化部 *****/
+init_start:
+ /* 画面のクリア */
+ ; call bios_clr_disp
+
+ /* メッセージ出力 */
+ movw $boot_message, %si
+ call bios_puts
+
+ /* 本体のロード */
+ movw $LOAD_SEG, %ax
+ movw %ax, %es
+ xorw %bx, %bx /* 読込先アドレス */
+ movb $0x02, %ah
+ movb $0x06, %al /* セクタ数 */
+ movw $0x0002, %cx /* シリンダ・セクタ番号 */
+ movb $0x00, %dh /* ヘッド番号 */
+ movb $0x00, %dl /* ドライブ番号 */
+ int $0x13
+
+ /* ロード先に移動 */
+ movw $LOAD_SEG, %ax
+ movw %ax, %ds
+ movw %ax, %ss
+ xorw %sp, %sp
+ jmpl $LOAD_SEG, $0x0000
+
+end_loop:
+ jmp end_loop
+
+
+ /* 画面のクリア */
+bios_clr_disp:
+ movb $0x3, %al
+ movb $0, %ah
+ int $0x10
+ ret
+
+
+ /* 1文字出力 */
+bios_putc:
+ movb $0x0e, %ah
+ movb $0, %bh
+ int $0x10
+ ret
+
+ /* 文字列出力 */
+bios_puts:
+ lodsb
+ cmpb $0, %al
+ jz bios_puts_end
+ call bios_putc
+ jmp bios_puts
+bios_puts_end:
+ ret
+
+
+
+ /* 起動メッセージ */
+boot_message:
+ .ascii "HOS-Loader\r\nNow Loading...\r\n\0"
+
+
+ /* マジックナンバー */
+ .org 510
+ .word 0xaa55
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * Sample program for PC/AT
+ *
+ * Copyright (C) 1998-2007 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+
+ .code16
+ .text
+ .align 4
+
+
+ .global _switch32
+
+/************************************************
+ 起動ハンドラ
+************************************************/
+_switch32:
+ /* 画面のクリア */
+ call bios_clr_disp
+
+ /* メッセージ出力 */
+ movw $boot_message, %si
+ call bios_puts
+
+_switch32_end:
+ jmp _switch32_end
+
+ lgdt gdtr
+ lidt idtr
+
+ movl $0x11, %eax
+ movl %eax, %cr0
+ jmp _go_32bit_mode
+
+_go_32bit_mode:
+ .byte 0x66, 0xea
+ .long _start_32bit + 0x90000
+ .word 0x0001
+
+ .code32
+_start_32bit:
+ jmp _start_32bit
+
+
+/************************************************
+ BIOSサービス
+************************************************/
+
+ /* 画面のクリア */
+bios_clr_disp:
+ movb $0x3, %al
+ movb $0, %ah
+ int $0x10
+ ret
+
+
+ /* 1文字出力 */
+bios_putc:
+ movb $0x0e, %ah
+ movb $0, %bh
+ int $0x10
+ ret
+
+ /* 文字列出力 */
+bios_puts:
+ lodsb
+ cmpb $0, %al
+ jz bios_puts_end
+ call bios_putc
+ jmp bios_puts
+bios_puts_end:
+ ret
+
+
+
+ /* 起動メッセージ */
+boot_message:
+ .ascii "Hyper Operation System V4 Advance\r\n\0"
+
+
+
+
+/************************************************
+ グローバルディスクリプタテーブル
+************************************************/
+
+gdt_base:
+gdt_000: /* ヌルセグメント */
+ .word 0x0000
+ .word 0x0000
+ .byte 0x00
+ .byte 0x00
+ .byte 0x00
+ .byte 0x00
+
+gdt_001: /* コードセグメント用 */
+ .word 0xffff /* リミット[15:0]:0xffff */
+ .word 0x0000 /* ベース[15:0]:0x0000 */
+ .byte 0x00 /* ベース[23:16] */
+ .byte 0x9a /* P:1, DPL:0, S:1, TYPE:5, A:0 */
+ .byte 0xcf /* G:1, D=1, リミット[19:15]:0xf */
+ .byte 0x00 /* ベース[32:24]:0x00 */
+
+gdt_002: /* データセグメント用 */
+ .word 0xffff /* リミット[15:0]:0xffff */
+ .word 0x0000 /* ベース[15:0]:0x0000 */
+ .byte 0x00 /* ベース[23:16] */
+ .byte 0x92 /* P:1, DPL:0, S:1, TYPE:1, A:0 */
+ .byte 0xcf /* G:1, D=1, リミット[19:15]:0xf */
+ .byte 0x00 /* ベース[32:24]:0x00 */
+gdt_end:
+
+
+ /* lgdt命令用領域 */
+gdtr: .word gdt_end - gdt_base - 1
+ .long 0
+
+
+
+/************************************************
+ 割込みディスクリプタテーブル
+************************************************/
+
+idt_base:
+idt_000: /* INT0 #DE 除算エラー */
+ .word 0x0000 /* オフセット[15:0] */
+ .word 0x0001 /* セグメントセレクタ */
+ .byte 0x00 /* 予約 */
+ .byte 0x8e /* P:1, DPL:0 */
+ .word 0x00 /* オフセット[31:16] */
+
+idt_001: /* INT1 #DB 予約 */
+ .word 0x0000 /* オフセット[15:0] */
+ .word 0x0001 /* セグメントセレクタ */
+ .byte 0x00 /* 予約 */
+ .byte 0x8e /* P:1, DPL:0 */
+ .word 0x00 /* オフセット[31:16] */
+
+idt_002: /* INT2 NMI */
+ .word 0x0000 /* オフセット[15:0] */
+ .word 0x0001 /* セグメントセレクタ */
+ .byte 0x00 /* 予約 */
+ .byte 0x8e /* P:1, DPL:0 */
+ .word 0x00 /* オフセット[31:16] */
+
+idt_003: /* INT5 #BP ブレークポイント */
+ .word 0x0000 /* オフセット[15:0] */
+ .word 0x0001 /* セグメントセレクタ */
+ .byte 0x00 /* 予約 */
+ .byte 0x8e /* P:1, DPL:0 */
+ .word 0x00 /* オフセット[31:16] */
+
+idt_004: /* INT4 #OF オーバーフロー */
+ .word 0x0000 /* オフセット[15:0] */
+ .word 0x0001 /* セグメントセレクタ */
+ .byte 0x00 /* 予約 */
+ .byte 0x8e /* P:1, DPL:0 */
+ .word 0x00 /* オフセット[31:16] */
+
+
+idt_end:
+
+
+ /* lidt命令用領域 */
+idtr: .word idt_end - idt_base - 1
+ .long 0
+
+
+
+
+ .end
+
+
+/* end of file */