Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line handling in fb_printStr #196

Merged
merged 9 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ debug: DEBUG=1
debug: CFLAGS += $(C_DEBUG_FLAGS)
debug: ASM_FLAGS += $(ASM_DEBUG_FLAGS)
debug: $(BUILD_FOLDER)/$(ISO_IMAGE_FILENAME)
# TODO could be useful to use stdio as both log output and monitor input
# qemu-system-x86_64 -monitor unix:qemu-monitor-socket,server,nowait -cpu qemu64,+x2apic -cdrom $(BUILD_FOLDER)/$(ISO_IMAGE_FILENAME) -serial file:dreamos64.log -m 1G -d int -no-reboot -no-shutdown
$(QEMU_SYSTEM) -monitor unix:qemu-monitor-socket,server,nowait -cpu qemu64,+x2apic -cdrom $(BUILD_FOLDER)/$(ISO_IMAGE_FILENAME) -serial stdio -m 2G -no-reboot -no-shutdown

Expand Down
3 changes: 1 addition & 2 deletions src/asm/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ higher_half:
lgdt [gdt64.pointer]

; The two lines below are needed to un map the kernel in the lower half
; But i'll leave them commented for now because the code in the kernel need
; to be changed and some addresses need to be updated (i.e. multiboot stuff)
mov eax, 0x0
mov dword [(p4_table - KERNEL_VIRTUAL_ADDR) + 0], eax

mov rax, cr3
mov cr3, rax
call kernel_start
Expand Down
9 changes: 7 additions & 2 deletions src/include/kernel/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ typedef struct framebuffer_info {
uint32_t width;
uint32_t height;

uint32_t number_of_lines;
uint32_t number_of_rows;

uint64_t phys_address;
} framebuffer_info;

void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg);
void _fb_printStr(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_t bg);
void _fb_printStrAt(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_t bg);
void _fb_printStr(const char *string, uint32_t fg, uint32_t bg);
void _fb_put_pixel(uint32_t, uint32_t, uint32_t);

/*void map_framebuffer(struct multiboot_tag_framebuffer *);*/
void set_fb_data(struct multiboot_tag_framebuffer *);
void _fb_printStrAndNumber(const char*, uint64_t, size_t, size_t, uint32_t, uint32_t);
void _fb_printStrAndNumber(const char*, uint64_t, uint32_t, uint32_t);
void _fb_printStrAndNumberAt(const char*, uint64_t, size_t, size_t, uint32_t, uint32_t);

void get_framebuffer_mode(uint32_t* pixels_w, uint32_t* pixels_h, uint32_t* chars_w, uint32_t* chars_h);
void draw_logo(uint32_t start_x, uint32_t start_y);
Expand Down
10 changes: 5 additions & 5 deletions src/include/kernel/psf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define MAGIC_V1_0 0x36
#define MAGIC_V1_1 0x04

#define MAGIC_V2 0x864ab572
#define MAGIC_V2 0x864ab572

#define PSF1_MODE512 0x01
#define PSF1_MODEHASTAB 0x02
Expand Down Expand Up @@ -37,10 +37,10 @@ extern char _binary_fonts_default_psf_size;
extern char _binary_fonts_default_psf_start[];
extern char _binary_fonts_default_psf_end;

uint8_t get_PSF_version(char *);
uint8_t _psf_get_version(char *);

uint8_t* get_glyph(uint8_t, uint8_t);
uint32_t get_height(uint8_t);
uint32_t get_width(uint8_t);
uint8_t* _psf_get_glyph(uint8_t, uint8_t);
uint32_t _psf_get_height(uint8_t);
uint32_t _psf_get_width(uint8_t);

#endif
2 changes: 1 addition & 1 deletion src/kernel/arch/x86_64/mem/vmm_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void *map_phys_to_virt_addr(void* physical_address, void* address, size_t flags)
if( !(pdpr_table[pdpr_e] & 0b1) ) {
uint64_t *new_table = pmm_alloc_frame();
pdpr_table[pdpr_e] = (uint64_t) new_table | user_mode_status | WRITE_BIT | PRESENT_BIT;
// pretty_logf(Verbose, " PDPR entry value: 0x%x", pdpr_table[pdpr_e]);
//pretty_logf(Verbose, " PDPR entry value: 0x%x", pdpr_table[pdpr_e]);
clean_new_table(pd_table);
}

