Skip to content

Commit e64ae99

Browse files
committed
first commit
1 parent 6d4ac19 commit e64ae99

File tree

6 files changed

+386
-0
lines changed

6 files changed

+386
-0
lines changed

BestsoftOS.flp

1.41 MB
Binary file not shown.

BestsoftOS.iso

1.76 MB
Binary file not shown.

bootloader.asm

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
BITS 16
2+
3+
4+
jmp short bootloader_start
5+
nop
6+
7+
8+
9+
10+
OEMLabel db "BESTSOFT"
11+
BytesPerSector dw 512
12+
SectorsPerCluster db 1
13+
ReservedForBoot dw 1
14+
NumberOfFats db 2
15+
RootDirEntries dw 224
16+
17+
LogicalSectors dw 2880
18+
MediumByte db 0F0h
19+
SectorsPerFat dw 9
20+
SectorsPerTrack dw 18
21+
Sides dw 2
22+
HiddenSectors dd 0
23+
LargeSectors dd 0
24+
DriveNo dw 0
25+
Signature db 41
26+
VolumeID dd 00000000h
27+
VolumeLabel db " "
28+
FileSystem db "FAT12 "
29+
30+
31+
32+
33+
bootloader_start:
34+
mov ax, 07C0h ; Set up 4K of stack space above buffer
35+
add ax, 544 ; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
36+
cli ; Disable interrupts while changing stack
37+
mov ss, ax
38+
mov sp, 4096
39+
sti ; Restore interrupts
40+
41+
mov ax, 07C0h ; Set data segment to where we are loaded
42+
mov ds, ax
43+
44+
; NOTE: A few early BIOSes are reported to improperly set DL
45+
46+
cmp dl, 0
47+
je no_change
48+
mov [bootdev], dl ; Save boot device number
49+
mov ah, 8 ; Get drive parameters
50+
int 13h
51+
jc fatal_disk_error
52+
and cx, 3Fh ; Maximum sector number
53+
mov [SectorsPerTrack], cx ; Sector numbers start at 1
54+
movzx dx, dh ; Maximum head number
55+
add dx, 1 ; Head numbers start at 0 - add 1 for total
56+
mov [Sides], dx
57+
58+
no_change:
59+
mov eax, 0 ; Needed for some older BIOSes
60+
61+
62+
63+
floppy_ok:
64+
mov ax, 19
65+
call l2hts
66+
67+
mov si, buffer
68+
mov bx, ds
69+
mov es, bx
70+
mov bx, si
71+
72+
mov ah, 2
73+
mov al, 14
74+
75+
pusha
76+
77+
78+
read_root_dir:
79+
popa
80+
pusha
81+
82+
stc
83+
int 13h
84+
85+
jnc search_dir
86+
call reset_floppy
87+
jnc read_root_dir
88+
89+
jmp reboot
90+
91+
92+
search_dir:
93+
popa
94+
95+
mov ax, ds
96+
mov es, ax
97+
mov di, buffer
98+
99+
mov cx, word [RootDirEntries]
100+
mov ax, 0
101+
102+
103+
next_root_entry:
104+
xchg cx, dx
105+
106+
mov si, kern_filename
107+
mov cx, 11
108+
rep cmpsb
109+
je found_file_to_load
110+
111+
add ax, 32
112+
113+
mov di, buffer
114+
add di, ax
115+
116+
xchg dx, cx
117+
loop next_root_entry
118+
119+
mov si, file_not_found
120+
call print_string
121+
jmp reboot
122+
123+
124+
found_file_to_load:
125+
mov ax, word [es:di+0Fh]
126+
mov word [cluster], ax
127+
128+
mov ax, 1
129+
call l2hts
130+
131+
mov di, buffer
132+
mov bx, di
133+
134+
mov ah, 2
135+
mov al, 9
136+
137+
pusha
138+
139+
140+
read_fat:
141+
popa
142+
pusha
143+
144+
stc
145+
int 13h
146+
147+
jnc read_fat_ok
148+
call reset_floppy
149+
jnc read_fat
150+
151+
152+
fatal_disk_error:
153+
154+
mov si, disk_error
155+
call print_string
156+
jmp reboot
157+
158+
159+
read_fat_ok:
160+
popa
161+
162+
mov ax, 2000h
163+
mov es, ax
164+
mov bx, 0
165+
166+
mov ah, 2
167+
mov al, 1
168+
169+
push ax
170+
171+
172+
load_file_sector:
173+
mov ax, word [cluster]
174+
add ax, 31
175+
176+
call l2hts
177+
178+
mov ax, 2000h
179+
mov es, ax
180+
mov bx, word [pointer]
181+
182+
pop ax
183+
push ax
184+
185+
stc
186+
int 13h
187+
188+
jnc calculate_next_cluster
189+
190+
call reset_floppy
191+
jmp load_file_sector
192+
193+
calculate_next_cluster:
194+
mov ax, [cluster]
195+
mov dx, 0
196+
mov bx, 3
197+
mul bx
198+
mov bx, 2
199+
div bx
200+
mov si, buffer
201+
add si, ax
202+
mov ax, word [ds:si]
203+
204+
or dx, dx
205+
206+
jz even
207+
208+
209+
odd:
210+
shr ax, 4
211+
jmp short next_cluster_cont
212+
213+
214+
even:
215+
and ax, 0FFFh
216+
217+
218+
next_cluster_cont:
219+
mov word [cluster], ax
220+
221+
cmp ax, 0FF8h
222+
jae end
223+
224+
add word [pointer], 512
225+
jmp load_file_sector
226+
227+
228+
end:
229+
pop ax
230+
mov dl, byte [bootdev]
231+
232+
jmp 2000h:0000h
233+
234+
235+
reboot:
236+
mov ax, 0
237+
int 16h
238+
mov ax, 0
239+
int 19h
240+
241+
242+
print_string:
243+
pusha
244+
245+
mov ah, 0Eh
246+
247+
.repeat:
248+
lodsb
249+
cmp al, 0
250+
je .done
251+
int 10h
252+
jmp short .repeat
253+
254+
.done:
255+
popa
256+
ret
257+
258+
259+
reset_floppy:
260+
push ax
261+
push dx
262+
mov ax, 0
263+
mov dl, byte [bootdev]
264+
stc
265+
int 13h
266+
pop dx
267+
pop ax
268+
ret
269+
270+
271+
l2hts:
272+
273+
push bx
274+
push ax
275+
276+
mov bx, ax
277+
278+
mov dx, 0
279+
div word [SectorsPerTrack]
280+
add dl, 01h
281+
mov cl, dl
282+
mov ax, bx
283+
284+
mov dx, 0
285+
div word [SectorsPerTrack]
286+
mov dx, 0
287+
div word [Sides]
288+
mov dh, dl
289+
mov ch, al
290+
291+
pop ax
292+
pop bx
293+
294+
mov dl, byte [bootdev]
295+
296+
ret
297+
298+
299+
300+
kern_filename db "KERNEL BIN"
301+
302+
disk_error db "Floppy error! Press any key...", 0
303+
file_not_found db "KERNEL.BIN not found!", 0
304+
305+
bootdev db 0
306+
cluster dw 0
307+
pointer dw 0
308+
309+
310+
311+
312+
313+
times 510-($-$$) db 0
314+
dw 0AA55h
315+
316+
317+
buffer:
318+
319+
320+
321+

