-
Notifications
You must be signed in to change notification settings - Fork 1
/
pmm.asm
93 lines (72 loc) · 1.86 KB
/
pmm.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
; pmm.asm -- Interaction with the POST memory manager
; This file is part of ahci_sbe.
; Copyright (C) 2014 Tobias Kaiser <[email protected]>
; Detect POST memory manager
; --------------------------
pmm_detect_and_alloc:
mov AX, 0xE000
mov ES, AX
pmm_detection_loop:
mov EBX, [ES:0]
cmp EBX, 0x4d4d5024
jz pmm_detected
inc AX
mov ES, AX
jnz pmm_detection_loop
mov AX, err_no_pmm
jmp fatal_error
pmm_detected:
; calculate checksum
mov BX, 0 ; offset
mov CL, 0 ; checksum comes here
mov AL, [ES:05h] ; length
pmm_sum:
add CL, [ES:BX]
inc BL
cmp BL, AL
jl pmm_sum
cmp CL, 0
jz pmm_sum_success
mov AX, err_pmm_chksum
jmp fatal_error
pmm_sum_success:
; save entry point - our PMM interfe far function pointer
mov AX, [ES:07h]
mov [pmm_entry_point], AX
mov AX, [ES:07h+2]
mov [pmm_entry_point+2], AX
mov AX, 0
mov ES, AX ; now we can use ES for 32 bit physical adressing
; Allocate memory
; ---------------
mov EAX, 1024/16
call pmm_alloc_paragraphs
mov [cmd_list], EAX
mov EAX, 256/16
call pmm_alloc_paragraphs
mov [cmd_table], EAX
mov EAX, 4096/16
call pmm_alloc_paragraphs
mov [fis_recv], EAX
mov EAX, 512/16
call pmm_alloc_paragraphs
mov [ahci_data_buf], EAX
ret
; Function: Allocate EAX paragraphs
; ---------------------------------
pmm_alloc_paragraphs:
push word 0b111 ; Flags: Aligned, conventional or extended
push dword 0xFFFFFFFF ; anonymous allocation
push EAX; size in paragraphs
push 0x0000 ; function: allocate
call far [pmm_entry_point]
add sp, 12 ; clean up after C style function call
xchg DX, AX
shl EAX, 16
mov AX, DX
cmp EAX, 0
je pmm_alloc_fail
ret
pmm_alloc_fail:
mov AX, err_pmm_alloc
jmp fatal_error