Skip to content

Commit 5ac0a97

Browse files
page size informado con vector segun cpuid
1 parent 2c5bee0 commit 5ac0a97

File tree

4 files changed

+113
-88
lines changed

4 files changed

+113
-88
lines changed

asm/tsl.asm

Lines changed: 113 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -162,66 +162,6 @@ set_pit_initial_freq:
162162
;;mov r9, fmt_pae
163163
;;call print
164164

165-
;; Aqui se comienzan a armar tablas de sistema. Breve resumen de lo que finalmen
166-
;; te va a quedar:
167-
;; | | | if |if |mapped| | table(s) total
168-
;; |4KiB | | 1Mib |1GiB |per | | initilized
169-
;; |blocks| | pages |pages|entry | | mem mapping
170-
;; -----------+------+-----------+-----------+-----+------+--------+---------------
171-
;; 0x00000000 | 1 | idt | | | |
172-
;; 0x00000FFF | | | | | |
173-
;; -----------+------+-----------+-----------+-----+------+------------------------
174-
;; 0x00001000 | 1 | gdt | | | |
175-
;; 0x00001FFF | | | | | |
176-
;; -----------+------+-----------+-----------+-----+------+------------------------
177-
;; 0x00002000 | 1 | pml4 | | | |
178-
;; 0x00002FFF | | | | | | | |
179-
;; -----------+------+-----------+-----------+-----+------+------------------------
180-
;; 0x00003000 | 1 | pdpt cano | 16 |512 | 1GiB |
181-
;; 0x00003FFF | | nical low | entr. |entr.| |
182-
;; -----------+------+-----------+-----------+-----+------+------------------------
183-
;; 0x00004000 | 1 | pdpt cano | | | |
184-
;; 0x00004FFF | | nical hig | | | |
185-
;; -----------+------+-----------+-----------+-----+------+-----------------------
186-
;; 0x00005000 | 3 | system | | | | |
187-
;; 0x00007FFF | | data | | | |
188-
;; -----------+------+-----------+-----------+-----+------+------------------------
189-
;; 0x00008000 | 8 | dispo | | | |
190-
;; 0x0000FFFF | | nible | | | |
191-
;; -----------+------+-----------+-----------+-----+------+---------------------------
192-
;; 0x00010000 | 16 | pd low |16 pag * | sin |2MiB |
193-
;; 0x0001FFFF | | |512 entr | uso | |
194-
;; -----------+------+-----------+-----------+-----+------+---------------------------
195-
;; 0x00020000 | 64 | pd high | | sin | |
196-
;; 0x0005FFFF | | | | uso | |
197-
;; -----------+------+-----------+-----------+-----+------+--------------------------
198-
;; 0x00060000 | 64 |disponible |pd fb si | | | |
199-
;; 0x0009FFFF | |condicion |*fb<16*2^30| | | |
200-
;; -----------+------+-----------+-----------+-----+------+---------------------------
201-
mov r9, msg_gdt
202-
call print
203-
204-
mov rsi, gdt64
205-
mov rdi, 0x00001000 ;; GDT 0x1000..0x1FFF (max)
206-
mov rcx, gdt64_end - gdt64
207-
rep movsb ;; Move GDT to final location in memory.
208-
209-
mov r9, msg_pml4
210-
call print
211-
212-
;; PML4. Starts at 0x0000000000002000. Each entry maps 512GiB.
213-
pml4:
214-
mov edi, 0x00002000 ;; PML4 entry for physical mem, canonical low.
215-
mov eax, 0x00003003 ;; #1 (R/W) | #0 (P) | *PDP low (4KiB aligned).
216-
stosq ;; 1 | 1 |
217-
mov edi, 0x00002800 ;; PML4 entry for canonical high start address of 0x
218-
;; FFFF800000000000
219-
mov eax, 0x00004003 ;; #1 (R/W) | #0 (P) | *PDP high (4KiB aligned).
220-
stosq ;; 1 | 1 |
221-
222-
mov r9, msg_ready
223-
call print
224-
225165

226166
;; Some cpuid information will be printed.
227167
mov r9, msg_cpuid_info
@@ -263,43 +203,124 @@ pse36:
263203
mov r9, fmt_pse36
264204
call print
265205

266-
physical_address_size:
206+
addr_sizes:
267207
mov rax, 0x80000008
268208
cpuid
269-
push rax ;; Para recuperarlo luego del print.
270-
and rax, 0xFF
209+
mov [addr_bits_physical], al
210+
mov [addr_bits_logical], ah
211+
212+
physical_address_size:
213+
xor rax, rax
214+
mov al, [addr_bits_physical]
271215
mov rsi, rax
272216
mov r9, fmt_physical_addr
273217
call print
274218

