Page 1 of 2

Problem with strings

Posted: Fri Aug 31, 2012 4:31 pm
by Khronos
I am developing a pure 64 bit C++ Kernel under Windows using MinGW. I think that the problem is the linker script.

Code: Select all

OUTPUT_FORMAT("pe-x86-64") 
ENTRY("loader")
SECTIONS 
{ 
    . = 0x100000;
    .text :
    { 
        code = .; 
        *(.text) 
        text_end = .;
    }
    .rodata : 
    { 
        rodata = text_end; 
        *(.rodata)
        rodata_end  = .;      
    }    
    .rdata : 
    { 
        rdata = rodata_end; 
        *(.rodata)
        rdata_end  = .;      
    } 
    .data : 
    { 
        data = rdata_end; 
        *(.data) 
        data_end = .;
    } 
    .bss :  
    { 
        bss = data_end; 
        *(.bss) 
        bss__end = .;
    } 
    end = .; 
            /DISCARD/ :{
                *(.note*)
                *(.indent)
                *(.comment)
                *(.stab)
                *(.stabstr)
        }
}
My Make.bat is not perfect...

Code: Select all

@echo off
set nasm="tools\nasm.exe"
set bochs="C:\Program Files (x86)\Bochs-2.5.1\bochs.exe"
set fat12maker="tools\fat12maker.exe"
set ld="..\MinGW64\bin\x86_64-w64-mingw32-ld.exe"
set cpp="..\MinGW64\bin\x86_64-w64-mingw32-g++.exe"
set objcopy="..\MinGW64\bin\x86_64-w64-mingw32-objcopy.exe"
set cpp_params=-I.\Kernel\ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin
set cpp_files=Kernel\kernel.cpp Kernel\Drivers\screen.cpp Kernel\string.cpp Kernel\io.cpp Kernel\idt.cpp

%nasm% -fbin bootloader\Stage_1.asm -o Stage_1.bin
if NOT %ERRORLEVEL%==0 goto error

%nasm% -fbin bootloader\Stage_2.asm -o Stage_2.bin
if NOT %ERRORLEVEL%==0 goto error

%cpp% %cpp_params% -c Kernel\kernel.cpp -o bin\kernel.o
%cpp% %cpp_params% -c Kernel\Drivers\screen.cpp -o bin\screen.o
%cpp% %cpp_params% -c Kernel\string.cpp -o bin\string.o
%cpp% %cpp_params% -c Kernel\io.cpp -o bin\io.o
%cpp% %cpp_params% -c Kernel\idt.cpp -o bin\idt.o
%nasm% -f win64 Kernel\Stage_3.asm -o bin\Stage_3.o
if NOT %ERRORLEVEL%==0 goto error

%ld% -nostdlib -nodefaultlibs -T linker.ld bin\Stage_3.o bin\kernel.o bin\screen.o bin\string.o bin\io.o bin\idt.o -o Kernel.out
%objcopy% -x -g -X -S -O binary Kernel.out kernel.bin

copy /b Stage_2.bin+kernel.bin Stage_2.bin
if NOT %ERRORLEVEL%==0 goto error

%fat12maker% -b Stage_1.bin -i Stage_2.bin -o Kernel.img
%bochs% -f bochsconf

goto fin

:error
echo Se produjo un error de compilacion
exit

:fin
echo Compilacion satisfactoria
I can´t do something like this:

Code: Select all

const char * interrupts_exceptions[] = {
	 "0 - Division by zero exception",
	 "1 - Debug exception",
	 "2 - Non maskable interrupt",
	 "3 - Breakpoint exception",
	 "4 - 'Into detected overflow",
	 "5 - Out of bounds exception",
	 "6 - Invalid opcode exception",
	 "7 - No coprocessor exception",
	 "8 - Double fault",
	 "9 - Coprocessor segment overrun",
	 "10 - Bad TSS",
	 "11 - Segment not present",
	 "12 - Stack fault",
	 "13 - General protection fault",
	 "14 - Page fault",
	 "15 - Unknown interrupt exception",
	 "16 - Coprocessor fault",
	 "17 - Alignment check exception",
	 "18 - Machine check exception",
	 "19 - Reserved exception",
	 "20 - Reserved exception",
	 "21 - Reserved exception",
	 "22 - Reserved exception",
	 "23 - Reserved exception",
	 "24 - Reserved exception",
	 "25 - Reserved exception",
	 "26 - Reserved exception",
	 "27 - Reserved exception",
	 "28 - Reserved exception",
	 "29 - Reserved exception",
	 "30 - Reserved exception" 
	 "31 - Reserved exception"};

