mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-11 13:35:03 -04:00
Load the C++ kernel directly after the micro kernel
This commit is contained in:
parent
11451dd669
commit
030fb53985
3
Makefile
3
Makefile
@ -8,9 +8,10 @@ bootloader.bin: src/bootloader/bootloader.asm
|
|||||||
|
|
||||||
micro_kernel.bin: $(KERNEL_SRC) $(KERNEL_UTILS_SRC)
|
micro_kernel.bin: $(KERNEL_SRC) $(KERNEL_UTILS_SRC)
|
||||||
nasm -w+all -f bin -o micro_kernel.bin src/micro_kernel.asm
|
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
|
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
|
kernel.bin: kernel.o
|
||||||
g++ -std=c++11 -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o
|
g++ -std=c++11 -T linker.ld -o kernel.bin.o -ffreestanding -O2 -nostdlib kernel.o
|
||||||
|
16
addresses.bash
Normal file
16
addresses.bash
Normal 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
|
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
size=`stat -c%s kernel.bin`
|
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
|
dd if=/dev/zero of=filler.bin bs=1 count=$filler_size
|
||||||
|
BIN
micro_kernel.g
Normal file
BIN
micro_kernel.g
Normal file
Binary file not shown.
4
src/addresses.hpp
Normal file
4
src/addresses.hpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#ifndef ADDRESSES_H
|
||||||
|
#define ADDRESSES_H
|
||||||
|
#define asm_register_irq_handler 0x272E
|
||||||
|
#endif
|
@ -64,7 +64,7 @@ rm_start:
|
|||||||
; Loading the assembly kernel from floppy
|
; Loading the assembly kernel from floppy
|
||||||
|
|
||||||
ASM_KERNEL_BASE equ 0x100 ; 0x0100:0x0 = 0x1000
|
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
|
bootdev equ 0x0
|
||||||
|
|
||||||
mov ax, ASM_KERNEL_BASE
|
mov ax, ASM_KERNEL_BASE
|
||||||
|
@ -573,9 +573,7 @@ load_command:
|
|||||||
|
|
||||||
call 0x5000
|
call 0x5000
|
||||||
|
|
||||||
jmp $
|
;jmp $
|
||||||
|
|
||||||
call clear_command
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -1,18 +1,45 @@
|
|||||||
void k_print_line(const char* string);
|
void k_print_line(const char* string);
|
||||||
void k_print(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"
|
extern "C"
|
||||||
void __attribute__ ((section ("main_section"))) kernel_main(){
|
void __attribute__ ((section ("main_section"))) kernel_main(){
|
||||||
k_print("thor> ");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
|
|
||||||
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
|
|
||||||
|
|
||||||
enum vga_color {
|
enum vga_color {
|
||||||
BLACK = 0,
|
BLACK = 0,
|
||||||
BLUE = 1,
|
BLUE = 1,
|
||||||
@ -32,9 +59,6 @@ enum vga_color {
|
|||||||
WHITE = 15,
|
WHITE = 15,
|
||||||
};
|
};
|
||||||
|
|
||||||
long current_line = 0;
|
|
||||||
long current_column = 0;
|
|
||||||
|
|
||||||
uint8_t make_color(vga_color fg, vga_color bg){
|
uint8_t make_color(vga_color fg, vga_color bg){
|
||||||
return fg | bg << 4;
|
return fg | bg << 4;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
[BITS 16]
|
[BITS 16]
|
||||||
|
|
||||||
|
%ifndef DEBUG
|
||||||
[ORG 0x1000]
|
[ORG 0x1000]
|
||||||
|
%endif
|
||||||
|
|
||||||
jmp _start
|
jmp _start
|
||||||
|
|
||||||
@ -98,11 +101,13 @@ lm_start:
|
|||||||
|
|
||||||
call install_timer
|
call install_timer
|
||||||
|
|
||||||
; Enter the shell
|
call 0x5000
|
||||||
call shell_start
|
|
||||||
|
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
|
; Enter the shell
|
||||||
|
;call shell_start
|
||||||
|
|
||||||
; Includes
|
; Includes
|
||||||
|
|
||||||
%include "src/utils/macros.asm"
|
%include "src/utils/macros.asm"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user