Page 1 of 1

Use of IN/OUT directive

Posted: Sun Oct 25, 2015 3:38 am
by remy
deleted

Re: Use of IN/OUT directive

Posted: Sun Oct 25, 2015 6:24 am
by glauxosdever
Hi,

remy wrote:I'm trying to make use of the IN/OUT directives.
IN/OUT instructions are used to read and write to ports, to answer your question.

Regarding the code, you shouldn't send device specific commands in the bootloader, as you have BIOS services directly accessible. However, real mode is used for this. Only after you have done initializations, switch to Long Mode.

http://wiki.osdev.org/Rolling_Your_Own_Bootloader and http://wiki.osdev.org/My_Bootloader_Does_Not_Work might be of interest.


Regards,
glauxosdever

Re: Use of IN/OUT directive

Posted: Sun Oct 25, 2015 10:13 am
by Schol-R-LEA
To elaborate a bit: there are a number of different ways for the CPU to pass data to and from the peripherals (basically, device outside of the CPU aside from the system memory). The most common one is memory mapping, where part of the main memory address space is redirected by the bus to registers or memory on the peripheral. A related technique is the somewhat misnamed Direct Memory Access, which is where a section of memory is mapped to a mediating device called a DMA controller, which can be triggered to transfer the whole block of memory to or from a device without requiring continued action by the CPU.

While PCs do use memory mapping, especially for video memory and peripheral firmware, and have DMA controllers for disks, the x86 family of processors also has a separate 'port' address space for input and output as well. The IN and OUT instructions (which are instructions with actual opcodes, not assembler directives) are used to access these ports. The original 8086/8088 design only allowed single bytes to be passed to the ports, but newer processors in the family allow for ports of two or four bytes to be addressed as well.

Port I/O is largely a thing of the past today, as most hardware now is memory mapped. It is really only used for the disk controllers, timers, old PS/2 style keyboard and mouse ports, and some parts of the legacy video management.

Re: Use of IN/OUT directive

Posted: Mon Oct 26, 2015 9:22 am
by Combuster
I can see almost every error in the FAQ entry My Bootloader Does Not Work, in combination with a misleading thread title, huge code dump and minimal description of the actual problem. For everyone's sanity and the ability to help you properly this time and the next, could you please spend some time and read the forum rules as well? It would be much appreciated.