void idt::init_idt()
{
	idt_ptr = (idt_ptr_t*)IDT_ADDRESS;
	*idt_entries = (idt_entry_t*)IDT_ADDRESS;
	
	clean_gates();
	screen::kprintf("Exceptions pointer: 0x%p\n", ::interrupts_exceptions);
	screen::kprintf("String: %s\n", ::interrupts_exceptions[0]); //<------------------------------------------------

	idt_set_gate(0, (QWORD)isr0, 0x08, 0x8E); //
}

I have read all the related articles in the wiki and forum... Thanks...

Re: Problem with strings

Posted: Fri Aug 31, 2012 4:52 pm
by Combuster
Besides the fact that a windows targeted toolchain is not the best idea in general, you have both duplicate and missing sections in your linker script (hint: *)

Re: Problem with strings

Posted: Sat Sep 01, 2012 5:53 am
by Khronos
I haven´t duplicate sections in the linker script. I think that the problem can be:

Stage_2.asm

Code: Select all

...

[BITS 64]

long_mode:
	xor rax, rax
	xor rbx, rbx
	xor rcx, rcx
	xor rdx, rdx
	xor r8, r8
	xor r9, r9
	xor r10, r10
	xor r11, r11
	xor r12, r12
	xor r13, r13
	xor r14, r14
	xor r15, r15

cpp_kernel:
And then, I convert my PE-x86-64 to raw binary and copy /b Stage_2.bin+Kernel.bin Stage_2.bin.

Is this correct?

Re: Problem with strings

Posted: Sat Sep 01, 2012 9:24 am
by Combuster
I haven´t duplicate sections in the linker script.
Lies:
*(.rodata)
...
*(.rodata)

Re: Problem with strings

Posted: Sun Sep 02, 2012 7:04 am
by Khronos
Yes, you are right, sorry, I was blind :oops:

Can anyone help me? Thanks for advance

Re: Problem with strings

Posted: Mon Sep 03, 2012 1:07 pm
by FallenAvatar
Does GCC automatically change strings to be null-terminated? *hint*

- Monk

Re: Problem with strings

Posted: Mon Sep 03, 2012 2:15 pm
by Khronos
tjmonk15 wrote:Does GCC automatically change strings to be null-terminated? *hint*

- Monk
Thanks for the answer. No, G++ don´t show any hints or warnings.

I have porting the Kernel source for building in GNU/Linux. This is my Makefile:

Code: Select all

CPP = g++
CPP_PARAMS = -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin
OBJECTS = Stage_3.o kernel.o screen.o string.o io.o idt.o
FAT12MAKER = ./tools/fat12maker/fat12maker


all:
	nasm -fbin bootloader/Stage_1.asm -o Stage_1.bin
	nasm -fbin bootloader/Stage_2.asm -o Stage_2.o

	nasm -felf64 Kernel/Stage_3.asm -o Stage_3.o
	$(CPP) $(CPP_PARAMS) -c Kernel/kernel.cpp -o kernel.o
	$(CPP) $(CPP_PARAMS) -c Kernel/Drivers/screen.cpp -o screen.o
	$(CPP) $(CPP_PARAMS) -c Kernel/string.cpp -o string.o
	$(CPP) $(CPP_PARAMS) -c Kernel/io.cpp -o io.o
	$(CPP) $(CPP_PARAMS) -c Kernel/idt.cpp -o idt.o

	ld -nostdlib -nodefaultlibs -T linker-linux.ld $(OBJECTS) -o Kernel.o
	cat Stage_2.o Kernel.o > Stage_2.bin
	$(FAT12MAKER) -b Stage_1.bin -i Stage_2.bin -o Kernel.img
	bochs -f bochsconf-linux

clean:
	rm *.o
	rm *.bin
