Skip to content

Commit 82c72a3

Browse files
Some better readability changes
1 parent f311137 commit 82c72a3

17 files changed

+173
-146
lines changed

source/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $(eval $(call DEFAULT_VAR,LDFLAGS,$(DEFAULT_LDFLAGS)))
5454

5555
# Internal C flags that should not be changed by the user.
5656
override CFLAGS += \
57-
-Wall \
57+
-w \
5858
-std=gnu11 \
5959
-ffreestanding \
6060
-fno-stack-protector \
@@ -163,23 +163,27 @@ all: ./kernel/typescript/compile.sh $(KERNEL)
163163
$(KERNEL): linker/$(ARCH).ld $(OBJ)
164164
@mkdir -p "$$(dirname $@)"
165165
@$(LD) $(OBJ) $(LDFLAGS) -o $@
166+
@echo "\033[1;32mLinking using\033[0m $<"
166167

167168
# Include header dependencies.
168169
-include $(HEADER_DEPS)
169170

170171
# Compilation rules for *.c files.
171172
obj/%.c.o: %.c includes/limine.h
172173
@mkdir -p "$$(dirname $@)"
174+
@echo "\033[1;34mCompiling\033[0m $<"
173175
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
174176

175177
# Compilation rules for *.S files.
176178
obj/%.S.o: %.S
177179
@mkdir -p "$$(dirname $@)"
180+
@echo "\033[1;34mAssembling\033[0m $<"
178181
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
179182

180183
# Compilation rules for *.asm (nasm) files.
181184
obj/%.asm.o: %.asm
182185
@mkdir -p "$$(dirname $@)"
186+
@echo "\033[1;34mAssembling\033[0m $<"
183187
@nasm $(NASMFLAGS) $< -o $@
184188

185189
# Remove object files

source/includes/acpi-shutdown.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313

1414
#include <stddef.h>
1515
#include <stdint.h>
16+
#include <basics.h>
1617

1718
int acpi_shutdown_hack(
1819
uintptr_t direct_map_base,
19-
void *(*find_sdt)(const char *signature, size_t index),
20-
uint8_t (*inb)(uint16_t port),
21-
uint16_t (*inw)(uint16_t port),
22-
void (*outb)(uint16_t port, uint8_t value),
23-
void (*outw)(uint16_t port, uint16_t value)
20+
void *(*find_sdt)(cstring signature, size_t index),
21+
int8 (*inb)(int16 port),
22+
int16 (*inw)(int16 port),
23+
void (*outb)(int16 port, int8 value),
24+
void (*outw)(int16 port, int16 value)
2425
);
2526
#endif

source/includes/basics.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdint.h>
2+
#include <stddef.h>
3+
4+
typedef uint64_t int64;
5+
typedef uint32_t int32;
6+
typedef uint16_t int16;
7+
typedef uint8_t int8;
8+
9+
#define null NULL
10+
11+
typedef const char* cstring;
12+
typedef char* string;

source/includes/debugger.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#include <stdint.h>
1212
#include <stddef.h>
13+
#include <basics.h>
1314
#include <hal.h>
1415

1516
/**
@@ -32,4 +33,4 @@ void debug_putc(char c);
3233
*
3334
* @param msg
3435
*/
35-
void debug_print(const char * msg);
36+
void debug_print(cstring msg);

source/includes/graphics.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
#include <stddef.h>
1616
#include <stdarg.h>
1717
#include <stdbool.h>
18+
#include <basics.h>
1819

1920
// ANSI color codes for text formatting
20-
#define ANSI_COLOR_RESET "\x1b[0m"
21-
#define ANSI_COLOR_RED "\x1b[91m"
22-
#define ANSI_COLOR_YELLOW "\x1b[93m"
23-
#define ANSI_COLOR_BLUE "\x1b[36m"
24-
#define ANSI_COLOR_GREEN "\x1b[32m"
21+
#define reset_color "\x1b[0m"
22+
#define red_color "\x1b[91m"
23+
#define yellow_color "\x1b[93m"
24+
#define blue_color "\x1b[36m"
25+
#define green_color "\x1b[32m"
2526

2627
/**
2728
* @brief Display a warning message.
@@ -31,7 +32,7 @@
3132
* @param message The warning message to be displayed.
3233
* @param file The file name where the warning occurred.
3334
*/
34-
void warn(const char *message, const char* file);
35+
void warn(cstring message, cstring file);
3536

3637
/**
3738
* @brief Display an error message.
@@ -41,7 +42,7 @@ void warn(const char *message, const char* file);
4142
* @param message The error message to be displayed.
4243
* @param file The file name where the error occurred.
4344
*/
44-
void error(const char *message, const char* file);
45+
void error(cstring message, cstring file);
4546

4647
/**
4748
* @brief Display an informational message.
@@ -51,7 +52,7 @@ void error(const char *message, const char* file);
5152
* @param message The informational message to be displayed.
5253
* @param file The file name where the information is coming from.
5354
*/
54-
void info(const char *message, const char* file);
55+
void info(cstring message, cstring file);
5556

5657
/**
5758
* @brief Display a success message.
@@ -61,7 +62,7 @@ void info(const char *message, const char* file);
6162
* @param message The success message to be displayed.
6263
* @param file The file name associated with the success.
6364
*/
64-
void done(const char *message, const char* file);
65+
void done(cstring message, cstring file);
6566

6667
/* Normal Hybrid printing functions ahead */
6768

@@ -93,6 +94,6 @@ void printhex(int hex);
9394
* @param format
9495
* @param ...
9596
*/
96-
void printf(const char *format, ...);
97+
void printf(cstring format, ...);
9798

9899
#endif

source/includes/hal.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <stdint.h>
13+
#include <basics.h>
1314

1415
/**
1516
* @brief Output a byte to the specified I/O port.
@@ -19,7 +20,7 @@
1920
* @param port The 16-bit I/O port number.
2021
* @param value The 8-bit value to be sent to the port.
2122
*/
22-
void outb(uint16_t port, uint8_t value);
23+
void outb(int16 port, int8 value);
2324

2425
/**
2526
* @brief Read a byte from the specified I/O port.
@@ -29,7 +30,7 @@ void outb(uint16_t port, uint8_t value);
2930
* @param port The 16-bit I/O port number.
3031
* @return The 8-bit value read from the port.
3132
*/
32-
uint8_t inb(uint16_t port);
33+
int8 inb(int16 port);
3334

3435
/**
3536
* @brief Output a 16-bit value to the specified I/O port.
@@ -39,7 +40,7 @@ uint8_t inb(uint16_t port);
3940
* @param portNumber The 16-bit I/O port number.
4041
* @param data The 16-bit value to be sent to the port.
4142
*/
42-
void outw(uint16_t portNumber, uint16_t data);
43+
void outw(int16 portNumber, int16 data);
4344

4445
/**
4546
* @brief Read a 16-bit value from the specified I/O port.
@@ -49,7 +50,7 @@ void outw(uint16_t portNumber, uint16_t data);
4950
* @param portNumber The 16-bit I/O port number.
5051
* @return The 16-bit value read from the port.
5152
*/
52-
uint16_t inw(uint16_t portNumber);
53+
int16 inw(int16 portNumber);
5354

5455
/**
5556
* @brief Read a 32-bit value from the specified I/O port.
@@ -59,7 +60,7 @@ uint16_t inw(uint16_t portNumber);
5960
* @param portNumber The 16-bit I/O port number.
6061
* @return The 32-bit value read from the port.
6162
*/
62-
uint32_t inl(uint16_t portNumber);
63+
int32 inl(int16 portNumber);
6364

6465
/**
6566
* @brief Output a 32-bit value to the specified I/O port.
@@ -69,7 +70,7 @@ uint32_t inl(uint16_t portNumber);
6970
* @param portNumber The 16-bit I/O port number.
7071
* @param data The 32-bit value to be sent to the port.
7172
*/
72-
void outl(uint16_t portNumber, uint32_t data);
73+
void outl(int16 portNumber, int32 data);
7374

7475
/**
7576
* @brief Perform an I/O wait operation.

source/includes/kernel.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
#include <typescript-loader.h>
2828
#include <debugger.h>
2929
#include <drivers/serial.h>
30+
#include <basics.h>
3031

3132
/**
3233
* @brief The memory address pointer where the kernel ends.
3334
*
3435
*/
35-
extern uint64_t* kend;
36+
extern int64* kend;
3637

3738
/**
3839
* @brief Halt and catch fire function.
@@ -69,10 +70,10 @@ extern int terminal_columns;
6970
* @brief The fake or pseudo frame buffer in the memory which will be queued for next frame update
7071
*
7172
*/
72-
extern uint64_t* back_buffer;
73+
extern int64* back_buffer;
7374

7475
/**
7576
* @brief Direct pointer to framebuffer->address. It doesn't queue, directly writes to the memory
7677
*
7778
*/
78-
extern uint64_t* front_buffer;
79+
extern int64* front_buffer;

source/includes/pci.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,50 @@
1212
#include <hal.h>
1313
#include <graphics.h>
1414

15-
extern const char* display_adapter_name;
16-
extern const char* GPUName[1]; //Max 2 GPUs allowed
15+
extern cstring display_adapter_name;
16+
extern cstring GPUName[1]; //Max 2 GPUs allowed
1717

