summaryrefslogtreecommitdiff
path: root/other/Kermit/lib/rwKernel.cpp
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/lib/rwKernel.cpp
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'other/Kermit/lib/rwKernel.cpp')
-rw-r--r--other/Kermit/lib/rwKernel.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/other/Kermit/lib/rwKernel.cpp b/other/Kermit/lib/rwKernel.cpp
new file mode 100644
index 0000000..4077ff5
--- /dev/null
+++ b/other/Kermit/lib/rwKernel.cpp
@@ -0,0 +1,107 @@
1/*
2 * rwKernel.cpp:
3 * written by palmers / teso
4 */
5#include <rwKernel.hpp>
6#include <unistd.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <sys/mman.h>
11#include <iostream>
12
13
14 bool rwKernel::openFile (int w)
15 {
16 int a = 0;
17 void *tmp = NULL;
18 char *file = NULL;
19
20 if (w == DEVMEM)
21 file = "/dev/mem";
22 else if (w == PROCKCORE)
23 file = "/proc/kcore";
24
25 if ((a = open (file, O_RDWR)) <= 0)
26 {
27 cerr << "open error" << endl;
28 abort ();
29 }
30
31 if ((tmp = mmap (NULL, 0x40000000, PROT_READ | \
32 PROT_WRITE, MAP_SHARED, a, 0xc0000000 - mem_conf)) == (void *) -1)
33 {
34 cerr << "mmap failed" << endl;
35 abort ();
36 }
37 fd = (char *) tmp;
38 return true;
39 }
40
41
42 void rwKernel::setOffset (int x)
43 {
44 switch (x)
45 {
46 case CONF_1GB:
47 mem_conf = 0xC0000000;
48 break;
49 case CONF_2GB:
50 mem_conf = 0x80000000;
51 break;
52 case CONF_3GB:
53 mem_conf = 0x40000000;
54 break;
55 case IGNORE:
56 mem_conf = 0xC0000000;
57 break;
58 default:
59 mem_conf = 0xC0000000;
60 break;
61 }
62 }
63
64
65 void rwKernel::closeFile ()
66 {
67 munmap (fd, 0x40000000);
68 }
69
70
71 rwKernel::rwKernel ()
72 {
73 setOffset (CONF_1GB);
74 openFile (DEVMEM);
75 }
76
77
78 rwKernel::rwKernel (int file, int off)
79 {
80 if (file == PROCKCORE)
81 off = IGNORE;
82 setOffset (off);
83 openFile (file);
84 }
85
86
87 rwKernel::~rwKernel ()
88 {
89 closeFile ();
90 }
91
92
93 void rwKernel::read (unsigned char *dest, unsigned int len, \
94 unsigned int offset)
95 {
96 offset -= mem_conf;
97 copy (fd + offset, fd + offset + len, dest);
98 }
99
100
101 void rwKernel::write (unsigned char *src, unsigned int len, \
102 unsigned int offset)
103 {
104 offset -= mem_conf;
105 copy (src, src + len, fd + offset);
106 }
107