Expand Down
43 changes: 34 additions & 9 deletions src/kernel/framebuffer/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ uint32_t FRAMEBUFFER_HEIGHT;
struct framebuffer_info framebuffer_data;

size_t cur_fb_line;
uint32_t number_of_lines;

void map_framebuffer(struct framebuffer_info fbdata) {
uint32_t fb_entries = fbdata.memory_size / PAGE_SIZE_IN_BYTES;
Expand Down Expand Up @@ -104,22 +105,25 @@ void set_fb_data(struct multiboot_tag_framebuffer *fbtag){
framebuffer_data.height = fbtag->common.framebuffer_height;
framebuffer_data.phys_address = fbtag->common.framebuffer_addr;

number_of_lines = 0;

map_framebuffer(framebuffer_data);
cur_fb_line = 0;

#endif
}

void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
uint8_t *framebuffer = (uint8_t *) framebuffer_data.address;
uint32_t pitch = framebuffer_data.pitch;
uint32_t width, height;
width = get_width(psf_font_version);
height = get_height(psf_font_version);
width = _psf_get_width(psf_font_version);
height = _psf_get_height(psf_font_version);

//uint32_t charsize = default_font->height * ((default_font->width + 7)/8);
//uint8_t *glyph = (uint8_t*)&_binary_fonts_default_psf_start +
// default_font->headersize + (symbol>0&&symbol<default_font->numglyph?symbol:0) * default_font->bytesperglyph;
uint8_t *glyph = get_glyph(symbol, psf_font_version);
uint8_t *glyph = _psf_get_glyph(symbol, psf_font_version);
//bytesperline is the number of bytes per each row of the glyph
size_t bytesperline = (width + 7)/8;
size_t offset = (cy * height * pitch) +
Expand Down Expand Up @@ -147,11 +151,32 @@ void _fb_putchar(char symbol, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
}
}

