2011-10-14 23:38:50 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 17:15:14 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc mem_test
|
|
|
|
; if we have BIOS with fn E820, skip the test
|
2020-11-17 22:47:10 +01:00
|
|
|
cmp [BOOT_LO.memmap_block_cnt], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .ret
|
|
|
|
|
|
|
|
mov eax, cr0
|
2022-02-12 18:27:41 +01:00
|
|
|
and eax, not (CR0_CD + CR0_NW)
|
2011-10-14 23:38:50 +02:00
|
|
|
or eax, CR0_CD ;disable caching
|
|
|
|
mov cr0, eax
|
|
|
|
wbinvd ;invalidate cache
|
|
|
|
|
|
|
|
xor edi, edi
|
|
|
|
mov ebx, 'TEST'
|
|
|
|
@@:
|
|
|
|
add edi, 0x100000
|
|
|
|
xchg ebx, dword [edi]
|
|
|
|
cmp dword [edi], 'TEST'
|
|
|
|
xchg ebx, dword [edi]
|
|
|
|
je @b
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
and eax, not (CR0_CD + CR0_NW) ;enable caching
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cr0, eax
|
2017-12-17 03:12:53 +01:00
|
|
|
inc dword [BOOT_LO.memmap_block_cnt]
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [BOOT_LO.memmap_blocks + e820entry.addr.lo], eax
|
|
|
|
mov [BOOT_LO.memmap_blocks + e820entry.addr.hi], eax
|
|
|
|
mov [BOOT_LO.memmap_blocks + e820entry.size.lo], edi
|
|
|
|
mov [BOOT_LO.memmap_blocks + e820entry.size.hi], eax
|
2013-12-20 14:13:43 +01:00
|
|
|
inc eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [BOOT_LO.memmap_blocks + e820entry.type], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc init_mem
|
|
|
|
; calculate maximum allocatable address and number of allocatable pages
|
2017-12-17 03:12:53 +01:00
|
|
|
mov edi, BOOT_LO.memmap_blocks
|
2020-11-17 22:47:10 +01:00
|
|
|
mov ecx, [edi-4] ; memmap_block_cnt
|
2011-10-14 23:38:50 +02:00
|
|
|
xor esi, esi; esi will hold total amount of memory
|
|
|
|
xor edx, edx; edx will hold maximum allocatable address
|
|
|
|
.calcmax:
|
|
|
|
; round all to pages
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [edi + e820entry.addr.lo]
|
|
|
|
cmp byte [edi + e820entry.type], 1
|
2012-03-15 14:05:45 +01:00
|
|
|
jne .unusable
|
|
|
|
|
2023-02-12 22:37:30 +01:00
|
|
|
test eax, PAGE_SIZE-1
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
|
|
|
neg eax
|
2023-02-12 22:37:30 +01:00
|
|
|
and eax, PAGE_SIZE-1
|
2022-02-12 18:27:41 +01:00
|
|
|
add [edi + e820entry.addr.lo], eax
|
|
|
|
adc [edi + e820entry.addr.hi], 0
|
|
|
|
sub [edi + e820entry.size.lo], eax
|
|
|
|
sbb [edi + e820entry.size.hi], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jc .unusable
|
|
|
|
@@:
|
2023-02-12 22:37:30 +01:00
|
|
|
and [edi + e820entry.size.lo], -PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
jz .unusable
|
2020-11-17 22:47:10 +01:00
|
|
|
; ignore memory after 4 GiB
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp [edi + e820entry.addr.hi], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .unusable
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [edi + e820entry.addr.lo]
|
|
|
|
cmp [edi + e820entry.size.hi], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .overflow
|
2022-02-12 18:27:41 +01:00
|
|
|
add eax, [edi + e820entry.size.lo]
|
2011-10-14 23:38:50 +02:00
|
|
|
jnc @f
|
|
|
|
.overflow:
|
2023-02-12 22:37:30 +01:00
|
|
|
mov eax, -PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
cmp edx, eax
|
|
|
|
jae @f
|
|
|
|
mov edx, eax
|
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
sub eax, [edi + e820entry.addr.lo]
|
|
|
|
mov [edi + e820entry.size.lo], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
add esi, eax
|
|
|
|
jmp .usable
|
|
|
|
.unusable:
|
2020-11-17 22:47:10 +01:00
|
|
|
; and dword [edi+e820entry.size.lo], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
.usable:
|
2020-11-17 22:47:10 +01:00
|
|
|
add edi, sizeof.e820entry
|
2011-10-14 23:38:50 +02:00
|
|
|
loop .calcmax
|
|
|
|
.calculated:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [MEM_AMOUNT - OS_BASE], esi
|
|
|
|
mov [pg_data.mem_amount - OS_BASE], esi
|
2011-10-14 23:38:50 +02:00
|
|
|
shr esi, 12
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [pg_data.pages_count - OS_BASE], esi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
shr edx, 12
|
|
|
|
add edx, 31
|
|
|
|
and edx, not 31
|
|
|
|
shr edx, 3
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [pg_data.pagemap_size - OS_BASE], edx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2023-02-12 22:37:30 +01:00
|
|
|
add edx, (sys_pgmap - OS_BASE)+PAGE_SIZE-1
|
|
|
|
and edx, -PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [tmp_page_tabs], edx
|
|
|
|
|
|
|
|
mov edx, esi
|
|
|
|
and edx, -1024
|
2023-02-12 22:37:30 +01:00
|
|
|
cmp edx, (OS_BASE/PAGE_SIZE)
|
2011-10-14 23:38:50 +02:00
|
|
|
jbe @F
|
2023-02-12 22:37:30 +01:00
|
|
|
mov edx, (OS_BASE/PAGE_SIZE)
|
2011-10-14 23:38:50 +02:00
|
|
|
jmp .set
|
|
|
|
@@:
|
2023-02-12 22:37:30 +01:00
|
|
|
cmp edx, (HEAP_BASE - OS_BASE + HEAP_MIN_SIZE)/PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .set
|
2023-02-12 22:37:30 +01:00
|
|
|
mov edx, (HEAP_BASE - OS_BASE + HEAP_MIN_SIZE)/PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
.set:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [pg_data.kernel_pages - OS_BASE], edx
|
2011-10-14 23:38:50 +02:00
|
|
|
shr edx, 10
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [pg_data.kernel_tables - OS_BASE], edx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
xor eax, eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, sys_proc - OS_BASE
|
2023-02-12 22:37:30 +01:00
|
|
|
mov ecx, 2*PAGE_SIZE/4
|
2011-10-14 23:38:50 +02:00
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
2023-02-12 22:37:30 +01:00
|
|
|
mov edx, (sys_proc - OS_BASE + PROC.pdt_0) + (OS_BASE shr 20)
|
2022-02-12 18:27:41 +01:00
|
|
|
bt [cpu_caps - OS_BASE], CAPS_PSE
|
2011-10-14 23:38:50 +02:00
|
|
|
jnc .no_PSE
|
|
|
|
|
|
|
|
mov ebx, cr4
|
|
|
|
or ebx, CR4_PSE
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, PDE_LARGE + PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov cr4, ebx
|
2022-02-12 18:27:41 +01:00
|
|
|
dec [pg_data.kernel_tables - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov [edx], eax
|
|
|
|
add edx, 4
|
|
|
|
|
|
|
|
mov edi, [tmp_page_tabs]
|
|
|
|
jmp .map_kernel_heap ; new kernel fits to the first 4Mb - nothing to do with ".map_low"
|
|
|
|
.no_PSE:
|
2015-01-06 15:53:54 +01:00
|
|
|
mov eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, [tmp_page_tabs]
|
|
|
|
shr ecx, 12
|
|
|
|
.map_low:
|
|
|
|
mov edi, [tmp_page_tabs]
|
|
|
|
@@: ;
|
|
|
|
stosd
|
2023-02-12 22:37:30 +01:00
|
|
|
add eax, PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
.map_kernel_heap:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [pg_data.kernel_tables - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
shl ecx, 10
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [pg_data.kernel_tables - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, [tmp_page_tabs]
|
2015-01-06 15:53:54 +01:00
|
|
|
or eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov edi, edx
|
|
|
|
|
|
|
|
.map_kernel_tabs:
|
|
|
|
stosd
|
2023-02-12 22:37:30 +01:00
|
|
|
add eax, PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
dec ecx
|
|
|
|
jnz .map_kernel_tabs
|
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
mov dword [sys_proc-OS_BASE+PROC.pdt_0+(page_tabs shr 20)], sys_proc+PROC.pdt_0+PG_SWR-OS_BASE
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, (sys_proc + PROC.pdt_0 - OS_BASE)
|
|
|
|
lea esi, [edi + (OS_BASE shr 20)]
|
2011-10-14 23:38:50 +02:00
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc init_page_map
|
|
|
|
; mark all memory as unavailable
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, sys_pgmap - OS_BASE
|
|
|
|
mov ecx, [pg_data.pagemap_size - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
shr ecx, 2
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
; scan through memory map and mark free areas as available
|
2017-12-17 03:12:53 +01:00
|
|
|
mov ebx, BOOT_LO.memmap_blocks
|
2011-10-14 23:38:50 +02:00
|
|
|
mov edx, [ebx-4]
|
|
|
|
.scanmap:
|
2022-02-12 18:27:41 +01:00
|
|
|
cmp byte [ebx + e820entry.type], 1
|
2012-03-15 14:05:45 +01:00
|
|
|
jne .next
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ecx, [ebx + e820entry.size.lo]
|
2011-10-14 23:38:50 +02:00
|
|
|
shr ecx, 12; ecx = number of pages
|
|
|
|
jz .next
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, [ebx + e820entry.addr.lo]
|
2011-10-14 23:38:50 +02:00
|
|
|
shr edi, 12; edi = first page
|
|
|
|
mov eax, edi
|
|
|
|
shr edi, 5
|
|
|
|
shl edi, 2
|
2022-02-12 18:27:41 +01:00
|
|
|
add edi, sys_pgmap - OS_BASE
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 31
|
|
|
|
jz .startok
|
|
|
|
add ecx, eax
|
|
|
|
sub ecx, 32
|
|
|
|
jbe .onedword
|
|
|
|
push ecx
|
|
|
|
mov ecx, eax
|
|
|
|
or eax, -1
|
|
|
|
shl eax, cl
|
|
|
|
or [edi], eax
|
|
|
|
add edi, 4
|
|
|
|
pop ecx
|
|
|
|
.startok:
|
|
|
|
push ecx
|
|
|
|
shr ecx, 5
|
|
|
|
or eax, -1
|
|
|
|
rep stosd
|
|
|
|
pop ecx
|
|
|
|
and ecx, 31
|
|
|
|
neg eax
|
|
|
|
shl eax, cl
|
|
|
|
dec eax
|
|
|
|
or [edi], eax
|
|
|
|
jmp .next
|
|
|
|
.onedword:
|
|
|
|
add ecx, 32
|
|
|
|
sub ecx, eax
|
|
|
|
@@:
|
|
|
|
bts [edi], eax
|
|
|
|
inc eax
|
|
|
|
loop @b
|
|
|
|
.next:
|
2020-11-17 22:47:10 +01:00
|
|
|
add ebx, sizeof.e820entry
|
2011-10-14 23:38:50 +02:00
|
|
|
dec edx
|
|
|
|
jnz .scanmap
|
|
|
|
|
|
|
|
; mark kernel memory as allocated (unavailable)
|
|
|
|
mov ecx, [tmp_page_tabs]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edx, [pg_data.pages_count - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
shr ecx, 12
|
2022-02-12 18:27:41 +01:00
|
|
|
add ecx, [pg_data.kernel_tables - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
sub edx, ecx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [pg_data.pages_free - OS_BASE], edx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edi, sys_pgmap - OS_BASE
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ebx, ecx
|
|
|
|
shr ecx, 5
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
not eax
|
|
|
|
mov ecx, ebx
|
|
|
|
and ecx, 31
|
|
|
|
shl eax, cl
|
|
|
|
and [edi], eax
|
|
|
|
add edi, OS_BASE
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [page_start - OS_BASE], edi;
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov ebx, sys_pgmap
|
2022-02-12 18:27:41 +01:00
|
|
|
add ebx, [pg_data.pagemap_size - OS_BASE]
|
|
|
|
mov [page_end - OS_BASE], ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
|
|
|
init_BIOS32:
|
|
|
|
mov edi, 0xE0000
|
|
|
|
.pcibios_nxt:
|
|
|
|
cmp dword[edi], '_32_'; "magic" word
|
|
|
|
je .BIOS32_found
|
|
|
|
.pcibios_nxt2:
|
|
|
|
add edi, 0x10
|
|
|
|
cmp edi, 0xFFFF0
|
|
|
|
je .BIOS32_not_found
|
|
|
|
jmp .pcibios_nxt
|
|
|
|
.BIOS32_found: ; magic word found, check control summ
|
|
|
|
|
|
|
|
movzx ecx, byte[edi + 9]
|
|
|
|
shl ecx, 4
|
|
|
|
mov esi, edi
|
|
|
|
xor eax, eax
|
|
|
|
cld ; paranoia
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
add ah, al
|
|
|
|
loop @b
|
|
|
|
jnz .pcibios_nxt2; control summ must be zero
|
|
|
|
; BIOS32 service found !
|
|
|
|
mov ebp, [edi + 4]
|
|
|
|
mov [bios32_entry], ebp
|
|
|
|
; check PCI BIOS present
|
|
|
|
mov eax, '$PCI'
|
|
|
|
xor ebx, ebx
|
|
|
|
push cs ; special for 'ret far' from BIOS
|
|
|
|
call ebp
|
|
|
|
test al, al
|
|
|
|
jnz .PCI_BIOS32_not_found
|
|
|
|
|
2020-07-16 15:51:29 +02:00
|
|
|
; descriptors for PCI BIOS are created here
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
add ebx, OS_BASE
|
|
|
|
dec ecx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [(pci_code_32 - OS_BASE)], cx ;limit 0-15
|
|
|
|
mov [(pci_data_32 - OS_BASE)], cx ;limit 0-15
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [(pci_code_32 - OS_BASE)+2], bx ;base 0-15
|
|
|
|
mov [(pci_data_32 - OS_BASE)+2], bx ;base 0-15
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
shr ebx, 16
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [(pci_code_32 - OS_BASE)+4], bl ;base 16-23
|
|
|
|
mov [(pci_data_32 - OS_BASE)+4], bl ;base 16-23
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
shr ecx, 16
|
|
|
|
and cl, 0x0F
|
|
|
|
mov ch, bh
|
|
|
|
add cx, D32
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [(pci_code_32 - OS_BASE)+6], cx ;lim 16-19 &
|
|
|
|
mov [(pci_data_32 - OS_BASE)+6], cx ;base 24-31
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [(pci_bios_entry - OS_BASE)], edx
|
2011-10-14 23:38:50 +02:00
|
|
|
; jmp .end
|
|
|
|
.PCI_BIOS32_not_found:
|
2020-07-16 15:51:29 +02:00
|
|
|
; pci_emu_dat structure should be filled here
|
2011-10-14 23:38:50 +02:00
|
|
|
.BIOS32_not_found:
|
|
|
|
.end:
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc test_cpu
|
|
|
|
locals
|
|
|
|
cpu_type dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [cpu_type], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [cpu_caps - OS_BASE], eax
|
|
|
|
mov [cpu_caps + 4 - OS_BASE], eax
|
|
|
|
mov [cpu_phys_addr_width - OS_BASE], 32
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
mov ecx, eax
|
2017-12-05 07:39:34 +01:00
|
|
|
xor eax, EFLAGS_AC
|
2011-10-14 23:38:50 +02:00
|
|
|
push eax
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
xor eax, ecx
|
|
|
|
mov [cpu_type], CPU_386
|
|
|
|
jz .end_cpuid
|
|
|
|
push ecx
|
|
|
|
popfd
|
|
|
|
|
|
|
|
mov [cpu_type], CPU_486
|
|
|
|
mov eax, ecx
|
2017-12-05 07:39:34 +01:00
|
|
|
xor eax, EFLAGS_ID
|
2011-10-14 23:38:50 +02:00
|
|
|
push eax
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
xor eax, ecx
|
|
|
|
je .end_cpuid
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
cpuid
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [cpu_vendor - OS_BASE], ebx
|
|
|
|
mov [cpu_vendor + 4 - OS_BASE], edx
|
|
|
|
mov [cpu_vendor + 8 - OS_BASE], ecx
|
2014-02-25 20:12:10 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp eax, 1
|
|
|
|
jl .end_cpuid
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [cpu_sign - OS_BASE], eax
|
|
|
|
mov [cpu_info - OS_BASE], ebx
|
|
|
|
mov [cpu_caps - OS_BASE], edx
|
|
|
|
mov [cpu_caps + 4 - OS_BASE], ecx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2014-02-25 20:12:10 +01:00
|
|
|
bt edx, CAPS_PAE
|
|
|
|
jnc @f
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [cpu_phys_addr_width - OS_BASE], 36
|
2014-02-25 20:12:10 +01:00
|
|
|
@@:
|
|
|
|
mov eax, 0x80000000
|
|
|
|
cpuid
|
|
|
|
cmp eax, 0x80000008
|
|
|
|
jb @f
|
|
|
|
mov eax, 0x80000008
|
|
|
|
cpuid
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [cpu_phys_addr_width - OS_BASE], al
|
2014-02-25 20:12:10 +01:00
|
|
|
@@:
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [cpu_sign - OS_BASE]
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
and eax, 0x0f
|
|
|
|
ret
|
|
|
|
.end_cpuid:
|
|
|
|
mov eax, [cpu_type]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2017-12-20 02:07:10 +01:00
|
|
|
ACPI_RSDP_CHECKSUM_LENGTH = 20
|
2015-09-03 16:47:08 +02:00
|
|
|
|
2020-10-21 16:23:51 +02:00
|
|
|
proc acpi_locate_tables uses ebx esi edi
|
2022-02-12 18:27:41 +01:00
|
|
|
mov ebx, [ebx + ACPI_RSDP.RsdtAddress]
|
|
|
|
mov [acpi_rsdt_base - OS_BASE], ebx
|
|
|
|
mov eax, [ebx + ACPI_RSDT.Length]
|
|
|
|
mov [acpi_rsdt_size - OS_BASE], eax
|
|
|
|
|
|
|
|
mov esi, [acpi_rsdt_base - OS_BASE]
|
|
|
|
mov ecx, [esi + ACPI_RSDT.Length]
|
|
|
|
lea edi, [esi + ecx]
|
2020-10-21 16:23:51 +02:00
|
|
|
add esi, sizeof.ACPI_TABLE
|
|
|
|
movi ecx, 1
|
|
|
|
.next_table:
|
|
|
|
cmp esi, edi
|
|
|
|
jae .done
|
|
|
|
lodsd
|
|
|
|
cmp [eax+ACPI_TABLE.Signature], 'SSDT' ; skip DSDT if present
|
|
|
|
jz .ssdt ; read it from FADT
|
|
|
|
cmp [eax+ACPI_TABLE.Signature], 'FACP' ; this is FADT
|
|
|
|
jz .fadt
|
|
|
|
cmp [eax+ACPI_TABLE.Signature], 'APIC' ; this is MADT
|
|
|
|
jz .madt
|
|
|
|
cmp [eax+ACPI_TABLE.Signature], 'HPET'
|
|
|
|
jz .hpet
|
|
|
|
jmp .next_table
|
|
|
|
.ssdt:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_ssdt_base + ecx*4 - OS_BASE], eax
|
2020-10-21 16:23:51 +02:00
|
|
|
mov eax, [eax+ACPI_TABLE.Length]
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_ssdt_size + ecx*4 - OS_BASE], eax
|
2020-10-21 16:23:51 +02:00
|
|
|
inc ecx
|
|
|
|
jmp .next_table
|
|
|
|
.fadt:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_fadt_base - OS_BASE], eax
|
|
|
|
cmp [eax + ACPI_FADT.DSDT], 0
|
2020-10-21 16:23:51 +02:00
|
|
|
jz @f
|
2022-02-12 18:27:41 +01:00
|
|
|
mov edx, [eax + ACPI_FADT.DSDT]
|
|
|
|
mov [acpi_ssdt_base - OS_BASE], edx
|
|
|
|
mov edx, [edx + ACPI_TABLE.Length]
|
|
|
|
mov [acpi_ssdt_size - OS_BASE], edx
|
2020-10-21 16:23:51 +02:00
|
|
|
@@:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [eax + ACPI_TABLE.Length]
|
|
|
|
mov [acpi_fadt_size - OS_BASE], eax
|
2020-10-21 16:23:51 +02:00
|
|
|
jmp .next_table
|
|
|
|
.madt:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_madt_base - OS_BASE], eax
|
|
|
|
mov eax, [eax + ACPI_TABLE.Length]
|
|
|
|
mov [acpi_madt_size - OS_BASE], eax
|
2020-10-21 16:23:51 +02:00
|
|
|
jmp .next_table
|
|
|
|
.hpet:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_hpet_base - OS_BASE], eax
|
|
|
|
mov eax, [eax + ACPI_TABLE.Length]
|
|
|
|
mov [acpi_hpet_size - OS_BASE], eax
|
2020-10-21 16:23:51 +02:00
|
|
|
jmp .next_table
|
|
|
|
.done:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_ssdt_cnt - OS_BASE], ecx
|
2020-10-21 16:23:51 +02:00
|
|
|
ret
|
|
|
|
endp
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
acpi_locate:
|
|
|
|
push ebx
|
2016-02-18 03:03:38 +01:00
|
|
|
push edi
|
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
mov ebx, [BOOT_LO.acpi_rsdp]
|
2017-12-16 22:10:49 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .done
|
2024-01-14 02:39:36 +01:00
|
|
|
mov edi, ebx
|
2017-12-16 22:10:49 +01:00
|
|
|
call .check
|
2016-02-18 03:03:38 +01:00
|
|
|
.done:
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [acpi_rsdp_base - OS_BASE], ebx
|
2020-10-21 16:23:51 +02:00
|
|
|
test ebx, ebx
|
|
|
|
jz @f
|
|
|
|
call acpi_locate_tables
|
|
|
|
@@:
|
2016-02-18 03:03:38 +01:00
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
.check:
|
2017-11-29 23:03:58 +01:00
|
|
|
cmp [ebx], dword 'RSD '
|
2011-10-14 23:38:50 +02:00
|
|
|
jne .next
|
2017-11-29 23:03:58 +01:00
|
|
|
cmp [ebx+4], dword 'PTR '
|
2011-10-14 23:38:50 +02:00
|
|
|
jne .next
|
|
|
|
|
|
|
|
mov edx, ebx
|
|
|
|
mov ecx, ACPI_RSDP_CHECKSUM_LENGTH
|
|
|
|
xor eax, eax
|
|
|
|
.sum:
|
|
|
|
add al, [edx]
|
|
|
|
inc edx
|
|
|
|
loop .sum
|
|
|
|
|
|
|
|
test al, al
|
|
|
|
jnz .next
|
|
|
|
ret
|
|
|
|
.next:
|
|
|
|
add ebx, 16
|
2016-02-18 03:03:38 +01:00
|
|
|
cmp ebx, edi
|
2011-10-14 23:38:50 +02:00
|
|
|
jb .check
|
2016-02-18 03:03:38 +01:00
|
|
|
xor ebx, ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|