Skip to content

Commit 31c52d9

Browse files
imprime en start16
1 parent a03240c commit 31c52d9

18 files changed

Lines changed: 267 additions & 230 deletions

File tree

.gdb_history

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

asm/bios/mbr.asm

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
%include "./asm/include/sysvar.inc"
1919

2020

21-
global print ;; Export symbol so to use this print function in start16.asm.
21+
;;global print_bios ;; Export symbol so to use this print function in start16.asm.
2222

2323

2424
BITS 16
@@ -35,28 +35,34 @@ entryPoint:
3535

3636
mov [drvNum], dl ;; Bios passes drive number in dl.
3737

38+
39+
mov si, msg_extSupport
40+
call print_bios
41+
3842
call extensionTest
3943

40-
mov si, msg_load
41-
call print
4244

4345
load:
44-
mov ax, (512 + 1) ;; Cant sectors. Load 512 = 262144 bytes = 256 KiB + 1 (start16.asm).
46+
mov si, msg_reading
47+
call print_bios
48+
49+
mov ax, (512 + 1) ;; Cant sectors. Load 512 = 262144 bytes = 256 KiB + 1 (
50+
;; start16.asm). TO-DO: en realidad solo 240 que es el t
51+
;; amano completo de la payload. Ya incluye a start16. R
52+
;; evisar tamanos.
4553
mov bx, 6117 ;; Offset = 8192.
46-
;;mov cx, 0x8000 ;; Copy here.
4754
mov cx, 0x7E00 ;; Destination.
4855
call diskcpy ;; Copia payload completo.
4956

5057
mov si, msg_ok
51-
call print
58+
call print_bios
5259

5360
;; TO-DO reponer
5461
;;mov eax, [0x8000 + SIGNATURE_OFFSET]
5562
;;cmp eax, "BOOT" ;; Simple payload verification (tsl_start.sys binary).
5663
;;jne magic_fail
5764

5865

59-
;; TO-DO: averiguar por que activar a20 debe estar luego de load.
6066
a20:
6167
call a20_check
6268
jnz start16_prepare
@@ -75,6 +81,7 @@ a20:
7581
mov al, 0xdf
7682
out 0x60, al
7783

84+
7885
start16_prepare:
7986
mov eax, 0
8087
mov ebx, 0
@@ -95,11 +102,11 @@ start16_jump:
95102
;;==============================================================================
96103

97104
failure:
98-
call print
105+
call print_bios
99106

100107
.halt:
101108
mov si, msg_halt
102-
call print
109+
call print_bios
103110
hlt
104111
jmp $
105112

@@ -193,9 +200,6 @@ cpySec:
193200
;;==============================================================================
194201

195202
extensionTest:
196-
mov si, msg_extSupport
197-
call print
198-
199203
mov ah, 0x41 ;; Check extensions present.
200204
mov bx, 55aah ;; Required signature.
201205
mov dl, [drvNum]
@@ -204,8 +208,11 @@ extensionTest:
204208
cmp bx, 0xaa55
205209
jne .unsupported
206210

211+
;;mov si, msg_extSupport
212+
;;call print_bios
213+
207214
mov si, msg_ok
208-
call print
215+
call print_bios
209216
jmp .fin
210217

211218
.unsupported:
@@ -217,21 +224,21 @@ extensionTest:
217224

218225

219226
;;==============================================================================
220-
;; print | Imprime a pantalla usando bootservice.
227+
;; print_bios | Imprime a pantalla usando bootservice.
221228
;;==============================================================================
222229
;; Argumentos:
223230
;; -- si: string addr 16 bits.
224231
;;==============================================================================
225232

226-
print:
233+
print_bios:
227234
pusha
228-
mov ah, 0x0e ;; int 0x10: write text in teletype mode.
235+
mov ah, 0x0e ;; int 0x10: write text in teletype mode.
229236

230237
.next:
231238
lodsb
232239
cmp al, 0
233240
je .fin
234-
int 0x10 ;; Write boot service.
241+
int 0x10 ;; Write boot service.
235242
jmp .next
236243

237244
.fin:
@@ -250,13 +257,18 @@ print:
250257
;;==============================================================================
251258
;; Returns:
252259
;; -- FLAGS[zero] = 1 (a20 disabled) | FLAGS[zero] = 0 (a20 enabled)
260+
;;
261+
;; Preserves all registers including segment registers.
253262
;;==============================================================================
254263

