Skip to content

Commit 79827be

Browse files
committed
Refine the SDL-oriented system calls declaration
Replace the type of some unsigned parameters of system calls with signed int and treat they as int32_t internally in the emulator. Change the name of the parameter "screen" of the "draw_frame" system call to "base" for the sake of consistency with the "setup_queue" system call.
1 parent 3011a36 commit 79827be

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

docs/syscall.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ These system calls are solely for the convenience of accessing the [SDL library]
103103

104104
**system call number**: `0xBEEF`
105105

106-
**synopsis**: `void draw_frame(void *screen, int width, int height)`
106+
**synopsis**: `void draw_frame(void *base, int width, int height)`
107107

108-
If a window does not already exist, one will be created with the specified `width` and `height`. The `screen` buffer will replace the content of the framebuffer, passing a different `width` or `height` compared to the size of the window is undefined behavior. This system call additionally polls events from the SDL library, and, if necessary, update the internal input specific event queue.
108+
If a window does not already exist, one will be created with the specified `width` and `height`. The buffer pointed to by `base` will replace the content of the framebuffer, passing a different `width` or `height` compared to the size of the window is undefined behavior. This system call additionally polls events from the SDL library, and, if necessary, update the internal input specific event queue.
109109

110110
The width and height are merely the virutal dimensions of the screen; they are unrelated to the window's real size. The system call would deal with resizing events internally when they occurred.
111111

112112
### `setup_queue` - Setup input system's dedicated event and submission queue
113113

114114
**system call number**: `0xC0DE`
115115

116-
**synopsis**: `void *setup_queue(void *base, int capacity, unsigned int *event_count)`
116+
**synopsis**: `void setup_queue(void *base, size_t capacity, int *event_count)`
117117

118118
The user must pass a continuous memory chunk that contains two tightly packed queues, the event queue and the submission queue. And the submission queue is immediately following the last element of the event queue, which is the event queue's base address plus the size of each event element multiplied by the given capacity. If the capacity is not a power of two, it will be treated as the rounded value of the next highest power of two. Additionally, because the event counter variable serves as a notifier to the user that an event has been added to the event queue, it is critical to initialize it before passing its address to this system call.
119119

@@ -129,7 +129,7 @@ An event entry is made up of a 32-bit value representing the event's type and a
129129

130130
**system call number**: `0xFEED`
131131

132-
**synopsis**: `void submit_queue(int count)`
132+
**synopsis**: `void submit_queue(size_t count)`
133133

134134
To inform the emulator that a batch of submissions should be processed, the application code should push several submissions into the queue first, and then pass the size of the submissions batch to this system call; the submissions will be processed and executed sequentially and immediately.
135135

src/syscall_sdl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static void event_push(riscv_t *rv, event_t event)
107107
++event_queue.end;
108108
event_queue.end &= queues_capacity - 1;
109109

110-
uint32_t count;
110+
int32_t count;
111111
memory_read(s->mem, (void *) &count, event_count, sizeof(uint32_t));
112112
count += 1;
113113
memory_write(s->mem, event_count, (void *) &count, sizeof(uint32_t));
@@ -218,10 +218,10 @@ void syscall_draw_frame(riscv_t *rv)
218218
{
219219
state_t *s = rv_userdata(rv); /* access userdata */
220220

221-
/* draw_frame(screen, width, height) */
221+
/* draw_frame(base, width, height) */
222222
const uint32_t screen = rv_get_reg(rv, rv_reg_a0);
223-
const uint32_t width = rv_get_reg(rv, rv_reg_a1);
224-
const uint32_t height = rv_get_reg(rv, rv_reg_a2);
223+
const int32_t width = rv_get_reg(rv, rv_reg_a1);
224+
const int32_t height = rv_get_reg(rv, rv_reg_a2);
225225

226226
if (!check_sdl(rv, width, height))
227227
return;

0 commit comments

Comments
 (0)