Merge branch 'master' into rust

rust
E. Almqvist 3 years ago
commit 54337e72e9
  1. 24
      TODO.md
  2. 94
      bootloader/bios/memory.asm
  3. 16
      bootloader/bootloader.asm
  4. 4
      drivers/vga.c
  5. 73
      kernel/kernel.c
  6. 8
      kernel/kernel.h
  7. 12
      kernel/memory.c
  8. 5
      kernel/memory.h
  9. 52
      lib/conv.c
  10. 4
      lib/conv.h
  11. BIN
      preview.png

@ -1,9 +1,19 @@
# TO DO
- Multiboot (read end of memory etc)
- String interpolation
# TO DO
- FIX E820
- actual gdt
- CPU freq detection
- proc?
- Screen scrolling
- Malloc all kernel code
- (Random lib: random num from a to b?)
## Long term
- Get rust lang to work/switch to rust
- Shell?
- Improve memory management
## Userland?????????
- Shell: input, execute
- 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
mmap_probe: ; literally just test the memory boundaries
push eax
push ebx
push edx
push ebp
; mmap_probe: ; literally just test the memory boundaries
; push eax
; push ebx
; push edx
; push ebp
;
; mov ebp, esi
; add esi, 0x00000ff
; and esi, ~0x00000ff
; mmap_probe_addr:
;
; mmap_probe_done:
mov ebp, esi
add esi, 0x00000ff
and esi, ~0x00000ff
mmap_probe_addr:
e820_stats_addr equ 0x9820
mmap_probe_done:
mmap_e820:
mov di, 0x8004
e820:
mov di, e820_stats_addr + 4
mov ebx, 0 ; Must be 0
mov bp, 0 ; entry count
mov eax, 0xe820 ; function reg
mov edx, 'SMAP' ; function sig
; TODO: update es:di to e820_dt
mov [es:di + 20], dword 1 ; fill
mov ecx, 24 ; ask for 24 bytes
int 0x15 ; Do the interupt
; 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'
jne mmap_e820_fail ; if not then fail
jne e820_fail_smap ; if not then fail
test ebx, ebx
je mmap_e820_fail
test ebx, ebx ; no entries
je e820_fail_noent
mmap_e820_fail:
stc
e820_lp:
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
e820_dt_start:
e820_low: dd 0
e820_high: dd 0
e820_len_low: dd 0
e820_len_high: dd 0
e820_type: dd 0
e820_dt_end:
e820_fail_unsup:
mov [e820_stats_addr], byte -1
jmp e820_fail
e820_fail_smap:
mov [e820_stats_addr], byte -2
jmp e820_fail
e820_fail_noent:
mov [e820_stats_addr], byte -3
jmp e820_fail
e820_fail:
stc
ret

@ -5,7 +5,7 @@
mov [BOOT_DRIVE], dl
; Move the stack pointer somewhere safe
mov bp, 0x9000 ; move it to 0x9000
mov bp, 0xe000
mov sp, bp
; Load kernel into memory
@ -35,15 +35,15 @@
; Switching to PM
[bits 16]
pm_preinit:
call mmap_e820 ; Map the physical memory
cli ; Switch interupts
; Do stats before mode switch
call e820 ; Map the physical memory
; PM prep stuff
cli ; Switch interupts
lgdt [gdt_descriptor] ; Tell the CPU about the GDT
mov eax, cr0 ; Set first bit of the CR0 register
or eax, 0x1 ; to 1
mov cr0, eax ; Update the control register
mov eax, cr0 ; Set first bit of the CR0 register
or eax, 0x1 ; to 1
mov cr0, eax ; Update the control register
; Initialize PM
jmp GDT_CODE_SEG:pm_init

@ -16,9 +16,9 @@ void vga_init() {
// Clear screen
// clear_row(0);
clear_screen();
// clear_screen();
set_cursor_pos(0, 0);
//set_cursor_pos(0, 0);
}
/*

@ -1,23 +1,76 @@
#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() {
vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera.
println("Kernel loaded", SUCCESS_COLOR);
// i.e. clear the screen et cetera.
// Allocate VGA memory range
pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range
// ENABLE PAGING
// TODO: make this work
// enable_paging();
println("");
char* title = "eOS - lim[h->0] (1+h)^(1/h) OS";
println(title, DEFAULT_COLOR);
char* subtitle = "A x86 operating system, licenced under GPL-2.0";
println(subtitle, DEFAULT_COLOR);
clear_screen();
print_kernel_motd();
print_kernel_stats();
}

@ -1,11 +1,11 @@
#include "memory.h"
#include "paging.h"
#include "../drivers/vga.h"
#include "../lib/str.h"
#include "../lib/conv.h"
#define STATUS_TEXT_COLOR 0x0f
#define BANNER_COLOR 0x0c
void init();
void display_status(char*, unsigned int);
void print_kernel_motd();
void print_kernel_stats();
void kernel_init();

@ -22,6 +22,17 @@
static int bitmap = 0;
static uint last_block;
uint get_phys_mem_size() {
// TODO: read actual mappings
uint entry_count = (uint) *BIOS_E820;
return entry_count;
}
int get_bitmap() {
return bitmap;
}
void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap
int bitmask = 1 << bit;
@ -31,7 +42,6 @@ void mod_bitmap(uint bit, uint bflag) {
bitmap = (((bitmap & ~bitmask)) | (bflag << bit));
}
pointer block_alloc(uint blockidx) {
int block_bflag;
block_bflag = CHECK_BITMAP(bitmap, blockidx);

@ -1,5 +1,7 @@
#include "../lib/types.h"
#define BIOS_E820 (char*)0x9820
#define BLOCK_SIZE 1024 // 1 KiB
#define MAX_BLOCK_COUNT 32 // placeholder
#define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE)
@ -11,6 +13,7 @@
// void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager
int get_bitmap();
void mod_bitmap(uint bit, uint flag);
pointer block_alloc(uint blockidx); // allocate a block
@ -23,3 +26,5 @@ void pm_malloc_range(ulong start, ulong end, bool force); // allocate a range of
pointer pm_malloc(uint block_count); // allocate some blocks
void pm_free(int* p); // free a var (if allocated with pm_malloc)
uint get_phys_mem_size(); // physical memory size with e820 left by the bootloader

@ -1,18 +1,48 @@
#include "conv.h"
#include "../drivers/vga.h"
char* int_to_str(int i, char* buf) {
ulong num = (ulong)i; // convert to ulong
uint len = ulong_len(num); // number of digits
char* itoa( int value, char * str, int base ) {
char* rc;
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;
for(j = 0; j < len; j++) { // iterate over each digit and assign it to the buffer
// super dangerous memory write
*(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char
println(*(buf+j), 0xc0);
// Invert the numbers.
while ( low < ptr ) {
char tmp = *low;
*low++ = *ptr;
*ptr-- = tmp;
}
return buf;
return rc;
}

@ -1,6 +1,4 @@
#include "types.h"
#include "util.h"
#define ASCII_OFFSET 0x30
char* int_to_str(int i, char* buf);
char* itoa(int, char*, int);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Loading…
Cancel
Save