255264
a20_check:
265+
pusha
266+
push ds
267+
push es
256268

257269
xor ax, ax
258270
mov es, ax
259-
not ax ;; 0xFFFF
271+
not ax ;; 0xFFFF
260272
mov ds, ax
261273

262274
mov di, 0x0500
@@ -276,9 +288,11 @@ a20_check:
276288
pop ax
277289
mov [es:di], al
278290

279-
ret
280-
291+
pop es
292+
pop ds
293+
popa
281294

295+
ret
282296

283297

284298
;;==============================================================================
@@ -332,9 +346,9 @@ ret
332346
;; section .data
333347
;;==============================================================================
334348

335-
msg_extSupport: db "Verifying bios ext support..", 0
349+
msg_extSupport: db "Bios ext support..", 0
336350
msg_no: db " no", 13, 10, 0
337-
msg_load: db "Reading disk..", 0
351+
msg_reading: db "Reading disk..", 0
338352
msg_err: db " [error]", 13, 10, 0
339353
msg_ok: db " [ok]", 13, 10, 0
340354
msg_halt: db "System halted", 0

asm/bios/start16.asm

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;;==============================================================================
2-
;; pick real mode swich to protected mode | @file /asm/bios/start16.asm
2+
;; Real mode swich to protected mode | @file /asm/bios/start16.asm
33
;;==============================================================================
44

55

@@ -8,10 +8,11 @@
88

99
;; TO-DO: poner esto como un simbolo definido en donde mbr.ld hara el load de la
1010
;; funcion.
11-
;;extern print
12-
print equ 0xde + 0x7c00
13-
failure equ 0x67 + 0x7c00
14-
vesa equ 0x117 + 0x7c00
11+
;;extern print_bios
12+
;;extern failure
13+
print_bios equ 0x00de + 0x7c00 ;; print_bios en 0x7cde
14+
;;failure equ 0x0067 + 0x7c00
15+
;;vesa equ 0x0111 + 0x7c00
1516

1617

1718
;; tsl_ap.asm
@@ -24,16 +25,11 @@ extern start64
2425

2526
;; Primera parte: pasa real mode a protected mode.
2627

27-
28-
29-
30-
3128
BITS 16
32-
3329
start16:
34-
30+
mov ax, print_bios
3531
mov si, msg_e820
36-
call print
32+
call ax
3733

3834
; Get the BIOS E820 Memory Map
3935
; https://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15,_EAX_=_0xE820
@@ -125,11 +121,11 @@ jmp 8:start32
125121
;; no se usa, puesto que reutiliza el del mbr.
126122

127123
;;failure:
128-
;; call print
124+
;; call print_bios
129125
;;halt:
130126
;;.halt:
131127
;; mov si, msg_halt
132-
;; call print
128+
;; call print_bios
133129
;; hlt
134130
;; jmp $
135131

@@ -306,12 +302,14 @@ pde_low_32: ; Create a 2 MiB page
306302

307303

308304
;;;;;;;;;;;;;;;;;;;; delete this
309-
;;print:
305+
;;print_bios:
310306
;;nop
311307

312308

313309
;;==============================================================================
314310
;; section .data
315311
;;==============================================================================
316312

317-
msg_e820: db "Performing e820..", 0
313+
;; TO-DO: agregar section data.
314+
315+
msg_e820: db "Performing e820..", 0

asm/include/sysvar.inc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ SystemVariables: equ 0x0000000000005800
2121
IM_ActivedCoreIDs: equ 0x0000000000005E00 ;; 1by per entry. 1 = 1 core active.
2222

2323

24-
;; Cuando bootea uefi, la info de video durante uefi la mete aqui:
25-
;; [0x00005F00] ;; Frame buffer base
26-
;; [0x00005F08] ;; Frame buffer size (bytes)
27-
;; [0x00005F10] ;; Screen X
28-
;; [0x00005F12] ;; Screen Y
29-
;; [0x00005F14] ;; PixelsPerScanLine
30-
;; [0x00005F16] ;; bpp
31-
;; Luego, durante el bootloader, la mantiene aqui, pero tambien copia al infoMap
32-
;; 0x5080
33-
34-
VBEModeInfoBlock:
35-
3624

3725

