Skip to content

Commit 3f89df3

Browse files
mbr creo que listo
1 parent ef6baf1 commit 3f89df3

13 files changed

Lines changed: 245 additions & 201 deletions

File tree

.gdb_history

Lines changed: 151 additions & 151 deletions
Large diffs are not rendered by default.

asm/bios/mbr.asm

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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+
;; -- https://wiki.osdev.org/A20_Line
1011
;;
1112
;; This mbr is for 32 and 64 bit machines. Will not work fine on 16 bit 8086 or
1213
;; 80286 because it uses prefix override for some instructions.
@@ -16,6 +17,9 @@
1617
%include "./asm/include/mbr.inc"
1718

1819

20+
global print ;; Export symbol so to use this print function in start16.asm.
21+
22+
1923
BITS 16
2024

2125
entryPoint:
@@ -35,9 +39,11 @@ entryPoint:
3539
mov si, msg_load
3640
call print
3741

38-
mov ax, 512 ;; Cant sectors. Load 512 = 262144 bytes = 256 KiB.
42+
load:
43+
mov ax, (512 + 1) ;; Cant sectors. Load 512 = 262144 bytes = 256 KiB + 1 (start16.asm).
3944
mov bx, 6117 ;; Offset = 8192.
40-
mov cx, 0x8000 ;; Copy here.
45+
;;mov cx, 0x8000 ;; Copy here.
46+
mov cx, 0x7E00 ;; Destination.
4147
call diskcpy ;; Copia payload completo.
4248

4349
mov si, msg_ok
@@ -48,14 +54,36 @@ entryPoint:
4854
;;cmp eax, "BOOT" ;; Simple payload verification (tsl_start.sys binary).
4955
;;jne magic_fail
5056

57+
58+
;; TO-DO: averiguar por que activar a20 debe estar luego de load.
59+
a20:
60+
call a20_check
61+
jnz start16_prepare
62+
63+
.a20_set:
64+
in al, 0x64 ;; Status.
65+
test al, 0x02
66+
jnz .a20_set
67+
mov al, 0xd1 ;; 8042 Write command.
68+
out 0x64, al
69+
70+
.check:
71+
in al, 0x64
72+
test al, 0x02
73+
jnz .check
74+
mov al, 0xdf
75+
out 0x60, al
76+
77+
start16_prepare:
5178
mov eax, 0
5279
mov ebx, 0
5380
mov ecx, 0
5481
mov edx, 0
5582
mov fs, ax
5683
mov es, ax
5784

58-
jmp 0x0000:0x8000
85+
start16_jump:
86+
jmp 0x0000:0x7E00
5987

6088

6189
;;==============================================================================
@@ -210,6 +238,46 @@ print:
210238
ret
211239

212240

241+
242+
243+
244+
245+
246+
247+
;;==============================================================================
248+
;; a20_check | Check the status of a20 line
249+
;;==============================================================================
250+
;; Returns:
251+
;; -- FLAGS[zero] = 1 (a20 disabled) | FLAGS[zero] = 0 (a20 enabled)
252+
;;==============================================================================
253+
254+
a20_check:
255+
256+
xor ax, ax
257+
mov es, ax
258+
not ax ;; 0xFFFF
259+
mov ds, ax
260+
261+
mov di, 0x0500
262+
mov si, 0x0510
263+
264+
mov al, [es:di]
265+
push ax
266+
mov al, [ds:si]
267+
push ax
268+
269+
mov byte [es:di], 0x00
270+
mov byte [ds:si], 0xFF ;; Will overwrite the prev move if a20 not set.
271+
cmp byte [es:di], 0xFF
272+
273+
pop ax
274+
mov [ds:si], al
275+
pop ax
276+
mov [es:di], al
277+
278+
ret
279+
280+
213281
;;==============================================================================
214282
;; section .data
215283
;;==============================================================================
@@ -224,12 +292,12 @@ msg_halt: db "System halted", 0
224292
drvNum: db 0x00
225293

226294
;; Zero fill.
227-
times 446 - $ + $$ db 0
295+
;;times 446 - $ + $$ db 0
228296

