Skip to content

Commit e4b7f50

Browse files
Ahora uefi.sys puede ser de 3KiB.
1 parent cafa00b commit e4b7f50

File tree

3 files changed

+113
-109
lines changed

3 files changed

+113
-109
lines changed

asm/init/acpi.asm

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
; =============================================================================
2-
; INIT ACPI
3-
;; Comments reference the following document:
4-
; Advanced Configuration and Power Interface (ACPI) Specification Release 6.5
5-
; https://uefi.org/sites/default/files/resources/ACPI_Spec_6_5_Aug29.pdf
6-
; =============================================================================
7-
8-
9-
1+
;;==============================================================================
2+
;; acpi.asm
3+
;;==============================================================================
4+
;; Documentos:
5+
;; -- Advanced Configuration and Power Interface (ACPI) Spec Release 6.5
6+
;; https://uefi.org/sites/default/files/resources/ACPI_Spec_6_5_Aug29.pdf
7+
;; -- https://uefi.org/sites/default/files/resources/BDAT_Spec_v4_0_9%20(2).pdf
8+
;;==============================================================================
109

10+
bits 64
1111

1212
init_acpi:
1313
mov al, [p_BootMode] ; Check how the system was booted
@@ -22,42 +22,45 @@ searchingforACPI:
2222
cmp rax, rbx ; Verify the Signature
2323
je foundACPI
2424
cmp esi, 0x000FFFFF ; Keep looking until we get here
25-
jae noACPI ; ACPI tables couldn't be found, fail
25+
jae acpiFail ; ACPI tables couldn't be found, fail
2626
jmp searchingforACPI
2727

2828
; Find the ACPI RSDP Structure on a UEFI system
2929
foundACPIfromUEFI:
3030
mov rsi, [0x400000 + 3 * 1024 + 8 * 6] ;; TODO: simbolizar. El 3 es KiB que
3131
;; ocupa seccion de codig o de uefi.
32-
mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352)
33-
lodsq ; Signature
34-
cmp rax, rbx ; Verify the Signature
35-
jne noACPI ; If it isn't a match then fail
36-
37-
; Parse the Root System Description Pointer (RSDP) Structure (5.2.5.3)
38-
foundACPI: ; Found a Pointer Structure, verify the checksum
39-
push rsi ; Save the RSDP location - currently pointing to the checksum
32+
mov rbx, "RSD PTR " ;; Root Sys Description Pointer Table (RSDT). Signature.
33+
lodsq ;; Carga signature. Luego de carga, apunta a checksum.
34+
cmp rax, rbx
35+
jne acpiFail ;; If it isn't a match then fail
36+
37+
;; Parse the Root System Description Pointer (RSDP) Structure (5.2.5.3)
38+
foundACPI: ;; Found a Pointer Structure, verify the checksum
39+
push rsi ;; rsi = RSDP[checksum]
4040
xor ebx, ebx
41-
mov ecx, 20 ; As per the spec only the first 20 bytes matter
42-
sub rsi, 8 ; Bytes 0 thru 19 must sum to zero
43-
nextchecksum:
44-
lodsb ; Get a byte
45-
add bl, al ; Add it to the running total
46-
sub cl, 1
47-
cmp cl, 0
48-
jne nextchecksum
49-
pop rsi ; Restore the RSDP location
50-
cmp bl, 0 ; Verify the checksum is zero
51-
jne noACPI ; Checksum didn't check out? Fail
52-
53-
lodsb ; Checksum
54-
lodsd ; OEMID (First 4 bytes)
55-
lodsw ; OEMID (Last 2 bytes)
56-
lodsb ; Revision (0 is v1.0, 1 is v2.0, 2 is v3.0, etc)
41+
mov ecx, 20 ;; As per the spec only the first 20 bytes matter
42+
sub rsi, 8 ;; rsi = RSDP[0]. Revisar suma cero bytes 0..19.
43+
44+
.next:
45+
lodsb ;; Checksum byte
46+
add bl, al
47+
dec cl
48+
jnz .next
49+
cmp bl, 0 ;; Checksum tiene q dar cero.
50+
jne acpiFail
51+
52+
pop rsi ;; rsi = RSDP[checksum]
53+
54+
lodsb ;; Checksum
55+
lodsd ;; OEMID (First 4 bytes)
56+
lodsw ;; OEMID (Last 2 bytes)
57+
lodsb ;; Revision (0 is v1.0, 1 is v2.0, 2 is v3.0, etc)
5758
cmp al, 0
58-
je foundACPIv1 ; If AL is 0 then the system is using ACPI v1.0
59-
jmp foundACPIv2 ; Otherwise it is v2.0 or higher
59+
je foundACPIv1 ;; If AL is 0 then the system is using ACPI v1.0
60+
jmp foundACPIv2 ;; Otherwise it is v2.0 or higher
6061

