Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ff6e4fdb8 | |||
| 8332af1370 | |||
|
|
14a9bdad7d | ||
|
|
756dc638e8 | ||
|
|
903188a543 | ||
|
|
8a68cf3b30 | ||
|
|
1085222d98 | ||
|
|
68a4be55ce | ||
|
|
cee509f6a1 | ||
|
|
7071b4788b | ||
|
|
8bac95890a |
@@ -1,8 +1,8 @@
|
|||||||

|

|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> The project is currently paused, after months of work around the subject. I've had enough for now, and I'll surely come back in some time to implement the more advanced stuff I had planned. For now, enjoy the latest alpha version.
|
> This is free and unencumbered software released into the public domain. Many things might be (are) broken.
|
||||||
> This is a hobbyist operating system, and it comes without any warranty whatsoever! See the license for more info. Feedback and contributions are highly appreciated.
|
> The project is a hobbyist operating system, and it comes without any warranty whatsoever! See the license for more info. Feedback and contributions are highly appreciated.
|
||||||
|
|
||||||
# BlankOS
|
# BlankOS
|
||||||
|
|
||||||
|
|||||||
BIN
blankos.png
Normal file
BIN
blankos.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 405 KiB |
@@ -46,7 +46,7 @@ Be warned, these are not actual programs in the sense you'd expect. These are in
|
|||||||
|
|
||||||
### Step 1 - Making the program and the entry point
|
### Step 1 - Making the program and the entry point
|
||||||
|
|
||||||
To make a program for the OS, first create the appropriate C source file and header file in the `src/programs` subfolder. Name it appropriately, for example `myprogram.c`.
|
To make a program for the OS, first create the appropriate C source file and header file in the `src/utils` subfolder. Name it appropriately, for example `myprogram.c`.
|
||||||
|
|
||||||
In this file, you will put the functions your program will use. The entry point for the program should be a void function named `program_<PROGRAM_NAME>`. The entry point can either take no arguments, or use the classic argc/argv structure.
|
In this file, you will put the functions your program will use. The entry point for the program should be a void function named `program_<PROGRAM_NAME>`. The entry point can either take no arguments, or use the classic argc/argv structure.
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ Now that your program is done, you will need to make it a part of the OS.
|
|||||||
|
|
||||||
#### General program header file registering
|
#### General program header file registering
|
||||||
|
|
||||||
To make the entry point function reachable from the shell, you first have to include it in the general programs header file located in `src/programs/programs.h`.
|
To make the entry point function reachable from the shell, you first have to include it in the general programs header file located in `src/utils/programs.h`.
|
||||||
|
|
||||||
Put the entry point function prototype in that file. A valid example might be:
|
Put the entry point function prototype in that file. A valid example might be:
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ Don't make your command name too long, preferably a few characters, like the oth
|
|||||||
|
|
||||||
#### Help utility registering (optional)
|
#### Help utility registering (optional)
|
||||||
|
|
||||||
Finally, you can add your command to the list of available commands by adding it to the `printf` call in the `src/programs/misc.c` source file, in the function `program_help()`.
|
Finally, you can add your command to the list of available commands by adding it to the `printf` call in the `src/utils/misc.c` source file, in the function `program_help()`.
|
||||||
|
|
||||||
If possible make sure that the new command name is aligned with the other ones.
|
If possible make sure that the new command name is aligned with the other ones.
|
||||||
|
|
||||||
|
|||||||
@@ -147,3 +147,7 @@ Controls:
|
|||||||
#### `exec <binary>`
|
#### `exec <binary>`
|
||||||
|
|
||||||
Executes a binary file. Warning: this is highly broken and syscalls aren't working. It's written in a childish manner. Help is always appreciated (lol).
|
Executes a binary file. Warning: this is highly broken and syscalls aren't working. It's written in a childish manner. Help is always appreciated (lol).
|
||||||
|
|
||||||
|
#### `uhex <file>`
|
||||||
|
|
||||||
|
Prints the hex and ASCII contents of a file.
|
||||||
|
|||||||
Binary file not shown.
BIN
include/fonts/viscii10-8x16.psfu
Normal file
BIN
include/fonts/viscii10-8x16.psfu
Normal file
Binary file not shown.
4
makefile
4
makefile
@@ -26,8 +26,8 @@ PROGRAM_OBJECTS = $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(PROGRAM_SOURCES:.c=.o
|
|||||||
TOOLCHAIN_SRC = https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz
|
TOOLCHAIN_SRC = https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz
|
||||||
TOOLCHAIN_FILE = i386-elf-7.5.0-Linux-x86_64.tar.xz
|
TOOLCHAIN_FILE = i386-elf-7.5.0-Linux-x86_64.tar.xz
|
||||||
|
|
||||||
FONT_OBJ = $(OBJ_DIR)/fonts/UniCyr_8x16.o
|
FONT_OBJ = $(OBJ_DIR)/fonts/viscii10-8x16.o
|
||||||
FONT_SRC = $(FONTS_DIR)/UniCyr_8x16.psf
|
FONT_SRC = $(FONTS_DIR)/viscii10-8x16.psfu
|
||||||
|
|
||||||
all: $(OBJ_DIR) kernel.elf programs
|
all: $(OBJ_DIR) kernel.elf programs
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,51 @@
|
|||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "../kernel/system.h"
|
#include "../kernel/system.h"
|
||||||
|
#include "../kernel/kheap.h"
|
||||||
|
|
||||||
extern char* framebuffer;
|
extern char* framebuffer;
|
||||||
|
|
||||||
|
void psf_init()
|
||||||
|
{
|
||||||
|
uint16_t glyph = 0;
|
||||||
|
PSF_font *font = (PSF_font*)&FONT_START;
|
||||||
|
if (font->flags)
|
||||||
|
{
|
||||||
|
unicode = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* s = (char*)((unsigned char*)&FONT_START + font->headersize + font->numglyph * font->bytesperglyph);
|
||||||
|
unicode = calloc(USHRT_MAX, 2);
|
||||||
|
|
||||||
|
while((uintptr_t)s>(uintptr_t)FONT_END){
|
||||||
|
uint16_t uc = (uint16_t)((unsigned char)s[0]);
|
||||||
|
if(uc == 0xFF) {
|
||||||
|
glyph++;
|
||||||
|
s++;
|
||||||
|
continue;
|
||||||
|
} else if(uc & 128) {
|
||||||
|
/* UTF-8 to unicode */
|
||||||
|
if((uc & 32) == 0 ) {
|
||||||
|
uc = ((s[0] & 0x1F)<<6)+(s[1] & 0x3F);
|
||||||
|
s++;
|
||||||
|
} else
|
||||||
|
if((uc & 16) == 0 ) {
|
||||||
|
uc = ((((s[0] & 0xF)<<6)+(s[1] & 0x3F))<<6)+(s[2] & 0x3F);
|
||||||
|
s+=2;
|
||||||
|
} else
|
||||||
|
if((uc & 8) == 0 ) {
|
||||||
|
uc = ((((((s[0] & 0x7)<<6)+(s[1] & 0x3F))<<6)+(s[2] & 0x3F))<<6)+(s[3] & 0x3F);
|
||||||
|
s+=3;
|
||||||
|
} else
|
||||||
|
uc = 0;
|
||||||
|
}
|
||||||
|
/* save translation */
|
||||||
|
unicode[uc] = glyph;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
|
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
|
||||||
{
|
{
|
||||||
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
|
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
|
||||||
@@ -18,13 +60,13 @@ void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
|
|||||||
|
|
||||||
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
|
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
|
||||||
{
|
{
|
||||||
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;
|
PSF_font *font = (PSF_font*)&FONT_START;
|
||||||
int bytesperline=(font->width+7)/8;
|
int bytesperline=(font->width+7)/8;
|
||||||
if (unicode != NULL) {
|
if (unicode != NULL) {
|
||||||
c = unicode[c];
|
c = unicode[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* glyph = (unsigned char*)&_binary_include_fonts_UniCyr_8x16_psf_start + font->headersize + (c>0&&c<font->numglyph?c:0)*font->bytesperglyph;
|
unsigned char* glyph = (unsigned char*)&FONT_START + font->headersize + (c>0&&c<font->numglyph?c:0)*font->bytesperglyph;
|
||||||
|
|
||||||
int offs =
|
int offs =
|
||||||
(cy * font->height * scanline) +
|
(cy * font->height * scanline) +
|
||||||
@@ -54,7 +96,7 @@ void scroll()
|
|||||||
{
|
{
|
||||||
serial_printf(3, "Scrolling...\r");
|
serial_printf(3, "Scrolling...\r");
|
||||||
uint32_t bg_color = 0x00000000;
|
uint32_t bg_color = 0x00000000;
|
||||||
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;
|
PSF_font *font = (PSF_font*)&FONT_START;
|
||||||
|
|
||||||
int line_size = font->height * scanline;
|
int line_size = font->height * scanline;
|
||||||
int framebuffer_size = scanline * font->height * (1080/font->height);
|
int framebuffer_size = scanline * font->height * (1080/font->height);
|
||||||
|
|||||||
@@ -9,11 +9,16 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern int scanline;
|
extern int scanline;
|
||||||
extern char _binary_include_fonts_UniCyr_8x16_psf_start;
|
|
||||||
uint16_t* unicode;
|
|
||||||
|
|
||||||
|
#define FONT_START _binary_include_fonts_viscii10_8x16_psfu_start
|
||||||
|
#define FONT_END _binary_include_fonts_viscii10_8x16_psfu_start
|
||||||
|
|
||||||
|
extern char FONT_START;
|
||||||
|
extern char FONT_END;
|
||||||
|
uint16_t* unicode;
|
||||||
#define PIXEL uint32_t
|
#define PIXEL uint32_t
|
||||||
|
|
||||||
|
#define USHRT_MAX 10000
|
||||||
#define PSF1_FONT_MAGIC 0x0436
|
#define PSF1_FONT_MAGIC 0x0436
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -38,5 +43,6 @@ typedef struct {
|
|||||||
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
|
||||||
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
|
||||||
void scroll();
|
void scroll();
|
||||||
|
void psf_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -93,10 +93,22 @@ void ls_initrd(uint8_t* initrd, int verbose)
|
|||||||
{
|
{
|
||||||
if (!verbose)
|
if (!verbose)
|
||||||
{
|
{
|
||||||
printf("%s\n", header->filename);
|
if (header->typeflag == '5')
|
||||||
|
{
|
||||||
|
colorprintf(cyan, black, "%s\n", header->filename);
|
||||||
} else {
|
} else {
|
||||||
|
printf("%s\n", header->filename);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (header->typeflag == '5')
|
||||||
|
{
|
||||||
|
printf("%7d\t%c\t", (int)header->size, header->typeflag);
|
||||||
|
colorprintf(cyan, black, " %s\n", header->filename);
|
||||||
|
} else {
|
||||||
|
|
||||||
printf("%7d\t%c\t %s\n", (int)header->size, header->typeflag, header->filename);
|
printf("%7d\t%c\t %s\n", (int)header->size, header->typeflag, header->filename);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t size = tar_parse_size(header->size);
|
uint32_t size = tar_parse_size(header->size);
|
||||||
uint32_t next_file_offset = ((size+TAR_BLOCK_SIZE-1)/TAR_BLOCK_SIZE)*TAR_BLOCK_SIZE;
|
uint32_t next_file_offset = ((size+TAR_BLOCK_SIZE-1)/TAR_BLOCK_SIZE)*TAR_BLOCK_SIZE;
|
||||||
|
|||||||
@@ -56,6 +56,23 @@ void* malloc(size_t size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* calloc(size_t num, size_t size)
|
||||||
|
{
|
||||||
|
size_t total_size = num*size;
|
||||||
|
void* ptr = malloc(total_size);
|
||||||
|
|
||||||
|
if (ptr != NULL)
|
||||||
|
{
|
||||||
|
uint8_t* byte_ptr = (uint8_t*)ptr;
|
||||||
|
for (size_t i=0; i<total_size; i++)
|
||||||
|
{
|
||||||
|
byte_ptr[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
void free(void* ptr)
|
void free(void* ptr)
|
||||||
{
|
{
|
||||||
if (ptr == NULL) return;
|
if (ptr == NULL) return;
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ typedef struct block
|
|||||||
void init_alloc();
|
void init_alloc();
|
||||||
void* malloc(size_t size);
|
void* malloc(size_t size);
|
||||||
void free(void* ptr);
|
void free(void* ptr);
|
||||||
|
void* calloc(size_t num, size_t size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch);
|
serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch);
|
||||||
serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp);
|
serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp);
|
||||||
}
|
}
|
||||||
|
psf_init();
|
||||||
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
|
||||||
printf("[kernel] framebuffer discovered at 0x%x\n", (unsigned int)fb_info->framebuffer_addr);
|
printf("[kernel] framebuffer discovered at 0x%x\n", (unsigned int)fb_info->framebuffer_addr);
|
||||||
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
||||||
@@ -118,6 +118,10 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
printf("[debug] malloc test ptr1=0x%x, ptr2=0x%x\n", (unsigned int)ptr1, (unsigned int)ptr2);
|
printf("[debug] malloc test ptr1=0x%x, ptr2=0x%x\n", (unsigned int)ptr1, (unsigned int)ptr2);
|
||||||
free(ptr1); free(ptr2);
|
free(ptr1); free(ptr2);
|
||||||
|
|
||||||
|
void* ptr3 = calloc(1024, 2);
|
||||||
|
printf("[debug] calloc test ptr3=0x%x\n", (unsigned int)ptr3);
|
||||||
|
free (ptr3);
|
||||||
|
|
||||||
// usually the place where i do testing
|
// usually the place where i do testing
|
||||||
|
|
||||||
timer_install();
|
timer_install();
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ void shell_install()
|
|||||||
register_command("naval", program_navalbattle);
|
register_command("naval", program_navalbattle);
|
||||||
register_command("snake", program_snake);
|
register_command("snake", program_snake);
|
||||||
register_command("exec", program_exec);
|
register_command("exec", program_exec);
|
||||||
|
register_command("uhex", program_uhex);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ void program_uptime()
|
|||||||
|
|
||||||
void program_help()
|
void program_help()
|
||||||
{
|
{
|
||||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake exec\n");
|
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake exec\t uhex\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic
|
// Panic
|
||||||
|
|||||||
@@ -7,12 +7,19 @@
|
|||||||
// and now by being here it is even worse because it is RO and will have
|
// and now by being here it is even worse because it is RO and will have
|
||||||
// hardcoded stuff in it (no ioctl, STDOUT, or other stuff here...)
|
// hardcoded stuff in it (no ioctl, STDOUT, or other stuff here...)
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
#define BYTES 1024
|
#define BYTES 1024
|
||||||
#define round(x) (int)(x < 0 ? (x -0.5) : x + 0.5)
|
#define round(x) (int)(x < 0 ? (x -0.5) : x + 0.5)
|
||||||
|
|
||||||
// WIP: pushed but not done yet
|
#include "../libc/stdio.h"
|
||||||
|
#include "../kernel/kmain.h"
|
||||||
|
#include "../kernel/initrd.h"
|
||||||
|
#include "../libc/string.h"
|
||||||
|
#include "../kernel/kheap.h"
|
||||||
|
|
||||||
|
int isprint(int c)
|
||||||
|
{
|
||||||
|
return (c >= 32 && c <= 126);
|
||||||
|
}
|
||||||
|
|
||||||
void print_hex(unsigned char* buf, int byteno, int pos, int BYTES_PER_LINE)
|
void print_hex(unsigned char* buf, int byteno, int pos, int BYTES_PER_LINE)
|
||||||
{
|
{
|
||||||
@@ -59,14 +66,17 @@ void program_uhex(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
printf("Usage: uhex <file>\nInline commands:\n\tpX - print position X\n\teX - edit position X\n\tq - quit\n");
|
puts("Usage: uhex <file>\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BYTES_PER_LINE = 20;
|
int BYTES_PER_LINE = 20;
|
||||||
|
|
||||||
|
//unsigned char buf[BYTES]; // malloc with file_size next?
|
||||||
|
uint32_t file_size = tar_get_file_size((uint8_t*)initrd_addr, argv[1]);
|
||||||
|
unsigned char* buf = (unsigned char*)malloc(file_size);
|
||||||
|
tar_file_to_buffer((uint8_t*)initrd_addr, argv[1], (char*)buf);
|
||||||
|
print_hex(buf, file_size, 0, BYTES_PER_LINE);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -48,4 +48,6 @@ void program_snake();
|
|||||||
// Binaries loading and execution
|
// Binaries loading and execution
|
||||||
void program_exec();
|
void program_exec();
|
||||||
|
|
||||||
|
void program_uhex();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user