A question of the transform between .SFN and .O
Posted: Tue Aug 11, 2020 7:53 am
Hello everyone,
I'm currently developing a really simple GUI for my operating system. And I've just found this 1-year-ago topic of SSFN from this post: https://wiki.osdev.org/Scalable_Screen_Font
Recently I want to add the ability of rendering text (more precisely, Unicode) on VRam, I've tried to use PSFs format & plain data written in array, but these method are too... clumsy and difficult to maintain, so I changed my plan and started to use SSFN library to render text.
Unfortunately, my OS is still in early-stage. I cannot use any file function such as, I couldn't read data from SFN file directly in my project directory.[/b] The only way to read data from SFN, is to convert .sfn to .o file via objcopy when building, after that I can link datas in my code.
I found that there are a few fonts attached to the SSFN directory, I moved one of them, FreeSans.sfn, into my project directory. I simply created fonts.c and packaged an API:
My Makefile:
My project was successfully built, however it couldn't print the character 'A' when I use it in kernel.c. So I started debug. And I found that, in int ssfn_putc(uint32_t unicode), there's a line of code:
The whole function was returned due to this if statement. I printed ssfn_src->magic via gdb and found that, there is no magic SFN number of my .O file.Hence, my transform from .SFN to .O wasn't correct.
So, my question is, how do I transform .sfn to .o correctly? If there is no such method, are there any alternatives
I'm currently developing a really simple GUI for my operating system. And I've just found this 1-year-ago topic of SSFN from this post: https://wiki.osdev.org/Scalable_Screen_Font
Recently I want to add the ability of rendering text (more precisely, Unicode) on VRam, I've tried to use PSFs format & plain data written in array, but these method are too... clumsy and difficult to maintain, so I changed my plan and started to use SSFN library to render text.
Unfortunately, my OS is still in early-stage. I cannot use any file function such as
Code: Select all
fread()
I found that there are a few fonts attached to the SSFN directory, I moved one of them, FreeSans.sfn, into my project directory. I simply created fonts.c and packaged an API:
Code: Select all
#define SSFN_CONSOLEBITMAP_HICOLOR
#include "font.h"
#include "ssfn.h"
extern char _binary_drivers_FreeSans_sfn_start;
/*
* @brief Plot a character on the VRam.
*
* @param vram Video RAM,
* @param bpr Bytes per row.
* @param x X axis of the char.
* @param y Y axis of the char.
* @param w Width of the screen.
* @param h Height of the screen.
* @param fg Foreground color.
* @param bg Background color.
* @param unicode Unicode of the char.
*/
void plot_font(uint8_t *vram, uint16_t bpr, int x, int y, int w, int h,
uint32_t fg, uint32_t bg, uint32_t unicode) {
ssfn_src = &_binary_drivers_FreeSans_sfn_start;
ssfn_dst.ptr = vram;
ssfn_dst.p = bpr;
ssfn_dst.fg = fg;
ssfn_dst.bg = bg;
ssfn_dst.x = x;
ssfn_dst.y = y;
ssfn_dst.w = w;
ssfn_dst.h = h;
ssfn_putc(unicode);
}
Code: Select all
C_SOURCES = ......
HEADERS = ......
OBJ = ${C_SOURCES:.c=.o ...... drivers/FreeSans.o}
CC = /path/to/cc
GDB = /usr/local/bin/gdb
CFLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions -m32
.............(omitted)
%.o: %.sfn
i386-elf-objcopy -O elf32-i386 -B i386 -I binary $< $@
Code: Select all
if(!ssfn_src || ssfn_src->magic[0] != 'S' || ssfn_src->magic[1] != 'F' || ssfn_src->magic[2] != 'N' ||
ssfn_src->magic[3] != '2' || !ssfn_dst.ptr || !ssfn_dst.p) return SSFN_ERR_INVINP;
So, my question is, how do I transform .sfn to .o correctly? If there is no such method, are there any alternatives