Actually, that address is a holdover of realmode, not protected mode. While still mapped (up to a point) when you switch to protected mode, it does not need to, nor usually will, remain mapped to that address range. Furthermore, if you have enabled paging then that code could be doing all sorts of nasty things to the byte at 0xB8000. Additionally, your code only affects a single byte of memory, and thus doesn't actually print your string so much as it puts '!' to the byte at address 0xB8000.When I say "direct access to physical memory" I mean that literally. For example, on x86 architecture when an OS is running in PMode (protected, 32-bit memory mode) with video memory in color text mode, the contents of video memory are in the address range 0x000B8000 to 0x000BFFFF. Want to write to video memory directly?
[source lang="cpp"]char* screen = (char *) 0xB8000;const char* str = "Hello, OS world!\0";char* pstr = (char *)str;for( ; *pstr != '\0'; ++pstr) *screen = *pstr;[/source]
Show differencesHistory of post edits
#ActualWashu
Posted 27 October 2012 - 02:24 AM
#1Washu
Posted 27 October 2012 - 02:24 AM
Actually, that address is a holdover of realmode, not pmode. While still mapped (up to a point) when you switch to protected mode, it does not need to, nor usually will, remain mapped to that address range. Furthermore, if you have enabled paging then that code could be doing all sorts of nasty things to the byte at 0xB8000. Additionally, your code only affects a single byte of memory, and thus doesn't actually print your string so much as it puts '!' to the byte at address 0xB8000.When I say "direct access to physical memory" I mean that literally. For example, on x86 architecture when an OS is running in PMode (protected, 32-bit memory mode) with video memory in color text mode, the contents of video memory are in the address range 0x000B8000 to 0x000BFFFF. Want to write to video memory directly?
[source lang="cpp"]char* screen = (char *) 0xB8000;const char* str = "Hello, OS world!\0";char* pstr = (char *)str;for( ; *pstr != '\0'; ++pstr) *screen = *pstr;[/source]