11;;==============================================================================
2- ;; Master Boot Record
3- ;;
2+ ;; master boot record | @file /asm/boot/mbr.asm
3+ ;;==============================================================================
44;; Referencias:
5- ;; -- https://github.com/fysnet/FYSOS/blob/master/boot/embr/embr.asm
65;; -- BIOS Enhanced Disk Drive Specification 3.0: http://www.o3one.org/hwdocs/bi
76;; os_doc/bios_specs_edd30.pdf
7+ ;; -- https://github.com/fysnet/FYSOS/blob/master/boot/embr/embr.asm
88;; http://www.ctyme.com/intr/rb-0708.htm
99;;
10- ;; En 16 bits cuando el procesador no es de 16 si no de 32 o 64 en un modo de 16
11- ;; bits, prestar atencion a algunas instrucciones: jumps por ejemplo. El mismo o
12- ;; pcode lo interpreta en 32 de una manera y en 16 de otra, saltando en cada uno
13- ;; de esos casos a direcciones cercanas pero distintas porque en 32 toma operand
14- ;; o de 32 y en 16 de 16 (8?) lo cual genera un offset en la direccion de destin
15- ;; o . Pero un push de 32 es reconocido en 16 bits y ejecutado correctamente a pe
16- ;; sar de estar en modo de 16.
10+ ;; En 16 bits cuando el procesador no es de 16 si no de 32 o 64 pero ejecuta en
11+ ;; un modo de 16 bits, prestar atencion a algunas instrucciones: jumps por ejemp
12+ ;; lo. El mismo opcode lo interpreta en 32 de una manera y en 16 de otra, saltan
13+ ;; do en cada uno de esos casos a direcciones cercanas pero distintas porque en
14+ ;; 32 toma operando de 32 y en 16 de 16 (8?) lo cual genera un offset en la dire
15+ ;; ccion de destino . Pero un push de 32 es reconocido en 16 bits y ejecutado cor
16+ ;; rectamente a pesar de estar en modo de 16.
1717;;==============================================================================
1818
1919
@@ -31,16 +31,7 @@ entry:
3131
3232 mov [ driveNumber ], dl ;; Bios passes drive number in dl.
3333
34- mov bx , sp
35- push eax
36- sub bx , sp
37- pop eax
38- add [ msg_sizeofPush + 32 ], bl
39- mov si , msg_sizeofPush
40- call print_string_16
41-
42- mov si , msg_extSupport
43- call print_string_16
34+ call pushTest
4435
4536 mov ah , 41h ;; Check extensions present.
4637 mov bx , 55AAh ;; Required signature.
@@ -51,23 +42,18 @@ entry:
5142 jne print_ext_not_supported
5243
5344 mov si , msg_ok
54- call print_string_16
45+ call print
5546
5647 mov si , msg_load
57- call print_string_16
48+ call print
5849
59- mov ax , 512 ;; Load 512 sectors = 262144 bytes = 256 KiB.
50+ mov ax , 512 ;; Load 512 sectors = 262144 bytes = 256 KiB.
6051 mov bx , 6117 ;; Offset = 8192.
6152 mov cx , 0x8000 ;; Copy here.
62-
63- load_nextsector:
64- call readsector ;; Each loop 512 bytes.
65- dec ax
66- cmp ax , 0
67- jnz load_nextsector
53+ call diskcpy
6854
6955 mov si , msg_ok
70- call print_string_16
56+ call print
7157
7258
7359;; TO-DO reponer
@@ -103,37 +89,60 @@ load_nextsector:
10389 mov fs , ax
10490 mov es , ax
10591
106-
10792 jmp 0x0000 : 0x8000
10893
10994
11095err:
11196 mov si , msg_err
112- call print_string_16
97+ call print
11398
11499;; TO-DO: aqui mensaje.
115100print_ext_not_supported:
116101 mov si , msg_no
117- call print_string_16
102+ call print
118103
119104
120105halt:
121106 mov si , msg_halt
122- call print_string_16
107+ call print
123108 hlt
124109 jmp $
125110
126- ;------------------------------------------------------------------------------
127- ; Read a sector from a disk, using LBA
128- ; IN: EAX - High word of 64-bit DOS sector number
129- ; EBX - Low word of 64-bit DOS sector number
130- ; ES:CX - destination buffer
131- ; OUT: ES:CX points one byte after the last byte read
132- ; EAX - High word of next sector
133- ; EBX - Low word of sector
134- readsector:
111+
112+
113+ ;;==============================================================================
114+ ;; diskcpy | Copy n sectors from disk.
115+ ;;==============================================================================
116+ ;; Arguments:
117+ ;; -- ax: cant of 512 mem sectors to copy.
118+ ;; -- bx: source offset in disk (addr/512).
119+ ;; -- cx: destination addr.
120+ ;;==============================================================================
121+
122+ diskcpy:
123+ call readSec ;; Each loop 512 bytes.
124+ dec ax
125+ cmp ax , 0
126+ jnz diskcpy
127+ ret
128+
129+
130+ ;;==============================================================================
131+ ;; readSec | Read a sector from a disk using extended read.
132+ ;;==============================================================================
133+ ;; Arguments:
134+ ;; -- eax: high word of 64 bit sector.
135+ ;; -- ebx: low word of 64 bit sector.
136+ ;; -- {es:cx}: destination address.
137+ ;; Returns:
138+ ;; -- eax: high word of next sector.
139+ ;; -- ebx: low word of sector.
140+ ;; -- {es:cx}: p2source + cantBytes2copy
141+ ;;==============================================================================
142+
143+ readSec:
135144 push eax
136- xor eax , eax ; We don't need to load from sectors > 32-bit
145+ xor eax , eax ; ; We don't need to load from sectors > 32-bit
137146 push dx
138147 push si
139148 push di
@@ -143,12 +152,13 @@ read_it:
143152 push ebx
144153 mov di , sp ; remember parameter block end
145154
146- push eax ; [C] sector number high 32bit
147- push ebx ; [8] sector number low 32bit
148- push es ; [6] buffer segment
149- push cx ; [4] buffer offset
150- push byte 1 ; [2] 1 sector (word)
151- push byte 16 ; [0] size of parameter block (word)
155+ ;; Build disk address packet.
156+ push eax ;; dap10..15 dap.srcLba.hi
157+ push ebx ;; dap06..09 dap.srcLba.lo
158+ push es ;; dap04..05 dap.dst.seg
159+ push cx ;; dap02..03 dap.dst.offset
160+ push byte 1 ;; dap01 dap.bkCant
161+ push byte 16 ;; dap00 dap.pkSiz
152162
153163 mov si , sp
154164 mov dl , [ driveNumber ]
@@ -188,10 +198,31 @@ no_incr_es:
188198;------------------------------------------------------------------------------
189199
190200
201+ ;;==============================================================================
202+ ;; pushtest | Verifica compatibilidad de opcode push eax en modo 16 bits
203+ ;;==============================================================================
204+
205+ pushTest:
206+ mov bx , sp
207+ push eax
208+ sub bx , sp
209+ pop eax
210+ add [ msg_sizeofPush + 32 ], bl
211+ mov si , msg_sizeofPush
212+ call print
213+
214+ mov si , msg_extSupport
215+ call print
216+
217+ ret
218+
219+
220+
221+
191222;------------------------------------------------------------------------------
192223; 16-bit function to print a string to the screen
193224; IN: SI - Address of start of string
194- print_string_16 : ; Output string in SI to screen
225+ print : ; Output string in SI to screen
195226 pusha
196227 mov ah , 0x0E ; int 0x10 teletype function
197228.repe at :
0 commit comments