implemented a few utils
This commit is contained in:
parent
15b6f7ee43
commit
8d3d090772
|
@ -0,0 +1,22 @@
|
|||
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
|
||||
*
|
||||
* NyxOS is free software:
|
||||
* you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* NyxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NYXOS_MATH_H
|
||||
#define NYXOS_MATH_H
|
||||
|
||||
#define max(a, b) (a > b ? a : b)
|
||||
#define min(a, b) (a > b ? b : a)
|
||||
|
||||
#endif //NYXOS_MATH_H
|
|
@ -0,0 +1,25 @@
|
|||
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
|
||||
*
|
||||
* NyxOS is free software:
|
||||
* you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* NyxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NYXOS_MEMORY_H
|
||||
#define NYXOS_MEMORY_H
|
||||
|
||||
#include "stdtypes.h"
|
||||
|
||||
void memory_copy (void* source, void* destination, uint32_t num);
|
||||
void memory_set (void* destination, uint8_t data, uint32_t num);
|
||||
bool memory_compare (void* a, void* b, uint32_t num);
|
||||
|
||||
#endif //NYXOS_MEMORY_H
|
|
@ -0,0 +1,26 @@
|
|||
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
|
||||
*
|
||||
* NyxOS is free software:
|
||||
* you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* NyxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NYXOS_STRING_H
|
||||
#define NYXOS_STRING_H
|
||||
|
||||
#include "stdtypes.h"
|
||||
|
||||
typedef const char* string_t;
|
||||
|
||||
uint32_t string_length (string_t str);
|
||||
bool string_compare(string_t a, string_t b);
|
||||
|
||||
#endif //NYXOS_STRING_H
|
|
@ -29,7 +29,7 @@ void _start() {
|
|||
|
||||
struct limine_terminal* terminal = terminal_request.response->terminals[0];
|
||||
|
||||
terminal_request.response->write(terminal, "Hello Limine", 12);
|
||||
terminal_request.response->write(terminal, "Booting NyxOS", 13);
|
||||
|
||||
while(true) asm("hlt");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
|
||||
*
|
||||
* NyxOS is free software:
|
||||
* you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* NyxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "utils/memory.h"
|
||||
|
||||
void memory_copy (void* source, void* destination, uint32_t num) {
|
||||
uint8_t* src_8 = (uint8_t*)source;
|
||||
uint8_t* dst_8 = (uint8_t*)destination;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
dst_8[i] = src_8[i];
|
||||
}
|
||||
}
|
||||
|
||||
void memory_set (void* destination, uint8_t data, uint32_t num) {
|
||||
uint8_t* dst_8 = (uint8_t*)destination;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
dst_8[i] = data;
|
||||
}
|
||||
}
|
||||
|
||||
bool memory_compare (void* a, void* b, uint32_t num) {
|
||||
uint8_t* a_8 = (uint8_t*)a;
|
||||
uint8_t* b_8 = (uint8_t*)b;
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (a_8[i] != b_8[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
|
||||
*
|
||||
* NyxOS is free software:
|
||||
* you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* NyxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "utils/string.h"
|
||||
#include "utils/memory.h"
|
||||
|
||||
uint32_t string_length (string_t str) {
|
||||
uint32_t n = 0;
|
||||
char* c = (char*)str;
|
||||
|
||||
while(*c != '\0') {
|
||||
c++;
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
bool string_compare(string_t a, string_t b) {
|
||||
uint32_t a_len = string_length(a);
|
||||
|
||||
if (a_len != string_length(b)) {
|
||||
return false;
|
||||
}
|
||||
return memory_compare(a, b, a_len);
|
||||
}
|
Loading…
Reference in New Issue