OSDN Git Service

projects clean up 1
[pinoc/pinoc.git] / tryos / tryos_test / pinoc_x86 / test / PINoC / boot / src / bootsct.cpp
1 #include "../../../common/typedef.h"
2 #include "../head/realmode.h"
3
4 vo io_load16();
5 vo io_debug16();
6
7 /*******************************************************************************
8                 スタックの初期化
9  *******************************************************************************/
10 __asm__(
11                 ".text                                          \n\t"
12                 "movw   $0x0400,        %ax             \n\t"
13                 "movw   %ax,            %ss             \n\t"
14                 "movl   $0x0,           %eax    \n\t"
15                 "movl   %eax,           %esp    \n\t"
16                 "movl   %eax,           %ebp    \n\t"
17 );
18
19 /*******************************************************************************
20                 メイン関数
21  *******************************************************************************/
22 void main16()
23 {
24         // ブートローダを0x5000番地へ配置
25         io_load16();
26
27 //#if DEBUG
28 //      io_debug16();
29 //#endif
30
31         // 関数の途中で抜けるのでスタックを戻しておく
32         __asm__("popl   %ebx");
33
34
35         /*--------------------------------------------------------------------------------
36                          ブートローダへjamp
37          --------------------------------------------------------------------------------*/
38         __asm__("jmp    0x5000");
39
40 }
41
42 /*******************************************************************************
43                 サブ関数
44  *******************************************************************************/
45 //vo io_debug16()       // 画面に何か1つ表示します
46 //{
47 //
48 //      __asm__(
49 //                      "pushw  %ax                             \n\t"
50 //                      "movb   $0x0e,  %ah             \n\t"
51 //                      "movb   $1,             %al             \n\t"
52 //                      "int    $0x10                   \n\t"
53 //                      "popw   %ax                             \n\t"
54 //      );
55 //}
56
57 // フロッピーディスクからBIOSの力を借りてデータを読み込みます
58 // biosがつかえなくなったらドライバの力を...
59 vo io_load16()
60 {
61         __asm__(
62                         "movw   $0x500, %di             \n\t"
63                         "movw   %di,            %es             \n\t"
64                         "movw    $0x00,     %bx  \n\t"
65
66                         "movb    $0x00,     %ch  \n\t"
67                         "movb    $0x00,     %dh  \n\t"
68                         "movb    $0x02,     %cl  \n\t"
69
70                         "movw    $0x00,     %si  \n\t" // 失敗カウンタ初期化
71
72                         "io_load_retry:          \n\t"
73
74                         "movb    $0x02,     %ah  \n\t"
75                         "movb    $0x08,     %al  \n\t" // 連続したセクタr
76                         "movb    $0x00,     %dl  \n\t"
77                         "int     $0x13           \n\t" //       セクタ読み込み[bios]
78
79                         "jnc     io_load_success        \n\t"
80
81                         "add     $0x01,     %si  \n\t" //       失敗回数をカウントアップ
82                         "cmp     $0x05,     %si  \n\t" // 5回失敗したらエラー終了
83                         "jae     io_load_error   \n\t"
84
85                         "movb    $0x00,     %ah  \n\t"
86                         "movb    $0x00,     %dl  \n\t"
87                         "int     $0x13           \n\t"
88                         "jmp     io_load_retry   \n\t" //       初期化してリトライ
89         );
90
91         __asm__("io_load_error:");
92 #if DEBUG
93 //      io_debug16();
94 #endif
95
96         __asm__("io_load_success:");
97 #if DEBUG
98 //      io_debug16();
99 #endif
100
101 }
102