Posted: Sat Mar 24, 2007 12:11 am
Try
instead.
Code: Select all
unsigned char p[] = "Hello World!";
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
unsigned char p[] = "Hello World!";
Code: Select all
*(.rodata)
Code: Select all
*(.rodata*)
Code: Select all
init.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000002cd 00000000 00000000 00000040 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 00000310 2**2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 00000310 2**2
ALLOC
3 .rodata 00000008 00000000 00000000 00000310 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .rodata.str1.1 0000001e 00000000 00000000 00000318 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .rodata.str1.32 00000072 00000000 00000000 00000340 2**5
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .note.GNU-stack 00000000 00000000 00000000 000003b2 2**0
CONTENTS, READONLY
7 .comment 00000044 00000000 00000000 000003b2 2**0
CONTENTS, READONLY
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
load_address = 0x100000; /* at 1M */
SECTIONS
{
. = load_address;
.text :
{
*(.multiboot.header) /* must be within 8k, so put first */
*(.text)
*(.rodata*)
}
.data : {
data = .;
*(.data)
}
.bss : {
bss = .;
*(.bss)
*(COMMON)
}
_kernel_end = .;
}
Code: Select all
void main () {
_clrscr (WINCOL);
unsigned char p[]="HELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLD";
__asm ("hlt");
}
Code: Select all
00005146035e[CPU0 ] write_virtual_checks(): write beyond limit, r/w
00005146035e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00005146035e[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00005146035i[CPU0 ] protected mode
00005146035i[CPU0 ] CS.d_b = 32 bit
00005146035i[CPU0 ] SS.d_b = 32 bit
00005146035i[CPU0 ] | EAX=0000000e EBX=00007a00 ECX=0000000e EDX=000b8eff
00005146035i[CPU0 ] | ESP=0008ffb0 EBP=0008fff8 ESI=00001c20 EDI=0008ffb0
00005146035i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00005146035i[CPU0 ] | SEG selector base limit G D
00005146035i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00005146035i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00005146035i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00005146035i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00005146035i[CPU0 ] | ES:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00005146035i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00005146035i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00005146035i[CPU0 ] | EIP=0000110d (0000110d)
00005146035i[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00005146035i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00005146035i[CPU0 ] >> rep movsd dword ptr es:[edi], dword ptr ds:[esi] : F3A5
00005146035e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Oh ok. It'll tell you why. When you writeneon wrote: I went back to my code and insured it.. keeping it as unsigned char*
works while unsigned char p[] causes a triple fault.
Code: Select all
unsigned char p[] = "foobar";
Code: Select all
> rep movsd dword ptr es:[edi], dword ptr ds:[esi] : F3A5
Code: Select all
mov ds,cs
mov es,cs
mov ss,cs
That will not work. For one, CS needs a code segment, DS/ES/SS need a data segment....pcmattman wrote:Code: Select all
mov ds,cs mov es,cs mov ss,cs
Code: Select all
unsigned char p[]="HELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLD";
_printf (p);
Code: Select all
unsigned char p[]="HELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLDHELLO WORLD";
int i=0;
for (i=0; i<10; i++)
p[i]='3';
_printf (p);
Code: Select all
gcc -ffreestanding -nostdlib -nostartfiles -c -o Main.o Main.c
ld -i Link.ld -o KERNEL.o Stage2.o Main.o
Code: Select all
ld -T Link.ld -o KERNEL.o Stage2.o Main.o
Code: Select all
-i Perform an incremental link (same as option -r).
Code: Select all
-r
--relocatable
Generate relocatable output---i.e., generate an output file that can in turn serve as input to ld. This is
often called partial linking. As a side effect, in environments that support standard Unix magic numbers, this
option also sets the output file's magic number to "OMAGIC". If this option is not specified, an absolute file
is produced. When linking C++ programs, this option will not resolve references to constructors; to do that,
use -Ur.
When an input file does not have the same format as the output file, partial linking is only supported if that
input file does not contain any relocations. Different output formats can have further restrictions; for exam-
ple some "a.out"-based formats do not support partial linking with input files in other formats at all.
This option does the same thing as -i.
Code: Select all
ld -T Link.ld -o KERNEL.o Main.o
objcopy -R .note -R .comment -S -O binary KERNEL.o KERNEL.bin
objcopy.exe: KERNEL.o: File format not recognized
Code: Select all
ENTRY("0x00000000")
OUTPUT_FORMAT("binary")
SECTIONS
{
.text 0x1000 :
{
code = .; _code = .; __code = .;
*(.text*)
}
.data :
{
data = .; _data = .; __data = .;
*(.data*)
}
.rodata :
{
rodata = .; _rodata = .; __rodata = .;
*(.rodata*)
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss*)
}
end = .; _end = .; __end = .;
}