[N0000bie!] Entry=0x0??

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Zuliani
Posts: 1
Joined: Fri Sep 01, 2006 2:21 pm

[N0000bie!] Entry=0x0??

Post by Zuliani »

start.asm:

Code: Select all

SECTION .text
BITS 32

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; entry point
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GLOBAL entry
entry:

; display a blinking white-on-blue 'D' and freeze
	mov word [0B8000h],9F44h
	jmp short $

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Multiboot header for GRUB bootloader. This must be in the first 8K
; of the kernel file. We use the aout kludge so it works with ELF,
; DJGPP COFF, Win32 PE, or other formats.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MULTIBOOT_PAGE_ALIGN	equ 1<<0
MULTIBOOT_MEMORY_INFO	equ 1<<1
MULTIBOOT_AOUT_KLUDGE	equ 1<<16
MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

ALIGN 4
mboot:
	dd MULTIBOOT_HEADER_MAGIC
	dd MULTIBOOT_HEADER_FLAGS
	dd MULTIBOOT_CHECKSUM
; aout kludge. These must be PHYSICAL addresses
	dd mboot
	dd entry

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(entry)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
Makefile:

Code: Select all

all : kernel.bin
start.o : start.asm
	nasm -f aout -o start.o start.asm
kernel.bin : start.o
	ld -T link.ld -o kernel.bin start.o
cleanup:
	rm kernel.bin start.o
When BRUB loads that kernel, this is the output:
[Multiboot-kludge, loadaddr=0x100000, text-and-data=0x1000, bss=0x0 entry=0x0]

When i type boot, my computer reboots (duh?). I think that's becouse entry should be 0x100000, (I think that becouse other little OS'ses do that.) But how do I manage that??
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Post by carbonBased »

I'm not entirely sure of what the "AT" syntax does in an ld script... haven't really looked into it, as I haven't required it.

All that you should really require is a location for your first section, the others will follow.

The following works for me:

Code: Select all

SECTIONS {
  .text 0x00100000 :{
    *(.text)
  }
  textEnd = .;

  .data :{
    *(.data)
    *(.rodata)
  }
  dataEnd = .;

  .bss :{
    *(.common)
    *(.bss)
  }
  bssEnd = .;
}
Keep in mind that rodata could go into .text... seeing as .text *should* really be read-only. Once I implement better paging-based memory protection, I'll probably make this change.

--Jeff
Post Reply