57 lines
2.1 KiB
C
57 lines
2.1 KiB
C
/* Calcite, src/kernel/utility.h
|
|
* Copyright 2025-2026 Benji Dial
|
|
*
|
|
* This program 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.
|
|
*
|
|
* This program 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/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
//returns 1 if equal, 0 if not.
|
|
int strequ(const char *str1, const char *str2);
|
|
|
|
void memcpy(void *to, const void *from, uint64_t bytes);
|
|
void memzero(void *start, uint64_t bytes);
|
|
|
|
//swaps the endianness of the value
|
|
uint32_t end_swap_u32(uint32_t value);
|
|
|
|
//1. allocates a new buffer with 2 * length * bytes_per_entry bytes
|
|
//2. copies length * bytes_per_entry bytes from old buffer to new buffer
|
|
//3. deallocates old buffer
|
|
//4. zeroes rest of new buffer
|
|
//5. sets buffer and length to new buffer and twice length
|
|
void double_buffer_zero(void **buffer, int *length, uint64_t bytes_per_entry);
|
|
|
|
void outb(uint16_t port, uint8_t byte);
|
|
uint8_t inb(uint16_t port);
|
|
void outsw(uint16_t port, const void *buffer, uint64_t words);
|
|
void insw(uint16_t port, void *buffer, uint64_t words);
|
|
|
|
struct handle_list {
|
|
uint64_t entry_size;
|
|
void *buffer;
|
|
uint8_t *buffer_used_bitmap;
|
|
//in entries, always a multiple of 8
|
|
uint64_t buffer_size;
|
|
};
|
|
|
|
void create_handle_list(struct handle_list *list, uint64_t entry_size);
|
|
//add to list by calling this and writing into returned object
|
|
void *add_handle(struct handle_list *list, uint64_t *handle_out);
|
|
//zero if not in list
|
|
void *look_up_handle(struct handle_list *list, uint64_t handle);
|
|
void for_each_handle(struct handle_list *list, void (*callback)(void *object));
|
|
void destroy_handle_list(struct handle_list *list);
|