Skip to content

Commit e6d996b

Browse files
segment oferrive aclaracion
1 parent 8a036fa commit e6d996b

5 files changed

Lines changed: 34 additions & 67 deletions

File tree

.gdb_history

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
continue
2-
quit
3-
b *0x8000
4-
continue
5-
si
6-
sisi
7-
si
8-
exit
9-
quit
101
b *0x8000
112
continue
123
dashboard
@@ -254,3 +245,12 @@ quit
254245
b *0x8000
255246
continue
256247
quit
248+
b *0x8000
249+
continue
250+
quit
251+
b *0x8000
252+
continue
253+
quit
254+
b *0x8000
255+
continue
256+
quit

asm/bios/mbr.asm

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
;; -- https://github.com/fysnet/FYSOS/blob/master/boot/embr/embr.asm
88
;; http://www.ctyme.com/intr/rb-0708.htm
99
;; -- https://stanislavs.org/helppc/int_10.html
10-
11-
;; En 16 bits cuando el procesador no es de 16 si no de 32 o 64 pero ejecuta en
12-
;; un modo de 16 bits, prestar atencion a algunas instrucciones: jumps por ejemp
13-
;; lo. El mismo opcode lo interpreta en 32 de una manera y en 16 de otra, saltan
14-
;; do en cada uno de esos casos a direcciones cercanas pero distintas porque en
15-
;; 32 toma operando de 32 y en 16 de 16 (8?) lo cual genera un offset en la dire
16-
;; ccion de destino. Pero un push de 32 es reconocido en 16 bits y ejecutado cor
17-
;; rectamente a pesar de estar en modo de 16.
10+
;;
11+
;; This mbr is for 32 and 64 bit machines. Will not work fine on 16 bit 8086 or
12+
;; 80286 because it uses prefix override for some instructions.
1813
;;==============================================================================
1914

2015

@@ -35,7 +30,6 @@ entry:
3530

3631
mov [drvNum], dl ;; Bios passes drive number in dl.
3732

38-
call pushTest
3933
call extensionTest
4034

4135
mov si, msg_load
@@ -89,41 +83,38 @@ notify_ext_not_supported:
8983
;;==============================================================================
9084

9185
diskcpy:
92-
call readSec ;; Each loop 512 bytes.
86+
call cpySec ;; Each loop 512 byte copy.
9387
dec ax
9488
cmp ax, 0
9589
jnz diskcpy
9690
ret
9791

9892

9993
;;==============================================================================
100-
;; readSec | Read a sector from a disk using extended read.
94+
;; cpySec | Read a sector from a disk using extended read (2TB max disk size)
10195
;;==============================================================================
10296
;; Arguments:
103-
;; -- eax: high word of 64 bit sector.
104-
;; -- ebx: low word of 64 bit sector.
97+
;; -- ebx: low word of 64 bit src sector (only 32 bits implementation).
10598
;; -- {es:cx}: destination address, {seg:offset}
10699
;; Returns:
107-
;; -- eax: high word of next sector.
108-
;; -- ebx: low word of sector.
109-
;; -- {es:cx}: p2source + cantBytes2copy
100+
;; -- ebx: low word of src sector.
101+
;; -- {es:cx}: p2dest + cantBytes2copy
102+
;;
103+
;; No altera registros, excepto los que indica retorna.
104+
;; Size of source sector received in ebx, so limited to 2^32 sectors (= 2TB).
110105
;;==============================================================================
111106

112-
readSec:
113-
push eax
107+
cpySec:
114108
push dx
115109
push si
116110
push di
117111

118-
xor eax, eax ;; We don't need to load from sectors > 32-bit
119-
120-
.read:
121-
push eax ;; Backup sectorNumber.hi
122-
push ebx ;; Backup sectorNumber.lo
112+
.cpy:
113+
push ebx ;; Backup sectorNumber.
123114
mov di, sp ;; Base of disk address packet.
124115

