Added k_bootstrap.c, k_early_panic.[ch]
Calling k_bootstrap() from boot.asm in segmented mode git-svn-id: svn://anubis/hos/trunk@25 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
parent
d4f5a0b244
commit
6ea8fe1a27
1
Makefile
1
Makefile
@ -18,6 +18,7 @@ iso: $(ISO) kernel
|
||||
|
||||
$(ISO): kernel
|
||||
cp kernel/$(KERNEL_FILE) iso/boot
|
||||
-rm -f $(ISO)
|
||||
$(MKISOFS) -R -b boot/grub/stage2_eltorito -no-emul-boot \
|
||||
-boot-load-size 4 -boot-info-table -o $(ISO) iso
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
%define MULTIBOOT_HEADER_FLAGS 0x00010003
|
||||
|
||||
%define VIRTUAL_OFFSET 0xE0000000 ; kernel virtual addr
|
||||
%define CONSOLE_MEMORY VIRTUAL_OFFSET + 0xB8000
|
||||
|
||||
%define PAGE_SIZE 0x1000 ; 4KB pages
|
||||
|
||||
@ -15,7 +16,7 @@
|
||||
extern _end, _bss
|
||||
|
||||
; Symbols from C
|
||||
extern k_mbsave, page_directory
|
||||
extern k_bootstrap, page_directory
|
||||
|
||||
;-------------------------------------------------------
|
||||
[section .text]
|
||||
@ -46,8 +47,8 @@ multiboot_header:
|
||||
;* Resume execution *
|
||||
;**************************************************************************
|
||||
multiboot_entry:
|
||||
mov ax, 0x0700 + 'a'
|
||||
mov [0xB8000+160*8+0*2], ax
|
||||
mov cx, 0x0700 + 'a'
|
||||
mov [CONSOLE_MEMORY-VIRTUAL_OFFSET+160*8+0*2], cx
|
||||
|
||||
lgdt [gdtr_tmp32-VIRTUAL_OFFSET] ; load temporary GDTR
|
||||
jmp KERNEL_CODE_32_TMP_SEG:segmented_start
|
||||
@ -65,17 +66,17 @@ segmented_start:
|
||||
mov fs, cx
|
||||
mov esp, page_directory+PAGE_SIZE-4 ; set up temporary stack space
|
||||
|
||||
mov ax, 0x0700 + 'b'
|
||||
mov [VIRTUAL_OFFSET+0xB8000+160*8+1*2], ax
|
||||
mov cx, 0x0700 + 'b'
|
||||
mov [CONSOLE_MEMORY+160*8+1*2], cx
|
||||
|
||||
; add ebx, VIRTUAL_OFFSET
|
||||
; push eax
|
||||
; push ebx ; pointer to multiboot info struct
|
||||
; call k_mbsave
|
||||
; add esp, 8
|
||||
add ebx, VIRTUAL_OFFSET
|
||||
push eax
|
||||
push ebx ; pointer to multiboot info struct
|
||||
call k_bootstrap
|
||||
add esp, 8
|
||||
|
||||
; mov ax, 0x0700 + 'c'
|
||||
; mov [VIRTUAL_OFFSET+0xB8000+160*8+2*2], ax
|
||||
mov cx, 0x0700 + 'e'
|
||||
mov [CONSOLE_MEMORY+160*8+4*2], cx
|
||||
|
||||
idle_loop:
|
||||
hlt
|
||||
|
26
kernel/boot/k_bootstrap.c
Normal file
26
kernel/boot/k_bootstrap.c
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "multiboot.h"
|
||||
#include "k_early_panic.h"
|
||||
|
||||
#define DEBUG_LETTER(col,chr) *(u16_t *)(CONSOLE_MEMORY + 160 * 8 + (col) * 2) \
|
||||
= 0x0700 | (chr)
|
||||
|
||||
/**************************************************************************
|
||||
* This function is invoked before paging is enabled. Segmentation is *
|
||||
* utilized to map virtual address 0xE000_0000 to physical address 0x0. *
|
||||
*************************************************************************/
|
||||
u32_t k_bootstrap(mb_info_t * mb_info, u32_t mb_magic)
|
||||
{
|
||||
DEBUG_LETTER(2, 'c');
|
||||
|
||||
if (mb_magic != MB_BOOTLOADER_MAGIC)
|
||||
{
|
||||
k_early_panic("Bad multiboot magic identifier!");
|
||||
}
|
||||
|
||||
DEBUG_LETTER(3, 'd');
|
||||
|
||||
return 0;
|
||||
}
|
18
kernel/boot/k_early_panic.c
Normal file
18
kernel/boot/k_early_panic.c
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#include "hos_types.h"
|
||||
#include "hos_defines.h"
|
||||
#include "k_early_panic.h"
|
||||
|
||||
void k_early_panic(const char * msg)
|
||||
{
|
||||
char * dest = (char *) CONSOLE_MEMORY;
|
||||
while (*msg)
|
||||
{
|
||||
*dest++ = *msg++;
|
||||
*dest++ = 0x04; /* red error message */
|
||||
}
|
||||
|
||||
/* infinite loop */
|
||||
for (;;)
|
||||
;
|
||||
}
|
7
kernel/boot/k_early_panic.h
Normal file
7
kernel/boot/k_early_panic.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef K_EARLY_PANIC_H
|
||||
#define K_EARLY_PANIC_H
|
||||
|
||||
void k_early_panic(const char * msg);
|
||||
|
||||
#endif
|
@ -2,6 +2,11 @@
|
||||
#ifndef HOS_DEFINES_H
|
||||
#define HOS_DEFINES_H
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
#define PAGE_LOG_SIZE 12
|
||||
#define PAGE_SIZE (1 << PAGE_LOG_SIZE)
|
||||
#define PAGE_HIGH_MASK (0xFFFFFFFFu << PAGE_LOG_SIZE)
|
||||
#define PAGE_LOW_MASK (0xFFFFFFFFu >> (32 - PAGE_LOG_SIZE))
|
||||
|
||||
#define CONSOLE_MEMORY 0xE00B8000
|
||||
|
||||
#endif
|
||||
|
@ -36,11 +36,15 @@ typedef struct
|
||||
u32_t magic;
|
||||
u32_t flags;
|
||||
u32_t checksum;
|
||||
u32_t header_addr;
|
||||
u32_t load_addr;
|
||||
u32_t load_end_addr;
|
||||
u32_t bss_end_addr;
|
||||
u32_t entry_addr;
|
||||
u32_t header_addr; // if flags[16]
|
||||
u32_t load_addr; // if flags[16]
|
||||
u32_t load_end_addr; // if flags[16]
|
||||
u32_t bss_end_addr; // if flags[16]
|
||||
u32_t entry_addr; // if flags[16]
|
||||
u32_t mode_type; // if flags[2]
|
||||
u32_t width; // if flags[2]
|
||||
u32_t height; // if flags[2]
|
||||
u32_t depth; // if flags[2]
|
||||
} mb_header_t;
|
||||
|
||||
/* The symbol table for a.out. */
|
||||
@ -70,26 +74,26 @@ typedef struct
|
||||
u32_t boot_device; // 1
|
||||
u32_t cmdline; // 2
|
||||
u32_t mods_count; // 3
|
||||
u32_t mods_addr;
|
||||
u32_t mods_addr; // 3
|
||||
union
|
||||
{
|
||||
mb_aout_symbol_table_t aout_sym; // 4
|
||||
mb_elf_section_header_table_t elf_sec; // 5
|
||||
};
|
||||
u32_t mmap_length; // 6
|
||||
u32_t mmap_addr;
|
||||
u32_t mmap_addr; // 6
|
||||
u32_t drives_length; // 7
|
||||
u32_t drives_addr;
|
||||
u32_t drives_addr; // 7
|
||||
u32_t config_table; // 8
|
||||
u32_t bootloader_name; // 9
|
||||
u32_t apm_table; // 10
|
||||
|
||||
u32_t vbe_control_info; // 11
|
||||
u32_t vbe_mode_info;
|
||||
u16_t vbe_mode;
|
||||
u16_t vbe_interface_seg;
|
||||
u16_t vbe_interface_off;
|
||||
u16_t vbe_interface_len;
|
||||
u32_t vbe_mode_info; // 11
|
||||
u16_t vbe_mode; // 11
|
||||
u16_t vbe_interface_seg; // 11
|
||||
u16_t vbe_interface_off; // 11
|
||||
u16_t vbe_interface_len; // 11
|
||||
} mb_info_t;
|
||||
|
||||
/* The module structure. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user