Page 2 of 3

Re: I/O functions

Posted: Sat Mar 23, 2013 12:31 am
by p0s1x
I have a only one question... Bare Bones switch CPU to pmode or real mode?

Re: I/O functions

Posted: Sat Mar 23, 2013 12:40 am
by Brendan
Hi,
p0s1x wrote:I have a only one question... Bare Bones switch CPU to pmode or real mode?
GRUB switches to protected mode and then starts the Bare Bones code, and the Bare Bones code stays in protected mode.


Cheers,

Brendan

Re: I/O functions

Posted: Sat Mar 23, 2013 12:57 am
by p0s1x
Brendan wrote:Hi,
p0s1x wrote:I have a only one question... Bare Bones switch CPU to pmode or real mode?
GRUB switches to protected mode and then starts the Bare Bones code, and the Bare Bones code stays in protected mode.


Cheers,

Brendan
Thanks, but i have a problem, ld linking my kernel into PE file, how to make ELF file?
Upd: I don't use GRUB :)

Re: I/O functions

Posted: Sat Mar 23, 2013 3:03 am
by p0s1x
Please help, I need make elf binary.

Re: I/O functions

Posted: Sat Mar 23, 2013 3:19 am
by Brendan
Hi,
p0s1x wrote:
Brendan wrote:GRUB switches to protected mode and then starts the Bare Bones code, and the Bare Bones code stays in protected mode.
Thanks, but i have a problem, ld linking my kernel into PE file, how to make ELF file?
Where in the relevant part of the multi-boot specification does it say you need to use ELF?
p0s1x wrote:Upd: I don't use GRUB :)
If you're not using GRUB or multi-boot, then just use "flat binary" (it's easier).


Cheers,

Brendan

Re: I/O functions

Posted: Sat Mar 23, 2013 3:28 am
by p0s1x
Brendan wrote:Hi,
p0s1x wrote:
Brendan wrote:GRUB switches to protected mode and then starts the Bare Bones code, and the Bare Bones code stays in protected mode.
Thanks, but i have a problem, ld linking my kernel into PE file, how to make ELF file?
Where in the relevant part of the multi-boot specification does it say you need to use ELF?
p0s1x wrote:Upd: I don't use GRUB :)
If you're not using GRUB or multi-boot, then just use "flat binary" (it's easier).


Cheers,

Brendan
I can't create bootable image, my bat:

Code: Select all

@echo off
path = C:\MinGW\bin
gcc -o bin\kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
ld -T bin\linker.ld -o bin\kernel.bin bin\loader.o bin\kernel.o
objcopy -O elf32-i386 bin\kernel.bin
dd if=bin\kernel.bin of=bin\image.img bs=1440k
PAUSE
Bootable image (output) don't boot in Bochs. If I boot it with VMware Player, I get black screen.

Thanks.

Re: I/O functions

Posted: Sat Mar 23, 2013 4:18 am
by bluemoon
What you need is not being babysit with every problem you encountered, not that we're not willing to help (indeed we are willing to help), but it's not the way to learn and proceed for os development.

You should check out the Main_Page, Required_Knowledge, Beginner_Mistakes and Getting_Started before copy & paste the tutorials.

Re: I/O functions

Posted: Sat Mar 23, 2013 8:05 am
by mich
bluemoon wrote:before copy & paste the tutorials.
Also when you should copy & paste tutorials make sure they work _before_ adding your own code.

Also make sure the tutorial is compatible with your tool chain because the bare bones tutorial you linked says:
"This tutorial assumes you have a compiler / assembler / linker toolchain capable of handling ELF files."
"[...] GRUB will be the bootloader, and the kernel will be in ELF format."
"GRUB (a Multiboot compliant boot loader) puts [...] the system [into] 32-bit Protected Mode"

This contrasts sharply with your statements in this thread:
p0s1x wrote:Bare Bones switch CPU to Real or Protected mode?
p0s1x wrote:I have a only one question... Bare Bones switch CPU to pmode or real mode?
p0s1x wrote:Thanks, but i have a problem, ld linking my kernel into PE file, how to make ELF file?
Upd: I don't use GRUB :)
Anyway I would highly recommend using Linux as your development platform because it makes away with lots of your problems such as PE files.