And the linker script:

Code: Select all

OUTPUT_FORMAT(binary)
ENTRY(loader)
SECTIONS 
{ 
    . = 0x100000;
    .text :
    { 
        code = .; 
        *(.text) 
        text_end = .;
    }
    .rodata : 
    { 
        rodata = text_end; 
        *(.rodata)
        rodata_end  = .;      
    }    
    .data : 
    { 
        data = rodata_end; 
        *(.data) 
        data_end = .;
    } 
    .bss :  
    { 
        bss = data_end; 
        *(.bss) 
        bss__end = .;
    } 
    end = .; 
}
But now I have a worse problem, because functions like this doesn't work fine!

Code: Select all

extern "C" void kmain(WORD Foo, WORD Foo2)
{
	screen::clear_screen();
	screen::hide_cursor();

	screen::kprintf("Hello!\n");

...
This is the console output of the Makefile:

Code: Select all

khronos@CASA:~/Tanis Kernel$ make
nasm -fbin bootloader/Stage_1.asm -o Stage_1.bin
nasm -fbin bootloader/Stage_2.asm -o Stage_2.o
nasm -felf64 Kernel/Stage_3.asm -o Stage_3.o
g++ -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c Kernel/kernel.cpp -o kernel.o
g++ -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c Kernel/Drivers/screen.cpp -o screen.o
g++ -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c Kernel/string.cpp -o string.o
g++ -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c Kernel/io.cpp -o io.o
g++ -I./Kernel/ -nostdlib -nostartfiles -nodefaultlibs -masm=intel -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c Kernel/idt.cpp -o idt.o
ld -nostdlib -nodefaultlibs -T linker-linux.ld Stage_3.o kernel.o screen.o string.o io.o idt.o -o Kernel.o
cat Stage_2.o Kernel.o > Stage_2.bin
./tools/fat12maker/fat12maker -b Stage_1.bin -i Stage_2.bin -o Kernel.img
FAT12 FileSystem Maker
Developed by Estanislao R. P�rez Nartallo, under the GNU License
Version: 1.0, Date: 29/06/2012

File: Stage_2.bin, Size: 6558 bytes, Sectors count: 13, LBA Address: 0x0002

Image created successfully!
bochs -f bochsconf-linux
========================================================================
                       Bochs x86 Emulator 2.4.6
             Build from CVS snapshot, on February 22, 2011
                   Compiled at Nov 11 2011, 09:31:18
========================================================================
00000000000i[     ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins'
00000000000i[     ] BXSHARE not set. using compile time default '/usr/share/bochs'
00000000000i[     ] reading configuration from bochsconf-linux
00000000000i[     ] lt_dlhandle is 0x25e89a0
00000000000i[PLGIN] loaded plugin libbx_sdl.so
00000000000i[     ] installing sdl module as the Bochs GUI
00000000000i[     ] Bochs x86 Emulator 2.4.6
00000000000i[     ]   Build from CVS snapshot, on February 22, 2011
00000000000i[     ] Compiled at Nov 11 2011, 09:31:18
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   SMP support: no
00000000000i[     ]   APIC support: yes
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   SEP support: yes
00000000000i[     ]   SSE support: sse2
00000000000i[     ]   XSAVE support: no
00000000000i[     ]   AES support: no
00000000000i[     ]   MOVBE support: no
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   1G paging support: no
00000000000i[     ]   VMX support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes, enabled=yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe 
00000000000i[MEM0 ] allocated memory at 0x2b6881072010. after alignment, vector=0x2b6881073000
00000000000i[MEM0 ] 32,00MB
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=32
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/usr/share/bochs/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/40448 ('/usr/share/bochs/VGABIOS-lgpl-latest')
00000000000i[     ] lt_dlhandle is 0x264e080
00000000000i[PLGIN] loaded plugin libbx_cmos.so
00000000000i[     ] lt_dlhandle is 0x264eaa0
00000000000i[PLGIN] loaded plugin libbx_dma.so
00000000000i[     ] lt_dlhandle is 0x264f500
00000000000i[PLGIN] loaded plugin libbx_pic.so
00000000000i[     ] lt_dlhandle is 0x264fd40
00000000000i[PLGIN] loaded plugin libbx_pit.so
00000000000i[     ] lt_dlhandle is 0x26506b0
00000000000i[PLGIN] loaded plugin libbx_vga.so
00000000000i[     ] lt_dlhandle is 0x2650de0
00000000000i[PLGIN] loaded plugin libbx_hdimage.so
00000000000i[     ] lt_dlhandle is 0x26516c0
00000000000i[PLGIN] loaded plugin libbx_floppy.so
00000000000i[     ] lt_dlhandle is 0x2652280
00000000000i[PLGIN] loaded plugin libbx_soundmod.so
00000000000i[     ] lt_dlhandle is 0x2652b00
00000000000i[PLGIN] loaded plugin libbx_pci.so
00000000000i[     ] lt_dlhandle is 0x26536c0
00000000000i[PLGIN] loaded plugin libbx_pci2isa.so
00000000000i[     ] lt_dlhandle is 0x2654000
00000000000i[PLGIN] loaded plugin libbx_usb_common.so
00000000000i[     ] lt_dlhandle is 0x2654860
00000000000i[PLGIN] loaded plugin libbx_unmapped.so
00000000000i[     ] lt_dlhandle is 0x26550d0
00000000000i[PLGIN] loaded plugin libbx_biosdev.so
00000000000i[     ] lt_dlhandle is 0x2655aa0
00000000000i[PLGIN] loaded plugin libbx_speaker.so
00000000000i[     ] lt_dlhandle is 0x2656230
00000000000i[PLGIN] loaded plugin libbx_extfpuirq.so
00000000000i[     ] lt_dlhandle is 0x2656aa0
00000000000i[PLGIN] loaded plugin libbx_gameport.so
00000000000i[     ] lt_dlhandle is 0x2657410
00000000000i[PLGIN] loaded plugin libbx_pci_ide.so
00000000000i[     ] lt_dlhandle is 0x2657de0
00000000000i[PLGIN] loaded plugin libbx_acpi.so
00000000000i[     ] lt_dlhandle is 0x2658720
00000000000i[PLGIN] loaded plugin libbx_ioapic.so
00000000000i[     ] lt_dlhandle is 0x26590d0
00000000000i[PLGIN] loaded plugin libbx_keyboard.so
00000000000i[     ] lt_dlhandle is 0x26598d0
00000000000i[PLGIN] loaded plugin libbx_harddrv.so
00000000000i[     ] lt_dlhandle is 0x266b9a0
00000000000i[PLGIN] loaded plugin libbx_serial.so
00000000000i[     ] lt_dlhandle is 0x266c810
00000000000i[PLGIN] loaded plugin libbx_parallel.so
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Tue Sep  4 00:26:57 2012 (time0=1346711217)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'Kernel.img' ro=1, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[VGA  ] interval=50000
00000000000i[MEM0 ] Register memory access handlers: 0x00000000000a0000 - 0x00000000000bffff
00000000000i[MEM0 ] Register memory access handlers: 0x00000000e0000000 - 0x00000000e0ffffff
00000000000i[VGA  ] VBE Bochs Display Extension Enabled
00000000000i[PLGIN] init_dev of 'unmapped' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[SPEAK] Failed to open /dev/console: Recurso no disponible temporalmente
00000000000i[SPEAK] Deactivating beep on console
00000000000i[PLGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[PLGIN] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[PLGIN] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAP ] initializing I/O APIC
00000000000i[MEM0 ] Register memory access handlers: 0x00000000fec00000 - 0x00000000fec00fff
00000000000i[PLGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[PLGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, none, none
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[PLGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[PLGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[PLGIN] register state of 'unmapped' plugin device by virtual method
00000000000i[PLGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLGIN] register state of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] register state of 'gameport' plugin device by virtual method
00000000000i[PLGIN] register state of 'pci_ide' plugin device by virtual method
00000000000i[PLGIN] register state of 'acpi' plugin device by virtual method
00000000000i[PLGIN] register state of 'ioapic' plugin device by virtual method
00000000000i[PLGIN] register state of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] register state of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLGIN] register state of 'parallel' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x00000000fee00000
00000000000i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
00000000000i[CPU0 ] CPUID[0x00000001]: 00000f23 00000800 00002000 07cbfbff
00000000000i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000001 2a100800
00000000000i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
00000000000i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
00000000000i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
00000000000i[PLGIN] reset of 'unmapped' plugin device by virtual method
00000000000i[PLGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[PLGIN] reset of 'acpi' plugin device by virtual method
00000000000i[PLGIN] reset of 'ioapic' plugin device by virtual method
00000000000i[PLGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLGIN] reset of 'parallel' plugin device by virtual method
00000003305i[BIOS ] $Revision: 1.257 $ $Date: 2011/01/26 09:52:02 $
00000318042i[KBD  ] reset-disable command received
00000442356i[VBIOS] VGABios $Id$
00000442427i[VGA  ] VBE known Display Interface b0c0
00000442459i[VGA  ] VBE known Display Interface b0c5
00000443128i[VBIOS] VBE Bios $Id$
00000760600i[BIOS ] Starting rombios32
00000761033i[BIOS ] Shutdown flag 0
00000761628i[BIOS ] ram_size=0x02000000
00000762048i[BIOS ] ram_end=32MB
00000802574i[BIOS ] Found 1 cpu(s)
00000818429i[BIOS ] bios_table_addr: 0x000fb928 end=0x000fcc00
00000818526i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001146221i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001474149i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001474168i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001474187i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001474206i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001474216i[P2I  ] write: ELCR2 = 0x0a
00001474982i[BIOS ] PIIX3/PIIX4 init: elcr=00 0a
00001482642i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00001484907i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00001487011i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00001487243i[PIDE ] new BM-DMA address: 0xc000
00001487858i[BIOS ] region 4: 0x0000c000
00001489874i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00001490107i[ACPI ] new irq line = 11
00001490119i[ACPI ] new irq line = 9
00001490148i[ACPI ] new PM base address: 0xb000
00001490162i[ACPI ] new SM base address: 0xb100
00001490190i[PCI  ] setting SMRAM control register to 0x4a
00001654281i[CPU0 ] Enter to System Management Mode
00001654291i[CPU0 ] RSM: Resuming from System Management Mode
00001818309i[PCI  ] setting SMRAM control register to 0x0a
00001827062i[BIOS ] MP table addr=0x000fba00 MPC table addr=0x000fb930 size=0xd0
00001828801i[BIOS ] SMBIOS table addr=0x000fba10
00001831952i[BIOS ] Firmware waking vector 0x1ff00cc
00001836891i[BIOS ] ACPI tables: RSDP addr=0x000fbb30 ACPI DATA addr=0x01ff0000 size=0x1f18
00001836927i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001837655i[BIOS ] bios_table_cur_addr: 0x000fbb54
00014041548i[BIOS ] Booting from 0000:7c00
00079784000p[SDL  ] >>PANIC<< User requested shutdown.
00079784000i[CPU0 ] CPU is in long mode (active)
00079784000i[CPU0 ] CS.d_b = 16 bit
00079784000i[CPU0 ] SS.d_b = 32 bit
00079784000i[CPU0 ] EFER   = 0x00000501
00079784000i[CPU0 ] | RAX=00000000000b8000  RBX=0000000000000000
00079784000i[CPU0 ] | RCX=0000000000100d00  RDX=0000000000105520
00079784000i[CPU0 ] | RSP=0000000000105780  RBP=0000000000000000
00079784000i[CPU0 ] | RSI=0000000000100d00  RDI=0000000000105520
00079784000i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00079784000i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00079784000i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00079784000i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00079784000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af PF cf
00079784000i[CPU0 ] | SEG selector     base    limit G D
00079784000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00079784000i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 00000000 0 0
00079784000i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00079784000i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00079784000i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00079784000i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00079784000i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00079784000i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00079784000i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00079784000i[CPU0 ] | RIP=0000000000001260 (0000000000001260)
00079784000i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000000000000
00079784000i[CPU0 ] | CR3=0x00002008 CR4=0x000000b0
00079784000i[CPU0 ] 0x0000000000001260>> jmp .-2 (0x0000000000001260) : EBFE
00079784000i[CMOS ] Last time is 1346711236 (Tue Sep  4 00:27:16 2012)
00079784000i[     ] restoring default signal behavior
00079784000i[CTRL ] quit_sim called with exit code 1
make: *** [all] Error 1
Thanks for advance.

Re: Problem with strings

Posted: Mon Sep 03, 2012 4:48 pm
by FallenAvatar
Khronos wrote: But now I have a worse problem, because functions like this doesn't work fine!

Code: Select all

extern "C" void kmain(WORD Foo, WORD Foo2)
{
	screen::clear_screen();
	screen::hide_cursor();

	screen::kprintf("Hello!\n");

...
Why should it work? That string isn't null terminated...

- Monk

Re: Problem with strings

Posted: Mon Sep 03, 2012 4:55 pm
by bradbobak
tjmonk15 wrote:
Khronos wrote: But now I have a worse problem, because functions like this doesn't work fine!

Code: Select all

extern "C" void kmain(WORD Foo, WORD Foo2)
{
	screen::clear_screen();
	screen::hide_cursor();

	screen::kprintf("Hello!\n");

...
Why should it work? That string isn't null terminated...

- Monk
All string literals in C are '\0' terminated.

Re: Problem with strings

Posted: Mon Sep 03, 2012 5:19 pm
by Khronos
I forgot to post the linker script, edited.

Yes, you are right, but under Windows these method works fine.

Now I can only print a string if I do something like this:

Code: Select all

extern "C" void kmain(WORD Foo, WORD Foo2)
{
	char saludo[] = "Hello!\n";
	screen::clear_screen();
	screen::hide_cursor();

	screen::kprintf(saludo);
But if I declare a const char * int_exceptions[] as global, it doesn't work :evil:

Sorry for disturb you with my errors :oops:
Thanks.

Re: Problem with strings

Posted: Mon Sep 03, 2012 10:54 pm
by jnc100
Check http://wiki.osdev.org/Beginner_Mistakes#Strings. In short, you need to include a *(.rdata) section in your linker script (probably in the .rodata section after *(.rodata)) if using MinGW however we seriously recommend using a cross compiler instead to avoid these issues.

Regards,
John.

Re: Problem with strings

Posted: Mon Sep 03, 2012 11:12 pm
by FallenAvatar
bradbobak wrote:
tjmonk15 wrote:
Khronos wrote:...
Why should it work? That string isn't null terminated...

- Monk
All string literals in C are '\0' terminated.
I wasn't aware of that, good to know. Is that a C thing (ISO Spec?), or a GCC thing?

- Monk

P.S. I'm much more of a C++ guy than, C, so sorry for the confusion.

Re: Problem with strings

Posted: Tue Sep 04, 2012 12:37 am
by Brynet-Inc
tjmonk15 wrote:Is that a C thing (ISO Spec?), or a GCC thing?
I believe it's a "you should probably know this" thing.

Re: Problem with strings

Posted: Tue Sep 04, 2012 5:14 am
by Khronos
Thanks for the answers.
jnc100 wrote:Check http://wiki.osdev.org/Beginner_Mistakes#Strings. In short, you need to include a *(.rdata) section in your linker script (probably in the .rodata section after *(.rodata)) if using MinGW however we seriously recommend using a cross compiler instead to avoid these issues.

Regards,
John.
I included the section *(.rodata) after .rodata how you said me, but using MinGW I continue with the global strings problem. With GCC I can only print a string using local variables :evil:

I'm going crazy with the strings...

Re: Problem with strings

Posted: Tue Sep 04, 2012 5:52 am
by Combuster
Can anyone help me? Thanks for advance
Everything that was posted was there for a reason.

Take the .o file with the string and run it through objdump for the headers, because that's what you should have done in the first place. You still have to in case you really want to understand what gcc does to strings.

After that, I'll be more obvious...
Combuster wrote:Besides the fact that a windows targeted toolchain is not the best idea in general, you have both duplicate and missing sections in your linker script (hint: *)
as in:
*(.rodata)
vs
*(.rodata*)

and of course the same goes for .rdata*


And since it was typed over wrong from the wiki that'll be a hint to more than one of you to be a bit more careful, it's a very important skill in this particular business :wink: