Added shared/kstdlib.c:mlog and adjacent definitions
This commit is contained in:
parent
79496c1299
commit
da1c639f9f
3
makefile
3
makefile
|
|
@ -1,6 +1,7 @@
|
||||||
CC := gcc
|
CC := gcc
|
||||||
AS := nasm
|
AS := nasm
|
||||||
CFLAGS:=-g -c -m32 -fno-pie -mno-sse -O3 -D __bits__=32 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-incompatible-pointer-types -Wno-address-of-packed-member -Wno-discarded-qualifiers -fno-stack-protector -mno-red-zone -mno-sse -mno-sse2 -ffreestanding -nostdlib -mno-mmx
|
CFLAGS:=-g -c -m32 -fno-pie -mno-sse -O3 -D __bits__=32 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-incompatible-pointer-types -Wno-address-of-packed-member -Wno-discarded-qualifiers -fno-stack-protector -mno-red-zone -mno-sse -mno-sse2 -ffreestanding -nostdlib -mno-mmx
|
||||||
|
CFLAGS_MODULE:=-g -c -m32 -mno-sse -O3 -D __bits__=32 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-incompatible-pointer-types -Wno-address-of-packed-member -Wno-discarded-qualifiers -fno-stack-protector -mno-red-zone -mno-sse -mno-sse2 -ffreestanding -nostdlib -mno-mmx
|
||||||
BL_ASFLAGS := -f bin
|
BL_ASFLAGS := -f bin
|
||||||
SRCS := $(wildcard src/kernel/*/*.c)
|
SRCS := $(wildcard src/kernel/*/*.c)
|
||||||
OBJS := $(patsubst src/kernel/%.c, bin/kernel/%.o, $(SRCS))
|
OBJS := $(patsubst src/kernel/%.c, bin/kernel/%.o, $(SRCS))
|
||||||
|
|
@ -21,7 +22,7 @@ bootloader:
|
||||||
# kernel: $(OBJS)
|
# kernel: $(OBJS)
|
||||||
kernel:
|
kernel:
|
||||||
nasm src/kernel/entry.s -o bin/kernel/entry.o -f elf32
|
nasm src/kernel/entry.s -o bin/kernel/entry.o -f elf32
|
||||||
gcc src/kmodules/disk_driver.c $(CFLAGS) -o bin/modules/disk_driver.o -m32
|
gcc src/kmodules/disk_driver.c $(CFLAGS_MODULE) -o bin/modules/disk_driver.o -m32
|
||||||
sh c_build_helper.sh
|
sh c_build_helper.sh
|
||||||
nasm src/kernel/arch_i386/idt.s -o bin/kernel/idt.o -felf32
|
nasm src/kernel/arch_i386/idt.s -o bin/kernel/idt.o -felf32
|
||||||
# ld -T linker.ld bin/kernel/entry.o bin/kernel/*.o -melf_i386
|
# ld -T linker.ld bin/kernel/entry.o bin/kernel/*.o -melf_i386
|
||||||
|
|
|
||||||
|
|
@ -353,12 +353,13 @@ part_2:
|
||||||
call open_file
|
call open_file
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je .start32_no_fs
|
je .start32_no_fs
|
||||||
|
mov [fs_module_struct.size], edx
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
and edx, 0xfffffc00
|
and edx, 0xfffffc00
|
||||||
add edx, 0x1000
|
add edx, 0x1000
|
||||||
add [kload_paddr], edx
|
add [kload_paddr], edx
|
||||||
|
|
||||||
mov edi, edx
|
mov edi, [kload_paddr]
|
||||||
mov [fs_module_struct.ptr], edi
|
mov [fs_module_struct.ptr], edi
|
||||||
call read_file
|
call read_file
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ int pm_init(kernel_info_t *kernel_info){
|
||||||
for(uint32_t i = 0; i < mmap_count; i++){
|
for(uint32_t i = 0; i < mmap_count; i++){
|
||||||
pm_map[i] = 0xff;
|
pm_map[i] = 0xff;
|
||||||
}
|
}
|
||||||
|
mlog("KERNEL(MEMORY)", " BASE | LENGTH | TYPE\n", MLOG_PRINT);
|
||||||
for(uint32_t i = 0; i < kernel_info->mmap_entry_count; i++){
|
for(uint32_t i = 0; i < kernel_info->mmap_entry_count; i++){
|
||||||
for(uint32_t j = 0; j < (mmap[i].entry_length >> 12); j++){
|
for(uint32_t j = 0; j < (mmap[i].entry_length >> 12); j++){
|
||||||
if(mmap[i].entry_base + (j << 12) <= mmap[i-1].entry_base + mmap[i-1].entry_length){
|
if(mmap[i].entry_base + (j << 12) <= mmap[i-1].entry_base + mmap[i-1].entry_length){
|
||||||
|
|
@ -54,9 +55,9 @@ int pm_init(kernel_info_t *kernel_info){
|
||||||
// printf("%d, %x, %d\n", j >> 3, pm_map[(mmap[i].entry_base >> 12 ) + (j >> 3)], mmap[i].type);
|
// printf("%d, %x, %d\n", j >> 3, pm_map[(mmap[i].entry_base >> 12 ) + (j >> 3)], mmap[i].type);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
printf("|%x|", mmap[i].entry_base);
|
mlog("KERNEL(MEMORY)", " %x|%x|%d\n", MLOG_PRINT, (uint32_t)mmap[i].entry_base, (uint32_t)mmap[i].entry_length, mmap[i].type);
|
||||||
printf("%x", mmap[i].entry_length);
|
// printf("%x", mmap[i].entry_length);
|
||||||
printf("|%d |\n", mmap[i].type);
|
// printf("|%d |\n", mmap[i].type);
|
||||||
}
|
}
|
||||||
for(uint32_t i = 0; i < 512; i++){
|
for(uint32_t i = 0; i < 512; i++){
|
||||||
pm_reserve(i * 4096);
|
pm_reserve(i * 4096);
|
||||||
|
|
|
||||||
|
|
@ -43,30 +43,40 @@ void debug_puts(char *string){
|
||||||
outb(com_ports[0], *string++);
|
outb(com_ports[0], *string++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void printf(char *str, ...){
|
||||||
void printf(char *string, ...){
|
|
||||||
va_list vars;
|
va_list vars;
|
||||||
va_start(vars, string);
|
va_start(vars, str);
|
||||||
|
vprintf(str, vars);
|
||||||
|
va_end(vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vprintf(char *string, va_list vars){
|
||||||
while(*string){
|
while(*string){
|
||||||
if(*string == '%'){
|
if(*string == '%'){
|
||||||
|
string++;
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
|
char *ptr = 0;
|
||||||
char numb[12];
|
char numb[12];
|
||||||
switch(*(string + 1)){
|
switch(*string){
|
||||||
case 'd':
|
case 'd':
|
||||||
string += 2;
|
string++;
|
||||||
num = va_arg(vars, int32_t);
|
num = va_arg(vars, int32_t);
|
||||||
itoa(num, numb, 10);
|
itoa(num, numb, 10);
|
||||||
debug_puts(numb);
|
debug_puts(numb);
|
||||||
continue;
|
continue;
|
||||||
case 'x':
|
case 'x':
|
||||||
// debug_puts(":3");
|
// debug_puts(":3");
|
||||||
string += 2;
|
string++;
|
||||||
num = va_arg(vars, int32_t);
|
num = va_arg(vars, int32_t);
|
||||||
// char hnumb[12];
|
// char hnumb[12];
|
||||||
itoa(num, numb, 16);
|
itoa(num, numb, 16);
|
||||||
strpad(numb, '0', 8);
|
strpad(numb, '0', 8);
|
||||||
debug_puts(numb);
|
debug_puts(numb);
|
||||||
continue;
|
continue;
|
||||||
|
case 's':
|
||||||
|
string++;
|
||||||
|
ptr = va_arg(vars, char *);
|
||||||
|
printf(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outb(com_ports[0], *string);
|
outb(com_ports[0], *string);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
void init_serial();
|
void init_serial();
|
||||||
void serial_writeb(uint8_t port, uint8_t data);
|
void serial_writeb(uint8_t port, uint8_t data);
|
||||||
void serial_writereg(uint8_t port, uint8_t reg, uint8_t data);
|
void serial_writereg(uint8_t port, uint8_t reg, uint8_t data);
|
||||||
|
|
@ -7,3 +8,4 @@ uint8_t serial_readreg(uint8_t port, uint8_t reg);
|
||||||
uint8_t serial_readb(uint8_t port);
|
uint8_t serial_readb(uint8_t port);
|
||||||
void debug_puts(char *string);
|
void debug_puts(char *string);
|
||||||
void printf(char *string, ...);
|
void printf(char *string, ...);
|
||||||
|
void vprintf(char *string, va_list vars);
|
||||||
|
|
@ -10,6 +10,10 @@
|
||||||
void pid0(){
|
void pid0(){
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
|
void sysinit(){
|
||||||
|
|
||||||
|
for(;;);
|
||||||
|
}
|
||||||
extern void kmain(kernel_info_t *kernel_info){
|
extern void kmain(kernel_info_t *kernel_info){
|
||||||
init_serial();
|
init_serial();
|
||||||
pm_init(kernel_info);
|
pm_init(kernel_info);
|
||||||
|
|
@ -19,12 +23,9 @@ extern void kmain(kernel_info_t *kernel_info){
|
||||||
pic_setmask(0xfe, PIC1_DATA);
|
pic_setmask(0xfe, PIC1_DATA);
|
||||||
//TODO: Map and load filesystem and disk modules
|
//TODO: Map and load filesystem and disk modules
|
||||||
//TODO: Start Initial Process
|
//TODO: Start Initial Process
|
||||||
|
|
||||||
printf("%x\n", *(uint32_t *)kernel_info->loaded_modules->ptr);
|
|
||||||
printf("%x", kernel_info->loaded_modules->size);
|
|
||||||
|
|
||||||
init_scheduler();
|
init_scheduler();
|
||||||
thread_start(pid0);
|
thread_start(pid0);
|
||||||
|
thread_start(sysinit);
|
||||||
enable_interrupts();
|
enable_interrupts();
|
||||||
for(;;);
|
for(;;);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "kstdlib.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
char* log_info_types[] = {
|
||||||
|
"",
|
||||||
|
":DEBUG",
|
||||||
|
"",
|
||||||
|
":WARNING",
|
||||||
|
":ERROR"
|
||||||
|
};
|
||||||
|
|
||||||
|
void mlog(char *module, char *str, uint32_t type, ...){
|
||||||
|
va_list vars;
|
||||||
|
va_start(vars, type);
|
||||||
|
if(!type || type > 4){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("[ %s %s]", module, log_info_types[type]);
|
||||||
|
vprintf(str, vars);
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
// #include "memory.h"
|
// #include "memory.h"
|
||||||
|
#include "stdint.h"
|
||||||
#include "../drivers/serial.h"
|
#include "../drivers/serial.h"
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
|
|
||||||
|
#define MLOG_DEBUG 1
|
||||||
|
#define MLOG_PRINT 2
|
||||||
|
#define MLOG_WARN 3
|
||||||
|
#define MLOG_ERR 4
|
||||||
|
|
||||||
typedef struct module_linked_list{
|
typedef struct module_linked_list{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
@ -22,6 +28,8 @@ typedef struct kernel_info{
|
||||||
// uint32_t loaded_module_count;
|
// uint32_t loaded_module_count;
|
||||||
}__attribute__((packed)) kernel_info_t;
|
}__attribute__((packed)) kernel_info_t;
|
||||||
|
|
||||||
|
void mlog(char *module, char *str, uint32_t type, ...);
|
||||||
|
|
||||||
|
|
||||||
#define MODULE_TYPE_DISK 1
|
#define MODULE_TYPE_DISK 1
|
||||||
#define MODULE_TYPE_FS 2
|
#define MODULE_TYPE_FS 2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue