-
Notifications
You must be signed in to change notification settings - Fork 1
/
ben_common.asm
234 lines (175 loc) · 6.49 KB
/
ben_common.asm
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
; ==================================================================
; 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
; ==================================================================
; ------------------------------------------------------------------
; benOS Common Loaders - Load Kernel Args
; ------------------------------------------------------------------
SECTION .text
USE16
args:
.kernel_base dq 0x100000
.kernel_size dq 0
.stack_base dq 0
.stack_size dq 0
.env_base dq 0
.env_size dq 0
; ------------------------------------------------------------------
; benOS Common Loaders - Load Kernel Args
; ------------------------------------------------------------------
startup:
; enable A20-Line via IO-Port 92, might not work on all motherboards
in al, 0x92
or al, 2
out 0x92, al
%ifdef KERNEL
mov edi, [args.kernel_base]
mov ecx, (benos_kernel_file.end - benos_kernel_file)
mov [args.kernel_size], ecx
mov eax, (benos_kernel_file - boot)/512
add ecx, 511
shr ecx, 9
call load_extent
%else
call benfs
test eax, eax
jnz error
%endif
jmp .loaded_benos_kernel
.loaded_benos_kernel:
; ------------------------------------------------------------------
; benOS Common Loaders - benOS Memory Mapping Call
; ------------------------------------------------------------------
call ben_mm
; ------------------------------------------------------------------
; benOS Common Loaders - benOS BenPlay Video Loaders / Mode Finder
; ------------------------------------------------------------------
call benplay
; ------------------------------------------------------------------
; benOS Common Loaders - Initialize FPU
; ------------------------------------------------------------------
mov si, init_fpu_msg
call print
call initialize.fpu
; ------------------------------------------------------------------
; benOS Common Loaders - Initialize SSE
; ------------------------------------------------------------------
mov si, init_sse_msg
call print
call initialize.sse
mov si, startup_ben_arch_msg
call print
jmp startup_ben_arch
; ------------------------------------------------------------------
; benOS Common Loaders
; LOAD DISK 'EXTENT' INTO HIGH MEMORY
; EAX - Sector Address
; ECX - Sector Count
; EDI - Destination
; ------------------------------------------------------------------
load_extent:
; ------------------------------------------------------------------
; benOS Common Loaders
; LOADING KERNEL TO 1 MEGABYTE
; MOVE PARTIAL PIECE OF BENOS MICROKERNEL TO BENOS_LAUNCH_END
; THEN - COPY IT UP
; THEN - REPEAT UNTIL ALL OF THE benOS MICROKERNEL HAS BEEN LOADED
; ------------------------------------------------------------------
buffer_size_sectors equ 127
.lp:
cmp ecx, buffer_size_sectors
jb .break
; ------------------------------------------------------------------
; benOS Common Loaders - Save Counter
; ------------------------------------------------------------------
push eax
push ecx
push edi
; ------------------------------------------------------------------
; benOS Common Loaders - Populate Buffer
; ------------------------------------------------------------------
mov ecx, buffer_size_sectors
mov bx, benos_launch_end
mov dx, 0x0
; ------------------------------------------------------------------
; benOS Common Loaders - Load Sector
; ------------------------------------------------------------------
call load
; ------------------------------------------------------------------
; benOS Common Loaders - Setup benUnreal Mode
; ------------------------------------------------------------------
call benur
pop edi
; ------------------------------------------------------------------
; benOS Common Loaders - Move Data To benOS Launch End Stage
; ------------------------------------------------------------------
mov esi, benos_launch_end
mov ecx, buffer_size_sectors * 512 / 4
cld
a32 rep movsd
pop ecx
pop eax
add eax, buffer_size_sectors
sub ecx, buffer_size_sectors
jmp .lp
; ------------------------------------------------------------------------------------
; benOS Common Loaders - Any Left Over Microkernel Outside The Buffer - Loads Here
; ------------------------------------------------------------------------------------
.break:
; load the part of the kernel that does not fill the buffer completely
test ecx, ecx
jz .finish ; if cx = 0 => skip
push ecx
push edi
mov bx, benos_launch_end
mov dx, 0x0
call load
; ------------------------------------------------------------------
; benOS Common Loaders - Moving Remnants Of Microkernel
; ------------------------------------------------------------------
call benur
pop edi
pop ecx
mov esi, benos_launch_end
shl ecx, 7 ; * 512 / 4
cld
a32 rep movsd
; ------------------------------------------------------------------
; benOS Common Loaders - Finalization Of Common Bootloader Stage
; ------------------------------------------------------------------
.finish:
call print_line
ret
; ------------------------------------------------------------------
; benOS Common Loaders - Common Imports
; 'benconfig.asm' - benOS Bootloader Configuration
; 'ben_df.asm' - benOS Bootloader Diffs
; 'global_descriptor_table_entry.inc' - benOS GDTE
; 'benur.asm' - benOS Bootloader BENUR Mode
; 'ben_mm.asm' - benOS Bootloader Memory Mapping
; 'benplay.asm' - benOS BenPlay Bootloader Video Config / Driver Loader
; 'startup_ben.asm' - benOS Bootloader Launcher
; 'benfs.asm' - benOS Local FileSystem
; ------------------------------------------------------------------
%include "benconfig.asm"
%include "ben_df.inc"
%include "global_descriptor_table_entry.inc"
%include "benur.asm"
%include "ben_mm.asm"
%include "benplay.asm"
%include "startup_ben.asm"
%ifndef KERNEL
%include "benfs.asm"
%endif
init_fpu_msg: db "Initialize FPU",13,10,0
init_sse_msg: db "Initialize SSE",13,10,0
init_pit_msg: db "Initialize PIT",13,10,0
init_pic_msg: db "Initialize PIC",13,10,0
startup_ben_arch_msg: db "Startup benOS Arch",13,10,0