Skip to content

Commit 3a8984c

Browse files
Cleaned up a lot of printing code, renamed original print to kprint.
1 parent 077d874 commit 3a8984c

File tree

6 files changed

+189
-205
lines changed

6 files changed

+189
-205
lines changed

source/includes/graphics.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,35 @@ void done(cstring message, cstring file);
8787
/* Normal Hybrid printing functions ahead */
8888

8989
/**
90-
* @brief Prints a char, using print(&c);
90+
* @brief Prints a char, using vput(char c); Replaces '\b' with "\b \b"
9191
*
9292
* @param c char to print
9393
*/
9494
void putc(char c);
9595

96+
/**
97+
* @brief Prints a char though the standard streams.
98+
*
99+
* @param c The charecter to be printed.
100+
*/
101+
void vputc(char c);
102+
96103
/**
97104
* @brief Prints a value in binary format
98105
*
99106
* @param value The value that will be printed
100107
*/
101108
void printbin(uint8_t value);
102109

110+
int format_number(
111+
char *out,
112+
long value,
113+
int base,
114+
int width,
115+
bool zero,
116+
bool upper
117+
);
118+
103119
/**
104120
* @brief Prints with formatting supported.
105121
*
@@ -163,21 +179,19 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
163179
*/
164180
int snprintf(char *buf, size_t size, const char *fmt, ...);
165181

166-
167182
/**
168-
* @brief Prints a char, using print(&c);
183+
* @brief RAW kernel print function for plain strings. (No Formatter & No Streams)
169184
*
170-
* @param c char to print
171-
* @note Internally using Flanterm's putchar function
185+
* @param msg The string.
172186
*/
173-
void vputc(char c);
187+
void kprint(cstring msg);
174188

175189
/**
176-
* @brief Print function for plain strings. (No Formatter)
190+
* @brief Plain print function, goes through the stream.
177191
*
178-
* @param msg The string.
192+
* @param s Normal string to be displayed
179193
*/
180-
void print(cstring msg);
194+
void print(cstring s);
181195

182196
/**
183197
* @brief

source/kernel/C/executables/fwde.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ void execute_fwde(int64* addr, kernel_data* data){
5757
entry_function execute_binary = (entry_function)local;
5858

5959
info("Function is ready! executing it..", __FILE__);
60-
print("=========================================================\n");
60+
printf("=========================================================");
6161
execute_binary(data);
62-
print("=========================================================\n");
62+
printf("=========================================================");
6363
}else{
6464
error("Unsupported architecture!", __FILE__);
6565
return;

source/kernel/C/heap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ uint64_t memory_used = 0;
1818

1919
void mm_init(uintptr_t kernel_end, int64 heap_size)
2020
{
21-
info("Initializing heap.", __FILE__);
21+
info("Initializing heap", __FILE__);
2222

2323
heap_begin = kernel_end;
2424
heap_end = heap_begin + heap_size;
@@ -29,13 +29,13 @@ void mm_init(uintptr_t kernel_end, int64 heap_size)
2929
printf("heap begin -> 0x%X", heap_begin);
3030
printf("heap end -> 0x%X", heap_end);
3131

32-
done("Heap initialized.", __FILE__);
32+
done("Heap initialized", __FILE__);
3333
}
3434

3535
void* kmalloc(size_t size)
3636
{
3737
if (size == 0) {
38-
warn("kmalloc: Cannot allocate 0 bytes.", __FILE__);
38+
warn("kmalloc: Cannot allocate 0 bytes", __FILE__);
3939
return NULL;
4040
}
4141

@@ -87,7 +87,7 @@ void* kmalloc(size_t size)
8787
void kfree(void* ptr)
8888
{
8989
if (!ptr) {
90-
warn("kfree: Cannot free null pointer.", __FILE__);
90+
warn("kfree: Cannot free null pointer", __FILE__);
9191
return;
9292
}
9393

@@ -135,4 +135,4 @@ void mm_print_out()
135135
debug_printf("%sMemory used :%s %u KiB\n", yellow_color, reset_color, memory_used/(1 KiB));
136136
debug_printf("%sMemory free :%s %u KiB\n", yellow_color, reset_color, (heap_end - last_alloc)/(1 KiB));
137137
debug_printf("%sHeap size :%s %u KiB\n", yellow_color, reset_color, (heap_end - heap_begin)/(1 KiB));
138-
}
138+
}

source/kernel/C/kernel.c

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void main(void) {
123123
stream_init();
124124
// Fetch the first framebuffer.
125125
framebuffer = framebuffer_request.response->framebuffers[0];
126+
memmap = memory_map_request.response;
126127

127128
ft_ctx = flanterm_fb_simple_init(
128129
framebuffer->address, framebuffer->width, framebuffer->height, framebuffer->pitch
@@ -154,6 +155,10 @@ void main(void) {
154155
*/
155156
mm_init(0x1000000, 64 MiB);
156157

158+
// Optional method of initializing heap, TODO make an VMM & PMM
159+
// void* heap_page = allocate_pages(64 MiB / PAGE_SIZE);
160+
// mm_init(heap_page, 64 MiB);
161+
157162
struct memory_context* memory = (struct memory_context*)kmalloc(sizeof(struct memory_context));
158163

159164
acpi_init();
@@ -166,7 +171,6 @@ void main(void) {
166171
RTL8139 = (struct rtl8139*) kmalloc(sizeof(struct rtl8139));
167172

168173
analyze_memory_map(memory, memory_map_request);
169-
memmap = memory_map_request.response;
170174

171175
uintptr_t page1 = allocate_page();
172176
uintptr_t page2 = allocate_page();
@@ -243,48 +247,16 @@ void main(void) {
243247
sh_exec();
244248
}
245249

246-
/**
247-
* @brief The basic raw print function. (DO NOT HANDLE STREAMS)
248-
*
249-
* @param msg The message to be printed
250-
*/
251-
void print(cstring msg) {
252-
if(!isBufferReady) return;
253-
if(msg == null){
254-
flanterm_write(ft_ctx, "null", 4);
255-
return;
256-
}
257-
flanterm_write(ft_ctx, msg, strlen(msg));
258-
}
259-
260-
/**
261-
* @brief The basic put char function.
262-
*
263-
* @param c The char to be printed
264-
*/
265-
extern void vputc(char c);
266-
void putc(char c){
267-
if(!isBufferReady)
268-
return;
269-
270-
271-
if (c == '\b')
272-
{
273-
vputc('\b');
274-
vputc(' ');
275-
}
276-
277-
vputc(c);
278-
}
279-
280-
/**
281-
* @brief ACPI Shutdown code wrapper.
282-
*
283-
*/
284250
void shutdown(){
251+
info("shutdown has been called", __FILE__);
252+
debug_printf("hhdm offset -> 0x%x", hhdm_request.response->offset);
253+
285254
acpi_shutdown_hack(hhdm_request.response->offset, acpi_find_sdt);
286255
}
287256

288257
void reboot(){
258+
info("reboot has been called", __FILE__);
259+
debug_printf("hhdm offset -> 0x%x", hhdm_request.response->offset);
260+
289261
acpi_reboot(hhdm_request.response->offset);
290262
}

0 commit comments

Comments
 (0)