Skip to content

Commit

Permalink
[servers/video] Fix font setting
Browse files Browse the repository at this point in the history
This fixes #121. It also gets rid of some inline assembly, rewriting the code in easier-to-understand C code, which is normally a good thing.
  • Loading branch information
perlun committed Oct 13, 2018
1 parent b2e6e1a commit e3af2ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 128 deletions.
10 changes: 9 additions & 1 deletion servers/video/vga/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ static void vga_font_set(uint8_t *font_data, unsigned int length)
system_port_out_uint8_t_pause(VGA_GRAPHIC_REGISTER, 0x06);
system_port_out_uint8_t_pause(VGA_GRAPHIC_DATA, 0x00);

memory_copy(graphic_video_memory, font_data, length);
// The VGA hardware always reserves 32 bytes for each font, so we can't just copy the data to video memory as-is;
// we need to skip n bytes per character unless we use an 8x32 font.
int bytes_per_character = length / 256;
for (int i = 0; i < 256; i++)
{
memory_copy(graphic_video_memory + (i * 32), &font_data[i * bytes_per_character], bytes_per_character);
}

// First, the sequencer.
// Synchronous reset.
Expand Down Expand Up @@ -286,6 +292,8 @@ static void handle_connection(ipc_structure_type *ipc_structure)
{
vga_palette_set_entry(index, &text_palette[index]);
}

vga_font_set(font_8x8, sizeof(font_8x8));
}
else if (video_mode->mode_type == VIDEO_MODE_TYPE_GRAPHIC &&
video_mode->depth == 8)
Expand Down
127 changes: 3 additions & 124 deletions servers/video/vga/vgalib.asm
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
; Abstract: x86 assembly-level VGA helper functions
; Author: Johan Thim (Thank you for your great help!)
;
; © Copyright 1999-2000 chaos development
; © Copyright 2013 chaos development
; © Copyright 2015-2016 chaos development
; © Copyright 1999 chaos development

; FIXME: Rewrite this in C!

extern font_8x8
extern graphic_video_memory
global vga_set_mode

Expand Down Expand Up @@ -41,23 +38,6 @@ mode_table: dd mode_320x200x256
dd mode_640x480x16
dd mode_640x400x256

mode_t_table: db 0
db 1
db 0
db 0
mode_t_len equ $ - mode_t_table

font_ptr dd 0
font_bytes db 0
vga_buff dd miff

; FIXME: for some reason, the VGA server won't start if this is put into the
; BSS section.

;section .bss

miff times 300 db 0

section .text

vga_set_mode: push ebp
Expand All @@ -68,17 +48,9 @@ vga_set_mode: push ebp
mov esi, [mode_table + eax * 4]
push eax
call setmode
add esp,4

pop eax
cmp byte [mode_t_table + eax], 1
jne .no_font

mov dword [font_ptr], font_8x8
mov byte [font_bytes], 8

call loadfont

.no_font: popa
popa
pop ebp
ret

Expand Down Expand Up @@ -146,96 +118,3 @@ setmode: mov dx,3c2h ; misc addr
out dx,al

ret

loadfont: cld
mov edi, [vga_buff]

mov dx,3ceh ; graphics
mov al,5 ; write mode reg
out dx,al
inc dx
in al,dx
stosb
and al,0fch
xchg al,ah
mov al,5
dec dx
out dx,ax

mov al,6 ; misc reg
out dx,al
inc dx
in al,dx
stosb
and al,0f1h
or al,4
xchg al,ah
mov al,6
dec dx
out dx,ax

mov dx,3c4h ; sequencer port
mov al,2 ; map mask reg
out dx,al
inc dx
in al,dx
stosb

dec dx
mov ax,402h
out dx,ax

mov al,4 ; memory selector reg
out dx,al
inc dx
in al,dx
stosb
or al,4
xchg al,ah
mov al,4
dec dx
out dx,ax

mov esi, [font_ptr]
mov edi, [graphic_video_memory]

xor ecx,ecx
mov ebx,ecx

.1: mov cl,[font_bytes]
rep movsb

mov cl,32
sub cl,[font_bytes]
xor eax,eax
rep stosb

dec bl ; 256 chars
jnz .1

mov esi,[vga_buff]

mov dx,3ceh
lodsb
xchg al,ah
mov al,5
out dx,ax

lodsb
xchg al,ah
mov al,6
out dx,ax

mov dx,3c4h
lodsb
xchg al,ah
mov al,2
out dx,ax

lodsb
xchg al,ah
mov al,4
out dx,ax

ret

12 changes: 9 additions & 3 deletions storm/x86/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <storm/x86/gdt.h>
#include <storm/x86/tss.h>

#define DELAY_PORT 0x80

// Linked list over allocated I/O regions.
port_range_type *port_list = NULL;

Expand Down Expand Up @@ -133,7 +135,7 @@ return_type port_range_register(unsigned int start, unsigned int ports, char *de
}

// If the TSS is too small, expand it.
if (current_tss->iomap_size < BIT_IN_BYTES(start + ports - 1))
if (current_tss->iomap_size < BIT_IN_BYTES(MAX_OF_TWO(start + ports - 1, DELAY_PORT)))
{
int old_iomap_size = current_tss->iomap_size;
storm_tss_type *old_tss = current_tss;
Expand All @@ -151,7 +153,7 @@ return_type port_range_register(unsigned int start, unsigned int ports, char *de
current_tss->iomap_size = BIT_IN_BYTES(start + ports);
memory_set_uint8_t(current_tss->iomap + old_iomap_size, 0xFF, current_tss->iomap_size - old_iomap_size);
DEBUG_MESSAGE(DEBUG, "Clearing %u bytes", current_tss->iomap_size - old_iomap_size)

thread_unlink(old_tss->thread_id);
current_tss_node = thread_link(current_tss);

Expand Down Expand Up @@ -188,6 +190,10 @@ return_type port_range_register(unsigned int start, unsigned int ports, char *de
BIT_CLEAR(current_tss->iomap[port / 8], port % 8);
}

// Also make sure all processes working with I/O can use the delay port, since it's sometimes needed when dealing
// with ISA hardware.
BIT_CLEAR(current_tss->iomap[DELAY_PORT / 8], DELAY_PORT % 8);

// Since this thread has got a new TSS, we have to check if it is an IRQ handler. If so, we must update the TSS pointer.
for (index = 0; index < IRQ_LEVELS; index++)
{
Expand Down Expand Up @@ -265,7 +271,7 @@ void port_range_free_all(thread_id_type thread_id)
// FIXME: This algorithm feels a little sub-optimal... or is it just me?
// FIXME: Don't repeat a lot of the code from port_range_unregister, but rather use a common helper method that
// both of these methods can call to perform the actual work.

// Loop until we find no more matches.
while (TRUE)
{
Expand Down

0 comments on commit e3af2ae

Please sign in to comment.