Skip to content

Commit e640aa5

Browse files
committed
VGA driver, syscall and pingpong creation dump
1 parent ab29477 commit e640aa5

File tree

15 files changed

+332
-53
lines changed

15 files changed

+332
-53
lines changed
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#pragma once
22

3-
#define GRAPHICS_HEIGHT 640
4-
#define GRAPHICS_WIDTH 480
3+
#include <stddef.h>
54

6-
// following functions doesn't verify arguments
7-
inline void draw_pixel(int x, int y, int color);
8-
inline void draw_char(int x, int y, int fnt_size, int color);
9-
// x1<=x2, y1<=y2
10-
inline void draw_rectangle(int x1, int y1, int x2, int y2, int color);
11-
inline void draw_ellipse(int x1, int y1, int x2, int y2, int color);
12-
13-
void graphics_flush();
5+
int graphics_switchto_320x200x256();
6+
int graphics_write_320x200x256(int user_ds, uint8_t *__us_buffer);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int syscall_4_graphics(int operation, int a1, int a2, int a3, int user_ds);

include/fuzzy/real_mode/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#pragma once
22

3-
int real_mode_client(int eax, int ebx, int ecx, int edx, int es);
3+
int real_mode_client(int int_num, int eax, int ebx, int ecx, int edx, int es);

