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.
/* PDN is just a macro which handles the shifting stuff */
phyaddr = 0;
for(i = PDN(0xC0000000); i<1024; i++)
{
for(j=0; j<1024; j++)
{
pt[j] = (paddress << 12) | 3;
paddress += 0x1000;
}
pd[i] = pt[-PDN(0xC0000000)+i] | 3;
}
this code should map the first 4MB to 0xC0000000 but qemu hangs when running this code. I'm sure that I didn't quite understand howto map memory correctly
why are you shifting?
pt[0] = 0 | 3
pt[1] = 0x1000 << 12 | 3 = 0x1000003
pt[2] = 0x2000003
first page points to 0k..4k
second page points to 16M..16.004M instead of 4k..8k
third page points to 32M..32M+4k instead of 8k..12k
so you're not mapping the first MB, you're mapping random stuff.
"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 ]
Truthfully, I'm struggling to understand exactly what that code does. Maybe I'm just tired . If I were you I would build my page table first and insert into the page directory later:
Due to my last success I started to integrate my older code to the newer one (higher half kernel).
I thought that this is basically easy since 1:1 paging is still active thus I don't have to add any offset to fixed memory addresses. Most of my code run without any problems but one function makes problems (putc). Whenever I add it GRUB reports: Invalid or unsupported executable format.
Here is a complete lists of all symbols within the kernel file:
001041d2 A __early_init_end
00100000 A __early_init_start
c0108000 A __end
c01041d2 A __start
c0105030 T _interrupt0
c0105039 T _interrupt1
c0105078 T _interrupt10
c010507e T _interrupt11
c0105084 T _interrupt12
c010508a T _interrupt13
c0105090 T _interrupt14
c0105096 T _interrupt15
c0105042 T _interrupt2
c010504b T _interrupt3
c0105054 T _interrupt4
c010505a T _interrupt5
c0105060 T _interrupt6
c0105066 T _interrupt7
c010506c T _interrupt8
c0105072 T _interrupt9
00100000 T _start
c0104f28 T _trap0
c0104f31 T _trap1
c0104f80 T _trap10
c0104f87 T _trap11
c0104f8e T _trap12
c0104f95 T _trap13
c0104f9c T _trap14
c0104fa3 T _trap15
c0104fac T _trap16
c0104fb5 T _trap17
c0104fbe T _trap18
c0104fc7 T _trap19
c0104f3a T _trap2
c0104fd0 T _trap20
c0104fd9 T _trap21
c0104fe2 T _trap22
c0104feb T _trap23
c0104ff4 T _trap24
c0104ffd T _trap25
c0105006 T _trap26
c010500f T _trap27
c0105018 T _trap28
c010501e T _trap29
c0104f43 T _trap3
c0105024 T _trap30
c010502a T _trap31
c0104f4c T _trap4
c0104f55 T _trap5
c0104f5e T _trap6
c0104f67 T _trap7
c0104f70 T _trap8
c0104f77 T _trap9
c0104e94 T add_interrupt_handler
c0105114 T add_trap_handler
00104030 T early_init
c0106004 D ega_mm
c010509c t fault_handle
c0104de0 T inb
c01041d4 T init
c0104e1c T inl
c01050d7 t interrupt_handle
c0104eb4 T interrupt_handler
c0107000 B interrupt_handlers
c0104dfd T inw
c0104304 t isdigit
0010001f t loop
c0104297 T memcpy
c01042d7 T memset
00100010 t multiboot_entry
00100004 t multiboot_header
c01043c2 t number
c0104e38 T outb
c0104e7c T outl
c0104e59 T outw
c0104d48 T printk
c0105138 T putc
c0104367 t skip_atoi
00100030 T stack
00100000 T start
c0104268 T strlen
c010432c t strnlen
c0105131 T trap_handler
c0107400 B trap_handlers
c010472b T vsnprintf
c0107480 b xpos
c0106000 d ypos
What confuses me is that this message is only printed when putc is compiled.
Whenever I add it GRUB reports: Invalid or unsupported executable format.
first suspect is:
is that code being placed before the multi-boot header? thereby pushing it beyond the limit? (i dont use grub, but iirc it must be in the first 4k of the file?)
Your multiboot header is too far from the start. Place it completely at the start by using a separate section for it, and a linker script similar to this:
The Multiboot header needs to be within the first 8192 bytes of the binary image and it must be 32-bit aligned. Run mbchk on your kernel image and it will tell you if your Multiboot headers are correct.
Like others have said, you can correct this by placing the Multiboot header into its own section and linking that section before any others.
I still don't understand clearly why it doesn't run with my current linker script.
early_init should be the very first section which contains everything of grub.o and early_init.o. Both files are certainly less than 8192 bytes:
kiwipresse wrote:I still don't understand clearly why it doesn't run with my current linker script.
Off the top of my head, I don't either. Maybe someone else does. I'm thinking it could be a 32-bit alignment problem. Are you sure you 4-byte aligned your multiboot header in your assembly code?