-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenstart.asm
More file actions
201 lines (154 loc) · 4.09 KB
/
benstart.asm
File metadata and controls
201 lines (154 loc) · 4.09 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
; ==================================================================
; benOS Bootloader
; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
;
; The official bootloader for benOS and BenchX desktop/laptop products.
; The first bootloader built for a decentralized operating system.
; Many bootloaders were looked at and utilized in the creation of
; benOS's BenchX bootloader.
;
; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
; ==================================================================
ORG 0x7C00
SECTION .text
USE16
; ------------------------------------------------------------------
; benOS Boot Process - Starting the Engines
; ------------------------------------------------------------------
boot: ; dl comes with disk
; benos boot process
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
; start the benOS engines
mov sp, 0x7C00
; start the CS engines
push ax
push word .init_codeseg
retf
; ------------------------------------------------------------------
; benOS Boot Process - Init Code Segments
; ------------------------------------------------------------------
.init_codeseg:
; After the boot process, benOS will need to retrieve the number of the primary disk.
; We are able to do that with mov and the [primary-disk].
; After retreiving disk number, it's registered using 'dl', an 8 byte registry.
mov [disk], dl
mov si, name
call print
call print_line
mov bx, (startup_start - boot) / 512
call print_hex
call print_line
mov bx, startup_start
call print_hex
call print_line
mov eax, (startup_start - boot) / 512
mov bx, startup_start
mov cx, (startup_end - startup_start) / 512
xor dx, dx
call load
call print_line
mov si, finished
call print
call print_line
jmp startup
load:
cmp cx, 127
jbe .ben_ready
pusha
mov cx, 127
call load
popa
add eax, 127
add dx, 127 * 512 / 16
sub cx, 127
jmp load
.ben_ready:
mov [BENFIN.addr], eax
mov [BENFIN.buf], bx
mov [BENFIN.count], cx
mov [BENFIN.seg], dx
call print_benfin
mov dl, [disk]
mov si, BENFIN
mov ah, 0x42
int 0x13
jc error
ret
store:
cmp cx, 127
jbe .ben_ready
pusha
mov cx, 127
call store
popa
add ax, 127
add dx, 127 * 512 / 16
sub cx, 127
jmp store
.ben_ready:
mov [BENFIN.addr], eax
mov [BENFIN.buf], bx
mov [BENFIN.count], cx
mov [BENFIN.seg], dx
call print_benfin
mov dl, [disk]
mov si, BENFIN
mov ah, 0x43
int 0x13
jc error
ret ; return ben_ready
print_benfin:
mov al, 13
call print_char
mov bx, [BENFIN.addr + 2]
call print_hex
mov bx, [BENFIN.addr]
call print_hex
mov al, '#'
call print_char
mov bx, [BENFIN.count]
call print_hex
mov al, ' '
call print_char
mov bx, [BENFIN.seg]
call print_hex
mov al, ':'
call print_char
mov bx, [BENFIN.buf]
call print_hex
ret ; return printed result of BENFIN
error:
call print_line
mov bh, 0
mov bl, ah
call print_hex
mov al, ' '
call print_char
mov si, errored
call print
call print_line
.halt:
cli
hlt
jmp .halt
%include "print.asm"
name: db "benOS Loader - Stage1",0
errored: db "Was unable to read from local primary disk.",0
finished: db "benOS Loader - Stage2",0
disk: db 0 ; disk with databyte 0
; ------------------------------------------------------------------
; benOS Boot Process - BENFIN
; ------------------------------------------------------------------
BENFIN:
db 0x10
db 0
.count: dw 0 ; integer 13 resets this to the number of blocks written to/from the primary disk in the boot process.
.buf: dw 0 ; Sets 0:7c00 as the memory in-buffer destination address
.seg: dw 0 ; Sets zero as the in-memory page, which we will utilize later in the boot process
.addr: dq 0 ; put the lba to read in this spot
times 510-($-$$) db 0 ; databyte 0
db 0x55 ; databyte 1
db 0xaa ; databyte 2