OSDN Git Service

(none)
authorryuz <ryuz>
Thu, 3 Jan 2008 14:28:50 +0000 (14:28 +0000)
committerryuz <ryuz>
Thu, 3 Jan 2008 14:28:50 +0000 (14:28 +0000)
sample/ia32/pcat/gcc/bootloader.S
sample/ia32/pcat/gcc/crt0.S
sample/ia32/pcat/gcc/fd_img.pl
sample/ia32/pcat/gcc/gmake.mak
sample/ia32/pcat/gcc/ipl.S [new file with mode: 0755]
sample/ia32/pcat/gcc/link_fd.x
sample/ia32/pcat/gcc/switch32.S [new file with mode: 0755]

index 3583084..ddf8587 100755 (executable)
@@ -9,13 +9,14 @@
 
 
 
-IPL_SEG   = 0x07C0                     /* ロードされるセグメントアドレス */
+IPL_SEG   = 0x07c0                     /* ロードされるセグメントアドレス */
 INIT_SEG  = 0x8000                     /* 初期化コード用セグメントアドレス */
 LOAD_SEG  = 0x9000                     /* 本体をロードするセグメントアドレス */
 
 
                                .code16
                                .text
+                               .org    0
 
                                .global ipl_top
 
@@ -45,7 +46,7 @@ ipl_start:
                /***** 初期化部 *****/
 init_start:
                                /* 画面のクリア */
-                               call    bios_clr_disp
+               ;               call    bios_clr_disp
                                
                                /* メッセージ出力 */
                                movw    $boot_message, %si
@@ -73,7 +74,6 @@ end_loop:
                                jmp             end_loop
                                
                                
-                               
                                /* 画面のクリア */
 bios_clr_disp:
                                movb    $0x3, %al
index c741089..0131d94 100755 (executable)
 
                                .code16
                                .text
+                               .align  4
 
 /************************************************
   起動ハンドラ
 ************************************************/
-                               .align          4
-_boot_handler: 
-                               jmp                     _boot_handler
                                
+_boot_handler: 
                                /* 画面のクリア */
                                call    bios_clr_disp
                                
@@ -38,12 +37,9 @@ _boot_handler:
 _boot_end:
                                jmp                     _boot_end
                                
-                               
-                               
-                               
                                lgdt    gdtr
                                lidt    idtr
-
+                               
                                movl    $0x11, %eax
                                movl    %eax, %cr0
                                jmp             _go_protect_mode
index ae09637..f87ad55 100755 (executable)
@@ -1,17 +1,33 @@
 #!/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);
 
index 6622c2b..0515c7f 100755 (executable)
@@ -35,6 +35,7 @@ TARGET := $(TARGET)dbg
 endif
 
 
+# %jp{リンカスクリプト}
 LINK_SCRIPT = link_fd.x
 
 
@@ -61,8 +62,7 @@ include $(KERNEL_MAKINC_DIR)/gcc_d.inc
 SRC_DIRS += . ..
 
 # アセンブラファイルの追加
-ASRCS += ./bootloader.S                        \
-         ./crt0.S
+ASRCS += ./crt0.S
 
 
 # %jp{C言語ファイルの追加}
@@ -87,7 +87,7 @@ LIBS  +=
 # --------------------------------------
 
 .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
@@ -100,8 +100,8 @@ depend: makeexe_depend
 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
@@ -115,11 +115,23 @@ include $(KERNEL_MAKINC_DIR)/makeexe.inc
 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
 
 
diff --git a/sample/ia32/pcat/gcc/ipl.S b/sample/ia32/pcat/gcc/ipl.S
new file mode 100755 (executable)
index 0000000..ddf8587
--- /dev/null
@@ -0,0 +1,115 @@
+/** 
+ * 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  */
index af14ed7..8b598f3 100755 (executable)
@@ -1,28 +1,17 @@
-ENTRY(ipl_top)
+ENTRY(_boot_handler)
 
-MEMORY
-{
-       ipl   : o = 0x07c00, l = 0x000400
-       load  : o = 0x09000, l = 0x167800
-}
 
 SECTIONS
 {
-       .ipl : AT (0x00000)
-       {
-               ___vector = . ; 
-               */bootloader.o(.text)
-               FILL(0x00)
-               ___vector_end = . ; 
-       } > ipl
-       .text : AT (0x00800)
+       .text :
        {
                 ___text = . ; 
+               objs_*/crt0.o(.text)
                *(.text)
                *(.strings)
                *(.rodata*)
                 ___text_end = . ; 
-       }  > load
+       }
        .tors :
        {
                . = ALIGN(4);
@@ -32,20 +21,20 @@ SECTIONS
                ___dtors = . ;
                *(.dtors)
                ___dtors_end = . ;
-       } > load
+       }
        data : 
        {
                ___data = . ;
                *(.data)
                ___data_end = . ;
-       } > load
+       }
        .bss :
        {
                ___bss = . ;
                *(.bss)
                *(COMMON)
                ___bss_end = . ;  
-       }  >load
+       }
 }
 
 
diff --git a/sample/ia32/pcat/gcc/switch32.S b/sample/ia32/pcat/gcc/switch32.S
new file mode 100755 (executable)
index 0000000..339ced8
--- /dev/null
@@ -0,0 +1,180 @@
+/** 
+ * 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 */