-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKERNEL.ASM
250 lines (191 loc) · 4.57 KB
/
KERNEL.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
;NXOS kernel
;-----------
;Written by: Alberto Venturini (Alb‚) - 2000/2001
;Email address: [email protected]
;------------------------------------------------
;
;
;Sorry, but comments are in italian... :(
org 0h
InitSystem:
;Inizializzo i segmenti
mov ax,1000h
mov ss,ax
mov sp,0fffeh
mov ds,ax
mov ax,0003h
int 10h
mov si,offset InitSystemMsg
call WriteSimple
;Inizializzo gli "exception handlers"
call InstallExceptionHandlers
;Inizializzo gli interrupt per le chiamate di sistema
call InstallInterrupt
;Inizializzo la Fat
mov si,offset InitFat
call WriteSimple
call Fat12_FatInit
;Inizializzo la gestione della memoria
mov si,offset InitMem
call WriteSimple
call MemInit
;Inizializzo la gestione dei processi multitasking
mov si,offset InitMt
call WriteSimple
call StartMultiTasking
mov al,13
mov ah,0eh
int 10h
mov al,10
int 10h
;Installo il driver video
mov si,offset InitVideoDrv
call WriteSimple
mov si,offset VideoDrv
call LoadProgram
jc KeyboardInstall
mov bl,1
call RunProcess
KeyboardInstall:
;Installo il driver della tastiera
mov si,offset InitKeyboardDrv
call WriteSimple
mov si,offset KeyboardDrv
call LoadProgram
jc BigMemInstall
mov bl,1
call RunProcess
BigMemInstall:
;Installo il driver per la Real mode 32-bit
mov si,offset InitBigMemDrv
call WriteSimple
mov si,offset BigMemDrv
call LoadProgram
jc ShellInstall
mov bl,1
call RunProcess
ShellInstall:
mov si,offset ContinueMsg
call WriteSimple
mov ah,00h
int 25h
; [..]
mov si,offset InitShell
call WriteSimple
; mov ah,00h
; int 25h
mov si,offset Shell
call LoadProgram
jc ErrorNoShell
call RunProcess
mov si,1
mov ah,02h
int 24h
InitSystem_End:
mov ah,02h
mov bl,1
int 20h
ErrorNoShell:
mov si,offset ErrorShell
call WriteSimple
mov ah,00h
int 25h
jmp EndSystem
;------------------------------------------------------------------------------
EndSystem:
call EndMultiTasking
mov ah,01h ;Termina la Real Mode a 32 bit.
int 2fh
mov ah,04h
int 25h ;Termina il driver della tastiera
mov si,offset ShutDown
EndSystem_WriteMsg:
call WriteSimple
mov ah,00h
int 16h
cmp al,'R'
je EndSystem_Reboot
cmp al,'r'
je EndSystem_Reboot
cmp al,'S'
je EndSystem_ShutDown
cmp al,'s'
je EndSystem_ShutDown
jmp EndSystem_WriteMsg
EndSystem_Reboot:
int 19h
EndSystem_ShutDown:
mov ax,5300h
xor bx, bx
int 15h
mov ax,5304h
xor bx, bx
int 15h
mov ax,5301h
xor bx, bx
int 15h
mov ax,5307h
mov bx,1
mov cx,3
int 15h
;------------------------------------------------------------------------------
SetError:
;input AL=codice dell'errore
mov cs:[SystemError],al
ret
;------------------------------------------------------------------------------
GetError:
;output AL=codice dell'errore
mov al,cs:[SystemError]
ret
;------------------------------------------------------------------------------
WriteSimple:
;input CS:SI --> indirizzo della stringa
push ax
push bx
push si
mov ah,0eh
mov bx,7
WriteSimple_1:
mov al,byte ptr cs:[si]
test al,al
jz WriteSimple_End
int 10h
inc si
jmp WriteSimple_1
WriteSimple_End:
pop si
pop bx
pop ax
ret
;------------------------------------------------------------------------------
include Fat12d.asm
include MemManag.asm
include Processi.asm
include Interrpt.asm
include Except.asm
include LoadExeC.asm
;------------------------------------------------------------------------------
;Kernel Data
;Messaggi
InitSystemMsg db 'NXOS version 0.3.3',13,10,0
InitFat db 'Initializing filesystem: 12-bit Fat...',13,10,0
InitMem db 'Initializing 16-bit memory management...',13,10,0
InitMt db 'Initializing process manager (multitasker)...',13,10,0
InitVideoDrv db 'Loading video driver (video.drv)...',13,10,0
InitKeyboardDrv db 'Loading keyboard driver (keyboard.drv)...',13,10,0
InitBigMemDrv db 'Loading 32-bit real mode driver (bigmem.drv)...',13,10,0
InitShell db 'Loading shell (shell.bin)...',13,10,0
ErrorShell db 'Error - file shell.bin not found.',13,10,0
ContinueMsg db 'Press any key to continue...',13,10,0
ShutDown db 'Do you want to (R)eboot or (S)hutdown?',0
;Shell db 'SHELL BIN'
;VideoDrv db 'VIDEO DRV'
;KeyboardDrv db 'KEYBOARDDRV'
;BigMemDrv db 'BIGMEM DRV'
Shell db 'SHELL.BIN'
VideoDrv db 'VIDEO.DRV'
KeyboardDrv db 'KEYBOARD.DRV'
BigMemDrv db 'BIGMEM.DRV'
;------------------------------------------------------------------------------
include Sysmem.asm