Skip to content

Commit 2b3ccf4

Browse files
memmap resumen tipos y cant agregado
1 parent 847675e commit 2b3ccf4

File tree

5 files changed

+117
-23
lines changed

5 files changed

+117
-23
lines changed

asm/tsl.asm

Lines changed: 115 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,14 @@ patch_ap_code:
473473
parse_uefi_memmap:
474474
;; Find all usable memory. Types 1-7 are ok to use once Boot Services has exited.
475475
;; Anything else not usable.
476-
xor r8, r8 ;; Usable memory accum to inform. Will count num pages.
477-
xor r10, r10 ;; Number of descriptors in usable memmap.
478-
xor r9, r9
476+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;xor r9, r9
477+
.info_mem:
478+
sub rsp, 8 * EfiMaxMemoryType ;; Space for an information array.
479+
mov rdi, rsp
480+
mov rax, 0
481+
mov rcx, EfiMaxMemoryType
482+
rep stosq ;; Clear automatic array in stack.
483+
479484
xor rbx, rbx ;; A flag to keep track of contiguous blocks. Zero means
480485
;; the block being currently parsed is contiguous with t
481486
;; he one before. If so, we could merge.
@@ -487,7 +492,46 @@ parse_uefi_memmap:
487492
cmp rax, 0 ;; The 0 pages mark leaved in uefi.asm at the tail.
488493
je .finish ;; If so, we have finished.
489494

490-
;; What if the descriptor is system one and includes 0x100000 address?
495+
;; For every descriptor: get info to inform.
496+
497+
.info_array_add:
498+
mov rax, [rsi] ;; EFI type.
499+
mov rcx, [rsi + 24] ;; Cant pages.
500+
add [rsp + 8 * rax], rcx ;; Add pages to corresponding element.
501+
502+
503+
;; jmp .finish
504+
505+
;; mov rax, [rsi] ;; EFI type.
506+
;; push rax
507+
;; mov rax, [rsi + 24] ;; Cant pages.
508+
;; push rax
509+
;; mov rax, [rsi + 8] ;; phy add
510+
;; push rax
511+
;; mov rax, [rsi + 16] ;; virt add.
512+
;; push rax
513+
;;
514+
;; mov r9, msg_test_num
515+
;; pop rsi
516+
;; call print
517+
;;
518+
;; mov r9, msg_test_num
519+
;; pop rsi
520+
;; call print
521+
;;
522+
;; mov r9, msg_test_hex;; ph
523+
;; pop rsi
524+
;; call print
525+
;;
526+
;; mov r9, msg_test_hex;; vir
527+
;; pop rsi
528+
;; call print
529+
;;
530+
;; cli
531+
;; hlt
532+
533+
534+
.continue_parse:
491535
mov rax, [rsi + 8]
492536
cmp rax, 0x100000 ;; Test if the Physical Address less than 0x100000.
493537
jb .next_entry ;; If so, directly skip.
@@ -502,13 +546,6 @@ parse_uefi_memmap:
502546
jmp .next_entry
503547

504548
.usable:
505-
506-
;;mov r9, msg_test_hex
507-
;;mov rsi, rax
508-
;;call print
509-
;;cli
510-
;;hlt
511-
512549
cmp rbx, 1
513550
je .parse_as_usable_contiguous_to_prev
514551
mov rax, [rsi + 8]
@@ -548,10 +585,40 @@ parse_uefi_memmap:
548585
stosq
549586
stosq
550587

551-
;; Clear entries < 3MiB.
588+
mov r9, msg_ready
589+
call print
590+
591+
mov r9, msg_mm_info
592+
call print
593+
594+
595+
;; Habiando terminado de parser todo el mapa de memoria, imprimir la info.
596+
.info_out:
597+
mov r9, fmt_mm_info_array
598+
mov rcx, 0
599+
600+
.out_loop:
601+
mov rsi, [rsp + 8 * rcx]
602+
push r9
603+
push rcx
604+
call print
605+
pop rcx
606+
pop r9
607+
lea r9, [r9 + fmt_mm_info_siz] ;; Siguiente elemento (fmt string).
608+
inc rcx
609+
cmp rcx, EfiMaxMemoryType
610+
jb .out_loop
611+
612+
add rsp, 8 * EfiMaxMemoryType ;; Devuvelvo space for an information array.
613+
614+
cli
615+
hlt
616+
617+
;; Clear entries < 3MiB.
618+
clear_small:
552619
mov rsi, 0x00200000 ;; Memory map at 0x200000
553620
mov rdi, 0x00200000
554-
clear_small:
621+
.loop:
555622
lodsq
556623
cmp rax, 0
557624
je .finish
@@ -560,10 +627,10 @@ clear_small:
560627
cmp rax, 0x300
561628
jb .remove
562629
stosq
563-
jmp clear_small
630+
jmp .loop
564631
.remove:
565632
sub rdi, 8
566-
jmp clear_small
633+
jmp .loop
567634
.finish:
568635
xor rax, rax ;; Blank record.
569636
stosq
@@ -822,10 +889,10 @@ lfb_wc_end:
822889

823890