But even if you don't want to the original Bare Bones tutorial already explains what you need to do to make ELF files:
"On a Windows machine, you are strongly encouraged to set up a GCC Cross-Compiler, as it removes all the various toolchain-specific issues you might have ("PE operation on a non-PE file", "unsupported file format", and a number of others)."

But again as already said try Linux, you can even use Virtualbox so you can run it inside Windows. Ubuntu is an easy to use Linux distribution.

Then try to follow the Bare Bones tutorial again, step by step to the point where you see "character 'A'" in "light grey (7) on black (0)" on the screen of your favourite emulator. I personally prefer, and would recommend, QEMU because it has a build in Multiboot boot loader thus booting is as simple as "$ qemu -kernel kernel.elf".

P.S.
p0s1x wrote: I can't create bootable image, my bat:

Code: Select all

@echo off
path = C:\MinGW\bin
gcc -o bin\kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs
ld -T bin\linker.ld -o bin\kernel.bin bin\loader.o bin\kernel.o
objcopy -O elf32-i386 bin\kernel.bin
dd if=bin\kernel.bin of=bin\image.img bs=1440k
PAUSE
Bootable image (output) don't boot in Bochs. If I boot it with VMware Player, I get black screen.

Thanks.
You need a Multiboot loader to load the Bare Bone tutorial. Please read the Bare Bone tutorial. And every time it says you need something, such as GRUB, please don't consider it optional but rather mandatory!
Also you batch file is missing this whole chapter of the Bare Bone tutorial or how do you try to boot the not-bootable[1] image in Bochs?

[1] The Bare Bones tutorial does not give you a bootable kernel. It is just a Multiboot compliant binary and needs a Multiboot boot loader to boot.

Re: I/O functions

Posted: Sat Mar 23, 2013 10:30 am
by Mikemk
Qemu is difficult to set up on windows, and onx86, bochs is just as good.

PS, technically, you can set up ubuntu in an emulator, then qemu in that, but...

Re: I/O functions

Posted: Sat Mar 23, 2013 11:03 pm
by Nessphoro
m12 wrote:Qemu is difficult to set up on windows
Sources, please?

This site has pre-compiled windows binaries. I do not see how easier can it get.
http://lassauge.free.fr/qemu/

l2google

Re: I/O functions

Posted: Sun Mar 24, 2013 12:43 pm
by Mikemk
Nessphoro wrote:
m12 wrote:Qemu is difficult to set up on windows
Sources, please?

This site has pre-compiled windows binaries. I do not see how easier can it get.
http://lassauge.free.fr/qemu/

l2google
Why don't we put that link in the wiki under Qemu?

Re: I/O functions

Posted: Sun Mar 24, 2013 1:00 pm
by bluemoon
m12 wrote:Why don't we put that link in the wiki under Qemu?
It's on the first link from the official qemu wiki / Links / "Unofficial QEMU binaries" section, it should be easy to find it.

Re: I/O functions

Posted: Fri May 03, 2013 1:38 pm
by betatest
You can use this code:

Anyone here should know how to #define their own WHITE_TEXT value.

Code: Select all

 
unsigned int k_printf(char *message, unsigned int line) {
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0) {
if(*message=='\n') {
line++;
i=(line*80*2);
*message++;
} else {
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
return(1);
};

Re: I/O functions

Posted: Sat May 04, 2013 8:55 am
by p0s1x
Ok, I normally builded OS.
printf and cls functions works. How about keyboard input?
I try this:

Code: Select all

char getch() {
	asm ("mov $1, %ah");
	asm ("int $0x16");
}
but I don't know how to use c variables in inline assembler.

Re: I/O functions

Posted: Thu May 09, 2013 3:10 pm
by gusc
I know that I'm jumping late in to the printf game, but I wanted to share my tiny writef implementation https://github.com/gusc/mbr2gpt/blob/ma ... rnel/lib.c

If it helps, you're welcome!