229297
;; False partition table entry required by some BIOS vendors.
230298
db 0x80, 0x00, 0x01, 0x00, 0xEB, 0xFF, 0xFF, 0xFF
231299
db 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
232300

233-
times 510 - $ + $$ db 0
301+
;;times 510 - $ + $$ db 0
234302

235303
sign: dw 0xAA55

asm/bios/start16.asm

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
%include "./asm/include/sysvar.inc"
77

8+
9+
;;extern print
10+
811
;; tsl_ap.asm
912
extern GDTR32
1013
extern tmpGDTR64 ;; Only for bios boot. See tsl.asm 1178 TO-DO.
@@ -83,19 +86,7 @@ memmapend:
8386
mov ecx, 8
8487
rep stosd
8588

86-
; Enable the A20 gate
87-
set_A20:
88-
in al, 0x64
89-
test al, 0x02
90-
jnz set_A20
91-
mov al, 0xD1
92-
out 0x64, al
93-
check_A20:
94-
in al, 0x64
95-
test al, 0x02
96-
jnz check_A20
97-
mov al, 0xDF
98-
out 0x60, al
89+
9990

10091
mov cx, 0x4000 - 1 ; Start looking from here
10192
VBESearch:
@@ -160,31 +151,6 @@ halt:
160151
;;msg_halt: db "System halted", 0
161152

162153

163-
;;==============================================================================
164-
;; print | Imprime a pantalla usando bootservice.
165-
;;==============================================================================
166-
;; Argumentos:
167-
;; -- si: string addr 16 bits.
168-
;;==============================================================================
169-
170-
171-
;; TO-DO: pasar a libreria, esta repetido del mbr
172-
print:
173-
pusha
174-
mov ah, 0x0e ;; int 0x10: write text in teletype mode.
175-
176-
.next:
177-
lodsb
178-
cmp al, 0
179-
je .fin
180-
int 0x10 ;; Write boot service.
181-
jmp .next
182-
183-
.fin:
184-
popa
185-
ret
186-
187-
188154

189155

190156
BITS 32
@@ -348,4 +314,11 @@ pde_low_32: ; Create a 2 MiB page
348314
or eax, 0x80000000 ; PG (Bit 31)
349315
mov cr0, eax
350316

351-
jmp SYS64_CODE_SEL:start64 ; Jump to 64-bit mode
317+
jmp SYS64_CODE_SEL:start64 ; Jump to 64-bit mode
318+
319+
320+
321+
322+
;;;;;;;;;;;;;;;;;;;; delete this
323+
print:
324+
nop

asm/tsl_start.asm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
;; Ubicacion en memoria los distintos fuentes que componen esta parte de inicial
1010
;; izacion del sistema.
1111
;; +---------------+------------+-------+---..---+----------+------+
12-
;; | tsl_start.asm | tsl_ap.asm | .data | 00..00 | tsl.asm |.data |
13-
;; | .text_low | .text_low | _low | 00..00 | .text | |
12+
;; | start | tsl_sta | tsl_ap.asm | .data | 00..00 | tsl.asm |.data |
13+
;; | 16.asm | rt.asm
14+
;; | .text_low | .text_low | _low | 00..00 | .text | |
1415
;; +---------------+------------+-------+---..---+----------+------+
1516
;; |^ | | | | | |
1617
;; |<-------------- 4KiB -------------->| |<---- KiB ---->|

build/tsl.sys

0 Bytes
Binary file not shown.

elf/tsl_lo.elf

-152 Bytes
Binary file not shown.

ldScript/tsl.ld

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
OUTPUT_FORMAT("binary")
2-
SECTIONS
3-
{
2+
3+
SECTIONS {
4+
5+
6+
7+
48
code_lo_start_reloc = 0x8000;
59
code_lo_start_load = 0x0000;
610
.text_low code_lo_start_reloc : AT (code_lo_start_load) {
@@ -48,8 +52,6 @@ SECTIONS
4852
*(EXCLUDE_FILE (*.o) COMMON)
4953
}
5054

51-
52-
5355
/* file_size = . - code_low_start;*/
5456
}
5557

obj/mbr.o

112 Bytes
Binary file not shown.

obj/start16.o

-192 Bytes
Binary file not shown.

obj/tsl_start.o

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)