vga now working with term and shell program
This commit is contained in:
@@ -13,4 +13,4 @@ find "." -type f \( -name "Makefile" -o -name "makefile" \) | while read -r make
|
|||||||
)
|
)
|
||||||
done
|
done
|
||||||
|
|
||||||
cd..
|
cd ..
|
||||||
@@ -30,7 +30,7 @@ uint32_t vga_mmap(vfs_node_t* node, uint32_t address) {
|
|||||||
for (uint32_t i = 0; i < num_pages; i++) {
|
for (uint32_t i = 0; i < num_pages; i++) {
|
||||||
uint32_t phys_addr = framebuffer_address + (i * 4096);
|
uint32_t phys_addr = framebuffer_address + (i * 4096);
|
||||||
uint32_t virt_addr = address + (i * 4096);
|
uint32_t virt_addr = address + (i * 4096);
|
||||||
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE | PAGE_USER | PAGE_MMIO);
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ void vga_init(
|
|||||||
for (uint32_t i = 0; i < num_pages; i++) {
|
for (uint32_t i = 0; i < num_pages; i++) {
|
||||||
uint32_t phys_addr = fb_paddr + (i * 4096);
|
uint32_t phys_addr = fb_paddr + (i * 4096);
|
||||||
uint32_t virt_addr = VGA_FRAMEBUFFER + (i * 4096);
|
uint32_t virt_addr = VGA_FRAMEBUFFER + (i * 4096);
|
||||||
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE | PAGE_MMIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
vga_clear_scrn(0x00000000);
|
vga_clear_scrn(0x00000000);
|
||||||
|
|||||||
@@ -166,14 +166,7 @@ void kmain(multiboot_info* mbi) {
|
|||||||
dev->mnt = devfs;
|
dev->mnt = devfs;
|
||||||
kprintf("mounted devfs\n");
|
kprintf("mounted devfs\n");
|
||||||
|
|
||||||
int font_loaded = set_console_font("/usr/fonts/kernel_font.psf");
|
kprintf("basic initializations complete\n");
|
||||||
if (!font_loaded) {
|
|
||||||
kprintf("failed to load console font\n");
|
|
||||||
}
|
|
||||||
console_init();
|
|
||||||
|
|
||||||
kprintf("kernel console initialized\n");
|
|
||||||
kprintf("basic initializations complete. check serial for details\n");
|
|
||||||
kprintf("starting rockos\n");
|
kprintf("starting rockos\n");
|
||||||
|
|
||||||
load_root_program("/usr/bin/rockterm");
|
load_root_program("/usr/bin/rockterm");
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ static char* hex_chars = "0123456789abcdef";
|
|||||||
|
|
||||||
static void kwrite(char c) {
|
static void kwrite(char c) {
|
||||||
write_serial(c);
|
write_serial(c);
|
||||||
console_putchar(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kprint(const char *str) {
|
static void kprint(const char *str) {
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ void* clone_current_pd() {
|
|||||||
uint32_t pte_src = pt_src[j];
|
uint32_t pte_src = pt_src[j];
|
||||||
if (!(pte_src & PAGE_PRESENT)) continue;
|
if (!(pte_src & PAGE_PRESENT)) continue;
|
||||||
|
|
||||||
if (!(pte_src & PAGE_WRITABLE)) {
|
if (!(pte_src & PAGE_WRITABLE) || (pte_src & PAGE_MMIO)) {
|
||||||
pt_dst[j] = pt_src[j];
|
pt_dst[j] = pt_src[j];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define PAGE_WRITABLE (1 << 1)
|
#define PAGE_WRITABLE (1 << 1)
|
||||||
#define PAGE_USER (1 << 2)
|
#define PAGE_USER (1 << 2)
|
||||||
#define PAGE_COW (1 << 9)
|
#define PAGE_COW (1 << 9)
|
||||||
|
#define PAGE_MMIO (1 << 10)
|
||||||
|
|
||||||
#define TEMP_KERNPD_VADDR 0xDFF90000
|
#define TEMP_KERNPD_VADDR 0xDFF90000
|
||||||
#define TEMP_TASKPD_VADDR 0xDFFA0000
|
#define TEMP_TASKPD_VADDR 0xDFFA0000
|
||||||
|
|||||||
@@ -25,7 +25,14 @@ void unlock_scheduler() {
|
|||||||
enable_interrupts();
|
enable_interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct registers {
|
||||||
|
uint32_t ds; // push %ds
|
||||||
|
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // pushal
|
||||||
|
uint32_t eip, cs, eflags, useresp, ss; // pushed by cpu
|
||||||
|
} __attribute__((packed)) registers_t;
|
||||||
|
|
||||||
uint32_t switch_context(uint32_t current_esp) {
|
uint32_t switch_context(uint32_t current_esp) {
|
||||||
|
registers_t* regs = (registers_t*)current_esp;
|
||||||
current_process->esp = current_esp;
|
current_process->esp = current_esp;
|
||||||
|
|
||||||
process_t* next_process = current_process->sched_next;
|
process_t* next_process = current_process->sched_next;
|
||||||
@@ -62,8 +69,6 @@ uint32_t switch_context(uint32_t current_esp) {
|
|||||||
if (current_process->flags & PROCESS_FLAG_USER) {
|
if (current_process->flags & PROCESS_FLAG_USER) {
|
||||||
tss.esp0 = current_process->kstack_top;
|
tss.esp0 = current_process->kstack_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return current_process->esp;
|
return current_process->esp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "drivers/serial/serial.h"
|
||||||
#include "lib/memory.h"
|
#include "lib/memory.h"
|
||||||
#include "lib/ringbuf.h"
|
#include "lib/ringbuf.h"
|
||||||
|
|
||||||
@@ -25,11 +26,12 @@ typedef struct registers {
|
|||||||
|
|
||||||
static int32_t sys_exit(int status) {
|
static int32_t sys_exit(int status) {
|
||||||
process_t* task = current_task();
|
process_t* task = current_task();
|
||||||
task->state = STATE_ZOMBIE;
|
task->state = STATE_DEAD;
|
||||||
task->exit_status = status;
|
// task->exit_status = status;
|
||||||
if (task->waiting) {
|
// if (task->waiting) {
|
||||||
wake(task->waiting);
|
// wake(task->waiting);
|
||||||
}
|
// }
|
||||||
|
kprintf("task %d exited with status %d\n", task->pid, status);
|
||||||
exit();
|
exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -212,6 +214,7 @@ static int32_t sys_exec(registers_t* regs, const char* prgm) {
|
|||||||
regs->eip = eip;
|
regs->eip = eip;
|
||||||
regs->useresp = (uint32_t)u_esp;
|
regs->useresp = (uint32_t)u_esp;
|
||||||
|
|
||||||
|
print_serial("returning from exec\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +256,7 @@ static int32_t sys_mmap(int fd) {
|
|||||||
|
|
||||||
if (!(file->node->flags & VFS_CHARDEVICE)) return 0;
|
if (!(file->node->flags & VFS_CHARDEVICE)) return 0;
|
||||||
|
|
||||||
uint32_t map_vaddr = 0x3FF00000;
|
uint32_t map_vaddr = 0x20000000;
|
||||||
return file->node->mmap(file->node, map_vaddr);
|
return file->node->mmap(file->node, map_vaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
const char* shell_prompt = "rocksh> ";
|
const char* shell_prompt = "rocksh> ";
|
||||||
@@ -11,7 +11,7 @@ size_t buf_offset = 0;
|
|||||||
|
|
||||||
char path[256];
|
char path[256];
|
||||||
|
|
||||||
const char* bin_dir = "/bin/";
|
const char* bin_dir = "/usr/bin/";
|
||||||
|
|
||||||
void parse_cmd() {
|
void parse_cmd() {
|
||||||
if (strcmp(buf, "exit") == 0) {
|
if (strcmp(buf, "exit") == 0) {
|
||||||
|
|||||||
@@ -1,74 +1,215 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <sys/video.h>
|
#include <sys/video.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uint8_t magic[2];
|
||||||
|
uint8_t mode;
|
||||||
|
uint8_t charsz;
|
||||||
|
} psf_hdr_t;
|
||||||
|
|
||||||
} font_t;
|
typedef struct {
|
||||||
|
int fd;
|
||||||
|
psf_hdr_t hdr;
|
||||||
|
void* glyphs;
|
||||||
|
} psf_font_t;
|
||||||
|
|
||||||
|
psf_font_t* load_font(const char* path);
|
||||||
|
void free_font(psf_font_t* font);
|
||||||
|
|
||||||
void term_write_char(char c);
|
void term_write_char(char c);
|
||||||
void render_char_at(char c, int x, int y);
|
void render_char(char c);
|
||||||
|
void clear(uint32_t color);
|
||||||
|
void spawn_shell();
|
||||||
|
|
||||||
int spawn_shell();
|
void start_terminal();
|
||||||
|
|
||||||
int ptys;
|
static int ptys;
|
||||||
int ptym;
|
static int ptym;
|
||||||
|
static int vga_fd;
|
||||||
|
|
||||||
void* fb;
|
static void* fb = NULL;
|
||||||
fb_info_t fb_info;
|
static fb_info_t fb_info;
|
||||||
|
|
||||||
int terminal_col = 0;
|
static uint32_t console_row = 0;
|
||||||
int terminal_row = 0;
|
static uint32_t console_col = 0;
|
||||||
|
static uint32_t console_width = 0;
|
||||||
|
static uint32_t console_height = 0;
|
||||||
|
static uint32_t console_text_color = 0;
|
||||||
|
static uint32_t console_backgrnd_color = 0;
|
||||||
|
|
||||||
font_t* terminal_font = NULL;
|
static int shell_pid;
|
||||||
|
|
||||||
|
psf_font_t* terminal_font = NULL;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
int vga_fd = open("/dev/vga");
|
ptym = pty(&ptys);
|
||||||
if (vga_fd == -1) return 1;
|
|
||||||
|
|
||||||
int kbd_fd = open("/dev/kbd");
|
vga_fd = open("/dev/vga");
|
||||||
if (kbd_fd == -1) return 1;
|
if (vga_fd == -1) return 1;
|
||||||
|
|
||||||
int res = ioctl(vga_fd, FBIOGET_INFO, &fb_info);
|
int res = ioctl(vga_fd, FBIOGET_INFO, &fb_info);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mmap(vga_fd);
|
fb = mmap(vga_fd);
|
||||||
|
|
||||||
// if (!spawn_shell()) {
|
terminal_font = load_font("/usr/fonts/kernel_font.psf");
|
||||||
// return 1;
|
if (!terminal_font) {
|
||||||
// }
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console_height = fb_info.height / terminal_font->hdr.charsz;
|
||||||
|
console_width = fb_info.width / 8;
|
||||||
|
console_text_color = 0xFFFFFFFF;
|
||||||
|
console_backgrnd_color = 0xFF6c7482;
|
||||||
|
|
||||||
|
start_terminal();
|
||||||
|
|
||||||
|
free_font(terminal_font);
|
||||||
|
close(vga_fd);
|
||||||
|
close(ptym);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_char_at(char c, int x, int y) {
|
void render_char(char c) {
|
||||||
if (!terminal_font) return;
|
if (!terminal_font) return;
|
||||||
|
uint32_t vga_pitch = fb_info.pitch;
|
||||||
|
uint8_t* glyph = (uint8_t*)terminal_font->glyphs + (c * terminal_font->hdr.charsz);
|
||||||
|
|
||||||
|
uint32_t pixel_y_start = console_row * terminal_font->hdr.charsz;
|
||||||
|
uint32_t pixel_x_start = console_col * 8;
|
||||||
|
|
||||||
|
for (uint32_t y = 0; y < terminal_font->hdr.charsz; y++) {
|
||||||
|
uint8_t bits = glyph[y];
|
||||||
|
uint8_t* row_bytes = (uint8_t*)fb + ((pixel_y_start + y) * vga_pitch);
|
||||||
|
uint32_t* pixel_row = (uint32_t*)row_bytes;
|
||||||
|
|
||||||
|
for (int x = 0; x < 8; x++) {
|
||||||
|
if (bits & (0b10000000 >> x)) {
|
||||||
|
pixel_row[pixel_x_start + x] = console_text_color;
|
||||||
|
} else {
|
||||||
|
pixel_row[pixel_x_start + x] = console_backgrnd_color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void term_write_char(char c) {
|
void spawn_shell() {
|
||||||
|
if ((shell_pid = fork()) == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
int spawn_shell() {
|
|
||||||
ptym = pty(&ptys);
|
|
||||||
|
|
||||||
if (fork() == 0) {
|
|
||||||
close(ptym);
|
close(ptym);
|
||||||
|
close(vga_fd);
|
||||||
|
|
||||||
dup2(ptys, 0);
|
dup2(ptys, 0);
|
||||||
dup2(0, 1);
|
dup2(0, 1);
|
||||||
dup2(0, 2);
|
dup2(0, 2);
|
||||||
|
if (!exec("/usr/bin/rocksh")) exit(1);
|
||||||
if (!exec("/usr/bin/rocksh")) return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(ptys);
|
close(ptys);
|
||||||
dup2(ptym, 0);
|
dup2(ptym, 0);
|
||||||
dup2(0, 1);
|
dup2(0, 1);
|
||||||
dup2(0, 2);
|
dup2(0, 2);
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
void clear(uint32_t color) {
|
||||||
|
for (uint32_t i = 0; i < fb_info.fb_size; i++) {
|
||||||
|
((uint32_t*)fb)[i] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
psf_font_t* load_font(const char* path) {
|
||||||
|
int fd = open(path);
|
||||||
|
if (fd == -1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
psf_hdr_t header;
|
||||||
|
int rd = read(fd, &header, sizeof(psf_hdr_t));
|
||||||
|
if (rd <= 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t num_glyphs = (header.mode & (1 << 0)) ? 512 : 256;
|
||||||
|
uint32_t glyph_sz = header.charsz;
|
||||||
|
size_t glyph_buf_sz = num_glyphs * glyph_sz;
|
||||||
|
|
||||||
|
void* glyphs = malloc(glyph_buf_sz);
|
||||||
|
|
||||||
|
rd = 0;
|
||||||
|
rd = read(fd, glyphs, glyph_buf_sz);
|
||||||
|
if (rd <= 0) {
|
||||||
|
free(glyphs);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
psf_font_t* font = (psf_font_t*)malloc(sizeof(psf_font_t));
|
||||||
|
font->fd = fd;
|
||||||
|
font->hdr = header;
|
||||||
|
font->glyphs = glyphs;
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_font(psf_font_t* font) {
|
||||||
|
close(font->fd);
|
||||||
|
free(font->glyphs);
|
||||||
|
free(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
void term_write_char(char c) {
|
||||||
|
if (!terminal_font) return;
|
||||||
|
|
||||||
|
if (c == '\n') {
|
||||||
|
console_col = 0;
|
||||||
|
console_row++;
|
||||||
|
if (console_row >= console_height) {
|
||||||
|
console_row = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
render_char(c);
|
||||||
|
|
||||||
|
console_col++;
|
||||||
|
if (console_col >= console_width) {
|
||||||
|
console_col = 0;
|
||||||
|
console_row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (console_row >= console_height) {
|
||||||
|
console_row = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_terminal() {
|
||||||
|
spawn_shell();
|
||||||
|
|
||||||
|
clear(console_backgrnd_color);
|
||||||
|
|
||||||
|
int kbd_fd = open("/dev/kbd");
|
||||||
|
if (kbd_fd == -1) return;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
char c;
|
||||||
|
int rd = read(STDIN_FILENO, &c, 1);
|
||||||
|
if (rd > 0) {
|
||||||
|
term_write_char(c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rd = 0;
|
||||||
|
c = 0;
|
||||||
|
rd = read(kbd_fd, &c, 1);
|
||||||
|
if (rd > 0) {
|
||||||
|
write(STDOUT_FILENO, &c, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,5 +4,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void* malloc(size_t size);
|
void* malloc(size_t size);
|
||||||
|
void free(void* ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Binary file not shown.
Reference in New Issue
Block a user