125116
;; Build disk address packet.
126-
push eax ;; dap10..15 dap.srcLba.hi
117+
push dword 0 ;; dap10..15 dap.srcLba.hi. No necesario, trunco a 2TB.
127118
push ebx ;; dap06..09 dap.srcLba.lo
128119
push es ;; dap04..05 dap.dst.seg
129120
push cx ;; dap02..03 dap.dst.offset
@@ -132,24 +123,22 @@ readSec:
132123

133124
mov si, sp
134125
mov dl, [drvNum]
135-
mov ah, 42h ; EXTENDED READ
136-
int 0x13 ; http://hdebruijn.soo.dto.tudelft.nl/newpage/interupt/out-0700.htm#0651
126+
mov ah, 42h ;; Extended read.
127+
int 0x13
137128

138-
mov sp, di ; remove parameter block from stack
129+
mov sp, di ;; Clean stack.
139130
pop ebx
140-
pop eax ; Restore the sector number
141131

142-
jnc read_ok ; jump if no error
132+
jnc read_ok ; jump if no error
143133

144134
push ax
145-
xor ah, ah ; else, reset and retry
135+
xor ah, ah ; else, reset and retry
146136
int 0x13
147137
pop ax
148-
jmp .read
138+
jmp .cpy
149139

150140
read_ok:
151141
add ebx, 1 ; increment next sector with carry
152-
adc eax, 0
153142
add cx, 512 ; Add bytes per sector
154143
jnc no_incr_es ; if overflow...
155144

@@ -162,27 +151,6 @@ no_incr_es:
162151
pop di
163152
pop si
164153
pop dx
165-
pop eax
166-
167-
ret
168-
169-
170-
;;==============================================================================
171-
;; pushTest | Verifica compatibilidad de opcode push eax en modo 16 bits
172-
;;==============================================================================
173-
;; Registers CS, DS, ES, SS, BX, CX, DX are preserved unless
174-
;; explicitly changed
175-
;;==============================================================================
176-
177-
pushTest:
178-
mov bx, sp
179-
push eax
180-
sub bx, sp
181-
pop eax
182-
add [msg_sizeofPush + POSITION_COUNT], bl
183-
184-
mov si, msg_sizeofPush
185-
call print
186154

187155
ret
188156

@@ -199,11 +167,11 @@ extensionTest:
199167
call print
200168

201169
mov ah, 0x41 ;; Check extensions present.
202-
mov bx, 55AAh ;; Required signature.
170+
mov bx, 55aah ;; Required signature.
203171
mov dl, [drvNum]
204172
int 0x13
205173
jc notify_ext_not_supported
206-
cmp bx, 0xAA55
174+
cmp bx, 0xaa55
207175
jne notify_ext_not_supported
208176

209177
mov si, msg_ok
@@ -239,9 +207,6 @@ print:
239207
;; section .data
240208
;;==============================================================================
241209

242-
msg_sizeofPush: db "16b mode 32b push opcode pushes "
243-
POSITION_COUNT equ $ - msg_sizeofPush
244-
db "0 bytes", 13, 10, 0
245210
msg_extSupport: db "Verifying bios ext support..", 0
246211
msg_no: db " no", 13, 10, 0
247212
msg_load: db "Reading disk..", 0

obj/mbr.o

-192 Bytes
Binary file not shown.

out/mbr.sys

0 Bytes
Binary file not shown.

run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ done
2626
qemu-system-x86_64 $bios_flag -hda img/x64_arq.qcow2 -m 512 \
2727
-name "arq64 uefi" $debug_flags -smp "$cant_cores"
2828

29+
30+
2931
### Dejar esto para probar el booteo con bios, luego, agregar flag para seleccionar uno u otro.
3032
##qemu-system-x86_64 -hda img/gpt_with_pmbr.qcow2 -m 512 \
3133
## -name "arq64 uefi" $debug_flags -smp "$cant_cores"

0 commit comments

Comments
 (0)