Page 1 of 1

wats this code means???

Posted: Fri Jan 02, 2004 12:00 am
by yahoo
this is the code in script.ld file...plz tell me wats thsi means and also
wat is the use of this file?
plz tell in detail
INPUT("lib\libc.a")
OUTPUT_FORMAT("binary")
SECTIONS
{
    .text 0x100000 : /* 1 meg */
    {
/* kernel code */
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
    }
    .data :
    {
/* kernel data */
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
    }
    .bss :
    {
/* kernel BSS */
bss = .; _bss = .; __bss = .;
*(.bss)
*(COMMON) /* GNU C "common" variables */
. = ALIGN(4096);
    }
    end = .; _end = .; __end = .;
}

RE:wats this code means???

Posted: Fri Jan 02, 2004 12:00 am
by carbonBased
It's a linker script... it tells LD how the resultant binary should look.  I've added some # comments that might make it more clear:

INPUT("lib\libc.a")
OUTPUT_FORMAT("binary")

# tell's LD to output without an binary format (such as elf, coff, or pe)... I really don't know why they'd be using libc.a as input, however... this is for an OS, right!?

# next, start defining sections...
SECTIONS
{

  
    # the .TEXT (or code) section starts at 1MB...
     .text 0x100000 : /* 1 meg */
     {

# make a bunch of variables visible to your C/C++ code, with addresses equivalent to . which is the current position in the binary at this point... in other words, 1MB
code = .; _code = .; __code = .;

# include ALL .TEXT sections (for all objects) inside this section of the binary
*(.text)

# and then round the current position up to the nearest 4kb page (such that the next section will be page aligned...
. = ALIGN(4096);
     }


    # this section is roughly equivalent to the above, so I'm sure you can figure it out
     .data :
     {
/* kernel data */
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
     }

    # perhaps a bit different, only because it includes all .BSS sections from all input objects, as well as all COMMON sections
     .bss :
     {
/* kernel BSS */
bss = .; _bss = .; __bss = .;
*(.bss)
*(COMMON) /* GNU C "common" variables */
. = ALIGN(4096);
     }

     # define another variable, with an address equal to the current address in the binary... in other words, the absolute end of the kernel in memory
     end = .; _end = .; __end = .;
}


Cheers, hopefully that all makes sense!
Jeff

RE:wats this code means???

Posted: Sat Jan 03, 2004 12:00 am
by yahoo
can u plz explain lines having number 22,24,25,26, and 45 to onwards this is the entry .asm which was included in previous script.ld fil we r making an OS and having problems in understanding these initial things
and wat if we remove lines from 9 to 14 and 53 toi 57 since we r not making a multi boot kernel..will it work.im sure u would help
6.
7. ; entry.asm
8. ;---------------------------------------------------------------------------------------------------
9. MULTIBOOT_PAGE_ALIGN equ 1<<0
10. MULTIBOOT_MEMORY_INFO equ 1<<1
11. MULTIBOOT_AOUT_KLUDGE equ 1<<16
12. MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
13. MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
14. MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

15. [SECTION .text]
16. [BITS 32]

17. EXTERN _main, _inthand              ; C Code

18. entry:                              ; Entry Point from Boot Sector
19. cli                              ; Make Sure Interrupts are disabled
20. lgdt [gdtptr]                    ; Load new GDT
21. mov ax, GDT_DATA                 ; Update Registers to New GDT Segment values
22. mov ds, ax
23. mov es, ax
24. mov fs, ax
25. mov gs, ax
26. mov ss, ax
27. jmp GDT_CODE:newgdt             ; Jump to code with new register values
28. newgdt:
29. mov esi, stub0                   ; Load address of first stub
30. mov ecx, (idtend - idt) >> 3     ; Get number of interrupts
31. mov edi, idt                     ; Load address of IDT Table
32. setupints:
33. mov eax, esi
34. mov [edi], ax                    ; Low Byte
35. shr eax, 16
36. add edi, 6
37. mov [edi], ax                    ; High Byte
38. add edi, 2
39. add esi, (stub1 - stub0)
40. loop setupints                   ; Setup Next Interrupt Gate
41. lidt [idtptr]                    ; Load IDT Table
42. mov esp, 0x200000                ; Setup Kernel Stack
43. call _main                       ; Call C Code
44. jmp $                            ; If C Code returns freeze