275-
276219
logical_address_size:
277-
pop rax
278-
mov al, ah
279-
and rax, 0xFF
220+
xor rax, rax
221+
mov al, [addr_bits_logical]
280222
mov rsi, rax
281223
mov r9, fmt_logical_addr
282224
call print
283225

226+
pag_1gb:
227+
mov rax, 0x80000001
228+
cpuid
229+
mov rax, rdx
230+
bt rax, 26
231+
lahf
232+
mov al, ah
233+
and rax, 0x0000000000000001
234+
mov [p_1gb_pages], al
235+
mov rsi, rax
236+
mov r9, msg_support_1g_pages
237+
call print
284238

239+
xor rax, rax
240+
mov al, [p_1gb_pages]
241+
mov rax, 1
242+
mov r9, msg_pages_will_be
243+
lea rsi, [msg_pages_size + 8 * rax]
244+
call print
285245

286246

287-
pag_1gb_support:
288-
mov r9, msg_support_1g_pages ;; Comienza aviso de soporte.
247+
;; Aqui se comienzan a armar tablas de sistema. Breve resumen de lo que finalmen
248+
;; te va a quedar:
249+
;; | | | if |if |mapped| |
250+
;; |4KiB | | 1Mib |1GiB |per | |
251+
;; |blocks| | pages |pages|entry | |
252+
;; -----------+------+-----------+-----------+-----+------+--------+------------
253+
;; 0x00000000 | 1 | idt | | | |
254+
;; 0x00000FFF | | | | | |
255+
;; -----------+------+-----------+-----------+-----+------+---------------------
256+
;; 0x00001000 | 1 | gdt | | | |
257+
;; 0x00001FFF | | | | | |
258+
;; -----------+------+-----------+-----------+-----+------+---------------------
259+
;; 0x00002000 | 1 | pml4 | | | |
260+
;; 0x00002FFF | | | | | | | |
261+
;; -----------+------+-----------+-----------+-----+------+---------------------
262+
;; 0x00003000 | 1 | pdpt cano | 16 |512 | 1GiB |
263+
;; 0x00003FFF | | nical low | entr. |entr.| |
264+
;; -----------+------+-----------+-----------+-----+------+---------------------
265+
;; 0x00004000 | 1 | pdpt cano | | | |
266+
;; 0x00004FFF | | nical hig | | | |
267+
;; -----------+------+-----------+-----------+-----+------+---------------------
268+
;; 0x00005000 | 3 | system | | | | |
269+
;; 0x00007FFF | | data | | | |
270+
;; -----------+------+-----------+-----------+-----+------+---------------------
271+
;; 0x00008000 | 8 | dispo | | | |
272+
;; 0x0000FFFF | | nible | | | |
273+
;; -----------+------+-----------+-----------+-----+------+---------------------
274+
;; 0x00010000 | 16 | pd low |16 pag * | sin |2MiB |
275+
;; 0x0001FFFF | | |512 entr | uso | |
276+
;; -----------+------+-----------+-----------+-----+------+---------------------
277+
;; 0x00020000 | 64 | pd high | | sin | |
278+
;; 0x0005FFFF | | | | uso | |
279+
;; -----------+------+-----------+-----------+-----+------+---------------------
280+
;; 0x00060000 | 64 |disponible |pd fb si | | | |
281+
;; 0x0009FFFF | |condicion |*fb<16*2^30| | | |
282+
;; -----------+------+-----------+-----------+-----+------+---------------------
283+
mov r9, msg_gdt
289284
call print
290285

291-
mov eax, 0x80000001
292-
cpuid
293-
bt edx, 26 ;; Bit signals page 1GiB support.
294-
jc support_1gb_pages
286+
mov rsi, gdt64
287+
mov rdi, 0x00001000 ;; GDT 0x1000..0x1FFF (max)
288+
mov rcx, gdt64_end - gdt64
289+
rep movsb ;; Move GDT to final location in memory.
295290

296-
mov r9, msg_support_1g_pages_no ;; Completa: no soporta pags 1GB.
291+
mov r9, msg_pml4
297292
call print
298293

