wip: fix terminal stuff
This commit is contained in:
20
documentation/task/memory.md
Normal file
20
documentation/task/memory.md
Normal file
@ -0,0 +1,20 @@
|
||||
# TASK - MEMORY
|
||||
|
||||
By my own convention
|
||||
|
||||
|
||||
## Task Page Directory
|
||||
| address | content |
|
||||
---|---
|
||||
| 0 | first_page_table|
|
||||
| 1-767 | ALLOCABLE HEAP|
|
||||
| 768-1023 | KERNEL CODE, SCREEN, MULTIBOOT HEADER, FRAME_MAP, etc|
|
||||
|
||||
|
||||
## first_page_table
|
||||
| address | content |
|
||||
---|-
|
||||
| 0-253 | NULL
|
||||
| 254 | The addr of the `first_page_table`
|
||||
| 255 | The phys address of the task pd. so the task can access at his pd on the address `GET_PAGE_ADDR(0, 255)`
|
||||
| 256-1023 | Like in the kernel task, reserved for heap page_table
|
||||
@ -58,7 +58,6 @@ int terminal_writestring(const char *data);
|
||||
int terminal_writelong(long number);
|
||||
void terminal_set_screen(int pos);
|
||||
void terminal_clear(void);
|
||||
void terminal_refresh(void);
|
||||
struct key_event terminal_getkey(void);
|
||||
void update_cursor(void);
|
||||
void move_cursor(int direction);
|
||||
@ -69,3 +68,4 @@ void terminal_change_default_fg_color(uint32_t color);
|
||||
uint32_t terminal_get_default_color(void);
|
||||
uint8_t terminal_get_char(int column, int row);
|
||||
void terminal_remove_last_char(void);
|
||||
void terminal_refresh_color(void);
|
||||
|
||||
@ -32,20 +32,18 @@
|
||||
|
||||
static void bozo(int int_code)
|
||||
{
|
||||
(void)int_code;
|
||||
kprintf("apagnan code\n");
|
||||
}
|
||||
|
||||
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||
{
|
||||
terminal_initialize();
|
||||
init_gdt();
|
||||
init_idt();
|
||||
init_memory(mbd, magic);
|
||||
load_drivers();
|
||||
terminal_initialize();
|
||||
create_kernel_task();
|
||||
kill(0, 4);
|
||||
for (size_t i = 0; i < 10000; i++)
|
||||
free_pages(alloc_pages(1, NULL), 1);
|
||||
signal(4, bozo);
|
||||
kill(0, 4);
|
||||
shell_init();
|
||||
|
||||
7
src/memory/page_directory.c
Normal file
7
src/memory/page_directory.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void init_page_directory(uint32_t page_directory[1024])
|
||||
{
|
||||
for (uint16_t i = 0; i < 0x300; i++)
|
||||
page_directory[i] = 0x02;
|
||||
}
|
||||
@ -18,7 +18,8 @@ void color_cmd(char *arg)
|
||||
goto invalid;
|
||||
for (size_t i = 0; i < ARRAY_SIZE(colors); i++) {
|
||||
if (strcmp(colors[i], arg) == 0) {
|
||||
terminal_change_default_fg_color(i);
|
||||
terminal_set_fg_color(i);
|
||||
terminal_refresh_color();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,12 +26,14 @@ void terminal_initialize(void)
|
||||
for (int i = 0; i < TERM_COUNT; i++) {
|
||||
screens[i].row = 0;
|
||||
screens[i].column = 0;
|
||||
screens[i].default_color = 0xffffff;
|
||||
screens[i].default_color = 0;
|
||||
screens[i].fg_color = screens[i].default_color;
|
||||
screens[i].bg_color = 0x8acd01;
|
||||
// screens[i].background = &image_icon;
|
||||
screens[i].font = consolas_regular_13_font;
|
||||
memset(screens[i].line, 0, sizeof(screen->line));
|
||||
}
|
||||
terminal_clear();
|
||||
}
|
||||
|
||||
void terminal_remove_last_char(void)
|
||||
@ -42,7 +44,7 @@ void terminal_remove_last_char(void)
|
||||
screen->column = VGA_WIDTH - 1;
|
||||
screen->row--;
|
||||
}
|
||||
uint32_t pos_x = (screen->column) * FONT_WIDTH;
|
||||
uint32_t pos_x = screen->column * FONT_WIDTH;
|
||||
uint32_t pos_y = screen->row * FONT_HEIGHT;
|
||||
|
||||
struct font node = get_font_node(
|
||||
@ -51,13 +53,14 @@ void terminal_remove_last_char(void)
|
||||
for (uint32_t y = 0; y < node.height; y++) {
|
||||
for (uint32_t x = 0; x < node.width; x++) {
|
||||
// Current bg is taking too much memory
|
||||
// so we do a black bg for now
|
||||
// so we do a colored bg for now
|
||||
// struct icon *bg = screen->background;
|
||||
// uint32_t pixel = 0;
|
||||
// if (bg->width > pos_x + x && bg->height > pos_y + y)
|
||||
// pixel = bg->pixels[(pos_y + y) * bg->width +
|
||||
// (pos_x + x)];
|
||||
put_pixel(0, pos_x + x, pos_y + y + node.yoffset);
|
||||
put_pixel(screen->bg_color, pos_x + x,
|
||||
pos_y + y + node.yoffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,7 +83,7 @@ void terminal_set_bg_color(uint32_t bg_color)
|
||||
|
||||
void terminal_set_fg_color(uint32_t fg_color)
|
||||
{
|
||||
screen->fg_color = screen->fg_color;
|
||||
screen->fg_color = fg_color;
|
||||
}
|
||||
|
||||
void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
|
||||
@ -104,8 +107,8 @@ uint8_t terminal_get_char(int x, int y)
|
||||
return screen->buffer[y * VGA_WIDTH + x];
|
||||
}
|
||||
|
||||
void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
|
||||
size_t x, size_t y)
|
||||
void terminal_putentryat(struct font node, uint32_t fg_color, size_t x,
|
||||
size_t y)
|
||||
{
|
||||
char *glyph = node.bitmap;
|
||||
for (size_t cy = 0; cy < node.height; cy++) {
|
||||
@ -131,7 +134,7 @@ static void terminal_scroll(void)
|
||||
const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
|
||||
screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
|
||||
terminal_putentryat(get_font_node(screen->buffer[i]),
|
||||
screen->fg_color, screen->bg_color, x, y);
|
||||
screen->fg_color, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,55 +145,21 @@ static void terminal_new_line(void)
|
||||
terminal_scroll();
|
||||
}
|
||||
|
||||
void terminal_change_default_color(uint32_t color)
|
||||
void terminal_refresh_color(void)
|
||||
{
|
||||
// TODO
|
||||
/* terminal_set_color(color); */
|
||||
/* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
|
||||
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
|
||||
/* const size_t index = y * VGA_WIDTH + x;
|
||||
*/
|
||||
/* uint8_t entry_color =
|
||||
* get_entry_color(TERM_BUF[index]);
|
||||
*/
|
||||
/* TERM_BUF[index] = vga_entry( */
|
||||
/* TERM_BUF[index], */
|
||||
/* entry_color == screen->default_color
|
||||
* ? color
|
||||
*/
|
||||
/* :
|
||||
* entry_color);
|
||||
*/
|
||||
/* } */
|
||||
/* } */
|
||||
/* memcpy(screen->buffer, TERM_BUF,
|
||||
* sizeof(screen->buffer)); */
|
||||
/* screen->default_color = color; */
|
||||
/* screen->color = color; */
|
||||
}
|
||||
|
||||
void terminal_change_default_fg_color(uint32_t fg_color)
|
||||
{
|
||||
terminal_set_fg_color(fg_color);
|
||||
/* terminal_change_default_color(screen->fg_color); */
|
||||
terminal_clear();
|
||||
for (uint32_t y = 0; y < VGA_HEIGHT; y++)
|
||||
for (uint32_t x = 0; x < VGA_WIDTH; x++)
|
||||
terminal_putentryat(
|
||||
get_font_node(screen->buffer[y * VGA_WIDTH + x]),
|
||||
screen->fg_color, x, y);
|
||||
}
|
||||
|
||||
void terminal_clear(void)
|
||||
{
|
||||
// TODO
|
||||
/* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
|
||||
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
|
||||
/* const size_t index = y * VGA_WIDTH + x;
|
||||
*/
|
||||
/* TERM_BUF[index] = vga_entry(' ',
|
||||
* screen->color);
|
||||
*/
|
||||
/* } */
|
||||
/* } */
|
||||
/* memcpy(screen->buffer, TERM_BUF,
|
||||
* sizeof(screen->buffer)); */
|
||||
/* screen->column = 0; */
|
||||
/* screen->row = 0; */
|
||||
for (uint32_t y = 0; y < SCREEN_HEIGHT; y++)
|
||||
for (uint32_t x = 0; x < SCREEN_WIDTH; x++)
|
||||
put_pixel(screen->bg_color, x, y);
|
||||
}
|
||||
|
||||
int terminal_putchar(char c)
|
||||
@ -203,7 +172,7 @@ int terminal_putchar(char c)
|
||||
return 1;
|
||||
screen->buffer[screen->column + screen->row * VGA_WIDTH] = c;
|
||||
terminal_putentryat(get_font_node(c), screen->fg_color,
|
||||
screen->bg_color, screen->column * FONT_WIDTH,
|
||||
screen->column * FONT_WIDTH,
|
||||
screen->row * FONT_HEIGHT);
|
||||
if (++screen->column >= VGA_WIDTH)
|
||||
terminal_new_line();
|
||||
|
||||
Reference in New Issue
Block a user