void _fb_printStr(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
void _fb_printStr( const char *string, uint32_t fg, uint32_t bg ) {
_fb_printStrAt(string, 0, cur_fb_line, fg, bg);
cur_fb_line++;
if ( cur_fb_line > framebuffer_data.number_of_lines ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt this be >=?

pretty_log(Verbose, "Exceeding number of lines, cycling");
cur_fb_line = 0;
}
}

void _fb_printStrAndNumber(const char *string, uint64_t number, uint32_t fg, uint32_t bg) {
_fb_printStrAndNumberAt(string, number, 0, cur_fb_line, fg, bg);
cur_fb_line++;
if ( cur_fb_line > framebuffer_data.number_of_lines ) {
pretty_log(Verbose, "Exceeding number of lines, cycling");
cur_fb_line = 0;
}
}

void _fb_printStrAt( const char *string, size_t cx, size_t cy, uint32_t fg, uint32_t bg ){
while (*string != '\0'){
if (*string == '\n'){
cx=0;
cy++;
cur_fb_line = cy;
} else if (*string == '\t'){
cx += 4;
} else {
_fb_putchar(*string, cx, cy, fg, bg);
cx++;
Expand All @@ -160,18 +185,18 @@ void _fb_printStr(const char *string, size_t cx, size_t cy, uint32_t fg, uint32_
}
}

void _fb_printStrAndNumber(const char *string, uint64_t number, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
void _fb_printStrAndNumberAt(const char *string, uint64_t number, size_t cx, size_t cy, uint32_t fg, uint32_t bg){
char buffer[30];

_getHexString(buffer, number, true);
_fb_printStr(string, cx, cy, fg, bg);
_fb_printStrAt(string, cx, cy, fg, bg);
int counter = 0;
while(*string != '\0') {
counter++;
string++;
}

_fb_printStr(buffer, cx + counter, cy, fg, bg);
_fb_printStrAt(buffer, cx + counter, cy, fg, bg);
}

void get_framebuffer_mode(uint32_t* pixels_w, uint32_t* pixels_h, uint32_t* chars_w, uint32_t* chars_h)
Expand All @@ -182,9 +207,9 @@ void get_framebuffer_mode(uint32_t* pixels_w, uint32_t* pixels_h, uint32_t* char
*pixels_h = framebuffer_data.height;

if (chars_w != NULL)
*chars_w = framebuffer_data.width / get_width(psf_font_version);
*chars_w = framebuffer_data.width / _psf_get_width(psf_font_version);
if (chars_h != NULL)
*chars_h = framebuffer_data.height / get_height(psf_font_version);
*chars_h = framebuffer_data.height / _psf_get_height(psf_font_version);
}

void _fb_put_pixel(uint32_t x, uint32_t y, uint32_t color) {
Expand Down
8 changes: 4 additions & 4 deletions src/kernel/graphics/psf.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ char _binary_fonts_default_psf_end;

uint8_t psf_font_version;

uint8_t get_PSF_version(char *_font_structure){
uint8_t _psf_get_version(char *_font_structure){
PSFv1_Font *_v1_font = (PSFv1_Font*) _font_structure;
if( _v1_font->magic[0] == MAGIC_V1_0 && _v1_font->magic[1] == MAGIC_V1_1){
return PSF_V1;
Expand All @@ -21,7 +21,7 @@ uint8_t get_PSF_version(char *_font_structure){
return 0;
}

uint8_t* get_glyph(uint8_t symbolnumber, uint8_t version){
uint8_t* _psf_get_glyph(uint8_t symbolnumber, uint8_t version){
if (version == PSF_V1){
PSFv1_Font* loaded_font = (PSFv1_Font *) &_binary_fonts_default_psf_start;
return (uint8_t *) loaded_font + sizeof(PSFv1_Font) + (symbolnumber * loaded_font->charsize);
Expand All @@ -32,14 +32,14 @@ uint8_t* get_glyph(uint8_t symbolnumber, uint8_t version){
return 0;
}

uint32_t get_width(uint8_t version){
uint32_t _psf_get_width(uint8_t version){
if ( version == PSF_V1) {
return 8;
}
return ((PSF_font *) &_binary_fonts_default_psf_start)->width;
}

uint32_t get_height(uint8_t version){
uint32_t _psf_get_height(uint8_t version){
if ( version == PSF_V1) {
return ((PSFv1_Font *) &_binary_fonts_default_psf_start)->charsize;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/hardware/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void handle_keyboard_interrupt() {
string[9] = read_char;
string[10] = '-';
//printf("%s\n", string);
_fb_printStr(string, 0, 10, 0x000000, 0x1ad652);
_fb_printStrAt(string, 0, 10, 0x000000, 0x1ad652);
}
#endif
pretty_logf(Verbose, "\t+ Key is pressed pos %d: SC: %x - Code: %x - Mod: %x %c", buf_position, scancode, keyboard_buffer[buf_position].code, keyboard_buffer[buf_position].modifiers, kgetch(keyboard_buffer[buf_position]));
Expand Down
8 changes: 4 additions & 4 deletions src/kernel/hardware/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ void timer_handler() {
#if USE_FRAMEBUFFER == 1
if(pit_timer_counter == 0) {
pit_timer_counter = 1;
//_fb_printStr("*", 0, 14, 0x000000, 0xE169CD);
// _fb_printStrAt("+", 0, 12, 0x000000, 0x365B00);
} else {
pit_timer_counter = 0;
//_fb_printStr("/", 0, 14, 0x000000, 0xE169CD);
// _fb_printStrAt("-", 0, 12, 0x000000, 0x365B00);
}
#endif

Expand All @@ -88,10 +88,10 @@ void pit_irq_handler() {
#if USE_FRAMEBUFFER == 1
if(pit_timer_counter == 0) {
pit_timer_counter = 1;
_fb_printStr("-", 0, 11, 0x000000, 0xE169CD);
// _fb_printStrAt("-", 0, 12, 0x000000, 0x365B00);
} else {
pit_timer_counter = 0;
_fb_printStr("+", 0, 11, 0x000000, 0xE169CD);
// _fb_printStrAt("+", 0, 12, 0x000000, 0x365B00);
}
#endif
}
9 changes: 4 additions & 5 deletions src/kernel/io/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <qemu.h>
#endif
//#include <image.h>

//TODO: Remove legacy VGA support
char *VIDEO_MEM = (char *) _VIDEO_MEM_START;
char *VIDEO_PTR = (char *) _VIDEO_MEM_START;

Expand All @@ -21,7 +21,7 @@ char *VIDEO_PTR = (char *) _VIDEO_MEM_START;
px_addr[j*4+1] = MagickImage[i+j+1 + k];
px_addr[j*4+2] = MagickImage[i+j+2 + k];
k +=3;
//px_addr = FRAMEBUFFER_MEM + row + j * FRAMEBUFFER_BPP;
//px_addr = FRAMEBUFFER_MEM + row + j * FRAMEBUFFER_BPP;
}
px_addr +=3200;
}
Expand Down Expand Up @@ -59,14 +59,13 @@ void _printStringAndNumber(char *string, unsigned long number){

void _printNumber(char *buffer, unsigned long number, int base){
switch(base){
case 10:
break;
case 10:
break;
case 16:
_getHexString(buffer, number, false);
break;
}
_printStr(buffer);

}

void _printHex(char *buffer, unsigned long hexnumber){
Expand Down
13 changes: 7 additions & 6 deletions src/kernel/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool useVgaOutput;
void init_log(size_t defaultOutputs, log_level_t trimBelowLevel, bool useVgaVideo){
if (defaultOutputs == LOG_OUTPUT_DONT_CARE)
defaultOutputs = LOG_OUTPUT_SERIAL; //default to serial

logDestBitmap = defaultOutputs;
logTrimLevel = trimBelowLevel;

Expand All @@ -48,7 +48,7 @@ void set_log_trim_level(size_t newTrim){
void logline(log_level_t level, const char* msg){
if (level < logTrimLevel)
return; //dont log things that we dont want to see for now. (would be nice to store these somewhere in the future perhaps, just not display them?)

for (size_t i = 0; i < LOG_OUTPUT_COUNT; i++){
if ((logDestBitmap & (1 << i)) == 0)
continue; //bit is cleared, we should not log there
Expand All @@ -74,15 +74,16 @@ void logline(log_level_t level, const char* msg){
fbCurrentLine++;
}
else {
_fb_printStr(logLevelStrings[level], 0, fbCurrentLine, 0xFFFFFFFF, 0);
_fb_printStr(msg, logLevelStrLen, fbCurrentLine, 0xFFFFFFFF, 0);
//TODO: fbCurrentLine should be aligned with cur_fbLine in the framebuffer case.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah, this is an interesting one - I remember doing that because there no state tracking a current line number for the terminal output.
Now that the framebuffer keeps track of that itself, fbCurrentLine can be removed I reckon, and just use the new codepath. Log messages will work nicely with other things that print directly to the framebuffer now too.

_fb_printStrAt(logLevelStrings[level], 0, fbCurrentLine, 0xFFFFFFFF, 0);
_fb_printStrAt(msg, logLevelStrLen, fbCurrentLine, 0xFFFFFFFF, 0);
fbCurrentLine++;
}

if (fbCurrentLine > fbMaxLine)
fbCurrentLine = 0;
break;

default:
continue;
}
Expand All @@ -98,7 +99,7 @@ void logline(log_level_t level, const char* msg){
void loglinef(log_level_t level, const char* msg, ...)
{
char format_buffer[formatBufferLen];

va_list format_args;
va_start(format_args, msg);
vsprintf(format_buffer, msg, format_args);
Expand Down
Loading
Loading