This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.S
164 lines (133 loc) · 2.34 KB
/
setup.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
.code16
.text
.equ SETUPSEG, 0x1020
.equ INITSEG, 0x9000
.equ LEN, 54
show_text:
mov $SETUPSEG, %ax
mov %ax, %es
mov $0x03, %ah
xor %bh, %bh
int $0x10
mov $0x000a, %bx
mov $0x1301, %ax
mov $LEN, %cx
mov $msg, %bp
int $0x10
ljmp $SETUPSEG, $_start
_start:
# Save corsor position
mov $INITSEG, %ax
mov %ax, %ds
mov $0x03, %ah
xor %bh, %bh
int $10
mov %dx, %ds:0
# Extended memory store
# 0x15 0x88
mov $0x88, %ah
int $0x15
mov %ax, %ds:2
# VGA Display Mode
mov $0x12, %ah
mov $0x10, %bl
int $0x10
mov %ax, %ds:8
mov %bx, %ds:10
mov %cx, %ds:12
#Harddisk Parameter table
mov $0x0000, %ax
mov %ax, %ds
lds %ds:4*0x41, %si
mov $INITSEG, %ax
mov %ax, %es
mov $0x0080, %di
mov $0x10, %cx
rep movsb
mov $0x0000, %ax
mov %ax, %ds
lds %ds:4*0x46, %si
mov $INITSEG, %ax
mov %ax, %es
mov $0x0090, %di
mov $0x10, %cx
rep movsb
# Check second harddisk parameter
mov $0x1500, %ax
mov $0x81, %dl
int $0x13
jc no_disk1
cmp $3, %ah
je is_disk1
no_disk1:
mov $INITSEG, %ax
mov %ax, %es
mov $0x0090, %di
mov $0x10, %cx
mov $0x00, %ax
rep stosb
is_disk1:
# Prepare to enter protect mode
cli
#Move System image to 0x0000:0x0000
mov $0x0000, %ax
do_move:
# rep movsw ds:si -> es:di
# 0x1000:0 -> 0x0000:0
# 0x2000:0 -> 0x1000:0
mov %ax, %es
add $0x1000, %ax
cmp $0x9000, %ax
jz end_move
mov %ax, %ds
sub %di, %di
sub %si, %si
mov $0x8000, %cx
rep movsw
jmp do_move
# GDT & IDT load
end_move:
mov $SETUPSEG, %ax
mov %ax, %ds
lgdt gdt_48
enable_a20:
in $0x92, %al
or $0x02, %al
out %al, $0x92
# CR0 Protect Enabled = 1
mov %cr0, %eax
bts $0, %eax
mov %eax, %cr0
# Jump to Protect Mode
# Long Jump
# <Segment Selector>:<Offset>
.equ sel_cs0, 0x0008
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
ljmp $sel_cs0, $0
# 8259A programming
# GDT Descriptor
gdt_48:
.word 0x800
.word 512+gdt, 0x9
# Global Descriptor Table
gdt:
.word 0, 0, 0, 0
# Code Segment Size 8MB BaseAddr:0x0000:0x0000
# 0 -> 2047
.word 0x07FF # Limit 0-2047
.word 0x0000 # Base
.word 0x9A00 # 1 00 1 1010 0000 0000
.word 0x00c0 # 0000 0000 1 1 0 0 0000
.word 0x07FF # Limit 0-2047
.word 0x0000 # Base
.word 0x9200 # 1 00 1 0010 0000 0000
.word 0x00c0 # 0000 0000 1 1 0 0 0000
msg:
.byte 13, 10
.ascii "You've sucessfully load the floppy data into RAM"
.byte 13, 10, 13, 10
#Proof Floppy Disk Load OK