Problems with basic D OS

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
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Problems with basic D OS

Post by newmangamers »

EDIT: Update code like comments said, also had to change voliatile to synchronized so gdc would work
i have followed this tutorial on a d os bare bones but i am having problems, link: D_Bare_Bones (http://wiki.osdev.org/D_Bare_Bones)

when i run

Code: Select all

ld -T linker.ld -o kernel.bin start.o kernel.main.o
, i get a few errors:

Code: Select all

kernel.main.o: In function `main':
/home/daniel/N3OS/OLD/1.0/kernel.main.d:13: undefined reference to `_d_criticalenter'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:13: undefined reference to `_d_criticalexit'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:16: undefined reference to `_d_criticalenter'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:16: undefined reference to `_d_criticalexit'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:17: undefined reference to `_d_criticalenter'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:17: undefined reference to `_d_criticalexit'
kernel.main.o: In function `kernel.main._D6kernel4main9__modinitFZv':
/home/daniel/N3OS/OLD/1.0/kernel.main.d:1: undefined reference to `_Dmodule_ref'
/home/daniel/N3OS/OLD/1.0/kernel.main.d:1: undefined reference to `_Dmodule_ref'
can some one please tell me how to fix this...

my source code:
start.asm

Code: Select all

global start
extern main        ; Allow main() to be called from the assembly code
extern start_ctors, end_ctors, start_dtors, end_dtors
 
MODULEALIGN        equ        1<<0
MEMINFO            equ        1<<1
FLAGS              equ        MODULEALIGN | MEMINFO
MAGIC              equ        0x1BADB002
CHECKSUM           equ        -(MAGIC + FLAGS)
 
section .text      ; Next is the Grub Multiboot Header
 
align 4
MultiBootHeader:
       dd MAGIC
       dd FLAGS
       dd CHECKSUM
 
STACKSIZE equ 0x4000  ; 16k if you're wondering
 
static_ctors_loop:
   mov ebx, start_ctors
   jmp .test
.body:
   call [ebx]
   add ebx,4
.test:
   cmp ebx, end_ctors
   jb .body
 
start:
       mov esp, STACKSIZE+stack
 
       push eax
       push ebx
 
       call main
 
static_dtors_loop:
   mov ebx, start_dtors
   jmp .test
.body:
   call [ebx]
   add ebx,4
.test:
   cmp ebx, end_dtors
   jb .body
 
 
cpuhalt:
       hlt
       jmp cpuhalt
 
section .bss
align 32
 
stack:
      resb      STACKSIZE
kernel.main.d

Code: Select all

module kernel.main;

extern(C) void main(uint magic, uint addr) {

        int ypos = 0; //Starting points of the cursor
	int xpos = 0;
	const uint COLUMNS = 80; //Screensize
	const uint LINES = 24;

	ubyte* vidmem = cast(ubyte*)0xFFFF8000000B8000; //Video memory address

	for (int i = 0; i < COLUMNS * LINES * 2; i++) { //Loops through the screen and clears it
			synchronized {*(vidmem + i) = 0;}
	}

	synchronized {*(vidmem + (xpos + ypos * COLUMNS) * 2) = 'D' & 0xFF;} //Prints the letter D
	synchronized {*(vidmem + (xpos + ypos * COLUMNS) * 2 + 1) = 0x07;} //Sets the colour for D to be light grey (0x07)

	for (;;) { //Loop forever. You can add your kernel logic here
	} 
}
linker.ld

Code: Select all

OUTPUT_FORMAT(elf32-i386)
ENTRY (start)

SECTIONS{
    . = 0x00100000;

    .text :{
        code = .; _code = .; __code = .;
        *(.text)
        *(.rodata)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        data = .; _data = .; __data = .;
        *(.data)
        start_ctors = .; *(.ctors)   end_ctors = .;
        start_dtors = .; *(.dtors)   end_dtors = .;
    }

    .bss : {
        sbss = .;
        bss = .; _bss = .; __bss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
    end = .; _end = .; __end = .;
}
Thanks in adv for any help
Last edited by newmangamers on Sat Aug 25, 2012 4:45 am, edited 1 time in total.
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Re: Problems with basic D OS

Post by newmangamers »

also i am running ubuntu, i do not remember the version, i think it is 64bit, unless i installed 32bit for some random reason :P :?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems with basic D OS

Post by xenos »

I don't know anything about D, but this is certainly wrong:

Code: Select all

import std.stdio;
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problems with basic D OS

Post by Combuster »

It's quite simple actually:
i have followed this tutorial
Your code says you did not. So either fix the question (and probably read all the introduction topics on the wiki beforehand) or actually follow the tutorial.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Re: Problems with basic D OS

Post by newmangamers »

well i had to fix some of the code as it was the 1.0 version of d. and the import makes no diffrence...
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Re: Problems with basic D OS

Post by newmangamers »

i will update it later but still it dossent fix the problem.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Problems with basic D OS

Post by Kazinsal »

newmangamers wrote:and the import makes no diffrence...
Yes. Yes it does. You can't use any standard libraries in your kernel. This is true for any programming language.
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Re: Problems with basic D OS

Post by newmangamers »

Blacklight wrote:
newmangamers wrote:and the import makes no diffrence...
Yes. Yes it does. You can't use any standard libraries in your kernel. This is true for any programming language.
ok, i have update the code. still getting errors
EDIT: also had to change voliatile to synchronized so gdc would work as voliatile is D 1.0 not D 2.0
newmangamers
Posts: 6
Joined: Fri Aug 24, 2012 6:06 am

Re: Problems with basic D OS

Post by newmangamers »

anyone know how to fix it with the changes?
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Problems with basic D OS

Post by iansjack »

I don't know D, but it seems fairly obvious to me that the "synchronized" keyword is causing calls to lbrary routines that you are not linking against. I think your mistake is in the use of this keyword - it's not as if you need to be concerned about concurrency here. You can easily check this by looking at the code in the object files.

To use any language for OS development you have to be very familiar with its keywords and the code it produces. This is also true of C, but it tends to pull in less run-time baggage than other languages.

Study the generated code.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Problems with basic D OS

Post by iansjack »

Just for fun I had a little play with D. It is exactly as I supposed; the "synchronized" key word adds calls to a couple of library routines.
Post Reply