3826
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -52,10 +40,26 @@ VBEModeInfoBlock:
5240
; Set the desired screen resolution values below
5341
;;;;;; esto en br1100 no cambia nada
5442
;;;;;; en qemu hace que se vea ok, o que no pueda inicializar pantalla (1366 por ej)
55-
Horizontal_Resolution equ 1024
56-
Vertical_Resolution equ 768
43+
Horizontal_Resolution: equ 1024
44+
Vertical_Resolution: equ 768
45+
46+
47+
48+
;; Cuando bootea uefi, la info de video durante uefi la mete aqui:
49+
;; [0x00005F00] ;; Frame buffer base
50+
;; [0x00005F08] ;; Frame buffer size (bytes)
51+
;; [0x00005F10] ;; Screen X
52+
;; [0x00005F12] ;; Screen Y
53+
;; [0x00005F14] ;; PixelsPerScanLine
54+
;; [0x00005F16] ;; bpp
55+
;; Luego, durante el bootloader, la mantiene aqui, pero tambien copia al infoMap
56+
;; 0x5080
57+
58+
;;VBEModeInfoBlock:
59+
60+
61+
VBEModeInfoBlock: equ 0x5F00
5762

58-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;VBEModeInfoBlock: equ 0x5F00
5963
; VESA
6064
; Mandatory information for all VBE revisions
6165
VBEModeInfoBlock.ModeAttributes equ VBEModeInfoBlock + 0 ; DW - mode attributes

build/tsl.sys

0 Bytes
Binary file not shown.

elf/tsl_hi.elf

0 Bytes
Binary file not shown.

elf/tsl_lo.elf

-48 Bytes
Binary file not shown.

ldScript/mbr copy.ld

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
OUTPUT_FORMAT("binary")
2+
3+
SECTIONS {
4+
. = 0x7C00;
5+
codeStart = .;
6+
7+
8+
9+
10+
.text : {
11+
text = .;
12+
*(.text)
13+
}
14+
15+
codeSize = . - codeStart;
16+
17+
. = ALIGN(0x1000);
18+
dataStart = .;
19+
dataOffset = dataStart - codeStart;
20+
21+
.data : {
22+
data = .;
23+
*(.data)
24+
25+
. = ALIGN(0x4000);
26+
payload = .;
27+
*(.payload)
28+
}
29+
30+
dataSize = . - dataStart;
31+
. = ALIGN(0x1000);
32+
33+
.bss : {
34+
bss = .;
35+
*(.bss)
36+
*(EXCLUDE_FILE (*.o) COMMON)
37+
}
38+
39+
fileSize = . - codeStart;
40+
}

ldScript/mbr.ld

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
11
OUTPUT_FORMAT("binary")
2-
SECTIONS
3-
{
4-
. = 0x7C00;
5-
codeStart = .;
62

7-
.text : {
8-
text = .;
9-
*(.text)
10-
}
11-
12-
codeSize = . - codeStart;
13-
14-
. = ALIGN(0x1000);
15-
dataStart = .;
16-
dataOffset = dataStart - codeStart;
3+
SECTIONS {
174

18-
.data : {
19-
data = .;
20-
*(.data)
21-
22-
. = ALIGN(0x4000);
23-
payload = .;
24-
*(.payload)
5+
code_reloc = 0x7c00 ;
6+
code_load = 0x0000;
7+
.text code_reloc : AT (code_load) {
8+
./obj/mbr.o (.text)
259
}
2610

27-
dataSize = . - dataStart;
28-
. = ALIGN(0x1000);
29-
30-
.bss : {
31-
bss = .;
32-
*(.bss)
33-
*(EXCLUDE_FILE (*.o) COMMON)
11+
. = ALIGN(0x10);
12+
code_end_reloc_aligned = . ;
13+
code_size_aligned = code_end_reloc_aligned - code_reloc;
14+
data_start_reloc_aligned = . ;
15+
data_start_load = code_load + code_size_aligned;
16+
.data data_start_reloc_aligned : AT (data_start_load) {
17+
./obj/mbr.o (.data)
3418
}
3519

36-
fileSize = . - codeStart;
3720
}

ldScript/tsl.ld

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ OUTPUT_FORMAT("binary")
22

33
SECTIONS {
44

5-
6-
75
code_start16_reloc = 0x7e00;
86
code_start16_load = 0x0000;
97
.text_start16 code_start16_reloc : AT (code_start16_load) {

0 commit comments

Comments
 (0)