Page 1 of 1

Grub MultiBoot

Posted: Mon Aug 14, 2006 8:11 pm
by spider
im trying to load my kernel with grub, i have the multi kernel headers inside my asm file, but when ever i try to link the asm file with my c code grub says the file isnt supported. But it works if i dont link to the c file.

The code i have is

kernel.asm

Code: Select all

[BITS 32]
global start
start:
      extern YaOS_main
      call YaOS_main
    cli;
    hlt;

ALIGN 4
mboot:
    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)
    EXTERN code, bss, end

    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    
    dd mboot
    dd code
    dd bss
    dd end
    dd start
kernel.c

Code: Select all

#define TEXT 0x07

void YaOS_clearScreen();
void YaOS_updateCursor(int row, int col);

unsigned int YaOS_printf(char *msg, unsigned int line);

//Entry point for the OS (like main in a normal program)
YaOS_main() {
   YaOS_clearScreen();
   YaOS_printf("Welcome to YaOS (Yet another Operating System)\nVersion:0.1", 0);
};

void YaOS_clearScreen() {
   char *vid =(char *) 0xb8000;
   unsigned int i =0;
   
   while(i <(80*25*2)) {
      vid[i] =' ';
      i++;
      vid[i] =TEXT;
      i++;
   };
};

unsigned int YaOS_printf(char *msg, unsigned int line) {
   char *vid =(char *) 0x8000;
   
   unsigned int i =(line*80*2);
   
   while(*msg !=0) {
      if(*msg ='\n') {
         line++;
         i =(line*80*2);
         *msg++;
      } else {
         vid[i] =*msg;
         i++;
         vid[i] =TEXT;
         i++;
      };
   };
};
link.ld

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
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 = .;
}
I should also note that im using a linux system to develop this.

Edit: I ended up working it out, after looking through just about every post in here and seeing someone else's linker script i noticed i didnt have *(.rodata) I added that compiled it all together and it works fine now, well kind of. I just have to work out why it isnt actually printing to the screen.

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 3:11 am
by Kim
Think this would be beter :P

Note: = is not == (assign and compare) and your loop isn't correct.

Code: Select all

  while(*msg !=0) {
      if(*msg == '\n') {
        line++;
        i =(line*80*2);
      } else {
        vid[i] =*msg;
        i++;
        vid[i] =TEXT;
        i++;
      };
      *msg++;
  };

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 5:37 am
by Kemp
In case it wasn't a simple slip and you're used to a language with different behaviour,

Code: Select all

if(*msg ='\n')
Will set *msg to '\n' and afaik the condition will always evaluate to true.

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 5:40 am
by spider
yeh i noticed that, there where a few things wrong with it. I had the wrong address for starters. the assign instead of equal to, and i forgot to move the msg pointer up after i printed it. ;D i just wont code this kind of thing when im half asleep now. Its all working perfect now. HeHe time to actually start coding the OS now i know it loads. Im just not sure what i should start on first. I was thinking of starting with some kind of memory manager as everything ill be doing on the kernel is going to be handling memory pretty much.

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 8:32 am
by Candy
Kemp wrote: In case it wasn't a simple slip and you're used to a language with different behaviour,
That's why I actively disrecommend learning pascal or delphi, with a small sidenote that functional languages have a lot of those operators that all do something just not the same.

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 10:26 am
by Kemp
Heh, I learned Pascal and Delphi before C and never really had a problem with it, both methods made sense to me in context. But then, everyone's different, and I had the advantage of not getting too ingrained in the pascal way before learning php (which uses the same method as C). I don't really know where I'm trying to go with this post so I'll stop now...

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 5:35 pm
by spider
Yeh i learned delphi before anything else, i dont find knowing more then one languages makes programming harder if anything i find it makes it easyer. Considering at uni they where teaching me all the different kinds of languages to get a better fill for how the computer/compilers work together. e.g languages like lisp.

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 6:29 pm
by evincarofautumn

Code: Select all

if(*msg ='\n')
Will set *msg to '\n' and afaik the condition will always evaluate to true.
But [tt]*msg = 0[/tt] will always evaluate to false (0), ne? Ah, the joys of C and its many cousins. :D *melts into a happy little puddle*

Re:Grub MultiBoot

Posted: Tue Aug 15, 2006 10:55 pm
by Candy
spider wrote: Yeh i learned delphi before anything else, i dont find knowing more then one languages makes programming harder if anything i find it makes it easyer. Considering at uni they where teaching me all the different kinds of languages to get a better fill for how the computer/compilers work together. e.g languages like lisp.
I got to know Pascal/Delphi after 13 languages that used "=" for assignment and one that used "is" for assignment. Of those, some 6-7 used accolades for grouping and didn't use "then". The rest didn't support grouping. Semicolons were placed at the end of every statement. Objects are virtual if I say so and it'll override automatically. Only C# is as picky as delphi in mentioning override, abstract etc. It uses C calling conventions which allows return value optimization, variable number of arguments and adding parameters to functions without forcing a recompile.

Then I got to delphi. You don't assign stuff with =, you get a compiler warning. You use ":=" for assignment. You use "begin" for "{" and "end" for "}". You place a semicolon at the end of every statement, but not in front of else or end. You place a series of keywords after a function in a particular order (no other order is right) and you commonly use a bunch of them. You can't even use variable arguments or anything in different languages without messing about with special linking stuff.

Honestly, everytime I try to use delphi I have a switchover of a few hours and then I still usually type the C-ish syntax, then delete it and then type the delphi syntax.

Delphi just chooses the exact opposite solution of about every design choice there is in C/C++-ish languages. At least I have quite a hard time to switch over to the other set whenever I got used to the C-ish set for quicker coding.

Re:Grub MultiBoot

Posted: Wed Aug 16, 2006 12:30 pm
by Kemp
You place a semicolon at the end of every statement, but not in front of else or end.
Actually it's only elses that get annoyed by it, and it's if it's a line that isn't in a begin..end block.

Code: Select all

if foo then
begin
   something();
end
else
begin
   oh_noes();
end;
compared to

Code: Select all

if foo then
   something()
else
   oh_noes();
A semicolon terminates the thing that is happening, and an else sitting on its own at the start of a line doesn't make much sense :P This is also kinda a personal thing as a semicolon really does break the flow for me, so something like

Code: Select all

if (foo)
   something();
else
   oh_noes();
does make me pause for a second while my internal parser fetches back the flow that was moments ago discarded by the semicolon.