From a3c98baf0ba1a88d3f1d3be30170a573b0ae21f2 Mon Sep 17 00:00:00 2001
From: Paolo Fabio Zaino
Date: Mon, 20 Nov 2023 18:32:19 +0000
Subject: [PATCH] Pushing in more work done from last night
---
MkDDE,fd7 | 2 ++
src/dtblib/MakefileDDE | 10 ++++++++--
src/dtblib/c/strlib | 8 ++++++++
src/dtblib/h/strlib | 1 +
tests/001BasicDTBParse/MakefileDDE | 4 ++++
tests/001BasicDTBParse/c/main | 20 +++++++++++++++-----
tests/001BasicDTBParse/h/main | 10 ++++++++++
7 files changed, 48 insertions(+), 7 deletions(-)
create mode 100644 tests/001BasicDTBParse/h/main
diff --git a/MkDDE,fd7 b/MkDDE,fd7
index d2097ff..919be0a 100644
--- a/MkDDE,fd7
+++ b/MkDDE,fd7
@@ -26,6 +26,8 @@ IfThere @.!LibDTB.h Then Else CDir @.!LibDTB.h
IFthere @.src.dtblib.o.dtblib Then copy @.src.dtblib.o.dtblib @.!LibDTB.o.dtblib ~C N
IFthere @.src.dtblib.o.dtblibzm Then copy @.src.dtblib.o.dtblibzm @.!LibDTB.o.dtblibzm ~C N
IFthere @.src.dtblib.h.dtb Then copy @.src.dtblib.h.dtb @.!LibDTB.h.dtblib ~C N
+IFthere @.src.dtblib.h.krnllib Then copy @.src.dtblib.h.krnllib @.!LibDTB.h.krnllib ~C N
+IFthere @.src.dtblib.h.strlib Then copy @.src.dtblib.h.strlib @.!LibDTB.h.strlib ~C N
echo
echo ---------------------
diff --git a/src/dtblib/MakefileDDE b/src/dtblib/MakefileDDE
index 77e0f8a..30dc335 100644
--- a/src/dtblib/MakefileDDE
+++ b/src/dtblib/MakefileDDE
@@ -9,13 +9,19 @@ LIBS =
# Dynamic dependencies:
+oz.krnllib: c.krnllib
+oz.krnllib: h.krnllib
+o.krnllib: c.krnllib
+o.krnllib: h.krnllib
+oz.strlib: c.strlib
+oz.strlib: h.krnllib
+oz.strlib: h.strlib
+oz.strlib: h.krnllib
oz.dtb: c.dtb
oz.dtb: h.krnllib
oz.dtb: h.strlib
oz.dtb: h.krnllib
oz.dtb: h.dtb
-o.krnllib: c.krnllib
-o.krnllib: h.krnllib
o.strlib: c.strlib
o.strlib: h.krnllib
o.strlib: h.strlib
diff --git a/src/dtblib/c/strlib b/src/dtblib/c/strlib
index 9d7577b..41106d6 100644
--- a/src/dtblib/c/strlib
+++ b/src/dtblib/c/strlib
@@ -63,6 +63,14 @@ size_t str_len(const char* str) {
return length;
}
+int str_cmp(const char* str1, const char* str2) {
+ while (*str1 && (*str1 == *str2)) {
+ str1++;
+ str2++;
+ }
+ return *(const unsigned char*)str1 - *(const unsigned char*)str2;
+}
+
char* str_read(const char* data, int offset) {
int length = 0;
// Calculate the length of the string
diff --git a/src/dtblib/h/strlib b/src/dtblib/h/strlib
index ba2952f..c4cdc6d 100644
--- a/src/dtblib/h/strlib
+++ b/src/dtblib/h/strlib
@@ -58,6 +58,7 @@
#include "krnllib.h"
size_t str_len(const char* str);
+int str_cmp(const char* str1, const char* str2);
char* str_read(const char* data, int offset);
#endif /* STRLIB_H_ */
diff --git a/tests/001BasicDTBParse/MakefileDDE b/tests/001BasicDTBParse/MakefileDDE
index b2b2fb9..72b0c5b 100644
--- a/tests/001BasicDTBParse/MakefileDDE
+++ b/tests/001BasicDTBParse/MakefileDDE
@@ -10,4 +10,8 @@ LDFLAGS = -util
# Dynamic dependencies:
o.main: c.main
+o.main: LibDTB:h.krnllib
+o.main: LibDTB:h.strlib
+o.main: LibDTB:h.krnllib
o.main: LibDTB:h.dtblib
+o.main: h.main
diff --git a/tests/001BasicDTBParse/c/main b/tests/001BasicDTBParse/c/main
index c37249b..cbd627b 100644
--- a/tests/001BasicDTBParse/c/main
+++ b/tests/001BasicDTBParse/c/main
@@ -3,19 +3,29 @@
#include
+#include "LibDTB:krnllib.h"
+#include "LibDTB:strlib.h"
#include "LibDTB:dtblib.h"
+#include "main.h"
-void test_simple_dtb() {
+const char* load_dtb(const char* filename) {
+ // Function to load a DTB file
+ (void)filename;
+ return NULL;
+}
+
+void test_simple_dtb(void) {
const char* simple_dtb = load_dtb("simple.dtb"); // Function to load a DTB file
- struct dt_node* root = parse_dtb(simple_dtb);
+ char *string_block = (char *)krnl_malloc(1024);
+ struct dt_node* root = parse_dtb(simple_dtb, string_block, 0);
assert(root != NULL); // Replace with your own assert function
- assert(strcmp(root->name, "root_node_name") == 0);
+ assert(str_cmp(root->name, "root_node_name") == 0);
// Further checks for children, properties, etc.
- free_tree(root); // Clean up
- free_dtb(simple_dtb); // Function to free DTB data
+ krnl_free((void *)root); // Clean up
+ krnl_free((void *)simple_dtb); // Function to free DTB data
}
int main() {
diff --git a/tests/001BasicDTBParse/h/main b/tests/001BasicDTBParse/h/main
new file mode 100644
index 0000000..fef9375
--- /dev/null
+++ b/tests/001BasicDTBParse/h/main
@@ -0,0 +1,10 @@
+/*
+*/
+
+#ifndef MAIN_H_
+#define MAIN_H_
+
+const char* load_dtb(const char* filename);
+void test_simple_dtb(void);
+
+#endif /* MAIN_H_ */