45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46. ; Multiboot header for GRUB bootloader. This must be in the first 8K
47. ; of the kernel file. We use the aout kludge so it works with ELF,
48. ; DJGPP COFF, Win32 PE, or other formats.
49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

50. ; these are in the linker script file
51. EXTERN code, bss, end

52. ALIGN 4
53. mboot:
54. dd MULTIBOOT_HEADER_MAGIC
55. dd MULTIBOOT_HEADER_FLAGS
56. dd MULTIBOOT_CHECKSUM
57. ; aout kludge. These must be PHYSICAL addresses
58. dd mboot
59. dd code
60. dd bss
61. dd end
62. dd entry

63. %macro STUB 1                       ; Template for all ISR stubs - Macro with 1 argument
64. stub%1:
65. push gs                          ; Store all registers on stack
66. push fs
67. push es
68. push ds
69. pusha
70. mov ax, GDT_DATA                 ; Set registers to known values
71. mov ds, eax
72. mov es, eax
73. mov fs, eax
74. mov gs, eax
75. mov eax, %1
76. push eax
77. mov eax,_inthand
78. call eax
79. pop eax
80. popa                             ; Restore all registers
81. pop ds
82. pop es
83. pop fs
84. pop gs
85. iret
86. %endmacro

87. %assign i 0                         ; Define all 256 interupts
88. %rep (0FFh)
89. STUB i                      ; Using template above
90. %assign i (i + 1)
91. %endrep

92. [SECTION .data]

93. gdt:
94. dw  0               ; NULL
95. dw  0
96. db  0
97. db  0
98. db  0
99. db  0

100. dw  0               ; Unused
101. dw  0
102. db  0
103. db  0
104. db  0
105. db  0

106. GDT_DATA equ $-gdt           ; Data
107. dw  0FFFFh
108. dw  0
109. db  0
110. db  92h
111. db  0CFh
112. db  0

113. GDT_CODE equ $-gdt           ; Code
114. dw  0FFFFh
115. dw  0
116. db  0
117. db  9Ah
118. db  0CFh
119. db  0
120. gdtend:

121. gdtptr:
a. dw  gdtend - gdt - 1
b. dd  gdt

122. idt:
123. %rep 256
a. dw  0
b. dw  GDT_CODE
c. db  0
d. db  8Eh
e. dw  0
124. %endrep
125. idtend:

126. idtptr:
a. dw  idtend - idt - 1
b. dd  idt

RE:wats this code means???

Posted: Sat Jan 03, 2004 12:00 am
by df
can you please explain the number 42 and the meaning of life as it pertains to a sea snail on the verge of extinction?

honestly.. mov ss, ax is a basic command. whats at line 45+ is a multiboot header and GDT data.

you can remove likes 9-14 and any other lines you like, even then if you cant understand mov ss,ax, then i doubt you understand any of the rest of the code.

RE:wats this code means???

Posted: Sat Jan 03, 2004 12:00 am
by Dangamoose
These kind of questions could easily be answered if you read some books. They can also expand your knowledge to help you be able to answer the questions you'll get of the much much harder bits in writing an OS.
And 'mov ss, ax' aint **** compared to other things.

I've read maybe 10 books now and im getting into the swing of os development. You should to.

Start with the Intel Manuals on x86 processors. You'll get an idea of how they work.
The second intel manual, Instruction Set Reference, will tell you exactly what 'mov ss, ax' does, and other instructions, so you can build your own.

A link is in the develeopment links in the nav strip at the top of this site.

Dangamoose.

RE: Now theres an idea.

Posted: Sat Jan 03, 2004 12:00 am
by Dangamoose
With everyone on this board surely knows something unique they could advise others with. So why not write some sort of manual, and make a pdf from it.

Dangamoose.

RE:wats this code means???

Posted: Sun Jan 04, 2004 12:00 am
by pete
The reason for including libc.a is that that was an archive of all my libc functions. Is that from Therx?

Pete