824891
;; Kernel to its final location.
825-
mov esi, TSL_BASE_ADDRESS + BOOTLOADER_SIZE ;; Offset to end of tsl.sys
892+
mov esi, TSL_BASE_ADDRESS + TSL_SIZE ;; Offset to end of tsl.sys
826893
mov rdi, 0x100000 ;; Kernel final destination.
827-
;;mov rcx, ((32768 - BOOTLOADER_SIZE) / 8)
828-
mov rcx, (((232 * 1024) - BOOTLOADER_SIZE) / 8) ;; 232KiB Kernel + Userland
894+
;;mov rcx, ((32768 - TSL_SIZE) / 8)
895+
mov rcx, (((232 * 1024) - TSL_SIZE) / 8) ;; 232KiB Kernel + Userland
829896
rep movsq
830897

831898
%ifdef BIOS
@@ -1474,22 +1541,49 @@ msg_idt_load: db "load... ", 0
14741541
msg_exception_occurred: db "An exception has occurred in the system.", 0x0A, 0
14751542
msg_pages_will_be_2mib: db "Page size = 2MiB", 0x0A, 0
14761543
msg_setting_memmap: db "Setting up memmap...", 0
1477-
msg_cr3_at_this_point: db "CR3 at this point = 0x%h", 0x0A, 0
1544+
msg_cr3_at_this_point: db "CR3 at this point = 0x%h", 0x0A, 0
14781545
msg_cr3_load: db "Load CR3 a new value", 0x0A, 0
14791546
msg_patch: db "Patching code for AP... ", 0x0A, 0
14801547

1548+
msg_mm_info: db "Memory map consists of the following regions (number of 4KiB pages):"
1549+
db 0x0A, 0
1550+
1551+
;; El orden importa. Es un arreglo.
1552+
fmt_mm_info_array:
1553+
fmt_mm_info_efi_res: db "EFI Reserved Memory = %d", 0x0A, 0
1554+
fmt_mm_info_efi_lc: db "EFI Loader Code = %d", 0x0A, 0
1555+
fmt_mm_info_efi_ld: db "EFI Loader Data = %d", 0x0A, 0
1556+
fmt_mm_info_efi_bsc: db "EFI Boot Services Code = %d", 0x0A, 0
1557+
fmt_mm_info_efi_bsd: db "EFI Boot Services Data = %d", 0x0A, 0
1558+
fmt_mm_info_efi_rtsc: db "EFI Runtime Services Code = %d", 0x0A, 0
1559+
fmt_mm_info_efi_rtsd: db "EFI Runtime Services Data = %d", 0x0A, 0
1560+
fmt_mm_info_efi_conv: db "EFI Conventional Memory = %d", 0x0A, 0
1561+
fmt_mm_info_efi_unuse: db "EFI Unusable Memory = %d", 0x0A, 0
1562+
fmt_mm_info_efi_acpi_rec: db "EFI ACPI Reclaim Memory = %d", 0x0A, 0
1563+
fmt_mm_info_efi_acpi_nvs: db "EFI ACPI Memory NVS = %d", 0x0A, 0
1564+
fmt_mm_info_efi_mmio: db "EFI Memory Mapped IO = %d", 0x0A, 0
1565+
fmt_mm_info_efi_mmio_ports: db "EFI MM IO Port Space = %d", 0x0A, 0
1566+
fmt_mm_info_efi_pal_code: db "EFI Pal Code = %d", 0x0A, 0
1567+
fmt_mm_info_siz equ $ - fmt_mm_info_efi_pal_code
1568+
1569+
14811570
msg_test_hex: db "Value = 0x%h", 0x0A, 0
1571+
msg_test_num: db "Value = 0x%d", 0x0A, 0
1572+
1573+
1574+
1575+
14821576

14831577

1484-
BOOTLOADER_SIZE equ 0x2000 ;; 8KiB
1578+
TSL_SIZE equ 0x3000 ;; 8KiB
14851579

14861580

14871581

14881582
EOF:
14891583
db 0xDE, 0xAD, 0xC0, 0xDE
14901584

14911585
;; Pad to an even KB file
1492-
times BOOTLOADER_SIZE-($-$$) db 0x90
1586+
times TSL_SIZE - ($ - $$) db 0x90
14931587

14941588

14951589
; =============================================================================

asm/uefi.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
;; luego de agregado el payload queda:
1515
;; +--------------------------+-------------------------+------------+
1616
;; | binario BOOTX64.EFI | payload | padeo de |
17-
;; | | | | bootloader | packed | 0x00 hasta |
18-
;; | Encabez | Codigo | Datos | | Kernel.bin | el fin |
17+
;; | | | | transient | packed | 0x00 hasta |
18+
;; | Encabez | Codigo | Datos | system | Kernel.bin | el fin |
1919
;; +---------+--------+-------+------------+------------+------------+
2020
;; |^ |^ |^ |^ |^ |^ ^|
2121
;; 0x0 0x200 0x1000 0x4000 0x5800 0x40000 0xFFFFF

build/tsl.sys

4 KB
Binary file not shown.

out/BOOTX64.EFI

0 Bytes
Binary file not shown.

out/payload.sys

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)