use objdump -h build/kernel-x86.bin to show sections, linker scripts squishes relevant ones together

This commit is contained in:
Jack Halford 2018-02-22 18:54:08 +01:00
parent 3ee7508331
commit fc3c60d970
5 changed files with 60 additions and 52 deletions

View file

@ -8,3 +8,4 @@ crate-type = ["staticlib"]
[dependencies]
rlibc = "1.0"
multiboot2 = "0.1.0"

View file

@ -4,11 +4,10 @@ extern x86_start
section .text
bits 32
start:
mov esp, head_stack
mov edi, ebx
push ebx
call check_multiboot
lgdt [GDTR.ptr]
lgdt [GDTR.ptr] ; load the new gdt
jmp GDTR.gdt_cs:x86_start
error:
@ -78,18 +77,11 @@ GDTR:
DW 0x0 ; Limit ( bits 0 -15 )
DW 0x0 ; Base ( bits 0 -15 )
DB 0x0 ; Base ( bits 16 -23 )
DB 0xF2 ; [ Access Flags: 0x9A=11110110b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand up => 1)|(readable)|(0) ]
DB 0xCF ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ]
DB 0x00 ; [ Access Flags: 0x9A=11110110b = (present)|(Privilege Ring 3=11b)|(1)|(data => 0)|(expand up => 1)|(readable)|(0) ]
DB 0x00 ; [ Flags: C=1100b = (granularity)|(32bit)|(!64bit)|(0) ] / [ Limits: (bits 16-19): F=1111b ]
DB 0x0 ; Base ( bits 24 -31 )
.gdt_bottom:
.ptr:
DW .gdt_bottom - .gdt_top - 1
DD .gdt_top
section .bss
align 4
stack_end:
resb 4096 * 4
head_stack:
DW .gdt_bottom - .gdt_top - 1 ; length of the structure minus 1
DD .gdt_top ; pointer to top of gdt

View file

@ -13,11 +13,13 @@ SECTIONS {
. = 1M;
kernel_start = . ;
/* ensure that the multiboot header is at the beginning */
.boot : {KEEP(*(.multiboot_header))}
.text : {*(.text)}
/* .rodata BLOCK(4K) : ALIGN(4K) {*(.rodata)} */
/* .data BLOCK(4K) : ALIGN(4K) {*(.data)} */
.multiboot_header : { KEEP(*(.multiboot_header)) }
.text : { *(.text .text.*) }
.rodata : { *(.rodata .rodata.*) }
.data.rel.ro : { *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) }
.debug : { *(.debug_*) }
/* load stack */
.bss : {*(.bss)}
kernel_end = . ;
.bss : {*(.bss .bss.*)}
/* kernel_end = . ; */
}

View file

@ -4,18 +4,13 @@ extern kmain
section .text
bits 32
x86_start:
; we should clear register but it does not work, it's okay with 0x10 instead of 0
mov ax, 0x10
mov ax, 0x10 ; 16 bytes (0x10) is where the offset for data section (gdt_ds)
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; PRINT OK
; mov dword [0xb8000], 0x2f4b2f4f
; hlt
call kmain
; if main return, loop forever ; that should NEVER append

View file

@ -1,4 +1,4 @@
//! project hosted at [https://github.com/jzck/kernel]
//! project hosted at (https://github.com/jzck/kernel)
#![no_std]
#![feature(lang_items)]
@ -7,10 +7,10 @@
#![feature(asm)] //needed by cpuio for inline asm
extern crate rlibc;
extern crate multiboot2;
#[macro_use]
/// 80x25 screen and simplistic terminal driver
pub mod vga;
#[macro_use] pub mod vga;
/// kernel init and environment
pub mod context;
/// PS/2 detection and processing
@ -24,24 +24,42 @@ use context::CONTEXT;
use vga::{Color, ColorCode};
#[no_mangle]
pub extern fn kmain() -> ! {
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
format_args!("{: ^80}", r#" ,--, "#),
format_args!("{: ^80}", r#" ,--.'| ,----, "#),
format_args!("{: ^80}", r#" ,--, | : .' .' \ "#),
format_args!("{: ^80}", r#",---.'| : ' ,----,' | "#),
format_args!("{: ^80}", r#"; : | | ; | : . ; "#),
format_args!("{: ^80}", r#"| | : _' | ; |.' / "#),
format_args!("{: ^80}", r#": : |.' | `----'/ ; "#),
format_args!("{: ^80}", r#"| ' ' ; : / ; / "#),
format_args!("{: ^80}", r#"\ \ .'. | ; / /-, "#),
format_args!("{: ^80}", r#" `---`: | ' / / /.`| "#),
format_args!("{: ^80}", r#" ' ; |./__; : "#),
format_args!("{: ^80}", r#" | : ;| : .' "#),
format_args!("{: ^80}", r#" ' ,/ ; | .' "#),
format_args!("{: ^80}", r#" '--' `---' "#));
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); }
pub extern fn kmain(multiboot_information_address: usize) -> ! {
// unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
// print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
// format_args!("{: ^80}", r#" ,--, "#),
// format_args!("{: ^80}", r#" ,--.'| ,----, "#),
// format_args!("{: ^80}", r#" ,--, | : .' .' \ "#),
// format_args!("{: ^80}", r#",---.'| : ' ,----,' | "#),
// format_args!("{: ^80}", r#"; : | | ; | : . ; "#),
// format_args!("{: ^80}", r#"| | : _' | ; |.' / "#),
// format_args!("{: ^80}", r#": : |.' | `----'/ ; "#),
// format_args!("{: ^80}", r#"| ' ' ; : / ; / "#),
// format_args!("{: ^80}", r#"\ \ .'. | ; / /-, "#),
// format_args!("{: ^80}", r#" `---`: | ' / / /.`| "#),
// format_args!("{: ^80}", r#" ' ; |./__; : "#),
// format_args!("{: ^80}", r#" | : ;| : .' "#),
// format_args!("{: ^80}", r#" ' ,/ ; | .' "#),
// format_args!("{: ^80}", r#" '--' `---' "#));
// unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); }
let boot_info = unsafe{ multiboot2::load(multiboot_information_address) };
let memory_map_tag = boot_info.memory_map_tag()
.expect("Memory map tag required");
println!("memory areas:");
for area in memory_map_tag.memory_areas() {
println!(" start: 0x{:x}, length: 0x{:x}",
area.base_addr, area.length);
}
let elf_sections_tag = boot_info.elf_sections_tag()
.expect("Elf-sections tag required");
println!("kernel sections:");
for section in elf_sections_tag.sections() {
println!(" addr: 0x{:x}, size: 0x{:x}, flags: 0x{:x}",
section.addr, section.size, section.flags);
}
unsafe { CONTEXT.vga1.prompt();CONTEXT.vga1.flush(); }
unsafe { CONTEXT.vga2.prompt(); }