From 2c79240cc66dd2a116056662def9bdc165b2b3e7 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 14 May 2017 11:06:13 +0200 Subject: playing with addresses and seing the CRT index port number now in port8_read --- README | 9 ++++++++- src/kernel.c | 5 +---- src/port.asm | 21 ++++++++++++++++++++- src/port.c | 5 ----- src/vga.c | 34 +++++++++++++++++++++++++++++++--- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/README b/README index 0d29dbd..c92d044 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ ndisasm -b16 -o7c00h -a image.bin | less objdump -M intel -d kernel.o | less gcc -m32 -ffreestanding -c -o kernel.o kernel.c -ld -o kernel.bin -Ttext 0x8000 kernel.o -m elf_i386 --oformat binary +ld -o kernel.bin -Ttext 0x8400 kernel.o -m elf_i386 --oformat binary objdump -M intel -d kernel.bin | less # oformat: objdump -i lists tons of formats @@ -37,6 +37,13 @@ Booting from 0000:7c00 Next at t=14040244 (0) [0x000000007c00] 0000:7c00 (unk. ctxt): mov ax, 0x0000 ; b80000 +C entry: +break 0x8400 + +disassemble kernel in 32-bit mode +ndisasm -b32 -o8400h -a kernel.bin | less + + links ----- diff --git a/src/kernel.c b/src/kernel.c index 91ed26b..d5db426 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -27,10 +27,7 @@ void entry( void ) } vga_put_char_at( &vga, x_pos, y_pos, '.' ); vga_put_newline( &vga ); - - vga_put_hex( &vga, 4711 ); - vga_put_newline( &vga ); - + //~ vga_set_color( &vga, VGA_COLOR_WHITE ); //~ vga_set_background_color( &vga, VGA_COLOR_RED ); //~ vga_clear_screen( &vga ); diff --git a/src/port.asm b/src/port.asm index 34d1f78..c7a2b85 100644 --- a/src/port.asm +++ b/src/port.asm @@ -1,18 +1,33 @@ [bits 32] global port8_write +global port8_read +; void port8_write( port8_t *port, uint8_t data ); port8_write: + push ebp + mov ebp, esp mov edx, [ebp+16] mov eax, (edx) +; mov eax, [epb+8] ; mov dx, [ebp+8] ; out ax, dl + leave ret - +; uint8_t port8_read( port8_t *port ) +port8_read: + push ebp + mov ebp, esp + mov edx, [ebp+8] + mov eax, [edx] + leave + ret + ;~ void port8_init( port8_t *port, uint16_t number ) +; __asm__ volatile("inb %1, %0" : "=a" (result) : "Nd" (_port)); ;~ global _myfunc ;~ _myfunc: push ebp @@ -23,3 +38,7 @@ port8_write: ;~ leave ; mov esp,ebp / pop ebp ;~ ret ; __asm__ volatile("outb %0, %1" : : "a" (_data), "Nd" (_port)); + +;~ { + ;~ return 0; +;~ } diff --git a/src/port.c b/src/port.c index 1a55669..f64cc69 100644 --- a/src/port.c +++ b/src/port.c @@ -4,8 +4,3 @@ void port8_init( port8_t *port, uint16_t number ) { port->number = number; } - -uint8_t port8_read( port8_t *port ) -{ - return 0; -} diff --git a/src/vga.c b/src/vga.c index 0c344f7..fd67552 100644 --- a/src/vga.c +++ b/src/vga.c @@ -53,12 +53,41 @@ void vga_set_cursor( vga_t *vga, const int x, const int y ) void vga_set_cursor_from_hardware( vga_t *vga ) { + // value of port we want to see later in assembly + uint16_t n = vga->crtc_index_port.number; + vga_put_hex( vga, n ); + vga_put_newline( vga ); + + // the address of the vga structure + uintptr_t uip = (uintptr_t)( (void *)vga ); + vga_put_hex( vga, uip ); + vga_put_newline( vga ); + + // the address of the port structure inside the vga structure + uintptr_t uip2 = (uintptr_t)( (void *)&vga->crtc_index_port ); + vga_put_hex( vga, uip2 ); + vga_put_newline( vga ); + + // the address of the number membger in the port structure inside the vga structure + // must be the same as uip2 by C99 + uintptr_t uip3 = (uintptr_t)( (void *)&vga->crtc_index_port.number ); + vga_put_hex( vga, uip3 ); + vga_put_newline( vga ); + + uint8_t data = port8_read( &(vga->crtc_index_port ) ); + vga_put_hex( vga, data ); + vga_put_newline( vga ); +//~ unsigned short offset; + //~ out(0x3D4, 14); + //~ offset = in(0x3D5) << 8; + //~ out(0x3D4, 15); + //~ offset |= in(0x3D5); } void vga_set_cursor_on_hardware( vga_t *vga ) { uint16_t hw_cursor_pos = vga->cursor_x + vga->cursor_y * vga->res_x; - + port8_write( &vga->crtc_index_port, 15 ); port8_write( &vga->crtc_index_port, hw_cursor_pos & 0xff ); port8_write( &vga->crtc_index_port, 14 ); @@ -164,8 +193,7 @@ void vga_put_hex( vga_t *vga, const uint32_t v ) { char buf[9]; - strlcpy( buf, "0x", 9 ); - vga_put_string( vga, (const char *)buf ); + vga_put_string( vga, "0x" ); itoa( v, (char *)buf, 16 ); vga_put_string( vga, (const char *)buf ); } -- cgit v1.2.3-54-g00ecf