web siteweb site examplesexamples 1 mode of operation protected mode 4 gb 32-bit address windows,...

38
1 Web site Examples Mode of Operation Protected mode 4 GB 32-bit address Windows, Linux Real-address mode 1 MB space 20-bit address MS-DOS

Post on 20-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

1Web site Examples

Mode of Operation

Protected mode 4 GB 32-bit address Windows, Linux

Real-address mode 1 MB space 20-bit address MS-DOS

Page 2: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

2Web site Examples

Real-Address mode

1 MB RAM maximum addressable Application programs can access any area of

memory Single tasking Supported by MS-DOS operating system

Page 3: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

3Web site Examples

Segmented MemorySegmented memory addressing: absolute (linear) address is a

combination of a 16-bit segment value added to a 16-bit offset

Page 4: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

4Web site Examples

Calculating Linear Addresses

Given a segment address, multiply it by 16 (add a hexadecimal zero), and add it to the offset

Example: convert 08F1:0100 to a linear address

Adjusted Segment value: 0 8 F 1 0

Add the offset: 0 1 0 0

Linear address: 0 9 0 1 0

Page 5: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

5Web site Examples

Protected Mode

4 GB addressable RAM (00000000 to FFFFFFFFh)

Each program assigned a memory partition which is protected from other programs

Designed for multitasking Supported by Linux & MS-Windows

Page 6: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

6Web site Examples

Flat Model All segments are mapped to the entire 32-bit physical address

space of the compter.. Each segment is defined by a segment descriptor, a 64-bit value stored in a table known as the global descriptor table (GDT).

Page 7: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

7Web site Examples

Multi-Segment Model Each program has a local descriptor table (LDT)

holds descriptor for each segment used by the program

Page 8: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

32-Bit Windows Programming

Page 9: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

9Web site Examples

Standard Console Handles

STD_INPUT_HANDLE standard input

STD_OUTPUT_HANDLE standard output

STD_ERROR_HANDLE standard error output

A handle is an unsigned 32-bit integer. The following MS-Windows constants are predefined:

Page 10: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

10Web site Examples

GetStdHandle

GetStdHandle returns a handle to a console stream Specify the type of handle (see previous slide) The handle is returned in EAX Prototype:

GetStdHandle PROTO,

nStdHandle:DWORD ; handle type

Page 11: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

11Web site Examples

ReadConsole The ReadConsole function provides a convenient

way to read text input and put it in a buffer. Prototype:

ReadConsole PROTO,

handle:DWORD, ; input handle

pBuffer:PTR BYTE, ; pointer to buffer

maxBytes:DWORD, ; number of chars to read

pBytesRead:PTR DWORD, ; ptr to num bytes read

notUsed:DWORD ; (not used)

Page 12: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

12Web site Examples

ReadConsole Example

Page 13: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

13Web site Examples

ReadConsole Example

Page 14: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

14Web site Examples

ReadConsole Example

Page 15: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

15Web site Examples

ReadConsole Example

Page 16: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

16Web site Examples

WriteConsole The WriteConsole function writes a string to

the screen, using the console output handle. Prototype:

WriteConsole PROTO,

handle:DWORD, ; output handle

pBuffer:PTR BYTE, ; pointer to buffer

bufsize:DWORD, ; size of buffer

pCount:PTR DWORD, ; output count

lpReserved:DWORD ; (not used)

Page 17: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

17Web site Examples

WriteConsole Example

Page 18: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

18Web site Examples

WriteConsole Example

Page 19: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

19Web site Examples

WriteConsole Example

Page 20: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

20Web site Examples

CreateFile CreateFile either creates a new file or opens an

existing file. If successful, it returns a handle to the open file; otherwise, it returns a special constant named INVALID_HANDLE_VALUE.

Prototype:

CreateFile PROTO,

pFilename:PTR BYTE, ; ptr to filename

desiredAccess:DWORD, ; access mode

shareMode:DWORD, ; share mode

lpSecurity:DWORD, ; ptr to security attribs

creationDisposition:DWORD, ; file creation options

flagsAndAttributes:DWORD, ; file attributes

htemplate:DWORD ; handle to template file

Page 21: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

21Web site Examples

CreateFile Example

INVOKE CreateFile,ADDR filename, ; ptr to filenameGENERIC_READ, ; access modeDO_NOT_SHARE, ; share modeNULL, ; ptr to security attributesOPEN_EXISTING, ; file creation optionsFILE_ATTRIBUTE_NORMAL, ; file attributes0 ; handle to template file

Opens an existing file for reading:

Page 22: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

22Web site Examples

CreateFile Example

INVOKE CreateFile,ADDR filename,GENERIC_WRITE, ; access modeDO_NOT_SHARE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0

Opens an existing file for writing:

Page 23: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

23Web site Examples

CreateFile Example

INVOKE CreateFile,ADDR filename,GENERIC_WRITE,DO_NOT_SHARE,NULL,CREATE_ALWAYS, ; overwrite existing fileFILE_ATTRIBUTE_NORMAL,0

Creates a new file with normal attributes, erasing any existing file by the same name:

Page 24: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

24Web site Examples

ReadFile

ReadFile reads text from an input file Prototype:

ReadFile PROTO,

handle:DWORD, ; handle to file

pBuffer:PTR BYTE, ; ptr to buffer

nBufsize:DWORD, ; num bytes to read

pBytesRead:PTR DWORD, ; bytes actually read

pOverlapped:PTR DWORD ; ptr to asynch info

Page 25: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

25Web site Examples

ReadFile Example

Page 26: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

26Web site Examples

ReadFile Example

Page 27: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

27Web site Examples

ReadFile Example

Page 28: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

28Web site Examples

WriteFile WriteFile writes data to a file, using an output

handle. The handle can be the screen buffer handle, or it can be one assigned to a text file.

Prototype:WriteFile PROTO,

fileHandle:DWORD, ; output handle

pBuffer:PTR BYTE, ; pointer to buffer

nBufsize:DWORD, ; size of buffer

pBytesWritten:PTR DWORD, ; num bytes written

pOverlapped:PTR DWORD ; ptr to asynch info

Page 29: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

29Web site Examples

WriteFile Example

Page 30: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

30Web site Examples

WriteFile Example

Page 31: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

31Web site Examples

WriteFile Example

Page 32: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

16-Bit MS-DOS Programming

Page 33: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

33Web site Examples

Interrupt

Do something else, and get interrupted when I/O events happen.

May be triggered by hardware or software.

Page 34: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

34Web site Examples

INT I/O Example

Page 35: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

35Web site Examples

INT I/O Example

Page 36: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

36Web site Examples

Interrupt Vector Processing

Page 37: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

37Web site Examples

Interrupt Vector Processing

Page 38: Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address

38Web site Examples

Common Interrupts

INT 10h Video Services INT 16h Keyboard Services INT 17h Printer Services INT 1Ah Time of Day INT 1Ch User Timer Interrupt INT 21h MS-DOS Services