[Setting up a quick+basic environment -> Linux/*BSD] |
||
![]() ![]() Delta Gen int16h I write this post with the assumption that you know how to find and install development tools and other utilities on your UNIX-like OS, as writing up each step for every distro/OS at this stage would be a little pointless as anyone developing for OSR/CAROS should have a basic/good knowledge of their OS||distro and will have at least compiled applications before. Step 1 - Initial Tool-chain Install GCC, Binutils, nasm, etc - basically all the usual development tools and libraries needed to compile+link asm and C++ code. Step 2 - Emulator Installation Install QEMU (kqemu, the kernel module is optional). You may also use Bochs, VMWare, VirtualBox etc but I will be working with and covering QEMU at this stage. Step 3 - Initial Tree Create the following directory structure somewhere: CAROS/
-> src/
-> mnt/
-> doc/
Step 4 - The Floppy image with GRUBDownload caros.img, and place it in the CAROS directory. This is a floppy disk image with GRUB pre-installed and setup to load the file /kernel from the first floppy drive. This is where we will copy the initial kernel builds to for testing. Step 5 - Booting the image We will write a tiny script to boot our floppy image, for now - we will execute qemu with the following options:
#!/bin/sh qemu -M pc -fda caros.img -boot a -m 32 -std-vga -serial file:debug.txtStep 6 - Transferring the kernel to floppy image The easiest way to do this is to mount the floppy image through the loopback device, copy kernel to the root of the image and unmount it. We can write another little script to automate this process: (install.sh) #!/bin/sh sudo mount -oloop caros.img mnt sudo cp src/kernel /mnt/kernel sudo umount caros.imgThis will mount the image, copy the kernel to it and then unmount it :) Step 7 - The Makefile In the 'src' directory, create a new text file named 'Makefile'. This file will basically inform 'make' how to compile and link our kernel/'OS'. SORES = bootstrap.o kernel.o
CFLAGS = -nostdlib -nostdinc -fno-builtin -fno-stack-protector
ASFLAGS = -felf
LDFLAGS = -Tlinker.ld
all: $(SORES) link
link:
ld $(LDFLAGS) -o kernel $(SORES)
.so.o:
nasm $(ASFLAGS) $<
clean:
-rm *.o kernel
Let's explain each line of this Makefile:
Step 8 - linker.ld The linker (ld) script is quite important for this project, it will tell 'ld' how to structure our kernel binary. I had already wrote notes at the top of this file before writing this, so I will just paste the whole file here: (linker.ld) /*
This file is used by the linker (ld) so that it knows how to structure(link)
our kernel binary. Our linker script informs ld the following:
- The entry of our kernel should be 'start'
- The .text section (where the actual code is in Elfs) should be the first
section, and should start at 1MB (0x100000).
- The .data section is for initialised, static data - this should be placed
after our .text section and is page-aligned (more on memory paging later).
- You will notice within our .data section that .rodata is present... this
is used to store read-only/static data such as constants. In memory, data
stored in .rodata will either go into the process' code segment or data
segment. This is a feature mostly unique to Operating Systems such as Linux
and may be discussed in a document about the Elf executable format.
- The .bss section is for initialised, static data and will be placed after
.data, also being page-aligned.
*/
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
That's it for now, I'll post the code for a basic mult-boot bootstrap and kernel later ;)* -serial can also be setup to use a network socket or other devices for debugging, but for now outputting to a text file is most useful. Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.01685 seconds |