Skip to content

Commit d77b07b

Browse files
committed
added acpi dump module
1 parent f56cdf4 commit d77b07b

File tree

9 files changed

+167
-14
lines changed

9 files changed

+167
-14
lines changed

mckrnl/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ all:
88
make -C driver/ac97
99
make -C driver/ata
1010
make -C driver/ps2
11-
make -C driver/ahci
1211

1312
make -C network/am79C973
1413
make -C network/e1000
1514
make -C network/ne2k
1615
make -C network/rtl8139
1716

17+
make -C feature/acpi_dump
18+
1819

1920
clean:
2021
make -C core clean
@@ -25,13 +26,14 @@ clean:
2526
make -C driver/ac97 clean
2627
make -C driver/ata clean
2728
make -C driver/ps2 clean
28-
make -C driver/ahci clean
2929

3030
make -C network/am79C973 clean
3131
make -C network/e1000 clean
3232
make -C network/ne2k clean
3333
make -C network/rtl8139 clean
3434

35+
make -C feature/acpi_dump clean
36+
3537
compile_flags.txt:
3638
make -C core compile_flags.txt
3739

@@ -41,9 +43,10 @@ compile_flags.txt:
4143
make -C driver/ac97 compile_flags.txt
4244
make -C driver/ata compile_flags.txt
4345
make -C driver/ps2 compile_flags.txt
44-
make -C driver/ahci compile_flags.txt
4546

4647
make -C network/am79C973 compile_flags.txt
4748
make -C network/e1000 compile_flags.txt
4849
make -C network/ne2k compile_flags.txt
49-
make -C network/rtl8139 compile_flags.txt
50+
make -C network/rtl8139 compile_flags.txt
51+
52+
make -C feature/acpi_dump compile_flags.txt

mckrnl/core/driver/acpi/rsdp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ void map_sdt(sdt_header_t* header) {
6767

6868
void* find_SDT(const char *signature) {
6969
if(xsdt != NULL) {
70-
for(uint64_t i = 0; i < (xsdt->header.length - sizeof(sdt_header_t)); i++) {
70+
int entries = (xsdt->header.length - sizeof(sdt_header_t)) / 8;
71+
for(uint64_t i = 0; i < entries; i++) {
7172
sdt_header_t* acpihdr = (sdt_header_t*) (uint32_t) xsdt->acpiptr[i];
7273
map_sdt(acpihdr);
7374
if(memcmp(acpihdr->signature, signature, 4) == 0) {
@@ -78,7 +79,8 @@ void* find_SDT(const char *signature) {
7879
}
7980

8081
if(rsdt != NULL) {
81-
for(uint64_t i = 0; i < (rsdt->header.length - sizeof(sdt_header_t)); i++) {
82+
int entries = (rsdt->header.length - sizeof(sdt_header_t)) / 4;
83+
for(uint64_t i = 0; i < entries; i++) {
8284
sdt_header_t* acpihdr = (sdt_header_t*) (rsdt->acpiptr[i]);
8385
map_sdt(acpihdr);
8486
if(memcmp(acpihdr->signature, signature, 4) == 0) {

mckrnl/core/include/driver/acpi/rsdp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ extern xsdt_t* xsdt;
2323

2424
rsdp2_t* scan_for_rsdp(char* start, uint32_t length);
2525
void rsdp_init();
26-
void* find_SDT(const char *signature);
26+
void* find_SDT(const char *signature);
27+
28+
void map_sdt(sdt_header_t* header);

mckrnl/core/module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ void initrd_load_modules(void* saf_image, char* path) {
264264
debugf("initrd: loading module %s (%d bytes)", child->name, file_node->size);
265265
module_t* module = load_object_file(module_data);
266266

267+
loaded_modules[loaded_module_count++] = module;
268+
267269
debugf("Loaded module %s", module->name);
268270

269271
if (module->init) {
270272
module->init();
271273
}
272274

273-
loaded_modules[loaded_module_count++] = module;
274275
}
275276
}
276277

mckrnl/feature/acpi_dump/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MODULE = acpi_dump.o
2+
include ../../module.mk
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include <acpi_vfs.h>
2+
#include <driver/disk_driver.h>
3+
#include <memory/vmm.h>
4+
#include <string.h>
5+
#include <assert.h>
6+
#include <stdio.h>
7+
8+
acpi_vfs_mount_data_t create_acpi_vfs_mount_data() {
9+
int entriesXSDT = xsdt ? (xsdt->header.length - sizeof(sdt_header_t)) / 8 : 0;
10+
int entriesRSDT = rsdt ? (rsdt->header.length - sizeof(sdt_header_t)) / 4 : 0;
11+
12+
acpi_vfs_mount_data_t mount_data;
13+
mount_data.table_count = entriesXSDT + entriesRSDT;
14+
mount_data.tables = (sdt_header_t**) vmm_alloc(sizeof(sdt_header_t*) * mount_data.table_count);
15+
16+
if(xsdt != NULL) {
17+
for(uint64_t i = 0; i < entriesXSDT; i++) {
18+
sdt_header_t* acpihdr = (sdt_header_t*) (uint32_t) xsdt->acpiptr[i];
19+
debugf("[XSDT] Found ACPI table: %c%c%c%c", acpihdr->signature[0], acpihdr->signature[1], acpihdr->signature[2], acpihdr->signature[3]);
20+
mount_data.tables[i] = acpihdr;
21+
}
22+
}
23+
24+
if(rsdt != NULL) {
25+
for(uint64_t i = 0; i < entriesRSDT; i++) {
26+
sdt_header_t* acpihdr = (sdt_header_t*) (rsdt->acpiptr[i]);
27+
debugf("[RSDT] Found ACPI table: %c%c%c%c", acpihdr->signature[0], acpihdr->signature[1], acpihdr->signature[2], acpihdr->signature[3]);
28+
mount_data.tables[entriesXSDT + i] = acpihdr;
29+
}
30+
}
31+
32+
return mount_data;
33+
}
34+
35+
char* acpi_vfs_name(vfs_mount_t* mount) {
36+
return "acpi";
37+
}
38+
39+
file_t* acpi_vfs_open(vfs_mount_t* mount, char* path, int flags) {
40+
acpi_vfs_mount_data_t* data = (acpi_vfs_mount_data_t*) mount->driver_specific_data;
41+
42+
char file[0xff] = { 0 };
43+
while (*(path = copy_until('/', path, file)));
44+
debugf("file: %s", file);
45+
46+
for (size_t i = 0; i < data->table_count; i++) {
47+
sdt_header_t* table = data->tables[i];
48+
char expected_name[0xff] = { 0 };
49+
sprintf(expected_name, "%d.%c%c%c%c", i, table->signature[0], table->signature[1], table->signature[2], table->signature[3]);
50+
51+
if (strcmp(file, expected_name) == 0) {
52+
file_t* file = (file_t*) vmm_alloc(1);
53+
memset(file, 0, sizeof(file_t));
54+
55+
file->mount = mount;
56+
file->size = table->length;
57+
file->driver_specific_data = table;
58+
59+
return file;
60+
}
61+
}
62+
63+
return NULL;
64+
}
65+
66+
void acpi_vfs_close(vfs_mount_t* mount, file_t* f) {
67+
vmm_free(f, 1);
68+
}
69+
70+
void acpi_vfs_read(vfs_mount_t* mount, file_t* f, void* buffer, size_t size, size_t offset) {
71+
if (offset + size > f->size) {
72+
abortf(true, "Attempted to read beyond end of ACPI table file");
73+
}
74+
memcpy(buffer, &((char*) f->driver_specific_data)[offset], size);
75+
}
76+
77+
78+
dir_t acpi_vfs_dir_at(vfs_mount_t* mount, int idx, char* path) {
79+
acpi_vfs_mount_data_t* mount_data = (acpi_vfs_mount_data_t*) mount->driver_specific_data;
80+
if(idx >= mount_data->table_count) {
81+
dir_t empty = {
82+
.is_none = true
83+
};
84+
return empty;
85+
}
86+
87+
sdt_header_t* table = mount_data->tables[idx];
88+
dir_t entry = {
89+
.idx = idx,
90+
.is_none = false,
91+
.type = ENTRY_FILE
92+
};
93+
sprintf(entry.name, "%d.%c%c%c%c", idx, table->signature[0], table->signature[1], table->signature[2], table->signature[3]);
94+
95+
return entry;
96+
}
97+
98+
vfs_mount_t* acpi_vfs_mount() {
99+
vfs_mount_t* mount = (vfs_mount_t*) vmm_alloc(1);
100+
memset(mount, 0, 0x1000);
101+
102+
assert((sizeof(vfs_mount_t) + sizeof(acpi_vfs_mount_data_t)) <= 0x1000);
103+
104+
acpi_vfs_mount_data_t* mount_data = (acpi_vfs_mount_data_t*) &mount[1];
105+
mount->driver_specific_data = mount_data;
106+
107+
*mount_data = create_acpi_vfs_mount_data();
108+
109+
mount->name = acpi_vfs_name;
110+
mount->open = acpi_vfs_open;
111+
mount->close = acpi_vfs_close;
112+
mount->read = acpi_vfs_read;
113+
mount->dir_at = acpi_vfs_dir_at;
114+
115+
return mount;
116+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <fs/vfs.h>
4+
#include <driver/acpi/rsdp.h>
5+
6+
typedef struct {
7+
sdt_header_t** tables;
8+
size_t table_count;
9+
} acpi_vfs_mount_data_t;
10+
11+
vfs_mount_t* acpi_vfs_mount();

mckrnl/feature/acpi_dump/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <module.h>
2+
#include <stddef.h>
3+
#include <acpi_vfs.h>
4+
5+
#include <driver/acpi/rsdp.h>
6+
#include <stdio.h>
7+
8+
void main() {
9+
}
10+
11+
void stage_mount() {
12+
vfs_mount(acpi_vfs_mount());
13+
}
14+
15+
define_module("acpi_dump", main, NULL, stage_mount);

user/cp/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdlib.h>
33
#include <stdint.h>
44
#include <string.h>
5+
#include <assert.h>
56
#include <sys/file.h>
67

78
void copy_file(char* src_dir, char* dest_dir, char* file_name, bool verbose) {
@@ -99,17 +100,17 @@ int main(int argc, char** argv) {
99100
}
100101
}
101102

102-
char real_dest[512] = { 0 };
103-
resolve(dest, real_dest);
104-
105-
char real_src[512] = { 0 };
106-
resolve(src, real_src);
107-
108103
if (src == NULL || dest == NULL) {
109104
printf("Usage: cp [-r][-v] <src> <dest>\n");
110105
return 1;
111106
}
112107

108+
char real_dest[512] = { 0 };
109+
assert(resolve(dest, real_dest));
110+
111+
char real_src[512] = { 0 };
112+
assert(resolve(src, real_src));
113+
113114
if (recursive) {
114115
recursive_dir_copy(real_src, real_dest, verbose);
115116
} else {

0 commit comments

Comments
 (0)