简体   繁体   中英

X86 assembly instruction to MIPS instruction (Port, IN, I/O)

In X86, there is an instruction called IN:
https://c9x.me/x86/html/file_module_x86_id_139.html https://en.wikipedia.org/wiki/X86_instruction_listings

MIPS does not have this instruction:
http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html

I want to write my own IN instruction in MIPS.
How can this be done?
We are writing an operating system using C and MIPS:
https://github.com/uu-os-2018/project-iota

This function results in:
Error: unrecognized opcode inb $2,lo

static inline uint8_t inb(uint16_t port)  {  
     uint8_t ret;  
    asm volatile ( "inb %1, %0"  
                   : "=a"(ret)  
                   : "Nd"(port) );  
    return ret;  
}

The significant difference between in/out and memory access instructions is in how the hardware behaves. There is no way for software to make a system that uses I/O-mapped I/O work with memory instructions or vice-versa. Since MIPS systems use only memory-mapped I/O, there is no possible use for in/out instructions.

The predecessors of the x86 family (the 8080 and 8085 processors) only had a 16-bit address bus and thus could only use a total of 64 kB of memory.

Reserving some of this space for devices was seen as problematic as it limited the small amount of memory even more. So the processors got a second address space (I/O space), with an additional 64 kB, by using IN and OUT instructions instead of load and store. The difference appeared externally as a special pin, in essence giving the CPU a 17th address bit.

When Intel designed the 8086, they followed this design from the 8085 as some kind of limited backward compatibility. Despite this the original PC reserved the space between 640 kB and 1 MB for devices using memory mapped I/O. The video board, for example, appeared in this space.

The designers of the MIPS series didn't have those concerns about predecessors, and having gigabytes of address space from the start they didn't see a problem in using some 64 kB of this space for devices. That way they also only had to provide load and store instructions and could skip the IN and OUT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM