4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.

Slides:



Advertisements
Similar presentations
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Advertisements

There are two types of addressing schemes:
COMP 2003: Assembly Language and Digital Logic
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Lecture 6 Machine Code: How the CPU is programmed.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Defining protected-mode segment-descriptors An example of a protected-mode bootsector application that draws a message to the video display.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
Kip Irvine: Assembly Language for Intel-Based Computers
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Administrative Overview 6 Projects Design Review: Monday before 6:30pm Lab Friend Center 010 (“Fishbowl”)
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
The Pentium Processor.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Text-mode Video Dr. Dimitrios S. Nikolopoulos CSL/UIUC
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
ENGI 3655 Lab Sessions 1Richard Khoury.  Linked Allocation ◦ Section Richard Khoury2.
Text-Mode Programming Question #1 What are the three levels of access to the video display when writing characters on the screen in text mode?
1. Stage-1 Bootloader ENGI 3655 Lab Sessions Richard Khoury.
Strings, Procedures and Macros
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
ICS312 Lecture13 String Instructions.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
8086 Internal Architecture
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.
5. C Functions ENGI 3655 Lab Sessions A UNIX saleslady, Lenore, Enjoys work, but she likes the beach more. She found a good way To combine work and play:
Assembly 09. Outline Strings in x86 esi, edi, ecx, eax stosb, stosw, stosd cld, std rep loop 1.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
Lecture 11 Text mode video
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
ECE291 Computer Engineering II Lecture 12 Josh Potts University of Illinois at Urbana- Champaign.
Assembly Language Addressing Modes. Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the.
Chapter 8 String Operations. 8.1 Using String Instructions.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Computer Graphics Lecture 04 Point Taqdees A. Siddiqi
Assembly language.
Assembly 07 String Processing.
Chapter 4 Data Movement Instructions
Assembly IA-32.
9/17/2018 Kiến Trúc Máy Tính.
Microprocessor and Assembly Language
Symbolic Instruction and Addressing
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
CS 301 Fall 2002 Computer Organization
CS-401 Computer Architecture & Assembly Language Programming
Symbolic Instruction and Addressing
(Array and Addressing Modes)
Computer Architecture CST 250
X86 Assembly Review.
Chapter 6 –Symbolic Instruction and Addressing
Computer Architecture and System Programming Laboratory
(Array and Addressing Modes)
Presentation transcript:

4. Kernel and VGA ENGI 3655 Lab Sessions

Richard Khoury2 Textbook Readings  None

Richard Khoury3 Kernel  Last week, our stage-2 bootloader loaded a 32-bit kernel  This week, we will create our first kernel! ◦ Displays a message ◦ Infinite loop

Richard Khoury4 Kernel org 0x bits 32 jmp KernelCode %include "KernelDisplay.inc" msg db 0x0A, 0x0A, "ENGI Bit Kernel", 0x0A, 0 KernelCode: mov ax, 0x10 mov ds, ax mov ss, ax mov es, ax mov esp, 90000h call ClearScreen mov ebx, msg call DisplayString jmp $ cli hlt

Richard Khoury5 Kernel  We already have a simple display function in the bootloader ◦ Uses BIOS Interrupt 10h ◦ But that won’t work in Protected Mode  We’ll have to use the VGA adaptor ◦ Functions “ClearScreen” and “DisplayString” (and more) are in the included file “KernelDisplay.inc”

Richard Khoury6 VGA  Video Graphic Array (VGA) is the video standard since 1987  Consists of ◦ Graphics Controller: interface between video buffer and the rest of the system ◦ Video Buffer: a segment of memory ◦ Sequencer: converts memory data to colour indexes ◦ Video Digital-to-Analog Controller: converts memory data and sequencer indexes to analog signal ◦ CRTC: controls various hardware functions, such as screen resolution, converting DAC signal to video signal, and moving the cursor System Bus Graphics Controller Video Buffer Sequencer DAC CRTC

Richard Khoury7 Video Buffer  Segment of memory  Assigned by BIOS at start-up as 0xA0000 to 0xBFFFF ◦ 0xA0000 to 0xAFFFF: graphics mode ◦ 0xB0000 to 0xB7FFF: monochrome text mode ◦ 0xB8000 to 0xBFFFF: color text mode  VGA system automatically displays the content of part of this buffer, based on current video mode

Richard Khoury8 Graphics Controller  Supports different video modes  For backward compatibility, it is in Mode 7 at start- up ◦ 16 colours ◦ ASCII text ◦ 80 columns by 25 lines ◦ 2 bytes per character  First byte for character  Second byte for attribute  Bits 0-2: Foreground RGB  Bit 3: Foreground intensity  Bits 4-6: Background RGB  Bit 7: Foreground blinking

Richard Khoury9 Displaying in Mode 7  Content of Video Buffer displayed on screen directly  Therefore, we display simply by writing into the buffer at the right place  What is the right place? ◦ Mode 7 is a colour text mode, so the right place starts at 0xB8000 %define VIDMEM 0xB8000 mov edi, VIDMEM ; pointer to video memory mov byte [edi], 'A' mov byte [edi+1], 0x94  0x94 = = blinking red on blue background

Richard Khoury10 Displaying in Mode 7  Each word in memory is a character position on screen ◦ 0xB8000 is top-left corner, coordinate (0,0)  Displaying elsewhere on screen is simply writing elsewhere in memory  Screen position is counted in characters from 0 ◦ 5th character of first line = 4 ◦ 5th character of second line = one line’s worth of characters + 4 ◦ More generally: (X,Y) position on screen = Y * screen width in characters + X

Richard Khoury11 Displaying in Mode 7  Memory position = 0xB screen position in memory  But remember that each character is two bytes in memory ◦ So multiply by 2  (X,Y) position on screen = 0xB Y * 2 * screen width in characters + X * 2

Richard Khoury12 Displaying in Mode 7  Let’s add a blinking blue on red B at (4,5) ◦ Attributes: = 0xC1 %define COLS 80 xor ecx, ecx mov ecx, COLS*2; 2 * screen width xor eax, eax mov al, 5; Y mul ecx; Y * 2 * screen width push eax mov al, 4; X mov cl, 2 mul cl; X * 2 pop ecx add eax, ecx; Y * 2 * screen width + X * 2 add eax, VIDMEM; 0xB Y * 2 * sw + X * 2 mov edi, eax mov byte [edi], 'B' mov byte [edi+1], 0xC1

Richard Khoury13 Displaying in Mode 7  Now we can display a single character anywhere on screen  What more do we need?

Richard Khoury14 What more do we need?  We need to keep track of the current (X,Y) coordinates _CurX db 0 _CurY db 0  We need to watch for new lines ◦ Newline ASCII char cmp bl, 0x0A je.Row ◦ Reached column 80 inc byte [_CurX] cmp [_CurX], COLS je.Row  We need to jump to the next line.Row: mov byte [_CurX], 0 inc byte [_CurY]  We need to put all this in a character-display function

Richard Khoury15 What more do we need?  String-handling ◦ Notice from our kernel mov ebx, msg call DisplayString ◦ And just last slide cmp bl, 0x0A  Function DisplayString ◦ Split up a string, putting each character in bl, watching out for the 0 end char, and calling the character-display function for each one and the cursor-update function at the end ◦ Minor modification of the one we already have

Richard Khoury16 What more do we need?  From the kernel, we also need call ClearScreen ◦ As you might guess, this function clears the screen and resets _CurX and _CurY to zero ◦ Clearing the screen is simply displaying 80 x 25 = 2000 consecutive spaces of the screen background colour

 STOSW ◦ Copy the value of AX into memory at ES:DI in the specified order  REP STOSW ◦ Repeat CX times  CLD ◦ Specify order: copy left-to-right and increment ES:DI Clear Screen Richard Khoury17

Richard Khoury18 Cursor  You might notice that the cursor doesn’t move as we add text  The Cathode Ray Tube Controller (CRTC) handles the cursor  The CRTC has several 8-bit ports, including ◦ Port 0x3D4: Index Register ◦ Port 0x3D5: Data Register  The Index Register offset indicates what the data sent to the Data Register is ◦ 0xE: Cursor Location High ◦ 0xF: Cursor Location Low

Richard Khoury19 Cursor  Moving the cursor to an address in EBX done in two steps, low byte then high byte  For each ◦ Point to the right offset (0x0E or 0x0F) in the index register (0x03D4) ◦ Send the new value (BH or BL) to the data register (0x03D5) ◦ Recall: last week we saw a function to send a value from our Assembly program to a controller port OUT port#, value

Richard Khoury20 Cursor  The new cursor position has to be in ebx  The cursor position is a screen, not memory, position ◦ Use _CurX and _CurY without multiplying by 2 mov bh, byte [_CurY] mov bl, byte [_CurX] ◦ Compute ebx = bh * COLS + bl xor eax, eax mov ecx, COLS mov al, bh mul ecx add al, bl mov ebx, eax

Richard Khoury21 Lab Assignment  New files online ◦ New kernel code: Kernel.asm & KernelDisplay.inc  Write the functions in KernelDisplay.inc that handle the memory or controller ◦ ClearScreen ◦ DisplayChar ◦ MoveCursor ◦ DisplayString is already given  Those are the first four OS functions we’ll make!