bootloader.bin

512 Bytes
Binary file not shown.

kernel.asm

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
BITS 16
2+
[org 0]
3+
4+
mov ax,cs
5+
mov ds,ax
6+
mov es,ax
7+
mov ax,0x7000
8+
mov ss,ax
9+
mov sp,ss
10+
11+
start:
12+
13+
mov al,03h
14+
mov ah,0
15+
int 10h
16+
17+
_mouser:
18+
mov ah,02h
19+
mov dl,bl
20+
int 10h
21+
mov ah , 80h
22+
int 16h
23+
24+
cmp al,08h
25+
je _backspace
26+
cmp al,09h
27+
jge _print
28+
cmp al,07h
29+
jae _print
30+
jmp _mouser
31+
32+
_backspace:
33+
sub bl,1h
34+
jmp _backspace2
35+
36+
_backspace2:
37+
mov ah,0eh
38+
mov al,20h
39+
int 10h
40+
jmp _mouser
41+
42+
_down:
43+
add cl,1h
44+
jmp _mouser
45+
46+
_up:
47+
sub cl,1h
48+
jmp _mouser
49+
50+
_left:
51+
sub bl,1h
52+
jmp _mouser
53+
54+
_right:
55+
add bl,1h
56+
jmp _mouser
57+
58+
_print:
59+
mov ah,0eh
60+
cmp al,80h
61+
je _down
62+
int 10h
63+
jmp _right
64+
65+
ret

kernel.bin

95 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)