Load the C++ kernel directly after the micro kernel

This commit is contained in:
Baptiste Wicht 2013-10-27 15:30:25 +01:00
parent 11451dd669
commit 030fb53985
9 changed files with 63 additions and 15 deletions

View File

@ -8,9 +8,10 @@ bootloader.bin: src/bootloader/bootloader.asm
micro_kernel.bin: $(KERNEL_SRC) $(KERNEL_UTILS_SRC)
nasm -w+all -f bin -o micro_kernel.bin src/micro_kernel.asm
nasm -D DEBUG -g -w+all -f elf64 -o micro_kernel.g src/micro_kernel.asm
kernel.o: src/kernel.cpp
g++ -O2 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding -c src/kernel.cpp -o kernel.o
g++ -masm=intel -O2 -std=c++11 -Wall -Wextra -fno-exceptions -fno-rtti -ffreestanding -c src/kernel.cpp -o kernel.o
kernel.bin: kernel.o
g++ -std=c++11 -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o

16
addresses.bash Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
function generate_address {
address=`readelf --symbols micro_kernel.g | grep $1 | xargs | cut -d ' ' -f 2`
hex_address="0x$address"
hex_offset=`echo "obase=16; $(($hex_address+0x1000))" | bc`
echo "#define asm_$1 0x$hex_offset" >> src/addresses.hpp
}
echo "#ifndef ADDRESSES_H" > src/addresses.hpp
echo "#define ADDRESSES_H" >> src/addresses.hpp
generate_address "register_irq_handler"
echo "#endif" >> src/addresses.hpp

View File

@ -1,5 +1,5 @@
#!/bin/bash
size=`stat -c%s kernel.bin`
let filler_size=512-$size
let filler_size=1024-$size
dd if=/dev/zero of=filler.bin bs=1 count=$filler_size

BIN
micro_kernel.g Normal file

Binary file not shown.

4
src/addresses.hpp Normal file
View File

@ -0,0 +1,4 @@
#ifndef ADDRESSES_H
#define ADDRESSES_H
#define asm_register_irq_handler 0x272E
#endif

View File

@ -64,7 +64,7 @@ rm_start:
; Loading the assembly kernel from floppy
ASM_KERNEL_BASE equ 0x100 ; 0x0100:0x0 = 0x1000
asm_sectors equ 0x21 ; sectors to read
asm_sectors equ 0x22 ; sectors to read
bootdev equ 0x0
mov ax, ASM_KERNEL_BASE

View File

@ -573,9 +573,7 @@ load_command:
call 0x5000
jmp $
call clear_command
;jmp $
ret

View File

@ -1,18 +1,45 @@
void k_print_line(const char* string);
void k_print(const char* string);
#include "addresses.hpp"
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
uint8_t in_byte(uint16_t _port){
uint8_t rv;
__asm__ __volatile__ ("in %0, %1" : "=a" (rv) : "dN" (_port));
return rv;
}
void out_byte (uint16_t _port, uint8_t _data){
__asm__ __volatile__ ("out %0, %1" : : "dN" (_port), "a" (_data));
}
void __attribute__((naked)) keyboard_handler(){
in_byte(0x60);
k_print("key");
}
long current_line = 0;
long current_column = 0;
extern "C"
void __attribute__ ((section ("main_section"))) kernel_main(){
k_print("thor> ");
//TODO Register keyword handler
asm ("mov r8, 1; mov r9, %0; call %1"
:
: "i" (&keyboard_handler), "i" (asm_register_irq_handler)
: "r8", "r9"
);
//while(true);
return;
}
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
enum vga_color {
BLACK = 0,
BLUE = 1,
@ -32,9 +59,6 @@ enum vga_color {
WHITE = 15,
};
long current_line = 0;
long current_column = 0;
uint8_t make_color(vga_color fg, vga_color bg){
return fg | bg << 4;
}

View File

@ -1,5 +1,8 @@
[BITS 16]
%ifndef DEBUG
[ORG 0x1000]
%endif
jmp _start
@ -98,11 +101,13 @@ lm_start:
call install_timer
; Enter the shell
call shell_start
call 0x5000
jmp $
; Enter the shell
;call shell_start
; Includes
%include "src/utils/macros.asm"