62+
;; TODO: el foundACPIvN se puede juntar en 1 sola funcion o macro que contemple
63+
;; las pocas diferencias que hay que considerar.
6164
foundACPIv1: ; Root System Description Table (RSDT)
6265
xor eax, eax
6366
lodsd ; RsdtAddress - 32 bit physical address of the RSDT (Offset 16)
@@ -149,7 +152,7 @@ foundFADTTable:
149152
init_smp_acpi_done:
150153
ret
151154

152-
noACPI:
155+
acpiFail:
153156
novalidacpi:
154157
; Set screen to Teal
155158

asm/sysvar.asm

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,53 @@
1-
; =============================================================================
2-
; System Variables
3-
; =============================================================================
4-
5-
6-
;CONFIG
7-
cfg_smpinit: db 1 ; By default SMP is enabled. Set to 0 to disable.
8-
9-
; Memory locations
10-
InfoMap: equ 0x0000000000005000
11-
12-
;;;;;;;;;;;;;;; info de video la tengo en 2 lugares para consultar: InfoMap y VBEModeInfoBlock
13-
;;;;;;;;;;;;;;;; Info de video desde 0x5080
14-
;;;;;;;;;;;;;;;; 0x5080 = qword, framebuffer
15-
;;;;;;;;;;;;;;;; 0x5088 = word, screen x
16-
;;;;;;;;;;;;;;;; 0x508A = word, screen y
17-
;;;;;;;;;;;;;;;; 0x508C = word, ppsl
18-
;;;;;;;;;;;;;;;; 0x508E = word, bits ppx
19-
20-
IM_DetectedCoreIDs: equ 0x0000000000005100 ; 1 byte per entry - Each byte is the APIC ID of a core
21-
IM_PCIE: equ 0x0000000000005400 ; 16 bytes per entry
22-
IM_IOAPICAddress: equ 0x0000000000005600 ; 16 bytes per entry
23-
IM_IOAPICIntSource: equ 0x0000000000005700 ; 8 bytes per entry
1+
;;==============================================================================
2+
;; System Variables
3+
;;==============================================================================
4+
5+
6+
cfg_smpinit: db 1 ; By default SMP is enabled. Set to 0 to disable.
7+
8+
;; Memory locations
9+
;; Info de video en 2 lugares para consultar: InfoMap y VBEModeInfoBlock.
10+
;; Info de video desde 0x5080
11+
;; 0x5080 = qword, framebuffer
12+
;; 0x5088 = word, screen x
13+
;; 0x508A = word, screen y
14+
;; 0x508C = word, ppsl
15+
;; 0x508E = word, bits ppx
16+
17+
InfoMap: equ 0x0000000000005000
18+
IM_DetectedCoreIDs: equ 0x0000000000005100 ;; 1 byte per entry. Each is the API
19+
;; C ID of a core.
20+
IM_PCIE: equ 0x0000000000005400 ;; 16 bytes per entry
21+
IM_IOAPICAddress: equ 0x0000000000005600 ;; 16 bytes per entry
22+
IM_IOAPICIntSource: equ 0x0000000000005700 ;; 8 bytes per entry
2423
SystemVariables: equ 0x0000000000005800
25-
IM_ActivedCoreIDs: equ 0x0000000000005E00 ; 1 byte per entry - 1 if the core was activated
26-
24+
IM_ActivedCoreIDs: equ 0x0000000000005E00 ;; 1by per entry. 1 = 1 core active.
2725

2826

29-
;;; cuando bootea uefi, la info de video durante uefi la mete aqui\
30-
;;; y de esta manera:
31-
;;;[0x00005F00] ; Frame buffer base
32-
;;;[0x00005F08] ; Frame buffer size (bytes)
33-
;;;[0x00005F10] ; Screen X
34-
;;;;[0x00005F12] ; Screen Y
35-
;;;;[0x00005F14] ; PixelsPerScanLine
36-
;;; luego, durante el bootloader, la mantiene aqui, pero lo copia al infoMap 0x5080
37-
VBEModeInfoBlock: equ 0x0000000000005F00 ; 256 bytes
27+
;; Cuando bootea uefi, la info de video durante uefi la mete aqui:
28+
;; [0x00005F00] ;; Frame buffer base
29+
;; [0x00005F08] ;; Frame buffer size (bytes)
30+
;; [0x00005F10] ;; Screen X
31+
;; [0x00005F12] ;; Screen Y
32+
;; [0x00005F14] ;; PixelsPerScanLine
33+
;; Luego, durante el bootloader, la mantiene aqui, pero tambien copia al infoMap
34+
;; 0x5080
3835

36+
VBEModeInfoBlock: equ 0x0000000000005F00 ;; 256 bytes.
3937

40-
41-
; DQ - Starting at offset 0, increments by 0x8
38+
;; DQ - Starting at offset 0, increments by 0x8
4239
p_ACPITableAddress: equ SystemVariables + 0x00
4340
p_LocalAPICAddress: equ SystemVariables + 0x10
4441
p_Counter_Timer: equ SystemVariables + 0x18
4542
p_Counter_RTC: equ SystemVariables + 0x20
4643
p_HPET_Address: equ SystemVariables + 0x28
4744

48-
; DD - Starting at offset 0x80, increments by 4
49-
p_BSP: equ SystemVariables + 0x80
50-
p_mem_amount: equ SystemVariables + 0x84 ; in MiB
45+
;; DD - Starting at offset 0x80, increments by 4
46+
p_BSP: equ SystemVariables + 0x80
47+
p_mem_amount: equ SystemVariables + 0x84 ;; MiB
5148
p_HPET_Frequency: equ SystemVariables + 0x88
5249

53-
; DW - Starting at offset 0x100, increments by 2
50+
;; DW - Starting at offset 0x100, increments by 2
5451
p_cpu_speed: equ SystemVariables + 0x100
5552
p_cpu_activated: equ SystemVariables + 0x102
5653
p_cpu_detected: equ SystemVariables + 0x104
@@ -60,51 +57,55 @@ p_IAPC_BOOT_ARCH: equ SystemVariables + 0x10A
6057

6158
; DB - Starting at offset 0x180, increments by 1
6259
p_IOAPICCount: equ SystemVariables + 0x180
63-
p_BootMode: equ SystemVariables + 0x181 ; 'U' for UEFI, otherwise BIOS
60+
p_BootMode: equ SystemVariables + 0x181 ;; 'U' for UEFI, otherwise BIOS
6461
p_IOAPICIntSourceC: equ SystemVariables + 0x182
65-
p_x2APIC: equ SystemVariables + 0x183
62+
p_x2APIC: equ SystemVariables + 0x183
6663
p_HPET_Timers: equ SystemVariables + 0x184
67-
p_BootDisk: equ SystemVariables + 0x185 ; 'F' for Floppy drive
68-
p_1GPages: equ SystemVariables + 0x186 ; 1 if 1GB pages are supported
64+
p_BootDisk: equ SystemVariables + 0x185 ;; 'F' for Floppy drive
65+
p_1GPages: equ SystemVariables + 0x186 ;; 1 if 1GB pages are supported
6966

7067
align 16
71-
GDTR32: ; Global Descriptors Table Register
72-
dw gdt32_end - gdt32 - 1 ; limit of GDT (size minus one)
73-
dq gdt32 ; linear address of GDT
68+
GDTR32: ;; Global Descriptors Table Register
69+
dw gdt32_end - gdt32 - 1 ;; Limit.
70+
dq gdt32 ;; Linear address of GDT
7471

