I/O functions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
p0s1x
Posts: 18
Joined: Thu Mar 21, 2013 8:37 am

Re: I/O functions

Post by p0s1x »

I have a only one question... Bare Bones switch CPU to pmode or real mode?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: I/O functions

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
p0s1x
Posts: 18
Joined: Thu Mar 21, 2013 8:37 am

Re: I/O functions

Post 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 :)
User avatar
p0s1x
Posts: 18
Joined: Thu Mar 21, 2013 8:37 am

Re: I/O functions

Post by p0s1x »

Please help, I need make elf binary.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: I/O functions

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
p0s1x
Posts: 18
Joined: Thu Mar 21, 2013 8:37 am

Re: I/O functions

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: I/O functions

Post 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.
mich
Posts: 18
Joined: Sun Nov 11, 2012 5:36 pm

Re: I/O functions

Post 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.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: I/O functions

Post 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...
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: I/O functions

Post 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
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: I/O functions

Post 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?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: I/O functions

Post 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.
betatest
Posts: 2
Joined: Fri May 03, 2013 12:11 am

Re: I/O functions

Post 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);
};
User avatar
p0s1x
Posts: 18
Joined: Thu Mar 21, 2013 8:37 am

Re: I/O functions

Post 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.
gusc
Member
Member
Posts: 50
Joined: Tue Feb 05, 2013 1:42 pm

Re: I/O functions

Post 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!
Post Reply