summaryrefslogtreecommitdiff
path: root/src/kernel/util.c
diff options
context:
space:
mode:
authorBenji Dial <benji3.141@gmail.com>2020-05-24 11:02:43 -0400
committerBenji Dial <benji3.141@gmail.com>2020-05-24 11:02:43 -0400
commit02f14113cbf14c6f842fb43ecbc68d0c851ef3b0 (patch)
tree75d2d943d9822b3f945fd947e9b91eec1d68e900 /src/kernel/util.c
parent31d8ae388a7ded576abd3e3d99c3d9193ea6d704 (diff)
downloadportland-os-02f14113cbf14c6f842fb43ecbc68d0c851ef3b0.tar.gz
very basic vga, ata, serial drivers. start of fat and fs drivers
Diffstat (limited to 'src/kernel/util.c')
-rw-r--r--src/kernel/util.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/kernel/util.c b/src/kernel/util.c
new file mode 100644
index 0000000..df6e7d8
--- /dev/null
+++ b/src/kernel/util.c
@@ -0,0 +1,100 @@
+#include <stdint.h>
+#include "panic.h"
+#include <stdbool.h>
+
+void memcpy(void *from, void *to, uint32_t n) {
+ panic("Not implemented (memcpy).");
+}
+
+void u32_dec(uint32_t n, uint8_t *b) {
+ if (!n) {
+ *(uint16_t *)b = '0';
+ return;
+ }
+ bool zero = false;
+ for (uint32_t m = 1000000000; m; m /= 10) {
+ uint8_t d = (n / m) % 10;
+ if (zero)
+ *(b++) = d + '0';
+ else if (d) {
+ zero = true;
+ *(b++) = d + '0';
+ }
+ }
+ *b = 0;
+}
+
+void u16_dec(uint16_t n, uint8_t *b) {
+ if (!n) {
+ *(uint16_t *)b = '0';
+ return;
+ }
+ bool zero = false;
+ for (uint32_t m = 10000; m; m /= 10) {
+ uint8_t d = (n / m) % 10;
+ if (zero)
+ *(b++) = d + '0';
+ else if (d) {
+ zero = true;
+ *(b++) = d + '0';
+ }
+ }
+ *b = 0;
+}
+
+void u8_dec(uint8_t n, uint8_t *b) {
+ if (!n) {
+ *(uint16_t *)b = '0';
+ return;
+ }
+ bool zero = false;
+ for (uint32_t m = 100; m; m /= 10) {
+ uint8_t d = (n / m) % 10;
+ if (zero)
+ *(b++) = d + '0';
+ else if (d) {
+ zero = true;
+ *(b++) = d + '0';
+ }
+ }
+ *b = 0;
+}
+
+void u32_hex(uint32_t n, uint8_t *b) {
+ uint8_t m = 28;
+ while (1) {
+ uint8_t d = (n >> m) & 0xf;
+ *(b++) = d >= 10 ? 'a' + d - 10 : '0' + d;
+ if (!m) {
+ *b = 0;
+ return;
+ }
+ m -= 4;
+ }
+}
+
+void u16_hex(uint16_t n, uint8_t *b) {
+ uint8_t m = 12;
+ while (1) {
+ uint8_t d = (n >> m) & 0xf;
+ *(b++) = d >= 10 ? 'a' + d - 10 : '0' + d;
+ if (!m) {
+ *b = 0;
+ return;
+ }
+ m -= 4;
+ }
+}
+
+void u8_hex(uint8_t n, uint8_t *b) {
+ uint8_t m = 4;
+ while (1) {
+ uint8_t d = (n >> m) & 0xf;
+ *(b++) = d >= 10 ? 'a' + d - 10 : '0' + d;
+ if (!m) {
+ *b = 0;
+ return;
+ }
+ m -= 4;
+ }
+} \ No newline at end of file