diff options
author | Benji Dial <Benji3.141@gmail.com> | 2020-08-11 11:33:21 -0400 |
---|---|---|
committer | Benji Dial <Benji3.141@gmail.com> | 2020-08-11 11:33:21 -0400 |
commit | 63167f223e1f54910f6b80e698390ee60aec79ee (patch) | |
tree | 41844f646bdcb5c9ba241bb5867c5e4f51737d52 /src/kernel/util.c | |
parent | 77d7a284c02bc6b1b3a3a92ad5d957172cee9b81 (diff) | |
download | portland-os-63167f223e1f54910f6b80e698390ee60aec79ee.tar.gz |
lots of progress
currently, BAR fields of IDE drives are all returning zero, and the ATA read function isn't working. i'm not sure why.
i'm going to work on VESA next, and come back to the IDE driver later
Diffstat (limited to 'src/kernel/util.c')
-rw-r--r-- | src/kernel/util.c | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/src/kernel/util.c b/src/kernel/util.c index c7a5035..1531f83 100644 --- a/src/kernel/util.c +++ b/src/kernel/util.c @@ -1,6 +1,7 @@ #include <stdint.h> #include "panic.h" #include <stdbool.h> +#include "drive.h" void memcpy(void *to, void *from, uint32_t n) { uint32_t *tp = to, *fp = from; @@ -13,9 +14,36 @@ void memcpy(void *to, void *from, uint32_t n) { *(tpp++) = *(fpp++); } -void u32_dec(uint32_t n, uint8_t *b) { +void fmcpy(void *to, struct drive *d, drive_file_id_t f, uint32_t from, uint32_t n) { + uint8_t buf[512]; + d->load_sector(d, f, from >> 9, buf); + uint16_t from_low = from & 511; + if (!((from_low + n) & ~511)) { + memcpy(to, buf + from_low, n); + return; + } + + uint32_t i = 512 - from_low; + memcpy(to, buf + from_low, i); + + n -= i; + uint32_t fsi = (from + i) >> 9; + + while (n & ~511) { + d->load_sector(d, f, fsi, buf); + memcpy(to + i, buf, 512); + i += 512; + n -= 512; + ++fsi; + } + + d->load_sector(d, f, fsi, buf); + memcpy(to + i, buf, n); +} + +void u32_dec(uint32_t n, char *b) { if (!n) { - *(uint16_t *)b = '0'; + *(uint16_t *)b = (uint16_t)'0'; return; } bool zero = false; @@ -28,12 +56,12 @@ void u32_dec(uint32_t n, uint8_t *b) { *(b++) = d + '0'; } } - *b = 0; + *b = '\0'; } -void u16_dec(uint16_t n, uint8_t *b) { +void u16_dec(uint16_t n, char *b) { if (!n) { - *(uint16_t *)b = '0'; + *(uint16_t *)b = (uint16_t)'0'; return; } bool zero = false; @@ -46,12 +74,12 @@ void u16_dec(uint16_t n, uint8_t *b) { *(b++) = d + '0'; } } - *b = 0; + *b = '\0'; } -void u8_dec(uint8_t n, uint8_t *b) { +void u8_dec(uint8_t n, char *b) { if (!n) { - *(uint16_t *)b = '0'; + *(uint16_t *)b = (uint16_t)'0'; return; } bool zero = false; @@ -64,42 +92,42 @@ void u8_dec(uint8_t n, uint8_t *b) { *(b++) = d + '0'; } } - *b = 0; + *b = '\0'; } -void u32_hex(uint32_t n, uint8_t *b) { +void u32_hex(uint32_t n, char *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; + *b = '\0'; return; } m -= 4; } } -void u16_hex(uint16_t n, uint8_t *b) { +void u16_hex(uint16_t n, char *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; + *b = '\0'; return; } m -= 4; } } -void u8_hex(uint8_t n, uint8_t *b) { +void u8_hex(uint8_t n, char *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; + *b = '\0'; return; } m -= 4; |