7572
align 16
7673
gdt32:
77-
SYS32_NULL_SEL equ $-gdt32 ; Null Segment
78-
dq 0x0000000000000000
79-
SYS32_CODE_SEL equ $-gdt32 ; 32-bit code descriptor
80-
dq 0x00CF9A000000FFFF ; 55 Granularity 4KiB, 54 Size 32bit, 47 Present, 44 Code/Data, 43 Executable, 41 Readable
81-
SYS32_DATA_SEL equ $-gdt32 ; 32-bit data descriptor
82-
dq 0x00CF92000000FFFF ; 55 Granularity 4KiB, 54 Size 32bit, 47 Present, 44 Code/Data, 41 Writeable
74+
SYS32_NULL_SEL: equ $ - gdt32 ;; Null Segment
75+
dq 0x0000000000000000
76+
SYS32_CODE_SEL: equ $ - gdt32 ;; 32-bit code descriptor
77+
dq 0x00CF9A000000FFFF ;; 55 Granularity 4KiB, 54 Size 32bit, 4
78+
;; 7 Present, 44 Code/Data, 43 Executabl
79+
;; e, 41 Readable.
80+
SYS32_DATA_SEL: equ $ - gdt32 ;; 32-bit data descriptor
81+
dq 0x00CF92000000FFFF ;; 55 Granularity 4KiB, 54 Size 32bit, 4
82+
;; 7 Present, 44 Code/Data, 41 Writeable
8383
gdt32_end:
8484

8585
align 16
86-
tGDTR64: ; Global Descriptors Table Register
87-
dw gdt64_end - gdt64 - 1 ; limit of GDT (size minus one)
88-
dq gdt64 ; linear address of GDT
86+
87+
tGDTR64: ;; Global Descriptors Table Register
88+
dw gdt64_end - gdt64 - 1 ;; Limit.
89+
dq gdt64 ;; linear address of GDT
8990

9091
align 16
91-
GDTR64: ; Global Descriptors Table Register
92-
dw gdt64_end - gdt64 - 1 ; limit of GDT (size minus one)
93-
dq 0x0000000000001000 ; linear address of GDT
94-
95-
gdt64: ; This structure is copied to 0x0000000000001000
96-
SYS64_NULL_SEL equ $-gdt64 ; Null Segment
97-
dq 0x0000000000000000
98-
SYS64_CODE_SEL equ $-gdt64 ; Code segment, read/execute, nonconforming
99-
dq 0x00209A0000000000 ; 53 Long mode code, 47 Present, 44 Code/Data, 43 Executable, 41 Readable
100-
SYS64_DATA_SEL equ $-gdt64 ; Data segment, read/write, expand down
101-
dq 0x0000920000000000 ; 47 Present, 44 Code/Data, 41 Writable
92+
GDTR64: ;; Global Descriptors Table Register
93+
dw gdt64_end - gdt64 - 1 ;; Limit.
94+
dq 0x0000000000001000 ;; linear address of GDT
95+
96+
gdt64: ;; Struct copied to 0x0000000000001000
97+
SYS64_NULL_SEL: equ $ - gdt64 ;; Null Segment
98+
dq 0x0000000000000000
99+
SYS64_CODE_SEL: equ $ - gdt64 ;; Code segment, read/execute, nonconfor
100+
;; ming
101+
dq 0x00209A0000000000 ;; 53 Long mode code, 47 Present, 44 Cod
102+
;; e/Data, 43 Executable, 41 Readable
103+
SYS64_DATA_SEL: equ $ - gdt64 ;; Data segment, read/write, expand down
104+
dq 0x0000920000000000 ;; 47 Present, 44 Code/Data, 41 Writable
102105
gdt64_end:
103106

104-
IDTR64: ; Interrupt Descriptor Table Register
105-
dw 256*16-1 ; limit of IDT (size minus one) (4096 bytes - 1)
106-
dq 0x0000000000000000 ; linear address of IDT
107+
IDTR64: ;; Interrupt Descriptor Table Register
108+
dw 256 * 16 - 1 ;; Limit = 4096 - 1
109+
dq 0x0000000000000000 ;; linear address of IDT
107110

108111

109-
; =============================================================================
110-
; EOF

build/bootloader.sys

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)