Booting ELF kernel converted to plain BIN
Posted: Wed Oct 18, 2017 10:39 am
So, i have ELF kernel that has one part written in C and the other in NASM. These two parts are linked into the ELF kernel and converted to plain BIN with objcopy. The kernel has to be started from primary bootloader (I'm using one from MikeOS). But bootloader starts up, finds kernel, jumps to it and hangs the system. And i don't know where the problem is.
ASM part of kernel (_start is the entry point):
C part:
ASM part of kernel (_start is the entry point):
Code: Select all
;This part is needed for keyboard support and kernel launch
BITS 16
disk_buffer equ 24576
global _start
extern kernel_main
_start:
msg: db "Entrypoint",10
cli
mov ax, 0
mov ss, ax
mov sp, 0FFFFh
sti
cld
mov ax, 2000h
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call kernel_main
hlt
global keyboard_handler
global read_port
global write_port
global load_idt
extern keyboard_handler_main
read_port:
mov edx, [esp + 4]
in al, dx
ret
write_port:
mov edx, [esp + 4]
mov al, [esp + 4 + 4]
out dx, al
ret
load_idt:
mov edx, [esp + 4]
lidt [edx]
sti
ret
keyboard_handler:
call keyboard_handler_main
iretd
Code: Select all
#if !defined(__cplusplus)
#include <stdbool.h>
#endif
#include <stddef.h>
#include <stdint.h>
#include "keyboard_map.h"
#include "standard/strings.h"
#include "screen/terminal.h"
#include "owshell/execute.h"
#include "keyboard/kbdinit.h"
#include "keyboard/kbdhandle.h"
#include "screen/init.h"
#include "standard/stdio.h"
#include "owshell/die.h"
#if defined(__cplusplus)
extern "C"
#endif
void kernel_main(void) {
console_init();
idt_init();
kb_init();
while(!dead);
}