66;; os_doc/bios_specs_edd30.pdf
77;; -- https://github.com/fysnet/FYSOS/blob/master/boot/embr/embr.asm
88;; http://www.ctyme.com/intr/rb-0708.htm
9- ;;
9+ ;; -- https://stanislavs.org/helppc/int_10.html
10+
1011;; En 16 bits cuando el procesador no es de 16 si no de 32 o 64 pero ejecuta en
1112;; un modo de 16 bits, prestar atencion a algunas instrucciones: jumps por ejemp
1213;; lo. El mismo opcode lo interpreta en 32 de una manera y en 16 de otra, saltan
@@ -32,30 +33,19 @@ entry:
3233 mov [ driveNumber ], dl ;; Bios passes drive number in dl.
3334
3435 call pushTest
35-
36- mov ah , 0x41 ;; Check extensions present.
37- mov bx , 55AAh ;; Required signature.
38- mov dl , [ driveNumber ]
39- int 0x13
40- jc notify_ext_not_supported
41- cmp bx , 0xAA55
42- jne notify_ext_not_supported
43-
44- mov si , msg_ok
45- call print
36+ call extensionTest
4637
4738 mov si , msg_load
4839 call print
4940
50- mov ax , 512 ;; Load 512 sectors = 262144 bytes = 256 KiB.
41+ mov ax , 512 ;; Cant sectors. Load 512 = 262144 bytes = 256 KiB.
5142 mov bx , 6117 ;; Offset = 8192.
5243 mov cx , 0x8000 ;; Copy here.
5344 call diskcpy ;; Copia payload completo.
5445
5546 mov si , msg_ok
5647 call print
5748
58-
5949;; TO-DO reponer
6050 ;;mov eax, [0x8000 + 6]
6151 ;;cmp eax, "BOOT" ; Match against the tsl_start.sys binary
@@ -92,25 +82,21 @@ entry:
9282 jmp 0x0000 : 0x8000
9383
9484
95-
96-
97- err:
98- mov si , msg_err
99- call print
85+ ;;==============================================================================
86+ ;; errors
87+ ;;==============================================================================
10088
10189notify_ext_not_supported:
10290 mov si , msg_no
10391 call print
10492
105-
106- halt:
93+ .halt:
10794 mov si , msg_halt
10895 call print
10996 hlt
11097 jmp $
11198
11299
113-
114100;;==============================================================================
115101;; diskcpy | Copy n sectors from disk.
116102;;==============================================================================
@@ -134,7 +120,7 @@ diskcpy:
134120;; Arguments:
135121;; -- eax: high word of 64 bit sector.
136122;; -- ebx: low word of 64 bit sector.
137- ;; -- {es:cx}: destination address.
123+ ;; -- {es:cx}: destination address, {seg:offset}
138124;; Returns:
139125;; -- eax: high word of next sector.
140126;; -- ebx: low word of sector.
@@ -143,15 +129,16 @@ diskcpy:
143129
144130readSec:
145131 push eax
146- xor eax , eax ;; We don't need to load from sectors > 32-bit
147132 push dx
148133 push si
149134 push di
150135
151- read_it:
152- push eax ; Save the sector number
153- push ebx
154- mov di , sp ; remember parameter block end
136+ xor eax , eax ;; We don't need to load from sectors > 32-bit
137+
138+ .read:
139+ push eax ;; Backup sectorNumber.hi
140+ push ebx ;; Backup sectorNumber.lo
141+ mov di , sp ;; Base of disk address packet.
155142
156143 ;; Build disk address packet.
157144 push eax ;; dap10..15 dap.srcLba.hi
@@ -176,7 +163,7 @@ read_it:
176163 xor ah , ah ; else, reset and retry
177164 int 0x13
178165 pop ax
179- jmp read_it
166+ jmp .read
180167
181168read_ok:
182169 add ebx , 1 ; increment next sector with carry
@@ -196,67 +183,98 @@ no_incr_es:
196183 pop eax
197184
198185 ret
199- ;------------------------------------------------------------------------------
200186
201187
202188;;==============================================================================
203- ;; pushtest | Verifica compatibilidad de opcode push eax en modo 16 bits
189+ ;; pushTest | Verifica compatibilidad de opcode push eax en modo 16 bits
190+ ;;==============================================================================
191+ ;; Registers CS, DS, ES, SS, BX, CX, DX are preserved unless
192+ ;; explicitly changed
204193;;==============================================================================
205194
206195pushTest:
207196 mov bx , sp
208197 push eax
209198 sub bx , sp
210199 pop eax
211- add [ msg_sizeofPush + 32 ], bl
200+ add [ msg_sizeofPush + POSITION_COUNT ], bl
201+
212202 mov si , msg_sizeofPush
213203 call print
214204
205+ ret
206+
207+
208+ ;;==============================================================================
209+ ;; extensionTest | Verifica soporte de extension bios.
210+ ;;==============================================================================
211+ ;; Registers CS, DS, ES, SS, BX, CX, DX are preserved unless
212+ ;; explicitly changed
213+ ;;==============================================================================
214+
215+ extensionTest:
215216 mov si , msg_extSupport
216217 call print
217218
218- ret
219+ mov ah , 0x41 ;; Check extensions present.
220+ mov bx , 55AAh ;; Required signature.
221+ mov dl , [ driveNumber ]
222+ int 0x13
223+ jc notify_ext_not_supported
224+ cmp bx , 0xAA55
225+ jne notify_ext_not_supported
226+
227+ mov si , msg_ok
228+ call print
219229
230+ ret
220231
221232
233+ ;;==============================================================================
234+ ;; print | Imprime a pantalla usando bootservice.
235+ ;;==============================================================================
236+ ;; Argumentos:
237+ ;; -- si: string addr 16 bits.
238+ ;;==============================================================================
222239
223- ;------------------------------------------------------------------------------
224- ; 16-bit function to print a string to the screen
225- ; IN: SI - Address of start of string
226- print: ; Output string in SI to screen
240+ print:
227241 pusha
228- mov ah , 0x0E ; int 0x10 teletype function
229- .repe at :
230- lodsb ; Get char from string
242+ mov ah , 0x0e ;; int 0x10: write text in teletype mode.
243+
244+ .next:
245+ lodsb
231246 cmp al , 0
232- je .done ; If char is zero, end of string
233- int 0x10 ; Otherwise, print it
234- jmp short .repe at
235- .done:
247+ je .fin
248+ int 0x10 ;; Write boot service.
249+ jmp .next
250+
251+ .fin:
236252 popa
237253 ret
238254
239255
256+ ;;==============================================================================
257+ ;; section .data
240258;;==============================================================================
241259
242-
243- msg_sizeofPush: db "16b mode 32b push opcode pushes 0 bytes" , 13 , 10 , 0
260+ msg_sizeofPush: db "16b mode 32b push opcode pushes "
261+ POSITION_COUNT equ $ - msg_sizeofPush
262+ db "0 bytes" , 13 , 10 , 0
244263msg_extSupport: db "Verifying bios ext support.." , 0
245264msg_no: db " no" , 13 , 10 , 0
246265msg_load: db "Reading disk.." , 0
247266msg_ok: db " ok" , 13 , 10 , 0
248- msg_exec: db "Executing.." , 0
249- msg_err: db " error" , 0
250267msg_halt: db "Sys halted" , 0
251268
252- driveNumber: db 0x00
269+ driveNumber: db 0x00
253270
271+ ;; Zero fill.
254272times 446 - $ + $$ db 0
255273
256- ; False partition table entry required by some BIOS vendors.
257- db 0x80 , 0x00 , 0x01 , 0x00 , 0xEB , 0xFF , 0xFF , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF
274+ ;; False partition table entry required by some BIOS vendors.
275+ db 0x80 , 0x00 , 0x01 , 0x00 , 0xEB , 0xFF , 0xFF , 0xFF
276+ db 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF
258277
259- ;; TO-DO: ld script.
260- ;;times 510 - $ + $$ db 0
278+ times 510 - $ + $$ db 0
261279
262- sign dw 0xAA55
280+ sign: dw 0xAA55
0 commit comments