OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:12 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: why 'Delay is needed after doing I/O'?
PostPosted: Mon Aug 05, 2019 11:40 pm 
Offline

Joined: Tue Jul 30, 2019 11:53 pm
Posts: 3
When I read the Linux kernel source code(Linux 3.10.0), I noticed following codes in the file 'arch/x86/boot/pm.c':
Code:
22 static void realmode_switch_hook(void)
23 {
24         if (boot_params.hdr.realmode_swtch) {
25                 asm volatile("lcallw *%0"
26                              : : "m" (boot_params.hdr.realmode_swtch)
27                              : "eax", "ebx", "ecx", "edx");
28         } else {
29                 asm volatile("cli");
30                 outb(0x80, 0x70); /* Disable NMI */
31                 io_delay();
32         }
33 }

The function call 'io_delay()' here is to let the CPU wait for some time (by 'outb' a byte to the diagnostics IO Port 0x80), and my question is:
Why does it need to wait for some delay after doing I/O?


Top
 Profile  
 
 Post subject: Re: why 'Delay is needed after doing I/O'?
PostPosted: Mon Aug 05, 2019 11:52 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Most devices require a delay after writing to their command registers to give the device time to respond to the command. Alternatively, there may be a status register that can be polled to indicate when a command has been processed.

Ignoring ths is the sort of thing that can cause an OS to run on an emulator but not a real CPU.


Top
 Profile  
 
 Post subject: Re: why 'Delay is needed after doing I/O'?
PostPosted: Tue Aug 06, 2019 12:34 am 
Offline

Joined: Tue Jul 30, 2019 11:53 pm
Posts: 3
iansjack wrote:
Most devices require a delay after writing to their command registers to give the device time to respond to the command. Alternatively, there may be a status register that can be polled to indicate when a command has been processed.

Ignoring ths is the sort of thing that can cause an OS to run on an emulator but not a real CPU.

Thank you very much, :)


Top
 Profile  
 
 Post subject: Re: why 'Delay is needed after doing I/O'?
PostPosted: Tue Aug 06, 2019 2:58 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I should have mentioned another possibility. Some devices can be configured to issue an interrupt to notify the cpu that an operation has completed. Typically this is used with network controllers or drive controllers, where the time to complete some operations may be relatively long. That way the whole system doesn't have to stop waiting for an i/o operation. And, of course, a keyboard controller is normally configured this way.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group