299-
;; 2MiB pages.
300-
mov r9, msg_pages_will_be_2mib
294+
;; TODO: low y high definirlo leyendo el logical addr max.
295+
;; PML4. Starts at 0x0000000000002000. Each entry maps 512GiB.
296+
pml4:
297+
mov edi, 0x00002000 ;; PML4 entry for physical mem, canonical low.
298+
mov eax, 0x00003003 ;; #1 (R/W) | #0 (P) | *PDP low (4KiB aligned).
299+
stosq ;; 1 | 1 |
300+
mov edi, 0x00002800 ;; PML4 entry for canonical high start address of 0x
301+
;; FFFF800000000000
302+
mov eax, 0x00004003 ;; #1 (R/W) | #0 (P) | *PDP high (4KiB aligned).
303+
stosq ;; 1 | 1 |
304+
305+
mov r9, msg_ready
301306
call print
302307

308+
309+
pag_1gb_support:
310+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mov r9, msg_support_1g_pages ;; Comienza aviso de soporte.
311+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;call print
312+
313+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mov eax, 0x80000001
314+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cpuid
315+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;bt edx, 26 ;; Bit signals page 1GiB support.
316+
317+
cmp byte [p_1gb_pages], 1
318+
je support_1gb_pages
319+
320+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mov r9, msg_support_1g_pages_no ;; Completa: no soporta pags 1GB.
321+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;call print
322+
323+
303324
mov r9, msg_pdpt
304325
call print
305326

@@ -398,11 +419,11 @@ pd_low_2mb:
398419
;; GiB of RAM. The last entry is reserved for the virtual LFB address.
399420
support_1gb_pages:
400421

401-
mov r9, msg_support_1g_pages_yes ;; Completa: soporta pags 1GB.
402-
call print
422+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mov r9, msg_support_1g_pages_yes ;; Completa: soporta pags 1GB.
423+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;call print
403424

404425
;; TODO: revisar esta rama.
405-
mov byte [p_1gb_pages], 1
426+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov byte [p_1gb_pages], 1
406427

407428
;; Overwrite the original PML4 entry for physical memory.
408429
;;pml4_1g:
@@ -1857,17 +1878,19 @@ msg_gdt: db "Setting up GDT... ", 0
18571878
msg_pml4: db "PML4... ", 0
18581879
msg_pdpt: db "PDPT... ", 0
18591880
msg_pd: db "PD... ", 0
1860-
msg_support_1g_pages: db "Support for 1GB pages = ", 0
1861-
msg_support_1g_pages_yes: db "yes", 0x0A, 0
1862-
msg_support_1g_pages_no: db "no", 0x0A, 0
1881+
1882+
msg_support_1g_pages: db "Support for 1GB pages = %d", 0
1883+
msg_pages_will_be: db " | Page size %s", 0
1884+
msg_pages_size: db "= 1GiB", 0x0A, 0
1885+
db "= 2MiB", 0x0A, 0
1886+
18631887
msg_load_gdt: db "Load gdt... ", 0
18641888
msg_idt: db "Setting up IDT... ", 0
18651889
msg_idt_exceptions: db "exceptions... ", 0
18661890
msg_idt_irqs: db "irqs ", 0
18671891
msg_idt_load: db "load... ", 0
18681892
msg_exception_occurred: db "An exception has occurred in the system.", 0x0A, 0
1869-
msg_pages_will_be_2mib: db "Page size = 2MiB", 0x0A, 0
1870-
msg_setting_memmap: db "Setting up memmap...", 0
1893+
msg_setting_memmap: db "Setting up memmap...", 0
18711894
msg_cr3_at_this_point: db "CR3 at this point = 0x%h", 0x0A, 0
18721895
msg_cr3_load: db "Load CR3 a new value", 0x0A, 0
18731896
msg_patch: db "Patching code for AP... ", 0x0A, 0
@@ -1905,12 +1928,14 @@ fmt_physical_addr db "Physical address size [bits] = %d", 0
19051928
fmt_logical_addr db " | Logical address size [bits] = %d", 0x0A, 0
19061929

19071930

1908-
msg_test_hex: db "Value = 0x%h", 0x0A, 0
1909-
msg_test_num: db "Value = 0x%d", 0x0A, 0
1910-
1911-
1931+
msg_test: db "String de prueba", 0x0A, 0
1932+
msg_test_hex: db "Value = 0x%h", 0x0A, 0
1933+
msg_test_num: db "Value = 0x%d", 0x0A, 0
19121934

19131935

1936+
;; Some additional system vars.
1937+
addr_bits_physical db 0
1938+
addr_bits_logical db 0
19141939

19151940

19161941
TSL_SIZE equ 0x3000 ;; 8KiB

build/tsl.sys

0 Bytes
Binary file not shown.

out/BOOTX64.EFI

0 Bytes
Binary file not shown.

out/payload.sys

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)