18-
uint16_t pci_read_word(uint16_t bus, uint16_t slot, uint16_t func, uint16_t offset);
18+
int16 pci_read_word(int16 bus, int16 slot, int16 func, int16 offset);
1919

2020
/**
2121
* @brief Gets the Vendor ID from PCI
2222
*
2323
* @param bus
2424
* @param device
2525
* @param function
26-
* @return uint16_t Vendor ID
26+
* @return int16 Vendor ID
2727
*/
28-
uint16_t getVendorID(uint16_t bus, uint16_t device, uint16_t function);
28+
int16 getVendorID(int16 bus, int16 device, int16 function);
2929

3030
/**
3131
* @brief Gets the Device ID from PCI
3232
*
3333
* @param bus
3434
* @param device
3535
* @param function
36-
* @return uint16_t Device ID
36+
* @return int16 Device ID
3737
*/
38-
uint16_t getDeviceID(uint16_t bus, uint16_t device, uint16_t function);
38+
int16 getDeviceID(int16 bus, int16 device, int16 function);
3939

4040
/**
4141
* @brief Gets the Class ID from PCI
4242
*
4343
* @param bus
4444
* @param device
4545
* @param function
46-
* @return uint16_t Class ID
46+
* @return int16 Class ID
4747
*/
48-
uint16_t getClassId(uint16_t bus, uint16_t device, uint16_t function);
48+
int16 getClassId(int16 bus, int16 device, int16 function);
4949

5050
/**
5151
* @brief Gets the Sub-class ID from PCI
5252
*
5353
* @param bus
5454
* @param device
5555
* @param function
56-
* @return uint16_t Sub-class ID
56+
* @return int16 Sub-class ID
5757
*/
58-
uint16_t getSubClassId(uint16_t bus, uint16_t device, uint16_t function);
58+
int16 getSubClassId(int16 bus, int16 device, int16 function);
5959

6060
/**
6161
* @brief Scans (Probes) PCI Devices

source/includes/strings.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#include <stdint.h>
1212
#include <stddef.h>
1313
#include <stdbool.h>
14+
#include <basics.h>
1415

15-
typedef char symbol[];
16+
// typedef char symbol[];
1617

1718
/**
1819
* @brief Calculate the length of a null-terminated string.
@@ -32,7 +33,7 @@ int strlen_(char s[]);
3233
* @param src Source string
3334
* @returns The resulting copy of the string `src`
3435
*/
35-
char *strcpy(char *dest, const char *src);
36+
string strcpy(string dest, cstring src);
3637

3738
/**
3839
* @brief Copies `n` characters from `src` to `dest`
@@ -42,7 +43,7 @@ char *strcpy(char *dest, const char *src);
4243
* @param n Number of characters that will be copies
4344
* @returns The resulting copy of the string `src`
4445
*/
45-
char *strncpy(char *dest, const char *src, size_t n);
46+
string strncpy(string dest, cstring src, size_t n);
4647

4748
/**
4849
* @brief Compares two strings lexicographically.
@@ -56,7 +57,7 @@ char *strncpy(char *dest, const char *src, size_t n);
5657
* @returns An integer less than, equal to, or greater than zero, depending on the
5758
* comparison result.
5859
*/
59-
int strcmp(const char *s1, const char *s2);
60+
int strcmp(cstring s1, cstring s2);
6061

6162
/**
6263
* @brief Compares two strings, up to a specified number of characters.
@@ -71,7 +72,7 @@ int strcmp(const char *s1, const char *s2);
7172
* @return An integer less than, equal to, or greater than zero, depending on the
7273
* comparison result.
7374
*/
74-
int strncmp(const char *s1, const char *s2, size_t n);
75+
int strncmp(cstring s1, cstring s2, size_t n);
7576

7677
/**
7778
* @brief Check if a substring is found within a string.
@@ -82,4 +83,4 @@ int strncmp(const char *s1, const char *s2, size_t n);
8283
* @param substr The substring to search for.
8384
* @return true if the substring is found in the string, false otherwise.
8485
*/
85-
bool contains(const char *str, const char *substr);
86+
bool contains(cstring str, cstring substr);

source/includes/unifont.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
*
1010
*/
1111
#include <stdint.h>
12+
#include <basics.h>
1213

1314
#define UNIFONT_WIDTH 8
1415
#define UNIFONT_HEIGHT 16
1516

16-
static const uint8_t unifont[] = {
17+
static const int8 unifont[] = {
1718
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1819
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x81, 0xa5, 0x81, 0xa5, 0x99, 0x42, 0x3c, 0x00, 0x00, 0x00,
1920
0x00, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0xff, 0xdb, 0xff, 0xdb, 0xe7, 0x7e, 0x3c, 0x00, 0x00, 0x00,

0 commit comments

Comments
 (0)