Multitasking problem

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.
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Hello again, i have problem with multiboot, when i am trying to run system with modules on some emulators, grub doesn't provide modules, modules count and address are zero, what is reason?
Modules are provided only when virtual machine have 128MB of ram.
When i enable paging the data of multiboot are sets to zero, why?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Multitasking problem

Post by iansjack »

But the multiboot data is provided before you enable paging. If it disappears after you enable paging then you are overwriting the data, or not mapping the memory region where it is contained properly.
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

iansjack wrote:But the multiboot data is provided before you enable paging. If it disappears after you enable paging then you are overwriting the data, or not mapping the memory region where it is contained properly.
Maybe i overwrite the data.
I have second problem, if i pass the another file as module the module start field are zero, but if i pass the same module as second module, it's work, why?
And about multiboot the same if i load and enable paging after loading modules.
EDIT: Modules works fine, but kernel end address are incorrect, how i can get the kernel end address? And the problem caused by invalid kernel end address.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multitasking problem

Post by Octocontrabass »

WinExperements wrote:how i can get the kernel end address?
Define a symbol at the end of your kernel in your linker script. Use the address of that symbol.
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Octocontrabass wrote:
WinExperements wrote:how i can get the kernel end address?
Define a symbol at the end of your kernel in your linker script. Use the address of that symbol.
Yeah i add this, but the address in this symbol are incorrect, the value is 10696057704939582.
My linker script:

Code: Select all

ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)

SECTIONS
{
  . = 0x100000;
  kernel_start = .;
  .text :
  {
    *(.multiboot)
    *(.text*)
    *(.rodata)
  }

  .data  :
  {
    *(.data)
  }

  .bss  :
  {
    *(.bss)
  }
  kernel_end = .;
}
What i do wrong in my linker script and how correctly get kernel end address and size?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multitasking problem

Post by Octocontrabass »

How are you getting an address that doesn't fit in 32 bits?
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Octocontrabass wrote:How are you getting an address that doesn't fit in 32 bits?
Problem in my linker script or in how i use this variable? I define it as uint64_t in my kernel source
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Multitasking problem

Post by nullplan »

You should define linker symbols in C as

Code: Select all

extern char <name>[];
The value of a symbol from the linker shows up as address of a name in C. If you declare that name as an array, just referencing the name will automatically take its address. If you define it as anything else, you must take the address. What you did was likely to dereference it. Thus showing you that there are indeed some data bytes at the end of your kernel, and what they look like if interpreted as a 64-bit number. But that doesn't help you.
Carpe diem!
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Hello again, i have some problems with vga fonts.
After converting psf to elf, my symbol table seems incorrect, what is reason?
Converted PSF symtab:

Code: Select all

Symbol table '.symtab' contains 5 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 NOTYPE  GLOBAL DEFAULT    1 _binary_D__Download_font_
     3: 00008020     0 NOTYPE  GLOBAL DEFAULT    1 _binary_D__Download_font_
     4: 00008020     0 NOTYPE  GLOBAL DEFAULT  ABS _binary_D__Download_font_
How i convert it:

Code: Select all

objcopy -O elf32-i386 -B i386 -I binary font.psf font.o
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multitasking problem

Post by Octocontrabass »

There's nothing wrong with your symbol table. The symbol names are being truncated by readelf.

Try "readelf -s -W" or "objdump -t" and you'll see the correct symbol names.
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Hello! How i can translate virtual address to physical knows only the page directory and virtual address?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Multitasking problem

Post by iansjack »

You read the physical address from the page directory. The other way round is more difficult (and is not necessarily a 1 to 1 relationship).
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Hello, i am about translation virtual to physical address, how i can get physical address from page table entry?
And how correctly get page table address from page directory?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multitasking problem

Post by Octocontrabass »

The upper 20 bits of the physical address are stored in the upper 20 bits of the entry. The lower 12 bits of the physical address are always 0. This applies to both page table and page directory entries.

You can get the physical address from the entry by using bitwise AND to mask the lower 12 bits.
WinExperements
Member
Member
Posts: 97
Joined: Thu Jul 14, 2022 9:45 am
Contact:

Re: Multitasking problem

Post by WinExperements »

Octocontrabass wrote:The upper 20 bits of the physical address are stored in the upper 20 bits of the entry. The lower 12 bits of the physical address are always 0. This applies to both page table and page directory entries.

You can get the physical address from the entry by using bitwise AND to mask the lower 12 bits.
How i can mask 12 bits in C? Can you give example of it?
Post Reply