-
Notifications
You must be signed in to change notification settings - Fork 11
/
A20.pas
97 lines (76 loc) · 1.83 KB
/
A20.pas
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
94
95
96
97
(*
说明:全志A20的地址映射封装类。
单例,请勿在程序中使用。
作者:tjCFeng
邮箱:tjCFeng@163.com
更新日期:2014.12.06
*)
unit A20;
{$mode objfpc}{$H+}
interface
uses Unix, BaseUnix, SysUtils;
type
TGROUP1_REG = ^LongWord;
TGROUP2_REG = array [0..1] of ^LongWord;
TGROUP4_REG = array [0..3] of ^LongWord;
TGROUP5_REG = array [0..4] of ^LongWord;
TGROUP6_REG = array [0..5] of ^LongWord;
TGROUP16_REG = array [0..15] of ^LongWord;
type
TA20 = class
private
class var FInstance: TA20;
class function GetInstance: TA20; static;
public
class procedure Release;
class property Instance: TA20 read GetInstance;
private
FhMEM: Integer;
constructor Create;
destructor Destroy; override;
public
function GetMMap(BaseAddr: LongWord): PLongWord;
function BaseOffset(BaseAddr: LongWord): LongWord;
procedure FreeMMap(MMapAddr: PLongWord);
end;
implementation
const
PAGE_SIZE = 4096;
BLOCK_SIZE = 4096;
class function TA20.GetInstance: TA20;
begin
if FInstance = nil then FInstance:= TA20.Create;
Result:= FInstance;
end;
class procedure TA20.Release;
begin
FreeAndNil(FInstance);
end;
constructor TA20.Create;
begin
inherited Create;
FhMEM:= fpopen('/dev/mem', O_RdWr);
if (FhMEM < 0) then Exit;
end;
destructor TA20.Destroy;
begin
fpclose(FhMEM);
inherited Destroy;
end;
function TA20.GetMMap(BaseAddr: LongWord): PLongWord;
var MEM: LongWord;
begin
MEM:= (BaseAddr and $FFFFF000) div PAGE_SIZE;
Result:= fpMmap(nil, PAGE_SIZE, PROT_READ or PROT_WRITE, MAP_SHARED, FhMem, MEM);
end;
function TA20.BaseOffset(BaseAddr: LongWord): LongWord;
begin
Result:= (BaseAddr and $00000FFF);
end;
procedure TA20.FreeMMap(MMapAddr: PLongWord);
begin
if (MMapAddr <> nil) then fpMUnmap(MMapAddr, PAGE_SIZE);
end;
finalization
TA20.Instance.Release;
end.