src/drivers/disk/disk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static int load_sector_via_reallibrary_data(
2020
int sector_index = lba%63 + 1;
2121
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=02h:_Read_Sectors_From_Drive
2222
real_mode_client(
23+
0x13, // interrupt number
2324
(0x02<<8) | count,
2425
es_address,
2526
((cylinder_head>>2)&0xFFC0) | (sector_index),
@@ -28,6 +29,7 @@ static int load_sector_via_reallibrary_data(
2829
);
2930
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=01h:_Get_Status_of_Last_Drive_Operation
3031
int eax = real_mode_client(
32+
0x13, // interrupt number
3133
(0x01<<8),
3234
0,
3335
0,

src/drivers/display/vga/graphics.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22
#include<fuzzy/kernel/process/process.h>
33
#include<fuzzy/memmgr/tables/gdt.h>
44
#include<fuzzy/memmgr/layout.h>
5+
#include<fuzzy/real_mode/client.h>
56

67
#include <stddef.h>
78

8-
// FIX: large buffer size, looks like we need to move kernel.
9-
static uint16_t buffer[GRAPHICS_HEIGHT][GRAPHICS_WIDTH] = {0};
9+
int graphics_switchto_320x200x256() {
10+
uint8_t video_mode_flag = 0x13; // 320x200x256
11+
real_mode_client(
12+
0x10, // interrupt number
13+
(0x00<<8) | video_mode_flag,
14+
0, // do not care
15+
0, // do not care
16+
0, // do not care
17+
0 // do not care
18+
);
19+
return 0;
20+
}
1021

11-
void graphics_flush() {
22+
int graphics_write_320x200x256(int user_ds, uint8_t *__us_buffer) {
23+
const int size = 320*200*1;
1224
kernel_memncpy_absolute(
1325
GDT_ABS32_DS, // dst ds
1426
MEMORY_VGA_GRAPHICS_ADDRESS, // dst address
15-
GDT_KERNEL_DS, // src ds
16-
buffer, // src address
17-
MEMORY_VGA_GRAPHICS_SIZE); // FIX: doesn't match
27+
user_ds, // src ds
28+
__us_buffer, // src address
29+
size);
30+
return 0;
1831
}

src/kernel/syscall/graphics.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <fuzzy/kernel/syscall/graphics.h>
2+
#include <fuzzy/drivers/display/vga/graphics.h>
3+
4+
#include <graphics.h>
5+
6+
static int _graphics_init() {
7+
// switch to 320x200x256 mode
8+
return graphics_switchto_320x200x256();
9+
}
10+
11+
static int _graphics_close() {
12+
return 0;
13+
}
14+
15+
static int _graphics_copybuffer(int user_ds, void *_us_buffer) {
16+
return graphics_write_320x200x256(user_ds, _us_buffer);
17+
}
18+
19+
int syscall_4_graphics(int operation, int a1, int a2, int a3, int user_ds) {
20+
switch (operation) {
21+
case SYSCALL_GRAPHICS_INITGRAPH:
22+
return _graphics_init();
23+
case SYSCALL_GRAPHICS_CLOSEGRAPH:
24+
return _graphics_close();
25+
case SYSCALL_GRAPHICS_COPYBUFFER:
26+
return _graphics_copybuffer(user_ds, (void *)a1);
27+
}
28+
return -1;
29+
}

src/kernel/syscall/syscall.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <fuzzy/kernel/process/process.h>
33
#include <fuzzy/kernel/syscall/file_handler.h>
44
#include <fuzzy/kernel/syscall/console.h>
5+
#include <fuzzy/kernel/syscall/graphics.h>
56
#include <fuzzy/kernel/syscall/syscall.h>
67

78
#include <sys/syscall.h>
@@ -26,6 +27,7 @@ void interrupt_register_0x32_syscall() {
2627
SYSCALL_TABLE[SYSCALL_PROCESS]=syscall_1_process;
2728
SYSCALL_TABLE[SYSCALL_FILE_OP]=syscall_2_file_handler;
2829
SYSCALL_TABLE[SYSCALL_CONSOLE]=syscall_3_console;
30+
SYSCALL_TABLE[SYSCALL_GRAPHICS]=syscall_4_graphics;
2931
}
3032

3133
int syscall_selector(int id, int arg0, int arg1, int arg2, int arg3, int user_ds) {

src/real_mode/client.asm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,30 @@ global real_mode_client
4040
; push all value to be poped in real mode
4141
mov ecx, 0
4242
mov esi, ebp
43-
mov ebx, [ds:esi + 0x18] ; (arg4:es)
43+
mov ebx, [ds:esi + 28] ; (arg5:es)
4444

4545
push ecx ; realmode: ds
4646
push ebx ; realmode: es
4747
push ecx ; realmode: fs
4848
push ecx ; realmode: gs
4949

50-
mov eax, [ds:esi + 0x8] ; (arg0:eax)
51-
mov ebx, [ds:esi + 0xc] ; (arg1:ebx)
52-
mov ecx, [ds:esi + 0x10] ; (arg2:ecx)
53-
mov edx, [ds:esi + 0x14] ; (arg3:edx)
50+
mov eax, [ds:esi + 12] ; (arg1:eax)
51+
mov ebx, [ds:esi + 16] ; (arg2:ebx)
52+
mov ecx, [ds:esi + 20] ; (arg3:ecx)
53+
mov edx, [ds:esi + 24] ; (arg4:edx)
5454

5555
push eax ; realmode: ax
5656
push ebx ; realmode: bx
5757
push ecx ; realmode: cx
5858
push edx ; realmode: dx
5959

60+
mov eax, [ds:esi + 8] ; (arg0:interrupt)
61+
push eax
62+
6063
; Note: Make sure these line have IP representable
6164
; in 2 bytes.
6265
call GDT_ABS16_CS:0x7E00 ; execute_0x13_enter_real_mode
63-
add esp, 32
66+
add esp, 36
6467

6568
; revert back to original stack
6669
pop ebx

src/real_mode/static_library.asm

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
pop ebx
1212
push bx
1313
push ax
14-
jmp execute_0x13_enter_real_mode
14+
jmp execute_int_enter_real_mode
1515

16-
execute_0x13_enter_real_mode:
16+
execute_int_enter_real_mode:
1717
; interrupts should already be disabled
1818
; meant to be executed serially.
1919
; mov ss, 0 ; Hack: Prerequisite
@@ -24,28 +24,46 @@
2424
mov eax, cr0
2525
and eax, 0xFFFFFFFE
2626
mov cr0, eax
27-
jmp GDT_NULL_CS:execute_0x13_from_real_mode
27+
jmp GDT_NULL_CS:execute_int_from_real_mode
2828

29-
execute_0x13_from_real_mode:
29+
execute_int_from_real_mode:
3030
; fix stack
3131
mov eax, 0
3232
mov ss, ax
3333
mov ds, ax ; for loading IDT table
3434
lidt [idt_table_real_mode]
3535

3636
; minimal setup for real mode as required.
37-
mov ds, [ebp+32]
38-
mov es, [ebp+28]
39-
mov fs, [ebp+24]
40-
mov gs, [ebp+20]
37+
mov ds, [ebp+36]
38+
mov es, [ebp+32]
39+
mov fs, [ebp+28]
40+
mov gs, [ebp+24]
4141

42-
mov eax, [ebp+16]
43-
mov ebx, [ebp+12]
44-
mov ecx, [ebp+8]
45-
mov edx, [ebp+4] ; 4 byte for far call
42+
mov eax, [ebp+20]
43+
mov ebx, [ebp+16]
44+
mov ecx, [ebp+12]
45+
mov edx, [ebp+8]
4646

47+
; interrupt number
48+
mov esi, [ebp+4] ; 4 byte for far call
49+
50+
; check for some interrupt numbers only
51+
cmp esi, 0x10
52+
je _int_0x10
53+
cmp esi, 0x13
54+
je _int_0x13
55+
56+
jmp _int_end ; found no match
57+
58+
_int_0x10:
59+
int 0x10
60+
jmp _int_end
61+
62+
_int_0x13:
4763
int 0x13
64+
jmp _int_end
4865

66+
_int_end:
4967
push eax
5068
mov eax, cr0
5169
or eax, 0x00000001
@@ -54,9 +72,9 @@
5472

5573
pop ss; restore absolute stack
5674

57-
jmp GDT_ABS16_CS:execute_0x13_leave_real_mode ; Absolute Code Segment Selector
75+
jmp GDT_ABS16_CS:execute_int_leave_real_mode ; Absolute Code Segment Selector
5876

59-
execute_0x13_leave_real_mode:
77+
execute_int_leave_real_mode:
6078
retf
6179

6280
[SECTION .data]

src/usr/include/graphics.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#define GRAPHICS_MAX_HEIGHT 320
4+
#define GRAPHICS_MAX_WIDTH 200
5+
6+
#define DETECT 0
7+
#define GRAPHIC_DRIVER_VGA 1
8+
9+
#define GRAPHIC_MODE_320x200x16 1
10+
11+
#define BLACK 0x0
12+
#define BLUE 0x1
13+
#define GREEN 0x2
14+
#define CYAN 0x3
15+
#define RED 0x4
16+
#define MAGENTA 0x5
17+
#define BROWN 0x6
18+
#define LIGHT_GRAY 0x7
19+
#define DARK_GRAY 0x8
20+
#define LIGHT_BLUE 0x9
21+
#define LIGHT_GREEN 0xA
22+
#define LIGHT_CYAN 0xB
23+
#define LIGHT_RED 0xC
24+
#define LIGHT_MAGENTA 0xD
25+
#define YELLOW 0xE
26+
#define WHITE 0xF
27+
28+
#define SYSCALL_GRAPHICS_INITGRAPH 0
29+
#define SYSCALL_GRAPHICS_CLOSEGRAPH 1
30+
#define SYSCALL_GRAPHICS_COPYBUFFER 2
31+
32+
void initgraph(int *graphdetect, int *graphmode, char *not_used);
33+
int graphresult();
34+
void closegraph();
35+
void cleardevice();
36+
37+
38+
void setcolor(int color);
39+
int getcolor();
40+
void setbkcolor(int color);
41+
int getbkcolor();

0 commit comments

Comments
 (0)