mirror of https://github.com/E-Almqvist/eOS
commit
54337e72e9
@ -1,9 +1,19 @@ |
|||||||
# TO DO |
# TO DO |
||||||
- Multiboot (read end of memory etc) |
- FIX E820 |
||||||
- String interpolation |
- actual gdt |
||||||
|
- CPU freq detection |
||||||
|
- proc? |
||||||
- Screen scrolling |
- Screen scrolling |
||||||
|
- Malloc all kernel code |
||||||
|
- (Random lib: random num from a to b?) |
||||||
|
|
||||||
## Long term |
## Userland????????? |
||||||
- Get rust lang to work/switch to rust |
- Shell: input, execute |
||||||
- Shell? |
|
||||||
- Improve memory management |
- prog/time: show time |
||||||
|
- prog/date: show date |
||||||
|
- prog/mem: show amount of memory |
||||||
|
- prog/bitmap: show phys bitmap |
||||||
|
|
||||||
|
# Long term |
||||||
|
- Rust? |
||||||
|
@ -1,49 +1,89 @@ |
|||||||
; SRs to find memory size and leave it as a "note" for the kernel |
; SRs to find memory size and leave it as a "note" for the kernel |
||||||
|
|
||||||
mmap_probe: ; literally just test the memory boundaries |
; mmap_probe: ; literally just test the memory boundaries |
||||||
push eax |
; push eax |
||||||
push ebx |
; push ebx |
||||||
push edx |
; push edx |
||||||
push ebp |
; push ebp |
||||||
|
; |
||||||
|
; mov ebp, esi |
||||||
|
; add esi, 0x00000ff |
||||||
|
; and esi, ~0x00000ff |
||||||
|
; mmap_probe_addr: |
||||||
|
; |
||||||
|
; mmap_probe_done: |
||||||
|
|
||||||
mov ebp, esi |
e820_stats_addr equ 0x9820 |
||||||
add esi, 0x00000ff |
|
||||||
and esi, ~0x00000ff |
|
||||||
mmap_probe_addr: |
|
||||||
|
|
||||||
mmap_probe_done: |
e820: |
||||||
|
mov di, e820_stats_addr + 4 |
||||||
mmap_e820: |
|
||||||
mov di, 0x8004 |
|
||||||
mov ebx, 0 ; Must be 0 |
mov ebx, 0 ; Must be 0 |
||||||
mov bp, 0 ; entry count |
mov bp, 0 ; entry count |
||||||
|
|
||||||
mov eax, 0xe820 ; function reg |
mov eax, 0xe820 ; function reg |
||||||
mov edx, 'SMAP' ; function sig |
mov edx, 'SMAP' ; function sig |
||||||
|
|
||||||
; TODO: update es:di to e820_dt |
|
||||||
mov [es:di + 20], dword 1 ; fill |
mov [es:di + 20], dword 1 ; fill |
||||||
mov ecx, 24 ; ask for 24 bytes |
mov ecx, 24 ; ask for 24 bytes |
||||||
int 0x15 ; Do the interupt |
int 0x15 ; Do the interupt |
||||||
|
|
||||||
; carry flag = (un)supported function |
; carry flag = (un)supported function |
||||||
jc mmap_e820_fail ; Try probing instead |
jc e820_fail_unsup ; TODO: Try probing instead |
||||||
|
|
||||||
cmp eax, edx ; eax should be = 'SMAP' |
cmp eax, edx ; eax should be = 'SMAP' |
||||||
jne mmap_e820_fail ; if not then fail |
jne e820_fail_smap ; if not then fail |
||||||
|
|
||||||
test ebx, ebx |
test ebx, ebx ; no entries |
||||||
je mmap_e820_fail |
je e820_fail_noent |
||||||
|
|
||||||
mmap_e820_fail: |
e820_lp: |
||||||
stc |
mov eax, 0xe820 |
||||||
|
mov [es:di + 20], dword 1 |
||||||
|
mov ecx, 24 |
||||||
|
int 0x15 |
||||||
|
jc e820_finish ; carry => finished -> save entry count |
||||||
|
|
||||||
|
e820_iter: |
||||||
|
; skip 0 entries |
||||||
|
jcxz e820_skip |
||||||
|
|
||||||
|
; check resp |
||||||
|
cmp cl, 20 |
||||||
|
jbe e820_ntxt |
||||||
|
|
||||||
|
; check the ignore bit |
||||||
|
test byte [es:di + 20], 1 |
||||||
|
je e820_skip |
||||||
|
|
||||||
|
e820_ntxt: |
||||||
|
mov ecx, [es:di + 8] ; lower mem length |
||||||
|
; test for 0 |
||||||
|
or ecx, [es:di + 12] |
||||||
|
jz e820_skip |
||||||
|
|
||||||
|
; next entry |
||||||
|
inc bp |
||||||
|
add di, 24 |
||||||
|
|
||||||
|
e820_skip: |
||||||
|
test ebx, ebx ; of ebx = 0 then complete |
||||||
|
jne e820_lp |
||||||
|
|
||||||
|
e820_finish: |
||||||
|
mov [e820_stats_addr], bp ; save entry count at e820_ent |
||||||
|
clc |
||||||
ret |
ret |
||||||
|
|
||||||
e820_dt_start: |
e820_fail_unsup: |
||||||
e820_low: dd 0 |
mov [e820_stats_addr], byte -1 |
||||||
e820_high: dd 0 |
jmp e820_fail |
||||||
e820_len_low: dd 0 |
e820_fail_smap: |
||||||
e820_len_high: dd 0 |
mov [e820_stats_addr], byte -2 |
||||||
e820_type: dd 0 |
jmp e820_fail |
||||||
e820_dt_end: |
e820_fail_noent: |
||||||
|
mov [e820_stats_addr], byte -3 |
||||||
|
jmp e820_fail |
||||||
|
|
||||||
|
e820_fail: |
||||||
|
stc |
||||||
|
ret |
||||||
|
@ -1,23 +1,76 @@ |
|||||||
#include "kernel.h" |
#include "kernel.h" |
||||||
|
|
||||||
|
void print_kernel_motd() { |
||||||
|
printalign(" ___ ____ ", BANNER_COLOR, MIDDLE); |
||||||
|
printalign(" ___ / _ \\/ ___| ", BANNER_COLOR, MIDDLE); |
||||||
|
printalign(" / _ \\ | | \\___ \\ ", BANNER_COLOR, MIDDLE); |
||||||
|
printalign("| __/ |_| |___) | A x86 operating system,", BANNER_COLOR, MIDDLE); |
||||||
|
printalign(" \\___|\\___/|____/ licenced under GPL-2.0", BANNER_COLOR, MIDDLE); |
||||||
|
|
||||||
|
println(""); |
||||||
|
printalign("Fun fact: e = lim[h->0] (1+h)^(1/h)", DEFAULT_COLOR, MIDDLE); |
||||||
|
printalign("Created by E. Almqvist", DEFAULT_COLOR, MIDDLE); |
||||||
|
println(""); |
||||||
|
} |
||||||
|
|
||||||
|
void print_kernel_stats() { |
||||||
|
char* buf; |
||||||
|
// Memory stats
|
||||||
|
print("MEMORY BITMAP: ", 0x0f); |
||||||
|
buf = itoa(get_bitmap(), buf, 2); |
||||||
|
println(buf, DEFAULT_COLOR); |
||||||
|
|
||||||
|
println(""); |
||||||
|
|
||||||
|
println("BIOS E820", 0x0f); |
||||||
|
print("Loaded Entries: ", DEFAULT_COLOR); |
||||||
|
uint entries = get_phys_mem_size(); |
||||||
|
buf = itoa(entries, buf, 10); |
||||||
|
println(buf, DEFAULT_COLOR); |
||||||
|
|
||||||
|
print("Physical Memory Size: "); |
||||||
|
println("?", DEFAULT_COLOR); |
||||||
|
|
||||||
|
println(""); |
||||||
|
|
||||||
|
// VGA stats
|
||||||
|
println("Display (VGA)", 0x0f); |
||||||
|
print("Memory Range: ", DEFAULT_COLOR); |
||||||
|
buf = itoa(VGA_ADDRESS, buf, 16); |
||||||
|
print(buf, DEFAULT_COLOR); |
||||||
|
print(" - "); |
||||||
|
buf = itoa(VGA_ADDRESS_MAX, buf, 16); |
||||||
|
println(buf, DEFAULT_COLOR); |
||||||
|
|
||||||
|
print("Screen Dimensions: ", DEFAULT_COLOR); |
||||||
|
buf = itoa(MAX_COLS, buf, 10); |
||||||
|
print(buf, DEFAULT_COLOR); |
||||||
|
print("x"); |
||||||
|
buf = itoa(MAX_ROWS, buf, 10); |
||||||
|
println(buf, DEFAULT_COLOR); |
||||||
|
|
||||||
|
uint ticks = 0; |
||||||
|
while (true) { |
||||||
|
set_cursor_pos(0, 20); |
||||||
|
buf = itoa(ticks, buf, 10); |
||||||
|
printalign(buf, 0x0f, MIDDLE); |
||||||
|
++ticks; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
void kernel_init() { |
void kernel_init() { |
||||||
vga_init(); // Initialize the screen first
|
vga_init(); // Initialize the screen first
|
||||||
// i.e. clear the screen et cetera.
|
// i.e. clear the screen et cetera.
|
||||||
|
|
||||||
println("Kernel loaded", SUCCESS_COLOR); |
|
||||||
|
|
||||||
// Allocate VGA memory range
|
// Allocate VGA memory range
|
||||||
pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
|
pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
|
||||||
|
|
||||||
// ENABLE PAGING
|
// ENABLE PAGING
|
||||||
// TODO: make this work
|
// TODO: make this work
|
||||||
// enable_paging();
|
// enable_paging();
|
||||||
|
|
||||||
println(""); |
clear_screen(); |
||||||
char* title = "eOS - lim[h->0] (1+h)^(1/h) OS"; |
print_kernel_motd(); |
||||||
println(title, DEFAULT_COLOR); |
print_kernel_stats(); |
||||||
|
|
||||||
char* subtitle = "A x86 operating system, licenced under GPL-2.0"; |
|
||||||
println(subtitle, DEFAULT_COLOR); |
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -1,11 +1,11 @@ |
|||||||
|
|
||||||
#include "memory.h" |
#include "memory.h" |
||||||
#include "paging.h" |
#include "paging.h" |
||||||
#include "../drivers/vga.h" |
#include "../drivers/vga.h" |
||||||
#include "../lib/str.h" |
#include "../lib/str.h" |
||||||
#include "../lib/conv.h" |
#include "../lib/conv.h" |
||||||
|
|
||||||
#define STATUS_TEXT_COLOR 0x0f |
#define BANNER_COLOR 0x0c |
||||||
|
|
||||||
void init(); |
void print_kernel_motd(); |
||||||
void display_status(char*, unsigned int);
|
void print_kernel_stats(); |
||||||
|
void kernel_init(); |
||||||
|
@ -1,18 +1,48 @@ |
|||||||
#include "conv.h" |
#include "conv.h" |
||||||
#include "../drivers/vga.h" |
#include "../drivers/vga.h" |
||||||
|
|
||||||
char* int_to_str(int i, char* buf) { |
char* itoa( int value, char * str, int base ) { |
||||||
ulong num = (ulong)i; // convert to ulong
|
char* rc; |
||||||
uint len = ulong_len(num); // number of digits
|
char* ptr; |
||||||
|
char* low; |
||||||
|
|
||||||
*(buf+len) = '\0'; // add a "end-of-string" at the end
|
// Check for supported base.
|
||||||
|
if( base < 2 || base > 36 ) { |
||||||
|
*str = '\0'; |
||||||
|
return str; |
||||||
|
} |
||||||
|
rc = ptr = str; |
||||||
|
|
||||||
|
switch(base) { |
||||||
|
case 16: |
||||||
|
*ptr++ = '0'; |
||||||
|
*ptr++ = 'x'; |
||||||
|
case 10: |
||||||
|
if(value < 0) |
||||||
|
*ptr++ = '-'; |
||||||
|
} |
||||||
|
|
||||||
|
// if(value < 0 && base == 10 ) // sign
|
||||||
|
// *ptr++ = '-';
|
||||||
|
|
||||||
|
// Remember where the numbers start.
|
||||||
|
low = ptr; |
||||||
|
|
||||||
|
// The actual conversion.
|
||||||
|
do { |
||||||
|
// Modulo is negative for negative value. This trick makes abs() unnecessary.
|
||||||
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base]; |
||||||
|
value /= base; |
||||||
|
} while(value); |
||||||
|
|
||||||
|
// Terminating the string.
|
||||||
|
*ptr-- = '\0'; |
||||||
|
|
||||||
int j; |
// Invert the numbers.
|
||||||
for(j = 0; j < len; j++) { // iterate over each digit and assign it to the buffer
|
while ( low < ptr ) { |
||||||
// super dangerous memory write
|
char tmp = *low; |
||||||
*(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char
|
*low++ = *ptr; |
||||||
println(*(buf+j), 0xc0); |
*ptr-- = tmp; |
||||||
} |
} |
||||||
|
return rc; |
||||||
return buf; |
|
||||||
} |
} |
||||||
|
@ -1,6 +1,4 @@ |
|||||||
#include "types.h" |
#include "types.h" |
||||||
#include "util.h" |
#include "util.h" |
||||||
|
|
||||||
#define ASCII_OFFSET 0x30 |
char* itoa(int, char*, int); |
||||||
|
|
||||||
char* int_to_str(int i, char* buf); |
|
||||||
|
Before Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in new issue